@luma.gl/engine 9.0.0-alpha.14 → 9.0.0-alpha.16

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 (172) hide show
  1. package/dist/animation/key-frames.d.ts +1 -1
  2. package/dist/animation/key-frames.d.ts.map +1 -1
  3. package/dist/animation/key-frames.js +51 -72
  4. package/dist/animation/timeline.d.ts +4 -4
  5. package/dist/animation/timeline.d.ts.map +1 -1
  6. package/dist/animation/timeline.js +94 -131
  7. package/dist/animation-loop/animation-loop.d.ts +2 -3
  8. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  9. package/dist/animation-loop/animation-loop.js +414 -473
  10. package/dist/animation-loop/animation-props.d.ts +1 -2
  11. package/dist/animation-loop/animation-props.d.ts.map +1 -1
  12. package/dist/animation-loop/animation-props.js +0 -1
  13. package/dist/animation-loop/make-animation-loop.d.ts +1 -1
  14. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
  15. package/dist/animation-loop/make-animation-loop.js +26 -31
  16. package/dist/animation-loop/render-loop.js +17 -7
  17. package/dist/bundle.js +2 -2
  18. package/dist/dist.min.js +31 -0
  19. package/dist/es5/animation/key-frames.js +84 -0
  20. package/dist/es5/animation/key-frames.js.map +1 -0
  21. package/dist/es5/animation/timeline.js +183 -0
  22. package/dist/es5/animation/timeline.js.map +1 -0
  23. package/dist/es5/animation-loop/animation-loop.js +534 -0
  24. package/dist/es5/animation-loop/animation-loop.js.map +1 -0
  25. package/dist/es5/animation-loop/animation-props.js +2 -0
  26. package/dist/es5/animation-loop/animation-props.js.map +1 -0
  27. package/dist/es5/animation-loop/make-animation-loop.js +53 -0
  28. package/dist/es5/animation-loop/make-animation-loop.js.map +1 -0
  29. package/dist/es5/animation-loop/render-loop.js +39 -0
  30. package/dist/es5/animation-loop/render-loop.js.map +1 -0
  31. package/dist/es5/bundle.js +6 -0
  32. package/dist/es5/bundle.js.map +1 -0
  33. package/dist/es5/geometries/cone-geometry.js +43 -0
  34. package/dist/es5/geometries/cone-geometry.js.map +1 -0
  35. package/dist/es5/geometries/cube-geometry.js +84 -0
  36. package/dist/es5/geometries/cube-geometry.js.map +1 -0
  37. package/dist/es5/geometries/cylinder-geometry.js +39 -0
  38. package/dist/es5/geometries/cylinder-geometry.js.map +1 -0
  39. package/dist/es5/geometries/ico-sphere-geometry.js +185 -0
  40. package/dist/es5/geometries/ico-sphere-geometry.js.map +1 -0
  41. package/dist/es5/geometries/plane-geometry.js +137 -0
  42. package/dist/es5/geometries/plane-geometry.js.map +1 -0
  43. package/dist/es5/geometries/sphere-geometry.js +120 -0
  44. package/dist/es5/geometries/sphere-geometry.js.map +1 -0
  45. package/dist/es5/geometries/truncated-cone-geometry.js +160 -0
  46. package/dist/es5/geometries/truncated-cone-geometry.js.map +1 -0
  47. package/dist/es5/geometry/geometry-table.js +2 -0
  48. package/dist/es5/geometry/geometry-table.js.map +1 -0
  49. package/dist/es5/geometry/geometry-utils.js +39 -0
  50. package/dist/es5/geometry/geometry-utils.js.map +1 -0
  51. package/dist/es5/geometry/geometry.js +150 -0
  52. package/dist/es5/geometry/geometry.js.map +1 -0
  53. package/dist/es5/geometry/primitive-utils.js +2 -0
  54. package/dist/es5/geometry/primitive-utils.js.map +1 -0
  55. package/dist/es5/index.js +112 -0
  56. package/dist/es5/index.js.map +1 -0
  57. package/dist/es5/lib/clip-space.js +2 -0
  58. package/dist/es5/lib/clip-space.js.map +1 -0
  59. package/dist/es5/lib/model-utils.js +52 -0
  60. package/dist/es5/lib/model-utils.js.map +1 -0
  61. package/dist/es5/lib/model.js +173 -0
  62. package/dist/es5/lib/model.js.map +1 -0
  63. package/dist/es5/lib/pipeline-factory.js +244 -0
  64. package/dist/es5/lib/pipeline-factory.js.map +1 -0
  65. package/dist/esm/animation/key-frames.js +57 -0
  66. package/dist/esm/animation/key-frames.js.map +1 -0
  67. package/dist/esm/animation/timeline.js +113 -0
  68. package/dist/esm/animation/timeline.js.map +1 -0
  69. package/dist/esm/animation-loop/animation-loop.js +367 -0
  70. package/dist/esm/animation-loop/animation-loop.js.map +1 -0
  71. package/dist/esm/animation-loop/animation-props.js +2 -0
  72. package/dist/esm/animation-loop/animation-props.js.map +1 -0
  73. package/dist/esm/animation-loop/make-animation-loop.js +28 -0
  74. package/dist/esm/animation-loop/make-animation-loop.js.map +1 -0
  75. package/dist/esm/animation-loop/render-loop.js +7 -0
  76. package/dist/esm/animation-loop/render-loop.js.map +1 -0
  77. package/dist/esm/bundle.js +4 -0
  78. package/dist/esm/bundle.js.map +1 -0
  79. package/dist/esm/geometries/cone-geometry.js +21 -0
  80. package/dist/esm/geometries/cone-geometry.js.map +1 -0
  81. package/dist/esm/geometries/cube-geometry.js +67 -0
  82. package/dist/esm/geometries/cube-geometry.js.map +1 -0
  83. package/dist/esm/geometries/cylinder-geometry.js +18 -0
  84. package/dist/esm/geometries/cylinder-geometry.js.map +1 -0
  85. package/dist/esm/geometries/ico-sphere-geometry.js +170 -0
  86. package/dist/esm/geometries/ico-sphere-geometry.js.map +1 -0
  87. package/dist/esm/geometries/plane-geometry.js +119 -0
  88. package/dist/esm/geometries/plane-geometry.js.map +1 -0
  89. package/dist/esm/geometries/sphere-geometry.js +102 -0
  90. package/dist/esm/geometries/sphere-geometry.js.map +1 -0
  91. package/dist/esm/geometries/truncated-cone-geometry.js +136 -0
  92. package/dist/esm/geometries/truncated-cone-geometry.js.map +1 -0
  93. package/dist/esm/geometry/geometry-table.js +2 -0
  94. package/dist/esm/geometry/geometry-table.js.map +1 -0
  95. package/dist/esm/geometry/geometry-utils.js +37 -0
  96. package/dist/esm/geometry/geometry-utils.js.map +1 -0
  97. package/dist/esm/geometry/geometry.js +119 -0
  98. package/dist/esm/geometry/geometry.js.map +1 -0
  99. package/dist/esm/geometry/primitive-utils.js +2 -0
  100. package/dist/esm/geometry/primitive-utils.js.map +1 -0
  101. package/dist/esm/index.js +16 -0
  102. package/dist/esm/index.js.map +1 -0
  103. package/dist/esm/lib/clip-space.js +2 -0
  104. package/dist/esm/lib/clip-space.js.map +1 -0
  105. package/dist/esm/lib/model-utils.js +40 -0
  106. package/dist/esm/lib/model-utils.js.map +1 -0
  107. package/dist/esm/lib/model.js +146 -0
  108. package/dist/esm/lib/model.js.map +1 -0
  109. package/dist/esm/lib/pipeline-factory.js +180 -0
  110. package/dist/esm/lib/pipeline-factory.js.map +1 -0
  111. package/dist/geometries/cone-geometry.d.ts +1 -1
  112. package/dist/geometries/cone-geometry.d.ts.map +1 -1
  113. package/dist/geometries/cone-geometry.js +12 -17
  114. package/dist/geometries/cube-geometry.d.ts +1 -1
  115. package/dist/geometries/cube-geometry.d.ts.map +1 -1
  116. package/dist/geometries/cube-geometry.js +187 -56
  117. package/dist/geometries/cylinder-geometry.d.ts +1 -1
  118. package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
  119. package/dist/geometries/cylinder-geometry.js +10 -14
  120. package/dist/geometries/ico-sphere-geometry.d.ts +1 -1
  121. package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
  122. package/dist/geometries/ico-sphere-geometry.js +141 -170
  123. package/dist/geometries/plane-geometry.d.ts +1 -1
  124. package/dist/geometries/plane-geometry.d.ts.map +1 -1
  125. package/dist/geometries/plane-geometry.js +93 -121
  126. package/dist/geometries/sphere-geometry.d.ts +1 -1
  127. package/dist/geometries/sphere-geometry.d.ts.map +1 -1
  128. package/dist/geometries/sphere-geometry.js +76 -100
  129. package/dist/geometries/truncated-cone-geometry.d.ts +1 -1
  130. package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
  131. package/dist/geometries/truncated-cone-geometry.js +104 -131
  132. package/dist/geometry/geometry-table.d.ts +1 -1
  133. package/dist/geometry/geometry-table.d.ts.map +1 -1
  134. package/dist/geometry/geometry-table.js +0 -1
  135. package/dist/geometry/geometry-utils.js +22 -41
  136. package/dist/geometry/geometry.d.ts +4 -4
  137. package/dist/geometry/geometry.d.ts.map +1 -1
  138. package/dist/geometry/geometry.js +96 -142
  139. package/dist/geometry/primitive-utils.js +30 -1
  140. package/dist/index.js +20 -16
  141. package/dist/lib/clip-space.js +50 -1
  142. package/dist/lib/model-utils.js +97 -29
  143. package/dist/lib/model.d.ts +1 -1
  144. package/dist/lib/model.d.ts.map +1 -1
  145. package/dist/lib/model.js +122 -166
  146. package/dist/lib/pipeline-factory.d.ts +3 -3
  147. package/dist/lib/pipeline-factory.d.ts.map +1 -1
  148. package/dist/lib/pipeline-factory.js +136 -204
  149. package/package.json +12 -11
  150. package/dist/animation/key-frames.js.map +0 -1
  151. package/dist/animation/timeline.js.map +0 -1
  152. package/dist/animation-loop/animation-loop.js.map +0 -1
  153. package/dist/animation-loop/animation-props.js.map +0 -1
  154. package/dist/animation-loop/make-animation-loop.js.map +0 -1
  155. package/dist/animation-loop/render-loop.js.map +0 -1
  156. package/dist/bundle.js.map +0 -1
  157. package/dist/geometries/cone-geometry.js.map +0 -1
  158. package/dist/geometries/cube-geometry.js.map +0 -1
  159. package/dist/geometries/cylinder-geometry.js.map +0 -1
  160. package/dist/geometries/ico-sphere-geometry.js.map +0 -1
  161. package/dist/geometries/plane-geometry.js.map +0 -1
  162. package/dist/geometries/sphere-geometry.js.map +0 -1
  163. package/dist/geometries/truncated-cone-geometry.js.map +0 -1
  164. package/dist/geometry/geometry-table.js.map +0 -1
  165. package/dist/geometry/geometry-utils.js.map +0 -1
  166. package/dist/geometry/geometry.js.map +0 -1
  167. package/dist/geometry/primitive-utils.js.map +0 -1
  168. package/dist/index.js.map +0 -1
  169. package/dist/lib/clip-space.js.map +0 -1
  170. package/dist/lib/model-utils.js.map +0 -1
  171. package/dist/lib/model.js.map +0 -1
  172. package/dist/lib/pipeline-factory.js.map +0 -1
