@margoengine/gltf 0.1.0 → 1.0.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 (83) hide show
  1. package/LICENSE +201 -201
  2. package/NOTICE +4 -4
  3. package/README.md +1754 -1438
  4. package/dist/accessor-CU_1uSZ1.js +1 -0
  5. package/dist/asset-DN3ocEdY.js +4 -0
  6. package/dist/asset-entry.js +1 -1
  7. package/dist/asset.d.ts +76 -0
  8. package/dist/audio.js +1 -1
  9. package/dist/auto.js +1 -1
  10. package/dist/compression-CUOCmjmE.js +1 -0
  11. package/dist/compression.d.ts +6 -0
  12. package/dist/dds.js +1 -1
  13. package/dist/default-materials.d.ts +3 -1
  14. package/dist/default-transmission.d.ts +13 -0
  15. package/dist/extended.js +1 -1
  16. package/dist/group.d.ts +15 -3
  17. package/dist/index.d.ts +11 -0
  18. package/dist/index.js +1 -1
  19. package/dist/{instanced-shader-BebTnbkj.js → instanced-shader-C9ZMazvo.js} +1 -1
  20. package/dist/instancing.js +1 -1
  21. package/dist/lights.js +1 -1
  22. package/dist/material-draw-state-GKiHDb0p.js +1 -0
  23. package/dist/material-draw.js +1 -1
  24. package/dist/meshopt.js +1 -1
  25. package/dist/mipmaps-38NmjDc3.js +21 -0
  26. package/dist/model-C77ATxi1.js +25 -0
  27. package/dist/model-entry.js +1 -1
  28. package/dist/model.d.ts +84 -7
  29. package/dist/native-glass-D85twud0.js +19 -0
  30. package/dist/pack-DdxRO8k6.js +1 -0
  31. package/dist/pbr-instancing.js +1 -1
  32. package/dist/pbr.js +1 -1
  33. package/dist/physics.js +1 -1
  34. package/dist/prepare.js +1 -1
  35. package/dist/progressive-lod.d.ts +13 -0
  36. package/dist/progressive.d.ts +5 -2
  37. package/dist/progressive.js +3 -3
  38. package/dist/quantized.js +1 -1
  39. package/dist/report.js +1 -1
  40. package/dist/scene-data.js +1 -1
  41. package/dist/scene-scope-CZDEkd24.js +2 -2
  42. package/dist/scene.js +3 -3
  43. package/dist/{shader-DPqfUcmp.js → shader-C29RtPAw.js} +43 -39
  44. package/dist/shader.d.ts +24 -0
  45. package/dist/shared/caster.d.ts +159 -152
  46. package/dist/shared/gltf.d.ts +257 -257
  47. package/dist/shared/iridescence.d.ts +2 -2
  48. package/dist/shared/prepared-geometry.d.ts +8 -8
  49. package/dist/soft-mesh.d.ts +39 -1
  50. package/dist/soft-mesh.js +2 -2
  51. package/dist/spec-gloss.js +2 -2
  52. package/dist/splats.js +1 -1
  53. package/dist/src-Btvz5f6i.js +4 -0
  54. package/dist/stream-CrfNNCRd.js +1 -0
  55. package/dist/stream.d.ts +20 -3
  56. package/dist/stroke-width-B2cnYGgn.js +1 -0
  57. package/dist/stroke-width.d.ts +18 -0
  58. package/dist/strokes.d.ts +12 -0
  59. package/dist/strokes.js +1 -0
  60. package/dist/texture-stream-Cu_XpyVO.js +3 -3
  61. package/dist/textured.js +3 -3
  62. package/dist/transmission.d.ts +81 -0
  63. package/dist/transmission.js +66 -0
  64. package/dist/version-B6NE5cJf.js +1 -0
  65. package/dist/vertex-inputs.d.ts +6 -0
  66. package/dist/{unit-light-DvtsuFYP.js → warning-UqjZyyqW.js} +2 -22
  67. package/dist/warning.d.ts +24 -0
  68. package/dist/worker.d.ts +1 -1
  69. package/dist/worker.js +3 -3
  70. package/dist/workers/gltf.js +36 -36
  71. package/dist/workers/progressive.js +1 -1
  72. package/package.json +234 -213
  73. package/dist/accessor-nVsu_f1L.js +0 -1
  74. package/dist/asset-1b8ejkZX.js +0 -4
  75. package/dist/compression-D4IkO5vE.js +0 -1
  76. package/dist/errors-THVaUwlL.js +0 -1
  77. package/dist/material-draw-state-BHeTb1FP.js +0 -1
  78. package/dist/model-iRvuj19h.js +0 -39
  79. package/dist/optimize-7SEzNA23.js +0 -1
  80. package/dist/pack-BVDYuqZe.js +0 -1
  81. package/dist/src-WMRHArDp.js +0 -4
  82. package/dist/stream-C3bKMy1B.js +0 -1
  83. package/dist/version-BmU1nesQ.js +0 -1
