@luma.gl/engine 9.4.1 → 10.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/animation-loop/animation-loop.d.ts +12 -5
  2. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  3. package/dist/animation-loop/animation-loop.js +3 -1
  4. package/dist/animation-loop/animation-loop.js.map +1 -1
  5. package/dist/animation-loop/animation-props.d.ts +3 -1
  6. package/dist/animation-loop/animation-props.d.ts.map +1 -1
  7. package/dist/compute/computation.d.ts +12 -0
  8. package/dist/compute/computation.d.ts.map +1 -1
  9. package/dist/compute/computation.js +85 -22
  10. package/dist/compute/computation.js.map +1 -1
  11. package/dist/compute/kernel.d.ts +54 -0
  12. package/dist/compute/kernel.d.ts.map +1 -0
  13. package/dist/compute/kernel.js +103 -0
  14. package/dist/compute/kernel.js.map +1 -0
  15. package/dist/compute/render-kernel.d.ts +65 -0
  16. package/dist/compute/render-kernel.d.ts.map +1 -0
  17. package/dist/compute/render-kernel.js +129 -0
  18. package/dist/compute/render-kernel.js.map +1 -0
  19. package/dist/controls/orbit-controls.d.ts +9 -2
  20. package/dist/controls/orbit-controls.d.ts.map +1 -1
  21. package/dist/controls/orbit-controls.js +55 -8
  22. package/dist/controls/orbit-controls.js.map +1 -1
  23. package/dist/dist.dev.js +483 -127
  24. package/dist/dist.min.js +23 -23
  25. package/dist/index.cjs +485 -110
  26. package/dist/index.cjs.map +3 -3
  27. package/dist/index.d.ts +4 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +2 -0
  30. package/dist/index.js.map +1 -1
  31. package/dist/model/model.d.ts +13 -2
  32. package/dist/model/model.d.ts.map +1 -1
  33. package/dist/model/model.js +137 -66
  34. package/dist/model/model.js.map +1 -1
  35. package/dist/passes/shader-pass-renderer.d.ts +12 -12
  36. package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
  37. package/dist/passes/shader-pass-renderer.js +17 -17
  38. package/dist/passes/shader-pass-renderer.js.map +1 -1
  39. package/package.json +4 -4
  40. package/src/animation-loop/animation-loop.ts +16 -7
  41. package/src/animation-loop/animation-props.ts +4 -1
  42. package/src/compute/computation.ts +83 -30
  43. package/src/compute/kernel.ts +146 -0
  44. package/src/compute/render-kernel.ts +192 -0
  45. package/src/controls/orbit-controls.ts +61 -9
  46. package/src/index.ts +12 -0
  47. package/src/model/model.ts +149 -87
  48. package/src/passes/shader-pass-renderer.ts +28 -25
