summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo2009-03-22 05:57:51 +0000
committerLeo2009-03-22 05:57:51 +0000
commitaf984ac7c70952da843f459f5a25e06408e21522 (patch)
tree6ccf916d9d8d8314ab1f7d1b1dc93204c4b697e1
parent5ddc827be12907afffb32430299701b2dc020e54 (diff)
Removed quads.
git-svn-id: http://svn.leocad.org/tags/leocad-0.75@751 c7d43263-9d01-0410-8a33-9dba5d9f93d6
-rwxr-xr-xcommon/library.cpp4
-rw-r--r--common/piece.cpp108
-rw-r--r--common/pieceinf.cpp1614
-rw-r--r--common/pieceinf.h12
-rw-r--r--common/project.cpp83
-rw-r--r--common/project.h2
6 files changed, 548 insertions, 1275 deletions
diff --git a/common/library.cpp b/common/library.cpp
index 9b49d62..3c517d3 100755
--- a/common/library.cpp
+++ b/common/library.cpp
@@ -1667,7 +1667,7 @@ static void CreateMesh(group_t* pGroup, lineinfo_t* info, LC_LDRAW_PIECE* piece)
if (i == 15) i = 23;
}
- if (piece->verts_count > 65535 || quads > 65535)
+ if (piece->verts_count > 65535)
{
piece->long_info = true;
unsigned long* drawinfo;
@@ -2622,7 +2622,7 @@ bool SaveLDrawPiece(LC_LDRAW_PIECE* piece)
bt |= LC_PIECE_MEDIUM;
if (piece->long_info)
- bt |= LC_PIECE_LONGDATA;
+ bt |= LC_PIECE_LONGDATA_FILE;
newidx.WriteByte(&bt, 1);
diff --git a/common/piece.cpp b/common/piece.cpp
index 2410a98..5386f49 100644
--- a/common/piece.cpp
+++ b/common/piece.cpp
@@ -483,21 +483,6 @@ void Piece::MinIntersectDist(LC_CLICKLINE* pLine)
{
info++;
- for (i = 0; i < *info; i += 4)
- {
- Vector3 v1(verts[info[i+1]*3], verts[info[i+1]*3+1], verts[info[i+1]*3+2]);
- Vector3 v2(verts[info[i+2]*3], verts[info[i+2]*3+1], verts[info[i+2]*3+2]);
- Vector3 v3(verts[info[i+3]*3], verts[info[i+3]*3+1], verts[info[i+3]*3+2]);
- Vector3 v4(verts[info[i+4]*3], verts[info[i+4]*3+1], verts[info[i+4]*3+2]);
-
- if (LineQuadMinIntersection(v1, v2, v3, v4, Start, End, pLine->mindist, Intersection))
- {
- pLine->pClosest = this;
- }
- }
-
- info += *info + 1;
-
for (i = 0; i < *info; i += 3)
{
Vector3 v1(verts[info[i+1]*3], verts[info[i+1]*3+1], verts[info[i+1]*3+2]);
@@ -524,21 +509,6 @@ void Piece::MinIntersectDist(LC_CLICKLINE* pLine)
{
info++;
- for (i = 0; i < *info; i += 4)
- {
- Vector3 v1(verts[info[i+1]*3], verts[info[i+1]*3+1], verts[info[i+1]*3+2]);
- Vector3 v2(verts[info[i+2]*3], verts[info[i+2]*3+1], verts[info[i+2]*3+2]);
- Vector3 v3(verts[info[i+3]*3], verts[info[i+3]*3+1], verts[info[i+3]*3+2]);
- Vector3 v4(verts[info[i+4]*3], verts[info[i+4]*3+1], verts[info[i+4]*3+2]);
-
- if (LineQuadMinIntersection(v1, v2, v3, v4, Start, End, pLine->mindist, Intersection))
- {
- pLine->pClosest = this;
- }
- }
-
- info += *info + 1;
-
for (i = 0; i < *info; i += 3)
{
Vector3 v1(verts[info[i+1]*3], verts[info[i+1]*3+1], verts[info[i+1]*3+2]);
@@ -702,18 +672,6 @@ bool Piece::IntersectsVolume(const Vector4* Planes, int NumPlanes)
{
info++;
- for (i = 0; i < *info; i += 4)
- {
- if (PolygonIntersectsPlanes(&verts[info[i+1]*3], &verts[info[i+2]*3],
- &verts[info[i+3]*3], &verts[info[i+4]*3], LocalPlanes, NumPlanes))
- {
- ret = true;
- break;
- }
- }
-
- info += *info + 1;
-
for (i = 0; i < *info; i += 3)
{
if (PolygonIntersectsPlanes(&verts[info[i+1]*3], &verts[info[i+2]*3],
@@ -738,18 +696,6 @@ bool Piece::IntersectsVolume(const Vector4* Planes, int NumPlanes)
{
info++;
- for (i = 0; i < *info; i += 4)
- {
- if (PolygonIntersectsPlanes(&verts[info[i+1]*3], &verts[info[i+2]*3],
- &verts[info[i+3]*3], &verts[info[i+4]*3], LocalPlanes, NumPlanes))
- {
- ret = true;
- break;
- }
- }
-
- info += *info + 1;
-
for (i = 0; i < *info; i += 3)
{
if (PolygonIntersectsPlanes(&verts[info[i+1]*3], &verts[info[i+2]*3],
@@ -878,7 +824,7 @@ void Piece::BuildDrawInfo()
DRAWGROUP* dg;
bool add;
unsigned short group, colcount, i, j;
- unsigned long count[LC_COL_DEFAULT+1][3], vert;
+ unsigned long count[LC_COL_DEFAULT+1][2], vert;
memset (count, 0, sizeof(count));
// Get the vertex count
@@ -913,8 +859,6 @@ void Piece::BuildDrawInfo()
p += *p + 1;
count[curcol][1] += *p;
p += *p + 1;
- count[curcol][2] += *p;
- p += *p + 1;
}
}
else
@@ -932,8 +876,6 @@ void Piece::BuildDrawInfo()
p += *p + 1;
count[curcol][1] += *p;
p += *p + 1;
- count[curcol][2] += *p;
- p += *p + 1;
}
}
}
@@ -942,12 +884,12 @@ void Piece::BuildDrawInfo()
colcount = 0;
vert = 0;
for (i = 0; i < LC_COL_DEFAULT+1; i++)
- if (count[i][0] || count[i][1] || count[i][2])
+ if (count[i][0] || count[i][1])
{
colcount++;
- vert += count[i][0] + count[i][1] + count[i][2];
+ vert += count[i][0] + count[i][1];
}
- vert += (colcount*4)+1;
+ vert += (colcount*3)+1;
// Build the info
if (m_pPieceInfo->m_nFlags & LC_PIECE_LONGDATA)
@@ -960,12 +902,12 @@ void Piece::BuildDrawInfo()
for (i = LC_COL_DEFAULT; i != LC_COL_EDGES+1;)
{
- if (count[i][0] || count[i][1] || count[i][2])
+ if (count[i][0] || count[i][1])
{
*drawinfo = i;
drawinfo++;
- for (j = 0; j < 3; j++)
+ for (j = 0; j < 2; j++)
{
*drawinfo = count[i][j];
drawinfo++;
@@ -1014,20 +956,12 @@ void Piece::BuildDrawInfo()
drawinfo += *p;
}
p += *p + 1;
-
- if (j == 2)
- {
- memcpy(drawinfo, p+1, (*p)*sizeof(unsigned long));
- drawinfo += *p;
- }
- p += *p + 1;
- }
+ }
else
{
p++;
p += *p + 1;
p += *p + 1;
- p += *p + 1;
}
}
}
@@ -1049,12 +983,12 @@ void Piece::BuildDrawInfo()
for (i = LC_COL_DEFAULT; i != LC_COL_EDGES+1;)
{
- if (count[i][0] || count[i][1] || count[i][2])
+ if (count[i][0] || count[i][1])
{
*drawinfo = i;
drawinfo++;
- for (j = 0; j < 3; j++)
+ for (j = 0; j < 2; j++)
{
*drawinfo = (unsigned short)count[i][j];
drawinfo++;
@@ -1103,20 +1037,12 @@ void Piece::BuildDrawInfo()
drawinfo += *p;
}
p += *p + 1;
-
- if (j == 2)
- {
- memcpy(drawinfo, p+1, (*p)*sizeof(unsigned short));
- drawinfo += *p;
- }
- p += *p + 1;
}
else
{
p++;
p += *p + 1;
p += *p + 1;
- p += *p + 1;
}
}
}
@@ -1218,14 +1144,6 @@ void Piece::Render(bool bLighting, bool bEdges, unsigned char* nLastColor, bool*
if (*info)
{
- glDrawElements(GL_QUADS, *info, GL_UNSIGNED_INT, info+1);
- info += *info + 1;
- }
- else
- info++;
-
- if (*info)
- {
glDrawElements(GL_TRIANGLES, *info, GL_UNSIGNED_INT, info+1);
info += *info + 1;
}
@@ -1290,14 +1208,6 @@ void Piece::Render(bool bLighting, bool bEdges, unsigned char* nLastColor, bool*
if (*info)
{
- glDrawElements(GL_QUADS, *info, GL_UNSIGNED_SHORT, info+1);
- info += *info + 1;
- }
- else
- info++;
-
- if (*info)
- {
glDrawElements(GL_TRIANGLES, *info, GL_UNSIGNED_SHORT, info+1);
info += *info + 1;
}
diff --git a/common/pieceinf.cpp b/common/pieceinf.cpp
index 32dd76f..cbf7635 100644
--- a/common/pieceinf.cpp
+++ b/common/pieceinf.cpp
@@ -17,7 +17,7 @@
#include "library.h"
#include "lc_application.h"
-#define SIDES 16
+#define SIDES 8
static float sintbl[SIDES];
static float costbl[SIDES];
@@ -295,1195 +295,618 @@ void PieceInfo::RenderBox()
glDisableClientState(GL_VERTEX_ARRAY);
}
-void PieceInfo::LoadInformation()
+inline lcuint16 EndianSwap(lcuint16 Val)
{
- FileDisk bin;
- char filename[LC_MAXPATH];
- CONNECTIONINFO* pConnection;
- DRAWGROUP* pGroup;
- void* buf;
- lcuint32 verts, *longs, fixverts;
- lcuint16 *ushorts, sh;
- lcuint8 *bytes, *tmp, bt;
- float scale, shift;
- lcint16* shorts;
- int i, j;
-
- // We don't want memory leaks.
- FreeInformation ();
+ return LCUINT16(Val);
+}
- // Open pieces.bin and buffer the information we need.
- strcpy (filename, lcGetPiecesLibrary()->GetLibraryPath());
- strcat (filename, "pieces.bin");
- if (!bin.Open (filename, "rb"))
- return;
-
- buf = malloc(m_nSize);
- bin.Seek(m_nOffset, SEEK_SET);
- bin.Read(buf, m_nSize);
- bin.Close();
-
- shift = 1.0f/(1<<14);
- scale = 0.01f;
- if (m_nFlags & LC_PIECE_MEDIUM) scale = 0.001f;
- if (m_nFlags & LC_PIECE_SMALL) scale = 0.0001f;
- longs = (lcuint32*)buf;
- fixverts = verts = LCUINT32(*longs);
- bytes = (unsigned char*)(longs + 1);
- bytes += verts * sizeof(lcint16) * 3;
-
- // Read connections
- m_nConnectionCount = LCUINT16(*((lcuint16*)bytes));
- bytes += sizeof (lcuint16);
- m_pConnections = (CONNECTIONINFO*)malloc((m_nConnectionCount+1) * sizeof(CONNECTIONINFO));
-
- sh = m_nConnectionCount;
- for (pConnection = m_pConnections; sh--; pConnection++)
- {
- pConnection->type = *bytes;
- bytes++;
-
- shorts = (lcint16*)bytes;
- pConnection->center[0] = (float)(LCINT16(*shorts))*scale;
- shorts++;
- pConnection->center[1] = (float)(LCINT16(*shorts))*scale;
- shorts++;
- pConnection->center[2] = (float)(LCINT16(*shorts))*scale;
- shorts++;
- pConnection->normal[0] = (float)(LCINT16(*shorts))*shift;
- shorts++;
- pConnection->normal[1] = (float)(LCINT16(*shorts))*shift;
- shorts++;
- pConnection->normal[2] = (float)(LCINT16(*shorts))*shift;
- shorts++;
-
- bytes = (unsigned char*)shorts;
- }
+inline lcuint32 EndianSwap(lcuint32 Val)
+{
+ return LCUINT32(Val);
+}
- // Load textures
- m_nTextureCount = *bytes;
- if (m_nTextureCount > 0)
- m_pTextures = (TEXTURE*)malloc(m_nTextureCount*sizeof(TEXTURE));
- bytes++;
+template<class S, class D>
+static void WriteMeshDrawInfo(lcuint8*& Data, DRAWGROUP* Group)
+{
+ S* SrcPtr = (S*)Data;
+ int NumColors = EndianSwap(*SrcPtr);
+ SrcPtr++;
- for (sh = 0; sh < m_nTextureCount; sh++)
- {
- char name[9];
- TEXTURE* tex = &m_pTextures[sh];
- tex->color = ConvertColor(*bytes);
- bytes++;
+ // Count the number of indices needed.
+ int TotalLines = 0, TotalTris = 0, TotalQuads = 0;
- strcpy(name, (char*)bytes);
- tex->texture = lcGetPiecesLibrary()->FindTexture(name);
+ for (int i = 0; i < NumColors; i++)
+ {
+ SrcPtr++;
+
+ int NumQuads = EndianSwap(*SrcPtr);
+ SrcPtr += NumQuads + 1;
+ TotalQuads += NumQuads;
+ int NumTris = EndianSwap(*SrcPtr);
+ SrcPtr += NumTris + 1;
+ TotalTris += NumTris;
+ int NumLines = EndianSwap(*SrcPtr);
+ SrcPtr += NumLines + 1;
+ TotalLines += NumLines;
+ }
- shorts = (lcint16*)(bytes + 8);
- for (i = 0; i < 4; i++)
- {
- tex->vertex[i][0] = (float)LCINT16(shorts[0])*scale;
- tex->vertex[i][1] = (float)LCINT16(shorts[1])*scale;
- tex->vertex[i][2] = (float)LCINT16(shorts[2])*scale;
- shorts += 3;
- }
+ int TotalIndices = TotalLines + TotalTris + TotalQuads / 4 * 6 + 1 + 3 * NumColors;
- for (i = 0; i < 4; i++)
- {
- tex->coords[i][0] = (float)LCINT16(shorts[0]);
- tex->coords[i][1] = (float)LCINT16(shorts[1]);
- shorts += 2;
- }
+ Group->drawinfo = malloc(TotalIndices * sizeof(D));
+ D* DestPtr = (D*)Group->drawinfo;
- bytes += 8 + 20*sizeof(lcuint16);
- }
+ SrcPtr = (S*)Data;
+ SrcPtr++;
+ *DestPtr = NumColors;
+ DestPtr++;
- // Read groups
- m_nGroupCount = LCUINT16(*((lcuint16*)bytes));
- bytes += sizeof(lcuint16);
- m_pGroups = (DRAWGROUP*)malloc(sizeof(DRAWGROUP)*m_nGroupCount);
- memset(m_pGroups, 0, sizeof(DRAWGROUP)*m_nGroupCount);
-
- // First we need to know the number of vertexes
- tmp = bytes;
- sh = m_nGroupCount;
- lcuint32 quads = 0, fixquads = 0;
- while (sh--)
- {
- bt = *bytes;
- bytes++;
- bytes += bt*sizeof(lcuint16);
+ for (int Color = 0; Color < NumColors; Color++)
+ {
+ *DestPtr = ConvertColor(EndianSwap(*SrcPtr));
+ DestPtr++;
+ SrcPtr++;
- while (*bytes)
- {
- if (*bytes == LC_MESH)
- {
- if ((fixverts > 65535) || (m_nFlags & LC_PIECE_LONGDATA))
- {
- lcuint32 colors, *p;
- p = (lcuint32*)(bytes + 1);
- colors = LCUINT32(*p);
- p++;
+ D* TriPtr = DestPtr;
+ DestPtr++;
- while (colors--)
- {
- p++; // color code
- quads += LCUINT32(*p);
- fixquads += LCUINT32(*p);
- p += LCUINT32(*p) + 1;
- p += LCUINT32(*p) + 1;
- p += LCUINT32(*p) + 1;
- }
+ int NumQuads = EndianSwap(*SrcPtr);
+ SrcPtr++;
- bytes = (unsigned char*)p;
- }
- else
- {
- lcuint16 colors, *p;
- p = (lcuint16*)(bytes + 1);
- colors = LCUINT16(*p);
- p++;
+ for (int i = 0; i < NumQuads; i += 4)
+ {
+ DestPtr[0] = EndianSwap(SrcPtr[0]);
+ DestPtr[1] = EndianSwap(SrcPtr[1]);
+ DestPtr[2] = EndianSwap(SrcPtr[2]);
+ DestPtr[3] = EndianSwap(SrcPtr[0]);
+ DestPtr[4] = EndianSwap(SrcPtr[2]);
+ DestPtr[5] = EndianSwap(SrcPtr[3]);
+ DestPtr += 6;
+ SrcPtr += 4;
+ }
- while (colors--)
- {
- p++; // color code
- quads += LCUINT16(*p);
- fixquads += LCUINT16(*p);
- p += LCUINT16(*p) + 1;
- p += LCUINT16(*p) + 1;
- p += LCUINT16(*p) + 1;
- }
+ int NumTris = EndianSwap(*SrcPtr);
+ SrcPtr++;
- bytes = (unsigned char*)p;
- }
- }
+ for (int i = 0; i < NumTris; i++, SrcPtr++, DestPtr++)
+ *DestPtr = EndianSwap(*SrcPtr);
- if (*bytes == LC_STUD)
- {
- verts += (2*SIDES)+1;
- quads += 4*SIDES;
- bytes += 2*sizeof(unsigned char) + 12*sizeof(float);
- }
+ *TriPtr = NumTris + NumQuads / 4 * 6;
- if (*bytes == LC_STUD2)
- {
- verts += 4*SIDES;
- quads += 12*SIDES;
- bytes += 2*sizeof(unsigned char) + 12*sizeof(float);
- }
+ int NumLines = EndianSwap(*SrcPtr);
+ SrcPtr++;
+ *DestPtr = NumLines;
+ DestPtr++;
- if (*bytes == LC_STUD3)
- {
- verts += (2*SIDES)+1;
- quads += 4*SIDES;
- bytes += 2*sizeof(unsigned char) + 12*sizeof(float);
- }
+ for (int i = 0; i < NumLines; i++, SrcPtr++, DestPtr++)
+ *DestPtr = EndianSwap(*SrcPtr);
+ }
- if (*bytes == LC_STUD4)
- {
- verts += 4*SIDES;
- quads += 12*SIDES;
- bytes += 2*sizeof(unsigned char) + 12*sizeof(float);
- }
- }
- bytes++; // should be 0
- }
+ Data = (lcuint8*)SrcPtr;
+}
- m_fVertexArray = (float*)malloc(3*sizeof(float)*verts);
- m_nVertexCount = verts;
- if ((verts > 65535) || (quads > 65535) || (fixquads > 65535))
+template<class T>
+static void WriteStudDrawInfo(int Color, float* Verts, int BaseVertex, DRAWGROUP* Group, float Radius)
+{
+ // Build vertices.
+ for (int i = 0; i < SIDES; i++)
{
- if ((m_nFlags & LC_PIECE_LONGDATA) == 0)
- {
- m_nFlags |= LC_PIECE_LONGDATA | LC_PIECE_LONGDATA_RUNTIME;
- }
+ *Verts++ = Radius * costbl[i];
+ *Verts++ = Radius * sintbl[i];
+ *Verts++ = 0.0f;
+
+ *Verts++ = Radius * costbl[i];
+ *Verts++ = Radius * sintbl[i];
+ *Verts++ = LC_STUD_HEIGHT;
}
- else
- m_nFlags &= ~(LC_PIECE_LONGDATA | LC_PIECE_LONGDATA_RUNTIME);
- // Copy the 'fixed' vertexes
- shorts = (lcint16*)(longs + 1);
- for (verts = 0; verts < LCUINT32(*longs); verts++)
- {
- m_fVertexArray[verts*3] = (float)LCINT16(*shorts)*scale;
- shorts++;
- m_fVertexArray[verts*3+1] = (float)LCINT16(*shorts)*scale;
- shorts++;
- m_fVertexArray[verts*3+2] = (float)LCINT16(*shorts)*scale;
- shorts++;
- }
+ *Verts++ = 0.0f;
+ *Verts++ = 0.0f;
+ *Verts++ = LC_STUD_HEIGHT;
- // Read groups
- bytes = tmp;
- sh = m_nGroupCount;
- for (pGroup = m_pGroups; sh--; pGroup++)
- {
- bt = *bytes;
- bytes++;
+ // Build indices.
+ int NumIndices = 1 + 2 * 3 + 9 * SIDES + 4 * SIDES;
- pGroup->connections[bt] = 0xFFFF;
- while(bt--)
- {
- lcuint16 tmp = LCUINT16(*((lcuint16*)bytes));
- pGroup->connections[bt] = tmp;
- bytes += sizeof(lcuint16);
- }
+ Group->drawinfo = malloc(sizeof(T) * NumIndices);
+ T* Indices = (T*)Group->drawinfo;
- // Currently there's only one type of drawinfo (mesh or stud)
- // per group but this will change in the future.
- switch (*bytes)
- {
- case LC_MESH:
- if ((fixverts > 65535) || (fixquads > 65535))
- {
- lcuint32 colors, *p;
- bytes++;
- p = (lcuint32*)bytes;
- *p = LCUINT32(*p);
- colors = *p;
- p++;
+ *Indices++ = 2;
+ *Indices++ = Color;
+ *Indices++ = 9 * SIDES;
- while (colors--)
- {
- *p = ConvertColor(LCUINT32(*p));
- p++; // color code
-#ifdef LC_BIG_ENDIAN
- int f;
- f = LCUINT32(*p) + 1;
- while (f--) { *p = LCUINT32(*p); p++; };
- f = LCUINT32(*p) + 1;
- while (f--) { *p = LCUINT32(*p); p++; };
- f = LCUINT32(*p) + 1;
- while (f--) { *p = LCUINT32(*p); p++; };
-#else
- p += LCUINT32(*p) + 1;
- p += LCUINT32(*p) + 1;
- p += LCUINT32(*p) + 1;
-#endif
- }
+ int v0 = BaseVertex + 2 * SIDES;
- i = (unsigned char*)p - bytes;
- pGroup->drawinfo = malloc(i);
- memcpy(pGroup->drawinfo, bytes, i);
- bytes = (unsigned char*)p;
- }
- else
- {
- lcuint16 colors, *p;
- bytes++;
- p = (lcuint16*)bytes;
- *p = LCUINT16(*p);
- colors = *p;
- p++;
+ // Triangles.
+ for (int i = 0; i < SIDES; i++)
+ {
+ int i1 = BaseVertex + (i % SIDES) * 2;
+ int i2 = BaseVertex + ((i + 1) % SIDES) * 2;
- while (colors--)
- {
- *p = ConvertColor(LCUINT16(*p));
- p++; // color code
-#ifdef LC_BIG_ENDIAN
- int f;
- f = LCUINT16(*p) + 1;
- while (f--) { *p = LCUINT16(*p); p++; };
- f = LCUINT16(*p) + 1;
- while (f--) { *p = LCUINT16(*p); p++; };
- f = LCUINT16(*p) + 1;
- while (f--) { *p = LCUINT16(*p); p++; };
-#else
- p += *p + 1;
- p += *p + 1;
- p += *p + 1;
-#endif
- }
+ int v1 = i1;
+ int v2 = i1 + 1;
+ int v3 = i2;
+ int v4 = i2 + 1;
- i = (unsigned char*)p - bytes;
+ *Indices++ = v0;
+ *Indices++ = v2;
+ *Indices++ = v4;
- if (m_nFlags & LC_PIECE_LONGDATA)
- {
- pGroup->drawinfo = malloc(i*sizeof(lcuint32)/sizeof(lcuint16));
- longs = (lcuint32*)pGroup->drawinfo;
+ *Indices++ = v1;
+ *Indices++ = v3;
+ *Indices++ = v2;
- for (ushorts = (lcuint16*)bytes; ushorts != p; ushorts++, longs++)
- *longs = *ushorts;//LCUINT16(*ushorts);
- }
- else
- {
- pGroup->drawinfo = malloc(i);
- memcpy(pGroup->drawinfo, bytes, i);
- }
+ *Indices++ = v3;
+ *Indices++ = v4;
+ *Indices++ = v2;
+ }
- bytes = (unsigned char*)p;
- }
- break;
+ *Indices++ = 0;
- case LC_STUD:
- {
- int size;
- Matrix mat;
-
- for (i = 0; i < 12; i++)
- ((float*)(bytes+2))[i] = LCFLOAT (((float*)(bytes+2))[i]);
- mat.FromPacked ((float*)(bytes+2));
- lcuint16 color = ConvertColor(*(bytes+1));
-
- // Create the vertexes
- for (i = 0; i < SIDES; i++)
- {
- m_fVertexArray[(verts+i+SIDES)*3] =
- m_fVertexArray[(verts+i)*3] =
- LC_STUD_RADIUS * costbl[i];
- m_fVertexArray[(verts+i+SIDES)*3+1] =
- m_fVertexArray[(verts+i)*3+1] =
- LC_STUD_RADIUS * sintbl[i];
- m_fVertexArray[(verts+i)*3+2] = 0;
- m_fVertexArray[(verts+i+SIDES)*3+2] = LC_STUD_HEIGHT;
- }
- m_fVertexArray[(verts+2*SIDES)*3] = 0;
- m_fVertexArray[(verts+2*SIDES)*3+1] = 0;
- m_fVertexArray[(verts+2*SIDES)*3+2] = LC_STUD_HEIGHT;
-
- mat.TransformPoints(&m_fVertexArray[verts*3], 2*SIDES+1);
- // colors + 2*num_prim + sides*prims
- size = 9+SIDES*11;
-
- if (m_nFlags & LC_PIECE_LONGDATA)
- {
- pGroup->drawinfo = malloc(sizeof(lcuint32)*size);
- longs = (lcuint32*)pGroup->drawinfo;
-
- longs[0] = 2; // colors
- longs[1] = color;
- longs[2] = SIDES*4;
- j = 3;
-
- for (i = 0; i < SIDES; i++)
- {
- longs[3+i*4] = (lcuint32)verts + i;
- if (i == SIDES-1)
- {
- longs[4+i*4] = (lcuint32)verts;
- longs[5+i*4] = (lcuint32)verts + SIDES;
- }
- else
- {
- longs[4+i*4] = (lcuint32)verts + i + 1;
- longs[5+i*4] = (lcuint32)verts + SIDES + i + 1;
- }
- longs[6+i*4] = (lcuint32)verts + SIDES + i;
- }
- j += 4*SIDES;
- longs[j] = SIDES*3;
- j++;
+ // Lines.
+ *Indices++ = LC_COL_EDGES;
+ *Indices++ = 0;
+ *Indices++ = 4 * SIDES;
- for (i = 0; i < SIDES; i++)
+ for (int i = 0; i < SIDES; i++)
{
- longs[j+i*3] = (lcuint16)verts + 2*SIDES;
- longs[1+j+i*3] = (lcuint16)verts + SIDES + i;
- if (i == SIDES-1)
- longs[2+j+i*3] = (lcuint16)verts + SIDES;
- else
- longs[2+j+i*3] = (lcuint16)verts + SIDES + i + 1;
- }
+ int i1 = BaseVertex + (i % SIDES) * 2;
+ int i2 = BaseVertex + ((i + 1) % SIDES) * 2;
- j += 3*SIDES;
- longs[j] = 0; j++; // lines
- longs[j] = LC_COL_EDGES; j++; // color
- longs[j] = 0; j++; // quads
- longs[j] = 0; j++; // tris
- longs[j] = 4*SIDES; j++;
+ int v1 = i1;
+ int v2 = i1 + 1;
+ int v3 = i2;
+ int v4 = i2 + 1;
- for (i = 0; i < SIDES; i++)
- {
- longs[j+i*4] = (lcuint32)verts + i;
- if (i == SIDES-1)
- longs[1+j+i*4] = (lcuint32)verts;
- else
- longs[1+j+i*4] = (lcuint32)verts + i + 1;
-
- longs[2+j+i*4] = longs[j+i*4] + SIDES;
- longs[3+j+i*4] = longs[1+j+i*4] + SIDES;
- }
- }
- else
- {
- pGroup->drawinfo = malloc(sizeof(lcuint16)*size);
- ushorts = (lcuint16*)pGroup->drawinfo;
-
- ushorts[0] = 2; // colors
- ushorts[1] = color;
- ushorts[2] = SIDES*4;
- j = 3;
-
- for (i = 0; i < SIDES; i++)
- {
- ushorts[3+i*4] = (lcuint16)(verts + i);
- if (i == SIDES-1)
- {
- ushorts[4+i*4] = (lcuint16)verts;
- ushorts[5+i*4] = (lcuint16)verts + SIDES;
- }
- else
- {
- ushorts[4+i*4] = (lcuint16)verts + i + 1;
- ushorts[5+i*4] = (lcuint16)verts + SIDES + i + 1;
- }
- ushorts[6+i*4] = (lcuint16)verts + SIDES + i;
- }
- j += 4*SIDES;
- ushorts[j] = SIDES*3;
- j++;
+ *Indices++ = v1;
+ *Indices++ = v3;
- for (i = 0; i < SIDES; i++)
- {
- ushorts[j+i*3] = (lcuint16)verts + 2*SIDES;
- ushorts[1+j+i*3] = (lcuint16)verts + SIDES + i;
- if (i == SIDES-1)
- ushorts[2+j+i*3] = (lcuint16)verts + SIDES;
- else
- ushorts[2+j+i*3] = (lcuint16)verts + SIDES + i + 1;
+ *Indices++ = v2;
+ *Indices++ = v4;
}
+}
- j += 3*SIDES;
- ushorts[j] = 0; j++; // lines
- ushorts[j] = LC_COL_EDGES; j++; // color
- ushorts[j] = 0; j++; // quads
- ushorts[j] = 0; j++; // tris
- ushorts[j] = 4*SIDES; j++;
-
- for (i = 0; i < SIDES; i++)
+template<class T>
+static void WriteHollowStudDrawInfo(int Color, float* Verts, int BaseVertex, DRAWGROUP* Group, float InnerRadius, float OuterRadius)
+{
+ // Build vertices.
+ for (int i = 0; i < SIDES; i++)
{
- ushorts[j+i*4] = (lcuint16)verts + i;
- if (i == SIDES-1)
- ushorts[1+j+i*4] = (lcuint16)verts;
- else
- ushorts[1+j+i*4] = (lcuint16)verts + i + 1;
-
- ushorts[2+j+i*4] = ushorts[j+i*4] + SIDES;
- ushorts[3+j+i*4] = ushorts[1+j+i*4] + SIDES;
+ // Outside.
+ *Verts++ = OuterRadius * costbl[i];
+ *Verts++ = OuterRadius * sintbl[i];
+ *Verts++ = 0.0f;
+
+ *Verts++ = OuterRadius * costbl[i];
+ *Verts++ = OuterRadius * sintbl[i];
+ *Verts++ = LC_STUD_HEIGHT;
+
+ // Inside.
+ *Verts++ = InnerRadius * costbl[i];
+ *Verts++ = InnerRadius * sintbl[i];
+ *Verts++ = LC_STUD_HEIGHT;
+
+ *Verts++ = InnerRadius * costbl[i];
+ *Verts++ = InnerRadius * sintbl[i];
+ *Verts++ = 0.0f;
}
- }
- verts += 2*SIDES+1;
- bytes += 2*sizeof(unsigned char) + 12*sizeof(float);
- } break;
+ // Build indices.
+ int NumIndices = 1 + 2 * 3 + 18 * SIDES + 8 * SIDES;
- case LC_STUD2:
- {
- int size;
- Matrix mat;
-
- for (i = 0; i < 12; i++)
- ((float*)(bytes+2))[i] = LCFLOAT (((float*)(bytes+2))[i]);
- mat.FromPacked ((float*)(bytes+2));
- lcuint16 color = ConvertColor(*(bytes+1));
-
- // Create the vertexes
- for (i = 0; i < SIDES; i++)
- {
- // outside
- m_fVertexArray[(verts+i+SIDES)*3] =
- m_fVertexArray[(verts+i)*3] =
- LC_STUD_RADIUS * costbl[i];
- m_fVertexArray[(verts+i+SIDES)*3+1] =
- m_fVertexArray[(verts+i)*3+1] =
- LC_STUD_RADIUS * sintbl[i];
- m_fVertexArray[(verts+i)*3+2] = LC_STUD_HEIGHT;
- m_fVertexArray[(verts+i+SIDES)*3+2] = 0;
-
- // inside
- m_fVertexArray[(verts+i+2*SIDES)*3] =
- m_fVertexArray[(verts+i+3*SIDES)*3] =
- 0.16f * costbl[i];
- m_fVertexArray[(verts+i+2*SIDES)*3+1] =
- m_fVertexArray[(verts+i+3*SIDES)*3+1] =
- 0.16f * sintbl[i];
- m_fVertexArray[(verts+i+3*SIDES)*3+2] = LC_STUD_HEIGHT;
- m_fVertexArray[(verts+i+2*SIDES)*3+2] = 0;
- }
-
- mat.TransformPoints(&m_fVertexArray[verts*3], 4*SIDES);
- // colors + 2*num_prim + sides*prims
- size = 9+SIDES*20;
-
- if (m_nFlags & LC_PIECE_LONGDATA)
- {
- pGroup->drawinfo = malloc(sizeof(lcuint32)*size);
- longs = (lcuint32*)pGroup->drawinfo;
-
- longs[0] = 2; // colors
- longs[1] = color;
- longs[2] = SIDES*12;
- j = 3;
-
- // outside
- for (i = 0; i < SIDES; i++)
- {
- longs[j+i*4] = (lcuint32)(verts + SIDES + i);
- if (i == SIDES-1)
- {
- longs[j+1+i*4] = (lcuint32)verts + SIDES;
- longs[j+2+i*4] = (lcuint32)verts;
- }
- else
- {
- longs[j+1+i*4] = (lcuint32)verts + SIDES + i + 1;
- longs[j+2+i*4] = (lcuint32)verts + i + 1;
- }
- longs[j+3+i*4] = (lcuint32)verts + i;
- }
- j += 4*SIDES;
+ Group->drawinfo = malloc(sizeof(T) * NumIndices);
+ T* Indices = (T*)Group->drawinfo;
- // inside
- for (i = 0; i < SIDES; i++)
- {
- longs[j+i*4] = (lcuint32)(verts + 2*SIDES + i);
- if (i == SIDES-1)
- {
- longs[j+1+i*4] = (lcuint32)verts + 2*SIDES;
- longs[j+2+i*4] = (lcuint32)verts + 3*SIDES;
- }
- else
- {
- longs[j+1+i*4] = (lcuint32)verts + 2*SIDES + i + 1;
- longs[j+2+i*4] = (lcuint32)verts + 3*SIDES + i + 1;
- }
- longs[j+3+i*4] = (lcuint32)verts + 3*SIDES + i;
- }
- j += 4*SIDES;
+ *Indices++ = 2;
+ *Indices++ = Color;
+ *Indices++ = 18 * SIDES;
- // ring
- for (i = 0; i < SIDES; i++)
+ // Triangles.
+ for (int i = 0; i < SIDES; i++)
{
- longs[j+i*4] = (lcuint32)(verts + i);
- if (i == SIDES-1)
- {
- longs[j+1+i*4] = (lcuint32)verts;
- longs[j+2+i*4] = (lcuint32)verts + 3*SIDES;
- }
- else
- {
- longs[j+1+i*4] = (lcuint32)verts + i + 1;
- longs[j+2+i*4] = (lcuint32)verts + 3*SIDES + i + 1;
- }
- longs[j+3+i*4] = (lcuint32)verts + 3*SIDES + i;
+ int i1 = BaseVertex + (i % SIDES) * 4;
+ int i2 = BaseVertex + ((i + 1) % SIDES) * 4;
+
+ int v1 = i1;
+ int v2 = i1 + 1;
+ int v3 = i1 + 2;
+ int v4 = i1 + 3;
+ int v5 = i2;
+ int v6 = i2 + 1;
+ int v7 = i2 + 2;
+ int v8 = i2 + 3;
+
+ *Indices++ = v1;
+ *Indices++ = v5;
+ *Indices++ = v2;
+
+ *Indices++ = v5;
+ *Indices++ = v6;
+ *Indices++ = v2;
+
+ *Indices++ = v2;
+ *Indices++ = v6;
+ *Indices++ = v3;
+
+ *Indices++ = v6;
+ *Indices++ = v7;
+ *Indices++ = v3;
+
+ *Indices++ = v3;
+ *Indices++ = v7;
+ *Indices++ = v4;
+
+ *Indices++ = v7;
+ *Indices++ = v8;
+ *Indices++ = v4;
}
- j += 4*SIDES;
- longs[j] = 0; j++; // tris
- longs[j] = 0; j++; // lines
- longs[j] = LC_COL_EDGES; j++; // color
- longs[j] = 0; j++; // quads
- longs[j] = 0; j++; // tris
- longs[j] = 8*SIDES; j++;
+ *Indices++ = 0;
- // outside
- for (i = 0; i < SIDES; i++)
- {
- longs[j+i*4] = (lcuint32)verts + i;
- if (i == SIDES-1)
- longs[1+j+i*4] = (lcuint32)verts;
- else
- longs[1+j+i*4] = (lcuint32)verts + i + 1;
-
- longs[2+j+i*4] = longs[j+i*4] + SIDES;
- longs[3+j+i*4] = longs[1+j+i*4] + SIDES;
- }
- j += 4*SIDES;
+ // Lines.
+ *Indices++ = LC_COL_EDGES;
+ *Indices++ = 0;
+ *Indices++ = 8 * SIDES;
- // inside
- for (i = 0; i < SIDES; i++)
+ for (int i = 0; i < SIDES; i++)
{
- longs[j+i*4] = (lcuint32)verts + 2*SIDES + i;
- if (i == SIDES-1)
- longs[1+j+i*4] = (lcuint32)verts + 2*SIDES;
- else
- longs[1+j+i*4] = (lcuint32)verts + 2*SIDES + i + 1;
-
- longs[2+j+i*4] = longs[j+i*4] + SIDES;
- longs[3+j+i*4] = longs[1+j+i*4] + SIDES;
- }
- }
- else
- {
- pGroup->drawinfo = malloc(sizeof(lcuint16)*size);
- ushorts = (lcuint16*)pGroup->drawinfo;
-
- ushorts[0] = 2; // colors
- ushorts[1] = color;
- ushorts[2] = SIDES*12;
- j = 3;
-
- // outside
- for (i = 0; i < SIDES; i++)
- {
- ushorts[j+i*4] = (lcuint16)(verts + SIDES + i);
- if (i == SIDES-1)
- {
- ushorts[j+1+i*4] = (lcuint16)verts + SIDES;
- ushorts[j+2+i*4] = (lcuint16)verts;
- }
- else
- {
- ushorts[j+1+i*4] = (lcuint16)verts + SIDES + i + 1;
- ushorts[j+2+i*4] = (lcuint16)verts + i + 1;
- }
- ushorts[j+3+i*4] = (lcuint16)verts + i;
- }
- j += 4*SIDES;
+ int i1 = BaseVertex + (i % SIDES) * 4;
+ int i2 = BaseVertex + ((i + 1) % SIDES) * 4;
- // inside
- for (i = 0; i < SIDES; i++)
- {
- ushorts[j+i*4] = (lcuint16)(verts + 3*SIDES + i);
- if (i == SIDES-1)
- {
- ushorts[j+1+i*4] = (lcuint16)verts + 3*SIDES;
- ushorts[j+2+i*4] = (lcuint16)verts + 2*SIDES;
- }
- else
- {
- ushorts[j+1+i*4] = (lcuint16)verts + 3*SIDES + i + 1;
- ushorts[j+2+i*4] = (lcuint16)verts + 2*SIDES + i + 1;
- }
- ushorts[j+3+i*4] = (lcuint16)verts + 2*SIDES + i;
- }
- j += 4*SIDES;
+ int v1 = i1;
+ int v2 = i1 + 1;
+ int v3 = i1 + 2;
+ int v4 = i1 + 3;
+ int v5 = i2;
+ int v6 = i2 + 1;
+ int v7 = i2 + 2;
+ int v8 = i2 + 3;
- // ring
- for (i = 0; i < SIDES; i++)
- {
- ushorts[j+i*4] = (lcuint16)(verts + i);
- if (i == SIDES-1)
- {
- ushorts[j+1+i*4] = (lcuint16)verts;
- ushorts[j+2+i*4] = (lcuint16)verts + 3*SIDES;
- }
- else
- {
- ushorts[j+1+i*4] = (lcuint16)verts + i + 1;
- ushorts[j+2+i*4] = (lcuint16)verts + 3*SIDES + i + 1;
- }
- ushorts[j+3+i*4] = (lcuint16)verts + 3*SIDES + i;
- }
- j += 4*SIDES;
+ *Indices++ = v1;
+ *Indices++ = v5;
- ushorts[j] = 0; j++; // tris
- ushorts[j] = 0; j++; // lines
- ushorts[j] = LC_COL_EDGES; j++; // color
- ushorts[j] = 0; j++; // quads
- ushorts[j] = 0; j++; // tris
- ushorts[j] = 8*SIDES; j++;
+ *Indices++ = v2;
+ *Indices++ = v6;
- // outside
- for (i = 0; i < SIDES; i++)
- {
- ushorts[j+i*4] = (lcuint16)verts + i;
- if (i == SIDES-1)
- ushorts[1+j+i*4] = (lcuint16)verts;
- else
- ushorts[1+j+i*4] = (lcuint16)verts + i + 1;
-
- ushorts[2+j+i*4] = ushorts[j+i*4] + SIDES;
- ushorts[3+j+i*4] = ushorts[1+j+i*4] + SIDES;
+ *Indices++ = v3;
+ *Indices++ = v7;
+
+ *Indices++ = v4;
+ *Indices++ = v8;
}
- j += 4*SIDES;
+}
- // inside
- for (i = 0; i < SIDES; i++)
+void PieceInfo::LoadInformation()
+{
+ FileDisk bin;
+ char filename[LC_MAXPATH];
+ CONNECTIONINFO* pConnection;
+ DRAWGROUP* pGroup;
+ void* buf;
+ lcuint32 verts, *longs, fixverts;
+ lcuint16 sh;
+ lcuint8 *bytes, *tmp, bt;
+ float scale, shift;
+ lcint16* shorts;
+ int i;
+
+ // We don't want memory leaks.
+ FreeInformation ();
+
+ // Open pieces.bin and buffer the information we need.
+ strcpy (filename, lcGetPiecesLibrary()->GetLibraryPath());
+ strcat (filename, "pieces.bin");
+ if (!bin.Open (filename, "rb"))
+ return;
+
+ buf = malloc(m_nSize);
+ bin.Seek(m_nOffset, SEEK_SET);
+ bin.Read(buf, m_nSize);
+ bin.Close();
+
+ shift = 1.0f/(1<<14);
+ scale = 0.01f;
+ if (m_nFlags & LC_PIECE_MEDIUM) scale = 0.001f;
+ if (m_nFlags & LC_PIECE_SMALL) scale = 0.0001f;
+ longs = (lcuint32*)buf;
+ fixverts = verts = LCUINT32(*longs);
+ bytes = (unsigned char*)(longs + 1);
+ bytes += verts * sizeof(lcint16) * 3;
+
+ // Read connections
+ m_nConnectionCount = LCUINT16(*((lcuint16*)bytes));
+ bytes += sizeof (lcuint16);
+ m_pConnections = (CONNECTIONINFO*)malloc((m_nConnectionCount+1) * sizeof(CONNECTIONINFO));
+
+ sh = m_nConnectionCount;
+ for (pConnection = m_pConnections; sh--; pConnection++)
{
- ushorts[j+i*4] = (lcuint16)verts + 2*SIDES + i;
- if (i == SIDES-1)
- ushorts[1+j+i*4] = (lcuint16)verts + 2*SIDES;
- else
- ushorts[1+j+i*4] = (lcuint16)verts + 2*SIDES + i + 1;
-
- ushorts[2+j+i*4] = ushorts[j+i*4] + SIDES;
- ushorts[3+j+i*4] = ushorts[1+j+i*4] + SIDES;
+ pConnection->type = *bytes;
+ bytes++;
+
+ shorts = (lcint16*)bytes;
+ pConnection->center[0] = (float)(LCINT16(*shorts))*scale;
+ shorts++;
+ pConnection->center[1] = (float)(LCINT16(*shorts))*scale;
+ shorts++;
+ pConnection->center[2] = (float)(LCINT16(*shorts))*scale;
+ shorts++;
+ pConnection->normal[0] = (float)(LCINT16(*shorts))*shift;
+ shorts++;
+ pConnection->normal[1] = (float)(LCINT16(*shorts))*shift;
+ shorts++;
+ pConnection->normal[2] = (float)(LCINT16(*shorts))*shift;
+ shorts++;
+
+ bytes = (unsigned char*)shorts;
}
- }
- verts += 4*SIDES;
- bytes += 2*sizeof(unsigned char) + 12*sizeof(float);
- } break;
+ // Load textures
+ m_nTextureCount = *bytes;
+ if (m_nTextureCount > 0)
+ m_pTextures = (TEXTURE*)malloc(m_nTextureCount*sizeof(TEXTURE));
+ bytes++;
- case LC_STUD3:
- {
- int size;
- Matrix mat;
-
- for (i = 0; i < 12; i++)
- ((float*)(bytes+2))[i] = LCFLOAT (((float*)(bytes+2))[i]);
- mat.FromPacked ((float*)(bytes+2));
- lcuint16 color = ConvertColor(*(bytes+1));
-
- // Create the vertexes
- for (i = 0; i < SIDES; i++)
- {
- m_fVertexArray[(verts+i+SIDES)*3] =
- m_fVertexArray[(verts+i)*3] =
- 0.16f * costbl[i];
- m_fVertexArray[(verts+i+SIDES)*3+1] =
- m_fVertexArray[(verts+i)*3+1] =
- 0.16f * sintbl[i];
- m_fVertexArray[(verts+i)*3+2] = 0;
- m_fVertexArray[(verts+i+SIDES)*3+2] = LC_STUD_HEIGHT;
- }
- m_fVertexArray[(verts+2*SIDES)*3] = 0;
- m_fVertexArray[(verts+2*SIDES)*3+1] = 0;
- m_fVertexArray[(verts+2*SIDES)*3+2] = LC_STUD_HEIGHT;
-
- mat.TransformPoints(&m_fVertexArray[verts*3], 2*SIDES+1);
- // colors + 2*num_prim + sides*prims
- size = 9+SIDES*11;
-
- if (m_nFlags & LC_PIECE_LONGDATA)
- {
- pGroup->drawinfo = malloc(sizeof(lcuint32)*size);
- longs = (lcuint32*)pGroup->drawinfo;
-
- longs[0] = 2; // colors
- longs[1] = color;
- longs[2] = SIDES*4;
- j = 3;
-
- for (i = 0; i < SIDES; i++)
+ for (sh = 0; sh < m_nTextureCount; sh++)
{
- longs[3+i*4] = (lcuint32)verts + SIDES + i;
- if (i == SIDES-1)
- {
- longs[4+i*4] = (lcuint32)verts + SIDES;
- longs[5+i*4] = (lcuint32)verts;
- }
- else
- {
- longs[4+i*4] = (lcuint32)verts + SIDES + i + 1;
- longs[5+i*4] = (lcuint32)verts + i + 1;
- }
- longs[6+i*4] = (lcuint32)verts + i;
- }
- j += 4*SIDES;
- longs[j] = SIDES*3;
- j++;
+ char name[9];
+ TEXTURE* tex = &m_pTextures[sh];
+ tex->color = ConvertColor(*bytes);
+ bytes++;
- for (i = 0; i < SIDES; i++)
- {
- if (i == SIDES-1)
- longs[j+i*3] = (lcuint16)verts + SIDES;
- else
- longs[j+i*3] = (lcuint16)verts + SIDES + i + 1;
- longs[1+j+i*3] = (lcuint16)verts + SIDES + i;
- longs[2+j+i*3] = (lcuint16)verts + 2*SIDES;
- }
+ strcpy(name, (char*)bytes);
+ tex->texture = lcGetPiecesLibrary()->FindTexture(name);
- j += 3*SIDES;
- longs[j] = 0; j++; // lines
- longs[j] = LC_COL_EDGES; j++; // color
- longs[j] = 0; j++; // quads
- longs[j] = 0; j++; // tris
- longs[j] = 4*SIDES; j++;
+ shorts = (lcint16*)(bytes + 8);
+ for (i = 0; i < 4; i++)
+ {
+ tex->vertex[i][0] = (float)LCINT16(shorts[0])*scale;
+ tex->vertex[i][1] = (float)LCINT16(shorts[1])*scale;
+ tex->vertex[i][2] = (float)LCINT16(shorts[2])*scale;
+ shorts += 3;
+ }
- for (i = 0; i < SIDES; i++)
- {
- longs[j+i*4] = (lcuint32)verts + i;
- if (i == SIDES-1)
- longs[1+j+i*4] = (lcuint32)verts;
- else
- longs[1+j+i*4] = (lcuint32)verts + i + 1;
-
- longs[2+j+i*4] = longs[j+i*4] + SIDES;
- longs[3+j+i*4] = longs[1+j+i*4] + SIDES;
- }
- }
- else
- {
- pGroup->drawinfo = malloc(sizeof(lcuint16)*size);
- ushorts = (lcuint16*)pGroup->drawinfo;
-
- ushorts[0] = 2; // colors
- ushorts[1] = color;
- ushorts[2] = SIDES*4;
- j = 3;
-
- for (i = 0; i < SIDES; i++)
- {
- ushorts[3+i*4] = (lcuint16)(verts + SIDES + i);
- if (i == SIDES-1)
- {
- ushorts[4+i*4] = (lcuint16)verts + SIDES;
- ushorts[5+i*4] = (lcuint16)verts;
- }
- else
- {
- ushorts[4+i*4] = (lcuint16)verts + SIDES + i + 1;
- ushorts[5+i*4] = (lcuint16)verts + i + 1;
- }
- ushorts[6+i*4] = (lcuint16)verts + i;
- }
- j += 4*SIDES;
- ushorts[j] = SIDES*3;
- j++;
+ for (i = 0; i < 4; i++)
+ {
+ tex->coords[i][0] = (float)LCINT16(shorts[0]);
+ tex->coords[i][1] = (float)LCINT16(shorts[1]);
+ shorts += 2;
+ }
- for (i = 0; i < SIDES; i++)
- {
- if (i == SIDES-1)
- ushorts[j+i*3] = (lcuint16)verts + SIDES;
- else
- ushorts[j+i*3] = (lcuint16)verts + SIDES + i + 1;
- ushorts[1+j+i*3] = (lcuint16)verts + SIDES + i;
- ushorts[2+j+i*3] = (lcuint16)verts + 2*SIDES;
+ bytes += 8 + 20*sizeof(lcuint16);
}
- j += 3*SIDES;
- ushorts[j] = 0; j++; // lines
- ushorts[j] = LC_COL_EDGES; j++; // color
- ushorts[j] = 0; j++; // quads
- ushorts[j] = 0; j++; // tris
- ushorts[j] = 4*SIDES; j++;
+ // Read groups
+ m_nGroupCount = LCUINT16(*((lcuint16*)bytes));
+ bytes += sizeof(lcuint16);
+ m_pGroups = (DRAWGROUP*)malloc(sizeof(DRAWGROUP)*m_nGroupCount);
+ memset(m_pGroups, 0, sizeof(DRAWGROUP)*m_nGroupCount);
- for (i = 0; i < SIDES; i++)
+ // Calculate number of vertices.
+ tmp = bytes;
+ sh = m_nGroupCount;
+ lcuint32 tris = 0;
+ while (sh--)
{
- ushorts[j+i*4] = (lcuint16)verts + i;
- if (i == SIDES-1)
- ushorts[1+j+i*4] = (lcuint16)verts;
- else
- ushorts[1+j+i*4] = (lcuint16)verts + i + 1;
-
- ushorts[2+j+i*4] = ushorts[j+i*4] + SIDES;
- ushorts[3+j+i*4] = ushorts[1+j+i*4] + SIDES;
- }
- }
+ bt = *bytes;
+ bytes++;
+ bytes += bt*sizeof(lcuint16);
- verts += 2*SIDES+1;
- bytes += 2*sizeof(unsigned char) + 12*sizeof(float);
- } break;
+ while (*bytes)
+ {
+ if (*bytes == LC_MESH)
+ {
+ if (m_nFlags & LC_PIECE_LONGDATA_FILE)
+ {
+ lcuint32 colors, *p;
+ p = (lcuint32*)(bytes + 1);
+ colors = LCUINT32(*p);
+ p++;
- case LC_STUD4:
- {
- int size;
- Matrix mat;
-
- for (i = 0; i < 12; i++)
- ((float*)(bytes+2))[i] = LCFLOAT (((float*)(bytes+2))[i]);
- mat.FromPacked ((float*)(bytes+2));
- lcuint16 color = ConvertColor(*(bytes+1));
-
- // Create the vertexes
- for (i = 0; i < SIDES; i++)
- {
- // outside
- m_fVertexArray[(verts+i+SIDES)*3] =
- m_fVertexArray[(verts+i)*3] =
- LC_KNOB_RADIUS * costbl[i];
- m_fVertexArray[(verts+i+SIDES)*3+1] =
- m_fVertexArray[(verts+i)*3+1] =
- LC_KNOB_RADIUS * sintbl[i];
- m_fVertexArray[(verts+i)*3+2] = LC_STUD_HEIGHT;
- m_fVertexArray[(verts+i+SIDES)*3+2] = 0;
-
- // inside
- m_fVertexArray[(verts+i+2*SIDES)*3] =
- m_fVertexArray[(verts+i+3*SIDES)*3] =
- LC_STUD_RADIUS * costbl[i];
- m_fVertexArray[(verts+i+2*SIDES)*3+1] =
- m_fVertexArray[(verts+i+3*SIDES)*3+1] =
- LC_STUD_RADIUS * sintbl[i];
- m_fVertexArray[(verts+i+3*SIDES)*3+2] = LC_STUD_HEIGHT;
- m_fVertexArray[(verts+i+2*SIDES)*3+2] = 0;
- }
-
- mat.TransformPoints(&m_fVertexArray[verts*3], 4*SIDES);
- // colors + 2*num_prim + sides*prims
- size = 9+SIDES*20;
-
- if (m_nFlags & LC_PIECE_LONGDATA)
- {
- pGroup->drawinfo = malloc(sizeof(lcuint32)*size);
- longs = (lcuint32*)pGroup->drawinfo;
-
- longs[0] = 2; // colors
- longs[1] = color;
- longs[2] = SIDES*12;
- j = 3;
-
- // outside
- for (i = 0; i < SIDES; i++)
- {
- longs[j+i*4] = (lcuint32)(verts + i);
- if (i == SIDES-1)
- {
- longs[j+1+i*4] = (lcuint32)verts;
- longs[j+2+i*4] = (lcuint32)verts + SIDES;
- }
- else
- {
- longs[j+1+i*4] = (lcuint32)verts + i + 1;
- longs[j+2+i*4] = (lcuint32)verts + SIDES + i + 1;
- }
- longs[j+3+i*4] = (lcuint32)verts + SIDES + i;
- }
- j += 4*SIDES;
+ while (colors--)
+ {
+ p++; // color code
+ tris += LCUINT32(*p) / 4 * 6;
+ p += LCUINT32(*p) + 1;
+ tris += LCUINT32(*p);
+ p += LCUINT32(*p) + 1;
+ p += LCUINT32(*p) + 1;
+ }
- // inside
- for (i = 0; i < SIDES; i++)
- {
- longs[j+i*4] = (lcuint32)(verts + 3*SIDES + i);
- if (i == SIDES-1)
- {
- longs[j+1+i*4] = (lcuint32)verts + 3*SIDES;
- longs[j+2+i*4] = (lcuint32)verts + 2*SIDES;
- }
- else
- {
- longs[j+1+i*4] = (lcuint32)verts + 3*SIDES + i + 1;
- longs[j+2+i*4] = (lcuint32)verts + 2*SIDES + i + 1;
- }
- longs[j+3+i*4] = (lcuint32)verts + 2*SIDES + i;
- }
- j += 4*SIDES;
+ bytes = (unsigned char*)p;
+ }
+ else
+ {
+ lcuint16 colors, *p;
+ p = (lcuint16*)(bytes + 1);
+ colors = LCUINT16(*p);
+ p++;
- // ring
- for (i = 0; i < SIDES; i++)
- {
- longs[j+i*4] = (lcuint32)(verts + 3*SIDES + i);
- if (i == SIDES-1)
- {
- longs[j+1+i*4] = (lcuint32)verts + 3*SIDES;
- longs[j+2+i*4] = (lcuint32)verts;
- }
- else
- {
- longs[j+1+i*4] = (lcuint32)verts + 3*SIDES + i + 1;
- longs[j+2+i*4] = (lcuint32)verts + i + 1;
- }
- longs[j+3+i*4] = (lcuint32)verts + i;
- }
- j += 4*SIDES;
+ while (colors--)
+ {
+ p++; // color code
+ tris += LCUINT32(*p) / 4 * 6;
+ p += LCUINT16(*p) + 1;
+ tris += LCUINT32(*p);
+ p += LCUINT16(*p) + 1;
+ p += LCUINT16(*p) + 1;
+ }
- longs[j] = 0; j++; // tris
- longs[j] = 0; j++; // lines
- longs[j] = LC_COL_EDGES; j++; // color
- longs[j] = 0; j++; // quads
- longs[j] = 0; j++; // tris
- longs[j] = 8*SIDES; j++;
+ bytes = (unsigned char*)p;
+ }
+ }
- // outside
- for (i = 0; i < SIDES; i++)
- {
- longs[j+i*4] = (lcuint32)verts + i;
- if (i == SIDES-1)
- longs[1+j+i*4] = (lcuint32)verts;
- else
- longs[1+j+i*4] = (lcuint32)verts + i + 1;
-
- longs[2+j+i*4] = longs[j+i*4] + SIDES;
- longs[3+j+i*4] = longs[1+j+i*4] + SIDES;
- }
- j += 4*SIDES;
+ if (*bytes == LC_STUD)
+ {
+ verts += (2*SIDES)+1;
+ tris += 9*SIDES;
+ bytes += 2*sizeof(unsigned char) + 12*sizeof(float);
+ }
- // inside
- for (i = 0; i < SIDES; i++)
- {
- longs[j+i*4] = (lcuint32)verts + 2*SIDES + i;
- if (i == SIDES-1)
- longs[1+j+i*4] = (lcuint32)verts + 2*SIDES;
- else
- longs[1+j+i*4] = (lcuint32)verts + 2*SIDES + i + 1;
-
- longs[2+j+i*4] = longs[j+i*4] + SIDES;
- longs[3+j+i*4] = longs[1+j+i*4] + SIDES;
- }
- }
- else
- {
- pGroup->drawinfo = malloc(sizeof(lcuint16)*size);
- ushorts = (lcuint16*)pGroup->drawinfo;
-
- ushorts[0] = 2; // colors
- ushorts[1] = color;
- ushorts[2] = SIDES*12;
- j = 3;
-
- // outside
- for (i = 0; i < SIDES; i++)
- {
- ushorts[j+i*4] = (lcuint16)(verts + i);
- if (i == SIDES-1)
- {
- ushorts[j+1+i*4] = (lcuint16)verts;
- ushorts[j+2+i*4] = (lcuint16)verts + SIDES;
- }
- else
- {
- ushorts[j+1+i*4] = (lcuint16)verts + i + 1;
- ushorts[j+2+i*4] = (lcuint16)verts + SIDES + i + 1;
- }
- ushorts[j+3+i*4] = (lcuint16)verts + SIDES + i;
- }
- j += 4*SIDES;
+ if (*bytes == LC_STUD2)
+ {
+ verts += 4*SIDES;
+ tris += 18*SIDES;
+ bytes += 2*sizeof(unsigned char) + 12*sizeof(float);
+ }
- // inside
- for (i = 0; i < SIDES; i++)
- {
- ushorts[j+i*4] = (lcuint16)(verts + 2*SIDES + i);
- if (i == SIDES-1)
- {
- ushorts[j+1+i*4] = (lcuint16)verts + 2*SIDES;
- ushorts[j+2+i*4] = (lcuint16)verts + 3*SIDES;
- }
- else
- {
- ushorts[j+1+i*4] = (lcuint16)verts + 2*SIDES + i + 1;
- ushorts[j+2+i*4] = (lcuint16)verts + 3*SIDES + i + 1;
- }
- ushorts[j+3+i*4] = (lcuint16)verts + 3*SIDES + i;
- }
- j += 4*SIDES;
+ if (*bytes == LC_STUD3)
+ {
+ verts += (2*SIDES)+1;
+ tris += 9*SIDES;
+ bytes += 2*sizeof(unsigned char) + 12*sizeof(float);
+ }
- // ring
- for (i = 0; i < SIDES; i++)
- {
- ushorts[j+i*4] = (lcuint16)(verts + 3*SIDES + i);
- if (i == SIDES-1)
- {
- ushorts[j+1+i*4] = (lcuint16)verts + 3*SIDES;
- ushorts[j+2+i*4] = (lcuint16)verts;
- }
- else
- {
- ushorts[j+1+i*4] = (lcuint16)verts + 3*SIDES + i + 1;
- ushorts[j+2+i*4] = (lcuint16)verts + i + 1;
- }
- ushorts[j+3+i*4] = (lcuint16)verts + i;
+ if (*bytes == LC_STUD4)
+ {
+ verts += 4*SIDES;
+ tris += 18*SIDES;
+ bytes += 2*sizeof(unsigned char) + 12*sizeof(float);
+ }
+ }
+ bytes++; // should be 0
}
- j += 4*SIDES;
- ushorts[j] = 0; j++; // tris
- ushorts[j] = 0; j++; // lines
- ushorts[j] = LC_COL_EDGES; j++; // color
- ushorts[j] = 0; j++; // quads
- ushorts[j] = 0; j++; // tris
- ushorts[j] = 8*SIDES; j++;
+ m_fVertexArray = (float*)malloc(3*sizeof(float)*verts);
+ m_nVertexCount = verts;
- // outside
- for (i = 0; i < SIDES; i++)
- {
- ushorts[j+i*4] = (lcuint16)verts + i;
- if (i == SIDES-1)
- ushorts[1+j+i*4] = (lcuint16)verts;
- else
- ushorts[1+j+i*4] = (lcuint16)verts + i + 1;
-
- ushorts[2+j+i*4] = ushorts[j+i*4] + SIDES;
- ushorts[3+j+i*4] = ushorts[1+j+i*4] + SIDES;
- }
- j += 4*SIDES;
+ if (m_nVertexCount > 65535 || tris > 65535)
+ m_nFlags |= LC_PIECE_LONGDATA;
+ else
+ m_nFlags &= ~LC_PIECE_LONGDATA;
- // inside
- for (i = 0; i < SIDES; i++)
+ // Copy the 'fixed' vertexes
+ shorts = (lcint16*)(longs + 1);
+ for (verts = 0; verts < LCUINT32(*longs); verts++)
{
- ushorts[j+i*4] = (lcuint16)verts + 2*SIDES + i;
- if (i == SIDES-1)
- ushorts[1+j+i*4] = (lcuint16)verts + 2*SIDES;
- else
- ushorts[1+j+i*4] = (lcuint16)verts + 2*SIDES + i + 1;
-
- ushorts[2+j+i*4] = ushorts[j+i*4] + SIDES;
- ushorts[3+j+i*4] = ushorts[1+j+i*4] + SIDES;
+ m_fVertexArray[verts*3] = (float)LCINT16(*shorts)*scale;
+ shorts++;
+ m_fVertexArray[verts*3+1] = (float)LCINT16(*shorts)*scale;
+ shorts++;
+ m_fVertexArray[verts*3+2] = (float)LCINT16(*shorts)*scale;
+ shorts++;
}
- }
-
- verts += 4*SIDES;
- bytes += 2*sizeof(unsigned char) + 12*sizeof(float);
- } break;
- }
- bytes++; // should be 0
- }
- free(buf);
-
-/*
- // Now create the information for the CD
- // If the object is big this can block the program for serveral seconds.
- // ATTENTION: The RAPID CD library is based on triangles.
-
- if (pInfo->pRModel)
- delete pInfo->pRModel;
-
- pInfo->pRModel = new CRModel();
- pInfo->pRModel->BeginModel();
+ // Read groups
+ bytes = tmp;
+ sh = m_nGroupCount;
+ for (pGroup = m_pGroups; sh--; pGroup++)
+ {
+ bt = *bytes;
+ bytes++;
- UINT col, loc, j, i;
- int vert = 0;
+ pGroup->connections[bt] = 0xFFFF;
+ while(bt--)
+ {
+ lcuint16 tmp = LCUINT16(*((lcuint16*)bytes));
+ pGroup->connections[bt] = tmp;
+ bytes += sizeof(lcuint16);
+ }
- for (UINT c = 0; c < pInfo->cons; c++)
- {
- if (pInfo->connection[c].info == NULL)
- continue;
- if (pInfo->count > 65535)
+ switch (*bytes)
{
- UINT* info = (UINT*)pInfo->connection[c].info;
- loc = 1;
- col = info[0];
- while (col)
+ case LC_MESH:
{
- loc++;
+ bytes++;
- j = info[loc];
- for (i = 0; i < j; i+=4)
+ if (m_nFlags & LC_PIECE_LONGDATA_FILE)
{
- pInfo->pRModel->AddTri(&pInfo->vertex[info[loc+i+1]*3], &pInfo->vertex[info[loc+i+2]*3],
- &pInfo->vertex[info[loc+i+3]*3], vert);
- vert++;
- pInfo->pRModel->AddTri(&pInfo->vertex[info[loc+i+3]*3], &pInfo->vertex[info[loc+i+4]*3],
- &pInfo->vertex[info[loc+i+1]*3], vert);
- vert++;
+ if (m_nFlags & LC_PIECE_LONGDATA)
+ WriteMeshDrawInfo<lcuint32, lcuint32>(bytes, pGroup);
+ else
+ WriteMeshDrawInfo<lcuint32, lcuint16>(bytes, pGroup);
}
- loc += j+1;
- j = info[loc];
- for (i = 0; i < j; i+=3)
+ else
{
- pInfo->pRModel->AddTri(&pInfo->vertex[info[loc+i+1]*3], &pInfo->vertex[info[loc+i+2]*3],
- &pInfo->vertex[info[loc+i+3]*3], vert);
- vert++;
+ if (m_nFlags & LC_PIECE_LONGDATA)
+ WriteMeshDrawInfo<lcuint16, lcuint32>(bytes, pGroup);
+ else
+ WriteMeshDrawInfo<lcuint16, lcuint16>(bytes, pGroup);
}
- loc += j+1;
- loc += info[loc]+1;
+ } break;
- col--;
- }
- }
- else
- {
- WORD* info = (WORD*)pInfo->connection[c].info;
- loc = 1;
- col = info[0];
- while (col)
+ case LC_STUD:
{
- loc++;
-
- j = info[loc];
- for (i = 0; i < j; i+=4)
- {
- pInfo->pRModel->AddTri(&pInfo->vertex[info[loc+i+1]*3], &pInfo->vertex[info[loc+i+2]*3],
- &pInfo->vertex[info[loc+i+3]*3], vert);
- vert++;
- pInfo->pRModel->AddTri(&pInfo->vertex[info[loc+i+3]*3], &pInfo->vertex[info[loc+i+4]*3],
- &pInfo->vertex[info[loc+i+1]*3], vert);
- vert++;
- }
- loc += j+1;
- j = info[loc];
- for (i = 0; i < j; i+=3)
- {
- pInfo->pRModel->AddTri(&pInfo->vertex[info[loc+i+1]*3], &pInfo->vertex[info[loc+i+2]*3],
- &pInfo->vertex[info[loc+i+3]*3], vert);
- vert++;
- }
- loc += j+1;
- loc += info[loc]+1;
-
- col--;
- }
+ Matrix mat;
+
+ for (i = 0; i < 12; i++)
+ ((float*)(bytes+2))[i] = LCFLOAT (((float*)(bytes+2))[i]);
+ mat.FromPacked ((float*)(bytes+2));
+ lcuint16 color = ConvertColor(*(bytes+1));
+
+ if (m_nFlags & LC_PIECE_LONGDATA)
+ WriteStudDrawInfo<lcuint32>(color, m_fVertexArray+verts*3, verts, pGroup, LC_STUD_RADIUS);
+ else
+ WriteStudDrawInfo<lcuint16>(color, m_fVertexArray+verts*3, verts, pGroup, LC_STUD_RADIUS);
+
+ mat.TransformPoints(m_fVertexArray+verts*3, 2 * SIDES + 1);
+
+ verts += 2*SIDES+1;
+ bytes += 2*sizeof(unsigned char) + 12*sizeof(float);
+ } break;
+
+ case LC_STUD2:
+ {
+ Matrix mat;
+
+ for (i = 0; i < 12; i++)
+ ((float*)(bytes+2))[i] = LCFLOAT (((float*)(bytes+2))[i]);
+ mat.FromPacked ((float*)(bytes+2));
+ lcuint16 color = ConvertColor(*(bytes+1));
+
+ if (m_nFlags & LC_PIECE_LONGDATA)
+ WriteHollowStudDrawInfo<lcuint32>(color, m_fVertexArray+verts*3, verts, pGroup, 0.16f, LC_STUD_RADIUS);
+ else
+ WriteHollowStudDrawInfo<lcuint16>(color, m_fVertexArray+verts*3, verts, pGroup, 0.16f, LC_STUD_RADIUS);
+
+ mat.TransformPoints(m_fVertexArray+verts*3, 4 * SIDES);
+
+ verts += 4*SIDES;
+ bytes += 2*sizeof(unsigned char) + 12*sizeof(float);
+ } break;
+
+ case LC_STUD3:
+ {
+ Matrix mat;
+
+ for (i = 0; i < 12; i++)
+ ((float*)(bytes+2))[i] = LCFLOAT (((float*)(bytes+2))[i]);
+ mat.FromPacked ((float*)(bytes+2));
+ lcuint16 color = ConvertColor(*(bytes+1));
+
+ if (m_nFlags & LC_PIECE_LONGDATA)
+ WriteStudDrawInfo<lcuint32>(color, m_fVertexArray+verts*3, verts, pGroup, LC_STUD_RADIUS);
+ else
+ WriteStudDrawInfo<lcuint16>(color, m_fVertexArray+verts*3, verts, pGroup, LC_STUD_RADIUS);
+
+ mat.TransformPoints(m_fVertexArray+verts*3, 2 * SIDES + 1);
+
+ verts += 2*SIDES+1;
+ bytes += 2*sizeof(unsigned char) + 12*sizeof(float);
+ } break;
+
+ case LC_STUD4:
+ {
+ Matrix mat;
+
+ for (i = 0; i < 12; i++)
+ ((float*)(bytes+2))[i] = LCFLOAT (((float*)(bytes+2))[i]);
+ mat.FromPacked ((float*)(bytes+2));
+ lcuint16 color = ConvertColor(*(bytes+1));
+
+ if (m_nFlags & LC_PIECE_LONGDATA)
+ WriteHollowStudDrawInfo<lcuint32>(color, m_fVertexArray+verts*3, verts, pGroup, 0.16f, LC_STUD_RADIUS);
+ else
+ WriteHollowStudDrawInfo<lcuint16>(color, m_fVertexArray+verts*3, verts, pGroup, 0.16f, LC_STUD_RADIUS);
+
+ mat.TransformPoints(m_fVertexArray+verts*3, 4 * SIDES);
+
+ verts += 4*SIDES;
+ bytes += 2*sizeof(unsigned char) + 12*sizeof(float);
+ } break;
}
+ bytes++; // should be 0
}
- pInfo->pRModel->EndModel();
-*/
+
+ free(buf);
}
void PieceInfo::FreeInformation()
@@ -1521,11 +944,6 @@ void PieceInfo::FreeInformation()
free(m_pTextures);
m_pTextures = NULL;
}
-
- if (m_nFlags & LC_PIECE_LONGDATA_RUNTIME)
- {
- m_nFlags &= ~(LC_PIECE_LONGDATA | LC_PIECE_LONGDATA_RUNTIME);
- }
}
// Zoom extents for the preview window and print catalog
@@ -1755,9 +1173,6 @@ void PieceInfo::RenderPiece(int nColor)
}
if (*info)
- glDrawElements(GL_QUADS, *info, GL_UNSIGNED_INT, info+1);
- info += *info + 1;
- if (*info)
glDrawElements(GL_TRIANGLES, *info, GL_UNSIGNED_INT, info+1);
info += *info + 1;
if (*info)
@@ -1796,9 +1211,6 @@ void PieceInfo::RenderPiece(int nColor)
}
if (*info)
- glDrawElements(GL_QUADS, *info, GL_UNSIGNED_SHORT, info+1);
- info += *info + 1;
- if (*info)
glDrawElements(GL_TRIANGLES, *info, GL_UNSIGNED_SHORT, info+1);
info += *info + 1;
if (*info)
diff --git a/common/pieceinf.h b/common/pieceinf.h
index cb574c6..17bef2f 100644
--- a/common/pieceinf.h
+++ b/common/pieceinf.h
@@ -11,12 +11,12 @@
#endif
#include "algebra.h"
-#define LC_PIECE_COUNT 0x01 // Count this piece in the totals ?
-#define LC_PIECE_LONGDATA 0x02 // unsigned long/short index
-#define LC_PIECE_CCW 0x04 // Use back-face culling
-#define LC_PIECE_SMALL 0x10 // scale = 10000
-#define LC_PIECE_MEDIUM 0x20 // scale = 1000 (otherwise = 100)
-#define LC_PIECE_LONGDATA_RUNTIME 0x40 // If the original data is 16 bits but we expanded to 32 bits
+#define LC_PIECE_COUNT 0x01 // Count this piece in the totals ?
+#define LC_PIECE_LONGDATA_FILE 0x02 // unsigned long/short index
+#define LC_PIECE_CCW 0x04 // Use back-face culling
+#define LC_PIECE_SMALL 0x10 // scale = 10000
+#define LC_PIECE_MEDIUM 0x20 // scale = 1000 (otherwise = 100)
+#define LC_PIECE_LONGDATA 0x40 // If the original data is 16 bits but we expanded to 32 bits
class File;
class Texture;
diff --git a/common/project.cpp b/common/project.cpp
index c199e8a..a1c9df7 100644
--- a/common/project.cpp
+++ b/common/project.cpp
@@ -4347,28 +4347,15 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
info++;
// skip if color only have lines
- if ((*info == 0) && (info[1] == 0))
+ if (*info == 0)
{
- info += 2;
+ info++;
info += *info + 1;
continue;
}
fputs(" mesh {\n", f);
- for (count = *info, info++; count; count -= 4)
- {
- fprintf(f, " triangle { <%.2f, %.2f, %.2f>, <%.2f, %.2f, %.2f>, <%.2f, %.2f, %.2f> }\n",
- -pInfo->m_fVertexArray[info[0]*3+1], -pInfo->m_fVertexArray[info[0]*3], pInfo->m_fVertexArray[info[0]*3+2],
- -pInfo->m_fVertexArray[info[1]*3+1], -pInfo->m_fVertexArray[info[1]*3], pInfo->m_fVertexArray[info[1]*3+2],
- -pInfo->m_fVertexArray[info[2]*3+1], -pInfo->m_fVertexArray[info[2]*3], pInfo->m_fVertexArray[info[2]*3+2]);
- fprintf(f, " triangle { <%.2f, %.2f, %.2f>, <%.2f, %.2f, %.2f>, <%.2f, %.2f, %.2f> }\n",
- -pInfo->m_fVertexArray[info[2]*3+1], -pInfo->m_fVertexArray[info[2]*3], pInfo->m_fVertexArray[info[2]*3+2],
- -pInfo->m_fVertexArray[info[3]*3+1], -pInfo->m_fVertexArray[info[3]*3], pInfo->m_fVertexArray[info[3]*3+2],
- -pInfo->m_fVertexArray[info[0]*3+1], -pInfo->m_fVertexArray[info[0]*3], pInfo->m_fVertexArray[info[0]*3+2]);
- info += 4;
- }
-
for (count = *info, info++; count; count -= 3)
{
fprintf(f, " triangle { <%.2f, %.2f, %.2f>, <%.2f, %.2f, %.2f>, <%.2f, %.2f, %.2f> }\n",
@@ -4396,28 +4383,15 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
info++;
// skip if color only have lines
- if ((*info == 0) && (info[1] == 0))
+ if (*info == 0)
{
- info += 2;
+ info++;
info += *info + 1;
continue;
}
fputs(" mesh {\n", f);
- for (count = *info, info++; count; count -= 4)
- {
- fprintf(f, " triangle { <%.2f, %.2f, %.2f>, <%.2f, %.2f, %.2f>, <%.2f, %.2f, %.2f> }\n",
- -pInfo->m_fVertexArray[info[0]*3+1], -pInfo->m_fVertexArray[info[0]*3], pInfo->m_fVertexArray[info[0]*3+2],
- -pInfo->m_fVertexArray[info[1]*3+1], -pInfo->m_fVertexArray[info[1]*3], pInfo->m_fVertexArray[info[1]*3+2],
- -pInfo->m_fVertexArray[info[2]*3+1], -pInfo->m_fVertexArray[info[2]*3], pInfo->m_fVertexArray[info[2]*3+2]);
- fprintf(f, " triangle { <%.2f, %.2f, %.2f>, <%.2f, %.2f, %.2f>, <%.2f, %.2f, %.2f> }\n",
- -pInfo->m_fVertexArray[info[2]*3+1], -pInfo->m_fVertexArray[info[2]*3], pInfo->m_fVertexArray[info[2]*3+2],
- -pInfo->m_fVertexArray[info[3]*3+1], -pInfo->m_fVertexArray[info[3]*3], pInfo->m_fVertexArray[info[3]*3+2],
- -pInfo->m_fVertexArray[info[0]*3+1], -pInfo->m_fVertexArray[info[0]*3], pInfo->m_fVertexArray[info[0]*3+2]);
- info += 4;
- }
-
for (count = *info, info++; count; count -= 3)
{
fprintf(f, " triangle { <%.2f, %.2f, %.2f>, <%.2f, %.2f, %.2f>, <%.2f, %.2f, %.2f> }\n",
@@ -9793,7 +9767,6 @@ template<class type> void Project::writeVRMLShapes(type color, FILE *stream, int
info++;
info += *info + 1;
info += *info + 1;
- info += *info + 1;
continue;
}
@@ -9802,19 +9775,8 @@ template<class type> void Project::writeVRMLShapes(type color, FILE *stream, int
}
info++;
- bool skipNext = (info[0] < 1);
- if (skipNext)
- skipNext = (info[1] < 1);
- if (skipNext)
- info += 2;
- else
+ if (*info)
{
- for (count = *info, info++; count; count -= 4)
- {
- generateMeshData(info, pos, pPiece, 4, currentColor);
- info += 4;
- }
-
for (count = *info, info++; count; count -= 3)
{
generateMeshData(info, pos, pPiece, 3, currentColor);
@@ -9842,8 +9804,10 @@ template<class type> void Project::writeVRMLShapes(type color, FILE *stream, int
writeVRMLShapeEnd(stream);
}
}
+ else
+ info++;
- if (*info > 0)
+ if (*info)
{
// IndexedLineSet not supported in RigidBody node for the xj3d browser 8-(
if (VRMLdialect != X3DV_WITH_RIGID_BODY_PHYSICS)
@@ -9867,8 +9831,10 @@ template<class type> void Project::writeVRMLShapes(type color, FILE *stream, int
writeVRMLShapeMeshEnd(stream);
writeVRMLShapeEnd(stream);
}
- } else
+ }
+ else
info++;
+
free(coords);
free(coordIndices);
}
@@ -9881,7 +9847,8 @@ template<class type> void Project::writeVRMLShapes(type color, FILE *stream, int
// So the exporter use the mid of the boundingbox of all pieces in a group as center of mass
// the needed information is stored in the following compound datatype
-class GroupInfo {
+class GroupInfo
+{
public:
Group *group;
float minBoundingBox[3];
@@ -9894,7 +9861,7 @@ public:
// routines to account a boundingbox
-template<class type> void Project::getMinMaxData(type* info, Piece* pPiece, int numVertices, GroupInfo* groupInfo)
+template<class type> void Project::getMinMaxData(type* info, Piece* pPiece, GroupInfo* groupInfo)
{
float rot[4];
Vector3 Pos = pPiece->GetPosition();
@@ -9903,7 +9870,7 @@ template<class type> void Project::getMinMaxData(type* info, Piece* pPiece, int
PieceInfo* pInfo = pPiece->GetPieceInfo();
- for (int i = 0; i < numVertices; i++)
+ for (int i = 0; i < 3; i++)
{
float vertex[3];
float *localVertex = &pInfo->m_fVertexArray[info[i] * 3];
@@ -9946,7 +9913,6 @@ template<class type> void Project::getMinMax(type col, Piece* piece, unsigned sh
info++;
info += *info + 1;
info += *info + 1;
- info += *info + 1;
continue;
}
@@ -9960,28 +9926,14 @@ template<class type> void Project::getMinMax(type col, Piece* piece, unsigned sh
info += 2;
else
{
- for (count = *info, info++; count; count -= 4)
- {
- getMinMaxData(info, piece, 4, groupInfo);
- info += 4;
- }
-
for (count = *info, info++; count; count -= 3)
{
- getMinMaxData(info, piece, 3, groupInfo);
+ getMinMaxData(info, piece, groupInfo);
info += 3;
}
}
- if (*info > 0)
- {
- // skip lines
- for (count = *info, info++; count; count -= 2)
- {
- info += 2;
- }
- } else
- info++;
+ info += *info + 1;
}
}
@@ -10169,7 +10121,6 @@ void Project::exportVRMLFile(char *filename, int dialect)
if (pInfo->m_nGroupCount > 0)
{
-
if (beginGroup && rigidBody)
{
if (pInfo->m_nFlags & LC_PIECE_LONGDATA)
diff --git a/common/project.h b/common/project.h
index de951ce..61fd111 100644
--- a/common/project.h
+++ b/common/project.h
@@ -327,7 +327,7 @@ protected:
bool firstData;
int searchForVertex(float *vertex);
template<class type> void generateMeshData(type* info, float *pos, Piece* pPiece, int numVertices, int currentColor);
- template<class type> void getMinMaxData(type* info, Piece* pPiece, int numVertices, GroupInfo* groupInfo);
+ template<class type> void getMinMaxData(type* info, Piece* pPiece, GroupInfo* groupInfo);
template<class type> void getMinMax(type col, Piece* pPiece, unsigned short group, GroupInfo* groupInfo);
bool handleAsGroup(Piece* piece, GroupInfo groupInfo);
int numCoords;