Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- atUint16 readAttribute(atUint16& value, atUint32 attributes, atUint32 index, Athena::io::IStreamReader& reader);
- void readPrimitives(CMesh& mesh, const CMaterial& material, atUint16 dataSize, Athena::io::IStreamReader& reader)
- {
- atUint32 vertexAttributes = material.vertexAttributes();
- atUint32 mainAttributes = 0;
- atUint32 subAttributes = 0;
- mainAttributes = vertexAttributes & 0x00FFFFFF;
- subAttributes = (vertexAttributes >> 0x18) & 0xFF;
- atUint32 readBytes = 0;
- while (!reader.atEnd())
- {
- atUint8 primitiveFlags = reader.readUByte();
- atUint32 indexCount = 0;
- if (primitiveFlags == 0)
- {
- break;
- }
- indexCount = reader.readUint16();
- readBytes += 2;
- if (indexCount == 0 || reader.atEnd())
- {
- break;
- }
- CPrimitive primitive;
- primitive.primitive = (EPrimitive)(primitiveFlags & 0xF8);
- primitive.vertexFormatIdx = primitiveFlags & 0x07;
- atUint32 startReadBytes = readBytes;
- atUint32 currentPos = reader.position();
- bool valid = false;
- primitive.indices.resize(indexCount);
- SVertexDescriptor* pFaces = &primitive.indices.front();
- if (mainAttributes)
- {
- reader.seek(currentPos, Athena::SeekOrigin::Begin);
- readBytes = startReadBytes;
- atUint32 attributes = 0;
- for (atUint32 v = 0; v < indexCount; ++v)
- {
- // read unknown attribute indices
- attributes = subAttributes;
- while (attributes)
- {
- if (attributes & 1)
- {
- reader.readUByte();
- readBytes += 1;
- }
- attributes >>= 1;
- }
- // read main attribute indices
- attributes = mainAttributes;
- readBytes += readAttribute(pFaces[v].position, attributes, 0, reader);
- readBytes += readAttribute(pFaces[v].normal, attributes, 1, reader);
- for (int iColor = 0; iColor < 2; ++iColor)
- {
- readBytes += readAttribute(pFaces[v].clr[iColor], attributes, iColor + 2, reader);
- }
- for (int iUV = 0; iUV < 8; ++iUV)
- {
- readBytes += readAttribute(pFaces[v].texCoord[iUV], attributes, iUV + 4, reader);
- }
- for (int iUnk = 0; iUnk < 4; ++iUnk)
- {
- readBytes += readAttribute(pFaces[v].unkIndex[iUnk], attributes, iUnk + 12, reader);
- }
- }
- valid = true;
- }
- if (!valid)
- {
- primitive.primitive = (EPrimitive)0;
- break;
- }
- mesh.m_primitives.push_back(primitive);
- }
- }
- atUint16 readAttribute(atUint16 & value, atUint32 attributes, atUint32 index, Athena::io::IStreamReader& reader)
- {
- atUint16 readCount = 0;
- switch ((attributes >> (index << 1)) & 3)
- {
- case 3:
- value = reader.readUint16();
- readCount = 2;
- break;
- case 2:
- value = reader.readUByte();
- readCount = 1;
- break;
- default:
- break;
- }
- return readCount;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement