@luma.gl/engine 9.0.0-alpha.9 → 9.0.0-beta.10
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 +51 -72
- package/dist/animation/timeline.d.ts +8 -8
- package/dist/animation/timeline.d.ts.map +1 -1
- package/dist/animation/timeline.js +95 -131
- 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 +21 -0
- package/dist/{lib → animation-loop}/animation-loop.d.ts +31 -23
- package/dist/animation-loop/animation-loop.d.ts.map +1 -0
- package/dist/animation-loop/animation-loop.js +442 -0
- package/dist/{lib → animation-loop}/animation-props.d.ts +4 -5
- package/dist/animation-loop/animation-props.d.ts.map +1 -0
- package/dist/animation-loop/animation-props.js +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 +32 -0
- package/dist/computation.d.ts +95 -0
- package/dist/computation.d.ts.map +1 -0
- package/dist/computation.js +248 -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 +43 -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 +46 -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 +27 -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 +39 -0
- package/dist/dist.dev.js +9592 -0
- package/dist/dist.min.js +102 -0
- package/dist/geometries/cone-geometry.d.ts +2 -2
- package/dist/geometries/cone-geometry.d.ts.map +1 -1
- package/dist/geometries/cone-geometry.js +13 -18
- 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 +192 -57
- package/dist/geometries/cylinder-geometry.d.ts +2 -2
- package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
- package/dist/geometries/cylinder-geometry.js +11 -15
- 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 +143 -171
- 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 +95 -122
- 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 +78 -101
- 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 +100 -134
- 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 +3 -1
- package/dist/geometry/geometry-utils.d.ts.map +1 -1
- package/dist/geometry/geometry-utils.js +35 -41
- package/dist/geometry/geometry.d.ts +43 -43
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +82 -139
- 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 +90 -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 +42 -0
- package/dist/index.cjs +3444 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +43 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -15
- 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 +43 -2
- package/dist/lib/pipeline-factory.d.ts +17 -51
- package/dist/lib/pipeline-factory.d.ts.map +1 -1
- package/dist/lib/pipeline-factory.js +84 -209
- 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 +46 -0
- package/dist/model/model.d.ts +219 -0
- package/dist/model/model.d.ts.map +1 -0
- package/dist/model/model.js +659 -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 +84 -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 +35 -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 +153 -0
- package/dist/shader-inputs.d.ts +63 -0
- package/dist/shader-inputs.d.ts.map +1 -0
- package/dist/shader-inputs.js +107 -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 +70 -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 +117 -0
- package/dist.min.js +25 -0
- package/package.json +24 -14
- package/src/animation/timeline.ts +35 -34
- package/src/animation-loop/animation-loop-template.ts +25 -0
- package/src/{lib → animation-loop}/animation-loop.ts +114 -93
- package/src/{lib → animation-loop}/animation-props.ts +2 -2
- package/src/animation-loop/make-animation-loop.ts +53 -0
- package/src/computation.ts +346 -0
- package/src/debug/copy-texture-to-image.ts +70 -0
- package/src/debug/debug-framebuffer.ts +70 -0
- package/src/debug/debug-shader-layout.ts +38 -0
- package/src/debug/pixel-data-utils.ts +54 -0
- package/src/geometries/cone-geometry.ts +1 -1
- package/src/geometries/cube-geometry.ts +62 -56
- 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 +6 -14
- package/src/geometry/geometry-table.ts +10 -7
- package/src/geometry/geometry-utils.ts +19 -3
- package/src/geometry/geometry.ts +68 -110
- package/src/geometry/gpu-geometry.ts +132 -0
- package/src/geometry/gpu-table.ts +41 -0
- package/src/index.ts +37 -10
- package/src/lib/clip-space.ts +32 -34
- package/src/lib/pipeline-factory.ts +83 -193
- package/src/lib/shader-factory.ts +57 -0
- package/src/model/model.ts +835 -0
- package/src/scenegraph/group-node.ts +107 -0
- package/src/scenegraph/model-node.ts +50 -0
- package/src/scenegraph/scenegraph-node.ts +204 -0
- package/src/shader-inputs.ts +157 -0
- package/src/transform/buffer-transform.ts +102 -0
- package/src/transform/texture-transform.ts +168 -0
- package/dist/animation/key-frames.js.map +0 -1
- package/dist/animation/timeline.js.map +0 -1
- 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/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/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/index.js.map +0 -1
- package/dist/lib/animation-loop.d.ts.map +0 -1
- package/dist/lib/animation-loop.js +0 -480
- 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 +0 -2
- package/dist/lib/animation-props.js.map +0 -1
- package/dist/lib/clip-space.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/pipeline-factory.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/model.js
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
import { RenderPipeline } from '@luma.gl/api';
|
|
3
|
-
import { getAttributeBuffersFromGeometry, getIndexBufferFromGeometry } from './model-utils';
|
|
4
|
-
import { PipelineFactory } from './pipeline-factory';
|
|
5
|
-
const DEFAULT_MODEL_PROPS = { ...RenderPipeline._DEFAULT_PROPS,
|
|
6
|
-
vs: null,
|
|
7
|
-
fs: null,
|
|
8
|
-
id: 'unnamed',
|
|
9
|
-
handle: undefined,
|
|
10
|
-
userData: {},
|
|
11
|
-
modules: [],
|
|
12
|
-
moduleSettings: {},
|
|
13
|
-
geometry: null
|
|
14
|
-
};
|
|
15
|
-
export default class Model {
|
|
16
|
-
constructor(device, props) {
|
|
17
|
-
_defineProperty(this, "device", void 0);
|
|
18
|
-
|
|
19
|
-
_defineProperty(this, "pipeline", void 0);
|
|
20
|
-
|
|
21
|
-
_defineProperty(this, "id", void 0);
|
|
22
|
-
|
|
23
|
-
_defineProperty(this, "vs", void 0);
|
|
24
|
-
|
|
25
|
-
_defineProperty(this, "fs", null);
|
|
26
|
-
|
|
27
|
-
_defineProperty(this, "topology", void 0);
|
|
28
|
-
|
|
29
|
-
_defineProperty(this, "vertexCount", void 0);
|
|
30
|
-
|
|
31
|
-
_defineProperty(this, "props", void 0);
|
|
32
|
-
|
|
33
|
-
_defineProperty(this, "_getModuleUniforms", void 0);
|
|
34
|
-
|
|
35
|
-
this.props = { ...DEFAULT_MODEL_PROPS,
|
|
36
|
-
...props
|
|
37
|
-
};
|
|
38
|
-
props = this.props;
|
|
39
|
-
this.id = this.props.id;
|
|
40
|
-
this.device = device;
|
|
41
|
-
|
|
42
|
-
if (!props.vs) {
|
|
43
|
-
throw new Error('no vertex shader');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
this.vs = getShaderSource(this.device, props.vs);
|
|
47
|
-
|
|
48
|
-
if (props.fs) {
|
|
49
|
-
this.fs = getShaderSource(this.device, props.fs);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
this.vertexCount = this.props.vertexCount;
|
|
53
|
-
this.topology = this.props.topology;
|
|
54
|
-
|
|
55
|
-
if (this.props.geometry) {
|
|
56
|
-
this.vertexCount = this.props.geometry.vertexCount;
|
|
57
|
-
this.topology = this.props.geometry.topology || 'triangle-list';
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const pipelineFactory = PipelineFactory.getDefaultPipelineFactory(this.device);
|
|
61
|
-
const {
|
|
62
|
-
pipeline,
|
|
63
|
-
getUniforms
|
|
64
|
-
} = pipelineFactory.createRenderPipeline({ ...this.props,
|
|
65
|
-
vs: this.vs,
|
|
66
|
-
fs: this.fs,
|
|
67
|
-
topology: this.topology,
|
|
68
|
-
parameters: props.parameters,
|
|
69
|
-
layout: props.layout
|
|
70
|
-
});
|
|
71
|
-
this.pipeline = pipeline;
|
|
72
|
-
this._getModuleUniforms = getUniforms;
|
|
73
|
-
|
|
74
|
-
if (this.props.geometry) {
|
|
75
|
-
this._setGeometry(this.props.geometry);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
this.setUniforms(this._getModuleUniforms());
|
|
79
|
-
this.setProps(this.props);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
destroy() {
|
|
83
|
-
this.pipeline.destroy();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
draw(renderPass) {
|
|
87
|
-
this.pipeline.draw({
|
|
88
|
-
renderPass,
|
|
89
|
-
vertexCount: this.vertexCount,
|
|
90
|
-
instanceCount: this.props.instanceCount
|
|
91
|
-
});
|
|
92
|
-
return this;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
setProps(props) {
|
|
96
|
-
if (props.indices) {
|
|
97
|
-
this.setIndexBuffer(props.indices);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (props.attributes) {
|
|
101
|
-
this.setAttributes(props.attributes);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (props.bindings) {
|
|
105
|
-
this.setBindings(props.bindings);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (props.uniforms) {
|
|
109
|
-
this.setUniforms(props.uniforms);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (props.moduleSettings) {
|
|
113
|
-
this.updateModuleSettings(props.moduleSettings);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return this;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
updateModuleSettings(props) {
|
|
120
|
-
const uniforms = this._getModuleUniforms(props);
|
|
121
|
-
|
|
122
|
-
this.setUniforms(uniforms);
|
|
123
|
-
return this;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
setIndexBuffer(indices) {
|
|
127
|
-
this.pipeline.setIndexBuffer(indices);
|
|
128
|
-
return this;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
setAttributes(attributes) {
|
|
132
|
-
this.pipeline.setAttributes(attributes);
|
|
133
|
-
Object.assign(this.props.attributes, attributes);
|
|
134
|
-
return this;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
setBindings(bindings) {
|
|
138
|
-
this.pipeline.setBindings(bindings);
|
|
139
|
-
Object.assign(this.props.bindings, bindings);
|
|
140
|
-
return this;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
setUniforms(uniforms) {
|
|
144
|
-
this.pipeline.setUniforms(uniforms);
|
|
145
|
-
Object.assign(this.props.uniforms, uniforms);
|
|
146
|
-
return this;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
_setGeometry(geometry) {
|
|
150
|
-
const geometryBuffers = getAttributeBuffersFromGeometry(this.device, geometry);
|
|
151
|
-
this.setAttributes(geometryBuffers);
|
|
152
|
-
const indexBuffer = getIndexBufferFromGeometry(this.device, geometry);
|
|
153
|
-
|
|
154
|
-
if (indexBuffer) {
|
|
155
|
-
this.setIndexBuffer(indexBuffer);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function getShaderSource(device, shader) {
|
|
162
|
-
if (typeof shader === 'string') {
|
|
163
|
-
return shader;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
switch (device.info.type) {
|
|
167
|
-
case 'webgpu':
|
|
168
|
-
if (shader !== null && shader !== void 0 && shader.wgsl) {
|
|
169
|
-
return shader.wgsl;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
throw new Error('WebGPU does not support GLSL shaders');
|
|
173
|
-
|
|
174
|
-
default:
|
|
175
|
-
if (shader !== null && shader !== void 0 && shader.glsl) {
|
|
176
|
-
return shader.glsl;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
throw new Error('WebGL does not support WGSL shaders');
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
//# sourceMappingURL=model.js.map
|
package/dist/lib/model.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/model.ts"],"names":["RenderPipeline","getAttributeBuffersFromGeometry","getIndexBufferFromGeometry","PipelineFactory","DEFAULT_MODEL_PROPS","_DEFAULT_PROPS","vs","fs","id","handle","undefined","userData","modules","moduleSettings","geometry","Model","constructor","device","props","Error","getShaderSource","vertexCount","topology","pipelineFactory","getDefaultPipelineFactory","pipeline","getUniforms","createRenderPipeline","parameters","layout","_getModuleUniforms","_setGeometry","setUniforms","setProps","destroy","draw","renderPass","instanceCount","indices","setIndexBuffer","attributes","setAttributes","bindings","setBindings","uniforms","updateModuleSettings","Object","assign","geometryBuffers","indexBuffer","shader","info","type","wgsl","glsl"],"mappings":";AAGA,SAAQA,cAAR,QAA2C,cAA3C;AAGA,SAAQC,+BAAR,EAAyCC,0BAAzC,QAA0E,eAA1E;AACA,SAAQC,eAAR,QAA8B,oBAA9B;AAWA,MAAMC,mBAAyC,GAAG,EAChD,GAAGJ,cAAc,CAACK,cAD8B;AAEhDC,EAAAA,EAAE,EAAE,IAF4C;AAGhDC,EAAAA,EAAE,EAAE,IAH4C;AAIhDC,EAAAA,EAAE,EAAE,SAJ4C;AAKhDC,EAAAA,MAAM,EAAEC,SALwC;AAMhDC,EAAAA,QAAQ,EAAE,EANsC;AAOhDC,EAAAA,OAAO,EAAE,EAPuC;AAQhDC,EAAAA,cAAc,EAAE,EARgC;AAShDC,EAAAA,QAAQ,EAAE;AATsC,CAAlD;AAaA,eAAe,MAAMC,KAAN,CAAY;AAYzBC,EAAAA,WAAW,CAACC,MAAD,EAAiBC,KAAjB,EAAoC;AAAA;;AAAA;;AAAA;;AAAA;;AAAA,gCAPlB,IAOkB;;AAAA;;AAAA;;AAAA;;AAAA;;AAC7C,SAAKA,KAAL,GAAa,EAAC,GAAGd,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E,UAAIF,MAAJ,aAAIA,MAAJ,eAAIA,MAAM,CAAEG,IAAZ,EAAkB;AAChB,eAAOH,MAAM,CAACG,IAAd;AACD;;AACD,YAAM,IAAIlC,KAAJ,CAAU,sCAAV,CAAN;;AAEF;AACE,UAAI+B,MAAJ,aAAIA,MAAJ,eAAIA,MAAM,CAAEI,IAAZ,EAAkB;AAChB,eAAOJ,MAAM,CAACI,IAAd;AACD;;AACD,YAAM,IAAInC,KAAJ,CAAU,qCAAV,CAAN;AAXJ;AAaD","sourcesContent":["// luma.gl, MIT license\n\nimport type {Device, Buffer, RenderPipelineProps, RenderPass, Binding, PrimitiveTopology} from '@luma.gl/api';\nimport {RenderPipeline, Shader, cast} from '@luma.gl/api';\nimport type { ShaderModule } from '@luma.gl/shadertools';\nimport type Geometry from '../geometry/geometry';\nimport {getAttributeBuffersFromGeometry, getIndexBufferFromGeometry} from './model-utils';\nimport {PipelineFactory} from './pipeline-factory';\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 modules?: ShaderModule[];\n moduleSettings?: Record<string, Record<string, any>>;\n geometry?: Geometry | null;\n};\n\nconst DEFAULT_MODEL_PROPS: Required<ModelProps> = {\n ...RenderPipeline._DEFAULT_PROPS,\n vs: null,\n fs: null,\n id: 'unnamed',\n handle: undefined,\n userData: {},\n modules: [],\n moduleSettings: {},\n geometry: null\n};\n\n/** v9 API */\nexport default class Model {\n readonly device: Device;\n readonly pipeline: RenderPipeline;\n readonly id: string;\n readonly vs: string;\n readonly fs: string | null = null;\n readonly topology: PrimitiveTopology;\n readonly vertexCount;\n props: Required<ModelProps>;\n\n private _getModuleUniforms: (props?: Record<string, Record<string, any>>) => Record<string, any>;\n\n constructor(device: Device, props: ModelProps) {\n this.props = {...DEFAULT_MODEL_PROPS, ...props};\n props = this.props;\n this.id = this.props.id;\n this.device = device;\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 = this.props.vertexCount;\n this.topology = this.props.topology;\n\n if (this.props.geometry) {\n this.vertexCount = this.props.geometry.vertexCount;\n this.topology = this.props.geometry.topology || 'triangle-list';\n }\n\n const pipelineFactory = PipelineFactory.getDefaultPipelineFactory(this.device);\n const {pipeline, getUniforms} = pipelineFactory.createRenderPipeline({\n ...this.props,\n vs: this.vs,\n fs: this.fs,\n topology: this.topology,\n parameters: props.parameters,\n layout: props.layout\n });\n\n this.pipeline = pipeline;\n this._getModuleUniforms = getUniforms;\n\n if (this.props.geometry) {\n this._setGeometry(this.props.geometry);\n }\n this.setUniforms(this._getModuleUniforms()) // Get all default module uniforms\n this.setProps(this.props);\n }\n\n destroy(): void {\n this.pipeline.destroy();\n }\n\n draw(renderPass?: RenderPass): this {\n this.pipeline.draw({\n renderPass,\n vertexCount: this.vertexCount,\n instanceCount: this.props.instanceCount\n });\n return this;\n }\n\n setProps(props: ModelProps): this {\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 return this;\n }\n\n updateModuleSettings(props: Record<string, any>): this {\n const uniforms = this._getModuleUniforms(props);\n this.setUniforms(uniforms);\n return this;\n }\n\n setIndexBuffer(indices: Buffer): this {\n this.pipeline.setIndexBuffer(indices);\n // this._indices = indices;\n return this;\n }\n\n setAttributes(attributes: Record<string, Buffer>): this {\n this.pipeline.setAttributes(attributes);\n Object.assign(this.props.attributes, attributes);\n return this;\n }\n\n /** Set the bindings */\n setBindings(bindings: Record<string, Binding>): this {\n this.pipeline.setBindings(bindings);\n Object.assign(this.props.bindings, bindings);\n return this;\n }\n\n setUniforms(uniforms: Record<string, any>): this {\n this.pipeline.setUniforms(uniforms);\n Object.assign(this.props.uniforms, uniforms);\n return this;\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"],"file":"model.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/pipeline-factory.ts"],"names":["assembleShaders","DEFAULT_RENDER_PIPELINE_OPTIONS","vs","fs","modules","defines","inject","transpileToGLSL100","layout","varyings","bufferMode","topology","parameters","PipelineFactory","getDefaultPipelineFactory","device","defaultPipelineFactory","constructor","addDefaultModule","module","_defaultModules","find","m","name","push","stateHash","removeDefaultModule","moduleName","filter","addShaderHook","hook","opts","Object","assign","_hookFunctions","createRenderPipeline","options","props","_getModuleList","hash","_hashRenderPipeline","_pipelineCache","pipeline","getUniforms","_createRenderPipeline","_getUniforms","x","_useCounts","release","destroy","platformInfo","gpu","info","features","Error","assembled","hookFunctions","createShader","stage","source","vsHash","_getHash","fsHash","moduleHashes","map","sort","varyingHashes","v","defineKeys","keys","injectKeys","defineHashes","injectHashes","key","parameterHash","JSON","stringify","join","_hashes","undefined","_hashCounter","appModules","Array","length","seen","count","i","len"],"mappings":";AAGA,SAAQ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AApL0B","sourcesContent":["import type {RenderPipelineProps, RenderPipelineParameters, PrimitiveTopology, ShaderLayout} from '@luma.gl/api';\nimport {Device, RenderPipeline, ComputePipeline} from '@luma.gl/api/';\nimport type { ShaderModule } from '@luma.gl/shadertools';\nimport {assembleShaders} from '@luma.gl/shadertools';\n\nexport type GetRenderPipelineOptions = {\n vs: string;\n fs: string | null;\n topology: PrimitiveTopology;\n layout?: ShaderLayout | null;\n parameters?: RenderPipelineParameters;\n\n modules?: ShaderModule[];\n defines?: Record<string, string | number | boolean>;\n inject?: Record<string, string>;\n transpileToGLSL100?: boolean;\n\n varyings?: string[];\n bufferMode?: number, \n};\n\nexport type GetComputePipelineOptions = {\n cs: string;\n parameters?: RenderPipelineParameters;\n\n modules?: ShaderModule[];\n defines?: Record<string, string>;\n inject?: Record<string, string>;\n transpileToGLSL100?: boolean;\n\n varyings?: string[];\n bufferMode?: number;\n};\n\nconst DEFAULT_RENDER_PIPELINE_OPTIONS: Required<GetRenderPipelineOptions> = {\n vs: '',\n fs: '',\n modules: [],\n defines: {},\n inject: {},\n transpileToGLSL100: false,\n layout: null,\n\n varyings: [],\n bufferMode: 0x8c8d, // // varyings/bufferMode for xform feedback, 0x8c8d: SEPARATE_ATTRIBS\n topology: 'triangle-list',\n parameters: {} \n};\n\ntype GetUniformsFunc = (props?: Record<string, any>) => Record<string, any>;\n\n/** Efficiently create shared pipelines with varying parameters */\nexport class PipelineFactory {\n readonly device: Device;\n\n stateHash: number = 0; // Used to change hashing if hooks are modified\n private _hashCounter: number = 0;\n private readonly _hashes: Record<string, number> = {};\n private readonly _useCounts: Record<string, number> = {};\n\n private readonly _pipelineCache: Record<string, RenderPipeline> = {};\n\n private readonly _getUniforms: Record<string, GetUniformsFunc> = {};\n private readonly _hookFunctions: any[] = [];\n private _defaultModules: any[] = [];\n // private readonly _registeredModules = {}; // TODO: Remove? This isn't used anywhere in luma.gl\n\n static getDefaultPipelineFactory(device: Device): PipelineFactory {\n // @ts-expect-error Add to device\n device.defaultPipelineFactory = device.defaultPipelineFactory || new PipelineFactory(device);\n // @ts-expect-error Add to device\n return device.defaultPipelineFactory;\n }\n\n constructor(device: Device) {\n this.device = device;\n }\n\n addDefaultModule(module: ShaderModule): void {\n if (!this._defaultModules.find((m) => m.name === (typeof module === 'string' ? module : module.name))) {\n this._defaultModules.push(module);\n }\n this.stateHash++;\n }\n\n removeDefaultModule(module: ShaderModule): void {\n const moduleName = typeof module === 'string' ? module : module.name;\n this._defaultModules = this._defaultModules.filter((m) => m.name !== moduleName);\n this.stateHash++;\n }\n\n addShaderHook(hook, opts?): void {\n if (opts) {\n hook = Object.assign(opts, {hook});\n }\n this._hookFunctions.push(hook);\n this.stateHash++;\n }\n\n createRenderPipeline(options: GetRenderPipelineOptions): {\n pipeline: RenderPipeline;\n getUniforms: GetUniformsFunc;\n } {\n const props: Required<GetRenderPipelineOptions> = {...DEFAULT_RENDER_PIPELINE_OPTIONS, ...options};\n\n const modules = this._getModuleList(props.modules); // Combine with default modules\n\n const hash = this._hashRenderPipeline({...props, modules});\n\n if (!this._pipelineCache[hash]) {\n const {pipeline, getUniforms} = this._createRenderPipeline({...props, modules});\n pipeline.hash = hash;\n this._pipelineCache[hash] = pipeline;\n this._getUniforms[hash] = getUniforms || ((x?: unknown) => ({}));\n this._useCounts[hash] = 0;\n }\n\n this._useCounts[hash]++;\n\n return {\n pipeline: this._pipelineCache[hash],\n getUniforms: this._getUniforms[hash]\n };\n }\n\n release(pipeline: RenderPipeline): void {\n const hash = pipeline.hash;\n this._useCounts[hash]--;\n if (this._useCounts[hash] === 0) {\n this._pipelineCache[hash].destroy();\n delete this._pipelineCache[hash];\n delete this._getUniforms[hash];\n delete this._useCounts[hash];\n }\n }\n\n getUniforms(pipeline: RenderPipeline) {\n return this._getUniforms[pipeline.hash] || null;\n }\n\n // PRIVATE\n\n _createRenderPipeline(props: GetRenderPipelineOptions): {\n pipeline: RenderPipeline,\n getUniforms: GetUniformsFunc\n } {\n const platformInfo = {\n gpu: this.device.info.gpu,\n features: this.device.features\n };\n\n if (!props.fs) {\n throw new Error('fs');\n }\n\n const assembled = assembleShaders(platformInfo, {...props, fs: props.fs, hookFunctions: this._hookFunctions});\n\n const pipeline = this.device.createRenderPipeline({\n ...props,\n vs: this.device.createShader({stage: 'vertex', source: assembled.vs}),\n fs: assembled.fs ? this.device.createShader({stage: 'fragment', source: assembled.fs}) : null,\n });\n\n return {pipeline, getUniforms: assembled.getUniforms};\n }\n\n /** Calculate a hash based on all the inputs for a render pipeline */\n _hashRenderPipeline(props: GetRenderPipelineOptions): string {\n const {modules = [], varyings = [], defines = [], inject = [], parameters = []} = props;\n const vsHash = this._getHash(props.vs);\n const fsHash = props.fs ? this._getHash(props.fs) : 0;\n\n const moduleHashes = modules.map((m) => this._getHash(typeof m === 'string' ? m : m.name)).sort();\n const varyingHashes = varyings.map((v) => this._getHash(v));\n\n const defineKeys = Object.keys(defines).sort();\n const injectKeys = Object.keys(inject).sort();\n const defineHashes: number[] = [];\n const injectHashes: number[] = [];\n\n for (const key of defineKeys) {\n defineHashes.push(this._getHash(key));\n defineHashes.push(this._getHash(defines[key]));\n }\n\n for (const key of injectKeys) {\n injectHashes.push(this._getHash(key));\n injectHashes.push(this._getHash(inject[key]));\n }\n\n // TODO - hash parameters!\n const parameterHash = JSON.stringify(parameters);\n\n return `${vsHash}/${fsHash}D${defineHashes.join('/')}M${moduleHashes.join(\n '/'\n )}I${injectHashes.join('/')}V${varyingHashes.join('/')}H${this.stateHash}B${props.bufferMode}${\n props.transpileToGLSL100 ? 'T' : ''\n }P${parameterHash}`;\n }\n\n _getHash(key: string): number {\n if (this._hashes[key] === undefined) {\n this._hashes[key] = this._hashCounter++;\n }\n return this._hashes[key];\n }\n\n // Dedupe and combine with default modules\n _getModuleList(appModules: ShaderModule[] = []): ShaderModule[] {\n const modules = new Array(this._defaultModules.length + appModules.length);\n const seen: Record<string, boolean> = {};\n let count = 0;\n\n for (let i = 0, len = this._defaultModules.length; i < len; ++i) {\n const module = this._defaultModules[i];\n const name = module.name;\n modules[count++] = module;\n seen[name] = true;\n }\n\n for (let i = 0, len = appModules.length; i < len; ++i) {\n const module = appModules[i];\n const name = module.name;\n if (!seen[name]) {\n modules[count++] = module;\n seen[name] = true;\n }\n }\n\n modules.length = count;\n\n return modules;\n }\n}\n"],"file":"pipeline-factory.js"}
|
|
@@ -1,14 +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
|
-
* Minimal animation loop that initializes models in constructor
|
|
6
|
-
* Simplifying type management
|
|
7
|
-
* v9 API
|
|
8
|
-
*/
|
|
9
|
-
export declare abstract class RenderLoop {
|
|
10
|
-
constructor(animationProps?: AnimationProps);
|
|
11
|
-
/** Instantiates and runs the render loop */
|
|
12
|
-
static run(RenderLoopConstructor: typeof RenderLoop, deviceProps?: DeviceProps): AnimationLoop;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=render-loop.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"render-loop.d.ts","sourceRoot":"","sources":["../../src/lib/render-loop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAE/C;;;;GAIG;AACH,8BAAsB,UAAU;gBAClB,cAAc,CAAC,EAAE,cAAc;IAE3C,4CAA4C;IAC5C,MAAM,CAAC,GAAG,CAAC,qBAAqB,EAAE,OAAO,UAAU,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,aAAa;CAS/F"}
|
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
|
-
}
|