Search Unity

Mesh Baker LOD [RELEASED]

Discussion in 'Assets and Asset Store' started by Phong, Nov 1, 2013.

  1. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I remember working with a user batching trees from a long time ago. There is a forum thread hear that talks about batching trees. http://forum.unity3d.com/threads/batching-trees-and-speed-up-rendering.138929/. Much of this applies to Mesh Baker. There is also this page which has some specific info about baking Tree Creator trees with Mesh Baker http://www.digitalopus.ca/site/faqs/tips-for-using-mesh-baker-with-unity-tree-creator-trees/.

    I think when I tried this before I had to use a shader for the trunk that was not affected by wind and a separate shader for the leaves that was. This is not a perfect solution as the branches don't sway. Unfortunately I believe the default unity bark shader assumes that every tree has its local root at 0,0,0 which is not true for batched trees.
     
  2. sowatnow

    sowatnow

    Joined:
    Jun 12, 2014
    Posts:
    309
    [QUOTE="Phong, post: 1875232, member: 18029"

    ]I remember working with a user batching trees from a long time ago. There is a forum thread hear that talks about batching trees. http://forum.unity3d.com/threads/batching-trees-and-speed-up-rendering.138929/. Much of this applies to Mesh Baker. There is also this page which has some specific info about baking Tree Creator trees with Mesh Baker http://www.digitalopus.ca/site/faqs/tips-for-using-mesh-baker-with-unity-tree-creator-trees/.

    I think when I tried this before I had to use a shader for the trunk that was not affected by wind and a separate shader for the leaves that was. This is not a perfect solution as the branches don't sway. Unfortunately I believe the default unity bark shader assumes that every tree has its local root at 0,0,0 which is not true for batched trees.[/QUOTE]


    Ok cool, will try that method.
    I am using this mobile foliager shader, and seems to be not working. Everything moves around, trunk is not holding onto its base origin point.

    https://www.assetstore.unity3d.com/en/#!/content/3460

    Edit. I have been trying for the past 2 hrs, no luck with that script/method.
     
    Last edited: Dec 6, 2014
  3. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I will take a look this evening and let you know what I find.
     
  4. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi Sowotnow,

    I did get this to work. The wind script works although it doesn't use WindZones. Instead the wind is set through the script variables. The base of the trunks do not move. Not sure why not but I won't complain when something works better than I expected. Here is what I did.

    Created some tree creator trees. Applied "Nature -> Tree Creator Bark" and "Nature -> Tree Creator Leaves" to them.

    Baked them with Mesh Baker using multiple materials. I mapped the bark to one material and the leaves to another material.

    Attached the WindTest script to the child of the Result Scene Object. It needs to be the game object with the Mesh Renderer attached.

    Email me at ian.deane@gmail.com if you want me to send a package of the experimental scene.
     
  5. sowatnow

    sowatnow

    Joined:
    Jun 12, 2014
    Posts:
    309
    Thank you, will try that. I sent you an email regarding the scene you did.
    I don't use tree creator since I have other trees with meshes.
     
    Last edited: Dec 7, 2014
  6. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I sent the package. It uses tree creator trees and textures so you will probably need to import tree creator to get it to work. I think the approach I used should work with any shader that uses a _Wind property.
     
  7. sowatnow

    sowatnow

    Joined:
    Jun 12, 2014
    Posts:
    309
    Hi guys,

    I am having some trouble combing two different types of grass meshes, they are both using same material and texture.
    There is no problem when LOD Manager is combining same grass, but If I add another grass mesh, even though its using same material and texture, I get the following error. Any idea why? I have checked the Read/Write Enabled in model. Still no luck. Has anyone experienced this before?


    Edit. Ops I had the Static Option Ticked, that's why i was getting this error. I have unticked it and now its working.

    upload_2014-12-13_18-37-25.png
     
    Last edited: Dec 13, 2014
  8. Ascensi

    Ascensi

    Joined:
    Sep 7, 2013
    Posts:
    579
    I bought Mesh baker a while ago for the Pre Release of Unity 5 but I just tried to install it today and received the following error: Assets/MeshBaker/scripts/Editor/MB3_TextureCombinerEditorFunctions.cs(197,86): error CS0117: `UnityEditor.BuildTarget' does not contain a definition for `FlashPlayer' Is Mesh Baker Unity 5 compatible?
     
  9. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Since Unity 5 is still in pre-release with no release date announced I have not test it yet but am planning on getting to this soon.
     
    JonDadley likes this.
  10. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    A new version of Mesh Baker LOD has been submitted to the Asset Store. The main new feature is a change to the API to allow the world to be translated to avoid floating point precision glitches when the player is far from the origin.
     
  11. JonDadley

    JonDadley

    Joined:
    Sep 2, 2013
    Posts:
    139
    Excellent news :) I'm on the verge of purchasing Mesh Baker LOD for a procedural scene I'm running but it's running in Unity 5 so I'm waiting for support before I purchase it.
     
  12. sowatnow

    sowatnow

    Joined:
    Jun 12, 2014
    Posts:
    309
    Hi again,

    I am using ats foliage shader to with trees. I have lightmapped the trees and using ats vegetation unlit lightmap shader for the leaves. The batching with LOD works fine in the unity editor, I could see the trees properly lightmapped. However, on an adroid device, the trees are not lightmapped.

    Any Idea what i am doing wrong?

    Thanks
     
  13. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hmmm, I will have to give this some thought. This is a very detailed situation. To be honest I am not sure what the problem could be. What version of Unity are you running and for which platform?
     
  14. IFL

    IFL

    Joined:
    Apr 13, 2013
    Posts:
    408
    I was looking back through my old UMA/MBLOD project and realized that I got it to work by doing runtime atlasing and altering meshes. I think that the worst part about MB & MBLOD is the tedious combining/handling of textures. It'd be nice to see a solution that you don't have to do anything more than place a Manager in the scene, set the clustering size, set the desired (very loose) # of batches per shader, set the max combined texture size, and everything just happens at runtime. Of course, that wouldn't be very feasible for non-Pro users, but it would still be amazing. At any rate, MBLOD is one of (out of 129) the best purchases I've ever made from the asset store.

    Cheers
     
  15. sowatnow

    sowatnow

    Joined:
    Jun 12, 2014
    Posts:
    309

    Hi

    I am running unity 4.6 and tested it on android device samsung s5.
     
  16. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    No idea if this will work but try:

    build setting > PC and go Player setting and disable use Directx 11
     
  17. sowatnow

    sowatnow

    Joined:
    Jun 12, 2014
    Posts:
    309
    Tried that already, no luck with that. Anyway thanks.
    For now I have temporarily changed the shaders and removed lightmapped until I get this sorted out.
     
  18. sowatnow

    sowatnow

    Joined:
    Jun 12, 2014
    Posts:
    309
    Hi again,

    I have tested Meshbaker with LOD Baker on android device and encountered the following problems:

    - Application crashes after exploring multiple areas. It works fine with a single area, but as soon I explore different area, the app crashes. I believe this has something to do with the memory and its keeping all previous baked meshes in memory and not freeing up the memory.

    - There is a lag each time a mesh is baked

    In your first post you mentioned that this asset over comes this memory limitation as one would encounter in unity pro.

    Does this asset free up the memory each time a player is outside the required LOD distance and remove the baked mesh from the memory? So this would free up the memory for another batch and improve the performance and also avoid app crashing.

    Or what I am doing wrong?
    My level is not that big, just trees, terrain and couple of buildings with props, and yet it crashes.
     
  19. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Regarding application crashing, are you switching scenes or is it one big scene with multiple areas? If you are switching scenes have you tried Resources.UnloadUnusedAssets() before exiting the scene.

    If there is a lag each time a mesh is baked then the combined meshes are probably too large for the device to bake quickly. Try reducing the size of the combined meshes.

    Yes, when the player is beyond the furthest LOD distance, the combined mesh for that area should end up with zero vertices and triangles.

    Is there anything in the device log just before the crash?
     
  20. sowatnow

    sowatnow

    Joined:
    Jun 12, 2014
    Posts:
    309
    For now I am just using one big scen, and about 90% of is empty, and recently I only added few trees and buildings to it. I am thinking of splitting the scene into multiple scene just to reduce the loading time and also crashes.

    If the combined meshes end up with zero vertices and triangles, does that mean the rendered images loaded are still in memory?

    I can't get log file since my phone is not rooted. The catLog app works with rooted phone only.

    P.S Edit: After playing around with the numbers, it's stable now for at least 5-10 mins, which is good improvement. I have reduced the grid size to 200, cluster size to 12000, num frames between checks to 40 instead of 20, and num bakes between GC calls to 1.
     
    Last edited: Jan 20, 2015
  21. VHornet

    VHornet

    Joined:
    Jul 10, 2012
    Posts:
    48
    Hi, I am using mesh baker and mesh baker LOD in my game, both plugins work great. I set up lod to switch mesh so that animation will continue where it is



    But there is a bug like: when the camera see all the baked meshes, all the animation of character work fine, but if I move the camera to a location where the camera doesn't see those characters and then move the camera back to see them then the animation of character won't work. It would be great to have a clue where to modify/enhance in the code
     
  22. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi Eric,

    Just had a look. Are you using Mecanim or legacy animations? I believe most of the animation stuff is handled by the MB2_LOD.cs component. It has an "anim" field that is Sampled when the mesh is switched you can search the code to see where this happens. Looks like I need to update this to handle Mecanim animations as well as legacy.

    Other that that did you set the culling setting on your animator/animation components to "always animate"?
     
  23. VHornet

    VHornet

    Joined:
    Jul 10, 2012
    Posts:
    48
    I used legacy animation, and yes I did set animation culling to "always animate".
    Another use case where this happen frequently is for example there are a lot of moving character on the scene (I control the movement of character using DOTween/LeanTween/iTween), they are playing animation "Walking", then I enable a 2d element for example a panel inside canvas (Unity 4.6.x new UI) and disable the 3d camera, the panel take the whole screen space, then I enable back the 3d camera and disable the panel, then most of the character (not all, sometimes all) just playing "idle" animation.

    It also good to know if I can dig and modify it by myself or it's something that needs to have a lot of modifications to the current MeshBaker LOD system.
     
  24. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I am puzzled on this one. Would it be possible to send me a reproducible case?

    As far as debugging goes, this problem is not in the more complex parts of mesh baker so you may be able to debug this yourself. If it were me, I would take advantage of the logging system in the MB2_LOD.cs component. There is a field called myLog. Write log statements using something like:

    if (LOG_LEVEL >= MB2_LogLevel.trace) myLog.Log(MB2_LogLevel.trace,this + "Init called",LOG_LEVEL);

    The myLog object caches the last 100 log statements made by this MB2_LOD component. There should be a button in the inspector where you can dump the log to the console if log_level is set to debug or trace for this component. I would set the log level to debug or trace on one of the misbehaving LOD components. Then I would add some lines to the CheckIfLODsNeedToChange function to report the state of the "anim" variable. This setup should tell you exactly when the animation clip switched state. You should be able to dump the log and see what happened just before anim clip switch. You should be able to narrow down what is causing the anim to switch state..
     
  25. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,684
  26. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    This is very likely the problem. I will try to make some time over the weekend to look at this.
     
  27. VHornet

    VHornet

    Joined:
    Jul 10, 2012
    Posts:
    48
    Hi I pm you the test project link.

    Run the "Test" scene in folder "Scenes" and you will see the instruction on how to reproduce the problem.
     
  28. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Thanks, I will take a look today.

    [EDIT] Had a look yesterday. Looks like the animation state is being forgotten when when the GameObject with the animation is disabled. I will work on this today.
     
    Last edited: Apr 7, 2015
  29. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi Ericweiss,

    I had a look and came up with a solution that should get this working although it is not very elegant. I thought I would be able to capture the animation state when LOD 0 is disabled and restore it when it is enabled again. Turns out that doing this with the old Unity Animation API is very nasty as mentioned by hopful. Many, very good devs have tried and failed to solve this problem see this thread:

    http://forum.unity3d.com/threads/animation-api-acts-funny-some-parts-not-documented.20367/

    There is a workaround. Mesh Baker LOD sends a message "LOD_OnSetLODActive" when the LOD0 game object is enabled. You will need to write a script that catches this event and plays the correct animation at that time. Your animation controller should set the animationThatIShouldBePlaying variable on this script whenever the animation changes so it knows what the correct animation is.

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class MyScriptThatStoresAnimState : MonoBehaviour {
    6.  
    7.     public string animationThatIShouldBePlaying.
    8.  
    9.     public void LOD_OnSetLODActive(GameObject obj){
    10.         obj.animation.Play (animationThatIShouldBePlaying);
    11.     }
    12. }
    Since the Animation API has been deprecated I am going to try to get this working with the Mecanim Animation components. Hopefully this works better with Mecanim.
     
  30. VHornet

    VHornet

    Joined:
    Jul 10, 2012
    Posts:
    48
    Thanks, I've come up with a solution exactly like you said, just a slightly different, instead of using SendMessage, I change your code to use UnityAction for better performance
     
  31. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Glad to here. I should update that code.
     
  32. seagle1984

    seagle1984

    Joined:
    Apr 27, 2015
    Posts:
    3
    Hi Phong,
    My project use the JS, I import MeshBaker v3.8 and MeshBakerLOD v2.6 in Plugins folder,
    like this:
    upload_2015-4-27_8-22-39.png

    Runing MeshBakerLOD/Examples/CityScene, in console getting circular error:
    upload_2015-4-27_8-37-48.png

    Runing MeshBakerLOD/Examples/SimpleScene, in console getting circular error:
    upload_2015-4-27_8-39-20.png

    How use MeshBaker and MeshBakerLOD working in JS ?
     
    Last edited: Apr 27, 2015
  33. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi seagle1984,

    To be honest I had not thought to test this. Initially I thought it should work. However now that I think about it I realize that MeshBaker tries to load some code from the ScriptAssembilies.dll using reflection. If the scripts are in the plugin folder then those classes won't be found in ScriptAssemblies.dll. I will take a look and report back.
     
  34. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi seagle1984,

    Make the following code changes and everything should work. You may have to reimport the MeshBaker and MeshBakerLOD folders to get these chages to stick.

    In file MB2_MBVersion search for

    Assembly-CSharp

    and replace with:

    Assembly-CSharp-firstpass

    In file MB3_MBVersionEditor search for

    Type.GetType("DigitalOpus.MB.Core.MBVersionEditorConcrete,Assembly-CSharp-Editor")

    and replace with:

    typeof(MBVersionEditorConcrete)

    I will be sure to put up a more robust fix for this problem in the next version so this code editing is not necessary.
     
  35. StaffanEk

    StaffanEk

    Joined:
    Jul 13, 2012
    Posts:
    380
    Has a new version shipped?
     
  36. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi Staffan,

    Yes, this change is in Mesh Baker. You will need a more recent version of Mesh Baker.
     
  37. usupator

    usupator

    Joined:
    Oct 16, 2016
    Posts:
    31
    Hello there, I bought "plain" mesh baker last week and it's a wonderful program. Today I tried it on a morph3d character (a dwarven I had build from their standard male model - that is what their system is for! lol) and when I baked my draws I found myself as a result with..... the naked "normal" guy I had started from. All my changes in size, nose shape, clothes had gone.
    Would Mesh Baker LOD solve this problem? Has anybody tried MBLOD on morph 3D? a morph 3D model - at least for me - result in a 400 meg file when exported as a prefab so I do need help!
    I'm a newbie, I'm probably asking stupid questions here but any help and advise will be most welcome.
     
  38. Knightmore

    Knightmore

    Joined:
    May 11, 2012
    Posts:
    227
    The Morph3D models depend heavily on the build-in blendshapes. Does the script with your options disappear after using mesh baker?
     
    usupator likes this.
  39. usupator

    usupator

    Joined:
    Oct 16, 2016
    Posts:
    31
    yes it does but i had de-ticked the script on the model before baking it... was that a mistake?
     
  40. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Mesh Baker LOD will not help with this problem, but it should work with the regular Mesh Baker.

    There is a check box on the Mesh Baker inspector for blend shapes. Make sure it is ticked.

    Note that if you are combining more than one source meshes that have blend shapes, then the indexes of the blend shapes on the combined mesh will not match. The mesh baker will contain a map for mapping from the source blend shape indexes to the combined blend shape indexes.

    After the combined mesh is baked you may need to write a script to set blend shape weights on the combined mesh to make it look like the source mesh.
     
    usupator likes this.
  41. usupator

    usupator

    Joined:
    Oct 16, 2016
    Posts:
    31
    Phong many thanks for your answer, I've tried it with the blend shapes box ticked but after two hours the mesh were still not baked (the textures went super fast) and I think I have to try again.
    The morph 3D system is that the clothes they have adapt to the body you create, so my kids for example wear jeans and Tshirts that were originally on their adult "parents" before I transformed them, would it be interesting to try and do the body first then the clothes one by one to simplify the task for baker? i'm sorry I'm very ignorant and totally over my head in this (btw mesh baker has served me last week by baking a whole town without any trouble, it's a real marvel!)
    As for making a script to set the weight of the blend shapes...... the idea terrifies me - but I will try!! many thanks again
     
  42. usupator

    usupator

    Joined:
    Oct 16, 2016
    Posts:
    31
    Phong, I just tried baking one of my alien kids with the blend shapes box ticked.
    it gave me the adult normal original version I worked from not the alien kid.
    Being a one track mind person I tried again with skinned mesh render, usual render, I also tried baking the thing as one mesh just in case (it's several meshes with the clothes).
    skinned mesh render gave me the adult with the clothes (nicely baked too - just have to put bones in it again if it was the adult version I needed :c)
    normal render gave me emptiness (I check: nothing was hidden in the layers) BUT the W cursor did appear as if dealing with an empty object - and by the height at which it appeared I can tell you it was an adult empty object :c
    In both cases I found myself with a -mesh inside the CombinedMesh-MultiMeshBaker folder but nothing in the empty game object I had created to put in the target prefab (when I bake "normal" stuff I end up with a -mesh in both the empty object and the CombinedMesh-MultiMeshBaker folders don't know why and it's of no importance, I mention it in case it can help.

    I am SO sorry to bother you with this, my Morph 3D characters currently weigh 400 meg each - I am well and truly lost as Alice used to say.
    My apologies for taking up your valuable time
    cheers
     
  43. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I haven't used the Morph3D character but I suspect that your child is in the baked mesh as a blend shape you just have to turn it on. I have not tested this script but something like the following should work for activating a blend shape. Save this as file BlendShapes.cs and add the component to your baked Skinned Mesh. On Start it should set the blend shape index to 1. Experiment with the index until you find the correct Blend Shape.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class BlendShapes : MonoBehaviour {
    6.     public SkinnedMeshRenderer smr;
    7.     public Mesh m;
    8.  
    9.     void Start()
    10.     {
    11.         smr = GetComponent<SkinnedMeshRenderer>();
    12.         m = smr.sharedMesh;
    13.         Debug.Log("Number of blend shapes " + m.blendShapeCount);
    14.         //to set a blend shape
    15.         int index = 1;
    16.         float weight = 1.0f;
    17.         smr.SetBlendShapeWeight(index, weight);
    18.     }
    19. }
     
  44. human890209

    human890209

    Joined:
    Feb 27, 2017
    Posts:
    9
    Hi, How to setup the of Renderer Settings of the Combined Meshes if Baking during Runtime or using Mesh Baker LOD addon?
     
  45. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Hi Human890209,
    Usually you want the render settings to be similar to the settings on the source renderers. Same layer, same shadow casting etc..
     
  46. MrIconic

    MrIconic

    Joined:
    Apr 5, 2013
    Posts:
    239
    There's no updated reviews it seems on this asset so I was unsure if it was still being developed. I'm glad to see you're still around and I'm thinking this is a perfect solution to my issues.
     
  47. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    Let me know if you have any issues.
     
  48. human890209

    human890209

    Joined:
    Feb 27, 2017
    Posts:
    9
    Hi,
    I'm wondering if the LOD manager could handle Skinned Mesh with Optimize Game Objects ON. Cause If turn that off NavmeshAgent will get lag. o_O
     
  49. Phong

    Phong

    Joined:
    Apr 12, 2010
    Posts:
    2,085
    I don't think so. Support for Optimize Game Object only works in the editor because it uses AnimationUtility and MeshUtility classes which are editor only. Sorry. :(
     
  50. LeveAnts

    LeveAnts

    Joined:
    Jan 13, 2016
    Posts:
    2
    Hey Phong,

    I am having a bit of an issue with the LODs, I am trying to have my skinned meshes use the LOD and baking system, followed pretty much the same setup as in the example and your skinned meshes LOD video, my MB2_LOD script is on a character and it's children are 3 LOD levels of the same mesh, they all follow one animator.
    LODManager has a child with a MeshBaker made the MaterialBakeResult and assigned it to the MeshBaker.

    Anyway when playing, I am getting a CombinedMesh but it seems that all 3 LODs are combined right away into this one mesh (which is not how its supposed to be, vertices are 3x pretty much on the combined mesh), so when I am moving the camera away or towards my character that holds the MB2_LOD I am getting errors that tell me my lod0 mesh already exists.

    I should note as well that the meshes used in LOD0-2 are previously combined meshes made with another baker and baked into a prefab of which later added to the hierarchy of the character as the LOD meshes . they show the correct vertices as they should but are stored as .asset files so I am thing it might be an issue?

    a console snapshot might help:



    what is the issue exactly here? I am not quite grasping why the MeshBaker is baking all 3 LODs straight away
    and then tries to add them again, to the CombinedMesh upon switching to a different LOD, what am I doing wrong?

    EDIT: Ok, so what I was suspecting with the previously baked meshes into prefabs was correct, the issue causing these errors was that I was using an .asset file previously created with another mesh baker, my guess is the .asset file had some mesh vertices data stored from another LOD mesh.

    Another thing I noticed though, CombinedMesh and the original mesh have a bit of a difference in vertex count a small number though of about a 100 more on the CombinedMesh.
     
    Last edited: Apr 18, 2017