我怎样才能使这个papervision3d代码工作?

时间:2011-02-12 17:03:39

标签: actionscript-3 actionscript flash-cs5 papervision3d

此代码有效,但它确实将多维数据集显示为第一个代码,并且视图,缩放和交互性不同,所以我希望立方体显示为具有相同功能的第一个代码。

第一个代码在这里:http://papervision2.com/10-advanced-interactivity/

  package 
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.materials.MovieMaterial;
    import org.papervision3d.materials.utils.MaterialsList;
    import org.papervision3d.objects.primitives.Cube;
    import org.papervision3d.view.BasicView;

    public class Main extends BasicView 
    {
        protected var cube:Cube;
        protected var interactiveMats:Array;
        protected var materialsList:MaterialsList;
        protected var targetrotationX:Number;
        protected var targetrotationY:Number;
        protected var targetrotationZ:Number;
        protected var tweening:Boolean;

        public function Main():void 
        {
            super();
            init();
        }
        protected function init():void 
        {
            createChildren();
            startRendering();
        }
        protected function createChildren():void 
        {
            //Set the viewport to interactive
            viewport.interactive = true;

            //Create Materials:
            materialsList           = new MaterialsList();
            interactiveMats         = ["front", "back", "left", "right", "bottom", "top"];
            var colorsArray:Array   = [0x76b6f8, 0x4291e1, 0x1f73c8, 0xe77111, 0xe8914c, 0xfad2b2];

            for (var i:int = 0; i < interactiveMats.length; i++)
            {
                //Create a color box so we can use our MouseEvents
                var colorBox:Sprite = new Sprite();
                colorBox.graphics.beginFill(colorsArray[i]);
                colorBox.graphics.drawRect(0, 0, 100, 100);
                colorBox.graphics.endFill();
                colorBox.name = interactiveMats[i];

                //Add a textField for reference
                var textField:TextField = new TextField()
                colorBox.addChild(textField)
                textField.text = interactiveMats[i];

                //Add a MouseEvent to the Sprite
                colorBox.mouseChildren = false;
                colorBox.addEventListener(MouseEvent.CLICK, onMovieMatClicked);

                //Create the MovieMat
                var movieMat:MovieMaterial      = new MovieMaterial(colorBox, true, true);
                movieMat.interactive            = true;
                movieMat.smooth                 = true;
                materialsList.addMaterial(movieMat, interactiveMats[i]);
            }

            //Create Cube
            cube    = new Cube(materialsList, 100, 100, 100);

            //Add cube to the scene
            scene.addChild(cube);
        }

        protected function onMovieMatClicked(evt:MouseEvent):void 
        {
            if (tweening) 
            {
                // Let it rotate again
                tweening = false;
            }
            else 
            {
                switch(evt.target.name) {
                    case "front":
                        targetrotationX = 0;
                        targetrotationY = 180;
                        targetrotationZ = 0;
                        tweening = true;
                    break;
                    case "back":
                        targetrotationX = 0;
                        targetrotationY = 0;
                        targetrotationZ = 0;
                        tweening = true;
                    break;
                    case "left":
                        targetrotationX = 0;
                        targetrotationY = -90;
                        targetrotationZ = 0;
                        tweening = true;
                    break;
                    case "right":
                        targetrotationX = 0;
                        targetrotationY = 90;
                        targetrotationZ = 0;
                        tweening = true;
                    break;
                    case "top":
                        targetrotationX = -90;
                        targetrotationY = 0;
                        targetrotationZ = 0;
                        tweening = true;
                    break;
                    case "bottom":
                        targetrotationX = 90;
                        targetrotationY = 0;
                        targetrotationZ = 180;
                        tweening = true;
                    break;
                }
            }
        }

        override protected function onRenderTick(event:Event = null):void 
        {
            super.onRenderTick(event);

            if (tweening) {
                // If a face has been clicked
                if (camera.zoom <230) {
                    // If the camera isn't zoomed enough then zoom in a bit more:
                    camera.zoom += Math.sqrt(230-camera.zoom)/5;
                }
                // Test each rotation and rotate it towards the target rotation:
                // X axis:
                if (cube.rotationX < targetrotationX) 
                {
                    cube.rotationX += Math.sqrt(targetrotationX-cube.rotationX);
                    cube.rotationX = Math.round(cube.rotationX);
                }
                else if (cube.rotationX > targetrotationX) 
                {
                    cube.rotationX -= Math.sqrt(cube.rotationX-targetrotationX);
                    cube.rotationX = Math.round(cube.rotationX);
                }

                // Y axis:
                if (cube.rotationY < targetrotationY) 
                {
                    cube.rotationY += Math.sqrt(targetrotationY-cube.rotationY);
                    cube.rotationY = Math.round(cube.rotationY);
                }
                else if (cube.rotationY > targetrotationY) 
                {
                    cube.rotationY -= Math.sqrt(cube.rotationY-targetrotationY);
                    cube.rotationY = Math.round(cube.rotationY);
                }

                // Z axis:
                if (cube.rotationZ < targetrotationZ) 
                {
                    cube.rotationZ += Math.sqrt(targetrotationZ-cube.rotationZ);
                    cube.rotationZ = Math.round(cube.rotationZ);
                }
                else if (cube.rotationZ > targetrotationZ) 
                {
                    cube.rotationZ -= Math.sqrt(cube.rotationZ-targetrotationZ);
                    cube.rotationZ = Math.round(cube.rotationZ);
                }
            }
            else 
            {
                // If the camera is zoomed in, it shouldn't be now
                if (camera.zoom > 200) 
                {
                    // So zoom out a bit.
                    camera.zoom -= Math.sqrt(camera.zoom-2)/5;
                }
                // Rotate the cube a bit:
                cube.rotationX += 2;
                cube.rotationY += 2;
                // Make sure that we dont "wind up" the rotation
                if (cube.rotationX>= 360) cube.rotationX = 0;
                if (cube.rotationY>= 360) cube.rotationY = 0;
            }
        }       
    }
}

code2取自:http://papervision2.com/advanced-interactivity/

1 个答案:

答案 0 :(得分:0)

然而,该文章已提交,它将<解析为&lt;,将>解析为&gt;

对每个错误进行查找/替换,大部分错误都应该消失。