From 4d8f41f3aaf846f9b6525560fd005ae097ea06c7 Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Sun, 7 Sep 2008 23:11:29 +0000 Subject: [PATCH] Minor Collada-converter bug fixes This was SVN commit r6342. --- source/collada/PMDConvert.cpp | 20 +++++++++++++------- source/collada/XMLFix.cpp | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/source/collada/PMDConvert.cpp b/source/collada/PMDConvert.cpp index 7345956eca..f89f3fff8c 100644 --- a/source/collada/PMDConvert.cpp +++ b/source/collada/PMDConvert.cpp @@ -42,11 +42,17 @@ struct PropPoint uint8 bone; }; -// this isn't defined anywhere and is needed by FMVector3::Normalize. -// note that CommonConvert mentions that this and other static const -// members aren't exported from the DLL and that the preferred fix -// is to define it there; hopefully the same applies here. -/*static*/ const FMVector3 FMVector3::XAxis(1.0f, 0.0f, 0.0f); +// Based on FMVector3::Normalize, but that function uses a static member +// FMVector3::XAxis which causes irritating linker errors. Rather than trying +// to make that XAxis work in a cross-platform way, just reimplement Normalize: +static FMVector3 FMVector3_Normalize(const FMVector3& vec) +{ + float l = vec.Length(); + if (l > 0.0f) + return FMVector3(vec.x/l, vec.y/l, vec.z/l); + else + return FMVector3(1.0f, 0.0f, 0.0f); +} class PMDConvert { @@ -426,7 +432,7 @@ public: // Apply the scene-node transforms pos = transform.TransformCoordinate(pos); - norm = transform.TransformVector(norm).Normalize(); + norm = FMVector3_Normalize(transform.TransformVector(norm)); // Convert from Y_UP or Z_UP to the game's coordinate system @@ -480,7 +486,7 @@ public: // Apply the scene-node transforms pos = scaledTransform.TransformCoordinate(pos); - norm = scaledTransform.TransformVector(norm).Normalize(); + norm = FMVector3_Normalize(scaledTransform.TransformVector(norm)); // Convert from Y_UP or Z_UP to the game's coordinate system diff --git a/source/collada/XMLFix.cpp b/source/collada/XMLFix.cpp index 670bfd0110..bda9a9ed75 100644 --- a/source/collada/XMLFix.cpp +++ b/source/collada/XMLFix.cpp @@ -152,7 +152,7 @@ void FixBrokenXML(const char* text, const char** out, size_t* outSize) xmlDocPtr doc = xmlParseMemory(text, textSize); xmlNode* root = xmlDocGetRootElement(doc); - if (processDocument(root)) + if (root && processDocument(root)) { // Reserialising the document, then parsing it again inside FCollada, is a bit ugly; // but it's the only way I can see to make it work through FCollada's public API