away3d 4.0加载obj文件

三维网站 everyinch 2580℃ 0评论

本例使用了7个建筑模型,其中包括哈尔滨的经典建筑:防洪纪念塔和索菲亚教堂。当然建筑的安排并没有按照实际的位置来做,而是将防洪纪念塔放置到最右侧,索菲亚教堂在最左侧。

试用了LoaderMax来加载资源:

var queue:LoaderMax = new LoaderMax({name:"main",autoDispose:false,onProgress:onProgressHandler,onComplete:onCompleteHandler,onError:onErrorHandler});
dataLoader = new DataLoader("arch1/arch1.obj",{name:"arch1",format:"text"})
queue.append(dataLoader);
imageLoader = new ImageLoader("arch1/arch1-map.jpg",{name:"arch1-map"})
queue.append(imageLoader);
imageLoader = new ImageLoader("arch1/arch1-specular.jpg",{name:"arch1-specular"})
queue.append(imageLoader);
imageLoader = new ImageLoader("arch1/arch1-normal.jpg",{name:"arch1-normal"})
queue.append(imageLoader);

使用自定义的loadModel函数来加载模型:

private function loadModel(name:String):void{
  _material = new TextureMaterial(new BitmapTexture(ContentDisplay(LoaderMax.getContent(name+"-map")).rawContent.bitmapData));
  _material.normalMap = new BitmapTexture(ContentDisplay(LoaderMax.getContent(name+"-normal")).rawContent.bitmapData);
  _material.specularMap = new BitmapTexture(ContentDisplay(LoaderMax.getContent(name+"-specular")).rawContent.bitmapData);
  _material.lightPicker = _lightPicker;
  _material.gloss = 10;
  _material.specular = 1;
  _material.ambientColor = 0x303040;
  _material.ambient = 1;
  subsurfaceMethod = new SubsurfaceScatteringDiffuseMethod(2048, 2);
  subsurfaceMethod.scatterColor = 0xff7733;
  subsurfaceMethod.scattering = 0.05;
  subsurfaceMethod.translucency = 4;
  _material.diffuseMethod = subsurfaceMethod;</code>

  fresnelMethod = new FresnelSpecularMethod(true);
  _material.specularMethod = fresnelMethod;
  _material.diffuseMethod = new BasicDiffuseMethod();
  _material.specularMethod = new BasicSpecularMethod();

  Parsers.enableAllBundled();
  AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE,onAssetComplete);
  AssetLibrary.loadData(LoaderMax.getContent(name));
}

正面效果:

背面的效果:

从索菲亚教堂看过去:



转载请注明:陈童的博客 » away3d 4.0加载obj文件

喜欢 (1)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

无觅相关文章插件,快速提升流量