mirror of
https://github.com/leozide/leocad
synced 2025-01-30 20:34:56 +01:00
Export normals to pov and obj. Fixes #117 .
This commit is contained in:
parent
bc327a3b00
commit
f6e4c054a7
2 changed files with 29 additions and 5 deletions
|
@ -270,11 +270,15 @@ void lcMesh::ExportPOVRay(lcFile& File, const char* MeshName, const char** Color
|
||||||
|
|
||||||
for (int Idx = 0; Idx < Section->NumIndices; Idx += 3)
|
for (int Idx = 0; Idx < Section->NumIndices; Idx += 3)
|
||||||
{
|
{
|
||||||
lcVector3& v1 = Verts[Indices[Idx]].Position;
|
const lcVector3 v1 = Verts[Indices[Idx]].Position / 25.0f;
|
||||||
lcVector3& v2 = Verts[Indices[Idx + 1]].Position;
|
const lcVector3 v2 = Verts[Indices[Idx + 1]].Position / 25.0f;
|
||||||
lcVector3& v3 = Verts[Indices[Idx + 2]].Position;
|
const lcVector3 v3 = Verts[Indices[Idx + 2]].Position / 25.0f;
|
||||||
|
const lcVector3 n1 = lcUnpackNormal(Verts[Indices[Idx]].Normal);
|
||||||
|
const lcVector3 n2 = lcUnpackNormal(Verts[Indices[Idx + 1]].Normal);
|
||||||
|
const lcVector3 n3 = lcUnpackNormal(Verts[Indices[Idx + 2]].Normal);
|
||||||
|
|
||||||
sprintf(Line, " triangle { <%.2f, %.2f, %.2f>, <%.2f, %.2f, %.2f>, <%.2f, %.2f, %.2f> }\n", -v1.y / 25.0f, -v1.x / 25.0f, v1.z / 25.0f, -v2.y / 25.0f, -v2.x / 25.0f, v2.z / 25.0f, -v3.y / 25.0f, -v3.x / 25.0f, v3.z / 25.0f);
|
sprintf(Line, " smooth_triangle { <%.2f, %.2f, %.2f>, <%.2f, %.2f, %.2f>, <%.2f, %.2f, %.2f>, <%.2f, %.2f, %.2f>, <%.2f, %.2f, %.2f>, <%.2f, %.2f, %.2f> }\n",
|
||||||
|
-v1.y, -v1.x, v1.z, -n1.y, -n1.x, n1.z, -v2.y, -v2.x, v2.z, -n2.y, -n2.x, n2.z, -v3.y, -v3.x, v3.z, -n3.y, -n3.x, n3.z);
|
||||||
File.WriteLine(Line);
|
File.WriteLine(Line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,7 +327,7 @@ void lcMesh::ExportWavefrontIndices(lcFile& File, int DefaultColorIndex, int Ver
|
||||||
long int idx3 = Indices[Idx + 2] + VertexOffset;
|
long int idx3 = Indices[Idx + 2] + VertexOffset;
|
||||||
|
|
||||||
if (idx1 != idx2 && idx1 != idx3 && idx2 != idx3)
|
if (idx1 != idx2 && idx1 != idx3 && idx2 != idx3)
|
||||||
sprintf(Line, "f %ld %ld %ld\n", idx1, idx2, idx3);
|
sprintf(Line, "f %ld//%ld %ld//%ld %ld//%ld\n", idx1, idx1, idx2, idx2, idx3, idx3);
|
||||||
File.WriteLine(Line);
|
File.WriteLine(Line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2282,6 +2282,26 @@ void Project::ExportWavefront(const QString& FileName)
|
||||||
OBJFile.WriteLine("#\n\n");
|
OBJFile.WriteLine("#\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int PartIdx = 0; PartIdx < ModelParts.GetSize(); PartIdx++)
|
||||||
|
{
|
||||||
|
lcMesh* Mesh = ModelParts[PartIdx].Info->GetMesh();
|
||||||
|
|
||||||
|
if (!Mesh)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const lcMatrix44& ModelWorld = ModelParts[PartIdx].WorldMatrix;
|
||||||
|
lcVertex* Verts = (lcVertex*)Mesh->mVertexData;
|
||||||
|
|
||||||
|
for (int VertexIdx = 0; VertexIdx < Mesh->mNumVertices; VertexIdx++)
|
||||||
|
{
|
||||||
|
lcVector3 Normal = lcMul30(lcUnpackNormal(Verts[VertexIdx].Normal), ModelWorld);
|
||||||
|
sprintf(Line, "vn %.2f %.2f %.2f\n", Normal[0], Normal[1], Normal[2]);
|
||||||
|
OBJFile.WriteLine(Line);
|
||||||
|
}
|
||||||
|
|
||||||
|
OBJFile.WriteLine("#\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
for (int PartIdx = 0; PartIdx < ModelParts.GetSize(); PartIdx++)
|
for (int PartIdx = 0; PartIdx < ModelParts.GetSize(); PartIdx++)
|
||||||
{
|
{
|
||||||
PieceInfo* Info = ModelParts[PartIdx].Info;
|
PieceInfo* Info = ModelParts[PartIdx].Info;
|
||||||
|
|
Loading…
Add table
Reference in a new issue