parseMesh static method
String
parseMesh(
- Mesh object, [
- bool usingParse = false
])
Implementation
static String parseMesh(Mesh object,[bool usingParse = false]){
String output = '';
if(!usingParse){
output = 'solid exported\n';
}
BufferGeometry? geometry = object.geometry;
final Float32BufferAttribute? vertices = geometry?.getAttribute(Attribute.position);
final indices = geometry?.getIndex();
if(indices != null){
for(int i = 0, l = indices.length; i < l; i+=3) {
final faces = [indices.getX(i)!.toInt(), indices.getX(i+1)!.toInt(), indices.getX(i+2)!.toInt()];
String verts = '';
List<Vector3> vecsToNormal = [];
for(int j = 0; j < 3; j ++){
vecsToNormal.add(Vector3(vertices!.getX(faces[j])!.toDouble(),vertices.getY(faces[j])!.toDouble(),vertices.getZ(faces[j])!.toDouble()));
verts += '\t\t\tvertex ${vecsToNormal[j].x} ${vecsToNormal[j].y} ${vecsToNormal[j].z}\n';
}
Vector3 toNormal = _computeNormal(vecsToNormal[0],vecsToNormal[1],vecsToNormal[2]);
output += '\tfacet normal ${toNormal.x} ${toNormal.y} ${toNormal.z}\n';
output += '\t\touter loop\n';
output += verts;
output += '\t\tendloop\n';
output += '\tendfacet\n';
}
}
if(!usingParse){
output += 'endsolid exported\n';
}
return output;
}