@@ -0,0 +1,146 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {Binding, ComputePipelineProps, Shader} from '@luma.gl/core';
6
+ import {
7
+ Buffer,
8
+ ComputePass,
9
+ ComputePipeline,
10
+ Device,
11
+ PipelineFactory,
12
+ ShaderFactory
13
+ } from '@luma.gl/core';
14
+
15
+ /** Properties for a lightweight immutable WebGPU compute kernel. */
16
+ export type KernelProps = Omit<ComputePipelineProps, 'shader'> & {
17
+ /** WGSL compute shader source. Shader assembly belongs to higher-level APIs. */
18
+ source: string;
19
+ /** Factory used to create/reuse the compute pipeline. */
20
+ pipelineFactory?: PipelineFactory;
21
+ /** Factory used to create/reuse the compute shader. */
22
+ shaderFactory?: ShaderFactory;
23
+ /** Show shader source in browser debugging UI. */
24
+ debugShaders?: 'never' | 'errors' | 'warnings' | 'always';
25
+ };
26
+
27
+ /** Bindings and workgroup dimensions for one direct dispatch. */
28
+ export type KernelDispatchOptions = {
29
+ bindings?: Record<string, Binding>;
30
+ x: number;
31
+ y?: number;
32
+ z?: number;
33
+ };
34
+
35
+ /** Bindings and GPU-written dispatch record for one indirect dispatch. */
36
+ export type KernelDispatchIndirectOptions = {
37
+ bindings?: Record<string, Binding>;
38
+ indirectBuffer: Buffer;
39
+ indirectOffset?: number;
40
+ };
41
+
42
+ /**
43
+ * Lightweight executable WebGPU compute program.
44
+ *
45
+ * `Kernel` deliberately does not assemble shadertools modules or own ShaderInputs/uniform state.
46
+ * Higher-level APIs may assemble WGSL before constructing a kernel. Bindings are supplied per
47
+ * dispatch so a kernel remains reusable and does not retain mutable resource binding state.
48
+ */
49
+ export class Kernel {
50
+ /** Creates a kernel while allowing the backend to compile its pipeline asynchronously. */
51
+ static async createAsync(device: Device, props: KernelProps): Promise<Kernel> {
52
+ const ownsCompilation = !PipelineFactory.getAsyncCompilation(device);
53
+ const asyncCompilation = ownsCompilation
54
+ ? PipelineFactory.beginAsyncCompilation(device)
55
+ : PipelineFactory.getAsyncCompilation(device)!;
56
+ let kernel: Kernel;
57
+ try {
58
+ kernel = new Kernel(device, props);
59
+ } finally {
60
+ if (ownsCompilation) PipelineFactory.endAsyncCompilation(device, asyncCompilation);
61
+ }
62
+ try {
63
+ if (ownsCompilation) {
64
+ await Promise.all(asyncCompilation);
65
+ } else {
66
+ await kernel._pipelineInitialization;
67
+ }
68
+ return kernel;
69
+ } catch (error) {
70
+ kernel.destroy();
71
+ throw error;
72
+ }
73
+ }
74
+
75
+ readonly device: Device;
76
+ readonly id: string;
77
+ readonly source: string;
78
+ readonly pipelineFactory: PipelineFactory;
79
+ readonly shaderFactory: ShaderFactory;
80
+
81
+ shader: Shader;
82
+ pipeline!: ComputePipeline;
83
+
84
+ private _pipelineInitialization?: Promise<ComputePipeline>;
85
+ private _destroyed = false;
86
+
87
+ constructor(device: Device, props: KernelProps) {
88
+ if (device.type !== 'webgpu') {
89
+ throw new Error('Kernel is only supported in WebGPU');
90
+ }
91
+ const {source, pipelineFactory, shaderFactory, debugShaders, ...pipelineProps} = props;
92
+
93
+ this.device = device;
94
+ this.id = props.id ?? 'kernel';
95
+ this.source = source;
96
+ this.pipelineFactory = pipelineFactory ?? PipelineFactory.getDefaultPipelineFactory(device);
97
+ this.shaderFactory = shaderFactory ?? ShaderFactory.getDefaultShaderFactory(device);
98
+ this.shader = this.shaderFactory.createShader({
99
+ id: `${this.id}-compute`,
100
+ stage: 'compute',
101
+ source: this.source,
102
+ debugShaders
103
+ });
104
+
105
+ const computePipelineProps: ComputePipelineProps = {...pipelineProps, shader: this.shader};
106
+
107
+ const asyncCompilation = PipelineFactory.getAsyncCompilation(device);
108
+ if (asyncCompilation) {
109
+ const pipelineInitialization =
110
+ this.pipelineFactory.createComputePipelineAsync(computePipelineProps);
111
+ this._pipelineInitialization = pipelineInitialization;
112
+ asyncCompilation.push(
113
+ pipelineInitialization.then(pipeline => {
114
+ this.pipeline = pipeline;
115
+ return pipeline;
116
+ })
117
+ );
118
+ } else {
119
+ this.pipeline = this.pipelineFactory.createComputePipeline(computePipelineProps);
120
+ }
121
+ }
122
+
123
+ /** Applies per-dispatch bindings and records a direct compute dispatch. */
124
+ dispatch(computePass: ComputePass, options: KernelDispatchOptions): void {
125
+ this._setPipeline(computePass, options.bindings);
126
+ computePass.dispatch(options.x, options.y, options.z);
127
+ }
128
+
129
+ /** Applies per-dispatch bindings and records a GPU-driven indirect compute dispatch. */
130
+ dispatchIndirect(computePass: ComputePass, options: KernelDispatchIndirectOptions): void {
131
+ this._setPipeline(computePass, options.bindings);
132
+ computePass.dispatchIndirect(options.indirectBuffer, options.indirectOffset ?? 0);
133
+ }
134
+
135
+ destroy(): void {
136
+ if (this._destroyed) return;
137
+ if (this.pipeline) this.pipelineFactory.release(this.pipeline);
138
+ this.shaderFactory.release(this.shader);
139
+ this._destroyed = true;
140
+ }
141
+
142
+ private _setPipeline(computePass: ComputePass, bindings: Record<string, Binding> = {}): void {
143
+ computePass.setPipeline(this.pipeline);
144
+ computePass.setBindings(bindings);
145
+ }
146
+ }
@@ -0,0 +1,192 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ import type {
6
+ Binding,
7
+ RenderPass,
8
+ RenderPassDrawOptions,
9
+ RenderPipelineProps,
10
+ Shader,
11
+ VertexArray
12
+ } from '@luma.gl/core';
13
+ import {Buffer, Device, PipelineFactory, RenderPipeline, ShaderFactory} from '@luma.gl/core';
14
+
15
+ /** Properties for a lightweight immutable WebGPU render kernel. */
16
+ export type RenderKernelProps = Omit<RenderPipelineProps, 'vs' | 'fs'> & {
17
+ /** Already assembled WGSL vertex shader source. */
18
+ vertexSource: string;
19
+ /** Already assembled WGSL fragment shader source. Omit for vertex/depth-only pipelines. */
20
+ fragmentSource?: string;
21
+ /** Factory used to create/reuse the render pipeline. */
22
+ pipelineFactory?: PipelineFactory;
23
+ /** Factory used to create/reuse the render shaders. */
24
+ shaderFactory?: ShaderFactory;
25
+ /** Show shader source in browser debugging UI. */
26
+ debugShaders?: 'never' | 'errors' | 'warnings' | 'always';
27
+ };
28
+
29
+ /** Per-draw state that deliberately remains outside the immutable render kernel. */
30
+ export type RenderKernelDrawOptions = RenderPassDrawOptions & {
31
+ /** Complete resource binding set for this draw. */
32
+ bindings?: Record<string, Binding>;
33
+ /** Vertex/index bindings consumed by this draw. */
34
+ vertexArray: VertexArray;
35
+ };
36
+
37
+ /** Per-indirect-draw state shared by indexed and non-indexed indirect rendering. */
38
+ export type RenderKernelIndirectDrawOptions = {
39
+ /** Complete resource binding set for this draw. */
40
+ bindings?: Record<string, Binding>;
41
+ /** Vertex/index bindings consumed by this draw. */
42
+ vertexArray: VertexArray;
43
+ /** Buffer containing WebGPU indirect draw arguments. */
44
+ indirectBuffer: Buffer;
45
+ /** Byte offset of the indirect draw record. */
46
+ indirectOffset?: number;
47
+ };
48
+
49
+ /**
50
+ * Lightweight executable WebGPU render program.
51
+ *
52
+ * `RenderKernel` owns compiled shaders and a cached render pipeline only. Shader assembly,
53
+ * uniforms, geometry ownership, draw counts, command graphs and scene/model policy stay above it.
54
+ * Bindings and vertex arrays are supplied per draw so the kernel does not retain mutable draw state.
55
+ */
56
+ export class RenderKernel {
57
+ /** Creates a render kernel while allowing the backend to compile its pipeline asynchronously. */
58
+ static async createAsync(device: Device, props: RenderKernelProps): Promise<RenderKernel> {
59
+ const ownsCompilation = !PipelineFactory.getAsyncCompilation(device);
60
+ const asyncCompilation = ownsCompilation
61
+ ? PipelineFactory.beginAsyncCompilation(device)
62
+ : PipelineFactory.getAsyncCompilation(device)!;
63
+ let kernel: RenderKernel;
64
+ try {
65
+ kernel = new RenderKernel(device, props);
66
+ } finally {
67
+ if (ownsCompilation) PipelineFactory.endAsyncCompilation(device, asyncCompilation);
68
+ }
69
+ try {
70
+ if (ownsCompilation) {
71
+ await Promise.all(asyncCompilation);
72
+ } else {
73
+ await kernel._pipelineInitialization;
74
+ }
75
+ return kernel;
76
+ } catch (error) {
77
+ kernel.destroy();
78
+ throw error;
79
+ }
80
+ }
81
+
82
+ readonly device: Device;
83
+ readonly id: string;
84
+ readonly vertexSource: string;
85
+ readonly fragmentSource?: string;
86
+ readonly pipelineFactory: PipelineFactory;
87
+ readonly shaderFactory: ShaderFactory;
88
+
89
+ readonly vertexShader: Shader;
90
+ readonly fragmentShader: Shader | null;
91
+ pipeline!: RenderPipeline;
92
+
93
+ private _pipelineInitialization?: Promise<RenderPipeline>;
94
+ private _destroyed = false;
95
+
96
+ constructor(device: Device, props: RenderKernelProps) {
97
+ if (device.type !== 'webgpu') {
98
+ throw new Error('RenderKernel is only supported in WebGPU');
99
+ }
100
+
101
+ const {
102
+ vertexSource,
103
+ fragmentSource,
104
+ pipelineFactory,
105
+ shaderFactory,
106
+ debugShaders,
107
+ ...pipelineProps
108
+ } = props;
109
+
110
+ this.device = device;
111
+ this.id = props.id ?? 'render-kernel';
112
+ this.vertexSource = vertexSource;
113
+ this.fragmentSource = fragmentSource;
114
+ this.pipelineFactory = pipelineFactory ?? PipelineFactory.getDefaultPipelineFactory(device);
115
+ this.shaderFactory = shaderFactory ?? ShaderFactory.getDefaultShaderFactory(device);
116
+
117
+ this.vertexShader = this.shaderFactory.createShader({
118
+ id: `${this.id}-vertex`,
119
+ stage: 'vertex',
120
+ source: this.vertexSource,
121
+ debugShaders
122
+ });
123
+ this.fragmentShader = this.fragmentSource
124
+ ? this.shaderFactory.createShader({
125
+ id: `${this.id}-fragment`,
126
+ stage: 'fragment',
127
+ source: this.fragmentSource,
128
+ debugShaders
129
+ })
130
+ : null;
131
+
132
+ const renderPipelineProps: RenderPipelineProps = {
133
+ ...pipelineProps,
134
+ vs: this.vertexShader,
135
+ fs: this.fragmentShader
136
+ };
137
+
138
+ const asyncCompilation = PipelineFactory.getAsyncCompilation(device);
139
+ if (asyncCompilation) {
140
+ const pipelineInitialization =
141
+ this.pipelineFactory.createRenderPipelineAsync(renderPipelineProps);
142
+ this._pipelineInitialization = pipelineInitialization;
143
+ asyncCompilation.push(
144
+ pipelineInitialization.then(pipeline => {
145
+ this.pipeline = pipeline;
146
+ return pipeline;
147
+ })
148
+ );
149
+ } else {
150
+ this.pipeline = this.pipelineFactory.createRenderPipeline(renderPipelineProps);
151
+ }
152
+ }
153
+
154
+ /** Applies per-draw bindings/vertex state and records a direct draw. */
155
+ draw(renderPass: RenderPass, options: RenderKernelDrawOptions): boolean {
156
+ const {bindings = {}, vertexArray, ...drawOptions} = options;
157
+ this._setPipeline(renderPass, bindings, vertexArray);
158
+ return renderPass.draw(drawOptions);
159
+ }
160
+
161
+ /** Applies per-draw state and records a non-indexed indirect draw. */
162
+ drawIndirect(renderPass: RenderPass, options: RenderKernelIndirectDrawOptions): void {
163
+ const {bindings = {}, vertexArray, indirectBuffer, indirectOffset = 0} = options;
164
+ this._setPipeline(renderPass, bindings, vertexArray);
165
+ renderPass.drawIndirect(indirectBuffer, indirectOffset);
166
+ }
167
+
168
+ /** Applies per-draw state and records an indexed indirect draw. */
169
+ drawIndexedIndirect(renderPass: RenderPass, options: RenderKernelIndirectDrawOptions): void {
170
+ const {bindings = {}, vertexArray, indirectBuffer, indirectOffset = 0} = options;
171
+ this._setPipeline(renderPass, bindings, vertexArray);
172
+ renderPass.drawIndexedIndirect(indirectBuffer, indirectOffset);
173
+ }
174
+
175
+ destroy(): void {
176
+ if (this._destroyed) return;
177
+ if (this.pipeline) this.pipelineFactory.release(this.pipeline);
178
+ this.shaderFactory.release(this.vertexShader);
179
+ if (this.fragmentShader) this.shaderFactory.release(this.fragmentShader);
180
+ this._destroyed = true;
181
+ }
182
+
183
+ private _setPipeline(
184
+ renderPass: RenderPass,
185
+ bindings: Record<string, Binding>,
186
+ vertexArray: VertexArray
187
+ ): void {
188
+ renderPass.setPipeline(this.pipeline);
189
+ renderPass.setBindings(bindings);
190
+ renderPass.setVertexArray(vertexArray);
191
+ }
192
+ }
@@ -9,6 +9,7 @@ export type OrbitControlsProps = {
9
9
  distance?: number;
10
10
  yaw?: number;
11
11
  pitch?: number;
12
+ roll?: number;
12
13
  minDistance?: number;
13
14
  maxDistance?: number;
14
15
  minPitch?: number;
@@ -17,6 +18,7 @@ export type OrbitControlsProps = {
17
18
  pitchSpeed?: number;
18
19
  zoomSpeed?: number;
19
20
  enabled?: boolean;
21
+ enableRotate?: boolean;
20
22
  enableZoom?: boolean;
21
23
  enablePan?: boolean;
22
24
  panSpeed?: number;
@@ -35,6 +37,7 @@ const DEFAULT_PROPS: ResolvedOrbitControlsProps = {
35
37
  distance: 10,
36
38
  yaw: 0,
37
39
  pitch: 0.25,
40
+ roll: 0,
38
41
  minDistance: 1,
39
42
  maxDistance: 100,
40
43
  minPitch: -Math.PI / 2 + 0.01,
@@ -42,6 +45,7 @@ const DEFAULT_PROPS: ResolvedOrbitControlsProps = {
42
45
  rotateSpeed: 0.006,
43
46
  zoomSpeed: 0.001,
44
47
  enabled: true,
48
+ enableRotate: false,
45
49
  enableZoom: true,
46
50
  enablePan: false,
47
51
  panSpeed: 0.0018,
@@ -50,7 +54,7 @@ const DEFAULT_PROPS: ResolvedOrbitControlsProps = {
50
54
  };
51
55
 
52
56
  /**
53
- * Pointer orbit, wheel and pinch zoom, and optional automatic rotation controls for a canvas.
57
+ * Pointer orbit, optional pinch roll, wheel and pinch zoom, and automatic rotation controls.
54
58
  *
55
59
  * Call {@link update} once per frame with an animation-loop timestamp in milliseconds before
56
60
  * reading {@link getEyePosition}. Manual dragging temporarily pauses automatic rotation and
@@ -61,12 +65,14 @@ export class OrbitControls {
61
65
  readonly props: ResolvedOrbitControlsProps;
62
66
  yaw: number;
63
67
  pitch: number;
68
+ roll: number;
64
69
  distance: number;
65
70
 
66
71
  private dragging = false;
67
72
  private readonly activePointers = new Map<number, [number, number]>();
68
73
  private lastPointer: [number, number] = [0, 0];
69
74
  private previousPinchDistance: number | null = null;
75
+ private previousPinchAngle: number | null = null;
70
76
  private previousTimeMilliseconds: number | null = null;
71
77
  private readonly previousCursor: string;
72
78
  private readonly previousTouchAction: string;
@@ -77,6 +83,7 @@ export class OrbitControls {
77
83
  this.props.target = [...this.props.target];
78
84
  this.yaw = this.props.yaw;
79
85
  this.pitch = clampNumber(this.props.pitch, this.props.minPitch, this.props.maxPitch);
86
+ this.roll = this.props.roll;
80
87
  this.distance = clampNumber(
81
88
  this.props.distance,
82
89
  this.props.minDistance,
@@ -120,6 +127,34 @@ export class OrbitControls {
120
127
  ];
121
128
  }
122
129
 
130
+ /** Returns the camera up direction after applying pitch and optional two-finger roll. */
131
+ getUpDirection(): OrbitPosition {
132
+ return this.getCameraFrame().up;
133
+ }
134
+
135
+ private getCameraFrame(): {right: OrbitPosition; up: OrbitPosition} {
136
+ const sineYaw = Math.sin(this.yaw);
137
+ const cosineYaw = Math.cos(this.yaw);
138
+ const sinePitch = Math.sin(this.pitch);
139
+ const cosinePitch = Math.cos(this.pitch);
140
+ const sineRoll = Math.sin(this.roll);
141
+ const cosineRoll = Math.cos(this.roll);
142
+ const right: OrbitPosition = [cosineYaw, 0, -sineYaw];
143
+ const up: OrbitPosition = [-sinePitch * sineYaw, cosinePitch, -sinePitch * cosineYaw];
144
+ return {
145
+ right: [
146
+ right[0] * cosineRoll - up[0] * sineRoll,
147
+ right[1] * cosineRoll - up[1] * sineRoll,
148
+ right[2] * cosineRoll - up[2] * sineRoll
149
+ ],
150
+ up: [
151
+ up[0] * cosineRoll + right[0] * sineRoll,
152
+ up[1] * cosineRoll + right[1] * sineRoll,
153
+ up[2] * cosineRoll + right[2] * sineRoll
154
+ ]
155
+ };
156
+ }
157
+
123
158
  /** Enables or pauses automatic rotation without losing the current manual angle. */
124
159
  setAutoRotate(autoRotate: boolean): void {
125
160
  this.props.autoRotate = autoRotate;
@@ -140,6 +175,9 @@ export class OrbitControls {
140
175
  if (props.pitch !== undefined || props.minPitch !== undefined || props.maxPitch !== undefined) {
141
176
  this.pitch = clampNumber(props.pitch ?? this.pitch, this.props.minPitch, this.props.maxPitch);
142
177
  }
178
+ if (props.roll !== undefined) {
179
+ this.roll = props.roll;
180
+ }
143
181
  if (
144
182
  props.distance !== undefined ||
145
183
  props.minDistance !== undefined ||
@@ -153,10 +191,11 @@ export class OrbitControls {
153
191
  }
154
192
  }
155
193
 
156
- /** Restores the configured starting angle and zoom. */
194
+ /** Restores the configured starting orbit, roll, and zoom. */
157
195
  reset(): void {
158
196
  this.yaw = this.props.yaw;
159
197
  this.pitch = clampNumber(this.props.pitch, this.props.minPitch, this.props.maxPitch);
198
+ this.roll = this.props.roll;
160
199
  this.distance = clampNumber(
161
200
  this.props.distance,
162
201
  this.props.minDistance,
@@ -193,9 +232,10 @@ export class OrbitControls {
193
232
  if (this.activePointers.size === 1) {
194
233
  this.lastPointer = [event.clientX, event.clientY];
195
234
  } else {
196
- const {center, distance} = this.getMultiPointerState();
235
+ const {center, distance, angle} = this.getMultiPointerState();
197
236
  this.lastPointer = center;
198
237
  this.previousPinchDistance = distance;
238
+ this.previousPinchAngle = distance > 0 ? angle : null;
199
239
  }
200
240
  this.canvas.setPointerCapture(event.pointerId);
201
241
  this.canvas.style.cursor = 'grabbing';
@@ -208,7 +248,7 @@ export class OrbitControls {
208
248
 
209
249
  this.activePointers.set(event.pointerId, [event.clientX, event.clientY]);
210
250
  if (this.activePointers.size > 1) {
211
- const {center, distance} = this.getMultiPointerState();
251
+ const {center, distance, angle} = this.getMultiPointerState();
212
252
  if (this.props.enablePan) {
213
253
  this.panTarget(center[0] - this.lastPointer[0], center[1] - this.lastPointer[1]);
214
254
  }
@@ -219,8 +259,12 @@ export class OrbitControls {
219
259
  this.props.maxDistance
220
260
  );
221
261
  }
262
+ if (this.props.enableRotate && this.previousPinchAngle !== null && distance > 0) {
263
+ this.roll += normalizeAngleDelta(angle - this.previousPinchAngle);
264
+ }
222
265
  this.lastPointer = center;
223
266
  this.previousPinchDistance = distance;
267
+ this.previousPinchAngle = distance > 0 ? angle : null;
224
268
  return;
225
269
  }
226
270
 
@@ -249,6 +293,7 @@ export class OrbitControls {
249
293
  }
250
294
  this.activePointers.delete(event.pointerId);
251
295
  this.previousPinchDistance = null;
296
+ this.previousPinchAngle = null;
252
297
 
253
298
  const remainingPointer = this.activePointers.entries().next().value;
254
299
  if (remainingPointer) {
@@ -267,25 +312,28 @@ export class OrbitControls {
267
312
  }
268
313
  this.activePointers.clear();
269
314
  this.previousPinchDistance = null;
315
+ this.previousPinchAngle = null;
270
316
  this.canvas.style.cursor = 'grab';
271
317
  }
272
318
 
273
- private getMultiPointerState(): {center: [number, number]; distance: number} {
319
+ private getMultiPointerState(): {center: [number, number]; distance: number; angle: number} {
274
320
  const [firstPointer, secondPointer] = this.activePointers.values();
275
321
  const deltaX = secondPointer[0] - firstPointer[0];
276
322
  const deltaY = secondPointer[1] - firstPointer[1];
277
323
  return {
278
324
  center: [(firstPointer[0] + secondPointer[0]) / 2, (firstPointer[1] + secondPointer[1]) / 2],
279
- distance: Math.hypot(deltaX, deltaY)
325
+ distance: Math.hypot(deltaX, deltaY),
326
+ angle: Math.atan2(deltaY, deltaX)
280
327
  };
281
328
  }
282
329
 
283
330
  private panTarget(deltaX: number, deltaY: number): void {
284
331
  const panScale = this.distance * this.props.panSpeed;
332
+ const {right, up} = this.getCameraFrame();
285
333
  this.props.target = [
286
- this.props.target[0] - Math.cos(this.yaw) * deltaX * panScale,
287
- this.props.target[1] + deltaY * panScale,
288
- this.props.target[2] + Math.sin(this.yaw) * deltaX * panScale
334
+ this.props.target[0] + (-right[0] * deltaX + up[0] * deltaY) * panScale,
335
+ this.props.target[1] + (-right[1] * deltaX + up[1] * deltaY) * panScale,
336
+ this.props.target[2] + (-right[2] * deltaX + up[2] * deltaY) * panScale
289
337
  ];
290
338
  }
291
339
 
@@ -307,3 +355,7 @@ export class OrbitControls {
307
355
  function clampNumber(value: number, minimum: number, maximum: number): number {
308
356
  return Math.min(Math.max(value, minimum), maximum);
309
357
  }
358
+
359
+ function normalizeAngleDelta(angle: number): number {
360
+ return Math.atan2(Math.sin(angle), Math.cos(angle));
361
+ }
package/src/index.ts CHANGED
@@ -173,6 +173,18 @@ export {SwapFramebuffers} from './compute/swap';
173
173
 
174
174
  export type {ComputationProps} from './compute/computation';
175
175
  export {Computation} from './compute/computation';
176
+ export type {
177
+ KernelProps,
178
+ KernelDispatchOptions,
179
+ KernelDispatchIndirectOptions
180
+ } from './compute/kernel';
181
+ export {Kernel} from './compute/kernel';
182
+ export type {
183
+ RenderKernelProps,
184
+ RenderKernelDrawOptions,
185
+ RenderKernelIndirectDrawOptions
186
+ } from './compute/render-kernel';
187
+ export {RenderKernel} from './compute/render-kernel';
176
188
 
177
189
  export type {
178
190
  PickInfo,