diff --git a/android/filament-android/src/main/cpp/RenderableManager.cpp b/android/filament-android/src/main/cpp/RenderableManager.cpp index 493996696a..0e7953a3c2 100644 --- a/android/filament-android/src/main/cpp/RenderableManager.cpp +++ b/android/filament-android/src/main/cpp/RenderableManager.cpp @@ -209,9 +209,9 @@ Java_com_google_android_filament_RenderableManager_nBuilderSkinningBones(JNIEnv* extern "C" JNIEXPORT void JNICALL Java_com_google_android_filament_RenderableManager_nBuilderMorphing(JNIEnv*, jclass, - jlong nativeBuilder, jboolean enabled) { + jlong nativeBuilder, jint targetCount) { RenderableManager::Builder *builder = (RenderableManager::Builder *) nativeBuilder; - builder->morphing(enabled); + builder->morphing(targetCount); } extern "C" JNIEXPORT void JNICALL @@ -267,11 +267,11 @@ Java_com_google_android_filament_RenderableManager_nSetBonesAsQuaternions(JNIEnv extern "C" JNIEXPORT void JNICALL Java_com_google_android_filament_RenderableManager_nSetMorphWeights(JNIEnv* env, jclass, - jlong nativeRenderableManager, jint instance, jfloatArray weights) { + jlong nativeRenderableManager, jint instance, jfloatArray weights, jint offset) { RenderableManager *rm = (RenderableManager *) nativeRenderableManager; jfloat* vec = env->GetFloatArrayElements(weights, NULL); jsize count = env->GetArrayLength(weights); - rm->setMorphWeights((RenderableManager::Instance)instance, vec, count); + rm->setMorphWeights((RenderableManager::Instance)instance, vec, count, offset); env->ReleaseFloatArrayElements(weights, vec, JNI_ABORT); } @@ -282,8 +282,14 @@ Java_com_google_android_filament_RenderableManager_nSetMorphTargetBufferAt(JNIEn RenderableManager *rm = (RenderableManager *) nativeRenderableManager; MorphTargetBuffer *morphTargetBuffer = (MorphTargetBuffer *) nativeMorphTargetBuffer; rm->setMorphTargetBufferAt((RenderableManager::Instance) i, (uint8_t) level, - (size_t) primitiveIndex, morphTargetBuffer, - (size_t) offset, (size_t) count); + (size_t) primitiveIndex, morphTargetBuffer, (size_t) offset, (size_t) count); +} + +extern "C" JNIEXPORT jint JNICALL +Java_com_google_android_filament_RenderableManager_nGetMorphTargetCount(JNIEnv* env, jclass, + jlong nativeRenderableManager, jint instance) { + RenderableManager *rm = (RenderableManager *) nativeRenderableManager; + return rm->getMorphTargetCount((RenderableManager::Instance)instance); } extern "C" JNIEXPORT void JNICALL diff --git a/android/filament-android/src/main/java/com/google/android/filament/RenderableManager.java b/android/filament-android/src/main/java/com/google/android/filament/RenderableManager.java index 61291f038b..ab1478e6fa 100644 --- a/android/filament-android/src/main/java/com/google/android/filament/RenderableManager.java +++ b/android/filament-android/src/main/java/com/google/android/filament/RenderableManager.java @@ -400,14 +400,14 @@ public class RenderableManager { } /** - * Controls if the renderable has vertex morphing targets, false by default. + * Controls if the renderable has vertex morphing targets, zero by default. * *

See also {@link RenderableManager#setMorphWeights}, which can be called on a per-frame basis * to advance the animation.

*/ @NonNull - public Builder morphing(boolean enabled) { - nBuilderMorphing(mNativeBuilder, enabled); + public Builder morphing(@IntRange(from = 0, to = 125) int targetCount) { + nBuilderMorphing(mNativeBuilder, targetCount); return this; } @@ -498,8 +498,8 @@ public class RenderableManager { * * @see Builder#morphing */ - public void setMorphWeights(@EntityInstance int i, @NonNull float[] weights) { - nSetMorphWeights(mNativeObject, i, weights); + public void setMorphWeights(@EntityInstance int i, @NonNull float[] weights, @IntRange(from = 0) int offset) { + nSetMorphWeights(mNativeObject, i, weights, offset); } /** @@ -519,6 +519,14 @@ public class RenderableManager { morphTargetBuffer.getNativeObject(), offset, count); } + /** + * Gets the morph target count on a renderable. + */ + @IntRange(from = 0) + public int getMorphTargetCount(@EntityInstance int i) { + return nGetMorphTargetCount(mNativeObject, i); + } + /** * Changes the morph target buffer for the given primitive. * @@ -789,15 +797,16 @@ public class RenderableManager { private static native void nBuilderSkinning(long nativeBuilder, int boneCount); private static native int nBuilderSkinningBones(long nativeBuilder, int boneCount, Buffer bones, int remaining); private static native void nBuilderSkinningBuffer(long nativeBuilder, long nativeSkinningBuffer, int boneCount, int offset); - private static native void nBuilderMorphing(long nativeBuilder, boolean enabled); + private static native void nBuilderMorphing(long nativeBuilder, int targetCount); private static native void nEnableSkinningBuffers(long nativeBuilder, boolean enabled); private static native void nBuilderLightChannel(long nativeRenderableManager, int channel, boolean enable); private static native void nSetSkinningBuffer(long nativeObject, int i, long nativeSkinningBuffer, int count, int offset); private static native int nSetBonesAsMatrices(long nativeObject, int i, Buffer matrices, int remaining, int boneCount, int offset); private static native int nSetBonesAsQuaternions(long nativeObject, int i, Buffer quaternions, int remaining, int boneCount, int offset); - private static native void nSetMorphWeights(long nativeObject, int instance, float[] weights); + private static native void nSetMorphWeights(long nativeObject, int instance, float[] weights, int offset); private static native void nSetMorphTargetBufferAt(long nativeObject, int i, int level, int primitiveIndex, long nativeMorphTargetBuffer, int offset, int count); + private static native int nGetMorphTargetCount(long nativeObject, int i); private static native void nSetAxisAlignedBoundingBox(long nativeRenderableManager, int i, float cx, float cy, float cz, float ex, float ey, float ez); private static native void nSetLayerMask(long nativeRenderableManager, int i, int select, int value); private static native void nSetPriority(long nativeRenderableManager, int i, int priority); diff --git a/android/gltfio-android/src/main/cpp/FilamentAsset.cpp b/android/gltfio-android/src/main/cpp/FilamentAsset.cpp index d121cb474b..252af29582 100644 --- a/android/gltfio-android/src/main/cpp/FilamentAsset.cpp +++ b/android/gltfio-android/src/main/cpp/FilamentAsset.cpp @@ -208,14 +208,6 @@ Java_com_google_android_filament_gltfio_FilamentAsset_nGetAnimator(JNIEnv* , jcl return (jlong) asset->getAnimator(); } -extern "C" JNIEXPORT int JNICALL -Java_com_google_android_filament_gltfio_FilamentAsset_nGetMorphTargetCount(JNIEnv* , jclass, - jlong nativeAsset, int entityId) { - FilamentAsset* asset = (FilamentAsset*) nativeAsset; - Entity entity = Entity::import(entityId); - return asset->getMorphTargetCount(entity); -} - extern "C" JNIEXPORT jint JNICALL Java_com_google_android_filament_gltfio_FilamentAsset_nGetResourceUriCount(JNIEnv*, jclass, jlong nativeAsset) { diff --git a/android/gltfio-android/src/main/java/com/google/android/filament/gltfio/FilamentAsset.java b/android/gltfio-android/src/main/java/com/google/android/filament/gltfio/FilamentAsset.java index e24a2134ab..046431100b 100644 --- a/android/gltfio-android/src/main/java/com/google/android/filament/gltfio/FilamentAsset.java +++ b/android/gltfio-android/src/main/java/com/google/android/filament/gltfio/FilamentAsset.java @@ -216,14 +216,6 @@ public class FilamentAsset { return mAnimator; } - /** - * Gets the number of morphing in the given entity. - */ - @IntRange(from = 0) - public int getMorphTargetCount(@Entity int entity) { - return nGetMorphTargetCount(mNativeObject, entity); - } - /** * Gets resource URIs for all externally-referenced buffers. */ @@ -273,7 +265,6 @@ public class FilamentAsset { private static native String nGetName(long nativeAsset, int entity); private static native String nGetExtras(long nativeAsset, int entity); private static native long nGetAnimator(long nativeAsset); - private static native int nGetMorphTargetCount(long nativeAsset, int entity); private static native int nGetResourceUriCount(long nativeAsset); private static native void nGetResourceUris(long nativeAsset, String[] result); private static native void nReleaseSourceData(long nativeAsset); diff --git a/filament/include/filament/RenderableManager.h b/filament/include/filament/RenderableManager.h index 5df4d183da..a77e1dea28 100644 --- a/filament/include/filament/RenderableManager.h +++ b/filament/include/filament/RenderableManager.h @@ -300,12 +300,12 @@ public: Builder& skinning(size_t boneCount) noexcept; //!< \overload /** - * Controls if the renderable has vertex morphing targets, false by default. + * Controls if the renderable has vertex morphing targets, zero by default. * * See also RenderableManager::setMorphWeights(), which can be called on a per-frame basis * to advance the animation. */ - Builder& morphing(bool enable) noexcept; + Builder& morphing(size_t targetCount) noexcept; /** * Sets an ordering index for blended primitives that all live at the same Z value. @@ -443,30 +443,41 @@ public: * Updates the bone transforms in the range [offset, offset + boneCount). * The bones must be pre-allocated using Builder::skinning(). */ - void setBones(Instance instance, Bone const* transforms, size_t boneCount = 1, size_t offset = 0) noexcept; - void setBones(Instance instance, math::mat4f const* transforms, size_t boneCount = 1, size_t offset = 0) noexcept; //!< \overload + void setBones(Instance instance, Bone const* transforms, size_t boneCount = 1, size_t offset = 0); + void setBones(Instance instance, math::mat4f const* transforms, size_t boneCount = 1, size_t offset = 0); //!< \overload /** * Associates a SkinningBuffer to a renderable instance */ void setSkinningBuffer(Instance instance, SkinningBuffer* skinningBuffer, - size_t count, size_t offset) noexcept; + size_t count, size_t offset); /** * Updates the vertex morphing weights on a renderable, all zeroes by default. * * The renderable must be built with morphing enabled, see Builder::morphing(). + * + * @param instance Instance of the component obtained from getInstance(). + * @param weights Pointer to morph target weights to be update. + * @param count Number of morph target weights. + * @param offset Index of the first first morph target weight to set at instance. */ - void setMorphWeights(Instance instance, float const* weights, size_t count) noexcept; - + void setMorphWeights(Instance instance, + float const* weights, size_t count, size_t offset = 0); /** * Associates a MorphTargetBuffer to the given primitive. */ void setMorphTargetBufferAt(Instance instance, uint8_t level, size_t primitiveIndex, - MorphTargetBuffer* morphTargetBuffer, size_t offset, size_t count) noexcept; + MorphTargetBuffer* morphTargetBuffer, size_t offset, size_t count); void setMorphTargetBufferAt(Instance instance, uint8_t level, size_t primitiveIndex, - MorphTargetBuffer* morphTargetBuffer, size_t count) noexcept; //!< \overload + MorphTargetBuffer* morphTargetBuffer, size_t count); //!< \overload + + /** + * Gets t + * number of morphing in the given entity. + */ + size_t getMorphTargetCount(Instance instance) const noexcept; /** * Gets the bounding box used for frustum culling. diff --git a/filament/src/components/RenderableManager.cpp b/filament/src/components/RenderableManager.cpp index 7ae6116433..ee1f39604c 100644 --- a/filament/src/components/RenderableManager.cpp +++ b/filament/src/components/RenderableManager.cpp @@ -53,9 +53,9 @@ struct RenderableManager::BuilderDetails { bool mCastShadows : 1; bool mReceiveShadows : 1; bool mScreenSpaceContactShadows : 1; - bool mMorphingEnabled : 1; bool mSkinningBufferMode : 1; size_t mSkinningBoneCount = 0; + size_t mMorphTargetCount = 0; Bone const* mUserBones = nullptr; mat4f const* mUserBoneMatrices = nullptr; FSkinningBuffer* mSkinningBuffer = nullptr; @@ -63,8 +63,7 @@ struct RenderableManager::BuilderDetails { explicit BuilderDetails(size_t count) : mEntries(count), mCulling(true), mCastShadows(false), mReceiveShadows(true), - mScreenSpaceContactShadows(false), mMorphingEnabled(false), - mSkinningBufferMode(false) { + mScreenSpaceContactShadows(false), mSkinningBufferMode(false) { } // this is only needed for the explicit instantiation below BuilderDetails() = default; @@ -193,8 +192,8 @@ RenderableManager::Builder& RenderableManager::Builder::enableSkinningBuffers(bo return *this; } -RenderableManager::Builder& RenderableManager::Builder::morphing(bool enable) noexcept { - mImpl->mMorphingEnabled = enable; +RenderableManager::Builder& RenderableManager::Builder::morphing(size_t targetCount) noexcept { + mImpl->mMorphTargetCount = targetCount; return *this; } @@ -318,10 +317,11 @@ void FRenderableManager::create( setScreenSpaceContactShadows(ci, builder->mScreenSpaceContactShadows); setCulling(ci, builder->mCulling); setSkinning(ci, false); - setMorphing(ci, builder->mMorphingEnabled); + setMorphing(ci, builder->mMorphTargetCount); mManager[ci].channels = builder->mChannels; const uint32_t boneCount = builder->mSkinningBoneCount; + const uint32_t targetCount = builder->mMorphTargetCount; if (builder->mSkinningBufferMode) { if (builder->mSkinningBuffer) { setSkinning(ci, boneCount > 0); @@ -333,7 +333,7 @@ void FRenderableManager::create( .skinningBufferMode = true }; } } else { - if (UTILS_UNLIKELY(boneCount > 0 || builder->mMorphingEnabled)) { + if (UTILS_UNLIKELY(boneCount > 0 || targetCount > 0)) { setSkinning(ci, boneCount > 0); Bones& bones = manager[ci].bones; // Note that we are sizing the bones UBO according to CONFIG_MAX_BONE_COUNT rather than @@ -378,7 +378,7 @@ void FRenderableManager::create( // Even morphing isn't enabled, we should create morphig resources. // Because morphing shader code is generated when skinning is enabled. // You can see more detail at Variant::SKINNING_OR_MORPHING. - if (UTILS_UNLIKELY(boneCount > 0 || builder->mMorphingEnabled)) { + if (UTILS_UNLIKELY(boneCount > 0 || targetCount > 0)) { // Instead of using a UBO per primitive, we could also have a single UBO for all primitives // and use bindUniformBufferRange which might be more efficient. MorphWeights& morphWeights = manager[ci].morphWeights; @@ -387,7 +387,7 @@ void FRenderableManager::create( sizeof(PerRenderableMorphingUib), BufferObjectBinding::UNIFORM, backend::BufferUsage::DYNAMIC), - .count = 0 }; + .count = targetCount }; } } engine.flushIfNeeded(); @@ -523,7 +523,7 @@ void FRenderableManager::setGeometryAt(Instance instance, uint8_t level, size_t } void FRenderableManager::setBones(Instance ci, - Bone const* UTILS_RESTRICT transforms, size_t boneCount, size_t offset) noexcept { + Bone const* UTILS_RESTRICT transforms, size_t boneCount, size_t offset) { if (ci) { Bones& bones = mManager[ci].bones; @@ -539,7 +539,7 @@ void FRenderableManager::setBones(Instance ci, } void FRenderableManager::setBones(Instance ci, - mat4f const* UTILS_RESTRICT transforms, size_t boneCount, size_t offset) noexcept { + mat4f const* UTILS_RESTRICT transforms, size_t boneCount, size_t offset) { if (ci) { Bones& bones = mManager[ci].bones; @@ -555,7 +555,7 @@ void FRenderableManager::setBones(Instance ci, } void FRenderableManager::setSkinningBuffer(FRenderableManager::Instance ci, - FSkinningBuffer* skinningBuffer, size_t count, size_t offset) noexcept { + FSkinningBuffer* skinningBuffer, size_t count, size_t offset) { Bones& bones = mManager[ci].bones; @@ -586,34 +586,41 @@ void FRenderableManager::setSkinningBuffer(FRenderableManager::Instance ci, } static void updateMorphWeights(FEngine& engine, backend::Handle handle, - float const* weights, size_t count) noexcept { + float const* weights, size_t count, size_t offset) noexcept { auto& driver = engine.getDriverApi(); - auto size = sizeof(PerRenderableMorphingUib); - auto* UTILS_RESTRICT out = driver.allocatePod(1); - std::transform(weights, weights + count, out->weights, + auto size = sizeof(float4) * count; + auto* UTILS_RESTRICT out = (float4*)driver.allocate(size); + std::transform(weights, weights + count, out, [](float value) { return float4(value, 0, 0, 0); }); - driver.updateBufferObject(handle, { out, size }, 0); + driver.updateBufferObject(handle, { out, size }, sizeof(float4) * offset); } -void FRenderableManager::setMorphWeights(Instance instance, float const* weights, size_t count) noexcept { +void FRenderableManager::setMorphWeights(Instance instance, float const* weights, + size_t count, size_t offset) { if (instance) { + ASSERT_PRECONDITION(count + offset < CONFIG_MAX_MORPH_TARGET_COUNT, + "Only %d morph targets are supported (count=%d, offset=%d)", + CONFIG_MAX_MORPH_TARGET_COUNT, count, offset); + MorphWeights& morphWeights = mManager[instance].morphWeights; - morphWeights.count = count; - - ASSERT_PRECONDITION(count < CONFIG_MAX_MORPH_TARGET_COUNT, - "Only %d morph targets are supported (count=%d)", CONFIG_MAX_MORPH_TARGET_COUNT, count); - if (morphWeights.handle) { - updateMorphWeights(mEngine, morphWeights.handle, weights, count); + updateMorphWeights(mEngine, morphWeights.handle, weights, count, offset); } } } void FRenderableManager::setMorphTargetBufferAt(Instance instance, uint8_t level, size_t primitiveIndex, - FMorphTargetBuffer* morphTargetBuffer, size_t offset, size_t count) noexcept { + FMorphTargetBuffer* morphTargetBuffer, size_t offset, size_t count) { assert_invariant(offset == 0 && "Offset not yet supported."); assert_invariant(count == morphTargetBuffer->getVertexCount() && "Count not yet supported."); if (instance) { + assert_invariant(morphTargetBuffer); + + MorphWeights& morphWeights = mManager[instance].morphWeights; + ASSERT_PRECONDITION(morphWeights.count == morphTargetBuffer->getCount(), + "Only %d morph targets can be set (count=%d)", + morphWeights.count, morphTargetBuffer->getCount()); + Slice& primitives = getRenderPrimitives(instance, level); if (primitiveIndex < primitives.size()) { primitives[primitiveIndex].set(morphTargetBuffer); @@ -621,6 +628,14 @@ void FRenderableManager::setMorphTargetBufferAt(Instance instance, uint8_t level } } +size_t FRenderableManager::getMorphTargetCount(Instance instance) const noexcept { + if (instance) { + const MorphWeights& morphWeights = mManager[instance].morphWeights; + return morphWeights.count; + } + return 0; +} + void FRenderableManager::setLightChannel(Instance ci, unsigned int channel, bool enable) noexcept { if (ci) { if (channel < 8) { @@ -737,36 +752,41 @@ void RenderableManager::setGeometryAt(RenderableManager::Instance instance, size } void RenderableManager::setBones(Instance instance, - RenderableManager::Bone const* transforms, size_t boneCount, size_t offset) noexcept { + RenderableManager::Bone const* transforms, size_t boneCount, size_t offset) { upcast(this)->setBones(instance, transforms, boneCount, offset); } void RenderableManager::setBones(Instance instance, - mat4f const* transforms, size_t boneCount, size_t offset) noexcept { + mat4f const* transforms, size_t boneCount, size_t offset) { upcast(this)->setBones(instance, transforms, boneCount, offset); } void RenderableManager::setSkinningBuffer(Instance instance, - SkinningBuffer* skinningBuffer, size_t count, size_t offset) noexcept { + SkinningBuffer* skinningBuffer, size_t count, size_t offset) { upcast(this)->setSkinningBuffer(instance, upcast(skinningBuffer), count, offset); } -void RenderableManager::setMorphWeights(Instance instance, float const* weights, size_t count) noexcept { - upcast(this)->setMorphWeights(instance, weights, count); +void RenderableManager::setMorphWeights(Instance instance, float const* weights, + size_t count, size_t offset) { + upcast(this)->setMorphWeights(instance, weights, count, offset); } void RenderableManager::setMorphTargetBufferAt(Instance instance, uint8_t level, size_t primitiveIndex, - MorphTargetBuffer* morphTargetBuffer, size_t offset, size_t count) noexcept { + MorphTargetBuffer* morphTargetBuffer, size_t offset, size_t count) { upcast(this)->setMorphTargetBufferAt(instance, level, primitiveIndex, upcast(morphTargetBuffer), offset, count); } void RenderableManager::setMorphTargetBufferAt(Instance instance, uint8_t level, size_t primitiveIndex, - MorphTargetBuffer* morphTargetBuffer, size_t count) noexcept { + MorphTargetBuffer* morphTargetBuffer, size_t count) { upcast(this)->setMorphTargetBufferAt(instance, level, primitiveIndex, upcast(morphTargetBuffer), 0, count); } +size_t RenderableManager::getMorphTargetCount(Instance instance) const noexcept { + return upcast(this)->getMorphTargetCount(instance); +} + void RenderableManager::setLightChannel(Instance instance, unsigned int channel, bool enable) noexcept { upcast(this)->setLightChannel(instance, channel, enable); } diff --git a/filament/src/components/RenderableManager.h b/filament/src/components/RenderableManager.h index c557b7b299..798fc889ec 100644 --- a/filament/src/components/RenderableManager.h +++ b/filament/src/components/RenderableManager.h @@ -106,13 +106,14 @@ public: inline void setSkinning(Instance instance, bool enable) noexcept; inline void setMorphing(Instance instance, bool enable) noexcept; inline void setPrimitives(Instance instance, utils::Slice const& primitives) noexcept; - inline void setBones(Instance instance, Bone const* transforms, size_t boneCount, size_t offset = 0) noexcept; - inline void setBones(Instance instance, math::mat4f const* transforms, size_t boneCount, size_t offset = 0) noexcept; + inline void setBones(Instance instance, Bone const* transforms, size_t boneCount, size_t offset = 0); + inline void setBones(Instance instance, math::mat4f const* transforms, size_t boneCount, size_t offset = 0); inline void setSkinningBuffer(Instance instance, FSkinningBuffer* skinningBuffer, - size_t count, size_t offset) noexcept; - void setMorphWeights(Instance instance, float const* weights, size_t count) noexcept; + size_t count, size_t offset); + void setMorphWeights(Instance instance, float const* weights, size_t count, size_t offset); void setMorphTargetBufferAt(Instance instance, uint8_t level, size_t primitiveIndex, - FMorphTargetBuffer* morphTargetBuffer, size_t offset, size_t count) noexcept; + FMorphTargetBuffer* morphTargetBuffer, size_t offset, size_t count); + inline size_t getMorphTargetCount(Instance instance) const noexcept; inline void setLightChannel(Instance instance, unsigned int channel, bool enable) noexcept; inline bool getLightChannel(Instance instance, unsigned int channel) const noexcept; @@ -142,7 +143,6 @@ public: uint32_t count; }; inline MorphingBindingInfo getMorphingBufferInfo(Instance instance) const noexcept; - inline int getMorphTargetCount(Instance instance) const noexcept; utils::Entity getEntity(Instance instance) const noexcept { return mManager.getEntity(instance); @@ -364,11 +364,6 @@ FRenderableManager::getMorphingBufferInfo(Instance instance) const noexcept { return { morphWeights.handle, morphWeights.count }; } -int FRenderableManager::getMorphTargetCount(Instance instance) const noexcept { - MorphWeights const& morphWeights = mManager[instance].morphWeights; - return morphWeights.count; -} - utils::Slice const& FRenderableManager::getRenderPrimitives( Instance instance, uint8_t level) const noexcept { return mManager[instance].primitives; diff --git a/libs/gltfio/include/gltfio/FilamentAsset.h b/libs/gltfio/include/gltfio/FilamentAsset.h index e61400f03a..bdbcf7e8dd 100644 --- a/libs/gltfio/include/gltfio/FilamentAsset.h +++ b/libs/gltfio/include/gltfio/FilamentAsset.h @@ -203,11 +203,6 @@ public: */ Animator* getAnimator() noexcept; - /** - * Gets the number of morphing in the given entity. - */ - int getMorphTargetCount(utils::Entity entity) noexcept; - /** * Get the target name at target index in the given entity. */ diff --git a/libs/gltfio/src/AssetLoader.cpp b/libs/gltfio/src/AssetLoader.cpp index 67b31ea2cc..3afe775eb8 100644 --- a/libs/gltfio/src/AssetLoader.cpp +++ b/libs/gltfio/src/AssetLoader.cpp @@ -492,7 +492,7 @@ void FAssetLoader::createRenderable(const cgltf_data* srcAsset, const cgltf_node } if (numMorphTargets > 0) { - builder.morphing(true); + builder.morphing(numMorphTargets); } const Aabb transformed = aabb.transform(worldTransform); diff --git a/libs/gltfio/src/FilamentAsset.cpp b/libs/gltfio/src/FilamentAsset.cpp index 22f6bf768b..7e82a2363c 100644 --- a/libs/gltfio/src/FilamentAsset.cpp +++ b/libs/gltfio/src/FilamentAsset.cpp @@ -97,13 +97,6 @@ Animator* FFilamentAsset::getAnimator() noexcept { return mAnimator; } -int FFilamentAsset::getMorphTargetCount(utils::Entity entity) noexcept { - if (mResourcesLoaded) { - return mMorpher->getTargetCount(entity); - } - return 0; -} - const char* FFilamentAsset::getMorphTargetNameAt(utils::Entity entity, size_t targetIndex) const noexcept { if (mResourcesLoaded) { @@ -291,10 +284,6 @@ Animator* FilamentAsset::getAnimator() noexcept { return upcast(this)->getAnimator(); } -int FilamentAsset::getMorphTargetCount(utils::Entity entity) noexcept { - return upcast(this)->getMorphTargetCount(entity); -} - const char* FilamentAsset::getMorphTargetNameAt(utils::Entity entity, size_t targetIndex) const noexcept { return upcast(this)->getMorphTargetNameAt(entity, targetIndex); diff --git a/libs/gltfio/src/MorphHelper.cpp b/libs/gltfio/src/MorphHelper.cpp index 9d9da60b66..42d0dad892 100644 --- a/libs/gltfio/src/MorphHelper.cpp +++ b/libs/gltfio/src/MorphHelper.cpp @@ -73,16 +73,6 @@ MorphHelper::~MorphHelper() { } } -int MorphHelper::getTargetCount(Entity entity) const noexcept { - if (mMorphTable.count(entity)) { - auto& primitive = mMorphTable.at(entity).primitives; - if (!primitive.empty() && primitive[0].targets) { - return primitive[0].targets->getCount(); - } - } - return 0; -} - const char* MorphHelper::getTargetNameAt(Entity entity, size_t targetIndex) const noexcept { if (mMorphTable.count(entity)) { auto& targetNames = mMorphTable.at(entity).targetNames; diff --git a/libs/gltfio/src/MorphHelper.h b/libs/gltfio/src/MorphHelper.h index 5509829202..f4b3c82c4d 100644 --- a/libs/gltfio/src/MorphHelper.h +++ b/libs/gltfio/src/MorphHelper.h @@ -49,7 +49,6 @@ public: MorphHelper(FFilamentAsset* asset, FFilamentInstance* inst); ~MorphHelper(); - int getTargetCount(Entity entity) const noexcept; const char* getTargetNameAt(Entity entity, size_t targetIndex) const noexcept; private: diff --git a/libs/viewer/src/SimpleViewer.cpp b/libs/viewer/src/SimpleViewer.cpp index bd9a351462..664086e215 100644 --- a/libs/viewer/src/SimpleViewer.cpp +++ b/libs/viewer/src/SimpleViewer.cpp @@ -583,7 +583,7 @@ void SimpleViewer::updateUserInterface() { rm.setCastShadows(instance, scaster); ImGui::Checkbox("receives shadows", &sreceiver); rm.setReceiveShadows(instance, sreceiver); - auto numMorphTargets = mAsset->getMorphTargetCount(entity); + auto numMorphTargets = rm.getMorphTargetCount(instance); if (numMorphTargets > 0) { bool selected = entity == mCurrentMorphingEntity; ImGui::Checkbox("morphing", &selected);