rhodonite 0.20.0 → 0.20.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.
Files changed (92) hide show
  1. package/VERSION-FILE +1 -1
  2. package/dist/esm/foundation/components/Animation/AnimationComponent.d.ts +18 -0
  3. package/dist/esm/foundation/components/Animation/AnimationOps.d.ts +20 -1
  4. package/dist/esm/foundation/components/Animation/AnimationStateRepository.d.ts +49 -0
  5. package/dist/esm/foundation/components/AnimationState/AnimationStateComponent.d.ts +5 -0
  6. package/dist/esm/foundation/components/BlendShape/BlendShapeComponent.d.ts +21 -0
  7. package/dist/esm/foundation/components/MeshRenderer/MeshRendererComponent.d.ts +61 -1
  8. package/dist/esm/foundation/components/SceneGraph/SceneGraphComponent.d.ts +50 -4
  9. package/dist/esm/foundation/components/Skeletal/SkeletalComponent.d.ts +45 -1
  10. package/dist/esm/foundation/components/Vrm/VrmComponent.d.ts +33 -3
  11. package/dist/esm/foundation/core/ComponentRepository.d.ts +17 -0
  12. package/dist/esm/foundation/geometry/Mesh.d.ts +27 -0
  13. package/dist/esm/foundation/gizmos/RotationGizmo.d.ts +2 -0
  14. package/dist/esm/foundation/gizmos/ScaleGizmo.d.ts +7 -0
  15. package/dist/esm/foundation/gizmos/TranslationGizmo.d.ts +7 -0
  16. package/dist/esm/foundation/helpers/MaterialHelper.d.ts +1 -1
  17. package/dist/esm/foundation/helpers/Shadow/ShadowSystem.d.ts +14 -0
  18. package/dist/esm/foundation/materials/contents/CustomMaterialContent.d.ts +4 -0
  19. package/dist/esm/foundation/materials/core/Material.d.ts +16 -0
  20. package/dist/esm/foundation/materials/core/MaterialRepository.d.ts +17 -0
  21. package/dist/esm/foundation/math/AnimatedQuaternion.d.ts +17 -1
  22. package/dist/esm/foundation/math/AnimatedScalar.d.ts +17 -1
  23. package/dist/esm/foundation/math/AnimatedValueEvaluationState.d.ts +56 -0
  24. package/dist/esm/foundation/math/AnimatedVector2.d.ts +17 -1
  25. package/dist/esm/foundation/math/AnimatedVector3.d.ts +17 -1
  26. package/dist/esm/foundation/math/AnimatedVector4.d.ts +17 -1
  27. package/dist/esm/foundation/math/AnimatedVectorN.d.ts +17 -1
  28. package/dist/esm/foundation/math/IAnimatedValue.d.ts +18 -0
  29. package/dist/esm/foundation/math/IMatrix.d.ts +12 -0
  30. package/dist/esm/foundation/math/IdentityMatrix44.d.ts +9 -0
  31. package/dist/esm/foundation/physics/Oimo/OimoPhysicsStrategy.d.ts +22 -0
  32. package/dist/esm/foundation/physics/PhysicsStrategy.d.ts +8 -0
  33. package/dist/esm/foundation/physics/Rapier/RapierCharacterControllerStrategy.d.ts +2 -0
  34. package/dist/esm/foundation/physics/Rapier/RapierPhysicsStrategy.d.ts +12 -0
  35. package/dist/esm/foundation/renderer/pipelines/ForwardRenderPipeline.d.ts +26 -26
  36. package/dist/esm/foundation/system/Engine.d.ts +31 -0
  37. package/dist/esm/foundation/textures/Sampler.d.ts +14 -0
  38. package/dist/esm/index.js +555 -555
  39. package/dist/esm/webgl/WebGLExtendedTypes.d.ts +2 -0
  40. package/dist/esm/webgl/WebGLGpuTimer.d.ts +32 -0
  41. package/dist/esm/webgl/WebGLResourceRepository.d.ts +21 -1
  42. package/dist/esm/webgl/WebGLStrategyDataTexture.d.ts +9 -0
  43. package/dist/esm/webgpu/RangeAllocator.d.ts +39 -0
  44. package/dist/esm/webgpu/WebGpuBufferArena.d.ts +60 -0
  45. package/dist/esm/webgpu/WebGpuGpuTimer.d.ts +49 -0
  46. package/dist/esm/webgpu/WebGpuResourceRepository.d.ts +212 -18
  47. package/dist/esmdev/foundation/components/Animation/AnimationComponent.d.ts +18 -0
  48. package/dist/esmdev/foundation/components/Animation/AnimationOps.d.ts +20 -1
  49. package/dist/esmdev/foundation/components/Animation/AnimationStateRepository.d.ts +49 -0
  50. package/dist/esmdev/foundation/components/AnimationState/AnimationStateComponent.d.ts +5 -0
  51. package/dist/esmdev/foundation/components/BlendShape/BlendShapeComponent.d.ts +21 -0
  52. package/dist/esmdev/foundation/components/MeshRenderer/MeshRendererComponent.d.ts +61 -1
  53. package/dist/esmdev/foundation/components/SceneGraph/SceneGraphComponent.d.ts +50 -4
  54. package/dist/esmdev/foundation/components/Skeletal/SkeletalComponent.d.ts +45 -1
  55. package/dist/esmdev/foundation/components/Vrm/VrmComponent.d.ts +33 -3
  56. package/dist/esmdev/foundation/core/ComponentRepository.d.ts +17 -0
  57. package/dist/esmdev/foundation/geometry/Mesh.d.ts +27 -0
  58. package/dist/esmdev/foundation/gizmos/RotationGizmo.d.ts +2 -0
  59. package/dist/esmdev/foundation/gizmos/ScaleGizmo.d.ts +7 -0
  60. package/dist/esmdev/foundation/gizmos/TranslationGizmo.d.ts +7 -0
  61. package/dist/esmdev/foundation/helpers/MaterialHelper.d.ts +1 -1
  62. package/dist/esmdev/foundation/helpers/Shadow/ShadowSystem.d.ts +14 -0
  63. package/dist/esmdev/foundation/materials/contents/CustomMaterialContent.d.ts +4 -0
  64. package/dist/esmdev/foundation/materials/core/Material.d.ts +16 -0
  65. package/dist/esmdev/foundation/materials/core/MaterialRepository.d.ts +17 -0
  66. package/dist/esmdev/foundation/math/AnimatedQuaternion.d.ts +17 -1
  67. package/dist/esmdev/foundation/math/AnimatedScalar.d.ts +17 -1
  68. package/dist/esmdev/foundation/math/AnimatedValueEvaluationState.d.ts +56 -0
  69. package/dist/esmdev/foundation/math/AnimatedVector2.d.ts +17 -1
  70. package/dist/esmdev/foundation/math/AnimatedVector3.d.ts +17 -1
  71. package/dist/esmdev/foundation/math/AnimatedVector4.d.ts +17 -1
  72. package/dist/esmdev/foundation/math/AnimatedVectorN.d.ts +17 -1
  73. package/dist/esmdev/foundation/math/IAnimatedValue.d.ts +18 -0
  74. package/dist/esmdev/foundation/math/IMatrix.d.ts +12 -0
  75. package/dist/esmdev/foundation/math/IdentityMatrix44.d.ts +9 -0
  76. package/dist/esmdev/foundation/physics/Oimo/OimoPhysicsStrategy.d.ts +22 -0
  77. package/dist/esmdev/foundation/physics/PhysicsStrategy.d.ts +8 -0
  78. package/dist/esmdev/foundation/physics/Rapier/RapierCharacterControllerStrategy.d.ts +2 -0
  79. package/dist/esmdev/foundation/physics/Rapier/RapierPhysicsStrategy.d.ts +12 -0
  80. package/dist/esmdev/foundation/renderer/pipelines/ForwardRenderPipeline.d.ts +26 -26
  81. package/dist/esmdev/foundation/system/Engine.d.ts +31 -0
  82. package/dist/esmdev/foundation/textures/Sampler.d.ts +14 -0
  83. package/dist/esmdev/index.js +6620 -4050
  84. package/dist/esmdev/webgl/WebGLExtendedTypes.d.ts +2 -0
  85. package/dist/esmdev/webgl/WebGLGpuTimer.d.ts +32 -0
  86. package/dist/esmdev/webgl/WebGLResourceRepository.d.ts +21 -1
  87. package/dist/esmdev/webgl/WebGLStrategyDataTexture.d.ts +9 -0
  88. package/dist/esmdev/webgpu/RangeAllocator.d.ts +39 -0
  89. package/dist/esmdev/webgpu/WebGpuBufferArena.d.ts +60 -0
  90. package/dist/esmdev/webgpu/WebGpuGpuTimer.d.ts +49 -0
  91. package/dist/esmdev/webgpu/WebGpuResourceRepository.d.ts +212 -18
  92. package/package.json +1 -1
