论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Flash AS教程
Tag:2.0,3.0菜鸟,游戏,,cs,技巧,源码,,文本,文字,函数,音乐,随机,拖拽,asp,access,xml,mc,视频教程

有关3D引擎的制作

文章类别:Flash AS | 发表日期:2009-8-8 16:10:02

有关3D引擎的制作

目标是在flash里创建顶级的渲染画质。同时CPU还在可以接收的范围内。(必要时牺牲画质换cpu)
如果能做成虚幻3那样的引擎那当然最好了,不过还要很久很久。。

其实rokix那种引擎的性能并非不可超越的(像stage品质设为低就是一个很重要的3d技巧),不过flash本身的性能却没办法超过。。。
复制内容到剪贴板代码:
package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.text.TextField;
   
    import flashk.k3d.camera.Camera3D;
    import flashk.k3d.geom.Point3D;
    import flashk.k3d.materials.ColorMaterial;
    import flashk.k3d.materials.FileMaterial;
    import flashk.k3d.object.Ball;
    import flashk.k3d.object.Cube;
    import flashk.k3d.object.Plane;
    import flashk.k3d.scene.Scene3D;
    import flashk.k3d.viewport.Viewport;
   
    [SWF(backgroundColor="#000000", frameRate="30", width="800", height="600")]
    public class Test extends Sprite
    {
        private var v:Viewport;
        private var c:Camera3D;
        private var s:Scene3D;
        private var count:uint = 0;
        private var cube:Cube ;
        private var points:Array = [];
        private var addVol:Number =1;
        private var cu2:Cube;
        private var pl:Plane;
        private var ball:Ball;
        private var ball2:Ball;
       
        public function Test()
        {
            v = new Viewport(this,800,600);
            c = new Camera3D();
            s = new Scene3D();
            c.len = 1000;
            this.addEventListener(Event.ENTER_FRAME,show);
            add();
            v.render(c,s);
            var txt:TextField = new TextField();
            txt.text = "K3D 演示 Demo \n 中国的3D引擎";
            txt.textColor = 0xFFFFFF;
            txt.x = 650;
            txt.scaleX = txt.scaleY = 1.3;
            this.addChild(txt);
        }
        private function show(event:Event):void{
            count++;
            if(count >5 || 2>1){
                addVol = Math.random()>0.5?1:0;
                //count = 0;
                v.render(c,s);
                cube.rotationY += 1;
                ball.rotationY += 1;
                if(count%2 ==0){
                    ball2.rotationY += 1.5;
                    count = 0;
                }
                if(this.mouseY>10 && this.mouseY<590 && this.mouseX>10 && this.mouseX< 780){
                    c.upRotation += (90 - this.mouseY/4- c.upRotation)/5;
                }else{
                    c.upRotation += (40- c.upRotation)/20;
                }
                for(var i:int = 0 ;i<points.length;i++){
                    points[i].z -=10;
                    if(points[i].z<0){
                        points[i].z = c.len *0.8;
                    }
                }
                cu2.x += 10;
                if(cu2.x >800) cu2.x =-800;
                //cube.y +=5;
            }
        }
        private function add():void{
            var p:Point3D;           
            for(var i:int =1;i<8;i++){
                p = new Point3D(-400+Math.random()*800,100+Math.random()*500,i*2);
                s.addChild(p);
                points.push(p);
            }
            /*
            s.addChild(new Point3D(300,50,10));
            s.addChild(new Point3D(-300,50,10));
            s.addChild(new Point3D(300,450,10));
            s.addChild(new Point3D(-300,450,10));
            s.addChild(new Point3D(300,50,110));
            s.addChild(new Point3D(-300,50,110));
            s.addChild(new Point3D(300,450,110));
            s.addChild(new Point3D(-300,450,110));
            */
            var cu:Cube;
           
            cu = new Cube(150,150,350);
            cu.setAllMaterial(new FileMaterial("uv.jpg"));
            cu.moveTo(-300,200,500);
            cu.rotationY = -71;
            //s.addChild(cu);
            cu = new Cube(150,200,300);
            cu.setAllMaterial(new FileMaterial("uv.jpg"));
            cu.moveTo(-500,700,800);
            cu.rotationY = 51;
            //s.addChild(cu);
            cu = new Cube(150,250,50);
            cu.setAllMaterial(new FileMaterial("uv.jpg"));
            cu.moveTo(500,200,500);
            cu.rotationY = -81;
            cu2 = cu;
            //s.addChild(cu);
            cube = new Cube(100,100,100);
            cube.moveTo(0,400,200);
            cube.setAllMaterial(new FileMaterial("uv.png"));
            s.addChild(cube);
            cu = new Cube(150,150,150);
            cu.moveTo(100,50,100);
            cu.setAllMaterial(new FileMaterial("uv.jpg"));
            cu.rotationY = -51;
            //s.addChild(cu);
            pl = new Plane(800,1300);
            pl.setMaterial(new FileMaterial("uv2.png"),true);
            pl.setMaterial(new FileMaterial("uv2-alpha.png"));
            s.addChild(pl);
           
            pl = new Plane(1300,600);
            pl.rotationY = -90;
            pl.setMaterial(new FileMaterial("uv3.png"),false);
            pl.setMaterial(new FileMaterial("uv3-alpha.png"));
            s.addChild(pl);
           
            pl = new Plane(1300,600);
            pl.puSide(2);
            pl.rotationY = -90;
            pl.setMaterial(new FileMaterial("uv3.png"),true);
            pl.setMaterial(new FileMaterial("uv3-alpha.png"));
            s.addChild(pl);
           
            pl = new Plane(800,1300);
            pl.puSide(3);
            //pl.rotationY = -90;
            pl.setMaterial(new FileMaterial("uv2.png"),true);
            pl.setMaterial(new FileMaterial("uv2-alpha.png"));
            s.addChild(pl);
           
            ball = new Ball(230);
            ball.moveTo(-30,200,20);
            ball.setMaterial(new FileMaterial("grid.png"));
            //ball.setMaterial(new ColorMaterial(0xCCFF3300));
            trace(ball);
            s.addChild(ball);
           
           
        ball2 = new Ball(120,"best");
        ball2.moveTo(175,150,20);
        ball2.setMaterial(new FileMaterial("ball.png"));
            //trace(ball);
            s.addChild(ball2);
        }
    }
}

视频教程列表
文章教程搜索
 
Flash AS推荐教程
Flash AS热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058