Jump to content

getMeshByName NULL Object


reddozen
 Share

Recommended Posts

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?

 

post-5217-0-79302100-1403461933.png

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

it's not a submesh though. it's loaded independently through a separate import mesh command

var 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";		}	); 
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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()...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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