多个立方体 - Papervision3D

发布于 2024-10-08 18:44:26 字数 2763 浏览 7 评论 0原文

我找到了一个 向立方体添加纹理的示例

我想要的是有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦中的蝴蝶 2024-10-15 18:44:26

老实说,您添加 3 个立方体的方式与添加 1 个立方体的方式相同。您可以执行基本的 for 循环并使用迭代器来增加位置:

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);
  }
 }
}

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);
  }
 }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文