47 Commits

Author SHA1 Message Date
seker
8c1e028b46 Fix : null pointer crash (#8326) 2024-12-30 11:42:18 -08:00
Evan Mezeske
16bab2479a When applying animations, allow the time to be exactly equal to the duration before taking the fmod(), so that it is possible to animate to the exact last keyframe. Without this change, trying to animate to the last keyframe wraps back to the first, which only works for animations that loop. (#8287) 2024-11-25 09:47:28 -08:00
Hanno J. Gödecke
4ea5872b26 fix: applyCrossFade use correct instance 2024-03-13 16:13:01 -07:00
Hanno J. Gödecke
f27f0ef4fc fix: apply stashCrossFade to correct entity 2024-03-13 16:13:01 -07:00
mackong
d9c2893976 Fix possible change of scale sign when decomposing matrix (#7138)
Co-authored-by: Mathias Agopian <mathias@google.com>
2023-09-12 12:28:02 -07:00
Mathias Agopian
30979124b5 skinning now works when the model is far from the origin
We are doing skinning computations effectively in world space, so
some of the math must be done in high-precision.
2023-03-31 14:47:54 -07:00
Philip Rideout
e157023fc1 Use mField style for fields in FFilamentInstance 2022-10-17 15:49:19 -07:00
daemyung jang
784416f658 Support glTF EXT_meshopt_compression 2022-10-17 09:57:58 -07:00
Mathias Agopian
734d8ff85c rename upcast() to downcast()
it was down casting all along!
2022-10-07 17:50:56 -07:00
Philip Rideout
034aaff56c gltfio: FilamentInstance owner is now const.
In the future, we will allow instances to be constructed from
immutable assets (this is a Google feature request) so this PR
prepares for that.
2022-09-16 16:32:49 -07:00
Philip Rideout
7337a467b9 gltfio cleanup: NodeMap is now a FixedCapacityVector, etc. 2022-08-30 15:57:30 -07:00
Philip Rideout
0695c12420 gltfio: Refactor skinning, fix duplicated data.
The immutable inverse bind matrices can be shared among instances, so
they are now stored in Asset, not in Instance.

Also, there are now two "load" phases for skinning data:

(1) storing the inverse bind matrices
(2) building the Entity mappings (for animation efficiency)

Phase 1 is done in `ResourceLoader` because inverse bind matrices can
live in an external bin file.

Phase 2 is done during Instance creation, because that's when entities
are created.
2022-08-29 09:18:17 -07:00
Philip Rideout
8dc6fde588 gltfio API change: assets are now always 'instanced' etc
This change was motivated by some internal work at Google and has the
benefit of simplifying the gltfio API and implementation. There are 2
major API changes:

(1) Consolidate separate loader entry points for GLB and GLTF.

The distinction between GLB and GLTF can be made from the file content
alone, because GLB has a 4-byte magic string in its header. There is no
need for separate entry points.  Clients do not (and should not) need
to check the file name extension.

(2) Remove the distinction between "instanced" and "non-instanced"
glTF assets.

In the new scheme, all assets have at least 1 instance.

Broadly speaking, in gltfio an "asset" is a collection of Filament
objects like textures and vertex buffers, while an "instance" is a
collection of entities and components (e.g. the transform hierarchy).

This API change makes life easier for clients because they no longer
need to decide a priori if they will ever need to add instances.

This change also moves some public-facing methods from FilamentAsset to
FilamentInstance:

    - getSkinCount, getSkinNameAt
    - getJointCountAt, getJointsAt
    - attachSkin, detachSkin
2022-08-18 08:58:24 -07:00
Philip Rideout
eb1b700ef7 gltfio: minor fixups to prep for g3 integration. 2022-07-15 08:36:53 -07:00
Philip Rideout
6aa11e5ceb gltfio: use openLocalTransformTransaction API. 2022-07-11 16:17:52 -07:00
Philip Rideout
15406825aa Update cgltf, remove a morphing constraint. (#5688)
Fixes #5670.
2022-06-14 10:53:45 -07:00
Philip Rideout
30dbd3ac4f Rename gltfio to filament::gltfio. 2022-06-06 16:25:02 -07:00
Philip Rideout
2947229d40 gltfio: Streamline the AABB + skinning computation.
This optimizes and cleans up some code from a 3P contributor.

When computing a bounding box, there was no need for an inner loop
through the entire skins array.

Tested using the torus model in #4973 and the `-r` flag in gltf_viewer.
2022-05-25 10:44:31 -07:00
Philip Rideout
a01fa21209 gltfio: introduce cross-fade animation API
Fixes #4754
2022-05-24 13:22:21 -07:00
Philip Rideout
e3ccb4bb3c gltfio Animator: add resetBoneMatrices().
See #5436.
2022-04-18 15:07:35 -07:00
daemyung jang
da99fe63be Make public gltfio's math 2022-03-15 09:11:12 -07:00
daemyung jang
1924810c17 Deprecate MorphHelper
These changes bring the loading performance optimization by removing
flush and wait.
2022-02-08 10:31:17 -08:00
daemyung jang
4b572cf065 Remove duplicated APIs 2022-01-19 09:55:59 -08:00
daemyung jang
6805940bbf Compute morphing on GPU (#4999) 2022-01-12 11:06:47 -08:00
Philip Rideout
82fcb656d9 gltfio: Use BufferObject API, simplify MorphHelper. (#3737)
* gltfio: Use BufferObject API, simplify MorphHelper.

* Repair Android build.
2021-04-05 13:00:39 -07:00
Philip Rideout
8d78b1f2e1 gltfio: Add internal MorphHelper, enable up to 255 targets. (#3661)
* gltfio: Add internal MorphHelper, enable up to 255 targets.

Previously, gltfio could not animate models with more than 4 morph
targets. Now we can handle up to 255 targets, as long as no more than
4 targets are ever used simultaneously. This allows us to handle
many more models, such as those exported by Modo, and the horse model
in #1852.

We do this by picking the highest 4 weights. The indices for these
weights are called the "primary indices", and we construct a new
VertexBuffer for each unique set of primary indices.

In the near future this will be made more efficient by adding a new
VertexBuffer API to the Filament core.

Fixes #1487.

* Code review fixups.
2021-03-17 15:52:24 -07:00
Philip Rideout
6eabe0491c gltfio: Refactor Animator.
This does not change any behavior, it just prepares for the upcoming
MorphHelper class.
2021-03-17 07:38:00 -07:00
Philip Rideout
243ba77025 gltfio: support animation in dynamically-added instances.
I tested this by viewing CesiumMan with our `gltf_instances` sample app.

There is now a need for some general refactoring in gltfio. I feel that
the high-level objects have become too tightly coupled to each other.

Fixes #3137.
2021-01-19 16:37:54 -08:00
Philip Rideout
a4817f3e2a Simplify lifetime management of cgltf_data.
The gltfio API allows users to destroy ResourceLoader or FilamentAsset
even when various asynchronous work (e.g. uploading buffers to the GPU)
has not yet been completed. This was achieved in an error-prone manner
using manual reference counting and an internal management object called
AssetPool.

This PR refactors gltfio by wrapping cgltf_data in shared_ptr, which I
usually try to avoid. However in this case it provides the precisely the
functionality that is needed.

I tested this PR for memory leaks and crashes by hacking gltf_viewer
and monitoring memory usage in Activity Monitor.

This fixes #3383 and makes it easier to implement some missing features,
such as animation support for instanced assets.
2021-01-13 09:44:56 -08:00
Philip Rideout
9c20294e4b gltfio: Fix animator crash for orphaned nodes.
Fixes #3285
2020-11-18 11:26:39 -08:00
Philip Rideout
70dba2398e gltfio: add createInstance() to AssetLoader.
Note that this API is on the loader rather than the asset. This is
because the loader knows how to create Filament entities by traversing
a cgltf node hierarchy.

Animation on dynamically added instances is not yet supported.

We did not add destroyInstance() because gltfio favors flat arrays for
long term storage of entity lists and instance lists, which would be
slow to shift. We also wish to discourage create/destroy churn since it
is more efficient to pre-allocate instances and selectively add them
into the scene.

Fixes #3137.
2020-11-02 09:47:14 -08:00
Philip Rideout
47521d70a1 gltfio: fix ASAN issue when consuming invalid animation.
Release builds do not call cgltf_validate() so it was possible to
read out-of-bounds animation data when encountering a badly formed glTF
file with mismatched counts between sampler inputs and outputs.
2020-10-31 15:17:15 -07:00
Philip Rideout
1159435d47 gltfio: add safety checks to getAnimator. 2020-10-28 11:51:06 -07:00
Philip Rideout
d8c7bba403 gltfio: Fix animation by clamping the per-channel interpolant.
Tested with the model in #3124 as well as Fox, BusterDrone, CesiumMan,
InterpolationTest, and VC.

Fixes #3124.
2020-09-26 09:26:40 -07:00
Philip Rideout
cf5b6ccba3 Use MAX_MORPH_TARGETS instead of magic number. 2020-06-22 16:02:12 -07:00
Philip Rideout
42c80d5d5e Fix CUBICSPLINE interpolation for morph weights.
Tested with Polly the robo-hound and ensured that InterpolationTest
did not regress.

Partial fix for #2714.
2020-06-22 16:02:12 -07:00
Philip Rideout
adccf9f432 gltfio: remove details namespace 2020-06-01 09:19:18 -07:00
Philip Rideout
6870d360cd gltfio: Simplify FilamentInstance. 2020-05-29 07:43:44 -07:00
Philip Rideout
83cff32856 gltfio: Add support for instanced animation.
When animation is applied to the master asset, all instances are
animated.

Instances can also be individually animated via the Animator in
FilamentInstance.

Fixes #1513.
2020-05-29 07:43:44 -07:00
Philip Rideout
8de730f76c gltfio: Add support for simple instancing.
This adds createInstancedAsset() to AssetLoader, which creates a master
asset and a set of slave instances. Vertex buffers, index buffers,
textures, and material instances are shared. Entities and components are
duplicated.

Instances have their own API object that is very simple. Light sources
and material instances are not instanced, so are not accessible through
the instance API object.

The master-slave ownership model lets us avoid complex shared ownership
semantics. The existing cache structures in AssetLoader allow the
implementation of this feature to be fairly simple.

The master asset exposes the union of all entities and allows clients to
modify all instances en masse if they wish. This design also works
naturally with ResourceLoader, which does not need to know about
instancing. For example, asynchronous loading is completely unchanged;
the dependency graph simply contains the union of entities across all
instances.

Support for animation is added in a subsequent commit.

Fixes #1513.
2020-05-29 07:43:44 -07:00
Philip Rideout
e66215295c gltfio: use the new sparse support in cgltf. 2019-10-09 18:45:27 -07:00
Philip Rideout
678ffc7503 gltfio: do not loop animation samplers, fixes #1730. 2019-10-04 08:48:35 -07:00
Philip Rideout
3263c46355 Add morphing support to gltfio.
Issue #1149, #1417
2019-07-30 10:20:50 -07:00
Philip Rideout
2e391b01fe Introduce AssetPipeline for performing glTF manipulations. (#1163)
* Introduce AssetPipeline for performing glTF manipulations.

AssetPipeline offers a place for doing things like scene flattening,
transform baking, and optimization of glTF assets. These types of scene
manipulations will allow us to tackle lightmap baking in the upcoming
atlasgen tool.

This initial PR includes support for scene flattening, which is fairly
non-trivial. Support for parameterization via xatlas will be added in a
subsequent PR.

In a glTF asset, a single mesh can be referenced by several nodes, and
each reference can have a unique transform. AssetPipeline can flatten
the asset such that each instanced mesh has its own vertex data, and the
node transform gets baked into the vertex data.

Recall that gltfio is composed of two libraries: the core library (no
filamat) and the full library. This adds to the size of the full library
but leaves the core library as is.

* Fix various Windows build issues.
2019-05-03 09:49:04 -07:00
Philip Rideout
6c75c6436e Add support for glb files.
Tested with DamagedHelmet.glb
2019-03-02 00:02:40 -08:00
Philip Rideout
16d878186c Finalize Animator implementation.
- Add support for CUBICSPLINE and STEP interpolation methods.
- Use cgltf_accessor_read_float() instead of manually unpacking values.
- Fix potential NaN in decomposeMatrix.
- Reduce malloc churn by stashing the vector of bone matrices.
2019-03-01 12:35:55 -08:00
Philip Rideout
c7848efd86 Introduce the gltfio library.
This is our new mobile-friendly and web-friendly library for loading
glTF assets. It is still a work in progress, but already capable of
loading many conformance models, including those with animation,
skinning, and a couple of extensions (nonlit and texture transforms).

Next week we will add a sample app demonstrating its usage.
2019-03-01 07:27:03 -08:00