@luma.gl/engine 9.0.0-alpha.5 → 9.0.0-alpha.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/LICENSE +3 -1
  2. package/dist/animation/key-frames.d.ts +1 -1
  3. package/dist/animation/key-frames.d.ts.map +1 -1
  4. package/dist/animation/key-frames.js +6 -27
  5. package/dist/animation/key-frames.js.map +1 -1
  6. package/dist/animation/timeline.d.ts +9 -9
  7. package/dist/animation/timeline.d.ts.map +1 -1
  8. package/dist/animation/timeline.js +18 -49
  9. package/dist/animation/timeline.js.map +1 -1
  10. package/dist/{lib → animation-loop}/animation-loop.d.ts +30 -31
  11. package/dist/animation-loop/animation-loop.d.ts.map +1 -0
  12. package/dist/{lib → animation-loop}/animation-loop.js +115 -199
  13. package/dist/animation-loop/animation-loop.js.map +1 -0
  14. package/dist/{lib → animation-loop}/animation-props.d.ts +6 -7
  15. package/dist/animation-loop/animation-props.d.ts.map +1 -0
  16. package/dist/animation-loop/animation-props.js.map +1 -0
  17. package/dist/animation-loop/make-animation-loop.d.ts +6 -0
  18. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -0
  19. package/dist/animation-loop/make-animation-loop.js +28 -0
  20. package/dist/animation-loop/make-animation-loop.js.map +1 -0
  21. package/dist/animation-loop/render-loop.d.ts +23 -0
  22. package/dist/animation-loop/render-loop.d.ts.map +1 -0
  23. package/dist/animation-loop/render-loop.js +7 -0
  24. package/dist/animation-loop/render-loop.js.map +1 -0
  25. package/dist/dist.dev.js +7064 -0
  26. package/dist/geometries/cone-geometry.d.ts +1 -1
  27. package/dist/geometries/cone-geometry.d.ts.map +1 -1
  28. package/dist/geometries/cone-geometry.js +6 -5
  29. package/dist/geometries/cone-geometry.js.map +1 -1
  30. package/dist/geometries/cube-geometry.d.ts +2 -2
  31. package/dist/geometries/cube-geometry.d.ts.map +1 -1
  32. package/dist/geometries/cube-geometry.js +15 -8
  33. package/dist/geometries/cube-geometry.js.map +1 -1
  34. package/dist/geometries/cylinder-geometry.d.ts +1 -1
  35. package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
  36. package/dist/geometries/cylinder-geometry.js +6 -5
  37. package/dist/geometries/cylinder-geometry.js.map +1 -1
  38. package/dist/geometries/ico-sphere-geometry.d.ts +2 -2
  39. package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
  40. package/dist/geometries/ico-sphere-geometry.js +10 -19
  41. package/dist/geometries/ico-sphere-geometry.js.map +1 -1
  42. package/dist/geometries/plane-geometry.d.ts +2 -2
  43. package/dist/geometries/plane-geometry.d.ts.map +1 -1
  44. package/dist/geometries/plane-geometry.js +14 -23
  45. package/dist/geometries/plane-geometry.js.map +1 -1
  46. package/dist/geometries/sphere-geometry.d.ts +2 -2
  47. package/dist/geometries/sphere-geometry.d.ts.map +1 -1
  48. package/dist/geometries/sphere-geometry.js +9 -13
  49. package/dist/geometries/sphere-geometry.js.map +1 -1
  50. package/dist/geometries/truncated-cone-geometry.d.ts +2 -4
  51. package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
  52. package/dist/geometries/truncated-cone-geometry.js +9 -25
  53. package/dist/geometries/truncated-cone-geometry.js.map +1 -1
  54. package/dist/geometry/geometry-table.d.ts +2 -2
  55. package/dist/geometry/geometry-table.d.ts.map +1 -1
  56. package/dist/geometry/geometry-table.js.map +1 -1
  57. package/dist/geometry/geometry-utils.d.ts.map +1 -1
  58. package/dist/geometry/geometry-utils.js +0 -9
  59. package/dist/geometry/geometry-utils.js.map +1 -1
  60. package/dist/geometry/geometry.d.ts +50 -59
  61. package/dist/geometry/geometry.d.ts.map +1 -1
  62. package/dist/geometry/geometry.js +32 -97
  63. package/dist/geometry/geometry.js.map +1 -1
  64. package/dist/geometry/gpu-geometry.d.ts +37 -0
  65. package/dist/geometry/gpu-geometry.d.ts.map +1 -0
  66. package/dist/geometry/gpu-geometry.js +107 -0
  67. package/dist/geometry/gpu-geometry.js.map +1 -0
  68. package/dist/geometry/gpu-table.d.ts +1 -0
  69. package/dist/geometry/gpu-table.d.ts.map +1 -0
  70. package/dist/geometry/gpu-table.js +2 -0
  71. package/dist/geometry/gpu-table.js.map +1 -0
  72. package/dist/index.cjs +2959 -0
  73. package/dist/index.d.ts +26 -9
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +23 -13
  76. package/dist/index.js.map +1 -1
  77. package/dist/lib/clip-space.d.ts +8 -0
  78. package/dist/lib/clip-space.d.ts.map +1 -1
  79. package/dist/lib/clip-space.js +47 -0
  80. package/dist/lib/clip-space.js.map +1 -1
  81. package/dist/lib/pipeline-factory.d.ts +12 -40
  82. package/dist/lib/pipeline-factory.d.ts.map +1 -1
  83. package/dist/lib/pipeline-factory.js +50 -148
  84. package/dist/lib/pipeline-factory.js.map +1 -1
  85. package/dist/model/model.d.ts +192 -0
  86. package/dist/model/model.d.ts.map +1 -0
  87. package/dist/model/model.js +312 -0
  88. package/dist/model/model.js.map +1 -0
  89. package/dist/scenegraph/group-node.d.ts +21 -0
  90. package/dist/scenegraph/group-node.d.ts.map +1 -0
  91. package/dist/scenegraph/group-node.js +94 -0
  92. package/dist/scenegraph/group-node.js.map +1 -0
  93. package/dist/scenegraph/model-node.d.ts +18 -0
  94. package/dist/scenegraph/model-node.d.ts.map +1 -0
  95. package/dist/scenegraph/model-node.js +28 -0
  96. package/dist/scenegraph/model-node.js.map +1 -0
  97. package/dist/scenegraph/scenegraph-node.d.ts +56 -0
  98. package/dist/scenegraph/scenegraph-node.d.ts.map +1 -0
  99. package/dist/scenegraph/scenegraph-node.js +141 -0
  100. package/dist/scenegraph/scenegraph-node.js.map +1 -0
  101. package/dist/shader-inputs.d.ts +62 -0
  102. package/dist/shader-inputs.d.ts.map +1 -0
  103. package/dist/shader-inputs.js +49 -0
  104. package/dist/shader-inputs.js.map +1 -0
  105. package/dist/transform/buffer-transform.d.ts +35 -0
  106. package/dist/transform/buffer-transform.d.ts.map +1 -0
  107. package/dist/transform/buffer-transform.js +62 -0
  108. package/dist/transform/buffer-transform.js.map +1 -0
  109. package/dist/transform/texture-transform.d.ts +57 -0
  110. package/dist/transform/texture-transform.d.ts.map +1 -0
  111. package/dist/transform/texture-transform.js +122 -0
  112. package/dist/transform/texture-transform.js.map +1 -0
  113. package/dist.min.js +286 -0
  114. package/package.json +21 -12
  115. package/src/animation/timeline.ts +16 -15
  116. package/src/{lib → animation-loop}/animation-loop.ts +120 -107
  117. package/src/{lib → animation-loop}/animation-props.ts +5 -5
  118. package/src/animation-loop/make-animation-loop.ts +44 -0
  119. package/src/animation-loop/render-loop.ts +23 -0
  120. package/src/geometries/cone-geometry.ts +1 -1
  121. package/src/geometries/cube-geometry.ts +6 -3
  122. package/src/geometries/cylinder-geometry.ts +2 -2
  123. package/src/geometries/ico-sphere-geometry.ts +7 -6
  124. package/src/geometries/plane-geometry.ts +5 -4
  125. package/src/geometries/sphere-geometry.ts +4 -3
  126. package/src/geometries/truncated-cone-geometry.ts +4 -13
  127. package/src/geometry/geometry-table.ts +1 -1
  128. package/src/geometry/geometry-utils.ts +3 -3
  129. package/src/geometry/geometry.ts +79 -119
  130. package/src/geometry/gpu-geometry.ts +124 -0
  131. package/src/geometry/gpu-table.ts +41 -0
  132. package/src/index.ts +38 -12
  133. package/src/lib/clip-space.ts +22 -21
  134. package/src/lib/pipeline-factory.ts +60 -168
  135. package/src/model/model.ts +549 -0
  136. package/src/scenegraph/group-node.ts +103 -0
  137. package/src/scenegraph/model-node.ts +50 -0
  138. package/src/scenegraph/scenegraph-node.ts +204 -0
  139. package/src/shader-inputs.ts +132 -0
  140. package/src/transform/buffer-transform.ts +94 -0
  141. package/src/transform/texture-transform.ts +169 -0
  142. package/dist/bundle.d.ts +0 -2
  143. package/dist/bundle.d.ts.map +0 -1
  144. package/dist/bundle.js +0 -5
  145. package/dist/bundle.js.map +0 -1
  146. package/dist/geometry/primitive-utils.d.ts +0 -1
  147. package/dist/geometry/primitive-utils.d.ts.map +0 -1
  148. package/dist/geometry/primitive-utils.js +0 -2
  149. package/dist/geometry/primitive-utils.js.map +0 -1
  150. package/dist/lib/animation-loop.d.ts.map +0 -1
  151. package/dist/lib/animation-loop.js.map +0 -1
  152. package/dist/lib/animation-props.d.ts.map +0 -1
  153. package/dist/lib/animation-props.js.map +0 -1
  154. package/dist/lib/model-utils.d.ts +0 -5
  155. package/dist/lib/model-utils.d.ts.map +0 -1
  156. package/dist/lib/model-utils.js +0 -45
  157. package/dist/lib/model-utils.js.map +0 -1
  158. package/dist/lib/model.d.ts +0 -41
  159. package/dist/lib/model.d.ts.map +0 -1
  160. package/dist/lib/model.js +0 -176
  161. package/dist/lib/model.js.map +0 -1
  162. package/dist/lib/render-loop.d.ts +0 -14
  163. package/dist/lib/render-loop.d.ts.map +0 -1
  164. package/dist/lib/render-loop.js +0 -49
  165. package/dist/lib/render-loop.js.map +0 -1
  166. package/src/bundle.ts +0 -4
  167. package/src/geometry/primitive-utils.ts +0 -30
  168. package/src/lib/model-utils.ts +0 -124
  169. package/src/lib/model.ts +0 -179
  170. package/src/lib/render-loop.ts +0 -58
  171. /package/dist/{lib → animation-loop}/animation-props.js +0 -0
