@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
@@ -1,180 +1,151 @@
1
1
  import { uid } from '@luma.gl/api';
2
2
  import { Vector3 } from '@math.gl/core';
3
- import Geometry from '../geometry/geometry';
3
+ import Geometry from '../geometry/geometry.js';
4
+ /* eslint-disable comma-spacing, max-statements, complexity */
4
5
  const ICO_POSITIONS = [-1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 1, 0, -1, 0, 1, 0, 0];
5
6
  const ICO_INDICES = [3, 4, 5, 3, 5, 1, 3, 1, 0, 3, 0, 4, 4, 0, 2, 4, 2, 5, 2, 0, 1, 5, 2, 1];
6
7
  export class IcoSphereGeometry extends Geometry {
7
- constructor(props = {}) {
8
- const {
9
- id = uid('ico-sphere-geometry')
10
- } = props;
11
- const {
12
- indices,
13
- attributes
14
- } = tesselateIcosaHedron(props);
15
- super({ ...props,
16
- id,
17
- indices,
18
- attributes: { ...attributes,
19
- ...props.attributes
20
- }
21
- });
22
- }
23
-
8
+ constructor(props = {}) {
9
+ const { id = uid('ico-sphere-geometry') } = props;
10
+ const { indices, attributes } = tesselateIcosaHedron(props);
11
+ super({
12
+ ...props,
13
+ id,
14
+ indices,
15
+ attributes: { ...attributes, ...props.attributes }
16
+ });
17
+ }
24
18
  }
