Jump to content

method for parsing several contiguous meshes in a single obj


phaselock
 Share

Recommended Posts

Hi, I thought I would ask before coding functions for which I'm not certain babylon.js already supports.

Is there a ready method that can take a single obj/mesh that consists of several contiguous meshes and parse the contiguous meshes into, say, an array ? I have attached an example of a hex tile terrain (see attached) exported from blender which consists of 50 hex tiles. If possible, I'd like to simply pass the hex terrain data and obtain all the 50 hex tiles in an array. Which I can then use mouse triggers on and so forth.

I have read the doc and done some testing but cannot seem to get the behaviour I wanted with subMeshes. Does another method/function exists that can do the job? Or do I have to code my own by parsing the babylon file ?

test_scene.jpg

Link to comment
Share on other sites

@phaselock : Hi and welcome to the forum. :)

3 hours ago, phaselock said:

I have attached an example of a hex tile terrain (see attached) exported from blender

Well here are a couple of ways you might get your tiles. I'm using an example of six meshes - 5 "rocks" and a cube exported from Blender. The white cube, which you can just under the rock at the centre, is the parent to the five rocks (for the animation). But if your tiles have no parent and there are no other meshes to confuse the issue then :

PlayGround 1

The important lines are 27-35. The "action" I take on these meshes is to print out each mesh name to the browser console (line 34) you can add one or more lines of code to set your tile properties.

 

Now if you have other meshes beside the "tiles", in Blender you can create a parent just for the tile meshes.  I created a cube but you can use an "empty". Then when the file loads into BJS get that parent mesh (in my case the cube)  and then get its children (line 25 - 39). Again replace the line (37)where I print out the mesh name with your code to set the mesh properties.

PlayGround2

Others may have different ways - I tend to use these.

Hope that helps.

cheers, gryff :)

Link to comment
Share on other sites

@gryff Hey, thanks for the quick reply and welcome. I've checked both pgs and I think there might be some confusion as you have multiple distinct scene meshes. I'm not certain how to repro my case in pg (can I upload my file to babylon server ?) so I've attached the babylon file here instead. My problem here is that there is only 1 mesh and therefore only 1 name (terrain), and a whole list of vertices and indices corresponding to the 50 hex tiles. The hex tiles are not connected as a single contiguous mesh. I created them quickly via the array modifier in blender.

Ideally, I'd like to, say, mouseover the terrain and the corresponding hex tile below the cursor could highlight/change material etc. Which would mean that the code would need to parse the terrain mesh and obtain say hex[49] submeshes? In the actual application, the number of hex tiles could be anywhere between 200-500? and each individual hex tile might have different heights etc.

terrain.babylon

Link to comment
Share on other sites

@phaselock : I don't know if you are still interested in using Blender but here is an example I created using Blender and some  simple javascript code (I'm not a very good coder :o) :

Hexagons1

Using the array modifier is going to create a single mesh  (as you found),  so I used Blender's particle system to layout the hexagons on a plane. Then I "baked" out the meshes as instances.-  so they all have the same material

In the javascript code I then replaced some of the instances with new instances with a different material, then repeated this procedure by creating more new instances with another new material taking care not to overwrite the instances from the first replacement.

It works fine.

There are 4 drawcalls - three for the tree groups of hexagons and one for a tiny cube that is used as the target for the arcRotate camera (look underneath the hexagons).

cheers, gryff :)

 

Link to comment
Share on other sites

On 8/7/2017 at 1:13 AM, Temechon said:

You can try to have one SPS per texture (that's what I did on my map with 3 different ground levels)

Hey @Temechon, thanks for the advice. At the moment, I do not think terrain type mesh creation with SPS is part of my workflow atm, maybe you can understand better in the below ss. I'll keep in mind tho.

 

On 8/7/2017 at 5:34 AM, gryff said:

@phaselock : I don't know if you are still interested in using Blender but here is an example I created using Blender and some  simple javascript code (I'm not a very good coder :o) :

...

@gryff, hey this is a nice effort, thanks ! Yes, my workflow is still Blender to babylon. I didn't clone or make new instances but took a different direction, as my below ss shows. I made a slightly more randomized untextured terrain in blender which could easily use 4/5 different textures. Then I parented a few empties to some of the hex tiles (just for testing purposes) and wrote some code in babylon with scene.pick to find the empties position corresponding to a mouse click. The yellow highlight is a temp disc mesh that will match to empty position when said tile is clicked (will replace with dynamic texture in future). By my estimates, this is memory and computation wise more efficient. No mesh cloning or instances needed and still scalable.  The largest memory overhead would be from the getVerticesData call of the imported mesh (would be nice if I could just grab part of the data instead of the whole array). I will need to prolly load a denser mesh and do some profiling to know for sure.

Right now, having problems getting it to trigger for mouse moves instead of working with clicks...hrm...

Still thanks to everyone for the many advice and help. The current approach is somewhat different from the OP, I'm not sure if this Q&A is still relevant tho. Hope it helps, cheers.

test_scene1.jpg

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