Dear Team,
  I am trying to draw a custom 2-d shape on the screen and then create
its 3-d model using  Away 3-d. I have included the classes that I have
used. I am yet to create the 3-d model using extrusion.
The problem is that there is always a small offset when making the
drawing. When trying out the code please click on the screen at two
different points to get the drawing start and going. The drawing is
triggered on MouseDown. Please do help me as I have been trying to
find a solution for quiet sometime.

package
{
        import away3d.cameras.*;
        import away3d.containers.*;

        import flash.display.*;
        import flash.events.*;

        [SWF(width="800", height="600")]
        public class ExtrusionBaseClass extends Sprite
        {
                protected var _view : View3D;
                protected var _camera : HoverCamera3D;

                public function ExtrusionBaseClass()
                {
                        _createView(); _createScene();
                }

                protected function _createView() : void
                {
                        _camera = new HoverCamera3D();
                        _camera.distance = 1000;
                        _camera.tiltAngle = 10;
                        _camera.panAngle = 180;

                        _view = new View3D();
                        _view.x = 400;
                        _view.y = 300;
                        _view.camera = _camera;

                        addChild(_view);
                        addEventListener(Event.ENTER_FRAME, _onEnterFrame);
                }

                protected function _createScene() : void
                {
                }

                protected function _onEnterFrame(ev : Event) : void
                {
                        //_camera.panAngle -= (stage.mouseX - 
stage.stageWidth/2) / 100;
                   _camera.hover();

                        _view.render();
                }
        }
}




package {
        import away3d.core.base.*;
        import away3d.core.geom.*;
        import away3d.core.math.*;
        import away3d.extrusions.*;
        import away3d.materials.*;

        import flash.events.MouseEvent;


        public class UsingExtrusionTest3 extends ExtrusionBaseClass
        {

                private var _xpos:Array = new Array(20);
                private var _ypos:Array = new Array(20);
                private var sides:Number = 1;
                private var init:Boolean = true;
                private var firstTime:Boolean = true;
                private var mesh:Mesh = new Mesh();
                private var i:uint=0;


                public function UsingExtrusionTest3()
                {
                        super();
                }
                override protected function _createScene() : void
                {
                         mesh.bothsides = true;
                        var material : WireColorMaterial = new 
WireColorMaterial(0xFF0000);
                        material.wireColor = 0x000000;
                        material.thickness = 2;
                        mesh.material = material;
                        _view.scene.addChild(mesh);

                         var segment0:Segment = new Segment();
                        segment0.moveTo(0, 0, 0);
                        segment0.lineTo(200, 0, 0);
                        segment0.lineTo(200, 0,100);
                        segment0.lineTo(0, 0,100);
                        segment0.lineTo(0, 0,0);
                        mesh.addSegment(segment0);

                        stage.addEventListener(MouseEvent.MOUSE_DOWN, 
onMouseDown);
                }

                public function onMouseDown(event:MouseEvent):void {

                        if(firstTime)
                        {
                                mesh.mouseEnabled = true;
                                _xpos[i] = _view.mouseX;
                                _ypos[i] = _view.mouseY;
                                firstTime = false;

                                trace("x = "+ _xpos[i]);
                                trace("y = "+ _ypos[i]);

                                i++;


                        }
                        else
                        {
                                _xpos[i] = _view.mouseX;
                                _ypos[i] = _view.mouseY;

                                trace("x1 = "+ _xpos[i-1]);
                                trace("y1 = "+ _ypos[i-1]);

                                trace("x2 = "+ _xpos[i]);
                                trace("y2 = "+ _ypos[i]);
                                var segment1:Segment = new Segment();
                        segment1.moveTo(_xpos[i-1],- _ypos[i-1],0);
                                segment1.lineTo(_xpos[i],-_ypos[i],0);
                                mesh.addSegment(segment1);

                                i++;
                        }

                }
        }
}

Reply via email to