Hi. I have a small problem with texturing polygon created from subgeometries.
My code :(argument array is array of points which are vertexes of the polygon in 2d)
public function drawFloor(tab:Array):Mesh {
var triangles:Array = EarCutting.cut(tab);
var segments:Array = EarCutting.buildSegments(tab);
var s:Segment;
var vertices:Vector.<Number> = new Vector.<Number>;
var indices:Vector.<uint> = new Vector.<uint>;
var uvs:Vector.<Number> = new Vector.<Number>;
var t:Triangle;
var count:uint = 0;
for each( t in triangles ){
indices.push(count,++count,++count);
vertices.push(t.p0.y, 0, t.p0.x, t.p1.y, 0, t.p1.x, t.p2.y, 0, t.p2.x);
count++;
}
var _numUvs:uint = (triangles.length * 2) + (segments.length * 2);
for(var i:uint = 0; i < _numUvs; i++){
uvs.push(0, 0, 0, 0, 1, 1);
}
var subGeometry:SubGeometry = new SubGeometry();
subGeometry.updateVertexData(vertices);
subGeometry.updateUVData(uvs);
subGeometry.updateIndexData(indices);
subGeometry.autoDeriveVertexTangents = true;
subGeometry.autoDeriveVertexNormals = true;
var colorMaterial:TextureMaterial = new TextureMaterial(Cast.bitmapTexture(new TestPodloga),true,true)
colorMaterial.bothSides = true
colorMaterial.repeat = true
var geometry:Geometry = new Geometry();
geometry.addSubGeometry(subGeometry);
var mesh:Mesh = MeshHelper.build(vertices, indices, uvs, "floor", colorMaterial, true, false);
mesh.mouseEnabled = true
mesh.addEventListener(MouseEvent3D.MOUSE_DOWN, klik_floor)
mesh.name = "floor"
return mesh
}
It draws polygon well, but texture is bad (left picture)
How can i get it right - like on the right side of the picture?
Is it possible in away3d 4 ?