Jump to content

Importar arquivos .babylon / Import files .babylon


Recommended Posts

I just've seen several posts here that shows how to do this more never works for me to decide to ask for help.

I just want to learn how to import files not there is nothing very clear about it all the codes I found after two days of searching failed.

maybe someone here can help me.

my code.

<! DOCTYPE html>
<Meta charset = utf-8>
<Title> My first Babylon.js app </ title>
    html, body {
        overflow: hidden;
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;

    renderCanvas {
        width: 100%;
        height: 100%;
        touch-action: none;
</ Style>
</ Head>
<Script src = 'babylon.2.5.js'> </ script>
<! - <script src = 'http://www.babylonjs.com/hand.minified-1.2.js'> </ script> ->
<Canvas id = 'renderCanvas'> </ canvas>
   window.addEventListener ( 'DOMContentLoaded', function () {
            // get the DOM element canvas
            var canvas = document.getElementById ( 'renderCanvas');

            // load the 3D engine
            var = new engine BABYLON.Engine (canvas, true);
            // function createScene que Creates and return the scene
            var createScene = function () {
                // create a basic object BJS Scene
                var = new scene BABYLON.Scene (engine);
//scene.clearColor = new BABYLON.Color3 (10,22,10);
                // create a Freecamera, And Set to its position (x: 0, y 5, z -10)
                Camera = new BABYLON.FreeCamera var ( 'CAMERA1' new BABYLON.Vector3 (0, 5, -10), scene);

                // target camera to the scene origin
                camera.setTarget (BABYLON.Vector3.Zero ());

                // attach the camera to the canvas
                camera.attachControl (canvas, false);

                // create a basic light, aiming 0,1,0 - meaning, to the sky
                var = new light BABYLON.HemisphericLight ( 'light1' new BABYLON.Vector3 (0,1,0) scene);

                // create a built-in 'sphere' shape; its constructor takes 5 params: name, width, depth, subdivisions, scene
                var = BABYLON.Mesh.CreateSphere sphere ( 'sphere1', 16, 1, scene);
                // the sphere moves upward half of its height
                sphere.position.x = -2;
// var box = BABYLON.Mesh.CreateBox ( 'box', 1.0, scene, false, BABYLON.Mesh.DEFAULTSIDE);
//box.rotation.y = -10;
                // create a built-in 'ground' shape; its constructor takes the same 5 params the sphere's the one
  BABYLON.SceneLoader.ImportMesh ( '', 'model /' '01.babylon' scene, function (meshes) {
    var meshes m = [0];
    = //m.isVisible;
    m.scaling new BABYLON.Vector3 = (2,2,2);
    TOAD_MODEL = m;
              var = BABYLON.Mesh.CreateGround ground ( 'ground1', 6, 6, 2, scene);

                // return the created scene
                return scene;

            // call the function createScene
            var = createScene scene ();

            // run the loop surrender
            engine.runRenderLoop (function () {
                scene.render ();

            // the canvas / window resize event handler
            window.addEventListener ( 'resize', function () {
                engine.resize ();
</ Script>
</ Body>
</ Html>

--- The ball appears the ground too light and more etc 3d model that matter try does not work.

Link to comment
Share on other sites

Hello @LuisM, welcome to the forum.

Our playground has MANY importMesh demosHere is one... using a .babylon file (a model) from my free github account.

You can use the playground's "Zip" button... to get a copy of this playground demo... to your home computer.

Then change URL to ummm....  "model/', "01.babylon"  You have extra spaces in your URL.  And you have mis-matched quotes.  You need more-careful JS coding.

Carefully examine the code in the playground demo linked above.  For SOME imported mesh, you may need to create another camera and light... near line 21 in the demo code.

Experiment.  You will be successful.  Be sure you have newer Blender/3DSMax, and newest exporters for them.  The top-6 lines of MY borrowed .babylon file looks like this:

"producer": {"name": "Blender","version": "2.77 (sub 0)","exporter_version": "4.6.1","file": TestSubSurf02.babylon"},

View yours in Notepad, online JSON viewer, or other editors.  Yours should look similar.  If not, then likely old exporter.  Hope this helps.  Be well.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...