Hey fellow users i created a new class in my library called “LODObject.as” you might find it useful.
package{
import flash.geom.Vector3D;
import away3d.containers.ObjectContainer3D;
import away3d.entities.Mesh;
public class LODGroup extends ObjectContainer3D{
public var viewRanges:Array;
public var lodModels:Array;
private var currentLevel:int = -2;
public function LODGroup(viewRanges:Array, lodModels:Array){
this.viewRanges = viewRanges;
this.lodModels = lodModels;
for each(var m:ObjectContainer3D in this.lodModels){
this.addChild(m);
m.visible = false;
}
}
public function update(camPosition:Vector3D):void{
var d:Number = Vector3D.distance(camPosition, this.position);
var level:int = -1;
for(var i:int = 0; i < this.viewRanges.length; i++){
if(d < this.viewRanges[i]){
level = i;
i = this.viewRanges.length;
}
}
if(level == -1){level = this.viewRanges.length;}
if(this.currentLevel != level){swapLOD(level);}
}
private function swapLOD(level:int):void{
for each(var m:ObjectContainer3D in this.lodModels){m.visible = false;}
this.lodModels[level].visible = true;
this.currentLevel = level;
}
}
}
super simple to use
var geo1:SphereGeometry = new SphereGeometry(50,64,64);
var geo2:SphereGeometry = new SphereGeometry(50,32,32);
var geo3:SphereGeometry = new SphereGeometry(50,8,8);
var geo4:SphereGeometry = new SphereGeometry(50,4,4);
var m1:Mesh = new Mesh(geo1, material);
var m2:Mesh = new Mesh(geo2, material);
var m3:Mesh = new Mesh(geo3, material);
var m4:Mesh = new Mesh(geo4, material);
var meshList:Array = [m1,m2,m3,m4];
var ranges:Array = [200,400,600]; //should always be 1 less than meshList length
var lodGroup:LODGroup(ranges, meshList);
_scene.addChild(lodGroup);
...
loop(){
lodGroup.update(_view.camera.position);
_view.render();
}
if anyone finds this useful, let me know