WME3D: Move portions code to mesh loader

This commit is contained in:
Paweł Kołodziejski 2023-02-26 15:45:43 +01:00
parent ac506478d9
commit b5daa5fb8c
No known key found for this signature in database
GPG Key ID: 0BDADC9E74440FF7
3 changed files with 51 additions and 49 deletions

View File

@ -69,54 +69,7 @@ bool XMesh::loadFromXData(const Common::String &filename, XFileData *xobj, Commo
XSkinMeshLoader *mesh = new XSkinMeshLoader(this, meshObject);
_skinMesh = new SkinMeshHelper(mesh);
mesh->parsePositionCoords(meshObject);
uint numFaces = _skinMesh->getNumFaces();
//uint numBones = _skinMesh->getNumBones();
Common::Array<int> indexCountPerFace;
mesh->parseFaces(meshObject, numFaces, indexCountPerFace);
uint numChildren = 0;
xobj->getChildren(numChildren);
for (uint32 i = 0; i < numChildren; i++) {
XFileData xchildData;
XClassType objectType;
if (xobj->getChild(i, xchildData)) {
if (xchildData.getType(objectType)) {
if (objectType == kXClassMeshTextureCoords) {
mesh->parseTextureCoords(&xchildData);
} else if (objectType == kXClassMeshNormals) {
mesh->parseNormalCoords(&xchildData);
} else if (objectType == kXClassMeshMaterialList) {
mesh->parseMaterials(&xchildData, _gameRef, numFaces, filename, materialReferences, indexCountPerFace);
} else if (objectType == kXClassMaterial) {
Material *mat = new Material(_gameRef);
mat->loadFromX(&xchildData, filename);
_materials.add(mat);
// one material = one index range
_numAttrs = 1;
mesh->_indexRanges.push_back(0);
mesh->_indexRanges.push_back(mesh->_indexData.size());
} else if (objectType == kXClassSkinMeshHeader) {
int boneCount = xchildData.getXSkinMeshHeaderObject()->_nBones;
_skinnedMesh = boneCount > 0;
} else if (objectType == kXClassSkinWeights) {
_skinnedMesh = true;
mesh->parseSkinWeights(&xchildData);
} else if (objectType == kXClassDeclData) {
mesh->parseVertexDeclaration(&xchildData);
}
}
}
}
mesh->generateAdjacency(_adjacency);
mesh->loadMesh(filename, xobj, materialReferences);
return true;
}

View File

@ -53,6 +53,54 @@ XSkinMeshLoader::~XSkinMeshLoader() {
delete[] _vertexNormalData;
}
void XSkinMeshLoader::loadMesh(const Common::String &filename, XFileData *xobj, Common::Array<MaterialReference> &materialReferences) {
parsePositionCoords(_meshObject);
uint numFaces = _meshObject->_numFaces;
Common::Array<int> indexCountPerFace;
parseFaces(_meshObject, numFaces, indexCountPerFace);
uint numChildren = 0;
xobj->getChildren(numChildren);
for (uint32 i = 0; i < numChildren; i++) {
XFileData xchildData;
XClassType objectType;
if (xobj->getChild(i, xchildData)) {
if (xchildData.getType(objectType)) {
if (objectType == kXClassMeshTextureCoords) {
parseTextureCoords(&xchildData);
} else if (objectType == kXClassMeshNormals) {
parseNormalCoords(&xchildData);
} else if (objectType == kXClassMeshMaterialList) {
parseMaterials(&xchildData, _mesh->_gameRef, numFaces, filename, materialReferences, indexCountPerFace);
} else if (objectType == kXClassMaterial) {
Material *mat = new Material(_mesh->_gameRef);
mat->loadFromX(&xchildData, filename);
_mesh->_materials.add(mat);
// one material = one index range
_mesh->_numAttrs = 1;
_indexRanges.push_back(0);
_indexRanges.push_back(_indexData.size());
} else if (objectType == kXClassSkinMeshHeader) {
int boneCount = xchildData.getXSkinMeshHeaderObject()->_nBones;
_mesh->_skinnedMesh = boneCount > 0;
} else if (objectType == kXClassSkinWeights) {
_mesh->_skinnedMesh = true;
parseSkinWeights(&xchildData);
} else if (objectType == kXClassDeclData) {
parseVertexDeclaration(&xchildData);
}
}
}
}
generateAdjacency(_mesh->_adjacency);
}
bool XSkinMeshLoader::parsePositionCoords(XMeshObject *mesh) {
for (uint i = 0; i < _vertexCount; ++i) {
_vertexPositionData[i * 3 + 0] = mesh->_vertices[i]._x;

View File

@ -53,7 +53,8 @@ class XSkinMeshLoader {
public:
XSkinMeshLoader(XMesh *mesh, XMeshObject *meshObject);
virtual ~XSkinMeshLoader();
void loadMesh(const Common::String &filename, XFileData *xobj, Common::Array<MaterialReference> &materialReferences);
protected:
static const int kVertexComponentCount = 8;
static const int kPositionOffset = 5;