@@ -4,11 +4,33 @@ import type { Engine } from '../../system/Engine';
4
4
  * Repository for managing shared animation state between AnimationComponent and SkeletalComponent.
5
5
  * This module exists to break the circular dependency between these two components.
6
6
  */
7
+ /**
8
+ * Joint information needed to decide whether a joint can skip animation.
9
+ */
10
+ type JointForEarlyReturn = {
11
+ readonly jointIndex: number;
12
+ readonly entityUID: EntityUID;
13
+ };
7
14
  export declare class AnimationStateRepository {
8
15
  /** Map to store globalTime per Engine instance for multi-engine support */
9
16
  private static __globalTimeMap;
10
17
  /** Map to store isAnimating flag per Engine instance for multi-engine support */
11
18
  private static __isAnimatingMap;
19
+ /**
20
+ * Version counter of animation bindings (channels, samplers and active tracks).
21
+ * Incremented whenever data that affects animation track feature hashes may change,
22
+ * so that consumers (e.g. SkeletalComponent skin cache keys) can avoid recomputing every frame.
23
+ */
24
+ private static __animationBindingVersion;
25
+ /**
26
+ * Marks that animation bindings (channels, samplers or active tracks) may have changed.
27
+ */
28
+ static markAnimationBindingChanged(): void;
29
+ /**
30
+ * Gets the current version of animation bindings.
31
+ * @returns The version counter, which changes whenever animation bindings may have changed
32
+ */
33
+ static getAnimationBindingVersion(): number;
12
34
  /**
13
35
  * Joint EntityUIDs that can skip animation in the CURRENT frame.
14
36
  * Populated during SkeletalComponent.$logic when cache hits occur.
@@ -49,6 +71,13 @@ export declare class AnimationStateRepository {
49
71
  * Managed per Engine instance for multi-engine support.
50
72
  */
51
73
  private static __leaderJointIndexToEntityUIDMap;
74
+ /**
75
+ * Joints of frustum-culled SkeletalComponents collected during the current frame.
76
+ * They are resolved at the next frame transition, after the leaders of the frame are decided,
77
+ * so that leader joints are never registered for early return.
78
+ * Managed per Engine instance for multi-engine support.
79
+ */
80
+ private static __pendingCulledSkeletonJointsMap;
52
81
  /**
53
82
  * Sets the global animation time for the specified engine.
54
83
  * @param engine - The engine instance to set the global time for
@@ -99,6 +128,25 @@ export declare class AnimationStateRepository {
99
128
  * @returns True if frame transition occurred, false otherwise
100
129
  */
101
130
  static handleFrameTransitionIfNeeded(engine: Engine, currentProcessFrameToken: number): boolean;
131
+ /**
132
+ * Registers the joints of a frustum-culled SkeletalComponent as candidates for early return.
133
+ *
134
+ * A culled SkeletalComponent neither computes nor applies skinning, so its joints do not need to
135
+ * be animated as long as another (visible) SkeletalComponent with the same cache key is the leader.
136
+ * The candidates are resolved at the next frame transition, when the leaders of this frame are known:
137
+ * joints that are the same entities as the leader's joints (e.g. a culled Face mesh sharing joints
138
+ * with a visible Body mesh) keep animating.
139
+ *
140
+ * @param engine - The engine instance for multi-engine support
141
+ * @param cacheKey - The skinning cache key of the culled SkeletalComponent
142
+ * @param joints - The joints of the culled SkeletalComponent
143
+ */
144
+ static addCulledSkeletonJoints(engine: Engine, cacheKey: string, joints: readonly JointForEarlyReturn[]): void;
145
+ /**
146
+ * Moves the joints of culled SkeletalComponents whose cache key had a leader in the finished frame
147
+ * into the given cached EntityUID set, excluding the leader joints.
148
+ */
149
+ private static __resolvePendingCulledSkeletonJoints;
102
150
  /**
103
151
  * Handles frame transition and clears leader tracking.
104
152
  * Used by SkeletalComponent.isEntityCached which runs before SkeletalComponent.$logic.
@@ -126,3 +174,4 @@ export declare class AnimationStateRepository {
126
174
  */
127
175
  static _cleanupForEngine(engine: Engine): void;
128
176
  }
