@luma.gl/engine 9.0.0-beta.4 → 9.0.0-beta.6
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.
- package/dist/animation/key-frames.js +54 -54
- package/dist/animation/timeline.d.ts.map +1 -1
- package/dist/animation/timeline.js +95 -100
- package/dist/animation-loop/animation-loop-template.d.ts +1 -1
- package/dist/animation-loop/animation-loop-template.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop-template.js +19 -5
- package/dist/animation-loop/animation-loop.d.ts +2 -2
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +433 -356
- package/dist/animation-loop/animation-props.d.ts +2 -2
- package/dist/animation-loop/animation-props.d.ts.map +1 -1
- package/dist/animation-loop/animation-props.js +0 -1
- package/dist/animation-loop/make-animation-loop.d.ts +2 -2
- package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/make-animation-loop.js +28 -24
- package/dist/debug/copy-texture-to-image.d.ts.map +1 -1
- package/dist/debug/copy-texture-to-image.js +41 -42
- package/dist/debug/debug-framebuffer.d.ts.map +1 -1
- package/dist/debug/debug-framebuffer.js +43 -40
- package/dist/debug/debug-shader-layout.js +24 -25
- package/dist/debug/pixel-data-utils.d.ts.map +1 -1
- package/dist/debug/pixel-data-utils.js +34 -36
- package/dist/dist.dev.js +3873 -8643
- package/dist/geometries/cone-geometry.d.ts +1 -1
- package/dist/geometries/cone-geometry.d.ts.map +1 -1
- package/dist/geometries/cone-geometry.js +11 -17
- package/dist/geometries/cube-geometry.d.ts +1 -1
- package/dist/geometries/cube-geometry.d.ts.map +1 -1
- package/dist/geometries/cube-geometry.js +190 -61
- package/dist/geometries/cylinder-geometry.d.ts +1 -1
- package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
- package/dist/geometries/cylinder-geometry.js +9 -14
- package/dist/geometries/ico-sphere-geometry.d.ts +1 -1
- package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/ico-sphere-geometry.js +141 -160
- package/dist/geometries/plane-geometry.d.ts +1 -1
- package/dist/geometries/plane-geometry.d.ts.map +1 -1
- package/dist/geometries/plane-geometry.js +92 -110
- package/dist/geometries/sphere-geometry.d.ts +1 -1
- package/dist/geometries/sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/sphere-geometry.js +76 -95
- package/dist/geometries/truncated-cone-geometry.d.ts +1 -1
- package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
- package/dist/geometries/truncated-cone-geometry.js +99 -117
- package/dist/geometry/geometry-table.d.ts.map +1 -1
- package/dist/geometry/geometry-table.js +3 -1
- package/dist/geometry/geometry-utils.js +35 -32
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +80 -71
- package/dist/geometry/gpu-geometry.d.ts +1 -1
- package/dist/geometry/gpu-geometry.d.ts.map +1 -1
- package/dist/geometry/gpu-geometry.js +80 -99
- package/dist/geometry/gpu-table.js +41 -1
- package/dist/index.cjs +241 -206
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +41 -40
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/lib/clip-space.d.ts +1 -1
- package/dist/lib/clip-space.d.ts.map +1 -1
- package/dist/lib/clip-space.js +23 -28
- package/dist/lib/pipeline-factory.d.ts +1 -5
- package/dist/lib/pipeline-factory.d.ts.map +1 -1
- package/dist/lib/pipeline-factory.js +64 -68
- package/dist/lib/shader-factory.d.ts +17 -0
- package/dist/lib/shader-factory.d.ts.map +1 -0
- package/dist/lib/shader-factory.js +44 -0
- package/dist/model/model.d.ts +22 -10
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +562 -410
- package/dist/scenegraph/group-node.d.ts +1 -1
- package/dist/scenegraph/group-node.d.ts.map +1 -1
- package/dist/scenegraph/group-node.js +73 -83
- package/dist/scenegraph/model-node.d.ts +2 -2
- package/dist/scenegraph/model-node.d.ts.map +1 -1
- package/dist/scenegraph/model-node.js +31 -24
- package/dist/scenegraph/scenegraph-node.d.ts.map +1 -1
- package/dist/scenegraph/scenegraph-node.js +136 -124
- package/dist/shader-inputs.d.ts.map +1 -1
- package/dist/shader-inputs.js +99 -58
- package/dist/transform/buffer-transform.d.ts +1 -1
- package/dist/transform/buffer-transform.d.ts.map +1 -1
- package/dist/transform/buffer-transform.js +65 -57
- package/dist/transform/texture-transform.d.ts +1 -1
- package/dist/transform/texture-transform.d.ts.map +1 -1
- package/dist/transform/texture-transform.js +109 -114
- package/dist.min.js +2 -272
- package/package.json +10 -9
- package/src/animation/timeline.ts +20 -20
- package/src/animation-loop/animation-loop-template.ts +10 -8
- package/src/animation-loop/animation-loop.ts +20 -10
- package/src/animation-loop/animation-props.ts +1 -1
- package/src/animation-loop/make-animation-loop.ts +17 -8
- package/src/debug/copy-texture-to-image.ts +8 -6
- package/src/debug/debug-framebuffer.ts +16 -3
- package/src/debug/debug-shader-layout.ts +1 -1
- package/src/debug/pixel-data-utils.ts +3 -6
- package/src/geometries/cube-geometry.ts +17 -13
- package/src/geometries/ico-sphere-geometry.ts +1 -1
- package/src/geometries/plane-geometry.ts +1 -1
- package/src/geometries/sphere-geometry.ts +1 -1
- package/src/geometries/truncated-cone-geometry.ts +2 -1
- package/src/geometry/geometry-table.ts +9 -6
- package/src/geometry/geometry-utils.ts +1 -1
- package/src/geometry/geometry.ts +9 -6
- package/src/geometry/gpu-geometry.ts +14 -6
- package/src/index.ts +1 -0
- package/src/lib/clip-space.ts +14 -18
- package/src/lib/pipeline-factory.ts +12 -22
- package/src/lib/shader-factory.ts +55 -0
- package/src/model/model.ts +74 -42
- package/src/scenegraph/group-node.ts +14 -10
- package/src/scenegraph/model-node.ts +2 -2
- package/src/scenegraph/scenegraph-node.ts +2 -2
- package/src/shader-inputs.ts +19 -12
- package/src/transform/buffer-transform.ts +16 -8
- package/src/transform/texture-transform.ts +14 -15
- package/dist/animation/key-frames.js.map +0 -1
- package/dist/animation/timeline.js.map +0 -1
- package/dist/animation-loop/animation-loop-template.js.map +0 -1
- package/dist/animation-loop/animation-loop.js.map +0 -1
- package/dist/animation-loop/animation-props.js.map +0 -1
- package/dist/animation-loop/make-animation-loop.js.map +0 -1
- package/dist/debug/copy-texture-to-image.js.map +0 -1
- package/dist/debug/debug-framebuffer.js.map +0 -1
- package/dist/debug/debug-shader-layout.js.map +0 -1
- package/dist/debug/pixel-data-utils.js.map +0 -1
- package/dist/geometries/cone-geometry.js.map +0 -1
- package/dist/geometries/cube-geometry.js.map +0 -1
- package/dist/geometries/cylinder-geometry.js.map +0 -1
- package/dist/geometries/ico-sphere-geometry.js.map +0 -1
- package/dist/geometries/plane-geometry.js.map +0 -1
- package/dist/geometries/sphere-geometry.js.map +0 -1
- package/dist/geometries/truncated-cone-geometry.js.map +0 -1
- package/dist/geometry/geometry-table.js.map +0 -1
- package/dist/geometry/geometry-utils.js.map +0 -1
- package/dist/geometry/geometry.js.map +0 -1
- package/dist/geometry/gpu-geometry.js.map +0 -1
- package/dist/geometry/gpu-table.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/clip-space.js.map +0 -1
- package/dist/lib/pipeline-factory.js.map +0 -1
- package/dist/model/model.js.map +0 -1
- package/dist/scenegraph/group-node.js.map +0 -1
- package/dist/scenegraph/model-node.js.map +0 -1
- package/dist/scenegraph/scenegraph-node.js.map +0 -1
- package/dist/shader-inputs.js.map +0 -1
- package/dist/transform/buffer-transform.js.map +0 -1
- package/dist/transform/texture-transform.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/engine",
|
|
3
|
-
"version": "9.0.0-beta.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "9.0.0-beta.6",
|
|
4
|
+
"description": "3D Engine Components for luma.gl",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"publishConfig": {
|
|
@@ -35,17 +35,18 @@
|
|
|
35
35
|
],
|
|
36
36
|
"sideEffects": false,
|
|
37
37
|
"scripts": {
|
|
38
|
-
"build-bundle": "ocular-bundle ./src/index.ts",
|
|
39
|
-
"
|
|
38
|
+
"build-minified-bundle": "ocular-bundle ./src/index.ts -output=dist/dist.min.js",
|
|
39
|
+
"build-dev-bundle": "ocular-bundle ./src/index.ts -output=dist/dist.dev.js -- --env=dev",
|
|
40
|
+
"prepublishOnly": "npm run build-minified-bundle && npm run build-dev-bundle"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@luma.gl/core": "^9.0.0-beta.4",
|
|
44
|
+
"@luma.gl/shadertools": "^9.0.0-beta.4"
|
|
40
45
|
},
|
|
41
46
|
"dependencies": {
|
|
42
|
-
"@babel/runtime": "^7.0.0",
|
|
43
|
-
"@luma.gl/constants": "9.0.0-beta.4",
|
|
44
|
-
"@luma.gl/core": "9.0.0-beta.4",
|
|
45
|
-
"@luma.gl/shadertools": "9.0.0-beta.4",
|
|
46
47
|
"@math.gl/core": "^4.0.0",
|
|
47
48
|
"@probe.gl/log": "^4.0.2",
|
|
48
49
|
"@probe.gl/stats": "^4.0.2"
|
|
49
50
|
},
|
|
50
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "cb2f0938d03a65e3588622ac99650b14a10488b6"
|
|
51
52
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -9,30 +10,30 @@
|
|
|
9
10
|
* @param repeat = 1
|
|
10
11
|
*/
|
|
11
12
|
export type ChannelOptions = {
|
|
12
|
-
delay?: number
|
|
13
|
-
duration?: number
|
|
14
|
-
rate?: number
|
|
15
|
-
repeat?: number
|
|
16
|
-
}
|
|
13
|
+
delay?: number;
|
|
14
|
+
duration?: number;
|
|
15
|
+
rate?: number;
|
|
16
|
+
repeat?: number;
|
|
17
|
+
};
|
|
17
18
|
|
|
18
19
|
export type AnimationOptions = {
|
|
19
|
-
setTime: (time: number) => void
|
|
20
|
-
}
|
|
20
|
+
setTime: (time: number) => void;
|
|
21
|
+
};
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
time: number
|
|
24
|
-
delay: number
|
|
25
|
-
duration: number
|
|
26
|
-
rate: number
|
|
27
|
-
repeat: number
|
|
28
|
-
}
|
|
23
|
+
type Channel = {
|
|
24
|
+
time: number;
|
|
25
|
+
delay: number;
|
|
26
|
+
duration: number;
|
|
27
|
+
rate: number;
|
|
28
|
+
repeat: number;
|
|
29
|
+
};
|
|
29
30
|
|
|
30
31
|
type Animation = {
|
|
31
32
|
channel?: number;
|
|
32
33
|
animation: {
|
|
33
|
-
setTime: (time: number) => void
|
|
34
|
-
}
|
|
35
|
-
}
|
|
34
|
+
setTime: (time: number) => void;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
36
37
|
|
|
37
38
|
let channelHandles = 1;
|
|
38
39
|
let animationHandles = 1;
|
|
@@ -44,8 +45,7 @@ export class Timeline {
|
|
|
44
45
|
playing: boolean = false;
|
|
45
46
|
lastEngineTime: number = -1;
|
|
46
47
|
|
|
47
|
-
constructor() {
|
|
48
|
-
}
|
|
48
|
+
constructor() {}
|
|
49
49
|
|
|
50
50
|
addChannel(props: ChannelOptions): number {
|
|
51
51
|
const {delay = 0, duration = Number.POSITIVE_INFINITY, rate = 1, repeat = 1} = props;
|
|
@@ -3,21 +3,23 @@ import type {AnimationProps} from './animation-props';
|
|
|
3
3
|
/**
|
|
4
4
|
* Minimal class that represents a "componentized" rendering life cycle
|
|
5
5
|
* (resource construction, repeated rendering, resource destruction)
|
|
6
|
-
*
|
|
7
|
-
* @note A motivation for this class compared to the raw animation loop is
|
|
8
|
-
* that it simplifies TypeScript code by allowing resources to be typed unconditionally
|
|
6
|
+
*
|
|
7
|
+
* @note A motivation for this class compared to the raw animation loop is
|
|
8
|
+
* that it simplifies TypeScript code by allowing resources to be typed unconditionally
|
|
9
9
|
* since they are allocated in the constructor rather than in onInitialized
|
|
10
|
-
*
|
|
10
|
+
*
|
|
11
11
|
* @note Introduced in luma.gl v9
|
|
12
|
-
*
|
|
13
|
-
* @example AnimationLoopTemplate is intended to be subclassed,
|
|
12
|
+
*
|
|
13
|
+
* @example AnimationLoopTemplate is intended to be subclassed,
|
|
14
14
|
* but the subclass should not be instantiated directly. Instead the subclass
|
|
15
|
-
* (i.e. the constructor of the subclass) should be used
|
|
15
|
+
* (i.e. the constructor of the subclass) should be used
|
|
16
16
|
* as an argument to create an AnimationLoop.
|
|
17
17
|
*/
|
|
18
18
|
export abstract class AnimationLoopTemplate {
|
|
19
19
|
constructor(animationProps?: AnimationProps) {}
|
|
20
|
-
async onInitialize(animationProps: AnimationProps): Promise<unknown> {
|
|
20
|
+
async onInitialize(animationProps: AnimationProps): Promise<unknown> {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
21
23
|
abstract onRender(animationProps: AnimationProps): unknown;
|
|
22
24
|
abstract onFinalize(animationProps: AnimationProps): void;
|
|
23
25
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import {luma, Device} from '@luma.gl/core';
|
|
@@ -32,23 +33,25 @@ export type MutableAnimationLoopProps = {
|
|
|
32
33
|
autoResizeViewport?: boolean;
|
|
33
34
|
autoResizeDrawingBuffer?: boolean;
|
|
34
35
|
useDevicePixels?: number | boolean;
|
|
35
|
-
}
|
|
36
|
+
};
|
|
36
37
|
|
|
37
38
|
const DEFAULT_ANIMATION_LOOP_PROPS: Required<AnimationLoopProps> = {
|
|
38
39
|
device: null!,
|
|
39
40
|
|
|
40
41
|
onAddHTML: () => '',
|
|
41
|
-
onInitialize: async () => {
|
|
42
|
+
onInitialize: async () => {
|
|
43
|
+
return null;
|
|
44
|
+
},
|
|
42
45
|
onRender: () => {},
|
|
43
46
|
onFinalize: () => {},
|
|
44
|
-
onError:
|
|
47
|
+
onError: error => console.error(error), // eslint-disable-line no-console
|
|
45
48
|
|
|
46
49
|
stats: luma.stats.get(`animation-loop-${statIdCounter++}`),
|
|
47
50
|
|
|
48
51
|
// view parameters
|
|
49
52
|
useDevicePixels: true,
|
|
50
53
|
autoResizeViewport: false,
|
|
51
|
-
autoResizeDrawingBuffer: false
|
|
54
|
+
autoResizeDrawingBuffer: false
|
|
52
55
|
};
|
|
53
56
|
|
|
54
57
|
/** Convenient animation loop */
|
|
@@ -148,7 +151,6 @@ export class AnimationLoop {
|
|
|
148
151
|
this._running = true;
|
|
149
152
|
|
|
150
153
|
try {
|
|
151
|
-
|
|
152
154
|
let appContext;
|
|
153
155
|
if (!this._initialized) {
|
|
154
156
|
this._initialized = true;
|
|
@@ -174,7 +176,7 @@ export class AnimationLoop {
|
|
|
174
176
|
|
|
175
177
|
return this;
|
|
176
178
|
} catch (err: unknown) {
|
|
177
|
-
const error = err instanceof Error ? err : new Error('Unknown error')
|
|
179
|
+
const error = err instanceof Error ? err : new Error('Unknown error');
|
|
178
180
|
this.props.onError(error);
|
|
179
181
|
// this._running = false; // TODO
|
|
180
182
|
throw error;
|
|
@@ -242,7 +244,7 @@ export class AnimationLoop {
|
|
|
242
244
|
this.setNeedsRedraw('waitForRender');
|
|
243
245
|
|
|
244
246
|
if (!this._nextFramePromise) {
|
|
245
|
-
this._nextFramePromise = new Promise(
|
|
247
|
+
this._nextFramePromise = new Promise(resolve => {
|
|
246
248
|
this._resolveNextFrame = resolve;
|
|
247
249
|
});
|
|
248
250
|
}
|
|
@@ -461,7 +463,7 @@ export class AnimationLoop {
|
|
|
461
463
|
}
|
|
462
464
|
}
|
|
463
465
|
|
|
464
|
-
_getSizeAndAspect(): {width: number; height: number; aspect: number}
|
|
466
|
+
_getSizeAndAspect(): {width: number; height: number; aspect: number} {
|
|
465
467
|
if (!this.device) {
|
|
466
468
|
return {width: 1, height: 1, aspect: 1};
|
|
467
469
|
}
|
|
@@ -485,10 +487,18 @@ export class AnimationLoop {
|
|
|
485
487
|
|
|
486
488
|
/** Default viewport setup */
|
|
487
489
|
_resizeViewport(): void {
|
|
490
|
+
// TODO can we use canvas context to code this in a portable way?
|
|
488
491
|
// @ts-expect-error Expose on canvasContext
|
|
489
492
|
if (this.props.autoResizeViewport && this.device.gl) {
|
|
490
493
|
// @ts-expect-error Expose canvasContext
|
|
491
|
-
this.device.gl.viewport(
|
|
494
|
+
this.device.gl.viewport(
|
|
495
|
+
0,
|
|
496
|
+
0,
|
|
497
|
+
// @ts-expect-error Expose canvasContext
|
|
498
|
+
this.device.gl.drawingBufferWidth,
|
|
499
|
+
// @ts-expect-error Expose canvasContext
|
|
500
|
+
this.device.gl.drawingBufferHeight
|
|
501
|
+
);
|
|
492
502
|
}
|
|
493
503
|
}
|
|
494
504
|
|
|
@@ -1,20 +1,29 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
2
5
|
import {luma} from '@luma.gl/core';
|
|
3
|
-
import {AnimationLoopTemplate} from './animation-loop-template'
|
|
4
|
-
import {AnimationLoop, AnimationLoopProps} from './animation-loop'
|
|
6
|
+
import {AnimationLoopTemplate} from './animation-loop-template';
|
|
7
|
+
import {AnimationLoop, AnimationLoopProps} from './animation-loop';
|
|
5
8
|
import type {AnimationProps} from './animation-props';
|
|
6
9
|
|
|
7
|
-
export type MakeAnimationLoopProps = Omit<
|
|
10
|
+
export type MakeAnimationLoopProps = Omit<
|
|
11
|
+
AnimationLoopProps,
|
|
12
|
+
'onCreateDevice' | 'onInitialize' | 'onRedraw' | 'onFinalize'
|
|
13
|
+
>;
|
|
8
14
|
|
|
9
15
|
/** Instantiates and runs the render loop */
|
|
10
|
-
export function makeAnimationLoop(
|
|
16
|
+
export function makeAnimationLoop(
|
|
17
|
+
AnimationLoopTemplateCtor: typeof AnimationLoopTemplate,
|
|
18
|
+
props?: MakeAnimationLoopProps
|
|
19
|
+
): AnimationLoop {
|
|
11
20
|
let renderLoop: AnimationLoopTemplate | null = null;
|
|
12
21
|
|
|
13
22
|
const device = props?.device || luma.createDevice();
|
|
14
23
|
|
|
15
24
|
// Create an animation loop;
|
|
16
25
|
const animationLoop = new AnimationLoop({
|
|
17
|
-
...
|
|
26
|
+
...props,
|
|
18
27
|
|
|
19
28
|
device,
|
|
20
29
|
|
|
@@ -26,7 +35,7 @@ export function makeAnimationLoop(AnimationLoopTemplateCtor: typeof AnimationLoo
|
|
|
26
35
|
},
|
|
27
36
|
|
|
28
37
|
onRender: (animationProps: AnimationProps) => renderLoop?.onRender(animationProps),
|
|
29
|
-
|
|
38
|
+
|
|
30
39
|
onFinalize: (animationProps: AnimationProps) => renderLoop?.onFinalize(animationProps)
|
|
31
40
|
});
|
|
32
41
|
|
|
@@ -35,7 +44,7 @@ export function makeAnimationLoop(AnimationLoopTemplateCtor: typeof AnimationLoo
|
|
|
35
44
|
// @ts-ignore
|
|
36
45
|
// eslint-disable-next-line no-invalid-this
|
|
37
46
|
return this.AnimationLoopTemplateCtor.info;
|
|
38
|
-
}
|
|
47
|
+
};
|
|
39
48
|
|
|
40
49
|
// Start the loop automatically
|
|
41
50
|
// animationLoop.start();
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
2
5
|
import {Texture, Framebuffer} from '@luma.gl/core';
|
|
3
6
|
import {GL} from '@luma.gl/constants';
|
|
4
7
|
import {flipRows, scalePixels} from './pixel-data-utils';
|
|
@@ -8,7 +11,7 @@ import {flipRows, scalePixels} from './pixel-data-utils';
|
|
|
8
11
|
* @todo - support gl.readBuffer
|
|
9
12
|
*/
|
|
10
13
|
export type CopyTextureToImageOptions = {
|
|
11
|
-
sourceAttachment?: number;
|
|
14
|
+
sourceAttachment?: number;
|
|
12
15
|
targetMaxHeight?: number;
|
|
13
16
|
targetImage?: HTMLImageElement;
|
|
14
17
|
};
|
|
@@ -16,15 +19,14 @@ export type CopyTextureToImageOptions = {
|
|
|
16
19
|
/**
|
|
17
20
|
* Reads pixels from a Framebuffer or Texture object into an HTML Image
|
|
18
21
|
* @todo - can we move this to @luma.gl/core?
|
|
19
|
-
* @param source
|
|
22
|
+
* @param source
|
|
20
23
|
* @param options options passed to copyToDataUrl
|
|
21
|
-
* @returns
|
|
24
|
+
* @returns
|
|
22
25
|
*/
|
|
23
26
|
export function copyTextureToImage(
|
|
24
27
|
source: Texture | Framebuffer,
|
|
25
28
|
options?: CopyTextureToImageOptions
|
|
26
29
|
): HTMLImageElement {
|
|
27
|
-
|
|
28
30
|
const dataUrl = copyTextureToDataUrl(source, options);
|
|
29
31
|
const targetImage: HTMLImageElement = options?.targetImage || new Image();
|
|
30
32
|
targetImage.src = dataUrl;
|
|
@@ -36,7 +38,7 @@ export function copyTextureToImage(
|
|
|
36
38
|
* Reads pixels from a Framebuffer or Texture object to a dataUrl
|
|
37
39
|
* @todo - can we move this to @luma.gl/core?
|
|
38
40
|
* @param source texture or framebuffer to read from
|
|
39
|
-
* @param options
|
|
41
|
+
* @param options
|
|
40
42
|
*/
|
|
41
43
|
export function copyTextureToDataUrl(
|
|
42
44
|
source: Texture | Framebuffer,
|
|
@@ -10,7 +10,21 @@ let ctx: CanvasRenderingContext2D | null = null;
|
|
|
10
10
|
// eslint-disable-next-line
|
|
11
11
|
export function debugFramebuffer(
|
|
12
12
|
fbo: Framebuffer | Texture,
|
|
13
|
-
{
|
|
13
|
+
{
|
|
14
|
+
id,
|
|
15
|
+
minimap,
|
|
16
|
+
opaque,
|
|
17
|
+
top = '0',
|
|
18
|
+
left = '0',
|
|
19
|
+
rgbaScale = 1
|
|
20
|
+
}: {
|
|
21
|
+
id: string;
|
|
22
|
+
minimap?: boolean;
|
|
23
|
+
opaque?: boolean;
|
|
24
|
+
top?: string;
|
|
25
|
+
left?: string;
|
|
26
|
+
rgbaScale?: number;
|
|
27
|
+
}
|
|
14
28
|
) {
|
|
15
29
|
if (!canvas) {
|
|
16
30
|
canvas = document.createElement('canvas');
|
|
@@ -34,7 +48,6 @@ export function debugFramebuffer(
|
|
|
34
48
|
canvas.height = fbo.height / 2;
|
|
35
49
|
canvas.style.width = '400px';
|
|
36
50
|
canvas.style.height = '400px';
|
|
37
|
-
|
|
38
51
|
}
|
|
39
52
|
|
|
40
53
|
// const image = copyTextureToImage(fbo, {targetMaxHeight: 100, targetImage});
|
|
@@ -54,4 +67,4 @@ export function debugFramebuffer(
|
|
|
54
67
|
imageData.data[offset + i + 3] = opaque ? 255 : color[i + 3] * rgbaScale;
|
|
55
68
|
}
|
|
56
69
|
ctx.putImageData(imageData, 0, 0);
|
|
57
|
-
}
|
|
70
|
+
}
|
|
@@ -8,7 +8,7 @@ import type {ShaderLayout} from '@luma.gl/core';
|
|
|
8
8
|
* Extracts a table suitable for `console.table()` from a shader layout to assist in debugging.
|
|
9
9
|
* @param layout shader layout
|
|
10
10
|
* @param name app should provide the most meaningful name, usually the model or pipeline name / id.
|
|
11
|
-
* @returns
|
|
11
|
+
* @returns
|
|
12
12
|
*/
|
|
13
13
|
export function getDebugTableForShaderLayout(
|
|
14
14
|
layout: ShaderLayout,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import {TypedArray} from '@luma.gl/core';
|
|
@@ -33,11 +34,7 @@ export function flipRows(options: {
|
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
export function scalePixels(options: {
|
|
37
|
-
data: TypedArray;
|
|
38
|
-
width: number;
|
|
39
|
-
height: number;
|
|
40
|
-
}): {
|
|
37
|
+
export function scalePixels(options: {data: TypedArray; width: number; height: number}): {
|
|
41
38
|
data: Uint8Array;
|
|
42
39
|
width: number;
|
|
43
40
|
height: number;
|
|
@@ -11,19 +11,23 @@ export type CubeGeometryProps = {
|
|
|
11
11
|
export class CubeGeometry extends Geometry {
|
|
12
12
|
constructor(props: CubeGeometryProps = {}) {
|
|
13
13
|
const {id = uid('cube-geometry'), indices = true} = props;
|
|
14
|
-
super(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
super(
|
|
15
|
+
indices
|
|
16
|
+
? {
|
|
17
|
+
...props,
|
|
18
|
+
id,
|
|
19
|
+
topology: 'triangle-list',
|
|
20
|
+
indices: {size: 1, value: CUBE_INDICES},
|
|
21
|
+
attributes: {...ATTRIBUTES, ...props.attributes}
|
|
22
|
+
}
|
|
23
|
+
: {
|
|
24
|
+
...props,
|
|
25
|
+
id,
|
|
26
|
+
topology: 'triangle-list',
|
|
27
|
+
indices: undefined,
|
|
28
|
+
attributes: {...NON_INDEXED_ATTRIBUTES, ...props.attributes}
|
|
29
|
+
}
|
|
30
|
+
);
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
|
|
@@ -36,7 +36,8 @@ export class TruncatedConeGeometry extends Geometry {
|
|
|
36
36
|
POSITION: {size: 3, value: attributes.POSITION},
|
|
37
37
|
NORMAL: {size: 3, value: attributes.NORMAL},
|
|
38
38
|
TEXCOORD_0: {size: 2, value: attributes.TEXCOORD_0},
|
|
39
|
-
...props.attributes
|
|
39
|
+
...props.attributes
|
|
40
|
+
}
|
|
40
41
|
});
|
|
41
42
|
}
|
|
42
43
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
2
5
|
import type {TypedArray, VertexFormat} from '@luma.gl/core';
|
|
3
6
|
|
|
4
7
|
/** Holds one geometry */
|
|
@@ -6,11 +9,11 @@ export type GeometryTable = {
|
|
|
6
9
|
length: number;
|
|
7
10
|
schema?: Record<string, VertexFormat>;
|
|
8
11
|
attributes: {
|
|
9
|
-
POSITION: TypedArray
|
|
10
|
-
NORMAL: TypedArray
|
|
11
|
-
TEXCOORD_0: TypedArray
|
|
12
|
-
[key: string]: TypedArray
|
|
12
|
+
POSITION: TypedArray;
|
|
13
|
+
NORMAL: TypedArray;
|
|
14
|
+
TEXCOORD_0: TypedArray;
|
|
15
|
+
[key: string]: TypedArray;
|
|
13
16
|
};
|
|
14
17
|
indices?: Uint16Array | Uint32Array;
|
|
15
18
|
topology?: 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip';
|
|
16
|
-
}
|
|
19
|
+
};
|
package/src/geometry/geometry.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
// luma.gl
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
2
5
|
import type {PrimitiveTopology, TypedArray} from '@luma.gl/core';
|
|
3
6
|
import {uid, assert} from '@luma.gl/core';
|
|
4
7
|
|
|
@@ -98,7 +101,7 @@ export class Geometry {
|
|
|
98
101
|
return this.vertexCount;
|
|
99
102
|
}
|
|
100
103
|
|
|
101
|
-
/**
|
|
104
|
+
/**
|
|
102
105
|
* Return an object with all attributes plus indices added as a field.
|
|
103
106
|
* TODO Geometry types are a mess
|
|
104
107
|
*/
|
|
@@ -118,10 +121,10 @@ export class Geometry {
|
|
|
118
121
|
* type: indices, vertices, uvs
|
|
119
122
|
* size: elements per vertex
|
|
120
123
|
* target: WebGL buffer type (string or constant)
|
|
121
|
-
*
|
|
122
|
-
* @param attributes
|
|
123
|
-
* @param indices
|
|
124
|
-
* @returns
|
|
124
|
+
*
|
|
125
|
+
* @param attributes
|
|
126
|
+
* @param indices
|
|
127
|
+
* @returns
|
|
125
128
|
*/
|
|
126
129
|
_setAttributes(attributes: Record<string, GeometryAttribute>, indices: any): this {
|
|
127
130
|
return this;
|
|
@@ -101,7 +101,7 @@ export function getIndexBufferFromGeometry(device: Device, geometry: Geometry):
|
|
|
101
101
|
export function getAttributeBuffersFromGeometry(
|
|
102
102
|
device: Device,
|
|
103
103
|
geometry: Geometry
|
|
104
|
-
): {attributes: Record<string, Buffer
|
|
104
|
+
): {attributes: Record<string, Buffer>; bufferLayout: BufferLayout[]; vertexCount: number} {
|
|
105
105
|
const bufferLayout: BufferLayout[] = [];
|
|
106
106
|
|
|
107
107
|
const attributes: Record<string, Buffer> = {};
|
|
@@ -109,17 +109,25 @@ export function getAttributeBuffersFromGeometry(
|
|
|
109
109
|
let name: string = attributeName;
|
|
110
110
|
// TODO Map some GLTF attribute names (is this still needed?)
|
|
111
111
|
switch (attributeName) {
|
|
112
|
-
case 'POSITION':
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
case '
|
|
112
|
+
case 'POSITION':
|
|
113
|
+
name = 'positions';
|
|
114
|
+
break;
|
|
115
|
+
case 'NORMAL':
|
|
116
|
+
name = 'normals';
|
|
117
|
+
break;
|
|
118
|
+
case 'TEXCOORD_0':
|
|
119
|
+
name = 'texCoords';
|
|
120
|
+
break;
|
|
121
|
+
case 'COLOR_0':
|
|
122
|
+
name = 'colors';
|
|
123
|
+
break;
|
|
116
124
|
}
|
|
117
125
|
attributes[name] = device.createBuffer({data: attribute.value, id: `${attributeName}-buffer`});
|
|
118
126
|
const {value, size, normalized} = attribute;
|
|
119
127
|
bufferLayout.push({name, format: getVertexFormatFromAttribute(value, size, normalized)});
|
|
120
128
|
}
|
|
121
129
|
|
|
122
|
-
const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices)
|
|
130
|
+
const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices);
|
|
123
131
|
|
|
124
132
|
return {attributes, bufferLayout, vertexCount};
|
|
125
133
|
}
|
package/src/index.ts
CHANGED
|
@@ -23,6 +23,7 @@ export type {TextureTransformProps} from './transform/texture-transform';
|
|
|
23
23
|
export {TextureTransform} from './transform/texture-transform';
|
|
24
24
|
|
|
25
25
|
export {PipelineFactory} from './lib/pipeline-factory';
|
|
26
|
+
export {ShaderFactory} from './lib/shader-factory';
|
|
26
27
|
|
|
27
28
|
// Utils
|
|
28
29
|
export {ClipSpace} from './lib/clip-space';
|
package/src/lib/clip-space.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
// ClipSpace
|
|
3
2
|
import {Device, glsl} from '@luma.gl/core';
|
|
4
3
|
import {Model, ModelProps} from '../model/model';
|
|
@@ -30,24 +29,21 @@ const POSITIONS = [-1, -1, 1, -1, -1, 1, 1, 1];
|
|
|
30
29
|
*/
|
|
31
30
|
export class ClipSpace extends Model {
|
|
32
31
|
constructor(device: Device, opts: Omit<ModelProps, 'vs' | 'vertexCount' | 'geometry'>) {
|
|
33
|
-
const TEX_COORDS = POSITIONS.map(
|
|
32
|
+
const TEX_COORDS = POSITIONS.map(coord => (coord === -1 ? 0 : coord));
|
|
34
33
|
|
|
35
|
-
super(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
super(device, {
|
|
35
|
+
...opts,
|
|
36
|
+
vs: CLIPSPACE_VERTEX_SHADER,
|
|
37
|
+
vertexCount: 4,
|
|
38
|
+
geometry: new Geometry({
|
|
39
|
+
topology: 'triangle-strip',
|
|
40
40
|
vertexCount: 4,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
);
|
|
41
|
+
attributes: {
|
|
42
|
+
aClipSpacePosition: {size: 2, value: new Float32Array(POSITIONS)},
|
|
43
|
+
aTexCoord: {size: 2, value: new Float32Array(TEX_COORDS)},
|
|
44
|
+
aCoordinate: {size: 2, value: new Float32Array(TEX_COORDS)}
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
});
|
|
52
48
|
}
|
|
53
49
|
}
|