@@ -1,257 +1,257 @@
1
- /** Structural glTF 2.0 data consumed by the optional loaders. Runtime validation stays at each use site. */
2
- export interface GLTFProperty<E extends Record<string, unknown> = GLTFExtensions> {
3
- name?: string;
4
- extras?: unknown;
5
- extensions?: E;
6
- [key: string]: unknown;
7
- }
8
-
9
- /** One entry of EXT_lights_image_based `lights`. */
10
- export interface GLTFImageBasedLight extends GLTFProperty {
11
- rotation?: number[];
12
- intensity?: number;
13
- irradianceCoefficients: number[][];
14
- specularImages: number[][];
15
- specularImageSize: number;
16
- }
17
-
18
- /** Known extension payloads retain their schema; application-specific extensions remain unknown. */
19
- export interface GLTFExtensions {
20
- [key: string]: unknown;
21
- KHR_draco_mesh_compression?: { bufferView: number; attributes: Record<string, number> };
22
- EXT_meshopt_compression?: GLTFMeshopt;
23
- KHR_meshopt_compression?: GLTFMeshopt;
24
- KHR_texture_basisu?: { source: number };
25
- MSFT_texture_dds?: { source: number };
26
- EXT_texture_webp?: { source: number };
27
- EXT_texture_avif?: { source: number };
28
- KHR_texture_transform?: GLTFTextureTransform;
29
- EXT_mesh_gpu_instancing?: GLTFInstancing;
30
- KHR_lights_punctual?: { light?: number; lights?: GLTFLightDefinition[] };
31
- // On the document: `lights`. On a node: `light`, `multiplier`, `color`.
32
- EXT_lights_ies?: {
33
- lights?: { name?: string; uri?: string; bufferView?: number; mimeType?: string }[];
34
- light?: number;
35
- multiplier?: number;
36
- color?: number[];
37
- };
38
- // On the document: `lights`. On a scene: `light`.
39
- EXT_lights_image_based?: { lights?: GLTFImageBasedLight[]; light?: number };
40
- KHR_node_visibility?: { visible?: boolean };
41
- KHR_materials_variants?: { variants?: { name: string }[]; mappings?: { material: number; variants: number[] }[] };
42
- KHR_materials_unlit?: object;
43
- KHR_materials_emissive_strength?: { emissiveStrength?: number };
44
- KHR_materials_ior?: { ior?: number };
45
- KHR_materials_dispersion?: { dispersion?: number };
46
- KHR_materials_clearcoat?: {
47
- clearcoatFactor?: number;
48
- clearcoatRoughnessFactor?: number;
49
- clearcoatTexture?: GLTFTextureInfo;
50
- clearcoatRoughnessTexture?: GLTFTextureInfo;
51
- clearcoatNormalTexture?: GLTFTextureInfo;
52
- };
53
- KHR_materials_transmission?: { transmissionFactor?: number; transmissionTexture?: GLTFTextureInfo };
54
- KHR_materials_volume?: {
55
- thicknessFactor?: number;
56
- thicknessTexture?: GLTFTextureInfo;
57
- attenuationDistance?: number;
58
- attenuationColor?: number[];
59
- };
60
- KHR_materials_sheen?: {
61
- sheenColorFactor?: number[];
62
- sheenRoughnessFactor?: number;
63
- sheenColorTexture?: GLTFTextureInfo;
64
- sheenRoughnessTexture?: GLTFTextureInfo;
65
- };
66
- KHR_materials_specular?: {
67
- specularFactor?: number;
68
- specularColorFactor?: number[];
69
- specularTexture?: GLTFTextureInfo;
70
- specularColorTexture?: GLTFTextureInfo;
71
- };
72
- KHR_materials_iridescence?: {
73
- iridescenceFactor?: number;
74
- iridescenceIor?: number;
75
- iridescenceThicknessMinimum?: number;
76
- iridescenceThicknessMaximum?: number;
77
- iridescenceTexture?: GLTFTextureInfo;
78
- iridescenceThicknessTexture?: GLTFTextureInfo;
79
- };
80
- KHR_materials_anisotropy?: {
81
- anisotropyStrength?: number;
82
- anisotropyRotation?: number;
83
- anisotropyTexture?: GLTFTextureInfo;
84
- };
85
- KHR_materials_diffuse_roughness?: {
86
- diffuseRoughnessFactor?: number;
87
- diffuseRoughnessTexture?: GLTFTextureInfo;
88
- };
89
- KHR_materials_diffuse_transmission?: {
90
- diffuseTransmissionFactor?: number;
91
- diffuseTransmissionColorFactor?: number[];
92
- diffuseTransmissionTexture?: GLTFTextureInfo;
93
- diffuseTransmissionColorTexture?: GLTFTextureInfo;
94
- };
95
- KHR_materials_volume_scatter?: {
96
- multiscatterColorFactor?: number[];
97
- multiscatterColorTexture?: GLTFTextureInfo;
98
- scatterAnisotropy?: number;
99
- };
100
- EXT_materials_bump?: {
101
- bumpFactor?: number;
102
- bumpTexture?: GLTFTextureInfo;
103
- heightSpace?: 'world' | 'object';
104
- };
105
- }
106
- export interface GLTFMeshopt {
107
- fallback?: boolean;
108
- buffer: number;
109
- byteOffset?: number;
110
- byteLength: number;
111
- byteStride: number;
112
- count: number;
113
- mode: string;
114
- filter?: string;
115
- }
116
- export interface GLTFInstancing {
117
- attributes: Record<string, number>;
118
- }
119
- export interface GLTFTextureTransform {
120
- offset?: readonly [number, number];
121
- rotation?: number;
122
- scale?: readonly [number, number];
123
- texCoord?: number;
124
- }
125
- export interface GLTFTextureInfo extends GLTFProperty {
126
- index: number;
127
- texCoord?: number;
128
- scale?: number;
129
- strength?: number;
130
- }
131
- export interface GLTFBufferExtensions {
132
- [key: string]: unknown;
133
- EXT_meshopt_compression?: { fallback?: boolean };
134
- }
135
- export interface GLTFBuffer extends GLTFProperty<GLTFBufferExtensions> {
136
- byteLength: number;
137
- uri?: string;
138
- }
139
- export interface GLTFBufferView extends GLTFProperty {
140
- buffer: number;
141
- byteLength: number;
142
- byteOffset?: number;
143
- byteStride?: number;
144
- target?: number;
145
- }
146
- export interface GLTFAccessor extends GLTFProperty {
147
- bufferView?: number;
148
- byteOffset?: number;
149
- componentType: number;
150
- count: number;
151
- type: string;
152
- normalized?: boolean;
153
- min?: number[];
154
- max?: number[];
155
- sparse?: {
156
- count: number;
157
- indices: { bufferView: number; byteOffset?: number; componentType: number };
158
- values: { bufferView: number; byteOffset?: number };
159
- };
160
- }
161
- export interface GLTFPrimitive extends GLTFProperty {
162
- /** Absent for engine-owned prepared geometry whose vertices are supplied separately. */
163
- attributes?: Record<string, number>;
164
- indices?: number;
165
- material?: number;
166
- mode?: number;
167
- targets?: Record<string, number>[];
168
- }
169
- export interface GLTFMesh extends GLTFProperty {
170
- primitives: GLTFPrimitive[];
171
- weights?: number[];
172
- }
173
- export interface GLTFNode extends GLTFProperty {
174
- mesh?: number;
175
- skin?: number;
176
- camera?: number;
177
- children?: number[];
178
- matrix?: number[];
179
- translation?: number[];
180
- rotation?: number[];
181
- scale?: number[];
182
- weights?: number[];
183
- }
184
- export interface GLTFMaterial extends GLTFProperty {
185
- pbrMetallicRoughness?: {
186
- baseColorFactor?: number[];
187
- metallicFactor?: number;
188
- roughnessFactor?: number;
189
- baseColorTexture?: GLTFTextureInfo;
190
- metallicRoughnessTexture?: GLTFTextureInfo;
191
- };
192
- normalTexture?: GLTFTextureInfo;
193
- occlusionTexture?: GLTFTextureInfo;
194
- emissiveTexture?: GLTFTextureInfo;
195
- emissiveFactor?: number[];
196
- alphaMode?: string;
197
- alphaCutoff?: number;
198
- doubleSided?: boolean;
199
- }
200
- export interface GLTFTexture extends GLTFProperty {
201
- source?: number;
202
- sampler?: number;
203
- }
204
- export interface GLTFImageDefinition extends GLTFProperty {
205
- uri?: string;
206
- mimeType?: string;
207
- bufferView?: number;
208
- }
209
- export interface GLTFSampler extends GLTFProperty {
210
- wrapS?: number;
211
- wrapT?: number;
212
- magFilter?: number;
213
- minFilter?: number;
214
- }
215
- export interface GLTFSkin extends GLTFProperty {
216
- joints: number[];
217
- inverseBindMatrices?: number;
218
- skeleton?: number;
219
- }
220
- export interface GLTFAnimation extends GLTFProperty {
221
- samplers: { input: number; output: number; interpolation?: string }[];
222
- channels: { sampler: number; target: { node?: number; path: string; extensions?: Record<string, unknown> } }[];
223
- }
224
- export interface GLTFLightDefinition extends GLTFProperty {
225
- type: 'directional' | 'point' | 'spot';
226
- color?: number[];
227
- intensity?: number;
228
- range?: number;
229
- spot?: { innerConeAngle?: number; outerConeAngle?: number };
230
- }
231
- export interface GLTFCameraDefinition extends GLTFProperty {
232
- type: 'perspective' | 'orthographic';
233
- perspective?: { yfov: number; znear: number; zfar?: number; aspectRatio?: number };
234
- orthographic?: { xmag: number; ymag: number; znear: number; zfar: number };
235
- }
236
- /**
237
- * A glTF 2.0 JSON document as the loaders read it: scenes, nodes, meshes, materials, animations and the other top-level arrays.
238
- */
239
- export interface GLTFDocument extends GLTFProperty {
240
- asset?: { version: string; generator?: string; [key: string]: unknown };
241
- buffers?: GLTFBuffer[];
242
- bufferViews?: GLTFBufferView[];
243
- accessors?: GLTFAccessor[];
244
- meshes?: GLTFMesh[];
245
- nodes?: GLTFNode[];
246
- scenes?: (GLTFProperty & { nodes?: number[] })[];
247
- scene?: number;
248
- materials?: GLTFMaterial[];
249
- textures?: GLTFTexture[];
250
- images?: GLTFImageDefinition[];
251
- samplers?: GLTFSampler[];
252
- skins?: GLTFSkin[];
253
- animations?: GLTFAnimation[];
254
- cameras?: GLTFCameraDefinition[];
255
- extensionsUsed?: string[];
256
- extensionsRequired?: string[];
257
- }
1
+ /** Structural glTF 2.0 data consumed by the optional loaders. Runtime validation stays at each use site. */
2
+ export interface GLTFProperty<E extends Record<string, unknown> = GLTFExtensions> {
3
+ name?: string;
4
+ extras?: unknown;
5
+ extensions?: E;
6
+ [key: string]: unknown;
7
+ }
8
+
9
+ /** One entry of EXT_lights_image_based `lights`. */
10
+ export interface GLTFImageBasedLight extends GLTFProperty {
11
+ rotation?: number[];
12
+ intensity?: number;
13
+ irradianceCoefficients: number[][];
14
+ specularImages: number[][];
15
+ specularImageSize: number;
16
+ }
17
+
18
+ /** Known extension payloads retain their schema; application-specific extensions remain unknown. */
19
+ export interface GLTFExtensions {
20
+ [key: string]: unknown;
21
+ KHR_draco_mesh_compression?: { bufferView: number; attributes: Record<string, number> };
22
+ EXT_meshopt_compression?: GLTFMeshopt;
23
+ KHR_meshopt_compression?: GLTFMeshopt;
24
+ KHR_texture_basisu?: { source: number };
25
+ MSFT_texture_dds?: { source: number };
26
+ EXT_texture_webp?: { source: number };
27
+ EXT_texture_avif?: { source: number };
28
+ KHR_texture_transform?: GLTFTextureTransform;
29
+ EXT_mesh_gpu_instancing?: GLTFInstancing;
30
+ KHR_lights_punctual?: { light?: number; lights?: GLTFLightDefinition[] };
31
+ // On the document: `lights`. On a node: `light`, `multiplier`, `color`.
32
+ EXT_lights_ies?: {
33
+ lights?: { name?: string; uri?: string; bufferView?: number; mimeType?: string }[];
34
+ light?: number;
35
+ multiplier?: number;
36
+ color?: number[];
37
+ };
38
+ // On the document: `lights`. On a scene: `light`.
39
+ EXT_lights_image_based?: { lights?: GLTFImageBasedLight[]; light?: number };
40
+ KHR_node_visibility?: { visible?: boolean };
41
+ KHR_materials_variants?: { variants?: { name: string }[]; mappings?: { material: number; variants: number[] }[] };
42
+ KHR_materials_unlit?: object;
43
+ KHR_materials_emissive_strength?: { emissiveStrength?: number };
44
+ KHR_materials_ior?: { ior?: number };
45
+ KHR_materials_dispersion?: { dispersion?: number };
46
+ KHR_materials_clearcoat?: {
47
+ clearcoatFactor?: number;
48
+ clearcoatRoughnessFactor?: number;
49
+ clearcoatTexture?: GLTFTextureInfo;
50
+ clearcoatRoughnessTexture?: GLTFTextureInfo;
51
+ clearcoatNormalTexture?: GLTFTextureInfo;
52
+ };
53
+ KHR_materials_transmission?: { transmissionFactor?: number; transmissionTexture?: GLTFTextureInfo };
54
+ KHR_materials_volume?: {
55
+ thicknessFactor?: number;
56
+ thicknessTexture?: GLTFTextureInfo;
57
+ attenuationDistance?: number;
58
+ attenuationColor?: number[];
59
+ };
60
+ KHR_materials_sheen?: {
61
+ sheenColorFactor?: number[];
62
+ sheenRoughnessFactor?: number;
63
+ sheenColorTexture?: GLTFTextureInfo;
64
+ sheenRoughnessTexture?: GLTFTextureInfo;
65
+ };
66
+ KHR_materials_specular?: {
67
+ specularFactor?: number;
68
+ specularColorFactor?: number[];
69
+ specularTexture?: GLTFTextureInfo;
70
+ specularColorTexture?: GLTFTextureInfo;
71
+ };
72
+ KHR_materials_iridescence?: {
73
+ iridescenceFactor?: number;
74
+ iridescenceIor?: number;
75
+ iridescenceThicknessMinimum?: number;
76
+ iridescenceThicknessMaximum?: number;
77
+ iridescenceTexture?: GLTFTextureInfo;
78
+ iridescenceThicknessTexture?: GLTFTextureInfo;
79
+ };
80
+ KHR_materials_anisotropy?: {
81
+ anisotropyStrength?: number;
82
+ anisotropyRotation?: number;
83
+ anisotropyTexture?: GLTFTextureInfo;
84
+ };
85
+ KHR_materials_diffuse_roughness?: {
86
+ diffuseRoughnessFactor?: number;
87
+ diffuseRoughnessTexture?: GLTFTextureInfo;
88
+ };
89
+ KHR_materials_diffuse_transmission?: {
90
+ diffuseTransmissionFactor?: number;
91
+ diffuseTransmissionColorFactor?: number[];
92
+ diffuseTransmissionTexture?: GLTFTextureInfo;
93
+ diffuseTransmissionColorTexture?: GLTFTextureInfo;
94
+ };
95
+ KHR_materials_volume_scatter?: {
96
+ multiscatterColorFactor?: number[];
97
+ multiscatterColorTexture?: GLTFTextureInfo;
98
+ scatterAnisotropy?: number;
99
+ };
100
+ EXT_materials_bump?: {
101
+ bumpFactor?: number;
102
+ bumpTexture?: GLTFTextureInfo;
103
+ heightSpace?: 'world' | 'object';
104
+ };
105
+ }
106
+ export interface GLTFMeshopt {
107
+ fallback?: boolean;
108
+ buffer: number;
109
+ byteOffset?: number;
110
+ byteLength: number;
111
+ byteStride: number;
112
+ count: number;
113
+ mode: string;
114
+ filter?: string;
115
+ }
116
+ export interface GLTFInstancing {
117
+ attributes: Record<string, number>;
118
+ }
119
+ export interface GLTFTextureTransform {
120
+ offset?: readonly [number, number];
121
+ rotation?: number;
122
+ scale?: readonly [number, number];
123
+ texCoord?: number;
124
+ }
125
+ export interface GLTFTextureInfo extends GLTFProperty {
126
+ index: number;
127
+ texCoord?: number;
128
+ scale?: number;
129
+ strength?: number;
130
+ }
131
+ export interface GLTFBufferExtensions {
132
+ [key: string]: unknown;
133
+ EXT_meshopt_compression?: { fallback?: boolean };
134
+ }
135
+ export interface GLTFBuffer extends GLTFProperty<GLTFBufferExtensions> {
136
+ byteLength: number;
137
+ uri?: string;
138
+ }
139
+ export interface GLTFBufferView extends GLTFProperty {
140
+ buffer: number;
141
+ byteLength: number;
142
+ byteOffset?: number;
143
+ byteStride?: number;
144
+ target?: number;
145
+ }
146
+ export interface GLTFAccessor extends GLTFProperty {
147
+ bufferView?: number;
148
+ byteOffset?: number;
149
+ componentType: number;
150
+ count: number;
151
+ type: string;
152
+ normalized?: boolean;
153
+ min?: number[];
154
+ max?: number[];
155
+ sparse?: {
156
+ count: number;
157
+ indices: { bufferView: number; byteOffset?: number; componentType: number };
158
+ values: { bufferView: number; byteOffset?: number };
159
+ };
160
+ }
161
+ export interface GLTFPrimitive extends GLTFProperty {
162
+ /** Absent for engine-owned prepared geometry whose vertices are supplied separately. */
163
+ attributes?: Record<string, number>;
164
+ indices?: number;
165
+ material?: number;
166
+ mode?: number;
167
+ targets?: Record<string, number>[];
168
+ }
169
+ export interface GLTFMesh extends GLTFProperty {
170
+ primitives: GLTFPrimitive[];
171
+ weights?: number[];
172
+ }
173
+ export interface GLTFNode extends GLTFProperty {
174
+ mesh?: number;
175
+ skin?: number;
176
+ camera?: number;
177
+ children?: number[];
178
+ matrix?: number[];
179
+ translation?: number[];
180
+ rotation?: number[];
181
+ scale?: number[];
182
+ weights?: number[];
183
+ }
184
+ export interface GLTFMaterial extends GLTFProperty {
185
+ pbrMetallicRoughness?: {
186
+ baseColorFactor?: number[];
187
+ metallicFactor?: number;
188
+ roughnessFactor?: number;
189
+ baseColorTexture?: GLTFTextureInfo;
190
+ metallicRoughnessTexture?: GLTFTextureInfo;
191
+ };
192
+ normalTexture?: GLTFTextureInfo;
193
+ occlusionTexture?: GLTFTextureInfo;
194
+ emissiveTexture?: GLTFTextureInfo;
195
+ emissiveFactor?: number[];
196
+ alphaMode?: string;
197
+ alphaCutoff?: number;
198
+ doubleSided?: boolean;
199
+ }
200
+ export interface GLTFTexture extends GLTFProperty {
201
+ source?: number;
202
+ sampler?: number;
203
+ }
204
+ export interface GLTFImageDefinition extends GLTFProperty {
205
+ uri?: string;
206
+ mimeType?: string;
207
+ bufferView?: number;
208
+ }
209
+ export interface GLTFSampler extends GLTFProperty {
210
+ wrapS?: number;
211
+ wrapT?: number;
212
+ magFilter?: number;
213
+ minFilter?: number;
214
+ }
215
+ export interface GLTFSkin extends GLTFProperty {
216
+ joints: number[];
217
+ inverseBindMatrices?: number;
218
+ skeleton?: number;
219
+ }
220
+ export interface GLTFAnimation extends GLTFProperty {
221
+ samplers: { input: number; output: number; interpolation?: string }[];
222
+ channels: { sampler: number; target: { node?: number; path: string; extensions?: Record<string, unknown> } }[];
223
+ }
224
+ export interface GLTFLightDefinition extends GLTFProperty {
225
+ type: 'directional' | 'point' | 'spot';
226
+ color?: number[];
227
+ intensity?: number;
228
+ range?: number;
229
+ spot?: { innerConeAngle?: number; outerConeAngle?: number };
230
+ }
231
+ export interface GLTFCameraDefinition extends GLTFProperty {
232
+ type: 'perspective' | 'orthographic';
233
+ perspective?: { yfov: number; znear: number; zfar?: number; aspectRatio?: number };
234
+ orthographic?: { xmag: number; ymag: number; znear: number; zfar: number };
235
+ }
236
+ /**
237
+ * A glTF 2.0 JSON document as the loaders read it: scenes, nodes, meshes, materials, animations and the other top-level arrays.
238
+ */
239
+ export interface GLTFDocument extends GLTFProperty {
240
+ asset?: { version: string; generator?: string; [key: string]: unknown };
241
+ buffers?: GLTFBuffer[];
242
+ bufferViews?: GLTFBufferView[];
243
+ accessors?: GLTFAccessor[];
244
+ meshes?: GLTFMesh[];
245
+ nodes?: GLTFNode[];
246
+ scenes?: (GLTFProperty & { nodes?: number[] })[];
247
+ scene?: number;
248
+ materials?: GLTFMaterial[];
249
+ textures?: GLTFTexture[];
250
+ images?: GLTFImageDefinition[];
251
+ samplers?: GLTFSampler[];
252
+ skins?: GLTFSkin[];
253
+ animations?: GLTFAnimation[];
254
+ cameras?: GLTFCameraDefinition[];
255
+ extensionsUsed?: string[];
256
+ extensionsRequired?: string[];
257
+ }
@@ -1,2 +1,2 @@
1
- /** Shared clean-room thin-film Fresnel WGSL from Belcour and Barla (2017), with the Khronos Gaussian sensitivity fit. */
2
- export const iridescenceWgsl: string;
1
+ /** Shared clean-room thin-film Fresnel WGSL from Belcour and Barla (2017), with the Khronos Gaussian sensitivity fit. */
2
+ export const iridescenceWgsl: string;
@@ -1,8 +1,8 @@
1
- /** Validate packed triangle geometry without loading its renderer. */
2
- export function validatePreparedGeometry(data: {
3
- vertices: Float32Array;
4
- indices: Uint32Array;
5
- interpolatedDirections?: boolean;
6
- }): void;
7
- /** Validate an already checked vertex range. */
8
- export function checkPreparedVertices(vertices: Float32Array, from: number, to: number, interpolated?: boolean): void;
1
+ /** Validate packed triangle geometry without loading its renderer. */
2
+ export function validatePreparedGeometry(data: {
3
+ vertices: Float32Array;
4
+ indices: Uint32Array;
5
+ interpolatedDirections?: boolean;
6
+ }): void;
7
+ /** Validate an already checked vertex range. */
8
+ export function checkPreparedVertices(vertices: Float32Array, from: number, to: number, interpolated?: boolean): void;
@@ -2,6 +2,8 @@
2
2
  import type { EngineKernel } from '@margoengine/core';
