Fixed a few GLTF importer/exporter bugs

pull/868/head
Otger 2016-04-28 18:44:47 +02:00
parent 7468ca5c35
commit d9b365eb90
7 changed files with 47 additions and 42 deletions

View File

@ -269,9 +269,13 @@ option ( ASSIMP_BUILD_ASSIMP_TOOLS
ON
)
IF ( ASSIMP_BUILD_ASSIMP_TOOLS )
IF ( WIN32 AND DirectX_FOUND )
ADD_SUBDIRECTORY( tools/assimp_view/ )
ENDIF ( 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/ )
ENDIF ( ASSIMP_BUILD_ASSIMP_VIEW )
ENDIF ( WIN32 )
ADD_SUBDIRECTORY( tools/assimp_cmd/ )
ENDIF ( ASSIMP_BUILD_ASSIMP_TOOLS )

View File

@ -446,6 +446,9 @@ ADD_ASSIMP_IMPORTER(IFC
STEPFileEncoding.cpp
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
XGLLoader.cpp

View File

@ -754,12 +754,12 @@ namespace glTF
virtual void WriteObjects(AssetWriter& writer) = 0;
};
//! (Stub class that is specialized in glTFAssetWriter.h)
template<class T>
struct LazyDictWriter
{
static void Write(T& d, AssetWriter& w) {}
};
class LazyDict;
//! (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
//! 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 WriteObjects(AssetWriter& writer)
{ LazyDictWriter< LazyDict >::Write(*this, writer); }
{ WriteLazyDict<T>(*this, writer); }
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 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 {
std::string api; //!< Specifies the target rendering API (default: "WebGL")
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: {})
int version; //!< The glTF format version (should be 1)
int version = 0; //!< The glTF format version (should be 1)
void Read(Document& doc);
};
@ -894,6 +894,7 @@ namespace glTF
public:
Asset(IOSystem* io = 0)
: mIOSystem(io)
, asset()
, accessors (*this, "accessors")
, animations (*this, "animations")
, buffers (*this, "buffers")
@ -913,7 +914,6 @@ namespace glTF
, lights (*this, "lights", "KHR_materials_common")
{
memset(&extensionsUsed, 0, sizeof(extensionsUsed));
memset(&asset, 0, sizeof(asset));
}
//! Main function

View File

@ -71,11 +71,11 @@ namespace {
}};
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) {
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) {
@ -842,7 +842,7 @@ inline void AssetMetadata::Read(Document& doc)
if (version != 1) {
char msg[128];
ai_snprintf(msg, 128, "Unsupported glTF version: %d", version);
ai_snprintf(msg, 128, "Unsupported glTF version: %d", version);
throw DeadlyImportError(msg);
}
}
@ -1013,30 +1013,26 @@ inline std::string Asset::FindUniqueID(const std::string& str, const char* suffi
{
std::string id = str;
Asset::IdMap::iterator it;
if (!id.empty()) {
if (mUsedIds.find(id) == mUsedIds.end())
return id;
do {
if (!id.empty()) {
it = mUsedIds.find(id);
if (it == mUsedIds.end()) break;
id += "_";
}
id += "_";
}
id += suffix;
id += suffix;
Asset::IdMap::iterator it = mUsedIds.find(id);
if (it == mUsedIds.end())
return id;
char buffer[256];
int offset = ai_snprintf(buffer, sizeof(buffer), "%s_", id.c_str());
for (int i = 0; it != mUsedIds.end(); ++i) {
ai_snprintf(buffer + offset, sizeof(buffer) - offset, "%d", i);
id = buffer;
it = mUsedIds.find(id);
if (it == mUsedIds.end()) break;
char buffer[256];
int offset = ai_snprintf(buffer, 256, "%s_", id.c_str());
for (int i = 0; it != mUsedIds.end(); ++i) {
ai_snprintf(buffer + offset, 256, "%d", i);
id = buffer;
it = mUsedIds.find(id);
}
} while (false); // fake loop to allow using "break"
}
return id;
}

View File

@ -58,7 +58,7 @@ using rapidjson::MemoryPoolAllocator;
class AssetWriter
{
template<class T>
friend struct LazyDictWriter;
friend void WriteLazyDict(LazyDict<T>& d, AssetWriter& w);
private:

View File

@ -484,13 +484,10 @@ namespace glTF {
}
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);
}
}

View File

@ -50,6 +50,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/DefaultLogger.hpp>
#include <memory>
#include "MakeVerboseFormat.h"
#include "glTFAsset.h"
using namespace Assimp;
@ -617,7 +619,10 @@ void glTFImporter::InternReadFile(const std::string& pFile, aiScene* pScene, IOS
ImportNodes(asset);
// 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) {
pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;