RESOLVED: Apply lights to a mesh’s submesh.the mesh will become black.

Software: Away3D 4.x

liuyi, Member
Posted: 19 September 2011 12:41 PM   Total Posts: 65

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=nulllocalRot: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!=nullupdateRigidbody(shape,localPos,localRot);
  
}
  
  
public function addRestrictedArea(subGeo:SubGeometry,shape:AWPCollisionShapelocalPos:Vector3DlocalRot: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!=nullupdateRigidbody(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:AWPCollisionShapelocalPos:Vector3DlocalRot:Matrix3D):void {
   _shape
.addChildShape(shapelocalPoslocalRot);
   
  
}
  
  
  
  
  
  
  
 }

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!

 

 

   

Avatar
Alejandro Santander, Administrator
Posted: 20 September 2011 01:13 AM   Total Posts: 414   [ # 1 ]

Hey liuyi,

I’ve reduced what you are doing to the simplest scenario and did not find any bugs.

The following examples contains a sphere and a cube geometry added as sub-geometries to a cylinder primitive. I then accessed the sub-geometries and assigned new color materials to them using a point light: http://www.lidev.com.ar/tests/away3d/subgeom_test/

As far as I can see, everything works fine. Are you using the latest github source?

My code is:

var redMat:ColorMaterial = new ColorMaterial(0xFF0000);
   
redMat.lights [cameraPointLight];

   var 
greenMat:ColorMaterial = new ColorMaterial(0x00FF00);
   
greenMat.lights [cameraPointLight];

   var 
blueMat:ColorMaterial = new ColorMaterial(0x0000FF);
   
blueMat.lights [cameraPointLight];

   var 
cube:Cube = new Cube();
   var 
cubeGeometry:SubGeometry cube.geometry.subGeometries[0].clone();
   var 
translate:Matrix3D = new Matrix3D();
   
translate.appendTranslation(15000);
   
cubeGeometry.applyTransformation(translate);

   var 
sphere:Sphere = new Sphere();
   var 
sphereGeometry:SubGeometry sphere.geometry.subGeometries[0].clone();
   
translate = new Matrix3D();
   
translate.appendTranslation(-15000);
   
sphereGeometry.applyTransformation(translate);

   var 
r:Cylinder = new Cylinder(redMat);
   
r.geometry.addSubGeometry(cubeGeometry);
   
r.subMeshes[r.subMeshes.length 1].material greenMat;
   
r.geometry.addSubGeometry(sphereGeometry);
   
r.subMeshes[r.subMeshes.length 1].material blueMat;
   
r.scale(2);
   
view.scene.addChild(r); 
   

liuyi, Member
Posted: 20 September 2011 04:59 AM   Total Posts: 65   [ # 2 ]

I tested your example, works very well.
But have you try add a plane’s subgeometry to a mesh?

I tested that, and get this bug.

var p:Plane = new Plane(null100100100);
    var 
planeGeo:SubGeometry p.geometry.subGeometries[0];
  var 
btmapMat:BitmapMaterial = new BitmapMaterial(_textureManager.getTexture("stoneTexture"));
  
btmapMat.lights [_light];
  
btmapMat.bothSides true;

  var 
ms:Mesh = new Mesh();
  
ms.geometry.addSubGeometry(planeGeo);
   
ms.subMeshes[0].material btmapMat;
   
_view.scene.addChild(ms); 

 

   

liuyi, Member
Posted: 20 September 2011 06:31 AM   Total Posts: 65   [ # 3 ]

I test and test , and then found the reason:
_light = new DirectionalLight( 0, -1, 0);

When I changed it to :
_light = new DirectionalLight( 0.2, -1, 0.2);

issue fixed.

In my opinion, DirectionalLight( 0, -1, 0) means light face to the y axis’s inverse direction.
But why the ground can not be see?
anyway,it has resolved.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X