From f6720271cb7f58084695e9cff2a9f3b3640b4525 Mon Sep 17 00:00:00 2001 From: Yingying Wang Date: Fri, 15 May 2020 12:20:31 -0700 Subject: [PATCH 01/17] sparce accessor exporter --- code/AssetLib/glTF2/glTF2Asset.h | 24 ++++ code/AssetLib/glTF2/glTF2Asset.inl | 130 ++++++++++++++++++- code/AssetLib/glTF2/glTF2AssetWriter.inl | 48 +++++-- code/AssetLib/glTF2/glTF2Exporter.cpp | 156 ++++++++++++++++++++++- 4 files changed, 346 insertions(+), 12 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Asset.h b/code/AssetLib/glTF2/glTF2Asset.h index 48dab24a7..a60ac98f3 100644 --- a/code/AssetLib/glTF2/glTF2Asset.h +++ b/code/AssetLib/glTF2/glTF2Asset.h @@ -367,6 +367,7 @@ struct Object { //! An accessor provides a typed view into a BufferView or a subset of a BufferView //! similar to how WebGL's vertexAttribPointer() defines an attribute in a buffer. struct Accessor : public Object { + struct Sparse; //wangyi 0506 Ref bufferView; //!< The ID of the bufferView. (required) size_t byteOffset; //!< The offset relative to the start of the bufferView in bytes. (required) ComponentType componentType; //!< The datatype of components in the attribute. (required) @@ -374,6 +375,7 @@ struct Accessor : public Object { AttribType::Value type; //!< Specifies if the attribute is a scalar, vector, or matrix. (required) std::vector max; //!< Maximum value of each component in this attribute. std::vector min; //!< Minimum value of each component in this attribute. + std::unique_ptr sparse; //wangyi 0506 unsigned int GetNumComponents(); unsigned int GetBytesPerComponent(); @@ -385,6 +387,10 @@ struct Accessor : public Object { void ExtractData(T *&outData); void WriteData(size_t count, const void *src_buffer, size_t src_stride); + //wangyi 0506 + void WriteSparseValues(size_t count, const void *src_data, size_t src_dataStride); + void WriteSparseIndices(size_t count, const void *src_idx, size_t src_idxStride); + //! Helper class to iterate the data class Indexer { @@ -423,6 +429,22 @@ struct Accessor : public Object { Accessor() {} void Read(Value &obj, Asset &r); + + //wangyi 0506 + //sparse + struct Sparse { + size_t count; + ComponentType indicesType; + Ref indices; + size_t indicesByteOffset; + Ref values; + size_t valuesByteOffset; + + std::vector data; //!< Actual data, which may be defaulted to an array of zeros or the original data, with the sparse buffer view applied on top of it. + + void PopulateData(size_t numBytes, uint8_t *bytes); + void PatchData(unsigned int elementSize); + }; }; //! A buffer points to binary geometry, animation, or skins. @@ -555,6 +577,8 @@ struct BufferView : public Object { BufferViewTarget target; //! The target that the WebGL buffer should be bound to. void Read(Value &obj, Asset &r); + //wangyi 0506 + uint8_t *GetPointer(size_t accOffset); }; struct Camera : public Object { diff --git a/code/AssetLib/glTF2/glTF2Asset.inl b/code/AssetLib/glTF2/glTF2Asset.inl index 881fd4efc..09fd48761 100644 --- a/code/AssetLib/glTF2/glTF2Asset.inl +++ b/code/AssetLib/glTF2/glTF2Asset.inl @@ -550,10 +550,67 @@ inline void BufferView::Read(Value &obj, Asset &r) { byteStride = MemberOrDefault(obj, "byteStride", 0u); } +//wangyi 0506 +inline uint8_t *BufferView::GetPointer(size_t accOffset) { + if (!buffer) return 0; + uint8_t *basePtr = buffer->GetPointer(); + if (!basePtr) return 0; + + size_t offset = accOffset + byteOffset; + if (buffer->EncodedRegion_Current != nullptr) { + const size_t begin = buffer->EncodedRegion_Current->Offset; + const size_t end = begin + buffer->EncodedRegion_Current->DecodedData_Length; + if ((offset >= begin) && (offset < end)) + return &buffer->EncodedRegion_Current->DecodedData[offset - begin]; + } + + return basePtr + offset; +} + // // struct Accessor // +//wangyi 0506 +inline void Accessor::Sparse::PopulateData(size_t numBytes, uint8_t *bytes) { + if (bytes) { + data.assign(bytes, bytes + numBytes); + } else { + data.resize(numBytes, 0x00); + } +} + +inline void Accessor::Sparse::PatchData(unsigned int elementSize) { + uint8_t *pIndices = indices->GetPointer(indicesByteOffset); + const unsigned int indexSize = int(ComponentTypeSize(indicesType)); + uint8_t *indicesEnd = pIndices + count * indexSize; + + uint8_t *pValues = values->GetPointer(valuesByteOffset); + while (pIndices != indicesEnd) { + size_t offset; + switch (indicesType) { + case ComponentType_UNSIGNED_BYTE: + offset = *pIndices; + break; + case ComponentType_UNSIGNED_SHORT: + offset = *reinterpret_cast(pIndices); + break; + case ComponentType_UNSIGNED_INT: + offset = *reinterpret_cast(pIndices); + break; + default: + // have fun with float and negative values from signed types as indices. + throw DeadlyImportError("Unsupported component type in index."); + } + + offset *= elementSize; + std::memcpy(data.data() + offset, pValues, elementSize); + + pValues += elementSize; + pIndices += indexSize; + } +} +// wangyi 0506 inline void Accessor::Read(Value &obj, Asset &r) { if (Value *bufferViewVal = FindUInt(obj, "bufferView")) { @@ -566,6 +623,43 @@ inline void Accessor::Read(Value &obj, Asset &r) { const char *typestr; type = ReadMember(obj, "type", typestr) ? AttribType::FromString(typestr) : AttribType::SCALAR; + + //wangyi 0506 + if (Value *sparseValue = FindObject(obj, "sparse")) { + sparse.reset(new Sparse); + // count + ReadMember(*sparseValue, "count", sparse->count); + + // indices + if (Value *indicesValue = FindObject(*sparseValue, "indices")) { + //indices bufferView + Value *indiceViewID = FindUInt(*indicesValue, "bufferView"); + sparse->indices = r.bufferViews.Retrieve(indiceViewID->GetUint()); + //indices byteOffset + sparse->indicesByteOffset = MemberOrDefault(*indicesValue, "byteOffset", size_t(0)); + //indices componentType + sparse->indicesType = MemberOrDefault(*indicesValue, "componentType", ComponentType_BYTE); + //sparse->indices->Read(*indicesValue, r); + } + + // value + if (Value *valuesValue = FindObject(*sparseValue, "values")) { + //value bufferView + Value *valueViewID = FindUInt(*valuesValue, "bufferView"); + sparse->values = r.bufferViews.Retrieve(valueViewID->GetUint()); + //value byteOffset + sparse->valuesByteOffset = MemberOrDefault(*valuesValue, "byteOffset", size_t(0)); + //sparse->values->Read(*valuesValue, r); + } + + // indicesType + sparse->indicesType = MemberOrDefault(*sparseValue, "componentType", ComponentType_UNSIGNED_SHORT); + + const unsigned int elementSize = GetElementSize(); + const size_t dataSize = count * elementSize; + sparse->PopulateData(dataSize, bufferView ? bufferView->GetPointer(byteOffset) : 0); + sparse->PatchData(elementSize); + } } inline unsigned int Accessor::GetNumComponents() { @@ -580,7 +674,11 @@ inline unsigned int Accessor::GetElementSize() { return GetNumComponents() * GetBytesPerComponent(); } +// wangyi 0506 inline uint8_t *Accessor::GetPointer() { + if (sparse) + return sparse->data.data(); + if (!bufferView || !bufferView->buffer) return 0; uint8_t *basePtr = bufferView->buffer->GetPointer(); if (!basePtr) return 0; @@ -635,7 +733,8 @@ void Accessor::ExtractData(T *&outData) const size_t targetElemSize = sizeof(T); ai_assert(elemSize <= targetElemSize); - ai_assert(count * stride <= bufferView->byteLength); + //wangyi 0506 + ai_assert(count * stride <= (bufferView ? bufferView->byteLength : sparse->data.size())); outData = new T[count]; if (stride == elemSize && targetElemSize == elemSize) { @@ -660,6 +759,35 @@ inline void Accessor::WriteData(size_t _count, const void *src_buffer, size_t sr CopyData(_count, src, src_stride, dst, dst_stride); } +//wangyi 0506 +inline void Accessor::WriteSparseValues(size_t _count, const void *src_data, size_t src_dataStride) { + if (!sparse) + return; + + // values + uint8_t *value_buffer_ptr = sparse->values->buffer->GetPointer(); + size_t value_offset = sparse->valuesByteOffset + sparse->values->byteOffset; + size_t value_dst_stride = GetNumComponents() * GetBytesPerComponent(); + const uint8_t *value_src = reinterpret_cast(src_data); + uint8_t *value_dst = reinterpret_cast(value_buffer_ptr + value_offset); + ai_assert(value_dst + _count * value_dst_stride <= value_buffer_ptr + sparse->values->buffer->byteLength); + CopyData(_count, value_src, src_dataStride, value_dst, value_dst_stride); +} + +//wangyi 0506 +inline void Accessor::WriteSparseIndices(size_t _count, const void *src_idx, size_t src_idxStride) { + if (!sparse) + return; + + // indices + uint8_t *indices_buffer_ptr = sparse->indices->buffer->GetPointer(); + size_t indices_offset = sparse->indicesByteOffset + sparse->indices->byteOffset; + size_t indices_dst_stride = 1 * sizeof(unsigned short); + const uint8_t *indices_src = reinterpret_cast(src_idx); + uint8_t *indices_dst = reinterpret_cast(indices_buffer_ptr + indices_offset); + ai_assert(indices_dst + _count * indices_dst_stride <= indices_buffer_ptr + sparse->indices->buffer->byteLength); + CopyData(_count, indices_src, src_idxStride, indices_dst, indices_dst_stride); +} inline Accessor::Indexer::Indexer(Accessor &acc) : accessor(acc), data(acc.GetPointer()), elemSize(acc.GetElementSize()), stride(acc.bufferView && acc.bufferView->byteStride ? acc.bufferView->byteStride : elemSize) { } diff --git a/code/AssetLib/glTF2/glTF2AssetWriter.inl b/code/AssetLib/glTF2/glTF2AssetWriter.inl index 798f38c1c..5e936384f 100644 --- a/code/AssetLib/glTF2/glTF2AssetWriter.inl +++ b/code/AssetLib/glTF2/glTF2AssetWriter.inl @@ -107,21 +107,49 @@ namespace glTF2 { inline void Write(Value& obj, Accessor& a, AssetWriter& w) { - obj.AddMember("bufferView", a.bufferView->index, w.mAl); - obj.AddMember("byteOffset", (unsigned int)a.byteOffset, w.mAl); + //wangyi 0506 + if (a.bufferView) { + obj.AddMember("bufferView", a.bufferView->index, w.mAl); + obj.AddMember("byteOffset", (unsigned int)a.byteOffset, w.mAl); + Value vTmpMax, vTmpMin; + if (a.componentType == ComponentType_FLOAT) { + obj.AddMember("max", MakeValue(vTmpMax, a.max, w.mAl), w.mAl); + obj.AddMember("min", MakeValue(vTmpMin, a.min, w.mAl), w.mAl); + } else { + obj.AddMember("max", MakeValueCast(vTmpMax, a.max, w.mAl), w.mAl); + obj.AddMember("min", MakeValueCast(vTmpMin, a.min, w.mAl), w.mAl); + } + } obj.AddMember("componentType", int(a.componentType), w.mAl); obj.AddMember("count", (unsigned int)a.count, w.mAl); obj.AddMember("type", StringRef(AttribType::ToString(a.type)), w.mAl); - Value vTmpMax, vTmpMin; - if (a.componentType == ComponentType_FLOAT) { - obj.AddMember("max", MakeValue(vTmpMax, a.max, w.mAl), w.mAl); - obj.AddMember("min", MakeValue(vTmpMin, a.min, w.mAl), w.mAl); - } else { - obj.AddMember("max", MakeValueCast(vTmpMax, a.max, w.mAl), w.mAl); - obj.AddMember("min", MakeValueCast(vTmpMin, a.min, w.mAl), w.mAl); - } + // wangyi 0506 + if (a.sparse) { + Value sparseValue; + sparseValue.SetObject(); + + //count + sparseValue.AddMember("count", (unsigned int)a.sparse->count, w.mAl); + + //indices + Value indices; + indices.SetObject(); + indices.AddMember("bufferView", a.sparse->indices->index, w.mAl); + indices.AddMember("byteOffset", (unsigned int)a.sparse->indicesByteOffset, w.mAl); + indices.AddMember("componentType", int(a.sparse->indicesType), w.mAl); + sparseValue.AddMember("indices", indices, w.mAl); + + //values + Value values; + values.SetObject(); + values.AddMember("bufferView", a.sparse->values->index, w.mAl); + values.AddMember("byteOffset", (unsigned int)a.sparse->valuesByteOffset, w.mAl); + sparseValue.AddMember("values", values, w.mAl); + + obj.AddMember("sparse", sparseValue, w.mAl); + } } inline void Write(Value& obj, Animation& a, AssetWriter& w) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index da6d9ab2e..8d6471db2 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -207,6 +207,152 @@ inline void SetAccessorRange(ComponentType compType, Ref acc, void* da } } +// wangyi 0506 +// compute the (data-dataBase), store the non-zero data items +template +size_t NZDiff(void *data, void *dataBase, size_t count, unsigned int numCompsIn, unsigned int numCompsOut, void *&outputNZDiff, void *&outputNZIdx) { + std::vector vNZDiff; + std::vector vNZIdx; + size_t totalComps = count * numCompsIn; + T *bufferData_ptr = static_cast(data); + T *bufferData_end = bufferData_ptr + totalComps; + T *bufferBase_ptr = static_cast(dataBase); + + // Search and set extreme values. + for (short idx = 0; bufferData_ptr < bufferData_end; idx += 1, bufferData_ptr += numCompsIn) { + bool bNonZero = false; + + //for the data, check any component Non Zero + for (unsigned int j = 0; j < numCompsOut; j++) { + double valueData = bufferData_ptr[j]; + double valueBase = bufferBase_ptr ? bufferBase_ptr[j] : 0; + if ((valueData - valueBase) != 0) { + bNonZero = true; + break; + } + } + + //all zeros, continue + if (!bNonZero) + continue; + + //non zero, store the data + for (unsigned int j = 0; j < numCompsOut; j++) { + T valueData = bufferData_ptr[j]; + T valueBase = bufferBase_ptr ? bufferBase_ptr[j] : 0; + vNZDiff.push_back(valueData - valueBase); + } + vNZIdx.push_back(idx); + } + + //process data + outputNZDiff = new T[vNZDiff.size()]; + memcpy(outputNZDiff, vNZDiff.data(), vNZDiff.size() * sizeof(T)); + + outputNZIdx = new unsigned short[vNZIdx.size()]; + memcpy(outputNZIdx, vNZIdx.data(), vNZIdx.size() * sizeof(unsigned short)); + return vNZIdx.size(); +} + +inline size_t NZDiff(ComponentType compType, void *data, void *dataBase, size_t count, unsigned int numCompsIn, unsigned int numCompsOut, void *&nzDiff, void *&nzIdx) { + switch (compType) { + case ComponentType_SHORT: + return NZDiff(data, dataBase, count, numCompsIn, numCompsOut, nzDiff, nzIdx); + case ComponentType_UNSIGNED_SHORT: + return NZDiff(data, dataBase, count, numCompsIn, numCompsOut, nzDiff, nzIdx); + case ComponentType_UNSIGNED_INT: + return NZDiff(data, dataBase, count, numCompsIn, numCompsOut, nzDiff, nzIdx); + case ComponentType_FLOAT: + return NZDiff(data, dataBase, count, numCompsIn, numCompsOut, nzDiff, nzIdx); + case ComponentType_BYTE: + return NZDiff(data, dataBase, count, numCompsIn, numCompsOut, nzDiff, nzIdx); + case ComponentType_UNSIGNED_BYTE: + return NZDiff(data, dataBase, count, numCompsIn, numCompsOut, nzDiff, nzIdx); + } + return 0; +} +// wangyi 0506 +inline Ref ExportDataSparse(Asset &a, std::string &meshName, Ref &buffer, + size_t count, void *data, AttribType::Value typeIn, AttribType::Value typeOut, ComponentType compType, BufferViewTarget target = BufferViewTarget_NONE, void *dataBase = 0) { + if (!count || !data) { + return Ref(); + } + + unsigned int numCompsIn = AttribType::GetNumComponents(typeIn); + unsigned int numCompsOut = AttribType::GetNumComponents(typeOut); + unsigned int bytesPerComp = ComponentTypeSize(compType); + + // accessor + Ref acc = a.accessors.Create(a.FindUniqueID(meshName, "accessor")); + + // if there is a basic data vector + if (dataBase) { + size_t base_offset = buffer->byteLength; + size_t base_padding = base_offset % bytesPerComp; + base_offset += base_padding; + size_t base_length = count * numCompsOut * bytesPerComp; + buffer->Grow(base_length + base_padding); + + Ref bv = a.bufferViews.Create(a.FindUniqueID(meshName, "view")); + bv->buffer = buffer; + bv->byteOffset = base_offset; + bv->byteLength = base_length; //! The target that the WebGL buffer should be bound to. + bv->byteStride = 0; + bv->target = target; + acc->bufferView = bv; + acc->WriteData(count, dataBase, numCompsIn * bytesPerComp); + } + acc->byteOffset = 0; + acc->componentType = compType; + acc->count = count; + acc->type = typeOut; + + if (data) { + void *nzDiff = 0, *nzIdx = 0; + size_t nzCount = NZDiff(compType, data, dataBase, count, numCompsIn, numCompsOut, nzDiff, nzIdx); + acc->sparse.reset(new Accessor::Sparse); + acc->sparse->count = nzCount; + + //indices + unsigned int bytesPerIdx = sizeof(unsigned short); + size_t indices_offset = buffer->byteLength; + size_t indices_padding = indices_offset % bytesPerIdx; + indices_offset += indices_padding; + size_t indices_length = nzCount * 1 * bytesPerIdx; + buffer->Grow(indices_length + indices_padding); + + Ref indicesBV = a.bufferViews.Create(a.FindUniqueID(meshName, "view")); + indicesBV->buffer = buffer; + indicesBV->byteOffset = indices_offset; + indicesBV->byteLength = indices_length; + indicesBV->byteStride = 0; + acc->sparse->indices = indicesBV; + acc->sparse->indicesType = ComponentType_UNSIGNED_SHORT; + acc->sparse->indicesByteOffset = 0; + acc->WriteSparseIndices(nzCount, nzIdx, 1 * bytesPerIdx); + + //values + size_t values_offset = buffer->byteLength; + size_t values_padding = values_offset % bytesPerComp; + values_offset += values_padding; + size_t values_length = nzCount * numCompsOut * bytesPerComp; + buffer->Grow(values_length + values_padding); + + Ref valuesBV = a.bufferViews.Create(a.FindUniqueID(meshName, "view")); + valuesBV->buffer = buffer; + valuesBV->byteOffset = values_offset; + valuesBV->byteLength = values_length; + valuesBV->byteStride = 0; + acc->sparse->values = valuesBV; + acc->sparse->valuesByteOffset = 0; + acc->WriteSparseValues(nzCount, nzDiff, numCompsIn * bytesPerComp); + + //clear + delete[] nzDiff; + delete[] nzIdx; + } + return acc; +} inline Ref ExportData(Asset& a, std::string& meshName, Ref& buffer, size_t count, void* data, AttribType::Value typeIn, AttribType::Value typeOut, ComponentType compType, BufferViewTarget target = BufferViewTarget_NONE) { @@ -828,7 +974,11 @@ void glTF2Exporter::ExportMeshes() for (unsigned int vt = 0; vt < pAnimMesh->mNumVertices; ++vt) { pPositionDiff[vt] = pAnimMesh->mVertices[vt] - aim->mVertices[vt]; } - Ref vec = ExportData(*mAsset, meshId, b, + /*Ref vec = ExportData(*mAsset, meshId, b, + pAnimMesh->mNumVertices, pPositionDiff, + AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);*/ + //wangyi 0506 + Ref vec = ExportDataSparse(*mAsset, meshId, b, pAnimMesh->mNumVertices, pPositionDiff, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT); if (vec) { @@ -843,6 +993,10 @@ void glTF2Exporter::ExportMeshes() for (unsigned int vt = 0; vt < pAnimMesh->mNumVertices; ++vt) { pNormalDiff[vt] = pAnimMesh->mNormals[vt] - aim->mNormals[vt]; } + /*Ref vec = ExportData(*mAsset, meshId, b, + pAnimMesh->mNumVertices, pNormalDiff, + AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);*/ + //wangyi 0506 Ref vec = ExportData(*mAsset, meshId, b, pAnimMesh->mNumVertices, pNormalDiff, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT); From b8e39b58d1a5101b88032de00029c3b40d8bf750 Mon Sep 17 00:00:00 2001 From: Yingying Wang Date: Fri, 15 May 2020 12:32:58 -0700 Subject: [PATCH 02/17] clean up --- code/AssetLib/glTF2/glTF2Asset.h | 7 ++----- code/AssetLib/glTF2/glTF2Asset.inl | 10 +--------- code/AssetLib/glTF2/glTF2AssetWriter.inl | 2 -- code/AssetLib/glTF2/glTF2Exporter.cpp | 21 ++++++++++----------- 4 files changed, 13 insertions(+), 27 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Asset.h b/code/AssetLib/glTF2/glTF2Asset.h index a60ac98f3..b413f1fe7 100644 --- a/code/AssetLib/glTF2/glTF2Asset.h +++ b/code/AssetLib/glTF2/glTF2Asset.h @@ -367,7 +367,7 @@ struct Object { //! An accessor provides a typed view into a BufferView or a subset of a BufferView //! similar to how WebGL's vertexAttribPointer() defines an attribute in a buffer. struct Accessor : public Object { - struct Sparse; //wangyi 0506 + struct Sparse; Ref bufferView; //!< The ID of the bufferView. (required) size_t byteOffset; //!< The offset relative to the start of the bufferView in bytes. (required) ComponentType componentType; //!< The datatype of components in the attribute. (required) @@ -375,7 +375,7 @@ struct Accessor : public Object { AttribType::Value type; //!< Specifies if the attribute is a scalar, vector, or matrix. (required) std::vector max; //!< Maximum value of each component in this attribute. std::vector min; //!< Minimum value of each component in this attribute. - std::unique_ptr sparse; //wangyi 0506 + std::unique_ptr sparse; unsigned int GetNumComponents(); unsigned int GetBytesPerComponent(); @@ -387,7 +387,6 @@ struct Accessor : public Object { void ExtractData(T *&outData); void WriteData(size_t count, const void *src_buffer, size_t src_stride); - //wangyi 0506 void WriteSparseValues(size_t count, const void *src_data, size_t src_dataStride); void WriteSparseIndices(size_t count, const void *src_idx, size_t src_idxStride); @@ -430,7 +429,6 @@ struct Accessor : public Object { Accessor() {} void Read(Value &obj, Asset &r); - //wangyi 0506 //sparse struct Sparse { size_t count; @@ -577,7 +575,6 @@ struct BufferView : public Object { BufferViewTarget target; //! The target that the WebGL buffer should be bound to. void Read(Value &obj, Asset &r); - //wangyi 0506 uint8_t *GetPointer(size_t accOffset); }; diff --git a/code/AssetLib/glTF2/glTF2Asset.inl b/code/AssetLib/glTF2/glTF2Asset.inl index 09fd48761..b81d73eda 100644 --- a/code/AssetLib/glTF2/glTF2Asset.inl +++ b/code/AssetLib/glTF2/glTF2Asset.inl @@ -550,7 +550,6 @@ inline void BufferView::Read(Value &obj, Asset &r) { byteStride = MemberOrDefault(obj, "byteStride", 0u); } -//wangyi 0506 inline uint8_t *BufferView::GetPointer(size_t accOffset) { if (!buffer) return 0; uint8_t *basePtr = buffer->GetPointer(); @@ -571,7 +570,6 @@ inline uint8_t *BufferView::GetPointer(size_t accOffset) { // struct Accessor // -//wangyi 0506 inline void Accessor::Sparse::PopulateData(size_t numBytes, uint8_t *bytes) { if (bytes) { data.assign(bytes, bytes + numBytes); @@ -610,7 +608,7 @@ inline void Accessor::Sparse::PatchData(unsigned int elementSize) { pIndices += indexSize; } } -// wangyi 0506 + inline void Accessor::Read(Value &obj, Asset &r) { if (Value *bufferViewVal = FindUInt(obj, "bufferView")) { @@ -624,7 +622,6 @@ inline void Accessor::Read(Value &obj, Asset &r) { const char *typestr; type = ReadMember(obj, "type", typestr) ? AttribType::FromString(typestr) : AttribType::SCALAR; - //wangyi 0506 if (Value *sparseValue = FindObject(obj, "sparse")) { sparse.reset(new Sparse); // count @@ -674,7 +671,6 @@ inline unsigned int Accessor::GetElementSize() { return GetNumComponents() * GetBytesPerComponent(); } -// wangyi 0506 inline uint8_t *Accessor::GetPointer() { if (sparse) return sparse->data.data(); @@ -732,8 +728,6 @@ void Accessor::ExtractData(T *&outData) const size_t targetElemSize = sizeof(T); ai_assert(elemSize <= targetElemSize); - - //wangyi 0506 ai_assert(count * stride <= (bufferView ? bufferView->byteLength : sparse->data.size())); outData = new T[count]; @@ -759,7 +753,6 @@ inline void Accessor::WriteData(size_t _count, const void *src_buffer, size_t sr CopyData(_count, src, src_stride, dst, dst_stride); } -//wangyi 0506 inline void Accessor::WriteSparseValues(size_t _count, const void *src_data, size_t src_dataStride) { if (!sparse) return; @@ -774,7 +767,6 @@ inline void Accessor::WriteSparseValues(size_t _count, const void *src_data, siz CopyData(_count, value_src, src_dataStride, value_dst, value_dst_stride); } -//wangyi 0506 inline void Accessor::WriteSparseIndices(size_t _count, const void *src_idx, size_t src_idxStride) { if (!sparse) return; diff --git a/code/AssetLib/glTF2/glTF2AssetWriter.inl b/code/AssetLib/glTF2/glTF2AssetWriter.inl index 5e936384f..6d7e28738 100644 --- a/code/AssetLib/glTF2/glTF2AssetWriter.inl +++ b/code/AssetLib/glTF2/glTF2AssetWriter.inl @@ -107,7 +107,6 @@ namespace glTF2 { inline void Write(Value& obj, Accessor& a, AssetWriter& w) { - //wangyi 0506 if (a.bufferView) { obj.AddMember("bufferView", a.bufferView->index, w.mAl); obj.AddMember("byteOffset", (unsigned int)a.byteOffset, w.mAl); @@ -125,7 +124,6 @@ namespace glTF2 { obj.AddMember("count", (unsigned int)a.count, w.mAl); obj.AddMember("type", StringRef(AttribType::ToString(a.type)), w.mAl); - // wangyi 0506 if (a.sparse) { Value sparseValue; sparseValue.SetObject(); diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index 8d6471db2..41fe4c9c8 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -207,7 +207,6 @@ inline void SetAccessorRange(ComponentType compType, Ref acc, void* da } } -// wangyi 0506 // compute the (data-dataBase), store the non-zero data items template size_t NZDiff(void *data, void *dataBase, size_t count, unsigned int numCompsIn, unsigned int numCompsOut, void *&outputNZDiff, void *&outputNZIdx) { @@ -271,7 +270,7 @@ inline size_t NZDiff(ComponentType compType, void *data, void *dataBase, size_t } return 0; } -// wangyi 0506 + inline Ref ExportDataSparse(Asset &a, std::string &meshName, Ref &buffer, size_t count, void *data, AttribType::Value typeIn, AttribType::Value typeOut, ComponentType compType, BufferViewTarget target = BufferViewTarget_NONE, void *dataBase = 0) { if (!count || !data) { @@ -974,13 +973,13 @@ void glTF2Exporter::ExportMeshes() for (unsigned int vt = 0; vt < pAnimMesh->mNumVertices; ++vt) { pPositionDiff[vt] = pAnimMesh->mVertices[vt] - aim->mVertices[vt]; } - /*Ref vec = ExportData(*mAsset, meshId, b, - pAnimMesh->mNumVertices, pPositionDiff, - AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);*/ - //wangyi 0506 - Ref vec = ExportDataSparse(*mAsset, meshId, b, + Ref vec = ExportData(*mAsset, meshId, b, pAnimMesh->mNumVertices, pPositionDiff, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT); + /* sparse + Ref vec = ExportDataSparse(*mAsset, meshId, b, + pAnimMesh->mNumVertices, pPositionDiff, + AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);*/ if (vec) { p.targets[am].position.push_back(vec); } @@ -993,13 +992,13 @@ void glTF2Exporter::ExportMeshes() for (unsigned int vt = 0; vt < pAnimMesh->mNumVertices; ++vt) { pNormalDiff[vt] = pAnimMesh->mNormals[vt] - aim->mNormals[vt]; } - /*Ref vec = ExportData(*mAsset, meshId, b, - pAnimMesh->mNumVertices, pNormalDiff, - AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);*/ - //wangyi 0506 Ref vec = ExportData(*mAsset, meshId, b, pAnimMesh->mNumVertices, pNormalDiff, AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT); + /* sparse + Ref vec = ExportDataSparse(*mAsset, meshId, b, + pAnimMesh->mNumVertices, pNormalDiff, + AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);*/ if (vec) { p.targets[am].normal.push_back(vec); } From 50f0a86798399d474495da22d045d4da543ed481 Mon Sep 17 00:00:00 2001 From: Yingying Wang Date: Tue, 19 May 2020 16:10:41 -0700 Subject: [PATCH 03/17] conditional export --- code/AssetLib/glTF2/glTF2Exporter.cpp | 45 +++++++++++++++++---------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index 088503636..072809dc4 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -969,10 +969,15 @@ void glTF2Exporter::ExportMeshes() /*************** Targets for blendshapes ****************/ if (aim->mNumAnimMeshes > 0) { + //wangyi 0506 + bool bUseSparse = this->mProperties->HasPropertyBool("GLTF2_SPARSE_ACCESSOR_EXP") && + this->mProperties->GetPropertyBool("GLTF2_SPARSE_ACCESSOR_EXP"); + bool bIncludeNormal = this->mProperties->HasPropertyBool("GLTF2_TARGET_NORMAL_EXP") && + this->mProperties->GetPropertyBool("GLTF2_TARGET_NORMAL_EXP"); + p.targets.resize(aim->mNumAnimMeshes); for (unsigned int am = 0; am < aim->mNumAnimMeshes; ++am) { aiAnimMesh *pAnimMesh = aim->mAnimMeshes[am]; - // position if (pAnimMesh->HasPositions()) { // NOTE: in gltf it is the diff stored @@ -980,13 +985,17 @@ void glTF2Exporter::ExportMeshes() for (unsigned int vt = 0; vt < pAnimMesh->mNumVertices; ++vt) { pPositionDiff[vt] = pAnimMesh->mVertices[vt] - aim->mVertices[vt]; } - Ref vec = ExportData(*mAsset, meshId, b, - pAnimMesh->mNumVertices, pPositionDiff, - AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT); - /* sparse - Ref vec = ExportDataSparse(*mAsset, meshId, b, - pAnimMesh->mNumVertices, pPositionDiff, - AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);*/ + //wangyi 0506 + Ref vec; + if (bUseSparse) { + vec = ExportDataSparse(*mAsset, meshId, b, + pAnimMesh->mNumVertices, pPositionDiff, + AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT); + } else { + vec = ExportData(*mAsset, meshId, b, + pAnimMesh->mNumVertices, pPositionDiff, + AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT); + } if (vec) { p.targets[am].position.push_back(vec); } @@ -994,18 +1003,22 @@ void glTF2Exporter::ExportMeshes() } // normal - if (pAnimMesh->HasNormals()) { + if (pAnimMesh->HasNormals() && bIncludeNormal) { aiVector3D *pNormalDiff = new aiVector3D[pAnimMesh->mNumVertices]; for (unsigned int vt = 0; vt < pAnimMesh->mNumVertices; ++vt) { pNormalDiff[vt] = pAnimMesh->mNormals[vt] - aim->mNormals[vt]; } - Ref vec = ExportData(*mAsset, meshId, b, - pAnimMesh->mNumVertices, pNormalDiff, - AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT); - /* sparse - Ref vec = ExportDataSparse(*mAsset, meshId, b, - pAnimMesh->mNumVertices, pNormalDiff, - AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);*/ + //wangyi 0506 + Ref vec; + if (bUseSparse) { + vec = ExportDataSparse(*mAsset, meshId, b, + pAnimMesh->mNumVertices, pNormalDiff, + AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT); + } else { + vec = ExportData(*mAsset, meshId, b, + pAnimMesh->mNumVertices, pNormalDiff, + AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT); + } if (vec) { p.targets[am].normal.push_back(vec); } From 87584eb007df4dda029cbac5e328941742129d5d Mon Sep 17 00:00:00 2001 From: FRICOTEAUX Date: Thu, 28 May 2020 11:05:38 +0200 Subject: [PATCH 04/17] glTF2: fix "file size doesn't match" issue when importing GLB in Blender --- code/glTF2/glTF2AssetWriter.inl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/code/glTF2/glTF2AssetWriter.inl b/code/glTF2/glTF2AssetWriter.inl index 02c14980d..f9bbb7ef7 100644 --- a/code/glTF2/glTF2AssetWriter.inl +++ b/code/glTF2/glTF2AssetWriter.inl @@ -672,10 +672,13 @@ namespace glTF2 { // Binary chunk // + int GLB_Chunk_count = 1; uint32_t binaryChunkLength = 0; if (bodyBuffer->byteLength > 0) { binaryChunkLength = (bodyBuffer->byteLength + 3) & ~3; // Round up to next multiple of 4 - auto paddingLength = binaryChunkLength - bodyBuffer->byteLength; + + auto curPaddingLength = binaryChunkLength - bodyBuffer->byteLength; + ++GLB_Chunk_count; GLB_Chunk binaryChunk; binaryChunk.chunkLength = binaryChunkLength; @@ -690,7 +693,7 @@ namespace glTF2 { if (outfile->Write(bodyBuffer->GetPointer(), 1, bodyBuffer->byteLength) != bodyBuffer->byteLength) { throw DeadlyExportError("Failed to write body data!"); } - if (paddingLength && outfile->Write(&padding, 1, paddingLength) != paddingLength) { + if (curPaddingLength && outfile->Write(&padding, 1, paddingLength) != paddingLength) { throw DeadlyExportError("Failed to write body data padding!"); } } @@ -705,7 +708,7 @@ namespace glTF2 { header.version = 2; AI_SWAP4(header.version); - header.length = uint32_t(sizeof(GLB_Header) + 2 * sizeof(GLB_Chunk) + jsonChunkLength + binaryChunkLength); + header.length = uint32_t(sizeof(GLB_Header) + GLB_Chunk_count * sizeof(GLB_Chunk) + jsonChunkLength + binaryChunkLength); AI_SWAP4(header.length); outfile->Seek(0, aiOrigin_SET); From 206551247050a02cf21bdf1b5cf45190af38492a Mon Sep 17 00:00:00 2001 From: Yingying Wang Date: Mon, 8 Jun 2020 14:41:53 -0700 Subject: [PATCH 05/17] remove comments --- code/AssetLib/glTF2/glTF2Exporter.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index 072809dc4..def4268a1 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -969,7 +969,6 @@ void glTF2Exporter::ExportMeshes() /*************** Targets for blendshapes ****************/ if (aim->mNumAnimMeshes > 0) { - //wangyi 0506 bool bUseSparse = this->mProperties->HasPropertyBool("GLTF2_SPARSE_ACCESSOR_EXP") && this->mProperties->GetPropertyBool("GLTF2_SPARSE_ACCESSOR_EXP"); bool bIncludeNormal = this->mProperties->HasPropertyBool("GLTF2_TARGET_NORMAL_EXP") && @@ -985,7 +984,6 @@ void glTF2Exporter::ExportMeshes() for (unsigned int vt = 0; vt < pAnimMesh->mNumVertices; ++vt) { pPositionDiff[vt] = pAnimMesh->mVertices[vt] - aim->mVertices[vt]; } - //wangyi 0506 Ref vec; if (bUseSparse) { vec = ExportDataSparse(*mAsset, meshId, b, @@ -1008,7 +1006,6 @@ void glTF2Exporter::ExportMeshes() for (unsigned int vt = 0; vt < pAnimMesh->mNumVertices; ++vt) { pNormalDiff[vt] = pAnimMesh->mNormals[vt] - aim->mNormals[vt]; } - //wangyi 0506 Ref vec; if (bUseSparse) { vec = ExportDataSparse(*mAsset, meshId, b, From f18f1a35f6026ff14e1f60dc549bad8c69b5e4f0 Mon Sep 17 00:00:00 2001 From: Yingying Wang Date: Mon, 8 Jun 2020 14:49:50 -0700 Subject: [PATCH 06/17] accommodate linux build --- code/AssetLib/glTF2/glTF2Exporter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index def4268a1..eb642ca08 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -354,8 +354,8 @@ inline Ref ExportDataSparse(Asset &a, std::string &meshName, RefWriteSparseValues(nzCount, nzDiff, numCompsIn * bytesPerComp); //clear - delete[] nzDiff; - delete[] nzIdx; + delete[] (char*)nzDiff; + delete[] (char*)nzIdx; } return acc; } From 8fed101432ae4f24b69db105971089791a98fee7 Mon Sep 17 00:00:00 2001 From: Yingying Wang Date: Mon, 8 Jun 2020 16:18:11 -0700 Subject: [PATCH 07/17] avoid all zero --- code/AssetLib/glTF2/glTF2Exporter.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index eb642ca08..31cd1f1c6 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -251,6 +251,13 @@ size_t NZDiff(void *data, void *dataBase, size_t count, unsigned int numCompsIn, vNZIdx.push_back(idx); } + //avoid all-0, put 1 item + if (vNZDiff.size() == 0) { + for (unsigned int j = 0; j < numCompsOut; j++) + vNZDiff.push_back(0); + vNZIdx.push_back(0); + } + //process data outputNZDiff = new T[vNZDiff.size()]; memcpy(outputNZDiff, vNZDiff.data(), vNZDiff.size() * sizeof(T)); From 578a7ac5022f26facaef146390cedbd5229c347f Mon Sep 17 00:00:00 2001 From: Yingying Wang Date: Tue, 9 Jun 2020 11:20:48 -0700 Subject: [PATCH 08/17] add Callback API in ExporterProperties --- code/Common/Exporter.cpp | 16 ++++- include/assimp/Exporter.hpp | 135 +++++++++++++++++++----------------- 2 files changed, 87 insertions(+), 64 deletions(-) diff --git a/code/Common/Exporter.cpp b/code/Common/Exporter.cpp index c34457be5..e8ee188e6 100644 --- a/code/Common/Exporter.cpp +++ b/code/Common/Exporter.cpp @@ -580,10 +580,24 @@ ExportProperties::ExportProperties(const ExportProperties &other) : mIntProperties(other.mIntProperties) , mFloatProperties(other.mFloatProperties) , mStringProperties(other.mStringProperties) -, mMatrixProperties(other.mMatrixProperties) { +, mMatrixProperties(other.mMatrixProperties) +//wangyi 0608 +, mCallbackProperties(other.mCallbackProperties){ // empty } +//wangyi 0608 +bool ExportProperties::SetPropertyCallback(const char *szName, std::function &f) { + return SetGenericProperty>(mCallbackProperties, szName, f); +} +std::function ExportProperties::GetPropertyCallback(const char *szName) const { + return GetGenericProperty>(mCallbackProperties, szName, 0); +} +//wangyi 0608 +bool ExportProperties::HasPropertyCallback(const char *szName) const { + return HasGenericProperty>(mCallbackProperties, szName); +} + // ------------------------------------------------------------------------------------------------ // Set a configuration property bool ExportProperties::SetPropertyInteger(const char* szName, int iValue) { diff --git a/include/assimp/Exporter.hpp b/include/assimp/Exporter.hpp index dc6661c11..4abea6ad0 100644 --- a/include/assimp/Exporter.hpp +++ b/include/assimp/Exporter.hpp @@ -47,16 +47,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define AI_EXPORT_HPP_INC #ifdef __GNUC__ -# pragma GCC system_header +#pragma GCC system_header #endif #ifndef ASSIMP_BUILD_NO_EXPORT #include "cexport.h" #include +//wangyi 0608 +#include namespace Assimp { - + class ExporterPimpl; class IOSystem; class ProgressHandler; @@ -84,7 +86,7 @@ class ASSIMP_API ExportProperties; class ASSIMP_API Exporter { public: /** Function pointer type of a Export worker function */ - typedef void (*fpExportFunc)(const char*, IOSystem*, const aiScene*, const ExportProperties*); + typedef void (*fpExportFunc)(const char *, IOSystem *, const aiScene *, const ExportProperties *); /** Internal description of an Assimp export format option */ struct ExportFormatEntry { @@ -98,8 +100,7 @@ public: unsigned int mEnforcePP; // Constructor to fill all entries - ExportFormatEntry( const char* pId, const char* pDesc, const char* pExtension, fpExportFunc pFunction, unsigned int pEnforcePP = 0u) - { + ExportFormatEntry(const char *pId, const char *pDesc, const char *pExtension, fpExportFunc pFunction, unsigned int pEnforcePP = 0u) { mDescription.id = pId; mDescription.description = pDesc; mDescription.fileExtension = pExtension; @@ -108,9 +109,8 @@ public: } ExportFormatEntry() : - mExportFunction() - , mEnforcePP() - { + mExportFunction(), + mEnforcePP() { mDescription.id = NULL; mDescription.description = NULL; mDescription.fileExtension = NULL; @@ -142,7 +142,7 @@ public: * * @param pIOHandler The IO handler to be used in all file accesses * of the Importer. */ - void SetIOHandler( IOSystem* pIOHandler); + void SetIOHandler(IOSystem *pIOHandler); // ------------------------------------------------------------------- /** Retrieves the IO handler that is currently set. @@ -151,7 +151,7 @@ public: * handler is active as long the application doesn't supply its own * custom IO handler via #SetIOHandler(). * @return A valid IOSystem interface, never NULL. */ - IOSystem* GetIOHandler() const; + IOSystem *GetIOHandler() const; // ------------------------------------------------------------------- /** Checks whether a default IO handler is active @@ -171,7 +171,7 @@ public: * disable progress reporting. * @note Progress handlers can be used to abort the loading * at almost any time.*/ - void SetProgressHandler(ProgressHandler* pHandler); + void SetProgressHandler(ProgressHandler *pHandler); // ------------------------------------------------------------------- /** Exports the given scene to a chosen file format. Returns the exported @@ -191,10 +191,10 @@ public: * Any IO handlers set via #SetIOHandler are ignored here. * @note Use aiCopyScene() to get a modifiable copy of a previously * imported scene. */ - const aiExportDataBlob* ExportToBlob(const aiScene* pScene, const char* pFormatId, - unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = nullptr); - const aiExportDataBlob* ExportToBlob( const aiScene* pScene, const std::string& pFormatId, - unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = nullptr); + const aiExportDataBlob *ExportToBlob(const aiScene *pScene, const char *pFormatId, + unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr); + const aiExportDataBlob *ExportToBlob(const aiScene *pScene, const std::string &pFormatId, + unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr); // ------------------------------------------------------------------- /** Convenience function to export directly to a file. Use @@ -229,10 +229,10 @@ public: * @return AI_SUCCESS if everything was fine. * @note Use aiCopyScene() to get a modifiable copy of a previously * imported scene.*/ - aiReturn Export( const aiScene* pScene, const char* pFormatId, const char* pPath, - unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = nullptr); - aiReturn Export( const aiScene* pScene, const std::string& pFormatId, const std::string& pPath, - unsigned int pPreprocessing = 0u, const ExportProperties* pProperties = nullptr); + aiReturn Export(const aiScene *pScene, const char *pFormatId, const char *pPath, + unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr); + aiReturn Export(const aiScene *pScene, const std::string &pFormatId, const std::string &pPath, + unsigned int pPreprocessing = 0u, const ExportProperties *pProperties = nullptr); // ------------------------------------------------------------------- /** Returns an error description of an error that occurred in #Export @@ -244,17 +244,17 @@ public: * * @note The returned function remains valid until one of the * following methods is called: #Export, #ExportToBlob, #FreeBlob */ - const char* GetErrorString() const; + const char *GetErrorString() const; // ------------------------------------------------------------------- /** Return the blob obtained from the last call to #ExportToBlob */ - const aiExportDataBlob* GetBlob() const; + const aiExportDataBlob *GetBlob() const; // ------------------------------------------------------------------- /** Orphan the blob from the last call to #ExportToBlob. This means * the caller takes ownership and is thus responsible for calling * the C API function #aiReleaseExportBlob to release it. */ - const aiExportDataBlob* GetOrphanedBlob() const; + const aiExportDataBlob *GetOrphanedBlob() const; // ------------------------------------------------------------------- /** Frees the current blob. @@ -264,7 +264,7 @@ public: * automatically by the destructor. The only reason to call * it manually would be to reclaim as much storage as possible * without giving up the #Exporter instance yet. */ - void FreeBlob( ); + void FreeBlob(); // ------------------------------------------------------------------- /** Returns the number of export file formats available in the current @@ -290,7 +290,7 @@ public: * for. Valid range is 0 to #Exporter::GetExportFormatCount * @return A description of that specific export format. * NULL if pIndex is out of range. */ - const aiExportFormatDesc* GetExportFormatDescription( size_t pIndex ) const; + const aiExportFormatDesc *GetExportFormatDescription(size_t pIndex) const; // ------------------------------------------------------------------- /** Register a custom exporter. Custom export formats are limited to @@ -303,7 +303,7 @@ public: * registered. A common cause that would prevent an exporter * from being registered is that its format id is already * occupied by another format. */ - aiReturn RegisterExporter(const ExportFormatEntry& desc); + aiReturn RegisterExporter(const ExportFormatEntry &desc); // ------------------------------------------------------------------- /** Remove an export format previously registered with #RegisterExporter @@ -314,11 +314,11 @@ public: * 'id' field of #aiExportFormatDesc. * @note Calling this method on a format description not yet registered * has no effect.*/ - void UnregisterExporter(const char* id); + void UnregisterExporter(const char *id); protected: // Just because we don't want you to know how we're hacking around. - ExporterPimpl* pimpl; + ExporterPimpl *pimpl; }; class ASSIMP_API ExportProperties { @@ -332,6 +332,8 @@ public: typedef std::map FloatPropertyMap; typedef std::map StringPropertyMap; typedef std::map MatrixPropertyMap; + //wangyi 0608 + typedef std::map> CallbackPropertyMap; public: /** Standard constructor @@ -345,7 +347,7 @@ public: * This copies the configuration properties of another ExportProperties. * @see ExportProperties(const ExportProperties& other) */ - ExportProperties(const ExportProperties& other); + ExportProperties(const ExportProperties &other); // ------------------------------------------------------------------- /** Set an integer configuration property. @@ -360,7 +362,7 @@ public: * floating-point property has no effect - the loader will call * GetPropertyFloat() to read the property, but it won't be there. */ - bool SetPropertyInteger(const char* szName, int iValue); + bool SetPropertyInteger(const char *szName, int iValue); // ------------------------------------------------------------------- /** Set a boolean configuration property. Boolean properties @@ -369,27 +371,30 @@ public: * #GetPropertyBool and vice versa. * @see SetPropertyInteger() */ - bool SetPropertyBool(const char* szName, bool value) { - return SetPropertyInteger(szName,value); + bool SetPropertyBool(const char *szName, bool value) { + return SetPropertyInteger(szName, value); } // ------------------------------------------------------------------- /** Set a floating-point configuration property. * @see SetPropertyInteger() */ - bool SetPropertyFloat(const char* szName, ai_real fValue); + bool SetPropertyFloat(const char *szName, ai_real fValue); // ------------------------------------------------------------------- /** Set a string configuration property. * @see SetPropertyInteger() */ - bool SetPropertyString(const char* szName, const std::string& sValue); + bool SetPropertyString(const char *szName, const std::string &sValue); // ------------------------------------------------------------------- /** Set a matrix configuration property. * @see SetPropertyInteger() */ - bool SetPropertyMatrix(const char* szName, const aiMatrix4x4& sValue); + bool SetPropertyMatrix(const char *szName, const aiMatrix4x4 &sValue); + + //wangyi 0608 + bool SetPropertyCallback(const char *szName, std::function &f); // ------------------------------------------------------------------- /** Get a configuration property. @@ -404,8 +409,8 @@ public: * floating-point property has no effect - the loader will call * GetPropertyFloat() to read the property, but it won't be there. */ - int GetPropertyInteger(const char* szName, - int iErrorReturn = 0xffffffff) const; + int GetPropertyInteger(const char *szName, + int iErrorReturn = 0xffffffff) const; // ------------------------------------------------------------------- /** Get a boolean configuration property. Boolean properties @@ -414,16 +419,16 @@ public: * #GetPropertyBool and vice versa. * @see GetPropertyInteger() */ - bool GetPropertyBool(const char* szName, bool bErrorReturn = false) const { - return GetPropertyInteger(szName,bErrorReturn)!=0; + bool GetPropertyBool(const char *szName, bool bErrorReturn = false) const { + return GetPropertyInteger(szName, bErrorReturn) != 0; } // ------------------------------------------------------------------- /** Get a floating-point configuration property * @see GetPropertyInteger() */ - ai_real GetPropertyFloat(const char* szName, - ai_real fErrorReturn = 10e10f) const; + ai_real GetPropertyFloat(const char *szName, + ai_real fErrorReturn = 10e10f) const; // ------------------------------------------------------------------- /** Get a string configuration property @@ -431,8 +436,8 @@ public: * The return value remains valid until the property is modified. * @see GetPropertyInteger() */ - const std::string GetPropertyString(const char* szName, - const std::string& sErrorReturn = "") const; + const std::string GetPropertyString(const char *szName, + const std::string &sErrorReturn = "") const; // ------------------------------------------------------------------- /** Get a matrix configuration property @@ -440,37 +445,42 @@ public: * The return value remains valid until the property is modified. * @see GetPropertyInteger() */ - const aiMatrix4x4 GetPropertyMatrix(const char* szName, - const aiMatrix4x4& sErrorReturn = aiMatrix4x4()) const; + const aiMatrix4x4 GetPropertyMatrix(const char *szName, + const aiMatrix4x4 &sErrorReturn = aiMatrix4x4()) const; - // ------------------------------------------------------------------- - /** Determine a integer configuration property has been set. + //wangyi 0608 + std::function GetPropertyCallback(const char* szName) const; + + // ------------------------------------------------------------------- + /** Determine a integer configuration property has been set. * @see HasPropertyInteger() */ - bool HasPropertyInteger(const char* szName) const; + bool HasPropertyInteger(const char *szName) const; /** Determine a boolean configuration property has been set. * @see HasPropertyBool() */ - bool HasPropertyBool(const char* szName) const; + bool HasPropertyBool(const char *szName) const; /** Determine a boolean configuration property has been set. * @see HasPropertyFloat() */ - bool HasPropertyFloat(const char* szName) const; + bool HasPropertyFloat(const char *szName) const; /** Determine a String configuration property has been set. * @see HasPropertyString() */ - bool HasPropertyString(const char* szName) const; + bool HasPropertyString(const char *szName) const; /** Determine a Matrix configuration property has been set. * @see HasPropertyMatrix() */ - bool HasPropertyMatrix(const char* szName) const; + bool HasPropertyMatrix(const char *szName) const; + + //wangyi 0608 + bool HasPropertyCallback(const char *szName) const; protected: - /** List of integer properties */ IntPropertyMap mIntProperties; @@ -482,23 +492,22 @@ protected: /** List of Matrix properties */ MatrixPropertyMap mMatrixProperties; + + //wangyi 0608 + CallbackPropertyMap mCallbackProperties; }; // ---------------------------------------------------------------------------------- -inline -const aiExportDataBlob* Exporter::ExportToBlob( const aiScene* pScene, const std::string& pFormatId, - unsigned int pPreprocessing, const ExportProperties* pProperties) -{ - return ExportToBlob(pScene,pFormatId.c_str(),pPreprocessing, pProperties); +inline const aiExportDataBlob *Exporter::ExportToBlob(const aiScene *pScene, const std::string &pFormatId, + unsigned int pPreprocessing, const ExportProperties *pProperties) { + return ExportToBlob(pScene, pFormatId.c_str(), pPreprocessing, pProperties); } // ---------------------------------------------------------------------------------- -inline -aiReturn Exporter :: Export( const aiScene* pScene, const std::string& pFormatId, - const std::string& pPath, unsigned int pPreprocessing, - const ExportProperties* pProperties) -{ - return Export(pScene,pFormatId.c_str(),pPath.c_str(),pPreprocessing, pProperties); +inline aiReturn Exporter ::Export(const aiScene *pScene, const std::string &pFormatId, + const std::string &pPath, unsigned int pPreprocessing, + const ExportProperties *pProperties) { + return Export(pScene, pFormatId.c_str(), pPath.c_str(), pPreprocessing, pProperties); } } // namespace Assimp From f57e7221c07f385cebcc457d294e90c446995d41 Mon Sep 17 00:00:00 2001 From: ywang Date: Wed, 10 Jun 2020 13:23:29 -0700 Subject: [PATCH 09/17] temp --- code/AssetLib/glTF2/glTF2Exporter.cpp | 17 +++++++++++++++-- code/Common/Exporter.cpp | 2 +- include/assimp/Exporter.hpp | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index 566f95e80..98eb79e57 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -1,4 +1,4 @@ -/* +/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- @@ -115,7 +115,20 @@ glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const ai ExportScene(); ExportAnimations(); - + + //wangyi 0608 + if(mProperties->HasPropertyCallback("extras")) + { + std::function ExportExtras = mProperties->GetPropertyCallback("extras"); + char* ret = (char*)ExportExtras((void*)mAsset.get()); + + Document extrasD; + extrasD.Parse(ret); + std::string strHello = extrasD["hello"].GetString(); + + printf("wangyi 0608 ret: %s\r\n", ret); + } + AssetWriter writer(*mAsset); if (isBinary) { diff --git a/code/Common/Exporter.cpp b/code/Common/Exporter.cpp index e8ee188e6..5fef455bb 100644 --- a/code/Common/Exporter.cpp +++ b/code/Common/Exporter.cpp @@ -587,7 +587,7 @@ ExportProperties::ExportProperties(const ExportProperties &other) } //wangyi 0608 -bool ExportProperties::SetPropertyCallback(const char *szName, std::function &f) { +bool ExportProperties::SetPropertyCallback(const char *szName, const std::function &f) { return SetGenericProperty>(mCallbackProperties, szName, f); } std::function ExportProperties::GetPropertyCallback(const char *szName) const { diff --git a/include/assimp/Exporter.hpp b/include/assimp/Exporter.hpp index 4abea6ad0..87c12f374 100644 --- a/include/assimp/Exporter.hpp +++ b/include/assimp/Exporter.hpp @@ -394,7 +394,7 @@ public: bool SetPropertyMatrix(const char *szName, const aiMatrix4x4 &sValue); //wangyi 0608 - bool SetPropertyCallback(const char *szName, std::function &f); + bool SetPropertyCallback(const char *szName, const std::function &f); // ------------------------------------------------------------------- /** Get a configuration property. From e65434bf8241a5408ff213dc315d5b8d3ed2f60e Mon Sep 17 00:00:00 2001 From: ywang Date: Thu, 11 Jun 2020 17:37:06 -0700 Subject: [PATCH 10/17] extra callback --- code/AssetLib/glTF2/glTF2Asset.h | 3 ++- code/AssetLib/glTF2/glTF2AssetWriter.inl | 6 +++++- code/AssetLib/glTF2/glTF2Exporter.cpp | 10 ++-------- code/Common/Exporter.cpp | 5 ++--- include/assimp/Exporter.hpp | 12 +++--------- 5 files changed, 14 insertions(+), 22 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Asset.h b/code/AssetLib/glTF2/glTF2Asset.h index fc0fe1544..de252b329 100644 --- a/code/AssetLib/glTF2/glTF2Asset.h +++ b/code/AssetLib/glTF2/glTF2Asset.h @@ -1,4 +1,4 @@ -/* +/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- @@ -1006,6 +1006,7 @@ public: } extensionsRequired; AssetMetadata asset; + Value* extras = nullptr; // Dictionaries for each type of object diff --git a/code/AssetLib/glTF2/glTF2AssetWriter.inl b/code/AssetLib/glTF2/glTF2AssetWriter.inl index 361af40cd..0a4d0b2f4 100644 --- a/code/AssetLib/glTF2/glTF2AssetWriter.inl +++ b/code/AssetLib/glTF2/glTF2AssetWriter.inl @@ -1,4 +1,4 @@ -/* +/* Open Asset Import Library (assimp) ---------------------------------------------------------------------- @@ -600,6 +600,10 @@ namespace glTF2 { if (mAsset.scene) { mDoc.AddMember("scene", mAsset.scene->index, mAl); } + + if(mAsset.extras) { + mDoc.AddMember("extras", *mAsset.extras, mAl); + } } inline void AssetWriter::WriteFile(const char* path) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index 98eb79e57..537787eb7 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -116,17 +116,11 @@ glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const ai ExportAnimations(); - //wangyi 0608 + // export extras if(mProperties->HasPropertyCallback("extras")) { std::function ExportExtras = mProperties->GetPropertyCallback("extras"); - char* ret = (char*)ExportExtras((void*)mAsset.get()); - - Document extrasD; - extrasD.Parse(ret); - std::string strHello = extrasD["hello"].GetString(); - - printf("wangyi 0608 ret: %s\r\n", ret); + mAsset->extras = (rapidjson::Value*)ExportExtras(0); } AssetWriter writer(*mAsset); diff --git a/code/Common/Exporter.cpp b/code/Common/Exporter.cpp index 5fef455bb..30ab3a813 100644 --- a/code/Common/Exporter.cpp +++ b/code/Common/Exporter.cpp @@ -581,19 +581,18 @@ ExportProperties::ExportProperties(const ExportProperties &other) , mFloatProperties(other.mFloatProperties) , mStringProperties(other.mStringProperties) , mMatrixProperties(other.mMatrixProperties) -//wangyi 0608 , mCallbackProperties(other.mCallbackProperties){ // empty } -//wangyi 0608 bool ExportProperties::SetPropertyCallback(const char *szName, const std::function &f) { return SetGenericProperty>(mCallbackProperties, szName, f); } + std::function ExportProperties::GetPropertyCallback(const char *szName) const { return GetGenericProperty>(mCallbackProperties, szName, 0); } -//wangyi 0608 + bool ExportProperties::HasPropertyCallback(const char *szName) const { return HasGenericProperty>(mCallbackProperties, szName); } diff --git a/include/assimp/Exporter.hpp b/include/assimp/Exporter.hpp index 87c12f374..8e47e24db 100644 --- a/include/assimp/Exporter.hpp +++ b/include/assimp/Exporter.hpp @@ -54,7 +54,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "cexport.h" #include -//wangyi 0608 #include namespace Assimp { @@ -332,7 +331,6 @@ public: typedef std::map FloatPropertyMap; typedef std::map StringPropertyMap; typedef std::map MatrixPropertyMap; - //wangyi 0608 typedef std::map> CallbackPropertyMap; public: @@ -392,8 +390,7 @@ public: * @see SetPropertyInteger() */ bool SetPropertyMatrix(const char *szName, const aiMatrix4x4 &sValue); - - //wangyi 0608 + bool SetPropertyCallback(const char *szName, const std::function &f); // ------------------------------------------------------------------- @@ -448,7 +445,6 @@ public: const aiMatrix4x4 GetPropertyMatrix(const char *szName, const aiMatrix4x4 &sErrorReturn = aiMatrix4x4()) const; - //wangyi 0608 std::function GetPropertyCallback(const char* szName) const; // ------------------------------------------------------------------- @@ -476,8 +472,7 @@ public: * @see HasPropertyMatrix() */ bool HasPropertyMatrix(const char *szName) const; - - //wangyi 0608 + bool HasPropertyCallback(const char *szName) const; protected: @@ -492,8 +487,7 @@ protected: /** List of Matrix properties */ MatrixPropertyMap mMatrixProperties; - - //wangyi 0608 + CallbackPropertyMap mCallbackProperties; }; From ba09e1ef94176a97766203f36a850c6fe9c58c8c Mon Sep 17 00:00:00 2001 From: Filip Lundgren <45687559+ifiddynine@users.noreply.github.com> Date: Sun, 21 Jun 2020 23:56:11 +0200 Subject: [PATCH 11/17] Fix Blender .fbx metalness detection --- code/AssetLib/FBX/FBXConverter.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/code/AssetLib/FBX/FBXConverter.cpp b/code/AssetLib/FBX/FBXConverter.cpp index 261567e48..09711ee8d 100644 --- a/code/AssetLib/FBX/FBXConverter.cpp +++ b/code/AssetLib/FBX/FBXConverter.cpp @@ -1992,6 +1992,7 @@ void FBXConverter::SetTextureProperties(aiMaterial *out_mat, const TextureMap &_ TrySetTextureProperties(out_mat, _textures, "ShininessExponent", aiTextureType_SHININESS, mesh); TrySetTextureProperties(out_mat, _textures, "TransparencyFactor", aiTextureType_OPACITY, mesh); TrySetTextureProperties(out_mat, _textures, "EmissiveFactor", aiTextureType_EMISSIVE, mesh); + TrySetTextureProperties(out_mat, _textures, "ReflectionFactor", aiTextureType_METALNESS, mesh); //Maya counterparts TrySetTextureProperties(out_mat, _textures, "Maya|DiffuseTexture", aiTextureType_DIFFUSE, mesh); TrySetTextureProperties(out_mat, _textures, "Maya|NormalTexture", aiTextureType_NORMALS, mesh); From 0b18d27042b37429a3f82fd546500411fe1360c2 Mon Sep 17 00:00:00 2001 From: Hill Ma Date: Sun, 28 Jun 2020 15:58:20 -0700 Subject: [PATCH 12/17] Use strrchr() when finding the '.' that begins the file extension. Sometimes we encounter file paths like ../foo/bar.obj; searching from the end of the string would yield the correct result. --- samples/SimpleOpenGL/Sample_SimpleOpenGL.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/SimpleOpenGL/Sample_SimpleOpenGL.c b/samples/SimpleOpenGL/Sample_SimpleOpenGL.c index bcc964efe..01704a1e4 100644 --- a/samples/SimpleOpenGL/Sample_SimpleOpenGL.c +++ b/samples/SimpleOpenGL/Sample_SimpleOpenGL.c @@ -376,7 +376,7 @@ int main(int argc, char **argv) // Check and validate the specified model file extension. model_file = argv[1]; - const char* extension = strchr(model_file, '.'); + const char* extension = strrchr(model_file, '.'); if (!extension) { print_error("Please provide a file with a valid extension."); return EXIT_FAILURE; From 9aa468262f615dee390e3ce1bf34cdc14a676fa5 Mon Sep 17 00:00:00 2001 From: kimkulling Date: Tue, 7 Jul 2020 17:35:03 +0200 Subject: [PATCH 13/17] closes https://github.com/assimp/assimp/issues/3252: fix build. --- code/AssetLib/3DS/3DSHelper.h | 2 +- code/AssetLib/IFC/IFCReaderGen_2x3.h | 2 +- code/AssetLib/M3D/m3d.h | 4 +++- code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp | 4 ++-- code/AssetLib/Step/STEPFile.h | 6 +++--- code/Common/Exporter.cpp | 4 ++-- code/Common/Subdivision.cpp | 2 +- 7 files changed, 13 insertions(+), 11 deletions(-) diff --git a/code/AssetLib/3DS/3DSHelper.h b/code/AssetLib/3DS/3DSHelper.h index 89c15f5f2..3ccb1fd07 100644 --- a/code/AssetLib/3DS/3DSHelper.h +++ b/code/AssetLib/3DS/3DSHelper.h @@ -321,7 +321,7 @@ public: struct Face : public FaceWithSmoothingGroup { }; -#ifdef _WIN32 +#if _MSC_VER > 1920 #pragma warning(disable : 4315) #endif diff --git a/code/AssetLib/IFC/IFCReaderGen_2x3.h b/code/AssetLib/IFC/IFCReaderGen_2x3.h index 8ae623dd8..b3f71a7f1 100644 --- a/code/AssetLib/IFC/IFCReaderGen_2x3.h +++ b/code/AssetLib/IFC/IFCReaderGen_2x3.h @@ -45,7 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "AssetLib/Step/STEPFile.h" -#ifdef _WIN32 +#if _MSC_VER > 1920 # pragma warning( disable : 4512 ) #endif // _WIN32 diff --git a/code/AssetLib/M3D/m3d.h b/code/AssetLib/M3D/m3d.h index 3d7a2564c..5ab3d16de 100644 --- a/code/AssetLib/M3D/m3d.h +++ b/code/AssetLib/M3D/m3d.h @@ -85,7 +85,9 @@ typedef uint16_t M3D_INDEX; #define M3D_BONEMAXLEVEL 8 #endif #ifndef _MSC_VER +#ifndef _inline #define _inline __inline__ +#endif #define _pack __attribute__((packed)) #define _unused __attribute__((unused)) #else @@ -99,7 +101,7 @@ typedef uint16_t M3D_INDEX; #define _register #endif -#ifdef _WIN32 +#if _MSC_VER > 1920 # pragma warning(push) # pragma warning(disable : 4100 4127 4189 4505 4244 4403 4701 4703) # if (_MSC_VER > 1800 ) diff --git a/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp b/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp index 2bb7b42ee..e9930dfed 100644 --- a/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp +++ b/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp @@ -68,8 +68,8 @@ namespace Assimp { namespace MDL { namespace HalfLife { -#ifdef _WIN32 -# pragma warning(disable : 4706) +#if _MSC_VER > 1920 +# pragma warning(disable : 4706) #endif // _WIN32 // ------------------------------------------------------------------------------------------------ diff --git a/code/AssetLib/Step/STEPFile.h b/code/AssetLib/Step/STEPFile.h index 1448c107f..72648e462 100644 --- a/code/AssetLib/Step/STEPFile.h +++ b/code/AssetLib/Step/STEPFile.h @@ -54,7 +54,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#ifdef _WIN32 +#if _MSC_VER > 1920 # pragma warning(push) # pragma warning(disable : 4127 4456 4245 4512 ) #endif // _WIN32 @@ -727,7 +727,7 @@ struct InternGenericConvert> { } }; -#ifdef _WIN32 +#if _MSC_VER > 1920 #pragma warning(push) #pragma warning(disable : 4127) #endif // _WIN32 @@ -960,7 +960,7 @@ private: const EXPRESS::ConversionSchema *schema; }; -#ifdef _WIN32 +#if _MSC_VER > 1920 #pragma warning(pop) #endif // _WIN32 diff --git a/code/Common/Exporter.cpp b/code/Common/Exporter.cpp index 58fc01d91..a47c52a6c 100644 --- a/code/Common/Exporter.cpp +++ b/code/Common/Exporter.cpp @@ -74,8 +74,8 @@ Here we implement only the C++ interface (Assimp::Exporter). namespace Assimp { -#ifdef _WIN32 -# pragma warning( disable : 4800 ) +#if _MSC_VER > 1920 +# pragma warning( disable : 4800 ) #endif // _WIN32 diff --git a/code/Common/Subdivision.cpp b/code/Common/Subdivision.cpp index b1f07c9f5..4f64a00c4 100644 --- a/code/Common/Subdivision.cpp +++ b/code/Common/Subdivision.cpp @@ -53,7 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using namespace Assimp; void mydummy() {} -#ifdef _WIN32 +#if _MSC_VER > 1920 #pragma warning(disable : 4709) #endif // _WIN32 // ------------------------------------------------------------------------------------------------ From b8ec93aa2137d18e8fb861df17fb6878b8e7d656 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 11 Jul 2020 22:34:43 +0200 Subject: [PATCH 14/17] use c-styl cast in a c-file --- samples/SimpleOpenGL/Sample_SimpleOpenGL.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/SimpleOpenGL/Sample_SimpleOpenGL.c b/samples/SimpleOpenGL/Sample_SimpleOpenGL.c index 01704a1e4..bcb109564 100644 --- a/samples/SimpleOpenGL/Sample_SimpleOpenGL.c +++ b/samples/SimpleOpenGL/Sample_SimpleOpenGL.c @@ -278,7 +278,7 @@ void do_motion (void) static int frames = 0; int time = glutGet(GLUT_ELAPSED_TIME); - angle += static_cast((time-prev_time)*0.01); + angle += (float)((time-prev_time)*0.01); prev_time = time; frames += 1; From 108b3a62e5b1ace725f3ddee06a701eddc19199e Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sat, 11 Jul 2020 22:45:45 +0200 Subject: [PATCH 15/17] Update Exporter.hpp revert merge issue --- include/assimp/Exporter.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/assimp/Exporter.hpp b/include/assimp/Exporter.hpp index 6fcbafe92..15918dd47 100644 --- a/include/assimp/Exporter.hpp +++ b/include/assimp/Exporter.hpp @@ -110,9 +110,9 @@ public: ExportFormatEntry() : mExportFunction(), mEnforcePP() { - mDescription.id = NULL; - mDescription.description = NULL; - mDescription.fileExtension = NULL; + mDescription.id = nullptr; + mDescription.description = nullptr; + mDescription.fileExtension = nullptr; } }; From 6619ec82531e76ebb926d0ba9e90bc31623b765e Mon Sep 17 00:00:00 2001 From: Ryan Styrczula Date: Mon, 22 Jun 2020 14:26:37 -0400 Subject: [PATCH 16/17] FBXExporter: Use scene metadata for global settings Models with non-standard axes and scale are not imported and exported correctly if the input metadata is ignored. --- code/AssetLib/FBX/FBXExporter.cpp | 93 +++++++++++++++++++++++++------ 1 file changed, 76 insertions(+), 17 deletions(-) diff --git a/code/AssetLib/FBX/FBXExporter.cpp b/code/AssetLib/FBX/FBXExporter.cpp index 3fc7701f5..bd59cf885 100644 --- a/code/AssetLib/FBX/FBXExporter.cpp +++ b/code/AssetLib/FBX/FBXExporter.cpp @@ -400,6 +400,65 @@ void FBXExporter::WriteHeaderExtension () ); } +// WriteGlobalSettings helpers + +void WritePropInt(const aiScene* scene, FBX::Node& p, const std::string& key, int defaultValue) +{ + int value; + if (scene->mMetaData->Get(key, value)) { + p.AddP70int(key, value); + } else { + p.AddP70int(key, defaultValue); + } +} + +void WritePropDouble(const aiScene* scene, FBX::Node& p, const std::string& key, double defaultValue) +{ + double value; + if (scene->mMetaData->Get(key, value)) { + p.AddP70double(key, value); + } else { + // fallback lookup float instead + float floatValue; + if (scene->mMetaData->Get(key, floatValue)) { + p.AddP70double(key, (double)floatValue); + } else { + p.AddP70double(key, defaultValue); + } + } +} + +void WritePropEnum(const aiScene* scene, FBX::Node& p, const std::string& key, int defaultValue) +{ + int value; + if (scene->mMetaData->Get(key, value)) { + p.AddP70enum(key, value); + } else { + p.AddP70enum(key, defaultValue); + } +} + +void WritePropColor(const aiScene* scene, FBX::Node& p, const std::string& key, const aiVector3D& defaultValue) +{ + aiVector3D value; + if (scene->mMetaData->Get(key, value)) { + // ai_real can be float or double, cast to avoid warnings + p.AddP70color(key, (double)value.x, (double)value.y, (double)value.z); + } else { + p.AddP70color(key, 0.0, 0.0, 0.0); + } +} + +void WritePropString(const aiScene* scene, FBX::Node& p, const std::string& key, const std::string& defaultValue) +{ + aiString value; // MetaData doesn't hold std::string + if (scene->mMetaData->Get(key, value)) { + p.AddP70string(key, value.C_Str()); + } else { + p.AddP70string(key, defaultValue); + } +} + void FBXExporter::WriteGlobalSettings () { if (!binary) { @@ -409,26 +468,26 @@ void FBXExporter::WriteGlobalSettings () gs.AddChild("Version", int32_t(1000)); FBX::Node p("Properties70"); - p.AddP70int("UpAxis", 1); - p.AddP70int("UpAxisSign", 1); - p.AddP70int("FrontAxis", 2); - p.AddP70int("FrontAxisSign", 1); - p.AddP70int("CoordAxis", 0); - p.AddP70int("CoordAxisSign", 1); - p.AddP70int("OriginalUpAxis", 1); - p.AddP70int("OriginalUpAxisSign", 1); - p.AddP70double("UnitScaleFactor", 1.0); - p.AddP70double("OriginalUnitScaleFactor", 1.0); - p.AddP70color("AmbientColor", 0.0, 0.0, 0.0); - p.AddP70string("DefaultCamera", "Producer Perspective"); - p.AddP70enum("TimeMode", 11); - p.AddP70enum("TimeProtocol", 2); - p.AddP70enum("SnapOnFrameMode", 0); + WritePropInt(mScene, p, "UpAxis", 1); + WritePropInt(mScene, p, "UpAxisSign", 1); + WritePropInt(mScene, p, "FrontAxis", 2); + WritePropInt(mScene, p, "FrontAxisSign", 1); + WritePropInt(mScene, p, "CoordAxis", 0); + WritePropInt(mScene, p, "CoordAxisSign", 1); + WritePropInt(mScene, p, "OriginalUpAxis", 1); + WritePropInt(mScene, p, "OriginalUpAxisSign", 1); + WritePropDouble(mScene, p, "UnitScaleFactor", 1.0); + WritePropDouble(mScene, p, "OriginalUnitScaleFactor", 1.0); + WritePropColor(mScene, p, "AmbientColor", aiVector3D((ai_real)0.0, (ai_real)0.0, (ai_real)0.0)); + WritePropString(mScene, p,"DefaultCamera", "Producer Perspective"); + WritePropEnum(mScene, p, "TimeMode", 11); + WritePropEnum(mScene, p, "TimeProtocol", 2); + WritePropEnum(mScene, p, "SnapOnFrameMode", 0); p.AddP70time("TimeSpanStart", 0); // TODO: animation support p.AddP70time("TimeSpanStop", FBX::SECOND); // TODO: animation support - p.AddP70double("CustomFrameRate", -1.0); + WritePropDouble(mScene, p, "CustomFrameRate", -1.0); p.AddP70("TimeMarker", "Compound", "", ""); // not sure what this is - p.AddP70int("CurrentTimeMarker", -1); + WritePropInt(mScene, p, "CurrentTimeMarker", -1); gs.AddChild(p); gs.Dump(outfile, binary, 0); From 0c2f7a119cd6e2ad371638af2452be3568753629 Mon Sep 17 00:00:00 2001 From: Ryan Styrczula Date: Mon, 22 Jun 2020 15:22:08 -0400 Subject: [PATCH 17/17] FBXExporter: Forgot WritePropColor defaultValue --- code/AssetLib/FBX/FBXExporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AssetLib/FBX/FBXExporter.cpp b/code/AssetLib/FBX/FBXExporter.cpp index bd59cf885..20d166179 100644 --- a/code/AssetLib/FBX/FBXExporter.cpp +++ b/code/AssetLib/FBX/FBXExporter.cpp @@ -445,7 +445,7 @@ void WritePropColor(const aiScene* scene, FBX::Node& p, const std::string& key, // ai_real can be float or double, cast to avoid warnings p.AddP70color(key, (double)value.x, (double)value.y, (double)value.z); } else { - p.AddP70color(key, 0.0, 0.0, 0.0); + p.AddP70color(key, (double)defaultValue.x, (double)defaultValue.y, (double)defaultValue.z); } }