|
@@ -1,7 +1,7 @@
|
|
|
package h3d.prim;
|
|
|
import h3d.col.Point;
|
|
|
|
|
|
-class Polygon extends Primitive {
|
|
|
+class Polygon extends MeshPrimitive {
|
|
|
|
|
|
public var points : Array<Point>;
|
|
|
public var normals : Array<Point>;
|
|
@@ -30,14 +30,28 @@ class Polygon extends Primitive {
|
|
|
dispose();
|
|
|
|
|
|
var size = 3;
|
|
|
- if( normals != null )
|
|
|
+ var names = ["position"];
|
|
|
+ var positions = [0];
|
|
|
+ if( normals != null ) {
|
|
|
+ names.push("normal");
|
|
|
+ positions.push(size);
|
|
|
size += 3;
|
|
|
- if( tangents != null )
|
|
|
+ }
|
|
|
+ if( tangents != null ) {
|
|
|
+ names.push("tangent");
|
|
|
+ positions.push(size);
|
|
|
size += 3;
|
|
|
- if( uvs != null )
|
|
|
+ }
|
|
|
+ if( uvs != null ) {
|
|
|
+ names.push("uv");
|
|
|
+ positions.push(size);
|
|
|
size += 2;
|
|
|
- if( colors != null )
|
|
|
+ }
|
|
|
+ if( colors != null ) {
|
|
|
+ names.push("color");
|
|
|
+ positions.push(size);
|
|
|
size += 3;
|
|
|
+ }
|
|
|
|
|
|
var buf = new hxd.FloatBuffer();
|
|
|
for( k in 0...points.length ) {
|
|
@@ -74,6 +88,9 @@ class Polygon extends Primitive {
|
|
|
if( normals == null || tangents != null ) flags.push(RawFormat);
|
|
|
buffer = h3d.Buffer.ofFloats(buf, size, flags);
|
|
|
|
|
|
+ for( i in 0...names.length )
|
|
|
+ addBuffer(names[i], buffer, positions[i]);
|
|
|
+
|
|
|
if( idx != null )
|
|
|
indexes = h3d.Indexes.alloc(idx);
|
|
|
}
|
|
@@ -256,6 +273,18 @@ class Polygon extends Primitive {
|
|
|
return poly;
|
|
|
}
|
|
|
|
|
|
+ override function render( engine : h3d.Engine ) {
|
|
|
+ if( buffer == null || buffer.isDisposed() )
|
|
|
+ alloc(engine);
|
|
|
+ var bufs = getBuffers(engine);
|
|
|
+ if( indexes != null )
|
|
|
+ engine.renderMultiBuffers(bufs, indexes);
|
|
|
+ else if( buffer.flags.has(Quads) )
|
|
|
+ engine.renderMultiBuffers(bufs, engine.mem.quadIndexes, 0, triCount());
|
|
|
+ else
|
|
|
+ engine.renderMultiBuffers(bufs, engine.mem.triIndexes, 0, triCount());
|
|
|
+ }
|
|
|
+
|
|
|
#if hxbit
|
|
|
override function customSerialize(ctx:hxbit.Serializer) {
|
|
|
ctx.addInt(points.length);
|