mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-27 21:21:41 +00:00
fix > 65k verts
This commit is contained in:
parent
ef4d9b4861
commit
c033bb17e7
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) {
|
for (index => value in triangles) {
|
||||||
if (mats.exists(value.texture)) {
|
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 {
|
} else {
|
||||||
mats.set(value.texture, [value]);
|
arr[arr.length - 1].push(value);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mats.set(value.texture, [[value]]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
collider.finalize();
|
collider.finalize();
|
||||||
|
|
@ -674,10 +680,10 @@ class DifBuilder {
|
||||||
});
|
});
|
||||||
|
|
||||||
var prim = new Polygon();
|
var prim = new Polygon();
|
||||||
|
|
||||||
var materials = [];
|
var materials = [];
|
||||||
|
|
||||||
for (grp => tris in mats) {
|
for (grp => trigroup in mats) {
|
||||||
|
for (tris in trigroup) {
|
||||||
var points = [];
|
var points = [];
|
||||||
var normals = [];
|
var normals = [];
|
||||||
var uvs = [];
|
var uvs = [];
|
||||||
|
|
@ -702,6 +708,13 @@ class DifBuilder {
|
||||||
uvs.push(uv1);
|
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.addPoints(points);
|
||||||
prim.addUVs(uvs);
|
prim.addUVs(uvs);
|
||||||
prim.addNormals(normals);
|
prim.addNormals(normals);
|
||||||
|
|
@ -750,6 +763,7 @@ class DifBuilder {
|
||||||
material.mainPass.wireframe = true;
|
material.mainPass.wireframe = true;
|
||||||
materials.push(material);
|
materials.push(material);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
prim.endPrimitive();
|
prim.endPrimitive();
|
||||||
var mesh = new MultiMaterial(prim, materials, itr);
|
var mesh = new MultiMaterial(prim, materials, itr);
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ class Polygon extends MeshPrimitive {
|
||||||
public var normals:Array<Float>;
|
public var normals:Array<Float>;
|
||||||
public var tangents:Array<Float>;
|
public var tangents:Array<Float>;
|
||||||
public var uvs:Array<Float>;
|
public var uvs:Array<Float>;
|
||||||
public var idx:hxd.IndexBuffer;
|
|
||||||
public var indexStarts:Array<Int>;
|
public var indexStarts:Array<Int>;
|
||||||
public var indexCounts:Array<Int>;
|
public var indexCounts:Array<Int>;
|
||||||
|
|
||||||
|
|
@ -18,10 +18,9 @@ class Polygon extends MeshPrimitive {
|
||||||
|
|
||||||
var bounds:h3d.col.Bounds;
|
var bounds:h3d.col.Bounds;
|
||||||
|
|
||||||
public function new(?idx) {
|
public function new() {
|
||||||
this.indexStarts = [0];
|
this.indexStarts = [0];
|
||||||
this.indexCounts = [];
|
this.indexCounts = [];
|
||||||
this.idx = idx;
|
|
||||||
this.points = [];
|
this.points = [];
|
||||||
this.uvs = [];
|
this.uvs = [];
|
||||||
this.normals = [];
|
this.normals = [];
|
||||||
|
|
@ -121,7 +120,6 @@ class Polygon extends MeshPrimitive {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var flags:Array<h3d.Buffer.BufferFlag> = [];
|
var flags:Array<h3d.Buffer.BufferFlag> = [];
|
||||||
if (idx == null)
|
|
||||||
flags.push(Triangles);
|
flags.push(Triangles);
|
||||||
if (normals == null || tangents != null)
|
if (normals == null || tangents != null)
|
||||||
flags.push(RawFormat);
|
flags.push(RawFormat);
|
||||||
|
|
@ -130,8 +128,13 @@ class Polygon extends MeshPrimitive {
|
||||||
for (i in 0...names.length)
|
for (i in 0...names.length)
|
||||||
addBuffer(names[i], buffer, positions[i]);
|
addBuffer(names[i], buffer, positions[i]);
|
||||||
|
|
||||||
if (idx != null)
|
if (indexes == null && Std.int(points.length / 3) > 65535) {
|
||||||
indexes = h3d.Indexes.alloc(idx);
|
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() {
|
public function addTangents() {
|
||||||
|
|
@ -141,15 +144,9 @@ class Polygon extends MeshPrimitive {
|
||||||
var pos = 0;
|
var pos = 0;
|
||||||
for (i in 0...triCount()) {
|
for (i in 0...triCount()) {
|
||||||
var i0, i1, i2;
|
var i0, i1, i2;
|
||||||
if (idx == null) {
|
|
||||||
i0 = pos++;
|
i0 = pos++;
|
||||||
i1 = pos++;
|
i1 = pos++;
|
||||||
i2 = 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 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 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]);
|
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();
|
var n = super.triCount();
|
||||||
if (n != 0)
|
if (n != 0)
|
||||||
return n;
|
return n;
|
||||||
return Std.int((idx == null ? points.length / 3 : idx.length) / 3);
|
return Std.int(points.length / 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
override function vertexCount() {
|
override function vertexCount() {
|
||||||
|
|
@ -212,9 +209,7 @@ class Polygon extends MeshPrimitive {
|
||||||
alloc(engine);
|
alloc(engine);
|
||||||
var bufs = getBuffers(engine);
|
var bufs = getBuffers(engine);
|
||||||
if (indexes != null)
|
if (indexes != null)
|
||||||
engine.renderMultiBuffers(bufs, indexes);
|
engine.renderMultiBuffers(bufs, indexes, indexStarts[currentMaterial], indexCounts[currentMaterial]);
|
||||||
else if (buffer.flags.has(Quads))
|
|
||||||
engine.renderMultiBuffers(bufs, engine.mem.quadIndexes, 0, triCount());
|
|
||||||
else
|
else
|
||||||
engine.renderMultiBuffers(bufs, engine.mem.triIndexes, indexStarts[currentMaterial], indexCounts[currentMaterial]);
|
engine.renderMultiBuffers(bufs, engine.mem.triIndexes, indexStarts[currentMaterial], indexCounts[currentMaterial]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue