feat: add clearMorphAnimationData function

This commit is contained in:
Nick Fisher
2024-07-23 09:37:08 +08:00
parent d745712650
commit 41bf9ededa
12 changed files with 105 additions and 15 deletions

View File

@@ -368,6 +368,12 @@ external bool set_morph_animation(
double frameLengthInMs,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.Int)>()
external void clear_morph_animation(
ffi.Pointer<ffi.Void> sceneManager,
int entity,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.Int)>()
external void reset_to_rest_pose(
ffi.Pointer<ffi.Void> sceneManager,

View File

@@ -226,6 +226,11 @@ class ThermionViewerJSDartBridge {
.then((v) => v.toJS)
.toJS;
@JSExport()
void clearMorphAnimationData(ThermionEntity entity) {
viewer.clearMorphAnimationData(entity);
}
@JSExport()
JSPromise setMorphAnimationData(
ThermionEntity entity,

View File

@@ -263,6 +263,11 @@ class ThermionViewerJS implements ThermionViewer {
.toDartDouble;
}
@override
Future<void> clearMorphAnimationData(ThermionEntity entity) async {
_shim.clearMorphAnimationData(entity);
}
@override
Future<void> setMorphAnimationData(
ThermionEntity entity, MorphAnimationData animation,

View File

@@ -6,11 +6,10 @@ import 'dart:js_interop';
import 'package:thermion_dart/thermion_dart/thermion_viewer.dart';
///
/// An extension type on [JSObject] that represents a
/// An extension type on [JSObject] that represents a
/// Javascript shim implementation of the [ThermionViewer] interface.
///
///
extension type ThermionViewerJSShim(JSObject _) implements JSObject {
@JS('initialized')
external JSPromise<JSBoolean> get initialized;
@@ -136,6 +135,9 @@ extension type ThermionViewerJSShim(JSObject _) implements JSObject {
external JSPromise<JSNumber> getAnimationDuration(
ThermionEntity entity, int animationIndex);
@JS('clearMorphAnimationData')
external void clearMorphAnimationData(ThermionEntity entity);
@JS('setMorphAnimationData')
external JSPromise setMorphAnimationData(
ThermionEntity entity,
@@ -403,19 +405,16 @@ extension type ThermionViewerJSShim(JSObject _) implements JSObject {
ThermionEntity entity, JSArray<JSNumber> transform);
@JS('setBoneTransform')
external JSPromise setBoneTransform(
ThermionEntity entity, int boneIndex, JSArray<JSNumber> transform, int skinIndex);
external JSPromise setBoneTransform(ThermionEntity entity, int boneIndex,
JSArray<JSNumber> transform, int skinIndex);
@JS('setShadowsEnabled')
external JSPromise setShadowsEnabled(
bool enabled);
external JSPromise setShadowsEnabled(bool enabled);
@JS('setShadowType')
external JSPromise setShadowType(
int shadowType);
external JSPromise setShadowType(int shadowType);
@JS('setSoftShadowOptions')
external JSPromise setSoftShadowOptions(
double penumbraScale, double penumbraRatioScale);
}

View File

@@ -788,6 +788,27 @@ class ThermionViewerWasm implements ThermionViewer {
null);
}
@override
Future clearMorphAnimationData(
ThermionEntity entity) async {
var meshEntities = await getChildEntities(entity, false);
for(final childEntity in meshEntities) {
_module.ccall(
"clear_morph_animation",
"void",
[
"void*".toJS,
"int".toJS,
].toJS,
[
_sceneManager!,
childEntity.toJS,
].toJS,
null);
}
}
@override
Future setMorphAnimationData(
ThermionEntity entity, MorphAnimationData animation,

View File

@@ -269,6 +269,12 @@ abstract class ThermionViewer {
ThermionEntity entity, MorphAnimationData animation,
{List<String>? targetMeshNames});
///
/// Clear all current morph animations for [entity].
///
Future clearMorphAnimationData(
ThermionEntity entity);
///
/// Resets all bones in the given entity to their rest pose.
/// This should be done before every call to addBoneAnimation.

View File

@@ -599,6 +599,18 @@ class ThermionViewerFFI extends ThermionViewer {
return getAnimationDuration(entity, index);
}
Future clearMorphAnimationData(ThermionEntity entity) async {
var meshEntities = await getChildEntities(entity, true);
for(final childEntity in meshEntities) {
clear_morph_animation(
_sceneManager!,
childEntity);
}
}
///
///
///

View File

@@ -586,6 +586,11 @@ class ThermionViewerStub extends ThermionViewer {
throw UnimplementedError();
}
@override
Future clearMorphAnimationData(ThermionEntity entity) {
throw UnimplementedError();
}
@override
Future setMorphAnimationData(
ThermionEntity entity, MorphAnimationData animation,
@@ -726,19 +731,19 @@ class ThermionViewerStub extends ThermionViewer {
// TODO: implement zoomUpdate
throw UnimplementedError();
}
@override
Future setShadowType(ShadowType shadowType) {
// TODO: implement setShadowType
throw UnimplementedError();
}
@override
Future setShadowsEnabled(bool enabled) {
// TODO: implement setShadowsEnabled
throw UnimplementedError();
}
@override
Future setSoftShadowOptions(double penumbraScale, double penumbraRatioScale) {
// TODO: implement setSoftShadowOptions