zoukankan      html  css  js  c++  java
  • away3d 4.04.1 天地会 高清汽车案例 全解析

    away3d 4.1 alpha 教程 模型篇 <1> 之 away3d 4.0 天地会 高清汽车案例 全解析

    1.车库类 全解析

    package objects3D.environments
    {
    import away3d.containers.ObjectContainer3D;
    import away3d.entities.Mesh;
    import away3d.events.AssetEvent;
    import away3d.library.assets.AssetType;
    import away3d.lights.DirectionalLight;
    import away3d.loaders.Loader3D;
    import away3d.materials.TextureMaterial;
    import away3d.materials.lightpickers.StaticLightPicker;
    import away3d.materials.methods.TerrainDiffuseMethod;
    import away3d.primitives.PlaneGeometry;
    import away3d.textures.BitmapTexture;
    
    
    public class Garage extends ObjectContainer3D
    {
        [Embed(source="garage/FloorMap.jpg")]
        private var FloorMapAsset:Class;
    
        [Embed(source="garage/GarageMap.jpg")]
        private var GarageMapAsset:Class;
    
        [Embed(source="garage/FloorShadowMap.png", mimeType="image/png")]
        private var FloorShadowMapAsset:Class;
    
        [Embed(source="garage/Garage.3DS", mimeType="application/octet-stream")]
        private var GarageAsset:Class;
    
        private var garageMesh:Mesh;
        private var floorMesh:Mesh;
        private var floorShadowMesh:Mesh;
    
        public function Garage(param1:DirectionalLight = null)
        {
            var floorMapTexture:BitmapTexture = new BitmapTexture(new this.FloorMapAsset().bitmapData);
            var floorMap:TextureMaterial = new TextureMaterial(floorMapTexture, true, true);//贴图,平滑,重复
            floorMap.specular = 1;//反射
            floorMap.lightPicker = new StaticLightPicker([param1]);//贴图拾取灯光
            floorMap.diffuseMethod = new TerrainDiffuseMethod([floorMapTexture], new BitmapTexture(new this.FloorShadowMapAsset().bitmapData), [10]);//为地面贴图添加凹凸贴图
            
            var floorShadow:TextureMaterial = new TextureMaterial(new BitmapTexture(new this.FloorShadowMapAsset().bitmapData));//创建影子贴图png
            floorShadow.alpha = 0.9;
            
            this.floorMesh = new Mesh(new PlaneGeometry(3800, 3800), floorMap);//创建地面面片,贴上上面生成的地面贴图
            this.floorMesh.y = -238;
            this.floorMesh.rotationY = -95;
            this.floorShadowMesh = new Mesh(new PlaneGeometry(3800, 3800), floorShadow);//创建影子面片,贴上影子贴图png
            this.floorShadowMesh.y = -237;//影子面片放置于地面面片之上
            this.floorShadowMesh.rotationY = -95;
            
            var garageLoader:Loader3D = new Loader3D();//实例模型加载器
            garageLoader.addEventListener(AssetEvent.ASSET_COMPLETE, this.complete);
            garageLoader.loadData(new this.GarageAsset(), null, null);
            super.addChildren(this.floorMesh, this.floorShadowMesh);
        }
    
        private function complete(event:AssetEvent):void
        {
            if (event.asset.assetType == AssetType.MESH)
            {
                garageMesh = event.asset as Mesh;//将模型转换成面片
                garageMesh.material = new TextureMaterial(new BitmapTexture(new this.GarageMapAsset().bitmapData), true);//为加载进来的模型上贴图
                garageMesh.roll(180);//绕着旋转180度
                garageMesh.geometry.scale(3);
                super.addChild(this.garageMesh);
                super.y = 188;
            }
        }
    
    }
    }

     2.摄像机控制 OrbitControllerExtended.as

    其实摄像机控制就是我之前整理的

    away3d 4.0.9Gold 学习笔记 摄像机与摄像机控制器(7)

    这里我就在看看这个类中的用法,再做一次总结

    OrbitControllerExtended.as

    package controllers
    {
    import away3d.cameras.*;
    import away3d.containers.*;
    import away3d.controllers.*;
    import flash.display.*;
    import flash.events.*;
    
    public class OrbitControllerExtended extends Object
    {
        private var _camera:Camera3D;
        private var _stage:DisplayObject;
        private var _target:ObjectContainer3D;
        private var isMouseDown:Boolean = false;
        private var lastPanAngle:Number;
        private var lastTiltAngle:Number;
        private var lastMouseX:Number;
        private var lastMouseY:Number;
        public var fov:Number = 800;
        public var mainController:HoverController;
        private var _activate:Boolean = true;
    
        public function OrbitControllerExtended(param1:Camera3D, param2:DisplayObject, param3:ObjectContainer3D = null)
        {
            this._camera = param1;
            this._stage = param2;
            this._target = param3;
            this.mainController = new HoverController(this._camera, this._target, 180, 20, this.fov, 0, 35, NaN, NaN, 6, 1);
        }
    
        public function set activate(param1:Boolean):void
        {
            this._activate = param1;
        }
    
        public function get activate():Boolean
        {
            return this._activate;
        }
    
        private function activateController(param1:Boolean):void
        {
            if (param1)
            {
                this._stage.addEventListener(MouseEvent.MOUSE_DOWN, this.stageMouseDown);
                this._stage.addEventListener(MouseEvent.MOUSE_UP, this.stageMouseUp);
                this._stage.addEventListener(MouseEvent.MOUSE_WHEEL, this.stageMouseWheel);
            }
            else
            {
                this._stage.removeEventListener(MouseEvent.MOUSE_DOWN, this.stageMouseDown);
                this._stage.removeEventListener(MouseEvent.MOUSE_UP, this.stageMouseUp);
                this._stage.removeEventListener(MouseEvent.MOUSE_WHEEL, this.stageMouseWheel);
            }
        }
    
        private function stageMouseDown(event:MouseEvent):void
        {
            this.lastPanAngle = this.mainController.panAngle;
            this.lastTiltAngle = this.mainController.tiltAngle;
            this.lastMouseX = this._stage.mouseX;
            this.lastMouseY = this._stage.mouseY;
            this.isMouseDown = true;
        }
    
        private function stageMouseUp(event:MouseEvent):void
        {
            this.isMouseDown = false;
        }
    
        private function stageMouseWheel(event:MouseEvent):void
        {
            var value:Number = this.fov - event.delta / 0.5;
            if (value < 590)
            {
                value = 590;
            }
            if (value > 950)
            {
                value = 950;
            }
            this.fov = value;
        }
    
        public function update():void
        {
            if (this._activate)
            {
                this.activateController(true);
                this.mainController.update();
                this.mainController.distance = this.mainController.distance + (this.fov - this.mainController.distance) / 8;
                if (this.isMouseDown)
                {
                    this.mainController.panAngle = 0.3 * (this._stage.mouseX - this.lastMouseX) + this.lastPanAngle;
                    this.mainController.tiltAngle = 0.3 * (this._stage.mouseY - this.lastMouseY) + this.lastTiltAngle;
                }
            }
            else
            {
                this.activateController(false);
            }
        }
    
    }
    }

     3.车的 创建

    4.如何用4.1版本的动态反射用于此案例

  • 相关阅读:
    java基础部分的一些有意思的东西。
    antdvue按需加载插件babelpluginimport报错
    阿超的烦恼 javaScript篇
    .NET E F(Entity Framework)框架 DataBase First 和 Code First 简单用法。
    JQuery获得input ID相同但是type不同的方法
    gridview的删除,修改,数据绑定处理
    jgGrid数据格式
    Cannot read configuration file due to insufficient permissions
    Invoke action which type of result is JsonResult on controller from view using Ajax or geJSon
    Entity model数据库连接
  • 原文地址:https://www.cnblogs.com/bulolo/p/2797737.html
Copyright © 2011-2022 走看看