@@ -0,0 +1,204 @@
1
+ import {assert, uid, NumberArray} from '@luma.gl/core';
2
+ import {Vector3, Matrix4} from '@math.gl/core';
3
+
4
+ /** Properties for creating a new Scenegraph */
5
+ export type ScenegraphNodeProps = {
6
+ id?: string;
7
+ /** whether to display the object at all */
8
+ display?: boolean;
9
+ matrix?: NumberArray;
10
+ position?: NumberArray;
11
+ rotation?: NumberArray;
12
+ scale?: NumberArray;
13
+ update?: boolean
14
+ };
15
+
16
+ export class ScenegraphNode {
17
+ readonly id: string;
18
+ matrix: Matrix4 = new Matrix4();
19
+
20
+ display = true;
21
+ position = new Vector3();
22
+ rotation = new Vector3();
23
+ scale = new Vector3(1, 1, 1);
24
+ userData: Record<string, unknown> = {};
25
+
26
+ props: ScenegraphNodeProps = {};
27
+
28
+ constructor(props: ScenegraphNodeProps = {}) {
29
+ const {id} = props;
30
+
31
+ this.id = id || uid(this.constructor.name);
32
+
33
+ this._setScenegraphNodeProps(props);
34
+ }
35
+
36
+ getBounds(): [number[], number[]] | null {
37
+ return null;
38
+ }
39
+
40
+ destroy(): void {}
41
+
42
+ /** @deprecated use .destroy() */
43
+ delete(): void {
44
+ this.destroy();
45
+ }
46
+ setProps(props: ScenegraphNodeProps): this {
47
+ this._setScenegraphNodeProps(props);
48
+ return this;
49
+ }
50
+
51
+ toString(): string {
52
+ return `{type: ScenegraphNode, id: ${this.id})}`;
53
+ }
54
+
55
+ setPosition(position: any): this {
56
+ assert(position.length === 3, 'setPosition requires vector argument');
57
+ this.position = position;
58
+ return this;
59
+ }
60
+
61
+ setRotation(rotation: any): this {
62
+ assert(rotation.length === 3, 'setRotation requires vector argument');
63
+ this.rotation = rotation;
64
+ return this;
65
+ }
66
+
67
+ setScale(scale: any): this {
68
+ assert(scale.length === 3, 'setScale requires vector argument');
69
+ this.scale = scale;
70
+ return this;
71
+ }
72
+
73
+ setMatrix(matrix: any, copyMatrix: boolean = true): void {
74
+ if (copyMatrix) {
75
+ this.matrix.copy(matrix);
76
+ } else {
77
+ this.matrix = matrix;
78
+ }
79
+ }
80
+
81
+ setMatrixComponents(components: {
82
+ position?: any;
83
+ rotation?: any;
84
+ scale?: any;
85
+ update?: boolean;
86
+ }): this {
87
+ const {position, rotation, scale, update = true} = components;
88
+ if (position) {
89
+ this.setPosition(position);
90
+ }
91
+ if (rotation) {
92
+ this.setRotation(rotation);
93
+ }
94
+ if (scale) {
95
+ this.setScale(scale);
96
+ }
97
+ if (update) {
98
+ this.updateMatrix();
99
+ }
100
+ return this;
101
+ }
102
+
103
+ updateMatrix(): this {
104
+ const pos = this.position;
105
+ const rot = this.rotation;
106
+ const scale = this.scale;
107
+
108
+ this.matrix.identity();
109
+ this.matrix.translate(pos);
110
+ this.matrix.rotateXYZ(rot);
111
+ this.matrix.scale(scale);
112
+ return this;
113
+ }
114
+
115
+ update(options: {position?: any; rotation?: any; scale?: any} = {}): this {
116
+ const {position, rotation, scale} = options;
117
+ if (position) {
118
+ this.setPosition(position);
119
+ }
120
+ if (rotation) {
121
+ this.setRotation(rotation);
122
+ }
123
+ if (scale) {
124
+ this.setScale(scale);
125
+ }
126
+ this.updateMatrix();
127
+ return this;
128
+ }
129
+
130
+ getCoordinateUniforms(
131
+ viewMatrix: any,
132
+ modelMatrix?: any
133
+ ): {
134
+ viewMatrix: any;
135
+ modelMatrix: any;
136
+ objectMatrix: any;
137
+ worldMatrix: any;
138
+ worldInverseMatrix: any;
139
+ worldInverseTransposeMatrix: any;
140
+ } {
141
+ // TODO - solve multiple class problem
142
+ // assert(viewMatrix instanceof Matrix4);
143
+ assert(viewMatrix);
144
+ modelMatrix = modelMatrix || this.matrix;
145
+ const worldMatrix = new Matrix4(viewMatrix).multiplyRight(modelMatrix);
146
+ const worldInverse = worldMatrix.invert();
147
+ const worldInverseTranspose = worldInverse.transpose();
148
+
149
+ return {
150
+ viewMatrix,
151
+ modelMatrix,
152
+ objectMatrix: modelMatrix,
153
+ worldMatrix,
154
+ worldInverseMatrix: worldInverse,
155
+ worldInverseTransposeMatrix: worldInverseTranspose
156
+ };
157
+ }
158
+
159
+ // TODO - copied code, not yet vetted
160
+ /*
161
+ transform() {
162
+ if (!this.parent) {
163
+ this.endPosition.set(this.position);
164
+ this.endRotation.set(this.rotation);
165
+ this.endScale.set(this.scale);
166
+ } else {
167
+ const parent = this.parent;
168
+ this.endPosition.set(this.position.add(parent.endPosition));
169
+ this.endRotation.set(this.rotation.add(parent.endRotation));
170
+ this.endScale.set(this.scale.add(parent.endScale));
171
+ }
172
+
173
+ const ch = this.children;
174
+ for (let i = 0; i < ch.length; ++i) {
175
+ ch[i].transform();
176
+ }
177
+
178
+ return this;
179
+ }
180
+ */
181
+
182
+ _setScenegraphNodeProps(props: ScenegraphNodeProps): void {
183
+ if ('display' in props) {
184
+ this.display = props.display;
185
+ }
186
+
187
+ if ('position' in props) {
188
+ this.setPosition(props.position);
189
+ }
190
+ if ('rotation' in props) {
191
+ this.setRotation(props.rotation);
192
+ }
193
+ if ('scale' in props) {
194
+ this.setScale(props.scale);
195
+ }
196
+
197
+ // Matrix overwrites other props
198
+ if ('matrix' in props) {
199
+ this.setMatrix(props.matrix);
200
+ }
201
+
202
+ Object.assign(this.props, props);
203
+ }
204
+ }
@@ -0,0 +1,132 @@
1
+ // luma.gl, MIT license
2
+ import type {UniformValue, Texture, Sampler} from '@luma.gl/core';
3
+ import {log} from '@luma.gl/core';
4
+ // import type {ShaderUniformType, UniformValue, UniformFormat, UniformInfoDevice, Texture, Sampler} from '@luma.gl/core';
5
+ import {_resolveModules, ShaderModuleInstance} from '@luma.gl/shadertools'
6
+
7
+
8
+ /** Minimal ShaderModule subset, we don't need shader code etc */
9
+ export type ShaderModuleInputs<
10
+ PropsT extends Record<string, unknown> = Record<string, unknown>,
11
+ UniformsT extends Record<string, UniformValue> = Record<string, UniformValue>,
12
+ BindingsT extends Record<string, Texture | Sampler> = Record<string, Texture | Sampler>
13
+ > = {
14
+ defaultUniforms?: UniformsT;
15
+ getUniforms?: (settings: Partial<PropsT>, prevUniforms?: UniformsT) => UniformsT;
16
+
17
+ /** Not used. Used to access props type */
18
+ props?: PropsT;
19
+
20
+ bindings?: Record<
21
+ keyof BindingsT,
22
+ {
23
+ location: number;
24
+ type: 'texture' | 'sampler' | 'uniforms';
25
+ }
26
+ >;
27
+
28
+ uniformTypes?: any;
29
+ };
30
+
31
+ /**
32
+ * ShaderInputs holds uniform and binding values for one or more shader modules,
33
+ * - It can generate binary data for any uniform buffer
34
+ * - It can manage a uniform buffer for each block
35
+ * - It can update managed uniform buffers with a single call
36
+ * - It performs some book keeping on what has changed to minimize unnecessary writes to uniform buffers.
37
+ */
38
+ export class ShaderInputs<
39
+ ShaderPropsT extends Partial<Record<string, Record<string, unknown>>> = Partial<
40
+ Record<string, Record<string, unknown>>
41
+ >
42
+ > {
43
+ /**
44
+ * The map of modules
45
+ * @todo should should this include the resolved dependencies?
46
+ */
47
+ modules: Readonly<{[P in keyof ShaderPropsT]: ShaderModuleInputs<ShaderPropsT[P]>}>;
48
+
49
+ /** Stores the uniform values for each module */
50
+ moduleUniforms: Record<keyof ShaderPropsT, Record<string, UniformValue>>;
51
+ /** Stores the uniform bindings for each module */
52
+ moduleBindings: Record<keyof ShaderPropsT, Record<string, Texture | Sampler>>;
53
+ /** Tracks if uniforms have changed */
54
+ moduleUniformsChanged: Record<keyof ShaderPropsT, false | string>;
55
+
56
+ /**
57
+ * Create a new UniformStore instance
58
+ * @param modules
59
+ */
60
+ constructor(modules: {[P in keyof ShaderPropsT]: ShaderModuleInputs<ShaderPropsT[P]>}) {
61
+ // TODO - get all dependencies from modules
62
+ const allModules =_resolveModules(Object.values(modules));
63
+ log.log(1, 'Creating ShaderInputs with modules', allModules.map(m => m.name))();
64
+
65
+ // Store the module definitions and create storage for uniform values and binding values, per module
66
+ this.modules = modules;
67
+ this.moduleUniforms = {} as Record<keyof ShaderPropsT, Record<string, UniformValue>>;
68
+ this.moduleBindings = {} as Record<keyof ShaderPropsT, Record<string, Texture | Sampler>>;
69
+
70
+ // Initialize the modules
71
+ for (const [name, module] of Object.entries(modules)) {
72
+ const moduleName = name as keyof ShaderPropsT;
73
+
74
+ // Get default uniforms from module
75
+ this.moduleUniforms[moduleName] = module.defaultUniforms || {};
76
+ this.moduleBindings[moduleName] = {};
77
+ }
78
+ }
79
+
80
+ /** Destroy */
81
+ destroy(): void {}
82
+
83
+ /**
84
+ * Set module props
85
+ */
86
+ setProps(props: Partial<{[P in keyof ShaderPropsT]?: Partial<ShaderPropsT[P]>}>): void {
87
+ for (const name of Object.keys(props)) {
88
+ const moduleName = name as keyof ShaderPropsT;
89
+ const moduleProps = props[moduleName];
90
+ const module = this.modules[moduleName];
91
+
92
+ const oldUniforms = this.moduleUniforms[moduleName];
93
+ const uniforms = module.getUniforms?.(moduleProps, this.moduleUniforms[moduleName]) || moduleProps as any;
94
+ // console.error(uniforms)
95
+ this.moduleUniforms[moduleName] = {...oldUniforms, ...uniforms};
96
+ // this.moduleUniformsChanged ||= moduleName;
97
+
98
+ // console.log(`setProps(${String(moduleName)}`, moduleName, this.moduleUniforms[moduleName])
99
+
100
+ // TODO - Get Module bindings
101
+ // const bindings = module.getBindings?.(moduleProps);
102
+ // this.moduleUniforms[moduleName] = bindings;
103
+ }
104
+ }
105
+
106
+ /** Merges all bindings for the shader (from the various modules) */
107
+ // getUniformBlocks(): Record<string, Texture | Sampler> {
108
+ // return this.moduleUniforms;
109
+ // }
110
+
111
+ /**
112
+ * Return the map of modules
113
+ * @todo should should this include the resolved dependencies?
114
+ */
115
+ getModules(): ShaderModuleInstance[] {
116
+ return Object.values(this.modules);
117
+ }
118
+
119
+ /** Get all uniform values for all modules */
120
+ getUniformValues(): Record<keyof ShaderPropsT, Record<string, UniformValue>> {
121
+ return this.moduleUniforms;
122
+ }
123
+
124
+ /** Merges all bindings for the shader (from the various modules) */
125
+ getBindings(): Record<string, Texture | Sampler> {
126
+ const bindings = {} as Record<string, Texture | Sampler>;
127
+ for (const moduleBindings of Object.values(this.moduleBindings)) {
128
+ Object.assign(bindings, moduleBindings);
129
+ }
130
+ return bindings;
131
+ }
132
+ }
@@ -0,0 +1,94 @@
1
+ // luma.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
4
+ import {Device, Buffer, BufferRange, TransformFeedback, assert, RenderPassProps} from '@luma.gl/core';
5
+ import {getPassthroughFS} from '@luma.gl/shadertools';
6
+ import {Model} from '../model/model';
7
+ import type { ModelProps } from '..';
8
+
9
+ /**
10
+ * Properties for creating a {@link BufferTransform}
11
+ * @deprecated
12
+ */
13
+ export type BufferTransformProps = Omit<ModelProps, 'fs'> & {
14
+ fs?: ModelProps['fs']; // override as optional
15
+ feedbackBuffers?: Record<string, Buffer | BufferRange>;
16
+ };
17
+
18
+ /**
19
+ * Creates a pipeline for buffer→buffer transforms.
20
+ * @deprecated
21
+ */
22
+ export class BufferTransform {
23
+ readonly device: Device;
24
+ readonly model: Model;
25
+ readonly transformFeedback: TransformFeedback;
26
+
27
+ /** @deprecated Use device feature test. */
28
+ static isSupported(device: Device): boolean {
29
+ return device.features.has('transform-feedback-webgl2');
30
+ }
31
+
32
+ constructor(device: Device, props: BufferTransformProps = Model.defaultProps) {
33
+ assert(device.features.has('transform-feedback-webgl2'), 'Device must support transform feedback');
34
+
35
+ this.device = device;
36
+
37
+ this.model = new Model(this.device, {
38
+ id: props.id || 'buffer-transform-model',
39
+ fs: props.fs || getPassthroughFS({version: 300}),
40
+ topology: props.topology || 'point-list',
41
+ ...props,
42
+ });
43
+
44
+ this.transformFeedback = this.device.createTransformFeedback({
45
+ layout: this.model.pipeline.shaderLayout,
46
+ buffers: props.feedbackBuffers,
47
+ });
48
+
49
+ this.model.setTransformFeedback(this.transformFeedback);
50
+
51
+ Object.seal(this);
52
+ }
53
+
54
+ /** Destroy owned resources. */
55
+ destroy(): void {
56
+ if (this.model) {
57
+ this.model.destroy();
58
+ }
59
+ }
60
+
61
+ /** @deprecated Use {@link destroy}. */
62
+ delete(): void {
63
+ this.destroy();
64
+ }
65
+
66
+ /** Run one transform loop. */
67
+ run(options?: RenderPassProps): void {
68
+ const renderPass = this.device.beginRenderPass(options);
69
+ this.model.draw(renderPass);
70
+ renderPass.end();
71
+ }
72
+
73
+ /** @deprecated */
74
+ update(...args: any[]): void {
75
+ // TODO(v9): Method should likely be removed for v9. Keeping a method stub
76
+ // to assist with migrating DeckGL usage.
77
+ // eslint-disable-next-line no-console
78
+ console.warn('TextureTransform#update() not implemented');
79
+ }
80
+
81
+ /** Returns the {@link Buffer} or {@link BufferRange} for given varying name. */
82
+ getBuffer(varyingName: string): Buffer | BufferRange | null {
83
+ return this.transformFeedback.getBuffer(varyingName);
84
+ }
85
+
86
+ readAsync(varyingName: string): Promise<Uint8Array> {
87
+ const result = this.getBuffer(varyingName);
88
+ if (result instanceof Buffer) {
89
+ return result.readAsync();
90
+ }
91
+ const {buffer, byteOffset = 0, byteLength = buffer.byteLength} = result;
92
+ return buffer.readAsync(byteOffset, byteLength);
93
+ }
94
+ }
@@ -0,0 +1,169 @@
1
+ // luma.gl, MIT license
2
+ // Copyright (c) vis.gl contributors
3
+
4
+ import { Buffer, Device, Framebuffer, RenderPassProps, Sampler, Texture } from '@luma.gl/core';
5
+ import { Model, ModelProps } from '../model/model';
6
+ import { getPassthroughFS } from '@luma.gl/shadertools';
7
+
8
+ /**
9
+ * Properties for creating a {@link TextureTransform}
10
+ * @deprecated
11
+ */
12
+ export type TextureTransformProps = Omit<ModelProps, 'fs'> & {
13
+ fs?: ModelProps['fs']; // override as optional
14
+ /** @deprecated TODO(donmccurdy): Needed? */
15
+ inject?: Record<string, string>;
16
+ /** @deprecated TODO(donmccurdy): Needed? */
17
+ framebuffer?: Framebuffer;
18
+ /** @deprecated TODO(donmccurdy): Model already handles this? */
19
+ sourceBuffers?: Record<string, Buffer>;
20
+ /** @deprecated TODO(donmccurdy): Model already handles this? */
21
+ sourceTextures?: Record<string, Texture>;
22
+ targetTexture: Texture;
23
+ targetTextureChannels: 1 | 2 | 3 | 4;
24
+ targetTextureVarying: string;
25
+ };
26
+
27
+
28
+ type TextureBinding = {
29
+ sourceBuffers: Record<string, Buffer>;
30
+ sourceTextures: Record<string, Texture>;
31
+ targetTexture: Texture;
32
+ framebuffer?: Framebuffer;
33
+ };
34
+
35
+ const FS_OUTPUT_VARIABLE = 'transform_output';
36
+
37
+ /**
38
+ * Creates a pipeline for texture→texture transforms.
39
+ * @deprecated
40
+ */
41
+ export class TextureTransform {
42
+ readonly device: Device;
43
+ readonly model: Model;
44
+ readonly sampler: Sampler;
45
+
46
+ currentIndex = 0;
47
+ samplerTextureMap: Record<string, any> | null = null;
48
+ bindings: TextureBinding[] = []; // each element is an object : {sourceTextures, targetTexture, framebuffer}
49
+ resources: Record<string, any> = {}; // resources to be deleted
50
+
51
+ constructor(device: Device, props: TextureTransformProps) {
52
+ this.device = device;
53
+
54
+ // For precise picking of element IDs.
55
+ this.sampler = device.createSampler({
56
+ addressModeU: 'clamp-to-edge',
57
+ addressModeV: 'clamp-to-edge',
58
+ minFilter: 'nearest',
59
+ magFilter: 'nearest',
60
+ mipmapFilter: 'nearest',
61
+ });
62
+
63
+ this.model = new Model(this.device, {
64
+ id: props.id || 'texture-transform-model',
65
+ fs: props.fs || getPassthroughFS({
66
+ version: 300,
67
+ input: props.targetTextureVarying,
68
+ inputChannels: props.targetTextureChannels,
69
+ output: FS_OUTPUT_VARIABLE
70
+ }),
71
+ vertexCount: props.vertexCount, // TODO(donmccurdy): Naming?
72
+ ...props
73
+ });
74
+
75
+ this._initialize(props);
76
+ Object.seal(this);
77
+ }
78
+
79
+ // Delete owned resources.
80
+ destroy(): void {}
81
+
82
+ /** @deprecated Use {@link destroy}. */
83
+ delete(): void {
84
+ this.destroy();
85
+ }
86
+
87
+ run(options?: RenderPassProps): void {
88
+ const {framebuffer} = this.bindings[this.currentIndex];
89
+ const renderPass = this.device.beginRenderPass({framebuffer, ...options});
90
+ this.model.draw(renderPass);
91
+ renderPass.end();
92
+ }
93
+
94
+ /** @deprecated */
95
+ update(...args: any[]): void {
96
+ // TODO(v9): Method should likely be removed for v9. Keeping a method stub
97
+ // to assist with migrating DeckGL usage.
98
+ // eslint-disable-next-line no-console
99
+ console.warn('TextureTransform#update() not implemented');
100
+ }
101
+
102
+
103
+ getData({packed = false} = {}) {
104
+ // TODO(v9): Method should likely be removed for v9. Keeping a method stub
105
+ // to assist with migrating DeckGL usage.
106
+ throw new Error('getData() not implemented');
107
+ }
108
+
109
+ getTargetTexture(): Texture {
110
+ const {targetTexture} = this.bindings[this.currentIndex];
111
+ return targetTexture;
112
+ }
113
+
114
+
115
+ getFramebuffer(): Framebuffer {
116
+ const currentResources = this.bindings[this.currentIndex];
117
+ return currentResources.framebuffer;
118
+ }
119
+
120
+ // Private
121
+
122
+ _initialize(props: TextureTransformProps): void {
123
+ this._updateBindings(props);
124
+ }
125
+
126
+ _updateBindings(props: TextureTransformProps) {
127
+ this.bindings[this.currentIndex] = this._updateBinding(this.bindings[this.currentIndex], props);
128
+ }
129
+
130
+ _updateBinding(
131
+ binding: TextureBinding,
132
+ {sourceBuffers, sourceTextures, targetTexture}: TextureTransformProps
133
+ ): TextureBinding {
134
+ if (!binding) {
135
+ binding = {
136
+ sourceBuffers: {},
137
+ sourceTextures: {},
138
+ targetTexture: null
139
+ };
140
+ }
141
+ Object.assign(binding.sourceTextures, sourceTextures);
142
+ Object.assign(binding.sourceBuffers, sourceBuffers);
143
+ if (targetTexture) {
144
+ binding.targetTexture = targetTexture;
145
+ const {width, height} = targetTexture;
146
+ // TODO(donmccurdy): When is this called, and is this expected?
147
+ if (binding.framebuffer) {
148
+ binding.framebuffer.destroy();
149
+ }
150
+ binding.framebuffer = this.device.createFramebuffer({
151
+ id: 'transform-framebuffer',
152
+ width,
153
+ height,
154
+ colorAttachments: [targetTexture]
155
+ });
156
+ binding.framebuffer.resize({width, height});
157
+ }
158
+ return binding;
159
+ }
160
+
161
+ // set texture filtering parameters on source textures.
162
+ _setSourceTextureParameters(): void {
163
+ const index = this.currentIndex;
164
+ const {sourceTextures} = this.bindings[index];
165
+ for (const name in sourceTextures) {
166
+ sourceTextures[name].sampler = this.sampler;
167
+ }
168
+ }
169
+ }
package/dist/bundle.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare const moduleExports: any;
2
- //# sourceMappingURL=bundle.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,aAAa,KAAqB,CAAC"}
package/dist/bundle.js DELETED
@@ -1,5 +0,0 @@
1
- const moduleExports = require('./index');
2
-
3
- globalThis.luma = globalThis.luma || {};
4
- module.exports = Object.assign(globalThis.luma, moduleExports);
5
- //# sourceMappingURL=bundle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/bundle.ts"],"names":["moduleExports","require","globalThis","luma","module","exports","Object","assign"],"mappings":"AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,IAAX,GAAkBD,UAAU,CAACC,IAAX,IAAmB,EAArC;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,IAAzB,EAA+BH,aAA/B,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.luma = globalThis.luma || {};\nmodule.exports = Object.assign(globalThis.luma, moduleExports);\n"],"file":"bundle.js"}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=primitive-utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"primitive-utils.d.ts","sourceRoot":"","sources":["../../src/geometry/primitive-utils.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=primitive-utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"primitive-utils.js"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"animation-loop.d.ts","sourceRoot":"","sources":["../../src/lib/animation-loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,MAAM,EAAE,WAAW,EAAC,MAAM,cAAc,CAAC;AAEvD,OAAO,EAAC,QAAQ,EAAC,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAC,cAAc,EAAC,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAC,KAAK,EAAE,IAAI,EAAC,MAAM,iBAAiB,CAAC;AAS5C,+BAA+B;AAC/B,oBAAY,kBAAkB,GAAG;IAC/B,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACzD,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,MAAM,CAAC;IAC5C,YAAY,CAAC,EAAE,CAAC,cAAc,EAAE,cAAc,KAAK,IAAI,CAAC;IACxD,QAAQ,CA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