diff --git a/code/glTFAsset.h b/code/glTFAsset.h index 4f6c37a3f..1511d28ea 100644 --- a/code/glTFAsset.h +++ b/code/glTFAsset.h @@ -353,6 +353,8 @@ namespace glTF //! Objects marked as special are not exported (used to emulate the binary body buffer) virtual bool IsSpecial() const { return false; } + + virtual ~Object() {} }; @@ -391,8 +393,8 @@ namespace glTF { friend struct Accessor; - uint8_t* data; Accessor& accessor; + uint8_t* data; size_t elemSize, stride; Indexer(Accessor& acc); @@ -535,6 +537,8 @@ namespace glTF std::string mimeType; + int width, height; + private: uint8_t* mData; size_t mDataLength; @@ -770,7 +774,10 @@ namespace glTF void AttachToDocument(Document& doc); void DetachFromDocument(); - void WriteObjects(AssetWriter& writer); + void WriteObjectsImpl(AssetWriter& writer); + + void WriteObjects(AssetWriter& writer) + { WriteObjectsImpl(writer); } Ref Add(T* obj); diff --git a/code/glTFAsset.inl b/code/glTFAsset.inl index 82f7a92f3..df5fa8721 100644 --- a/code/glTFAsset.inl +++ b/code/glTFAsset.inl @@ -61,7 +61,7 @@ namespace { template struct ReadHelper { static bool Read(Value& val, float (&out)[N]) { if (!val.IsArray() || val.Size() != N) return false; - for (int i = 0; i < N; ++i) { + for (size_t i = 0; i < N; ++i) { if (val[i].IsNumber()) out[i] = static_cast(val[i].GetDouble()); } @@ -446,7 +446,9 @@ T Accessor::Indexer::GetValue(int i) } inline Image::Image() - : mData(0) + : width(0) + , height(0) + , mData(0) , mDataLength(0) { @@ -459,8 +461,8 @@ inline void Image::Read(Value& obj, Asset& r) if (r.extensionsUsed.KHR_binary_glTF) { if (Value* ext = FindObject(*extensions, "KHR_binary_glTF")) { - int width = MemberOrDefault(*ext, "width", 0); - int height = MemberOrDefault(*ext, "height", 0); + width = MemberOrDefault(*ext, "width", 0); + height = MemberOrDefault(*ext, "height", 0); ReadMember(*ext, "mimeType", mimeType); @@ -607,25 +609,25 @@ namespace { inline bool GetAttribVector(Mesh::Primitive& p, const char* attr, Mesh::AccessorList*& v, int& pos) { - if (pos = Compare(attr, "POSITION")) { + if ((pos = Compare(attr, "POSITION"))) { v = &(p.attributes.position); } - else if (pos = Compare(attr, "NORMAL")) { + else if ((pos = Compare(attr, "NORMAL"))) { v = &(p.attributes.normal); } - else if (pos = Compare(attr, "TEXCOORD")) { + else if ((pos = Compare(attr, "TEXCOORD"))) { v = &(p.attributes.texcoord); } - else if (pos = Compare(attr, "COLOR")) { + else if ((pos = Compare(attr, "COLOR"))) { v = &(p.attributes.color); } - else if (pos = Compare(attr, "JOINT")) { + else if ((pos = Compare(attr, "JOINT"))) { v = &(p.attributes.joint); } - else if (pos = Compare(attr, "JOINTMATRIX")) { + else if ((pos = Compare(attr, "JOINTMATRIX"))) { v = &(p.attributes.jointmatrix); } - else if (pos = Compare(attr, "WEIGHT")) { + else if ((pos = Compare(attr, "WEIGHT"))) { v = &(p.attributes.weight); } else return false; @@ -647,7 +649,8 @@ inline void Mesh::Read(Value& obj, Asset& r) for (Value::MemberIterator it = attrs->MemberBegin(); it != attrs->MemberEnd(); ++it) { if (!it->value.IsString()) continue; const char* attr = it->name.GetString(); - // Valid attribute semantics include POSITION, NORMAL, TEXCOORD, COLOR, JOINT, JOINTMATRIX, and WEIGHT.Attribute semantics can be of the form[semantic]_[set_index], e.g., TEXCOORD_0, TEXCOORD_1, etc. + // Valid attribute semantics include POSITION, NORMAL, TEXCOORD, COLOR, JOINT, JOINTMATRIX, + // and WEIGHT.Attribute semantics can be of the form[semantic]_[set_index], e.g., TEXCOORD_0, TEXCOORD_1, etc. int undPos = 0; Mesh::AccessorList* vec = 0; @@ -920,7 +923,7 @@ inline void Asset::Load(const std::string& pFile, bool isBinary) if (doc.HasParseError()) { char buffer[32]; - sprintf(buffer, "%u", doc.GetErrorOffset()); + sprintf(buffer, "%d", static_cast(doc.GetErrorOffset())); throw DeadlyImportError(std::string("JSON parse error, offset ") + buffer + ": " + GetParseError_En(doc.GetParseError())); } @@ -1107,12 +1110,12 @@ namespace Util inline char EncodeCharBase64(uint8_t b) { - return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="[b]; + return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="[size_t(b)]; } inline uint8_t DecodeCharBase64(char c) { - return DATA::tableDecodeBase64[c]; // TODO faster with lookup table or ifs? + return DATA::tableDecodeBase64[size_t(c)]; // TODO faster with lookup table or ifs? /*if (c >= 'A' && c <= 'Z') return c - 'A'; if (c >= 'a' && c <= 'z') return c - 'a' + 26; if (c >= '0' && c <= '9') return c - '0' + 52; diff --git a/code/glTFAssetWriter.inl b/code/glTFAssetWriter.inl index d6e313f93..174565ef3 100644 --- a/code/glTFAssetWriter.inl +++ b/code/glTFAssetWriter.inl @@ -190,7 +190,7 @@ namespace glTF { else { for (size_t i = 0; i < lst.size(); ++i) { char buffer[32]; - sprintf(buffer, "%s_%d", semantic, i); + sprintf(buffer, "%s_%d", semantic, int(i)); attrs.AddMember(Value(buffer, w.mAl).Move(), Value(lst[i]->id, w.mAl).Move(), w.mAl); } } @@ -304,52 +304,10 @@ namespace glTF { } - template - void LazyDict::WriteObjects(AssetWriter& w) - { - if (mObjs.empty()) return; - - Value* container = &w.mDoc; - - if (mExtId) { - Value* exts = FindObject(w.mDoc, "extensions"); - if (!exts) { - w.mDoc.AddMember("extensions", Value().SetObject().Move(), w.mDoc.GetAllocator()); - exts = FindObject(w.mDoc, "extensions"); - } - - if (!(container = FindObject(*exts, mExtId))) { - exts->AddMember(StringRef(mExtId), Value().SetObject().Move(), w.mDoc.GetAllocator()); - container = FindObject(*exts, mExtId); - } - } - - Value* dict; - if (!(dict = FindObject(*container, mDictId))) { - container->AddMember(StringRef(mDictId), Value().SetObject().Move(), w.mDoc.GetAllocator()); - dict = FindObject(*container, mDictId); - } - - for (size_t i = 0; i < mObjs.size(); ++i) { - if (mObjs[i]->IsSpecial()) continue; - - Value obj; - obj.SetObject(); - - if (!mObjs[i]->name.empty()) { - obj.AddMember("name", StringRef(mObjs[i]->name.c_str()), w.mAl); - } - - Write(obj, *mObjs[i], w); - - dict->AddMember(StringRef(mObjs[i]->id), obj, w.mAl); - } - } - AssetWriter::AssetWriter(Asset& a) - : mAsset(a) - , mDoc() + : mDoc() + , mAsset(a) , mAl(mDoc.GetAllocator()) { mDoc.SetObject(); @@ -368,7 +326,6 @@ namespace glTF { } } - void AssetWriter::WriteFile(const char* path) { bool isBinary = mAsset.extensionsUsed.KHR_binary_glTF; @@ -484,6 +441,48 @@ namespace glTF { mDoc.AddMember("extensionsUsed", exts, mAl); } + + template + void LazyDict::WriteObjectsImpl(AssetWriter& w) + { + if (mObjs.empty()) return; + + Value* container = &w.mDoc; + + if (mExtId) { + Value* exts = FindObject(w.mDoc, "extensions"); + if (!exts) { + w.mDoc.AddMember("extensions", Value().SetObject().Move(), w.mDoc.GetAllocator()); + exts = FindObject(w.mDoc, "extensions"); + } + + if (!(container = FindObject(*exts, mExtId))) { + exts->AddMember(StringRef(mExtId), Value().SetObject().Move(), w.mDoc.GetAllocator()); + container = FindObject(*exts, mExtId); + } + } + + Value* dict; + if (!(dict = FindObject(*container, mDictId))) { + container->AddMember(StringRef(mDictId), Value().SetObject().Move(), w.mDoc.GetAllocator()); + dict = FindObject(*container, mDictId); + } + + for (size_t i = 0; i < mObjs.size(); ++i) { + if (mObjs[i]->IsSpecial()) continue; + + Value obj; + obj.SetObject(); + + if (!mObjs[i]->name.empty()) { + obj.AddMember("name", StringRef(mObjs[i]->name.c_str()), w.mAl); + } + + Write(obj, *mObjs[i], w); + + dict->AddMember(StringRef(mObjs[i]->id), obj, w.mAl); + } + } } diff --git a/code/glTFExporter.cpp b/code/glTFExporter.cpp index b47e0da24..f11c51362 100644 --- a/code/glTFExporter.cpp +++ b/code/glTFExporter.cpp @@ -338,7 +338,7 @@ void glTFExporter::ExportScene() // root node will be the first one exported (idx 0) if (mAsset->nodes.Size() > 0) { - scene->nodes.push_back(mAsset->nodes.Get(0u)); + scene->nodes.push_back(mAsset->nodes.Get(size_t(0))); } // set as the default scene diff --git a/code/glTFImporter.cpp b/code/glTFImporter.cpp index d62271845..e8f8db96b 100644 --- a/code/glTFImporter.cpp +++ b/code/glTFImporter.cpp @@ -120,10 +120,10 @@ bool glTFImporter::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool -static void CopyValue(const glTF::vec3& v, aiColor3D& out) -{ - out.r = v[0]; out.g = v[1]; out.b = v[2]; -} +//static void CopyValue(const glTF::vec3& v, aiColor3D& out) +//{ +// out.r = v[0]; out.g = v[1]; out.b = v[2]; +//} static void CopyValue(const glTF::vec4& v, aiColor4D& out) { @@ -421,14 +421,14 @@ void glTFImporter::ImportLights(glTF::Asset& r) case Light::Type_directional: ail->mType = aiLightSource_DIRECTIONAL; break; - case Light::Type_point: - ail->mType = aiLightSource_POINT; break; - case Light::Type_spot: ail->mType = aiLightSource_SPOT; break; case Light::Type_ambient: ail->mType = aiLightSource_AMBIENT; break; + + default: // Light::Type_point + ail->mType = aiLightSource_POINT; break; } CopyValue(l.color, ail->mColorAmbient);