Merge branch 'master' into update-unzip

pull/3556/head
Kim Kulling 2021-01-02 12:06:53 +01:00 committed by GitHub
commit 3298082a96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 597 additions and 277 deletions

View File

@ -34,6 +34,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#----------------------------------------------------------------------
SET(CMAKE_POLICY_DEFAULT_CMP0012 NEW)
SET(CMAKE_POLICY_DEFAULT_CMP0074 NEW)
SET(CMAKE_POLICY_DEFAULT_CMP0092 NEW)

View File

@ -375,6 +375,11 @@ bool ReadScope(TokenList& output_tokens, const char* input, const char*& cursor,
// now come the individual properties
const char* begin_cursor = cursor;
if ((begin_cursor + prop_length) > end) {
TokenizeError("property length out of bounds reading length ", input, cursor);
}
for (unsigned int i = 0; i < prop_count; ++i) {
ReadData(sbeg, send, input, cursor, begin_cursor + prop_length);

View File

@ -40,6 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <assimp/StringUtils.h>
#include <assimp/MemoryIOWrapper.h>
#include <iomanip>
// Header files, Assimp
@ -331,7 +332,10 @@ inline void Buffer::Read(Value &obj, Asset &r) {
}
} else { // Local file
if (byteLength > 0) {
std::string dir = !r.mCurrentAssetDir.empty() ? (r.mCurrentAssetDir) : "";
std::string dir = !r.mCurrentAssetDir.empty() ? (
r.mCurrentAssetDir.back() == '/' ?
r.mCurrentAssetDir : r.mCurrentAssetDir + '/'
) : "";
IOStream *file = r.OpenFile(dir + uri, "rb");
if (file) {
@ -1276,7 +1280,9 @@ inline void Asset::Load(const std::string &pFile, bool isBinary) {
/*int pos = std::max(int(pFile.rfind('/')), int(pFile.rfind('\\')));
if (pos != int(std::string::npos)) mCurrentAssetDir = pFile.substr(0, pos + 1);*/
if (0 != strncmp(pFile.c_str(), AI_MEMORYIO_MAGIC_FILENAME, AI_MEMORYIO_MAGIC_FILENAME_LENGTH)) {
mCurrentAssetDir = getCurrentAssetDir(pFile);
}
shared_ptr<IOStream> stream(OpenFile(pFile.c_str(), "rb", true));
if (!stream) {

View File

@ -46,6 +46,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* KHR_materials_pbrSpecularGlossiness full
* KHR_materials_unlit full
* KHR_lights_punctual full
* KHR_materials_sheen full
* KHR_materials_clearcoat full
* KHR_materials_transmission full
*/
#ifndef GLTF2ASSET_H_INC
#define GLTF2ASSET_H_INC
@ -677,6 +680,7 @@ const vec4 defaultBaseColor = { 1, 1, 1, 1 };
const vec3 defaultEmissiveFactor = { 0, 0, 0 };
const vec4 defaultDiffuseFactor = { 1, 1, 1, 1 };
const vec3 defaultSpecularFactor = { 1, 1, 1 };
const vec3 defaultSheenFactor = { 0, 0, 0 };
struct TextureInfo {
Ref<Texture> texture;
@ -718,6 +722,29 @@ struct PbrSpecularGlossiness {
void SetDefaults();
};
struct MaterialSheen {
vec3 sheenColorFactor;
float sheenRoughnessFactor;
TextureInfo sheenColorTexture;
TextureInfo sheenRoughnessTexture;
MaterialSheen() { SetDefaults(); }
void SetDefaults();
};
struct MaterialClearcoat {
float clearcoatFactor = 0.f;
float clearcoatRoughnessFactor = 0.f;
TextureInfo clearcoatTexture;
TextureInfo clearcoatRoughnessTexture;
NormalTextureInfo clearcoatNormalTexture;
};
struct MaterialTransmission {
TextureInfo transmissionTexture;
float transmissionFactor = 0.f;
};
//! The material appearance of a primitive.
struct Material : public Object {
//PBR metallic roughness properties
@ -735,6 +762,15 @@ struct Material : public Object {
//extension: KHR_materials_pbrSpecularGlossiness
Nullable<PbrSpecularGlossiness> pbrSpecularGlossiness;
//extension: KHR_materials_sheen
Nullable<MaterialSheen> materialSheen;
//extension: KHR_materials_clearcoat
Nullable<MaterialClearcoat> materialClearcoat;
//extension: KHR_materials_transmission
Nullable<MaterialTransmission> materialTransmission;
//extension: KHR_materials_unlit
bool unlit;
@ -1053,6 +1089,9 @@ public:
bool KHR_materials_unlit;
bool KHR_lights_punctual;
bool KHR_texture_transform;
bool KHR_materials_sheen;
bool KHR_materials_clearcoat;
bool KHR_materials_transmission;
} extensionsUsed;
//! Keeps info about the required extensions

View File

@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/StringUtils.h>
#include <assimp/DefaultLogger.hpp>
#include <assimp/MemoryIOWrapper.h>
using namespace Assimp;
@ -400,7 +401,10 @@ inline void Buffer::Read(Value &obj, Asset &r) {
}
} else { // Local file
if (byteLength > 0) {
std::string dir = !r.mCurrentAssetDir.empty() ? (r.mCurrentAssetDir) : "";
std::string dir = !r.mCurrentAssetDir.empty() ? (
r.mCurrentAssetDir.back() == '/' ?
r.mCurrentAssetDir : r.mCurrentAssetDir + '/'
) : "";
IOStream *file = r.OpenFile(dir + uri, "rb");
if (file) {
@ -1042,6 +1046,44 @@ inline void Material::Read(Value &material, Asset &r) {
if (r.extensionsUsed.KHR_texture_transform) {
}
if (r.extensionsUsed.KHR_materials_sheen) {
if (Value *curMaterialSheen = FindObject(*extensions, "KHR_materials_sheen")) {
MaterialSheen sheen;
ReadMember(*curMaterialSheen, "sheenColorFactor", sheen.sheenColorFactor);
ReadTextureProperty(r, *curMaterialSheen, "sheenColorTexture", sheen.sheenColorTexture);
ReadMember(*curMaterialSheen, "sheenRoughnessFactor", sheen.sheenRoughnessFactor);
ReadTextureProperty(r, *curMaterialSheen, "sheenRoughnessTexture", sheen.sheenRoughnessTexture);
this->materialSheen = Nullable<MaterialSheen>(sheen);
}
}
if (r.extensionsUsed.KHR_materials_clearcoat) {
if (Value *curMaterialClearcoat = FindObject(*extensions, "KHR_materials_clearcoat")) {
MaterialClearcoat clearcoat;
ReadMember(*curMaterialClearcoat, "clearcoatFactor", clearcoat.clearcoatFactor);
ReadTextureProperty(r, *curMaterialClearcoat, "clearcoatTexture", clearcoat.clearcoatTexture);
ReadMember(*curMaterialClearcoat, "clearcoatRoughnessFactor", clearcoat.clearcoatRoughnessFactor);
ReadTextureProperty(r, *curMaterialClearcoat, "clearcoatRoughnessTexture", clearcoat.clearcoatRoughnessTexture);
ReadTextureProperty(r, *curMaterialClearcoat, "clearcoatNormalTexture", clearcoat.clearcoatNormalTexture);
this->materialClearcoat = Nullable<MaterialClearcoat>(clearcoat);
}
}
if (r.extensionsUsed.KHR_materials_transmission) {
if (Value *curMaterialTransmission = FindObject(*extensions, "KHR_materials_transmission")) {
MaterialTransmission transmission;
ReadMember(*curMaterialTransmission, "transmissionFactor", transmission.transmissionFactor);
ReadTextureProperty(r, *curMaterialTransmission, "transmissionTexture", transmission.transmissionTexture);
this->materialTransmission = Nullable<MaterialTransmission>(transmission);
}
}
unlit = nullptr != FindObject(*extensions, "KHR_materials_unlit");
}
}
@ -1081,6 +1123,12 @@ inline void PbrSpecularGlossiness::SetDefaults() {
glossinessFactor = 1.0;
}
inline void MaterialSheen::SetDefaults() {
//KHR_materials_sheen properties
SetVector(sheenColorFactor, defaultSheenFactor);
sheenRoughnessFactor = 0.f;
}
namespace {
template <int N>
@ -1590,7 +1638,9 @@ inline void Asset::Load(const std::string &pFile, bool isBinary) {
/*int pos = std::max(int(pFile.rfind('/')), int(pFile.rfind('\\')));
if (pos != int(std::string::npos)) */
if (0 != strncmp(pFile.c_str(), AI_MEMORYIO_MAGIC_FILENAME, AI_MEMORYIO_MAGIC_FILENAME_LENGTH)) {
mCurrentAssetDir = glTFCommon::getCurrentAssetDir(pFile);
}
shared_ptr<IOStream> stream(OpenFile(pFile.c_str(), "rb", true));
if (!stream) {
@ -1731,6 +1781,9 @@ inline void Asset::ReadExtensionsUsed(Document &doc) {
CHECK_EXT(KHR_materials_unlit);
CHECK_EXT(KHR_lights_punctual);
CHECK_EXT(KHR_texture_transform);
CHECK_EXT(KHR_materials_sheen);
CHECK_EXT(KHR_materials_clearcoat);
CHECK_EXT(KHR_materials_transmission);
#undef CHECK_EXT
}

View File

@ -46,6 +46,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* glTF Extensions Support:
* KHR_materials_pbrSpecularGlossiness: full
* KHR_materials_unlit: full
* KHR_materials_sheen: full
* KHR_materials_clearcoat: full
* KHR_materials_transmission: full
*/
#ifndef GLTF2ASSETWRITER_H_INC
#define GLTF2ASSETWRITER_H_INC

View File

@ -417,6 +417,63 @@ namespace glTF2 {
exts.AddMember("KHR_materials_unlit", unlit, w.mAl);
}
if (m.materialSheen.isPresent) {
Value materialSheen(rapidjson::Type::kObjectType);
MaterialSheen &sheen = m.materialSheen.value;
WriteVec(materialSheen, sheen.sheenColorFactor, "sheenColorFactor", defaultSheenFactor, w.mAl);
if (sheen.sheenRoughnessFactor != 0.f) {
WriteFloat(materialSheen, sheen.sheenRoughnessFactor, "sheenRoughnessFactor", w.mAl);
}
WriteTex(materialSheen, sheen.sheenColorTexture, "sheenColorTexture", w.mAl);
WriteTex(materialSheen, sheen.sheenRoughnessTexture, "sheenRoughnessTexture", w.mAl);
if (!materialSheen.ObjectEmpty()) {
exts.AddMember("KHR_materials_sheen", materialSheen, w.mAl);
}
}
if (m.materialClearcoat.isPresent) {
Value materialClearcoat(rapidjson::Type::kObjectType);
MaterialClearcoat &clearcoat = m.materialClearcoat.value;
if (clearcoat.clearcoatFactor != 0.f) {
WriteFloat(materialClearcoat, clearcoat.clearcoatFactor, "clearcoatFactor", w.mAl);
}
if (clearcoat.clearcoatRoughnessFactor != 0.f) {
WriteFloat(materialClearcoat, clearcoat.clearcoatRoughnessFactor, "clearcoatRoughnessFactor", w.mAl);
}
WriteTex(materialClearcoat, clearcoat.clearcoatTexture, "clearcoatTexture", w.mAl);
WriteTex(materialClearcoat, clearcoat.clearcoatRoughnessTexture, "clearcoatRoughnessTexture", w.mAl);
WriteTex(materialClearcoat, clearcoat.clearcoatNormalTexture, "clearcoatNormalTexture", w.mAl);
if (!materialClearcoat.ObjectEmpty()) {
exts.AddMember("KHR_materials_clearcoat", materialClearcoat, w.mAl);
}
}
if (m.materialTransmission.isPresent) {
Value materialTransmission(rapidjson::Type::kObjectType);
MaterialTransmission &transmission = m.materialTransmission.value;
if (transmission.transmissionFactor != 0.f) {
WriteFloat(materialTransmission, transmission.transmissionFactor, "transmissionFactor", w.mAl);
}
WriteTex(materialTransmission, transmission.transmissionTexture, "transmissionTexture", w.mAl);
if (!materialTransmission.ObjectEmpty()) {
exts.AddMember("KHR_materials_transmission", materialTransmission, w.mAl);
}
}
if (!exts.ObjectEmpty()) {
obj.AddMember("extensions", exts, w.mAl);
}
@ -808,6 +865,18 @@ namespace glTF2 {
if (this->mAsset.extensionsUsed.KHR_materials_unlit) {
exts.PushBack(StringRef("KHR_materials_unlit"), mAl);
}
if (this->mAsset.extensionsUsed.KHR_materials_sheen) {
exts.PushBack(StringRef("KHR_materials_sheen"), mAl);
}
if (this->mAsset.extensionsUsed.KHR_materials_clearcoat) {
exts.PushBack(StringRef("KHR_materials_clearcoat"), mAl);
}
if (this->mAsset.extensionsUsed.KHR_materials_transmission) {
exts.PushBack(StringRef("KHR_materials_transmission"), mAl);
}
}
if (!exts.Empty())

View File

@ -714,6 +714,53 @@ void glTF2Exporter::ExportMaterials()
mAsset->extensionsUsed.KHR_materials_unlit = true;
m->unlit = true;
}
bool hasMaterialSheen = false;
mat->Get(AI_MATKEY_GLTF_MATERIAL_SHEEN, hasMaterialSheen);
if (hasMaterialSheen) {
mAsset->extensionsUsed.KHR_materials_sheen = true;
MaterialSheen sheen;
GetMatColor(mat, sheen.sheenColorFactor, AI_MATKEY_GLTF_MATERIAL_SHEEN_COLOR_FACTOR);
mat->Get(AI_MATKEY_GLTF_MATERIAL_SHEEN_ROUGHNESS_FACTOR, sheen.sheenRoughnessFactor);
GetMatTex(mat, sheen.sheenColorTexture, AI_MATKEY_GLTF_MATERIAL_SHEEN_COLOR_TEXTURE);
GetMatTex(mat, sheen.sheenRoughnessTexture, AI_MATKEY_GLTF_MATERIAL_SHEEN_ROUGHNESS_TEXTURE);
m->materialSheen = Nullable<MaterialSheen>(sheen);
}
bool hasMaterialClearcoat = false;
mat->Get(AI_MATKEY_GLTF_MATERIAL_CLEARCOAT, hasMaterialClearcoat);
if (hasMaterialClearcoat) {
mAsset->extensionsUsed.KHR_materials_clearcoat= true;
MaterialClearcoat clearcoat;
mat->Get(AI_MATKEY_GLTF_MATERIAL_CLEARCOAT_FACTOR, clearcoat.clearcoatFactor);
mat->Get(AI_MATKEY_GLTF_MATERIAL_CLEARCOAT_ROUGHNESS_FACTOR, clearcoat.clearcoatRoughnessFactor);
GetMatTex(mat, clearcoat.clearcoatTexture, AI_MATKEY_GLTF_MATERIAL_CLEARCOAT_TEXTURE);
GetMatTex(mat, clearcoat.clearcoatRoughnessTexture, AI_MATKEY_GLTF_MATERIAL_CLEARCOAT_ROUGHNESS_TEXTURE);
GetMatTex(mat, clearcoat.clearcoatNormalTexture, AI_MATKEY_GLTF_MATERIAL_CLEARCOAT_NORMAL_TEXTURE);
m->materialClearcoat = Nullable<MaterialClearcoat>(clearcoat);
}
bool hasMaterialTransmission = false;
mat->Get(AI_MATKEY_GLTF_MATERIAL_TRANSMISSION, hasMaterialTransmission);
if (hasMaterialTransmission) {
mAsset->extensionsUsed.KHR_materials_transmission = true;
MaterialTransmission transmission;
mat->Get(AI_MATKEY_GLTF_MATERIAL_TRANSMISSION_FACTOR, transmission.transmissionFactor);
GetMatTex(mat, transmission.transmissionTexture, AI_MATKEY_GLTF_MATERIAL_TRANSMISSION_TEXTURE);
m->materialTransmission = Nullable<MaterialTransmission>(transmission);
}
}
}

View File

@ -229,6 +229,7 @@ inline void SetMaterialTextureProperty(std::vector<int> &embeddedTexIdxs, Asset
static aiMaterial *ImportMaterial(std::vector<int> &embeddedTexIdxs, Asset &r, Material &mat) {
aiMaterial *aimat = new aiMaterial();
try {
if (!mat.name.empty()) {
aiString str(mat.name);
@ -281,7 +282,43 @@ static aiMaterial *ImportMaterial(std::vector<int> &embeddedTexIdxs, Asset &r, M
aimat->AddProperty(&mat.unlit, 1, AI_MATKEY_GLTF_UNLIT);
}
//KHR_materials_sheen
if (mat.materialSheen.isPresent) {
MaterialSheen &sheen = mat.materialSheen.value;
aimat->AddProperty(&mat.materialSheen.isPresent, 1, AI_MATKEY_GLTF_MATERIAL_SHEEN);
SetMaterialColorProperty(r, sheen.sheenColorFactor, aimat, AI_MATKEY_GLTF_MATERIAL_SHEEN_COLOR_FACTOR);
aimat->AddProperty(&sheen.sheenRoughnessFactor, 1, AI_MATKEY_GLTF_MATERIAL_SHEEN_ROUGHNESS_FACTOR);
SetMaterialTextureProperty(embeddedTexIdxs, r, sheen.sheenColorTexture, aimat, AI_MATKEY_GLTF_MATERIAL_SHEEN_COLOR_TEXTURE);
SetMaterialTextureProperty(embeddedTexIdxs, r, sheen.sheenRoughnessTexture, aimat, AI_MATKEY_GLTF_MATERIAL_SHEEN_ROUGHNESS_TEXTURE);
}
//KHR_materials_clearcoat
if (mat.materialClearcoat.isPresent) {
MaterialClearcoat &clearcoat = mat.materialClearcoat.value;
aimat->AddProperty(&mat.materialClearcoat.isPresent, 1, AI_MATKEY_GLTF_MATERIAL_CLEARCOAT);
aimat->AddProperty(&clearcoat.clearcoatFactor, 1, AI_MATKEY_GLTF_MATERIAL_CLEARCOAT_FACTOR);
aimat->AddProperty(&clearcoat.clearcoatRoughnessFactor, 1, AI_MATKEY_GLTF_MATERIAL_CLEARCOAT_ROUGHNESS_FACTOR);
SetMaterialTextureProperty(embeddedTexIdxs, r, clearcoat.clearcoatTexture, aimat, AI_MATKEY_GLTF_MATERIAL_CLEARCOAT_TEXTURE);
SetMaterialTextureProperty(embeddedTexIdxs, r, clearcoat.clearcoatRoughnessTexture, aimat, AI_MATKEY_GLTF_MATERIAL_CLEARCOAT_ROUGHNESS_TEXTURE);
SetMaterialTextureProperty(embeddedTexIdxs, r, clearcoat.clearcoatNormalTexture, aimat, AI_MATKEY_GLTF_MATERIAL_CLEARCOAT_NORMAL_TEXTURE);
}
//KHR_materials_transmission
if (mat.materialTransmission.isPresent) {
MaterialTransmission &transmission = mat.materialTransmission.value;
aimat->AddProperty(&mat.materialTransmission.isPresent, 1, AI_MATKEY_GLTF_MATERIAL_TRANSMISSION);
aimat->AddProperty(&transmission.transmissionFactor, 1, AI_MATKEY_GLTF_MATERIAL_TRANSMISSION_FACTOR);
SetMaterialTextureProperty(embeddedTexIdxs, r, transmission.transmissionTexture, aimat, AI_MATKEY_GLTF_MATERIAL_TRANSMISSION_TEXTURE);
}
return aimat;
} catch (...) {
delete aimat;
throw;
}
}
void glTF2Importer::ImportMaterials(glTF2::Asset &r) {
@ -291,6 +328,7 @@ void glTF2Importer::ImportMaterials(glTF2::Asset &r) {
mScene->mNumMaterials = numImportedMaterials + 1;
mScene->mMaterials = new aiMaterial *[mScene->mNumMaterials];
std::fill(mScene->mMaterials, mScene->mMaterials + mScene->mNumMaterials, nullptr);
mScene->mMaterials[numImportedMaterials] = ImportMaterial(embeddedTexIdxs, r, defaultMaterial);
for (unsigned int i = 0; i < numImportedMaterials; ++i) {
@ -452,6 +490,7 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
if (targets.size() > 0) {
aim->mNumAnimMeshes = (unsigned int)targets.size();
aim->mAnimMeshes = new aiAnimMesh *[aim->mNumAnimMeshes];
std::fill(aim->mAnimMeshes, aim->mAnimMeshes + aim->mNumAnimMeshes, nullptr);
for (size_t i = 0; i < targets.size(); i++) {
bool needPositions = targets[i].position.size() > 0;
bool needNormals = targets[i].normal.size() > 0;
@ -510,7 +549,9 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
size_t count = prim.indices->count;
Accessor::Indexer data = prim.indices->GetIndexer();
ai_assert(data.IsValid());
if (!data.IsValid()) {
throw DeadlyImportError("GLTF: Invalid accessor without data in mesh ", getContextForErrorMessages(mesh.id, mesh.name));
}
switch (prim.mode) {
case PrimitiveMode_POINTS: {
@ -699,6 +740,7 @@ void glTF2Importer::ImportCameras(glTF2::Asset &r) {
ASSIMP_LOG_DEBUG_F("Importing ", numCameras, " cameras");
mScene->mNumCameras = numCameras;
mScene->mCameras = new aiCamera *[numCameras];
std::fill(mScene->mCameras, mScene->mCameras + numCameras, nullptr);
for (size_t i = 0; i < numCameras; ++i) {
Camera &cam = r.cameras[i];
@ -735,6 +777,7 @@ void glTF2Importer::ImportLights(glTF2::Asset &r) {
ASSIMP_LOG_DEBUG_F("Importing ", numLights, " lights");
mScene->mNumLights = numLights;
mScene->mLights = new aiLight *[numLights];
std::fill(mScene->mLights, mScene->mLights + numLights, nullptr);
for (size_t i = 0; i < numLights; ++i) {
Light &light = r.lights[i];
@ -898,9 +941,11 @@ aiNode *ImportNode(aiScene *pScene, glTF2::Asset &r, std::vector<unsigned int> &
aiNode *ainode = new aiNode(GetNodeName(node));
try {
if (!node.children.empty()) {
ainode->mNumChildren = unsigned(node.children.size());
ainode->mChildren = new aiNode *[ainode->mNumChildren];
std::fill(ainode->mChildren, ainode->mChildren + ainode->mNumChildren, nullptr);
for (unsigned int i = 0; i < ainode->mNumChildren; ++i) {
aiNode *child = ImportNode(pScene, r, meshOffsets, node.children[i]);
@ -938,6 +983,7 @@ aiNode *ImportNode(aiScene *pScene, glTF2::Asset &r, std::vector<unsigned int> &
mesh->mNumBones = static_cast<unsigned int>(numBones);
mesh->mBones = new aiBone *[mesh->mNumBones];
std::fill(mesh->mBones, mesh->mBones + mesh->mNumBones, nullptr);
// GLTF and Assimp choose to store bone weights differently.
// GLTF has each vertex specify which bones influence the vertex.
@ -1021,6 +1067,10 @@ aiNode *ImportNode(aiScene *pScene, glTF2::Asset &r, std::vector<unsigned int> &
}
return ainode;
} catch (...) {
delete ainode;
throw;
}
}
void glTF2Importer::ImportNodes(glTF2::Asset &r) {
@ -1036,14 +1086,16 @@ void glTF2Importer::ImportNodes(glTF2::Asset &r) {
if (numRootNodes == 1) { // a single root node: use it
mScene->mRootNode = ImportNode(mScene, r, meshOffsets, rootNodes[0]);
} else if (numRootNodes > 1) { // more than one root node: create a fake root
aiNode *root = new aiNode("ROOT");
aiNode *root = mScene->mRootNode = new aiNode("ROOT");
root->mChildren = new aiNode *[numRootNodes];
std::fill(root->mChildren, root->mChildren + numRootNodes, nullptr);
for (unsigned int i = 0; i < numRootNodes; ++i) {
aiNode *node = ImportNode(mScene, r, meshOffsets, rootNodes[i]);
node->mParent = root;
root->mChildren[root->mNumChildren++] = node;
}
mScene->mRootNode = root;
} else {
mScene->mRootNode = new aiNode("ROOT");
}
@ -1066,6 +1118,8 @@ struct AnimationSamplers {
aiNodeAnim *CreateNodeAnim(glTF2::Asset&, Node &node, AnimationSamplers &samplers) {
aiNodeAnim *anim = new aiNodeAnim();
try {
anim->mNodeName = GetNodeName(node);
static const float kMillisecondsFromSeconds = 1000.f;
@ -1147,10 +1201,16 @@ aiNodeAnim *CreateNodeAnim(glTF2::Asset&, Node &node, AnimationSamplers &sampler
}
return anim;
} catch (...) {
delete anim;
throw;
}
}
aiMeshMorphAnim *CreateMeshMorphAnim(glTF2::Asset&, Node &node, AnimationSamplers &samplers) {
aiMeshMorphAnim *anim = new aiMeshMorphAnim();
try {
anim->mName = GetNodeName(node);
static const float kMillisecondsFromSeconds = 1000.f;
@ -1186,13 +1246,17 @@ aiMeshMorphAnim *CreateMeshMorphAnim(glTF2::Asset&, Node &node, AnimationSampler
}
return anim;
} catch (...) {
delete anim;
throw;
}
}
std::unordered_map<unsigned int, AnimationSamplers> GatherSamplers(Animation &anim) {
std::unordered_map<unsigned int, AnimationSamplers> samplers;
for (unsigned int c = 0; c < anim.channels.size(); ++c) {
Animation::Channel &channel = anim.channels[c];
if (channel.sampler >= static_cast<int>(anim.samplers.size())) {
if (channel.sampler < 0 || channel.sampler >= static_cast<int>(anim.samplers.size())) {
continue;
}
@ -1224,10 +1288,13 @@ void glTF2Importer::ImportAnimations(glTF2::Asset &r) {
}
mScene->mAnimations = new aiAnimation *[numAnimations];
std::fill(mScene->mAnimations, mScene->mAnimations + numAnimations, nullptr);
for (unsigned int i = 0; i < numAnimations; ++i) {
aiAnimation *ai_anim = mScene->mAnimations[i] = new aiAnimation();
Animation &anim = r.animations[i];
aiAnimation *ai_anim = new aiAnimation();
ai_anim->mName = anim.name;
ai_anim->mDuration = 0;
ai_anim->mTicksPerSecond = 0;
@ -1249,6 +1316,7 @@ void glTF2Importer::ImportAnimations(glTF2::Asset &r) {
ai_anim->mNumChannels = numChannels;
if (ai_anim->mNumChannels > 0) {
ai_anim->mChannels = new aiNodeAnim *[ai_anim->mNumChannels];
std::fill(ai_anim->mChannels, ai_anim->mChannels + ai_anim->mNumChannels, nullptr);
int j = 0;
for (auto &iter : samplers) {
if ((nullptr != iter.second.rotation) || (nullptr != iter.second.scale) || (nullptr != iter.second.translation)) {
@ -1261,6 +1329,7 @@ void glTF2Importer::ImportAnimations(glTF2::Asset &r) {
ai_anim->mNumMorphMeshChannels = numMorphMeshChannels;
if (ai_anim->mNumMorphMeshChannels > 0) {
ai_anim->mMorphMeshChannels = new aiMeshMorphAnim *[ai_anim->mNumMorphMeshChannels];
std::fill(ai_anim->mMorphMeshChannels, ai_anim->mMorphMeshChannels + ai_anim->mNumMorphMeshChannels, nullptr);
int j = 0;
for (auto &iter : samplers) {
if (nullptr != iter.second.weight) {
@ -1312,8 +1381,6 @@ void glTF2Importer::ImportAnimations(glTF2::Asset &r) {
ai_anim->mDuration = maxDuration;
ai_anim->mTicksPerSecond = 1000.0;
mScene->mAnimations[i] = ai_anim;
}
}
@ -1333,6 +1400,7 @@ void glTF2Importer::ImportEmbeddedTextures(glTF2::Asset &r) {
ASSIMP_LOG_DEBUG_F("Importing ", numEmbeddedTexs, " embedded textures");
mScene->mTextures = new aiTexture *[numEmbeddedTexs];
std::fill(mScene->mTextures, mScene->mTextures + numEmbeddedTexs, nullptr);
// Add the embedded textures
for (size_t i = 0; i < r.images.Size(); ++i) {

View File

@ -254,25 +254,16 @@ bool IOStreamBuffer<T>::getNextDataLine( std::vector<T> &buffer, T continuationT
}
}
bool continuationFound( false );
size_t i = 0;
for( ;; ) {
if ( continuationToken == m_cache[ m_cachePos ] ) {
continuationFound = true;
if ( continuationToken == m_cache[ m_cachePos ] && IsLineEnd( m_cache[ m_cachePos + 1 ] ) ) {
++m_cachePos;
}
if ( IsLineEnd( m_cache[ m_cachePos ] ) ) {
if ( !continuationFound ) {
// the end of the data line
break;
} else {
// skip line end
while ( m_cache[ m_cachePos ] != '\n' ) {
++m_cachePos;
}
++m_cachePos;
continuationFound = false;
}
} else if ( IsLineEnd ( m_cache[ m_cachePos ] ) ) {
break;
}
buffer[ i ] = m_cache[ m_cachePos ];

View File

@ -60,6 +60,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS "$mat.gltf.pbrSpecularGlossiness", 0, 0
#define AI_MATKEY_GLTF_PBRSPECULARGLOSSINESS_GLOSSINESS_FACTOR "$mat.gltf.pbrMetallicRoughness.glossinessFactor", 0, 0
#define AI_MATKEY_GLTF_UNLIT "$mat.gltf.unlit", 0, 0
#define AI_MATKEY_GLTF_MATERIAL_SHEEN "$mat.gltf.materialSheen", 0, 0
#define AI_MATKEY_GLTF_MATERIAL_SHEEN_COLOR_FACTOR "$mat.gltf.materialSheen.sheenColorFactor", 0, 0
#define AI_MATKEY_GLTF_MATERIAL_SHEEN_ROUGHNESS_FACTOR "$mat.gltf.materialSheen.sheenRoughnessFactor", 0, 0
#define AI_MATKEY_GLTF_MATERIAL_SHEEN_COLOR_TEXTURE aiTextureType_UNKNOWN, 1
#define AI_MATKEY_GLTF_MATERIAL_SHEEN_ROUGHNESS_TEXTURE aiTextureType_UNKNOWN, 2
#define AI_MATKEY_GLTF_MATERIAL_CLEARCOAT "$mat.gltf.materialClearcoat", 0, 0
#define AI_MATKEY_GLTF_MATERIAL_CLEARCOAT_FACTOR "$mat.gltf.materialClearcoat.clearcoatFactor", 0, 0
#define AI_MATKEY_GLTF_MATERIAL_CLEARCOAT_ROUGHNESS_FACTOR "$mat.gltf.materialClearcoat.clearcoatRoughnessFactor", 0, 0
#define AI_MATKEY_GLTF_MATERIAL_CLEARCOAT_TEXTURE aiTextureType_UNKNOWN, 3
#define AI_MATKEY_GLTF_MATERIAL_CLEARCOAT_ROUGHNESS_TEXTURE aiTextureType_UNKNOWN, 4
#define AI_MATKEY_GLTF_MATERIAL_CLEARCOAT_NORMAL_TEXTURE aiTextureType_NORMALS, 1
#define AI_MATKEY_GLTF_MATERIAL_TRANSMISSION "$mat.gltf.materialTransmission", 0, 0
#define AI_MATKEY_GLTF_MATERIAL_TRANSMISSION_FACTOR "$mat.gltf.materialTransmission.transmissionFactor", 0, 0
#define AI_MATKEY_GLTF_MATERIAL_TRANSMISSION_TEXTURE aiTextureType_UNKNOWN, 5
#define _AI_MATKEY_GLTF_TEXTURE_TEXCOORD_BASE "$tex.file.texCoord"
#define _AI_MATKEY_GLTF_MAPPINGNAME_BASE "$tex.mappingname"

View File

@ -57,6 +57,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
template <typename TReal> class aiVector3t;
template <typename TReal> class aiMatrix3x3t;
template <typename TReal> class aiMatrix4x4t;
// ---------------------------------------------------------------------------
/** Represents a quaternion in a 4D vector. */
@ -88,6 +89,9 @@ public:
bool operator== (const aiQuaterniont& o) const;
bool operator!= (const aiQuaterniont& o) const;
// transform vector by matrix
aiQuaterniont& operator *= (const aiMatrix4x4t<TReal>& mat);
bool Equal(const aiQuaterniont& o, TReal epsilon = 1e-6) const;
public:

View File

@ -57,6 +57,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <cmath>
// ------------------------------------------------------------------------------------------------
/** Transformation of a quaternion by a 4x4 matrix */
template <typename TReal>
AI_FORCE_INLINE
aiQuaterniont<TReal> operator * (const aiMatrix4x4t<TReal>& pMatrix, const aiQuaterniont<TReal>& pQuaternion) {
aiQuaterniont<TReal> res;
res.x = pMatrix.a1 * pQuaternion.x + pMatrix.a2 * pQuaternion.y + pMatrix.a3 * pQuaternion.z + pMatrix.a4 * pQuaternion.w;
res.y = pMatrix.b1 * pQuaternion.x + pMatrix.b2 * pQuaternion.y + pMatrix.b3 * pQuaternion.z + pMatrix.b4 * pQuaternion.w;
res.z = pMatrix.c1 * pQuaternion.x + pMatrix.c2 * pQuaternion.y + pMatrix.c3 * pQuaternion.z + pMatrix.c4 * pQuaternion.w;
res.w = pMatrix.d1 * pQuaternion.x + pMatrix.d2 * pQuaternion.y + pMatrix.d3 * pQuaternion.z + pMatrix.d4 * pQuaternion.w;
return res;
}
// ---------------------------------------------------------------------------
template<typename TReal>
bool aiQuaterniont<TReal>::operator== (const aiQuaterniont& o) const
@ -71,6 +83,14 @@ bool aiQuaterniont<TReal>::operator!= (const aiQuaterniont& o) const
return !(*this == o);
}
// ------------------------------------------------------------------------------------------------
template <typename TReal>
AI_FORCE_INLINE
aiQuaterniont<TReal>& aiQuaterniont<TReal>::operator *= (const aiMatrix4x4t<TReal>& mat){
return (*this = mat * (*this));
}
// ------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------
template<typename TReal>
inline bool aiQuaterniont<TReal>::Equal(const aiQuaterniont& o, TReal epsilon) const {