Jump to content

Multiple instances of base mesh


ozRocker
 Share

Recommended Posts

I'm building a scene in Unity3D to export to Babylon which is a typical countryside.  It has trees and rocks but to optimise I was going to use the same tree and rock and drop them around the scene in different sizes and directions.  Unfortunately this has no effect when I export to Babylon.js.  Does anyone know the best way I can have one base tree mesh and one base rock mesh in my .babylon file and refer to those for all the duplicates?

Link to comment
Share on other sites

Hi,

 

you could do one of the two - 

either use instances  - an array of instances with their own transformation in each mesh's definition or use the same geometry and material id for each mesh you created. Instances will be better (performance will be much better) if you don't want to change the objects except for transformation.

 

 

you can read about the file format here (couldn't find it on the doc site using the search. Anyone?) - https://github.com/BabylonJS/Babylon.js/wiki/Babylon.js-file-format

Link to comment
Share on other sites

Ok cool, that's exactly what I need. Lots of rocks and trees.  Checking the doco now.  It looks like 3D Max and Blender supports instances for Babylon export but I can't see any mention of it for Unity3D.  Does anyone know if there's a way to specify an instance in Unity3D?

Link to comment
Share on other sites

  • 1 month later...

so it is a clone for babylonjs POV

 

I'm not sure what this means.  Is POV some kind of copy of another mesh?

 

I've been checking out Babylon.js instances and Unity3D prefab instances.  With prefab instances you can add / remove / change components and materials as well as change the transform.  With Babylon.js instances you can only change the transform (position, rotation, scale).  That's still very useful, but I'm wondering if there's a better way to represent prefab instances within Babylon.js so you can also include changes to components and materials.  Is this what POV is?

Link to comment
Share on other sites

DK is just saying that Unity.prefabs = Babylon.clone.

 

Unity prefabs are just clones from a babylon point of view (POV).

 

ah ok.  Can clones be stored in the .babylon file or can they only be created via javascript code during runtime?  I'm just trying to determine whether its possible to store prefab instances as clones within the .babylon file

Link to comment
Share on other sites

I'm trying to find a way that I can have the mesh data appear once within the .babylon file and all instances of that mesh just refer to that set of mesh data.  The only way I can think of doing that is by using BabylonJS instances.  It looks like cloning isn't suitable if it makes another copy of the mesh data.  I thinking of scenes where I'd have 40 trees using the same mesh

Link to comment
Share on other sites

No, clone does that.  Instances must be identical vertices & materials.  They can have skeletons, but I never tried.

 

Cloning saves you memory on cpu & gpu, but you need a separate draw call for each.  Shaders are actually built from materials.  This having the same shader allows for the gpu optimization of instances.  Thus there can never be different materials for instances.

Link to comment
Share on other sites

What would be cool is if there's a way to combine them.  Like have a "clone" defined in the .babylon file which is the same as a mesh but with the vertex data pointing to an existing mesh.  This may not give any gpu optimisation, but my focus here is to reduce file-size.  If I have a mesh of a person with 20,000 polys and I want 5 of them in the scene with different shirt colours this would prevent the file-size from blowing out. 

Link to comment
Share on other sites

You can do the cloning once the "original" is loaded in Javascript, of course.  3 lines really: b= a.clone(); b.material=...; b.position=...;

 

Changing the .babylon format to handle clones would require changes in the loading process, and any exporter that supported it.  Does not seem worth it, when it can still be done afterward.

 

Think you could still achieve the effect of your example, by using instances.  Each instance would have the same color tee shirt. Just put a different decal on the front.  True, Decals I do not believe are exportable, but as they say: "Life is hard, and then you die."

Link to comment
Share on other sites

  • 6 months later...
19 hours ago, exc_html5 said:

Might throw out that I did download the latest exporter, drag a pre-fab into my unity scene, and duplicated it a bunch of times. When I export, the filesize gets pretty big and in the code it looks like it's creating a diff mesh for every duplicate of the pre-fab. (far as I can tell). 

This shouldn't be the case.  I actually implemented the part of the exporter where prefabs get converted to instances because I had scenes with 100 trees and rocks and the exported scenes were simply unusable.  However, on inspection of the GITHub repo I've noticed that all the code I wrote has been removed. 

https://github.com/BabylonJS/Babylon.js/commit/9f9b85108ac709fe132c0af8a8724fb782b319ec

You can see the mention of prefabs in SceneBuilder.cs

So yeh, goodbye instances.

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