`
sjkgxf7191
  • 浏览: 257814 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Away3D Lite:Basic_LoadModel

UP 
阅读更多

开启Debug模式:具体什么作用,尚不知

// Class for emmiting debuging messages, warnings and errors.
Debug.active = true;

 

引入外部文件创建材质:

[Embed(source="assets/fskingr.jpg")]
private var GreenPaint:Class;

//ferrari texture
[Embed(source="assets/fskin.jpg")]
private var RedPaint:Class;
		
//ferrari texture
[Embed(source="assets/fskiny.jpg")]
private var YellowPaint:Class;
		
//ferrari texture
[Embed(source="assets/fsking.jpg")]
private var GreyPaint:Class;

// Cast: Helper class for casting assets to usable objects
materialArray = [Cast.material(GreenPaint), Cast.material(RedPaint), Cast.material(YellowPaint), Cast.material(GreyPaint)];

 

创建一个ObjectContainer3D对象和Max3DS对象并赋值:

// Max3DS:File loader for the 3DS file format.
// 仅仅关联到该加载3DS文件,不能直接呈现到scene中去,也没有各种rotation动作
private var max3ds:Max3DS;

// Loader3D:Abstract loader class used as a placeholder for loading 3d content
// 3D内容的加载器
private var loader:Loader3D;

 // 3d object container node for other 3d objects in a scene.
// 真正展示到场景中的对象,loader加载成功后会对其赋值
private var model:ObjectContainer3D;

max3ds = new Max3DS();
max3ds.scaling = 100;
// Controls the automatic centering of geometry data in the model, improving culling and the accuracy of bounding dimension values.
// 优化,精确的属性,不设置为true的话,模型可能会出现异常,例如部件错位
max3ds.centerMeshes = true;
// Overrides all materials in the model.
// 模型所用到的材质
max3ds.material = materialArray[materialIndex];

loader = new Loader3D();
loader.addEventListener(Loader3DEvent.LOAD_SUCCESS, onSuccess);
// Loads and parses a 3d file format.
// 加载解析3DS文件,加载成功,调用onSuccess函数继续处理
loader.loadGeometry("assets/f360.3ds", max3ds);

// 加载模型到场景中去,onSuccess函数里调用scene.addChild(model);亦可
scene.addChild(loader);

private function onSuccess(event:Event):void
{
    // loader.handle:Returns a 3d object relating to the currently visible model.
    // 给model赋值
	model = loader.handle as ObjectContainer3D;
	
	model.rotationX = -90;
	
	model.addEventListener(MouseEvent3D.MOUSE_UP, onClickModel);
}
 

点击model改变材质:

model.materialLibrary.getMaterial("fskin").material = materialArray[materialIndex];
 

旋转模型的子模型(轮胎):

if (model) {
	for each (var object:Object3D in model.children) {
		if (object.name.indexOf("wheel") != -1)
			object.rotationX += 10;
	}
}
 

从这个example里就可以看出away3d同pv3d的不同之处了,away3d在加载使用外部模型的时候确实没有pv3d这么简便


  • 大小: 129 KB
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics