@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.
- package/dist/animation/key-frames.d.ts +1 -1
- package/dist/animation/key-frames.d.ts.map +1 -1
- package/dist/animation/key-frames.js +51 -72
- package/dist/animation/timeline.d.ts +4 -4
- package/dist/animation/timeline.d.ts.map +1 -1
- package/dist/animation/timeline.js +94 -131
- package/dist/animation-loop/animation-loop.d.ts +2 -3
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +414 -473
- package/dist/animation-loop/animation-props.d.ts +1 -2
- package/dist/animation-loop/animation-props.d.ts.map +1 -1
- package/dist/animation-loop/animation-props.js +0 -1
- package/dist/animation-loop/make-animation-loop.d.ts +1 -1
- package/dist/animation-loop/make-animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/make-animation-loop.js +26 -31
- package/dist/animation-loop/render-loop.js +17 -7
- package/dist/bundle.js +2 -2
- package/dist/dist.min.js +31 -0
- package/dist/es5/animation/key-frames.js +84 -0
- package/dist/es5/animation/key-frames.js.map +1 -0
- package/dist/es5/animation/timeline.js +183 -0
- package/dist/es5/animation/timeline.js.map +1 -0
- package/dist/es5/animation-loop/animation-loop.js +534 -0
- package/dist/es5/animation-loop/animation-loop.js.map +1 -0
- package/dist/es5/animation-loop/animation-props.js +2 -0
- package/dist/es5/animation-loop/animation-props.js.map +1 -0
- package/dist/es5/animation-loop/make-animation-loop.js +53 -0
- package/dist/es5/animation-loop/make-animation-loop.js.map +1 -0
- package/dist/es5/animation-loop/render-loop.js +39 -0
- package/dist/es5/animation-loop/render-loop.js.map +1 -0
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/geometries/cone-geometry.js +43 -0
- package/dist/es5/geometries/cone-geometry.js.map +1 -0
- package/dist/es5/geometries/cube-geometry.js +84 -0
- package/dist/es5/geometries/cube-geometry.js.map +1 -0
- package/dist/es5/geometries/cylinder-geometry.js +39 -0
- package/dist/es5/geometries/cylinder-geometry.js.map +1 -0
- package/dist/es5/geometries/ico-sphere-geometry.js +185 -0
- package/dist/es5/geometries/ico-sphere-geometry.js.map +1 -0
- package/dist/es5/geometries/plane-geometry.js +137 -0
- package/dist/es5/geometries/plane-geometry.js.map +1 -0
- package/dist/es5/geometries/sphere-geometry.js +120 -0
- package/dist/es5/geometries/sphere-geometry.js.map +1 -0
- package/dist/es5/geometries/truncated-cone-geometry.js +160 -0
- package/dist/es5/geometries/truncated-cone-geometry.js.map +1 -0
- package/dist/es5/geometry/geometry-table.js +2 -0
- package/dist/es5/geometry/geometry-table.js.map +1 -0
- package/dist/es5/geometry/geometry-utils.js +39 -0
- package/dist/es5/geometry/geometry-utils.js.map +1 -0
- package/dist/es5/geometry/geometry.js +150 -0
- package/dist/es5/geometry/geometry.js.map +1 -0
- package/dist/es5/geometry/primitive-utils.js +2 -0
- package/dist/es5/geometry/primitive-utils.js.map +1 -0
- package/dist/es5/index.js +112 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/clip-space.js +2 -0
- package/dist/es5/lib/clip-space.js.map +1 -0
- package/dist/es5/lib/model-utils.js +52 -0
- package/dist/es5/lib/model-utils.js.map +1 -0
- package/dist/es5/lib/model.js +173 -0
- package/dist/es5/lib/model.js.map +1 -0
- package/dist/es5/lib/pipeline-factory.js +244 -0
- package/dist/es5/lib/pipeline-factory.js.map +1 -0
- package/dist/esm/animation/key-frames.js +57 -0
- package/dist/esm/animation/key-frames.js.map +1 -0
- package/dist/esm/animation/timeline.js +113 -0
- package/dist/esm/animation/timeline.js.map +1 -0
- package/dist/esm/animation-loop/animation-loop.js +367 -0
- package/dist/esm/animation-loop/animation-loop.js.map +1 -0
- package/dist/esm/animation-loop/animation-props.js +2 -0
- package/dist/esm/animation-loop/animation-props.js.map +1 -0
- package/dist/esm/animation-loop/make-animation-loop.js +28 -0
- package/dist/esm/animation-loop/make-animation-loop.js.map +1 -0
- package/dist/esm/animation-loop/render-loop.js +7 -0
- package/dist/esm/animation-loop/render-loop.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/geometries/cone-geometry.js +21 -0
- package/dist/esm/geometries/cone-geometry.js.map +1 -0
- package/dist/esm/geometries/cube-geometry.js +67 -0
- package/dist/esm/geometries/cube-geometry.js.map +1 -0
- package/dist/esm/geometries/cylinder-geometry.js +18 -0
- package/dist/esm/geometries/cylinder-geometry.js.map +1 -0
- package/dist/esm/geometries/ico-sphere-geometry.js +170 -0
- package/dist/esm/geometries/ico-sphere-geometry.js.map +1 -0
- package/dist/esm/geometries/plane-geometry.js +119 -0
- package/dist/esm/geometries/plane-geometry.js.map +1 -0
- package/dist/esm/geometries/sphere-geometry.js +102 -0
- package/dist/esm/geometries/sphere-geometry.js.map +1 -0
- package/dist/esm/geometries/truncated-cone-geometry.js +136 -0
- package/dist/esm/geometries/truncated-cone-geometry.js.map +1 -0
- package/dist/esm/geometry/geometry-table.js +2 -0
- package/dist/esm/geometry/geometry-table.js.map +1 -0
- package/dist/esm/geometry/geometry-utils.js +37 -0
- package/dist/esm/geometry/geometry-utils.js.map +1 -0
- package/dist/esm/geometry/geometry.js +119 -0
- package/dist/esm/geometry/geometry.js.map +1 -0
- package/dist/esm/geometry/primitive-utils.js +2 -0
- package/dist/esm/geometry/primitive-utils.js.map +1 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/clip-space.js +2 -0
- package/dist/esm/lib/clip-space.js.map +1 -0
- package/dist/esm/lib/model-utils.js +40 -0
- package/dist/esm/lib/model-utils.js.map +1 -0
- package/dist/esm/lib/model.js +146 -0
- package/dist/esm/lib/model.js.map +1 -0
- package/dist/esm/lib/pipeline-factory.js +180 -0
- package/dist/esm/lib/pipeline-factory.js.map +1 -0
- package/dist/geometries/cone-geometry.d.ts +1 -1
- package/dist/geometries/cone-geometry.d.ts.map +1 -1
- package/dist/geometries/cone-geometry.js +12 -17
- package/dist/geometries/cube-geometry.d.ts +1 -1
- package/dist/geometries/cube-geometry.d.ts.map +1 -1
- package/dist/geometries/cube-geometry.js +187 -56
- package/dist/geometries/cylinder-geometry.d.ts +1 -1
- package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
- package/dist/geometries/cylinder-geometry.js +10 -14
- package/dist/geometries/ico-sphere-geometry.d.ts +1 -1
- package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/ico-sphere-geometry.js +141 -170
- package/dist/geometries/plane-geometry.d.ts +1 -1
- package/dist/geometries/plane-geometry.d.ts.map +1 -1
- package/dist/geometries/plane-geometry.js +93 -121
- package/dist/geometries/sphere-geometry.d.ts +1 -1
- package/dist/geometries/sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/sphere-geometry.js +76 -100
- package/dist/geometries/truncated-cone-geometry.d.ts +1 -1
- package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
- package/dist/geometries/truncated-cone-geometry.js +104 -131
- package/dist/geometry/geometry-table.d.ts +1 -1
- package/dist/geometry/geometry-table.d.ts.map +1 -1
- package/dist/geometry/geometry-table.js +0 -1
- package/dist/geometry/geometry-utils.js +22 -41
- package/dist/geometry/geometry.d.ts +4 -4
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +96 -142
- package/dist/geometry/primitive-utils.js +30 -1
- package/dist/index.js +20 -16
- package/dist/lib/clip-space.js +50 -1
- package/dist/lib/model-utils.js +97 -29
- package/dist/lib/model.d.ts +1 -1
- package/dist/lib/model.d.ts.map +1 -1
- package/dist/lib/model.js +122 -166
- package/dist/lib/pipeline-factory.d.ts +3 -3
- package/dist/lib/pipeline-factory.d.ts.map +1 -1
- package/dist/lib/pipeline-factory.js +136 -204
- package/package.json +12 -11
- package/dist/animation/key-frames.js.map +0 -1
- package/dist/animation/timeline.js.map +0 -1
- package/dist/animation-loop/animation-loop.js.map +0 -1
- package/dist/animation-loop/animation-props.js.map +0 -1
- package/dist/animation-loop/make-animation-loop.js.map +0 -1
- package/dist/animation-loop/render-loop.js.map +0 -1
- package/dist/bundle.js.map +0 -1
- package/dist/geometries/cone-geometry.js.map +0 -1
- package/dist/geometries/cube-geometry.js.map +0 -1
- package/dist/geometries/cylinder-geometry.js.map +0 -1
- package/dist/geometries/ico-sphere-geometry.js.map +0 -1
- package/dist/geometries/plane-geometry.js.map +0 -1
- package/dist/geometries/sphere-geometry.js.map +0 -1
- package/dist/geometries/truncated-cone-geometry.js.map +0 -1
- package/dist/geometry/geometry-table.js.map +0 -1
- package/dist/geometry/geometry-utils.js.map +0 -1
- package/dist/geometry/geometry.js.map +0 -1
- package/dist/geometry/primitive-utils.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/clip-space.js.map +0 -1
- package/dist/lib/model-utils.js.map +0 -1
- package/dist/lib/model.js.map +0 -1
- 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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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 +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,
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
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 +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,
|
|
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"}
|