Drag points to change curve:
This example based on bezier Demo #8. Just small modification:private function redraw ():void { <...> segmentCenters = new Array(); var segmentsNum:uint = 10 var times:Array = bezier.getTimesSequence(20) for (var i:int = 1; i < times.length; i++) { var p1:Point = bezier.getPoint(times[i - 1]); var p2:Point = bezier.getPoint(times[i]); drawSegment2D(p1, p2) } drawSegment2D(bezier.getPoint(times[i - 1]), bezier.end) } private function drawSegment2D(p1:Point, p2:Point):void { var dx:Number = p2.x - p1.x var dy:Number = p2.y - p1.y //calculate rotation var angle:Number = Math.atan2(dy, dx) * Number3D.toDEGREES //calculate width of segment var distance:Number = Math.sqrt(dx * dx + dy * dy) //and center position var cx:int = p1.x + dx/2 var cy:int = p1.y + dy / 2 segmentCenters.push(new Segment2D(new Point(cx, cy), distance, angle)); }And create planes from each segment:
var seg:Segment2D = bezierView.segmentCenters[i] var plane:Plane = new Plane(new MaterialObject3D(), seg.length * propMult * 0.9, 100, 0, 0); //create extruded plane (Extruder class by J-roen http://www.j-roen.net/papervision/2008/06/12/tutorial-7-vertexes/) var depth:Number = 10; var fMat:MaterialObject3D = new ColorMaterial(0xfffcdf); var sMat:ColorMaterial = new ColorMaterial(0xbfbca2); var mList:MaterialsList = new MaterialsList( { front: fMat, back: fMat, side: sMat } ); var p1:Point = new Point(plane.geometry.vertices[0].x, plane.geometry.vertices[0].y) var p2:Point = new Point(plane.geometry.vertices[1].x, plane.geometry.vertices[1].y) var p3:Point = new Point(plane.geometry.vertices[2].x, plane.geometry.vertices[2].y) var p4:Point = new Point(plane.geometry.vertices[3].x, plane.geometry.vertices[3].y) var extrudedPlane:DisplayObject3D = new Extruder( mList, [p1, p2, p4, p3], depth ) //add our extrudedPlane for scene extrudedPlane.rotationY = -seg.angle extrudedPlane.x = seg.center.x extrudedPlane.z = seg.center.y scene.addChild(extrudedPlane)
I'm also use here new QuadrantRenderEngine because with ViewportLayers when rotating camera happens overlaps. Quaternion rotating for rolling ball from Dragging in 3D - The Right Way.
Get Full Source21.10.2008. 03:24
Nice example.
I've noticed some weird behaviour but I'm not sure if it's Firefox 3 or not. If I click on the link to the example it creates a new tab and everything works fine. If I then leave the tab open and browser other websites, after about 10 minutes the example slows down quite a lot. It speeds up again though it I rotate the view.
Also, the memory usage does increase slowly over time. I've had it open for about 20 minutes now and its at 30MB.
Memory leak because materials of planes not destroying completely
To fix it, I added destroy function from http://www.nabble.com/memory-leak-while-using-Cube-and-MovieMaterial-td19574050.html in Main.as(not in Displayobject3D.as)
But in IE Garbage Collector work better than in FF
Yet a other wonderfull example, as ever :)
Exey: join #papervision3d at irc server freenode server to talk to other pv3d'ers and Andy :)
Or webchat with http://pv3dchat.flashbookmarks.com/
Write a comment
* = required field