cleanup collada xml migration.
This commit is contained in:
@@ -48,7 +48,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "ColladaParser.h"
|
||||
#include <assimp/ParsingUtils.h>
|
||||
#include <assimp/StringUtils.h>
|
||||
#include <assimp/TinyFormatter.h>
|
||||
#include <assimp/ZipArchiveIOSystem.h>
|
||||
#include <assimp/commonMetaData.h>
|
||||
#include <assimp/fast_atof.h>
|
||||
@@ -56,14 +55,24 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
using namespace Assimp;
|
||||
using namespace Assimp::Collada;
|
||||
using namespace Assimp::Formatter;
|
||||
|
||||
static void ReportWarning(const char *msg, ...) {
|
||||
ai_assert(nullptr != msg);
|
||||
|
||||
va_list args;
|
||||
va_start(args, msg);
|
||||
|
||||
char szBuffer[3000];
|
||||
const int iLen = vsprintf(szBuffer, msg, args);
|
||||
ai_assert(iLen > 0);
|
||||
|
||||
va_end(args);
|
||||
ASSIMP_LOG_WARN_F("Validation warning: ", std::string(szBuffer, iLen));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Constructor to be privately used by Importer
|
||||
ColladaParser::ColladaParser(IOSystem *pIOHandler, const std::string &pFile) :
|
||||
@@ -301,11 +310,8 @@ void ColladaParser::ReadAssetInfo(XmlNode &node) {
|
||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
||||
const std::string name = currentNode.name();
|
||||
if (name == "unit") {
|
||||
pugi::xml_attribute attr = currentNode.attribute("meter");
|
||||
mUnitSize = 1.f;
|
||||
if (attr) {
|
||||
mUnitSize = static_cast<ai_real>(attr.as_double());
|
||||
}
|
||||
XmlParser::getFloatAttribute(node, "meter", mUnitSize);
|
||||
} else if (name == "up_axis") {
|
||||
std::string v;
|
||||
XmlParser::getValueAsString(currentNode, v);
|
||||
@@ -349,20 +355,22 @@ void ColladaParser::ReadMetaDataItem(XmlNode &node, StringMetaData &metadata) {
|
||||
}
|
||||
|
||||
std::string v;
|
||||
if (XmlParser::getValueAsString(node, v)) {
|
||||
trim(v);
|
||||
aiString aistr;
|
||||
aistr.Set(v);
|
||||
if (!XmlParser::getValueAsString(node, v)) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string camel_key_str(name);
|
||||
ToCamelCase(camel_key_str);
|
||||
trim(v);
|
||||
aiString aistr;
|
||||
aistr.Set(v);
|
||||
|
||||
size_t found_index;
|
||||
if (FindCommonKey(camel_key_str, key_renaming, found_index)) {
|
||||
metadata.emplace(key_renaming[found_index].second, aistr);
|
||||
} else {
|
||||
metadata.emplace(camel_key_str, aistr);
|
||||
}
|
||||
std::string camel_key_str(name);
|
||||
ToCamelCase(camel_key_str);
|
||||
|
||||
size_t found_index;
|
||||
if (FindCommonKey(camel_key_str, key_renaming, found_index)) {
|
||||
metadata.emplace(key_renaming[found_index].second, aistr);
|
||||
} else {
|
||||
metadata.emplace(camel_key_str, aistr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -469,7 +477,7 @@ void ColladaParser::ReadAnimationLibrary(XmlNode &node) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
||||
for (XmlNode currentNode : node.children()) {
|
||||
const std::string currentName = currentNode.name();
|
||||
if (currentName == "animation") {
|
||||
ReadAnimation(currentNode, &mAnims);
|
||||
@@ -506,7 +514,7 @@ void ColladaParser::ReadAnimation(XmlNode &node, Collada::Animation *pParent) {
|
||||
animID = idAttr.as_string();
|
||||
}
|
||||
|
||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
||||
for (XmlNode currentNode : node.children()) {
|
||||
const std::string currentName = currentNode.name();
|
||||
if (currentName == "animation") {
|
||||
if (!anim) {
|
||||
@@ -563,7 +571,7 @@ void ColladaParser::ReadAnimation(XmlNode &node, Collada::Animation *pParent) {
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Reads an animation sampler into the given anim channel
|
||||
void ColladaParser::ReadAnimationSampler(XmlNode &node, Collada::AnimationChannel &pChannel) {
|
||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
||||
for (XmlNode currentNode : node.children()) {
|
||||
const std::string currentName = currentNode.name();
|
||||
if (currentName == "input") {
|
||||
if (XmlParser::hasAttribute(currentNode, "semantic")) {
|
||||
@@ -618,7 +626,7 @@ void ColladaParser::ReadController(XmlNode &node, Collada::Controller &pControll
|
||||
// initial values
|
||||
pController.mType = Skin;
|
||||
pController.mMethod = Normalized;
|
||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
||||
for (XmlNode currentNode : node.children()) {
|
||||
const std::string ¤tName = currentNode.name();
|
||||
if (currentName == "morph") {
|
||||
pController.mType = Morph;
|
||||
@@ -670,7 +678,7 @@ void ColladaParser::ReadController(XmlNode &node, Collada::Controller &pControll
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Reads the joint definitions for the given controller
|
||||
void ColladaParser::ReadControllerJoints(XmlNode &node, Collada::Controller &pController) {
|
||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
||||
for (XmlNode currentNode : node.children()) {
|
||||
const std::string currentName = currentNode.name();
|
||||
if (currentName == "input") {
|
||||
const char *attrSemantic = currentNode.attribute("semantic").as_string();
|
||||
@@ -698,7 +706,7 @@ void ColladaParser::ReadControllerWeights(XmlNode &node, Collada::Controller &pC
|
||||
int vertexCount=0;
|
||||
XmlParser::getIntAttribute(node, "count", vertexCount);
|
||||
|
||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
||||
for (XmlNode currentNode : node.children()) {
|
||||
std::string currentName = currentNode.name();
|
||||
if (currentName == "input") {
|
||||
InputChannel channel;
|
||||
@@ -763,9 +771,9 @@ void ColladaParser::ReadImageLibrary(XmlNode &node) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
||||
const std::string name = currentNode.name();
|
||||
if (name == "image") {
|
||||
for (XmlNode currentNode : node.children()) {
|
||||
const std::string ¤tName = currentNode.name();
|
||||
if (currentName == "image") {
|
||||
std::string id = currentNode.attribute("id").as_string();
|
||||
mImageLibrary[id] = Image();
|
||||
|
||||
@@ -778,7 +786,7 @@ void ColladaParser::ReadImageLibrary(XmlNode &node) {
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Reads an image entry into the given image
|
||||
void ColladaParser::ReadImage(XmlNode &node, Collada::Image &pImage) {
|
||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
||||
for (XmlNode currentNode : node.children()) {
|
||||
const std::string currentName = currentNode.name();
|
||||
if (currentName == "image") {
|
||||
// Ignore
|
||||
@@ -861,8 +869,7 @@ void ColladaParser::ReadMaterialLibrary(XmlNode &node) {
|
||||
}
|
||||
|
||||
std::map<std::string, int> names;
|
||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
||||
const std::string currentName = currentNode.name();
|
||||
for (XmlNode currentNode : node.children()) {
|
||||
std::string id = currentNode.attribute("id").as_string();
|
||||
std::string name = currentNode.attribute("name").as_string();
|
||||
mMaterialLibrary[id] = Material();
|
||||
@@ -891,7 +898,7 @@ void ColladaParser::ReadLightLibrary(XmlNode &node) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
||||
for (XmlNode currentNode : node.children()) {
|
||||
const std::string ¤tName = currentNode.name();
|
||||
if (currentName == "light") {
|
||||
std::string id = currentNode.attribute("id").as_string();
|
||||
@@ -907,7 +914,7 @@ void ColladaParser::ReadCameraLibrary(XmlNode &node) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
||||
for (XmlNode currentNode : node.children()) {
|
||||
const std::string ¤tName = currentNode.name();
|
||||
if (currentName == "camera") {
|
||||
std::string id = currentNode.attribute("id").as_string();
|
||||
@@ -1032,7 +1039,7 @@ void ColladaParser::ReadEffectLibrary(XmlNode &node) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
||||
for (XmlNode currentNode : node.children()) {
|
||||
const std::string ¤tName = currentNode.name();
|
||||
if (currentName == "effect") {
|
||||
// read ID. Do I have to repeat my ranting about "optional" attributes?
|
||||
@@ -1051,7 +1058,7 @@ void ColladaParser::ReadEffectLibrary(XmlNode &node) {
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Reads an effect entry into the given effect
|
||||
void ColladaParser::ReadEffect(XmlNode &node, Collada::Effect &pEffect) {
|
||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
||||
for (XmlNode currentNode : node.children()) {
|
||||
const std::string ¤tName = currentNode.name();
|
||||
if (currentName == "profile_COMMON") {
|
||||
ReadEffectProfileCommon(currentNode, pEffect);
|
||||
@@ -1330,7 +1337,7 @@ void ColladaParser::ReadGeometryLibrary(XmlNode &node) {
|
||||
if (node.empty()) {
|
||||
return;
|
||||
}
|
||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
||||
for (XmlNode currentNode : node.children()) {
|
||||
const std::string ¤tName = currentNode.name();
|
||||
if (currentName == "geometry") {
|
||||
// read ID. Another entry which is "optional" by design but obligatory in reality
|
||||
@@ -1359,7 +1366,7 @@ void ColladaParser::ReadGeometry(XmlNode &node, Collada::Mesh &pMesh) {
|
||||
if (node.empty()) {
|
||||
return;
|
||||
}
|
||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
||||
for (XmlNode currentNode : node.children()) {
|
||||
const std::string ¤tName = currentNode.name();
|
||||
if (currentName == "mesh") {
|
||||
ReadMesh(currentNode, pMesh);
|
||||
@@ -1383,7 +1390,9 @@ void ColladaParser::ReadMesh(XmlNode &node, Mesh &pMesh) {
|
||||
ReadSource(currentNode);
|
||||
} else if (currentName == "vertices") {
|
||||
ReadVertexData(currentNode, pMesh);
|
||||
} else if (currentName == "triangles" || currentName == "lines" || currentName == "linestrips" || currentName == "polygons" || currentName == "polylist" || currentName == "trifans" || currentName == "tristrips") {
|
||||
} else if (currentName == "triangles" || currentName == "lines" || currentName == "linestrips" ||
|
||||
currentName == "polygons" || currentName == "polylist" || currentName == "trifans" ||
|
||||
currentName == "tristrips") {
|
||||
ReadIndexData(currentNode, pMesh);
|
||||
}
|
||||
}
|
||||
@@ -1575,7 +1584,7 @@ void ColladaParser::ReadAccessor(XmlNode &node, const std::string &pID) {
|
||||
void ColladaParser::ReadVertexData(XmlNode &node, Mesh &pMesh) {
|
||||
// extract the ID of the <vertices> element. Not that we care, but to catch strange referencing schemes we should warn about
|
||||
XmlParser::getStdStrAttribute(node, "id", pMesh.mVertexID);
|
||||
for (XmlNode currentNode = node.first_child(); currentNode; currentNode = currentNode.next_sibling()) {
|
||||
for (XmlNode currentNode : node.children()) {
|
||||
const std::string ¤tName = currentNode.name();
|
||||
if (currentName == "input") {
|
||||
ReadInputChannel(currentNode, pMesh.mPerVertexData);
|
||||
@@ -1733,20 +1742,20 @@ size_t ColladaParser::ReadPrimitives(XmlNode &node, Mesh &pMesh, std::vector<Inp
|
||||
// determine the expected number of indices
|
||||
size_t expectedPointCount = 0;
|
||||
switch (pPrimType) {
|
||||
case Prim_Polylist: {
|
||||
for (size_t i : pVCount)
|
||||
expectedPointCount += i;
|
||||
break;
|
||||
}
|
||||
case Prim_Lines:
|
||||
expectedPointCount = 2 * pNumPrimitives;
|
||||
break;
|
||||
case Prim_Triangles:
|
||||
expectedPointCount = 3 * pNumPrimitives;
|
||||
break;
|
||||
default:
|
||||
// other primitive types don't state the index count upfront... we need to guess
|
||||
break;
|
||||
case Prim_Polylist: {
|
||||
for (size_t i : pVCount)
|
||||
expectedPointCount += i;
|
||||
break;
|
||||
}
|
||||
case Prim_Lines:
|
||||
expectedPointCount = 2 * pNumPrimitives;
|
||||
break;
|
||||
case Prim_Triangles:
|
||||
expectedPointCount = 3 * pNumPrimitives;
|
||||
break;
|
||||
default:
|
||||
// other primitive types don't state the index count upfront... we need to guess
|
||||
break;
|
||||
}
|
||||
|
||||
// and read all indices into a temporary array
|
||||
@@ -2321,20 +2330,6 @@ void ColladaParser::ReadScene(XmlNode &node) {
|
||||
}
|
||||
}
|
||||
|
||||
void ColladaParser::ReportWarning(const char *msg, ...) {
|
||||
ai_assert(nullptr != msg);
|
||||
|
||||
va_list args;
|
||||
va_start(args, msg);
|
||||
|
||||
char szBuffer[3000];
|
||||
const int iLen = vsprintf(szBuffer, msg, args);
|
||||
ai_assert(iLen > 0);
|
||||
|
||||
va_end(args);
|
||||
ASSIMP_LOG_WARN_F("Validation warning: ", std::string(szBuffer, iLen));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Calculates the resulting transformation from all the given transform steps
|
||||
aiMatrix4x4 ColladaParser::CalculateResultTransform(const std::vector<Transform> &pTransforms) const {
|
||||
|
||||
Reference in New Issue
Block a user