Jump to content

[solved] BabylonJS multiple scenes


mout99
 Share

Recommended Posts

Hello, I'm making a page to see 3D objects with a .obj loader, this page has a menu that, when tight, changes the scene, So I'm just changing the location of the file and the name
 Code:
 BABYLON.SceneLoader.ImportMesh("", caminho, arquivo, scene, function (newMeshes) 
             	// caminho = way
             	// arquivo = file
These values I get from a function

 

The problem is that when I change the scene he applies the materials of the previous scene in the current scene, what am I doing wrong?
 
$scope.load3d = function(caminho,arquivo){
			$state.go('app.interna', null, {reload: true});

      		var canvas = document.querySelector("#renderCanvas");

      		var engine = new BABYLON.Engine(canvas, false);
     	
           	var createScene = function () {
            var scene = new BABYLON.Scene(engine);

             var light = new BABYLON.HemisphericLight("Hemi0", new BABYLON.Vector3(0, 1, 0), scene);
				 light.diffuse = new BABYLON.Color3(1, 1, 1);
				 light.intensity = 0.7;
				 light.groundColor = new BABYLON.Color3(1, 1, 1);
				 light.direction = new BABYLON.Vector3(0, -1, 0);

            var camera = new BABYLON.ArcRotateCamera("Camera", 0, 0.8, 100, BABYLON.Vector3.Zero(), scene);
            camera.attachControl(canvas, false);

             BABYLON.OBJFileLoader.OPTIMIZE_WITH_UV = true;

             BABYLON.SceneLoader.ImportMesh("", caminho, arquivo, scene, function (newMeshes) {
             	// caminho = way
             	// arquivo = file

             	var zeromat = new BABYLON.StandardMaterial("zeromat", scene);
                   zeromat.emissiveTexture  = new BABYLON.Texture("js/back2.jpg", scene);
                   zeromat.wireframe = false;
                   zeromat.backFaceCulling = true;
                   newMeshes[0].material = zeromat;

                 var meiomat = new BABYLON.StandardMaterial("meiomat", scene);
                     meiomat.diffuseColor = new BABYLON.Color3(0.3,0.3,0.3);
                     newMeshes[1].material = meiomat;

                camera.maxZ= 45000;
                camera.setPosition(new BABYLON.Vector3(7000,7000,7000));
                camera.wheelPrecision = 0.1;
            });

            // Move the light with the camera
            scene.registerBeforeRender(function () {
            });

            return scene;
        }

      var scene = createScene();
      // Register a render loop to repeatedly render the scene
      engine.runRenderLoop(function () {
         scene.render();
      });
      // Watch for browser/canvas resize events
      window.addEventListener("resize", function () {
         engine.resize();
      });
	}
Sorry for my english, I'm using google translate
 
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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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