// -------------------------------------------------------------------
void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
    size_t numComponents( 0 );
    const char* tmp( &m_DataIt[0] );
    while( !IsLineEnd( *tmp ) ) {
        if ( !SkipSpaces( &tmp ) ) {
            break;
        }
        SkipToken( tmp );
        ++numComponents;
    }
    float x, y, z;
    if( 2 == numComponents ) {
        copyNextWord( m_buffer, BUFFERSIZE );
        x = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, BUFFERSIZE );
        y = ( float ) fast_atof( m_buffer );
        z = 0.0;
    } else if( 3 == numComponents ) {
        copyNextWord( m_buffer, BUFFERSIZE );
        x = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, BUFFERSIZE );
        y = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, BUFFERSIZE );
        z = ( float ) fast_atof( m_buffer );
    } else {
        throw DeadlyImportError( "OBJ: Invalid number of components" );
    }
    point3d_array.push_back( aiVector3D( x, y, z ) );
    m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
}
Esempio n. 2
0
// -------------------------------------------------------------------
void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
    size_t numComponents( 0 );
    DataArrayIt tmp( m_DataIt );
    while( !IsLineEnd( *tmp ) ) {
        if( *tmp == ' ' ) {
            ++numComponents;
        }
        tmp++;
    }
    float x, y, z;
    if( 2 == numComponents ) {
        copyNextWord( m_buffer, BUFFERSIZE );
        x = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, BUFFERSIZE );
        y = ( float ) fast_atof( m_buffer );
        z = 0.0;
    } else if( 3 == numComponents ) {
        copyNextWord( m_buffer, BUFFERSIZE );
        x = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, BUFFERSIZE );
        y = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, BUFFERSIZE );
        z = ( float ) fast_atof( m_buffer );
    } else {
        ai_assert( !"Invalid number of components" );
    }
    point3d_array.push_back( aiVector3D( x, y, z ) );
    m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
}
Esempio n. 3
0
// -------------------------------------------------------------------
void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
    size_t numComponents = getNumComponentsInLine();
    float x, y, z;
    if( 2 == numComponents ) {
        copyNextWord( m_buffer, Buffersize );
        x = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, Buffersize );
        y = ( float ) fast_atof( m_buffer );
        z = 0.0;
    } else if( 3 == numComponents ) {
        copyNextWord( m_buffer, Buffersize );
        x = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, Buffersize );
        y = ( float ) fast_atof( m_buffer );

        copyNextWord( m_buffer, Buffersize );
        z = ( float ) fast_atof( m_buffer );
    } else {
        throw DeadlyImportError( "OBJ: Invalid number of components" );
    }
    point3d_array.push_back( aiVector3D( x, y, z ) );
    m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
}
Esempio n. 4
0
// -------------------------------------------------------------------
//	Get values for a new 2D vector instance
void ObjFileParser::getVector2( std::vector<aiVector2D> &point2d_array ) {
	float x, y;
	copyNextWord(m_buffer, BUFFERSIZE);
	x = (float) fast_atof(m_buffer);	
	
	copyNextWord(m_buffer, BUFFERSIZE);
	y = (float) fast_atof(m_buffer);

	point2d_array.push_back(aiVector2D(x, y));

	m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
}
Esempio n. 5
0
void MeshManager::getVector2(std::vector<glm::vec2>* vertices, char* buffer, int* i){
	getNextWord(buffer, i);
	float x, y;

	copyNextWord(tempBuffer, BUFFERSIZE, buffer, i);
	x = (float) fast_atof(tempBuffer);

	copyNextWord(tempBuffer, BUFFERSIZE, buffer, i);
	y = (float) fast_atof(tempBuffer);

	vertices->push_back(glm::vec2(x, y));

	skipLine(buffer, i);
}
Esempio n. 6
0
// -------------------------------------------------------------------
//  Get values for a new 3D vector instance
void ObjFileParser::getVector3( std::vector<aiVector3D> &point3d_array ) {
    float x, y, z;
    copyNextWord(m_buffer, Buffersize);
    x = (float) fast_atof(m_buffer);

    copyNextWord(m_buffer, Buffersize);
    y = (float) fast_atof(m_buffer);

    copyNextWord( m_buffer, Buffersize );
    z = ( float ) fast_atof( m_buffer );

    point3d_array.push_back( aiVector3D( x, y, z ) );
    m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
}
Esempio n. 7
0
void MeshManager::getFace(std::vector<glm::i32vec3>* vertices, char* buffer, int* i){
	getNextWord(buffer, i);
	int x, y, z;
	copyNextWord(tempBuffer, BUFFERSIZE, buffer, i);
	x = (int) atoi(tempBuffer) - 1 - elementOffsetOBJ;

	copyNextWord(tempBuffer, BUFFERSIZE, buffer, i);
	y = (int) atoi(tempBuffer) - 1 - elementOffsetOBJ;

	copyNextWord(tempBuffer, BUFFERSIZE, buffer, i);
	z = (int) atoi(tempBuffer) - 1 - elementOffsetOBJ;

	vertices->push_back(glm::i32vec3(x, y, z));

	skipLine(buffer, i);
}
Esempio n. 8
0
Mesh* MeshManager::parseMD5(string filename, char* buffer, int lenght){
    Mesh* resultMesh = new Mesh(filename, getNewId());
	int numJoints = 0;
	int numMeshes = 0;
	int numVerts = 0;
	int numTris = 0;
	int numWeights = 0;
	unsigned int idSubMesh = 0;
	int n = 0;
	copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);//autoincrease i
	while (buffer[n] != '\0'){
		if(strncmp(tempBuffer, "MD5Version", 10) == 0){
			copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
			//resultMesh->versionMD5 = (int) atoi(tempBuffer);
			//logInf("md5 version %s", tempBuffer);
		}
		else if(strncmp(tempBuffer, "commandline", 11) == 0){
			skipLine(buffer, &n);
		}
		else if(strncmp(tempBuffer, "numJoints", 9) == 0){
			copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
			numJoints = (int) atoi(tempBuffer);
			resultMesh->joints.reserve(numJoints);
		}
		else if(strncmp(tempBuffer, "numMeshes", 9) == 0){
			copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
			numMeshes = (int) atoi(tempBuffer);
			resultMesh->subMeshes.reserve(numMeshes);
		}
		else if(strncmp(tempBuffer, "joints", 6) == 0){
			copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n); //read the '{' character
			Mesh::Joint auxJoint;
			for(int i = 0; i < numJoints; i++){
				copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
				auxJoint.jointName = tempBuffer;
				copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
				auxJoint.jointParentID = (int) atoi(tempBuffer);
				copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);// '(' char
				copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
				auxJoint.jointPos.x = (float) fast_atof(tempBuffer);
				copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
				auxJoint.jointPos.y = (float) fast_atof(tempBuffer);
				copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
				auxJoint.jointPos.z = (float) fast_atof(tempBuffer);
				copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);// ')' char
				copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);// '(' char
				copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
				auxJoint.jointOrient.x = (float) fast_atof(tempBuffer);
				copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
				auxJoint.jointOrient.y = (float) fast_atof(tempBuffer);
				copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
				auxJoint.jointOrient.z = (float) fast_atof(tempBuffer);
				skipLine(buffer, &n);

				removeQuotes(&(auxJoint.jointName));
				computeQuaternionW(&(auxJoint.jointOrient));

				resultMesh->joints.push_back(auxJoint);
			}
		}
		else if(strncmp(tempBuffer, "mesh", 4) == 0){
			SubMesh* auxSubMesh = new SubMesh(idSubMesh);
			idSubMesh++;
			copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);// char {
			copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
			while(strncmp(tempBuffer, "}", 1) != 0){
				if(strncmp(tempBuffer, "shader", 6) == 0){
					///////////////TODO
					//shader factory
					//used to set the texture!! be careful
					copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
					auxSubMesh->setSubMeshTextureName(tempBuffer);
					skipLine(buffer, &n);
				}
				else if(strncmp(tempBuffer, "numverts", 8) == 0){
					copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
					numVerts = (int) atoi(tempBuffer);
					glm::vec2 textCoord;
					glm::i32vec2 weightStartAndCount;
					for(int i = 0; i < numVerts; ++i){
						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);//"vert"
						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);//id (sorted)
						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);//'('

						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
						textCoord.x = (float) fast_atof(tempBuffer);
						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
						textCoord.y = (float) fast_atof(tempBuffer);

						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);//')'

						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
						weightStartAndCount.x = (int) atoi(tempBuffer);
						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
						weightStartAndCount.y = (int) atoi(tempBuffer);

						auxSubMesh->textureCoord.push_back(textCoord);
						auxSubMesh->weightsIndex.push_back(weightStartAndCount);
					}
				}
				else if(strncmp(tempBuffer, "numtris", 7) == 0){
					copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
					numTris = (int) atoi(tempBuffer);
					glm::i32vec3 tri;
					auxSubMesh->elements.reserve(numTris);
					for (int i = 0; i < numTris; ++i){
						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
						tri.x = (int) atoi(tempBuffer);
						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
						tri.z = (int) atoi(tempBuffer);
						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
						tri.y = (int) atoi(tempBuffer);
						auxSubMesh->elements.push_back(tri);
					}
				}
				else if(strncmp(tempBuffer, "numweights", 10) == 0){
					copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
					numWeights = (int) atoi(tempBuffer);
					SubMesh::Weight auxWeight;
					auxSubMesh->weights.reserve(numWeights);
					for (int i = 0; i < numWeights; ++i){
						//logInf("Weight[%i]",i);
						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);//weight
						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);//id (sorted)
						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);//id joint
						auxWeight.weightJointID = (int) atoi(tempBuffer);
						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);//bias
						auxWeight.weightBias = (float) fast_atof(tempBuffer);
						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);//'('
						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
						auxWeight.weightPos.x = (float) fast_atof(tempBuffer);
						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
						auxWeight.weightPos.y = (float) fast_atof(tempBuffer);
						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);
						auxWeight.weightPos.z = (float) fast_atof(tempBuffer);
						copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);//')'

						auxSubMesh->weights.push_back(auxWeight);
						//logInf("Weight[%i]",i);
					}
				}
				else if(strncmp(tempBuffer, "//", 2) == 0){
					skipLine(buffer, &n);
				}
				copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);

			}
			prepareSubMeshVertex(resultMesh, auxSubMesh);
			prepareSubMeshNormals(resultMesh, auxSubMesh);
			resultMesh->subMeshes.push_back(auxSubMesh);
		}

		copyNextWord(tempBuffer, BUFFERSIZE, buffer, &n);//autoincrease i
        if(n>=lenght)break;

	}
	return resultMesh;
}