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 <memory>
|
||||
|
||||
using namespace Assimp;
|
||||
namespace Assimp {
|
||||
|
||||
using namespace Assimp::Formatter;
|
||||
|
||||
static const aiImporterDesc desc = {
|
||||
|
@ -73,10 +74,6 @@ static const aiImporterDesc desc = {
|
|||
"x"
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Constructor to be privately used by Importer
|
||||
XFileImporter::XFileImporter() = default;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Returns whether the class can handle the format of the given file.
|
||||
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.
|
||||
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
|
||||
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
|
||||
for (unsigned int d = 0; d < df.mNumIndices; ++d) {
|
||||
df.mIndices[d] = newIndex;
|
||||
const unsigned int newIdx( pf.mIndices[ d ] );
|
||||
if ( newIdx > sourceMesh->mPositions.size() ) {
|
||||
const unsigned int newIdx = pf.mIndices[d];
|
||||
if (newIdx >= sourceMesh->mPositions.size()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -328,9 +324,11 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec
|
|||
if (mesh->HasNormals()) {
|
||||
if (sourceMesh->mNormFaces[f].mIndices.size() > d) {
|
||||
const size_t idx(sourceMesh->mNormFaces[f].mIndices[d]);
|
||||
if (idx < sourceMesh->mNormals.size()) {
|
||||
mesh->mNormals[newIndex] = sourceMesh->mNormals[idx];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// texture coord sets
|
||||
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
|
||||
std::vector<ai_real> oldWeights(sourceMesh->mPositions.size(), 0.0);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// collect all vertex weights that influence a vertex in the new mesh
|
||||
std::vector<aiVertexWeight> newWeights;
|
||||
|
@ -451,8 +452,7 @@ void XFileImporter::CreateAnimations( aiScene* pScene, const XFile::Scene* pData
|
|||
nanim->mChannels[b] = nbone;
|
||||
|
||||
// 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->mPositionKeys = new aiVectorKey[nbone->mNumPositionKeys];
|
||||
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
|
||||
if( newAnims.size() > 0)
|
||||
{
|
||||
if (newAnims.size() > 0) {
|
||||
pScene->mNumAnimations = (unsigned int)newAnims.size();
|
||||
pScene->mAnimations = new aiAnimation *[pScene->mNumAnimations];
|
||||
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.
|
||||
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
|
||||
unsigned int numNewMaterials(0);
|
||||
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
|
||||
// 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)
|
||||
int shadeMode = (int)oldMat.mSpecularExponent == 0.0f
|
||||
? aiShadingMode_Gouraud : aiShadingMode_Phong;
|
||||
int shadeMode = (int)oldMat.mSpecularExponent == 0.0f ? aiShadingMode_Gouraud : aiShadingMode_Phong;
|
||||
|
||||
mat->AddProperty<int>(&shadeMode, 1, AI_MATKEY_SHADING_MODEL);
|
||||
// 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.mSpecularExponent, 1, AI_MATKEY_SHININESS);
|
||||
|
||||
|
||||
// texture, if there is one
|
||||
if (1 == oldMat.mTextures.size()) {
|
||||
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
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace XFile {
|
|||
*/
|
||||
class XFileImporter : public BaseImporter {
|
||||
public:
|
||||
XFileImporter();
|
||||
XFileImporter() = default;
|
||||
~XFileImporter() override = default;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue