Commit 82b4370f authored by David Llewellyn-Jones's avatar David Llewellyn-Jones

Added checks for invalid normals when exporting STL files.

parent b10632ca
......@@ -980,7 +980,7 @@ int CartesianOutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScr
// 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);
vN = NormalOrUp (& vX, & vY);
afVector[0] = vN.fX;
afVector[1] = vN.fY;
......@@ -1008,7 +1008,7 @@ int CartesianOutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScr
// 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);
vN = NormalOrUp (& vX, & vY);
afVector[0] = vN.fX;
afVector[1] = vN.fY;
......@@ -1039,7 +1039,7 @@ int CartesianOutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScr
// 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);
vN = NormalOrUp (& vX, & vY);
// Output the triangles
recprintf (hFile, "facet normal %e %e %e\n", vN.fX, vN.fY, vN.fZ);
......@@ -1054,7 +1054,7 @@ int CartesianOutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScr
// 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);
vN = NormalOrUp (& vX, & vY);
recprintf (hFile, "facet normal %e %e %e\n", vN.fX, vN.fY, vN.fZ);
recprintf (hFile, "outer loop\n");
......
......@@ -1644,7 +1644,7 @@ int CurveOutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScreenC
// 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);
vN = NormalOrUp (& vP, & vS);
afVector[0] = vN.fX;
afVector[1] = vN.fY;
......@@ -1672,7 +1672,7 @@ int CurveOutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScreenC
// 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);
vN = NormalOrUp (& vP, & vS);
afVector[0] = vN.fX;
afVector[1] = vN.fY;
......@@ -1703,7 +1703,7 @@ int CurveOutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScreenC
// 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);
vN = NormalOrUp (& vP, & vS);
// Output the triangles
recprintf (hFile, "facet normal %e %e %e\n", vN.fX, vN.fY, vN.fZ);
......@@ -1718,7 +1718,7 @@ int CurveOutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScreenC
// 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);
vN = NormalOrUp (& vP, & vS);
recprintf (hFile, "facet normal %e %e %e\n", vN.fX, vN.fY, vN.fZ);
recprintf (hFile, "outer loop\n");
......
......@@ -1203,7 +1203,7 @@ int SphericalOutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScr
// 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);
vN = NormalOrUp (& vA, & vP);
afVector[0] = vN.fX;
afVector[1] = vN.fY;
......@@ -1231,7 +1231,7 @@ int SphericalOutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScr
// 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);
vN = NormalOrUp (& vA, & vP);
afVector[0] = vN.fX;
afVector[1] = vN.fY;
......@@ -1262,7 +1262,7 @@ int SphericalOutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScr
// 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);
vN = NormalOrUp (& vA, & vP);
// Output the triangles
recprintf (hFile, "facet normal %e %e %e\n", vN.fX, vN.fY, vN.fZ);
......@@ -1277,7 +1277,7 @@ int SphericalOutputStoredTrianglesSTL (Recall * hFile, bool boBinary, bool boScr
// 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);
vN = NormalOrUp (& vA, & vP);
recprintf (hFile, "facet normal %e %e %e\n", vN.fX, vN.fY, vN.fZ);
recprintf (hFile, "outer loop\n");
......
......@@ -17,6 +17,8 @@
///////////////////////////////////////////////////////////////////
// Defines
#define LENGTH_THRESHOLD (0.001)
///////////////////////////////////////////////////////////////////
// Structures and enumerations
......@@ -51,6 +53,23 @@ Vector3 Normal (Vector3 * v1, Vector3 * v2) {
return vReturn;
}
Vector3 NormalOrUp (Vector3 * v1, Vector3 * v2) {
Vector3 vReturn;
vReturn.fX = (v1->fY * v2->fZ) - (v1->fZ * v2->fY);
vReturn.fY = (v1->fZ * v2->fX) - (v1->fX * v2->fZ);
vReturn.fZ = (v1->fX * v2->fY) - (v1->fY * v2->fX);
if (Length (& vReturn) < LENGTH_THRESHOLD) {
SetVector3 (vReturn, 0.0, 0.0, 1.0);
}
else {
Normalise (& vReturn);
}
return vReturn;
}
void Normalise (Vector3 * v1) {
float fLength;
......
......@@ -100,6 +100,7 @@ typedef struct _Matrix4 {
float absf (float fValue);
Vector3 Normal (Vector3 * v1, Vector3 * v2);
Vector3 NormalOrUp (Vector3 * v1, Vector3 * v2);
Vector3 AddVectors (Vector3 const * v1, Vector3 const * v2);
Vector3 SubtractVectors (Vector3 const * v1, Vector3 const * v2);
//Vector3 MultiplyVectors (Vector3 const * v1, Vector3 const * v2);
......
......@@ -8,25 +8,39 @@
</settings>
<range>
<min>
<coord x="-11.685368" y="-11.609003" z="-11.664000"/>
<coord x="-15.432098" y="-15.432098" z="-15.432098"/>
</min>
<width>
<coord x="23.328000" y="23.328000" z="23.328000"/>
<coord x="30.864198" y="30.864198" z="30.864198"/>
</width>
</range>
<function type="curve">
<equation>0.05*(1*3/((3*cos(p-(a*22/7))**2)+(1*sin(p-(a*22/7))**2)**(1/2)))</equation>
<red>(1+sin(25*a*44/7))/2</red>
<green>(1+cos(25*a*44/7))/2</green>
<blue>(1+cos((11/7)+(25*a*44/7)))/2</blue>
<function type="spherical">
<name>Spherical 0</name>
<equation>2*(2+(sin(cos(t+(3.14159265*sin(t)+a))+(p*((3+cos(t-1.5))/4))*10)**2)+(((6+cos(t))/7)*((2+sin(8*a))/3)**4))</equation>
<red>r/8</red>
<green>(3+sin((a)*8))/5</green>
<blue>(3+cos(a*8))/5</blue>
<alpha>1</alpha>
<accuracy double="0.000200"/>
<accuracy-radius double="0.020000"/>
<equation-x>4*cos(atan((3*sin(a*12*(22/7)))))*cos((((a*1))*(44/7)+(3*sin((4/3)+a*6*22/7))))</equation-x>
<equation-y>4*cos(atan((3*sin(a*12*(22/7)))))*sin((((a*1))*(44/7)+(3*sin((4/3)+a*6*22/7))))</equation-y>
<equation-z>4*sin(atan((3*sin(a*12*(22/7)))))</equation-z>
<accuracy double="0.005000"/>
<centre-x>0.000</centre-x>
<centre-y>0.000</centre-y>
<centre-z>2+(3*sin((5*t)-0.0)/(10))</centre-z>
<texture-file></texture-file>
<texture-x-scale>1.0</texture-x-scale>
<texture-y-scale>1.0</texture-y-scale>
<texture-x-offset>0.0</texture-x-offset>
<texture-y-offset>0.0</texture-y-offset>
</function>
<function type="spherical">
<name>Spherical 1</name>
<equation>5</equation>
<red>0.500</red>
<green>0.606</green>
<blue>0.994</blue>
<alpha>0.900</alpha>
<accuracy double="0.020000"/>
<centre-x>10</centre-x>
<centre-y>0.000</centre-y>
<centre-z>0.000</centre-z>
<texture-file></texture-file>
<texture-x-scale>1.0</texture-x-scale>
......@@ -34,17 +48,32 @@
<texture-x-offset>0.0</texture-x-offset>
<texture-y-offset>0.0</texture-y-offset>
</function>
<function type="cartesian">
<name>Cartesian 2</name>
<equation>sin(x)</equation>
<red>1.000</red>
<green>0.550</green>
<blue>0.550</blue>
<alpha>0.900</alpha>
<accuracy double="0.020000"/>
<texture-file></texture-file>
<texture-x-scale>1.0</texture-x-scale>
<texture-y-scale>1.0</texture-y-scale>
<texture-x-offset>0.0</texture-x-offset>
<texture-y-offset>0.0</texture-y-offset>
</function>
<function type="curve">
<equation>0.03*(1*3/((3*cos(p-(a*22/7))**2)+(1*sin(p-(a*22/7))**2)**(1/2)))</equation>
<red>1-(1+sin(25*a*44/7))/2</red>
<green>1-(1+cos(25*a*44/7))/2</green>
<blue>1-(1+cos((11/7)+(25*a*44/7)))/2</blue>
<alpha>0</alpha>
<accuracy double="0.000200"/>
<name>Curve 3</name>
<equation>(4+sin(a*150))/4</equation>
<red>1.000</red>
<green>0.550</green>
<blue>0.932</blue>
<alpha>1.000</alpha>
<accuracy double="0.010000"/>
<accuracy-radius double="0.020000"/>
<equation-x>4*sin(15*a*22/7)*((1-(((a*2)-1)**2))**(1/2))</equation-x>
<equation-y>4*cos(15*a*22/7)*((1-(((a*2)-1)**2))**(1/2))</equation-y>
<equation-z>((a*8)-4)</equation-z>
<equation-x>(20*a) - 10</equation-x>
<equation-y>7*cos(a*3)</equation-y>
<equation-z>10+5*sin(a*7)</equation-z>
<centre-x>0.000</centre-x>
<centre-y>0.000</centre-y>
<centre-z>0.000</centre-z>
......
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