Ejemplo n.º 1
0
    void DiMeshSerializerImpl::ReadSubMesh( DiDataStreamPtr& stream, DiMesh* pMesh )
    {
        DI_SERIAL_LOG("Reading submesh..");

        DiSubMesh* sm = pMesh->CreateSubMesh();

        unsigned short streamID = 0;

        DiString material = ReadString(stream);
        sm->SetMaterialName(material);

        DI_SERIAL_LOG("Liking material: %s", material.c_str());

        unsigned int indexCount = 0;
        ReadInts(stream, &indexCount, 1);

        DI_SERIAL_LOG("Indeices count: %d", indexCount);

        bool idx32bit;
        ReadBools(stream, &idx32bit, 1);

        DI_SERIAL_LOG("Index size: %d", idx32bit?32:16);

        uint16 primitive;
        ReadShorts(stream,&primitive,1);
        sm->SetPrimitiveType((DiPrimitiveType)primitive);

        DI_SERIAL_LOG("Primitive type: %d", primitive);

        if (indexCount > 0)
        {
            void* indexdata = sm->CreateIndexData(indexCount,idx32bit?TRUE:FALSE);
            int size = indexCount * (sm->GetIndexSize() / 8);
            stream->Read(indexdata, size);
            DI_SERIAL_LOG("%d bytes readed", size);
        }

        streamID = ReadChunk(stream);
        if (streamID != DI_GEOMETRY)
        {
            DI_ERROR("Bad stream ID");
            return;
        }

        ReadGeometry(stream, sm);

        if (!stream->Eof())
        {
            streamID = ReadChunk(stream);
            if (streamID == DI_MESH_WEIGHTS)
            {
                ReadSubMeshBoneWeights(stream,sm);
            }
            else
            {
                if (!stream->Eof())
                    stream->Skip(-MSTREAM_OVERHEAD_SIZE);
            }
        }
    }
Ejemplo n.º 2
0
void ColladaParser::ReadGeometry(XmlElement* e)
{
	Geometry g;
	g.id = e->Attribute("id");
	g.name = e->Attribute("name");

	{
		auto v = e->Child("mesh")->Childs("source");
		for (int ia = 0; ia < v.size(); ia++)
			g.ReadSource(v[ia]);
	}

	{
		auto v = e->Child("mesh")->Childs("vertices");
		for (int ia = 0; ia < v.size(); ia++)
		{
			Geometry::Vertices vert;
			vert.id = v[ia]->Attribute("id");
			vert.positionSourceId = ReadId(v[ia]->Child("input", "semantic", "POSITION")->Attribute("source"));
			vert.normalSourceId = ReadId(v[ia]->Child("input", "semantic", "NORMAL")->Attribute("source"));
			vert.texcoordSourceId = ReadId(v[ia]->Child("input", "semantic", "TEXCOORD")->Attribute("source"));
			g.vertices.emplace(vert.id, vert);
		}
	}

	auto t = e->Child("mesh")->Child("triangles");
	auto count = ReadInt(t->Attribute("count"));
	g.triangleVerticesId = ReadId(t->Child("input")->Attribute("source"));
	g.triangleIndices = ReadInts(t->Child("p")->content, count * 3);
	geometries.emplace(g.id, g);
}
Ejemplo n.º 3
0
    uint16 DiSerializer::ReadChunk( DiDataStreamPtr& stream )
    {
        unsigned short id;
        ReadShorts(stream, &id, 1);

        ReadInts(stream, &mCurChunkSize, 1);
        return id;
    }
Ejemplo n.º 4
0
    void DiMeshSerializerImpl::ReadGeometry( DiDataStreamPtr& stream, DiSubMesh* pMesh )
    {
        DI_SERIAL_LOG("Reading geometry data...");

        unsigned int vertexCount = 0;
        ReadInts(stream, &vertexCount, 1);
        pMesh->SetVerticeNum(vertexCount);

        DI_SERIAL_LOG("Vertices count: %d", vertexCount);

        unsigned int faceCount = 0;
        ReadInts(stream, &faceCount, 1);
        pMesh->SetPrimitiveCount(faceCount);

        DI_SERIAL_LOG("Face count: %d", faceCount);

        if (!stream->Eof())
        {
            unsigned short streamID = ReadChunk(stream);
            while(!stream->Eof() &&
                (streamID == DI_GEOMETRY_VERTEX_BUFFER ||
                streamID == DI_GEOMETRY_VERTEX_DECLARATION))
            {
                switch (streamID)
                {
                case DI_GEOMETRY_VERTEX_DECLARATION:
                    ReadGeometryVertexDeclaration(stream, pMesh);
                    break;
                case DI_GEOMETRY_VERTEX_BUFFER:
                    ReadGeometryVertexBuffer(stream, pMesh);
                    break;
                }

                if (!stream->Eof())
                {
                    streamID = ReadChunk(stream);
                }
            }
            if (!stream->Eof())
            {
                stream->Skip(-MSTREAM_OVERHEAD_SIZE);
            }
        }
    }
Ejemplo n.º 5
0
    void DiMeshSerializerImpl::ReadSubMeshBoneWeights( DiDataStreamPtr& stream, DiSubMesh* pMesh )
    {
        DI_SERIAL_LOG("Reading bone weights...");

        uint32 size = 0;
        ReadInts(stream,&size,1);
        DI_SERIAL_LOG("Size: %d",size);

        for (uint16 i=0; i<size; i++)
        {
            DiBoneWeight weight;
            ReadInts(stream,&weight.vertexIndex,1);
            ReadShorts(stream,&weight.boneIndex,1);
            ReadFloats(stream,&weight.weight,1);
            pMesh->mBoneWeights.insert(DiSubMesh::BoneWeightList::value_type(weight.vertexIndex, weight));
        }

        pMesh->SetupBoneWeights();
    }
Ejemplo n.º 6
0
std::vector<int> ColladaParser::ReadInts(const std::string& s, int n)
{
	return ReadInts(s.c_str(), n);
}