Fix add checks for indices
parent
a7cfa3264a
commit
f844c3397d
|
@ -57,7 +57,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace Assimp;
|
namespace Assimp {
|
||||||
|
|
||||||
using namespace Assimp::Formatter;
|
using namespace Assimp::Formatter;
|
||||||
|
|
||||||
static const aiImporterDesc desc = {
|
static const aiImporterDesc desc = {
|
||||||
|
@ -73,10 +74,6 @@ static const aiImporterDesc desc = {
|
||||||
"x"
|
"x"
|
||||||
};
|
};
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
// Constructor to be privately used by Importer
|
|
||||||
XFileImporter::XFileImporter() = default;
|
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Returns whether the class can handle the format of the given file.
|
// Returns whether the class can handle the format of the given file.
|
||||||
bool XFileImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const {
|
bool XFileImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const {
|
||||||
|
@ -124,8 +121,7 @@ void XFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene, I
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Constructs the return data structure out of the imported data.
|
// Constructs the return data structure out of the imported data.
|
||||||
void XFileImporter::CreateDataRepresentationFromImport( aiScene* pScene, XFile::Scene* pData)
|
void XFileImporter::CreateDataRepresentationFromImport(aiScene *pScene, XFile::Scene *pData) {
|
||||||
{
|
|
||||||
// Read the global materials first so that meshes referring to them can find them later
|
// Read the global materials first so that meshes referring to them can find them later
|
||||||
ConvertMaterials(pScene, pData->mGlobalMaterials);
|
ConvertMaterials(pScene, pData->mGlobalMaterials);
|
||||||
|
|
||||||
|
@ -315,8 +311,8 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec
|
||||||
// collect vertex data for indices of this face
|
// collect vertex data for indices of this face
|
||||||
for (unsigned int d = 0; d < df.mNumIndices; ++d) {
|
for (unsigned int d = 0; d < df.mNumIndices; ++d) {
|
||||||
df.mIndices[d] = newIndex;
|
df.mIndices[d] = newIndex;
|
||||||
const unsigned int newIdx( pf.mIndices[ d ] );
|
const unsigned int newIdx = pf.mIndices[d];
|
||||||
if ( newIdx > sourceMesh->mPositions.size() ) {
|
if (newIdx >= sourceMesh->mPositions.size()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,9 +324,11 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec
|
||||||
if (mesh->HasNormals()) {
|
if (mesh->HasNormals()) {
|
||||||
if (sourceMesh->mNormFaces[f].mIndices.size() > d) {
|
if (sourceMesh->mNormFaces[f].mIndices.size() > d) {
|
||||||
const size_t idx(sourceMesh->mNormFaces[f].mIndices[d]);
|
const size_t idx(sourceMesh->mNormFaces[f].mIndices[d]);
|
||||||
|
if (idx < sourceMesh->mNormals.size()) {
|
||||||
mesh->mNormals[newIndex] = sourceMesh->mNormals[idx];
|
mesh->mNormals[newIndex] = sourceMesh->mNormals[idx];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// texture coord sets
|
// texture coord sets
|
||||||
for (unsigned int e = 0; e < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++e) {
|
for (unsigned int e = 0; e < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++e) {
|
||||||
|
@ -361,8 +359,11 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec
|
||||||
// set up a vertex-linear array of the weights for quick searching if a bone influences a vertex
|
// set up a vertex-linear array of the weights for quick searching if a bone influences a vertex
|
||||||
std::vector<ai_real> oldWeights(sourceMesh->mPositions.size(), 0.0);
|
std::vector<ai_real> oldWeights(sourceMesh->mPositions.size(), 0.0);
|
||||||
for (unsigned int d = 0; d < obone.mWeights.size(); ++d) {
|
for (unsigned int d = 0; d < obone.mWeights.size(); ++d) {
|
||||||
|
const unsigned int boneIdx = obone.mWeights[d].mVertex;
|
||||||
|
if (boneIdx < obone.mWeights.size()) {
|
||||||
oldWeights[obone.mWeights[d].mVertex] = obone.mWeights[d].mWeight;
|
oldWeights[obone.mWeights[d].mVertex] = obone.mWeights[d].mWeight;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// collect all vertex weights that influence a vertex in the new mesh
|
// collect all vertex weights that influence a vertex in the new mesh
|
||||||
std::vector<aiVertexWeight> newWeights;
|
std::vector<aiVertexWeight> newWeights;
|
||||||
|
@ -451,8 +452,7 @@ void XFileImporter::CreateAnimations( aiScene* pScene, const XFile::Scene* pData
|
||||||
nanim->mChannels[b] = nbone;
|
nanim->mChannels[b] = nbone;
|
||||||
|
|
||||||
// key-frames are given as combined transformation matrix keys
|
// key-frames are given as combined transformation matrix keys
|
||||||
if( !bone->mTrafoKeys.empty() )
|
if (!bone->mTrafoKeys.empty()) {
|
||||||
{
|
|
||||||
nbone->mNumPositionKeys = (unsigned int)bone->mTrafoKeys.size();
|
nbone->mNumPositionKeys = (unsigned int)bone->mTrafoKeys.size();
|
||||||
nbone->mPositionKeys = new aiVectorKey[nbone->mNumPositionKeys];
|
nbone->mPositionKeys = new aiVectorKey[nbone->mNumPositionKeys];
|
||||||
nbone->mNumRotationKeys = (unsigned int)bone->mTrafoKeys.size();
|
nbone->mNumRotationKeys = (unsigned int)bone->mTrafoKeys.size();
|
||||||
|
@ -538,8 +538,7 @@ void XFileImporter::CreateAnimations( aiScene* pScene, const XFile::Scene* pData
|
||||||
}
|
}
|
||||||
|
|
||||||
// store all converted animations in the scene
|
// store all converted animations in the scene
|
||||||
if( newAnims.size() > 0)
|
if (newAnims.size() > 0) {
|
||||||
{
|
|
||||||
pScene->mNumAnimations = (unsigned int)newAnims.size();
|
pScene->mNumAnimations = (unsigned int)newAnims.size();
|
||||||
pScene->mAnimations = new aiAnimation *[pScene->mNumAnimations];
|
pScene->mAnimations = new aiAnimation *[pScene->mNumAnimations];
|
||||||
for (unsigned int a = 0; a < newAnims.size(); a++)
|
for (unsigned int a = 0; a < newAnims.size(); a++)
|
||||||
|
@ -549,8 +548,7 @@ void XFileImporter::CreateAnimations( aiScene* pScene, const XFile::Scene* pData
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Converts all materials in the given array and stores them in the scene's material list.
|
// Converts all materials in the given array and stores them in the scene's material list.
|
||||||
void XFileImporter::ConvertMaterials( aiScene* pScene, std::vector<XFile::Material>& pMaterials)
|
void XFileImporter::ConvertMaterials(aiScene *pScene, std::vector<XFile::Material> &pMaterials) {
|
||||||
{
|
|
||||||
// count the non-referrer materials in the array
|
// count the non-referrer materials in the array
|
||||||
unsigned int numNewMaterials(0);
|
unsigned int numNewMaterials(0);
|
||||||
for (unsigned int a = 0; a < pMaterials.size(); ++a) {
|
for (unsigned int a = 0; a < pMaterials.size(); ++a) {
|
||||||
|
@ -599,8 +597,7 @@ void XFileImporter::ConvertMaterials( aiScene* pScene, std::vector<XFile::Materi
|
||||||
// Shading model: hard-coded to PHONG, there is no such information in an XFile
|
// Shading model: hard-coded to PHONG, there is no such information in an XFile
|
||||||
// FIX (aramis): If the specular exponent is 0, use gouraud shading. This is a bugfix
|
// FIX (aramis): If the specular exponent is 0, use gouraud shading. This is a bugfix
|
||||||
// for some models in the SDK (e.g. good old tiny.x)
|
// for some models in the SDK (e.g. good old tiny.x)
|
||||||
int shadeMode = (int)oldMat.mSpecularExponent == 0.0f
|
int shadeMode = (int)oldMat.mSpecularExponent == 0.0f ? aiShadingMode_Gouraud : aiShadingMode_Phong;
|
||||||
? aiShadingMode_Gouraud : aiShadingMode_Phong;
|
|
||||||
|
|
||||||
mat->AddProperty<int>(&shadeMode, 1, AI_MATKEY_SHADING_MODEL);
|
mat->AddProperty<int>(&shadeMode, 1, AI_MATKEY_SHADING_MODEL);
|
||||||
// material colours
|
// material colours
|
||||||
|
@ -611,7 +608,6 @@ void XFileImporter::ConvertMaterials( aiScene* pScene, std::vector<XFile::Materi
|
||||||
mat->AddProperty(&oldMat.mSpecular, 1, AI_MATKEY_COLOR_SPECULAR);
|
mat->AddProperty(&oldMat.mSpecular, 1, AI_MATKEY_COLOR_SPECULAR);
|
||||||
mat->AddProperty(&oldMat.mSpecularExponent, 1, AI_MATKEY_SHININESS);
|
mat->AddProperty(&oldMat.mSpecularExponent, 1, AI_MATKEY_SHININESS);
|
||||||
|
|
||||||
|
|
||||||
// texture, if there is one
|
// texture, if there is one
|
||||||
if (1 == oldMat.mTextures.size()) {
|
if (1 == oldMat.mTextures.size()) {
|
||||||
const XFile::TexEntry &otex = oldMat.mTextures.back();
|
const XFile::TexEntry &otex = oldMat.mTextures.back();
|
||||||
|
@ -679,4 +675,6 @@ void XFileImporter::ConvertMaterials( aiScene* pScene, std::vector<XFile::Materi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Assimp
|
||||||
|
|
||||||
#endif // !! ASSIMP_BUILD_NO_X_IMPORTER
|
#endif // !! ASSIMP_BUILD_NO_X_IMPORTER
|
||||||
|
|
|
@ -68,7 +68,7 @@ namespace XFile {
|
||||||
*/
|
*/
|
||||||
class XFileImporter : public BaseImporter {
|
class XFileImporter : public BaseImporter {
|
||||||
public:
|
public:
|
||||||
XFileImporter();
|
XFileImporter() = default;
|
||||||
~XFileImporter() override = default;
|
~XFileImporter() override = default;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue