feat: allow setting material instance directly on ThermionAsset
This commit is contained in:
@@ -7,16 +7,50 @@ import 'package:thermion_dart/thermion_dart.dart';
|
|||||||
|
|
||||||
class FFIAsset extends ThermionAsset {
|
class FFIAsset extends ThermionAsset {
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
final Pointer<TSceneAsset> pointer;
|
final Pointer<TSceneAsset> pointer;
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
final Pointer<TSceneManager> sceneManager;
|
final Pointer<TSceneManager> sceneManager;
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
Pointer<TRenderableManager> get renderableManager =>
|
Pointer<TRenderableManager> get renderableManager =>
|
||||||
Engine_getRenderableManager(engine);
|
Engine_getRenderableManager(engine);
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
final Pointer<TEngine> engine;
|
final Pointer<TEngine> engine;
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
FFIAsset? _highlight;
|
FFIAsset? _highlight;
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
final Pointer<TMaterialProvider> _unlitMaterialProvider;
|
final Pointer<TMaterialProvider> _unlitMaterialProvider;
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
final bool isInstance;
|
final bool isInstance;
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
late final ThermionEntity entity;
|
late final ThermionEntity entity;
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
final ThermionViewer viewer;
|
final ThermionViewer viewer;
|
||||||
|
|
||||||
FFIAsset(this.pointer, this.sceneManager, this.engine,
|
FFIAsset(this.pointer, this.sceneManager, this.engine,
|
||||||
@@ -100,6 +134,9 @@ class FFIAsset extends ThermionAsset {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
@override
|
@override
|
||||||
Future removeStencilHighlight() async {
|
Future removeStencilHighlight() async {
|
||||||
if (_highlight != null) {
|
if (_highlight != null) {
|
||||||
@@ -111,6 +148,9 @@ class FFIAsset extends ThermionAsset {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
@override
|
@override
|
||||||
Future setStencilHighlight(
|
Future setStencilHighlight(
|
||||||
{double r = 1.0,
|
{double r = 1.0,
|
||||||
@@ -175,11 +215,17 @@ class FFIAsset extends ThermionAsset {
|
|||||||
SceneManager_addToScene(sceneManager, targetHighlightEntity);
|
SceneManager_addToScene(sceneManager, targetHighlightEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
@override
|
@override
|
||||||
Future addToScene() async {
|
Future addToScene() async {
|
||||||
SceneAsset_addToScene(pointer, SceneManager_getScene(sceneManager));
|
SceneAsset_addToScene(pointer, SceneManager_getScene(sceneManager));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
@override
|
@override
|
||||||
Future removeFromScene() async {
|
Future removeFromScene() async {
|
||||||
SceneManager_removeFromScene(sceneManager, entity);
|
SceneManager_removeFromScene(sceneManager, entity);
|
||||||
@@ -194,14 +240,17 @@ class FFIAsset extends ThermionAsset {
|
|||||||
late ThermionEntity targetEntity;
|
late ThermionEntity targetEntity;
|
||||||
if (RenderableManager_isRenderable(renderableManager, entity)) {
|
if (RenderableManager_isRenderable(renderableManager, entity)) {
|
||||||
targetEntity = entity;
|
targetEntity = entity;
|
||||||
} else {
|
} else {
|
||||||
targetEntity = (await getChildEntities()).first;
|
targetEntity = (await getChildEntities()).first;
|
||||||
}
|
}
|
||||||
final aabb3 = SceneManager_getRenderableBoundingBox(sceneManager, targetEntity);
|
final aabb3 =
|
||||||
|
SceneManager_getRenderableBoundingBox(sceneManager, targetEntity);
|
||||||
return aabb3;
|
return aabb3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
@override
|
@override
|
||||||
Future<void> setBoundingBoxVisibility(bool visible) async {
|
Future<void> setBoundingBoxVisibility(bool visible) async {
|
||||||
if (boundingBoxAsset == null) {
|
if (boundingBoxAsset == null) {
|
||||||
@@ -293,4 +342,17 @@ class FFIAsset extends ThermionAsset {
|
|||||||
await boundingBoxAsset!.removeFromScene();
|
await boundingBoxAsset!.removeFromScene();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
@override
|
||||||
|
Future setMaterialInstanceAt(FFIMaterialInstance instance) async {
|
||||||
|
var childEntities = await getChildEntities();
|
||||||
|
final entities = <ThermionEntity>[entity, ...childEntities];
|
||||||
|
for (final entity in entities) {
|
||||||
|
RenderableManager_setMaterialInstanceAt(
|
||||||
|
Engine_getRenderableManager(engine), entity, 0, instance.pointer);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,21 @@ export 'light_options.dart';
|
|||||||
typedef ThermionEntity = int;
|
typedef ThermionEntity = int;
|
||||||
|
|
||||||
abstract class ThermionAsset {
|
abstract class ThermionAsset {
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
ThermionEntity get entity;
|
ThermionEntity get entity;
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
Future<List<ThermionEntity>> getChildEntities();
|
Future<List<ThermionEntity>> getChildEntities();
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
Future setMaterialInstanceAt(covariant MaterialInstance instance);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Renders an outline around [entity] with the given color.
|
/// Renders an outline around [entity] with the given color.
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user