Merge branch 'master' into verboseLogging
This commit is contained in:
@@ -117,22 +117,37 @@ static const std::string XMLIDEncode(const std::string &name) {
|
||||
return idEncoded.str();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Helper functions to create unique ids
|
||||
inline bool IsUniqueId(const std::unordered_set<std::string> &idSet, const std::string &idStr) {
|
||||
return (idSet.find(idStr) == idSet.end());
|
||||
}
|
||||
|
||||
inline std::string MakeUniqueId(const std::unordered_set<std::string> &idSet, const std::string &idPrefix, const std::string &postfix) {
|
||||
std::string result(idPrefix + postfix);
|
||||
if (!IsUniqueId(idSet, result)) {
|
||||
// Select a number to append
|
||||
size_t idnum = 1;
|
||||
do {
|
||||
result = idPrefix + '_' + to_string(idnum) + postfix;
|
||||
++idnum;
|
||||
} while (!IsUniqueId(idSet, result));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Constructor for a specific scene to export
|
||||
ColladaExporter::ColladaExporter(const aiScene *pScene, IOSystem *pIOSystem, const std::string &path, const std::string &file) :
|
||||
mIOSystem(pIOSystem),
|
||||
mPath(path),
|
||||
mFile(file) {
|
||||
mFile(file),
|
||||
mScene(pScene),
|
||||
endstr("\n") {
|
||||
// make sure that all formatting happens using the standard, C locale and not the user's current locale
|
||||
mOutput.imbue(std::locale("C"));
|
||||
mOutput.precision(ASSIMP_AI_REAL_TEXT_PRECISION);
|
||||
|
||||
mScene = pScene;
|
||||
mSceneOwned = false;
|
||||
|
||||
// set up strings
|
||||
endstr = "\n";
|
||||
|
||||
// start writing the file
|
||||
WriteFile();
|
||||
}
|
||||
@@ -140,9 +155,6 @@ ColladaExporter::ColladaExporter(const aiScene *pScene, IOSystem *pIOSystem, con
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Destructor
|
||||
ColladaExporter::~ColladaExporter() {
|
||||
if (mSceneOwned) {
|
||||
delete mScene;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@@ -171,10 +183,11 @@ void ColladaExporter::WriteFile() {
|
||||
// customized, Writes the animation library
|
||||
WriteAnimationsLibrary();
|
||||
|
||||
// useless Collada fu at the end, just in case we haven't had enough indirections, yet.
|
||||
// instantiate the scene(s)
|
||||
// For Assimp there will only ever be one
|
||||
mOutput << startstr << "<scene>" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<instance_visual_scene url=\"#" + GetNodeUniqueId(mScene->mRootNode) + "\" />" << endstr;
|
||||
mOutput << startstr << "<instance_visual_scene url=\"#" + mSceneId + "\" />" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</scene>" << endstr;
|
||||
PopTag();
|
||||
@@ -209,13 +222,13 @@ void ColladaExporter::WriteHeader() {
|
||||
mScene->mRootNode->mTransformation.Decompose(scaling, rotation, position);
|
||||
rotation.Normalize();
|
||||
|
||||
bool add_root_node = false;
|
||||
mAdd_root_node = false;
|
||||
|
||||
ai_real scale = 1.0;
|
||||
if (std::abs(scaling.x - scaling.y) <= epsilon && std::abs(scaling.x - scaling.z) <= epsilon && std::abs(scaling.y - scaling.z) <= epsilon) {
|
||||
scale = (ai_real)((((double)scaling.x) + ((double)scaling.y) + ((double)scaling.z)) / 3.0);
|
||||
} else {
|
||||
add_root_node = true;
|
||||
mAdd_root_node = true;
|
||||
}
|
||||
|
||||
std::string up_axis = "Y_UP";
|
||||
@@ -226,33 +239,19 @@ void ColladaExporter::WriteHeader() {
|
||||
} else if (rotation.Equal(z_rot, epsilon)) {
|
||||
up_axis = "Z_UP";
|
||||
} else {
|
||||
add_root_node = true;
|
||||
mAdd_root_node = true;
|
||||
}
|
||||
|
||||
if (!position.Equal(aiVector3D(0, 0, 0))) {
|
||||
add_root_node = true;
|
||||
mAdd_root_node = true;
|
||||
}
|
||||
|
||||
if (mScene->mRootNode->mNumChildren == 0) {
|
||||
add_root_node = true;
|
||||
// Assimp root nodes can have meshes, Collada Scenes cannot
|
||||
if (mScene->mRootNode->mNumChildren == 0 || mScene->mRootNode->mMeshes != 0) {
|
||||
mAdd_root_node = true;
|
||||
}
|
||||
|
||||
if (add_root_node) {
|
||||
aiScene *scene;
|
||||
SceneCombiner::CopyScene(&scene, mScene);
|
||||
|
||||
aiNode *root = new aiNode("Scene");
|
||||
|
||||
root->mNumChildren = 1;
|
||||
root->mChildren = new aiNode *[root->mNumChildren];
|
||||
|
||||
root->mChildren[0] = scene->mRootNode;
|
||||
scene->mRootNode->mParent = root;
|
||||
scene->mRootNode = root;
|
||||
|
||||
mScene = scene;
|
||||
mSceneOwned = true;
|
||||
|
||||
if (mAdd_root_node) {
|
||||
up_axis = "Y_UP";
|
||||
scale = 1.0;
|
||||
}
|
||||
@@ -1226,17 +1225,29 @@ void ColladaExporter::WriteFloatArray(const std::string &pIdString, FloatDataTyp
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Writes the scene library
|
||||
void ColladaExporter::WriteSceneLibrary() {
|
||||
const std::string sceneId = GetNodeUniqueId(mScene->mRootNode);
|
||||
const std::string sceneName = GetNodeName(mScene->mRootNode);
|
||||
// Determine if we are using the aiScene root or our own
|
||||
std::string sceneName("Scene");
|
||||
if (mAdd_root_node) {
|
||||
mSceneId = MakeUniqueId(mUniqueIds, sceneName, std::string());
|
||||
mUniqueIds.insert(mSceneId);
|
||||
} else {
|
||||
mSceneId = GetNodeUniqueId(mScene->mRootNode);
|
||||
sceneName = GetNodeName(mScene->mRootNode);
|
||||
}
|
||||
|
||||
mOutput << startstr << "<library_visual_scenes>" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<visual_scene id=\"" + sceneId + "\" name=\"" + sceneName + "\">" << endstr;
|
||||
mOutput << startstr << "<visual_scene id=\"" + mSceneId + "\" name=\"" + sceneName + "\">" << endstr;
|
||||
PushTag();
|
||||
|
||||
// start recursive write at the root node
|
||||
for (size_t a = 0; a < mScene->mRootNode->mNumChildren; ++a)
|
||||
WriteNode(mScene->mRootNode->mChildren[a]);
|
||||
if (mAdd_root_node) {
|
||||
// Export the root node
|
||||
WriteNode(mScene->mRootNode);
|
||||
} else {
|
||||
// Have already exported the root node
|
||||
for (size_t a = 0; a < mScene->mRootNode->mNumChildren; ++a)
|
||||
WriteNode(mScene->mRootNode->mChildren[a]);
|
||||
}
|
||||
|
||||
PopTag();
|
||||
mOutput << startstr << "</visual_scene>" << endstr;
|
||||
@@ -1493,12 +1504,9 @@ void ColladaExporter::WriteNode(const aiNode *pNode) {
|
||||
const std::string node_name = GetNodeName(pNode);
|
||||
mOutput << startstr << "<node ";
|
||||
if (is_skeleton_root) {
|
||||
mOutput << "id=\"" << node_id << "\" " << (is_joint ? "sid=\"" + node_id + "\" " : ""); // For now, only support one skeleton in a scene.
|
||||
mFoundSkeletonRootNodeID = node_id;
|
||||
} else {
|
||||
mOutput << "id=\"" << node_id << "\" " << (is_joint ? "sid=\"" + node_id + "\" " : "");
|
||||
mFoundSkeletonRootNodeID = node_id; // For now, only support one skeleton in a scene.
|
||||
}
|
||||
|
||||
mOutput << "id=\"" << node_id << "\" " << (is_joint ? "sid=\"" + node_id + "\" " : "");
|
||||
mOutput << "name=\"" << node_name
|
||||
<< "\" type=\"" << node_type
|
||||
<< "\">" << endstr;
|
||||
@@ -1612,23 +1620,6 @@ void ColladaExporter::WriteNode(const aiNode *pNode) {
|
||||
mOutput << startstr << "</node>" << endstr;
|
||||
}
|
||||
|
||||
inline bool IsUniqueId(const std::unordered_set<std::string> &idSet, const std::string &idStr) {
|
||||
return (idSet.find(idStr) == idSet.end());
|
||||
}
|
||||
|
||||
inline std::string MakeUniqueId(const std::unordered_set<std::string> &idSet, const std::string &idPrefix, const std::string &postfix) {
|
||||
std::string result(idPrefix + postfix);
|
||||
if (!IsUniqueId(idSet, result)) {
|
||||
// Select a number to append
|
||||
size_t idnum = 1;
|
||||
do {
|
||||
result = idPrefix + '_' + to_string(idnum) + postfix;
|
||||
++idnum;
|
||||
} while (!IsUniqueId(idSet, result));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void ColladaExporter::CreateNodeIds(const aiNode *node) {
|
||||
GetNodeUniqueId(node);
|
||||
for (size_t a = 0; a < node->mNumChildren; ++a)
|
||||
|
||||
@@ -196,13 +196,14 @@ public:
|
||||
const std::string mFile;
|
||||
|
||||
/// The scene to be written
|
||||
const aiScene *mScene;
|
||||
bool mSceneOwned;
|
||||
const aiScene *const mScene;
|
||||
std::string mSceneId;
|
||||
bool mAdd_root_node = false;
|
||||
|
||||
/// current line start string, contains the current indentation for simple stream insertion
|
||||
std::string startstr;
|
||||
/// current line end string for simple stream insertion
|
||||
std::string endstr;
|
||||
const std::string endstr;
|
||||
|
||||
// pair of color and texture - texture precedences color
|
||||
struct Surface {
|
||||
|
||||
@@ -2479,7 +2479,7 @@ void ColladaParser::ReadSceneLibrary() {
|
||||
|
||||
// read name if given.
|
||||
int indexName = TestAttribute("name");
|
||||
const char *attrName = "unnamed";
|
||||
const char *attrName = "Scene";
|
||||
if (indexName > -1)
|
||||
attrName = mReader->getAttributeValue(indexName);
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace glTF {
|
||||
namespace {
|
||||
|
||||
template<typename T, size_t N>
|
||||
inline
|
||||
inline
|
||||
Value& MakeValue(Value& val, T(&r)[N], MemoryPoolAllocator<>& al) {
|
||||
val.SetArray();
|
||||
val.Reserve(N, al);
|
||||
@@ -70,7 +70,7 @@ namespace glTF {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline
|
||||
inline
|
||||
Value& MakeValue(Value& val, const std::vector<T> & r, MemoryPoolAllocator<>& al) {
|
||||
val.SetArray();
|
||||
val.Reserve(static_cast<rapidjson::SizeType>(r.size()), al);
|
||||
@@ -530,7 +530,9 @@ namespace glTF {
|
||||
StringBuffer docBuffer;
|
||||
|
||||
PrettyWriter<StringBuffer> writer(docBuffer);
|
||||
mDoc.Accept(writer);
|
||||
if (!mDoc.Accept(writer)) {
|
||||
throw DeadlyExportError("Failed to write scene data!");
|
||||
}
|
||||
|
||||
if (jsonOutFile->Write(docBuffer.GetString(), docBuffer.GetSize(), 1) != 1) {
|
||||
throw DeadlyExportError("Failed to write scene data!");
|
||||
@@ -569,7 +571,9 @@ namespace glTF {
|
||||
|
||||
StringBuffer docBuffer;
|
||||
Writer<StringBuffer> writer(docBuffer);
|
||||
mDoc.Accept(writer);
|
||||
if (!mDoc.Accept(writer)) {
|
||||
throw DeadlyExportError("Failed to write scene data!");
|
||||
}
|
||||
|
||||
if (outfile->Write(docBuffer.GetString(), docBuffer.GetSize(), 1) != 1) {
|
||||
throw DeadlyExportError("Failed to write scene data!");
|
||||
|
||||
@@ -145,13 +145,13 @@ bool ParseDataURI(const char *const_uri, size_t uriLen, DataURI &out) {
|
||||
size_t i = 5, j;
|
||||
if (uri[i] != ';' && uri[i] != ',') { // has media type?
|
||||
uri[1] = char(i);
|
||||
for (; uri[i] != ';' && uri[i] != ',' && i < uriLen; ++i) {
|
||||
for (;i < uriLen && uri[i] != ';' && uri[i] != ','; ++i) {
|
||||
// nothing to do!
|
||||
}
|
||||
}
|
||||
while (uri[i] == ';' && i < uriLen) {
|
||||
while (i < uriLen && uri[i] == ';') {
|
||||
uri[i++] = '\0';
|
||||
for (j = i; uri[i] != ';' && uri[i] != ',' && i < uriLen; ++i) {
|
||||
for (j = i; i < uriLen && uri[i] != ';' && uri[i] != ','; ++i) {
|
||||
// nothing to do!
|
||||
}
|
||||
|
||||
|
||||
@@ -348,7 +348,7 @@ void glTFExporter::GetMatColorOrTex(const aiMaterial* mat, glTF::TexProperty& pr
|
||||
|
||||
if (path[0] == '*') { // embedded
|
||||
aiTexture* curTex = mScene->mTextures[atoi(&path[1])];
|
||||
|
||||
|
||||
prop.texture->source->name = curTex->mFilename.C_Str();
|
||||
|
||||
uint8_t *data = reinterpret_cast<uint8_t *>(curTex->pcData);
|
||||
|
||||
@@ -1188,9 +1188,11 @@ inline void Node::Read(Value &obj, Asset &r) {
|
||||
}
|
||||
}
|
||||
|
||||
// Do not retrieve a skin here, just take a reference, to avoid infinite recursion
|
||||
// Skins will be properly loaded later
|
||||
Value *curSkin = FindUInt(obj, "skin");
|
||||
if (nullptr != curSkin) {
|
||||
this->skin = r.skins.Retrieve(curSkin->GetUint());
|
||||
this->skin = r.skins.Get(curSkin->GetUint());
|
||||
}
|
||||
|
||||
Value *curCamera = FindUInt(obj, "camera");
|
||||
@@ -1483,7 +1485,7 @@ inline void Asset::Load(const std::string &pFile, bool isBinary) {
|
||||
}
|
||||
}
|
||||
|
||||
// Force reading of skins since they're not always directly referenced
|
||||
// Read skins after nodes have been loaded to avoid infinite recursion
|
||||
if (Value *skinsArray = FindArray(doc, "skins")) {
|
||||
for (unsigned int i = 0; i < skinsArray->Size(); ++i) {
|
||||
skins.Retrieve(i);
|
||||
|
||||
@@ -613,7 +613,9 @@ namespace glTF2 {
|
||||
StringBuffer docBuffer;
|
||||
|
||||
PrettyWriter<StringBuffer> writer(docBuffer);
|
||||
mDoc.Accept(writer);
|
||||
if (!mDoc.Accept(writer)) {
|
||||
throw DeadlyExportError("Failed to write scene data!");
|
||||
}
|
||||
|
||||
if (jsonOutFile->Write(docBuffer.GetString(), docBuffer.GetSize(), 1) != 1) {
|
||||
throw DeadlyExportError("Failed to write scene data!");
|
||||
@@ -664,7 +666,9 @@ namespace glTF2 {
|
||||
|
||||
StringBuffer docBuffer;
|
||||
Writer<StringBuffer> writer(docBuffer);
|
||||
mDoc.Accept(writer);
|
||||
if (!mDoc.Accept(writer)) {
|
||||
throw DeadlyExportError("Failed to write scene data!");
|
||||
}
|
||||
|
||||
uint32_t jsonChunkLength = (docBuffer.GetSize() + 3) & ~3; // Round up to next multiple of 4
|
||||
auto paddingLength = jsonChunkLength - docBuffer.GetSize();
|
||||
@@ -816,5 +820,3 @@ namespace glTF2 {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
@@ -172,6 +172,13 @@ void SetAccessorRange(Ref<Accessor> acc, void* data, size_t count,
|
||||
for (unsigned int j = 0 ; j < numCompsOut ; j++) {
|
||||
double valueTmp = buffer_ptr[j];
|
||||
|
||||
// Gracefully tolerate rogue NaN's in buffer data
|
||||
// Any NaNs/Infs introduced in accessor bounds will end up in
|
||||
// document and prevent rapidjson from writing out valid JSON
|
||||
if (!std::isfinite(valueTmp)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (valueTmp < acc->min[j]) {
|
||||
acc->min[j] = valueTmp;
|
||||
}
|
||||
@@ -348,7 +355,7 @@ void glTF2Exporter::GetMatTex(const aiMaterial* mat, Ref<Texture>& texture, aiTe
|
||||
|
||||
if (path[0] == '*') { // embedded
|
||||
aiTexture* curTex = mScene->mTextures[atoi(&path[1])];
|
||||
|
||||
|
||||
texture->source->name = curTex->mFilename.C_Str();
|
||||
|
||||
// The asset has its own buffer, see Image::SetData
|
||||
@@ -751,7 +758,7 @@ void glTF2Exporter::ExportMeshes()
|
||||
// Normalize all normals as the validator can emit a warning otherwise
|
||||
if ( nullptr != aim->mNormals) {
|
||||
for ( auto i = 0u; i < aim->mNumVertices; ++i ) {
|
||||
aim->mNormals[ i ].Normalize();
|
||||
aim->mNormals[ i ].NormalizeSafe();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -762,7 +769,7 @@ void glTF2Exporter::ExportMeshes()
|
||||
for (int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
|
||||
if (!aim->HasTextureCoords(i))
|
||||
continue;
|
||||
|
||||
|
||||
// Flip UV y coords
|
||||
if (aim -> mNumUVComponents[i] > 1) {
|
||||
for (unsigned int j = 0; j < aim->mNumVertices; ++j) {
|
||||
|
||||
@@ -124,7 +124,7 @@ void FindInvalidDataProcess::Execute(aiScene *pScene) {
|
||||
if (2 == result) {
|
||||
// remove this mesh
|
||||
delete pScene->mMeshes[a];
|
||||
AI_DEBUG_INVALIDATE_PTR(pScene->mMeshes[a]);
|
||||
pScene->mMeshes[a] = NULL;
|
||||
|
||||
meshMapping[a] = UINT_MAX;
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user