多个立方体 - Papervision3D
我找到了一个 向立方体添加纹理的示例
我想要的是有 3 个立方体排成一排,并且能够将它们进一步放置在后面(x 轴),但我真的对 papervision3d 了解不多。我只是改变了纹理,仅此而已。这是代码:
http://www.kelvinluck.com/assets/papervision3d/cube_tweaks/< /a>
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);
}
}
}
谢谢你的帮助
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 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);
}
}
}
thanks for the help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
老实说,您添加 3 个立方体的方式与添加 1 个立方体的方式相同。您可以执行基本的 for 循环并使用迭代器来增加位置:
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: