Shading is lost after modifying mesh?

Software: Away3D 4.x

Rajneesh, Jr. Member
Posted: 24 January 2014 09:04 AM   Total Posts: 34

Hi, I plotted 3d sine wave by modifying plane’s vertices as shown below. But, after modifying the plane, its shading (gloss) is lost,

public function sineWave() {

   
var vertices:Vector.<Number> = planeMesh.geometry.subGeometries[0].vertexData;
         
   for ( var 
i:int 0vertices.length+= 13 )
   
{
    
var x:Number vertices[i];
    var 
y:Number vertices[i 1];
    var 
z:Number vertices[i 2];
     
    
vertices[i+1]  Math.sin(z*Math.PI/180 6)*30;    
    
   
}  
   CompactSubGeometry
(planeMesh.geometry.subGeometries[0]).updateData(vertices);
        

Here is a code for material,

private function initMaterials():void
  {
   planeMaterial 
= new ColorMaterial(0x00FFFF);
   
planeMaterial.specular 0.5;
   
planeMaterial.gloss 20;
   
planeMaterial.lightPicker lightPicker;
      
   
planeMesh.material planeMaterial;
  

What is happening here? Please guide me?

Thanks

   

Avatar
theMightyAtom, Sr. Member
Posted: 24 January 2014 10:28 AM   Total Posts: 669   [ # 1 ]

Perhaps because you are updating the vertices, but not the normals?
Have you tried omitting the CompactSubGeometry?

To test, you could also re-apply the material after the manipulation, but I’m quite sure it won’t have changed, but might appear to have no gloss because of messed up normals.

Btw, that’s all guess work, have never used the CompactSubGeometry call.

Good Luck!

   

Rajneesh, Jr. Member
Posted: 24 January 2014 10:41 AM   Total Posts: 34   [ # 2 ]

Thanks, theMightyAtom.

BTW, How to update normals? Can you help please?

I have tried without CompactSubGeometry and the result is same.

   

Avatar
theMightyAtom, Sr. Member
Posted: 24 January 2014 11:03 AM   Total Posts: 669   [ # 3 ]

Try setting..

mesh.geometry.subGeometries[0].autoDeriveVertexNormals true;
mesh.geometry.subGeometries[0].autoDeriveVertexTangents true
   

Rajneesh, Jr. Member
Posted: 24 January 2014 11:30 AM   Total Posts: 34   [ # 4 ]

Wow shock

Great theMightyAtom. Thanks it worked for CompactSubGeometry.


But it is not working if i do it with SubGeometry,

geometry = new Geometry();
var 
subgeometry:SubGeometry = new SubGeometry();

subgeometry.autoDeriveVertexNormals true;
subgeometry.autoDeriveVertexTangents true
   

Avatar
theMightyAtom, Sr. Member
Posted: 24 January 2014 11:50 AM   Total Posts: 669   [ # 5 ]

In your example code there’s no normals to calculate.

   

Rajneesh, Jr. Member
Posted: 31 January 2014 10:21 AM   Total Posts: 34   [ # 6 ]

Here’s how I am adding vertices, uvs and indices to the geometry, but

subgeometry.autoDeriveVertexNormals true;
   
subgeometry.autoDeriveVertexTangents true

doesn’t work with this approach,

// create the geometry
            
geometry = new Geometry();
            var 
subgeometry:SubGeometry = new SubGeometry();
            
// A list of vertex positions
            
var verts:Vector.<Number> = new Vector.<Number>();
            
// A list of UV coordinates
            
var uvs:Vector.<Number> = new Vector.<Number>();
            
// A list of indices - whole, positive numbers
            
var indices:Vector.<uint> = new Vector.<uint>();
   
   
// A few optional constants to simplify the look of the code
            
const TOP:Number height/2// top of the flag
            
const LEFT:Number = -width/2// left edge of the flag (centered)
            
const X_STEP:Number width/quads// width of each quad
            
const NUM_WAVES:uint=6;
            const 
RADS:Number=Math.PI*2*NUM_WAVES;
            const 
WAVE_POWER:Number=10;
   
   const 
radius:int 5;
   
   
// Populate all lists in a loop
            
for (var i:int=0i<=quadsi++) {
            
    
if (i>0{
                    
// Temporarily double i because we have 2 verts per step
                    
i*=2;
                    
// 'clockwise' polygons
                   
indices.push(i-2,i,i-1,i-1,i,i+1);
                    
// 'anti-clockwise' polygons
                   
indices.push(i-2,i-1,i,i-1,i+1,i);
                    
// Half i to return it to normal
                    
i/=2;
                
}
    
    
/*
     x=r sinu cosv 
     y=r cosu cosv 
     z=r sinv 
 
     r is the radius. 
     u ranges over a full circle, while
     v ranges from -pi/2 to pi/2. 
     If you consider a globe, u corresponds to longitude and v corresponds to latitude.
    */    
    
    // Calculate the Z-position as a sine wave
                
var zPos:Number=Math.sin(i/quads*RADS)*WAVE_POWER;
                
verts.push(LEFT+X_STEP*i,TOP,zPos); // top vert
                
uvs.push(i/quads,0); // top vert UVs
                
verts.push(LEFT+X_STEP*i,TOP-height,zPos); // bottom vert
                
uvs.push(i/quads,1); // bottom vert UVs
                // If i is bigger than 0, we can start connecting verts
                
if (i>0{
                    
// Temporarily double i because we have 2 verts per step
                    
i*=2;
                    
// 'clockwise' polygons
                   
indices.push(i-2,i,i-1,i-1,i,i+1);
                    
// 'anti-clockwise' polygons
                   
indices.push(i-2,i-1,i,i-1,i+1,i);
                    
// Half i to return it to normal
                    
i/=2;
                
}
            }
            
   subgeometry
.autoDeriveVertexNormals true;
   
subgeometry.autoDeriveVertexTangents true;
   
   
// Update the subgeometry with the verts, uvs and indices
            
subgeometry.updateVertexData(verts);
            
subgeometry.updateUVData(uvs);
            
subgeometry.updateIndexData(indices);
            
geometry.addSubGeometry(subgeometry); 
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X