Commit b10632ca authored by David Llewellyn-Jones's avatar David Llewellyn-Jones

Added binary STL export code.

parent 37231492
......@@ -12,6 +12,8 @@
///////////////////////////////////////////////////////////////////
// Includes
#include <stdint.h>
#include "vis.h"
#include "cartesian.h"
#include "function.h"
......@@ -934,7 +936,7 @@ void CartesianVertex (Vector3 * pvVertex, Vector3 * pvNormal, double fXFunc, dou
}
}
void CartesianOutputStoredVerticesSTL (Recall * hFile, bool boBinary, bool boScreenCoords, double fMultiplier, double fScale, FuncPersist const * psFuncData) {
int CartesianOutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScreenCoords, double fMultiplier, double fScale, FuncPersist const * psFuncData) {
//CartesianPersist * psCartesianData = psFuncData->Func.psCartesianData;
int nX;
int nY;
......@@ -948,6 +950,9 @@ void CartesianOutputStoredVerticesSTL (Recall * hFile, bool boBinary, bool boScr
Vector3 vY;
Vector3 vN;
double fAccuracy;
float afVector[3];
uint16_t uAttribute = 0;
int nTriangles = 0;
if (fMultiplier > 0.0) {
fAccuracy = psFuncData->fAccuracy / fMultiplier;
......@@ -970,36 +975,99 @@ void CartesianOutputStoredVerticesSTL (Recall * hFile, bool boBinary, bool boScr
CartesianVertex (& avPos[nVertex], NULL, fXFunc, fYFunc, boScreenCoords, fMultiplier, fScale, psFuncData);
}
// Calculate the normals
// Based on the triangles rather than the curves to avoid messy results
vX = SubtractVectors (& avPos[1], & avPos[0]);
vY = SubtractVectors (& avPos[2], & avPos[0]);
vN = Normal (& vX, & vY);
// Output the triangles
recprintf (hFile, "facet normal %e %e %e\n", vN.fX, vN.fY, vN.fZ);
recprintf (hFile, "outer loop\n");
recprintf (hFile, "\tvertex %e %e %e\n", avPos[0].fX, avPos[0].fY, avPos[0].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[2].fX, avPos[2].fY, avPos[2].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[1].fX, avPos[1].fY, avPos[1].fZ);
recprintf (hFile, "endloop\n");
recprintf (hFile, "endfacet\n");
// Calculate the normals
// Based on the triangles rather than the curves to avoid messy results
vX = SubtractVectors (& avPos[3], & avPos[1]);
vY = SubtractVectors (& avPos[2], & avPos[1]);
vN = Normal (& vX, & vY);
recprintf (hFile, "facet normal %e %e %e\n", vN.fX, vN.fY, vN.fZ);
recprintf (hFile, "outer loop\n");
recprintf (hFile, "\tvertex %e %e %e\n", avPos[1].fX, avPos[1].fY, avPos[1].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[2].fX, avPos[2].fY, avPos[2].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[3].fX, avPos[3].fY, avPos[3].fZ);
recprintf (hFile, "endloop\n");
recprintf (hFile, "endfacet\n");
if (boBinary) {
// Calculate the normals
// Based on the triangles rather than the curves to avoid messy results
vX = SubtractVectors (& avPos[1], & avPos[0]);
vY = SubtractVectors (& avPos[2], & avPos[0]);
vN = Normal (& vX, & vY);
afVector[0] = vN.fX;
afVector[1] = vN.fY;
afVector[2] = vN.fZ;
recwrite (afVector, sizeof(float), 3, hFile);
afVector[0] = avPos[0].fX;
afVector[1] = avPos[0].fY;
afVector[2] = avPos[0].fZ;
recwrite (afVector, sizeof(float), 3, hFile);
afVector[0] = avPos[2].fX;
afVector[1] = avPos[2].fY;
afVector[2] = avPos[2].fZ;
recwrite (afVector, sizeof(float), 3, hFile);
afVector[0] = avPos[1].fX;
afVector[1] = avPos[1].fY;
afVector[2] = avPos[1].fZ;
recwrite (afVector, sizeof(float), 3, hFile);
recwrite (& uAttribute, sizeof(uint16_t), 1, hFile);
// Calculate the normals
// Based on the triangles rather than the curves to avoid messy results
vX = SubtractVectors (& avPos[3], & avPos[1]);
vY = SubtractVectors (& avPos[2], & avPos[1]);
vN = Normal (& vX, & vY);
afVector[0] = vN.fX;
afVector[1] = vN.fY;
afVector[2] = vN.fZ;
recwrite (afVector, sizeof(float), 3, hFile);
afVector[0] = avPos[1].fX;
afVector[1] = avPos[1].fY;
afVector[2] = avPos[1].fZ;
recwrite (afVector, sizeof(float), 3, hFile);
afVector[0] = avPos[2].fX;
afVector[1] = avPos[2].fY;
afVector[2] = avPos[2].fZ;
recwrite (afVector, sizeof(float), 3, hFile);
afVector[0] = avPos[3].fX;
afVector[1] = avPos[3].fY;
afVector[2] = avPos[3].fZ;
recwrite (afVector, sizeof(float), 3, hFile);
recwrite (& uAttribute, sizeof(uint16_t), 1, hFile);
nTriangles += 2;
}
else {
// Calculate the normals
// Based on the triangles rather than the curves to avoid messy results
vX = SubtractVectors (& avPos[1], & avPos[0]);
vY = SubtractVectors (& avPos[2], & avPos[0]);
vN = Normal (& vX, & vY);
// Output the triangles
recprintf (hFile, "facet normal %e %e %e\n", vN.fX, vN.fY, vN.fZ);
recprintf (hFile, "outer loop\n");
recprintf (hFile, "\tvertex %e %e %e\n", avPos[0].fX, avPos[0].fY, avPos[0].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[2].fX, avPos[2].fY, avPos[2].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[1].fX, avPos[1].fY, avPos[1].fZ);
recprintf (hFile, "endloop\n");
recprintf (hFile, "endfacet\n");
// Calculate the normals
// Based on the triangles rather than the curves to avoid messy results
vX = SubtractVectors (& avPos[3], & avPos[1]);
vY = SubtractVectors (& avPos[2], & avPos[1]);
vN = Normal (& vX, & vY);
recprintf (hFile, "facet normal %e %e %e\n", vN.fX, vN.fY, vN.fZ);
recprintf (hFile, "outer loop\n");
recprintf (hFile, "\tvertex %e %e %e\n", avPos[1].fX, avPos[1].fY, avPos[1].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[2].fX, avPos[2].fY, avPos[2].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[3].fX, avPos[3].fY, avPos[3].fZ);
recprintf (hFile, "endloop\n");
recprintf (hFile, "endfacet\n");
}
}
}
return nTriangles;
}
bool CartesianAssignControlVarsToFunction (FnControlPersist * psFnControlData, FuncPersist * psFuncData) {
......
......@@ -56,7 +56,7 @@ int CartesianOutputStoredVertices (Recall * hFile, bool boBinary, bool boScreenC
int CartesianOutputStoredIndices (Recall * hFile, bool boBinary, double fMultiplier, int nOffset, FuncPersist const * psFuncData);
int CartesianCountStoredVertices (double fMultiplier, FuncPersist const * psFuncData);
int CartesianCountStoredFaces (double fMultiplier, FuncPersist const * psFuncData);
void CartesianOutputStoredVerticesSTL (Recall * hFile, bool boBinary, bool boScreenCoords, double fMultiplier, double fScale, FuncPersist const * psFuncData);
int CartesianOutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScreenCoords, double fMultiplier, double fScale, FuncPersist const * psFuncData);
bool CartesianAssignControlVarsToFunction (FnControlPersist * psFnControlData, FuncPersist * psFuncData);
///////////////////////////////////////////////////////////////////
......
......@@ -12,6 +12,8 @@
///////////////////////////////////////////////////////////////////
// Includes
#include <stdint.h>
#include "vis.h"
#include "curve.h"
#include "function.h"
......@@ -1599,7 +1601,7 @@ void CurveVertex (Vector3 * pvVertex, Vector3 * pvNormal, double fStep, double f
}
}
void CurveOutputStoredVerticesSTL (Recall * hFile, bool boBinary, bool boScreenCoords, double fMultiplier, double fScale, FuncPersist const * psFuncData) {
int CurveOutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScreenCoords, double fMultiplier, double fScale, FuncPersist const * psFuncData) {
CurvePersist * psCurveData = psFuncData->Func.psCurveData;
int nPiece;
int nPieces;
......@@ -1613,7 +1615,10 @@ void CurveOutputStoredVerticesSTL (Recall * hFile, bool boBinary, bool boScreenC
Vector3 vP;
Vector3 vS;
Vector3 vN;
float afVector[3];
uint16_t uAttribute = 0;
int nTriangles = 0;
nPieces = (int)((float)psCurveData->nPieces * fMultiplier);
if (nPieces < 2) {
nPieces = 2;
......@@ -1624,7 +1629,7 @@ void CurveOutputStoredVerticesSTL (Recall * hFile, bool boBinary, bool boScreenC
}
for (nPiece = 0; nPiece < (nPieces - 1); nPiece++) {
for (nSegment = 0; nSegment < (nSegments - 1); nSegment++) {
for (nSegment = 0; nSegment < (nSegments - 0); nSegment++) {
for (nVertex = 0; nVertex < 4; nVertex++) {
fStep = ((double)(((nPiece + (int)(nVertex / 2)) % nPieces))) / ((double)(nPieces - 1.0f));
......@@ -1634,36 +1639,99 @@ void CurveOutputStoredVerticesSTL (Recall * hFile, bool boBinary, bool boScreenC
CurveVertex (& avPos[nVertex], NULL, fStep, fTheta, boScreenCoords, fMultiplier, fScale, psFuncData);
}
// Calculate the normals
// Based on the triangles rather than the curves to avoid messy results
vP = SubtractVectors (& avPos[1], & avPos[0]);
vS = SubtractVectors (& avPos[2], & avPos[0]);
vN = Normal (& vP, & vS);
// Output the triangles
recprintf (hFile, "facet normal %e %e %e\n", vN.fX, vN.fY, vN.fZ);
recprintf (hFile, "outer loop\n");
recprintf (hFile, "\tvertex %e %e %e\n", avPos[0].fX, avPos[0].fY, avPos[0].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[2].fX, avPos[2].fY, avPos[2].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[1].fX, avPos[1].fY, avPos[1].fZ);
recprintf (hFile, "endloop\n");
recprintf (hFile, "endfacet\n");
// Calculate the normals
// Based on the triangles rather than the curves to avoid messy results
vP = SubtractVectors (& avPos[3], & avPos[1]);
vS = SubtractVectors (& avPos[2], & avPos[1]);
vN = Normal (& vP, & vS);
recprintf (hFile, "facet normal %e %e %e\n", vN.fX, vN.fY, vN.fZ);
recprintf (hFile, "outer loop\n");
recprintf (hFile, "\tvertex %e %e %e\n", avPos[1].fX, avPos[1].fY, avPos[1].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[2].fX, avPos[2].fY, avPos[2].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[3].fX, avPos[3].fY, avPos[3].fZ);
recprintf (hFile, "endloop\n");
recprintf (hFile, "endfacet\n");
if (boBinary) {
// Calculate the normals
// Based on the triangles rather than the curves to avoid messy results
vP = SubtractVectors (& avPos[1], & avPos[0]);
vS = SubtractVectors (& avPos[2], & avPos[0]);
vN = Normal (& vP, & vS);
afVector[0] = vN.fX;
afVector[1] = vN.fY;
afVector[2] = vN.fZ;
recwrite (afVector, sizeof(float), 3, hFile);
afVector[0] = avPos[0].fX;
afVector[1] = avPos[0].fY;
afVector[2] = avPos[0].fZ;
recwrite (afVector, sizeof(float), 3, hFile);
afVector[0] = avPos[2].fX;
afVector[1] = avPos[2].fY;
afVector[2] = avPos[2].fZ;
recwrite (afVector, sizeof(float), 3, hFile);
afVector[0] = avPos[1].fX;
afVector[1] = avPos[1].fY;
afVector[2] = avPos[1].fZ;
recwrite (afVector, sizeof(float), 3, hFile);
recwrite (& uAttribute, sizeof(uint16_t), 1, hFile);
// Calculate the normals
// Based on the triangles rather than the curves to avoid messy results
vP = SubtractVectors (& avPos[3], & avPos[1]);
vS = SubtractVectors (& avPos[2], & avPos[1]);
vN = Normal (& vP, & vS);
afVector[0] = vN.fX;
afVector[1] = vN.fY;
afVector[2] = vN.fZ;
recwrite (afVector, sizeof(float), 3, hFile);
afVector[0] = avPos[1].fX;
afVector[1] = avPos[1].fY;
afVector[2] = avPos[1].fZ;
recwrite (afVector, sizeof(float), 3, hFile);
afVector[0] = avPos[2].fX;
afVector[1] = avPos[2].fY;
afVector[2] = avPos[2].fZ;
recwrite (afVector, sizeof(float), 3, hFile);
afVector[0] = avPos[3].fX;
afVector[1] = avPos[3].fY;
afVector[2] = avPos[3].fZ;
recwrite (afVector, sizeof(float), 3, hFile);
recwrite (& uAttribute, sizeof(uint16_t), 1, hFile);
nTriangles += 2;
}
else {
// Calculate the normals
// Based on the triangles rather than the curves to avoid messy results
vP = SubtractVectors (& avPos[1], & avPos[0]);
vS = SubtractVectors (& avPos[2], & avPos[0]);
vN = Normal (& vP, & vS);
// Output the triangles
recprintf (hFile, "facet normal %e %e %e\n", vN.fX, vN.fY, vN.fZ);
recprintf (hFile, "outer loop\n");
recprintf (hFile, "\tvertex %e %e %e\n", avPos[0].fX, avPos[0].fY, avPos[0].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[2].fX, avPos[2].fY, avPos[2].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[1].fX, avPos[1].fY, avPos[1].fZ);
recprintf (hFile, "endloop\n");
recprintf (hFile, "endfacet\n");
// Calculate the normals
// Based on the triangles rather than the curves to avoid messy results
vP = SubtractVectors (& avPos[3], & avPos[1]);
vS = SubtractVectors (& avPos[2], & avPos[1]);
vN = Normal (& vP, & vS);
recprintf (hFile, "facet normal %e %e %e\n", vN.fX, vN.fY, vN.fZ);
recprintf (hFile, "outer loop\n");
recprintf (hFile, "\tvertex %e %e %e\n", avPos[1].fX, avPos[1].fY, avPos[1].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[2].fX, avPos[2].fY, avPos[2].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[3].fX, avPos[3].fY, avPos[3].fZ);
recprintf (hFile, "endloop\n");
recprintf (hFile, "endfacet\n");
}
}
}
return nTriangles;
}
bool CurveAssignControlVarsToFunction (FnControlPersist * psFnControlData, FuncPersist * psFuncData) {
......
......@@ -65,7 +65,7 @@ int CurveOutputStoredVertices (Recall * hFile, bool boBinary, bool boScreenCoord
int CurveOutputStoredIndices (Recall * hFile, bool boBinary, double fMultiplier, int nOffset, FuncPersist const * psFuncData);
int CurveCountStoredVertices (double fMultiplier, FuncPersist const * psFuncData);
int CurveCountStoredFaces (double fMultiplier, FuncPersist const * psFuncData);
void CurveOutputStoredVerticesSTL (Recall * hFile, bool boBinary, bool boScreenCoords, double fMultiplier, double fScale, FuncPersist const * psFuncData);
int CurveOutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScreenCoords, double fMultiplier, double fScale, FuncPersist const * psFuncData);
bool CurveAssignControlVarsToFunction (FnControlPersist * psFnControlData, FuncPersist * psFuncData);
///////////////////////////////////////////////////////////////////
......
......@@ -67,6 +67,8 @@ void ExportModelRecallSTL (Recall * hFile, bool boBinary, bool boScreenCoords, d
int nFaces;
GSList const * psFuncList;
LocaleRestore * psRestore;
char acHeader[80] = "For I dance\n\nAnd drink, and sing,\n\nTill some blind hand\n\nShall brush my wing.\n\n\n";
uint32_t uTriangles;
psRestore = ClearLocale ();
......@@ -88,7 +90,17 @@ void ExportModelRecallSTL (Recall * hFile, bool boBinary, bool boScreenCoords, d
if (boBinary) {
//recprintf (hFile, "solid functy\n");
// Header 80 bytes
recwrite (acHeader, sizeof(char), 80, hFile);
// Calculate the number of triangles
uTriangles = 0;
psFuncList = psFunctions;
while (psFuncList) {
uTriangles += CountStoredFaces (fMultiplier, (FuncPersist const *)(psFuncList->data));
psFuncList = g_slist_next (psFuncList);
}
recwrite (& uTriangles, sizeof(uint32_t), 1, hFile);
}
else {
recprintf (hFile, "solid functy\n");
......@@ -97,11 +109,13 @@ void ExportModelRecallSTL (Recall * hFile, bool boBinary, bool boScreenCoords, d
// Output the vertices
psFuncList = psFunctions;
while (psFuncList) {
OutputStoredVerticesSTL (hFile, boBinary, boScreenCoords, fMultiplier, fScale, (FuncPersist const *)(psFuncList->data));
OutputStoredTrianglesSTL (hFile, boBinary, boScreenCoords, fMultiplier, fScale, (FuncPersist const *)(psFuncList->data));
psFuncList = g_slist_next (psFuncList);
}
recprintf (hFile, "endsolid\n");
if (!boBinary) {
recprintf (hFile, "endsolid\n");
}
RestoreLocale (psRestore);
}
......
......@@ -1036,21 +1036,26 @@ int CountStoredFaces (double fMultiplier, FuncPersist const * psFuncData) {
return nFaces;
}
void OutputStoredVerticesSTL (Recall * hFile, bool boBinary, bool boScreenCoords, double fMultiplier, double fScale, FuncPersist const * psFuncData) {
int OutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScreenCoords, double fMultiplier, double fScale, FuncPersist const * psFuncData) {
int nTriangles;
switch (psFuncData->eType) {
case FUNCTYPE_CARTESIAN:
CartesianOutputStoredVerticesSTL (hFile, boBinary, boScreenCoords, fMultiplier, fScale, psFuncData);
nTriangles = CartesianOutputStoredTrianglesSTL (hFile, boBinary, boScreenCoords, fMultiplier, fScale, psFuncData);
break;
case FUNCTYPE_SPHERICAL:
SphericalOutputStoredVerticesSTL (hFile, boBinary, boScreenCoords, fMultiplier, fScale, psFuncData);
nTriangles = SphericalOutputStoredTrianglesSTL (hFile, boBinary, boScreenCoords, fMultiplier, fScale, psFuncData);
break;
case FUNCTYPE_CURVE:
CurveOutputStoredVerticesSTL (hFile, boBinary, boScreenCoords, fMultiplier, fScale, psFuncData);
nTriangles = CurveOutputStoredTrianglesSTL (hFile, boBinary, boScreenCoords, fMultiplier, fScale, psFuncData);
break;
default:
// Do nothing
// No triangles
nTriangles = 0;
break;
}
return nTriangles;
}
void DrawGraph (FuncPersist * psFuncData) {
......
......@@ -100,7 +100,7 @@ int OutputStoredVertices (Recall * hFile, bool boBinary, bool boScreenCoords, bo
int OutputStoredIndices (Recall * hFile, bool boBinary, double fMultiplier, int nOffset, FuncPersist const * psFuncData);
int CountStoredVertices (double fMultiplier, FuncPersist const * psFuncData);
int CountStoredFaces (double fMultiplier, FuncPersist const * psFuncData);
void OutputStoredVerticesSTL (Recall * hFile, bool boBinary, bool boScreenCoords, double fMultiplier, double fScale, FuncPersist const * psFuncData);
int OutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScreenCoords, double fMultiplier, double fScale, FuncPersist const * psFuncData);
void RecentreGraph (FuncPersist * psFuncData);
void DrawGraph (FuncPersist * psFuncData);
void DrawGraphShadow (FuncPersist * psFuncData);
......
......@@ -12,6 +12,8 @@
///////////////////////////////////////////////////////////////////
// Includes
#include <stdint.h>
#include "vis.h"
#include "spherical.h"
#include "function.h"
......@@ -1157,7 +1159,7 @@ void SphericalVertex (Vector3 * pvVertex, Vector3 * pvNormal, double fAFunc, dou
}
}
void SphericalOutputStoredVerticesSTL (Recall * hFile, bool boBinary, bool boScreenCoords, double fMultiplier, double fScale, FuncPersist const * psFuncData) {
int SphericalOutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScreenCoords, double fMultiplier, double fScale, FuncPersist const * psFuncData) {
//SphericalPersist * psSphericalData = psFuncData->Func.psSphericalData;
int nA;
int nP;
......@@ -1171,7 +1173,10 @@ void SphericalOutputStoredVerticesSTL (Recall * hFile, bool boBinary, bool boScr
Vector3 vP;
Vector3 vN;
double fAccuracy;
float afVector[3];
uint16_t uAttribute = 0;
int nTriangles = 0;
if (fMultiplier > 0.0) {
fAccuracy = psFuncData->fAccuracy / fMultiplier;
}
......@@ -1186,43 +1191,106 @@ void SphericalOutputStoredVerticesSTL (Recall * hFile, bool boBinary, bool boScr
nPVertices = floor (1.0 / fAccuracy) + 1;
for (nA = 0; nA < (nAVertices - 1); nA++) {
for (nP = 0; nP < (nPVertices - 1); nP++) {
for (nP = 0; nP < (nPVertices - 0); nP++) {
for (nVertex = 0; nVertex < 4; nVertex++) {
fAFunc = (((double)((nA + (int)(nVertex / 2)) % nAVertices)) * fAccuracy) * 2.0 * M_PI;
fPFunc = (((double)((nP + (nVertex % 2)) % nPVertices)) * fAccuracy) * 1.0 * M_PI;
SphericalVertex (& avPos[nVertex], NULL, fAFunc, fPFunc, boScreenCoords, fMultiplier, fScale, psFuncData);
}
// Calculate the normals
// Based on the triangles rather than the curves to avoid messy results
vA = SubtractVectors (& avPos[1], & avPos[0]);
vP = SubtractVectors (& avPos[2], & avPos[0]);
vN = Normal (& vA, & vP);
// Output the triangles
recprintf (hFile, "facet normal %e %e %e\n", vN.fX, vN.fY, vN.fZ);
recprintf (hFile, "outer loop\n");
recprintf (hFile, "\tvertex %e %e %e\n", avPos[0].fX, avPos[0].fY, avPos[0].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[1].fX, avPos[1].fY, avPos[1].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[2].fX, avPos[2].fY, avPos[2].fZ);
recprintf (hFile, "endloop\n");
recprintf (hFile, "endfacet\n");
// Calculate the normals
// Based on the triangles rather than the curves to avoid messy results
vA = SubtractVectors (& avPos[3], & avPos[1]);
vP = SubtractVectors (& avPos[2], & avPos[1]);
vN = Normal (& vA, & vP);
recprintf (hFile, "facet normal %e %e %e\n", vN.fX, vN.fY, vN.fZ);
recprintf (hFile, "outer loop\n");
recprintf (hFile, "\tvertex %e %e %e\n", avPos[1].fX, avPos[1].fY, avPos[1].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[3].fX, avPos[3].fY, avPos[3].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[2].fX, avPos[2].fY, avPos[2].fZ);
recprintf (hFile, "endloop\n");
recprintf (hFile, "endfacet\n");
if (boBinary) {
// Calculate the normals
// Based on the triangles rather than the curves to avoid messy results
vA = SubtractVectors (& avPos[1], & avPos[0]);
vP = SubtractVectors (& avPos[2], & avPos[0]);
vN = Normal (& vA, & vP);
afVector[0] = vN.fX;
afVector[1] = vN.fY;
afVector[2] = vN.fZ;
recwrite (afVector, sizeof(float), 3, hFile);
afVector[0] = avPos[0].fX;
afVector[1] = avPos[0].fY;
afVector[2] = avPos[0].fZ;
recwrite (afVector, sizeof(float), 3, hFile);
afVector[0] = avPos[1].fX;
afVector[1] = avPos[1].fY;
afVector[2] = avPos[1].fZ;
recwrite (afVector, sizeof(float), 3, hFile);
afVector[0] = avPos[2].fX;
afVector[1] = avPos[2].fY;
afVector[2] = avPos[2].fZ;
recwrite (afVector, sizeof(float), 3, hFile);
recwrite (& uAttribute, sizeof(uint16_t), 1, hFile);
// Calculate the normals
// Based on the triangles rather than the curves to avoid messy results
vA = SubtractVectors (& avPos[3], & avPos[1]);
vP = SubtractVectors (& avPos[2], & avPos[1]);
vN = Normal (& vA, & vP);
afVector[0] = vN.fX;
afVector[1] = vN.fY;
afVector[2] = vN.fZ;
recwrite (afVector, sizeof(float), 3, hFile);
afVector[0] = avPos[1].fX;
afVector[1] = avPos[1].fY;
afVector[2] = avPos[1].fZ;
recwrite (afVector, sizeof(float), 3, hFile);
afVector[0] = avPos[3].fX;
afVector[1] = avPos[3].fY;
afVector[2] = avPos[3].fZ;
recwrite (afVector, sizeof(float), 3, hFile);
afVector[0] = avPos[2].fX;
afVector[1] = avPos[2].fY;
afVector[2] = avPos[2].fZ;
recwrite (afVector, sizeof(float), 3, hFile);
recwrite (& uAttribute, sizeof(uint16_t), 1, hFile);
nTriangles += 2;
}
else {
// Calculate the normals
// Based on the triangles rather than the curves to avoid messy results
vA = SubtractVectors (& avPos[1], & avPos[0]);
vP = SubtractVectors (& avPos[2], & avPos[0]);
vN = Normal (& vA, & vP);
// Output the triangles
recprintf (hFile, "facet normal %e %e %e\n", vN.fX, vN.fY, vN.fZ);
recprintf (hFile, "outer loop\n");
recprintf (hFile, "\tvertex %e %e %e\n", avPos[0].fX, avPos[0].fY, avPos[0].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[1].fX, avPos[1].fY, avPos[1].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[2].fX, avPos[2].fY, avPos[2].fZ);
recprintf (hFile, "endloop\n");
recprintf (hFile, "endfacet\n");
// Calculate the normals
// Based on the triangles rather than the curves to avoid messy results
vA = SubtractVectors (& avPos[3], & avPos[1]);
vP = SubtractVectors (& avPos[2], & avPos[1]);
vN = Normal (& vA, & vP);
recprintf (hFile, "facet normal %e %e %e\n", vN.fX, vN.fY, vN.fZ);
recprintf (hFile, "outer loop\n");
recprintf (hFile, "\tvertex %e %e %e\n", avPos[1].fX, avPos[1].fY, avPos[1].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[3].fX, avPos[3].fY, avPos[3].fZ);
recprintf (hFile, "\tvertex %e %e %e\n", avPos[2].fX, avPos[2].fY, avPos[2].fZ);
recprintf (hFile, "endloop\n");
recprintf (hFile, "endfacet\n");
}
}
}
return nTriangles;
}
bool SphericalAssignControlVarsToFunction (FnControlPersist * psFnControlData, FuncPersist * psFuncData) {
......
......@@ -58,7 +58,7 @@ int SphericalOutputStoredVertices (Recall * hFile, bool boBinary, bool boScreenC
int SphericalOutputStoredIndices (Recall * hFile, bool boBinary, double fMultiplier, int nOffset, FuncPersist const * psFuncData);
int SphericalCountStoredVertices (double fMultiplier, FuncPersist const * psFuncData);
int SphericalCountStoredFaces (double fMultiplier, FuncPersist const * psFuncData);
void SphericalOutputStoredVerticesSTL (Recall * hFile, bool boBinary, bool boScreenCoords, double fMultiplier, double fScale, FuncPersist const * psFuncData);
int SphericalOutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScreenCoords, double fMultiplier, double fScale, FuncPersist const * psFuncData);
bool SphericalAssignControlVarsToFunction (FnControlPersist * psFnControlData, FuncPersist * psFuncData);
///////////////////////////////////////////////////////////////////
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment