rhodonite 0.19.10 → 0.20.0

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 (65) hide show
  1. package/README.md +32 -2
  2. package/VERSION-FILE +1 -1
  3. package/dist/esm/foundation/components/Skeletal/SkeletalComponent.d.ts +138 -45
  4. package/dist/esm/foundation/core/Component.d.ts +63 -3
  5. package/dist/esm/foundation/core/ComponentMemoryRegistry.d.ts +59 -1
  6. package/dist/esm/foundation/core/Config.d.ts +8 -7
  7. package/dist/esm/foundation/definitions/BoneDataType.d.ts +12 -1
  8. package/dist/esm/foundation/importer/BoneDataTypeDetector.d.ts +31 -0
  9. package/dist/esm/foundation/importer/index.d.ts +1 -0
  10. package/dist/esm/foundation/math/AbstractMatrix.d.ts +3 -2
  11. package/dist/esm/foundation/math/AbstractQuaternion.d.ts +2 -1
  12. package/dist/esm/foundation/math/IMatrix.d.ts +2 -2
  13. package/dist/esm/foundation/math/IQuaternion.d.ts +4 -4
  14. package/dist/esm/foundation/math/LogQuaternion.d.ts +110 -38
  15. package/dist/esm/foundation/math/MathUtil.d.ts +55 -0
  16. package/dist/esm/foundation/math/Matrix22.d.ts +176 -30
  17. package/dist/esm/foundation/math/Matrix33.d.ts +206 -38
  18. package/dist/esm/foundation/math/Matrix44.d.ts +222 -39
  19. package/dist/esm/foundation/math/MutableMatrix22.d.ts +125 -130
  20. package/dist/esm/foundation/math/MutableMatrix33.d.ts +148 -162
  21. package/dist/esm/foundation/math/MutableMatrix44.d.ts +159 -183
  22. package/dist/esm/foundation/math/MutableQuaternion.d.ts +241 -132
  23. package/dist/esm/foundation/math/MutableScalar.d.ts +11 -12
  24. package/dist/esm/foundation/math/MutableVector2.d.ts +30 -31
  25. package/dist/esm/foundation/math/MutableVector3.d.ts +28 -26
  26. package/dist/esm/foundation/math/MutableVector4.d.ts +37 -37
  27. package/dist/esm/foundation/math/Quaternion.d.ts +529 -36
  28. package/dist/esm/foundation/math/Scalar.d.ts +13 -14
  29. package/dist/esm/foundation/math/Vector2.d.ts +38 -38
  30. package/dist/esm/foundation/math/Vector3.d.ts +55 -54
  31. package/dist/esm/foundation/math/Vector4.d.ts +54 -55
  32. package/dist/esm/index.js +691 -686
  33. package/dist/esm/types/glTF2.d.ts +7 -0
  34. package/dist/esmdev/foundation/components/Skeletal/SkeletalComponent.d.ts +138 -45
  35. package/dist/esmdev/foundation/core/Component.d.ts +63 -3
  36. package/dist/esmdev/foundation/core/ComponentMemoryRegistry.d.ts +59 -1
  37. package/dist/esmdev/foundation/core/Config.d.ts +8 -7
  38. package/dist/esmdev/foundation/definitions/BoneDataType.d.ts +12 -1
  39. package/dist/esmdev/foundation/importer/BoneDataTypeDetector.d.ts +31 -0
  40. package/dist/esmdev/foundation/importer/index.d.ts +1 -0
  41. package/dist/esmdev/foundation/math/AbstractMatrix.d.ts +3 -2
  42. package/dist/esmdev/foundation/math/AbstractQuaternion.d.ts +2 -1
  43. package/dist/esmdev/foundation/math/IMatrix.d.ts +2 -2
  44. package/dist/esmdev/foundation/math/IQuaternion.d.ts +4 -4
  45. package/dist/esmdev/foundation/math/LogQuaternion.d.ts +110 -38
  46. package/dist/esmdev/foundation/math/MathUtil.d.ts +55 -0
  47. package/dist/esmdev/foundation/math/Matrix22.d.ts +176 -30
  48. package/dist/esmdev/foundation/math/Matrix33.d.ts +206 -38
  49. package/dist/esmdev/foundation/math/Matrix44.d.ts +222 -39
  50. package/dist/esmdev/foundation/math/MutableMatrix22.d.ts +125 -130
  51. package/dist/esmdev/foundation/math/MutableMatrix33.d.ts +148 -162
  52. package/dist/esmdev/foundation/math/MutableMatrix44.d.ts +159 -183
  53. package/dist/esmdev/foundation/math/MutableQuaternion.d.ts +241 -132
  54. package/dist/esmdev/foundation/math/MutableScalar.d.ts +11 -12
  55. package/dist/esmdev/foundation/math/MutableVector2.d.ts +30 -31
  56. package/dist/esmdev/foundation/math/MutableVector3.d.ts +28 -26
  57. package/dist/esmdev/foundation/math/MutableVector4.d.ts +37 -37
  58. package/dist/esmdev/foundation/math/Quaternion.d.ts +529 -36
  59. package/dist/esmdev/foundation/math/Scalar.d.ts +13 -14
  60. package/dist/esmdev/foundation/math/Vector2.d.ts +38 -38
  61. package/dist/esmdev/foundation/math/Vector3.d.ts +55 -54
  62. package/dist/esmdev/foundation/math/Vector4.d.ts +54 -55
  63. package/dist/esmdev/index.js +4994 -2723
  64. package/dist/esmdev/types/glTF2.d.ts +7 -0
  65. package/package.json +12 -10
