reddozen Posted June 22, 2014 Share Posted June 22, 2014 objName = scene.getMeshByName("Prt_f01_Rag2_bro_mtree_a_04");objName = objName.createInstance("Prt_f01_Rag2_bro_mtree_a_04_inst_"+ Prt_f01_Rag2_bro_mtree_a_04_inst +"");objName is NULL on the second line above. As you can see from the picture below, the object is loaded into the scene, so objName shouldn't be null after the getMeshByName call. Maybe I'm doing this wrong, or maybe there's a better way to handle this? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted June 22, 2014 Share Posted June 22, 2014 I believe that getMeshByName look at index 0 Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted June 22, 2014 Share Posted June 22, 2014 When you say is null on the second line, is this the result of the of the first line assignment or 2nd? Recommend until you have it working to use 2 differently named variables to make quite sure to avoid misdiagnosis. Quote Link to comment Share on other sites More sharing options...
reddozen Posted June 22, 2014 Author Share Posted June 22, 2014 Dad72,I'm not sure what you mean by index 0 JCPalmer,The first line should be setting objName to the original object referenced by the getMeshByName() call.The second like says that objName is null so it errors on the objName.createInstance() call. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted June 22, 2014 Share Posted June 22, 2014 All meshes of babylon on indexed meshes[0]meshes[1]... In your picture highlight you the name of the index 1 of your model but getMeshByName look at index 0 But if you made: meshes[1].name This will give you the expected name Quote Link to comment Share on other sites More sharing options...
reddozen Posted June 22, 2014 Author Share Posted June 22, 2014 I know the name of the object, so getMeshByName() should take the name, and return mesh 1 in this case. It makes since that meshes[1].name would give me the name of this item, but I know the name. I hope this makes since. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted June 22, 2014 Share Posted June 22, 2014 meshes [0] and the complete object. mesh [1] is a submesh. getMeshByName searches for an object, not a submesh Quote Link to comment Share on other sites More sharing options...
reddozen Posted June 22, 2014 Author Share Posted June 22, 2014 it's not a submesh though. it's loaded independently through a separate import mesh commandvar Prt_f01_Rag2_bro_mtree_a_04_inst = 0; BABYLON.SceneLoader.ImportMesh("", "../Models/Maps/", "Rag2_bro_mtree_a_04.babylon", scene, function(mapZone, particleSystems, skeletons) { mapZone[0].scaling = new BABYLON.Vector3(0.001, 0.001, 0.001); mapZone[0].position = new BABYLON.Vector3(0, -10000, 0); mapZone[0].Visible=false; mapZone[0].Name = "Prt_f01_Rag2_bro_mtree_a_04"; } ); Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted June 22, 2014 Share Posted June 22, 2014 As far as it being a sub mesh, sub meshes is a member of each mesh, where 0 is essentially the whole mesh. At the scene level, meshes are all meshes. That does not mean that there being 2 meshes in the scene might not be a clue. ImportMesh is defined: ImportMesh: function (meshesNames, rootUrl, sceneFilename, scene, onsuccess, progressCallBack, onerror) { You specify "" for the mesh, which loads 2 meshes from the file. Then in on success() you try to rename the first one[0]. Your picture shows you expanding [1]. Do you really want all of the meshes? When I have called ImportMesh, I gave it a specific mesh in the first arg. Not saying what you did is wrong, but it is not working & playing with it is probably your best chance to get it to "blink". I would try importing it by its blender name specifically rather than "", and try to instance it by the blender name. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted June 22, 2014 Share Posted June 22, 2014 Me this is what I see on your console image. meshes [1] is not your complete object. getMeshByName rechercheras the object on meshes [0] which is model complete. What do you have in the index 0 on name? Quote Link to comment Share on other sites More sharing options...
Dad72 Posted June 22, 2014 Share Posted June 22, 2014 Oh and I just see in your code: mapZone[0].Name = "Prt_f01_Rag2_bro_mtree_a_04"; Error => Name mapZone[0].name should work better In the console there is a capital letter but I wonder if it not automatic by the console and not what exists in the .json file Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted June 22, 2014 Share Posted June 22, 2014 Yea, the caps looks like the issue. Looking a your JS you probably need to break out the replaceAll() for all those Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted June 22, 2014 Share Posted June 22, 2014 Visibility is also not capitalized in AbstractMesh Quote Link to comment Share on other sites More sharing options...
reddozen Posted June 22, 2014 Author Share Posted June 22, 2014 I'll change that in my file creator.. just a sec. Quote Link to comment Share on other sites More sharing options...
binyan Posted June 22, 2014 Share Posted June 22, 2014 To avoid the caps issues move to TypeScript gwenael 1 Quote Link to comment Share on other sites More sharing options...
reddozen Posted June 22, 2014 Author Share Posted June 22, 2014 I'm not writing my general javascript in TypeScript, sorry. Also, this script is dynamically generated from my server engine based on item locations. Looks like I'm running into timing issues now. I'll add a scene.executeWhenReady()... Quote Link to comment Share on other sites More sharing options...
reddozen Posted June 23, 2014 Author Share Posted June 23, 2014 I got the basics worked out. Seems like I have a race condition. How can I make sure that all the files have loaded before I start instancing them? I tried using scene.executeWhenReady() but it seems to skip over it. Maybe that has to do with it being a loaded in function file. I guess I can do some setimeout conditions, but I would hate to do that... I would rather have some way of checking the scene to see that everything requested to load has loaded. Quote Link to comment Share on other sites More sharing options...
reddozen Posted June 24, 2014 Author Share Posted June 24, 2014 Sooo...Looks like you're forced to instance / clone all your objects from within the importMesh function. Trying to reference them from outside this function can cause race conditions. I'm not really sure how this is possible since javascript is a single threaded scripting language...but it's happening. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted June 24, 2014 Share Posted June 24, 2014 Sooo...Looks like you're forced to instance / clone all your objects from within the importMesh function. Trying to reference them from outside this function can cause race conditions. I'm not really sure how this is possible since javascript is a single threaded scripting language...but it's happening.Probably because importMesh is doing async file I/O. That why there all those callback entry points. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted June 24, 2014 Share Posted June 24, 2014 In jquery I use: $.ajaxSetup({ async: false}); I do not know if something like this exists in babylon. Quote Link to comment Share on other sites More sharing options...
reddozen Posted June 24, 2014 Author Share Posted June 24, 2014 It's fine if it's async.. no big deal there, but we need a way to call back and schedule things that work with the file to avoid race conditions if that makes sense. 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.