mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
fix > 65k verts
This commit is contained in:
parent
1706c16540
commit
c07083f400
2 changed files with 98 additions and 89 deletions
|
|
@ -581,12 +581,18 @@ class DifBuilder {
|
|||
}
|
||||
}
|
||||
}
|
||||
var mats = new Map<String, Array<DifBuilderTriangle>>();
|
||||
var mats = new Map<String, Array<Array<DifBuilderTriangle>>>();
|
||||
for (index => value in triangles) {
|
||||
if (mats.exists(value.texture)) {
|
||||
mats[value.texture].push(value);
|
||||
var arr = mats[value.texture];
|
||||
if (arr[arr.length - 1].length >= Math.floor(65535 / 3)) {
|
||||
var newArr = [value];
|
||||
arr.push(newArr);
|
||||
} else {
|
||||
mats.set(value.texture, [value]);
|
||||
arr[arr.length - 1].push(value);
|
||||
}
|
||||
} else {
|
||||
mats.set(value.texture, [[value]]);
|
||||
}
|
||||
}
|
||||
collider.finalize();
|
||||
|
|
@ -674,10 +680,10 @@ class DifBuilder {
|
|||
});
|
||||
|
||||
var prim = new Polygon();
|
||||
|
||||
var materials = [];
|
||||
|
||||
for (grp => tris in mats) {
|
||||
for (grp => trigroup in mats) {
|
||||
for (tris in trigroup) {
|
||||
var points = [];
|
||||
var normals = [];
|
||||
var uvs = [];
|
||||
|
|
@ -702,6 +708,13 @@ class DifBuilder {
|
|||
uvs.push(uv1);
|
||||
}
|
||||
|
||||
if (prim.vertexCount() + points.length > 65535) {
|
||||
prim.endPrimitive();
|
||||
var mesh = new MultiMaterial(prim, materials, itr);
|
||||
materials = [];
|
||||
prim = new Polygon();
|
||||
}
|
||||
|
||||
prim.addPoints(points);
|
||||
prim.addUVs(uvs);
|
||||
prim.addNormals(normals);
|
||||
|
|
@ -750,6 +763,7 @@ class DifBuilder {
|
|||
material.mainPass.wireframe = true;
|
||||
materials.push(material);
|
||||
}
|
||||
}
|
||||
|
||||
prim.endPrimitive();
|
||||
var mesh = new MultiMaterial(prim, materials, itr);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class Polygon extends MeshPrimitive {
|
|||
public var normals:Array<Float>;
|
||||
public var tangents:Array<Float>;
|
||||
public var uvs:Array<Float>;
|
||||
public var idx:hxd.IndexBuffer;
|
||||
|
||||
public var indexStarts:Array<Int>;
|
||||
public var indexCounts:Array<Int>;
|
||||
|
||||
|
|
@ -18,10 +18,9 @@ class Polygon extends MeshPrimitive {
|
|||
|
||||
var bounds:h3d.col.Bounds;
|
||||
|
||||
public function new(?idx) {
|
||||
public function new() {
|
||||
this.indexStarts = [0];
|
||||
this.indexCounts = [];
|
||||
this.idx = idx;
|
||||
this.points = [];
|
||||
this.uvs = [];
|
||||
this.normals = [];
|
||||
|
|
@ -121,7 +120,6 @@ class Polygon extends MeshPrimitive {
|
|||
}
|
||||
}
|
||||
var flags:Array<h3d.Buffer.BufferFlag> = [];
|
||||
if (idx == null)
|
||||
flags.push(Triangles);
|
||||
if (normals == null || tangents != null)
|
||||
flags.push(RawFormat);
|
||||
|
|
@ -130,8 +128,13 @@ class Polygon extends MeshPrimitive {
|
|||
for (i in 0...names.length)
|
||||
addBuffer(names[i], buffer, positions[i]);
|
||||
|
||||
if (idx != null)
|
||||
indexes = h3d.Indexes.alloc(idx);
|
||||
if (indexes == null && Std.int(points.length / 3) > 65535) {
|
||||
var indices = new haxe.io.BytesOutput();
|
||||
for (i in 0...Std.int(points.length / 3))
|
||||
indices.writeInt32(i);
|
||||
indexes = new h3d.Indexes(indices.length >> 2, true);
|
||||
indexes.uploadBytes(indices.getBytes(), 0, indices.length >> 2);
|
||||
}
|
||||
}
|
||||
|
||||
public function addTangents() {
|
||||
|
|
@ -141,15 +144,9 @@ class Polygon extends MeshPrimitive {
|
|||
var pos = 0;
|
||||
for (i in 0...triCount()) {
|
||||
var i0, i1, i2;
|
||||
if (idx == null) {
|
||||
i0 = pos++;
|
||||
i1 = pos++;
|
||||
i2 = pos++;
|
||||
} else {
|
||||
i0 = idx[pos++];
|
||||
i1 = idx[pos++];
|
||||
i2 = idx[pos++];
|
||||
}
|
||||
var p0 = new Vector(points[i0 * 3], points[i0 * 3 + 1], points[i0 * 3 + 2]);
|
||||
var p1 = new Vector(points[i1 * 3], points[i1 * 3 + 1], points[i1 * 3 + 2]);
|
||||
var p2 = new Vector(points[i2 * 3], points[i2 * 3 + 1], points[i2 * 3 + 2]);
|
||||
|
|
@ -192,7 +189,7 @@ class Polygon extends MeshPrimitive {
|
|||
var n = super.triCount();
|
||||
if (n != 0)
|
||||
return n;
|
||||
return Std.int((idx == null ? points.length / 3 : idx.length) / 3);
|
||||
return Std.int(points.length / 3);
|
||||
}
|
||||
|
||||
override function vertexCount() {
|
||||
|
|
@ -212,9 +209,7 @@ class Polygon extends MeshPrimitive {
|
|||
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());
|
||||
engine.renderMultiBuffers(bufs, indexes, indexStarts[currentMaterial], indexCounts[currentMaterial]);
|
||||
else
|
||||
engine.renderMultiBuffers(bufs, engine.mem.triIndexes, indexStarts[currentMaterial], indexCounts[currentMaterial]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue