Collada オブジェクトのマテリアルを変更してみる
Collada オブジェクトのマテリアルを変更してみる。
@author tkinjo
/**
* Copyright tkinjo ( http://wonderfl.net/user/tkinjo )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/4Kne
*/
package
{
import flash.display.Sprite;
import flash.events.Event;
import org.papervision3d.core.proto.CameraObject3D;
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.events.FileLoadEvent;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.shadematerials.CellMaterial;
import org.papervision3d.materials.shadematerials.EnvMapMaterial;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.materials.shadematerials.GouraudMaterial;
import org.papervision3d.materials.shadematerials.PhongMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.AbstractView;
import org.papervision3d.view.BasicView;
[SWF(width = "465", height = "465", frameRate = "60", backgroundColor = "#000000")]
/**
* Collada オブジェクトのマテリアルを変更してみる。
*
* @author tkinjo
*/
public class Main extends Sprite
{
private const DAE_PATH:String = "http://cross.gentenzero.com/wonderfl/assets/collada/material.dae";
private var view:AbstractView;
/**
* ローカル変数で使うと load に失敗する。
* load する前に scene.addChild( dae ) を呼んでおけば問題はないかもしれないが…。
*/
private var dae:DAE;
/**
*
*/
public function Main()
{
view = new BasicView( 465, 465 );
addChild( view );
dae = new DAE();
dae.addEventListener( FileLoadEvent.LOAD_COMPLETE, fileLoadCompleteHandler );
dae.load( DAE_PATH );
addEventListener( Event.ENTER_FRAME, enterFrameHandler );
view.startRendering();
}
/**
*
* @param event
*/
private function enterFrameHandler( event:Event ):void {
dae.rotationY++;
}
/**
*
* @param event
*/
private function fileLoadCompleteHandler( event:FileLoadEvent ):void {
var scene:Scene3D = view.scene;
scene.addChild( dae );
dae.scale = 200;
/**
* Collada ファイルに定義されている各オブジェクトの取得。
*/
var colladaScene:DisplayObject3D = dae.children[ DAE.ROOTNODE_NAME ];
/**
* オブジェクト名の取得方法。
*/
/*
for ( var key:String in colladaScene.children )
trace( key, colladaScene.children[ key ].name );
//*/
/*
for each ( var object:DisplayObject3D in colladaScene.children )
trace( object.name );
//*/
var material:MaterialObject3D;
for ( var key:String in colladaScene.children ) {
switch( key ) {
//*/
case "Cone":
var cone:DisplayObject3D = colladaScene.children[ key ] as DisplayObject3D;
material = new ColorMaterial( 0x00ff00, 0.5 );
material.doubleSided = true;
cone.material = material;
break;//*/
//*
case "Sphere":
var sphere:DisplayObject3D = colladaScene.children[ key ] as DisplayObject3D;
//material = new ColorMaterial( 0x0000ff );
//material = new CellMaterial( null, 0xffffff, 0x0000ff, 10 );
//material = new EnvMapMaterial( null, bmp.bitmapData );
material = new FlatShadeMaterial( null, 0xffffff, 0x0000ff );
//material = new GouraudMaterial( null, 0xffffff, 0x0000ff );
//material = new PhongMaterial( null, 0xffffff, 0x0000ff, 10 );
sphere.material = material;
break;//*/
}
}
}
}
}