@luma.gl/engine 9.0.0-beta.1 → 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.
Files changed (154) hide show
  1. package/dist/animation/key-frames.js +54 -54
  2. package/dist/animation/timeline.d.ts.map +1 -1
  3. package/dist/animation/timeline.js +95 -100
  4. package/dist/animation-loop/animation-loop-template.d.ts +1 -1
  5. package/dist/animation-loop/animation-loop-template.d.ts.map +1 -1
  6. package/dist/animation-loop/animation-loop-template.js +19 -5
  7. package/dist/animation-loop/animation-loop.d.ts +2 -2
  8. package/dist/animation-loop/animation-loop.d.ts.map +1 -1
  9. package/dist/animation-loop/animation-loop.js +433 -356
  10. package/dist/animation-loop/animation-props.d.ts +2 -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 +2 -2
  14. package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
  15. package/dist/animation-loop/make-animation-loop.js +28 -24
  16. package/dist/computation.d.ts +95 -0
  17. package/dist/computation.d.ts.map +1 -0
  18. package/dist/computation.js +248 -0
  19. package/dist/debug/copy-texture-to-image.d.ts.map +1 -1
  20. package/dist/debug/copy-texture-to-image.js +39 -42
  21. package/dist/debug/debug-framebuffer.d.ts.map +1 -1
  22. package/dist/debug/debug-framebuffer.js +43 -40
  23. package/dist/debug/debug-shader-layout.js +24 -25
  24. package/dist/debug/pixel-data-utils.d.ts.map +1 -1
  25. package/dist/debug/pixel-data-utils.js +34 -36
  26. package/dist/dist.dev.js +2538 -3027
  27. package/dist/dist.min.js +102 -0
  28. package/dist/geometries/cone-geometry.d.ts +1 -1
  29. package/dist/geometries/cone-geometry.d.ts.map +1 -1
  30. package/dist/geometries/cone-geometry.js +11 -17
  31. package/dist/geometries/cube-geometry.d.ts +1 -1
  32. package/dist/geometries/cube-geometry.d.ts.map +1 -1
  33. package/dist/geometries/cube-geometry.js +190 -61
  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 +9 -14
  37. package/dist/geometries/ico-sphere-geometry.d.ts +1 -1
  38. package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
  39. package/dist/geometries/ico-sphere-geometry.js +141 -160
  40. package/dist/geometries/plane-geometry.d.ts +1 -1
  41. package/dist/geometries/plane-geometry.d.ts.map +1 -1
  42. package/dist/geometries/plane-geometry.js +92 -110
  43. package/dist/geometries/sphere-geometry.d.ts +1 -1
  44. package/dist/geometries/sphere-geometry.d.ts.map +1 -1
  45. package/dist/geometries/sphere-geometry.js +76 -95
  46. package/dist/geometries/truncated-cone-geometry.d.ts +1 -1
  47. package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
  48. package/dist/geometries/truncated-cone-geometry.js +99 -117
  49. package/dist/geometry/geometry-table.d.ts.map +1 -1
  50. package/dist/geometry/geometry-table.js +3 -1
  51. package/dist/geometry/geometry-utils.js +35 -32
  52. package/dist/geometry/geometry.d.ts.map +1 -1
  53. package/dist/geometry/geometry.js +80 -71
  54. package/dist/geometry/gpu-geometry.d.ts +1 -1
  55. package/dist/geometry/gpu-geometry.d.ts.map +1 -1
  56. package/dist/geometry/gpu-geometry.js +79 -99
  57. package/dist/geometry/gpu-table.js +41 -1
  58. package/dist/index.cjs +725 -409
  59. package/dist/index.cjs.map +7 -0
  60. package/dist/index.d.ts +43 -40
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +6 -1
  63. package/dist/lib/clip-space.d.ts +2 -2
  64. package/dist/lib/clip-space.d.ts.map +1 -1
  65. package/dist/lib/clip-space.js +28 -34
  66. package/dist/lib/pipeline-factory.d.ts +13 -14
  67. package/dist/lib/pipeline-factory.d.ts.map +1 -1
  68. package/dist/lib/pipeline-factory.js +86 -85
  69. package/dist/lib/shader-factory.d.ts +17 -0
  70. package/dist/lib/shader-factory.d.ts.map +1 -0
  71. package/dist/lib/shader-factory.js +46 -0
  72. package/dist/model/model.d.ts +59 -46
  73. package/dist/model/model.d.ts.map +1 -1
  74. package/dist/model/model.js +635 -411
  75. package/dist/scenegraph/group-node.d.ts +1 -1
  76. package/dist/scenegraph/group-node.d.ts.map +1 -1
  77. package/dist/scenegraph/group-node.js +73 -83
  78. package/dist/scenegraph/model-node.d.ts +3 -3
  79. package/dist/scenegraph/model-node.d.ts.map +1 -1
  80. package/dist/scenegraph/model-node.js +31 -24
  81. package/dist/scenegraph/scenegraph-node.d.ts.map +1 -1
  82. package/dist/scenegraph/scenegraph-node.js +136 -124
  83. package/dist/shader-inputs.d.ts.map +1 -1
  84. package/dist/shader-inputs.js +99 -58
  85. package/dist/transform/buffer-transform.d.ts +1 -1
  86. package/dist/transform/buffer-transform.d.ts.map +1 -1
  87. package/dist/transform/buffer-transform.js +65 -57
  88. package/dist/transform/texture-transform.d.ts +1 -1
  89. package/dist/transform/texture-transform.d.ts.map +1 -1
  90. package/dist/transform/texture-transform.js +109 -114
  91. package/dist.min.js +3 -271
  92. package/package.json +10 -9
  93. package/src/animation/timeline.ts +20 -20
  94. package/src/animation-loop/animation-loop-template.ts +10 -8
  95. package/src/animation-loop/animation-loop.ts +20 -10
  96. package/src/animation-loop/animation-props.ts +1 -1
  97. package/src/animation-loop/make-animation-loop.ts +17 -8
  98. package/src/computation.ts +346 -0
  99. package/src/debug/copy-texture-to-image.ts +9 -11
  100. package/src/debug/debug-framebuffer.ts +16 -3
  101. package/src/debug/debug-shader-layout.ts +1 -1
  102. package/src/debug/pixel-data-utils.ts +3 -6
  103. package/src/geometries/cube-geometry.ts +17 -13
  104. package/src/geometries/ico-sphere-geometry.ts +1 -1
  105. package/src/geometries/plane-geometry.ts +1 -1
  106. package/src/geometries/sphere-geometry.ts +1 -1
  107. package/src/geometries/truncated-cone-geometry.ts +2 -1
  108. package/src/geometry/geometry-table.ts +9 -6
  109. package/src/geometry/geometry-utils.ts +16 -0
  110. package/src/geometry/geometry.ts +9 -6
  111. package/src/geometry/gpu-geometry.ts +18 -11
  112. package/src/index.ts +4 -1
  113. package/src/lib/clip-space.ts +16 -19
  114. package/src/lib/pipeline-factory.ts +71 -64
  115. package/src/lib/shader-factory.ts +57 -0
  116. package/src/model/model.ts +255 -146
  117. package/src/scenegraph/group-node.ts +14 -10
  118. package/src/scenegraph/model-node.ts +2 -2
  119. package/src/scenegraph/scenegraph-node.ts +2 -2
  120. package/src/shader-inputs.ts +19 -12
  121. package/src/transform/buffer-transform.ts +16 -8
  122. package/src/transform/texture-transform.ts +14 -15
  123. package/dist/animation/key-frames.js.map +0 -1
  124. package/dist/animation/timeline.js.map +0 -1
  125. package/dist/animation-loop/animation-loop-template.js.map +0 -1
  126. package/dist/animation-loop/animation-loop.js.map +0 -1
  127. package/dist/animation-loop/animation-props.js.map +0 -1
  128. package/dist/animation-loop/make-animation-loop.js.map +0 -1
  129. package/dist/debug/copy-texture-to-image.js.map +0 -1
  130. package/dist/debug/debug-framebuffer.js.map +0 -1
  131. package/dist/debug/debug-shader-layout.js.map +0 -1
  132. package/dist/debug/pixel-data-utils.js.map +0 -1
  133. package/dist/geometries/cone-geometry.js.map +0 -1
  134. package/dist/geometries/cube-geometry.js.map +0 -1
  135. package/dist/geometries/cylinder-geometry.js.map +0 -1
  136. package/dist/geometries/ico-sphere-geometry.js.map +0 -1
  137. package/dist/geometries/plane-geometry.js.map +0 -1
  138. package/dist/geometries/sphere-geometry.js.map +0 -1
  139. package/dist/geometries/truncated-cone-geometry.js.map +0 -1
  140. package/dist/geometry/geometry-table.js.map +0 -1
  141. package/dist/geometry/geometry-utils.js.map +0 -1
  142. package/dist/geometry/geometry.js.map +0 -1
  143. package/dist/geometry/gpu-geometry.js.map +0 -1
  144. package/dist/geometry/gpu-table.js.map +0 -1
  145. package/dist/index.js.map +0 -1
  146. package/dist/lib/clip-space.js.map +0 -1
  147. package/dist/lib/pipeline-factory.js.map +0 -1
  148. package/dist/model/model.js.map +0 -1
  149. package/dist/scenegraph/group-node.js.map +0 -1
  150. package/dist/scenegraph/model-node.js.map +0 -1
  151. package/dist/scenegraph/scenegraph-node.js.map +0 -1
  152. package/dist/shader-inputs.js.map +0 -1
  153. package/dist/transform/buffer-transform.js.map +0 -1
  154. package/dist/transform/texture-transform.js.map +0 -1
