@@ -5,31 +5,108 @@ import type * as THREE from 'three';
55import type { IWorkspaceExporter } from './export' ;
66import type { ShaderGraph } from './ast' ;
77
8+ /**
9+ * Provides the core Three.js components required to initialize and render a 3D preview.
10+ * * @property scene - The Three.js scene graph object.
11+ * @property camera - The default perspective camera for the viewport.
12+ * @property material - The shader material instance that will be updated by the AST.
13+ */
814export interface RenderContext {
915 scene : THREE . Scene ;
1016 camera : THREE . PerspectiveCamera ;
1117 material : THREE . ShaderMaterial ;
1218}
1319
20+ /**
21+ * Defines the lifecycle and rendering logic for a specific visual context in the 3D canvas.
22+ */
1423export interface IPreviewStrategy {
24+ /**
25+ * Called once when the preview canvas is mounted or the context is switched.
26+ * * @param ctx - The rendering context containing the scene, camera, and material.
27+ * @param settings - The current configuration settings for this context.
28+ */
1529 init : ( ctx : RenderContext , settings : Record < string , any > ) => void ;
30+
31+ /**
32+ * Called every frame to animate and update the preview logic.
33+ * * @param time - The elapsed time in milliseconds.
34+ * @param settings - The current configuration settings for this context.
35+ * @param graph - Optional reference to the current AST for real-time mathematical evaluation.
36+ */
1637 update : ( time : number , settings : Record < string , any > , graph ?: ShaderGraph ) => void ;
38+
39+ /**
40+ * Called when a configuration parameter is modified in the context's SettingsPanel.
41+ * * @param settings - The updated configuration settings object.
42+ */
1743 onSettingsChange : ( settings : Record < string , any > ) => void ;
44+
45+ /**
46+ * Called to safely dispose of geometry, materials, and helpers to prevent memory leaks.
47+ */
1848 dispose : ( ) => void ;
1949}
2050
51+ /**
52+ * Represents an isolated environment within the engine (e.g., Material, Trail, Beam).
53+ * Encapsulates context-specific logic, UI, and rendering rules to maintain extensibility.
54+ */
2155export interface IProjectContext {
56+ /** * @property id - Unique identifier for the context.
57+ */
2258 id : string ;
59+
60+ /** * @property name - Display name used in the user interface.
61+ */
2362 name : string ;
63+
64+ /** * @property requiresGlobalMaterial - Indicates if this context relies on the compiled shader from the global MATERIAL context.
65+ */
2466 requiresGlobalMaterial ?: boolean ;
67+
68+ /**
69+ * Determines if the current settings require an orthographic camera projection.
70+ * * @param settings - The current configuration settings for the context.
71+ * @returns True if an orthographic camera should be used, false otherwise.
72+ */
2573 isOrthographic ?: ( settings : Record < string , any > ) => boolean ;
74+
75+ /**
76+ * Generates the default workspace layout.
77+ * * @returns An array of initial React Flow nodes.
78+ */
2679 getInitialNodes : ( ) => Node [ ] ;
80+
81+ /**
82+ * Evaluates whether a specific AST node type is permitted within this context.
83+ * * @param nodeType - The string identifier of the node type to check.
84+ * @returns True if the node is permitted, false otherwise.
85+ */
2786 isNodeAllowed : ( nodeType : string ) => boolean ;
87+
88+ /** * @property SettingsPanel - React component rendering the specific configuration controls for this context.
89+ */
2890 SettingsPanel : React . FC < {
2991 settings : Record < string , any > ;
3092 onSettingChange : ( key : string , value : any ) => void ;
3193 } > ;
94+
95+ /**
96+ * Instantiates the Three.js rendering strategy for the 3D preview.
97+ * * @returns A new instance of the preview strategy.
98+ */
3299 createPreviewStrategy : ( ) => IPreviewStrategy ;
100+
101+ /**
102+ * Provides the fallback configuration values for the context settings.
103+ * * @returns A dictionary of default settings.
104+ */
33105 getDefaultSettings : ( ) => Record < string , any > ;
106+
107+ /**
108+ * Provides the exporter responsible for converting the AST into game-ready metadata.
109+ * * @returns The configured workspace exporter or null if exporting is not supported.
110+ */
34111 getExporter : ( ) => IWorkspaceExporter | null ;
35112}
0 commit comments