@luma.gl/engine 10.0.0-alpha.15 → 10.0.0-alpha.17

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 (34) hide show
  1. package/dist/dist.dev.js +0 -37
  2. package/dist/dist.min.js +58 -58
  3. package/dist/gltf/gltf/create-gltf-model.cjs +3 -0
  4. package/dist/gltf/gltf/create-gltf-model.d.ts.map +1 -1
  5. package/dist/gltf/gltf/create-gltf-model.js +4 -0
  6. package/dist/gltf/gltf/create-gltf-model.js.map +1 -1
  7. package/dist/gltf/index.cjs.map +3 -3
  8. package/dist/gltf/parsers/parse-gltf.d.ts +6 -2
  9. package/dist/gltf/parsers/parse-gltf.d.ts.map +1 -1
  10. package/dist/gltf/parsers/parse-gltf.js.map +1 -1
  11. package/dist/gltf/parsers/parse-pbr-material.cjs +13 -3
  12. package/dist/gltf/parsers/parse-pbr-material.d.ts +7 -2
  13. package/dist/gltf/parsers/parse-pbr-material.d.ts.map +1 -1
  14. package/dist/gltf/parsers/parse-pbr-material.js +17 -5
  15. package/dist/gltf/parsers/parse-pbr-material.js.map +1 -1
  16. package/dist/gltf/pbr/pbr-material.d.ts +3 -3
  17. package/dist/gltf/pbr/pbr-material.d.ts.map +1 -1
  18. package/dist/graph/physics/index.cjs.map +2 -2
  19. package/dist/graph/physics/physics-controller.cjs +42 -0
  20. package/dist/graph/physics/physics-controller.d.ts +12 -1
  21. package/dist/graph/physics/physics-controller.d.ts.map +1 -1
  22. package/dist/graph/physics/physics-controller.js +41 -0
  23. package/dist/graph/physics/physics-controller.js.map +1 -1
  24. package/dist/graph/physics/scenegraph-instance.cjs +7 -0
  25. package/dist/graph/physics/scenegraph-instance.d.ts.map +1 -1
  26. package/dist/graph/physics/scenegraph-instance.js +8 -0
  27. package/dist/graph/physics/scenegraph-instance.js.map +1 -1
  28. package/package.json +8 -8
  29. package/src/gltf/gltf/create-gltf-model.ts +4 -0
  30. package/src/gltf/parsers/parse-gltf.ts +6 -2
  31. package/src/gltf/parsers/parse-pbr-material.ts +35 -7
  32. package/src/gltf/pbr/pbr-material.ts +8 -3
  33. package/src/graph/physics/physics-controller.ts +55 -1
  34. package/src/graph/physics/scenegraph-instance.ts +10 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/engine",
3
- "version": "10.0.0-alpha.15",
3
+ "version": "10.0.0-alpha.17",
4
4
  "description": "3D Engine Components for luma.gl",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -128,20 +128,20 @@
128
128
  "prepublishOnly": "npm run build-minified-bundle && npm run build-dev-bundle"
129
129
  },
130
130
  "peerDependencies": {
131
- "@luma.gl/core": "~10.0.0-alpha.15",
132
- "@luma.gl/shaders": "~10.0.0-alpha.15",
131
+ "@luma.gl/core": "~10.0.0-alpha.17",
132
+ "@luma.gl/shaders": "~10.0.0-alpha.17",
133
133
  "apache-arrow": ">=17.0.0"
134
134
  },
135
135
  "dependencies": {
136
- "@luma.gl/graph": "10.0.0-alpha.15",
136
+ "@luma.gl/graph": "10.0.0-alpha.17",
137
137
  "@mapbox/tiny-sdf": "^2.0.7",
138
- "@math.gl/core": "~5.0.0-beta.10",
139
- "@math.gl/geometry": "~5.0.0-beta.10",
138
+ "@math.gl/core": "~5.0.0-beta.12",
139
+ "@math.gl/geometry": "~5.0.0-beta.12",
140
140
  "probe.gl": "^5.0.0"
141
141
  },
142
- "gitHead": "2a5a732d5fab9f90c6d3646f956e1304a6a22c2e",
142
+ "gitHead": "58016847269503d3dc169d9e43eb132b522c421a",
143
143
  "devDependencies": {
144
- "@luma.gl/anari": "10.0.0-alpha.15"
144
+ "@luma.gl/anari": "10.0.0-alpha.17"
145
145
  },
