upgrade to Filament 1.21.0
This commit is contained in:
@@ -80,6 +80,11 @@ private:
|
||||
|
||||
Animator(FFilamentAsset* asset, FFilamentInstance* instance);
|
||||
~Animator();
|
||||
|
||||
Animator(const Animator& animator) = delete;
|
||||
Animator(Animator&& animator) = delete;
|
||||
Animator& operator=(const Animator&) = delete;
|
||||
|
||||
AnimatorImpl* mImpl;
|
||||
};
|
||||
|
||||
|
||||
@@ -94,9 +94,6 @@ struct AssetConfiguration {
|
||||
* // Load buffers and textures from disk.
|
||||
* ResourceLoader({engine, ".", true}).loadResources(asset);
|
||||
*
|
||||
* // Obtain the simple animation interface.
|
||||
* Animator* animator = asset->getAnimator();
|
||||
*
|
||||
* // Free the glTF hierarchy as it is no longer needed.
|
||||
* asset->releaseSourceData();
|
||||
*
|
||||
@@ -105,8 +102,8 @@ struct AssetConfiguration {
|
||||
*
|
||||
* // Execute the render loop and play the first animation.
|
||||
* do {
|
||||
* animator->applyAnimation(0, time);
|
||||
* animator->updateBoneMatrices();
|
||||
* asset->getAnimator()->applyAnimation(0, time);
|
||||
* asset->getAnimator()->updateBoneMatrices();
|
||||
* if (renderer->beginFrame(swapChain)) {
|
||||
* renderer->render(view);
|
||||
* renderer->endFrame();
|
||||
|
||||
@@ -194,24 +194,68 @@ public:
|
||||
const char* getExtras(utils::Entity entity = {}) const noexcept;
|
||||
|
||||
/**
|
||||
* Lazily creates the animation engine or returns it from the cache.
|
||||
* Returns the animation engine.
|
||||
*
|
||||
* The animator is owned by the asset and should not be manually deleted.
|
||||
* The first time this is called, it must be called before FilamentAsset::releaseSourceData().
|
||||
* Must be called after loadResources or asyncBeginLoad, otherwise returns null.
|
||||
* If the asset is instanced, this returns a "primary" animator that controls all instances.
|
||||
* To animate each instance individually, use \see FilamentInstance.
|
||||
*/
|
||||
Animator* getAnimator() noexcept;
|
||||
Animator* getAnimator() const noexcept;
|
||||
|
||||
/**
|
||||
* Updates the morphing weights in the given entity.
|
||||
* Gets the number of skins.
|
||||
*/
|
||||
void setMorphWeights(utils::Entity entity, const float* weights, size_t count);
|
||||
size_t getSkinCount() const noexcept;
|
||||
|
||||
/**
|
||||
* Gets the number of morphing in the given entity.
|
||||
* Gets the skin name at skin index.
|
||||
*/
|
||||
int getMorphTargetCount(utils::Entity entity) noexcept;
|
||||
const char* getSkinNameAt(size_t skinIndex) const noexcept;
|
||||
|
||||
/**
|
||||
* Gets the number of joints at skin index.
|
||||
*/
|
||||
size_t getJointCountAt(size_t skinIndex) const noexcept;
|
||||
|
||||
/**
|
||||
* Gets joints at skin index.
|
||||
*/
|
||||
const utils::Entity* getJointsAt(size_t skinIndex) const noexcept;
|
||||
|
||||
/**
|
||||
* Gets the morph target name at the given index in the given entity.
|
||||
*/
|
||||
const char* getMorphTargetNameAt(utils::Entity entity, size_t targetIndex) const noexcept;
|
||||
|
||||
/**
|
||||
* Returns the number of morph targets in the given entity.
|
||||
*/
|
||||
size_t getMorphTargetCountAt(utils::Entity entity) const noexcept;
|
||||
|
||||
/**
|
||||
* Returns the number of material variants in the asset.
|
||||
*/
|
||||
size_t getMaterialVariantCount() const noexcept;
|
||||
|
||||
/**
|
||||
* Returns the name of the given material variant, or null if it is out of bounds.
|
||||
*/
|
||||
const char* getMaterialVariantName(size_t variantIndex) const noexcept;
|
||||
|
||||
/**
|
||||
* Applies the given material variant to all primitives that it affects.
|
||||
*
|
||||
* This is efficient because it merely swaps around persistent MaterialInstances. If you change
|
||||
* a material parameter while a certain variant is active, the updated value will be remembered
|
||||
* after you re-apply that variant.
|
||||
*
|
||||
* If the asset is instanced, this affects all instances in the same way.
|
||||
* To set the variant on an individual instance, use FilamentInstance::applyMaterialVariant.
|
||||
*
|
||||
* Ignored if variantIndex is out of bounds.
|
||||
*/
|
||||
void applyMaterialVariant(size_t variantIndex) noexcept;
|
||||
|
||||
/**
|
||||
* Lazily creates a single LINES renderable that draws the transformed bounding-box hierarchy
|
||||
@@ -228,7 +272,6 @@ public:
|
||||
* Reclaims CPU-side memory for URI strings, binding lists, and raw animation data.
|
||||
*
|
||||
* This should only be called after ResourceLoader::loadResources().
|
||||
* If using Animator, this should be called after getAnimator().
|
||||
* If this is an instanced asset, this prevents creation of new instances.
|
||||
*/
|
||||
void releaseSourceData() noexcept;
|
||||
|
||||
@@ -57,7 +57,14 @@ public:
|
||||
utils::Entity getRoot() const noexcept;
|
||||
|
||||
/**
|
||||
* Lazily creates the animation engine for the instance, or returns it from the cache.
|
||||
* Applies the given material variant to all primitives in this instance.
|
||||
*
|
||||
* Ignored if variantIndex is out of bounds.
|
||||
*/
|
||||
void applyMaterialVariant(size_t variantIndex) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the animation engine for the instance.
|
||||
*
|
||||
* Note that an animator can be obtained either from an individual instance, or from the
|
||||
* originating FilamentAsset. In the latter case, the animation frame is shared amongst all
|
||||
@@ -65,7 +72,6 @@ public:
|
||||
* individual instances.
|
||||
*
|
||||
* The animator is owned by the asset and should not be manually deleted.
|
||||
* The first time this is called, it must be called before FilamentAsset::releaseSourceData().
|
||||
*/
|
||||
Animator* getAnimator() noexcept;
|
||||
};
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// gltfio supports PNG and JPEG, disable all other formats.
|
||||
#define STBI_NO_BMP
|
||||
#define STBI_NO_PSD
|
||||
#define STBI_NO_TGA
|
||||
#define STBI_NO_GIF
|
||||
#define STBI_NO_HDR
|
||||
#define STBI_NO_PIC
|
||||
#define STBI_NO_PNM
|
||||
|
||||
// For emscripten and Android builds, we never load from the file
|
||||
// system, so we-opt out of the stdio functionality in stb.
|
||||
#if defined(__EMSCRIPTEN__) || defined(__ANDROID__)
|
||||
#define STBI_NO_STDIO
|
||||
#endif
|
||||
|
||||
#include <stb_image.h>
|
||||
@@ -34,6 +34,11 @@ enum class AlphaMode : uint8_t {
|
||||
BLEND
|
||||
};
|
||||
|
||||
// The following struct gets hashed so all padding bits should be explicit.
|
||||
// Tell the compiler to emit a warning if it adds any padding.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic warning "-Wpadded"
|
||||
|
||||
/**
|
||||
* \struct MaterialKey MaterialProvider.h gltfio/MaterialProvider.h
|
||||
* \brief Small POD structure that specifies the requirements for a glTF material.
|
||||
@@ -88,9 +93,12 @@ struct alignas(4) MaterialKey {
|
||||
bool hasSheen : 1;
|
||||
bool hasIOR : 1;
|
||||
bool hasVolume : 1;
|
||||
uint8_t padding : 5;
|
||||
};
|
||||
|
||||
static_assert(sizeof(MaterialKey) == 16, "MaterialKey has unexpected padding.");
|
||||
static_assert(sizeof(MaterialKey) == 16, "MaterialKey has unexpected size.");
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
bool operator==(const MaterialKey& k1, const MaterialKey& k2);
|
||||
|
||||
@@ -133,9 +141,10 @@ public:
|
||||
* @param uvmap Output argument that gets populated with a small table that maps from a glTF uv
|
||||
* index to a Filament uv index.
|
||||
* @param label Optional tag that is not a part of the cache key.
|
||||
* @param extras Optional extras as stringified JSON (not a part of the cache key). Don't store the pointer.
|
||||
*/
|
||||
virtual filament::MaterialInstance* createMaterialInstance(MaterialKey* config, UvMap* uvmap,
|
||||
const char* label = "material") = 0;
|
||||
const char* label = "material", const char* extras = nullptr) = 0;
|
||||
|
||||
/**
|
||||
* Gets a weak reference to the array of cached materials.
|
||||
|
||||
126
ios/include/gltfio/math.h
Normal file
126
ios/include/gltfio/math.h
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GLTFIO_MATH_H
|
||||
#define GLTFIO_MATH_H
|
||||
|
||||
#include <math/quat.h>
|
||||
#include <math/vec3.h>
|
||||
#include <math/mat3.h>
|
||||
#include <math/mat4.h>
|
||||
#include <math/TVecHelpers.h>
|
||||
|
||||
namespace gltfio {
|
||||
|
||||
template <typename T>
|
||||
UTILS_PUBLIC T cubicSpline(const T& vert0, const T& tang0, const T& vert1, const T& tang1, float t) {
|
||||
float tt = t * t, ttt = tt * t;
|
||||
float s2 = -2 * ttt + 3 * tt, s3 = ttt - tt;
|
||||
float s0 = 1 - s2, s1 = s3 - tt + t;
|
||||
T p0 = vert0;
|
||||
T m0 = tang0;
|
||||
T p1 = vert1;
|
||||
T m1 = tang1;
|
||||
return s0 * p0 + s1 * m0 * t + s2 * p1 + s3 * m1 * t;
|
||||
}
|
||||
|
||||
UTILS_PUBLIC inline void decomposeMatrix(const filament::math::mat4f& mat, filament::math::float3* translation,
|
||||
filament::math::quatf* rotation, filament::math::float3* scale) {
|
||||
using namespace filament::math;
|
||||
|
||||
// Extract translation.
|
||||
*translation = mat[3].xyz;
|
||||
|
||||
// Extract upper-left for determinant computation.
|
||||
const float a = mat[0][0];
|
||||
const float b = mat[0][1];
|
||||
const float c = mat[0][2];
|
||||
const float d = mat[1][0];
|
||||
const float e = mat[1][1];
|
||||
const float f = mat[1][2];
|
||||
const float g = mat[2][0];
|
||||
const float h = mat[2][1];
|
||||
const float i = mat[2][2];
|
||||
const float A = e * i - f * h;
|
||||
const float B = f * g - d * i;
|
||||
const float C = d * h - e * g;
|
||||
|
||||
// Extract scale.
|
||||
const float det(a * A + b * B + c * C);
|
||||
float scalex = length(float3({a, b, c}));
|
||||
float scaley = length(float3({d, e, f}));
|
||||
float scalez = length(float3({g, h, i}));
|
||||
float3 s = { scalex, scaley, scalez };
|
||||
if (det < 0) {
|
||||
s = -s;
|
||||
}
|
||||
*scale = s;
|
||||
|
||||
// Remove scale from the matrix if it is not close to zero.
|
||||
mat4f clone = mat;
|
||||
if (std::abs(det) > std::numeric_limits<float>::epsilon()) {
|
||||
clone[0] /= s.x;
|
||||
clone[1] /= s.y;
|
||||
clone[2] /= s.z;
|
||||
// Extract rotation
|
||||
*rotation = clone.toQuaternion();
|
||||
} else {
|
||||
// Set to identity if close to zero
|
||||
*rotation = quatf(1);
|
||||
}
|
||||
}
|
||||
|
||||
UTILS_PUBLIC inline filament::math::mat4f composeMatrix(const filament::math::float3& translation,
|
||||
const filament::math::quatf& rotation, const filament::math::float3& scale) {
|
||||
float tx = translation[0];
|
||||
float ty = translation[1];
|
||||
float tz = translation[2];
|
||||
float qx = rotation[0];
|
||||
float qy = rotation[1];
|
||||
float qz = rotation[2];
|
||||
float qw = rotation[3];
|
||||
float sx = scale[0];
|
||||
float sy = scale[1];
|
||||
float sz = scale[2];
|
||||
return filament::math::mat4f(
|
||||
(1 - 2 * qy*qy - 2 * qz*qz) * sx,
|
||||
(2 * qx*qy + 2 * qz*qw) * sx,
|
||||
(2 * qx*qz - 2 * qy*qw) * sx,
|
||||
0.f,
|
||||
(2 * qx*qy - 2 * qz*qw) * sy,
|
||||
(1 - 2 * qx*qx - 2 * qz*qz) * sy,
|
||||
(2 * qy*qz + 2 * qx*qw) * sy,
|
||||
0.f,
|
||||
(2 * qx*qz + 2 * qy*qw) * sz,
|
||||
(2 * qy*qz - 2 * qx*qw) * sz,
|
||||
(1 - 2 * qx*qx - 2 * qy*qy) * sz,
|
||||
0.f, tx, ty, tz, 1.f);
|
||||
}
|
||||
|
||||
inline filament::math::mat3f matrixFromUvTransform(const float offset[2], float rotation,
|
||||
const float scale[2]) {
|
||||
float tx = offset[0];
|
||||
float ty = offset[1];
|
||||
float sx = scale[0];
|
||||
float sy = scale[1];
|
||||
float c = cos(rotation);
|
||||
float s = sin(rotation);
|
||||
return filament::math::mat3f(sx * c, sx * s, tx, -sy * s, sy * c, ty, 0.0f, 0.0f, 1.0f);
|
||||
};
|
||||
|
||||
} // namespace gltfio
|
||||
|
||||
#endif // GLTFIO_MATH_H
|
||||
46
ios/include/gltfio/resources/gltfresources.h
Normal file
46
ios/include/gltfio/resources/gltfresources.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef GLTFRESOURCES_H_
|
||||
#define GLTFRESOURCES_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C" {
|
||||
extern const uint8_t GLTFRESOURCES_PACKAGE[];
|
||||
extern int GLTFRESOURCES_LIT_FADE_OFFSET;
|
||||
extern int GLTFRESOURCES_LIT_FADE_SIZE;
|
||||
extern int GLTFRESOURCES_LIT_OPAQUE_OFFSET;
|
||||
extern int GLTFRESOURCES_LIT_OPAQUE_SIZE;
|
||||
extern int GLTFRESOURCES_LIT_MASKED_OFFSET;
|
||||
extern int GLTFRESOURCES_LIT_MASKED_SIZE;
|
||||
extern int GLTFRESOURCES_SPECULARGLOSSINESS_FADE_OFFSET;
|
||||
extern int GLTFRESOURCES_SPECULARGLOSSINESS_FADE_SIZE;
|
||||
extern int GLTFRESOURCES_SPECULARGLOSSINESS_OPAQUE_OFFSET;
|
||||
extern int GLTFRESOURCES_SPECULARGLOSSINESS_OPAQUE_SIZE;
|
||||
extern int GLTFRESOURCES_SPECULARGLOSSINESS_MASKED_OFFSET;
|
||||
extern int GLTFRESOURCES_SPECULARGLOSSINESS_MASKED_SIZE;
|
||||
extern int GLTFRESOURCES_UNLIT_FADE_OFFSET;
|
||||
extern int GLTFRESOURCES_UNLIT_FADE_SIZE;
|
||||
extern int GLTFRESOURCES_UNLIT_OPAQUE_OFFSET;
|
||||
extern int GLTFRESOURCES_UNLIT_OPAQUE_SIZE;
|
||||
extern int GLTFRESOURCES_UNLIT_MASKED_OFFSET;
|
||||
extern int GLTFRESOURCES_UNLIT_MASKED_SIZE;
|
||||
extern int GLTFRESOURCES_LIT_VOLUME_OFFSET;
|
||||
extern int GLTFRESOURCES_LIT_VOLUME_SIZE;
|
||||
extern int GLTFRESOURCES_LIT_TRANSMISSION_OFFSET;
|
||||
extern int GLTFRESOURCES_LIT_TRANSMISSION_SIZE;
|
||||
extern int GLTFRESOURCES_LIT_SHEEN_OFFSET;
|
||||
extern int GLTFRESOURCES_LIT_SHEEN_SIZE;
|
||||
}
|
||||
#define GLTFRESOURCES_LIT_FADE_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_LIT_FADE_OFFSET)
|
||||
#define GLTFRESOURCES_LIT_OPAQUE_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_LIT_OPAQUE_OFFSET)
|
||||
#define GLTFRESOURCES_LIT_MASKED_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_LIT_MASKED_OFFSET)
|
||||
#define GLTFRESOURCES_SPECULARGLOSSINESS_FADE_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_SPECULARGLOSSINESS_FADE_OFFSET)
|
||||
#define GLTFRESOURCES_SPECULARGLOSSINESS_OPAQUE_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_SPECULARGLOSSINESS_OPAQUE_OFFSET)
|
||||
#define GLTFRESOURCES_SPECULARGLOSSINESS_MASKED_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_SPECULARGLOSSINESS_MASKED_OFFSET)
|
||||
#define GLTFRESOURCES_UNLIT_FADE_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_UNLIT_FADE_OFFSET)
|
||||
#define GLTFRESOURCES_UNLIT_OPAQUE_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_UNLIT_OPAQUE_OFFSET)
|
||||
#define GLTFRESOURCES_UNLIT_MASKED_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_UNLIT_MASKED_OFFSET)
|
||||
#define GLTFRESOURCES_LIT_VOLUME_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_LIT_VOLUME_OFFSET)
|
||||
#define GLTFRESOURCES_LIT_TRANSMISSION_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_LIT_TRANSMISSION_OFFSET)
|
||||
#define GLTFRESOURCES_LIT_SHEEN_DATA (GLTFRESOURCES_PACKAGE + GLTFRESOURCES_LIT_SHEEN_OFFSET)
|
||||
|
||||
#endif
|
||||
16
ios/include/gltfio/resources/gltfresources_lite.h
Normal file
16
ios/include/gltfio/resources/gltfresources_lite.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef GLTFRESOURCES_LITE_H_
|
||||
#define GLTFRESOURCES_LITE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C" {
|
||||
extern const uint8_t GLTFRESOURCES_LITE_PACKAGE[];
|
||||
extern int GLTFRESOURCES_LITE_LIT_OPAQUE_OFFSET;
|
||||
extern int GLTFRESOURCES_LITE_LIT_OPAQUE_SIZE;
|
||||
extern int GLTFRESOURCES_LITE_LIT_FADE_OFFSET;
|
||||
extern int GLTFRESOURCES_LITE_LIT_FADE_SIZE;
|
||||
}
|
||||
#define GLTFRESOURCES_LITE_LIT_OPAQUE_DATA (GLTFRESOURCES_LITE_PACKAGE + GLTFRESOURCES_LITE_LIT_OPAQUE_OFFSET)
|
||||
#define GLTFRESOURCES_LITE_LIT_FADE_DATA (GLTFRESOURCES_LITE_PACKAGE + GLTFRESOURCES_LITE_LIT_FADE_OFFSET)
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user