Merge pull request #2656 from assimp/kimkullig_dev

Kimkullig dev
pull/2659/head
Kim Kulling 2019-09-18 16:40:31 +02:00 committed by GitHub
commit e3d277faea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 931 additions and 77 deletions

View File

@ -7,7 +7,8 @@
#
function generate() {
OPTIONS="-DASSIMP_WERROR=ON"
OPTIONS="$OPTIONS -DASSIMP_NO_EXPORT=NO"
if [ "$DISABLE_EXPORTERS" = "YES" ] ; then
OPTIONS="$OPTIONS -DASSIMP_NO_EXPORT=YES"
else

View File

@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "ColladaExporter.h"
#include <assimp/Bitmap.h>
#include <assimp/MathFunctions.h>
#include <assimp/fast_atof.h>
#include <assimp/SceneCombiner.h>
#include <assimp/StringUtils.h>
@ -155,7 +156,7 @@ void ColladaExporter::WriteFile() {
// ------------------------------------------------------------------------------------------------
// Writes the asset header
void ColladaExporter::WriteHeader() {
static const ai_real epsilon = ai_real( 0.00001 );
static const ai_real epsilon = Math::getEpsilon<ai_real>();
static const aiQuaternion x_rot(aiMatrix3x3(
0, -1, 0,
1, 0, 0,
@ -1671,4 +1672,4 @@ void ColladaExporter::WriteNode( const aiScene* pScene, aiNode* pNode)
}
#endif
#endif
#endif

View File

@ -55,6 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "FBXImporter.h"
#include <assimp/StringComparison.h>
#include <assimp/MathFunctions.h>
#include <assimp/scene.h>
@ -553,7 +554,7 @@ namespace Assimp {
return;
}
const float angle_epsilon = 1e-6f;
const float angle_epsilon = Math::getEpsilon<float>();
out = aiMatrix4x4();
@ -694,7 +695,7 @@ namespace Assimp {
std::fill_n(chain, static_cast<unsigned int>(TransformationComp_MAXIMUM), aiMatrix4x4());
// generate transformation matrices for all the different transformation components
const float zero_epsilon = 1e-6f;
const float zero_epsilon = Math::getEpsilon<float>();
const aiVector3D all_ones(1.0f, 1.0f, 1.0f);
const aiVector3D& PreRotation = PropertyGet<aiVector3D>(props, "PreRotation", ok);
@ -2967,7 +2968,7 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial* out_mat, const PropertyTa
TransformationCompDefaultValue(comp)
);
const float epsilon = 1e-6f;
const float epsilon = Math::getEpsilon<float>();
return (dyn_val - static_val).SquareLength() < epsilon;
}

View File

@ -500,7 +500,7 @@ bool Curve::InRange(IfcFloat u) const {
if (IsClosed()) {
return true;
}
const IfcFloat epsilon = 1e-5;
const IfcFloat epsilon = Math::getEpsilon<float>();
return u - range.first > -epsilon && range.second - u > -epsilon;
}
#endif

View File

@ -593,7 +593,7 @@ typedef std::vector<std::pair<
bool BoundingBoxesAdjacent(const BoundingBox& bb, const BoundingBox& ibb)
{
// TODO: I'm pretty sure there is a much more compact way to check this
const IfcFloat epsilon = 1e-5f;
const IfcFloat epsilon = Math::getEpsilon<float>();
return (std::fabs(bb.second.x - ibb.first.x) < epsilon && bb.first.y <= ibb.second.y && bb.second.y >= ibb.first.y) ||
(std::fabs(bb.first.x - ibb.second.x) < epsilon && ibb.first.y <= bb.second.y && ibb.second.y >= bb.first.y) ||
(std::fabs(bb.second.y - ibb.first.y) < epsilon && bb.first.x <= ibb.second.x && bb.second.x >= ibb.first.x) ||
@ -681,7 +681,7 @@ bool IntersectingLineSegments(const IfcVector2& n0, const IfcVector2& n1,
// ------------------------------------------------------------------------------------------------
void FindAdjacentContours(ContourVector::iterator current, const ContourVector& contours)
{
const IfcFloat sqlen_epsilon = static_cast<IfcFloat>(1e-8);
const IfcFloat sqlen_epsilon = static_cast<IfcFloat>(Math::getEpsilon<float>());
const BoundingBox& bb = (*current).bb;
// What is to be done here is to populate the skip lists for the contour
@ -758,7 +758,7 @@ void FindAdjacentContours(ContourVector::iterator current, const ContourVector&
// ------------------------------------------------------------------------------------------------
AI_FORCE_INLINE bool LikelyBorder(const IfcVector2& vdelta)
{
const IfcFloat dot_point_epsilon = static_cast<IfcFloat>(1e-5);
const IfcFloat dot_point_epsilon = static_cast<IfcFloat>(Math::getEpsilon<float>());
return std::fabs(vdelta.x * vdelta.y) < dot_point_epsilon;
}

View File

@ -53,6 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "MD5Loader.h"
#include <assimp/StringComparison.h>
#include <assimp/fast_atof.h>
#include <assimp/MathFunctions.h>
#include <assimp/SkeletonMeshBuilder.h>
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
@ -64,7 +65,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using namespace Assimp;
// Minimum weight value. Weights inside [-n ... n] are ignored
#define AI_MD5_WEIGHT_EPSILON 1e-5f
#define AI_MD5_WEIGHT_EPSILON Math::getEpsilon<float>()
static const aiImporterDesc desc = {

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2019, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
@ -94,23 +92,24 @@ static const aiImporterDesc desc = {
// ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer
MDLImporter::MDLImporter()
: configFrameID(),
mBuffer(),
iGSFileVersion(),
pIOHandler(),
pScene(),
iFileSize()
{}
: configFrameID()
, mBuffer()
, iGSFileVersion()
, pIOHandler()
, pScene()
, iFileSize() {
// empty
}
// ------------------------------------------------------------------------------------------------
// Destructor, private as well
MDLImporter::~MDLImporter()
{}
MDLImporter::~MDLImporter() {
// empty
}
// ------------------------------------------------------------------------------------------------
// Returns whether the class can handle the format of the given file.
bool MDLImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const
{
bool MDLImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const {
const std::string extension = GetExtension(pFile);
// if check for extension is not enough, check for the magic tokens
@ -404,23 +403,15 @@ void MDLImporter::InternReadFile_Quake1() {
// now get a pointer to the first frame in the file
BE_NCONST MDL::Frame* pcFrames = (BE_NCONST MDL::Frame*)szCurrent;
BE_NCONST MDL::SimpleFrame* pcFirstFrame;
MDL::SimpleFrame* pcFirstFrame;
if (0 == pcFrames->type) {
// get address of single frame
pcFirstFrame = &pcFrames->frame;
pcFirstFrame =( MDL::SimpleFrame*) &pcFrames->frame;
} else {
// get the first frame in the group
#if 1
// FIXME: the cast is wrong and cause a warning on clang 5.0
// disable this code for now, fix it later
ai_assert(false && "Bad pointer cast");
pcFirstFrame = nullptr; // Workaround: msvc++ C4703 error
#else
BE_NCONST MDL::GroupFrame* pcFrames2 = (BE_NCONST MDL::GroupFrame*)pcFrames;
pcFirstFrame = (BE_NCONST MDL::SimpleFrame*)(&pcFrames2->time + pcFrames->type);
#endif
BE_NCONST MDL::GroupFrame* pcFrames2 = (BE_NCONST MDL::GroupFrame*) pcFrames;
pcFirstFrame = &(pcFrames2->frames[0]);
}
BE_NCONST MDL::Vertex* pcVertices = (BE_NCONST MDL::Vertex*) ((pcFirstFrame->name) + sizeof(pcFirstFrame->name));
VALIDATE_FILE_SIZE((const unsigned char*)(pcVertices + pcHeader->num_verts));

View File

@ -89,16 +89,12 @@ public:
MDLImporter();
~MDLImporter();
public:
// -------------------------------------------------------------------
/** Returns whether the class can handle the format of the given file.
* See BaseImporter::CanRead() for details. */
bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
bool checkSig) const;
// -------------------------------------------------------------------
/** Called prior to ReadFile().
* The function is a request to the importer to update its configuration
@ -107,8 +103,6 @@ public:
void SetupProperties(const Importer* pImp);
protected:
// -------------------------------------------------------------------
/** Return importer meta information.
* See #BaseImporter::GetInfo for the details
@ -122,8 +116,6 @@ protected:
void InternReadFile( const std::string& pFile, aiScene* pScene,
IOSystem* pIOHandler);
protected:
// -------------------------------------------------------------------
/** Import a quake 1 MDL file (IDPO)
*/
@ -154,7 +146,6 @@ protected:
void SizeCheck(const void* szPos);
void SizeCheck(const void* szPos, const char* szFile, unsigned int iLine);
// -------------------------------------------------------------------
/** Validate the header data structure of a game studio MDL7 file
* \param pcHeader Input header to be validated
@ -167,7 +158,6 @@ protected:
*/
void ValidateHeader_Quake1(const MDL::Header* pcHeader);
// -------------------------------------------------------------------
/** Try to load a palette from the current directory (colormap.lmp)
* If it is not found the default palette of Quake1 is returned
@ -179,9 +169,8 @@ protected:
*/
void FreePalette(const unsigned char* pszColorMap);
// -------------------------------------------------------------------
/** Load a paletized texture from the file and convert it to 32bpp
/** Load a palletized texture from the file and convert it to 32bpp
*/
void CreateTextureARGB8_3DGS_MDL3(const unsigned char* szData);
@ -195,7 +184,6 @@ protected:
unsigned int iType,
unsigned int* piSkip);
// -------------------------------------------------------------------
/** Used to load textures from MDL5
* \param szData Input data
@ -206,7 +194,6 @@ protected:
unsigned int iType,
unsigned int* piSkip);
// -------------------------------------------------------------------
/** Checks whether a texture can be replaced with a single color
* This is useful for all file formats before MDL7 (all those
@ -218,14 +205,12 @@ protected:
*/
aiColor4D ReplaceTextureWithColor(const aiTexture* pcTexture);
// -------------------------------------------------------------------
/** Converts the absolute texture coordinates in MDL5 files to
* relative in a range between 0 and 1
*/
void CalculateUVCoordinates_MDL5();
// -------------------------------------------------------------------
/** Read an UV coordinate from the file. If the file format is not
* MDL5, the function calculates relative texture coordinates
@ -245,7 +230,6 @@ protected:
*/
void SetupMaterialProperties_3DGS_MDL5_Quake1( );
// -------------------------------------------------------------------
/** Parse a skin lump in a MDL7/HMP7 file with all of its features
* variant 1: Current cursor position is the beginning of the skin header

View File

@ -1180,8 +1180,12 @@ inline void Light::SetDefaults()
falloffExponent = 0.f;
}
inline void Node::Read(Value& obj, Asset& r)
{
inline
void Node::Read(Value& obj, Asset& r) {
if (name.empty()) {
name = id;
}
if (Value* children = FindArray(obj, "children")) {
this->children.reserve(children->Size());
for (unsigned int i = 0; i < children->Size(); ++i) {

View File

@ -475,14 +475,17 @@ void glTFImporter::ImportCameras(glTF::Asset& r) {
if (cam.type == Camera::Perspective) {
aicam->mAspect = cam.perspective.aspectRatio;
aicam->mHorizontalFOV = cam.perspective.yfov * aicam->mAspect;
aicam->mHorizontalFOV = cam.perspective.yfov * ((aicam->mAspect == 0.f) ? 1.f : aicam->mAspect);
aicam->mClipPlaneFar = cam.perspective.zfar;
aicam->mClipPlaneNear = cam.perspective.znear;
} else {
aicam->mClipPlaneFar = cam.ortographic.zfar;
aicam->mClipPlaneNear = cam.ortographic.znear;
aicam->mHorizontalFOV = 0.0;
aicam->mAspect = cam.ortographic.xmag / cam.ortographic.ymag;
aicam->mAspect = 1.0f;
if (0.f != cam.ortographic.ymag) {
aicam->mAspect = cam.ortographic.xmag / cam.ortographic.ymag;
}
}
}
}

View File

@ -1098,8 +1098,11 @@ inline void Light::Read(Value& obj, Asset& /*r*/)
}
}
inline void Node::Read(Value& obj, Asset& r)
{
inline
void Node::Read(Value& obj, Asset& r) {
if (name.empty()) {
name = id;
}
if (Value* children = FindArray(obj, "children")) {
this->children.reserve(children->Size());

View File

@ -702,14 +702,17 @@ void glTF2Importer::ImportCameras(glTF2::Asset& r)
if (cam.type == Camera::Perspective) {
aicam->mAspect = cam.cameraProperties.perspective.aspectRatio;
aicam->mHorizontalFOV = cam.cameraProperties.perspective.yfov * aicam->mAspect;
aicam->mHorizontalFOV = cam.cameraProperties.perspective.yfov * ((aicam->mAspect == 0.f) ? 1.f : aicam->mAspect);
aicam->mClipPlaneFar = cam.cameraProperties.perspective.zfar;
aicam->mClipPlaneNear = cam.cameraProperties.perspective.znear;
} else {
aicam->mClipPlaneFar = cam.cameraProperties.ortographic.zfar;
aicam->mClipPlaneNear = cam.cameraProperties.ortographic.znear;
aicam->mHorizontalFOV = 0.0;
aicam->mAspect = cam.cameraProperties.ortographic.xmag / cam.cameraProperties.ortographic.ymag;
aicam->mAspect = 1.0f;
if (0.f != cam.cameraProperties.ortographic.ymag ) {
aicam->mAspect = cam.cameraProperties.ortographic.xmag / cam.cameraProperties.ortographic.ymag;
}
}
}
}
@ -905,6 +908,9 @@ aiNode* ImportNode(aiScene* pScene, glTF2::Asset& r, std::vector<unsigned int>&
std::vector<std::vector<aiVertexWeight>> weighting(mesh->mNumBones);
BuildVertexWeightMapping(node.meshes[0]->primitives[primitiveNo], weighting);
mat4* pbindMatrices = nullptr;
node.skin->inverseBindMatrices->ExtractData(pbindMatrices);
for (uint32_t i = 0; i < mesh->mNumBones; ++i) {
aiBone* bone = new aiBone();
@ -920,6 +926,8 @@ aiNode* ImportNode(aiScene* pScene, glTF2::Asset& r, std::vector<unsigned int>&
}
GetNodeTransform(bone->mOffsetMatrix, *joint);
CopyValue(pbindMatrices[i], bone->mOffsetMatrix);
std::vector<aiVertexWeight>& weights = weighting[i];
bone->mNumWeights = static_cast<uint32_t>(weights.size());
@ -935,6 +943,10 @@ aiNode* ImportNode(aiScene* pScene, glTF2::Asset& r, std::vector<unsigned int>&
}
mesh->mBones[i] = bone;
}
if (pbindMatrices) {
delete[] pbindMatrices;
}
}
}

View File

@ -215,7 +215,7 @@ namespace io
two methods to read your data and give a pointer to an instance of
your implementation when calling createIrrXMLReader(),
createIrrXMLReaderUTF16() or createIrrXMLReaderUTF32() */
class IFileReadCallBack
class IRRXML_API IFileReadCallBack
{
public:

View File

@ -39,22 +39,24 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#pragma once
/** @file MathFunctions.h
* @brief Implementation of the math functions (gcd and lcm)
* @brief Implementation of math utility functions.
*
* Copied from BoostWorkaround/math
*/
*/
#include <limits>
namespace Assimp {
namespace Math {
// TODO: use binary GCD for unsigned integers ....
template < typename IntegerType >
IntegerType gcd( IntegerType a, IntegerType b )
{
inline
IntegerType gcd( IntegerType a, IntegerType b ) {
const IntegerType zero = (IntegerType)0;
while ( true )
{
while ( true ) {
if ( a == zero )
return b;
b %= a;
@ -66,12 +68,19 @@ IntegerType gcd( IntegerType a, IntegerType b )
}
template < typename IntegerType >
IntegerType lcm( IntegerType a, IntegerType b )
{
inline
IntegerType lcm( IntegerType a, IntegerType b ) {
const IntegerType t = gcd (a,b);
if (!t)return t;
if (!t)
return t;
return a / t * b;
}
template<class T>
inline
T getEpsilon() {
return std::numeric_limits<T>::epsilon();
}
}
}

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2019, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
@ -53,6 +51,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "matrix4x4.h"
#include "matrix3x3.h"
#include "quaternion.h"
#include "MathFunctions.h"
#include <algorithm>
#include <limits>
@ -420,8 +419,8 @@ inline void aiMatrix4x4t<TReal>::Decompose (aiVector3t<TReal>& pScaling, aiQuate
}
template <typename TReal>
inline void aiMatrix4x4t<TReal>::Decompose(aiVector3t<TReal>& pScaling, aiVector3t<TReal>& pRotation, aiVector3t<TReal>& pPosition) const
{
inline
void aiMatrix4x4t<TReal>::Decompose(aiVector3t<TReal>& pScaling, aiVector3t<TReal>& pRotation, aiVector3t<TReal>& pPosition) const {
ASSIMP_MATRIX4_4_DECOMPOSE_PART;
/*
@ -442,7 +441,7 @@ inline void aiMatrix4x4t<TReal>::Decompose(aiVector3t<TReal>& pScaling, aiVector
*/
// Use a small epsilon to solve floating-point inaccuracies
const TReal epsilon = 10e-3f;
const TReal epsilon = Assimp::Math::getEpsilon<TReal>();
pRotation.y = std::asin(-vCols[0].z);// D. Angle around oY.

File diff suppressed because one or more lines are too long

View File

@ -276,3 +276,9 @@ TEST_F(utFBXImporterExporter, importEmbeddedFragmentedAsciiTest) {
ASSERT_TRUE(scene->mTextures[0]->pcData);
ASSERT_EQ(968029u, scene->mTextures[0]->mWidth) << "FBX ASCII base64 compression splits data by 512Kb, it should be two parts for this texture";
}
TEST_F(utFBXImporterExporter, fbxTokenizeTestTest) {
//Assimp::Importer importer;
//const aiScene* scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/FBX/transparentTest2.fbx", aiProcess_ValidateDataStructure);
//EXPECT_NE(nullptr, scene);
}