@@ -1,120 +1,102 @@
1
1
  import { uid } from '@luma.gl/core';
2
2
  import { Geometry } from "../geometry/geometry.js";
3
3
  import { unpackIndexedGeometry } from "../geometry/geometry-utils.js";
4
+ // Primitives inspired by TDL http://code.google.com/p/webglsamples/,
5
+ // copyright 2011 Google Inc. new BSD License
6
+ // (http://www.opensource.org/licenses/bsd-license.php).
4
7
  export class PlaneGeometry extends Geometry {
5
- constructor() {
6
- let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7
- const {
8
- id = uid('plane-geometry')
9
- } = props;
10
- const {
11
- indices,
12
- attributes
13
- } = tesselatePlane(props);
14
- super({
15
- ...props,
16
- id,
17
- topology: 'triangle-list',
18
- indices,
19
- attributes: {
20
- ...attributes,
21
- ...props.attributes
22
- }
23
- });
24
- }
8
+ constructor(props = {}) {
9
+ const { id = uid('plane-geometry') } = props;
10
+ const { indices, attributes } = tesselatePlane(props);
11
+ super({
12
+ ...props,
13
+ id,
14
+ topology: 'triangle-list',
15
+ indices,
16
+ attributes: { ...attributes, ...props.attributes }
17
+ });
18
+ }
25
19
  }
