コード例 #1
0
ファイル: Model_ma.cpp プロジェクト: boscorillium/dhewm3
bool MA_ReadVec3(idParser& parser, idVec3& vec) {
    idToken token;
    if(!parser.SkipUntilString("double3")) {
        throw idException( va("Maya Loader '%s': Invalid Vec3", parser.GetFileName()) );
    }


    //We need to flip y and z because of the maya coordinate system
    vec.x = parser.ParseFloat();
    vec.z = parser.ParseFloat();
    vec.y = parser.ParseFloat();

    return true;
}
コード例 #2
0
ファイル: Model_ma.cpp プロジェクト: boscorillium/dhewm3
bool MA_ParseConnectAttr(idParser& parser) {

    idStr temp;
    idStr srcName;
    idStr srcType;
    idStr destName;
    idStr destType;

    idToken token;
    parser.ReadToken(&token);
    temp = token;
    int dot = temp.Find(".");
    if(dot == -1) {
        throw idException(va("Maya Loader '%s': Invalid Connect Attribute.", parser.GetFileName()));
    }
    srcName = temp.Left(dot);
    srcType = temp.Right(temp.Length()-dot-1);

    parser.ReadToken(&token);
    temp = token;
    dot = temp.Find(".");
    if(dot == -1) {
        throw idException(va("Maya Loader '%s': Invalid Connect Attribute.", parser.GetFileName()));
    }
    destName = temp.Left(dot);
    destType = temp.Right(temp.Length()-dot-1);

    if(srcType.Find("oc") != -1) {

        //Is this attribute a material node attribute
        maMaterialNode_t**	matNode;
        maGlobal.model->materialNodes.Get(srcName, &matNode);
        if(matNode) {
            maMaterialNode_t**	destNode;
            maGlobal.model->materialNodes.Get(destName, &destNode);
            if(destNode) {
                (*destNode)->child = *matNode;
            }
        }

        //Is this attribute a file node
        maFileNode_t** fileNode;
        maGlobal.model->fileNodes.Get(srcName, &fileNode);
        if(fileNode) {
            maMaterialNode_t**	destNode;
            maGlobal.model->materialNodes.Get(destName, &destNode);
            if(destNode) {
                (*destNode)->file = *fileNode;
            }
        }
    }

    if(srcType.Find("iog") != -1) {
        //Is this an attribute for one of our meshes
        for(int i = 0; i < maGlobal.model->objects.Num(); i++) {
            if(!strcmp(maGlobal.model->objects[i]->name, srcName)) {
                //maGlobal.model->objects[i]->materialRef = MA_AddMaterial(destName);
                strcpy(maGlobal.model->objects[i]->materialName, destName);
                break;
            }
        }
    }

    return true;
}
コード例 #3
0
ファイル: Model_ma.cpp プロジェクト: boscorillium/dhewm3
void MA_ParseMesh(idParser& parser) {

    maObject_t	*object;
    object = (maObject_t *)Mem_Alloc( sizeof( maObject_t ) );
    memset( object, 0, sizeof( maObject_t ) );
    maGlobal.model->objects.Append( object );
    maGlobal.currentObject = object;
    object->materialRef = -1;


    //Get the header info from the mesh
    maNodeHeader_t	header;
    MA_ParseNodeHeader(parser, &header);

    //Find my parent
    if(header.parent[0] != 0) {
        //Find the parent
        maTransform_t**	parent;
        maGlobal.model->transforms.Get(header.parent, &parent);
        if(parent) {
            maGlobal.currentObject->mesh.transform = *parent;
        }
    }

    strcpy(object->name, header.name);

    //Read the transform attributes
    idToken token;
    while(parser.ReadToken(&token)) {
        if(IsNodeComplete(token)) {
            parser.UnreadToken(&token);
            break;
        }
        if(!token.Icmp("setAttr")) {
            maAttribHeader_t header;
            MA_ParseAttribHeader(parser, &header);

            if(strstr(header.name, ".vt")) {
                MA_ParseVertex(parser, &header);
            } else if (strstr(header.name, ".ed")) {
                MA_ParseEdge(parser, &header);
            } else if (strstr(header.name, ".pt")) {
                MA_ParseVertexTransforms(parser, &header);
            } else if (strstr(header.name, ".n")) {
                MA_ParseNormal(parser, &header);
            } else if (strstr(header.name, ".fc")) {
                MA_ParseFace(parser, &header);
            } else if (strstr(header.name, ".clr")) {
                MA_ParseColor(parser, &header);
            } else if (strstr(header.name, ".uvst")) {
                MA_ParseTVert(parser, &header);
            } else {
                parser.SkipRestOfLine();
            }
        }
    }


    maMesh_t* pMesh = &maGlobal.currentObject->mesh;

    //Get the verts from the edge
    for(int i = 0; i < pMesh->numFaces; i++) {
        for(int j = 0; j < 3; j++) {
            int edge = pMesh->faces[i].edge[j];
            if(edge < 0) {
                edge = idMath::Fabs(edge)-1;
                pMesh->faces[i].vertexNum[j] = pMesh->edges[edge].y;
            } else {
                pMesh->faces[i].vertexNum[j] = pMesh->edges[edge].x;
            }
        }
    }

    //Get the normals
    if(pMesh->normalsParsed) {
        for(int i = 0; i < pMesh->numFaces; i++) {
            for(int j = 0; j < 3; j++) {

                //Is this vertex shared
                int sharedFace = -1;
                int sharedVert = -1;

                if(MA_QuickIsVertShared(i, j)) {
                    MA_GetSharedFace(i, j, sharedFace, sharedVert);
                }

                if(sharedFace != -1) {
                    //Get the normal from the share
                    pMesh->faces[i].vertexNormals[j] = pMesh->faces[sharedFace].vertexNormals[sharedVert];

                } else {
                    //The vertex is not shared so get the next normal
                    if(pMesh->nextNormal >= pMesh->numNormals) {
                        //We are using more normals than exist
                        throw idException(va("Maya Loader '%s': Invalid Normals Index.", parser.GetFileName()));
                    }
                    pMesh->faces[i].vertexNormals[j] = pMesh->normals[pMesh->nextNormal];
                    pMesh->nextNormal++;
                }
            }
        }
    }

    //Now that the normals are good...lets reorder the verts to make the tris face the right way
    for(int i = 0; i < pMesh->numFaces; i++) {
        int tmp = pMesh->faces[i].vertexNum[1];
        pMesh->faces[i].vertexNum[1] = pMesh->faces[i].vertexNum[2];
        pMesh->faces[i].vertexNum[2] = tmp;

        idVec3 tmpVec = pMesh->faces[i].vertexNormals[1];
        pMesh->faces[i].vertexNormals[1] = pMesh->faces[i].vertexNormals[2];
        pMesh->faces[i].vertexNormals[2] = tmpVec;

        tmp = pMesh->faces[i].tVertexNum[1];
        pMesh->faces[i].tVertexNum[1] = pMesh->faces[i].tVertexNum[2];
        pMesh->faces[i].tVertexNum[2] = tmp;

        tmp = pMesh->faces[i].vertexColors[1];
        pMesh->faces[i].vertexColors[1] = pMesh->faces[i].vertexColors[2];
        pMesh->faces[i].vertexColors[2] = tmp;
    }

    //Now apply the pt transformations
    for(int i = 0; i < pMesh->numVertTransforms; i++) {
        pMesh->vertexes[(int)pMesh->vertTransforms[i].w] +=  pMesh->vertTransforms[i].ToVec3();
    }

    MA_VERBOSE((va("MESH %s - parent %s\n", header.name, header.parent)));
    MA_VERBOSE((va("\tverts:%d\n",maGlobal.currentObject->mesh.numVertexes)));
    MA_VERBOSE((va("\tfaces:%d\n",maGlobal.currentObject->mesh.numFaces)));
}
コード例 #4
0
ファイル: Model_ma.cpp プロジェクト: boscorillium/dhewm3
bool MA_ParseFace(idParser& parser, maAttribHeader_t* header) {

    maMesh_t* pMesh = &maGlobal.currentObject->mesh;
    idToken token;

    //Allocate enough space for all the verts if this is the first attribute for verticies
    if(!pMesh->faces) {
        pMesh->numFaces = header->size;
        pMesh->faces = (maFace_t *)Mem_Alloc( sizeof( maFace_t ) * pMesh->numFaces );
    }

    //Get the start and end index for this attribute
    int minIndex, maxIndex;
    if(!MA_ParseHeaderIndex(header, minIndex, maxIndex, "FaceHeader", NULL)) {
        //This was just a header
        return true;
    }

    //Read the face data
    int currentFace = minIndex-1;
    while(parser.ReadToken(&token)) {
        if(IsNodeComplete(token)) {
            parser.UnreadToken(&token);
            break;
        }

        if(!token.Icmp("f")) {
            int count = parser.ParseInt();
            if(count != 3) {
                throw idException(va("Maya Loader '%s': Face is not a triangle.", parser.GetFileName()));
            }
            //Increment the face number because a new face always starts with an "f" token
            currentFace++;

            //We cannot reorder edges until later because the normal processing
            //assumes the edges are in the original order
            pMesh->faces[currentFace].edge[0] = parser.ParseInt();
            pMesh->faces[currentFace].edge[1] = parser.ParseInt();
            pMesh->faces[currentFace].edge[2] = parser.ParseInt();

            //Some more init stuff
            pMesh->faces[currentFace].vertexColors[0] = pMesh->faces[currentFace].vertexColors[1] = pMesh->faces[currentFace].vertexColors[2] = -1;

        } else if(!token.Icmp("mu")) {
            /* int uvstIndex = */ parser.ParseInt();
            int count = parser.ParseInt();
            if(count != 3) {
                throw idException(va("Maya Loader '%s': Invalid texture coordinates.", parser.GetFileName()));
            }
            pMesh->faces[currentFace].tVertexNum[0] = parser.ParseInt();
            pMesh->faces[currentFace].tVertexNum[1] = parser.ParseInt();
            pMesh->faces[currentFace].tVertexNum[2] = parser.ParseInt();

        } else if(!token.Icmp("mf")) {
            int count = parser.ParseInt();
            if(count != 3) {
                throw idException(va("Maya Loader '%s': Invalid texture coordinates.", parser.GetFileName()));
            }
            pMesh->faces[currentFace].tVertexNum[0] = parser.ParseInt();
            pMesh->faces[currentFace].tVertexNum[1] = parser.ParseInt();
            pMesh->faces[currentFace].tVertexNum[2] = parser.ParseInt();

        } else if(!token.Icmp("fc")) {

            int count = parser.ParseInt();
            if(count != 3) {
                throw idException(va("Maya Loader '%s': Invalid vertex color.", parser.GetFileName()));
            }
            pMesh->faces[currentFace].vertexColors[0] = parser.ParseInt();
            pMesh->faces[currentFace].vertexColors[1] = parser.ParseInt();
            pMesh->faces[currentFace].vertexColors[2] = parser.ParseInt();

        }
    }

    return true;
}
コード例 #5
0
ファイル: Anim_Import.cpp プロジェクト: nbohr1more/Revelation
/*
====================
idModelExport::ParseExportSection
====================
*/
int idModelExport::ParseExportSection( idParser &parser ) {
	idToken	command;
	idToken	token;
	idStr	defaultCommands;
	idLexer lex;
	idStr	temp;
	idStr	parms;
	int		count;
	// only export sections that match our export mask
	if( g_exportMask.GetString()[ 0 ] ) {
		if( parser.CheckTokenString( "{" ) ) {
			parser.SkipBracedSection( false );
			return 0;
		}
		parser.ReadToken( &token );
		if( token.Icmp( g_exportMask.GetString() ) ) {
			parser.SkipBracedSection();
			return 0;
		}
		parser.ExpectTokenString( "{" );
	} else if( !parser.CheckTokenString( "{" ) ) {
		// skip the export mask
		parser.ReadToken( &token );
		parser.ExpectTokenString( "{" );
	}
	count = 0;
	lex.SetFlags( LEXFL_NOSTRINGCONCAT | LEXFL_ALLOWPATHNAMES | LEXFL_ALLOWMULTICHARLITERALS | LEXFL_ALLOWBACKSLASHSTRINGCONCAT );
	while( 1 ) {
		if( !parser.ReadToken( &command ) ) {
			parser.Error( "Unexpoected end-of-file" );
			break;
		}
		if( command == "}" ) {
			break;
		}
		if( command == "options" ) {
			parser.ParseRestOfLine( defaultCommands );
		} else if( command == "addoptions" ) {
			parser.ParseRestOfLine( temp );
			defaultCommands += " ";
			defaultCommands += temp;
		} else if( ( command == "mesh" ) || ( command == "anim" ) || ( command == "camera" ) ) {
			if( !parser.ReadToken( &token ) ) {
				parser.Error( "Expected filename" );
			}
			temp = token;
			parser.ParseRestOfLine( parms );
			if( defaultCommands.Length() ) {
				sprintf( temp, "%s %s", temp.c_str(), defaultCommands.c_str() );
			}
			if( parms.Length() ) {
				sprintf( temp, "%s %s", temp.c_str(), parms.c_str() );
			}
			lex.LoadMemory( temp, temp.Length(), parser.GetFileName() );
			Reset();
			if( ParseOptions( lex ) ) {
				const char *game = cvarSystem->GetCVarString( "fs_game" );
				if( strlen( game ) == 0 ) {
					game = BASE_GAMEDIR;
				}
				if( command == "mesh" ) {
					dest.SetFileExtension( MD5_MESH_EXT );
				} else if( command == "anim" ) {
					dest.SetFileExtension( MD5_ANIM_EXT );
				} else if( command == "camera" ) {
					dest.SetFileExtension( MD5_CAMERA_EXT );
				} else {
					dest.SetFileExtension( command );
				}
				idStr back = commandLine;
				sprintf( commandLine, "%s %s -dest %s -game %s%s", command.c_str(), src.c_str(), dest.c_str(), game, commandLine.c_str() );
				if( ConvertMayaToMD5() ) {
					count++;
				} else {
					parser.Warning( "Failed to export '%s' : %s", src.c_str(), Maya_Error.c_str() );
				}
			}
			lex.FreeSource();
		} else {
			parser.Error( "Unknown token: %s", command.c_str() );
			parser.SkipBracedSection( false );
			break;
		}
	}
	return count;
}