package/README.md CHANGED
@@ -207,8 +207,24 @@ The following command runs unit tests and E2E tests.
207
207
  $ pnpm run test
208
208
  ```
209
209
 
210
- The E2E test uses a headless browser for rendering. Because the results are GPU hardware-dependent rather than software-dependent, results will vary depending on your environment.
211
- Since the correct images were run in the library author's environment, it is likely that many tests will fail in your environment.
210
+ The E2E test uses a headless browser for rendering. The reference images are generated in the CI environment: Ubuntu + Mesa's software stack (llvmpipe for GL/WebGL2, lavapipe for Vulkan) and Chromium's "WebGPU on Vulkan via GL interop" path, which is what makes WebGPU canvases capturable without a GPU. That environment is available locally as a Docker container, so the strict check and the reference images are reproducible on any machine:
211
+
212
+ ```bash
213
+ $ pnpm test-e2e:docker # strict run in the reference environment
214
+ $ pnpm test-e2e:docker:update # regenerate all reference images
215
+ ```
216
+
217
+ Running the suite natively (for example on macOS with a real GPU) renders slightly differently from the software rasterizer (measured at up to ~1%, mostly IBL samples), so native runs apply a 2% tolerance floor (`E2E_NON_REFERENCE_FAILURE_THRESHOLD`). CI runs on the `ubuntu-24.04-arm` runner and compares with the same strict thresholds as the container (`E2E_REFERENCE_FAILURE_THRESHOLD`, default `0`); the arm64 image is used because llvmpipe renders slightly differently on x64. If a hosted runner ever renders differently from the machine that generated the reference images, that floor can be raised for CI only.
218
+
219
+ If a Linux environment cannot provide the GL/Vulkan interop (no Mesa, or the flags are opted out), WebGPU canvases stay blank. In that case run the WebGPU cases as smoke tests:
220
+
221
+ ```bash
222
+ $ E2E_WEBGPU_SMOKE=1 pnpm run test-e2e
223
+ ```
224
+
225
+ With `E2E_WEBGPU_SMOKE=1` the WebGPU samples only have to reach their render loop; no screenshot comparison is performed.
226
+
227
+ The E2E runner passes the Mesa-specific flags automatically on Linux. Set `E2E_SOFTWARE_RENDERING=0` to opt out, or `PUPPETEER_EXECUTABLE_PATH` to use a specific Chrome binary. `E2E_REFERENCE_FAILURE_THRESHOLD` (percent, default `0`) is a tolerance floor for the reference environment; CI sets it to `5` because GitHub's hosted runners use a different CPU/instance than the machine that generated the reference images (a few sensitive samples differ by up to ~3.5%). `E2E_NON_REFERENCE_FAILURE_THRESHOLD` (default `2`, percent) is the floor used outside the reference environment; `E2E_REFERENCE_ENVIRONMENT=0` forces that floor on Linux too.
212
228
 
213
229
  You can execute a part of tests like this.
214
230
 
@@ -228,6 +244,20 @@ $ pnpm run test-unit-part -- ./src/foundation/core/Entity.test.ts
228
244
  $ pnpm run test-e2e-part -- ./samples/test_e2e/DataTextureInstancedDrawing
229
245
  ```
230
246
 
247
+ ### Running the E2E suite in the CI environment (Docker)
248
+
249
+ The E2E job runs on `ubuntu-latest` with Mesa's software stack (llvmpipe for GL, lavapipe for Vulkan). To reproduce exactly the same environment on any machine with Docker:
250
+
251
+ ```bash
252
+ $ pnpm test-e2e:docker # run the full E2E suite in the container
253
+ $ pnpm test-e2e:docker:update # regenerate all reference images in the container
254
+ $ pnpm test-e2e:docker:shell # open a shell inside the container
255
+ ```
256
+
257
+ The repository is mounted into the container, but `node_modules`, `dist`, the pnpm store and the Puppeteer browser cache live in Docker volumes, so the host installation is never modified. The first run builds the image and downloads Chrome (a few minutes); later runs only rebuild the library and run the tests.
258
+
259
+ The reference images are generated by this container (`pnpm test-e2e:docker:update`), so the container is the source of truth: it compares strictly against them, while native runs apply the tolerance floor described above.
260
+
231
261
  ## Development using VSCode devcontainer
232
262
 
233
263
  This project supports the VSCode devcontainer for any docker-installed OS.
package/VERSION-FILE CHANGED
@@ -1,2 +1,2 @@
1
- v0.19.10-1-g2b33f7339-dirty
1
+ v0.20.0-1-g556e99a8a-dirty
2
2
  main
@@ -2,6 +2,7 @@ import type { ComponentSID, ComponentTID, EntityUID, Index, TypedArray } from '.
2
2
  import { Component } from '../../core/Component';
3
3
  import type { IEntity } from '../../core/Entity';
4
4
  import { type EntityRepository } from '../../core/EntityRepository';
