3D嵌套(Nesting)

来源:互联网 发布:北京大数据起薪 编辑:程序博客网 时间:2024/05/16 19:32

DisplayObject3D继承DisplayObjectContainer3D

Scene3D继承SceneObject3D,SceneObject3D继承DisplayObjectContainer3D

故DisplayObject3D有addChild()方法 可以当做容器使用 别忘了 它还有x y z 属性

下面是代码:一个sphere嵌套另一个sphere:一样是用模板创建的:

 

 

package {
 import flash.events.Event;
 import org.papervision3d.objects.primitives.Sphere;
 import org.papervision3d.view.BasicView;
 public class NestExample extends BasicView {
  private var parentSphere:Sphere;
  private var childSphere:Sphere;
  public function NestExample() {
   /* super.BasicView(width=640,height=480,scaleToStage(是否让viewPort3D视窗为舞台大小));
    当想改变大小时可以用它
   
   */
   /*
    * @ author :夜梦惊魂
    */
   stage.frameRate=40;
   //下面只需定义3D对象, 在将其add到scene中
   parentSphere=new Sphere(null,400,16,12);
   childSphere=new Sphere(null,100,12,8);
   //使两面都显示
   parentSphere.material.doubleSided=true;
   childSphere.material.doubleSided=true;
   //添加
   scene.addChild(parentSphere);
   parentSphere.addChild(childSphere);
   startRendering();//创建secne3D basicRenderEngine  viewPort3D camera3D 
  }
  // 重写 onRenderTick 及其 调用父类onRenderTick ;
  override protected function onRenderTick(e:Event=null):void {
   parentSphere.localRotationY+=1;//旋转轴
   childSphere.localRotationY+=2;//旋转轴
   super.onRenderTick();//开始渲染
  }
 }
}