@luma.gl/engine 9.0.0-alpha.3 → 9.0.0-alpha.31
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 +2 -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 +0 -20
- package/dist/animation/key-frames.js.map +1 -1
- package/dist/animation/timeline.d.ts +5 -5
- package/dist/animation/timeline.d.ts.map +1 -1
- package/dist/animation/timeline.js +0 -30
- package/dist/animation/timeline.js.map +1 -1
- package/dist/{lib → animation-loop}/animation-loop.d.ts +28 -29
- package/dist/animation-loop/animation-loop.d.ts.map +1 -0
- package/dist/{lib → animation-loop}/animation-loop.js +96 -175
- package/dist/animation-loop/animation-loop.js.map +1 -0
- package/dist/{lib → animation-loop}/animation-props.d.ts +7 -7
- 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/animation-loop/render-loop.d.ts +23 -0
- package/dist/animation-loop/render-loop.d.ts.map +1 -0
- package/dist/animation-loop/render-loop.js +7 -0
- package/dist/animation-loop/render-loop.js.map +1 -0
- package/dist/dist.dev.js +14977 -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 +15 -8
- 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 +9 -18
- 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 +10 -19
- 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 -2
- package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
- package/dist/geometries/truncated-cone-geometry.js +9 -14
- 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 +35 -58
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +26 -89
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/geometry/primitive-utils.js.map +1 -1
- package/dist/index.cjs +2576 -0
- package/dist/index.d.ts +18 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -13
- 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 +36 -1
- package/dist/lib/clip-space.js.map +1 -1
- package/dist/lib/pipeline-factory.d.ts +19 -14
- package/dist/lib/pipeline-factory.d.ts.map +1 -1
- package/dist/lib/pipeline-factory.js +52 -63
- package/dist/lib/pipeline-factory.js.map +1 -1
- package/dist/{lib → model}/model-utils.d.ts +2 -2
- package/dist/model/model-utils.d.ts.map +1 -0
- package/dist/{lib → model}/model-utils.js +3 -8
- package/dist/model/model-utils.js.map +1 -0
- package/dist/model/model.d.ts +67 -0
- package/dist/model/model.d.ts.map +1 -0
- package/dist/{lib → model}/model.js +59 -76
- 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 +95 -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 +29 -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 +142 -0
- package/dist/scenegraph/scenegraph-node.js.map +1 -0
- package/dist/transform/transform.d.ts +98 -0
- package/dist/transform/transform.d.ts.map +1 -0
- package/dist/transform/transform.js +67 -0
- package/dist/transform/transform.js.map +1 -0
- package/dist.min.js +314 -0
- package/package.json +22 -12
- package/src/animation/timeline.ts +2 -2
- package/src/{lib → animation-loop}/animation-loop.ts +115 -97
- package/src/{lib → animation-loop}/animation-props.ts +6 -5
- package/src/animation-loop/make-animation-loop.ts +44 -0
- package/src/animation-loop/render-loop.ts +23 -0
- package/src/geometries/cone-geometry.ts +1 -1
- package/src/geometries/cube-geometry.ts +6 -3
- package/src/geometries/cylinder-geometry.ts +2 -2
- package/src/geometries/ico-sphere-geometry.ts +7 -6
- package/src/geometries/plane-geometry.ts +5 -4
- package/src/geometries/sphere-geometry.ts +4 -3
- package/src/geometries/truncated-cone-geometry.ts +4 -3
- package/src/geometry/geometry-table.ts +1 -1
- package/src/geometry/geometry-utils.ts +3 -3
- package/src/geometry/geometry.ts +72 -115
- package/src/index.ts +28 -12
- package/src/lib/clip-space.ts +17 -15
- package/src/lib/pipeline-factory.ts +60 -50
- package/src/{lib → model}/model-utils.ts +5 -4
- package/src/model/model.ts +230 -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/transform/transform.ts +246 -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/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.map +0 -1
- 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.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/lib/model.ts +0 -179
- package/src/lib/render-loop.ts +0 -58
- /package/dist/{lib → animation-loop}/animation-props.js +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-utils.js","names":["Buffer","assert","GLTF_TO_LUMA_ATTRIBUTE_MAP","POSITION","NORMAL","COLOR_0","TEXCOORD_0","TEXCOORD_1","TEXCOORD_2","getIndexBufferFromGeometry","device","geometry","indices","undefined","data","value","Uint16Array","Uint32Array","createBuffer","usage","INDEX","getAttributeBuffersFromGeometry","buffers","name","attribute","Object","entries","attributes","remappedName","mapAttributeName","constant","Error","typedArray","id","concat"],"sources":["../../src/model/model-utils.ts"],"sourcesContent":["import {Device, Buffer, assert} from '@luma.gl/core';\nimport type {Geometry} from '../geometry/geometry';\n\n// Support for mapping new geometries with glTF attribute names to \"classic\" luma.gl shader names\nconst GLTF_TO_LUMA_ATTRIBUTE_MAP = {\n POSITION: 'positions',\n NORMAL: 'normals',\n COLOR_0: 'colors',\n TEXCOORD_0: 'texCoords',\n TEXCOORD_1: 'texCoords1',\n TEXCOORD_2: 'texCoords2'\n};\n\n/*\nexport function getAttributeLayoutsFromGeometry(geometry: Geometry) {\n const layouts: Record<string, {}> = {};\n let indices = geometry.indices;\n\n for (const [name, attribute] of Object.entries(geometry.attributes)) {\n const remappedName = mapAttributeName(name);\n\n if (attribute.constant) {\n throw new Error('constant attributes not supported');\n } else {\n const typedArray = attribute.value;\n // Create accessor by copying the attribute and removing `value``\n const accessor = {...attribute};\n delete accessor.value;\n buffers[remappedName] = [device.createBuffer(typedArray), accessor];\n\n inferAttributeAccessor(name, accessor);\n }\n }\n}\n\nexport class Table {\n length: number;\n // columns: Record<string, TypedArray> = {};\n}\n\nexport class GPUTable {\n length: number;\n columns: Record<string, Buffer> = {};\n}\n\nexport function convertTableToGPUTable(table: Table) {\n // for (const ) {}\n}\n\nexport function renameTableColumns(table: Table, map: (name: string) => string) {\n const newColumns = table.columns.reduce()\n table.clone();\n}\n*/\n\nexport function getIndexBufferFromGeometry(device: Device, geometry: Geometry): Buffer | undefined {\n if (!geometry.indices) {\n return undefined;\n }\n\n // @ts-expect-error\n const data = geometry.indices.value || geometry.indices;\n assert(\n data instanceof Uint16Array || data instanceof Uint32Array,\n 'attribute array for \"indices\" must be of integer type'\n );\n return device.createBuffer({usage: Buffer.INDEX, data});\n}\n\nexport function getAttributeBuffersFromGeometry(device: Device, geometry: Geometry): Record<string, Buffer> {\n const buffers: Record<string, Buffer> = {};\n\n for (const [name, attribute] of Object.entries(geometry.attributes)) {\n const remappedName = mapAttributeName(name);\n if (attribute?.constant) {\n throw new Error('constant attributes not supported');\n } else {\n const typedArray = attribute?.value;\n buffers[remappedName] = device.createBuffer({data: typedArray, id: `${remappedName}-buffer`});\n }\n }\n\n return buffers;\n}\n\nfunction mapAttributeName(name: string): string {\n // @ts-ignore-error\n return GLTF_TO_LUMA_ATTRIBUTE_MAP[name] || name;\n}\n\n/*\n// Check for well known attribute names\n// eslint-disable-next-line complexity\nexport function inferAttributeAccessor(attributeName, attribute) {\n let category;\n switch (attributeName) {\n case 'texCoords':\n case 'texCoord1':\n case 'texCoord2':\n case 'texCoord3':\n category = 'uvs';\n break;\n case 'vertices':\n case 'positions':\n case 'normals':\n case 'pickingColors':\n category = 'vectors';\n break;\n default:\n }\n\n // Check for categorys\n switch (category) {\n case 'vectors':\n attribute.size = attribute.size || 3;\n break;\n case 'uvs':\n attribute.size = attribute.size || 2;\n break;\n default:\n }\n\n assert(Number.isFinite(attribute.size), `attribute ${attributeName} needs size`);\n}\n*/\n"],"mappings":"AAAA,SAAgBA,MAAM,EAAEC,MAAM,QAAO,eAAe;AAIpD,MAAMC,0BAA0B,GAAG;EACjCC,QAAQ,EAAE,WAAW;EACrBC,MAAM,EAAE,SAAS;EACjBC,OAAO,EAAE,QAAQ;EACjBC,UAAU,EAAE,WAAW;EACvBC,UAAU,EAAE,YAAY;EACxBC,UAAU,EAAE;AACd,CAAC;AA4CD,OAAO,SAASC,0BAA0BA,CAACC,MAAc,EAAEC,QAAkB,EAAsB;EACjG,IAAI,CAACA,QAAQ,CAACC,OAAO,EAAE;IACrB,OAAOC,SAAS;EAClB;EAGA,MAAMC,IAAI,GAAGH,QAAQ,CAACC,OAAO,CAACG,KAAK,IAAIJ,QAAQ,CAACC,OAAO;EACvDX,MAAM,CACJa,IAAI,YAAYE,WAAW,IAAIF,IAAI,YAAYG,WAAW,EAC1D,uDACF,CAAC;EACD,OAAOP,MAAM,CAACQ,YAAY,CAAC;IAACC,KAAK,EAAEnB,MAAM,CAACoB,KAAK;IAAEN;EAAI,CAAC,CAAC;AACzD;AAEA,OAAO,SAASO,+BAA+BA,CAACX,MAAc,EAAEC,QAAkB,EAA0B;EAC1G,MAAMW,OAA+B,GAAG,CAAC,CAAC;EAE1C,KAAK,MAAM,CAACC,IAAI,EAAEC,SAAS,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACf,QAAQ,CAACgB,UAAU,CAAC,EAAE;IACnE,MAAMC,YAAY,GAAGC,gBAAgB,CAACN,IAAI,CAAC;IAC3C,IAAIC,SAAS,aAATA,SAAS,eAATA,SAAS,CAAEM,QAAQ,EAAE;MACvB,MAAM,IAAIC,KAAK,CAAC,mCAAmC,CAAC;IACtD,CAAC,MAAM;MACL,MAAMC,UAAU,GAAGR,SAAS,aAATA,SAAS,uBAATA,SAAS,CAAET,KAAK;MACnCO,OAAO,CAACM,YAAY,CAAC,GAAGlB,MAAM,CAACQ,YAAY,CAAC;QAACJ,IAAI,EAAEkB,UAAU;QAAEC,EAAE,KAAAC,MAAA,CAAKN,YAAY;MAAS,CAAC,CAAC;IAC/F;EACF;EAEA,OAAON,OAAO;AAChB;AAEA,SAASO,gBAAgBA,CAACN,IAAY,EAAU;EAE9C,OAAOrB,0BAA0B,CAACqB,IAAI,CAAC,IAAIA,IAAI;AACjD"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Device, Buffer, RenderPipelineProps, RenderPass, Binding, PrimitiveTopology } from '@luma.gl/core';
|
|
2
|
+
import { RenderPipeline } from '@luma.gl/core';
|
|
3
|
+
import type { ShaderModule } from '@luma.gl/shadertools';
|
|
4
|
+
import type { Geometry } from '../geometry/geometry';
|
|
5
|
+
import { PipelineFactory } from '../lib/pipeline-factory';
|
|
6
|
+
import { TypedArray } from '@math.gl/core';
|
|
7
|
+
/** @todo import type */
|
|
8
|
+
type UniformValue = unknown;
|
|
9
|
+
export type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs'> & {
|
|
10
|
+
vs?: {
|
|
11
|
+
glsl?: string;
|
|
12
|
+
wgsl?: string;
|
|
13
|
+
} | string | null;
|
|
14
|
+
fs?: {
|
|
15
|
+
glsl?: string;
|
|
16
|
+
wgsl?: string;
|
|
17
|
+
} | string | null;
|
|
18
|
+
defines?: Record<string, string | number | boolean>;
|
|
19
|
+
modules?: ShaderModule[];
|
|
20
|
+
moduleSettings?: Record<string, Record<string, any>>;
|
|
21
|
+
geometry?: Geometry | null;
|
|
22
|
+
/** deprecated pipeline factory to use to create renderpipelines */
|
|
23
|
+
pipelineFactory?: PipelineFactory;
|
|
24
|
+
vertexCount?: number;
|
|
25
|
+
instanceCount?: number;
|
|
26
|
+
};
|
|
27
|
+
/** v9 API */
|
|
28
|
+
export declare class Model {
|
|
29
|
+
readonly device: Device;
|
|
30
|
+
readonly id: string;
|
|
31
|
+
readonly vs: string;
|
|
32
|
+
readonly fs: string | null;
|
|
33
|
+
readonly topology: PrimitiveTopology;
|
|
34
|
+
readonly pipelineFactory: PipelineFactory;
|
|
35
|
+
/** The underlying GPU "program". @note May be recreated if parameters change */
|
|
36
|
+
pipeline: RenderPipeline;
|
|
37
|
+
userData: {
|
|
38
|
+
[key: string]: any;
|
|
39
|
+
};
|
|
40
|
+
/** Vertex count */
|
|
41
|
+
vertexCount: number;
|
|
42
|
+
/** instance count */
|
|
43
|
+
instanceCount: number;
|
|
44
|
+
/** Buffer-valued attributes */
|
|
45
|
+
bufferAttributes: Record<string, Buffer>;
|
|
46
|
+
/** Constant-valued attributes */
|
|
47
|
+
constantAttributes: Record<string, TypedArray>;
|
|
48
|
+
/** Bindings (textures, samplers, uniform buffers) */
|
|
49
|
+
bindings: Record<string, Binding>;
|
|
50
|
+
/** Uniforms */
|
|
51
|
+
uniforms: Record<string, UniformValue>;
|
|
52
|
+
private _getModuleUniforms;
|
|
53
|
+
constructor(device: Device, props: ModelProps);
|
|
54
|
+
destroy(): void;
|
|
55
|
+
draw(renderPass: RenderPass): void;
|
|
56
|
+
setProps(props: ModelProps): void;
|
|
57
|
+
updateModuleSettings(props: Record<string, any>): void;
|
|
58
|
+
setIndexBuffer(indices: Buffer | null): void;
|
|
59
|
+
setAttributes(bufferAttributes: Record<string, Buffer>): void;
|
|
60
|
+
setConstantAttributes(constantAttributes: Record<string, TypedArray>): void;
|
|
61
|
+
/** Set the bindings */
|
|
62
|
+
setBindings(bindings: Record<string, Binding>): void;
|
|
63
|
+
setUniforms(uniforms: Record<string, any>): void;
|
|
64
|
+
_setGeometry(geometry: Geometry): void;
|
|
65
|
+
}
|
|
66
|
+
export {};
|
|
67
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/model/model.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,MAAM,EACN,MAAM,EACN,mBAAmB,EACnB,UAAU,EACV,OAAO,EACP,iBAAiB,EAElB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAC,eAAe,EAAC,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC,wBAAwB;AACxB,KAAK,YAAY,GAAG,OAAO,CAAC;AAE5B,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,mBAAmB,EAAE,IAAI,GAAG,IAAI,CAAC,GAAG;IAEhE,EAAE,CAAC,EAAE;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAC,GAAG,MAAM,GAAG,IAAI,CAAC;IACpD,EAAE,CAAC,EAAE;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAC,GAAG,MAAM,GAAG,IAAI,CAAC;IACpD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;IACpD,OAAO,CAAC,EAAE,YAAY,EAAE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AIf,IAAI,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAQlC,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAkBjC,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAKtD,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAK5C,aAAa,CAAC,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;IAS7D,qBAAqB,CAAC,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,IAAI;IAM3E,uBAAuB;IACvB,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAKpD,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAKhD,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;CAWvC"}
|
|
@@ -1,175 +1,158 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { log } from '@luma.gl/core';
|
|
3
|
+
import { RenderPipeline } from '@luma.gl/core';
|
|
4
|
+
import { getAttributeBuffersFromGeometry, getIndexBufferFromGeometry } from "./model-utils.js";
|
|
5
|
+
import { PipelineFactory } from "../lib/pipeline-factory.js";
|
|
6
|
+
const DEFAULT_MODEL_PROPS = {
|
|
7
|
+
...RenderPipeline.defaultProps,
|
|
8
|
+
vs: null,
|
|
9
|
+
fs: null,
|
|
8
10
|
id: 'unnamed',
|
|
9
11
|
handle: undefined,
|
|
10
12
|
userData: {},
|
|
13
|
+
defines: {},
|
|
11
14
|
modules: [],
|
|
12
15
|
moduleSettings: {},
|
|
13
|
-
geometry:
|
|
16
|
+
geometry: null,
|
|
17
|
+
pipelineFactory: undefined,
|
|
18
|
+
vertexCount: 0,
|
|
19
|
+
instanceCount: 0
|
|
14
20
|
};
|
|
15
|
-
export
|
|
21
|
+
export class Model {
|
|
16
22
|
constructor(device, props) {
|
|
17
23
|
_defineProperty(this, "device", void 0);
|
|
18
|
-
|
|
19
|
-
_defineProperty(this, "pipeline", void 0);
|
|
20
|
-
|
|
21
24
|
_defineProperty(this, "id", void 0);
|
|
22
|
-
|
|
23
25
|
_defineProperty(this, "vs", void 0);
|
|
24
|
-
|
|
25
|
-
_defineProperty(this, "fs", void 0);
|
|
26
|
-
|
|
26
|
+
_defineProperty(this, "fs", null);
|
|
27
27
|
_defineProperty(this, "topology", void 0);
|
|
28
|
-
|
|
28
|
+
_defineProperty(this, "pipelineFactory", void 0);
|
|
29
|
+
_defineProperty(this, "pipeline", void 0);
|
|
30
|
+
_defineProperty(this, "userData", {});
|
|
29
31
|
_defineProperty(this, "vertexCount", void 0);
|
|
30
|
-
|
|
31
|
-
_defineProperty(this, "
|
|
32
|
-
|
|
32
|
+
_defineProperty(this, "instanceCount", 0);
|
|
33
|
+
_defineProperty(this, "bufferAttributes", {});
|
|
34
|
+
_defineProperty(this, "constantAttributes", {});
|
|
35
|
+
_defineProperty(this, "bindings", {});
|
|
36
|
+
_defineProperty(this, "uniforms", {});
|
|
33
37
|
_defineProperty(this, "_getModuleUniforms", void 0);
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
props = {
|
|
39
|
+
...DEFAULT_MODEL_PROPS,
|
|
36
40
|
...props
|
|
37
41
|
};
|
|
38
|
-
props = this.props;
|
|
39
42
|
this.id = props.id;
|
|
40
43
|
this.device = device;
|
|
44
|
+
Object.assign(this.userData, props.userData);
|
|
45
|
+
if (!props.vs) {
|
|
46
|
+
throw new Error('no vertex shader');
|
|
47
|
+
}
|
|
41
48
|
this.vs = getShaderSource(this.device, props.vs);
|
|
42
|
-
|
|
43
49
|
if (props.fs) {
|
|
44
50
|
this.fs = getShaderSource(this.device, props.fs);
|
|
45
51
|
}
|
|
46
|
-
|
|
47
|
-
this.
|
|
48
|
-
this.topology =
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.
|
|
52
|
-
this.topology = this.props.geometry.topology;
|
|
52
|
+
this.vertexCount = props.vertexCount;
|
|
53
|
+
this.instanceCount = props.instanceCount;
|
|
54
|
+
this.topology = props.topology;
|
|
55
|
+
if (props.geometry) {
|
|
56
|
+
this.vertexCount = props.geometry.vertexCount;
|
|
57
|
+
this.topology = props.geometry.topology || 'triangle-list';
|
|
53
58
|
}
|
|
54
|
-
|
|
59
|
+
this.pipelineFactory = props.pipelineFactory || PipelineFactory.getDefaultPipelineFactory(this.device);
|
|
55
60
|
const {
|
|
56
|
-
|
|
61
|
+
pipeline,
|
|
57
62
|
getUniforms
|
|
58
|
-
} =
|
|
63
|
+
} = this.pipelineFactory.createRenderPipeline({
|
|
64
|
+
...props,
|
|
59
65
|
vs: this.vs,
|
|
60
66
|
fs: this.fs,
|
|
61
67
|
topology: this.topology,
|
|
68
|
+
defines: props.defines,
|
|
62
69
|
parameters: props.parameters,
|
|
63
|
-
|
|
70
|
+
shaderLayout: props.shaderLayout
|
|
64
71
|
});
|
|
65
|
-
this.pipeline =
|
|
72
|
+
this.pipeline = pipeline;
|
|
66
73
|
this._getModuleUniforms = getUniforms;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this._setGeometry(this.props.geometry);
|
|
74
|
+
if (props.geometry) {
|
|
75
|
+
this._setGeometry(props.geometry);
|
|
70
76
|
}
|
|
71
|
-
|
|
72
77
|
this.setUniforms(this._getModuleUniforms());
|
|
73
|
-
this.setProps(
|
|
78
|
+
this.setProps(props);
|
|
74
79
|
}
|
|
75
|
-
|
|
76
80
|
destroy() {
|
|
77
|
-
this.
|
|
81
|
+
this.pipelineFactory.release(this.pipeline);
|
|
78
82
|
}
|
|
79
|
-
|
|
80
83
|
draw(renderPass) {
|
|
81
84
|
this.pipeline.draw({
|
|
82
85
|
renderPass,
|
|
83
86
|
vertexCount: this.vertexCount,
|
|
84
|
-
instanceCount: this.
|
|
87
|
+
instanceCount: this.instanceCount
|
|
85
88
|
});
|
|
86
|
-
return this;
|
|
87
89
|
}
|
|
88
|
-
|
|
89
90
|
setProps(props) {
|
|
90
91
|
if (props.indices) {
|
|
91
92
|
this.setIndexBuffer(props.indices);
|
|
92
93
|
}
|
|
93
|
-
|
|
94
94
|
if (props.attributes) {
|
|
95
95
|
this.setAttributes(props.attributes);
|
|
96
96
|
}
|
|
97
|
-
|
|
98
97
|
if (props.bindings) {
|
|
99
98
|
this.setBindings(props.bindings);
|
|
100
99
|
}
|
|
101
|
-
|
|
102
100
|
if (props.uniforms) {
|
|
103
101
|
this.setUniforms(props.uniforms);
|
|
104
102
|
}
|
|
105
|
-
|
|
106
103
|
if (props.moduleSettings) {
|
|
107
104
|
this.updateModuleSettings(props.moduleSettings);
|
|
108
105
|
}
|
|
109
|
-
|
|
110
|
-
return this;
|
|
111
106
|
}
|
|
112
|
-
|
|
113
107
|
updateModuleSettings(props) {
|
|
114
108
|
const uniforms = this._getModuleUniforms(props);
|
|
115
|
-
|
|
116
109
|
this.setUniforms(uniforms);
|
|
117
|
-
return this;
|
|
118
110
|
}
|
|
119
|
-
|
|
120
111
|
setIndexBuffer(indices) {
|
|
121
112
|
this.pipeline.setIndexBuffer(indices);
|
|
122
|
-
return this;
|
|
123
113
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
114
|
+
setAttributes(bufferAttributes) {
|
|
115
|
+
if (bufferAttributes.indices) {
|
|
116
|
+
log.warn("Model:".concat(this.id, " setAttributes() - indices should be set using setIndexBuffer()"));
|
|
117
|
+
}
|
|
118
|
+
this.pipeline.setAttributes(bufferAttributes);
|
|
119
|
+
Object.assign(this.bufferAttributes, bufferAttributes);
|
|
120
|
+
}
|
|
121
|
+
setConstantAttributes(constantAttributes) {
|
|
122
|
+
this.pipeline.setConstantAttributes(constantAttributes);
|
|
123
|
+
Object.assign(this.constantAttributes, constantAttributes);
|
|
129
124
|
}
|
|
130
|
-
|
|
131
125
|
setBindings(bindings) {
|
|
132
126
|
this.pipeline.setBindings(bindings);
|
|
133
|
-
Object.assign(this.
|
|
134
|
-
return this;
|
|
127
|
+
Object.assign(this.bindings, bindings);
|
|
135
128
|
}
|
|
136
|
-
|
|
137
129
|
setUniforms(uniforms) {
|
|
138
130
|
this.pipeline.setUniforms(uniforms);
|
|
139
|
-
Object.assign(this.
|
|
140
|
-
return this;
|
|
131
|
+
Object.assign(this.uniforms, uniforms);
|
|
141
132
|
}
|
|
142
|
-
|
|
143
133
|
_setGeometry(geometry) {
|
|
144
134
|
const geometryBuffers = getAttributeBuffersFromGeometry(this.device, geometry);
|
|
145
135
|
this.setAttributes(geometryBuffers);
|
|
146
136
|
const indexBuffer = getIndexBufferFromGeometry(this.device, geometry);
|
|
147
|
-
|
|
148
137
|
if (indexBuffer) {
|
|
149
138
|
this.setIndexBuffer(indexBuffer);
|
|
150
139
|
}
|
|
151
140
|
}
|
|
152
|
-
|
|
153
141
|
}
|
|
154
|
-
|
|
155
142
|
function getShaderSource(device, shader) {
|
|
156
143
|
if (typeof shader === 'string') {
|
|
157
144
|
return shader;
|
|
158
145
|
}
|
|
159
|
-
|
|
160
146
|
switch (device.info.type) {
|
|
161
147
|
case 'webgpu':
|
|
162
148
|
if (shader !== null && shader !== void 0 && shader.wgsl) {
|
|
163
149
|
return shader.wgsl;
|
|
164
150
|
}
|
|
165
|
-
|
|
166
151
|
throw new Error('WebGPU does not support GLSL shaders');
|
|
167
|
-
|
|
168
152
|
default:
|
|
169
153
|
if (shader !== null && shader !== void 0 && shader.glsl) {
|
|
170
154
|
return shader.glsl;
|
|
171
155
|
}
|
|
172
|
-
|
|
173
156
|
throw new Error('WebGL does not support WGSL shaders');
|
|
174
157
|
}
|
|
175
158
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","names":["log","RenderPipeline","getAttributeBuffersFromGeometry","getIndexBufferFromGeometry","PipelineFactory","DEFAULT_MODEL_PROPS","defaultProps","vs","fs","id","handle","undefined","userData","defines","modules","moduleSettings","geometry","pipelineFactory","vertexCount","instanceCount","Model","constructor","device","props","_defineProperty","Object","assign","Error","getShaderSource","topology","getDefaultPipelineFactory","pipeline","getUniforms","createRenderPipeline","parameters","shaderLayout","_getModuleUniforms","_setGeometry","setUniforms","setProps","destroy","release","draw","renderPass","indices","setIndexBuffer","attributes","setAttributes","bindings","setBindings","uniforms","updateModuleSettings","bufferAttributes","warn","concat","setConstantAttributes","constantAttributes","geometryBuffers","indexBuffer","shader","info","type","wgsl","glsl"],"sources":["../../src/model/model.ts"],"sourcesContent":["// luma.gl, MIT license\n\nimport {\n Device,\n Buffer,\n RenderPipelineProps,\n RenderPass,\n Binding,\n PrimitiveTopology,\n log\n} from '@luma.gl/core';\nimport {RenderPipeline} from '@luma.gl/core';\nimport type {ShaderModule} from '@luma.gl/shadertools';\nimport type {Geometry} from '../geometry/geometry';\nimport {getAttributeBuffersFromGeometry, getIndexBufferFromGeometry} from './model-utils';\nimport {PipelineFactory} from '../lib/pipeline-factory';\nimport {TypedArray} from '@math.gl/core';\n\n/** @todo import type */\ntype UniformValue = unknown;\n\nexport type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs'> & {\n // Model also accepts a string\n vs?: {glsl?: string; wgsl?: string} | string | null;\n fs?: {glsl?: string; wgsl?: string} | string | null;\n defines?: Record<string, string | number | boolean>;\n modules?: ShaderModule[];\n moduleSettings?: Record<string, Record<string, any>>;\n geometry?: Geometry | null;\n /** deprecated pipeline factory to use to create renderpipelines */\n pipelineFactory?: PipelineFactory;\n vertexCount?: number;\n instanceCount?: number;\n};\n\nconst DEFAULT_MODEL_PROPS: Required<ModelProps> = {\n ...RenderPipeline.defaultProps,\n vs: null,\n fs: null,\n id: 'unnamed',\n handle: undefined,\n userData: {},\n defines: {},\n modules: [],\n moduleSettings: {},\n geometry: null,\n pipelineFactory: undefined,\n vertexCount: 0,\n instanceCount: 0\n};\n\n/** v9 API */\nexport class Model {\n readonly device: Device;\n readonly id: string;\n readonly vs: string;\n readonly fs: string | null = null;\n readonly topology: PrimitiveTopology;\n readonly pipelineFactory: PipelineFactory;\n /** The underlying GPU \"program\". @note May be recreated if parameters change */\n pipeline: RenderPipeline;\n userData: {[key: string]: any} = {};\n\n // readonly props: Required<ModelProps>;\n\n /** Vertex count */\n vertexCount: number;\n /** instance count */\n instanceCount: number = 0;\n /** Buffer-valued attributes */\n bufferAttributes: Record<string, Buffer> = {};\n /** Constant-valued attributes */\n constantAttributes: Record<string, TypedArray> = {};\n /** Bindings (textures, samplers, uniform buffers) */\n bindings: Record<string, Binding> = {};\n /** Uniforms */\n uniforms: Record<string, UniformValue> = {};\n\n private _getModuleUniforms: (props?: Record<string, Record<string, any>>) => Record<string, any>;\n\n constructor(device: Device, props: ModelProps) {\n props = {...DEFAULT_MODEL_PROPS, ...props};\n this.id = props.id;\n this.device = device;\n\n Object.assign(this.userData, props.userData);\n\n // Create the pipeline\n if (!props.vs) {\n throw new Error('no vertex shader');\n }\n this.vs = getShaderSource(this.device, props.vs);\n if (props.fs) {\n this.fs = getShaderSource(this.device, props.fs);\n }\n\n this.vertexCount = props.vertexCount;\n this.instanceCount = props.instanceCount;\n this.topology = props.topology;\n\n if (props.geometry) {\n this.vertexCount = props.geometry.vertexCount;\n this.topology = props.geometry.topology || 'triangle-list';\n }\n\n this.pipelineFactory =\n props.pipelineFactory || PipelineFactory.getDefaultPipelineFactory(this.device);\n const {pipeline, getUniforms} = this.pipelineFactory.createRenderPipeline({\n ...props,\n vs: this.vs,\n fs: this.fs,\n topology: this.topology,\n defines: props.defines,\n parameters: props.parameters,\n shaderLayout: props.shaderLayout\n });\n\n this.pipeline = pipeline;\n this._getModuleUniforms = getUniforms;\n\n if (props.geometry) {\n this._setGeometry(props.geometry);\n }\n\n this.setUniforms(this._getModuleUniforms()); // Get all default module uniforms\n\n // Props can update any of the above, so call setProps last.\n this.setProps(props);\n }\n\n destroy(): void {\n this.pipelineFactory.release(this.pipeline);\n }\n\n draw(renderPass: RenderPass): void {\n this.pipeline.draw({\n renderPass,\n vertexCount: this.vertexCount,\n instanceCount: this.instanceCount\n });\n }\n\n setProps(props: ModelProps): void {\n if (props.indices) {\n this.setIndexBuffer(props.indices);\n }\n if (props.attributes) {\n this.setAttributes(props.attributes);\n }\n if (props.bindings) {\n this.setBindings(props.bindings);\n }\n if (props.uniforms) {\n this.setUniforms(props.uniforms);\n }\n if (props.moduleSettings) {\n this.updateModuleSettings(props.moduleSettings);\n }\n }\n\n updateModuleSettings(props: Record<string, any>): void {\n const uniforms = this._getModuleUniforms(props);\n this.setUniforms(uniforms);\n }\n\n setIndexBuffer(indices: Buffer | null): void {\n this.pipeline.setIndexBuffer(indices);\n // this._indices = indices;\n }\n\n setAttributes(bufferAttributes: Record<string, Buffer>): void {\n if (bufferAttributes.indices) {\n log.warn(`Model:${this.id} setAttributes() - indices should be set using setIndexBuffer()`);\n }\n\n this.pipeline.setAttributes(bufferAttributes);\n Object.assign(this.bufferAttributes, bufferAttributes);\n }\n\n setConstantAttributes(constantAttributes: Record<string, TypedArray>): void {\n // TODO - this doesn't work under WebGPU, we'll need to create buffers or inject uniforms\n this.pipeline.setConstantAttributes(constantAttributes);\n Object.assign(this.constantAttributes, constantAttributes);\n }\n\n /** Set the bindings */\n setBindings(bindings: Record<string, Binding>): void {\n this.pipeline.setBindings(bindings);\n Object.assign(this.bindings, bindings);\n }\n\n setUniforms(uniforms: Record<string, any>): void {\n this.pipeline.setUniforms(uniforms);\n Object.assign(this.uniforms, uniforms);\n }\n\n _setGeometry(geometry: Geometry): void {\n // this._deleteGeometryBuffers();\n\n const geometryBuffers = getAttributeBuffersFromGeometry(this.device, geometry);\n this.setAttributes(geometryBuffers);\n\n const indexBuffer = getIndexBufferFromGeometry(this.device, geometry);\n if (indexBuffer) {\n this.setIndexBuffer(indexBuffer);\n }\n }\n}\n\n/** Create a shader from the different overloads */\nfunction getShaderSource(device: Device, shader: string | {glsl?: string; wgsl?: string}): string {\n // TODO - detect WGSL/GLSL and throw an error if not supported\n if (typeof shader === 'string') {\n return shader;\n }\n\n switch (device.info.type) {\n case 'webgpu':\n if (shader?.wgsl) {\n return shader.wgsl;\n }\n throw new Error('WebGPU does not support GLSL shaders');\n\n default:\n if (shader?.glsl) {\n return shader.glsl;\n }\n throw new Error('WebGL does not support WGSL shaders');\n }\n}\n"],"mappings":";AAEA,SAOEA,GAAG,QACE,eAAe;AACtB,SAAQC,cAAc,QAAO,eAAe;AAAC,SAGrCC,+BAA+B,EAAEC,0BAA0B;AAAA,SAC3DC,eAAe;AAoBvB,MAAMC,mBAAyC,GAAG;EAChD,GAAGJ,cAAc,CAACK,YAAY;EAC9BC,EAAE,EAAE,IAAI;EACRC,EAAE,EAAE,IAAI;EACRC,EAAE,EAAE,SAAS;EACbC,MAAM,EAAEC,SAAS;EACjBC,QAAQ,EAAE,CAAC,CAAC;EACZC,OAAO,EAAE,CAAC,CAAC;EACXC,OAAO,EAAE,EAAE;EACXC,cAAc,EAAE,CAAC,CAAC;EAClBC,QAAQ,EAAE,IAAI;EACdC,eAAe,EAAEN,SAAS;EAC1BO,WAAW,EAAE,CAAC;EACdC,aAAa,EAAE;AACjB,CAAC;AAGD,OAAO,MAAMC,KAAK,CAAC;EA4BjBC,WAAWA,CAACC,MAAc,EAAEC,KAAiB,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA,aAxBlB,IAAI;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA,mBAKA,CAAC,CAAC;IAAAA,eAAA;IAAAA,eAAA,wBAOX,CAAC;IAAAA,eAAA,2BAEkB,CAAC,CAAC;IAAAA,eAAA,6BAEI,CAAC,CAAC;IAAAA,eAAA,mBAEf,CAAC,CAAC;IAAAA,eAAA,mBAEG,CAAC,CAAC;IAAAA,eA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GvD,+BAA+B,CAAC,IAAI,CAACoB,MAAM,EAAEN,QAAQ,CAAC;IAC9E,IAAI,CAAC+B,aAAa,CAACU,eAAe,CAAC;IAEnC,MAAMC,WAAW,GAAGvD,0BAA0B,CAAC,IAAI,CAACmB,MAAM,EAAEN,QAAQ,CAAC;IACrE,IAAI0C,WAAW,EAAE;MACf,IAAI,CAACb,cAAc,CAACa,WAAW,CAAC;IAClC;EACF;AACF;AAGA,SAAS9B,eAAeA,CAACN,MAAc,EAAEqC,MAA+C,EAAU;EAEhG,IAAI,OAAOA,MAAM,KAAK,QAAQ,EAAE;IAC9B,OAAOA,MAAM;EACf;EAEA,QAAQrC,MAAM,CAACsC,IAAI,CAACC,IAAI;IACtB,KAAK,QAAQ;MACX,IAAIF,MAAM,aAANA,MAAM,eAANA,MAAM,CAAEG,IAAI,EAAE;QAChB,OAAOH,MAAM,CAACG,IAAI;MACpB;MACA,MAAM,IAAInC,KAAK,CAAC,sCAAsC,CAAC;IAEzD;MACE,IAAIgC,MAAM,aAANA,MAAM,eAANA,MAAM,CAAEI,IAAI,EAAE;QAChB,OAAOJ,MAAM,CAACI,IAAI;MACpB;MACA,MAAM,IAAIpC,KAAK,CAAC,qCAAqC,CAAC;EAC1D;AACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Matrix4 } from '@math.gl/core';
|
|
2
|
+
import { ScenegraphNode, ScenegraphNodeProps } from './scenegraph-node';
|
|
3
|
+
export type GroupNodeProps = ScenegraphNodeProps & {
|
|
4
|
+
children?: ScenegraphNode[];
|
|
5
|
+
};
|
|
6
|
+
export declare class GroupNode extends ScenegraphNode {
|
|
7
|
+
children: ScenegraphNode[];
|
|
8
|
+
constructor(children: ScenegraphNode[]);
|
|
9
|
+
constructor(props?: GroupNodeProps);
|
|
10
|
+
getBounds(): [number[], number[]] | null;
|
|
11
|
+
destroy(): void;
|
|
12
|
+
add(...children: (ScenegraphNode | ScenegraphNode[])[]): this;
|
|
13
|
+
remove(child: ScenegraphNode): this;
|
|
14
|
+
removeAll(): this;
|
|
15
|
+
traverse(visitor: (node: ScenegraphNode, context: {
|
|
16
|
+
worldMatrix: Matrix4;
|
|
17
|
+
}) => void, { worldMatrix }?: {
|
|
18
|
+
worldMatrix?: Matrix4;
|
|
19
|
+
}): void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=group-node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group-node.d.ts","sourceRoot":"","sources":["../../src/scenegraph/group-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAU,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAC,cAAc,EAAE,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AAEtE,MAAM,MAAM,cAAc,GAAG,mBAAmB,GAAG;IACjD,QAAQ,CAAC,EAAE,cAAc,EAAE,CAAC;CAC7B,CAAA;AAED,qBAAa,SAAU,SAAQ,cAAc;IAC3C,QAAQ,EAAE,cAAc,EAAE,CAAC;gBAEf,QAAQ,EAAE,cAAc,EAAE;gBAC1B,KAAK,CAAC,EAAE,cAAc;IAazB,SAAS,IAAI,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI;IAkCxC,OAAO,IAAI,IAAI;IAOxB,GAAG,CAAC,GAAG,QAAQ,EAAE,CAAC,cAAc,GAAG,cAAc,EAAE,CAAC,EAAE,GAAG,IAAI;IAW7D,MAAM,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;IASnC,SAAS,IAAI,IAAI;IAKjB,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE;QAAC,WAAW,EAAE,OAAO,CAAA;KAAC,KAAK,IAAI,EAAE,EAAC,WAA2B,EAAC;;KAAK;CAWtH"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import { Matrix4, Vector3 } from '@math.gl/core';
|
|
3
|
+
import { log } from '@luma.gl/core';
|
|
4
|
+
import { ScenegraphNode } from "./scenegraph-node.js";
|
|
5
|
+
export class GroupNode extends ScenegraphNode {
|
|
6
|
+
constructor() {
|
|
7
|
+
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
8
|
+
props = Array.isArray(props) ? {
|
|
9
|
+
children: props
|
|
10
|
+
} : props;
|
|
11
|
+
const {
|
|
12
|
+
children = []
|
|
13
|
+
} = props;
|
|
14
|
+
log.assert(children.every(child => child instanceof ScenegraphNode), 'every child must an instance of ScenegraphNode');
|
|
15
|
+
super(props);
|
|
16
|
+
_defineProperty(this, "children", void 0);
|
|
17
|
+
this.children = children;
|
|
18
|
+
}
|
|
19
|
+
getBounds() {
|
|
20
|
+
const result = [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]];
|
|
21
|
+
this.traverse((node, _ref) => {
|
|
22
|
+
let {
|
|
23
|
+
worldMatrix
|
|
24
|
+
} = _ref;
|
|
25
|
+
const bounds = node.getBounds();
|
|
26
|
+
if (!bounds) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const [min, max] = bounds;
|
|
30
|
+
const center = new Vector3(min).add(max).divide([2, 2, 2]);
|
|
31
|
+
worldMatrix.transformAsPoint(center, center);
|
|
32
|
+
const halfSize = new Vector3(max).subtract(min).divide([2, 2, 2]);
|
|
33
|
+
worldMatrix.transformAsVector(halfSize, halfSize);
|
|
34
|
+
for (let v = 0; v < 8; v++) {
|
|
35
|
+
const position = new Vector3(v & 0b001 ? -1 : 1, v & 0b010 ? -1 : 1, v & 0b100 ? -1 : 1).multiply(halfSize).add(center);
|
|
36
|
+
for (let i = 0; i < 3; i++) {
|
|
37
|
+
result[0][i] = Math.min(result[0][i], position[i]);
|
|
38
|
+
result[1][i] = Math.max(result[1][i], position[i]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
if (!Number.isFinite(result[0][0])) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
destroy() {
|
|
48
|
+
this.children.forEach(child => child.destroy());
|
|
49
|
+
this.removeAll();
|
|
50
|
+
super.destroy();
|
|
51
|
+
}
|
|
52
|
+
add() {
|
|
53
|
+
for (var _len = arguments.length, children = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
54
|
+
children[_key] = arguments[_key];
|
|
55
|
+
}
|
|
56
|
+
for (const child of children) {
|
|
57
|
+
if (Array.isArray(child)) {
|
|
58
|
+
this.add(...child);
|
|
59
|
+
} else {
|
|
60
|
+
this.children.push(child);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
remove(child) {
|
|
66
|
+
const children = this.children;
|
|
67
|
+
const indexOf = children.indexOf(child);
|
|
68
|
+
if (indexOf > -1) {
|
|
69
|
+
children.splice(indexOf, 1);
|
|
70
|
+
}
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
removeAll() {
|
|
74
|
+
this.children = [];
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
traverse(visitor) {
|
|
78
|
+
let {
|
|
79
|
+
worldMatrix = new Matrix4()
|
|
80
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
81
|
+
const modelMatrix = new Matrix4(worldMatrix).multiplyRight(this.matrix);
|
|
82
|
+
for (const child of this.children) {
|
|
83
|
+
if (child instanceof GroupNode) {
|
|
84
|
+
child.traverse(visitor, {
|
|
85
|
+
worldMatrix: modelMatrix
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
visitor(child, {
|
|
89
|
+
worldMatrix: modelMatrix
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=group-node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group-node.js","names":["Matrix4","Vector3","log","ScenegraphNode","GroupNode","constructor","props","arguments","length","undefined","Array","isArray","children","assert","every","child","_defineProperty","getBounds","result","Infinity","traverse","node","_ref","worldMatrix","bounds","min","max","center","add","divide","transformAsPoint","halfSize","subtract","transformAsVector","v","position","multiply","i","Math","Number","isFinite","destroy","forEach","removeAll","_len","_key","push","remove","indexOf","splice","visitor","modelMatrix","multiplyRight","matrix"],"sources":["../../src/scenegraph/group-node.ts"],"sourcesContent":["import {Matrix4, Vector3} from '@math.gl/core';\nimport {log} from '@luma.gl/core';\nimport {ScenegraphNode, ScenegraphNodeProps} from './scenegraph-node';\n\nexport type GroupNodeProps = ScenegraphNodeProps & {\n children?: ScenegraphNode[];\n}\n\nexport class GroupNode extends ScenegraphNode {\n children: ScenegraphNode[];\n\n constructor(children: ScenegraphNode[]);\n constructor(props?: GroupNodeProps);\n\n constructor(props: ScenegraphNode[] | GroupNodeProps = {}) {\n props = Array.isArray(props) ? {children: props} : props;\n const {children = []} = props;\n log.assert(\n children.every((child) => child instanceof ScenegraphNode),\n 'every child must an instance of ScenegraphNode'\n );\n super(props);\n this.children = children;\n }\n\n override getBounds(): [number[], number[]] | null {\n const result: [number[], number[]] = [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]];\n\n this.traverse((node, {worldMatrix}) => {\n const bounds = node.getBounds();\n if (!bounds) {\n return;\n }\n const [min, max] = bounds;\n const center = new Vector3(min).add(max).divide([2, 2, 2]);\n worldMatrix.transformAsPoint(center, center);\n const halfSize = new Vector3(max).subtract(min).divide([2, 2, 2]);\n worldMatrix.transformAsVector(halfSize, halfSize);\n\n for (let v = 0; v < 8; v++) {\n // Test all 8 corners of the box\n const position = new Vector3(\n v & 0b001 ? -1 : 1,\n v & 0b010 ? -1 : 1,\n v & 0b100 ? -1 : 1\n ).multiply(halfSize).add(center);\n\n for (let i = 0; i < 3; i++) {\n result[0][i] = Math.min(result[0][i], position[i]);\n result[1][i] = Math.max(result[1][i], position[i]);\n }\n }\n });\n if (!Number.isFinite(result[0][0])) {\n return null;\n }\n return result;\n }\n\n override destroy(): void {\n this.children.forEach((child) => child.destroy());\n this.removeAll();\n super.destroy();\n }\n\n // Unpacks arrays and nested arrays of children\n add(...children: (ScenegraphNode | ScenegraphNode[])[]): this {\n for (const child of children) {\n if (Array.isArray(child)) {\n this.add(...child);\n } else {\n this.children.push(child);\n }\n }\n return this;\n }\n\n remove(child: ScenegraphNode): this {\n const children = this.children;\n const indexOf = children.indexOf(child);\n if (indexOf > -1) {\n children.splice(indexOf, 1);\n }\n return this;\n }\n\n removeAll(): this {\n this.children = [];\n return this;\n }\n\n traverse(visitor: (node: ScenegraphNode, context: {worldMatrix: Matrix4}) => void, {worldMatrix = new Matrix4()} = {}) {\n const modelMatrix = new Matrix4(worldMatrix).multiplyRight(this.matrix);\n\n for (const child of this.children) {\n if (child instanceof GroupNode) {\n child.traverse(visitor, {worldMatrix: modelMatrix});\n } else {\n visitor(child, {worldMatrix: modelMatrix});\n }\n }\n }\n}\n"],"mappings":";AAAA,SAAQA,OAAO,EAAEC,OAAO,QAAO,eAAe;AAC9C,SAAQC,GAAG,QAAO,eAAe;AAAC,SAC1BC,cAAc;AAMtB,OAAO,MAAMC,SAAS,SAASD,cAAc,CAAC;EAM5CE,WAAWA,CAAA,EAAgD;IAAA,IAA/CC,KAAwC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IACvDD,KAAK,GAAGI,KAAK,CAACC,OAAO,CAACL,KAAK,CAAC,GAAG;MAACM,QAAQ,EAAEN;IAAK,CAAC,GAAGA,KAAK;IACxD,MAAM;MAACM,QAAQ,GAAG;IAAE,CAAC,GAAGN,KAAK;IAC7BJ,GAAG,CAACW,MAAM,CACRD,QAAQ,CAACE,KAAK,CAAEC,KAAK,IAAKA,KAAK,YAAYZ,cAAc,CAAC,EAC1D,gDACF,CAAC;IACD,KAAK,C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|
|
3
|
+
import { Model } from '../model/model';
|
|
4
|
+
export type ModelNodeProps = ScenegraphNodeProps & {
|
|
5
|
+
model: Model;
|
|
6
|
+
managedResources?: any[];
|
|
7
|
+
bounds?: [number[], number[]];
|
|
8
|
+
};
|
|
9
|
+
export declare class ModelNode extends ScenegraphNode {
|
|
10
|
+
readonly model: Model;
|
|
11
|
+
bounds: [number[], number[]] | null;
|
|
12
|
+
managedResources: any[];
|
|
13
|
+
constructor(props: ModelNodeProps);
|
|
14
|
+
getBounds(): [number[], number[]] | null;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
draw(renderPass?: RenderPass): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=model-node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-node.d.ts","sourceRoot":"","sources":["../../src/scenegraph/model-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AACzC,OAAO,EAAC,cAAc,EAAE,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AACtE,OAAO,EAAC,KAAK,EAAC,MAAM,gBAAgB,CAAC;AAErC,MAAM,MAAM,cAAc,GAAG,mBAAmB,GAAG;IACjD,KAAK,EAAE,KAAK,CAAC;IACb,gBAAgB,CAAC,EAAE,GAAG,EAAE,CAAC;IACzB,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;CAC/B,CAAA;AAED,qBAAa,SAAU,SAAQ,cAAc;IAC3C,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI,CAAQ;IAC3C,gBAAgB,EAAE,GAAG,EAAE,CAAC;gBAOZ,KAAK,EAAE,cAAc;IAUxB,SAAS,IAAI,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI;IAIxC,OAAO,IAAI,IAAI;IAWxB,IAAI,CAAC,UAAU,CAAC,EAAE,UAAU;CAI7B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import { ScenegraphNode } from "./scenegraph-node.js";
|
|
3
|
+
export class ModelNode extends ScenegraphNode {
|
|
4
|
+
constructor(props) {
|
|
5
|
+
super(props);
|
|
6
|
+
_defineProperty(this, "model", void 0);
|
|
7
|
+
_defineProperty(this, "bounds", null);
|
|
8
|
+
_defineProperty(this, "managedResources", void 0);
|
|
9
|
+
this.model = props.model;
|
|
10
|
+
this.managedResources = props.managedResources || [];
|
|
11
|
+
this.bounds = props.bounds || null;
|
|
12
|
+
this.setProps(props);
|
|
13
|
+
}
|
|
14
|
+
getBounds() {
|
|
15
|
+
return this.bounds;
|
|
16
|
+
}
|
|
17
|
+
destroy() {
|
|
18
|
+
if (this.model) {
|
|
19
|
+
this.model.destroy();
|
|
20
|
+
this.model = null;
|
|
21
|
+
}
|
|
22
|
+
this.managedResources.forEach(resource => resource.destroy());
|
|
23
|
+
this.managedResources = [];
|
|
24
|
+
}
|
|
25
|
+
draw(renderPass) {
|
|
26
|
+
return this.model.draw(renderPass);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=model-node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-node.js","names":["ScenegraphNode","ModelNode","constructor","props","_defineProperty","model","managedResources","bounds","setProps","getBounds","destroy","forEach","resource","draw","renderPass"],"sources":["../../src/scenegraph/model-node.ts"],"sourcesContent":["import {RenderPass} from '@luma.gl/core';\nimport {ScenegraphNode, ScenegraphNodeProps} from './scenegraph-node';\nimport {Model} from '../model/model';\n\nexport type ModelNodeProps = ScenegraphNodeProps & {\n model: Model;\n managedResources?: any[];\n bounds?: [number[], number[]];\n}\n\nexport class ModelNode extends ScenegraphNode {\n readonly model: Model;\n bounds: [number[], number[]] | null = null;\n managedResources: any[];\n\n // TODO - is this used? override callbacks to make sure we call them with this\n // onBeforeRender = null;\n // onAfterRender = null;\n // AfterRender = null;\n\n constructor(props: ModelNodeProps) {\n super(props);\n\n // Create new Model or used supplied Model\n this.model = props.model;\n this.managedResources = props.managedResources || [];\n this.bounds = props.bounds || null;\n this.setProps(props);\n }\n\n override getBounds(): [number[], number[]] | null {\n return this.bounds;\n }\n\n override destroy(): void {\n if (this.model) {\n this.model.destroy();\n // @ts-expect-error\n this.model = null;\n }\n this.managedResources.forEach((resource) => resource.destroy());\n this.managedResources = [];\n }\n\n // Expose model methods\n draw(renderPass?: RenderPass) {\n // Return value indicates if something was actually drawn\n return this.model.draw(renderPass);\n }\n}\n"],"mappings":";SACQA,cAAc;AAStB,OAAO,MAAMC,SAAS,SAASD,cAAc,CAAC;EAU5CE,WAAWA,CAACC,KAAqB,EAAE;IACjC,KAAK,CAACA,KAAK,CAAC;IAACC,eAAA;IAAAA,eAAA,iBATuB,IAAI;IAAAA,eAAA;IAYxC,IAAI,CAACC,KAAK,GAAGF,KAAK,CAACE,KAAK;IACxB,IAAI,CAACC,gBAAgB,GAAGH,KAAK,CAACG,gBAAgB,IAAI,EAAE;IACpD,IAAI,CAACC,MAAM,GAAGJ,KAAK,CAACI,MAAM,IAAI,IAAI;IAClC,IAAI,CAACC,QAAQ,CAACL,KAAK,CAAC;EACtB;EAESM,SAASA,CAAA,EAAgC;IAChD,OAAO,IAAI,CAACF,MAAM;EACpB;EAESG,OAAOA,CAAA,EAAS;IACvB,IAAI,IAAI,CAACL,KAAK,EAAE;MACd,IAAI,CAACA,KAAK,CAACK,OAAO,CAAC,CAAC;MAEpB,IAAI,CAACL,KAAK,GAAG,IAAI;IACnB;IACA,IAAI,CAACC,gBAAgB,CAACK,OAAO,CAAEC,QAAQ,IAAKA,QAAQ,CAACF,OAAO,CAAC,CAAC,CAAC;IAC/D,IAAI,CAACJ,gBAAgB,GAAG,EAAE;EAC5B;EAGAO,IAAIA,CAACC,UAAuB,EAAE;IAE5B,OAAO,IAAI,CAACT,KAAK,CAACQ,IAAI,CAACC,UAAU,CAAC;EACpC;AACF"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { NumericArray } from '@luma.gl/core';
|
|
2
|
+
import { Vector3, Matrix4 } from '@math.gl/core';
|
|
3
|
+
/** Properties for creating a new Scenegraph */
|
|
4
|
+
export type ScenegraphNodeProps = {
|
|
5
|
+
id?: string;
|
|
6
|
+
/** whether to display the object at all */
|
|
7
|
+
display?: boolean;
|
|
8
|
+
matrix?: NumericArray;
|
|
9
|
+
position?: NumericArray;
|
|
10
|
+
rotation?: NumericArray;
|
|
11
|
+
scale?: NumericArray;
|
|
12
|
+
update?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare class ScenegraphNode {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
matrix: Matrix4;
|
|
17
|
+
display: boolean;
|
|
18
|
+
position: Vector3;
|
|
19
|
+
rotation: Vector3;
|
|
20
|
+
scale: Vector3;
|
|
21
|
+
userData: Record<string, unknown>;
|
|
22
|
+
props: ScenegraphNodeProps;
|
|
23
|
+
constructor(props?: ScenegraphNodeProps);
|
|
24
|
+
getBounds(): [number[], number[]] | null;
|
|
25
|
+
destroy(): void;
|
|
26
|
+
/** @deprecated use .destroy() */
|
|
27
|
+
delete(): void;
|
|
28
|
+
setProps(props: ScenegraphNodeProps): this;
|
|
29
|
+
toString(): string;
|
|
30
|
+
setPosition(position: any): this;
|
|
31
|
+
setRotation(rotation: any): this;
|
|
32
|
+
setScale(scale: any): this;
|
|
33
|
+
setMatrix(matrix: any, copyMatrix?: boolean): void;
|
|
34
|
+
setMatrixComponents(components: {
|
|
35
|
+
position?: any;
|
|
36
|
+
rotation?: any;
|
|
37
|
+
scale?: any;
|
|
38
|
+
update?: boolean;
|
|
39
|
+
}): this;
|
|
40
|
+
updateMatrix(): this;
|
|
41
|
+
update(options?: {
|
|
42
|
+
position?: any;
|
|
43
|
+
rotation?: any;
|
|
44
|
+
scale?: any;
|
|
45
|
+
}): this;
|
|
46
|
+
getCoordinateUniforms(viewMatrix: any, modelMatrix?: any): {
|
|
47
|
+
viewMatrix: any;
|
|
48
|
+
modelMatrix: any;
|
|
49
|
+
objectMatrix: any;
|
|
50
|
+
worldMatrix: any;
|
|
51
|
+
worldInverseMatrix: any;
|
|
52
|
+
worldInverseTransposeMatrix: any;
|
|
53
|
+
};
|
|
54
|
+
_setScenegraphNodeProps(props: ScenegraphNodeProps): void;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=scenegraph-node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scenegraph-node.d.ts","sourceRoot":"","sources":["../../src/scenegraph/scenegraph-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,YAAY,EAAC,MAAM,eAAe,CAAC;AACxD,OAAO,EAAC,OAAO,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAE/C,+CAA+C;AAC/C,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,2CAA2C;IAC3C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAC;AAEF,qBAAa,cAAc;IACzB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,OAAO,CAAiB;IAEhC,OAAO,UAAQ;IACf,QAAQ,UAAiB;IACzB,QAAQ,UAAiB;IACzB,KAAK,UAAwB;IAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM;IAEvC,KAAK,EAAE,mBAAmB,CAAM;gBAEpB,KAAK,GAAE,mBAAwB;IAQ3C,SAAS,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