Merge branch 'master' into feat/c4d-importer-macos-support
commit
97691c667c
|
@ -49,7 +49,7 @@ namespace HMP {
|
|||
#include <assimp/Compiler/pushpack1.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// to make it easier for us, we test the magic word against both "endianesses"
|
||||
// to make it easier for us, we test the magic word against both "endiannesses"
|
||||
#define AI_HMP_MAGIC_NUMBER_BE_4 AI_MAKE_MAGIC("HMP4")
|
||||
#define AI_HMP_MAGIC_NUMBER_LE_4 AI_MAKE_MAGIC("4PMH")
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
namespace Assimp {
|
||||
namespace MD2 {
|
||||
|
||||
// to make it easier for us, we test the magic word against both "endianesses"
|
||||
// to make it easier for us, we test the magic word against both "endiannesses"
|
||||
#define AI_MD2_MAGIC_NUMBER_BE AI_MAKE_MAGIC("IDP2")
|
||||
#define AI_MD2_MAGIC_NUMBER_LE AI_MAKE_MAGIC("2PDI")
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
namespace Assimp {
|
||||
namespace MD3 {
|
||||
|
||||
// to make it easier for us, we test the magic word against both "endianesses"
|
||||
// to make it easier for us, we test the magic word against both "endiannesses"
|
||||
#define AI_MD3_MAGIC_NUMBER_BE AI_MAKE_MAGIC("IDP3")
|
||||
#define AI_MD3_MAGIC_NUMBER_LE AI_MAKE_MAGIC("3PDI")
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ http://themdcfile.planetwolfenstein.gamespy.com/MDC_File_Format.pdf
|
|||
namespace Assimp {
|
||||
namespace MDC {
|
||||
|
||||
// to make it easier for us, we test the magic word against both "endianesses"
|
||||
// to make it easier for us, we test the magic word against both "endiannesses"
|
||||
#define AI_MDC_MAGIC_NUMBER_BE AI_MAKE_MAGIC("CPDI")
|
||||
#define AI_MDC_MAGIC_NUMBER_LE AI_MAKE_MAGIC("IDPC")
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ namespace Assimp {
|
|||
namespace MDL {
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
// to make it easier for us, we test the magic word against both "endianesses"
|
||||
// to make it easier for us, we test the magic word against both "endiannesses"
|
||||
|
||||
// magic bytes used in Quake 1 MDL meshes
|
||||
#define AI_MDL_MAGIC_NUMBER_BE AI_MAKE_MAGIC("IDPO")
|
||||
|
|
|
@ -59,9 +59,9 @@ namespace Assimp {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Worker function for exporting a scene to Wavefront OBJ. Prototyped and registered in Exporter.cpp
|
||||
void ExportSceneObj(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/) {
|
||||
void ExportSceneObj(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* props) {
|
||||
// invoke the exporter
|
||||
ObjExporter exporter(pFile, pScene);
|
||||
ObjExporter exporter(pFile, pScene, false, props);
|
||||
|
||||
if (exporter.mOutput.fail() || exporter.mOutputMat.fail()) {
|
||||
throw DeadlyExportError("output data creation failed. Most likely the file became too large: " + std::string(pFile));
|
||||
|
@ -86,9 +86,9 @@ void ExportSceneObj(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Worker function for exporting a scene to Wavefront OBJ without the material file. Prototyped and registered in Exporter.cpp
|
||||
void ExportSceneObjNoMtl(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* ) {
|
||||
void ExportSceneObjNoMtl(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* props) {
|
||||
// invoke the exporter
|
||||
ObjExporter exporter(pFile, pScene, true);
|
||||
ObjExporter exporter(pFile, pScene, true, props);
|
||||
|
||||
if (exporter.mOutput.fail() || exporter.mOutputMat.fail()) {
|
||||
throw DeadlyExportError("output data creation failed. Most likely the file became too large: " + std::string(pFile));
|
||||
|
@ -111,7 +111,7 @@ void ExportSceneObjNoMtl(const char* pFile,IOSystem* pIOSystem, const aiScene* p
|
|||
static const std::string MaterialExt = ".mtl";
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
ObjExporter::ObjExporter(const char* _filename, const aiScene* pScene, bool noMtl)
|
||||
ObjExporter::ObjExporter(const char* _filename, const aiScene* pScene, bool noMtl, const ExportProperties* props)
|
||||
: filename(_filename)
|
||||
, pScene(pScene)
|
||||
, vn()
|
||||
|
@ -130,7 +130,10 @@ ObjExporter::ObjExporter(const char* _filename, const aiScene* pScene, bool noMt
|
|||
mOutputMat.imbue(l);
|
||||
mOutputMat.precision(ASSIMP_AI_REAL_TEXT_PRECISION);
|
||||
|
||||
WriteGeometryFile(noMtl);
|
||||
WriteGeometryFile(
|
||||
noMtl,
|
||||
props == nullptr ? true : props->GetPropertyBool("bJoinIdenticalVertices", true)
|
||||
);
|
||||
if ( !noMtl ) {
|
||||
WriteMaterialFile();
|
||||
}
|
||||
|
@ -255,14 +258,14 @@ void ObjExporter::WriteMaterialFile() {
|
|||
}
|
||||
}
|
||||
|
||||
void ObjExporter::WriteGeometryFile(bool noMtl) {
|
||||
void ObjExporter::WriteGeometryFile(bool noMtl, bool merge_identical_vertices) {
|
||||
WriteHeader(mOutput);
|
||||
if (!noMtl)
|
||||
mOutput << "mtllib " << GetMaterialLibName() << endl << endl;
|
||||
|
||||
// collect mesh geometry
|
||||
aiMatrix4x4 mBase;
|
||||
AddNode(pScene->mRootNode, mBase);
|
||||
AddNode(pScene->mRootNode, mBase, merge_identical_vertices);
|
||||
|
||||
// write vertex positions with colors, if any
|
||||
mVpMap.getKeys( vp );
|
||||
|
@ -330,7 +333,7 @@ void ObjExporter::WriteGeometryFile(bool noMtl) {
|
|||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ObjExporter::AddMesh(const aiString& name, const aiMesh* m, const aiMatrix4x4& mat) {
|
||||
void ObjExporter::AddMesh(const aiString& name, const aiMesh* m, const aiMatrix4x4& mat, bool merge_identical_vertices) {
|
||||
mMeshes.emplace_back();
|
||||
MeshInstance& mesh = mMeshes.back();
|
||||
|
||||
|
@ -362,13 +365,14 @@ void ObjExporter::AddMesh(const aiString& name, const aiMesh* m, const aiMatrix4
|
|||
for(unsigned int a = 0; a < f.mNumIndices; ++a) {
|
||||
const unsigned int idx = f.mIndices[a];
|
||||
|
||||
const unsigned int fi = merge_identical_vertices ? 0 : idx;
|
||||
aiVector3D vert = mat * m->mVertices[idx];
|
||||
|
||||
if ( nullptr != m->mColors[ 0 ] ) {
|
||||
aiColor4D col4 = m->mColors[ 0 ][ idx ];
|
||||
face.indices[a].vp = mVpMap.getIndex({vert, aiColor3D(col4.r, col4.g, col4.b)});
|
||||
face.indices[a].vp = mVpMap.getIndex({vert, aiColor3D(col4.r, col4.g, col4.b), fi});
|
||||
} else {
|
||||
face.indices[a].vp = mVpMap.getIndex({vert, aiColor3D(0,0,0)});
|
||||
face.indices[a].vp = mVpMap.getIndex({vert, aiColor3D(0,0,0), fi});
|
||||
}
|
||||
|
||||
if (m->mNormals) {
|
||||
|
@ -388,21 +392,21 @@ void ObjExporter::AddMesh(const aiString& name, const aiMesh* m, const aiMatrix4
|
|||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ObjExporter::AddNode(const aiNode* nd, const aiMatrix4x4& mParent) {
|
||||
void ObjExporter::AddNode(const aiNode* nd, const aiMatrix4x4& mParent, bool merge_identical_vertices) {
|
||||
const aiMatrix4x4& mAbs = mParent * nd->mTransformation;
|
||||
|
||||
aiMesh *cm( nullptr );
|
||||
for(unsigned int i = 0; i < nd->mNumMeshes; ++i) {
|
||||
cm = pScene->mMeshes[nd->mMeshes[i]];
|
||||
if (nullptr != cm) {
|
||||
AddMesh(cm->mName, pScene->mMeshes[nd->mMeshes[i]], mAbs);
|
||||
AddMesh(cm->mName, pScene->mMeshes[nd->mMeshes[i]], mAbs, merge_identical_vertices);
|
||||
} else {
|
||||
AddMesh(nd->mName, pScene->mMeshes[nd->mMeshes[i]], mAbs);
|
||||
AddMesh(nd->mName, pScene->mMeshes[nd->mMeshes[i]], mAbs, merge_identical_vertices);
|
||||
}
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < nd->mNumChildren; ++i) {
|
||||
AddNode(nd->mChildren[i], mAbs);
|
||||
AddNode(nd->mChildren[i], mAbs, merge_identical_vertices);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include <assimp/Exporter.hpp>
|
||||
|
||||
struct aiScene;
|
||||
struct aiNode;
|
||||
struct aiMesh;
|
||||
|
@ -63,7 +65,7 @@ namespace Assimp {
|
|||
class ObjExporter {
|
||||
public:
|
||||
/// Constructor for a specific scene to export
|
||||
ObjExporter(const char* filename, const aiScene* pScene, bool noMtl=false);
|
||||
ObjExporter(const char* filename, const aiScene* pScene, bool noMtl=false, const ExportProperties* props = nullptr);
|
||||
~ObjExporter();
|
||||
std::string GetMaterialLibName();
|
||||
std::string GetMaterialLibFileName();
|
||||
|
@ -97,10 +99,10 @@ private:
|
|||
|
||||
void WriteHeader(std::ostringstream& out);
|
||||
void WriteMaterialFile();
|
||||
void WriteGeometryFile(bool noMtl=false);
|
||||
void WriteGeometryFile(bool noMtl=false, bool merge_identical_vertices = false);
|
||||
std::string GetMaterialName(unsigned int index);
|
||||
void AddMesh(const aiString& name, const aiMesh* m, const aiMatrix4x4& mat);
|
||||
void AddNode(const aiNode* nd, const aiMatrix4x4& mParent);
|
||||
void AddMesh(const aiString& name, const aiMesh* m, const aiMatrix4x4& mat, bool merge_identical_vertices);
|
||||
void AddNode(const aiNode* nd, const aiMatrix4x4& mParent, bool merge_identical_vertices);
|
||||
|
||||
private:
|
||||
std::string filename;
|
||||
|
@ -109,6 +111,7 @@ private:
|
|||
struct vertexData {
|
||||
aiVector3D vp;
|
||||
aiColor3D vc; // OBJ does not support 4D color
|
||||
uint32_t index = 0;
|
||||
};
|
||||
|
||||
std::vector<aiVector3D> vn, vt;
|
||||
|
@ -133,7 +136,7 @@ private:
|
|||
if (a.vc.g > b.vc.g) return false;
|
||||
if (a.vc.b < b.vc.b) return true;
|
||||
if (a.vc.b > b.vc.b) return false;
|
||||
return false;
|
||||
return a.index < b.index;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1545,7 +1545,7 @@ Don't trust the input data! Check all offsets!
|
|||
Mixed stuff for internal use by loaders, mostly documented (most of them are already included by <i>AssimpPCH.h</i>):
|
||||
<ul>
|
||||
<li><b>ByteSwapper</b> (<i>ByteSwapper.h</i>) - manual byte swapping stuff for binary loaders.</li>
|
||||
<li><b>StreamReader</b> (<i>StreamReader.h</i>) - safe, endianess-correct, binary reading.</li>
|
||||
<li><b>StreamReader</b> (<i>StreamReader.h</i>) - safe, endianness-correct, binary reading.</li>
|
||||
<li><b>IrrXML</b> (<i>irrXMLWrapper.h</i>) - for XML-parsing (SAX.</li>
|
||||
<li><b>CommentRemover</b> (<i>RemoveComments.h</i>) - remove single-line and multi-line comments from a text file.</li>
|
||||
<li>fast_atof, strtoul10, strtoul16, SkipSpaceAndLineEnd, SkipToNextToken .. large family of low-level
|
||||
|
|
|
@ -263,7 +263,7 @@ struct ByteSwapper<T,false> {
|
|||
};
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
template <bool SwapEndianess, typename T, bool RuntimeSwitch>
|
||||
template <bool SwapEndianness, typename T, bool RuntimeSwitch>
|
||||
struct Getter {
|
||||
void operator() (T* inout, bool le) {
|
||||
#ifdef AI_BUILD_BIG_ENDIAN
|
||||
|
@ -278,12 +278,12 @@ struct Getter {
|
|||
}
|
||||
};
|
||||
|
||||
template <bool SwapEndianess, typename T>
|
||||
struct Getter<SwapEndianess,T,false> {
|
||||
template <bool SwapEndianness, typename T>
|
||||
struct Getter<SwapEndianness,T,false> {
|
||||
|
||||
void operator() (T* inout, bool /*le*/) {
|
||||
// static branch
|
||||
ByteSwapper<T,(SwapEndianess && sizeof(T)>1)> () (inout);
|
||||
ByteSwapper<T,(SwapEndianness && sizeof(T)>1)> () (inout);
|
||||
}
|
||||
};
|
||||
} // end Intern
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace Assimp {
|
|||
*
|
||||
* XXX switch from unsigned int for size types to size_t? or ptrdiff_t?*/
|
||||
// --------------------------------------------------------------------------------------------
|
||||
template <bool SwapEndianess = false, bool RuntimeSwitch = false>
|
||||
template <bool SwapEndianness = false, bool RuntimeSwitch = false>
|
||||
class StreamReader {
|
||||
public:
|
||||
using diff = size_t;
|
||||
|
@ -84,7 +84,7 @@ public:
|
|||
* reads from the current position to the end of the stream.
|
||||
* @param le If @c RuntimeSwitch is true: specifies whether the
|
||||
* stream is in little endian byte order. Otherwise the
|
||||
* endianness information is contained in the @c SwapEndianess
|
||||
* endianness information is contained in the @c SwapEndianness
|
||||
* template parameter and this parameter is meaningless. */
|
||||
StreamReader(std::shared_ptr<IOStream> stream, bool le = false) :
|
||||
mStream(stream),
|
||||
|
@ -291,7 +291,7 @@ public:
|
|||
|
||||
T f;
|
||||
::memcpy(&f, mCurrent, sizeof(T));
|
||||
Intern::Getter<SwapEndianess, T, RuntimeSwitch>()(&f, mLe);
|
||||
Intern::Getter<SwapEndianness, T, RuntimeSwitch>()(&f, mLe);
|
||||
mCurrent += sizeof(T);
|
||||
|
||||
return f;
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace Assimp {
|
|||
* stream is to be determined at runtime.
|
||||
*/
|
||||
// --------------------------------------------------------------------------------------------
|
||||
template <bool SwapEndianess = false, bool RuntimeSwitch = false>
|
||||
template <bool SwapEndianness = false, bool RuntimeSwitch = false>
|
||||
class StreamWriter {
|
||||
enum {
|
||||
INITIAL_CAPACITY = 1024
|
||||
|
@ -82,7 +82,7 @@ public:
|
|||
continues at the current position of the stream cursor.
|
||||
* @param le If @c RuntimeSwitch is true: specifies whether the
|
||||
* stream is in little endian byte order. Otherwise the
|
||||
* endianness information is defined by the @c SwapEndianess
|
||||
* endianness information is defined by the @c SwapEndianness
|
||||
* template parameter and this parameter is meaningless. */
|
||||
StreamWriter(std::shared_ptr<IOStream> stream, bool le = false)
|
||||
: stream(stream)
|
||||
|
@ -260,7 +260,7 @@ public:
|
|||
/** Generic write method. ByteSwap::Swap(T*) *must* be defined */
|
||||
template <typename T>
|
||||
void Put(T f) {
|
||||
Intern :: Getter<SwapEndianess,T,RuntimeSwitch>() (&f, le);
|
||||
Intern :: Getter<SwapEndianness,T,RuntimeSwitch>() (&f, le);
|
||||
|
||||
if (cursor + sizeof(T) >= buffer.size()) {
|
||||
buffer.resize(cursor + sizeof(T));
|
||||
|
|
|
@ -44,9 +44,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <cstdlib>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#if defined(_MSC_VER) || defined(__MINGW64__) || defined(__MINGW32__)
|
||||
#define TMP_PATH "./"
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
#define TMP_PATH "/tmp/"
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#include <io.h>
|
||||
#define TMP_PATH "./"
|
||||
inline FILE* MakeTmpFile(char* tmplate)
|
||||
{
|
||||
auto pathtemplate = _mktemp(tmplate);
|
||||
|
@ -60,7 +65,6 @@ inline FILE* MakeTmpFile(char* tmplate)
|
|||
return fs;
|
||||
}
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
#define TMP_PATH "/tmp/"
|
||||
inline FILE* MakeTmpFile(char* tmplate)
|
||||
{
|
||||
auto fd = mkstemp(tmplate);
|
||||
|
|
Loading…
Reference in New Issue