Jump to content

Babylon.js, Blender and Instancing Possibilities


gryff
 Share

Recommended Posts

Here is a sample where this feature rocks

 

Throws a lot of errors in my web console (around 85) and all look like this:

Error: http://www.babylonjs.com/experiments/instances/Babylon/Math/babylon.math.js is being assigned a //# sourceMappingURL, but already has oneError: http://www.babylonjs.com/experiments/instances/Babylon/Tools/babylon.tools.tga.js is being assigned a //# sourceMappingURL, but already has oneError: http://www.babylonjs.com/experiments/instances/Babylon/Tools/babylon.tools.dds.js is being assigned a //# sourceMappingURL, but already has oneError: http://www.babylonjs.com/experiments/instances/Babylon/Tools/babylon.smartArray.js is being assigned a //# sourceMappingURL, but already has oneError: http://www.babylonjs.com/experiments/instances/Babylon/Tools/babylon.tools.js is being assigned a //# sourceMappingURL, but already has one....

all the same comment but with a different script.

 

Not sure why - but I do see a scene - hopefully all of it.

 

cheers, gryff :)

Link to comment
Share on other sites

I've been running some more tests to explore instancing. As I understand it the instances are copies of original geometry including the materials. In the image below (Blender screenshot) I have produced three linked duplicates of an object (the original is left most scaled red cube). I set the original object babylon property to "check collisions" and in Blender this cascades to the linked duplicates - a copy, Cube.001, highlighted in yellow, automatically has check collisions checked.

Here is the babylon code for that original object and the instances - all seemed fine:

{"name":"Cube","id":"Cube","materialId":"cube",

"position":[-5.0000,0.0000,0.0000],"rotation":[-0.0000,-0.0000,0.0000],"scaling":[1.0000,1.0000,1.0000],"isVisible":true,"isEnabled":true,"useFlatShading":true,"checkCollisions":true,"billboardMode":0,"receiveShadows":false,

"positions":[-0.1000,2.0000,1.0000,-0.1000,0.0000,-1.0000,-0.1000,2.0000,-1.0000,0.1000,2.0000,1.0000,-0.1000,0.0000,1.0000,0.1000,2.0000,-1.0000,0.1000,0.0000,1.0000,0.1000,0.0000,-1.0000]

,"normals":[-0.5773,0.5773,0.5773,-0.5773,-0.5773,-0.5773,-0.5773,0.5773,-0.5773,0.5773,0.5773,0.5773,-0.5773,-0.5773,0.5773,0.5773,0.5773,-0.5773,0.5773,-0.5773,0.5773,0.5773,-0.5773,-0.5773]

,"indices":[0,1,2,0,3,4,3,5,6,5,2,7,1,4,7,5,3,2,4,1,0,3,6,4,5,7,6,2,1,7,4,6,7,3,0,2]

,"subMeshes":[{"materialIndex":0,"verticesStart":0,"verticesCount":8,"indexStart":0,"indexCount":36}],

"instances":[

{"name":"Cube.003","position":[0.0000,0.0000,-5.0000],"rotation":[-0.0000,-1.5708,0.0000],"scaling":[1.0000,1.0000,1.0000]},

{"name":"Cube.002","position":[0.0000,0.0000,5.0000],"rotation":[-0.0000,-1.5708,0.0000],"scaling":[1.0000,1.0000,1.0000]},

{"name":"Cube.001","position":[5.0000,0.0000,0.0000],"rotation":[-0.0000,-0.0000,0.0000],"scaling":[1.0000,1.0000,1.0000]}]

}

Only problem is that "check collisions" is true for only the original object not copies. If you are creating a forest (for example), it seems that all the "check collisions" would have to be set to true in code after the trees are loaded as the check collision checkbox in Blender for the linked duplicates is ignored.

Any easy solution for this?

No idea whether this will post as all the formating options are greyed out :(

cheers, gryff :)

post-7026-0-85746000-1402329935.jpg

Link to comment
Share on other sites

and here comes the question: up to where an instance should be a perfect copy of a mesh? Do they share all properties (or the properties at least are synced) (physices, geometry...) except transform or some of them could/must be overriden?

Link to comment
Share on other sites

"I will fix this for you"

Thanks DK :)

 

"up to where an instance should be a perfect copy of a mesh?"

 

All I was trying to do gwenael was try to ensure that the  babylon parameters (flat shading, check collisions etc) for export that could be set in the Blender were transferred to the babylon file. It does not export any animations that are attached to the original object that was duplicated for the duplicates - but those are not mentioned in the exporter parameters, so a work around would have to be found.

 

I don't want to create work for DK (although he did ask further up this thread what features I might like to see for the Blender exporter - and I have a couple of those :o )

 

cheers, gryff :)

Link to comment
Share on other sites

Well a quick experiment, after I walked the dog, I can change the material on the original and it cascades to the duplicates. But altering the "checkCollisions" only impacts the original. I was kind of hoping that would cascade too without having to loop through all the copies.

 

cheers, gryff :)

Link to comment
Share on other sites

Blender also has a use flat shading & cast shadows custom properties

 

JC the "flat shading" is a property of the material - Scrap that JC it is "back face culling" that is a material property and any changes to the material seem to propagate.. I tried a test with the alpha value of material with this kind of code:

theColour = newScene.getMaterialByName("cube");theColour.alpha = .5;

and it sets all of them.

 

Will test the flat shading. (Edit :tested and it seems to propagate). Not tried the shadow stuff.

 

cheers, gryff :)

Link to comment
Share on other sites

mesh has the method convertToFlatShadedMesh(), not sure where it is called though. 

 

Looking closely at the python script, cast shadows property is used by the script to build the shadow generator for the lamp and does not end up in the mesh itself.  The property is evaluated in the script for every lamp that has the custom shadow map property set.  If it is true, the mesh gets added to the generators renderList. 

 

Implementing this might mean similar checking.

 

Jeff

Link to comment
Share on other sites

Change on checkCollisions is NOT propagated because you may want to set up on somes instances but not all

 

I had a feeling it might be that way. For the situation you hypothesis about, I would create two sets of instances with different checkCollision settings. With propagation I could easily flip their status. So for example nearby trees checkCollisions true, faraway trees checkCollisions false. If you enter that faraway area, flip the checkCollision properties of both.

 

And experimenting with cast shadows - I'm getting some odd results. But more about that after more experiments.

 

cheers, gryff :)

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