Merge branch 'master' into gltf2_fixes

pull/3541/head
Kim Kulling 2020-12-24 16:48:36 +01:00 committed by GitHub
commit 3f5238d7c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 105 additions and 41 deletions

View File

@ -34,6 +34,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#----------------------------------------------------------------------
SET(CMAKE_POLICY_DEFAULT_CMP0012 NEW)
SET(CMAKE_POLICY_DEFAULT_CMP0074 NEW)
SET(CMAKE_POLICY_DEFAULT_CMP0092 NEW)

View File

@ -53,7 +53,7 @@ const MetaKeyPairVector MakeColladaAssimpMetaKeys() {
result.emplace_back("authoring_tool", AI_METADATA_SOURCE_GENERATOR);
result.emplace_back("copyright", AI_METADATA_SOURCE_COPYRIGHT);
return result;
};
}
const MetaKeyPairVector &GetColladaAssimpMetaKeys() {
static const MetaKeyPairVector result = MakeColladaAssimpMetaKeys();
@ -66,7 +66,7 @@ const MetaKeyPairVector MakeColladaAssimpMetaKeysCamelCase() {
ToCamelCase(val.first);
}
return result;
};
}
const MetaKeyPairVector &GetColladaAssimpMetaKeysCamelCase() {
static const MetaKeyPairVector result = MakeColladaAssimpMetaKeysCamelCase();

View File

@ -79,7 +79,7 @@ using namespace Util;
#define MAGIC_NODE_TAG "_$AssimpFbx$"
#define CONVERT_FBX_TIME(time) static_cast<double>(time) / 46186158000LL
#define CONVERT_FBX_TIME(time) (static_cast<double>(time) * 1000.0 / 46186158000LL)
FBXConverter::FBXConverter(aiScene *out, const Document &doc, bool removeEmptyBones) :
defaultMaterialIndex(),
@ -2560,7 +2560,7 @@ void FBXConverter::ConvertAnimationStack(const AnimationStack &st) {
meshMorphAnim->mKeys[j].mNumValuesAndWeights = numValuesAndWeights;
meshMorphAnim->mKeys[j].mValues = new unsigned int[numValuesAndWeights];
meshMorphAnim->mKeys[j].mWeights = new double[numValuesAndWeights];
meshMorphAnim->mKeys[j].mTime = CONVERT_FBX_TIME(animIt.first) * anim_fps;
meshMorphAnim->mKeys[j].mTime = CONVERT_FBX_TIME(animIt.first);
for (unsigned int k = 0; k < numValuesAndWeights; k++) {
meshMorphAnim->mKeys[j].mValues[k] = keyData->values.at(k);
meshMorphAnim->mKeys[j].mWeights[k] = keyData->weights.at(k);
@ -2578,8 +2578,8 @@ void FBXConverter::ConvertAnimationStack(const AnimationStack &st) {
return;
}
double start_time_fps = has_local_startstop ? (CONVERT_FBX_TIME(start_time) * anim_fps) : min_time;
double stop_time_fps = has_local_startstop ? (CONVERT_FBX_TIME(stop_time) * anim_fps) : max_time;
double start_time_fps = has_local_startstop ? CONVERT_FBX_TIME(start_time) : min_time;
double stop_time_fps = has_local_startstop ? CONVERT_FBX_TIME(stop_time) : max_time;
// adjust relative timing for animation
for (unsigned int c = 0; c < anim->mNumChannels; c++) {
@ -3099,7 +3099,7 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name,
InterpolateKeys(outTranslations, keytimes, keyframeLists[TransformationComp_Translation], defTranslate, maxTime, minTime);
} else {
for (size_t i = 0; i < keyCount; ++i) {
outTranslations[i].mTime = CONVERT_FBX_TIME(keytimes[i]) * anim_fps;
outTranslations[i].mTime = CONVERT_FBX_TIME(keytimes[i]);
outTranslations[i].mValue = defTranslate;
}
}
@ -3108,7 +3108,7 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name,
InterpolateKeys(outRotations, keytimes, keyframeLists[TransformationComp_Rotation], defRotation, maxTime, minTime, rotOrder);
} else {
for (size_t i = 0; i < keyCount; ++i) {
outRotations[i].mTime = CONVERT_FBX_TIME(keytimes[i]) * anim_fps;
outRotations[i].mTime = CONVERT_FBX_TIME(keytimes[i]);
outRotations[i].mValue = defQuat;
}
}
@ -3117,7 +3117,7 @@ aiNodeAnim* FBXConverter::GenerateSimpleNodeAnim(const std::string& name,
InterpolateKeys(outScales, keytimes, keyframeLists[TransformationComp_Scaling], defScale, maxTime, minTime);
} else {
for (size_t i = 0; i < keyCount; ++i) {
outScales[i].mTime = CONVERT_FBX_TIME(keytimes[i]) * anim_fps;
outScales[i].mTime = CONVERT_FBX_TIME(keytimes[i]);
outScales[i].mValue = defScale;
}
}
@ -3306,7 +3306,7 @@ void FBXConverter::InterpolateKeys(aiVectorKey *valOut, const KeyTimeList &keys,
}
// magic value to convert fbx times to seconds
valOut->mTime = CONVERT_FBX_TIME(time) * anim_fps;
valOut->mTime = CONVERT_FBX_TIME(time);
min_time = std::min(min_time, valOut->mTime);
max_time = std::max(max_time, valOut->mTime);

View File

@ -1258,9 +1258,6 @@ inline Ref<Accessor> GetSamplerInputRef(Asset& asset, std::string& animId, Ref<B
inline void ExtractTranslationSampler(Asset& asset, std::string& animId, Ref<Buffer>& buffer, const aiNodeAnim* nodeChannel, float ticksPerSecond, Animation::Sampler& sampler)
{
const unsigned int numKeyframes = nodeChannel->mNumPositionKeys;
if (numKeyframes == 0) {
return;
}
std::vector<float> times(numKeyframes);
std::vector<float> values(numKeyframes * 3);
@ -1281,9 +1278,6 @@ inline void ExtractTranslationSampler(Asset& asset, std::string& animId, Ref<Buf
inline void ExtractScaleSampler(Asset& asset, std::string& animId, Ref<Buffer>& buffer, const aiNodeAnim* nodeChannel, float ticksPerSecond, Animation::Sampler& sampler)
{
const unsigned int numKeyframes = nodeChannel->mNumScalingKeys;
if (numKeyframes == 0) {
return;
}
std::vector<float> times(numKeyframes);
std::vector<float> values(numKeyframes * 3);
@ -1304,9 +1298,6 @@ inline void ExtractScaleSampler(Asset& asset, std::string& animId, Ref<Buffer>&
inline void ExtractRotationSampler(Asset& asset, std::string& animId, Ref<Buffer>& buffer, const aiNodeAnim* nodeChannel, float ticksPerSecond, Animation::Sampler& sampler)
{
const unsigned int numKeyframes = nodeChannel->mNumRotationKeys;
if (numKeyframes == 0) {
return;
}
std::vector<float> times(numKeyframes);
std::vector<float> values(numKeyframes * 4);
@ -1347,29 +1338,36 @@ void glTF2Exporter::ExportAnimations()
if (anim->mName.length > 0) {
nameAnim = anim->mName.C_Str();
}
Ref<Animation> animRef = mAsset->animations.Create(nameAnim);
for (unsigned int channelIndex = 0; channelIndex < anim->mNumChannels; ++channelIndex) {
const aiNodeAnim* nodeChannel = anim->mChannels[channelIndex];
// It appears that assimp stores this type of animation as multiple animations.
// where each aiNodeAnim in mChannels animates a specific node.
std::string name = nameAnim + "_" + to_string(channelIndex);
name = mAsset->FindUniqueID(name, "animation");
Ref<Animation> animRef = mAsset->animations.Create(name);
Ref<Node> animNode = mAsset->nodes.Get(nodeChannel->mNodeName.C_Str());
Animation::Sampler translationSampler;
ExtractTranslationSampler(*mAsset, name, bufferRef, nodeChannel, ticksPerSecond, translationSampler);
AddSampler(animRef, animNode, translationSampler, AnimationPath_TRANSLATION);
if (nodeChannel->mNumPositionKeys > 0)
{
Animation::Sampler translationSampler;
ExtractTranslationSampler(*mAsset, name, bufferRef, nodeChannel, ticksPerSecond, translationSampler);
AddSampler(animRef, animNode, translationSampler, AnimationPath_TRANSLATION);
}
Animation::Sampler rotationSampler;
ExtractRotationSampler(*mAsset, name, bufferRef, nodeChannel, ticksPerSecond, rotationSampler);
AddSampler(animRef, animNode, rotationSampler, AnimationPath_ROTATION);
if (nodeChannel->mNumRotationKeys > 0)
{
Animation::Sampler rotationSampler;
ExtractRotationSampler(*mAsset, name, bufferRef, nodeChannel, ticksPerSecond, rotationSampler);
AddSampler(animRef, animNode, rotationSampler, AnimationPath_ROTATION);
}
Animation::Sampler scaleSampler;
ExtractScaleSampler(*mAsset, name, bufferRef, nodeChannel, ticksPerSecond, scaleSampler);
AddSampler(animRef, animNode, scaleSampler, AnimationPath_SCALE);
if (nodeChannel->mNumScalingKeys > 0)
{
Animation::Sampler scaleSampler;
ExtractScaleSampler(*mAsset, name, bufferRef, nodeChannel, ticksPerSecond, scaleSampler);
AddSampler(animRef, animNode, scaleSampler, AnimationPath_SCALE);
}
}
// Assimp documentation staes this is not used (not implemented)

View File

@ -1015,7 +1015,7 @@ ENDIF()
# RT-extensions is used in "contrib/Open3DGC/o3dgcTimer.h" for collecting statistics. Pointed file
# has implementation for different platforms: WIN32, __MACH__ and other ("else" block).
FIND_PACKAGE(RT QUIET)
IF (NOT ASSIMP_HUNTER_ENABLED AND (RT_FOUND OR MSVC))
IF (NOT ASSIMP_HUNTER_ENABLED AND (RT_FOUND OR WIN32))
SET( ASSIMP_IMPORTER_GLTF_USE_OPEN3DGC 1 )
ADD_DEFINITIONS( -DASSIMP_IMPORTER_GLTF_USE_OPEN3DGC=1 )
ELSE ()

View File

@ -183,9 +183,10 @@ void SceneCombiner::MergeScenes(aiScene **_dest, std::vector<aiScene *> &src, un
*_dest = src[0];
return;
}
if (*_dest)
if (*_dest) {
(*_dest)->~aiScene();
else
new (*_dest) aiScene();
} else
*_dest = new aiScene();
// Create a dummy scene to serve as master for the others

View File

@ -146,7 +146,7 @@ int IOSystem2Unzip::testerror(voidpf /*opaque*/, voidpf /*stream*/) {
zlib_filefunc_def IOSystem2Unzip::get(IOSystem *pIOHandler) {
zlib_filefunc_def mapping;
#ifdef ASSIMP_USE_HUNTER
#if defined (ASSIMP_USE_HUNTER) || defined (__MINGW32__) // GH#3144
mapping.zopen_file = (open_file_func)open;
mapping.zread_file = (read_file_func)read;
mapping.zwrite_file = (write_file_func)write;
@ -335,7 +335,7 @@ ZipArchiveIOSystem::Implement::Implement(IOSystem *pIOHandler, const char *pFile
if (pFilename[0] == 0 || nullptr == pMode) {
return;
}
zlib_filefunc_def mapping = IOSystem2Unzip::get(pIOHandler);
m_ZipFileHandle = unzOpen2(pFilename, &mapping);
}

View File

@ -243,6 +243,45 @@ void SortByPTypeProcess::Execute(aiScene *pScene) {
}
}
if (mesh->mNumAnimMeshes > 0 && mesh->mAnimMeshes) {
out->mNumAnimMeshes = mesh->mNumAnimMeshes;
out->mAnimMeshes = new aiAnimMesh *[out->mNumAnimMeshes];
}
for (unsigned int j = 0; j < mesh->mNumAnimMeshes; ++j) {
aiAnimMesh *animMesh = mesh->mAnimMeshes[j];
aiAnimMesh *outAnimMesh = out->mAnimMeshes[j] = new aiAnimMesh;
outAnimMesh->mNumVertices = out->mNumVertices;
if (animMesh->mVertices)
outAnimMesh->mVertices = new aiVector3D[out->mNumVertices];
else
outAnimMesh->mVertices = nullptr;
if (animMesh->mNormals)
outAnimMesh->mNormals = new aiVector3D[out->mNumVertices];
else
outAnimMesh->mNormals = nullptr;
if (animMesh->mTangents)
outAnimMesh->mTangents = new aiVector3D[out->mNumVertices];
else
outAnimMesh->mTangents = nullptr;
if (animMesh->mBitangents)
outAnimMesh->mBitangents = new aiVector3D[out->mNumVertices];
else
outAnimMesh->mBitangents = nullptr;
for (int jj = 0; jj < AI_MAX_NUMBER_OF_COLOR_SETS; ++jj) {
if (animMesh->mColors[jj])
outAnimMesh->mColors[jj] = new aiColor4D[out->mNumVertices];
else
outAnimMesh->mColors[jj] = nullptr;
}
for (int jj = 0; jj < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++jj) {
if (animMesh->mTextureCoords[jj])
outAnimMesh->mTextureCoords[jj] = new aiVector3D[out->mNumVertices];
else
outAnimMesh->mTextureCoords[jj] = nullptr;
}
}
typedef std::vector<aiVertexWeight> TempBoneInfo;
std::vector<TempBoneInfo> tempBones(mesh->mNumBones);
@ -252,6 +291,7 @@ void SortByPTypeProcess::Execute(aiScene *pScene) {
}
unsigned int outIdx = 0;
unsigned int amIdx = 0; // AnimMesh index
for (unsigned int m = 0; m < mesh->mNumFaces; ++m) {
aiFace &in = mesh->mFaces[m];
if ((real == 3 && in.mNumIndices <= 3) || (real != 3 && in.mNumIndices != real + 1)) {
@ -293,6 +333,30 @@ void SortByPTypeProcess::Execute(aiScene *pScene) {
*cols[pp]++ = mesh->mColors[pp][idx];
}
unsigned int pp = 0;
for (; pp < mesh->mNumAnimMeshes; ++pp) {
aiAnimMesh *animMesh = mesh->mAnimMeshes[pp];
aiAnimMesh *outAnimMesh = out->mAnimMeshes[pp];
if (animMesh->mVertices)
outAnimMesh->mVertices[amIdx] = animMesh->mVertices[idx];
if (animMesh->mNormals)
outAnimMesh->mNormals[amIdx] = animMesh->mNormals[idx];
if (animMesh->mTangents)
outAnimMesh->mTangents[amIdx] = animMesh->mTangents[idx];
if (animMesh->mBitangents)
outAnimMesh->mBitangents[amIdx] = animMesh->mBitangents[idx];
for (int jj = 0; jj < AI_MAX_NUMBER_OF_COLOR_SETS; ++jj) {
if (animMesh->mColors[jj])
outAnimMesh->mColors[jj][amIdx] = animMesh->mColors[jj][idx];
}
for (int jj = 0; jj < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++jj) {
if (animMesh->mTextureCoords[jj])
outAnimMesh->mTextureCoords[jj][amIdx] = animMesh->mTextureCoords[jj][idx];
}
}
if (pp == mesh->mNumAnimMeshes)
amIdx++;
in.mIndices[q] = outIdx++;
}

View File

@ -175,7 +175,7 @@ namespace o3dgc
m_data[2] = rhs.m_data[2];
}
template <typename T>
inline Vec3<T>::~Vec3(void){};
inline Vec3<T>::~Vec3(void){}
template <typename T>
inline Vec3<T>::Vec3() {}
@ -308,7 +308,7 @@ namespace o3dgc
m_data[1] = rhs.m_data[1];
}
template <typename T>
inline Vec2<T>::~Vec2(void){};
inline Vec2<T>::~Vec2(void){}
template <typename T>
inline Vec2<T>::Vec2() {}

View File

@ -763,7 +763,7 @@ void cleanup()
if (g_hWnd)
KillGLWindow();
};
}
LRESULT CALLBACK WndProc(HWND hWnd, // Handles for this Window
UINT uMsg, // Message for this Window

View File

@ -161,4 +161,4 @@ int CMeshRenderer::DrawSorted(unsigned int iIndex,const aiMatrix4x4& mWorld) {
return 1;
}
};
}

View File

@ -2143,7 +2143,7 @@ INT_PTR CALLBACK AboutMessageProc(HWND hwndDlg,UINT uMsg,
}
return FALSE;
}
};
}
using namespace AssimpView;