2008年 08月 29日
以前にMovieAssetMaterial で複数のポリゴンに動画を張り付けて表示させ
それを removeChildを使って削除したが。
処理速度が重かったので 削除方法を自分で考えました。
もしかしたら papervisionのバージョンがあがって改善されているかもしれませんが。
用途によりますが ビットマップの削除
DisplayObject3D.material.bitmap.dispose();
マテリアルを破壊
obj.material.destroy();
これで処理は軽くなりました。
package {
import flash.display.Sprite;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.objects.primitives.Plane;
import flash.events.Event;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.core.utils.Mouse3D;
import org.papervision3d.objects.DisplayObject3D;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.text.TextField;
import flash.events.MouseEvent;
import flash.display.DisplayObject;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
import mx.core.ButtonAsset;
import org.papervision3d.materials.BitmapMaterial;
public class Remove3D extends Sprite
{
public var viewport :Viewport3D;
public var scene :Scene3D;
public var camera :Camera3D;
public var renderer :BasicRenderEngine;
/**----------------------------------------------------------------------
* コンストラクタ
-----------------------------------------------------------------------*/
public function Remove3D() {
this.stage.align = StageAlign.TOP_LEFT;
this.stage.scaleMode = StageScaleMode.NO_SCALE;
var text:TextField = new TextField();
text.width = this.stage.stageWidth;
text.y = this.stage.stageHeight/2 - text.height/2;
text.textColor = 0xffffff;
text.selectable = false;
text.defaultTextFormat = new TextFormat(null,16,null,null,null,null,null,null,TextFormatAlign.CENTER);
text.defaultTextFormat.align = TextFormatAlign.CENTER;
text.text = "クリックしてください";
this.addChild(text);
text.addEventListener(MouseEvent.CLICK , this.init);
}
/**----------------------------------------------------------------------
* init
* 初期化
-----------------------------------------------------------------------*/
public function init(evn:MouseEvent):void {
this.removeChild(DisplayObject(evn.currentTarget))
//このムービーのスケールモードを設定
this.stage.scaleMode = StageScaleMode.NO_SCALE;
this.stage.align = StageAlign.TOP_LEFT;
//3Dの初期設定
this.init3D();
//毎フレーム呼び出されるイベントを追加
this.addEventListener( Event.ENTER_FRAME, this.loop_Proc );
var text:TextField = new TextField();
text.textColor = 0x000000;
text.width = 220;
text.height = 25;
text.x = 10;
text.y = 10;
text.selectable = false;
text.defaultTextFormat = new TextFormat(null,12,null,null,null,null,null,null,TextFormatAlign.LEFT);
text.text = "クリックするとオブジェクトを削除します";
text.background = true;
text.backgroundColor = 0xdddddd;
this.addChild(text);
text.addEventListener(MouseEvent.CLICK, this._delete_Proc);
}
/**----------------------------------------------------------------------
* _delete_Proc
* オブジェクトを削除
-----------------------------------------------------------------------*/
public function _delete_Proc(evn:MouseEvent):void {
for(var s:String in this.scene.children){
var obj:DisplayObject3D = DisplayObject3D(this.scene.children[s]);
//マテリアルが存在するなら
if(obj.material){
//ビットマップがあるなら開放
if(obj.material.bitmap)obj.material.bitmap.dispose();
//マテリアルを破壊
obj.material.destroy();
}
//シーンから削除
this.scene.removeChild(obj);
//1つだけ削除
break;
}
}
/**----------------------------------------------------------------------
* init3D
* 3Dの初期設定
-----------------------------------------------------------------------*/
public function init3D():void {
// ビューポートの作成
this.viewport = new Viewport3D(0, 0, true, true);
this.addChild( viewport );
//レンダラーの設定
this.renderer = new BasicRenderEngine();
//シーン作成
this.scene = new Scene3D();
for(var i:uint=0; i<20; i++){
//Cubeを作成
var _cube:Cube = new Cube(
new MaterialsList({all:new ColorMaterial(Math.random() * 1000000000)}),
50,50,50
);
_cube.x = -200 + Math.random() * 400;
_cube.y = -200 + Math.random() * 400;
_cube.z = -200 + Math.random() * 400;
_cube.rotationX = Math.random() * 360;
_cube.rotationY = Math.random() * 360;
this.scene.addChild(_cube);
}
// カメラの作成
this.camera = new Camera3D();
this.camera.zoom = 50;
}
/**----------------------------------------------------------------------
* loop_Proc
* 毎フレーム呼び出される 関数
-----------------------------------------------------------------------*/
public function loop_Proc(event:Event):void
{
for(var s:String in this.scene.children){
var obj:DisplayObject3D = DisplayObject3D(this.scene.children[s]);
obj.rotationX += 3;
obj.rotationY += 5;
}
//レンダリング
this.renderer.renderScene(scene, camera, viewport);
}
}
}
投稿者: d5 19 : 08
更新日:2008-08-29 19:04:05
|
|
|
| |