20
+ /* eslint-disable complexity, max-statements */
26
21
  function tesselatePlane(props) {
27
- const {
28
- type = 'x,y',
29
- offset = 0,
30
- flipCull = false,
31
- unpack = false
32
- } = props;
33
- const coords = type.split(',');
34
- let c1len = props[`${coords[0]}len`] || 1;
35
- const c2len = props[`${coords[1]}len`] || 1;
36
- const subdivisions1 = props[`n${coords[0]}`] || 1;
37
- const subdivisions2 = props[`n${coords[1]}`] || 1;
38
- const numVertices = (subdivisions1 + 1) * (subdivisions2 + 1);
39
- const positions = new Float32Array(numVertices * 3);
40
- const normals = new Float32Array(numVertices * 3);
41
- const texCoords = new Float32Array(numVertices * 2);
42
- if (flipCull) {
43
- c1len = -c1len;
44
- }
45
- let i2 = 0;
46
- let i3 = 0;
47
- for (let z = 0; z <= subdivisions2; z++) {
48
- for (let x = 0; x <= subdivisions1; x++) {
49
- const u = x / subdivisions1;
50
- const v = z / subdivisions2;
51
- texCoords[i2 + 0] = flipCull ? 1 - u : u;
52
- texCoords[i2 + 1] = v;
53
- switch (type) {
54
- case 'x,y':
55
- positions[i3 + 0] = c1len * u - c1len * 0.5;
56
- positions[i3 + 1] = c2len * v - c2len * 0.5;
57
- positions[i3 + 2] = offset;
58
- normals[i3 + 0] = 0;
59
- normals[i3 + 1] = 0;
60
- normals[i3 + 2] = flipCull ? 1 : -1;
61
- break;
62
- case 'x,z':
63
- positions[i3 + 0] = c1len * u - c1len * 0.5;
64
- positions[i3 + 1] = offset;
65
- positions[i3 + 2] = c2len * v - c2len * 0.5;
66
- normals[i3 + 0] = 0;
67
- normals[i3 + 1] = flipCull ? 1 : -1;
68
- normals[i3 + 2] = 0;
69
- break;
70
- case 'y,z':
71
- positions[i3 + 0] = offset;
72
- positions[i3 + 1] = c1len * u - c1len * 0.5;
73
- positions[i3 + 2] = c2len * v - c2len * 0.5;
74
- normals[i3 + 0] = flipCull ? 1 : -1;
75
- normals[i3 + 1] = 0;
76
- normals[i3 + 2] = 0;
77
- break;
78
- default:
79
- throw new Error('PlaneGeometry: unknown type');
80
- }
81
- i2 += 2;
82
- i3 += 3;
22
+ const { type = 'x,y', offset = 0, flipCull = false, unpack = false } = props;
23
+ const coords = type.split(',');
24
+ // width, height
25
+ let c1len = props[`${coords[0]}len`] || 1;
26
+ const c2len = props[`${coords[1]}len`] || 1;
27
+ // subdivisionsWidth, subdivisionsDepth
28
+ const subdivisions1 = props[`n${coords[0]}`] || 1;
29
+ const subdivisions2 = props[`n${coords[1]}`] || 1;
30
+ const numVertices = (subdivisions1 + 1) * (subdivisions2 + 1);
31
+ const positions = new Float32Array(numVertices * 3);
32
+ const normals = new Float32Array(numVertices * 3);
33
+ const texCoords = new Float32Array(numVertices * 2);
34
+ if (flipCull) {
35
+ c1len = -c1len;
83
36
  }
84
- }
85
- const numVertsAcross = subdivisions1 + 1;
86
- const indices = new Uint16Array(subdivisions1 * subdivisions2 * 6);
87
- for (let z = 0; z < subdivisions2; z++) {
88
- for (let x = 0; x < subdivisions1; x++) {
89
- const index = (z * subdivisions1 + x) * 6;
90
- indices[index + 0] = (z + 0) * numVertsAcross + x;
91
- indices[index + 1] = (z + 1) * numVertsAcross + x;
92
- indices[index + 2] = (z + 0) * numVertsAcross + x + 1;
93
- indices[index + 3] = (z + 1) * numVertsAcross + x;
94
- indices[index + 4] = (z + 1) * numVertsAcross + x + 1;
95
- indices[index + 5] = (z + 0) * numVertsAcross + x + 1;
37
+ let i2 = 0;
38
+ let i3 = 0;
39
+ for (let z = 0; z <= subdivisions2; z++) {
40
+ for (let x = 0; x <= subdivisions1; x++) {
41
+ const u = x / subdivisions1;
42
+ const v = z / subdivisions2;
43
+ texCoords[i2 + 0] = flipCull ? 1 - u : u;
44
+ texCoords[i2 + 1] = v;
45
+ switch (type) {
46
+ case 'x,y':
47
+ positions[i3 + 0] = c1len * u - c1len * 0.5;
48
+ positions[i3 + 1] = c2len * v - c2len * 0.5;
49
+ positions[i3 + 2] = offset;
50
+ normals[i3 + 0] = 0;
51
+ normals[i3 + 1] = 0;
52
+ normals[i3 + 2] = flipCull ? 1 : -1;
53
+ break;
54
+ case 'x,z':
55
+ positions[i3 + 0] = c1len * u - c1len * 0.5;
56
+ positions[i3 + 1] = offset;
57
+ positions[i3 + 2] = c2len * v - c2len * 0.5;
58
+ normals[i3 + 0] = 0;
59
+ normals[i3 + 1] = flipCull ? 1 : -1;
60
+ normals[i3 + 2] = 0;
61
+ break;
62
+ case 'y,z':
63
+ positions[i3 + 0] = offset;
64
+ positions[i3 + 1] = c1len * u - c1len * 0.5;
65
+ positions[i3 + 2] = c2len * v - c2len * 0.5;
66
+ normals[i3 + 0] = flipCull ? 1 : -1;
67
+ normals[i3 + 1] = 0;
68
+ normals[i3 + 2] = 0;
69
+ break;
70
+ default:
71
+ throw new Error('PlaneGeometry: unknown type');
72
+ }
73
+ i2 += 2;
74
+ i3 += 3;
75
+ }
96
76
  }
97
- }
98
- const geometry = {
99
- indices: {
100
- size: 1,
101
- value: indices
102
- },
103
- attributes: {
104
- POSITION: {
105
- size: 3,
106
- value: positions
107
- },
108
- NORMAL: {
109
- size: 3,
110
- value: normals
111
- },
112
- TEXCOORD_0: {
113
- size: 2,
114
- value: texCoords
115
- }
77
+ const numVertsAcross = subdivisions1 + 1;
78
+ const indices = new Uint16Array(subdivisions1 * subdivisions2 * 6);
79
+ for (let z = 0; z < subdivisions2; z++) {
80
+ for (let x = 0; x < subdivisions1; x++) {
81
+ const index = (z * subdivisions1 + x) * 6;
82
+ // Make triangle 1 of quad.
83
+ indices[index + 0] = (z + 0) * numVertsAcross + x;
84
+ indices[index + 1] = (z + 1) * numVertsAcross + x;
85
+ indices[index + 2] = (z + 0) * numVertsAcross + x + 1;
86
+ // Make triangle 2 of quad.
87
+ indices[index + 3] = (z + 1) * numVertsAcross + x;
88
+ indices[index + 4] = (z + 1) * numVertsAcross + x + 1;
89
+ indices[index + 5] = (z + 0) * numVertsAcross + x + 1;
90
+ }
116
91
  }
117
- };
118
- return unpack ? unpackIndexedGeometry(geometry) : geometry;
92
+ const geometry = {
93
+ indices: { size: 1, value: indices },
94
+ attributes: {
95
+ POSITION: { size: 3, value: positions },
96
+ NORMAL: { size: 3, value: normals },
97
+ TEXCOORD_0: { size: 2, value: texCoords }
98
+ }
99
+ };
100
+ // Optionally, unpack indexed geometry
101
+ return unpack ? unpackIndexedGeometry(geometry) : geometry;
119
102
  }
120
- //# sourceMappingURL=plane-geometry.js.map
@@ -1,4 +1,4 @@
1
- import { Geometry } from '../geometry/geometry';
1
+ import { Geometry } from "../geometry/geometry.js";
2
2
  export type SphereGeometryProps = {
3
3
  id?: string;
4
4
  radius?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"sphere-geometry.d.ts","sourceRoot":"","sources":["../../src/geometries/sphere-geometry.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAE9C,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,GAAG,CAAA;CACjB,CAAC;AAKF,qBAAa,cAAe,SAAQ,QAAQ;gBAC9B,KAAK,GAAE,mBAAwB;CAW5C"}
1
+ {"version":3,"file":"sphere-geometry.d.ts","sourceRoot":"","sources":["../../src/geometries/sphere-geometry.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,gCAA6B;AAE9C,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,GAAG,CAAC;CAClB,CAAC;AAKF,qBAAa,cAAe,SAAQ,QAAQ;gBAC9B,KAAK,GAAE,mBAAwB;CAW5C"}
@@ -1,103 +1,84 @@
1
1
  import { uid } from '@luma.gl/core';
2
2
  import { Geometry } from "../geometry/geometry.js";
3
+ // Primitives inspired by TDL http://code.google.com/p/webglsamples/,
4
+ // copyright 2011 Google Inc. new BSD License
5
+ // (http://www.opensource.org/licenses/bsd-license.php).
3
6
  export class SphereGeometry extends Geometry {
4
- constructor() {
5
- let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
6
- const {
7
- id = uid('sphere-geometry')
8
- } = props;
9
- const {
10
- indices,
11
- attributes
12
- } = tesselateSphere(props);
13
- super({
14
- ...props,
15
- id,
16
- topology: 'triangle-list',
17
- indices,
18
- attributes: {
19
- ...attributes,
20
- ...props.attributes
21
- }
22
- });
23
- }
7
+ constructor(props = {}) {
8
+ const { id = uid('sphere-geometry') } = props;
9
+ const { indices, attributes } = tesselateSphere(props);
10
+ super({
11
+ ...props,
12
+ id,
13
+ topology: 'triangle-list',
14
+ indices,
15
+ attributes: { ...attributes, ...props.attributes }
16
+ });
17
+ }
24
18
  }
19
+ /* eslint-disable max-statements, complexity */
25
20
  function tesselateSphere(props) {
26
- const {
27
- nlat = 10,
28
- nlong = 10
29
- } = props;
30
- const startLat = 0;
31
- const endLat = Math.PI;
32
- const latRange = endLat - startLat;
33
- const startLong = 0;
34
- const endLong = 2 * Math.PI;
35
- const longRange = endLong - startLong;
36
- const numVertices = (nlat + 1) * (nlong + 1);
37
- const radius = (n1, n2, n3, u, v) => props.radius || 1;
38
- const positions = new Float32Array(numVertices * 3);
39
- const normals = new Float32Array(numVertices * 3);
40
- const texCoords = new Float32Array(numVertices * 2);
41
- const IndexType = numVertices > 0xffff ? Uint32Array : Uint16Array;
42
- const indices = new IndexType(nlat * nlong * 6);
43
- for (let y = 0; y <= nlat; y++) {
44
- for (let x = 0; x <= nlong; x++) {
45
- const u = x / nlong;
46
- const v = y / nlat;
47
- const index = x + y * (nlong + 1);
48
- const i2 = index * 2;
49
- const i3 = index * 3;
50
- const theta = longRange * u;
51
- const phi = latRange * v;
52
- const sinTheta = Math.sin(theta);
53
- const cosTheta = Math.cos(theta);
54
- const sinPhi = Math.sin(phi);
55
- const cosPhi = Math.cos(phi);
56
- const ux = cosTheta * sinPhi;
57
- const uy = cosPhi;
58
- const uz = sinTheta * sinPhi;
59
- const r = radius(ux, uy, uz, u, v);
60
- positions[i3 + 0] = r * ux;
61
- positions[i3 + 1] = r * uy;
62
- positions[i3 + 2] = r * uz;
63
- normals[i3 + 0] = ux;
64
- normals[i3 + 1] = uy;
65
- normals[i3 + 2] = uz;
66
- texCoords[i2 + 0] = u;
67
- texCoords[i2 + 1] = 1 - v;
68
- }
69
- }
70
- const numVertsAround = nlong + 1;
71
- for (let x = 0; x < nlong; x++) {
72
- for (let y = 0; y < nlat; y++) {
73
- const index = (x * nlat + y) * 6;
74
- indices[index + 0] = y * numVertsAround + x;
75
- indices[index + 1] = y * numVertsAround + x + 1;
76
- indices[index + 2] = (y + 1) * numVertsAround + x;
77
- indices[index + 3] = (y + 1) * numVertsAround + x;
78
- indices[index + 4] = y * numVertsAround + x + 1;
79
- indices[index + 5] = (y + 1) * numVertsAround + x + 1;
21
+ const { nlat = 10, nlong = 10 } = props;
22
+ const startLat = 0;
23
+ const endLat = Math.PI;
24
+ const latRange = endLat - startLat;
25
+ const startLong = 0;
26
+ const endLong = 2 * Math.PI;
27
+ const longRange = endLong - startLong;
28
+ const numVertices = (nlat + 1) * (nlong + 1);
29
+ const radius = (n1, n2, n3, u, v) => props.radius || 1;
30
+ const positions = new Float32Array(numVertices * 3);
31
+ const normals = new Float32Array(numVertices * 3);
32
+ const texCoords = new Float32Array(numVertices * 2);
33
+ const IndexType = numVertices > 0xffff ? Uint32Array : Uint16Array;
34
+ const indices = new IndexType(nlat * nlong * 6);
35
+ // Create positions, normals and texCoords
36
+ for (let y = 0; y <= nlat; y++) {
37
+ for (let x = 0; x <= nlong; x++) {
38
+ const u = x / nlong;
39
+ const v = y / nlat;
40
+ const index = x + y * (nlong + 1);
41
+ const i2 = index * 2;
42
+ const i3 = index * 3;
43
+ const theta = longRange * u;
44
+ const phi = latRange * v;
45
+ const sinTheta = Math.sin(theta);
46
+ const cosTheta = Math.cos(theta);
47
+ const sinPhi = Math.sin(phi);
48
+ const cosPhi = Math.cos(phi);
49
+ const ux = cosTheta * sinPhi;
50
+ const uy = cosPhi;
51
+ const uz = sinTheta * sinPhi;
52
+ const r = radius(ux, uy, uz, u, v);
53
+ positions[i3 + 0] = r * ux;
54
+ positions[i3 + 1] = r * uy;
55
+ positions[i3 + 2] = r * uz;
56
+ normals[i3 + 0] = ux;
57
+ normals[i3 + 1] = uy;
58
+ normals[i3 + 2] = uz;
59
+ texCoords[i2 + 0] = u;
60
+ texCoords[i2 + 1] = 1 - v;
61
+ }
80
62
  }
81
- }
82
- return {
83
- indices: {
84
- size: 1,
85
- value: indices
86
- },
87
- attributes: {
88
- POSITION: {
89
- size: 3,
90
- value: positions
91
- },
92
- NORMAL: {
93
- size: 3,
94
- value: normals
95
- },
96
- TEXCOORD_0: {
97
- size: 2,
98
- value: texCoords
99
- }
63
+ // Create indices
64
+ const numVertsAround = nlong + 1;
65
+ for (let x = 0; x < nlong; x++) {
66
+ for (let y = 0; y < nlat; y++) {
67
+ const index = (x * nlat + y) * 6;
68
+ indices[index + 0] = y * numVertsAround + x;
69
+ indices[index + 1] = y * numVertsAround + x + 1;
70
+ indices[index + 2] = (y + 1) * numVertsAround + x;
71
+ indices[index + 3] = (y + 1) * numVertsAround + x;
72
+ indices[index + 4] = y * numVertsAround + x + 1;
73
+ indices[index + 5] = (y + 1) * numVertsAround + x + 1;
74
+ }
100
75
  }
101
- };
76
+ return {
77
+ indices: { size: 1, value: indices },
78
+ attributes: {
79
+ POSITION: { size: 3, value: positions },
80
+ NORMAL: { size: 3, value: normals },
81
+ TEXCOORD_0: { size: 2, value: texCoords }
82
+ }
83
+ };
102
84
  }
103
- //# sourceMappingURL=sphere-geometry.js.map
@@ -1,4 +1,4 @@
1
- import { Geometry } from '../geometry/geometry';
1
+ import { Geometry } from "../geometry/geometry.js";
2
2
  export type TruncatedConeGeometryProps = {
3
3
  topRadius?: number;
4
4
  bottomRadius?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"truncated-cone-geometry.d.ts","sourceRoot":"","sources":["../../src/geometries/truncated-cone-geometry.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAQ9C,MAAM,MAAM,0BAA0B,GAAG;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;CAChC,CAAC;AAEF;;;;GAIG;AACH,qBAAa,qBAAsB,SAAQ,QAAQ;gBACrC,KAAK,GAAE,0BAA0B,GAAG;QAAC,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,GAAG,CAAA;KAAM;CAerF"}
1
+ {"version":3,"file":"truncated-cone-geometry.d.ts","sourceRoot":"","sources":["../../src/geometries/truncated-cone-geometry.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,gCAA6B;AAQ9C,MAAM,MAAM,0BAA0B,GAAG;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;CAChC,CAAC;AAEF;;;;GAIG;AACH,qBAAa,qBAAsB,SAAQ,QAAQ;gBACrC,KAAK,GAAE,0BAA0B,GAAG;QAAC,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,GAAG,CAAA;KAAM;CAgBrF"}
@@ -1,126 +1,108 @@
1
1
  import { uid } from '@luma.gl/core';
2
2
  import { Geometry } from "../geometry/geometry.js";
3
3
  const INDEX_OFFSETS = {
4
- x: [2, 0, 1],
5
- y: [0, 1, 2],
6
- z: [1, 2, 0]
4
+ x: [2, 0, 1],
5
+ y: [0, 1, 2],
6
+ z: [1, 2, 0]
7
7
  };
8
+ /**
9
+ * Primitives inspired by TDL http://code.google.com/p/webglsamples/,
10
+ * copyright 2011 Google Inc. new BSD License
11
+ * (http://www.opensource.org/licenses/bsd-license.php).
12
+ */
8
13
  export class TruncatedConeGeometry extends Geometry {
9
- constructor() {
10
- let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
11
- const {
12
- id = uid('truncated-code-geometry')
13
- } = props;
14
- const {
15
- indices,
16
- attributes
17
- } = tesselateTruncatedCone(props);
18
- super({
19
- ...props,
20
- id,
21
- topology: 'triangle-list',
22
- indices,
23
- attributes: {
24
- POSITION: {
25
- size: 3,
26
- value: attributes.POSITION
27
- },
28
- NORMAL: {
29
- size: 3,
30
- value: attributes.NORMAL
31
- },
32
- TEXCOORD_0: {
33
- size: 2,
34
- value: attributes.TEXCOORD_0
35
- },
36
- ...props.attributes
37
- }
38
- });
39
- }
40
- }
41
- function tesselateTruncatedCone() {
42
- let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
43
- const {
44
- bottomRadius = 0,
45
- topRadius = 0,
46
- height = 1,
47
- nradial = 10,
48
- nvertical = 10,
49
- verticalAxis = 'y',
50
- topCap = false,
51
- bottomCap = false
52
- } = props;
53
- const extra = (topCap ? 2 : 0) + (bottomCap ? 2 : 0);
54
- const numVertices = (nradial + 1) * (nvertical + 1 + extra);
55
- const slant = Math.atan2(bottomRadius - topRadius, height);
56
- const msin = Math.sin;
57
- const mcos = Math.cos;
58
- const mpi = Math.PI;
59
- const cosSlant = mcos(slant);
60
- const sinSlant = msin(slant);
61
- const start = topCap ? -2 : 0;
62
- const end = nvertical + (bottomCap ? 2 : 0);
63
- const vertsAroundEdge = nradial + 1;
64
- const indices = new Uint16Array(nradial * (nvertical + extra) * 6);
65
- const indexOffset = INDEX_OFFSETS[verticalAxis];
66
- const positions = new Float32Array(numVertices * 3);
67
- const normals = new Float32Array(numVertices * 3);
68
- const texCoords = new Float32Array(numVertices * 2);
69
- let i3 = 0;
70
- let i2 = 0;
71
- for (let i = start; i <= end; i++) {
72
- let v = i / nvertical;
73
- let y = height * v;
74
- let ringRadius;
75
- if (i < 0) {
76
- y = 0;
77
- v = 1;
78
- ringRadius = bottomRadius;
79
- } else if (i > nvertical) {
80
- y = height;
81
- v = 1;
82
- ringRadius = topRadius;
83
- } else {
84
- ringRadius = bottomRadius + (topRadius - bottomRadius) * (i / nvertical);
85
- }
86
- if (i === -2 || i === nvertical + 2) {
87
- ringRadius = 0;
88
- v = 0;
14
+ constructor(props = {}) {
15
+ const { id = uid('truncated-code-geometry') } = props;
16
+ const { indices, attributes } = tesselateTruncatedCone(props);
17
+ super({
18
+ ...props,
19
+ id,
20
+ topology: 'triangle-list',
21
+ indices,
22
+ attributes: {
23
+ POSITION: { size: 3, value: attributes.POSITION },
24
+ NORMAL: { size: 3, value: attributes.NORMAL },
25
+ TEXCOORD_0: { size: 2, value: attributes.TEXCOORD_0 },
26
+ ...props.attributes
27
+ }
28
+ });
89
29
  }
90
- y -= height / 2;
91
- for (let j = 0; j < vertsAroundEdge; j++) {
92
- const sin = msin(j * mpi * 2 / nradial);
93
- const cos = mcos(j * mpi * 2 / nradial);
94
- positions[i3 + indexOffset[0]] = sin * ringRadius;
95
- positions[i3 + indexOffset[1]] = y;
96
- positions[i3 + indexOffset[2]] = cos * ringRadius;
97
- normals[i3 + indexOffset[0]] = i < 0 || i > nvertical ? 0 : sin * cosSlant;
98
- normals[i3 + indexOffset[1]] = i < 0 ? -1 : i > nvertical ? 1 : sinSlant;
99
- normals[i3 + indexOffset[2]] = i < 0 || i > nvertical ? 0 : cos * cosSlant;
100
- texCoords[i2 + 0] = j / nradial;
101
- texCoords[i2 + 1] = v;
102
- i2 += 2;
103
- i3 += 3;
104
- }
105
- }
106
- for (let i = 0; i < nvertical + extra; i++) {
107
- for (let j = 0; j < nradial; j++) {
108
- const index = (i * nradial + j) * 6;
109
- indices[index + 0] = vertsAroundEdge * (i + 0) + 0 + j;
110
- indices[index + 1] = vertsAroundEdge * (i + 0) + 1 + j;
111
- indices[index + 2] = vertsAroundEdge * (i + 1) + 1 + j;
112
- indices[index + 3] = vertsAroundEdge * (i + 0) + 0 + j;
113
- indices[index + 4] = vertsAroundEdge * (i + 1) + 1 + j;
114
- indices[index + 5] = vertsAroundEdge * (i + 1) + 0 + j;
30
+ }
31
+ /* eslint-disable max-statements, complexity */
32
+ function tesselateTruncatedCone(props = {}) {
33
+ const { bottomRadius = 0, topRadius = 0, height = 1, nradial = 10, nvertical = 10, verticalAxis = 'y', topCap = false, bottomCap = false } = props;
34
+ const extra = (topCap ? 2 : 0) + (bottomCap ? 2 : 0);
35
+ const numVertices = (nradial + 1) * (nvertical + 1 + extra);
36
+ const slant = Math.atan2(bottomRadius - topRadius, height);
37
+ const msin = Math.sin;
38
+ const mcos = Math.cos;
39
+ const mpi = Math.PI;
40
+ const cosSlant = mcos(slant);
41
+ const sinSlant = msin(slant);
42
+ const start = topCap ? -2 : 0;
43
+ const end = nvertical + (bottomCap ? 2 : 0);
44
+ const vertsAroundEdge = nradial + 1;
45
+ const indices = new Uint16Array(nradial * (nvertical + extra) * 6);
46
+ const indexOffset = INDEX_OFFSETS[verticalAxis];
47
+ const positions = new Float32Array(numVertices * 3);
48
+ const normals = new Float32Array(numVertices * 3);
49
+ const texCoords = new Float32Array(numVertices * 2);
50
+ let i3 = 0;
51
+ let i2 = 0;
52
+ for (let i = start; i <= end; i++) {
53
+ let v = i / nvertical;
54
+ let y = height * v;
55
+ let ringRadius;
56
+ if (i < 0) {
57
+ y = 0;
58
+ v = 1;
59
+ ringRadius = bottomRadius;
60
+ }
61
+ else if (i > nvertical) {
62
+ y = height;
63
+ v = 1;
64
+ ringRadius = topRadius;
65
+ }
66
+ else {
67
+ ringRadius = bottomRadius + (topRadius - bottomRadius) * (i / nvertical);
68
+ }
69
+ if (i === -2 || i === nvertical + 2) {
70
+ ringRadius = 0;
71
+ v = 0;
72
+ }
73
+ y -= height / 2;
74
+ for (let j = 0; j < vertsAroundEdge; j++) {
75
+ const sin = msin((j * mpi * 2) / nradial);
76
+ const cos = mcos((j * mpi * 2) / nradial);
77
+ positions[i3 + indexOffset[0]] = sin * ringRadius;
78
+ positions[i3 + indexOffset[1]] = y;
79
+ positions[i3 + indexOffset[2]] = cos * ringRadius;
80
+ normals[i3 + indexOffset[0]] = i < 0 || i > nvertical ? 0 : sin * cosSlant;
81
+ normals[i3 + indexOffset[1]] = i < 0 ? -1 : i > nvertical ? 1 : sinSlant;
82
+ normals[i3 + indexOffset[2]] = i < 0 || i > nvertical ? 0 : cos * cosSlant;
83
+ texCoords[i2 + 0] = j / nradial;
84
+ texCoords[i2 + 1] = v;
85
+ i2 += 2;
86
+ i3 += 3;
87
+ }
115
88
  }
116
- }
117
- return {
118
- indices,
119
- attributes: {
120
- POSITION: positions,
121
- NORMAL: normals,
122
- TEXCOORD_0: texCoords
89
+ for (let i = 0; i < nvertical + extra; i++) {
90
+ for (let j = 0; j < nradial; j++) {
91
+ const index = (i * nradial + j) * 6;
92
+ indices[index + 0] = vertsAroundEdge * (i + 0) + 0 + j;
93
+ indices[index + 1] = vertsAroundEdge * (i + 0) + 1 + j;
94
+ indices[index + 2] = vertsAroundEdge * (i + 1) + 1 + j;
95
+ indices[index + 3] = vertsAroundEdge * (i + 0) + 0 + j;
96
+ indices[index + 4] = vertsAroundEdge * (i + 1) + 1 + j;
97
+ indices[index + 5] = vertsAroundEdge * (i + 1) + 0 + j;
98
+ }
123
99
  }
124
- };
100
+ return {
101
+ indices,
102
+ attributes: {
103
+ POSITION: positions,
104
+ NORMAL: normals,
105
+ TEXCOORD_0: texCoords
106
+ }
107
+ };
125
108
  }
126
- //# sourceMappingURL=truncated-cone-geometry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"geometry-table.d.ts","sourceRoot":"","sources":["../../src/geometry/geometry-table.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,UAAU,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AAE5D,yBAAyB;AACzB,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACtC,UAAU,EAAE;QACV,QAAQ,EAAE,UAAU,CAAC;QACrB,MAAM,EAAE,UAAU,CAAC;QACnB,UAAU,EAAE,UAAU,CAAC;QACvB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;KAC3B,CAAC;IACF,OAAO,CAAC,EAAE,WAAW,GAAG,WAAW,CAAC;IACpC,QAAQ,CAAC,EAAE,YAAY,GAAG,WAAW,GAAG,YAAY,GAAG,eAAe,GAAG,gBAAgB,CAAC;CAC3F,CAAA"}
1
+ {"version":3,"file":"geometry-table.d.ts","sourceRoot":"","sources":["../../src/geometry/geometry-table.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,UAAU,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AAE5D,yBAAyB;AACzB,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACtC,UAAU,EAAE;QACV,QAAQ,EAAE,UAAU,CAAC;QACrB,MAAM,EAAE,UAAU,CAAC;QACnB,UAAU,EAAE,UAAU,CAAC;QACvB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;KAC3B,CAAC;IACF,OAAO,CAAC,EAAE,WAAW,GAAG,WAAW,CAAC;IACpC,QAAQ,CAAC,EAAE,YAAY,GAAG,WAAW,GAAG,YAAY,GAAG,eAAe,GAAG,gBAAgB,CAAC;CAC3F,CAAC"}