How to create an empty mesh for parenting

Recommended Posts

I need to parent an object so that I can rotate the child to the proper angle and then move the parent. Right now, I'm creating a new sphere object and assigning a transparency of 0 for the material. If I simply try to create a new Mesh() object without adding geometry/material, the engine/renderer kicks back an error.

Share this post

Link to post

Share on other sites

You can just set the .isVisible property to false if you dont want to render it. Meaning you would't have to give the mesh a material.

mesh.isVisible = false;

That worked perfectly, thanks Merfoo

I had looked at that initially, and I should have just tried it, but my assumption was that if you set the parent visibility to false, then the children would also be invisible. Maybe setEnabled() would give you that result?

Not to create a sub topic, but I wonder what "visiblity:number" deals with

Thanks for all your help Gwenael - the pivot matrix would make sense, but in a scene with multiple items that have to rotate relative to a common pivot/parent, what would be the best approach? If I used a pivot matrix approach, i would have to rotate all objects that were "parented" or using the same matrix. If I just use a parent mesh and add those objects to the parent, all I have to do is rotated/translate the parent.

Behind the scenes, I realize the engine is traversing the child nodes and essentially doing the work for me, but from a code standpoint, it's much easier to read and understand for everyone involved I would think

I really like that - especially if it's more streamline than having an empty mesh as a parent/pivot.

I would love to see this concept flushed out. How would this concept work if you wanted the commonPivot parented? It'd be nice too of you could just pass the mesh and have it store the matrix of the child node based on where it's current matrix.

Share this post

Link to post

Share on other sites

You know though, in saying that out loud, I think it would make more sense to streamline BABYLON.Mesh or BABYLON.Node to act like this new pivot since all the things I listed above are already supported.

Share this post

Link to post

Share on other sites

That's pretty much what I suggest in the discussion I refer to in my first answer. Transform node would be nodes that can be parent of meshes, cameras, lights and other transform nodes. Actually only this kind of nodes (transform) should be used for parenting. Meshes wouldn't store transforms info, they would only store geometry. Once I have time I will work on it

Share this post

Link to post

Share on other sites

Beware here, I would like to keep babylon.js easy to use and if for creating a mesh you need to create a node and call setGeometry this will be too much for beginner. I do not want to reproduce 3js model (excellent though but I prefer keeping things simple)

Share this post

Link to post

Share on other sites

I couldn't agree with you more Deltakosh - In other engines ranging from PV3D, to Unity3D to Three.js, the paradigm has been to create a new Object3D/GameObject for parenting/pivot changes/rotating local vs world etc.

I think that using a new Mesh object and making that work would be the easiest entry point for people coming in, especially if they have experience with other 3D API's. Using setPivotMatrix, though I understand the concept and can appreciate it, is very high level in that it assumes the user knows how to deal with matrix values by hand - and most of us don't, that's why we lean on a 3D api.

Share this post

Link to post

Share on other sites

Having transformation-typed nodes would indeed be much cleaner than parenting with non-visible meshes. But I think you can also leave transformation info within the Mesh Node. I feel like it would be simpler if every Node in the scene tree had a transformation Matrix, then you just have to recursively multiply them to find the world matrix, regardless of the type of the parent.

Share this post

Link to post

Share on other sites

I'm back on BabylonJS unfortunately not for long for the moment. I'll keep in mind SIMPLICITY for all stuff I could do for BabylonJS since I think it's a good approach. I'll try to always have for a function a default mode and an expert mode (more parameters or override of a default value...)