5
+ import { type BoneDataTypeEnum } from '../../definitions/BoneDataType';
5
6
  import type { ISkeletalEntity } from '../../helpers/EntityHelper';
6
7
  import type { IMatrix44 } from '../../math/IMatrix';
7
8
  import { Matrix44 } from '../../math/Matrix44';
@@ -24,13 +25,36 @@ export declare class SkeletalComponent extends Component {
24
25
  private __jointMatrices?;
25
26
  topOfJointsHierarchy?: SceneGraphComponent;
26
27
  isSkinning: boolean;
27
- private __qtsInfo;
28
- private _boneMatrix;
29
- private _boneTranslatePackedQuat;
30
- private _boneScalePackedQuat;
31
- private _boneQuaternion;
32
- private _boneTranslateScale;
33
- private _boneCompressedChunk;
28
+ /**
29
+ * GPU bone data of all joints. The layout per joint depends on the bone data type:
30
+ * - Mat43x1: 3 vec4 per joint (4x3 matrix, column-major)
31
+ * - Vec4x2: 2 vec4 per joint ([translation.xyz, logQuat.lo], [scale.xyz, logQuat.hi]).
32
+ * The x scale is negative for a mirrored joint matrix.
33
+ * - Vec4x1: 1 vec4 per joint ([logQuat.lo, logQuat.hi, packedTranslateScale.lo, packedTranslateScale.hi]).
34
+ * packedTranslateScale is snorm16 x 4: the translation divided by `_boneDataInfo.xyz`, and
35
+ * log2(|uniform scale|) / 16 (see MathUtil.encodeVec4x1Scale). Bit 31 of logQuat.hi is the sign of the scale.
36
+ *
37
+ * This is a variable-length member: each component gets exactly (joint count) x (vec4 per joint) vec4s,
38
+ * even though skeletal components share buffer views, and shaders find it through `_boneDataLocation`.
39
+ */
40
+ private _boneData;
41
+ /**
42
+ * The location of `_boneData` in the GPU data (written by the memory allocation of Component).
43
+ */
44
+ private _boneDataLocation;
45
+ /**
46
+ * Per-component bone data info: xyz = dequantization factors of translation (Vec4x1 only),
47
+ * w = bone data type index (used by shaders to select the decoding path).
48
+ */
49
+ private _boneDataInfo;
50
+ private __boneDataUint32?;
51
+ private __boneDataType;
52
+ /** Whether __boneDataType was chosen automatically (an automatic Vec4x1 may be switched to Vec4x2) */
53
+ private __isBoneDataTypeAutoSelected;
54
+ private __hasWarnedNonUniformScale;
55
+ private __allocatedBoneDataType?;
56
+ private __boneDataArrayLength;
57
+ private __boneTranslateScaleWork;
34
58
  private __jointMatrix;
35
59
  private __isWorldMatrixVanilla;
36
60
  _isCulled: boolean;
@@ -41,7 +65,6 @@ export declare class SkeletalComponent extends Component {
41
65
  private __skinCacheKey?;
42
66
  private __inverseBindMatricesSignature?;
43
67
  private static __tookGlobalDataNum;
44
- private static __tmpVec3_0;
45
68
  private static __tmp_mat4;
46
69
  private static __tmp_q;
47
70
  private static __tmp_mat4_2;
@@ -90,71 +113,85 @@ export declare class SkeletalComponent extends Component {
90
113
  */
91
114
  setJoints(joints: SceneGraphComponent[]): void;
92
115
  /**
93
- * Lightweight joint update for remapping during shallow copy.
94
- * Only updates joint references without reinitializing buffers.
95
- * Used when joints are remapped to new entities during shallow copy.
116
+ * Gets the effective bone data type of this component.
117
+ * If Config.boneDataType is set, it overrides the bone data type of each component.
118
+ *
119
+ * @returns The effective bone data type
96
120
  */
97
- updateJointsLightweight(joints: SceneGraphComponent[]): void;
121
+ get boneDataType(): BoneDataTypeEnum;
98
122
  /**
99
- * Gets a copy of the joints array.
123
+ * Sets the bone data type of this component.
124
+ * Mat43x1 is the most precise (and the largest), Vec4x2 supports non-uniform scale,
125
+ * and Vec4x1 is the most compact but supports only uniform scale.
126
+ * If joints are already set and the GPU data layout changes, the bone data is re-allocated.
127
+ * Note that Config.boneDataType, if set, takes precedence over this value.
100
128
  *
101
- * @returns A copy of the SceneGraphComponents representing the joints
129
+ * If a non-uniform scale is found at runtime with Vec4x1, an automatically selected Vec4x1 is switched to Vec4x2,
130
+ * while an explicitly specified Vec4x1 is kept (the largest scale is used, and a warning is logged once).
131
+ *
132
+ * @param boneDataType - The bone data type to use
133
+ * @param isAutoSelected - True if the type was chosen automatically (e.g. by the glTF importer) rather than
134
+ * specified by the user
102
135
  */
103
- getJoints(): SceneGraphComponent[];
136
+ setBoneDataType(boneDataType: BoneDataTypeEnum, isAutoSelected?: boolean): void;
104
137
  /**
105
- * Gets the world matrix of the root joint in the hierarchy.
106
- *
107
- * @returns The world matrix of the top joint, or undefined if no top joint exists
138
+ * Re-allocates the bone data if the effective bone data type differs from the allocated layout.
108
139
  */
109
- get rootJointWorldMatrixInner(): MutableMatrix44 | undefined;
140
+ private __ensureBoneDataLayout;
110
141
  /**
111
- * Gets the computed joint matrices array.
142
+ * Calculates the array length (in vec4) of the bone data.
143
+ * The bone data is a variable-length member, so this is exact regardless of skeletalComponentCountPerBufferView.
112
144
  *
113
- * @returns The joint matrices array
145
+ * @param boneDataType - The bone data type
146
+ * @param jointCount - The number of joints
147
+ * @returns The array length in vec4
114
148
  */
115
- get jointMatrices(): number[] | undefined;
149
+ private static __calcBoneDataArrayLength;
116
150
  /**
117
- * Gets the quaternion array for joints (used in Vec4x2Old bone data type).
151
+ * Returns the per-instance array length of the bone data for memory allocation.
118
152
  *
119
- * @returns The Float32Array containing joint quaternions
153
+ * @param memberName - The name of the member field
154
+ * @returns The array length, or undefined for other members
120
155
  */
121
- get jointQuaternionArray(): TypedArray;
156
+ protected _getArrayLengthForAllocation(memberName: string): number | undefined;
157
+ private __setBoneDataInfo;
122
158
  /**
123
- * Gets the translate-scale array for joints.
124
- *
125
- * @returns The Float32Array containing joint translation and scale data
159
+ * Lightweight joint update for remapping during shallow copy.
160
+ * Only updates joint references without reinitializing buffers.
161
+ * Used when joints are remapped to new entities during shallow copy.
126
162
  */
127
- get jointTranslateScaleArray(): TypedArray;
163
+ updateJointsLightweight(joints: SceneGraphComponent[]): void;
128
164
  /**
129
- * Gets the translate-packed quaternion array for joints (used in Vec4x2 bone data type).
165
+ * Gets a copy of the joints array.
130
166
  *
131
- * @returns The Float32Array containing translation and packed quaternion data
167
+ * @returns A copy of the SceneGraphComponents representing the joints
132
168
  */
133
- get jointTranslatePackedQuat(): TypedArray;
169
+ getJoints(): SceneGraphComponent[];
134
170
  /**
135
- * Gets the scale-packed quaternion array for joints (used in Vec4x2 bone data type).
171
+ * Gets the world matrix of the root joint in the hierarchy.
136
172
  *
137
- * @returns The Float32Array containing scale and packed quaternion data
173
+ * @returns The world matrix of the top joint, or undefined if no top joint exists
138
174
  */
139
- get jointScalePackedQuat(): TypedArray;
175
+ get rootJointWorldMatrixInner(): MutableMatrix44 | undefined;
140
176
  /**
141
- * Gets the joint matrices array (used in Mat43x1 bone data type).
177
+ * Gets the computed joint matrices array.
142
178
  *
143
- * @returns The Float32Array containing joint matrices
179
+ * @returns The joint matrices array
144
180
  */
145
- get jointMatricesArray(): TypedArray;
181
+ get jointMatrices(): number[] | undefined;
146
182
  /**
147
- * Gets the compressed joint data chunk (used in Vec4x1 bone data type).
183
+ * Gets the GPU bone data array of all joints.
184
+ * The layout depends on the bone data type (see the `boneDataType` getter).
148
185
  *
149
- * @returns The Float32Array containing compressed joint data
186
+ * @returns The Float32Array containing the bone data
150
187
  */
151
- get jointCompressedChunk(): TypedArray;
188
+ get boneDataArray(): TypedArray;
152
189
  /**
153
- * Gets the compression information for joint data (used in Vec4x1 bone data type).
190
+ * Gets the bone data info (xyz: translation dequantization factors for Vec4x1, w: bone data type index).
154
191
  *
155
- * @returns The compression information vector
192
+ * @returns The bone data info vector
156
193
  */
157
- get jointCompressedInfo(): MutableVector4;
194
+ get boneDataInfo(): MutableVector4;
158
195
  /**
159
196
  * Gets a copy of the world matrix.
160
197
  *
@@ -210,6 +247,53 @@ export declare class SkeletalComponent extends Component {
210
247
  * Only follower joints are registered for early return (__currentFrameCachedEntityUIDs).
211
248
  */
212
249
  $logic(): void;
250
+ /**
251
+ * Calculates the determinant of the upper-left 3x3 part of a column-major 4x4 matrix.
252
+ *
253
+ * @param v - The matrix elements (column-major)
254
+ * @returns The determinant
255
+ */
256
+ private static __determinant3x3;
257
+ /**
258
+ * Extracts the rotation R of M = T * R * S, given the (signed) scales of S.
259
+ * The columns of the upper-left 3x3 of `m` are divided by the scales in place.
260
+ *
261
+ * If the rotation cannot be extracted (e.g. a zero scale used to hide a part of a mesh), the identity is
262
+ * returned without logging an error, since the rotation does not affect the result in that case.
263
+ *
264
+ * @param m - The matrix to decompose (overwritten)
265
+ * @param sx - The x scale (negative for a mirrored axis)
266
+ * @param sy - The y scale (negative for a mirrored axis)
267
+ * @param sz - The z scale (negative for a mirrored axis)
268
+ * @returns The rotation (a shared temporary quaternion)
269
+ */
270
+ private static __extractRotation;
271
+ /**
272
+ * Handles a non-uniform scale found with the Vec4x1 bone data type, which supports only uniform scale.
273
+ * An automatically selected Vec4x1 is switched to Vec4x2. An explicitly specified Vec4x1 (setBoneDataType or
274
+ * Config.boneDataType) is kept, and a warning is logged once (the largest scale of each joint is used).
275
+ *
276
+ * The components sharing the skinning cache with this one are switched together. Otherwise they would get
277
+ * a different cache key and lose the shared result, and a follower would fall back to its own joints, which
278
+ * may not be animated (see the AnimationComponent early return). If any of them specifies Vec4x1 explicitly,
279
+ * none of them is switched.
280
+ *
281
+ * @returns True if the bone data type has been switched to Vec4x2
282
+ */
283
+ private __handleNonUniformScaleOfVec4x1;
284
+ /**
285
+ * Gets the skeletal components that share the skinning cache with this component (including this one).
286
+ *
287
+ * @returns The components with the same skinning cache key
288
+ */
289
+ private __getComponentsSharingSkinCache;
290
+ /**
291
+ * Gets a CPU-side work buffer for translation and scale (used only in Vec4x1 bone data type).
292
+ *
293
+ * @param boneDataType - The bone data type
294
+ * @returns The work buffer (empty unless Vec4x1)
295
+ */
296
+ private __getTranslateScaleWork;
213
297
  /**
214
298
  * Copies matrix data to the matrix array in a specific format.
215
299
  * Extracts the first 3 rows of a 4x4 matrix (Mat43 format) for efficient GPU storage.
@@ -280,7 +364,16 @@ export declare class SkeletalComponent extends Component {
280
364
  */
281
365
  _getInverseBindMatrices(sg: SceneGraphComponent): IMatrix44;
282
366
  private __copyBoneBuffersFrom;
283
- private __registerBoneDataMembers;
367
+ /**
368
+ * Registers the bone data member and its location member.
369
+ * The bone data is a variable-length member, so its size is decided per component
370
+ * (see `_getArrayLengthForAllocation`).
371
+ */
372
+ static _registerBoneDataMember(): void;
373
+ /**
374
+ * Registers the bone data info member (one vec4 per component).
375
+ */
376
+ static _registerBoneDataInfoMember(): void;
284
377
  private static __buildJointListKey;
285
378
  private static __hashBytes;
286
379
  private static __getAccessorSignature;
@@ -1,4 +1,4 @@
1
- import type { ComponentTypeEnum } from '../../foundation/definitions/ComponentType';
1
+ import { type ComponentTypeEnum } from '../../foundation/definitions/ComponentType';
2
2
  import { type CompositionTypeEnum } from '../../foundation/definitions/CompositionType';
3
3
  import type { ComponentSID, Count, EntityUID, IndexOf16Bytes } from '../../types/CommonTypes';
4
4
  import type { ComponentToComponentMethods } from '../components/ComponentTypes';
@@ -29,6 +29,15 @@ export type MemberInfo = {
29
29
  componentType: ComponentTypeEnum;
30
30
  initValues: number[] | VectorN;
31
31
  convertToBool?: boolean;
32
+ /**
33
+ * Multiplier applied to the uniform array length in uniform mode
34
+ * (the array length becomes Config.maxSkeletalBoneNumberForUniformMode * this value).
35
+ */
36
+ uniformArrayLengthMultiplier?: number;
37
+ /**
38
+ * Whether this array member has a per-instance length (see `Component.registerMember`).
39
+ */
40
+ isVariableLength?: boolean;
32
41
  };
33
42
  type MemberName = string;
34
43
  /**
@@ -165,12 +174,45 @@ export declare class Component extends RnObject {
165
174
  * @param memberName - The name of the member field
166
175
  * @param dataClassType - The data class type for the member
167
176
  * @param initValues - Initial values to set for the member
168
- * @param isReUse - Whether to reuse an existing memory slot
177
+ * @param _isReUse - Whether this component is being reused (the existing slot is detected from the accessor)
169
178
  * @param componentSid - The component scoped ID
170
179
  * @param componentCountPerBufferView - The number of components per buffer view
171
180
  * @returns null on success
172
181
  */
173
182
  private __takeOne;
183
+ /**
184
+ * Allocates memory for a variable-length array member of this component instance.
185
+ *
186
+ * Unlike fixed members, the data is not placed in the slot layout shared by the components of a buffer view.
187
+ * Each instance gets its own chunk sized by `_getArrayLengthForAllocation`, and the location of the chunk
188
+ * (index of 16 bytes in the GPU data) is written to the `${memberName}Location` member so that shaders can find it.
189
+ * The chunk is kept per component SID and reused when it is large enough.
190
+ *
191
+ * @param info - The member info of the variable-length array member
192
+ * @param componentSid - The component scoped ID
193
+ */
194
+ private __takeVariableLengthOne;
195
+ /**
196
+ * Creates a new chunk of memory for a variable-length array member.
197
+ *
198
+ * @param engine - The engine instance
199
+ * @param bufferUse - The intended use of the buffer
200
+ * @param byteLength - The byte length of the chunk
201
+ * @returns The created chunk
202
+ */
203
+ private static __createVariableLengthChunk;
204
+ /**
205
+ * The radix used to split the location of a variable-length array member into two floats
206
+ * (`location = x * radix + y`), so that both are exactly representable as 32-bit floats.
207
+ */
208
+ static readonly _variableLengthLocationRadix = 65536;
209
+ /**
210
+ * Gets the name of the member which holds the location of a variable-length array member.
211
+ *
212
+ * @param memberName - The name of the variable-length array member
213
+ * @returns The name of the location member
214
+ */
215
+ static _getVariableLengthLocationMemberName(memberName: string): string;
174
216
  /**
175
217
  * Gets the ComponentMemoryRegistry for this component's engine.
176
218
  */
@@ -195,6 +237,11 @@ export declare class Component extends RnObject {
195
237
  * Registers a member field of the component class for memory allocation.
196
238
  * This method defines the memory layout and characteristics of component data members.
197
239
  *
240
+ * Variable-length array members (`isVariableLength: true`) are allocated per instance with the length
241
+ * returned by `_getArrayLengthForAllocation`, instead of the fixed slot layout shared by the components
242
+ * of a buffer view. Shaders find the data through a Vec4 member named `${memberName}Location`,
243
+ * which must be registered before the variable-length member.
244
+ *
198
245
  * @param bufferUse - The intended purpose/type of buffer use
199
246
  * @param memberName - The name of the member field
200
247
  * @param dataClassType - The class type of the data
@@ -202,8 +249,10 @@ export declare class Component extends RnObject {
202
249
  * @param componentType - The primitive data type (e.g., Float32, Int32)
203
250
  * @param initValues - Initial values for the member field
204
251
  * @param convertToBool - Whether to convert the member value to a boolean
252
+ * @param uniformArrayLengthMultiplier - Multiplier of the uniform array length in uniform mode
253
+ * @param isVariableLength - Whether the array member has a per-instance length
205
254
  */
206
- static registerMember(this: typeof Component, { bufferUse, memberName, dataClassType, shaderType, compositionType, componentType, initValues, arrayLength, componentSID, convertToBool, }: {
255
+ static registerMember(this: typeof Component, { bufferUse, memberName, dataClassType, shaderType, compositionType, componentType, initValues, arrayLength, componentSID, convertToBool, uniformArrayLengthMultiplier, isVariableLength, }: {
207
256
  bufferUse: BufferUseEnum;
208
257
  memberName: string;
209
258
  dataClassType: DataClassType;
@@ -214,6 +263,8 @@ export declare class Component extends RnObject {
214
263
  arrayLength?: Count | undefined;
215
264
  componentSID?: ComponentSID;
216
265
  convertToBool?: boolean;
266
+ uniformArrayLengthMultiplier?: number;
267
+ isVariableLength?: boolean;
217
268
  }): void;
218
269
  /**
219
270
  * Allocates memory for all member fields of this component instance.
@@ -224,6 +275,15 @@ export declare class Component extends RnObject {
224
275
  * @param isReUse - Whether to reuse existing memory allocations
225
276
  */
226
277
  submitToAllocation(componentCountPerBufferView: Count, isReUse: boolean): void;
278
+ /**
279
+ * Returns the array length to allocate for a variable-length array member of this component instance
280
+ * (see `registerMember`). Override this to allocate a per-instance size. When undefined is returned,
281
+ * the maximum array length registered for the component class is used.
282
+ *
283
+ * @param _memberName - The name of the variable-length array member
284
+ * @returns The array length, or undefined to use the class-wide value
285
+ */
286
+ protected _getArrayLengthForAllocation(_memberName: string): Count | undefined;
227
287
  /**
228
288
  * Gets the entity that owns this component.
229
289
  * This provides access to the entity and its other components.
@@ -1,8 +1,20 @@
1
- import type { Byte, Count } from '../../types/CommonTypes';
1
+ import type { Byte, ComponentSID, Count, IndexOf16Bytes } from '../../types/CommonTypes';
2
2
  import type { Accessor } from '../memory/Accessor';
3
+ import type { BufferView } from '../memory/BufferView';
3
4
  import type { Component } from './Component';
4
5
  type MemberName = string;
5
6
  type IndexOfTheBufferView = number;
7
+ /**
8
+ * A chunk of memory allocated for a variable-length array member of a component.
9
+ */
10
+ export type VariableLengthChunk = {
11
+ /** The buffer view which owns the memory of the chunk */
12
+ bufferView: BufferView;
13
+ /** The capacity of the chunk in bytes */
14
+ byteCapacity: Byte;
15
+ /** The location of the chunk in the GPU data (index of 16 bytes) */
16
+ location: IndexOf16Bytes;
17
+ };
6
18
  /**
7
19
  * ComponentMemoryRegistry manages memory-related data for components per Engine instance.
8
20
  *
@@ -41,6 +53,16 @@ export declare class ComponentMemoryRegistry {
41
53
  * Tracks which byte offset keys exist for each component class and member name.
42
54
  */
43
55
  private __byteOffsetKeysByMember;
56
+ /**
57
+ * Chunks of variable-length array members, per component SID.
58
+ * Key format: "ComponentTID:MemberName:ComponentSID"
59
+ */
60
+ private __variableLengthChunks;
61
+ /**
62
+ * Chunks of variable-length array members which are no longer used, per member.
63
+ * Key format: "ComponentTID:MemberName"
64
+ */
65
+ private __freeVariableLengthChunks;
44
66
  /**
45
67
  * The state version, incremented when component memory layout changes.
46
68
  */
@@ -137,6 +159,42 @@ export declare class ComponentMemoryRegistry {
137
159
  * @returns True if byte offset data exists
138
160
  */
139
161
  hasByteOffsetsForComponent(componentClass: typeof Component): boolean;
162
+ /**
163
+ * Gets the chunk of a variable-length array member of a component.
164
+ *
165
+ * @param componentClass - The component class
166
+ * @param memberName - The name of the variable-length array member
167
+ * @param componentSID - The component SID
168
+ * @returns The chunk or undefined if not allocated yet
169
+ */
170
+ getVariableLengthChunk(componentClass: typeof Component, memberName: MemberName, componentSID: ComponentSID): VariableLengthChunk | undefined;
171
+ /**
172
+ * Sets the chunk of a variable-length array member of a component.
173
+ * Note that this does not change the state version, since shaders read the locations of chunks at runtime.
174
+ *
175
+ * @param componentClass - The component class
176
+ * @param memberName - The name of the variable-length array member
177
+ * @param componentSID - The component SID
178
+ * @param chunk - The chunk to set
179
+ */
180
+ setVariableLengthChunk(componentClass: typeof Component, memberName: MemberName, componentSID: ComponentSID, chunk: VariableLengthChunk): void;
181
+ /**
182
+ * Puts a chunk which is no longer used into the free list so that it can be reused.
183
+ *
184
+ * @param componentClass - The component class
185
+ * @param memberName - The name of the variable-length array member
186
+ * @param chunk - The chunk to release
187
+ */
188
+ releaseVariableLengthChunk(componentClass: typeof Component, memberName: MemberName, chunk: VariableLengthChunk): void;
189
+ /**
190
+ * Takes the smallest free chunk which has enough capacity.
191
+ *
192
+ * @param componentClass - The component class
193
+ * @param memberName - The name of the variable-length array member
194
+ * @param byteLength - The required byte length
195
+ * @returns The chunk, or undefined if there is no suitable free chunk
196
+ */
197
+ takeFreeVariableLengthChunk(componentClass: typeof Component, memberName: MemberName, byteLength: Byte): VariableLengthChunk | undefined;
140
198
  /**
141
199
  * Gets the current state version.
142
200
  * This is incremented whenever the memory layout changes.
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Config.ts is a configuration file that contains the configuration for the library.
3
3
  */
4
- import { type BoneDataTypeEnum } from '../definitions/BoneDataType';
4
+ import type { BoneDataTypeEnum } from '../definitions/BoneDataType';
5
5
  import { LogLevel } from '../misc/Logger';
6
6
  type ConfigInitDescription = {
7
7
  scenegraphComponentCountPerBufferView?: number;
@@ -9,7 +9,6 @@ type ConfigInitDescription = {
9
9
  cameraComponentCountPerBufferView?: number;
10
10
  lightComponentCountPerBufferView?: number;
11
11
  maxLightNumber?: number;
12
- maxBoneNumberForMemoryBoostMode?: number;
13
12
  materialCountPerBufferView?: number;
14
13
  boneDataType?: BoneDataTypeEnum;
15
14
  maxSkeletalBoneNumberForUniformMode?: number;
@@ -37,16 +36,19 @@ export declare class Config {
37
36
  lightComponentCountPerBufferView: number;
38
37
  /** The maximum number of lights that Rhodonite can handle */
39
38
  maxLightNumber: number;
40
- /** The maximum number of bones that Rhodonite can handle for Memory Boost Mode */
41
- maxBoneNumberForMemoryBoostMode: number;
42
39
  /**
43
40
  * Number of instances of each material type to be placed consecutively in memory.
44
41
  * This is on the memory layout, and the number of material instances that can be generated is not limited by this setting.
45
42
  * If this limit is exceeded, the material type is internally treated as a separate material type.
46
43
  */
47
44
  materialCountPerBufferView: number;
48
- /** The data type of the bone */
49
- boneDataType: import("..").EnumIO;
45
+ /**
46
+ * Forces the bone data type of all SkeletalComponents.
47
+ * When undefined (default), each SkeletalComponent uses its own bone data type
48
+ * (see SkeletalComponent.setBoneDataType). Importers choose Vec4x1 or Vec4x2 automatically,
49
+ * and other SkeletalComponents default to Vec4x2.
50
+ */
51
+ boneDataType: BoneDataTypeEnum | undefined;
50
52
  /** The maximum number of bones of each skeleton that Rhodonite can handle for Uniform Mode */
51
53
  maxSkeletalBoneNumberForUniformMode: number;
52
54
  /** Whether the UBO is enabled */
@@ -68,6 +70,5 @@ export declare class Config {
68
70
  /** The minimum log level that will be output. Messages below this level are ignored. */
69
71
  logLevel: LogLevel;
70
72
  constructor(initDescription?: ConfigInitDescription);
71
- setUpAsMemoryBoostMode(): void;
72
73
  }
73
74
  export {};
@@ -2,12 +2,23 @@ import { type EnumIO } from '../misc/EnumIO';
2
2
  export type BoneDataTypeEnum = EnumIO;
3
3
  declare function from(index: number): BoneDataTypeEnum;
4
4
  declare function fromString(str: string): BoneDataTypeEnum;
5
+ /**
6
+ * Returns how many vec4 slots one joint occupies in the GPU bone data array.
7
+ *
8
+ * - Mat43x1: 3 (a 4x3 matrix)
9
+ * - Vec4x2: 2 (translation + scale, with a log-quaternion packed into the w components)
10
+ * - Vec4x1: 1 (log-quaternion + quantized translation/uniform scale)
11
+ *
12
+ * @param boneDataType - The bone data type
13
+ * @returns The number of vec4 slots per joint
14
+ */
15
+ declare function getVec4CountPerJoint(boneDataType: BoneDataTypeEnum): number;
5
16
  export declare const BoneDataType: Readonly<{
6
17
  Mat43x1: EnumIO;
7
18
  Vec4x2: EnumIO;
8
- Vec4x2Old: EnumIO;
9
19
  Vec4x1: EnumIO;
10
20
  from: typeof from;
11
21
  fromString: typeof fromString;
22
+ getVec4CountPerJoint: typeof getVec4CountPerJoint;
12
23
  }>;
13
24
  export {};
@@ -0,0 +1,31 @@
1
+ import type { RnM2, RnM2Skin } from '../../types/RnM2';
2
+ import { type BoneDataTypeEnum } from '../definitions/BoneDataType';
3
+ /**
4
+ * Checks whether the given three scale components are (almost) uniform.
5
+ * The same criterion is used by SkeletalComponent at runtime (see MathUtil.isUniformScale).
6
+ *
7
+ * @param x - The x component of the scale
8
+ * @param y - The y component of the scale
9
+ * @param z - The z component of the scale
10
+ * @returns True if the scale is uniform
11
+ */
12
+ export declare function isUniformScale(x: number, y: number, z: number): boolean;
13
+ /**
14
+ * Chooses the bone data type for a skin of a glTF model.
15
+ *
16
+ * The skinning result depends on the transforms of the joints, the skinned node and their ancestors,
17
+ * and on the inverse bind matrices. If all of their scales (static values and animations) are uniform,
18
+ * or no scale is specified, Vec4x1 (the most compact format, which supports only uniform scale) is chosen.
19
+ * Otherwise Vec4x2 (which supports non-uniform scale) is chosen.
20
+ * If a non-uniform scale still appears at runtime (e.g. an animation assigned later), SkeletalComponent
21
+ * switches the automatically selected Vec4x1 to Vec4x2.
22
+ *
23
+ * Note: _setupAnimation must have been called before this function so that animation output data is available.
24
+ *
25
+ * @param gltfModel - The glTF model
26
+ * @param skin - The skin to check
27
+ * @param skinnedNodeIndex - The index of the node which has the skin
28
+ * @param inverseBindMatrices - The inverse bind matrices of the skin (column-major, 16 elements per joint)
29
+ * @returns Vec4x1 if all scales are uniform, otherwise Vec4x2
30
+ */
31
+ export declare function detectBoneDataTypeForSkin(gltfModel: RnM2, skin: RnM2Skin, skinnedNodeIndex: number, inverseBindMatrices?: ArrayLike<number>): BoneDataTypeEnum;
@@ -1,4 +1,5 @@
1
1
  export * from './AnimationAssigner';
2
+ export * from './BoneDataTypeDetector';
2
3
  export * from './DrcPointCloudImporter';
3
4
  export * from './FormatDetector';
4
5
  export * from './Gltf2Importer';
@@ -1,3 +1,4 @@
1
+ import type { TypedArray } from '../../types/CommonTypes';
1
2
  import type { IMatrix } from './IMatrix';
2
3
  /**
3
4
  * Abstract base class for matrix implementations.
@@ -9,8 +10,8 @@ import type { IMatrix } from './IMatrix';
9
10
  * @abstract
10
11
  */
11
12
  export declare abstract class AbstractMatrix implements IMatrix {
12
- /** Internal Float32Array storage for matrix elements */
13
- _v: Float32Array;
13
+ /** Internal typed array storage for matrix elements (Float32Array or Float64Array) */
14
+ _v: TypedArray;
14
15
  /**
15
16
  * Gets the matrix element at the specified row and column.
16
17
  *
@@ -1,3 +1,4 @@
1
+ import type { TypedArray } from '../../types/CommonTypes';
1
2
  import type { IQuaternion } from './IQuaternion';
2
3
  import type { IMutableVector3, IVector3 } from './IVector';
3
4
  /**
@@ -146,5 +147,5 @@ export declare abstract class AbstractQuaternion implements IQuaternion {
146
147
  * Internal typed array storage for quaternion components [x, y, z, w].
147
148
  * @protected
148
149
  */
149
- _v: Float32Array;
150
+ _v: TypedArray;
150
151
  }