use boneName instead of boneIndex for setBoneTransform
This commit is contained in:
@@ -62,10 +62,10 @@ namespace polyvox
|
||||
/// @param entityId
|
||||
/// @param entityName
|
||||
/// @param skinIndex
|
||||
/// @param boneIndex
|
||||
/// @param boneName
|
||||
/// @param transform
|
||||
/// @return
|
||||
bool setBoneTransform(EntityId entityId, const char *entityName, int skinIndex, int boneIndex, math::mat4f transform);
|
||||
bool setBoneTransform(EntityId entityId, const char *entityName, int skinIndex, const char* boneName, math::mat4f transform);
|
||||
|
||||
/// @brief Set frame data to animate the given bones/entities.
|
||||
/// @param entity
|
||||
|
||||
@@ -127,7 +127,7 @@ extern "C"
|
||||
EntityId asset,
|
||||
const char *entityName,
|
||||
const float *const transform,
|
||||
int boneIndex);
|
||||
const char *boneName);
|
||||
FLUTTER_PLUGIN_EXPORT void play_animation(void *assetManager, EntityId asset, int index, bool loop, bool reverse, bool replaceActive, float crossfade);
|
||||
FLUTTER_PLUGIN_EXPORT void set_animation_frame(void *assetManager, EntityId asset, int animationIndex, int animationFrame);
|
||||
FLUTTER_PLUGIN_EXPORT void stop_animation(void *assetManager, EntityId asset, int index);
|
||||
|
||||
@@ -389,10 +389,10 @@ namespace polyvox
|
||||
}
|
||||
}
|
||||
|
||||
bool AssetManager::setBoneTransform(EntityId entityId, const char *entityName, int32_t skinIndex, int32_t boneIndex, math::mat4f localTransform)
|
||||
bool AssetManager::setBoneTransform(EntityId entityId, const char *entityName, int32_t skinIndex, const char* boneName, math::mat4f localTransform)
|
||||
{
|
||||
|
||||
Log("Setting transform for bone %d/skin %d for mesh target %s", boneIndex, skinIndex, entityName);
|
||||
Log("Setting transform for bone %s/skin %d for mesh target %s", boneName, skinIndex, entityName);
|
||||
|
||||
const auto &pos = _entityIdLookup.find(entityId);
|
||||
if (pos == _entityIdLookup.end())
|
||||
@@ -411,6 +411,25 @@ namespace polyvox
|
||||
TransformManager &transformManager = _engine->getTransformManager();
|
||||
|
||||
const auto &filamentInstance = sceneAsset.asset->getInstance();
|
||||
|
||||
int numJoints = filamentInstance->getJointCountAt(skinIndex);
|
||||
auto joints = filamentInstance->getJointsAt(skinIndex);
|
||||
int boneIndex = -1;
|
||||
for (int i = 0; i < numJoints; i++)
|
||||
{
|
||||
const char *jointName = _ncm->getName(_ncm->getInstance(joints[i]));
|
||||
if (strcmp(jointName, boneName) == 0)
|
||||
{
|
||||
boneIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(boneIndex == -1) {
|
||||
Log("Failed to find bone %s", boneName);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
utils::Entity joint = filamentInstance->getJointsAt(skinIndex)[boneIndex];
|
||||
|
||||
if (joint.isNull())
|
||||
|
||||
@@ -344,7 +344,7 @@ extern "C"
|
||||
EntityId entityId,
|
||||
const char *entityName,
|
||||
const float *const transform,
|
||||
int boneIndex)
|
||||
const char* boneName)
|
||||
{
|
||||
|
||||
auto matrix = math::mat4f(
|
||||
@@ -362,7 +362,7 @@ extern "C"
|
||||
transform[13],
|
||||
transform[14],
|
||||
transform[15]);
|
||||
return ((AssetManager *)assetManager)->setBoneTransform(entityId, entityName, 0, boneIndex, matrix);
|
||||
return ((AssetManager *)assetManager)->setBoneTransform(entityId, entityName, 0, boneName, matrix);
|
||||
}
|
||||
|
||||
FLUTTER_PLUGIN_EXPORT void play_animation(
|
||||
|
||||
@@ -27,6 +27,9 @@ class MorphAnimationData {
|
||||
|
||||
Iterable<double> getData(String morphName) sync* {
|
||||
int index = morphTargets.indexOf(morphName);
|
||||
if (index == -1) {
|
||||
throw Exception("No data for morph $morphName");
|
||||
}
|
||||
for (int i = 0; i < numFrames; i++) {
|
||||
yield data[(i * numMorphTargets) + index];
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ abstract class FilamentController {
|
||||
/// Sets the local joint transform for the bone at the given index in [entity] for the mesh under [meshName].
|
||||
///
|
||||
Future setBoneTransform(
|
||||
FilamentEntity entity, String meshName, int boneIndex, Matrix4 data);
|
||||
FilamentEntity entity, String meshName, String boneName, Matrix4 data);
|
||||
|
||||
///
|
||||
/// Removes/destroys the specified entity from the scene.
|
||||
|
||||
@@ -1161,16 +1161,20 @@ class FilamentControllerFFI extends FilamentController {
|
||||
}
|
||||
|
||||
@override
|
||||
Future setBoneTransform(FilamentEntity entity, String meshName, int boneIndex,
|
||||
Matrix4 data) async {
|
||||
Future setBoneTransform(FilamentEntity entity, String meshName,
|
||||
String boneName, Matrix4 data) async {
|
||||
var ptr = calloc<Float>(16);
|
||||
for (int i = 0; i < 16; i++) {
|
||||
ptr.elementAt(i).value = data.storage[i];
|
||||
}
|
||||
|
||||
set_bone_transform(_assetManager!, entity,
|
||||
meshName.toNativeUtf8().cast<Char>(), ptr, boneIndex);
|
||||
var meshNamePtr = meshName.toNativeUtf8(allocator: calloc).cast<Char>();
|
||||
var boneNamePtr = boneName.toNativeUtf8(allocator: calloc).cast<Char>();
|
||||
|
||||
set_bone_transform(_assetManager!, entity, meshNamePtr, ptr, boneNamePtr);
|
||||
|
||||
calloc.free(ptr);
|
||||
calloc.free(meshNamePtr);
|
||||
calloc.free(boneNamePtr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,15 +387,19 @@ external void add_bone_animation(
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Bool Function(ffi.Pointer<ffi.Void>, EntityId,
|
||||
ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Float>, ffi.Int)>(
|
||||
ffi.Bool Function(
|
||||
ffi.Pointer<ffi.Void>,
|
||||
EntityId,
|
||||
ffi.Pointer<ffi.Char>,
|
||||
ffi.Pointer<ffi.Float>,
|
||||
ffi.Pointer<ffi.Char>)>(
|
||||
symbol: 'set_bone_transform', assetId: 'flutter_filament_plugin')
|
||||
external bool set_bone_transform(
|
||||
ffi.Pointer<ffi.Void> assetManager,
|
||||
int asset,
|
||||
ffi.Pointer<ffi.Char> entityName,
|
||||
ffi.Pointer<ffi.Float> transform,
|
||||
int boneIndex,
|
||||
ffi.Pointer<ffi.Char> boneName,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
@@ -1049,30 +1053,6 @@ external bool set_morph_animation_ffi(
|
||||
double frameLengthInMs,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(
|
||||
ffi.Pointer<ffi.Void>,
|
||||
EntityId,
|
||||
ffi.Pointer<ffi.Float>,
|
||||
ffi.Int,
|
||||
ffi.Int,
|
||||
ffi.Pointer<ffi.Pointer<ffi.Char>>,
|
||||
ffi.Pointer<ffi.Pointer<ffi.Char>>,
|
||||
ffi.Int,
|
||||
ffi.Float)>(
|
||||
symbol: 'set_bone_animation_ffi', assetId: 'flutter_filament_plugin')
|
||||
external void set_bone_animation_ffi(
|
||||
ffi.Pointer<ffi.Void> assetManager,
|
||||
int asset,
|
||||
ffi.Pointer<ffi.Float> frameData,
|
||||
int numFrames,
|
||||
int numBones,
|
||||
ffi.Pointer<ffi.Pointer<ffi.Char>> boneNames,
|
||||
ffi.Pointer<ffi.Pointer<ffi.Char>> meshName,
|
||||
int numMeshTargets,
|
||||
double frameLengthInMs,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId, ffi.Int, ffi.Bool,
|
||||
ffi.Bool, ffi.Bool, ffi.Float)>(
|
||||
|
||||
Reference in New Issue
Block a user