21 #define SEEK_START 1900
22 #define SEEK_CURSOR 1901
26 #define COLOR_F 0x0010
27 #define COLOR_24 0x0011
28 #define LIN_COLOR_24 0x0012
29 #define LIN_COLOR_F 0x0013
31 #define INT_PERCENTAGE 0x0030
32 #define FLOAT_PERCENTAGE 0x0031
34 #define AMBIENT_LIGHT 0x2100
37 #define MAIN3DS 0x4D4D
38 #define EDIT3DS 0x3D3D // this is the start of the editor config
41 #define KFDATA 0xB000 // the keyframer section
43 #define OBJECT_NODE_TAG 0xB002
44 #define NODE_HDR 0xB010
46 #define POS_TRACK_TAG 0xB020
47 #define ROT_TRACK_TAG 0xB021
48 #define SCL_TRACK_TAG 0xB022
51 #define MAT_ENTRY 0xAFFF
52 #define MAT_NAME 0xA000
53 #define MAT_AMBIENT 0xA010
54 #define MAT_DIFFUSE 0xA020
55 #define MAT_SPECULAR 0xA030
56 #define MAT_SHININESS 0xA040
57 #define MAT_SHIN2PCT 0xA041
58 #define MAT_TRANSPARENCY 0xA050
59 #define MAT_SHADING 0xA100
60 #define MAT_TWO_SIDE 0xA081
61 #define MAT_ADDITIVE 0xA083
62 #define MAT_WIRE 0xA085
63 #define MAT_FACEMAP 0xA088
64 #define MAT_WIRESIZE 0xA087
65 #define MAT_DECAL 0xA082
66 #define MAT_TEXMAP 0xA200
67 #define MAT_MAPNAME 0xA300
68 #define MAT_MAP_TILING 0xA351
69 #define MAT_MAP_USCALE 0xA354
70 #define MAT_MAP_VSCALE 0xA356
71 #define MAT_MAP_UOFFSET 0xA358
72 #define MAT_MAP_VOFFSET 0xA35A
73 #define MAT_MAP_ANG 0xA35C
74 #define MAT_TEX2MAP 0xA33A
75 #define MAT_OPACMAP 0xA210
76 #define MAT_BUMPMAP 0xA230
77 #define MAT_SPECMAP 0xA204
78 #define MAT_SHINMAP 0xA33C
79 #define MAT_REFLMAP 0xA220
80 #define MAT_ACUBIC 0xA310
82 #define EDIT_OBJECT 0x4000
83 #define OBJ_TRIMESH 0x4100
84 #define OBJ_LIGHT 0x4600
85 #define OBJ_CAMERA 0x4700
86 #define LIT_OFF 0x4620
87 #define LIT_SPOT 0x4610
88 #define TRI_VERTEXLIST 0x4110
89 #define TRI_VERTEXOPTIONS 0x4111
91 #define TRI_FACELIST 0x4120
92 #define TRI_MAT_GROUP 0x4130
93 #define TRI_SMOOTH_GROUP 0x4150
95 #define TRI_FACEMAPPING 0x4140
96 #define TRI_MATRIX 0x4160
98 #define SPOTLIGHT 0x4610
102 #define MAX_SHARED_TRIS 100
169 return (
float)sqrt(vec.
x*vec.
x + vec.
y*vec.
y+vec.
z*vec.
z);
188 v.
x = a.
y*b.
z - a.
z*b.
y;
189 v.
y = a.
z*b.
x - a.
x*b.
z;
190 v.
z = a.
x*b.
y - a.
y*b.
x;
196 for (
int i = 0; i < 4; i++)
197 for (
int j = 0; j < 4; j++)
198 m.
m[i][j] = (i==j) ? 1.0f : 0.0f;
205 res.
x = m.
m[0][0]*vec.
x + m.
m[1][0]*vec.
y + m.
m[2][0]*vec.
z + m.
m[3][0]*vec.
w;
206 res.
y = m.
m[0][1]*vec.
x + m.
m[1][1]*vec.
y + m.
m[2][1]*vec.
z + m.
m[3][1]*vec.
w;
207 res.
z = m.
m[0][2]*vec.
x + m.
m[1][2]*vec.
y + m.
m[2][2]*vec.
z + m.
m[3][2]*vec.
w;
208 res.
w = m.
m[0][3]*vec.
x + m.
m[1][3]*vec.
y + m.
m[2][3]*vec.
z + m.
m[3][3]*vec.
w;
572 std::vector< std::vector<int> > array;
577 array[k].push_back(i);
580 array[k].push_back(i);
583 array[k].push_back(i);
588 if (!useSmoothingGroups)
594 int t = array[i].size();
596 for (
int k=0; k<t; k++)
598 temp.
x +=
m_tris[array[i][k]].normal.x;
599 temp.
y +=
m_tris[array[i][k]].normal.y;
600 temp.
z +=
m_tris[array[i][k]].normal.z;
609 std::vector<ulong> smGroups;
610 std::vector< std::vector <uint> > smList;
614 for (i=0; i<loop_size; i++)
616 int t = array[i].size();
623 smGroups.push_back(
m_tris[array[i][0]].smoothingGroups);
624 smList.resize(smGroups.size());
625 smList[smGroups.size()-1].push_back(array[i][0]);
628 for (
int k=0; k<t; k++)
631 for (
uint j=0; j<smGroups.size(); j++)
633 if (
m_tris[array[i][k]].smoothingGroups == smGroups[j])
635 smList[j].push_back(array[i][k]);
641 smGroups.push_back(
m_tris[array[i][k]].smoothingGroups);
642 smList.resize(smGroups.size());
643 smList[smGroups.size()-1].push_back(array[i][k]);
650 if (smGroups.size() > 1)
651 for (
uint j=1; j< smGroups.size(); j++)
660 for (
uint h=0; h<smList[j].size(); h++)
662 if (
m_tris[smList[j][h]].a == i)
663 m_tris[smList[j][h]].a = t;
664 if (
m_tris[smList[j][h]].b == i)
665 m_tris[smList[j][h]].b = t;
666 if (
m_tris[smList[j][h]].c == i)
667 m_tris[smList[j][h]].c = t;
673 for (i=0; i<array.size(); i++)
680 array[k].push_back(i);
683 array[k].push_back(i);
686 array[k].push_back(i);
693 int t = array[i].size();
695 for (
int k=0; k<t; k++)
697 temp.
x +=
m_tris[array[i][k]].normal.x;
698 temp.
y +=
m_tris[array[i][k]].normal.y;
699 temp.
z +=
m_tris[array[i][k]].normal.z;
757 m_tris[i].tangent.x = -(x_vec.
y/x_vec.
x);
758 m_tris[i].tangent.y = -(y_vec.
y/y_vec.
x);
759 m_tris[i].tangent.z = -(z_vec.
y/z_vec.
x);
761 m_tris[i].binormal.x = -(x_vec.
z/x_vec.
x);
762 m_tris[i].binormal.y = -(y_vec.
z/y_vec.
x);
763 m_tris[i].binormal.z = -(z_vec.
z/z_vec.
x);
768 std::vector< std::vector<int> > array;
773 array[k].push_back(i);
776 array[k].push_back(i);
779 array[k].push_back(i);
787 int t = array[i].size();
789 for (
int k=0; k<t; k++)
791 v1.
x +=
m_tris[array[i][k]].tangent.x;
792 v1.
y +=
m_tris[array[i][k]].tangent.y;
793 v1.
z +=
m_tris[array[i][k]].tangent.z;
795 v2.
x +=
m_tris[array[i][k]].binormal.x;
796 v2.
y +=
m_tris[array[i][k]].binormal.y;
797 v2.
z +=
m_tris[array[i][k]].binormal.z;
1053 f = fopen(filename,
"rb");
1056 ErrorMsg(
"L3DS::LoadFile - cannot open file");
1059 fseek(f, 0, SEEK_END);
1061 fseek(f, 0, SEEK_SET);
1065 ErrorMsg(
"L3DS::LoadFile - not enough memory (malloc failed)");
1073 ErrorMsg(
"L3DS::LoadFile - error reading from file");
1159 while ((c!=0) && (count<max_count-1))
1203 while (( chunk.
id != target.
id) && (chunk.
end <= parent.
end))
1206 if (chunk.
end >= parent.
end)
1210 if (chunk.
id == target.
id)
1256 ErrorMsg(
"L3DS::ReadColor - error this is not a color chunk");
1271 ErrorMsg(
"L3DS::ReadPercentage - error, the chunk is not a percentage chunk");
1283 ErrorMsg(
"L3DS::Read3DS - wrong file format");
1355 if (chunk.
end < parent.
end)
1357 while (chunk.
end <= parent.
end)
1381 if (chunk.
end >= parent.
end)
1392 unsigned short count, i;
1401 while (chunk.
end <= parent.
end)
1408 for (i=0; i < count; i++)
1420 for (i=0; i < count; i++)
1432 for (
int i = 0; i < 4; i++)
1433 for (
int j = 0; j < 3; j++)
1448 if (chunk.
end >= parent.
end)
1458 unsigned short count, t;
1468 ErrorMsg(
"L3DS::ReadFaceList - internal error: wrong chunk passed as parameter");
1476 for (i=0; i<count; i++)
1486 while (ch.
end <= chunk.
end)
1495 for (i=0; i<count; i++) {
1524 while (chunk.
end <= parent.
end)
1598 ErrorMsg(
"L3DS::ReadMaterial - error, expected chunk not found");
1602 if (strcmp(str,
"") == 0)
1620 while (child.
end <= chunk.
end)