@vib3code/sdk 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +118 -0
- package/DOCS/BLUEPRINT_EXECUTION_PLAN_2026-01-07.md +34 -0
- package/DOCS/CI_TESTING.md +38 -0
- package/DOCS/CLI_ONBOARDING.md +75 -0
- package/DOCS/CONTROL_REFERENCE.md +64 -0
- package/DOCS/DEV_TRACK_ANALYSIS.md +77 -0
- package/DOCS/DEV_TRACK_PLAN_2026-01-07.md +42 -0
- package/DOCS/DEV_TRACK_SESSION_2026-01-31.md +220 -0
- package/DOCS/ENV_SETUP.md +189 -0
- package/DOCS/EXPORT_FORMATS.md +417 -0
- package/DOCS/GPU_DISPOSAL_GUIDE.md +21 -0
- package/DOCS/LICENSING_TIERS.md +275 -0
- package/DOCS/MASTER_PLAN_2026-01-31.md +570 -0
- package/DOCS/OBS_SETUP_GUIDE.md +98 -0
- package/DOCS/PROJECT_SETUP.md +66 -0
- package/DOCS/RENDERER_LIFECYCLE.md +40 -0
- package/DOCS/REPO_MANIFEST.md +121 -0
- package/DOCS/SESSION_014_PLAN.md +195 -0
- package/DOCS/SESSION_LOG_2026-01-07.md +56 -0
- package/DOCS/STRATEGIC_BLUEPRINT_2026-01-07.md +72 -0
- package/DOCS/SYSTEM_AUDIT_2026-01-30.md +738 -0
- package/DOCS/SYSTEM_INVENTORY.md +520 -0
- package/DOCS/TELEMETRY_EXPORTS.md +34 -0
- package/DOCS/WEBGPU_STATUS.md +38 -0
- package/DOCS/XR_BENCHMARKS.md +608 -0
- package/LICENSE +21 -0
- package/README.md +426 -0
- package/docs/.nojekyll +0 -0
- package/docs/01-dissolution_of_euclidean_hegemony.html +346 -0
- package/docs/02-hyperspatial_ego_death.html +346 -0
- package/docs/03-post_cartesian_sublime.html +346 -0
- package/docs/04-crystalline_void_meditation.html +346 -0
- package/docs/05-quantum_decoherence_ballet.html +346 -0
- package/docs/06-dissolution_of_euclidean_hegemony.html +346 -0
- package/docs/07-hyperspatial_ego_death.html +346 -0
- package/docs/08-post_cartesian_sublime.html +346 -0
- package/docs/09-crystalline_void_meditation.html +346 -0
- package/docs/10-quantum_decoherence_ballet.html +346 -0
- package/docs/11-dissolution_of_euclidean_hegemony.html +346 -0
- package/docs/12-hyperspatial_ego_death.html +346 -0
- package/docs/13-post_cartesian_sublime.html +346 -0
- package/docs/index.html +794 -0
- package/docs/test-hub.html +441 -0
- package/docs/url-state.js +102 -0
- package/docs/vib3-exports/01-quantum-quantum-tetrahedron-lattice.html +489 -0
- package/docs/vib3-exports/02-quantum-quantum-hypersphere-matrix.html +489 -0
- package/docs/vib3-exports/03-quantum-quantum-hypertetra-fractal.html +489 -0
- package/docs/vib3-exports/04-faceted-faceted-crystal-structure.html +407 -0
- package/docs/vib3-exports/05-faceted-faceted-klein-bottle.html +407 -0
- package/docs/vib3-exports/06-faceted-faceted-hypertetra-torus.html +407 -0
- package/docs/vib3-exports/07-holographic-holographic-wave-field.html +457 -0
- package/docs/vib3-exports/08-holographic-holographic-hypersphere-sphere.html +457 -0
- package/docs/vib3-exports/09-holographic-holographic-hypertetra-crystal.html +457 -0
- package/docs/vib3-exports/index.html +238 -0
- package/docs/webgpu-live.html +702 -0
- package/package.json +367 -0
- package/src/advanced/AIPresetGenerator.js +777 -0
- package/src/advanced/MIDIController.js +703 -0
- package/src/advanced/OffscreenWorker.js +1051 -0
- package/src/advanced/WebGPUCompute.js +1051 -0
- package/src/advanced/WebXRRenderer.js +680 -0
- package/src/agent/cli/AgentCLI.js +615 -0
- package/src/agent/cli/index.js +14 -0
- package/src/agent/index.js +73 -0
- package/src/agent/mcp/MCPServer.js +950 -0
- package/src/agent/mcp/index.js +9 -0
- package/src/agent/mcp/tools.js +548 -0
- package/src/agent/telemetry/EventStream.js +669 -0
- package/src/agent/telemetry/Instrumentation.js +618 -0
- package/src/agent/telemetry/TelemetryExporters.js +427 -0
- package/src/agent/telemetry/TelemetryService.js +464 -0
- package/src/agent/telemetry/index.js +52 -0
- package/src/benchmarks/BenchmarkRunner.js +381 -0
- package/src/benchmarks/MetricsCollector.js +299 -0
- package/src/benchmarks/index.js +9 -0
- package/src/benchmarks/scenes.js +259 -0
- package/src/cli/index.js +675 -0
- package/src/config/ApiConfig.js +88 -0
- package/src/core/CanvasManager.js +217 -0
- package/src/core/ErrorReporter.js +117 -0
- package/src/core/ParameterMapper.js +333 -0
- package/src/core/Parameters.js +396 -0
- package/src/core/RendererContracts.js +200 -0
- package/src/core/UnifiedResourceManager.js +370 -0
- package/src/core/VIB3Engine.js +636 -0
- package/src/core/renderers/FacetedRendererAdapter.js +32 -0
- package/src/core/renderers/HolographicRendererAdapter.js +29 -0
- package/src/core/renderers/QuantumRendererAdapter.js +29 -0
- package/src/core/renderers/RendererLifecycleManager.js +63 -0
- package/src/creative/ColorPresetsSystem.js +980 -0
- package/src/creative/ParameterTimeline.js +1061 -0
- package/src/creative/PostProcessingPipeline.js +1113 -0
- package/src/creative/TransitionAnimator.js +683 -0
- package/src/export/CSSExporter.js +226 -0
- package/src/export/CardGeneratorBase.js +279 -0
- package/src/export/ExportManager.js +580 -0
- package/src/export/FacetedCardGenerator.js +279 -0
- package/src/export/HolographicCardGenerator.js +543 -0
- package/src/export/LottieExporter.js +552 -0
- package/src/export/QuantumCardGenerator.js +315 -0
- package/src/export/SVGExporter.js +519 -0
- package/src/export/ShaderExporter.js +903 -0
- package/src/export/TradingCardGenerator.js +3055 -0
- package/src/export/TradingCardManager.js +181 -0
- package/src/export/VIB3PackageExporter.js +559 -0
- package/src/export/index.js +14 -0
- package/src/export/systems/TradingCardSystemFaceted.js +494 -0
- package/src/export/systems/TradingCardSystemHolographic.js +452 -0
- package/src/export/systems/TradingCardSystemQuantum.js +411 -0
- package/src/faceted/FacetedSystem.js +963 -0
- package/src/features/CollectionManager.js +433 -0
- package/src/gallery/CollectionManager.js +240 -0
- package/src/gallery/GallerySystem.js +485 -0
- package/src/geometry/GeometryFactory.js +314 -0
- package/src/geometry/GeometryLibrary.js +72 -0
- package/src/geometry/buffers/BufferBuilder.js +338 -0
- package/src/geometry/buffers/index.js +18 -0
- package/src/geometry/generators/Crystal.js +420 -0
- package/src/geometry/generators/Fractal.js +298 -0
- package/src/geometry/generators/KleinBottle.js +197 -0
- package/src/geometry/generators/Sphere.js +192 -0
- package/src/geometry/generators/Tesseract.js +160 -0
- package/src/geometry/generators/Tetrahedron.js +225 -0
- package/src/geometry/generators/Torus.js +304 -0
- package/src/geometry/generators/Wave.js +341 -0
- package/src/geometry/index.js +142 -0
- package/src/geometry/warp/HypersphereCore.js +211 -0
- package/src/geometry/warp/HypertetraCore.js +386 -0
- package/src/geometry/warp/index.js +57 -0
- package/src/holograms/HolographicVisualizer.js +1073 -0
- package/src/holograms/RealHolographicSystem.js +966 -0
- package/src/holograms/variantRegistry.js +69 -0
- package/src/integrations/FigmaPlugin.js +854 -0
- package/src/integrations/OBSMode.js +754 -0
- package/src/integrations/ThreeJsPackage.js +660 -0
- package/src/integrations/TouchDesignerExport.js +552 -0
- package/src/integrations/frameworks/Vib3React.js +591 -0
- package/src/integrations/frameworks/Vib3Svelte.js +654 -0
- package/src/integrations/frameworks/Vib3Vue.js +628 -0
- package/src/llm/LLMParameterInterface.js +240 -0
- package/src/llm/LLMParameterUI.js +577 -0
- package/src/math/Mat4x4.js +708 -0
- package/src/math/Projection.js +341 -0
- package/src/math/Rotor4D.js +637 -0
- package/src/math/Vec4.js +476 -0
- package/src/math/constants.js +164 -0
- package/src/math/index.js +68 -0
- package/src/math/projections.js +54 -0
- package/src/math/rotations.js +196 -0
- package/src/quantum/QuantumEngine.js +906 -0
- package/src/quantum/QuantumVisualizer.js +1103 -0
- package/src/reactivity/ReactivityConfig.js +499 -0
- package/src/reactivity/ReactivityManager.js +586 -0
- package/src/reactivity/SpatialInputSystem.js +1783 -0
- package/src/reactivity/index.js +93 -0
- package/src/render/CommandBuffer.js +465 -0
- package/src/render/MultiCanvasBridge.js +340 -0
- package/src/render/RenderCommand.js +514 -0
- package/src/render/RenderResourceRegistry.js +523 -0
- package/src/render/RenderState.js +552 -0
- package/src/render/RenderTarget.js +512 -0
- package/src/render/ShaderLoader.js +253 -0
- package/src/render/ShaderProgram.js +599 -0
- package/src/render/UnifiedRenderBridge.js +496 -0
- package/src/render/backends/WebGLBackend.js +1108 -0
- package/src/render/backends/WebGPUBackend.js +1409 -0
- package/src/render/commands/CommandBufferExecutor.js +607 -0
- package/src/render/commands/RenderCommandBuffer.js +661 -0
- package/src/render/commands/index.js +17 -0
- package/src/render/index.js +367 -0
- package/src/scene/Disposable.js +498 -0
- package/src/scene/MemoryPool.js +618 -0
- package/src/scene/Node4D.js +697 -0
- package/src/scene/ResourceManager.js +599 -0
- package/src/scene/Scene4D.js +540 -0
- package/src/scene/index.js +98 -0
- package/src/schemas/error.schema.json +84 -0
- package/src/schemas/extension.schema.json +88 -0
- package/src/schemas/index.js +214 -0
- package/src/schemas/parameters.schema.json +142 -0
- package/src/schemas/tool-pack.schema.json +44 -0
- package/src/schemas/tool-response.schema.json +127 -0
- package/src/shaders/common/fullscreen.vert.glsl +5 -0
- package/src/shaders/common/fullscreen.vert.wgsl +17 -0
- package/src/shaders/common/geometry24.glsl +65 -0
- package/src/shaders/common/geometry24.wgsl +54 -0
- package/src/shaders/common/rotation4d.glsl +85 -0
- package/src/shaders/common/rotation4d.wgsl +86 -0
- package/src/shaders/common/uniforms.glsl +44 -0
- package/src/shaders/common/uniforms.wgsl +48 -0
- package/src/shaders/faceted/faceted.frag.glsl +129 -0
- package/src/shaders/faceted/faceted.frag.wgsl +164 -0
- package/src/shaders/holographic/holographic.frag.glsl +406 -0
- package/src/shaders/holographic/holographic.frag.wgsl +185 -0
- package/src/shaders/quantum/quantum.frag.glsl +513 -0
- package/src/shaders/quantum/quantum.frag.wgsl +361 -0
- package/src/testing/ParallelTestFramework.js +519 -0
- package/src/testing/__snapshots__/exportFormats.test.js.snap +24 -0
- package/src/testing/exportFormats.test.js +8 -0
- package/src/testing/projections.test.js +14 -0
- package/src/testing/rotations.test.js +37 -0
- package/src/ui/InteractivityMenu.js +516 -0
- package/src/ui/StatusManager.js +96 -0
- package/src/ui/adaptive/renderers/webgpu/BufferLayout.ts +252 -0
- package/src/ui/adaptive/renderers/webgpu/PolytopeInstanceBuffer.ts +144 -0
- package/src/ui/adaptive/renderers/webgpu/TripleBufferedUniform.ts +170 -0
- package/src/ui/adaptive/renderers/webgpu/WebGPURenderer.ts +735 -0
- package/src/ui/adaptive/renderers/webgpu/index.ts +112 -0
- package/src/variations/VariationManager.js +431 -0
- package/src/viewer/AudioReactivity.js +505 -0
- package/src/viewer/CardBending.js +481 -0
- package/src/viewer/GalleryUI.js +832 -0
- package/src/viewer/ReactivityManager.js +590 -0
- package/src/viewer/TradingCardExporter.js +600 -0
- package/src/viewer/ViewerPortal.js +374 -0
- package/src/viewer/index.js +12 -0
- package/src/wasm/WasmLoader.js +296 -0
- package/src/wasm/index.js +132 -0
- package/tools/agentic/mcpTools.js +88 -0
- package/tools/cli/agent-cli.js +92 -0
- package/tools/export/formats.js +24 -0
- package/tools/math/rotation-baseline.mjs +64 -0
- package/tools/shader-sync-verify.js +937 -0
- package/tools/telemetry/manifestPipeline.js +141 -0
- package/tools/telemetry/telemetryEvents.js +35 -0
- package/types/adaptive-sdk.d.ts +185 -0
- package/types/advanced/AIPresetGenerator.d.ts +81 -0
- package/types/advanced/MIDIController.d.ts +100 -0
- package/types/advanced/OffscreenWorker.d.ts +82 -0
- package/types/advanced/WebGPUCompute.d.ts +52 -0
- package/types/advanced/WebXRRenderer.d.ts +77 -0
- package/types/advanced/index.d.ts +46 -0
- package/types/core/ErrorReporter.d.ts +50 -0
- package/types/core/VIB3Engine.d.ts +204 -0
- package/types/creative/ColorPresetsSystem.d.ts +91 -0
- package/types/creative/ParameterTimeline.d.ts +74 -0
- package/types/creative/PostProcessingPipeline.d.ts +109 -0
- package/types/creative/TransitionAnimator.d.ts +71 -0
- package/types/creative/index.d.ts +35 -0
- package/types/integrations/FigmaPlugin.d.ts +46 -0
- package/types/integrations/OBSMode.d.ts +74 -0
- package/types/integrations/ThreeJsPackage.d.ts +62 -0
- package/types/integrations/TouchDesignerExport.d.ts +36 -0
- package/types/integrations/Vib3React.d.ts +74 -0
- package/types/integrations/Vib3Svelte.d.ts +63 -0
- package/types/integrations/Vib3Vue.d.ts +55 -0
- package/types/integrations/index.d.ts +52 -0
- package/types/reactivity/SpatialInputSystem.d.ts +173 -0
- package/types/reactivity/index.d.ts +394 -0
- package/types/render/CommandBuffer.d.ts +169 -0
- package/types/render/RenderCommand.d.ts +312 -0
- package/types/render/RenderState.d.ts +279 -0
- package/types/render/RenderTarget.d.ts +254 -0
- package/types/render/ShaderProgram.d.ts +277 -0
- package/types/render/UnifiedRenderBridge.d.ts +143 -0
- package/types/render/WebGLBackend.d.ts +168 -0
- package/types/render/WebGPUBackend.d.ts +186 -0
- package/types/render/index.d.ts +141 -0
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RenderState - GPU state management
|
|
3
|
+
*
|
|
4
|
+
* Encapsulates all GPU state settings for efficient state changes.
|
|
5
|
+
* Tracks blend, depth, stencil, cull, and viewport settings.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Blend mode presets
|
|
10
|
+
*/
|
|
11
|
+
export const BlendMode = {
|
|
12
|
+
NONE: 'none',
|
|
13
|
+
ALPHA: 'alpha',
|
|
14
|
+
ADDITIVE: 'additive',
|
|
15
|
+
MULTIPLY: 'multiply',
|
|
16
|
+
PREMULTIPLIED: 'premultiplied'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Depth comparison functions
|
|
21
|
+
*/
|
|
22
|
+
export const DepthFunc = {
|
|
23
|
+
NEVER: 'never',
|
|
24
|
+
LESS: 'less',
|
|
25
|
+
EQUAL: 'equal',
|
|
26
|
+
LEQUAL: 'lequal',
|
|
27
|
+
GREATER: 'greater',
|
|
28
|
+
NOTEQUAL: 'notequal',
|
|
29
|
+
GEQUAL: 'gequal',
|
|
30
|
+
ALWAYS: 'always'
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Cull face modes
|
|
35
|
+
*/
|
|
36
|
+
export const CullFace = {
|
|
37
|
+
NONE: 'none',
|
|
38
|
+
FRONT: 'front',
|
|
39
|
+
BACK: 'back',
|
|
40
|
+
FRONT_AND_BACK: 'front_and_back'
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Polygon fill modes
|
|
45
|
+
*/
|
|
46
|
+
export const PolygonMode = {
|
|
47
|
+
FILL: 'fill',
|
|
48
|
+
LINE: 'line',
|
|
49
|
+
POINT: 'point'
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Stencil operations
|
|
54
|
+
*/
|
|
55
|
+
export const StencilOp = {
|
|
56
|
+
KEEP: 'keep',
|
|
57
|
+
ZERO: 'zero',
|
|
58
|
+
REPLACE: 'replace',
|
|
59
|
+
INCR: 'incr',
|
|
60
|
+
INCR_WRAP: 'incr_wrap',
|
|
61
|
+
DECR: 'decr',
|
|
62
|
+
DECR_WRAP: 'decr_wrap',
|
|
63
|
+
INVERT: 'invert'
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Blend state configuration
|
|
68
|
+
*/
|
|
69
|
+
export class BlendState {
|
|
70
|
+
constructor() {
|
|
71
|
+
/** @type {boolean} */
|
|
72
|
+
this.enabled = false;
|
|
73
|
+
|
|
74
|
+
/** @type {string} */
|
|
75
|
+
this.mode = BlendMode.ALPHA;
|
|
76
|
+
|
|
77
|
+
/** @type {string} Source RGB factor */
|
|
78
|
+
this.srcRGB = 'src_alpha';
|
|
79
|
+
|
|
80
|
+
/** @type {string} Destination RGB factor */
|
|
81
|
+
this.dstRGB = 'one_minus_src_alpha';
|
|
82
|
+
|
|
83
|
+
/** @type {string} Source Alpha factor */
|
|
84
|
+
this.srcAlpha = 'one';
|
|
85
|
+
|
|
86
|
+
/** @type {string} Destination Alpha factor */
|
|
87
|
+
this.dstAlpha = 'one_minus_src_alpha';
|
|
88
|
+
|
|
89
|
+
/** @type {number[]} Blend color (RGBA) */
|
|
90
|
+
this.color = [0, 0, 0, 0];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Set from blend mode preset
|
|
95
|
+
* @param {string} mode
|
|
96
|
+
* @returns {this}
|
|
97
|
+
*/
|
|
98
|
+
setMode(mode) {
|
|
99
|
+
this.mode = mode;
|
|
100
|
+
this.enabled = mode !== BlendMode.NONE;
|
|
101
|
+
|
|
102
|
+
switch (mode) {
|
|
103
|
+
case BlendMode.ALPHA:
|
|
104
|
+
this.srcRGB = 'src_alpha';
|
|
105
|
+
this.dstRGB = 'one_minus_src_alpha';
|
|
106
|
+
this.srcAlpha = 'one';
|
|
107
|
+
this.dstAlpha = 'one_minus_src_alpha';
|
|
108
|
+
break;
|
|
109
|
+
|
|
110
|
+
case BlendMode.ADDITIVE:
|
|
111
|
+
this.srcRGB = 'src_alpha';
|
|
112
|
+
this.dstRGB = 'one';
|
|
113
|
+
this.srcAlpha = 'one';
|
|
114
|
+
this.dstAlpha = 'one';
|
|
115
|
+
break;
|
|
116
|
+
|
|
117
|
+
case BlendMode.MULTIPLY:
|
|
118
|
+
this.srcRGB = 'dst_color';
|
|
119
|
+
this.dstRGB = 'zero';
|
|
120
|
+
this.srcAlpha = 'dst_alpha';
|
|
121
|
+
this.dstAlpha = 'zero';
|
|
122
|
+
break;
|
|
123
|
+
|
|
124
|
+
case BlendMode.PREMULTIPLIED:
|
|
125
|
+
this.srcRGB = 'one';
|
|
126
|
+
this.dstRGB = 'one_minus_src_alpha';
|
|
127
|
+
this.srcAlpha = 'one';
|
|
128
|
+
this.dstAlpha = 'one_minus_src_alpha';
|
|
129
|
+
break;
|
|
130
|
+
|
|
131
|
+
case BlendMode.NONE:
|
|
132
|
+
default:
|
|
133
|
+
this.enabled = false;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Clone this state
|
|
142
|
+
* @returns {BlendState}
|
|
143
|
+
*/
|
|
144
|
+
clone() {
|
|
145
|
+
const state = new BlendState();
|
|
146
|
+
state.enabled = this.enabled;
|
|
147
|
+
state.mode = this.mode;
|
|
148
|
+
state.srcRGB = this.srcRGB;
|
|
149
|
+
state.dstRGB = this.dstRGB;
|
|
150
|
+
state.srcAlpha = this.srcAlpha;
|
|
151
|
+
state.dstAlpha = this.dstAlpha;
|
|
152
|
+
state.color = [...this.color];
|
|
153
|
+
return state;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Check equality
|
|
158
|
+
* @param {BlendState} other
|
|
159
|
+
* @returns {boolean}
|
|
160
|
+
*/
|
|
161
|
+
equals(other) {
|
|
162
|
+
return this.enabled === other.enabled &&
|
|
163
|
+
this.mode === other.mode &&
|
|
164
|
+
this.srcRGB === other.srcRGB &&
|
|
165
|
+
this.dstRGB === other.dstRGB &&
|
|
166
|
+
this.srcAlpha === other.srcAlpha &&
|
|
167
|
+
this.dstAlpha === other.dstAlpha;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Depth state configuration
|
|
173
|
+
*/
|
|
174
|
+
export class DepthState {
|
|
175
|
+
constructor() {
|
|
176
|
+
/** @type {boolean} */
|
|
177
|
+
this.testEnabled = true;
|
|
178
|
+
|
|
179
|
+
/** @type {boolean} */
|
|
180
|
+
this.writeEnabled = true;
|
|
181
|
+
|
|
182
|
+
/** @type {string} */
|
|
183
|
+
this.func = DepthFunc.LESS;
|
|
184
|
+
|
|
185
|
+
/** @type {number} Near clipping plane */
|
|
186
|
+
this.near = 0;
|
|
187
|
+
|
|
188
|
+
/** @type {number} Far clipping plane */
|
|
189
|
+
this.far = 1;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Clone this state
|
|
194
|
+
* @returns {DepthState}
|
|
195
|
+
*/
|
|
196
|
+
clone() {
|
|
197
|
+
const state = new DepthState();
|
|
198
|
+
state.testEnabled = this.testEnabled;
|
|
199
|
+
state.writeEnabled = this.writeEnabled;
|
|
200
|
+
state.func = this.func;
|
|
201
|
+
state.near = this.near;
|
|
202
|
+
state.far = this.far;
|
|
203
|
+
return state;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Check equality
|
|
208
|
+
* @param {DepthState} other
|
|
209
|
+
* @returns {boolean}
|
|
210
|
+
*/
|
|
211
|
+
equals(other) {
|
|
212
|
+
return this.testEnabled === other.testEnabled &&
|
|
213
|
+
this.writeEnabled === other.writeEnabled &&
|
|
214
|
+
this.func === other.func &&
|
|
215
|
+
this.near === other.near &&
|
|
216
|
+
this.far === other.far;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Stencil state configuration
|
|
222
|
+
*/
|
|
223
|
+
export class StencilState {
|
|
224
|
+
constructor() {
|
|
225
|
+
/** @type {boolean} */
|
|
226
|
+
this.enabled = false;
|
|
227
|
+
|
|
228
|
+
/** @type {string} */
|
|
229
|
+
this.func = 'always';
|
|
230
|
+
|
|
231
|
+
/** @type {number} */
|
|
232
|
+
this.ref = 0;
|
|
233
|
+
|
|
234
|
+
/** @type {number} */
|
|
235
|
+
this.mask = 0xFF;
|
|
236
|
+
|
|
237
|
+
/** @type {string} */
|
|
238
|
+
this.failOp = StencilOp.KEEP;
|
|
239
|
+
|
|
240
|
+
/** @type {string} */
|
|
241
|
+
this.depthFailOp = StencilOp.KEEP;
|
|
242
|
+
|
|
243
|
+
/** @type {string} */
|
|
244
|
+
this.passOp = StencilOp.KEEP;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Clone this state
|
|
249
|
+
* @returns {StencilState}
|
|
250
|
+
*/
|
|
251
|
+
clone() {
|
|
252
|
+
const state = new StencilState();
|
|
253
|
+
state.enabled = this.enabled;
|
|
254
|
+
state.func = this.func;
|
|
255
|
+
state.ref = this.ref;
|
|
256
|
+
state.mask = this.mask;
|
|
257
|
+
state.failOp = this.failOp;
|
|
258
|
+
state.depthFailOp = this.depthFailOp;
|
|
259
|
+
state.passOp = this.passOp;
|
|
260
|
+
return state;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Check equality
|
|
265
|
+
* @param {StencilState} other
|
|
266
|
+
* @returns {boolean}
|
|
267
|
+
*/
|
|
268
|
+
equals(other) {
|
|
269
|
+
return this.enabled === other.enabled &&
|
|
270
|
+
this.func === other.func &&
|
|
271
|
+
this.ref === other.ref &&
|
|
272
|
+
this.mask === other.mask &&
|
|
273
|
+
this.failOp === other.failOp &&
|
|
274
|
+
this.depthFailOp === other.depthFailOp &&
|
|
275
|
+
this.passOp === other.passOp;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Rasterizer state configuration
|
|
281
|
+
*/
|
|
282
|
+
export class RasterizerState {
|
|
283
|
+
constructor() {
|
|
284
|
+
/** @type {string} */
|
|
285
|
+
this.cullFace = CullFace.BACK;
|
|
286
|
+
|
|
287
|
+
/** @type {boolean} Front face is counter-clockwise */
|
|
288
|
+
this.frontFaceCCW = true;
|
|
289
|
+
|
|
290
|
+
/** @type {string} */
|
|
291
|
+
this.polygonMode = PolygonMode.FILL;
|
|
292
|
+
|
|
293
|
+
/** @type {boolean} */
|
|
294
|
+
this.scissorEnabled = false;
|
|
295
|
+
|
|
296
|
+
/** @type {number[]} Scissor rect [x, y, width, height] */
|
|
297
|
+
this.scissorRect = [0, 0, 0, 0];
|
|
298
|
+
|
|
299
|
+
/** @type {number} Line width for LINE mode */
|
|
300
|
+
this.lineWidth = 1;
|
|
301
|
+
|
|
302
|
+
/** @type {number} Point size for POINT mode */
|
|
303
|
+
this.pointSize = 1;
|
|
304
|
+
|
|
305
|
+
/** @type {boolean} */
|
|
306
|
+
this.depthBiasEnabled = false;
|
|
307
|
+
|
|
308
|
+
/** @type {number} */
|
|
309
|
+
this.depthBiasFactor = 0;
|
|
310
|
+
|
|
311
|
+
/** @type {number} */
|
|
312
|
+
this.depthBiasUnits = 0;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Clone this state
|
|
317
|
+
* @returns {RasterizerState}
|
|
318
|
+
*/
|
|
319
|
+
clone() {
|
|
320
|
+
const state = new RasterizerState();
|
|
321
|
+
state.cullFace = this.cullFace;
|
|
322
|
+
state.frontFaceCCW = this.frontFaceCCW;
|
|
323
|
+
state.polygonMode = this.polygonMode;
|
|
324
|
+
state.scissorEnabled = this.scissorEnabled;
|
|
325
|
+
state.scissorRect = [...this.scissorRect];
|
|
326
|
+
state.lineWidth = this.lineWidth;
|
|
327
|
+
state.pointSize = this.pointSize;
|
|
328
|
+
state.depthBiasEnabled = this.depthBiasEnabled;
|
|
329
|
+
state.depthBiasFactor = this.depthBiasFactor;
|
|
330
|
+
state.depthBiasUnits = this.depthBiasUnits;
|
|
331
|
+
return state;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Check equality
|
|
336
|
+
* @param {RasterizerState} other
|
|
337
|
+
* @returns {boolean}
|
|
338
|
+
*/
|
|
339
|
+
equals(other) {
|
|
340
|
+
return this.cullFace === other.cullFace &&
|
|
341
|
+
this.frontFaceCCW === other.frontFaceCCW &&
|
|
342
|
+
this.polygonMode === other.polygonMode &&
|
|
343
|
+
this.scissorEnabled === other.scissorEnabled &&
|
|
344
|
+
this.lineWidth === other.lineWidth;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Viewport configuration
|
|
350
|
+
*/
|
|
351
|
+
export class Viewport {
|
|
352
|
+
/**
|
|
353
|
+
* @param {number} x
|
|
354
|
+
* @param {number} y
|
|
355
|
+
* @param {number} width
|
|
356
|
+
* @param {number} height
|
|
357
|
+
*/
|
|
358
|
+
constructor(x = 0, y = 0, width = 800, height = 600) {
|
|
359
|
+
this.x = x;
|
|
360
|
+
this.y = y;
|
|
361
|
+
this.width = width;
|
|
362
|
+
this.height = height;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Get aspect ratio
|
|
367
|
+
* @returns {number}
|
|
368
|
+
*/
|
|
369
|
+
get aspectRatio() {
|
|
370
|
+
return this.width / this.height;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Clone this viewport
|
|
375
|
+
* @returns {Viewport}
|
|
376
|
+
*/
|
|
377
|
+
clone() {
|
|
378
|
+
return new Viewport(this.x, this.y, this.width, this.height);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Check equality
|
|
383
|
+
* @param {Viewport} other
|
|
384
|
+
* @returns {boolean}
|
|
385
|
+
*/
|
|
386
|
+
equals(other) {
|
|
387
|
+
return this.x === other.x &&
|
|
388
|
+
this.y === other.y &&
|
|
389
|
+
this.width === other.width &&
|
|
390
|
+
this.height === other.height;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Complete render state
|
|
396
|
+
*/
|
|
397
|
+
export class RenderState {
|
|
398
|
+
constructor() {
|
|
399
|
+
/** @type {BlendState} */
|
|
400
|
+
this.blend = new BlendState();
|
|
401
|
+
|
|
402
|
+
/** @type {DepthState} */
|
|
403
|
+
this.depth = new DepthState();
|
|
404
|
+
|
|
405
|
+
/** @type {StencilState} */
|
|
406
|
+
this.stencil = new StencilState();
|
|
407
|
+
|
|
408
|
+
/** @type {RasterizerState} */
|
|
409
|
+
this.rasterizer = new RasterizerState();
|
|
410
|
+
|
|
411
|
+
/** @type {Viewport} */
|
|
412
|
+
this.viewport = new Viewport();
|
|
413
|
+
|
|
414
|
+
/** @type {number[]} Color write mask [R, G, B, A] */
|
|
415
|
+
this.colorMask = [true, true, true, true];
|
|
416
|
+
|
|
417
|
+
/** @type {number[]} Clear color (RGBA) */
|
|
418
|
+
this.clearColor = [0, 0, 0, 1];
|
|
419
|
+
|
|
420
|
+
/** @type {number} Clear depth value */
|
|
421
|
+
this.clearDepth = 1;
|
|
422
|
+
|
|
423
|
+
/** @type {number} Clear stencil value */
|
|
424
|
+
this.clearStencil = 0;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Create default state for opaque rendering
|
|
429
|
+
* @returns {RenderState}
|
|
430
|
+
*/
|
|
431
|
+
static opaque() {
|
|
432
|
+
const state = new RenderState();
|
|
433
|
+
state.blend.enabled = false;
|
|
434
|
+
state.depth.testEnabled = true;
|
|
435
|
+
state.depth.writeEnabled = true;
|
|
436
|
+
state.rasterizer.cullFace = CullFace.BACK;
|
|
437
|
+
return state;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Create default state for transparent rendering
|
|
442
|
+
* @returns {RenderState}
|
|
443
|
+
*/
|
|
444
|
+
static transparent() {
|
|
445
|
+
const state = new RenderState();
|
|
446
|
+
state.blend.setMode(BlendMode.ALPHA);
|
|
447
|
+
state.depth.testEnabled = true;
|
|
448
|
+
state.depth.writeEnabled = false; // Don't write depth for transparent
|
|
449
|
+
state.rasterizer.cullFace = CullFace.NONE;
|
|
450
|
+
return state;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Create state for additive effects (particles, glow)
|
|
455
|
+
* @returns {RenderState}
|
|
456
|
+
*/
|
|
457
|
+
static additive() {
|
|
458
|
+
const state = new RenderState();
|
|
459
|
+
state.blend.setMode(BlendMode.ADDITIVE);
|
|
460
|
+
state.depth.testEnabled = true;
|
|
461
|
+
state.depth.writeEnabled = false;
|
|
462
|
+
state.rasterizer.cullFace = CullFace.NONE;
|
|
463
|
+
return state;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Create state for wireframe rendering
|
|
468
|
+
* @returns {RenderState}
|
|
469
|
+
*/
|
|
470
|
+
static wireframe() {
|
|
471
|
+
const state = new RenderState();
|
|
472
|
+
state.blend.setMode(BlendMode.ALPHA);
|
|
473
|
+
state.depth.testEnabled = true;
|
|
474
|
+
state.depth.writeEnabled = true;
|
|
475
|
+
state.rasterizer.cullFace = CullFace.NONE;
|
|
476
|
+
state.rasterizer.polygonMode = PolygonMode.LINE;
|
|
477
|
+
return state;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Clone this state
|
|
482
|
+
* @returns {RenderState}
|
|
483
|
+
*/
|
|
484
|
+
clone() {
|
|
485
|
+
const state = new RenderState();
|
|
486
|
+
state.blend = this.blend.clone();
|
|
487
|
+
state.depth = this.depth.clone();
|
|
488
|
+
state.stencil = this.stencil.clone();
|
|
489
|
+
state.rasterizer = this.rasterizer.clone();
|
|
490
|
+
state.viewport = this.viewport.clone();
|
|
491
|
+
state.colorMask = [...this.colorMask];
|
|
492
|
+
state.clearColor = [...this.clearColor];
|
|
493
|
+
state.clearDepth = this.clearDepth;
|
|
494
|
+
state.clearStencil = this.clearStencil;
|
|
495
|
+
return state;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Calculate state difference for minimal state changes
|
|
500
|
+
* @param {RenderState} other
|
|
501
|
+
* @returns {object} Changed properties
|
|
502
|
+
*/
|
|
503
|
+
diff(other) {
|
|
504
|
+
const changes = {};
|
|
505
|
+
|
|
506
|
+
if (!this.blend.equals(other.blend)) {
|
|
507
|
+
changes.blend = other.blend;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
if (!this.depth.equals(other.depth)) {
|
|
511
|
+
changes.depth = other.depth;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
if (!this.stencil.equals(other.stencil)) {
|
|
515
|
+
changes.stencil = other.stencil;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
if (!this.rasterizer.equals(other.rasterizer)) {
|
|
519
|
+
changes.rasterizer = other.rasterizer;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
if (!this.viewport.equals(other.viewport)) {
|
|
523
|
+
changes.viewport = other.viewport;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
return changes;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Generate sort key for state-based sorting
|
|
531
|
+
* Allows grouping draw calls by similar state
|
|
532
|
+
* @returns {number}
|
|
533
|
+
*/
|
|
534
|
+
getSortKey() {
|
|
535
|
+
let key = 0;
|
|
536
|
+
|
|
537
|
+
// Blend mode (bits 0-3)
|
|
538
|
+
key |= (this.blend.enabled ? 1 : 0);
|
|
539
|
+
key |= (Object.values(BlendMode).indexOf(this.blend.mode) << 1);
|
|
540
|
+
|
|
541
|
+
// Depth state (bits 4-7)
|
|
542
|
+
key |= ((this.depth.testEnabled ? 1 : 0) << 4);
|
|
543
|
+
key |= ((this.depth.writeEnabled ? 1 : 0) << 5);
|
|
544
|
+
|
|
545
|
+
// Cull state (bits 8-9)
|
|
546
|
+
key |= (Object.values(CullFace).indexOf(this.rasterizer.cullFace) << 8);
|
|
547
|
+
|
|
548
|
+
return key;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
export default RenderState;
|