Jump to content

Babylon.js, Blender and Instancing Possibilities


gryff
 Share

Recommended Posts

DK asked about Blender and Instancing so here is an initial possibility. See the image below that contains 3 cubes. The highlighted in yellow cube is the original cube (appears white in the red box.) The other two are duplicates created from the object menu using "Duplicate Linked" (highlighted in blue). These added cubes (Cube.001 and Cube.002 in the red box) share the same mesh data.

 

To check this change the Blender mode from "Object" to "Edit" (green box). You should see one vertex highlighted on each box - move it - the changes propagate through all the boxes as they are sharing mesh data.

 

Right click on any other vertex to change a different one.

 

All you need is to have the babylon exporter recognise how the duplicate additional cubes were produced - maybe a box in the mesh babylon properties saying "Use" then a pick mesh option?

 

The sample file is here (zip format):

 

Cubes

 

Hope that helps - or at least starts a discussion.

 

cheers, gryff :)

 

 

post-7026-0-82151000-1401073383.jpg

Link to comment
Share on other sites

DK, as you know you are getting into an area which is above my paygrade  my javascripting is poor, my python scripting is non-existant. :(

 

However here is a quick thought. If you look in that same menu , just below the "Duplicate Linked" menu item there is another way to duplicate "Duplicate Objects". These objects are not linked.

 

So do the two different types of "Duplicates" end up in the same "dupli_list" array ? Or are there two different arrays for the two types of duplication?

 

cheers, gryff :)

Link to comment
Share on other sites

I will dig into blender to understand how to get these objects

 

Well I searched for info about "dupli_list[]" - could not find anything. So I thought I might play around with Blender and Python - and ended up taking my Python knowledge from "non-existant" to very very tiny :D

 

Image 1 below shows my Blender layout - the 3D window with 3 cubes I created with the "Duplicate Linked" method I showed above, a camera and a light. The Cubes I renamed to Box, Box.001, Box002. Beside that window is a text editor in which I developed a little script. Clicking on the "Run Script" button - er .. runs the script.

 

Image 2 shows the output from the script with names and data. I have no idea what "<..... MeshVertex at ..... >" means but is the same data for Box and the duplicates. Also note that it finds the original Box last.

 

if you want to play with it, he zip of blend file is here: Instance2.zip . One note, if you want to see the output you have to go to the menu at top left, click Window->toggle console.

 

Not sure how useful it is to DK in getting an object and its duplicates for several reasons:

a.) you have to know the name of the original mesh

b.)it will also run and detect duplicates that were created with "Duplicate Objects" (as opposed to "Duplicate Linked") and these will return all different values for <..... MeshVertex at ..... > as the meshes are not instances.

 

Anyway I had some fun and frustration.  The python syntax is quite different from javascript - no ";" and more ":" and fewer brackets (look at the for loops and if statements) and indentation is important.

 

cheers, gryff :)

 

 

 

 

 

post-7026-0-46376200-1401237605.jpg

post-7026-0-82729100-1401237677.jpg

Link to comment
Share on other sites

And just to complete the picture The output from three cubes - an original plus two duplicates created with the "Duplicate Object" method (so they do not share the same mesh) Image below.

 

Note that each cube has a different set of eight "<..... MeshVertex at ..... >" values.

 

cheers, gryff :)

 

 

post-7026-0-51127800-1401255319.jpg

Link to comment
Share on other sites

yes but with a slightly difference clone generate a new mesh that share the geometry with the root one. You can have different materials on a clone and its root

 

Instances are extremely efficient BUT you have to share the same material

 

I can redo my system of herbs with ca and forests.
 
How are multiplying objects? 
 
var instance = mesh.createInstance("grass");
 
but afterwards, it does what to create many objects in this instance?
Link to comment
Share on other sites

The demo is still work in progress :)

 

Well in the meantime here is my quick and dirty demo:

 

The Stones

 

Not quite Stonehenge I must admit :D

 

The babylon file is tiny - 5.7Kb. (Edit: If the stones were created by the standard "Duplicate Objects" method file size is - 27kb)

 

And here are the instances in the babylon file - all using the mesh of the original rock:

"instances":[{"name":"rock.007","position":[-0.2382,0.0581,-1.7651],"rotation":[-0.0000,-0.0000,-1.5078],"scaling":[1.0000,1.0000,1.0000]},{"name":"rock.006","position":[0.4014,1.0423,1.9312],"rotation":[-0.5137,-0.0327,-1.4143],"scaling":[1.0000,1.0000,1.0000]},{"name":"rock.005","position":[-1.4722,1.1497,0.9832],"rotation":[-1.5708,0.3621,0.0000],"scaling":[1.0000,1.0000,0.5000]},{"name":"rock.004","position":[1.3625,0.0000,1.4692],"rotation":[-0.0000,-0.0000,0.0000],"scaling":[1.0000,1.0000,1.0000]},{"name":"rock.003","position":[0.4623,0.0000,1.8217],"rotation":[-0.0000,-0.0000,0.0000],"scaling":[1.0000,1.0000,1.0000]},{"name":"rock.002","position":[-1.4470,0.0000,0.9078],"rotation":[-0.0000,-0.0000,0.0000],"scaling":[1.0000,1.0000,1.0000]},{"name":"rock.001","position":[1.9053,-0.1817,0.0000],"rotation":[-0.4895,-0.1566,-0.3010],"scaling":[1.0000,1.0000,1.0000]}]

Looks like you have cracked it DK :)

 

cheers, gryff :)

Link to comment
Share on other sites

I've updated "The Stones" - still not Stonehenge, but not so quick and dirty. Added a terrain and textures.

 

While the instancing file coming out of blender is very much smaller, what I'm  curious to know is how more efficient the whole process is in terms of WebGL?

 

Does it really matter in my little example where all the stones are in full view and those vertices and faces still have to be drawn - and why?

 

cheers, gryff :)

Link to comment
Share on other sites

gryff,

In your situation it probably wouldn't matter as much. It's more for big scenes with a lot of little stuff, or things that repeat a lot. It doesn't limit what the GPU has to process so much as it frees up the CPU from having to feed additional triangles to the GPU per render frame. So it frees up your CPU operations to work on other things like AI, Physics, etc.

 

Here's some info about it: http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter03.html

Submitting triangles to the GPU for rendering in Direct3D is a relatively slow operation. Wloka 2003 shows that a 1 GHz CPU can render only around 10,000 to 40,000 batches per second in Direct3D. On a more modern CPU, we can expect this number to be between 30,000 and 120,000 batches per second (around 1,000 to 4,000 batches per frame at 30 frames/sec). That's not much! It means that if we want to render a forest of trees, and we submit one tree per batch, we cannot render more than 4,000 trees, regardless of how many polygons are in a tree—with no CPU time left for the rest of the game.

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