Here is my code:
package terrain
{
import away3d.containers.ObjectContainer3D;
import away3d.core.base.SubGeometry;
import away3d.core.base.SubMesh;
import away3d.entities.Mesh;
import away3d.materials.ColorMaterial;
import away3d.materials.MaterialBase;
import awayphysics.collision.shapes.AWPCollisionShape;
import awayphysics.collision.shapes.AWPCompoundShape;
import awayphysics.dynamics.AWPRigidBody;
import flash.geom.Matrix3D;
import flash.geom.Vector3D;
/**
* ...
* @author liu yi
*/
public class TerrainTile extends ObjectContainer3D
{
protected var _normalAreaList:Vector.<uint>;
protected var _restrictedAreaList:Vector.<uint>;//only store reference.
protected var _mesh:Mesh;
protected var _shape:AWPCompoundShape;
protected var _rigidbody:AWPRigidBody;
protected var _width:Number;
protected var _height:Number;
public var showRestrictedArea:Boolean;
public var material:MaterialBase
public var restrictedAreaMaterial:MaterialBase
public var neighbour:Vector.<uint>//for this game, just need know ,[0]=front,[2]=right,[4]=back
/*
* the frist child subMesh is ground, others are restricted area;
* */
public function TerrainTile(width:Number=100,height:Number=100)
{
_mesh = new Mesh();
_restrictedAreaList = new Vector.<uint>();
_normalAreaList = new Vector.<uint>();
_shape = new AWPCompoundShape();
_rigidbody = new AWPRigidBody(_shape,_mesh);
addChild(_mesh);
_width = width;
_height = _height;
neighbour = new Vector.<uint>(8);
}
public function addNormalArea(subGeo:SubGeometry,shape:AWPCollisionShape=null,mat:MaterialBase=null,localPos:Vector3D=null, localRot:Matrix3D=null):void {
_mesh.geometry.addSubGeometry(subGeo);
_normalAreaList.push(_mesh.numChildren - 1);
if (mat != null) _mesh.subMeshes[_mesh.subMeshes.length-1].material = mat;
else if(material!=null) _mesh.subMeshes[_mesh.subMeshes.length-1].material = material;
if(shape!=null) updateRigidbody(shape,localPos,localRot);
}
public function addRestrictedArea(subGeo:SubGeometry,shape:AWPCollisionShape, localPos:Vector3D, localRot:Matrix3D,mat:MaterialBase=null):void {
_mesh.geometry.addSubGeometry(subGeo);
_restrictedAreaList.push(_mesh.numChildren - 1);
if (mat != null) _mesh.subMeshes[_mesh.subMeshes.length-1].material = mat;
else if(restrictedAreaMaterial!=null) _mesh.subMeshes[_mesh.subMeshes.length-1].material = restrictedAreaMaterial;
if(shape!=null) updateRigidbody(shape,localPos,localRot);
}
public function get width():Number {
return _width;
}
public function get height():Number {
return _height;
}
public function get mesh():Mesh {
return _mesh;
}
public function get shape():AWPCompoundShape {
return _shape;
}
public function get rigidbody():AWPRigidBody {
return _rigidbody
}
public function set rigidbody(rigidbody:AWPRigidBody):void {
_rigidbody=rigidbody
}
protected function updateRigidbody(shape:AWPCollisionShape, localPos:Vector3D, localRot:Matrix3D):void {
_shape.addChildShape(shape, localPos, localRot);
}
}
}
here is my example( no light for ground: http://www.ourbrander.com/sites/ourbrander.com/demo/race/
you can save this class and add some submeshes, apply lights to materail
you will see this bug.
I checked all my code, no incorrect code.
If you think this is not a bug, please tell where I need fixed.
Thanks!