2010-12-23 72 views
0

我發現adding texture to a cube多個多維數據集 - Papervision3D的

我要的是有3個方塊成一排,也能夠進一步將它們放置在背面(X軸)的例子,但我真的不知道關於papervision3d。我只是改變了紋理,就是這樣。下面是代碼:

http://www.kelvinluck.com/assets/papervision3d/cube_tweaks/

package 
{ 
import flash.display.Bitmap; 
import flash.display.BitmapData; 
import flash.display.Sprite; 
import flash.events.Event; 
import flash.events.KeyboardEvent; 
import org.papervision3d.cameras.Camera3D; 
import org.papervision3d.materials.BitmapMaterial; 
import org.papervision3d.materials.BitmapFileMaterial; 
import org.papervision3d.materials.MaterialsList; 
import org.papervision3d.objects.DisplayObject3D; 
import org.papervision3d.scenes.Scene3D; 
import org.papervision3d.objects.Collada; 
import org.papervision3d.core.proto.DisplayObjectContainer3D; 
import org.papervision3d.objects.Cube; 
import org.papervision3d.materials.ColorMaterial; 

public class PapervisionCubeSides extends Sprite 
{ 

    private var container:Sprite; 
    private var scene:Scene3D; 
    private var camera:Camera3D; 
    private var rootNode:DisplayObject3D; 
    private var ml:MaterialsList = new MaterialsList(); 
    private var customcube:Cube; 

    public function PapervisionCubeSides() 
    { 
    init3D(); 
    addEventListener(Event.ENTER_FRAME, Timeline); 
    } 

    private function init3D():void { 
    container = new Sprite(); 
    addChild(container); 
    container.x = stage.stageWidth * .5; 
    container.y = stage.stageHeight * .5; 
    scene = new Scene3D(container); 
    camera = new Camera3D(); 
    camera.zoom = 10; 

    rootNode = scene.addChild(new DisplayObject3D("rootNode")); 

    var ml:MaterialsList = new MaterialsList(); 
    ml.addMaterial(new BitmapFileMaterial("ski.jpg"), 'face1'); 
    ml.addMaterial(new BitmapFileMaterial("ski.jpg"), 'face2'); 
    ml.addMaterial(new BitmapFileMaterial("ski.jpg"), 'face3'); 
    ml.addMaterial(new BitmapFileMaterial("ski.jpg"), 'face4'); 
    ml.addMaterial(new BitmapFileMaterial("ski.jpg"), 'face5'); 
    ml.addMaterial(new BitmapFileMaterial("ski.jpg"), 'face6'); 

    customcube = new Cube(ml, 280, 280, 280, 1, 1, 1); 

    rootNode.addChild(customcube, "myCube01"); 
    } 

    private function Timeline(event:Event):void { 
    var screen:DisplayObject3D = this.scene.getChildByName("rootNode"); 
    var rotationY:Number = -(this.mouseX/this.stage.stageWidth * 275); 
    var rotationX:Number = -(this.mouseY/this.stage.stageHeight * 275); 
    screen.rotationY += (rotationY - screen.rotationY)/12; 
    screen.rotationX += (rotationX - screen.rotationX)/12; 

    this.scene.renderCamera(this.camera); 
    } 
} 
} 

感謝您的幫助

+0

順便說一句,X是水平的,z是深度,你可以移動攝像機位和/或添加三叉戟/ UCS(HTTP: //papervision3d.googlecode.com/svn/trunk/as3/trunk/docs/org/papervision3d/objects/special/UCS.html)。此外,爲了避開現場,最初可以使用調試攝像頭(http://papervision3d.googlecode.com/svn/trunk/as3/trunk/docs/org/papervision3d/cameras/DebugCamera3D.html),您可以輕鬆地將後來爲目標相機例如 – 2010-12-23 10:19:24

回答

1

將添加3個方塊,你加1個立方以誠信的方式相同。您可以循環做一個基本的,使用迭代遞增的位置:

package 
{ 
import flash.display.Bitmap; 
import flash.display.BitmapData; 
import flash.display.Sprite; 
import flash.events.Event; 
import flash.events.KeyboardEvent; 
import org.papervision3d.cameras.Camera3D; 
import org.papervision3d.materials.BitmapMaterial; 
import org.papervision3d.materials.BitmapFileMaterial; 
import org.papervision3d.materials.MaterialsList; 
import org.papervision3d.objects.DisplayObject3D; 
import org.papervision3d.scenes.Scene3D; 
import org.papervision3d.objects.Collada; 
import org.papervision3d.core.proto.DisplayObjectContainer3D; 
import org.papervision3d.objects.Cube; 
import org.papervision3d.materials.ColorMaterial; 

public class PapervisionCubeSides extends Sprite 
{ 

    private var container:Sprite; 
    private var scene:Scene3D; 
    private var camera:Camera3D; 
    private var rootNode:DisplayObject3D; 
    private var ml:MaterialsList = new MaterialsList(); 
    private var customcube:Cube; 

    public function PapervisionCubeSides() 
    { 
    init3D(); 
    addEventListener(Event.ENTER_FRAME, Timeline); 
    } 

    private function init3D():void { 
    container = new Sprite(); 
    addChild(container); 
    container.x = stage.stageWidth * .5; 
    container.y = stage.stageHeight * .5; 
    scene = new Scene3D(container); 
    camera = new Camera3D(); 
    camera.zoom = 10; 

    rootNode = scene.addChild(new DisplayObject3D("rootNode")); 

    var ml:MaterialsList = new MaterialsList(); 
    ml.addMaterial(new BitmapFileMaterial("ski.jpg"), 'face1'); 
    ml.addMaterial(new BitmapFileMaterial("ski.jpg"), 'face2'); 
    ml.addMaterial(new BitmapFileMaterial("ski.jpg"), 'face3'); 
    ml.addMaterial(new BitmapFileMaterial("ski.jpg"), 'face4'); 
    ml.addMaterial(new BitmapFileMaterial("ski.jpg"), 'face5'); 
    ml.addMaterial(new BitmapFileMaterial("ski.jpg"), 'face6'); 

    for(var i:int = 0 ; i < 3 ; i++){ 
     customcube = new Cube(ml, 280, 280, 280, 1, 1, 1); 
     customcube.x = (280 + 10) * i 
     rootNode.addChild(customcube, "myCube"+i); 
    } 
    } 

    private function Timeline(event:Event):void { 
    var screen:DisplayObject3D = this.scene.getChildByName("rootNode"); 
    var rotationY:Number = -(this.mouseX/this.stage.stageWidth * 275); 
    var rotationX:Number = -(this.mouseY/this.stage.stageHeight * 275); 
    screen.rotationY += (rotationY - screen.rotationY)/12; 
    screen.rotationX += (rotationX - screen.rotationX)/12; 

    this.scene.renderCamera(this.camera); 
    } 
} 
} 
+0

我已經做到了。但是,謝謝! – DaTroop 2010-12-25 10:53:06