render: extract animated M2 materializer

This commit is contained in:
2026-07-18 01:48:55 +04:00
parent 9ab4c0762d
commit 456f3e2334
16 changed files with 725 additions and 78 deletions
@@ -27,8 +27,8 @@ select an imported animation and configure linear looping/playback/seek.
```mermaid
flowchart LR
Prototype[Animated prototype] --> Loader[StreamingWorldLoader materializer]
Loader -->|source and duplicate| Playback[M2AnimationPlaybackController]
Prototype[Animated prototype] --> Materializer[M2AnimatedInstanceMaterializer]
Materializer -->|source and duplicate| Playback[M2AnimationPlaybackController]
Finalizer[M2AnimatedSceneFinalizer player inventory] --> Playback
Playback --> Native[M2NativeAnimator mutation]
Playback --> Imported[AnimationPlayer mutation]
@@ -52,7 +52,7 @@ MultiMesh, SceneTree attachment and application layers are forbidden.
| Direction | Contract/data | Producer | Consumer | Ownership | Thread/lifetime |
|---|---|---|---|---|---|
| Input | Prototype and duplicate subtrees | Loader materializer | Native field copy | Borrowed Nodes | One duplicate |
| Input | Prototype and duplicate subtrees | M2 animated instance materializer | Native field copy | Borrowed Nodes | One duplicate |
| Input | Exact native animator Script | Loader composition | Native inventory | Borrowed Script | Call-local |
| Input | Relative path and instance index | Build batch adapter | Phase/selection | Copied values | One start |
| Input | AnimationPlayer inventory | Animated scene finalizer traversal | Imported playback | Borrowed players | One start |
@@ -94,29 +94,30 @@ The controller itself is stateless; lifecycle labels describe borrowed instance
```mermaid
sequenceDiagram
participant L as StreamingWorldLoader
participant M as M2AnimatedInstanceMaterializer
participant F as M2AnimatedSceneFinalizer
participant P as M2AnimationPlaybackController
participant N as M2NativeAnimator
participant A as AnimationPlayer
L->>P: copy_native_animator_data(prototype, duplicate, script)
L->>F: animation_players_in_subtree(duplicate)
F-->>L: ordered players
L->>P: start_instance_playback(path, index, players, debug)
M->>P: copy_native_animator_data(prototype, duplicate, script)
M->>F: animation_players_in_subtree(duplicate)
F-->>M: ordered players
M->>P: start_instance_playback(path, index, players, debug)
P->>N: prepare_runtime and set_phase
P->>A: choose, loop, play and seek
P-->>L: optional detached native diagnostics
L->>L: preserve existing log format
P-->>M: optional detached native diagnostics
M-->>M: tag states with instance index
```
## Dependency diagram
```mermaid
flowchart TB
Loader[StreamingWorldLoader] --> Playback[M2AnimationPlaybackController]
Finalizer[M2AnimatedSceneFinalizer] --> Loader
Loader[StreamingWorldLoader] --> Materializer[M2AnimatedInstanceMaterializer]
Materializer --> Playback[M2AnimationPlaybackController]
Materializer --> Finalizer[M2AnimatedSceneFinalizer]
Playback --> Engine[Node / Script / AnimationPlayer / Animation]
Loader --> Batch[SceneTree batch materialization]
Materializer --> Batch[SceneTree batch materialization]
Loader --> NativeScript[M2NativeAnimator script]
Playback -. no dependency .-> ResourceLoader
Playback -. no dependency .-> Cache[M2PrototypeCacheState]
@@ -125,8 +126,8 @@ flowchart TB
## Ownership, threading and resources
- Loader owns prototype duplication, instance/batch roots and SceneTree attachment.
- Finalizer traversal supplies borrowed AnimationPlayer references.
- Materializer owns prototype duplication, instance/batch roots and SceneTree attachment.
- Materializer uses finalizer traversal for borrowed AnimationPlayer references.
- Controller borrows Nodes/Script/players only for the synchronous call.
- Native arrays are assigned by reference exactly as before extraction.
- Diagnostic Dictionaries are deep-duplicated before return.
@@ -185,7 +186,7 @@ for world doodads and compatibility fixtures.
|---|---|---|---|
| Imported default selection/playback | Implemented extraction | Synthetic priority/play/seek verifier | Asset-backed animation-name corpus pending |
| Native data/phase startup | Implemented extraction | Exact-reference/native state verifier | Native visual fidelity remains experimental |
| Instance/batch materialization | Existing loader-owned | Adjacent build tests | Safe extraction next |
| Instance/batch materialization | Implemented extraction | Materializer contract verifier | Asset-backed traversal pending |
## Known gaps and risks
@@ -200,7 +201,8 @@ for world doodads and compatibility fixtures.
| `src/render/m2/m2_animation_playback_controller.gd` | Phase, selection, native copy/start and imported playback |
| `src/render/m2/m2_animated_scene_finalizer.gd` | Accepted prototype/player inventory |
| `src/scenes/streaming/m2_native_animator.gd` | Experimental native deformation runtime |
| `src/scenes/streaming/streaming_world_loader.gd` | Instance duplication/attachment and diagnostic formatting |
| `src/render/m2/m2_animated_instance_materializer.gd` | Instance duplication/attachment and playback composition |
| `src/scenes/streaming/streaming_world_loader.gd` | Build adapter, diagnostic formatting and Editor ownership |
| `src/tools/verify_m2_animation_playback_controller.gd` | Policy/mutation/boundary/timing regression |
## Related decisions and references