fromGeometry static method
CSG
fromGeometry(
- BufferGeometry geometry
)
Implementation
static CSG fromGeometry(BufferGeometry geometry){
List<Polygon> polys = [];
if (geometry.index != null) {
geometry = geometry.toNonIndexed();
}
final positions = geometry.attributes['position'];
final normals = geometry.attributes['normal'];
final uvs = geometry.attributes['uv'];
final colorattr = geometry.attributes['color'];
// TODO
// const colors = geometry.attributes.color;
Vertex createVertex(int index) {
final position = Vector3(
positions.getX(index),
positions.getY(index),
positions.getZ(index)
);
final normal = Vector3(
normals.getX(index),
normals.getY(index),
normals.getZ(index)
);
final uv = Vector3(uvs.getX(index), uvs.getY(index),0);
final color = colorattr != null?Vector3(colorattr.getX(index),colorattr.getY(index),colorattr.getZ(index)): null;
return Vertex(position, normal, uv, color);
}
for (int i = 0; i < positions.count; i += 3) {
final v1 = createVertex(i);
final v2 = createVertex(i + 1);
final v3 = createVertex(i + 2);
polys.add(Polygon([v1, v2, v3]));
}
//return this;
return CSG.fromPolygons(polys.where((p) => !p.plane.normal.x.isNaN).toList());
}