25
-
26
19
  function tesselateIcosaHedron(props) {
27
- const {
28
- iterations = 0
29
- } = props;
30
- const PI = Math.PI;
31
- const PI2 = PI * 2;
32
- const positions = [...ICO_POSITIONS];
33
- let indices = [...ICO_INDICES];
34
- positions.push();
35
- indices.push();
36
-
37
- const getMiddlePoint = (() => {
38
- const pointMemo = {};
39
- return (i1, i2) => {
40
- i1 *= 3;
41
- i2 *= 3;
42
- const mini = i1 < i2 ? i1 : i2;
43
- const maxi = i1 > i2 ? i1 : i2;
44
- const key = "".concat(mini, "|").concat(maxi);
45
-
46
- if (key in pointMemo) {
47
- return pointMemo[key];
48
- }
49
-
50
- const x1 = positions[i1];
51
- const y1 = positions[i1 + 1];
52
- const z1 = positions[i1 + 2];
53
- const x2 = positions[i2];
54
- const y2 = positions[i2 + 1];
55
- const z2 = positions[i2 + 2];
56
- let xm = (x1 + x2) / 2;
57
- let ym = (y1 + y2) / 2;
58
- let zm = (z1 + z2) / 2;
59
- const len = Math.sqrt(xm * xm + ym * ym + zm * zm);
60
- xm /= len;
61
- ym /= len;
62
- zm /= len;
63
- positions.push(xm, ym, zm);
64
- return pointMemo[key] = positions.length / 3 - 1;
65
- };
66
- })();
67
-
68
- for (let i = 0; i < iterations; i++) {
69
- const indices2 = [];
70
-
71
- for (let j = 0; j < indices.length; j += 3) {
72
- const a = getMiddlePoint(indices[j + 0], indices[j + 1]);
73
- const b = getMiddlePoint(indices[j + 1], indices[j + 2]);
74
- const c = getMiddlePoint(indices[j + 2], indices[j + 0]);
75
- indices2.push(c, indices[j + 0], a, a, indices[j + 1], b, b, indices[j + 2], c, a, b, c);
20
+ const { iterations = 0 } = props;
21
+ const PI = Math.PI;
22
+ const PI2 = PI * 2;
23
+ const positions = [...ICO_POSITIONS];
24
+ let indices = [...ICO_INDICES];
25
+ positions.push();
26
+ indices.push();
27
+ const getMiddlePoint = (() => {
28
+ const pointMemo = {};
29
+ return (i1, i2) => {
30
+ i1 *= 3;
31
+ i2 *= 3;
32
+ const mini = i1 < i2 ? i1 : i2;
33
+ const maxi = i1 > i2 ? i1 : i2;
34
+ const key = `${mini}|${maxi}`;
35
+ if (key in pointMemo) {
36
+ return pointMemo[key];
37
+ }
38
+ const x1 = positions[i1];
39
+ const y1 = positions[i1 + 1];
40
+ const z1 = positions[i1 + 2];
41
+ const x2 = positions[i2];
42
+ const y2 = positions[i2 + 1];
43
+ const z2 = positions[i2 + 2];
44
+ let xm = (x1 + x2) / 2;
45
+ let ym = (y1 + y2) / 2;
46
+ let zm = (z1 + z2) / 2;
47
+ const len = Math.sqrt(xm * xm + ym * ym + zm * zm);
48
+ xm /= len;
49
+ ym /= len;
50
+ zm /= len;
51
+ positions.push(xm, ym, zm);
52
+ return (pointMemo[key] = positions.length / 3 - 1);
53
+ };
54
+ })();
55
+ for (let i = 0; i < iterations; i++) {
56
+ const indices2 = [];
57
+ for (let j = 0; j < indices.length; j += 3) {
58
+ const a = getMiddlePoint(indices[j + 0], indices[j + 1]);
59
+ const b = getMiddlePoint(indices[j + 1], indices[j + 2]);
60
+ const c = getMiddlePoint(indices[j + 2], indices[j + 0]);
61
+ indices2.push(c, indices[j + 0], a, a, indices[j + 1], b, b, indices[j + 2], c, a, b, c);
62
+ }
63
+ indices = indices2;
76
64
  }
77
-
78
- indices = indices2;
79
- }
80
-
81
- const normals = new Array(positions.length);
82
- const texCoords = new Array(positions.length / 3 * 2);
83
- const l = indices.length;
84
-
85
- for (let i = l - 3; i >= 0; i -= 3) {
86
- const i1 = indices[i + 0];
87
- const i2 = indices[i + 1];
88
- const i3 = indices[i + 2];
89
- const in1 = i1 * 3;
90
- const in2 = i2 * 3;
91
- const in3 = i3 * 3;
92
- const iu1 = i1 * 2;
93
- const iu2 = i2 * 2;
94
- const iu3 = i3 * 2;
95
- const x1 = positions[in1 + 0];
96
- const y1 = positions[in1 + 1];
97
- const z1 = positions[in1 + 2];
98
- const theta1 = Math.acos(z1 / Math.sqrt(x1 * x1 + y1 * y1 + z1 * z1));
99
- const phi1 = Math.atan2(y1, x1) + PI;
100
- const v1 = theta1 / PI;
101
- const u1 = 1 - phi1 / PI2;
102
- const x2 = positions[in2 + 0];
103
- const y2 = positions[in2 + 1];
104
- const z2 = positions[in2 + 2];
105
- const theta2 = Math.acos(z2 / Math.sqrt(x2 * x2 + y2 * y2 + z2 * z2));
106
- const phi2 = Math.atan2(y2, x2) + PI;
107
- const v2 = theta2 / PI;
108
- const u2 = 1 - phi2 / PI2;
109
- const x3 = positions[in3 + 0];
110
- const y3 = positions[in3 + 1];
111
- const z3 = positions[in3 + 2];
112
- const theta3 = Math.acos(z3 / Math.sqrt(x3 * x3 + y3 * y3 + z3 * z3));
113
- const phi3 = Math.atan2(y3, x3) + PI;
114
- const v3 = theta3 / PI;
115
- const u3 = 1 - phi3 / PI2;
116
- const vec1 = [x3 - x2, y3 - y2, z3 - z2];
117
- const vec2 = [x1 - x2, y1 - y2, z1 - z2];
118
- const normal = new Vector3(vec1).cross(vec2).normalize();
119
- let newIndex;
120
-
121
- if ((u1 === 0 || u2 === 0 || u3 === 0) && (u1 === 0 || u1 > 0.5) && (u2 === 0 || u2 > 0.5) && (u3 === 0 || u3 > 0.5)) {
122
- positions.push(positions[in1 + 0], positions[in1 + 1], positions[in1 + 2]);
123
- newIndex = positions.length / 3 - 1;
124
- indices.push(newIndex);
125
- texCoords[newIndex * 2 + 0] = 1;
126
- texCoords[newIndex * 2 + 1] = v1;
127
- normals[newIndex * 3 + 0] = normal.x;
128
- normals[newIndex * 3 + 1] = normal.y;
129
- normals[newIndex * 3 + 2] = normal.z;
130
- positions.push(positions[in2 + 0], positions[in2 + 1], positions[in2 + 2]);
131
- newIndex = positions.length / 3 - 1;
132
- indices.push(newIndex);
133
- texCoords[newIndex * 2 + 0] = 1;
134
- texCoords[newIndex * 2 + 1] = v2;
135
- normals[newIndex * 3 + 0] = normal.x;
136
- normals[newIndex * 3 + 1] = normal.y;
137
- normals[newIndex * 3 + 2] = normal.z;
138
- positions.push(positions[in3 + 0], positions[in3 + 1], positions[in3 + 2]);
139
- newIndex = positions.length / 3 - 1;
140
- indices.push(newIndex);
141
- texCoords[newIndex * 2 + 0] = 1;
142
- texCoords[newIndex * 2 + 1] = v3;
143
- normals[newIndex * 3 + 0] = normal.x;
144
- normals[newIndex * 3 + 1] = normal.y;
145
- normals[newIndex * 3 + 2] = normal.z;
65
+ // Calculate texCoords and normals
66
+ const normals = new Array(positions.length);
67
+ const texCoords = new Array((positions.length / 3) * 2);
68
+ const l = indices.length;
69
+ for (let i = l - 3; i >= 0; i -= 3) {
70
+ const i1 = indices[i + 0];
71
+ const i2 = indices[i + 1];
72
+ const i3 = indices[i + 2];
73
+ const in1 = i1 * 3;
74
+ const in2 = i2 * 3;
75
+ const in3 = i3 * 3;
76
+ const iu1 = i1 * 2;
77
+ const iu2 = i2 * 2;
78
+ const iu3 = i3 * 2;
79
+ const x1 = positions[in1 + 0];
80
+ const y1 = positions[in1 + 1];
81
+ const z1 = positions[in1 + 2];
82
+ const theta1 = Math.acos(z1 / Math.sqrt(x1 * x1 + y1 * y1 + z1 * z1));
83
+ const phi1 = Math.atan2(y1, x1) + PI;
84
+ const v1 = theta1 / PI;
85
+ const u1 = 1 - phi1 / PI2;
86
+ const x2 = positions[in2 + 0];
87
+ const y2 = positions[in2 + 1];
88
+ const z2 = positions[in2 + 2];
89
+ const theta2 = Math.acos(z2 / Math.sqrt(x2 * x2 + y2 * y2 + z2 * z2));
90
+ const phi2 = Math.atan2(y2, x2) + PI;
91
+ const v2 = theta2 / PI;
92
+ const u2 = 1 - phi2 / PI2;
93
+ const x3 = positions[in3 + 0];
94
+ const y3 = positions[in3 + 1];
95
+ const z3 = positions[in3 + 2];
96
+ const theta3 = Math.acos(z3 / Math.sqrt(x3 * x3 + y3 * y3 + z3 * z3));
97
+ const phi3 = Math.atan2(y3, x3) + PI;
98
+ const v3 = theta3 / PI;
99
+ const u3 = 1 - phi3 / PI2;
100
+ const vec1 = [x3 - x2, y3 - y2, z3 - z2];
101
+ const vec2 = [x1 - x2, y1 - y2, z1 - z2];
102
+ const normal = new Vector3(vec1).cross(vec2).normalize();
103
+ let newIndex;
104
+ if ((u1 === 0 || u2 === 0 || u3 === 0) &&
105
+ (u1 === 0 || u1 > 0.5) &&
106
+ (u2 === 0 || u2 > 0.5) &&
107
+ (u3 === 0 || u3 > 0.5)) {
108
+ positions.push(positions[in1 + 0], positions[in1 + 1], positions[in1 + 2]);
109
+ newIndex = positions.length / 3 - 1;
110
+ indices.push(newIndex);
111
+ texCoords[newIndex * 2 + 0] = 1;
112
+ texCoords[newIndex * 2 + 1] = v1;
113
+ normals[newIndex * 3 + 0] = normal.x;
114
+ normals[newIndex * 3 + 1] = normal.y;
115
+ normals[newIndex * 3 + 2] = normal.z;
116
+ positions.push(positions[in2 + 0], positions[in2 + 1], positions[in2 + 2]);
117
+ newIndex = positions.length / 3 - 1;
118
+ indices.push(newIndex);
119
+ texCoords[newIndex * 2 + 0] = 1;
120
+ texCoords[newIndex * 2 + 1] = v2;
121
+ normals[newIndex * 3 + 0] = normal.x;
122
+ normals[newIndex * 3 + 1] = normal.y;
123
+ normals[newIndex * 3 + 2] = normal.z;
124
+ positions.push(positions[in3 + 0], positions[in3 + 1], positions[in3 + 2]);
125
+ newIndex = positions.length / 3 - 1;
126
+ indices.push(newIndex);
127
+ texCoords[newIndex * 2 + 0] = 1;
128
+ texCoords[newIndex * 2 + 1] = v3;
129
+ normals[newIndex * 3 + 0] = normal.x;
130
+ normals[newIndex * 3 + 1] = normal.y;
131
+ normals[newIndex * 3 + 2] = normal.z;
132
+ }
133
+ normals[in1 + 0] = normals[in2 + 0] = normals[in3 + 0] = normal.x;
134
+ normals[in1 + 1] = normals[in2 + 1] = normals[in3 + 1] = normal.y;
135
+ normals[in1 + 2] = normals[in2 + 2] = normals[in3 + 2] = normal.z;
136
+ texCoords[iu1 + 0] = u1;
137
+ texCoords[iu1 + 1] = v1;
138
+ texCoords[iu2 + 0] = u2;
139
+ texCoords[iu2 + 1] = v2;
140
+ texCoords[iu3 + 0] = u3;
141
+ texCoords[iu3 + 1] = v3;
146
142
  }
147
-
148
- normals[in1 + 0] = normals[in2 + 0] = normals[in3 + 0] = normal.x;
149
- normals[in1 + 1] = normals[in2 + 1] = normals[in3 + 1] = normal.y;
150
- normals[in1 + 2] = normals[in2 + 2] = normals[in3 + 2] = normal.z;
151
- texCoords[iu1 + 0] = u1;
152
- texCoords[iu1 + 1] = v1;
153
- texCoords[iu2 + 0] = u2;
154
- texCoords[iu2 + 1] = v2;
155
- texCoords[iu3 + 0] = u3;
156
- texCoords[iu3 + 1] = v3;
157
- }
158
-
159
- return {
160
- indices: {
161
- size: 1,
162
- value: new Uint16Array(indices)
163
- },
164
- attributes: {
165
- POSITION: {
166
- size: 3,
167
- value: new Float32Array(positions)
168
- },
169
- NORMAL: {
170
- size: 3,
171
- value: new Float32Array(normals)
172
- },
173
- TEXCOORD_0: {
174
- size: 2,
175
- value: new Float32Array(texCoords)
176
- }
177
- }
178
- };
143
+ return {
144
+ indices: { size: 1, value: new Uint16Array(indices) },
145
+ attributes: {
146
+ POSITION: { size: 3, value: new Float32Array(positions) },
147
+ NORMAL: { size: 3, value: new Float32Array(normals) },
148
+ TEXCOORD_0: { size: 2, value: new Float32Array(texCoords) }
149
+ }
150
+ };
179
151
  }
180
- //# sourceMappingURL=ico-sphere-geometry.js.map
@@ -1,5 +1,5 @@
1
1
  import Geometry from '../geometry/geometry';
2
- export declare type PlaneGeometryProps = {
2
+ export type PlaneGeometryProps = {
3
3
  id?: string;
4
4
  radius?: number;
5
5
  attributes?: any;
@@ -1 +1 @@
1
- {"version":3,"file":"plane-geometry.d.ts","sourceRoot":"","sources":["../../src/geometries/plane-geometry.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,sBAAsB,CAAC;AAG5C,oBAAY,kBAAkB,GAAG;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,GAAG,CAAA;CACjB,CAAC;AAKF,qBAAa,aAAc,SAAQ,QAAQ;gBAC7B,KAAK,GAAE,kBAAuB;CAW3C"}
1
+ {"version":3,"file":"plane-geometry.d.ts","sourceRoot":"","sources":["../../src/geometries/plane-geometry.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,sBAAsB,CAAC;AAG5C,MAAM,MAAM,kBAAkB,GAAG;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,GAAG,CAAA;CACjB,CAAC;AAKF,qBAAa,aAAc,SAAQ,QAAQ;gBAC7B,KAAK,GAAE,kBAAuB;CAW3C"}
@@ -1,129 +1,101 @@
1
1
  import { uid } from '@luma.gl/api';
2
- import Geometry from '../geometry/geometry';
3
- import { unpackIndexedGeometry } from '../geometry/geometry-utils';
2
+ import Geometry from '../geometry/geometry.js';
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(props = {}) {
6
- const {
7
- id = uid('plane-geometry')
8
- } = props;
9
- const {
10
- indices,
11
- attributes
12
- } = tesselatePlane(props);
13
- super({ ...props,
14
- id,
15
- indices,
16
- attributes: { ...attributes,
17
- ...props.attributes
18
- }
19
- });
20
- }
21
-
8
+ constructor(props = {}) {
9
+ const { id = uid('plane-geometry') } = props;
10
+ const { indices, attributes } = tesselatePlane(props);
11
+ super({
12
+ ...props,
13
+ id,
14
+ indices,
15
+ attributes: { ...attributes, ...props.attributes }
16
+ });
17
+ }
22
18
  }
23
-
19
+ /* eslint-disable complexity, max-statements */
24
20
  function tesselatePlane(props) {
25
- const {
26
- type = 'x,y',
27
- offset = 0,
28
- flipCull = false,
29
- unpack = false
30
- } = props;
31
- const coords = type.split(',');
32
- let c1len = props["".concat(coords[0], "len")] || 1;
33
- const c2len = props["".concat(coords[1], "len")] || 1;
34
- const subdivisions1 = props["n".concat(coords[0])] || 1;
35
- const subdivisions2 = props["n".concat(coords[1])] || 1;
36
- const numVertices = (subdivisions1 + 1) * (subdivisions2 + 1);
37
- const positions = new Float32Array(numVertices * 3);
38
- const normals = new Float32Array(numVertices * 3);
39
- const texCoords = new Float32Array(numVertices * 2);
40
-
41
- if (flipCull) {
42
- c1len = -c1len;
43
- }
44
-
45
- let i2 = 0;
46
- let i3 = 0;
47
-
48
- for (let z = 0; z <= subdivisions2; z++) {
49
- for (let x = 0; x <= subdivisions1; x++) {
50
- const u = x / subdivisions1;
51
- const v = z / subdivisions2;
52
- texCoords[i2 + 0] = flipCull ? 1 - u : u;
53
- texCoords[i2 + 1] = v;
54
-
55
- switch (type) {
56
- case 'x,y':
57
- positions[i3 + 0] = c1len * u - c1len * 0.5;
58
- positions[i3 + 1] = c2len * v - c2len * 0.5;
59
- positions[i3 + 2] = offset;
60
- normals[i3 + 0] = 0;
61
- normals[i3 + 1] = 0;
62
- normals[i3 + 2] = flipCull ? 1 : -1;
63
- break;
64
-
65
- case 'x,z':
66
- positions[i3 + 0] = c1len * u - c1len * 0.5;
67
- positions[i3 + 1] = offset;
68
- positions[i3 + 2] = c2len * v - c2len * 0.5;
69
- normals[i3 + 0] = 0;
70
- normals[i3 + 1] = flipCull ? 1 : -1;
71
- normals[i3 + 2] = 0;
72
- break;
73
-
74
- case 'y,z':
75
- positions[i3 + 0] = offset;
76
- positions[i3 + 1] = c1len * u - c1len * 0.5;
77
- positions[i3 + 2] = c2len * v - c2len * 0.5;
78
- normals[i3 + 0] = flipCull ? 1 : -1;
79
- normals[i3 + 1] = 0;
80
- normals[i3 + 2] = 0;
81
- break;
82
-
83
- default:
84
- throw new Error('PlaneGeometry: unknown type');
85
- }
86
-
87
- i2 += 2;
88
- i3 += 3;
21
+ const { type = 'x,y', offset = 0, flipCull = false, unpack = false } = props;
22
+ const coords = type.split(',');
23
+ // width, height
24
+ let c1len = props[`${coords[0]}len`] || 1;
25
+ const c2len = props[`${coords[1]}len`] || 1;
26
+ // subdivisionsWidth, subdivisionsDepth
27
+ const subdivisions1 = props[`n${coords[0]}`] || 1;
28
+ const subdivisions2 = props[`n${coords[1]}`] || 1;
29
+ const numVertices = (subdivisions1 + 1) * (subdivisions2 + 1);
30
+ const positions = new Float32Array(numVertices * 3);
31
+ const normals = new Float32Array(numVertices * 3);
32
+ const texCoords = new Float32Array(numVertices * 2);
33
+ if (flipCull) {
34
+ c1len = -c1len;
89
35
  }
90
- }
91
-
92
- const numVertsAcross = subdivisions1 + 1;
93
- const indices = new Uint16Array(subdivisions1 * subdivisions2 * 6);
94
-
95
- for (let z = 0; z < subdivisions2; z++) {
96
- for (let x = 0; x < subdivisions1; x++) {
97
- const index = (z * subdivisions1 + x) * 6;
98
- indices[index + 0] = (z + 0) * numVertsAcross + x;
99
- indices[index + 1] = (z + 1) * numVertsAcross + x;
100
- indices[index + 2] = (z + 0) * numVertsAcross + x + 1;
101
- indices[index + 3] = (z + 1) * numVertsAcross + x;
102
- indices[index + 4] = (z + 1) * numVertsAcross + x + 1;
103
- indices[index + 5] = (z + 0) * numVertsAcross + x + 1;
36
+ let i2 = 0;
37
+ let i3 = 0;
38
+ for (let z = 0; z <= subdivisions2; z++) {
39
+ for (let x = 0; x <= subdivisions1; x++) {
40
+ const u = x / subdivisions1;
41
+ const v = z / subdivisions2;
42
+ texCoords[i2 + 0] = flipCull ? 1 - u : u;
43
+ texCoords[i2 + 1] = v;
44
+ switch (type) {
45
+ case 'x,y':
46
+ positions[i3 + 0] = c1len * u - c1len * 0.5;
47
+ positions[i3 + 1] = c2len * v - c2len * 0.5;
48
+ positions[i3 + 2] = offset;
49
+ normals[i3 + 0] = 0;
50
+ normals[i3 + 1] = 0;
51
+ normals[i3 + 2] = flipCull ? 1 : -1;
52
+ break;
53
+ case 'x,z':
54
+ positions[i3 + 0] = c1len * u - c1len * 0.5;
55
+ positions[i3 + 1] = offset;
56
+ positions[i3 + 2] = c2len * v - c2len * 0.5;
57
+ normals[i3 + 0] = 0;
58
+ normals[i3 + 1] = flipCull ? 1 : -1;
59
+ normals[i3 + 2] = 0;
60
+ break;
61
+ case 'y,z':
62
+ positions[i3 + 0] = offset;
63
+ positions[i3 + 1] = c1len * u - c1len * 0.5;
64
+ positions[i3 + 2] = c2len * v - c2len * 0.5;
65
+ normals[i3 + 0] = flipCull ? 1 : -1;
66
+ normals[i3 + 1] = 0;
67
+ normals[i3 + 2] = 0;
68
+ break;
69
+ default:
70
+ throw new Error('PlaneGeometry: unknown type');
71
+ }
72
+ i2 += 2;
73
+ i3 += 3;
74
+ }
104
75
  }
105
- }
106
-
107
- const geometry = {
108
- indices: {
109
- size: 1,
110
- value: indices
111
- },
112
- attributes: {
113
- POSITION: {
114
- size: 3,
115
- value: positions
116
- },
117
- NORMAL: {
118
- size: 3,
119
- value: normals
120
- },
121
- TEXCOORD_0: {
122
- size: 2,
123
- value: texCoords
124
- }
76
+ const numVertsAcross = subdivisions1 + 1;
77
+ const indices = new Uint16Array(subdivisions1 * subdivisions2 * 6);
78
+ for (let z = 0; z < subdivisions2; z++) {
79
+ for (let x = 0; x < subdivisions1; x++) {
80
+ const index = (z * subdivisions1 + x) * 6;
81
+ // Make triangle 1 of quad.
82
+ indices[index + 0] = (z + 0) * numVertsAcross + x;
83
+ indices[index + 1] = (z + 1) * numVertsAcross + x;
84
+ indices[index + 2] = (z + 0) * numVertsAcross + x + 1;
85
+ // Make triangle 2 of quad.
86
+ indices[index + 3] = (z + 1) * numVertsAcross + x;
87
+ indices[index + 4] = (z + 1) * numVertsAcross + x + 1;
88
+ indices[index + 5] = (z + 0) * numVertsAcross + x + 1;
89
+ }
125
90
  }
126
- };
127
- return unpack ? unpackIndexedGeometry(geometry) : geometry;
91
+ const geometry = {
92
+ indices: { size: 1, value: indices },
93
+ attributes: {
94
+ POSITION: { size: 3, value: positions },
95
+ NORMAL: { size: 3, value: normals },
96
+ TEXCOORD_0: { size: 2, value: texCoords }
97
+ }
98
+ };
99
+ // Optionally, unpack indexed geometry
100
+ return unpack ? unpackIndexedGeometry(geometry) : geometry;
128
101
  }
129
- //# sourceMappingURL=plane-geometry.js.map
@@ -1,5 +1,5 @@
1
1
  import Geometry from '../geometry/geometry';
2
- export declare type SphereGeometryProps = {
2
+ export type SphereGeometryProps = {
3
3
  id?: string;
4
4
  radius?: number;
5
5
  nlat?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"sphere-geometry.d.ts","sourceRoot":"","sources":["../../src/geometries/sphere-geometry.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,sBAAsB,CAAC;AAE5C,oBAAY,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;CAU5C"}
1
+ {"version":3,"file":"sphere-geometry.d.ts","sourceRoot":"","sources":["../../src/geometries/sphere-geometry.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,sBAAsB,CAAC;AAE5C,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;CAU5C"}