3
3
  import type { Engine, EnginePlugin } from '@margoengine/core/extension';
4
4
  // @ts-ignore optional peer: its types apply when it is installed
5
+ import type { GPUCloth } from '@margoengine/physics/gpu-cloth';
6
+ // @ts-ignore optional peer: its types apply when it is installed
5
7
  import type { SoftBody } from '@margoengine/physics/soft';
6
8
  import { type GLTFDocument, type GLTFImage } from './asset.js';
7
9
  import { PBRModel } from './model.js';
@@ -10,7 +12,8 @@ export type SoftMeshMaterial = NonNullable<GLTFDocument['materials']>[number];
10
12
  /** Options for {@link SoftSurface}. */
11
13
  export interface SoftSurfaceOptions {
12
14
  /**
13
- * Texture coordinates, two a particle (two a skin vertex for a skinned body). Default: the grid of a body built by
15
+ * Texture coordinates, two a particle (two a skin vertex for a skinned body, two a vertex of the source mesh for a body
16
+ * made by `SoftBodyDesc.volume`). Default: a `volume` body's own (its mesh's `uvs` or `TEXCOORD_0`), the grid of a body built by
14
17
  * `cloth`, `clothAnisotropic` or `clothTube` (particle (i, j) at (i / (nu - 1), j / (nv - 1)), a tube's seam doubled so
15
18
  * u runs 0 to 1 around it), else the body's shape where the surface is made, laid flat on the plane of its two largest
16
19
  * extents and scaled to 0..1.
@@ -35,6 +38,8 @@ export declare class SoftSurface {
35
38
  /** Pairs of vertices that are one particle (a tube's first ring and its seam copy). */
36
39
  private readonly twins;
37
40
  private readonly skinned;
41
+ /** For a body made by `SoftBodyDesc.volume`, each particle's normal: the copies of a welded vertex share it. */
42
+ private readonly particleNormals;
38
43
  private readonly scratch;
39
44
  private readonly normal;
40
45
  private readonly tangent;
@@ -92,3 +97,36 @@ export declare class SoftBodyMesh implements EnginePlugin {
92
97
  * frame with recomputed normals and tangents and grid texture coordinates; `mesh.dispose()` (or `using`) removes it.
93
98
  */
94
99
  export declare function drawSoftBody(engine: EngineKernel, body: SoftBody, options?: SoftBodyMeshOptions): SoftBodyMesh;
100
+ /** Options for {@link drawGPUCloth}: the material and images, as {@link drawSoftBody} takes them. */
101
+ export type GPUClothMeshOptions = Pick<SoftBodyMeshOptions, 'material' | 'images'>;
102
+ /**
103
+ * A `GPUCloth` of `@margoengine/physics/gpu-cloth` drawn as a PBR mesh. On WebGPU the model draws the vertex buffer the
104
+ * cloth's compute writes (as a skin's output is drawn): no readback, no upload. On the WebGL2 compatibility layer the cloth
105
+ * steps on the CPU and the mesh uploads its vertices when they change.
106
+ */
107
+ export declare class GPUClothMesh implements EnginePlugin {
108
+ readonly cloth: GPUCloth;
109
+ readonly name: string;
110
+ /** After the cloth (a late plugin), so a CPU step of this frame is the one uploaded. */
111
+ readonly late = true;
112
+ /** The model it draws with: `model.setVisible`, picking and the PBR model API work on it. */
113
+ readonly model: PBRModel;
114
+ private engine?;
115
+ private disposed;
116
+ private seen;
117
+ private held;
118
+ private spare;
119
+ constructor(engine: EngineKernel, cloth: GPUCloth, _arg2?: GPUClothMeshOptions);
120
+ setup(engine: Engine): void;
121
+ onPreUpdate(): void;
122
+ /** Points the model at the cloth's GPU vertices, or uploads its CPU vertices when they changed (the frame does this). */
123
+ sync(): this;
124
+ /** Removes the mesh from the engine and frees its buffers. The cloth is not touched. */
125
+ dispose(): void;
126
+ [Symbol.dispose]: () => void;
127
+ }
128
+ /**
129
+ * Draws a GPU cloth with one call: `const mesh = drawGPUCloth(engine, cloth, {material})`. Attach it after the cloth;
130
+ * `mesh.dispose()` (or `using`) removes it.
131
+ */
132
+ export declare function drawGPUCloth(engine: EngineKernel, cloth: GPUCloth, options?: GPUClothMeshOptions): GPUClothMesh;
package/dist/soft-mesh.js CHANGED
@@ -1,4 +1,4 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
3
 
4
- import{n as e}from"./model-iRvuj19h.js";import{t}from"./asset-1b8ejkZX.js";import{MargoError as n}from"@margoengine/math/errors";var r=20,i=0,a=class{constructor(e,{uvs:t}={}){if(this.body=e,!e.valid)throw new n(`state`,`Soft body was removed; draw a body that is still in its world.`);this.skinned=e.meshIndices().length>0;let i=this.skinned?e.meshIndices():e.triangles();if(i.length===0)throw TypeError(`This soft body has no triangles to draw (a rope or a bare particle set); draw a rope with @margoengine/lines, or build the body with cloth, trimesh, sphere or setSkin.`);let a=this.skinned?e.meshVertices().length/3:e.numParticles(),s=this.skinned||t?null:e.grid,c,l,u;if(s?.wrap){let{nu:e,nv:t}=s;c=new Uint32Array((e+1)*t),u=new Float32Array(c.length*2);for(let n=0;n<=e;n++)for(let r=0;r<t;r++)c[n*t+r]=n%e*t+r,u[(n*t+r)*2]=n/e,u[(n*t+r)*2+1]=r/(t-1);l=new Uint32Array(i.length);for(let n=0;n<i.length;n+=3){let r=[0,1,2].map(e=>Math.floor(i[n+e]/t)),a=r.includes(e-1)&&r.includes(0);for(let o=0;o<3;o++)l[n+o]=a&&r[o]===0?e*t+i[n+o]%t:i[n+o]}}else if(c=this.skinned?/* @__PURE__ */ new Uint32Array:Uint32Array.from({length:a},(e,t)=>t),l=i,t){if(t.length!==a*2)throw RangeError(`Soft surface uvs need two numbers a vertex: ${a*2}, not ${t.length}.`);if(u=Float32Array.from(t),!u.every(Number.isFinite))throw RangeError(`Soft surface uvs must be finite numbers.`)}else if(s){u=new Float32Array(a*2);for(let e=0;e<s.nu;e++)for(let t=0;t<s.nv;t++)u[(e*s.nv+t)*2]=e/(s.nu-1),u[(e*s.nv+t)*2+1]=t/(s.nv-1)}else u=o(this.skinned?e.meshVertices():e.particlePositions());this.source=c;let d=[];if(s?.wrap)for(let e=0;e<s.nv;e++)d.push(e,s.nu*s.nv+e);this.twins=Uint32Array.from(d),this.indices=l,this.uvs=u;let f=this.vertices=new Float32Array(u.length/2*r);for(let e=0;e<u.length/2;e++){let t=e*r;f[t+3]=1,f[t+12]=f[t+14]=u[e*2],f[t+13]=f[t+15]=u[e*2+1],f[t+16]=f[t+17]=f[t+18]=f[t+19]=1}this.scratch=new Float32Array(a*3),this.normal=new Float32Array(u.length/2*3),this.tangent=new Float32Array(this.normal.length),this.bitangent=new Float32Array(this.normal.length),this.update()}get vertexCount(){return this.uvs.length/2}update(){if(!this.body.valid)throw new n(`state`,`Soft body was removed; draw the bodies that replaced it with drawSoftBody.`);let e=this.skinned?this.body.meshVertices():this.body.particlePositions(this.scratch),t=this.vertices,i=this.normal,a=this.tangent,o=this.bitangent,s=this.uvs,c=this.indices,l=this.vertexCount;for(let n=0;n<l;n++){let i=(this.skinned?n:this.source[n])*3,a=n*r;t[a]=e[i],t[a+1]=e[i+1],t[a+2]=e[i+2]}i.fill(0),a.fill(0),o.fill(0);for(let e=0;e<c.length;e+=3){let n=c[e],l=c[e+1],u=c[e+2],d=n*r,f=t[l*r]-t[d],p=t[l*r+1]-t[d+1],m=t[l*r+2]-t[d+2],h=t[u*r]-t[d],g=t[u*r+1]-t[d+1],_=t[u*r+2]-t[d+2],v=p*_-m*g,y=m*h-f*_,b=f*g-p*h,x=s[l*2]-s[n*2],S=s[l*2+1]-s[n*2+1],C=s[u*2]-s[n*2],w=s[u*2+1]-s[n*2+1],T=x*w-C*S,E=T===0?0:1/T,D=(f*w-h*S)*E,O=(p*w-g*S)*E,k=(m*w-_*S)*E,A=(h*x-f*C)*E,j=(g*x-p*C)*E,M=(_*x-m*C)*E;for(let e of[n,l,u])i[e*3]=i[e*3]+v,i[e*3+1]=i[e*3+1]+y,i[e*3+2]=i[e*3+2]+b,a[e*3]=a[e*3]+D,a[e*3+1]=a[e*3+1]+O,a[e*3+2]=a[e*3+2]+k,o[e*3]=o[e*3]+A,o[e*3+1]=o[e*3+1]+j,o[e*3+2]=o[e*3+2]+M}for(let e=0;e<this.twins.length;e+=2){let t=this.twins[e]*3,n=this.twins[e+1]*3;for(let e of[i,a,o])for(let r=0;r<3;r++)e[t+r]=e[n+r]=e[t+r]+e[n+r]}for(let e=0;e<l;e++){let n=e*r,s=i[e*3],c=i[e*3+1],l=i[e*3+2],u=Math.hypot(s,c,l);u>0?(s/=u,c/=u,l/=u):(s=t[n+4],c=t[n+5],l=t[n+6]||+(s===0&&c===0)),t[n+4]=s,t[n+5]=c,t[n+6]=l;let d=a[e*3],f=a[e*3+1],p=a[e*3+2],m=d*s+f*c+p*l;d-=s*m,f-=c*m,p-=l*m;let h=Math.hypot(d,f,p);h>1e-12||([d,f,p]=Math.abs(s)<.9?[0,-l,c]:[l,0,-s],h=Math.hypot(d,f,p)),t[n+8]=d/h,t[n+9]=f/h,t[n+10]=p/h;let g=c*p-l*f,_=l*d-s*p,v=s*f-c*d;t[n+11]=g*o[e*3]+_*o[e*3+1]+v*o[e*3+2]<0?-1:1}return this}};function o(e){let t=[1/0,1/0,1/0],n=[-1/0,-1/0,-1/0];for(let r=0;r<e.length;r++)t[r%3]=Math.min(t[r%3],e[r]),n[r%3]=Math.max(n[r%3],e[r]);let r=[0,1,2].map(e=>n[e]-t[e]),[i,a]=[0,1,2].sort((e,t)=>r[t]-r[e]||e-t),o=new Float32Array(e.length/3*2);for(let n=0;n<e.length/3;n++)o[n*2]=r[i]>0?(e[n*3+i]-t[i])/r[i]:0,o[n*2+1]=r[a]>0?(e[n*3+a]-t[a])/r[a]:0;return o}var s=class{coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);constructor(n,r,{material:o,images:s=[],...c}={}){this.name=`soft-mesh:`+i++,this.late=!0,this.disposed=!1,this.surface=new a(r,c),this.held=this.surface.vertices.slice(),this.spare=this.surface.vertices.slice();let l=s.map((e,t)=>({source:t}));this.model=new e(n,new t({asset:{version:`2.0`},materials:[{doubleSided:!0,pbrMetallicRoughness:{metallicFactor:0,roughnessFactor:.8},...o}],...l.length?{textures:l,images:s.map(()=>({}))}:{},meshes:[{primitives:[{attributes:{POSITION:0},material:0}]}],nodes:[{mesh:0}]},[]),s,[[{vertices:this.held,indices:this.surface.indices}]]),n.use(this.model);try{n.use(this)}catch(e){throw this.model.dispose(),e}}setup(e){this.engine=e}onPreUpdate(){let e=this.surface.body;this.disposed||!e.valid||e.sleeping||this.sync()}sync(){if(this.disposed)throw new n(`disposed`,`SoftBodyMesh is disposed; draw the body again with drawSoftBody.`);this.surface.update();let e=this.spare;return e.set(this.surface.vertices),this.model.writeGeometry([{vertices:e,indices:this.surface.indices}],{start:0,count:this.surface.vertexCount}),this.spare=this.held,this.held=e,this}dispose(){this.disposed||(this.disposed=!0,this.engine?.sceneOf(this)?.removePlugin(this.name),this.model.dispose())}[Symbol.dispose??Symbol()](){this.dispose()}};function c(e,t,n){return new s(e,t,n)}export{s as SoftBodyMesh,a as SoftSurface,c as drawSoftBody};
4
+ import{n as e}from"./model-C77ATxi1.js";import{t}from"./asset-DN3ocEdY.js";import{MargoError as n}from"@margoengine/math/errors";var r=20,i=0,a=class{constructor(e,{uvs:t}={}){if(this.body=e,!e.valid)throw new n(`state`,`Soft body was removed; draw a body that is still in its world.`);this.skinned=e.meshIndices().length>0;let i=this.skinned?e.meshIndices():e.triangles();if(i.length===0)throw TypeError(`This soft body has no triangles to draw (a rope or a bare particle set); draw a rope with @margoengine/lines, or build the body with cloth, trimesh, sphere or setSkin.`);let a=this.skinned?null:e.sourceMesh,s=t??e.sourceMesh?.uvs??void 0,c=this.skinned?e.meshVertices().length/3:a?a.particles.length:e.numParticles(),l=this.skinned||s||a?null:e.grid,u,d,f;if(l?.wrap){let{nu:e,nv:t}=l;u=new Uint32Array((e+1)*t),f=new Float32Array(u.length*2);for(let n=0;n<=e;n++)for(let r=0;r<t;r++)u[n*t+r]=n%e*t+r,f[(n*t+r)*2]=n/e,f[(n*t+r)*2+1]=r/(t-1);d=new Uint32Array(i.length);for(let n=0;n<i.length;n+=3){let r=[0,1,2].map(e=>Math.floor(i[n+e]/t)),a=r.includes(e-1)&&r.includes(0);for(let o=0;o<3;o++)d[n+o]=a&&r[o]===0?e*t+i[n+o]%t:i[n+o]}}else if(u=this.skinned?/* @__PURE__ */ new Uint32Array:a?a.particles.slice():Uint32Array.from({length:c},(e,t)=>t),d=a?a.indices.slice():i,s){if(s.length!==c*2)throw RangeError(`Soft surface uvs need two numbers a vertex: ${c*2}, not ${s.length}.`);if(f=Float32Array.from(s),!f.every(Number.isFinite))throw RangeError(`Soft surface uvs must be finite numbers.`)}else if(l){f=new Float32Array(c*2);for(let e=0;e<l.nu;e++)for(let t=0;t<l.nv;t++)f[(e*l.nv+t)*2]=e/(l.nu-1),f[(e*l.nv+t)*2+1]=t/(l.nv-1)}else{let t=this.skinned?e.meshVertices():e.particlePositions();f=o(a?Float32Array.from({length:c*3},(e,n)=>t[u[n/3|0]*3+n%3]):t)}this.source=u,this.particleNormals=a?new Float32Array(e.numParticles()*3):null;let p=[];if(l?.wrap)for(let e=0;e<l.nv;e++)p.push(e,l.nu*l.nv+e);this.twins=Uint32Array.from(p),this.indices=d,this.uvs=f;let m=this.vertices=new Float32Array(f.length/2*r);for(let e=0;e<f.length/2;e++){let t=e*r;m[t+3]=1,m[t+12]=m[t+14]=f[e*2],m[t+13]=m[t+15]=f[e*2+1],m[t+16]=m[t+17]=m[t+18]=m[t+19]=1}this.scratch=new Float32Array((this.skinned?c:e.numParticles())*3),this.normal=new Float32Array(f.length/2*3),this.tangent=new Float32Array(this.normal.length),this.bitangent=new Float32Array(this.normal.length),this.update()}get vertexCount(){return this.uvs.length/2}update(){if(!this.body.valid)throw new n(`state`,`Soft body was removed; draw the bodies that replaced it with drawSoftBody.`);let e=this.skinned?this.body.meshVertices():this.body.particlePositions(this.scratch),t=this.vertices,i=this.normal,a=this.tangent,o=this.bitangent,s=this.uvs,c=this.indices,l=this.vertexCount;for(let n=0;n<l;n++){let i=(this.skinned?n:this.source[n])*3,a=n*r;t[a]=e[i],t[a+1]=e[i+1],t[a+2]=e[i+2]}i.fill(0),a.fill(0),o.fill(0);for(let e=0;e<c.length;e+=3){let n=c[e],l=c[e+1],u=c[e+2],d=n*r,f=t[l*r]-t[d],p=t[l*r+1]-t[d+1],m=t[l*r+2]-t[d+2],h=t[u*r]-t[d],g=t[u*r+1]-t[d+1],_=t[u*r+2]-t[d+2],v=p*_-m*g,y=m*h-f*_,b=f*g-p*h,x=s[l*2]-s[n*2],S=s[l*2+1]-s[n*2+1],C=s[u*2]-s[n*2],w=s[u*2+1]-s[n*2+1],T=x*w-C*S,E=T===0?0:1/T,D=(f*w-h*S)*E,O=(p*w-g*S)*E,k=(m*w-_*S)*E,A=(h*x-f*C)*E,j=(g*x-p*C)*E,M=(_*x-m*C)*E;for(let e of[n,l,u])i[e*3]=i[e*3]+v,i[e*3+1]=i[e*3+1]+y,i[e*3+2]=i[e*3+2]+b,a[e*3]=a[e*3]+D,a[e*3+1]=a[e*3+1]+O,a[e*3+2]=a[e*3+2]+k,o[e*3]=o[e*3]+A,o[e*3+1]=o[e*3+1]+j,o[e*3+2]=o[e*3+2]+M}for(let e=0;e<this.twins.length;e+=2){let t=this.twins[e]*3,n=this.twins[e+1]*3;for(let e of[i,a,o])for(let r=0;r<3;r++)e[t+r]=e[n+r]=e[t+r]+e[n+r]}let u=this.particleNormals;if(u){u.fill(0);for(let e=0;e<l;e++)for(let t=0;t<3;t++)u[this.source[e]*3+t]=u[this.source[e]*3+t]+i[e*3+t];for(let e=0;e<l;e++)for(let t=0;t<3;t++)i[e*3+t]=u[this.source[e]*3+t]}for(let e=0;e<l;e++){let n=e*r,s=i[e*3],c=i[e*3+1],l=i[e*3+2],u=Math.hypot(s,c,l);u>0?(s/=u,c/=u,l/=u):(s=t[n+4],c=t[n+5],l=t[n+6]||+(s===0&&c===0)),t[n+4]=s,t[n+5]=c,t[n+6]=l;let d=a[e*3],f=a[e*3+1],p=a[e*3+2],m=d*s+f*c+p*l;d-=s*m,f-=c*m,p-=l*m;let h=Math.hypot(d,f,p);h>1e-12||([d,f,p]=Math.abs(s)<.9?[0,-l,c]:[l,0,-s],h=Math.hypot(d,f,p)),t[n+8]=d/h,t[n+9]=f/h,t[n+10]=p/h;let g=c*p-l*f,_=l*d-s*p,v=s*f-c*d;t[n+11]=g*o[e*3]+_*o[e*3+1]+v*o[e*3+2]<0?-1:1}return this}};function o(e){let t=[1/0,1/0,1/0],n=[-1/0,-1/0,-1/0];for(let r=0;r<e.length;r++)t[r%3]=Math.min(t[r%3],e[r]),n[r%3]=Math.max(n[r%3],e[r]);let r=[0,1,2].map(e=>n[e]-t[e]),[i,a]=[0,1,2].sort((e,t)=>r[t]-r[e]||e-t),o=new Float32Array(e.length/3*2);for(let n=0;n<e.length/3;n++)o[n*2]=r[i]>0?(e[n*3+i]-t[i])/r[i]:0,o[n*2+1]=r[a]>0?(e[n*3+a]-t[a])/r[a]:0;return o}var s=class{coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);constructor(e,t,{material:n,images:r=[],...o}={}){this.name=`soft-mesh:`+i++,this.late=!0,this.disposed=!1,this.surface=new a(t,o),this.held=this.surface.vertices.slice(),this.spare=this.surface.vertices.slice(),this.model=l(e,this.held,this.surface.indices,n,r),e.use(this.model);try{e.use(this)}catch(e){throw this.model.dispose(),e}}setup(e){this.engine=e}onPreUpdate(){let e=this.surface.body;this.disposed||!e.valid||e.sleeping||this.sync()}sync(){if(this.disposed)throw new n(`disposed`,`SoftBodyMesh is disposed; draw the body again with drawSoftBody.`);this.surface.update();let e=this.spare;return e.set(this.surface.vertices),this.model.writeGeometry([{vertices:e,indices:this.surface.indices}],{start:0,count:this.surface.vertexCount}),this.spare=this.held,this.held=e,this}dispose(){this.disposed||(this.disposed=!0,this.engine?.sceneOf(this)?.removePlugin(this.name),this.model.dispose())}[Symbol.dispose??Symbol()](){this.dispose()}};function c(e,t,n){return new s(e,t,n)}function l(n,r,i,a,o){let s=o.map((e,t)=>({source:t}));return new e(n,new t({asset:{version:`2.0`},materials:[{doubleSided:!0,pbrMetallicRoughness:{metallicFactor:0,roughnessFactor:.8},...a}],...s.length?{textures:s,images:o.map(()=>({}))}:{},meshes:[{primitives:[{attributes:{POSITION:0},material:0}]}],nodes:[{mesh:0}]},[]),o,[[{vertices:r,indices:i}]])}var u=class{coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);constructor(e,t,{material:r,images:a=[]}={}){if(this.cloth=t,this.name=`gpu-cloth-mesh:`+i++,this.late=!0,this.disposed=!1,this.seen=-1,!(t?.vertices instanceof Float32Array)||!(t.indices instanceof Uint32Array))throw new n(`unsupported`,`drawGPUCloth takes a GPUCloth of @margoengine/physics/gpu-cloth; pass the cloth that entry creates.`);this.held=t.vertices.slice(),this.spare=t.vertices.slice(),this.model=l(e,this.held,t.indices,r,a),e.use(this.model);try{e.use(this)}catch(e){throw this.model.dispose(),e}}setup(e){this.engine=e}onPreUpdate(){this.disposed||this.sync()}sync(){if(this.disposed)throw new n(`disposed`,`GPUClothMesh is disposed; draw the cloth again with drawGPUCloth.`);let e=this.cloth.vertexBuffer;if(e){for(let t of this.model.primitives)t.deformed!==e&&(t.deformed=e,t.deformedOffset=0);return this}for(let e of this.model.primitives)e.deformed=void 0;if(this.cloth.revision===this.seen)return this;this.seen=this.cloth.revision;let t=this.spare;return t.set(this.cloth.vertices),this.model.writeGeometry([{vertices:t,indices:this.cloth.indices}],{start:0,count:this.cloth.count}),this.spare=this.held,this.held=t,this}dispose(){if(!this.disposed){this.disposed=!0;for(let e of this.model.primitives)e.deformed=void 0;this.engine?.sceneOf(this)?.removePlugin(this.name),this.model.dispose()}}[Symbol.dispose??Symbol()](){this.dispose()}};function d(e,t,n){return new u(e,t,n)}export{u as GPUClothMesh,s as SoftBodyMesh,a as SoftSurface,d as drawGPUCloth,c as drawSoftBody};