ozRocker Posted October 27, 2015 Share Posted October 27, 2015 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? Quote Link to comment Share on other sites More sharing options...
RaananW Posted October 27, 2015 Share Posted October 27, 2015 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 Quote Link to comment Share on other sites More sharing options...
ozRocker Posted October 27, 2015 Author Share Posted October 27, 2015 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? Quote Link to comment Share on other sites More sharing options...
RaananW Posted October 27, 2015 Share Posted October 27, 2015 yep, that would be my next question :-) I know Blender exports instances, I can't see why unity wouldn't. But I never used the unity exporter (not a big unity user), I hope someone can help with that! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 27, 2015 Share Posted October 27, 2015 Doc link: http://doc.babylonjs.com/generals/File_Format_Map_(.babylon) Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 27, 2015 Share Posted October 27, 2015 Unity 3D does not support instances extraction for now (But if you are a c# developer that should be easy to add) Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 27, 2015 Share Posted October 27, 2015 question: How do you create instances in Unity? Quote Link to comment Share on other sites More sharing options...
Temechon Posted October 27, 2015 Share Posted October 27, 2015 I think Unity has a concept of Prefabs, but no instances. I might be wrong though. Quote Link to comment Share on other sites More sharing options...
ozRocker Posted October 27, 2015 Author Share Posted October 27, 2015 Yeh, they use prefabs http://docs.unity3d.com/ScriptReference/PrefabUtility.html Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 28, 2015 Share Posted October 28, 2015 But is it like instances? You cannot use different materials? Quote Link to comment Share on other sites More sharing options...
ozRocker Posted October 28, 2015 Author Share Posted October 28, 2015 You can change its materials and it still retains its connection to the prefab Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 28, 2015 Share Posted October 28, 2015 so it is a clone for babylonjs POV Quote Link to comment Share on other sites More sharing options...
ozRocker Posted December 2, 2015 Author Share Posted December 2, 2015 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? Quote Link to comment Share on other sites More sharing options...
Temechon Posted December 2, 2015 Share Posted December 2, 2015 DK is just saying that Unity.prefabs = Babylon.clone. Unity prefabs are just clones from a babylon point of view (POV). Quote Link to comment Share on other sites More sharing options...
ozRocker Posted December 2, 2015 Author Share Posted December 2, 2015 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 Quote Link to comment Share on other sites More sharing options...
Temechon Posted December 2, 2015 Share Posted December 2, 2015 I think that clones are stored in the babylon file, but as standard meshes, so when you reload the scene, it's not clones anymore. Quote Link to comment Share on other sites More sharing options...
ozRocker Posted December 2, 2015 Author Share Posted December 2, 2015 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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 2, 2015 Share Posted December 2, 2015 Yep in this case Instances are perfect Quote Link to comment Share on other sites More sharing options...
ozRocker Posted December 2, 2015 Author Share Posted December 2, 2015 ok cool, I will use instances. Do you think there's any way I can assign different materials to different instances? I know they currently don't support that, but I thought maybe there could be a workaround Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted December 3, 2015 Share Posted December 3, 2015 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. Quote Link to comment Share on other sites More sharing options...
ozRocker Posted December 3, 2015 Author Share Posted December 3, 2015 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. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted December 3, 2015 Share Posted December 3, 2015 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." Quote Link to comment Share on other sites More sharing options...
exc_html5 Posted June 12, 2016 Share Posted June 12, 2016 Hi everyone, was following this thread as I was about to create a scene in Unity and was hoping there was a way to designate objects as instances or clones upon export. @Deltakosh, is the Unity exporter still exporting a mesh for every object even if they are all using the same pre-fab? Quote Link to comment Share on other sites More sharing options...
exc_html5 Posted June 12, 2016 Share Posted June 12, 2016 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). hackSolo 1 Quote Link to comment Share on other sites More sharing options...
ozRocker Posted June 13, 2016 Author Share Posted June 13, 2016 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. 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.