JohnK Posted May 26, 2015 Share Posted May 26, 2015 Have read done the searching and found and followed the examples but am missing something that is probably pretty obvious. I have created a scene and usedvar serializedScene = BABYLON.SceneSerializer.Serialize(scene);var strScene = JSON.stringify(serializedScene);to create a JSON file testbox.babylon From what I have gathered the code below should extract the mesh named "box0" and import it into the scene I created. The created scene works fine, the ground appears and rotates as expected with the pointer. The import appears to be successful sinceconsole.log(mesh[0])gives Object { state: "", animations: Array[0], _childrenFlag: -1, _isEnabled: true, _isReady: true, _currentRenderId: 36, _parentRenderId: -1, name: "box0", id: "box0", _scene: Object, 74 more… } However the box does not appear in the scene.//Set Scenevar canvas = document.getElementById("canvas");var engine = new BABYLON.Engine(canvas, true);var scene = createScene(engine,canvas); //Create Materialsvar blueInMat = new BABYLON.StandardMaterial("blueIn", scene);blueInMat.emissiveColor = new BABYLON.Color3(0.2,0.2,1); var redInMat = new BABYLON.StandardMaterial("redIn", scene);redInMat.emissiveColor = new BABYLON.Color3(1,0,0); //Create Ground var groundin=BABYLON.Mesh.CreateGround("groundIn",1200, 1200, 20, scene, false, BABYLON.Mesh.DOUBLESIDE); groundin.material = blueInMat; // Register a render loop to repeatedly render the sceneengine.runRenderLoop(function () { scene.render(); }); // Watch for browser/canvas resize eventswindow.addEventListener("resize", function () { engine.resize(); }); BABYLON.SceneLoader.ImportMesh("box0", "./", "testbox.babylon", scene, function (meshes, particleSystems, skeletons) { console.log(meshes[0]); //meshes[0].material = redInMat; console.log(meshes[0].material); });When the box did not appear I thought maybe it was because the material was not defined so added the redInMat material and set mesh[0] to this - to no avail. I have tried, Firefox, Chrome and IE all give the same result. What am I missing. Quote Link to comment Share on other sites More sharing options...
Blax Posted May 26, 2015 Share Posted May 26, 2015 Hi, recently solve this task, but i'm newbee and the decision not to like to me. 1. Create new temporary scene2. Load extend file in new scene3. Create clones and pushing this in old scene4. Rebuild parend-children links5. Dispose temporary scene But i need import all kind objects (materials, lights, animations not only meshes).Perhaps you can find best decision? Quote Link to comment Share on other sites More sharing options...
jerome Posted May 26, 2015 Share Posted May 26, 2015 have you checked this : http://www.html5gamedevs.com/topic/6737-cant-get-babylon-files-to-load/ maybe renaming your file to testbox.json instead will solve the problem too ... Quote Link to comment Share on other sites More sharing options...
JohnK Posted May 26, 2015 Author Share Posted May 26, 2015 @Blax I do not have a problem loading the full scene including materials, cameras and lights (never tried with animations). Just need to put the render loop in the onsuccess parameter and active the camera here as well. Because of scoping rules the camera is created outside the createScene function. Code below.//Set Scenevar canvas = document.getElementById("canvas");var engine = new BABYLON.Engine(canvas, true);var scene = createScene(engine,canvas); //Set cameravar camera = new BABYLON.ArcRotateCamera("Camera", 0, 50, 300, new BABYLON.Vector3(0, 300, 0), scene); camera.setPosition(new BABYLON.Vector3(0, 200, -1400)); camera.lowerBetaLimit = 0.1;camera.upperBetaLimit = (Math.PI / 2) * 0.9; camera.attachControl(canvas, true); // Watch for browser/canvas resize eventswindow.addEventListener("resize", function () { engine.resize();}); BABYLON.SceneLoader.Load("./", "testbox.babylon", engine, function(scene) { scene.activeCameras.push(camera); // Register a render loop to repeatedly render the scene engine.runRenderLoop(function () { scene.render(); });}); function createScene(engine, canvas) { var canvas = document.getElementById("canvas"); var engine = new BABYLON.Engine(canvas, true); var scene = new BABYLON.Scene(engine); scene.clearColor = new BABYLON.Color3(0.75, 0.75, 0.75); var frontLight = new BABYLON.PointLight("omni", new BABYLON.Vector3(-3000, 6000, 2000), scene); var backLight = new BABYLON.PointLight("omni", new BABYLON.Vector3(3000, -6000, 2000), scene); var bottomLight = new BABYLON.PointLight("omni", new BABYLON.Vector3(-3000, 6000, -2000), scene); frontLight.intensity = 0.2; backLight.intensity = 0.2; bottomLight.intensity = 0.2; return scene; } Quote Link to comment Share on other sites More sharing options...
JohnK Posted May 26, 2015 Author Share Posted May 26, 2015 have you checked this : http://www.html5gamedevs.com/topic/6737-cant-get-babylon-files-to-load/ maybe renaming your file to testbox.json instead will solve the problem too ... Thank you jerome have not seen this. Will have a good read. Having read this post I do not think this is my problem. The testbox.babylon file is loading OK Web Console reports GET XHR http://127.0.0.1:8020/Cubees/testbox.babylon.manifest [HTTP/1.1 200 OK 17ms] GET XHR http://127.0.0.1:8020/Cubees/testbox.babylon [HTTP/1.1 200 OK 163ms] and the console.log shows that the data in the file seems to have been read. Also the code using BABYLON.SceneLoader.Load works OK. Quote Link to comment Share on other sites More sharing options...
jerome Posted May 26, 2015 Share Posted May 26, 2015 Ok, it's definetly NOT a download problem Quote Link to comment Share on other sites More sharing options...
RaananW Posted May 26, 2015 Share Posted May 26, 2015 Hey, John, as the console.log actually shows the mesh correctly, it is being loaded correctly. for some reason it is not being shown. Technically, I don't see anything wrong you are doing. Do you want to upload the .babylon file somewhere and let us see it? that will help us understand what went wrong. Quote Link to comment Share on other sites More sharing options...
Blax Posted May 26, 2015 Share Posted May 26, 2015 Perhaps we talk about this: BABYLON.SceneLoader.Load("/", "myScene.babylon", engine, function(newScene){ newScene.executeWhenReady(function (){ extendScene(); // here you settings for camera's, etc (create scene) engine.runRenderLoop(scRender); }); }); Quote Link to comment Share on other sites More sharing options...
JohnK Posted May 26, 2015 Author Share Posted May 26, 2015 As requested the .babylon file and in addition the code. The html file is testload.html and the .babylon file is testbox.babylon. A .txt version of the .babylon file. Quote Link to comment Share on other sites More sharing options...
RaananW Posted May 26, 2015 Share Posted May 26, 2015 Just looked in the file, haven't tested it yet. Looking at your code and at the file - this might be due to camera configuration... The object's position is 30,30,30. Your camera target is 30,0,0. What can also cause this is z clipping of the camera - the position in the z axis is -1400, which probably clips the imported box. Try getting the camera closer, and set the target correctly, see if that helps. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 26, 2015 Share Posted May 26, 2015 Could share a demo somewhere? It will be easier to help you Quote Link to comment Share on other sites More sharing options...
JohnK Posted May 26, 2015 Author Share Posted May 26, 2015 @DKThere's a demo link in my previous post. Is that what you need or do you require something else? Quote Link to comment Share on other sites More sharing options...
RaananW Posted May 26, 2015 Share Posted May 26, 2015 Looks like the geometry is not being loaded.The mesh is there its geometry isn't. I looked in the ImportMesh code, it looks like it doesn't parse the geometry when loading the mesh using ImportMesh. It only parses geometries when using load. The ImportMesh is missing the call toparseVertexData(...)when importing a mesh with geometry id (like in your case). This require a small commit, I will try finding the time tomorrow to fix that. JohnK 1 Quote Link to comment Share on other sites More sharing options...
JohnK Posted May 27, 2015 Author Share Posted May 27, 2015 @RanaanW That will be great. When you have done it I will try again. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted May 27, 2015 Share Posted May 27, 2015 Just a reminder, there is a BABYLON.SceneLoader.Append() method, if it helps. It is the same as Load(), except the engine arg is replaced with the scene to append to. Quote Link to comment Share on other sites More sharing options...
RaananW Posted May 28, 2015 Share Posted May 28, 2015 ImportMesh should work now, I have commited the changes, latest build in GitHub also includes them.I tested it with your scene, a blue box appears. so i guess it works :-) Quote Link to comment Share on other sites More sharing options...
JohnK Posted May 28, 2015 Author Share Posted May 28, 2015 @RaananW Excellent detective work tracking and fixing the issue as usual. Thank you. Quote Link to comment Share on other sites More sharing options...
JohnK Posted May 28, 2015 Author Share Posted May 28, 2015 Just a reminder, there is a BABYLON.SceneLoader.Append() method, if it helps. It is the same as Load(), except the engine arg is replaced with the scene to append to. For my project I did not want all the meshes in the saved scene loaded. Thanks anyway. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.