Jump to content

How to create an empty mesh for parenting


neoRiley
 Share

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.

 

What' the proper method for doing this?

 

Thanks for your help

Link to comment
Share on other sites

If by creating an empty mesh, you mean "create a mesh without geometry (vertices)", I'm not sure it's possible and you may be interested by the following discussion: http://www.html5gamedevs.com/topic/2796-discussion-about-nodes-meshes-instances/

 

Your problem seems to be "how to rotate a mesh to the proper angle and then move it" and "parenting it to an empty mesh" could be a solution. You can try to set a pivot matrix. http://jsfiddle.net/gwenaelhagenmuller/24mBJ/1/

Link to comment
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 

Link to comment
Share on other sites

If by creating an empty mesh, you mean "create a mesh without geometry (vertices)", I'm not sure it's possible and you may be interested by the following discussion: http://www.html5gamedevs.com/topic/2796-discussion-about-nodes-meshes-instances/

 

Your problem seems to be "how to rotate a mesh to the proper angle and then move it" and "parenting it to an empty mesh" could be a solution. You can try to set a pivot matrix. http://jsfiddle.net/gwenaelhagenmuller/24mBJ/1/

 

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

 

maybe I'm missing a feature that makes this not true?

Link to comment
Share on other sites

For sure it's easier to have a parent if you have multiple meshes that have to rotate relative to a common pivot/parent, nevertheless you can add a class to handle this differently.

Here's a start for this class (BABYLON.CommonPivot)

 

http://jsfiddle.net/gwenaelhagenmuller/2fA92/

 

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.

Link to comment
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

Link to comment
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.

Link to comment
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.

 

Anyway, looking forward to the pull request !

Link to comment
Share on other sites

  • 2 weeks later...

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