add implementation methods for getPrimitiveCount, setMaterialInstancesFromMap, getMaterialInstancesAsMap and setMaterialInstanceForAll
This commit is contained in:
@@ -478,14 +478,76 @@ class FFIAsset extends ThermionAsset {
|
|||||||
return FFIMaterialInstance(ptr, app);
|
return FFIMaterialInstance(ptr, app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
Future setMaterialInstanceForAll(FFIMaterialInstance instance) async {
|
||||||
|
for (int i = 0; i < await getPrimitiveCount(entity: entity); i++) {
|
||||||
|
if (RenderableManager_isRenderable(app.renderableManager, entity)) {
|
||||||
|
await setMaterialInstanceAt(instance,
|
||||||
|
entity: entity, primitiveIndex: i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (final entity in await getChildEntities()) {
|
||||||
|
if (!RenderableManager_isRenderable(app.renderableManager, entity)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < await getPrimitiveCount(entity: entity); i++) {
|
||||||
|
await setMaterialInstanceAt(instance,
|
||||||
|
entity: entity, primitiveIndex: i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
Future<Map<ThermionEntity, List<MaterialInstance>>>
|
||||||
|
getMaterialInstancesAsMap() async {
|
||||||
|
final result = <ThermionEntity, List<MaterialInstance>>{};
|
||||||
|
var entities = [entity, ...await getChildEntities()];
|
||||||
|
|
||||||
|
for (final entity in entities) {
|
||||||
|
if (RenderableManager_isRenderable(app.renderableManager, entity)) {
|
||||||
|
result[entity] = [];
|
||||||
|
for (int i = 0; i < await getPrimitiveCount(entity: entity); i++) {
|
||||||
|
result[entity]!
|
||||||
|
.add(await getMaterialInstanceAt(entity: entity, index: i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
Future setMaterialInstancesFromMap(
|
||||||
|
Map<ThermionEntity, List<MaterialInstance>> materialInstances) async {
|
||||||
|
for (final entity in materialInstances.keys) {
|
||||||
|
if (RenderableManager_isRenderable(app.renderableManager, entity)) {
|
||||||
|
for (int i = 0; i < materialInstances[entity]!.length; i++) {
|
||||||
|
final mi = materialInstances[entity]![i];
|
||||||
|
await setMaterialInstanceAt(mi as FFIMaterialInstance,
|
||||||
|
entity: entity, primitiveIndex: i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
@override
|
@override
|
||||||
Future setMaterialInstanceAt(FFIMaterialInstance instance,
|
Future setMaterialInstanceAt(FFIMaterialInstance instance,
|
||||||
{int? entity = null, int primitiveIndex = 0}) async {
|
{int? entity = null, int primitiveIndex = 0}) async {
|
||||||
|
if (entity != null &&
|
||||||
|
!RenderableManager_isRenderable(app.renderableManager, entity)) {
|
||||||
|
_logger.warning("Provided entity is not renderable");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
if (RenderableManager_isRenderable(app.renderableManager, this.entity)) {
|
if (RenderableManager_isRenderable(app.renderableManager, this.entity)) {
|
||||||
entity ??= this.entity;
|
entity ??= this.entity;
|
||||||
} else {
|
} else {
|
||||||
@@ -503,13 +565,12 @@ class FFIAsset extends ThermionAsset {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!RenderableManager_setMaterialInstanceAt(
|
if (!RenderableManager_setMaterialInstanceAt(
|
||||||
Engine_getRenderableManager(app.engine),
|
Engine_getRenderableManager(app.engine),
|
||||||
entity,
|
entity,
|
||||||
primitiveIndex,
|
primitiveIndex,
|
||||||
instance.pointer)) {
|
instance.pointer)) {
|
||||||
_logger.warning(
|
_logger.warning(
|
||||||
"Failed to set material instance for entity $entity at primitive index ${primitiveIndex}");
|
"Failed to set material instance for entity $entity at primitive index ${primitiveIndex}");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -907,8 +968,7 @@ class FFIAsset extends ThermionAsset {
|
|||||||
///
|
///
|
||||||
///
|
///
|
||||||
Future setTransform(Matrix4 transform, {ThermionEntity? entity}) async {
|
Future setTransform(Matrix4 transform, {ThermionEntity? entity}) async {
|
||||||
await FilamentApp.instance!.setTransform(
|
await FilamentApp.instance!.setTransform(entity ?? this.entity, transform);
|
||||||
entity ?? this.entity, transform);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -987,7 +1047,9 @@ class FFIAsset extends ThermionAsset {
|
|||||||
///
|
///
|
||||||
@override
|
@override
|
||||||
Future resetBones() async {
|
Future resetBones() async {
|
||||||
await withVoidCallback((requestId, cb) => AnimationManager_resetToRestPoseRenderThread(animationManager, asset, requestId, cb));
|
await withVoidCallback((requestId, cb) =>
|
||||||
|
AnimationManager_resetToRestPoseRenderThread(
|
||||||
|
animationManager, asset, requestId, cb));
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -1084,4 +1146,9 @@ class FFIAsset extends ThermionAsset {
|
|||||||
AnimationManager_removeMorphAnimationComponent(animationManager, child);
|
AnimationManager_removeMorphAnimationComponent(animationManager, child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<int> getPrimitiveCount({ThermionEntity? entity}) async {
|
||||||
|
entity ??= this.entity;
|
||||||
|
return RenderableManager_getPrimitiveCount(app.renderableManager, entity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user