Merge branch 'master' into master
commit
f5d5d7c5ed
|
@ -321,7 +321,7 @@ public:
|
|||
struct Face : public FaceWithSmoothingGroup {
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
#if _MSC_VER > 1920
|
||||
#pragma warning(disable : 4315)
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1988,6 +1988,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);
|
||||
|
|
|
@ -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, (double)defaultValue.x, (double)defaultValue.y, (double)defaultValue.z);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace Assimp {
|
|||
namespace MDL {
|
||||
namespace HalfLife {
|
||||
|
||||
#ifdef _WIN32
|
||||
#if _MSC_VER > 1920
|
||||
# pragma warning(disable : 4706)
|
||||
#endif // _WIN32
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
|
||||
#ifdef _WIN32
|
||||
#if _MSC_VER > 1920
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable : 4127 4456 4245 4512 )
|
||||
#endif // _WIN32
|
||||
|
@ -727,7 +727,7 @@ struct InternGenericConvert<Maybe<T>> {
|
|||
}
|
||||
};
|
||||
|
||||
#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
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
|
@ -406,6 +406,8 @@ struct Accessor : public Object {
|
|||
void ExtractData(T *&outData);
|
||||
|
||||
void WriteData(size_t count, const void *src_buffer, size_t src_stride);
|
||||
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 {
|
||||
|
@ -1066,6 +1068,7 @@ public:
|
|||
} extensionsRequired;
|
||||
|
||||
AssetMetadata asset;
|
||||
Value* extras = nullptr;
|
||||
|
||||
// Dictionaries for each type of object
|
||||
|
||||
|
|
|
@ -757,6 +757,33 @@ inline void Accessor::WriteData(size_t _count, const void *src_buffer, size_t sr
|
|||
CopyData(_count, src, src_stride, dst, dst_stride);
|
||||
}
|
||||
|
||||
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<const uint8_t *>(src_data);
|
||||
uint8_t *value_dst = reinterpret_cast<uint8_t *>(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);
|
||||
}
|
||||
|
||||
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<const uint8_t *>(src_idx);
|
||||
uint8_t *indices_dst = reinterpret_cast<uint8_t *>(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()),
|
||||
|
@ -1287,6 +1314,8 @@ inline void Node::Read(Value &obj, Asset &r) {
|
|||
}
|
||||
}
|
||||
|
||||
// Do not retrieve a skin here, just take a reference, to avoid infinite recursion
|
||||
// Skins will be properly loaded later
|
||||
Value *curSkin = FindUInt(obj, "skin");
|
||||
if (nullptr != curSkin) {
|
||||
this->skin = r.skins.Get(curSkin->GetUint());
|
||||
|
@ -1584,7 +1613,6 @@ inline void Asset::Load(const std::string &pFile, bool isBinary) {
|
|||
}
|
||||
}
|
||||
|
||||
// Read skins after nodes have been loaded to avoid infinite recursion
|
||||
if (Value *skinsArray = FindArray(doc, "skins")) {
|
||||
for (unsigned int i = 0; i < skinsArray->Size(); ++i) {
|
||||
skins.Retrieve(i);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
|
@ -107,21 +107,47 @@ 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);
|
||||
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<int64_t>(vTmpMax, a.max, w.mAl), w.mAl);
|
||||
obj.AddMember("min", MakeValueCast<int64_t>(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<int64_t>(vTmpMax, a.max, w.mAl), w.mAl);
|
||||
obj.AddMember("min", MakeValueCast<int64_t>(vTmpMin, a.min, w.mAl), w.mAl);
|
||||
}
|
||||
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)
|
||||
|
@ -616,6 +642,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)
|
||||
|
@ -709,10 +739,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 curPaddingLength = binaryChunkLength - bodyBuffer->byteLength;
|
||||
|
||||
auto curPaddingLength = binaryChunkLength - bodyBuffer->byteLength;
|
||||
++GLB_Chunk_count;
|
||||
|
||||
GLB_Chunk binaryChunk;
|
||||
binaryChunk.chunkLength = binaryChunkLength;
|
||||
|
@ -727,7 +760,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!");
|
||||
}
|
||||
}
|
||||
|
@ -742,7 +775,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);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
|
@ -116,6 +116,13 @@ glTF2Exporter::glTF2Exporter(const char* filename, IOSystem* pIOSystem, const ai
|
|||
|
||||
ExportAnimations();
|
||||
|
||||
// export extras
|
||||
if(mProperties->HasPropertyCallback("extras"))
|
||||
{
|
||||
std::function<void*(void*)> ExportExtras = mProperties->GetPropertyCallback("extras");
|
||||
mAsset->extras = (rapidjson::Value*)ExportExtras(0);
|
||||
}
|
||||
|
||||
AssetWriter writer(*mAsset);
|
||||
|
||||
if (isBinary) {
|
||||
|
@ -214,6 +221,158 @@ inline void SetAccessorRange(ComponentType compType, Ref<Accessor> acc, void* da
|
|||
}
|
||||
}
|
||||
|
||||
// compute the (data-dataBase), store the non-zero data items
|
||||
template <typename T>
|
||||
size_t NZDiff(void *data, void *dataBase, size_t count, unsigned int numCompsIn, unsigned int numCompsOut, void *&outputNZDiff, void *&outputNZIdx) {
|
||||
std::vector<T> vNZDiff;
|
||||
std::vector<unsigned short> vNZIdx;
|
||||
size_t totalComps = count * numCompsIn;
|
||||
T *bufferData_ptr = static_cast<T *>(data);
|
||||
T *bufferData_end = bufferData_ptr + totalComps;
|
||||
T *bufferBase_ptr = static_cast<T *>(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);
|
||||
}
|
||||
|
||||
//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));
|
||||
|
||||
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<short>(data, dataBase, count, numCompsIn, numCompsOut, nzDiff, nzIdx);
|
||||
case ComponentType_UNSIGNED_SHORT:
|
||||
return NZDiff<unsigned short>(data, dataBase, count, numCompsIn, numCompsOut, nzDiff, nzIdx);
|
||||
case ComponentType_UNSIGNED_INT:
|
||||
return NZDiff<unsigned int>(data, dataBase, count, numCompsIn, numCompsOut, nzDiff, nzIdx);
|
||||
case ComponentType_FLOAT:
|
||||
return NZDiff<float>(data, dataBase, count, numCompsIn, numCompsOut, nzDiff, nzIdx);
|
||||
case ComponentType_BYTE:
|
||||
return NZDiff<int8_t>(data, dataBase, count, numCompsIn, numCompsOut, nzDiff, nzIdx);
|
||||
case ComponentType_UNSIGNED_BYTE:
|
||||
return NZDiff<uint8_t>(data, dataBase, count, numCompsIn, numCompsOut, nzDiff, nzIdx);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline Ref<Accessor> ExportDataSparse(Asset &a, std::string &meshName, Ref<Buffer> &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<Accessor>();
|
||||
}
|
||||
|
||||
unsigned int numCompsIn = AttribType::GetNumComponents(typeIn);
|
||||
unsigned int numCompsOut = AttribType::GetNumComponents(typeOut);
|
||||
unsigned int bytesPerComp = ComponentTypeSize(compType);
|
||||
|
||||
// accessor
|
||||
Ref<Accessor> 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<BufferView> 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<BufferView> 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<BufferView> 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[] (char*)nzDiff;
|
||||
delete[] (char*)nzIdx;
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
inline Ref<Accessor> ExportData(Asset& a, std::string& meshName, Ref<Buffer>& buffer,
|
||||
size_t count, void* data, AttribType::Value typeIn, AttribType::Value typeOut, ComponentType compType, BufferViewTarget target = BufferViewTarget_NONE)
|
||||
{
|
||||
|
@ -824,6 +983,10 @@ void glTF2Exporter::ExportMeshes()
|
|||
|
||||
/*************** Targets for blendshapes ****************/
|
||||
if (aim->mNumAnimMeshes > 0) {
|
||||
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");
|
||||
bool bExportTargetNames = this->mProperties->HasPropertyBool("GLTF2_TARGETNAMES_EXP") &&
|
||||
this->mProperties->GetPropertyBool("GLTF2_TARGETNAMES_EXP");
|
||||
|
||||
|
@ -832,7 +995,6 @@ void glTF2Exporter::ExportMeshes()
|
|||
aiAnimMesh *pAnimMesh = aim->mAnimMeshes[am];
|
||||
if (bExportTargetNames)
|
||||
m->targetNames.push_back(pAnimMesh->mName.data);
|
||||
|
||||
// position
|
||||
if (pAnimMesh->HasPositions()) {
|
||||
// NOTE: in gltf it is the diff stored
|
||||
|
@ -840,9 +1002,16 @@ void glTF2Exporter::ExportMeshes()
|
|||
for (unsigned int vt = 0; vt < pAnimMesh->mNumVertices; ++vt) {
|
||||
pPositionDiff[vt] = pAnimMesh->mVertices[vt] - aim->mVertices[vt];
|
||||
}
|
||||
Ref<Accessor> vec = ExportData(*mAsset, meshId, b,
|
||||
pAnimMesh->mNumVertices, pPositionDiff,
|
||||
AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);
|
||||
Ref<Accessor> 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);
|
||||
}
|
||||
|
@ -850,14 +1019,21 @@ 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<Accessor> vec = ExportData(*mAsset, meshId, b,
|
||||
pAnimMesh->mNumVertices, pNormalDiff,
|
||||
AttribType::VEC3, AttribType::VEC3, ComponentType_FLOAT);
|
||||
Ref<Accessor> 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);
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ Here we implement only the C++ interface (Assimp::Exporter).
|
|||
|
||||
namespace Assimp {
|
||||
|
||||
#ifdef _WIN32
|
||||
#if _MSC_VER > 1920
|
||||
# pragma warning( disable : 4800 )
|
||||
#endif // _WIN32
|
||||
|
||||
|
@ -580,10 +580,23 @@ ExportProperties::ExportProperties(const ExportProperties &other)
|
|||
: mIntProperties(other.mIntProperties)
|
||||
, mFloatProperties(other.mFloatProperties)
|
||||
, mStringProperties(other.mStringProperties)
|
||||
, mMatrixProperties(other.mMatrixProperties) {
|
||||
, mMatrixProperties(other.mMatrixProperties)
|
||||
, mCallbackProperties(other.mCallbackProperties){
|
||||
// empty
|
||||
}
|
||||
|
||||
bool ExportProperties::SetPropertyCallback(const char *szName, const std::function<void *(void *)> &f) {
|
||||
return SetGenericProperty<std::function<void *(void *)>>(mCallbackProperties, szName, f);
|
||||
}
|
||||
|
||||
std::function<void *(void *)> ExportProperties::GetPropertyCallback(const char *szName) const {
|
||||
return GetGenericProperty<std::function<void *(void *)>>(mCallbackProperties, szName, 0);
|
||||
}
|
||||
|
||||
bool ExportProperties::HasPropertyCallback(const char *szName) const {
|
||||
return HasGenericProperty<std::function<void *(void *)>>(mCallbackProperties, szName);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Set a configuration property
|
||||
bool ExportProperties::SetPropertyInteger(const char* szName, int iValue) {
|
||||
|
|
|
@ -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
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -54,6 +54,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include "cexport.h"
|
||||
#include <map>
|
||||
#include <functional>
|
||||
|
||||
namespace Assimp {
|
||||
|
||||
|
@ -107,7 +108,8 @@ public:
|
|||
}
|
||||
|
||||
ExportFormatEntry() :
|
||||
mExportFunction(), mEnforcePP() {
|
||||
mExportFunction(),
|
||||
mEnforcePP() {
|
||||
mDescription.id = nullptr;
|
||||
mDescription.description = nullptr;
|
||||
mDescription.fileExtension = nullptr;
|
||||
|
@ -147,7 +149,7 @@ public:
|
|||
* interface is the default IO handler provided by ASSIMP. The default
|
||||
* handler is active as long the application doesn't supply its own
|
||||
* custom IO handler via #SetIOHandler().
|
||||
* @return A valid IOSystem interface, never nullptr. */
|
||||
* @return A valid IOSystem interface, never NULL. */
|
||||
IOSystem *GetIOHandler() const;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
@ -286,7 +288,7 @@ public:
|
|||
* @param pIndex Index of the export format to retrieve information
|
||||
* for. Valid range is 0 to #Exporter::GetExportFormatCount
|
||||
* @return A description of that specific export format.
|
||||
* nullptr if pIndex is out of range. */
|
||||
* NULL if pIndex is out of range. */
|
||||
const aiExportFormatDesc *GetExportFormatDescription(size_t pIndex) const;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
@ -329,6 +331,7 @@ public:
|
|||
typedef std::map<KeyType, ai_real> FloatPropertyMap;
|
||||
typedef std::map<KeyType, std::string> StringPropertyMap;
|
||||
typedef std::map<KeyType, aiMatrix4x4> MatrixPropertyMap;
|
||||
typedef std::map<KeyType, std::function<void *(void *)>> CallbackPropertyMap;
|
||||
|
||||
public:
|
||||
/** Standard constructor
|
||||
|
@ -388,6 +391,8 @@ public:
|
|||
*/
|
||||
bool SetPropertyMatrix(const char *szName, const aiMatrix4x4 &sValue);
|
||||
|
||||
bool SetPropertyCallback(const char *szName, const std::function<void *(void *)> &f);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Get a configuration property.
|
||||
* @param szName Name of the property. All supported properties
|
||||
|
@ -440,6 +445,8 @@ public:
|
|||
const aiMatrix4x4 GetPropertyMatrix(const char *szName,
|
||||
const aiMatrix4x4 &sErrorReturn = aiMatrix4x4()) const;
|
||||
|
||||
std::function<void *(void *)> GetPropertyCallback(const char* szName) const;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Determine a integer configuration property has been set.
|
||||
* @see HasPropertyInteger()
|
||||
|
@ -466,7 +473,8 @@ public:
|
|||
*/
|
||||
bool HasPropertyMatrix(const char *szName) const;
|
||||
|
||||
protected:
|
||||
bool HasPropertyCallback(const char *szName) const;
|
||||
|
||||
/** List of integer properties */
|
||||
IntPropertyMap mIntProperties;
|
||||
|
||||
|
@ -478,6 +486,8 @@ protected:
|
|||
|
||||
/** List of Matrix properties */
|
||||
MatrixPropertyMap mMatrixProperties;
|
||||
|
||||
CallbackPropertyMap mCallbackProperties;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
|
|
@ -278,7 +278,7 @@ void do_motion (void)
|
|||
static int frames = 0;
|
||||
|
||||
int time = glutGet(GLUT_ELAPSED_TIME);
|
||||
angle += static_cast<float>((time-prev_time)*0.01);
|
||||
angle += (float)((time-prev_time)*0.01);
|
||||
prev_time = time;
|
||||
|
||||
frames += 1;
|
||||
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue