DelaunayMesh with 3 sides turns all black with normalMap

Software: Away3D 4.x

Tayyab, Member
Posted: 17 September 2012 11:46 PM   Total Posts: 72

hi away3d forum,

I wanted to ask y does a DelaunayMesh with 3 sides shows all black when i put in a normalMap image. it works fine with a specular image. the same texture works fine on LinearExtrudes and cube meshes. what am i doing wrong here?

// Create a path for the front Triangle
var frontTrianglePath:Vector.<Vector3D> = Vector.<Vector3D>([
LEFT_TOP_FRONT
,
ROOF_TOP_FRONT,
RIGHT_TOP_FRONT
]
);
               
// Create the Triangle Meshes
frontTriangleMesh = new DelaunayMesh(GVC.initialColorMaterialfrontTrianglePath);
frontTriangleMesh.geometry.scaleUV(scaleUVsscaleUVs); 

and here is how I am generating the texture:

/**
 * 
 * @param imageClass: Embed Image Class
 * @param animateUVs: to help the roof to rotate the UVs so that the texture is 90 degrees rotated
 * @return
 */
public static function generateMaterialdiffuseBitmapClass:Class, animateUVs:Boolean falsenormalBitmapClass:Class = nullspecularBitmapClass:Class = null ): TextureMaterial
{
 
var textureMaterial:TextureMaterial = new TextureMaterial( new BitmapTexture( new diffuseBitmapClass().bitmapData ) );
 if (
normalBitmapClass != null)
  
textureMaterial.normalMap =  Cast.bitmapTexture(normalBitmapClass);
  
//textureMaterial.normalMap =  Cast.bitmapTexture(CUSTOM_ORB_AXIS_NRM);
 
if (specularBitmapClass != null)
  
textureMaterial.specularMap =  Cast.bitmapTexture(CUSTOM_ORB_AXIS_SPEC);
 
textureMaterial.repeat true;
 
textureMaterial.smooth true;
 
 
// turned animateUVs to false because of:
 // Warning: animateUVs is set to true with an IRenderable without a uvTransform. Identity matrix assumed.
 // the trace is at away3d/materials/passes/DefaultScreenPass.as at line 531.
 
textureMaterial.animateUVs animateUVs;
  
 
textureMaterial.mipmap false;
 
textureMaterial.lightPicker GVC.lightPicker;
 
textureMaterial.bothSides true;
 return 
textureMaterial;

 

 

   

Tayyab, Member
Posted: 17 September 2012 11:48 PM   Total Posts: 72   [ # 1 ]

UPDATE: when i disable:

frontTriangleMesh.geometry.scaleUV(scaleUVsscaleUVs); 

the texture shows up but i actually want to scale the UVs.

   

Avatar
Fabrice Closier, Administrator
Posted: 18 September 2012 08:13 AM   Total Posts: 1265   [ # 2 ]

To avoid the error: make sure that you define the material properties,  & subgeometry uv scale prior render.

   

Tayyab, Member
Posted: 18 September 2012 08:18 AM   Total Posts: 72   [ # 3 ]

Thanx fabrics, but my textures are created dynamically. And they can be changed through my UI menu.

   

Avatar
Fabrice Closier, Administrator
Posted: 18 September 2012 12:33 PM   Total Posts: 1265   [ # 4 ]

There is no problem with that. You need to set material/geometry uv changes into the same handler.  Now you probably have a render in between causing the error.

   

Tayyab, Member
Posted: 18 September 2012 12:46 PM   Total Posts: 72   [ # 5 ]

I am doing a render on onEnterFrame. How will I handle this?

   

Avatar
Fabrice Closier, Administrator
Posted: 18 September 2012 01:47 PM   Total Posts: 1265   [ # 6 ]

You probably missunderstood me. I mean that the first time that you do declare a mesh, alter its uv’s and declare a material, that you must addchild it and render only once its done. If you render in between you will get this error. Updating the texture has no effect on material or subgeometry.

so if you have different methods for this. make sure it goes in this sequence.
function make material
set animateuvs
set repeat = true
updateMesh(thematerial)

function updatemesh(mat)
scaleuvs
mesh.material.mat

now you can add to scene and render.

 

   

Tayyab, Member
Posted: 18 September 2012 01:54 PM   Total Posts: 72   [ # 7 ]

My mesh is already added to scene when I apply the material… should I remove the mesh and add it again with the new material?

   

Avatar
Fabrice Closier, Administrator
Posted: 18 September 2012 06:00 PM   Total Posts: 1265   [ # 8 ]

Have you tried the above? Again, it’s not about where the mesh is.
It’s about applying the uvscaling and material properties before or after a render. But not render in between the two, till all is correctly set up.

   

Tayyab, Member
Posted: 19 September 2012 02:08 AM   Total Posts: 72   [ # 9 ]

I am so sorry to be so much of a pain :(. thanx for all ur help thus far. I am just not able to understand ( sign of a newbie ) :S

view.render is on onEnterFrame when i initialize the Away3D engine.
I add the shed which contains: walls, roof and gutters meshes
walls consist of a LinearExtrude for the base and DelaunayMesh for the top triangle (which is causing error.)
it starts with a simple colorMaterial.
I add it to a class ActiveShed which contains: shed and its properties.
then i select a different textureMaterial from my menu.
then i call generateMaterial class to generate the material from the selected texture image.
then i call setTextureMaterial function of shed class to apply the materials to its walls, roof and gutters.

the scaleUVs are done when i create the shed object.is this the problem?
if yes then should i include scaleUVs in the generateMaterial function above? will i have to add that function to the shed class so that it can easily access that particular mesh in the shed?

In my shed class i have this function which assigns the materials to the shed:

public function setTextureMaterial(wallMaterial:MaterialBaseroofMaterial:MaterialBase):void 
{
 
if (wallMaterial == null)
 
{
  wallMaterial 
GVC.initialColorMaterial;
  
roofMaterial GVC.initialRoofColorMaterial;
 
}
 _roofMaterial 
roofMaterial;
 
_wallMaterial wallMaterial;
 
 
frontWall.material wallMaterial;
 
rightWall.material wallMaterial;
 
leftWall.material wallMaterial;
 
backWall.material wallMaterial;
 
frontTriangleMesh.material wallMaterial;
 
backTriangleMesh.material wallMaterial;
 
 
gutter.material roofMaterial;
 
roofTop.material roofMaterial;

I am saving that shed into another class which will save the properties and the container which contains all the meshes of the type of shed that i have created from the menu. I am applying the material to the already added to scene mesh:

//   roofTextureClass updates when clicked on refresh texture
ActiveShed._roofMaterial Textures.generateMaterial(roofTextureClasstruenormalMapClassspecularMapClass);
               
//   wallTextureClass updates when clicked on refresh texture
ActiveShed._wallMaterial Textures.generateMaterial(wallTextureClassfalsenormalMapClassspecularMapClass);
ActiveShed._shedModel.setTextureMaterialActiveShed._wallMaterialActiveShed._roofMaterial); 
   

Tayyab, Member
Posted: 19 September 2012 02:55 AM   Total Posts: 72   [ # 10 ]

I just created a simple DelaunayMesh Triangle for testing, here is the code:

var textureMaterial:TextureMaterial = new TextureMaterial( new BitmapTexture( new Textures.TRIMDEK_AXIS().bitmapData ) );
textureMaterial.normalMap =  Cast.bitmapTexture(Textures.TRIMDEK_NRM);
textureMaterial.specularMap =  Cast.bitmapTexture(Textures.TRIMDEK_SPEC);
textureMaterial.animateUVs false;
textureMaterial.repeat true;
textureMaterial.lightPicker GVC.lightPicker;
textureMaterial.bothSides true;

var 
frontTrianglePath:Vector.<Vector3D> = Vector.<Vector3D>([  new Vector3D(-10000),
new 
Vector3D(0500),
new 
Vector3D(10000)
]);
            
// Create the Triangle Meshe
var frontTriangleMesh:DelaunayMesh = new DelaunayMesh(textureMaterialfrontTrianglePath);
scene.addChild(frontTriangleMesh); 

but same issue, it is still black :( is the code still wrong? Also where will scaleUVs in this code? Could it be the Light? here is my light function:

/**
   * Initialise the lights
   */
  
protected function initLights():void
  {
   
//create a light for shadows that mimics the sun's position in the skybox
   
leftBackLight = new PointLight();
   
leftBackLight.= -3000;
   
leftBackLight.200;
   
leftBackLight.1400;
   
leftBackLight.color 0xfffce3;
   
leftBackLight.specular 0.4;
   
leftBackLight.diffuse 0.4;
   
scene.addChild(leftBackLight);

   
rightBackLight = new PointLight();
   
rightBackLight.3000;
   
rightBackLight.200;
   
rightBackLight.1400;
   
rightBackLight.color 0xfffce3;
   
rightBackLight.specular 0.4;
   
rightBackLight.diffuse 0.4;
   
scene.addChild(rightBackLight);

   
mainLight = new DirectionalLight(-100, -100100);
   
mainLight.color 0xfffce3;
   
mainLight.castsShadows true;
   
mainLight.ambient 1;
   
mainLight.ambientColor 0x303040;
   
mainLight.shadowMapper = new NearDirectionalShadowMapper(.2);
   
scene.addChild(mainLight);

   
lightPicker = new StaticLightPicker([leftBackLightrightBackLightmainLight]);


   
//create a global shadow method
   
shadowMapMethod = new NearShadowMapMethod(new FilteredShadowMapMethod(mainLight));
   
shadowMapMethod.epsilon .0003;
   
shadowMapMethod.alpha 0.4;
   
   
GVC.shadowMapMethod shadowMapMethod;

   
//create a global fog method
   
fogMethod = new FogMethod(0camera.lens.far 1.30x000000);
  
   

Tayyab, Member
Posted: 21 September 2012 01:19 AM   Total Posts: 72   [ # 11 ]

is there something wrong in my code ???

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X