• Away3D 学习笔记(一): 加载3DS格式的模型文件


    加载外部的3DS文件分为两种: 

      1: 模型与贴图独立于程序的,也就是从外部的文件夹中读取 

    1 private function load3DSFile():Loader3D
    2         {
    3             loader = new Loader3D();
    4             loader.addEventListener(LoaderEvent.RESOURCE_COMPLETE,onLoadComplete);
    5             loader.addEventListener(AssetEvent.ASSET_COMPLETE,onAssetComplete);
    6             loader.load(new URLRequest("files/printer.3DS"),null,null,new Max3DSParser());
    7             return loader;
    8         }

      这种情况可以将导入的模型做为一个空的Object的以物体名命名的属性的值,这样,方便我们去调用这个模型,并且这种情况下3DS文件与贴图文件在一个文件夹中,不需要使用AssetLoaderContext.直接Loader这个模型,贴图就跟着进来了.

      

     1 // var meshs:Object = new Object();
     2 
     3 protected function onAssetComplete(event:AssetEvent):void
     4         {
     5             if(event.asset.assetType == AssetType.MESH) {
     6                 // add loaded object to meshs, to easy find it.
     7                 meshs[event.asset.name] = event.asset;
     8             }
     9         }
    10 // 之后就可以这样去调用了: meshs.printer.rotationY++;

      2: 模型与贴图以Embed形式,嵌入应该程序中的

      因为此时,模型与贴图都嵌入在应用程序中,所以在载入的时候使用LoadData(载入已嵌入的数据),也需要使用AssetLoaderContext类去重新映射原3DS文件中的贴图,由路径映射为Data数据.

      

     1         private function load3DSFileEmbed():void
     2         {
     3             // 使用 AssetLoaderContext,映射3DS中的贴图路径与已嵌入的图版的Data数据.
     4             var context:AssetLoaderContext = new AssetLoaderContext();
     5             context.mapUrlToData("PRINTERV.JPG",new printerMap());
     6             
     7             // 创建一个Loader3D
     8             loader = new Loader3D();
     9             // 载入每一个素材后,如Texture,Material,Mesh,Geometry等.
    10             loader.addEventListener(AssetEvent.ASSET_COMPLETE,onAssetComplete2);
    11             // 所以的素材全部载入后.
    12             loader.addEventListener(LoaderEvent.RESOURCE_COMPLETE,onResComplete);
    13             // 开始载入.1:模型数据 2:AsssetLoaderContext 3,Null 4:模型文件解析器
    14             loader.loadData(new printerModel(),context,null,new Max3DSParser());
    15         }
  • 相关阅读:
    2008俱乐部高校行之中南民族大学
    [更新]MSDN中Webcast "WPF中的图形系统系列" 课程预告及反馈
    7月20日 武汉.NET俱乐部在线沙龙!
    2007武汉.NET俱乐部沙龙VS2008、WPF、Silverlight
    MSDN新年第一次WebCast总结
    [评]Microsoft Visual Web Developer 2008 Step by Step, Express Edition
    [老爸创作的歌词]我从瓦砾中站起
    [Expert MS IL Assembler]武汉.NET俱乐部在线沙龙与线下聚会
    2008开年大礼:《Application = Code + Markup》中文版面世
    2009武汉.NET俱乐部活动之黄冈站
  • 原文地址:https://www.cnblogs.com/easyfrog/p/3730904.html
Copyright © 2020-2023  润新知