Merge branch 'master' into uvwsrc_read
commit
54a86e6283
|
@ -51,6 +51,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "FBXUtil.h"
|
||||
#include <assimp/defs.h>
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
#include <assimp/Exceptional.h>
|
||||
#include <assimp/ByteSwapper.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
|
|
|
@ -577,16 +577,17 @@ void FBXConverter::GetRotationMatrix(Model::RotOrder mode, const aiVector3D &rot
|
|||
bool is_id[3] = { true, true, true };
|
||||
|
||||
aiMatrix4x4 temp[3];
|
||||
if (std::fabs(rotation.z) > angle_epsilon) {
|
||||
aiMatrix4x4::RotationZ(AI_DEG_TO_RAD(rotation.z), temp[2]);
|
||||
const auto rot = AI_DEG_TO_RAD(rotation);
|
||||
if (std::fabs(rot.z) > angle_epsilon) {
|
||||
aiMatrix4x4::RotationZ(rot.z, temp[2]);
|
||||
is_id[2] = false;
|
||||
}
|
||||
if (std::fabs(rotation.y) > angle_epsilon) {
|
||||
aiMatrix4x4::RotationY(AI_DEG_TO_RAD(rotation.y), temp[1]);
|
||||
if (std::fabs(rot.y) > angle_epsilon) {
|
||||
aiMatrix4x4::RotationY(rot.y, temp[1]);
|
||||
is_id[1] = false;
|
||||
}
|
||||
if (std::fabs(rotation.x) > angle_epsilon) {
|
||||
aiMatrix4x4::RotationX(AI_DEG_TO_RAD(rotation.x), temp[0]);
|
||||
if (std::fabs(rot.x) > angle_epsilon) {
|
||||
aiMatrix4x4::RotationX(rot.x, temp[0]);
|
||||
is_id[0] = false;
|
||||
}
|
||||
|
||||
|
@ -3225,7 +3226,6 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name,
|
|||
aiVector3D defTranslate = PropertyGet(props, "Lcl Translation", aiVector3D(0.f, 0.f, 0.f));
|
||||
aiVector3D defRotation = PropertyGet(props, "Lcl Rotation", aiVector3D(0.f, 0.f, 0.f));
|
||||
aiVector3D defScale = PropertyGet(props, "Lcl Scaling", aiVector3D(1.f, 1.f, 1.f));
|
||||
aiQuaternion defQuat = EulerToQuaternion(defRotation, rotOrder);
|
||||
|
||||
aiVectorKey* outTranslations = new aiVectorKey[keyCount];
|
||||
aiQuatKey* outRotations = new aiQuatKey[keyCount];
|
||||
|
@ -3241,8 +3241,9 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name,
|
|||
}
|
||||
|
||||
if (keyframeLists[TransformationComp_Rotation].size() > 0) {
|
||||
InterpolateKeys(outRotations, keytimes, keyframeLists[TransformationComp_Rotation], defRotation, maxTime, minTime, rotOrder);
|
||||
InterpolateKeys(outRotations, keytimes, keyframeLists[TransformationComp_Rotation], AI_DEG_TO_RAD(defRotation), maxTime, minTime, rotOrder);
|
||||
} else {
|
||||
aiQuaternion defQuat = EulerToQuaternion(AI_DEG_TO_RAD(defRotation), rotOrder);
|
||||
for (size_t i = 0; i < keyCount; ++i) {
|
||||
outRotations[i].mTime = CONVERT_FBX_TIME(keytimes[i]) * anim_fps;
|
||||
outRotations[i].mValue = defQuat;
|
||||
|
@ -3264,7 +3265,7 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name,
|
|||
|
||||
const aiVector3D& preRotation = PropertyGet<aiVector3D>(props, "PreRotation", ok);
|
||||
if (ok && preRotation.SquareLength() > zero_epsilon) {
|
||||
const aiQuaternion preQuat = EulerToQuaternion(preRotation, Model::RotOrder_EulerXYZ);
|
||||
const aiQuaternion preQuat = EulerToQuaternion(AI_DEG_TO_RAD(preRotation), Model::RotOrder_EulerXYZ);
|
||||
for (size_t i = 0; i < keyCount; ++i) {
|
||||
outRotations[i].mValue = preQuat * outRotations[i].mValue;
|
||||
}
|
||||
|
@ -3272,7 +3273,7 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name,
|
|||
|
||||
const aiVector3D& postRotation = PropertyGet<aiVector3D>(props, "PostRotation", ok);
|
||||
if (ok && postRotation.SquareLength() > zero_epsilon) {
|
||||
const aiQuaternion postQuat = EulerToQuaternion(postRotation, Model::RotOrder_EulerXYZ);
|
||||
const aiQuaternion postQuat = EulerToQuaternion(AI_DEG_TO_RAD(postRotation), Model::RotOrder_EulerXYZ);
|
||||
for (size_t i = 0; i < keyCount; ++i) {
|
||||
outRotations[i].mValue = outRotations[i].mValue * postQuat;
|
||||
}
|
||||
|
|
|
@ -74,8 +74,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
// https://code.blender.org/2013/08/fbx-binary-file-format-specification/
|
||||
// https://wiki.blender.org/index.php/User:Mont29/Foundation/FBX_File_Structure
|
||||
|
||||
const ai_real DEG = ai_real( 57.29577951308232087679815481 ); // degrees per radian
|
||||
|
||||
using namespace Assimp;
|
||||
using namespace Assimp::FBX;
|
||||
|
||||
|
@ -2434,7 +2432,7 @@ void FBXExporter::WriteObjects ()
|
|||
aiMatrix4x4 m(k.mValue.GetMatrix());
|
||||
aiVector3D qs, qr, qt;
|
||||
m.Decompose(qs, qr, qt);
|
||||
qr *= DEG;
|
||||
qr = AI_RAD_TO_DEG(qr);
|
||||
xval.push_back(qr.x);
|
||||
yval.push_back(qr.y);
|
||||
zval.push_back(qr.z);
|
||||
|
@ -2515,9 +2513,10 @@ void FBXExporter::WriteModelNode(
|
|||
);
|
||||
}
|
||||
if (r != zero) {
|
||||
r = AI_RAD_TO_DEG(r);
|
||||
p.AddP70(
|
||||
"Lcl Rotation", "Lcl Rotation", "", "A",
|
||||
double(DEG*r.x), double(DEG*r.y), double(DEG*r.z)
|
||||
double(r.x), double(r.y), double(r.z)
|
||||
);
|
||||
}
|
||||
if (s != one) {
|
||||
|
@ -2601,8 +2600,7 @@ void FBXExporter::WriteModelNodes(
|
|||
transform_chain.emplace_back(elem->first, t);
|
||||
break;
|
||||
case 'r': // rotation
|
||||
r *= float(DEG);
|
||||
transform_chain.emplace_back(elem->first, r);
|
||||
transform_chain.emplace_back(elem->first, AI_RAD_TO_DEG(r));
|
||||
break;
|
||||
case 's': // scale
|
||||
transform_chain.emplace_back(elem->first, s);
|
||||
|
|
|
@ -185,7 +185,7 @@ void IFCImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
|
|||
size_t total = 0;
|
||||
int read = 0;
|
||||
do {
|
||||
int bufferSize = fileInfo.uncompressed_size < INT16_MAX ? fileInfo.uncompressed_size : INT16_MAX;
|
||||
unsigned bufferSize = fileInfo.uncompressed_size < INT16_MAX ? static_cast<unsigned>(fileInfo.uncompressed_size) : INT16_MAX;
|
||||
void *buffer = malloc(bufferSize);
|
||||
read = unzReadCurrentFile(zip, buffer, bufferSize);
|
||||
if (read > 0) {
|
||||
|
|
|
@ -1372,7 +1372,7 @@ std::vector<IfcVector2> GetContourInPlane2D(const std::shared_ptr<TempMesh>& mes
|
|||
const std::vector<IfcVector3>& va = mesh->mVerts;
|
||||
if(va.size() <= 2) {
|
||||
std::stringstream msg;
|
||||
msg << "Skipping: Only " << va.size() << " verticies in opening mesh.";
|
||||
msg << "Skipping: Only " << va.size() << " vertices in opening mesh.";
|
||||
IFCImporter::LogDebug(msg.str().c_str());
|
||||
ok = false;
|
||||
return contour;
|
||||
|
|
|
@ -575,8 +575,8 @@ void SetupMapping(aiMaterial *mat, aiTextureMapping mode, const aiVector3D &axis
|
|||
m->mSemantic = prop->mSemantic;
|
||||
m->mType = aiPTI_Float;
|
||||
|
||||
m->mDataLength = 12;
|
||||
m->mData = new char[12];
|
||||
m->mDataLength = sizeof(aiVector3D);
|
||||
m->mData = new char[m->mDataLength];
|
||||
*((aiVector3D *)m->mData) = axis;
|
||||
p.push_back(m);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
|
|
@ -923,7 +923,7 @@ IF(ASSIMP_HUNTER_ENABLED)
|
|||
hunter_add_package(utf8)
|
||||
find_package(utf8cpp CONFIG REQUIRED)
|
||||
ELSE()
|
||||
# utf8 is header-only, so Assimp doesn't need to do anything.
|
||||
INCLUDE_DIRECTORIES("../contrib/utf8cpp/source")
|
||||
ENDIF()
|
||||
|
||||
# polyclipping
|
||||
|
@ -1380,7 +1380,12 @@ ENDIF()
|
|||
IF(NOT ASSIMP_HUNTER_ENABLED)
|
||||
if (UNZIP_FOUND)
|
||||
INCLUDE_DIRECTORIES(${UNZIP_INCLUDE_DIRS})
|
||||
# TODO if cmake required version has been updated to >3.12.0, collapse this to the second case only
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
|
||||
TARGET_LINK_LIBRARIES(assimp ${UNZIP_LIBRARIES})
|
||||
else()
|
||||
TARGET_LINK_LIBRARIES(assimp ${UNZIP_LINK_LIBRARIES})
|
||||
endif()
|
||||
else ()
|
||||
INCLUDE_DIRECTORIES("../")
|
||||
endif ()
|
||||
|
|
|
@ -290,12 +290,6 @@ void PretransformVertices::ComputeAbsoluteTransform(aiNode *pcNode) {
|
|||
}
|
||||
}
|
||||
|
||||
static void normalizeVectorArray(aiVector3D *vectorArrayIn, aiVector3D *vectorArrayOut, size_t numVectors) {
|
||||
for (size_t i=0; i<numVectors; ++i) {
|
||||
vectorArrayOut[i] = vectorArrayIn[i].Normalize();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Apply the node transformation to a mesh
|
||||
void PretransformVertices::ApplyTransform(aiMesh *mesh, const aiMatrix4x4 &mat) const {
|
||||
|
@ -322,8 +316,11 @@ void PretransformVertices::ApplyTransform(aiMesh *mesh, const aiMatrix4x4 &mat)
|
|||
const aiMatrix3x3 m = aiMatrix3x3(mat).Inverse().Transpose();
|
||||
|
||||
if (mesh->HasNormals()) {
|
||||
normalizeVectorArray(mesh->mNormals, mesh->mNormals, mesh->mNumVertices);
|
||||
for (unsigned int i = 0; i < mesh->mNumVertices; ++i) {
|
||||
mesh->mNormals[i] = (m * mesh->mNormals[i]).Normalize();
|
||||
}
|
||||
}
|
||||
|
||||
if (mesh->HasTangentsAndBitangents()) {
|
||||
for (unsigned int i = 0; i < mesh->mNumVertices; ++i) {
|
||||
mesh->mTangents[i] = (m * mesh->mTangents[i]).Normalize();
|
||||
|
|
|
@ -59,6 +59,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <assimp/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <unordered_set>
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
@ -872,11 +874,15 @@ struct aiMesh {
|
|||
|
||||
// DO NOT REMOVE THIS ADDITIONAL CHECK
|
||||
if (mNumBones && mBones) {
|
||||
std::unordered_set<const aiBone *> bones;
|
||||
for (unsigned int a = 0; a < mNumBones; a++) {
|
||||
if (mBones[a]) {
|
||||
delete mBones[a];
|
||||
bones.insert(mBones[a]);
|
||||
}
|
||||
}
|
||||
for (const aiBone *bone: bones) {
|
||||
delete bone;
|
||||
}
|
||||
delete[] mBones;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ INCLUDE_DIRECTORIES(
|
|||
${Assimp_SOURCE_DIR}/include
|
||||
${Assimp_SOURCE_DIR}/code
|
||||
${SAMPLES_SHARED_CODE_DIR}
|
||||
${Assimp_SOURCE_DIR}/contrib/utf8cpp/source
|
||||
)
|
||||
|
||||
LINK_DIRECTORIES(
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <dxgi1_2.h>
|
||||
#include <DirectXMath.h>
|
||||
#include <d3dcompiler.h>
|
||||
#include <utf8.h>
|
||||
|
||||
#include "ModelLoader.h"
|
||||
#include "SafeRelease.hpp"
|
||||
|
|
|
@ -21,6 +21,7 @@ INCLUDE_DIRECTORIES(
|
|||
${OPENGL_INCLUDE_DIR}
|
||||
${GLUT_INCLUDE_DIR}
|
||||
${SAMPLES_SHARED_CODE_DIR}
|
||||
${Assimp_SOURCE_DIR}/contrib/utf8cpp/source
|
||||
)
|
||||
|
||||
LINK_DIRECTORIES(
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <stdio.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <utf8.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable: 4100) // Disable warning 'unreferenced formal parameter'
|
||||
|
|
|
@ -48,6 +48,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
class BlendImportAreaLight : public ::testing::Test {
|
||||
public:
|
||||
BlendImportAreaLight() :
|
||||
im(nullptr) {}
|
||||
~BlendImportAreaLight() override = default;
|
||||
void SetUp() override {
|
||||
im = new Assimp::Importer();
|
||||
}
|
||||
|
|
|
@ -48,11 +48,14 @@ using namespace ::Assimp;
|
|||
|
||||
class BlenderWorkTest : public ::testing::Test {
|
||||
public:
|
||||
virtual void SetUp() {
|
||||
BlenderWorkTest() : im(nullptr) {}
|
||||
~BlenderWorkTest() override = default;
|
||||
|
||||
void SetUp() override {
|
||||
im = new Assimp::Importer();
|
||||
}
|
||||
|
||||
virtual void TearDown() {
|
||||
void TearDown() override {
|
||||
delete im;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue