Export vertex normals, not just face normals, for Three.js.
This causes NURBS models to render smoothly, like they do in SolveSpace itself.
This commit is contained in:
parent
1160b5d335
commit
310fa9a817
@ -819,8 +819,12 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename, S
|
|||||||
"\n"
|
"\n"
|
||||||
" geometry.faces.push(new THREE.Face3(mesh_obj.faces[i][0],\n"
|
" geometry.faces.push(new THREE.Face3(mesh_obj.faces[i][0],\n"
|
||||||
" mesh_obj.faces[i][1], mesh_obj.faces[i][2],\n"
|
" mesh_obj.faces[i][1], mesh_obj.faces[i][2],\n"
|
||||||
" new THREE.Vector3(mesh_obj.normals[i][0],\n"
|
" [new THREE.Vector3(mesh_obj.normals[i][0][0],\n"
|
||||||
" mesh_obj.normals[i][1], mesh_obj.normals[i][2]),\n"
|
" mesh_obj.normals[i][0][1], mesh_obj.normals[i][0][2]),\n"
|
||||||
|
" new THREE.Vector3(mesh_obj.normals[i][1][0],\n"
|
||||||
|
" mesh_obj.normals[i][1][1], mesh_obj.normals[i][1][2]),\n"
|
||||||
|
" new THREE.Vector3(mesh_obj.normals[i][2][0],\n"
|
||||||
|
" mesh_obj.normals[i][2][1], mesh_obj.normals[i][2][2])],\n"
|
||||||
" new THREE.Color(mesh_obj.colors[i] & 0x00FFFFFF),\n"
|
" new THREE.Color(mesh_obj.colors[i] & 0x00FFFFFF),\n"
|
||||||
" opacitiesSeen[currOpacity]));\n"
|
" opacitiesSeen[currOpacity]));\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
@ -911,9 +915,7 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename, S
|
|||||||
" intensity: %f, direction: [%f, %f, %f]\n"
|
" intensity: %f, direction: [%f, %f, %f]\n"
|
||||||
" },\n",
|
" },\n",
|
||||||
SS.lightIntensity[lightCount],
|
SS.lightIntensity[lightCount],
|
||||||
SS.lightDir[lightCount].x,
|
CO(SS.lightDir[lightCount]));
|
||||||
SS.lightDir[lightCount].y,
|
|
||||||
SS.lightDir[lightCount].z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Global Ambience.
|
// Global Ambience.
|
||||||
@ -948,6 +950,14 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename, S
|
|||||||
spl.IndexForPoint(tr->c));
|
spl.IndexForPoint(tr->c));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Output face normals.
|
||||||
|
fputs(" ],\n"
|
||||||
|
" normals: [\n", f);
|
||||||
|
for(tr = sm->l.First(); tr; tr = sm->l.NextAfter(tr)) {
|
||||||
|
fprintf(f, " [[%f, %f, %f], [%f, %f, %f], [%f, %f, %f]],\n",
|
||||||
|
CO(tr->an), CO(tr->bn), CO(tr->cn));
|
||||||
|
}
|
||||||
|
|
||||||
fputs(" ],\n"
|
fputs(" ],\n"
|
||||||
" colors: [\n", f);
|
" colors: [\n", f);
|
||||||
// Output triangle colors.
|
// Output triangle colors.
|
||||||
@ -955,28 +965,12 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename, S
|
|||||||
fprintf(f, " 0x%x,\n", tr->meta.color.ToARGB32());
|
fprintf(f, " 0x%x,\n", tr->meta.color.ToARGB32());
|
||||||
}
|
}
|
||||||
|
|
||||||
fputs(" ],\n"
|
|
||||||
" normals: [\n", f);
|
|
||||||
// Output face normals.
|
|
||||||
for(tr = sm->l.First(); tr; tr = sm->l.NextAfter(tr)) {
|
|
||||||
Vector currNormal = tr->Normal();
|
|
||||||
fprintf(f, " [%f, %f, %f],\n",
|
|
||||||
currNormal.x,
|
|
||||||
currNormal.y,
|
|
||||||
currNormal.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
fputs(" ],\n"
|
fputs(" ],\n"
|
||||||
" edges: [\n", f);
|
" edges: [\n", f);
|
||||||
// Output edges. Assume user's model colors do not obscure white edges.
|
// Output edges. Assume user's model colors do not obscure white edges.
|
||||||
for(e = sel->l.First(); e; e = sel->l.NextAfter(e)) {
|
for(e = sel->l.First(); e; e = sel->l.NextAfter(e)) {
|
||||||
fprintf(f, " [[%f, %f, %f], [%f, %f, %f]],\n",
|
fprintf(f, " [[%f, %f, %f], [%f, %f, %f]],\n",
|
||||||
e->a.x,
|
CO(e->a), CO(e->b));
|
||||||
e->a.y,
|
|
||||||
e->a.z,
|
|
||||||
e->b.x,
|
|
||||||
e->b.y,
|
|
||||||
e->b.z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fputs(" ]\n};\n", f);
|
fputs(" ]\n};\n", f);
|
||||||
|
Loading…
Reference in New Issue
Block a user