예제 #1
0
void MD3Model::GetVertices(uint32_t s, uint32_t f, MeshVertex_t*& vertexData, uint32_t& vertexCount) const {
    assert(s < header->numSurfaces);
    assert(f < header->numFrames);
    
    MD3::Surface_t*    surface = surfaces[s];
    MD3::Vertex_t*    vertices = GetVertices(s, f);
    MD3::TexCoord_t* texCoords = GetTexCoords(s);
    
    vertexCount = surface->numVerts;
    vertexData  = new MeshVertex_t[vertexCount];

    for (uint32_t i=0; i<vertexCount; ++i) {
        vertexData[i].coord = glm::vec3(
            vertices[i].x,
            vertices[i].y,
            vertices[i].z
        ) * MD3_SCALE;

        vertexData[i].normal = DecodeNormal(vertices[i].n);

        vertexData[i].texCoord = glm::vec2(
            texCoords[i].u,
            texCoords[i].v
        );
    }
}
예제 #2
0
unsigned int MDCSurface_read(Surface& surface, const byte* buffer)
{
  mdcSurface_t mdcSurface;
  {
    PointerInputStream inputStream(buffer);
    istream_read_mdcSurface(inputStream, mdcSurface);
  }

  {
    surface.vertices().reserve(mdcSurface.numVerts);

    PointerInputStream xyzStream(buffer + mdcSurface.ofsXyzNormals);
    PointerInputStream stStream(buffer + mdcSurface.ofsSt);
    // read verts into vertex array - xyz, st, normal
    for(std::size_t i = 0; i < mdcSurface.numVerts; i++)
	  {
      mdcXyzNormal_t mdcXyzNormal;
      istream_read_mdcXyzNormal(xyzStream, mdcXyzNormal);
      mdcSt_t mdcSt;
      istream_read_mdcSt(stStream, mdcSt);

      surface.vertices().push_back(
        ArbitraryMeshVertex(
          Vertex3f( mdcXyzNormal.xyz[0] * MDC_XYZ_SCALE, mdcXyzNormal.xyz[1] * MDC_XYZ_SCALE, mdcXyzNormal.xyz[2] * MDC_XYZ_SCALE),
          DecodeNormal(reinterpret_cast<byte*>(&mdcXyzNormal.normal)),
          TexCoord2f(mdcSt.st[0], mdcSt.st[1])
        )
      );
    }
  }

  {
 	  surface.indices().reserve(mdcSurface.numTriangles * 3);

    PointerInputStream triangleStream(buffer + mdcSurface.ofsTriangles);

    for(std::size_t i = 0; i < mdcSurface.numTriangles; i++)
    {
      mdcTriangle_t triangle;
      istream_read_mdcTriangle(triangleStream, triangle);
      surface.indices().insert(triangle.indexes[0]);
      surface.indices().insert(triangle.indexes[1]);
      surface.indices().insert(triangle.indexes[2]);
    }
  }

  {
    mdcShader_t shader;
    PointerInputStream inputStream(buffer + mdcSurface.ofsShaders);
    istream_read_mdcShader(inputStream, shader);
    surface.setShader(shader.name);
  }
	
	surface.updateAABB();

  return mdcSurface.ofsEnd;
}
예제 #3
0
void xmlBranchLoad::DecodePoint( ticpp::Element* pVertex , int i )
{
	//считать координаты точки
	int iNum = 0;
	pVertex->GetAttribute( m_BranchNames.m_sNum , &iNum );
	ticpp::Iterator< ticpp::Element > pPoint( m_BranchNames.m_sPoint );
	for ( pPoint = pPoint.begin( pVertex ); pPoint != pPoint.end(); pPoint++ )
	{
		//извлечь координаты вершины
		DecodeVertex( pPoint , &m_pData->m_vBranch[ i ].m_vVertex );

		//извлечь координаты нормали
		DecodeNormal( pPoint , &m_pData->m_vBranch[ i ].m_vNormal );

		//извлечь текстурные координаты
		DecodeTexCoord( pPoint , &m_pData->m_vBranch[ i ].m_vTexCoord );
	}
}