@@ -0,0 +1,37 @@
1
+ export function unpackIndexedGeometry(geometry) {
2
+ const {
3
+ indices,
4
+ attributes
5
+ } = geometry;
6
+ if (!indices) {
7
+ return geometry;
8
+ }
9
+ const vertexCount = indices.value.length;
10
+ const unpackedAttributes = {};
11
+ for (const attributeName in attributes) {
12
+ const attribute = attributes[attributeName];
13
+ const {
14
+ constant,
15
+ value,
16
+ size
17
+ } = attribute;
18
+ if (constant || !size) {
19
+ continue;
20
+ }
21
+ const unpackedValue = new value.constructor(vertexCount * size);
22
+ for (let x = 0; x < vertexCount; ++x) {
23
+ const index = indices.value[x];
24
+ for (let i = 0; i < size; i++) {
25
+ unpackedValue[x * size + i] = value[index * size + i];
26
+ }
27
+ }
28
+ unpackedAttributes[attributeName] = {
29
+ size,
30
+ value: unpackedValue
31
+ };
32
+ }
33
+ return {
34
+ attributes: Object.assign({}, attributes, unpackedAttributes)
35
+ };
36
+ }
37
+ //# sourceMappingURL=geometry-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry-utils.js","names":["unpackIndexedGeometry","geometry","indices","attributes","vertexCount","value","length","unpackedAttributes","attributeName","attribute","constant","size","unpackedValue","constructor","x","index","i","Object","assign"],"sources":["../../../src/geometry/geometry-utils.ts"],"sourcesContent":["// import type Geometry from './geometry';\n\nexport function unpackIndexedGeometry(geometry: any) {\n const {indices, attributes} = geometry;\n if (!indices) {\n return geometry;\n }\n\n const vertexCount = indices.value.length;\n const unpackedAttributes: Record<string, any> = {};\n\n for (const attributeName in attributes) {\n const attribute = attributes[attributeName];\n const {constant, value, size} = attribute;\n if (constant || !size) {\n continue; // eslint-disable-line\n }\n const unpackedValue = new value.constructor(vertexCount * size);\n for (let x = 0; x < vertexCount; ++x) {\n const index = indices.value[x];\n for (let i = 0; i < size; i++) {\n unpackedValue[x * size + i] = value[index * size + i];\n }\n }\n unpackedAttributes[attributeName] = {size, value: unpackedValue};\n }\n\n return {\n attributes: Object.assign({}, attributes, unpackedAttributes)\n };\n}\n"],"mappings":"AAEA,OAAO,SAASA,qBAAqBA,CAACC,QAAa,EAAE;EACnD,MAAM;IAACC,OAAO;IAAEC;EAAU,CAAC,GAAGF,QAAQ;EACtC,IAAI,CAACC,OAAO,EAAE;IACZ,OAAOD,QAAQ;EACjB;EAEA,MAAMG,WAAW,GAAGF,OAAO,CAACG,KAAK,CAACC,MAAM;EACxC,MAAMC,kBAAuC,GAAG,CAAC,CAAC;EAElD,KAAK,MAAMC,aAAa,IAAIL,UAAU,EAAE;IACtC,MAAMM,SAAS,GAAGN,UAAU,CAACK,aAAa,CAAC;IAC3C,MAAM;MAACE,QAAQ;MAAEL,KAAK;MAAEM;IAAI,CAAC,GAAGF,SAAS;IACzC,IAAIC,QAAQ,IAAI,CAACC,IAAI,EAAE;MACrB;IACF;IACA,MAAMC,aAAa,GAAG,IAAIP,KAAK,CAACQ,WAAW,CAACT,WAAW,GAAGO,IAAI,CAAC;IAC/D,KAAK,IAAIG,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGV,WAAW,EAAE,EAAEU,CAAC,EAAE;MACpC,MAAMC,KAAK,GAAGb,OAAO,CAACG,KAAK,CAACS,CAAC,CAAC;MAC9B,KAAK,IAAIE,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGL,IAAI,EAAEK,CAAC,EAAE,EAAE;QAC7BJ,aAAa,CAACE,CAAC,GAAGH,IAAI,GAAGK,CAAC,CAAC,GAAGX,KAAK,CAACU,KAAK,GAAGJ,IAAI,GAAGK,CAAC,CAAC;MACvD;IACF;IACAT,kBAAkB,CAACC,aAAa,CAAC,GAAG;MAACG,IAAI;MAAEN,KAAK,EAAEO;IAAa,CAAC;EAClE;EAEA,OAAO;IACLT,UAAU,EAAEc,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,EAAEf,UAAU,EAAEI,kBAAkB;EAC9D,CAAC;AACH"}
@@ -0,0 +1,119 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import { uid, assert } from '@luma.gl/api';
3
+ import GL from '@luma.gl/constants';
4
+ export default class Geometry {
5
+ constructor() {
6
+ let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7
+ _defineProperty(this, "id", void 0);
8
+ _defineProperty(this, "userData", {});
9
+ _defineProperty(this, "topology", void 0);
10
+ _defineProperty(this, "drawMode", GL.TRIANGLES);
11
+ _defineProperty(this, "vertexCount", void 0);
12
+ _defineProperty(this, "attributes", void 0);
13
+ _defineProperty(this, "indices", void 0);
14
+ const {
15
+ id = uid('geometry'),
16
+ drawMode = GL.TRIANGLES,
17
+ attributes = {},
18
+ indices = null,
19
+ vertexCount = null
20
+ } = props;
21
+ this.id = id;
22
+ this.drawMode = drawMode;
23
+ this.topology = props.topology || convertToTopology(drawMode);
24
+ if (indices) {
25
+ this.indices = ArrayBuffer.isView(indices) ? {
26
+ value: indices,
27
+ size: 1
28
+ } : indices;
29
+ }
30
+ this.attributes = {};
31
+ for (const [attributeName, attributeValue] of Object.entries(attributes)) {
32
+ const attribute = ArrayBuffer.isView(attributeValue) ? {
33
+ value: attributeValue
34
+ } : attributeValue;
35
+ assert(ArrayBuffer.isView(attribute.value), "".concat(this._print(attributeName), ": must be typed array or object with value as typed array"));
36
+ if ((attributeName === 'POSITION' || attributeName === 'positions') && !attribute.size) {
37
+ attribute.size = 3;
38
+ }
39
+ if (attributeName === 'indices') {
40
+ assert(!this.indices);
41
+ this.indices = attribute;
42
+ } else {
43
+ this.attributes[attributeName] = attribute;
44
+ }
45
+ }
46
+ if (this.indices && this.indices.isIndexed !== undefined) {
47
+ this.indices = Object.assign({}, this.indices);
48
+ delete this.indices.isIndexed;
49
+ }
50
+ this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);
51
+ }
52
+ get mode() {
53
+ return this.drawMode;
54
+ }
55
+ getVertexCount() {
56
+ return this.vertexCount;
57
+ }
58
+ getAttributes() {
59
+ return this.indices ? {
60
+ indices: this.indices,
61
+ ...this.attributes
62
+ } : this.attributes;
63
+ }
64
+ _print(attributeName) {
65
+ return "Geometry ".concat(this.id, " attribute ").concat(attributeName);
66
+ }
67
+ _setAttributes(attributes, indices) {
68
+ return this;
69
+ }
70
+ _calculateVertexCount(attributes, indices) {
71
+ if (indices) {
72
+ return indices.value.length;
73
+ }
74
+ let vertexCount = Infinity;
75
+ for (const attributeName in attributes) {
76
+ const attribute = attributes[attributeName];
77
+ const {
78
+ value,
79
+ size,
80
+ constant
81
+ } = attribute;
82
+ if (!constant && value && size >= 1) {
83
+ vertexCount = Math.min(vertexCount, value.length / size);
84
+ }
85
+ }
86
+ assert(Number.isFinite(vertexCount));
87
+ return vertexCount;
88
+ }
89
+ }
90
+ _defineProperty(Geometry, "DRAW_MODE", {
91
+ POINTS: GL.POINTS,
92
+ LINES: GL.LINES,
93
+ LINE_LOOP: GL.LINE_LOOP,
94
+ LINE_STRIP: GL.LINE_STRIP,
95
+ TRIANGLES: GL.TRIANGLES,
96
+ TRIANGLE_STRIP: GL.TRIANGLE_STRIP,
97
+ TRIANGLE_FAN: GL.TRIANGLE_FAN
98
+ });
99
+ function convertToTopology(drawMode) {
100
+ switch (drawMode) {
101
+ case GL.POINTS:
102
+ return 'point-list';
103
+ case GL.LINES:
104
+ return 'line-list';
105
+ case GL.LINE_STRIP:
106
+ return 'line-strip';
107
+ case GL.TRIANGLES:
108
+ return 'triangle-list';
109
+ case GL.TRIANGLE_STRIP:
110
+ return 'triangle-strip';
111
+ case GL.TRIANGLE_FAN:
112
+ return 'triangle-fan';
113
+ case GL.LINE_LOOP:
114
+ return 'line-loop';
115
+ default:
116
+ throw new Error(String(drawMode));
117
+ }
118
+ }
119
+ //# sourceMappingURL=geometry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry.js","names":["uid","assert","GL","Geometry","constructor","props","arguments","length","undefined","_defineProperty","TRIANGLES","id","drawMode","attributes","indices","vertexCount","topology","convertToTopology","ArrayBuffer","isView","value","size","attributeName","attributeValue","Object","entries","attribute","concat","_print","isIndexed","assign","_calculateVertexCount","mode","getVertexCount","getAttributes","_setAttributes","Infinity","constant","Math","min","Number","isFinite","POINTS","LINES","LINE_LOOP","LINE_STRIP","TRIANGLE_STRIP","TRIANGLE_FAN","Error","String"],"sources":["../../../src/geometry/geometry.ts"],"sourcesContent":["// luma.gl, MIT license\nimport type {PrimitiveTopology, TypedArray} from '@luma.gl/api';\nimport {uid, assert} from '@luma.gl/api';\nimport GL from '@luma.gl/constants';\n\n/**\n * Rendering primitives - \"topology\" specifies how to extract primitives from vertices.\n * @deprecated - use string constants instead\n */\nexport type GLTopology =\n GL.POINTS | // draw single points.\n GL.LINES | // draw lines. Each vertex connects to the one after it.\n GL.LINE_LOOP | // draw lines. Each set of two vertices is treated as a separate line segment.\n GL.LINE_STRIP | // draw a connected group of line segments from the first vertex to the last\n GL.TRIANGLES | // draw triangles. Each set of three vertices creates a separate triangle.\n GL.TRIANGLE_STRIP | // draw a connected group of triangles.\n GL.TRIANGLE_FAN // draw a connected group of triangles.\n ;\n\nexport type GeometryAttribute = {\n size?: number;\n value: TypedArray;\n [key: string]: any\n}\n\nexport type GeometryProps = {\n id?: string;\n attributes?: Record<string, GeometryAttribute | TypedArray>,\n indices?: GeometryAttribute | TypedArray;\n vertexCount?: number;\n /** Determines how vertices are read from the 'vertex' attributes */\n topology?: 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip';\n /** @deprecated */\n drawMode?: GLTopology;\n};\n\ntype GeometryAttributes = {\n POSITION: GeometryAttribute,\n NORMAL: GeometryAttribute,\n TEXCOORD_0: GeometryAttribute,\n COLOR_0?: GeometryAttribute,\n indices?: {size?: number, value: Uint32Array | Uint16Array};\n};\n\nexport default class Geometry {\n /** @deprecated */\n static DRAW_MODE = {\n POINTS: GL.POINTS, // draw single points.\n LINES: GL.LINES, // draw lines. Each vertex connects to the one after it.\n LINE_LOOP: GL.LINE_LOOP, // draw lines. Each set of two vertices is treated as a separate line segment.\n LINE_STRIP: GL.LINE_STRIP, // draw a connected group of line segments from the first vertex to the last\n TRIANGLES: GL.TRIANGLES, // draw triangles. Each set of three vertices creates a separate triangle.\n TRIANGLE_STRIP: GL.TRIANGLE_STRIP, // draw a connected group of triangles.\n TRIANGLE_FAN: GL.TRIANGLE_FAN // draw a connected group of triangles.\n };\n\n readonly id: string;\n userData: Record<string, unknown> = {};\n\n /** Determines how vertices are read from the 'vertex' attributes */\n topology?: PrimitiveTopology;\n /** @deprecated */\n readonly drawMode: GLTopology = GL.TRIANGLES;\n\n readonly vertexCount: number;\n readonly attributes: {\n POSITION: GeometryAttribute,\n NORMAL: GeometryAttribute,\n TEXCOORD_0: GeometryAttribute,\n COLOR_0?: GeometryAttribute,\n [key: string]: GeometryAttribute | undefined\n };\n readonly indices?: Uint16Array | Uint32Array;\n\n constructor(props: GeometryProps = {}) {\n const {\n id = uid('geometry'),\n drawMode = GL.TRIANGLES,\n attributes = {},\n indices = null,\n vertexCount = null\n } = props;\n\n this.id = id;\n this.drawMode = drawMode;\n this.topology = props.topology || convertToTopology(drawMode);\n\n if (indices) {\n // @ts-expect-error\n this.indices = ArrayBuffer.isView(indices) ? {value: indices, size: 1} : indices;\n }\n\n // @ts-expect-error\n this.attributes = {};\n\n for (const [attributeName, attributeValue] of Object.entries(attributes)) {\n\n // Wrap \"unwrapped\" arrays and try to autodetect their type\n const attribute: GeometryAttribute = ArrayBuffer.isView(attributeValue) ? {value: attributeValue} : attributeValue;\n\n assert(\n ArrayBuffer.isView(attribute.value),\n `${this._print(attributeName)}: must be typed array or object with value as typed array`\n );\n\n if ((attributeName === 'POSITION' || attributeName === 'positions') && !attribute.size) {\n attribute.size = 3;\n }\n\n // Move indices to separate field\n if (attributeName === 'indices') {\n assert(!this.indices);\n // @ts-expect-error\n this.indices = attribute;\n } else {\n this.attributes[attributeName] = attribute;\n }\n }\n\n // @ts-expect-error\n if (this.indices && this.indices.isIndexed !== undefined) {\n this.indices = Object.assign({}, this.indices);\n // @ts-expect-error\n delete this.indices.isIndexed;\n }\n\n this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);\n }\n\n /** @deprecated Use string topology constants instead */\n get mode() {\n return this.drawMode;\n }\n\n getVertexCount(): number {\n return this.vertexCount;\n }\n\n // Return an object with all attributes plus indices added as a field.\n getAttributes(): GeometryAttributes {\n // @ts-expect-error Geometry types are a mess\n return this.indices ? {indices: this.indices, ...this.attributes} : this.attributes;\n }\n\n // PRIVATE\n\n _print(attributeName: string): string {\n return `Geometry ${this.id} attribute ${attributeName}`;\n }\n\n // GeometryAttribute\n // value: typed array\n // type: indices, vertices, uvs\n // size: elements per vertex\n // target: WebGL buffer type (string or constant)\n _setAttributes(attributes: Record<string, GeometryAttribute>, indices: any): this {\n\n return this;\n }\n\n _calculateVertexCount(attributes: any, indices: any): number {\n if (indices) {\n return indices.value.length;\n }\n let vertexCount = Infinity;\n for (const attributeName in attributes) {\n const attribute = attributes[attributeName];\n const {value, size, constant} = attribute;\n if (!constant && value && size >= 1) {\n vertexCount = Math.min(vertexCount, value.length / size);\n }\n }\n\n assert(Number.isFinite(vertexCount));\n return vertexCount;\n }\n}\n\nfunction convertToTopology(drawMode: GLTopology): PrimitiveTopology {\n switch (drawMode) {\n case GL.POINTS: return 'point-list'; // draw single points.\n case GL.LINES: return 'line-list'; // draw lines. Each vertex connects to the one after it.\n case GL.LINE_STRIP: return 'line-strip'; // draw a connected group of line segments from the first vertex to the last\n case GL.TRIANGLES: return 'triangle-list'; // draw triangles. Each set of three vertices creates a separate triangle.\n case GL.TRIANGLE_STRIP: return 'triangle-strip'; // draw a connected group of triangles.\n\n case GL.TRIANGLE_FAN: return 'triangle-fan'; // draw a connected group of triangles.\n case GL.LINE_LOOP: return 'line-loop'; // draw lines. Each set of two vertices is treated as a separate line segment.\n default:\n throw new Error(String(drawMode));\n }\n}\n"],"mappings":";AAEA,SAAQA,GAAG,EAAEC,MAAM,QAAO,cAAc;AACxC,OAAOC,EAAE,MAAM,oBAAoB;AAyCnC,eAAe,MAAMC,QAAQ,CAAC;EA8B5BC,WAAWA,CAAA,EAA4B;IAAA,IAA3BC,KAAoB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAAAG,eAAA;IAAAA,eAAA,mBAjBD,CAAC,CAAC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,2 @@
1
+
2
+ //# sourceMappingURL=primitive-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitive-utils.js","names":[],"sources":["../../../src/geometry/primitive-utils.ts"],"sourcesContent":["/*\nimport type {GeometryTable} from './geometry-table';\n\nexport function unpackIndexedGeometry(geometry: GeometryTable): GeometryTable {\n const {indices, attributes} = geometry;\n if (!indices) {\n return geometry;\n }\n\n const vertexCount = indices.length;\n const unpackedAttributes = {};\n\n for (const [name, values] of Object.entries(attributes)) {\n const size = {POSITION: 3, NORMAL: 3, TEX_COORD0: 2}[name];\n const unpackedValues = new values.constructor(length * size);\n for (let x = 0; x < vertexCount; ++x) {\n const index = indices[x];\n for (let i = 0; i < size; i++) {\n unpackedValues[x * size + i] = values[index * size + i];\n }\n }\n unpackedAttributes[name] = unpackedValues;\n }\n\n return {\n length,\n attributes: unpackedAttributes\n };\n}\n*/"],"mappings":""}
@@ -0,0 +1,16 @@
1
+ export { Timeline } from './animation/timeline';
2
+ export { KeyFrames } from './animation/key-frames';
3
+ export { AnimationLoopTemplate } from './animation-loop/render-loop';
4
+ export { AnimationLoop } from './animation-loop/animation-loop';
5
+ export { makeAnimationLoop } from './animation-loop/make-animation-loop';
6
+ export { Model } from './lib/model';
7
+ export { PipelineFactory } from './lib/pipeline-factory';
8
+ export { default as Geometry } from './geometry/geometry';
9
+ export { ConeGeometry } from './geometries/cone-geometry';
10
+ export { CubeGeometry } from './geometries/cube-geometry';
11
+ export { CylinderGeometry } from './geometries/cylinder-geometry';
12
+ export { IcoSphereGeometry } from './geometries/ico-sphere-geometry';
13
+ export { PlaneGeometry } from './geometries/plane-geometry';
14
+ export { SphereGeometry } from './geometries/sphere-geometry';
15
+ export { TruncatedConeGeometry } from './geometries/truncated-cone-geometry';
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["Timeline","KeyFrames","AnimationLoopTemplate","AnimationLoop","makeAnimationLoop","Model","PipelineFactory","default","Geometry","ConeGeometry","CubeGeometry","CylinderGeometry","IcoSphereGeometry","PlaneGeometry","SphereGeometry","TruncatedConeGeometry"],"sources":["../../src/index.ts"],"sourcesContent":["// luma.gl Engine API\n\n// Animation\nexport {Timeline} from './animation/timeline';\nexport {KeyFrames} from './animation/key-frames';\nexport type {AnimationProps} from './animation-loop/animation-props';\n\nexport {AnimationLoopTemplate} from './animation-loop/render-loop';\n\nexport type {AnimationLoopProps} from './animation-loop/animation-loop';\nexport {AnimationLoop} from './animation-loop/animation-loop';\n\nexport type {MakeAnimationLoopProps} from './animation-loop/make-animation-loop';\nexport {makeAnimationLoop} from './animation-loop/make-animation-loop';\n\nexport type {ModelProps} from './lib/model';\nexport {Model} from './lib/model';\n\nexport {PipelineFactory} from './lib/pipeline-factory';\n\n// Utils\n// export {default as ClipSpace} from './lib/clip-space';\n\n// Geometries\nexport {default as Geometry} from './geometry/geometry';\n\n// Primitives\nexport type {ConeGeometryProps} from './geometries/cone-geometry';\nexport {ConeGeometry} from './geometries/cone-geometry';\nexport type {CubeGeometryProps} from './geometries/cube-geometry';\nexport {CubeGeometry} from './geometries/cube-geometry';\nexport type {CylinderGeometryProps} from './geometries/cylinder-geometry';\nexport {CylinderGeometry} from './geometries/cylinder-geometry';\nexport type {IcoSphereGeometryProps} from './geometries/ico-sphere-geometry';\nexport {IcoSphereGeometry} from './geometries/ico-sphere-geometry';\nexport type {PlaneGeometryProps} from './geometries/plane-geometry';\nexport {PlaneGeometry} from './geometries/plane-geometry';\nexport type {SphereGeometryProps} from './geometries/sphere-geometry';\nexport {SphereGeometry} from './geometries/sphere-geometry';\nexport type {TruncatedConeGeometryProps} from './geometries/truncated-cone-geometry';\nexport {TruncatedConeGeometry} from './geometries/truncated-cone-geometry';\n\n"],"mappings":"AAGA,SAAQA,QAAQ,QAAO,sBAAsB;AAC7C,SAAQC,SAAS,QAAO,wBAAwB;AAGhD,SAAQC,qBAAqB,QAAO,8BAA8B;AAGlE,SAAQC,aAAa,QAAO,iCAAiC;AAG7D,SAAQC,iBAAiB,QAAO,sCAAsC;AAGtE,SAAQC,KAAK,QAAO,aAAa;AAEjC,SAAQC,eAAe,QAAO,wBAAwB;AAMtD,SAAQC,OAAO,IAAIC,QAAQ,QAAO,qBAAqB;AAIvD,SAAQC,YAAY,QAAO,4BAA4B;AAEvD,SAAQC,YAAY,QAAO,4BAA4B;AAEvD,SAAQC,gBAAgB,QAAO,gCAAgC;AAE/D,SAAQC,iBAAiB,QAAO,kCAAkC;AAElE,SAAQC,aAAa,QAAO,6BAA6B;AAEzD,SAAQC,cAAc,QAAO,8BAA8B;AAE3D,SAAQC,qBAAqB,QAAO,sCAAsC"}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=clip-space.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clip-space.js","names":[],"sources":["../../../src/lib/clip-space.ts"],"sourcesContent":["\n// ClipSpace\n/*\nimport GL from '@luma.gl/constants';\nimport Model, {ModelProps} from './model';\nimport Geometry from '../geometry/geometry';\n\nconst CLIPSPACE_VERTEX_SHADER = glsl`\\\nattribute vec2 aClipSpacePosition;\nattribute vec2 aTexCoord;\nattribute vec2 aCoordinate;\n\nvarying vec2 position;\nvarying vec2 coordinate;\nvarying vec2 uv;\n\nvoid main(void) {\n gl_Position = vec4(aClipSpacePosition, 0., 1.);\n position = aClipSpacePosition;\n coordinate = aCoordinate;\n uv = aTexCoord;\n}\n`;\n\n/* eslint-disable indent, no-multi-spaces *\nconst POSITIONS = [-1, -1, 1, -1, -1, 1, 1, 1];\n\n\nexport default class ClipSpace extends Model {\n constructor(gl: WebGLRenderingContext, opts?: ModelProps) {\n const TEX_COORDS = POSITIONS.map((coord) => (coord === -1 ? 0 : coord));\n\n super(\n gl,\n Object.assign({}, opts, {\n vs: CLIPSPACE_VERTEX_SHADER,\n geometry: new Geometry({\n drawMode: GL.TRIANGLE_STRIP,\n vertexCount: 4,\n attributes: {\n aClipSpacePosition: {size: 2, value: new Float32Array(POSITIONS)},\n aTexCoord: {size: 2, value: new Float32Array(TEX_COORDS)},\n aCoordinate: {size: 2, value: new Float32Array(TEX_COORDS)}\n }\n })\n })\n );\n this.setVertexCount(4);\n }\n}\n*/"],"mappings":""}
@@ -0,0 +1,40 @@
1
+ import { Buffer, assert } from '@luma.gl/api';
2
+ const GLTF_TO_LUMA_ATTRIBUTE_MAP = {
3
+ POSITION: 'positions',
4
+ NORMAL: 'normals',
5
+ COLOR_0: 'colors',
6
+ TEXCOORD_0: 'texCoords',
7
+ TEXCOORD_1: 'texCoords1',
8
+ TEXCOORD_2: 'texCoords2'
9
+ };
10
+ export function getIndexBufferFromGeometry(device, geometry) {
11
+ if (!geometry.indices) {
12
+ return undefined;
13
+ }
14
+ const data = geometry.indices.value || geometry.indices;
15
+ assert(data instanceof Uint16Array || data instanceof Uint32Array, 'attribute array for "indices" must be of integer type');
16
+ return device.createBuffer({
17
+ usage: Buffer.INDEX,
18
+ data
19
+ });
20
+ }
21
+ export function getAttributeBuffersFromGeometry(device, geometry) {
22
+ const buffers = {};
23
+ for (const [name, attribute] of Object.entries(geometry.attributes)) {
24
+ const remappedName = mapAttributeName(name);
25
+ if (attribute !== null && attribute !== void 0 && attribute.constant) {
26
+ throw new Error('constant attributes not supported');
27
+ } else {
28
+ const typedArray = attribute === null || attribute === void 0 ? void 0 : attribute.value;
29
+ buffers[remappedName] = device.createBuffer({
30
+ data: typedArray,
31
+ id: "".concat(remappedName, "-buffer")
32
+ });
33
+ }
34
+ }
35
+ return buffers;
36
+ }
37
+ function mapAttributeName(name) {
38
+ return GLTF_TO_LUMA_ATTRIBUTE_MAP[name] || name;
39
+ }
40
+ //# sourceMappingURL=model-utils.js.map
@@ -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/lib/model-utils.ts"],"sourcesContent":["import {Device, Buffer, assert} from '@luma.gl/api';\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,cAAc;AAInD,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,uDAAuD,CACxD;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,146 @@
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 = {
6
+ ...RenderPipeline._DEFAULT_PROPS,
7
+ vs: null,
8
+ fs: null,
9
+ id: 'unnamed',
10
+ handle: undefined,
11
+ userData: {},
12
+ modules: [],
13
+ moduleSettings: {},
14
+ geometry: null
15
+ };
16
+ export class Model {
17
+ constructor(device, props) {
18
+ _defineProperty(this, "device", void 0);
19
+ _defineProperty(this, "pipeline", void 0);
20
+ _defineProperty(this, "id", void 0);
21
+ _defineProperty(this, "vs", void 0);
22
+ _defineProperty(this, "fs", null);
23
+ _defineProperty(this, "topology", void 0);
24
+ _defineProperty(this, "vertexCount", void 0);
25
+ _defineProperty(this, "props", void 0);
26
+ _defineProperty(this, "_getModuleUniforms", void 0);
27
+ this.props = {
28
+ ...DEFAULT_MODEL_PROPS,
29
+ ...props
30
+ };
31
+ props = this.props;
32
+ this.id = this.props.id;
33
+ this.device = device;
34
+ if (!props.vs) {
35
+ throw new Error('no vertex shader');
36
+ }
37
+ this.vs = getShaderSource(this.device, props.vs);
38
+ if (props.fs) {
39
+ this.fs = getShaderSource(this.device, props.fs);
40
+ }
41
+ this.vertexCount = this.props.vertexCount;
42
+ this.topology = this.props.topology;
43
+ if (this.props.geometry) {
44
+ this.vertexCount = this.props.geometry.vertexCount;
45
+ this.topology = this.props.geometry.topology || 'triangle-list';
46
+ }
47
+ const pipelineFactory = PipelineFactory.getDefaultPipelineFactory(this.device);
48
+ const {
49
+ pipeline,
50
+ getUniforms
51
+ } = pipelineFactory.createRenderPipeline({
52
+ ...this.props,
53
+ vs: this.vs,
54
+ fs: this.fs,
55
+ topology: this.topology,
56
+ parameters: props.parameters,
57
+ layout: props.layout
58
+ });
59
+ this.pipeline = pipeline;
60
+ this._getModuleUniforms = getUniforms;
61
+ if (this.props.geometry) {
62
+ this._setGeometry(this.props.geometry);
63
+ }
64
+ this.setUniforms(this._getModuleUniforms());
65
+ this.setProps(this.props);
66
+ }
67
+ destroy() {
68
+ this.pipeline.destroy();
69
+ }
70
+ draw(renderPass) {
71
+ this.pipeline.draw({
72
+ renderPass,
73
+ vertexCount: this.vertexCount,
74
+ instanceCount: this.props.instanceCount
75
+ });
76
+ return this;
77
+ }
78
+ setProps(props) {
79
+ if (props.indices) {
80
+ this.setIndexBuffer(props.indices);
81
+ }
82
+ if (props.attributes) {
83
+ this.setAttributes(props.attributes);
84
+ }
85
+ if (props.bindings) {
86
+ this.setBindings(props.bindings);
87
+ }
88
+ if (props.uniforms) {
89
+ this.setUniforms(props.uniforms);
90
+ }
91
+ if (props.moduleSettings) {
92
+ this.updateModuleSettings(props.moduleSettings);
93
+ }
94
+ return this;
95
+ }
96
+ updateModuleSettings(props) {
97
+ const uniforms = this._getModuleUniforms(props);
98
+ this.setUniforms(uniforms);
99
+ return this;
100
+ }
101
+ setIndexBuffer(indices) {
102
+ this.pipeline.setIndexBuffer(indices);
103
+ return this;
104
+ }
105
+ setAttributes(attributes) {
106
+ this.pipeline.setAttributes(attributes);
107
+ Object.assign(this.props.attributes, attributes);
108
+ return this;
109
+ }
110
+ setBindings(bindings) {
111
+ this.pipeline.setBindings(bindings);
112
+ Object.assign(this.props.bindings, bindings);
113
+ return this;
114
+ }
115
+ setUniforms(uniforms) {
116
+ this.pipeline.setUniforms(uniforms);
117
+ Object.assign(this.props.uniforms, uniforms);
118
+ return this;
119
+ }
120
+ _setGeometry(geometry) {
121
+ const geometryBuffers = getAttributeBuffersFromGeometry(this.device, geometry);
122
+ this.setAttributes(geometryBuffers);
123
+ const indexBuffer = getIndexBufferFromGeometry(this.device, geometry);
124
+ if (indexBuffer) {
125
+ this.setIndexBuffer(indexBuffer);
126
+ }
127
+ }
128
+ }
129
+ function getShaderSource(device, shader) {
130
+ if (typeof shader === 'string') {
131
+ return shader;
132
+ }
133
+ switch (device.info.type) {
134
+ case 'webgpu':
135
+ if (shader !== null && shader !== void 0 && shader.wgsl) {
136
+ return shader.wgsl;
137
+ }
138
+ throw new Error('WebGPU does not support GLSL shaders');
139
+ default:
140
+ if (shader !== null && shader !== void 0 && shader.glsl) {
141
+ return shader.glsl;
142
+ }
143
+ throw new Error('WebGL does not support WGSL shaders');
144
+ }
145
+ }
146
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","names":["RenderPipeline","getAttributeBuffersFromGeometry","getIndexBufferFromGeometry","PipelineFactory","DEFAULT_MODEL_PROPS","_DEFAULT_PROPS","vs","fs","id","handle","undefined","userData","modules","moduleSettings","geometry","Model","constructor","device","props","_defineProperty","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"],"sources":["../../../src/lib/model.ts"],"sourcesContent":["// luma.gl, MIT license\n\nimport type {Device, Buffer, RenderPipelineProps, RenderPass, Binding, PrimitiveTopology} from '@luma.gl/api';\nimport {RenderPipeline} 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 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"],"mappings":";AAGA,SAAQA,cAAc,QAAO,cAAc;AAG3C,SAAQC,+BAA+B,EAAEC,0BAA0B,QAAO,eAAe;AACzF,SAAQC,eAAe,QAAO,oBAAoB;AAWlD,MAAMC,mBAAyC,GAAG;EAChD,GAAGJ,cAAc,CAACK,cAAc;EAChCC,EAAE,EAAE,IAAI;EACRC,EAAE,EAAE,IAAI;EACRC,EAAE,EAAE,SAAS;EACbC,MAAM,EAAEC,SAAS;EACjBC,QAAQ,EAAE,CAAC,CAAC;EACZC,OAAO,EAAE,EAAE;EACXC,cAAc,EAAE,CAAC,CAAC;EAClBC,QAAQ,EAAE;AACZ,CAAC;AAGD,OAAO,MAAMC,KAAK,CAAC;EAYjBC,WAAWA,CAACC,MAAc,EAAEC,KAAiB,EAAE;IAAAC,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA;IAAAA,eAAA,aAPlB,IAAI;IAAAA,eAAA;IAAAA,e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AI,CAACV,cAAc,CAACU,WAAW,CAAC;IAClC;EACF;AACF;AAGA,SAAS7B,eAAeA,CAACJ,MAAc,EAAEkC,MAA+C,EAAU;EAEhG,IAAI,OAAOA,MAAM,KAAK,QAAQ,EAAE;IAC9B,OAAOA,MAAM;EACf;EAEA,QAAQlC,MAAM,CAACmC,IAAI,CAACC,IAAI;IACtB,KAAK,QAAQ;MACX,IAAIF,MAAM,aAANA,MAAM,eAANA,MAAM,CAAEG,IAAI,EAAE;QAChB,OAAOH,MAAM,CAACG,IAAI;MACpB;MACA,MAAM,IAAIlC,KAAK,CAAC,sCAAsC,CAAC;IAEzD;MACE,IAAI+B,MAAM,aAANA,MAAM,eAANA,MAAM,CAAEI,IAAI,EAAE;QAChB,OAAOJ,MAAM,CAACI,IAAI;MACpB;MACA,MAAM,IAAInC,KAAK,CAAC,qCAAqC,CAAC;EAAC;AAE7D"}
@@ -0,0 +1,180 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import { assembleShaders } from '@luma.gl/shadertools';
3
+ const DEFAULT_RENDER_PIPELINE_OPTIONS = {
4
+ vs: '',
5
+ fs: '',
6
+ modules: [],
7
+ defines: {},
8
+ inject: {},
9
+ transpileToGLSL100: false,
10
+ layout: null,
11
+ varyings: [],
12
+ bufferMode: 0x8c8d,
13
+ topology: 'triangle-list',
14
+ parameters: {}
15
+ };
16
+ export class PipelineFactory {
17
+ static getDefaultPipelineFactory(device) {
18
+ device.defaultPipelineFactory = device.defaultPipelineFactory || new PipelineFactory(device);
19
+ return device.defaultPipelineFactory;
20
+ }
21
+ constructor(device) {
22
+ _defineProperty(this, "device", void 0);
23
+ _defineProperty(this, "stateHash", 0);
24
+ _defineProperty(this, "_hashCounter", 0);
25
+ _defineProperty(this, "_hashes", {});
26
+ _defineProperty(this, "_useCounts", {});
27
+ _defineProperty(this, "_pipelineCache", {});
28
+ _defineProperty(this, "_getUniforms", {});
29
+ _defineProperty(this, "_hookFunctions", []);
30
+ _defineProperty(this, "_defaultModules", []);
31
+ this.device = device;
32
+ }
33
+ addDefaultModule(module) {
34
+ if (!this._defaultModules.find(m => m.name === (typeof module === 'string' ? module : module.name))) {
35
+ this._defaultModules.push(module);
36
+ }
37
+ this.stateHash++;
38
+ }
39
+ removeDefaultModule(module) {
40
+ const moduleName = typeof module === 'string' ? module : module.name;
41
+ this._defaultModules = this._defaultModules.filter(m => m.name !== moduleName);
42
+ this.stateHash++;
43
+ }
44
+ addShaderHook(hook, opts) {
45
+ if (opts) {
46
+ hook = Object.assign(opts, {
47
+ hook
48
+ });
49
+ }
50
+ this._hookFunctions.push(hook);
51
+ this.stateHash++;
52
+ }
53
+ createRenderPipeline(options) {
54
+ const props = {
55
+ ...DEFAULT_RENDER_PIPELINE_OPTIONS,
56
+ ...options
57
+ };
58
+ const modules = this._getModuleList(props.modules);
59
+ const hash = this._hashRenderPipeline({
60
+ ...props,
61
+ modules
62
+ });
63
+ if (!this._pipelineCache[hash]) {
64
+ const {
65
+ pipeline,
66
+ getUniforms
67
+ } = this._createRenderPipeline({
68
+ ...props,
69
+ modules
70
+ });
71
+ pipeline.hash = hash;
72
+ this._pipelineCache[hash] = pipeline;
73
+ this._getUniforms[hash] = getUniforms || (x => ({}));
74
+ this._useCounts[hash] = 0;
75
+ }
76
+ this._useCounts[hash]++;
77
+ return {
78
+ pipeline: this._pipelineCache[hash],
79
+ getUniforms: this._getUniforms[hash]
80
+ };
81
+ }
82
+ release(pipeline) {
83
+ const hash = pipeline.hash;
84
+ this._useCounts[hash]--;
85
+ if (this._useCounts[hash] === 0) {
86
+ this._pipelineCache[hash].destroy();
87
+ delete this._pipelineCache[hash];
88
+ delete this._getUniforms[hash];
89
+ delete this._useCounts[hash];
90
+ }
91
+ }
92
+ getUniforms(pipeline) {
93
+ return this._getUniforms[pipeline.hash] || null;
94
+ }
95
+ _createRenderPipeline(props) {
96
+ const platformInfo = {
97
+ gpu: this.device.info.gpu,
98
+ features: this.device.features
99
+ };
100
+ if (!props.fs) {
101
+ throw new Error('fs');
102
+ }
103
+ const assembled = assembleShaders(platformInfo, {
104
+ ...props,
105
+ fs: props.fs,
106
+ hookFunctions: this._hookFunctions
107
+ });
108
+ const pipeline = this.device.createRenderPipeline({
109
+ ...props,
110
+ vs: this.device.createShader({
111
+ stage: 'vertex',
112
+ source: assembled.vs
113
+ }),
114
+ fs: assembled.fs ? this.device.createShader({
115
+ stage: 'fragment',
116
+ source: assembled.fs
117
+ }) : null
118
+ });
119
+ return {
120
+ pipeline,
121
+ getUniforms: assembled.getUniforms
122
+ };
123
+ }
124
+ _hashRenderPipeline(props) {
125
+ const {
126
+ modules = [],
127
+ varyings = [],
128
+ defines = {},
129
+ inject = {},
130
+ parameters = {}
131
+ } = props;
132
+ const vsHash = this._getHash(props.vs);
133
+ const fsHash = props.fs ? this._getHash(props.fs) : 0;
134
+ const moduleHashes = modules.map(m => this._getHash(typeof m === 'string' ? m : m.name)).sort();
135
+ const varyingHashes = varyings.map(v => this._getHash(v));
136
+ const defineKeys = Object.keys(defines).sort();
137
+ const injectKeys = Object.keys(inject).sort();
138
+ const defineHashes = [];
139
+ const injectHashes = [];
140
+ for (const key of defineKeys) {
141
+ defineHashes.push(this._getHash(key));
142
+ defineHashes.push(this._getHash(String(defines[key])));
143
+ }
144
+ for (const key of injectKeys) {
145
+ injectHashes.push(this._getHash(key));
146
+ injectHashes.push(this._getHash(inject[key]));
147
+ }
148
+ const parameterHash = JSON.stringify(parameters);
149
+ return "".concat(vsHash, "/").concat(fsHash, "D").concat(defineHashes.join('/'), "M").concat(moduleHashes.join('/'), "I").concat(injectHashes.join('/'), "V").concat(varyingHashes.join('/'), "H").concat(this.stateHash, "B").concat(props.bufferMode).concat(props.transpileToGLSL100 ? 'T' : '', "P").concat(parameterHash);
150
+ }
151
+ _getHash(key) {
152
+ if (this._hashes[key] === undefined) {
153
+ this._hashes[key] = this._hashCounter++;
154
+ }
155
+ return this._hashes[key];
156
+ }
157
+ _getModuleList() {
158
+ let appModules = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
159
+ const modules = new Array(this._defaultModules.length + appModules.length);
160
+ const seen = {};
161
+ let count = 0;
162
+ for (let i = 0, len = this._defaultModules.length; i < len; ++i) {
163
+ const module = this._defaultModules[i];
164
+ const name = module.name;
165
+ modules[count++] = module;
166
+ seen[name] = true;
167
+ }
168
+ for (let i = 0, len = appModules.length; i < len; ++i) {
169
+ const module = appModules[i];
170
+ const name = module.name;
171
+ if (!seen[name]) {
172
+ modules[count++] = module;
173
+ seen[name] = true;
174
+ }
175
+ }
176
+ modules.length = count;
177
+ return modules;
178
+ }
179
+ }
180
+ //# sourceMappingURL=pipeline-factory.js.map