fromGeometryOld static method
CSG
fromGeometryOld(
- BufferGeometry geom, [
- int? objectIndex
])
Implementation
static CSG fromGeometryOld(BufferGeometry geom, [int? objectIndex]) {
List<Polygon?> polys = [];
final Float32BufferAttribute posattr = geom.attributes['position'];
final Float32BufferAttribute normalattr = geom.attributes['normal'];
final Float32BufferAttribute uvattr = geom.attributes['uv'];
final Float32BufferAttribute? colorattr = geom.attributes['color'];
final grps = geom.groups;
Uint16List index;
if (geom.index != null){
index = geom.index!.array as Uint16List;
}
else {
index = Uint16List((posattr.array.length ~/ posattr.itemSize) | 0);
for (int i = 0; i < index.length; i++){
index[i] = i;
}
}
final triCount = (index.length ~/ 3) | 0;
polys = List.filled(triCount, null);
for (int i = 0, pli = 0, l = index.length; i < l; i += 3, pli++) {
List<Vertex> vertices = [];
for (int j = 0; j < 3; j++) {
int vi = index[i + j];
int vp = vi * 3;
int vt = vi * 2;
double x = posattr.array[vp];
double y = posattr.array[vp + 1];
double z = posattr.array[vp + 2];
double nx = normalattr.array[vp];
double ny = normalattr.array[vp + 1];
double nz = normalattr.array[vp + 2];
double u = uvattr.array[vt];
double v = uvattr.array[vt + 1];
vertices.add(Vertex(
Vector3(x,y,z),
Vector3(nx,ny,nz),
Vector3(u,v,0),
colorattr != null?Vector3(colorattr.array[vt],colorattr.array[vt + 1],colorattr.array[vt + 2]): null
)
);
}
if (objectIndex == null && grps.isNotEmpty) {
for (final grp in grps) {
if (i >= grp['start'] && i < grp['start'] + grp['count']) {
polys[pli] = Polygon(vertices, grp['materialIndex']);
}
}
}
else {
polys[pli] = Polygon(vertices, objectIndex);
}
}
return CSG.fromPolygons(polys.where((p) => p != null && !p.plane.normal.x.isNaN).nonNulls.toList());
}