29 #include "../idlib/precompiled.h"
43 #define MA_VERBOSE( x ) { if ( maGlobal.verbose ) { common->Printf x ; } }
61 if(!token.
Icmp(
"-")) {
63 if (!token.
Icmp(
"n")) {
66 }
else if (!token.
Icmp(
"p")) {
70 }
else if (!token.
Icmp(
";")) {
92 if(!token.
Icmp(
"]")) {
107 if(!token.
Icmp(
"-")) {
109 if (!token.
Icmp(
"s")) {
135 if(!token.
Icmp(
"createNode") || !token.
Icmp(
"connectAttr") || !token.
Icmp(
"select")) {
145 memset(&header, 0,
sizeof(header));
162 if(!token.
Icmp(
"setAttr")) {
164 if(!token.
Icmp(
".t")) {
169 }
else if (!token.
Icmp(
".r")) {
173 }
else if (!token.
Icmp(
".s")) {
183 if(header.
parent[0] != 0) {
188 transform->
parent = *parent;
209 int minIndex, maxIndex;
216 for(
int i = minIndex;
i <= maxIndex;
i++) {
232 if(header->
size == 0) {
242 int minIndex, maxIndex;
249 if(!token.
Icmp(
"-")) {
252 if(!tk2.
Icmp(
"type")) {
263 for(
int i = minIndex;
i <= maxIndex;
i++) {
289 int minIndex, maxIndex;
296 for(
int i = minIndex;
i <= maxIndex;
i++) {
317 int minIndex, maxIndex;
325 if(!token.
Icmp(
"-")) {
328 if(!tk2.
Icmp(
"type")) {
340 for(
int i = minIndex;
i <= maxIndex;
i++) {
371 int minIndex, maxIndex;
378 int currentFace = minIndex-1;
385 if(!token.
Icmp(
"f")) {
403 }
else if(!token.
Icmp(
"mu")) {
414 }
else if(!token.
Icmp(
"mf")) {
424 }
else if(!token.
Icmp(
"fc")) {
453 int minIndex, maxIndex;
460 for(
int i = minIndex;
i <= maxIndex;
i++) {
476 if(strstr(header->
name,
"uvsn")) {
487 int minIndex, maxIndex;
494 if(!token.
Icmp(
"-")) {
497 if(!tk2.
Icmp(
"type")) {
508 for(
int i = minIndex;
i <= maxIndex;
i++) {
526 for(
int i = 0;
i < 3;
i++) {
531 if(pMesh->
edges[edge].
z == 1 && (pMesh->
edges[edge].
x == vertNum || pMesh->
edges[edge].
y == vertNum)) {
547 for(
int edgeIndex = 0; edgeIndex < 3; edgeIndex++) {
554 if(pMesh->
edges[edge].
z == 1 && (pMesh->
edges[edge].
x == vertNum || pMesh->
edges[edge].
y == vertNum)) {
556 for(
int i = 0;
i < faceIndex;
i++) {
558 for(
int j = 0;
j < 3;
j++) {
588 if(header.
parent[0] != 0) {
606 if(!token.
Icmp(
"setAttr")) {
610 if(strstr(header.
name,
".vt")) {
612 }
else if (strstr(header.
name,
".ed")) {
614 }
else if (strstr(header.
name,
".pt")) {
616 }
else if (strstr(header.
name,
".n")) {
618 }
else if (strstr(header.
name,
".fc")) {
620 }
else if (strstr(header.
name,
".clr")) {
622 }
else if (strstr(header.
name,
".uvst")) {
635 for(
int j = 0;
j < 3;
j++) {
649 for(
int j = 0;
j < 3;
j++) {
659 if(sharedFace != -1) {
718 if(!token.
Icmp(
"setAttr")) {
722 if(strstr(attribHeader.
name,
".ftn")) {
725 if(!token.
Icmp(
"(")) {
731 strcpy(fileNode->
name, header.
name);
762 if(!token.
Icmp(
"transform")) {
764 }
else if(!token.
Icmp(
"mesh")) {
766 }
else if(!token.
Icmp(
"file")) {
768 }
else if(!token.
Icmp(
"shadingEngine") || !token.
Icmp(
"lambert") || !token.
Icmp(
"phong") || !token.
Icmp(
"blinn") ) {
783 while(matNode && !matNode->
file) {
784 matNode = matNode->
child;
786 if(matNode && matNode->
file) {
822 srcName = temp.
Left(dot);
827 dot = temp.
Find(
".");
832 destName = temp.
Left(dot);
835 if(srcType.
Find(
"oc") != -1) {
844 (*destNode)->child = *matNode;
855 (*destNode)->file = *fileNode;
860 if(srcType.
Find(
"iog") != -1) {
927 if(fabs(transform->
rotate.
x) > 0.0f) {
930 if(fabs(transform->
rotate.
y) > 0.0f) {
933 if(fabs(transform->
rotate.
z) > 0.0f) {
950 transform = transform->
parent;
961 memset( &maGlobal, 0,
sizeof( maGlobal ) );
978 parser.
LoadMemory(buffer, strlen(buffer), filename);
983 if(!token.
Icmp(
"createNode")) {
985 }
else if(!token.
Icmp(
"connectAttr")) {
1000 return maGlobal.
model;
1010 ID_TIME_T timeStamp;
1019 ma =
MA_Parse( buf, fileName,
false );
1023 if(maGlobal.
model) {
1066 if ( mesh->
edges ) {
1072 if ( mesh->
faces ) {
1086 for ( i = 0; i < ma->
transforms.Num(); i++ ) {
maModel_t * MA_Load(const char *fileName)
void MA_ParseFileNode(idParser &parser)
bool MA_ParseConnectAttr(idParser &parser)
void MA_ParseNodeHeader(idParser &parser, maNodeHeader_t *header)
void UnreadToken(idToken *token)
bool MA_ParseAttribHeader(idParser &parser, maAttribHeader_t *header)
int SkipUntilString(const char *string)
bool MA_ReadVec3(idParser &parser, idVec3 &vec)
virtual int ReadFile(const char *relativePath, void **buffer, ID_TIME_T *timestamp=NULL)=0
GLenum GLenum GLenum GLenum GLenum scale
bool IsNodeComplete(idToken &token)
bool MA_ParseVertex(idParser &parser, maAttribHeader_t *header)
maTransform_t * transform
idFileSystem * fileSystem
idHashTable< maMaterialNode_t * > materialNodes
Type * GetIndex(int index) const
struct maModel_s maModel_t
const char * Left(int len, idStr &result) const
int LoadMemory(const char *ptr, int length, const char *name)
maObject_t * currentObject
int nextVertTransformIndex
virtual void FreeFile(void *buffer)=0
bool MA_ParseVertexTransforms(idParser &parser, maAttribHeader_t *header)
int Icmp(const char *text) const
idList< maObject_t * > objects
int ReadToken(idToken *token)
void Set(const char *key, Type &value)
GLuint GLuint GLsizei count
bool MA_ParseEdge(idParser &parser, maAttribHeader_t *header)
static float Sin(float a)
static float Fabs(float f)
void MA_BuildAxisRotation(idMat4 &mat, float ang, int axis)
void MA_GetSharedFace(int faceIndex, int vertIndex, int &sharedFace, int &sharedVert)
bool MA_ParseColor(idParser &parser, maAttribHeader_t *header)
bool MA_ParseTVert(idParser &parser, maAttribHeader_t *header)
const char * Right(int len, idStr &result) const
idHashTable< maTransform_t * > transforms
int Find(const char c, int start=0, int end=-1) const
bool MA_QuickIsVertShared(int faceIndex, int vertIndex)
void MA_Free(maModel_t *ma)
bool MA_ParseHeaderIndex(maAttribHeader_t *header, int &minIndex, int &maxIndex, const char *headerType, const char *skipString)
bool MA_ParseTransform(idParser &parser)
idList< maMaterial_t * > materials
bool MA_ParseFace(idParser &parser, maAttribHeader_t *header)
int MA_AddMaterial(const char *materialName)
bool Get(const char *key, Type **value=NULL) const
void MA_BuildScale(idMat4 &mat, float x, float y, float z)
int Append(const type &obj)
void MA_ApplyTransformation(maModel_t *model)
char error[MAX_STRING_CHARS]
void MA_ParseMaterialNode(idParser &parser)
bool MA_ParseNormal(idParser &parser, maAttribHeader_t *header)
void MA_ParseCreateNode(idParser &parser)
maModel_t * MA_Parse(const char *buffer, const char *filename, bool verbose)
const char * c_str(void) const
idHashTable< maFileNode_t * > fileNodes
const idVec3 & ToVec3(void) const
void * Mem_Alloc(const int size)
float dot(float a[], float b[])
GLuint GLenum GLenum transform
char * va(const char *fmt,...)
virtual const char * OSPathToRelativePath(const char *OSPath)=0
void MA_ParseMesh(idParser &parser)
virtual void virtual void Warning(const char *fmt,...) id_attribute((format(printf
const char * GetFileName(void) const
static float Cos(float a)