Hello,
I’m trying to figure out how to activate/deactivate a mesh inside a gameComponent in order to implement an “automatic” LOD switch inside one object.
I have edited Ara’s LOD script for use with 3 LODs:
var HLOD : Mesh;
var MLOD : Mesh;
var LLOD : Mesh;
var distance1 = 10.0;
var distance2 = 20.0;
function Update ()
{
var campos = Camera.main.transform.position;
var meshFilter : MeshFilter = GetComponent(MeshFilter);
if( (transform.position - campos).sqrMagnitude < distance1 * distance1 )
{
// use High LOD
if( meshFilter.sharedMesh != HLOD )
meshFilter.sharedMesh = HLOD;
}
else if ((transform.position - campos).sqrMagnitude < distance2 * distance2)
{
// use Medium LOD
if( meshFilter.sharedMesh != MLOD )
meshFilter.sharedMesh = MLOD;
}
else
{
// use Low LOD
if( meshFilter.sharedMesh != LLOD )
meshFilter.sharedMesh = LLOD;
}
}
It works great if I have 3 different models (in my case .dae), include one model (it does´t matter which one) into the world and attach the script to the mesh so that I can setup the mesh switching.
Now, what I would like it to do is to create just one model with 3 meshes (I usually call them HLOD, MLOD and LLOD) and edit the original script in order to get the same LOD switching but inside just one model. I mean, I would like to attach the script to the model (gameObject) and that the script recognize the name of the 3 meshes and activate/deactivate them depending on the distance.
This is my example:
This way creating LODs is much more easy because I only will have one object and because the script will recognize the corresponding LOD that should be rendered.
I have tried a lot of ways but none is printable here because they are really crap…
Can anyone help me?
Thanks in advance