gryff Posted May 26, 2014 Share Posted May 26, 2014 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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 26, 2014 Share Posted May 26, 2014 That is perfect!!!! I will use it as sample for babylon.js instances support Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 26, 2014 Share Posted May 26, 2014 When I do that, I cannot get the list of duplicate from the root object:>>> bpy.data.objects['Cube'].dupli_list[0]Traceback (most recent call last): File "<blender_console>", line 1, in <module>IndexError: bpy_prop_collection[index]: index 0 out of range, size 0 Quote Link to comment Share on other sites More sharing options...
gryff Posted May 26, 2014 Author Share Posted May 26, 2014 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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 26, 2014 Share Posted May 26, 2014 I have no idea I will dig into blender to understand how to get these objects Quote Link to comment Share on other sites More sharing options...
gwenael Posted May 27, 2014 Share Posted May 27, 2014 Instances Quote Link to comment Share on other sites More sharing options...
gryff Posted May 28, 2014 Author Share Posted May 28, 2014 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 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 meshb.)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 Quote Link to comment Share on other sites More sharing options...
gryff Posted May 28, 2014 Author Share Posted May 28, 2014 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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 28, 2014 Share Posted May 28, 2014 From the point of view of the exporter, I need to be able to get all duplicates from the root node Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 4, 2014 Share Posted June 4, 2014 Hey Gryff, sounds like I found a way:https://github.com/BabylonJS/Babylon.js/wiki/How-to-use-instances Please give me your feedback And BTW do you know features we have in Babylon.js that could be easily exported from blender? Quote Link to comment Share on other sites More sharing options...
gryff Posted June 4, 2014 Author Share Posted June 4, 2014 DK, I followed the link to the github page then tried to view the "Demo" Looked through the "Features Tests" - could not see a demo. cheers, gryff Quote Link to comment Share on other sites More sharing options...
Dad72 Posted June 4, 2014 Share Posted June 4, 2014 The Instances works like mesh.clone() if I understand everything. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 4, 2014 Share Posted June 4, 2014 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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 4, 2014 Share Posted June 4, 2014 The demo is still work in progress Quote Link to comment Share on other sites More sharing options...
Dad72 Posted June 4, 2014 Share Posted June 4, 2014 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? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 4, 2014 Share Posted June 4, 2014 for (var i = 0; i < 100; i++) {var instance = mesh.createInstance("grass" + i);}That simple Quote Link to comment Share on other sites More sharing options...
Dad72 Posted June 5, 2014 Share Posted June 5, 2014 Oh yes, this cannot be simpler. Quote Link to comment Share on other sites More sharing options...
gryff Posted June 5, 2014 Author Share Posted June 5, 2014 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 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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 5, 2014 Share Posted June 5, 2014 Love it Quote Link to comment Share on other sites More sharing options...
reddozen Posted June 5, 2014 Share Posted June 5, 2014 So is the function mesh.createInstance("<name>"); where mesh is the parent, and name is the new name of the instance? Quote Link to comment Share on other sites More sharing options...
gryff Posted June 5, 2014 Author Share Posted June 5, 2014 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 Quote Link to comment Share on other sites More sharing options...
reddozen Posted June 5, 2014 Share Posted June 5, 2014 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.htmlSubmitting 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 5, 2014 Share Posted June 5, 2014 Here is a sample where this feature rocks http://www.babylonjs.com/experiments/instances/ gwenael 1 Quote Link to comment Share on other sites More sharing options...
Kilombo Posted June 5, 2014 Share Posted June 5, 2014 Man..... That's really a great feature I have to try it. Quote Link to comment Share on other sites More sharing options...
gwenael Posted June 6, 2014 Share Posted June 6, 2014 Here is a sample where this feature rocks http://www.babylonjs.com/experiments/instances/ I got my forest sample Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.