Jump to content

How to check object type


MarianG
 Share

Recommended Posts

Hi guys. I have an idiot question, and I have no idea how to deal with it :)
I have a scene where I create meshes, disc or plane like

if(this.metadata.isCircle == true)
	layer = BABYLON.MeshBuilder.CreateDisc("disc", {radius: this.metadata.radius, tessellation: 64, sideOrientation: BABYLON.Mesh.DOUBLESIDE}, this.scene);
else	
	layer = BABYLON.MeshBuilder.CreatePlane("plane", {height: this.metadata.depth, width: this.metadata.width, sideOrientation: BABYLON.Mesh.DOUBLESIDE}, this.scene);

After that I export them and use in other scene.
How to check on the other scene if loaded mesh is a disc or a plane?
1. I export them as babylonjs file, add a metadata something like "isCircle" and on load check metadata, great! - no problems.

2. I export them as obj file, here comes the problem. As obj doesn't keep the name, doesn't keep the metadata, so I have to check myself someway if loaded mesh is a disc or a plane.
Is there something internal to know if loaded/created mesh (basic elements) is a disc, a plane, a box, or etc?
 

Link to comment
Share on other sites

Hi MG!  Not idiot AT ALL.  Really, a darned good question.

Obj format doesn't keep mesh name?  Are you sure? 

https://en.wikipedia.org/wiki/Wavefront_.obj_file

Named objects and polygon groups are specified via the following tags.

o [object name]
  ...
  g [group name]
  ...

I don't know what you are exporting to/from (what creates the .obj file)... but I think you are being cheated, somehow.  :)

Sometimes... all a mesh HAS... is its good name.  ;)

Can you tell us more about this name-excluding .obj exporter?  Who built that thing?  Do we need to have a little talk with someone?  heh

Link to comment
Share on other sites

I'm using babylonjs objExporter.

But you give me an idea.

I found where it override mesh name, and I modified it to take the name from mesh, by default it change meshes name :(
https://github.com/BabylonJS/Babylon.js/blob/5b36a24a55f5f572d0e28d3a7b1c9c521dc6701f/dist/serializers/babylonjs.serializers.js#LC38
It works well. Thanks @Wingnut.


Another question regarding on this. Why on import I get 2 different meshes foreach mesh? I mean I save an array with 5 meshes as obj, and when I import it in the other scene I have 10 meshes in the succes function?

Link to comment
Share on other sites

@Wingnut you are "grande". :D
Thanks to your previous post I found the answer to the second question too. 
Again, by default, the exporter create a group and a object foreach mesh that you want to export, I just comment 

output.push("g object" + j);

from exporter and I have only my meshes.
And I modified export.mtl to support material foreach mesh in the same mtl file, by default it create different mtl foreach mesh. 

Btw, I see these minor changes usefull, maybe they can be used by default on exporter, and a few flags like "useGroup" for group meshes and "useSameMtl" for using the same mtl for all meshes. 

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