Fixed a few GLTF importer/exporter bugs
parent
7468ca5c35
commit
d9b365eb90
|
@ -269,9 +269,13 @@ option ( ASSIMP_BUILD_ASSIMP_TOOLS
|
||||||
ON
|
ON
|
||||||
)
|
)
|
||||||
IF ( ASSIMP_BUILD_ASSIMP_TOOLS )
|
IF ( ASSIMP_BUILD_ASSIMP_TOOLS )
|
||||||
IF ( WIN32 AND DirectX_FOUND )
|
IF ( WIN32 )
|
||||||
|
option ( ASSIMP_BUILD_ASSIMP_VIEW "If the Assimp view tool is built. (requires DirectX)" ${DirectX_FOUND} )
|
||||||
|
IF ( ASSIMP_BUILD_ASSIMP_VIEW )
|
||||||
ADD_SUBDIRECTORY( tools/assimp_view/ )
|
ADD_SUBDIRECTORY( tools/assimp_view/ )
|
||||||
ENDIF ( WIN32 AND DirectX_FOUND )
|
ENDIF ( ASSIMP_BUILD_ASSIMP_VIEW )
|
||||||
|
ENDIF ( WIN32 )
|
||||||
|
|
||||||
ADD_SUBDIRECTORY( tools/assimp_cmd/ )
|
ADD_SUBDIRECTORY( tools/assimp_cmd/ )
|
||||||
ENDIF ( ASSIMP_BUILD_ASSIMP_TOOLS )
|
ENDIF ( ASSIMP_BUILD_ASSIMP_TOOLS )
|
||||||
|
|
||||||
|
|
|
@ -446,6 +446,9 @@ ADD_ASSIMP_IMPORTER(IFC
|
||||||
STEPFileEncoding.cpp
|
STEPFileEncoding.cpp
|
||||||
STEPFileEncoding.h
|
STEPFileEncoding.h
|
||||||
)
|
)
|
||||||
|
if (MSVC AND ASSIMP_BUILD_IFC_IMPORTER)
|
||||||
|
set_source_files_properties(IFCReaderGen.cpp PROPERTIES COMPILE_FLAGS "/bigobj")
|
||||||
|
endif (MSVC AND ASSIMP_BUILD_IFC_IMPORTER)
|
||||||
|
|
||||||
ADD_ASSIMP_IMPORTER(XGL
|
ADD_ASSIMP_IMPORTER(XGL
|
||||||
XGLLoader.cpp
|
XGLLoader.cpp
|
||||||
|
|
|
@ -754,12 +754,12 @@ namespace glTF
|
||||||
virtual void WriteObjects(AssetWriter& writer) = 0;
|
virtual void WriteObjects(AssetWriter& writer) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! (Stub class that is specialized in glTFAssetWriter.h)
|
|
||||||
template<class T>
|
template<class T>
|
||||||
struct LazyDictWriter
|
class LazyDict;
|
||||||
{
|
|
||||||
static void Write(T& d, AssetWriter& w) {}
|
//! (Implemented in glTFAssetWriter.h)
|
||||||
};
|
template<class T>
|
||||||
|
void WriteLazyDict(LazyDict<T>& d, AssetWriter& w);
|
||||||
|
|
||||||
//! Manages lazy loading of the glTF top-level objects, and keeps a reference to them by ID
|
//! Manages lazy loading of the glTF top-level objects, and keeps a reference to them by ID
|
||||||
//! It is the owner the loaded objects, so when it is destroyed it also deletes them
|
//! It is the owner the loaded objects, so when it is destroyed it also deletes them
|
||||||
|
@ -782,7 +782,7 @@ namespace glTF
|
||||||
void DetachFromDocument();
|
void DetachFromDocument();
|
||||||
|
|
||||||
void WriteObjects(AssetWriter& writer)
|
void WriteObjects(AssetWriter& writer)
|
||||||
{ LazyDictWriter< LazyDict >::Write(*this, writer); }
|
{ WriteLazyDict<T>(*this, writer); }
|
||||||
|
|
||||||
Ref<T> Add(T* obj);
|
Ref<T> Add(T* obj);
|
||||||
|
|
||||||
|
@ -810,14 +810,14 @@ namespace glTF
|
||||||
{
|
{
|
||||||
std::string copyright; //!< A copyright message suitable for display to credit the content creator.
|
std::string copyright; //!< A copyright message suitable for display to credit the content creator.
|
||||||
std::string generator; //!< Tool that generated this glTF model.Useful for debugging.
|
std::string generator; //!< Tool that generated this glTF model.Useful for debugging.
|
||||||
bool premultipliedAlpha; //!< Specifies if the shaders were generated with premultiplied alpha. (default: false)
|
bool premultipliedAlpha = false; //!< Specifies if the shaders were generated with premultiplied alpha. (default: false)
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
std::string api; //!< Specifies the target rendering API (default: "WebGL")
|
std::string api; //!< Specifies the target rendering API (default: "WebGL")
|
||||||
std::string version; //!< Specifies the target rendering API (default: "1.0.3")
|
std::string version; //!< Specifies the target rendering API (default: "1.0.3")
|
||||||
} profile; //!< Specifies the target rendering API and version, e.g., WebGL 1.0.3. (default: {})
|
} profile; //!< Specifies the target rendering API and version, e.g., WebGL 1.0.3. (default: {})
|
||||||
|
|
||||||
int version; //!< The glTF format version (should be 1)
|
int version = 0; //!< The glTF format version (should be 1)
|
||||||
|
|
||||||
void Read(Document& doc);
|
void Read(Document& doc);
|
||||||
};
|
};
|
||||||
|
@ -894,6 +894,7 @@ namespace glTF
|
||||||
public:
|
public:
|
||||||
Asset(IOSystem* io = 0)
|
Asset(IOSystem* io = 0)
|
||||||
: mIOSystem(io)
|
: mIOSystem(io)
|
||||||
|
, asset()
|
||||||
, accessors (*this, "accessors")
|
, accessors (*this, "accessors")
|
||||||
, animations (*this, "animations")
|
, animations (*this, "animations")
|
||||||
, buffers (*this, "buffers")
|
, buffers (*this, "buffers")
|
||||||
|
@ -913,7 +914,6 @@ namespace glTF
|
||||||
, lights (*this, "lights", "KHR_materials_common")
|
, lights (*this, "lights", "KHR_materials_common")
|
||||||
{
|
{
|
||||||
memset(&extensionsUsed, 0, sizeof(extensionsUsed));
|
memset(&extensionsUsed, 0, sizeof(extensionsUsed));
|
||||||
memset(&asset, 0, sizeof(asset));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Main function
|
//! Main function
|
||||||
|
|
|
@ -71,11 +71,11 @@ namespace {
|
||||||
}};
|
}};
|
||||||
|
|
||||||
template<> struct ReadHelper<const char*> { static bool Read(Value& val, const char*& out) {
|
template<> struct ReadHelper<const char*> { static bool Read(Value& val, const char*& out) {
|
||||||
return val.IsString() ? out = val.GetString(), true : false;
|
return val.IsString() ? (out = val.GetString(), true) : false;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
template<> struct ReadHelper<std::string> { static bool Read(Value& val, std::string& out) {
|
template<> struct ReadHelper<std::string> { static bool Read(Value& val, std::string& out) {
|
||||||
return val.IsString() ? out = val.GetString(), true : false;
|
return val.IsString() ? (out = std::string(val.GetString(), val.GetStringLength()), true) : false;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
template<class T> struct ReadHelper< Nullable<T> > { static bool Read(Value& val, Nullable<T>& out) {
|
template<class T> struct ReadHelper< Nullable<T> > { static bool Read(Value& val, Nullable<T>& out) {
|
||||||
|
@ -1013,30 +1013,26 @@ inline std::string Asset::FindUniqueID(const std::string& str, const char* suffi
|
||||||
{
|
{
|
||||||
std::string id = str;
|
std::string id = str;
|
||||||
|
|
||||||
Asset::IdMap::iterator it;
|
|
||||||
|
|
||||||
do {
|
|
||||||
if (!id.empty()) {
|
if (!id.empty()) {
|
||||||
it = mUsedIds.find(id);
|
if (mUsedIds.find(id) == mUsedIds.end())
|
||||||
if (it == mUsedIds.end()) break;
|
return id;
|
||||||
|
|
||||||
id += "_";
|
id += "_";
|
||||||
}
|
}
|
||||||
|
|
||||||
id += suffix;
|
id += suffix;
|
||||||
|
|
||||||
it = mUsedIds.find(id);
|
Asset::IdMap::iterator it = mUsedIds.find(id);
|
||||||
if (it == mUsedIds.end()) break;
|
if (it == mUsedIds.end())
|
||||||
|
return id;
|
||||||
|
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
int offset = ai_snprintf(buffer, 256, "%s_", id.c_str());
|
int offset = ai_snprintf(buffer, sizeof(buffer), "%s_", id.c_str());
|
||||||
for (int i = 0; it != mUsedIds.end(); ++i) {
|
for (int i = 0; it != mUsedIds.end(); ++i) {
|
||||||
ai_snprintf(buffer + offset, 256, "%d", i);
|
ai_snprintf(buffer + offset, sizeof(buffer) - offset, "%d", i);
|
||||||
|
|
||||||
id = buffer;
|
id = buffer;
|
||||||
it = mUsedIds.find(id);
|
it = mUsedIds.find(id);
|
||||||
}
|
}
|
||||||
} while (false); // fake loop to allow using "break"
|
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ using rapidjson::MemoryPoolAllocator;
|
||||||
class AssetWriter
|
class AssetWriter
|
||||||
{
|
{
|
||||||
template<class T>
|
template<class T>
|
||||||
friend struct LazyDictWriter;
|
friend void WriteLazyDict(LazyDict<T>& d, AssetWriter& w);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -484,13 +484,10 @@ namespace glTF {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
struct LazyDictWriter< LazyDict<T> >
|
void WriteLazyDict(LazyDict<T>& d, AssetWriter& w)
|
||||||
{
|
|
||||||
static void Write(LazyDict<T>& d, AssetWriter& w)
|
|
||||||
{
|
{
|
||||||
w.WriteObjects(d);
|
w.WriteObjects(d);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <assimp/DefaultLogger.hpp>
|
#include <assimp/DefaultLogger.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "MakeVerboseFormat.h"
|
||||||
|
|
||||||
#include "glTFAsset.h"
|
#include "glTFAsset.h"
|
||||||
|
|
||||||
using namespace Assimp;
|
using namespace Assimp;
|
||||||
|
@ -617,7 +619,10 @@ void glTFImporter::InternReadFile(const std::string& pFile, aiScene* pScene, IOS
|
||||||
ImportNodes(asset);
|
ImportNodes(asset);
|
||||||
|
|
||||||
// TODO: it does not split the loaded vertices, should it?
|
// TODO: it does not split the loaded vertices, should it?
|
||||||
pScene->mFlags |= AI_SCENE_FLAGS_NON_VERBOSE_FORMAT;
|
//pScene->mFlags |= AI_SCENE_FLAGS_NON_VERBOSE_FORMAT;
|
||||||
|
Assimp::MakeVerboseFormatProcess process;
|
||||||
|
process.Execute(pScene);
|
||||||
|
|
||||||
|
|
||||||
if (pScene->mNumMeshes == 0) {
|
if (pScene->mNumMeshes == 0) {
|
||||||
pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
|
pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
|
||||||
|
|
Loading…
Reference in New Issue