@luma.gl/engine 9.0.0-alpha.9 → 9.0.0-beta.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.
- package/LICENSE +3 -1
- package/dist/animation/key-frames.d.ts +1 -1
- package/dist/animation/key-frames.d.ts.map +1 -1
- package/dist/animation/key-frames.js +6 -27
- package/dist/animation/key-frames.js.map +1 -1
- package/dist/animation/timeline.d.ts +8 -8
- package/dist/animation/timeline.d.ts.map +1 -1
- package/dist/animation/timeline.js +18 -49
- package/dist/animation/timeline.js.map +1 -1
- package/dist/animation-loop/animation-loop-template.d.ts +23 -0
- package/dist/animation-loop/animation-loop-template.d.ts.map +1 -0
- package/dist/animation-loop/animation-loop-template.js +7 -0
- package/dist/animation-loop/animation-loop-template.js.map +1 -0
- package/dist/{lib → animation-loop}/animation-loop.d.ts +30 -22
- package/dist/animation-loop/animation-loop.d.ts.map +1 -0
- package/dist/{lib → animation-loop}/animation-loop.js +77 -192
- package/dist/animation-loop/animation-loop.js.map +1 -0
- package/dist/{lib → animation-loop}/animation-props.d.ts +2 -3
- package/dist/animation-loop/animation-props.d.ts.map +1 -0
- package/dist/animation-loop/animation-props.js.map +1 -0
- package/dist/animation-loop/make-animation-loop.d.ts +6 -0
- package/dist/animation-loop/make-animation-loop.d.ts.map +1 -0
- package/dist/animation-loop/make-animation-loop.js +28 -0
- package/dist/animation-loop/make-animation-loop.js.map +1 -0
- package/dist/debug/copy-texture-to-image.d.ts +26 -0
- package/dist/debug/copy-texture-to-image.d.ts.map +1 -0
- package/dist/debug/copy-texture-to-image.js +46 -0
- package/dist/debug/copy-texture-to-image.js.map +1 -0
- package/dist/debug/debug-framebuffer.d.ts +11 -0
- package/dist/debug/debug-framebuffer.d.ts.map +1 -0
- package/dist/debug/debug-framebuffer.js +43 -0
- package/dist/debug/debug-framebuffer.js.map +1 -0
- package/dist/debug/debug-shader-layout.d.ts +9 -0
- package/dist/debug/debug-shader-layout.d.ts.map +1 -0
- package/dist/debug/debug-shader-layout.js +28 -0
- package/dist/debug/debug-shader-layout.js.map +1 -0
- package/dist/debug/pixel-data-utils.d.ts +24 -0
- package/dist/debug/pixel-data-utils.d.ts.map +1 -0
- package/dist/debug/pixel-data-utils.js +41 -0
- package/dist/debug/pixel-data-utils.js.map +1 -0
- package/dist/dist.dev.js +10081 -0
- 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 +6 -5
- package/dist/geometries/cone-geometry.js.map +1 -1
- package/dist/geometries/cube-geometry.d.ts +2 -2
- package/dist/geometries/cube-geometry.d.ts.map +1 -1
- package/dist/geometries/cube-geometry.js +16 -10
- package/dist/geometries/cube-geometry.js.map +1 -1
- 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 +6 -5
- package/dist/geometries/cylinder-geometry.js.map +1 -1
- package/dist/geometries/ico-sphere-geometry.d.ts +2 -2
- package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/ico-sphere-geometry.js +10 -19
- package/dist/geometries/ico-sphere-geometry.js.map +1 -1
- package/dist/geometries/plane-geometry.d.ts +2 -2
- package/dist/geometries/plane-geometry.d.ts.map +1 -1
- package/dist/geometries/plane-geometry.js +14 -23
- package/dist/geometries/plane-geometry.js.map +1 -1
- package/dist/geometries/sphere-geometry.d.ts +2 -2
- package/dist/geometries/sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/sphere-geometry.js +9 -13
- package/dist/geometries/sphere-geometry.js.map +1 -1
- package/dist/geometries/truncated-cone-geometry.d.ts +2 -4
- package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
- package/dist/geometries/truncated-cone-geometry.js +9 -25
- package/dist/geometries/truncated-cone-geometry.js.map +1 -1
- package/dist/geometry/geometry-table.d.ts +2 -2
- package/dist/geometry/geometry-table.d.ts.map +1 -1
- package/dist/geometry/geometry-table.js.map +1 -1
- package/dist/geometry/geometry-utils.d.ts.map +1 -1
- package/dist/geometry/geometry-utils.js +0 -9
- package/dist/geometry/geometry-utils.js.map +1 -1
- package/dist/geometry/geometry.d.ts +43 -43
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +20 -86
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/geometry/gpu-geometry.d.ts +37 -0
- package/dist/geometry/gpu-geometry.d.ts.map +1 -0
- package/dist/geometry/gpu-geometry.js +110 -0
- package/dist/geometry/gpu-geometry.js.map +1 -0
- package/dist/geometry/gpu-table.d.ts +1 -0
- package/dist/geometry/gpu-table.d.ts.map +1 -0
- package/dist/geometry/gpu-table.js +2 -0
- package/dist/geometry/gpu-table.js.map +1 -0
- package/dist/index.cjs +3128 -0
- package/dist/index.d.ts +24 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -14
- package/dist/index.js.map +1 -1
- package/dist/lib/clip-space.d.ts +8 -0
- package/dist/lib/clip-space.d.ts.map +1 -1
- package/dist/lib/clip-space.js +47 -0
- package/dist/lib/clip-space.js.map +1 -1
- package/dist/lib/pipeline-factory.d.ts +12 -45
- package/dist/lib/pipeline-factory.d.ts.map +1 -1
- package/dist/lib/pipeline-factory.js +42 -168
- package/dist/lib/pipeline-factory.js.map +1 -1
- package/dist/model/model.d.ts +206 -0
- package/dist/model/model.d.ts.map +1 -0
- package/dist/model/model.js +435 -0
- package/dist/model/model.js.map +1 -0
- package/dist/scenegraph/group-node.d.ts +21 -0
- package/dist/scenegraph/group-node.d.ts.map +1 -0
- package/dist/scenegraph/group-node.js +94 -0
- package/dist/scenegraph/group-node.js.map +1 -0
- package/dist/scenegraph/model-node.d.ts +18 -0
- package/dist/scenegraph/model-node.d.ts.map +1 -0
- package/dist/scenegraph/model-node.js +28 -0
- package/dist/scenegraph/model-node.js.map +1 -0
- package/dist/scenegraph/scenegraph-node.d.ts +56 -0
- package/dist/scenegraph/scenegraph-node.d.ts.map +1 -0
- package/dist/scenegraph/scenegraph-node.js +141 -0
- package/dist/scenegraph/scenegraph-node.js.map +1 -0
- package/dist/shader-inputs.d.ts +63 -0
- package/dist/shader-inputs.d.ts.map +1 -0
- package/dist/shader-inputs.js +66 -0
- package/dist/shader-inputs.js.map +1 -0
- package/dist/transform/buffer-transform.d.ts +35 -0
- package/dist/transform/buffer-transform.d.ts.map +1 -0
- package/dist/transform/buffer-transform.js +62 -0
- package/dist/transform/buffer-transform.js.map +1 -0
- package/dist/transform/texture-transform.d.ts +57 -0
- package/dist/transform/texture-transform.d.ts.map +1 -0
- package/dist/transform/texture-transform.js +122 -0
- package/dist/transform/texture-transform.js.map +1 -0
- package/dist.min.js +293 -0
- package/package.json +21 -12
- package/src/animation/timeline.ts +15 -14
- package/src/animation-loop/animation-loop-template.ts +23 -0
- package/src/{lib → animation-loop}/animation-loop.ts +99 -88
- package/src/{lib → animation-loop}/animation-props.ts +1 -1
- package/src/animation-loop/make-animation-loop.ts +44 -0
- package/src/debug/copy-texture-to-image.ts +72 -0
- package/src/debug/debug-framebuffer.ts +57 -0
- package/src/debug/debug-shader-layout.ts +38 -0
- package/src/debug/pixel-data-utils.ts +57 -0
- package/src/geometries/cone-geometry.ts +1 -1
- package/src/geometries/cube-geometry.ts +47 -45
- package/src/geometries/cylinder-geometry.ts +2 -2
- package/src/geometries/ico-sphere-geometry.ts +6 -5
- package/src/geometries/plane-geometry.ts +5 -4
- package/src/geometries/sphere-geometry.ts +4 -3
- package/src/geometries/truncated-cone-geometry.ts +4 -13
- package/src/geometry/geometry-table.ts +1 -1
- package/src/geometry/geometry-utils.ts +3 -3
- package/src/geometry/geometry.ts +65 -110
- package/src/geometry/gpu-geometry.ts +125 -0
- package/src/geometry/gpu-table.ts +41 -0
- package/src/index.ts +34 -10
- package/src/lib/clip-space.ts +22 -21
- package/src/lib/pipeline-factory.ts +51 -168
- package/src/model/model.ts +726 -0
- package/src/scenegraph/group-node.ts +103 -0
- package/src/scenegraph/model-node.ts +50 -0
- package/src/scenegraph/scenegraph-node.ts +204 -0
- package/src/shader-inputs.ts +150 -0
- package/src/transform/buffer-transform.ts +94 -0
- package/src/transform/texture-transform.ts +169 -0
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/bundle.js +0 -5
- package/dist/bundle.js.map +0 -1
- package/dist/geometry/primitive-utils.d.ts +0 -1
- package/dist/geometry/primitive-utils.d.ts.map +0 -1
- package/dist/geometry/primitive-utils.js +0 -2
- package/dist/geometry/primitive-utils.js.map +0 -1
- package/dist/lib/animation-loop.d.ts.map +0 -1
- package/dist/lib/animation-loop.js.map +0 -1
- package/dist/lib/animation-props.d.ts.map +0 -1
- package/dist/lib/animation-props.js.map +0 -1
- package/dist/lib/model-utils.d.ts +0 -5
- package/dist/lib/model-utils.d.ts.map +0 -1
- package/dist/lib/model-utils.js +0 -45
- package/dist/lib/model-utils.js.map +0 -1
- package/dist/lib/model.d.ts +0 -41
- package/dist/lib/model.d.ts.map +0 -1
- package/dist/lib/model.js +0 -182
- package/dist/lib/model.js.map +0 -1
- package/dist/lib/render-loop.d.ts +0 -14
- package/dist/lib/render-loop.d.ts.map +0 -1
- package/dist/lib/render-loop.js +0 -49
- package/dist/lib/render-loop.js.map +0 -1
- package/src/bundle.ts +0 -4
- package/src/geometry/primitive-utils.ts +0 -30
- package/src/lib/model-utils.ts +0 -124
- package/src/lib/model.ts +0 -183
- package/src/lib/render-loop.ts +0 -58
- /package/dist/{lib → animation-loop}/animation-props.js +0 -0
package/dist/lib/render-loop.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
import { AnimationLoop } from './animation-loop';
|
|
3
|
-
export class RenderLoop {
|
|
4
|
-
constructor(animationProps) {}
|
|
5
|
-
|
|
6
|
-
static run(RenderLoopConstructor, deviceProps) {
|
|
7
|
-
const animationLoop = new SyncInitAnimationLoop(RenderLoopConstructor, deviceProps);
|
|
8
|
-
return animationLoop;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
class SyncInitAnimationLoop extends AnimationLoop {
|
|
14
|
-
getInfo() {
|
|
15
|
-
return this.RenderLoopConstructor.info;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
constructor(RenderLoopConstructor, deviceProps) {
|
|
19
|
-
super({
|
|
20
|
-
deviceProps
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
_defineProperty(this, "RenderLoopConstructor", void 0);
|
|
24
|
-
|
|
25
|
-
_defineProperty(this, "renderLoop", null);
|
|
26
|
-
|
|
27
|
-
this.RenderLoopConstructor = RenderLoopConstructor;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
onInitialize(animationProps) {
|
|
31
|
-
this.renderLoop = new this.RenderLoopConstructor(animationProps);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
onRender(animationProps) {
|
|
35
|
-
var _this$renderLoop, _this$renderLoop$onRe, _this$renderLoop2, _this$renderLoop2$fra;
|
|
36
|
-
|
|
37
|
-
(_this$renderLoop = this.renderLoop) === null || _this$renderLoop === void 0 ? void 0 : (_this$renderLoop$onRe = _this$renderLoop.onRender) === null || _this$renderLoop$onRe === void 0 ? void 0 : _this$renderLoop$onRe.call(_this$renderLoop, animationProps);
|
|
38
|
-
(_this$renderLoop2 = this.renderLoop) === null || _this$renderLoop2 === void 0 ? void 0 : (_this$renderLoop2$fra = _this$renderLoop2.frame) === null || _this$renderLoop2$fra === void 0 ? void 0 : _this$renderLoop2$fra.call(_this$renderLoop2, animationProps);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
onFinalize(animationProps) {
|
|
42
|
-
var _this$renderLoop3, _this$renderLoop3$onF, _this$renderLoop4, _this$renderLoop4$des;
|
|
43
|
-
|
|
44
|
-
(_this$renderLoop3 = this.renderLoop) === null || _this$renderLoop3 === void 0 ? void 0 : (_this$renderLoop3$onF = _this$renderLoop3.onFinalize) === null || _this$renderLoop3$onF === void 0 ? void 0 : _this$renderLoop3$onF.call(_this$renderLoop3, animationProps);
|
|
45
|
-
(_this$renderLoop4 = this.renderLoop) === null || _this$renderLoop4 === void 0 ? void 0 : (_this$renderLoop4$des = _this$renderLoop4.destroy) === null || _this$renderLoop4$des === void 0 ? void 0 : _this$renderLoop4$des.call(_this$renderLoop4, animationProps);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
//# sourceMappingURL=render-loop.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/render-loop.ts"],"names":["AnimationLoop","RenderLoop","constructor","animationProps","run","RenderLoopConstructor","deviceProps","animationLoop","SyncInitAnimationLoop","getInfo","info","onInitialize","renderLoop","onRender","frame","onFinalize","destroy"],"mappings":";AAEA,SAAQA,aAAR,QAA4B,kBAA5B;AAOA,OAAO,MAAeC,UAAf,CAA0B;AAC/BC,EAAAA,WAAW,CAACC,cAAD,EAAkC,CAAE;;AAGrC,SAAHC,GAAG,CAACC,qBAAD,EAA2CC,WAA3C,EAAqF;AAE7F,UAAMC,aAAa,GAAG,IAAIC,qBAAJ,CAA0BH,qBAA1B,EAAiDC,WAAjD,CAAtB;AAKA,WAAOC,aAAP;AACD;;AAZ8B;;AAgBjC,MAAMC,qBAAN,SAAoCR,aAApC,CAAkD;AAIhDS,EAAAA,OAAO,GAAG;AAER,WAAO,KAAKJ,qBAAL,CAA2BK,IAAlC;AACD;;AAEDR,EAAAA,WAAW,CAACG,qBAAD,EAA2CC,WAA3C,EAAsE;AAC/E,UAAM;AAACA,MAAAA;AAAD,KAAN;;AAD+E;;AAAA,wCAPjD,IAOiD;;AAE/E,SAAKD,qBAAL,GAA6BA,qBAA7B;AACD;;AAEDM,EAAAA,YAAY,CAACR,cAAD,EAAiC;AAE3C,SAAKS,UAAL,GAAkB,IAAI,KAAKP,qBAAT,CAA+BF,cAA/B,CAAlB;AACD;;AAEDU,EAAAA,QAAQ,CAACV,cAAD,EAAiC;AAAA;;AAEvC,6BAAKS,UAAL,+FAAiBC,QAAjB,uGAA4BV,cAA5B;AAEA,8BAAKS,UAAL,iGAAiBE,KAAjB,wGAAyBX,cAAzB;AACD;;AAEDY,EAAAA,UAAU,CAACZ,cAAD,EAAiC;AAAA;;AAEzC,8BAAKS,UAAL,iGAAiBG,UAAjB,wGAA8BZ,cAA9B;AAEA,8BAAKS,UAAL,iGAAiBI,OAAjB,wGAA2Bb,cAA3B;AACD;;AA/B+C","sourcesContent":["import type {DeviceProps} from '@luma.gl/api';\nimport type {AnimationProps} from '../lib/animation-props';\nimport {AnimationLoop} from './animation-loop';\n\n/**\n * Minimal animation loop that initializes models in constructor\n * Simplifying type management\n * v9 API\n */\nexport abstract class RenderLoop {\n constructor(animationProps?: AnimationProps) {}\n\n /** Instantiates and runs the render loop */\n static run(RenderLoopConstructor: typeof RenderLoop, deviceProps?: DeviceProps): AnimationLoop {\n // Create an animation loop;\n const animationLoop = new SyncInitAnimationLoop(RenderLoopConstructor, deviceProps);\n\n // Start the loop automatically\n // animationLoop.start();\n\n return animationLoop;\n }\n}\n\n/** Instantiates the RenderLoop once the device is created */\nclass SyncInitAnimationLoop extends AnimationLoop {\n RenderLoopConstructor: typeof RenderLoop;\n renderLoop: RenderLoop | null = null;\n\n getInfo() {\n // @ts-ignore\n return this.RenderLoopConstructor.info;\n }\n\n constructor(RenderLoopConstructor: typeof RenderLoop, deviceProps?: DeviceProps) {\n super({deviceProps});\n this.RenderLoopConstructor = RenderLoopConstructor;\n }\n\n onInitialize(animationProps: AnimationProps) {\n // @ts-expect-error abstract to prevent instantiation\n this.renderLoop = new this.RenderLoopConstructor(animationProps);\n }\n\n onRender(animationProps: AnimationProps) {\n // @ts-expect-error API still TBD\n this.renderLoop?.onRender?.(animationProps);\n // @ts-expect-error API still TBD\n this.renderLoop?.frame?.(animationProps);\n }\n\n onFinalize(animationProps: AnimationProps) {\n // @ts-expect-error API still TBD\n this.renderLoop?.onFinalize?.(animationProps);\n // @ts-expect-error API still TBD\n this.renderLoop?.destroy?.(animationProps);\n }\n}\n"],"file":"render-loop.js"}
|
package/src/bundle.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
import type {GeometryTable} from './geometry-table';
|
|
3
|
-
|
|
4
|
-
export function unpackIndexedGeometry(geometry: GeometryTable): GeometryTable {
|
|
5
|
-
const {indices, attributes} = geometry;
|
|
6
|
-
if (!indices) {
|
|
7
|
-
return geometry;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const vertexCount = indices.length;
|
|
11
|
-
const unpackedAttributes = {};
|
|
12
|
-
|
|
13
|
-
for (const [name, values] of Object.entries(attributes)) {
|
|
14
|
-
const size = {POSITION: 3, NORMAL: 3, TEX_COORD0: 2}[name];
|
|
15
|
-
const unpackedValues = new values.constructor(length * size);
|
|
16
|
-
for (let x = 0; x < vertexCount; ++x) {
|
|
17
|
-
const index = indices[x];
|
|
18
|
-
for (let i = 0; i < size; i++) {
|
|
19
|
-
unpackedValues[x * size + i] = values[index * size + i];
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
unpackedAttributes[name] = unpackedValues;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
length,
|
|
27
|
-
attributes: unpackedAttributes
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
*/
|
package/src/lib/model-utils.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import {Device, Buffer, assert} from '@luma.gl/api';
|
|
2
|
-
import type Geometry from '../geometry/geometry';
|
|
3
|
-
|
|
4
|
-
// Support for mapping new geometries with glTF attribute names to "classic" luma.gl shader names
|
|
5
|
-
const GLTF_TO_LUMA_ATTRIBUTE_MAP = {
|
|
6
|
-
POSITION: 'positions',
|
|
7
|
-
NORMAL: 'normals',
|
|
8
|
-
COLOR_0: 'colors',
|
|
9
|
-
TEXCOORD_0: 'texCoords',
|
|
10
|
-
TEXCOORD_1: 'texCoords1',
|
|
11
|
-
TEXCOORD_2: 'texCoords2'
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/*
|
|
15
|
-
export function getAttributeLayoutsFromGeometry(geometry: Geometry) {
|
|
16
|
-
const layouts: Record<string, {}> = {};
|
|
17
|
-
let indices = geometry.indices;
|
|
18
|
-
|
|
19
|
-
for (const [name, attribute] of Object.entries(geometry.attributes)) {
|
|
20
|
-
const remappedName = mapAttributeName(name);
|
|
21
|
-
|
|
22
|
-
if (attribute.constant) {
|
|
23
|
-
throw new Error('constant attributes not supported');
|
|
24
|
-
} else {
|
|
25
|
-
const typedArray = attribute.value;
|
|
26
|
-
// Create accessor by copying the attribute and removing `value``
|
|
27
|
-
const accessor = {...attribute};
|
|
28
|
-
delete accessor.value;
|
|
29
|
-
buffers[remappedName] = [device.createBuffer(typedArray), accessor];
|
|
30
|
-
|
|
31
|
-
inferAttributeAccessor(name, accessor);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export class Table {
|
|
37
|
-
length: number;
|
|
38
|
-
// columns: Record<string, TypedArray> = {};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export class GPUTable {
|
|
42
|
-
length: number;
|
|
43
|
-
columns: Record<string, Buffer> = {};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function convertTableToGPUTable(table: Table) {
|
|
47
|
-
// for (const ) {}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function renameTableColumns(table: Table, map: (name: string) => string) {
|
|
51
|
-
const newColumns = table.columns.reduce()
|
|
52
|
-
table.clone();
|
|
53
|
-
}
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
export function getIndexBufferFromGeometry(device: Device, geometry: Geometry): Buffer | undefined {
|
|
57
|
-
if (!geometry.indices) {
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// @ts-expect-error
|
|
62
|
-
const data = geometry.indices.value || geometry.indices;
|
|
63
|
-
assert(
|
|
64
|
-
data instanceof Uint16Array || data instanceof Uint32Array,
|
|
65
|
-
'attribute array for "indices" must be of integer type'
|
|
66
|
-
);
|
|
67
|
-
return device.createBuffer({usage: Buffer.INDEX, data});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function getAttributeBuffersFromGeometry(device: Device, geometry: Geometry): Record<string, Buffer> {
|
|
71
|
-
const buffers: Record<string, Buffer> = {};
|
|
72
|
-
|
|
73
|
-
for (const [name, attribute] of Object.entries(geometry.attributes)) {
|
|
74
|
-
const remappedName = mapAttributeName(name);
|
|
75
|
-
if (attribute.constant) {
|
|
76
|
-
throw new Error('constant attributes not supported');
|
|
77
|
-
} else {
|
|
78
|
-
const typedArray = attribute.value;
|
|
79
|
-
buffers[remappedName] = device.createBuffer({data: typedArray, id: `${remappedName}-buffer`});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return buffers;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function mapAttributeName(name: string): string {
|
|
87
|
-
return GLTF_TO_LUMA_ATTRIBUTE_MAP[name] || name;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/*
|
|
91
|
-
// Check for well known attribute names
|
|
92
|
-
// eslint-disable-next-line complexity
|
|
93
|
-
export function inferAttributeAccessor(attributeName, attribute) {
|
|
94
|
-
let category;
|
|
95
|
-
switch (attributeName) {
|
|
96
|
-
case 'texCoords':
|
|
97
|
-
case 'texCoord1':
|
|
98
|
-
case 'texCoord2':
|
|
99
|
-
case 'texCoord3':
|
|
100
|
-
category = 'uvs';
|
|
101
|
-
break;
|
|
102
|
-
case 'vertices':
|
|
103
|
-
case 'positions':
|
|
104
|
-
case 'normals':
|
|
105
|
-
case 'pickingColors':
|
|
106
|
-
category = 'vectors';
|
|
107
|
-
break;
|
|
108
|
-
default:
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Check for categorys
|
|
112
|
-
switch (category) {
|
|
113
|
-
case 'vectors':
|
|
114
|
-
attribute.size = attribute.size || 3;
|
|
115
|
-
break;
|
|
116
|
-
case 'uvs':
|
|
117
|
-
attribute.size = attribute.size || 2;
|
|
118
|
-
break;
|
|
119
|
-
default:
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
assert(Number.isFinite(attribute.size), `attribute ${attributeName} needs size`);
|
|
123
|
-
}
|
|
124
|
-
*/
|
package/src/lib/model.ts
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
// luma.gl, MIT license
|
|
2
|
-
|
|
3
|
-
import type {Device, Buffer, RenderPipelineProps, RenderPass, Binding, PrimitiveTopology} from '@luma.gl/api';
|
|
4
|
-
import {RenderPipeline, Shader, cast} from '@luma.gl/api';
|
|
5
|
-
import type { ShaderModule } from '@luma.gl/shadertools';
|
|
6
|
-
import type Geometry from '../geometry/geometry';
|
|
7
|
-
import {getAttributeBuffersFromGeometry, getIndexBufferFromGeometry} from './model-utils';
|
|
8
|
-
import {PipelineFactory} from './pipeline-factory';
|
|
9
|
-
|
|
10
|
-
export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs'> & {
|
|
11
|
-
// Model also accepts a string
|
|
12
|
-
vs?: {glsl?: string; wgsl?: string} | string | null;
|
|
13
|
-
fs?: {glsl?: string; wgsl?: string} | string | null;
|
|
14
|
-
modules?: ShaderModule[];
|
|
15
|
-
moduleSettings?: Record<string, Record<string, any>>;
|
|
16
|
-
geometry?: Geometry | null;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const DEFAULT_MODEL_PROPS: Required<ModelProps> = {
|
|
20
|
-
...RenderPipeline._DEFAULT_PROPS,
|
|
21
|
-
vs: null,
|
|
22
|
-
fs: null,
|
|
23
|
-
id: 'unnamed',
|
|
24
|
-
handle: undefined,
|
|
25
|
-
userData: {},
|
|
26
|
-
modules: [],
|
|
27
|
-
moduleSettings: {},
|
|
28
|
-
geometry: null
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/** v9 API */
|
|
32
|
-
export default class Model {
|
|
33
|
-
readonly device: Device;
|
|
34
|
-
readonly pipeline: RenderPipeline;
|
|
35
|
-
readonly id: string;
|
|
36
|
-
readonly vs: string;
|
|
37
|
-
readonly fs: string | null = null;
|
|
38
|
-
readonly topology: PrimitiveTopology;
|
|
39
|
-
readonly vertexCount;
|
|
40
|
-
props: Required<ModelProps>;
|
|
41
|
-
|
|
42
|
-
private _getModuleUniforms: (props?: Record<string, Record<string, any>>) => Record<string, any>;
|
|
43
|
-
|
|
44
|
-
constructor(device: Device, props: ModelProps) {
|
|
45
|
-
this.props = {...DEFAULT_MODEL_PROPS, ...props};
|
|
46
|
-
props = this.props;
|
|
47
|
-
this.id = this.props.id;
|
|
48
|
-
this.device = device;
|
|
49
|
-
|
|
50
|
-
// Create the pipeline
|
|
51
|
-
if (!props.vs) {
|
|
52
|
-
throw new Error('no vertex shader');
|
|
53
|
-
}
|
|
54
|
-
this.vs = getShaderSource(this.device, props.vs);
|
|
55
|
-
if (props.fs) {
|
|
56
|
-
this.fs = getShaderSource(this.device, props.fs);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
this.vertexCount = this.props.vertexCount;
|
|
60
|
-
this.topology = this.props.topology;
|
|
61
|
-
|
|
62
|
-
if (this.props.geometry) {
|
|
63
|
-
this.vertexCount = this.props.geometry.vertexCount;
|
|
64
|
-
this.topology = this.props.geometry.topology || 'triangle-list';
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const pipelineFactory = PipelineFactory.getDefaultPipelineFactory(this.device);
|
|
68
|
-
const {pipeline, getUniforms} = pipelineFactory.createRenderPipeline({
|
|
69
|
-
...this.props,
|
|
70
|
-
vs: this.vs,
|
|
71
|
-
fs: this.fs,
|
|
72
|
-
topology: this.topology,
|
|
73
|
-
parameters: props.parameters,
|
|
74
|
-
layout: props.layout
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
this.pipeline = pipeline;
|
|
78
|
-
this._getModuleUniforms = getUniforms;
|
|
79
|
-
|
|
80
|
-
if (this.props.geometry) {
|
|
81
|
-
this._setGeometry(this.props.geometry);
|
|
82
|
-
}
|
|
83
|
-
this.setUniforms(this._getModuleUniforms()) // Get all default module uniforms
|
|
84
|
-
this.setProps(this.props);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
destroy(): void {
|
|
88
|
-
this.pipeline.destroy();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
draw(renderPass?: RenderPass): this {
|
|
92
|
-
this.pipeline.draw({
|
|
93
|
-
renderPass,
|
|
94
|
-
vertexCount: this.vertexCount,
|
|
95
|
-
instanceCount: this.props.instanceCount
|
|
96
|
-
});
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
setProps(props: ModelProps): this {
|
|
101
|
-
if (props.indices) {
|
|
102
|
-
this.setIndexBuffer(props.indices);
|
|
103
|
-
}
|
|
104
|
-
if (props.attributes) {
|
|
105
|
-
this.setAttributes(props.attributes);
|
|
106
|
-
}
|
|
107
|
-
if (props.bindings) {
|
|
108
|
-
this.setBindings(props.bindings);
|
|
109
|
-
}
|
|
110
|
-
if (props.uniforms) {
|
|
111
|
-
this.setUniforms(props.uniforms);
|
|
112
|
-
}
|
|
113
|
-
if (props.moduleSettings) {
|
|
114
|
-
this.updateModuleSettings(props.moduleSettings);
|
|
115
|
-
}
|
|
116
|
-
return this;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
updateModuleSettings(props: Record<string, any>): this {
|
|
120
|
-
const uniforms = this._getModuleUniforms(props);
|
|
121
|
-
this.setUniforms(uniforms);
|
|
122
|
-
return this;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
setIndexBuffer(indices: Buffer): this {
|
|
126
|
-
this.pipeline.setIndexBuffer(indices);
|
|
127
|
-
// this._indices = indices;
|
|
128
|
-
return this;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
setAttributes(attributes: Record<string, Buffer>): this {
|
|
132
|
-
this.pipeline.setAttributes(attributes);
|
|
133
|
-
Object.assign(this.props.attributes, attributes);
|
|
134
|
-
return this;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/** Set the bindings */
|
|
138
|
-
setBindings(bindings: Record<string, Binding>): this {
|
|
139
|
-
this.pipeline.setBindings(bindings);
|
|
140
|
-
Object.assign(this.props.bindings, bindings);
|
|
141
|
-
return this;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
setUniforms(uniforms: Record<string, any>): this {
|
|
145
|
-
this.pipeline.setUniforms(uniforms);
|
|
146
|
-
Object.assign(this.props.uniforms, uniforms);
|
|
147
|
-
return this;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
_setGeometry(geometry: Geometry): void {
|
|
151
|
-
// this._deleteGeometryBuffers();
|
|
152
|
-
|
|
153
|
-
const geometryBuffers = getAttributeBuffersFromGeometry(this.device, geometry);
|
|
154
|
-
this.setAttributes(geometryBuffers);
|
|
155
|
-
|
|
156
|
-
const indexBuffer = getIndexBufferFromGeometry(this.device, geometry);
|
|
157
|
-
if (indexBuffer) {
|
|
158
|
-
this.setIndexBuffer(indexBuffer);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/** Create a shader from the different overloads */
|
|
164
|
-
function getShaderSource(device: Device, shader: string | {glsl?: string; wgsl?: string}): string {
|
|
165
|
-
// TODO - detect WGSL/GLSL and throw an error if not supported
|
|
166
|
-
if (typeof shader === 'string') {
|
|
167
|
-
return shader;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
switch (device.info.type) {
|
|
171
|
-
case 'webgpu':
|
|
172
|
-
if (shader?.wgsl) {
|
|
173
|
-
return shader.wgsl;
|
|
174
|
-
}
|
|
175
|
-
throw new Error('WebGPU does not support GLSL shaders');
|
|
176
|
-
|
|
177
|
-
default:
|
|
178
|
-
if (shader?.glsl) {
|
|
179
|
-
return shader.glsl;
|
|
180
|
-
}
|
|
181
|
-
throw new Error('WebGL does not support WGSL shaders');
|
|
182
|
-
}
|
|
183
|
-
}
|
package/src/lib/render-loop.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type {DeviceProps} from '@luma.gl/api';
|
|
2
|
-
import type {AnimationProps} from '../lib/animation-props';
|
|
3
|
-
import {AnimationLoop} from './animation-loop';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Minimal animation loop that initializes models in constructor
|
|
7
|
-
* Simplifying type management
|
|
8
|
-
* v9 API
|
|
9
|
-
*/
|
|
10
|
-
export abstract class RenderLoop {
|
|
11
|
-
constructor(animationProps?: AnimationProps) {}
|
|
12
|
-
|
|
13
|
-
/** Instantiates and runs the render loop */
|
|
14
|
-
static run(RenderLoopConstructor: typeof RenderLoop, deviceProps?: DeviceProps): AnimationLoop {
|
|
15
|
-
// Create an animation loop;
|
|
16
|
-
const animationLoop = new SyncInitAnimationLoop(RenderLoopConstructor, deviceProps);
|
|
17
|
-
|
|
18
|
-
// Start the loop automatically
|
|
19
|
-
// animationLoop.start();
|
|
20
|
-
|
|
21
|
-
return animationLoop;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** Instantiates the RenderLoop once the device is created */
|
|
26
|
-
class SyncInitAnimationLoop extends AnimationLoop {
|
|
27
|
-
RenderLoopConstructor: typeof RenderLoop;
|
|
28
|
-
renderLoop: RenderLoop | null = null;
|
|
29
|
-
|
|
30
|
-
getInfo() {
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
return this.RenderLoopConstructor.info;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
constructor(RenderLoopConstructor: typeof RenderLoop, deviceProps?: DeviceProps) {
|
|
36
|
-
super({deviceProps});
|
|
37
|
-
this.RenderLoopConstructor = RenderLoopConstructor;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
onInitialize(animationProps: AnimationProps) {
|
|
41
|
-
// @ts-expect-error abstract to prevent instantiation
|
|
42
|
-
this.renderLoop = new this.RenderLoopConstructor(animationProps);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
onRender(animationProps: AnimationProps) {
|
|
46
|
-
// @ts-expect-error API still TBD
|
|
47
|
-
this.renderLoop?.onRender?.(animationProps);
|
|
48
|
-
// @ts-expect-error API still TBD
|
|
49
|
-
this.renderLoop?.frame?.(animationProps);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
onFinalize(animationProps: AnimationProps) {
|
|
53
|
-
// @ts-expect-error API still TBD
|
|
54
|
-
this.renderLoop?.onFinalize?.(animationProps);
|
|
55
|
-
// @ts-expect-error API still TBD
|
|
56
|
-
this.renderLoop?.destroy?.(animationProps);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
File without changes
|