Question

I'am trying to figure out how to change material on loaded 3ds object/mesh during run-time after mouse click. (Away3D 3.5/3.6)

3ds object is loaded with Loader3D:

//global mesh variable and view3d
var my_mesh:Mesh;
var view:View3D = new View3D();    

//creating a parser with initial material
var max3ds_parser:Max3DS = new Max3DS();
max3ds_parser.material = new WireColorMaterial(0xFF0000);

var loader:Loader3D = new Loader3D();
loader.addEventListener(Loader3DEvent.ON_SUCCESS, onSuccess);
loader.loadGeometry("myMesh.3ds", max3ds_parser);

addChild(view);
addEventListener(Event.ENTER_FRAME, onEnterFrameRenderScene);

function onSuccess(e:Loader3DEvent):void{
    my_mesh = Mesh(e.loader.handle);
    view.scene.addChild(my_mesh)
}
function onEnterFrameRenderScene(e:Event):void{
    my_mesh.rotationY += 15;
    view.render();
}

So, after all this the 3ds object is added to the scene with initial material (WireColorMaterial) applied with parser object. But now I want to change the initial material after mouse click, so:

stage.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void{
    //start FAIL here:
    my_mesh.material = new WireframeMaterial(0x000000);
    //end FAIL
    trace("clicked!");
    trace(my_mesh.material)
} 

After the mouse click nothing changes in the view, my_mesh spins as it did with the initial material on. But the trace material shows that the new material was indeed applied.

Is there any other way to do this, or is there some kind of a way to refresh the scene to make it use the new material? Or refresh the view? Or should you somehow parse my_mesh again? Cheers.

Was it helpful?

Solution

I would recommend importing your models via Prefab3D. This will allows you to pre-process all these assets in a visual tool.

I either use the awd format or just export meshes as AS3 classes. Export as AS3 classes also compresses that data with the rest of you assets in the swf, a nice little bonus :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top