Multiple cubes - Papervision3D
I found an example of adding texture to a cube
What I want is to have 3 cubes in a row and also to be able to place them further at the back(x axis) but I really do not know much about papervision3d. I just changed the textures and that was it. Here is the code:
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 Displ开发者_如何转开发ayObject3D("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);
}
}
}
thanks for the help
you would add 3 cubes the same way you add 1 cube to be honest. You can do a basic for loop and use the iterator to increment the position:
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);
}
}
}
精彩评论