146
146
  "peerDependenciesMeta": {
147
147
  "apache-arrow": {
@@ -549,6 +549,10 @@ export function createGLTFMaterial(device: Device, options: CreateGLTFMaterialOp
549
549
 
550
550
  const pbrMaterialProps = {...options.parsedPPBRMaterial.uniforms};
551
551
  delete pbrMaterialProps.camera;
552
+ // Environment controls belong to the scene uniforms of each model, not to the material.
553
+ delete pbrMaterialProps.environmentIntensity;
554
+ delete pbrMaterialProps.environmentRotation;
555
+ delete pbrMaterialProps.environmentMipCount;
552
556
  const materialBindings = Object.fromEntries(
553
557
  Object.entries({
554
558
  ...pbrMaterialProps,
@@ -32,6 +32,7 @@ import {
32
32
  } from '../gltf/gltf-lightmap';
33
33
  import type {PrimitiveMaterialVariants} from '@luma.gl/engine';
34
34
  import {type GLTFMorphTargetState, setGLTFMorphWeights} from '../gltf/morph-targets';
35
+ import {type PBRLightingEnvironment} from '../../lighting/pbr-environment';
35
36
  import {type PBREnvironment} from '../pbr/pbr-environment';
36
37
  import {resolveTextureCoordinateSet} from '../pbr/texture-transform';
37
38
  import {
@@ -51,8 +52,11 @@ export type ParseGLTFOptions = {
51
52
  modelOptions?: Partial<ModelProps>;
52
53
  /** Enables shader-level PBR debug output. */
53
54
  pbrDebug?: boolean;
54
- /** Optional image-based lighting environment. */
55
- imageBasedLightingEnvironment?: PBREnvironment;
55
+ /**
56
+ * Optional image-based lighting environment: a loaded `PBREnvironment`, or a
57
+ * `PBRLightingEnvironment` such as the textures of `createPrefilteredEnvironment`.
58
+ */
59
+ imageBasedLightingEnvironment?: PBREnvironment | PBRLightingEnvironment;
56
60
  /** Enables punctual light extraction. */
57
61
  lights?: boolean;
58
62
  /** Enables tangent usage when available. */
@@ -19,6 +19,11 @@ import {Matrix3} from '@math.gl/core';
19
19
  import type {Device, ExternalImage, SamplerProps, TextureFormat} from '@luma.gl/core';
20
20
  import {assert, log, Texture, textureFormatDecoder} from '@luma.gl/core';
21
21
  import {type PBRMaterialBindings} from '@luma.gl/shaders';
22
+ import {
23
+ getPBREnvironmentBindings,
24
+ getPBREnvironmentUniforms,
25
+ type PBRLightingEnvironment
26
+ } from '../../lighting/pbr-environment';
22
27
  import {type PBREnvironment} from '../pbr/pbr-environment';
23
28
  import {type ParsedPBRMaterial} from '../pbr/pbr-material';
24
29
  import {
@@ -238,8 +243,12 @@ export type ParsePBRMaterialOptions = {
238
243
  lights?: any;
239
244
  /** Use tangents */
240
245
  useTangents?: boolean;
241
- /** provide an image based (texture cube) lighting environment */
242
- imageBasedLightingEnvironment?: PBREnvironment;
246
+ /**
247
+ * Image-based lighting environment. A `PBREnvironment` keeps the legacy sRGB decode and
248
+ * fixed mip range. A `PBRLightingEnvironment` is sampled as linear light and also supplies
249
+ * the `pbrScene` environment intensity, rotation and mip count.
250
+ */
251
+ imageBasedLightingEnvironment?: PBREnvironment | PBRLightingEnvironment;
243
252
  /** parent post-processed glTF, used to resolve extension texture infos */
244
253
  gltf?: GLTFPostprocessed;
245
254
  /** run primitive-attribute diagnostics such as missing TEXCOORD_0 / NORMAL */
@@ -250,6 +259,13 @@ export type ParsePBRMaterialOptions = {
250
259
  validateLightmapAttributes?: boolean;
251
260
  };
252
261
 
262
+ /** Distinguishes borrowed linear-light textures from the legacy dynamic-texture environment. */
263
+ function isPBRLightingEnvironment(
264
+ environment: PBREnvironment | PBRLightingEnvironment
265
+ ): environment is PBRLightingEnvironment {
266
+ return 'specularTexture' in environment;
267
+ }
268
+
253
269
  /**
254
270
  * Parses a GLTF material definition into uniforms and parameters for the PBR shader module
255
271
  */
@@ -281,11 +297,23 @@ export function parsePBRMaterial(
281
297
 
282
298
  const {imageBasedLightingEnvironment} = options;
283
299
  if (imageBasedLightingEnvironment) {
284
- parsedMaterial.bindings.pbr_diffuseEnvSampler =
285
- imageBasedLightingEnvironment.diffuseEnvSampler.texture;
286
- parsedMaterial.bindings.pbr_specularEnvSampler =
287
- imageBasedLightingEnvironment.specularEnvSampler.texture;
288
- parsedMaterial.bindings.pbr_brdfLUT = imageBasedLightingEnvironment.brdfLutTexture.texture;
300
+ if (isPBRLightingEnvironment(imageBasedLightingEnvironment)) {
301
+ Object.assign(
302
+ parsedMaterial.bindings,
303
+ getPBREnvironmentBindings(imageBasedLightingEnvironment)
304
+ );
305
+ Object.assign(
306
+ parsedMaterial.uniforms,
307
+ getPBREnvironmentUniforms(imageBasedLightingEnvironment)
308
+ );
309
+ parsedMaterial.defines['USE_SCENE_ENVIRONMENT'] = true;
310
+ } else {
311
+ parsedMaterial.bindings.pbr_diffuseEnvSampler =
312
+ imageBasedLightingEnvironment.diffuseEnvSampler.texture;
313
+ parsedMaterial.bindings.pbr_specularEnvSampler =
314
+ imageBasedLightingEnvironment.specularEnvSampler.texture;
315
+ parsedMaterial.bindings.pbr_brdfLUT = imageBasedLightingEnvironment.brdfLutTexture.texture;
316
+ }
289
317
  parsedMaterial.uniforms.IBLenabled = true;
290
318
  parsedMaterial.uniforms.scaleIBLAmbient = [1, 1];
291
319
  }
@@ -7,10 +7,15 @@ import {
7
7
  IBLBindings,
8
8
  PBRMaterialBindings,
9
9
  PBRMaterialUniforms,
10
- PBRProjectionProps
10
+ PBRProjectionProps,
11
+ PBRSceneUniforms
11
12
  } from '@luma.gl/shaders';
12
13
 
13
- type ParsedPBRMaterialUniforms = Partial<PBRProjectionProps & PBRMaterialUniforms> & {
14
+ type ParsedPBRMaterialUniforms = Partial<
15
+ PBRProjectionProps &
16
+ PBRMaterialUniforms &
17
+ Pick<PBRSceneUniforms, 'environmentIntensity' | 'environmentRotation' | 'environmentMipCount'>
18
+ > & {
14
19
  clearcoatRoughnessMapEnabled?: boolean;
15
20
  sheenRoughnessMapEnabled?: boolean;
16
21
  };
@@ -21,7 +26,7 @@ export type ParsedPBRMaterial = {
21
26
  readonly defines: Record<string, boolean>;
22
27
  /** Texture and sampler bindings for the PBR shader module. */
23
28
  readonly bindings: Partial<PBRMaterialBindings<Texture> & IBLBindings<Texture>>;
24
- /** Uniform values for the projection and PBR shader modules. */
29
+ /** Uniform values for the projection, PBR material and PBR scene shader modules. */
25
30
  readonly uniforms: ParsedPBRMaterialUniforms;
26
31
  /** Render pipeline parameters derived from the glTF material. */
27
32
  readonly parameters: Parameters;
@@ -46,7 +46,7 @@ export type PhysicsBodyOptions = Pick<
46
46
  };
47
47
  export type PhysicsControllerProps = Omit<
48
48
  GPURigidBodyWorldProps,
49
- 'bodies' | 'publicationBounds' | 'publishPoses' | 'joints'
49
+ 'bodies' | 'publicationBounds' | 'publishPoses' | 'joints' | 'vehicle'
50
50
  > & {
51
51
  scene: GroupNode;
52
52
  /** Bound catch-up work; excess elapsed time is reported, not silently simulated. */
@@ -80,6 +80,11 @@ export class PhysicsController {
80
80
  private readonly definitions = new Map<ScenegraphNode, PhysicsBodyOptions>();
81
81
  private readonly handles = new Map<ScenegraphNode, PhysicsBody>();
82
82
  private readonly manualTargets = new Set<ScenegraphNode>();
83
+ private vehicleAttachment?: {
84
+ chassis: ScenegraphNode;
85
+ terrain: ScenegraphNode;
86
+ options: Omit<NonNullable<GPURigidBodyWorldProps['vehicle']>, 'chassis' | 'terrainCollider'>;
87
+ };
83
88
  private readonly joints: ScenegraphJoint[] = [];
84
89
  private indices: ReadonlyMap<ScenegraphNode, number> = new Map();
85
90
  private session?: ScenegraphPhysicsSession;
@@ -195,12 +200,42 @@ export class PhysicsController {
195
200
  this.assertEditable();
196
201
  const node = this.resolveNode(reference);
197
202
  if (!node || !this.definitions.delete(node)) return false;
203
+ if (this.vehicleAttachment?.chassis === node || this.vehicleAttachment?.terrain === node)
204
+ this.vehicleAttachment = undefined;
198
205
  this.handles.delete(node);
199
206
  this.manualTargets.delete(node);
200
207
  this.dirty = true;
201
208
  return true;
202
209
  }
203
210
 
211
+ /** Attach a four-wheel suspension to two registered body nodes or scene paths. */
212
+ setVehicle(
213
+ chassis: PhysicsNodeReference,
214
+ terrain: PhysicsNodeReference,
215
+ options: Omit<NonNullable<GPURigidBodyWorldProps['vehicle']>, 'chassis' | 'terrainCollider'>
216
+ ): void {
217
+ this.assertEditable();
218
+ const chassisNode = this.resolveNode(chassis),
219
+ terrainNode = this.resolveNode(terrain);
220
+ if (!chassisNode || !terrainNode) throw new Error('Missing vehicle attachment');
221
+ this.vehicleAttachment = {
222
+ chassis: chassisNode,
223
+ terrain: terrainNode,
224
+ options: structuredClone(options)
225
+ };
226
+ this.dirty = true;
227
+ }
228
+
229
+ /** Borrow wheel transforms relative to the registered chassis after preparation. */
230
+ get vehicleWheelPoses() {
231
+ return this.requireReady().world.vehicleWheelPoses;
232
+ }
233
+
234
+ /** Update controls for subsequent fixed steps. */
235
+ setVehicleControls(throttle: number, steering: number, brake: number): void {
236
+ this.requireReady().world.setVehicleControls(throttle, steering, brake);
237
+ }
238
+
204
239
  addJoint(options: PhysicsJointOptions): ScenegraphJoint {
205
240
  this.assertEditable();
206
241
  const {first, second, ...properties} = options;
@@ -239,6 +274,25 @@ export class PhysicsController {
239
274
  this.worldOptions,
240
275
  this.joints
241
276
  );
277
+ if (this.vehicleAttachment) {
278
+ const chassis = scene.definition.bodies.get(this.vehicleAttachment.chassis);
279
+ const terrain = scene.definition.bodies.get(this.vehicleAttachment.terrain);
280
+ const bodies = scene.definition.world.bodies;
281
+ if (
282
+ chassis === undefined ||
283
+ terrain === undefined ||
284
+ (bodies[terrain].colliders?.length ?? 1) !== 1
285
+ )
286
+ throw new Error('Vehicle requires attached chassis and single-collider terrain');
287
+ const terrainCollider = bodies
288
+ .slice(0, terrain)
289
+ .reduce((count, body) => count + (body.colliders?.length ?? 1), 0);
290
+ scene.definition.world.vehicle = {
291
+ ...this.vehicleAttachment.options,
292
+ chassis,
293
+ terrainCollider
294
+ };
295
+ }
242
296
  if (this.session) await this.session.rebuild(async () => scene, preserveState);
243
297
  else this.session = await ScenegraphPhysicsSession.create(this.device, scene);
244
298
  this.indices = scene.definition.bodies;
@@ -227,6 +227,16 @@ export class ScenegraphPhysicsInstance {
227
227
  }
228
228
  const replacement = await compile(this.device, props);
229
229
  try {
230
+ if (preserveState && props.vehicle && this.definition.world.vehicle) {
231
+ const previousChassis = this.definition.world.vehicle.chassis;
232
+ for (const [node, index] of authored.bodies) {
233
+ if (
234
+ index === props.vehicle.chassis &&
235
+ this.definition.bodies.get(node) === previousChassis
236
+ )
237
+ replacement.world.copyVehicleMotionFrom(this.world);
238
+ }
239
+ }
230
240
  prepare?.(replacement.world);
231
241
  replacement.world.publishPoses();
232
242
  await this.finishSubmission();