177
+ export {};
@@ -50,6 +50,11 @@ export declare class AnimationStateComponent extends Component {
50
50
  * Handles animation blending calculations and updates the blending ratio over time.
51
51
  */
52
52
  $logic(): void;
53
+ /**
54
+ * Propagates the blending ratio to all descendants without evaluating the animation channels.
55
+ * @param ratio - The blending ratio value between 0.0 and 1.0
56
+ */
57
+ private __setAnimationBlendingRatioWithoutApplying;
53
58
  /**
54
59
  * Sets the first active animation track without blending.
55
60
  * This is typically used for initial animation setup.
@@ -11,9 +11,18 @@ import type { ComponentToComponentMethods } from '../ComponentTypes';
11
11
  */
12
12
  export declare class BlendShapeComponent extends Component {
13
13
  private __weights;
14
+ /**
15
+ * True when `__weights` is an array owned by this component.
16
+ * Importers and the `weights` setter may hand over arrays shared with the parsed glTF data or
17
+ * with other nodes, so mutations must clone first (see __ensureOwnWeights).
18
+ */
19
+ private __ownsWeights;
14
20
  private __targetNames;
15
21
  private static __updateCount;
16
22
  private static __weightsLengthBySid;
23
+ /** Incremented whenever the weight layout (lengths or slot count) may have changed. */
24
+ private static __layoutVersion;
25
+ private static __offsetsCache;
17
26
  /**
18
27
  * Creates a new BlendShapeComponent instance.
19
28
  * @param engine - The engine instance
@@ -63,6 +72,18 @@ export declare class BlendShapeComponent extends Component {
63
72
  * @returns Array of target names for blend shapes
64
73
  */
65
74
  get targetNames(): string[];
75
+ /**
76
+ * Ensures that `__weights` is an array this component owns before mutating it in place.
77
+ * Arrays passed to the `weights` setter may be shared with the parsed glTF data or with other
78
+ * nodes, so the first in-place write clones them.
79
+ */
80
+ private __ensureOwnWeights;
81
+ /**
82
+ * Copies weights from any array-like source, skipping the update when all values are unchanged.
83
+ * This is the allocation-free path used by animation each frame.
84
+ * @param source - Array-like source of weight values
85
+ */
86
+ setWeightsFromArrayLike(source: ArrayLike<number>): void;
66
87
  /**
67
88
  * Sets the weight value for a specific blend shape target by index.
68
89
  * @param index - The index of the blend shape target
@@ -8,6 +8,14 @@ import type { Engine } from '../../system/Engine';
8
8
  import type { CubeTexture } from '../../textures/CubeTexture';
9
9
  import type { RenderTargetTextureCube } from '../../textures/RenderTargetTextureCube';
10
10
  import type { ComponentToComponentMethods } from '../ComponentTypes';
11
+ /**
12
+ * Culling result of a render pass for per-instance culling of instanced draw calls.
13
+ * An entity was culled in the render pass while `culledEntityStamp[entityUID] === cullTick`.
14
+ */
15
+ export type InstanceCullingState = {
16
+ readonly culledEntityStamp: Uint32Array;
17
+ readonly cullTick: number;
18
+ };
11
19
  /**
12
20
  * MeshRendererComponent is a component that manages the rendering of a mesh entity.
13
21
  * It handles mesh rendering pipeline, IBL (Image-Based Lighting) cube maps, frustum culling,
@@ -26,6 +34,11 @@ export declare class MeshRendererComponent extends Component {
26
34
  private static __updateCount;
27
35
  static _isFrustumCullingEnabled: boolean;
28
36
  private __fingerPrint;
37
+ /** Per-render-pass scratch buffers reused by sort_$render to avoid per-frame allocations. */
38
+ private static __sortScratchMap;
39
+ /** Memoized rendering strategy for common_$prerender (the hot path runs once per frame). */
40
+ private static __prerenderStrategyEngineUid;
41
+ private static __prerenderStrategy;
29
42
  /**
30
43
  * Creates a new MeshRendererComponent instance.
31
44
  * @param engine - The engine instance
@@ -144,9 +157,56 @@ export declare class MeshRendererComponent extends Component {
144
157
  * Filters out mesh components that are not visible from the camera's perspective.
145
158
  * @param cameraComponent - The camera component used for frustum culling
146
159
  * @param meshComponents - Array of mesh components to be culled
147
- * @returns Array of primitives that passed the frustum culling test
160
+ * @param outPrimitives - Reusable output array. It is cleared and filled with the primitives that passed culling
161
+ * @param scratch - The scratch of the render pass. The entities culled in this pass are stamped into it
162
+ * so that instanced draw calls can skip their instances
163
+ * @returns The `outPrimitives` array (same reference) for convenience
148
164
  */
149
165
  private static __cullingWithViewFrustum;
166
+ /**
167
+ * Culls the instances that share a mesh with the mesh components of the render pass but are not
168
+ * registered in the render pass themselves.
169
+ *
170
+ * Instanced draw calls render every entity sharing a mesh. For example, the VRM outline pass only holds
171
+ * the original model, while its shallow copies are drawn through instancing. Such sibling instances are
172
+ * culled with the camera of this render pass as well, once per mesh. Their visibility flags are left
173
+ * untouched because they belong to the render passes the entities are registered in.
174
+ */
175
+ private static __cullSiblingInstances;
176
+ private static __stampCulledEntity;
177
+ /**
178
+ * Writes `cullTick` into `stamp[entityUID]`, growing the array up to the largest EntityUID seen so far.
179
+ * @returns The stamp array, which is a new array when it has grown
180
+ */
181
+ private static __stampEntity;
182
+ /**
183
+ * Gets the latest culling result of a render pass for per-instance culling of instanced draw calls.
184
+ * The result stays valid while `sort_$render` reuses its cached primitive list for the render pass.
185
+ * @param renderPass - The render pass
186
+ * @returns The culling state, or undefined if no culling has run for the render pass
187
+ * @internal
188
+ */
189
+ static _getInstanceCullingState(renderPass: RenderPass): InstanceCullingState | undefined;
190
+ /**
191
+ * Appends the primitives of a mesh component to `outPrimitives` and computes the
192
+ * view depth for blended primitives.
193
+ */
194
+ private static __appendPrimitivesOfMeshComponent;
195
+ /**
196
+ * Removes duplicated primitives in place without allocating a `Set` or a new array.
197
+ * A primitive UID is unique, so a stamp array indexed by the UID is enough to detect
198
+ * duplicates. `primitives.length` is updated to the deduplicated length.
199
+ */
200
+ private static __removeDuplicatedPrimitives;
201
+ /** Sort comparator shared by every render pass (avoids allocating a closure per frame). */
202
+ private static __comparePrimitives;
203
+ /**
204
+ * Builds the primitive UID list used for drawing. The trailing `-1` is the sentinel
205
+ * that terminates the list.
206
+ */
207
+ private static __createPrimitiveUids;
208
+ /** Returns (and lazily creates) the reusable scratch buffers of a render pass. */
209
+ private static __getSortScratch;
150
210
  /**
151
211
  * Common pre-rendering setup method that prepares the rendering strategy.
152
212
  * Initializes the rendering strategy if not already set and calls its prerender method.
@@ -6,7 +6,7 @@ import type { RaycastResultEx2 } from '../../geometry/types/GeometryTypes';
6
6
  import type { ISceneGraphEntity } from '../../helpers/EntityHelper';
7
7
  import { AABB } from '../../math/AABB';
8
8
  import type { IMatrix44 } from '../../math/IMatrix';
9
- import type { IQuaternion } from '../../math/IQuaternion';
9
+ import type { IMutableQuaternion, IQuaternion } from '../../math/IQuaternion';
10
10
  import type { IVector3 } from '../../math/IVector';
11
11
  import { MutableMatrix33 } from '../../math/MutableMatrix33';
12
12
  import { MutableMatrix44 } from '../../math/MutableMatrix44';
@@ -27,12 +27,20 @@ export declare class SceneGraphComponent extends Component {
27
27
  private __parent?;
28
28
  private __children;
29
29
  private __gizmoChildren;
30
+ /** True while this node is attached to its parent as a gizmo child (see _addGizmoChild). */
31
+ private __isGizmoChild;
30
32
  private __physicsComponentCountInSubtree;
33
+ private static __hierarchyVersion;
31
34
  private _worldMatrix;
32
35
  private _worldMatrixRest;
33
36
  private _normalMatrix;
34
37
  private _worldRotation;
35
38
  private __isWorldMatrixUpToDate;
39
+ /**
40
+ * Monotonically increasing counter that advances whenever this node's world matrix is invalidated.
41
+ * Consumers such as SkeletalComponent sum these counters to detect whether any input changed.
42
+ */
43
+ private __worldMatrixVersion;
36
44
  private __isWorldMatrixRestUpToDate;
37
45
  private __isNormalMatrixUpToDate;
38
46
  private __isWorldRotationUpToDate;
@@ -61,11 +69,19 @@ export declare class SceneGraphComponent extends Component {
61
69
  private static __sceneGraphs;
62
70
  private static invertedMatrix44;
63
71
  private static __tmp_mat4;
64
- private static __tmp_mat4_2;
65
72
  private static __tmp_mat4_3;
66
73
  private static __tmp_mat4_4;
67
74
  private static __tmp_quat_0;
68
75
  private static __tmp_quat_1;
76
+ private static __tmp_quat_2;
77
+ private static __tmp_quat_3;
78
+ private static __tmp_vec3_0;
79
+ private static __tmp_vec3_1;
80
+ private static __tmp_vec3_2;
81
+ private static __tmp_matrixScale;
82
+ private static __tmp_physicsWorldScale;
83
+ private static __tmp_euler;
84
+ private static __tmp_translate;
69
85
  /** Map to store update count per Engine instance for multi-engine support */
70
86
  private static __updateCountMap;
71
87
  private static __tmpAABB;
@@ -195,6 +211,12 @@ export declare class SceneGraphComponent extends Component {
195
211
  * Gets the component type identifier for SceneGraphComponent.
196
212
  * @returns The component type ID
197
213
  */
214
+ /**
215
+ * Gets the version counter of the scene graph hierarchy.
216
+ * It changes whenever a parent-child relationship of any SceneGraphComponent may have changed.
217
+ * @returns The hierarchy version counter
218
+ */
219
+ static get hierarchyVersion(): number;
198
220
  static get componentTID(): 4;
199
221
  /**
200
222
  * Gets the component type identifier for this instance.
@@ -209,6 +231,13 @@ export declare class SceneGraphComponent extends Component {
209
231
  * Recursively marks the world matrix rest state as dirty for this node and all children.
210
232
  */
211
233
  setWorldMatrixRestDirtyRecursively(): void;
234
+ /**
235
+ * Gets the monotonically increasing world matrix version of this node.
236
+ * The value changes whenever the node is marked dirty, so summing it over a set of nodes detects
237
+ * whether any of them may need to be recomputed.
238
+ * @returns The world matrix version
239
+ */
240
+ get worldMatrixVersion(): number;
212
241
  /**
213
242
  * Marks the world matrix as dirty and propagates changes up the hierarchy.
214
243
  */
@@ -325,7 +354,12 @@ export declare class SceneGraphComponent extends Component {
325
354
  isWorldMatrixUpToDateRecursively(): boolean;
326
355
  /**
327
356
  * Recursively calculates the world matrix from this node up to the root.
328
- * @returns The calculated world matrix
357
+ *
358
+ * The result is memoized into `_worldMatrix` for every node visited by the recursion, not only the
359
+ * node that was requested. Without the write-back, processing children before their parents would
360
+ * recompute the same ancestor matrices once per descendant.
361
+ *
362
+ * @returns The cached world matrix of this node
329
363
  */
330
364
  private __calcWorldMatrixRecursively;
331
365
  /**
@@ -335,9 +369,18 @@ export declare class SceneGraphComponent extends Component {
335
369
  private __calcWorldMatrixRestRecursively;
336
370
  /**
337
371
  * Gets the world rotation quaternion by recursively combining local rotations.
372
+ * This allocates a new quaternion. Use {@link getQuaternionRecursivelyTo}
373
+ * when a pre-allocated output quaternion is available (e.g. in hot per-frame paths).
338
374
  * @returns The world rotation quaternion
339
375
  */
340
376
  getQuaternionRecursively(): IQuaternion;
377
+ /**
378
+ * Gets the world rotation quaternion by recursively combining local rotations
379
+ * and stores the result in the given output quaternion without allocating.
380
+ * @param out - The output quaternion to store the result
381
+ * @returns The output quaternion containing the world rotation
382
+ */
383
+ getQuaternionRecursivelyTo(out: IMutableQuaternion): IMutableQuaternion;
341
384
  /**
342
385
  * Gets the world position of this node.
343
386
  * @returns The world position as a Vector3
@@ -548,9 +591,12 @@ export declare class SceneGraphComponent extends Component {
548
591
  /**
549
592
  * Resolves world-scale magnitudes with signs relative to the entity's proper world rotation.
550
593
  * Physics bodies use that rotation separately, so reflected local offsets need these signs.
594
+ *
595
+ * The returned vector is a shared reusable instance, so callers must copy it
596
+ * when they need to keep the values around.
551
597
  * @internal
552
598
  */
553
- _getPhysicsWorldScale(matrix?: IMatrix44): Vector3;
599
+ _getPhysicsWorldScale(matrix?: IMatrix44): IVector3;
554
600
  /**
555
601
  * Creates a shallow copy of a child scene graph component.
556
602
  * @param child - The child component to copy
@@ -11,7 +11,7 @@ import { MutableVector4 } from '../../math/MutableVector4';
11
11
  import type { Accessor } from '../../memory/Accessor';
12
12
  import type { Engine } from '../../system/Engine';
13
13
  import type { ComponentToComponentMethods } from '../ComponentTypes';
14
- import type { SceneGraphComponent } from '../SceneGraph/SceneGraphComponent';
14
+ import { SceneGraphComponent } from '../SceneGraph/SceneGraphComponent';
15
15
  /**
16
16
  * SkeletalComponent manages skeletal animation for entities.
17
17
  * This component handles bone transformations, joint matrices, and skinning calculations
@@ -63,7 +63,19 @@ export declare class SkeletalComponent extends Component {
63
63
  private static __bindShapeSignatureMap;
64
64
  private __jointListKey?;
65
65
  private __skinCacheKey?;
66
+ private __skinCacheKeyAnimationBindingVersion;
67
+ private __skinCacheKeyHierarchyVersion;
66
68
  private __inverseBindMatricesSignature?;
69
+ /**
70
+ * Memoized input signature of the last skinning computation. When the skin cache key, the joint
71
+ * world matrices, the skinned node world matrix and the bind shape matrix are unchanged, the
72
+ * whole skinning loop can be skipped and the previous bone data reused.
73
+ */
74
+ private __hasSkinComputeSignature;
75
+ private __lastSkinComputeCacheKey?;
76
+ private __lastSkinComputeJointVersionSum;
77
+ private __lastSkinComputeOwnVersion;
78
+ private __lastSkinComputeBindShapeMatrix?;
67
79
  private static __tookGlobalDataNum;
68
80
  private static __tmp_mat4;
69
81
  private static __tmp_q;
@@ -380,6 +392,15 @@ export declare class SkeletalComponent extends Component {
380
392
  private static __getBindShapeSignature;
381
393
  private __getAnimationTrackFeatureHash;
382
394
  private __findAnimationTrackFeatureHash;
395
+ /**
396
+ * Updates the skinning cache key only when animation bindings or the scene graph hierarchy
397
+ * may have changed since the key was last computed.
398
+ * Searching animation track feature hashes walks the whole model hierarchy, so doing it
399
+ * every frame for every SkeletalComponent is too expensive when many models are animated.
400
+ * Other inputs of the key (joints, inverse bind matrices, bone data type) update the key
401
+ * immediately in their setters.
402
+ */
403
+ private __updateSkinCacheKeyIfNeeded;
383
404
  /**
384
405
  * Updates the skinning cache key based on current animation state.
385
406
  *
@@ -397,6 +418,29 @@ export declare class SkeletalComponent extends Component {
397
418
  * - Each model maintains its own cache
398
419
  */
399
420
  private __updateSkinCacheKey;
421
+ /**
422
+ * Drops the memoized skinning input signature so the next $logic recomputes skinning.
423
+ */
424
+ private __invalidateSkinComputeSignature;
425
+ /**
426
+ * Returns true when every input that affects the bone data is identical to the last computation.
427
+ *
428
+ * The joint version sum works as a change detector because `worldMatrixVersion` only increases:
429
+ * if any joint (or the skinned node) was marked dirty, the sum necessarily differs.
430
+ *
431
+ * Constraint: like the world matrix cache itself, this signature only observes changes made
432
+ * through the transform/renderer APIs. Writing `matrixInner` directly or mutating
433
+ * `_bindShapeMatrix` in place is not detected; callers must invalidate through the setters.
434
+ *
435
+ * @param cacheKey - The current skinning cache key
436
+ * @returns True when the skinning loop can be skipped
437
+ */
438
+ private __isSkinComputeInputUnchanged;
439
+ /**
440
+ * Records the inputs that produced the current bone data.
441
+ * @param cacheKey - The skinning cache key used for this computation
442
+ */
443
+ private __recordSkinComputeSignature;
400
444
  private __createSkinningCache;
401
445
  private __applySkinningCache;
402
446
  }
@@ -23,6 +23,20 @@ export type VrmExpression = {
23
23
  export declare class VrmComponent extends Component {
24
24
  private __expressions;
25
25
  private __weights;
26
+ /** morph target key -> expressions that contribute to it (rebuilt when expressions change). */
27
+ private __morphTargetContributors;
28
+ /** expression name -> morph target keys it affects (rebuilt when expressions change). */
29
+ private __expressionMorphTargetKeys;
30
+ /** Reused scratch set of morph target keys affected by the current update. */
31
+ private __changedMorphTargetKeys;
32
+ /** True until all morph targets have been written once after the expression set changed. */
33
+ private __needsFullMorphTargetUpdate;
34
+ /**
35
+ * BlendShapeComponent.updateCount observed after the last morph target application.
36
+ * If the counter moved without this component writing, another writer (a weights animation
37
+ * channel, an editor slider, ...) changed morph weights and they must be recomputed.
38
+ */
39
+ private __lastAppliedBlendShapeUpdateCount;
26
40
  _version: string;
27
41
  /**
28
42
  * Creates a new VrmComponent instance.
@@ -49,6 +63,11 @@ export declare class VrmComponent extends Component {
49
63
  * @param expressions - Array of VRM expressions to register
50
64
  */
51
65
  setVrmExpressions(expressions: VrmExpression[]): void;
66
+ /**
67
+ * Builds the reverse index used for differential morph target updates.
68
+ * Called only when the expression set changes, never per frame.
69
+ */
70
+ private __rebuildMorphTargetContributors;
52
71
  /**
53
72
  * Sets the weight for a specific VRM expression.
54
73
  * This method clamps the input, applies binary-expression behavior, and updates
@@ -58,19 +77,30 @@ export declare class VrmComponent extends Component {
58
77
  */
59
78
  setExpressionWeight(expressionName: VrmExpressionName, weight: number): void;
60
79
  /**
61
- * Sets multiple VRM expression weights and updates morph targets in one pass.
80
+ * Sets multiple VRM expression weights and updates only the morph targets whose total changed.
62
81
  * This is used when several expression animation channels are evaluated together.
63
82
  * @param expressionWeights - Expression names and their evaluated weights
64
83
  */
65
84
  setExpressionWeights(expressionWeights: ReadonlyMap<VrmExpressionName, number>): void;
85
+ /**
86
+ * Applies one expression weight.
87
+ * @param expressionName - The expression to update
88
+ * @param weight - The requested weight
89
+ * @param changedKeys - Receives the morph target keys affected by a change
90
+ * @returns True when the applied weight actually changed
91
+ */
66
92
  private __setExpressionWeight;
67
93
  /**
68
- * Recomputes morph target weights from all expression contributions.
94
+ * Recomputes the given morph targets from all expression contributions.
69
95
  *
70
96
  * Multiple VRM expressions may bind the same morph target. Applying each expression directly
71
97
  * would make the result depend on map insertion order, so contributions are accumulated first.
98
+ * The total is recomputed from the contributing expressions (not accumulated as a delta) to avoid
99
+ * floating point drift.
100
+ *
101
+ * @param morphTargetKeys - Keys of the morph targets to recompute
72
102
  */
73
- private __applyExpressionWeightsToMorphTargets;
103
+ private __applyMorphTargets;
74
104
  /**
75
105
  * Gets the current weight of a specific VRM expression.
76
106
  * @param expressionName - The name of the expression to query
@@ -114,6 +114,23 @@ export declare class ComponentRepository {
114
114
  * ```
115
115
  */
116
116
  getComponentFromComponentTID(componentTid: ComponentTID, componentSid: ComponentSID): Component | undefined;
117
+ /**
118
+ * Checks whether at least one live component of the given type exists.
119
+ * This is allocation-free and is intended for hot paths such as the render
120
+ * loop, where building a filtered component list every frame is wasteful.
121
+ *
122
+ * @param componentTID - The ComponentTID to check
123
+ * @returns True if at least one live component of the type exists
124
+ */
125
+ hasAnyComponent(componentTID: ComponentTID): boolean;
126
+ /**
127
+ * Counts live components of the given type without allocating a filtered
128
+ * array. Intended for per-frame checks in the render loop.
129
+ *
130
+ * @param componentTID - The ComponentTID to count
131
+ * @returns The number of live components of the type
132
+ */
133
+ getComponentCount(componentTID: ComponentTID): number;
117
134
  /**
118
135
  * Gets an array of all component instances of the specified type.
119
136
  * This is an internal method that includes undefined slots in the array.
@@ -26,6 +26,19 @@ export declare class Mesh implements IMesh {
26
26
  private __localAABB;
27
27
  private __vaoUids;
28
28
  private __variationVBOUid;
29
+ /** Instance variation data of all the entities, in the order of `__variationEntityUIDs`. */
30
+ private __variationEntityInfo?;
31
+ /** EntityUIDs of the instances stored in `__variationEntityInfo`. */
32
+ private __variationEntityUIDs?;
33
+ /** Mirror of the current content of the variation VBO (WebGL). */
34
+ private __variationVBOContent?;
35
+ /** Scratch buffer to pack the instance variation data of the visible instances. */
36
+ private __packedVariationEntityInfo?;
37
+ /** Number of the instances packed at the front of the variation VBO. */
38
+ private __variationVBOInstanceCount;
39
+ /** Culling state the variation VBO content was packed for; used to skip redundant packing. */
40
+ private __variationVBOCulledEntityStamp?;
41
+ private __variationVBOCullTick;
29
42
  private __latestPrimitivePositionAccessorVersionForAABB;
30
43
  private __latestPrimitivePositionAccessorVersionForSetUpDone;
31
44
  private __belongToEntities;
@@ -136,6 +149,20 @@ export declare class Mesh implements IMesh {
136
149
  * @internal
137
150
  */
138
151
  updateVariationVBO(): boolean;
152
+ /**
153
+ * Packs the instance variation data of the instances that were not culled in a render pass
154
+ * into the front of the variation VBO, so that an instanced draw call renders only them.
155
+ * The VBO is rewritten only when its content changes. WebGL only.
156
+ *
157
+ * Instances whose entities are not handled by the render pass's culling keep being drawn.
158
+ *
159
+ * @param culledEntityStamp - Per-EntityUID stamps written by the culling of the render pass
160
+ * (undefined: draw all the instances)
161
+ * @param cullTick - The stamp value of the latest culling of the render pass
162
+ * @returns The number of the instances to draw
163
+ * @internal
164
+ */
165
+ _packVisibleInstancesToVariationVBO(culledEntityStamp: Uint32Array | undefined, cullTick: number): number;
139
166
  /**
140
167
  * Deletes the variation VBO (Vertex Buffer Object).
141
168
  * @returns True if updated, false if not changed (not dirty)
@@ -31,6 +31,8 @@ export declare class RotationGizmo extends Gizmo {
31
31
  private static readonly __tmpVector3_7;
32
32
  private static readonly __tmpVector3_8;
33
33
  private static readonly __tmpVector3_9;
34
+ /** Reusable quaternion for world-rotation calculations (avoids per-frame allocations) */
35
+ private static readonly __tmpQuaternion_0;
34
36
  private __isPointerDown;
35
37
  private __startVector;
36
38
  private __deltaQuaternion;
@@ -22,6 +22,13 @@ export declare class ScaleGizmo extends Gizmo {
22
22
  private __onPointerDownFunc;
23
23
  private __onPointerMoveFunc;
24
24
  private __onPointerUpFunc;
25
+ /** Reusable quaternion for world-rotation calculations (avoids per-frame allocations) */
26
+ private static readonly __tmpQuaternion_0;
27
+ /** Reusable vectors for drag calculations (avoids per-frame allocations) */
28
+ private static readonly __tmpVector3_0;
29
+ private static readonly __tmpVector3_1;
30
+ private static readonly __tmpVector3_2;
31
+ private static readonly __tmpVector3_3;
25
32
  /**
26
33
  * Gets the resources for a specific engine, or undefined if not initialized.
27
34
  */
@@ -23,6 +23,13 @@ export declare class TranslationGizmo extends Gizmo {
23
23
  private __onPointerUpFunc;
24
24
  private __isCameraControllerDisabled;
25
25
  private static __length;
26
+ /** Reusable quaternions for world-rotation calculations (avoids per-frame allocations) */
27
+ private static readonly __tmpQuaternion_0;
28
+ private static readonly __tmpQuaternion_1;
29
+ /** Reusable vectors for drag calculations (avoids per-frame allocations) */
30
+ private static readonly __tmpVector3_0;
31
+ private static readonly __tmpVector3_1;
32
+ private static readonly __tmpVector3_2;
26
33
  /**
27
34
  * Gets the resources for a specific engine, or undefined if not initialized.
28
35
  */
@@ -11,7 +11,7 @@ import type { Material } from '../materials/core/Material';
11
11
  import type { RenderPass } from '../renderer/RenderPass';
12
12
  import type { Engine } from '../system/Engine';
13
13
  import type { AbstractTexture } from '../textures/AbstractTexture';
14
- import { Sampler } from '../textures/Sampler';
14
+ import { type Sampler } from '../textures/Sampler';
15
15
  import type { Texture } from '../textures/Texture';
16
16
  /**
17
17
  * Creates a new material with the specified material content and maximum instances.
@@ -15,6 +15,15 @@ export declare class ShadowSystem {
15
15
  private __lightTypes;
16
16
  private __lightEnables;
17
17
  private __lightCastShadows;
18
+ /** Reused by setDepthBiasPV() on every frame. */
19
+ private __depthBiasPVArray?;
20
+ private __depthBiasPV?;
21
+ /** Scratch buffer used to detect whether the bias matrices changed since the last frame. */
22
+ private __depthBiasPVScratch?;
23
+ /** Incremented whenever the content of the depth bias matrices changes. */
24
+ private __depthBiasPVVersion;
25
+ /** `__depthBiasPVVersion` last written to each material, indexed by material UID. */
26
+ private __depthBiasPVVersionOfMaterials;
18
27
  private __lastTransformUpdateCountForAutoFit;
19
28
  private __lastEntityCountForAutoFit;
20
29
  private __lastAutoFitCenter;
@@ -64,6 +73,11 @@ export declare class ShadowSystem {
64
73
  * @param entities - Array of scene graph entities to apply the bias matrices to
65
74
  */
66
75
  setDepthBiasPV(entities: ISceneGraphEntity[]): void;
76
+ /**
77
+ * Background assets (tagged `type: background-assets`, e.g. the environment cube and the grid
78
+ * in RhodoniteEditor2) do not cast shadows. The shadow volume auto-fit excludes them as well.
79
+ */
80
+ private static __isShadowCaster;
67
81
  private __autoFitDirectionalLightShadowVolume;
68
82
  private __applyAutoFitToDirectionalLights;
69
83
  /**
@@ -12,6 +12,10 @@ import type { Material } from '../core/Material';
12
12
  export declare class CustomMaterialContent extends AbstractMaterialContent {
13
13
  private __diffuseIblCubeMapSampler;
14
14
  private __specularIblCubeMapSampler;
15
+ /** Material and values of the last IBL parameter write (WebGL DataTexture mode). */
16
+ private __lastIblMaterial?;
17
+ private __lastIblMaterialStateVersion;
18
+ private __lastIblValues;
15
19
  /**
16
20
  * Creates a new CustomMaterialContent instance with custom shaders and configuration.
17
21
  *