Hello, I'm going to create a new component with 3D effect. But I encounter this problem. I can't change the position of the Planes in function organize3DLayout but I can change the Images position by child.x = 200; etc. All the planes are still in the center of the canvas. I feel only the codes in function addChild is effective.
child.x = unscaledWidth/2 - child.width/2; child.y = unscaledHeight/2 - child.height/2; Anyone can help? I really confused. http://www.nabble.com/file/p23299407/temp.jpg package { import caurina.transitions.Tweener; import flash.display.DisplayObject; import flash.events.Event; import flash.utils.Dictionary; import mx.containers.Canvas; import org.papervision3d.cameras.Camera3D; import org.papervision3d.events.InteractiveScene3DEvent; import org.papervision3d.materials.MovieMaterial; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.objects.primitives.Plane; import org.papervision3d.render.BasicRenderEngine; import org.papervision3d.scenes.Scene3D; import org.papervision3d.view.Viewport3D; public class Canvas3DCom extends Canvas { //debug mode public var DEBUG:Boolean=false; //interactivity public var INTERACTIVITY:Boolean=false; //effects public var EFFECTS:Boolean=false; //tweening time (ms) private var _tw_time:Number=1000; //papervision basics private var _view:Viewport3D; private var _cam:Camera3D; private var _scene:Scene3D; private var _render:BasicRenderEngine; //defines planes segments private var _meshquality:Number = 2; //root node for nesting 3D objects private var _root3D:DisplayObject3D; //children dictionary /** * @description: associates displayobjects to planes. dictionary key are viewstack children. values are planes on 3D space. * !IMPORTANT: uses weak reference to ease garbage collection **/ private var _toPlane:Dictionary; private var _toChild:Dictionary; private var _current3DChild:DisplayObject3D; //viewports h,w private var _viewport_width:Number=0; private var _viewport_height:Number=0; //x gap private var _xgap:Number= 50; //coverflow angulation private var _cfangle:Number = 60; //number of the ring private var _no_of_ring:int = 1; public function Canvas3DCom() { super(); init3D(); } /** * @description: builds up 3D elements (scene, camera, renderer and viewport) **/ private function init3D():void { trace("INIT 3D"); _scene = new Scene3D(); _cam = new Camera3D(); _cam.focus = 100; //_cam.zoom = 11; _cam.z = -1000; _render = new BasicRenderEngine(); //_view is going to be initialized in organizelayout _toPlane = new Dictionary(true); _toChild = new Dictionary(true); _root3D = new DisplayObject3D(); _scene.addChild(_root3D); } override public function addChild(child:DisplayObject):DisplayObject{ super.addChild(child); // child.visible = false; //set child position in the middle of the viewstack child.x = unscaledWidth/2 - child.width/2; child.y = unscaledHeight/2 - child.height/2; //add a new plane to the 3d stack addChild3D(child); return child; } /** * @description: addChild3D adds a DisplayObject3D to viewstack3d and associates it with its own relative child on 2D space **/ private function addChild3D(child:DisplayObject):DisplayObject3D { trace("addChild3D"); var mat:MovieMaterial = new MovieMaterial(child,true,true); mat.oneSide=false; mat.smooth = true; mat.interactive = true; if(child.width>_viewport_width) _viewport_width=child.width; if(child.height>_viewport_height) _viewport_height=child.height; //create plane, add plane to root3D, associate plane to child var child3D:DisplayObject3D = new Plane(mat,child.width,child.height ,_meshquality,_meshquality); _root3D.addChild(child3D); _toPlane[child] = child3D; _toChild[child3D] = child; //INTERACTIVITY!!! //event listening for 3D objects child3D.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK,selectChild3D); return child3D; } /** * @description: selects children from 3D object **/ private function selectChild3D(e:InteractiveScene3DEvent):void { if(INTERACTIVITY){ //trace(_toChild[e.target]); //TODO } } /** * @description: enterframe render loop **/ private function loop3D(e:Event):void { try{ if(Tweener.isTweening(_cam) || Tweener.isTweening(_root3D)){ if(!INTERACTIVITY || !EFFECTS)render3D(); } if(INTERACTIVITY || EFFECTS)render3D(); }catch(e:Error){ trace("not able to render!"); } //render3D(); } /** * @description: render scene **/ private function render3D():void { _render.renderScene(_scene,_cam,_view); } /** * @description: override updateDisplayList to add 3D objects layout **/ override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { super.updateDisplayList(unscaledWidth,unscaledHeight); // layout all children in the root3D object organize3DLayout(); } /** * @description: organizes 3D objects layout switching current layout **/ protected function organize3DLayout():void { if(!_view){ _view = new Viewport3D(this.unscaledWidth,this.unscaledHeight,false,true,false,false); rawChildren.addChild(_view); render3D(); layoutRING(); } private function layoutRING():void{ var child3D:Plane; var child:DisplayObject; var rootRot:Number = 0; var rootX:Number = 0; for( var i:int = 0; i < numChildren; i++ ){ child = this.getChildAt(i); child3D = _toPlane[child]; child3D.x = (_viewport_width + _xgap) * i; } Tweener.addTween(_cam,{z:-1000-(_viewport_width+_xgap),time:_tw_time*.001}); Tweener.addTween(_root3D,{rotationY:rootRot,x:rootX,time:_tw_time*.001}); for( var h:int = 0; h < numChildren; h++ ){ child = this.getChildAt(h); child3D = _toPlane[child]; } } } } <local:Canvas3DCom id="c3d" x="0" y="0" width="1000" height="750"> <mx:Image id="i1" source="images/Belle.png" width="100" height="100" toolTip="image1"/> <mx:Image id="i2" source="images/Belle.png" width="100" height="100" toolTip="image2"/> <mx:Image id="i3" source="images/Belle.png" width="100" height="100" toolTip="image3"/> <mx:Image id="i4" source="images/Belle.png" width="100" height="100" toolTip="image4"/> <mx:Image id="i5" source="images/Belle.png" width="100" height="100" toolTip="image5"/> <!-- <mx:Image source="images/Belle.png" width="100" height="100" toolTip="image6"/> <mx:Image source="images/Belle.png" width="100" height="100" toolTip="image7"/> <mx:Image source="images/Belle.png" width="100" height="100" toolTip="image8"/> <mx:Image source="images/Belle.png" width="100" height="100" toolTip="image9"/> <mx:Image source="images/Belle.png" width="100" height="100" toolTip="image0"/> --> </local:Canvas3DCom>:confused: -- View this message in context: http://www.nabble.com/Create-new-Canvas-with-Papervision3D-tp23299407p23299407.html Sent from the FlexCoders mailing list archive at Nabble.com.

