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:
whitequark 2016-01-11 07:52:46 +00:00
parent 1160b5d335
commit 310fa9a817

View File

@ -819,8 +819,12 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename, S
"\n"
" geometry.faces.push(new THREE.Face3(mesh_obj.faces[i][0],\n"
" mesh_obj.faces[i][1], mesh_obj.faces[i][2],\n"
" new THREE.Vector3(mesh_obj.normals[i][0],\n"
" mesh_obj.normals[i][1], mesh_obj.normals[i][2]),\n"
" [new THREE.Vector3(mesh_obj.normals[i][0][0],\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"
" opacitiesSeen[currOpacity]));\n"
" }\n"
@ -911,9 +915,7 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename, S
" intensity: %f, direction: [%f, %f, %f]\n"
" },\n",
SS.lightIntensity[lightCount],
SS.lightDir[lightCount].x,
SS.lightDir[lightCount].y,
SS.lightDir[lightCount].z);
CO(SS.lightDir[lightCount]));
}
// Global Ambience.
@ -948,6 +950,14 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename, S
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"
" colors: [\n", f);
// 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());
}
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"
" edges: [\n", f);
// Output edges. Assume user's model colors do not obscure white edges.
for(e = sel->l.First(); e; e = sel->l.NextAfter(e)) {
fprintf(f, " [[%f, %f, %f], [%f, %f, %f]],\n",
e->a.x,
e->a.y,
e->a.z,
e->b.x,
e->b.y,
e->b.z);
CO(e->a), CO(e->b));
}
fputs(" ]\n};\n", f);