Sign in to follow this  
mout99

[solved] BabylonJS multiple scenes

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
 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.