mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-02 08:55:45 +00:00
WME3D: Move portions code to mesh loader
This commit is contained in:
parent
ac506478d9
commit
b5daa5fb8c
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user