, Jr. Member
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=0; i<=quads; i++) {
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);