Flash3D 编程技巧:无缝连接的地形展示(Away3D Lite)

1. 通过一个3DS模型,创建并复制出2个相同的地形模型

var max3ds:Max3DS = new Max3DS();
var container:ObjectContainer3D = max3ds.parseGeometry(new Terrain()) as ObjectContainer3D;
terrain1 = container.getChildAt(0) as Mesh;
terrain1.material = new BitmapMaterial(Cast.bitmap(TerrainTex));
terrain1.rotationX = -90;
terrain1.y = 500;	
terrain1.scaleZ = 0.5;

// 复制地形,terrain1的所有属性都将copy到terrain2		
terrain2 = terrain1.clone() as Mesh;
terrain2.z = 1000;

 

2. 关键:循环移动(为什么需要两个一样的terrain?)

// 到达-1000的临界点的时候,摄像机视角范围必须在其中一个z属性值较低的terrain之内,否则将出现terrain的跳转现象
override protected function onPreRender():void
{ 
	terrain1.z -= 10;
	if (terrain1.z <= -1000)
		terrain1.z = 1000;
		
	terrain2.z -= 10;
	if (terrain2.z <= -1000)
		terrain2.z = 1000;
}
 

你可能感兴趣的:(编程)