@luma.gl/engine 10.0.0-alpha.3 → 10.0.0-alpha.4
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/dist.dev.js +695 -1317
- package/dist/dist.min.js +31 -31
- package/dist/geometry/edge-geometry.d.ts +3 -2
- package/dist/geometry/edge-geometry.d.ts.map +1 -1
- package/dist/geometry/edge-geometry.js.map +1 -1
- package/dist/geometry/geometry-primitives.d.ts +54 -0
- package/dist/geometry/geometry-primitives.d.ts.map +1 -0
- package/dist/geometry/geometry-primitives.js +153 -0
- package/dist/geometry/geometry-primitives.js.map +1 -0
- package/dist/geometry/geometry-utils.d.ts +7 -15
- package/dist/geometry/geometry-utils.d.ts.map +1 -1
- package/dist/geometry/geometry-utils.js +9 -55
- package/dist/geometry/geometry-utils.js.map +1 -1
- package/dist/geometry/geometry.d.ts +9 -69
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +27 -93
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/geometry/gpu-geometry.d.ts +4 -2
- package/dist/geometry/gpu-geometry.d.ts.map +1 -1
- package/dist/geometry/gpu-geometry.js +3 -3
- package/dist/geometry/gpu-geometry.js.map +1 -1
- package/dist/index.cjs +241 -1301
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +14 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/model/model.d.ts +1 -1
- package/dist/model/model.d.ts.map +1 -1
- package/dist/models/clip-space.d.ts +4 -1
- package/dist/models/clip-space.d.ts.map +1 -1
- package/dist/models/clip-space.js +16 -13
- package/dist/models/clip-space.js.map +1 -1
- package/dist/models/directional-light-model.js +1 -1
- package/dist/models/directional-light-model.js.map +1 -1
- package/dist/models/point-light-model.js +1 -1
- package/dist/models/point-light-model.js.map +1 -1
- package/dist/models/spot-light-model.js +1 -1
- package/dist/models/spot-light-model.js.map +1 -1
- package/package.json +7 -6
- package/src/geometry/edge-geometry.ts +7 -3
- package/src/geometry/geometry-primitives.ts +215 -0
- package/src/geometry/geometry-utils.ts +16 -71
- package/src/geometry/geometry.ts +36 -163
- package/src/geometry/gpu-geometry.ts +9 -4
- package/src/index.ts +14 -14
- package/src/model/model.ts +1 -1
- package/src/models/clip-space.ts +21 -14
- package/src/models/directional-light-model.ts +1 -1
- package/src/models/point-light-model.ts +1 -1
- package/src/models/spot-light-model.ts +1 -1
- package/dist/geometries/cone-geometry.d.ts +0 -12
- package/dist/geometries/cone-geometry.d.ts.map +0 -1
- package/dist/geometries/cone-geometry.js +0 -19
- package/dist/geometries/cone-geometry.js.map +0 -1
- package/dist/geometries/cube-geometry.d.ts +0 -14
- package/dist/geometries/cube-geometry.d.ts.map +0 -1
- package/dist/geometries/cube-geometry.js +0 -222
- package/dist/geometries/cube-geometry.js.map +0 -1
- package/dist/geometries/cylinder-geometry.d.ts +0 -11
- package/dist/geometries/cylinder-geometry.d.ts.map +0 -1
- package/dist/geometries/cylinder-geometry.js +0 -17
- package/dist/geometries/cylinder-geometry.js.map +0 -1
- package/dist/geometries/ico-sphere-geometry.d.ts +0 -11
- package/dist/geometries/ico-sphere-geometry.d.ts.map +0 -1
- package/dist/geometries/ico-sphere-geometry.js +0 -158
- package/dist/geometries/ico-sphere-geometry.js.map +0 -1
- package/dist/geometries/plane-geometry.d.ts +0 -20
- package/dist/geometries/plane-geometry.d.ts.map +0 -1
- package/dist/geometries/plane-geometry.js +0 -106
- package/dist/geometries/plane-geometry.js.map +0 -1
- package/dist/geometries/sphere-geometry.d.ts +0 -12
- package/dist/geometries/sphere-geometry.d.ts.map +0 -1
- package/dist/geometries/sphere-geometry.js +0 -88
- package/dist/geometries/sphere-geometry.js.map +0 -1
- package/dist/geometries/truncated-cone-geometry.d.ts +0 -23
- package/dist/geometries/truncated-cone-geometry.d.ts.map +0 -1
- package/dist/geometries/truncated-cone-geometry.js +0 -112
- package/dist/geometries/truncated-cone-geometry.js.map +0 -1
- package/src/geometries/cone-geometry.ts +0 -31
- package/src/geometries/cube-geometry.ts +0 -258
- package/src/geometries/cylinder-geometry.ts +0 -28
- package/src/geometries/ico-sphere-geometry.ts +0 -193
- package/src/geometries/plane-geometry.ts +0 -142
- package/src/geometries/sphere-geometry.ts +0 -113
- package/src/geometries/truncated-cone-geometry.ts +0 -145
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
// luma.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import {Vector3} from '@math.gl/core';
|
|
6
|
-
import {Geometry} from '../geometry/geometry';
|
|
7
|
-
import {uid} from '../utils/uid';
|
|
8
|
-
|
|
9
|
-
/* eslint-disable comma-spacing, max-statements, complexity */
|
|
10
|
-
|
|
11
|
-
const ICO_POSITIONS = [-1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 1, 0, -1, 0, 1, 0, 0];
|
|
12
|
-
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];
|
|
13
|
-
|
|
14
|
-
export type IcoSphereGeometryProps = {
|
|
15
|
-
id?: string;
|
|
16
|
-
radius?: number;
|
|
17
|
-
iterations?: number;
|
|
18
|
-
attributes?: any;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export class IcoSphereGeometry extends Geometry {
|
|
22
|
-
constructor(props: IcoSphereGeometryProps = {}) {
|
|
23
|
-
const {id = uid('ico-sphere-geometry')} = props;
|
|
24
|
-
const {indices, attributes} = tesselateIcosaHedron(props);
|
|
25
|
-
super({
|
|
26
|
-
...props,
|
|
27
|
-
id,
|
|
28
|
-
topology: 'triangle-list',
|
|
29
|
-
indices,
|
|
30
|
-
attributes: {...attributes, ...props.attributes}
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function tesselateIcosaHedron(props: IcoSphereGeometryProps) {
|
|
36
|
-
const {iterations = 0} = props;
|
|
37
|
-
|
|
38
|
-
const PI = Math.PI;
|
|
39
|
-
const PI2 = PI * 2;
|
|
40
|
-
|
|
41
|
-
const positions = [...ICO_POSITIONS];
|
|
42
|
-
let indices = [...ICO_INDICES];
|
|
43
|
-
|
|
44
|
-
positions.push();
|
|
45
|
-
indices.push();
|
|
46
|
-
|
|
47
|
-
const getMiddlePoint = (() => {
|
|
48
|
-
const pointMemo: Record<string, number> = {};
|
|
49
|
-
|
|
50
|
-
return (i1: number, i2: number) => {
|
|
51
|
-
i1 *= 3;
|
|
52
|
-
i2 *= 3;
|
|
53
|
-
const mini = i1 < i2 ? i1 : i2;
|
|
54
|
-
const maxi = i1 > i2 ? i1 : i2;
|
|
55
|
-
const key = `${mini}|${maxi}`;
|
|
56
|
-
|
|
57
|
-
if (key in pointMemo) {
|
|
58
|
-
return pointMemo[key];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const x1 = positions[i1];
|
|
62
|
-
const y1 = positions[i1 + 1];
|
|
63
|
-
const z1 = positions[i1 + 2];
|
|
64
|
-
const x2 = positions[i2];
|
|
65
|
-
const y2 = positions[i2 + 1];
|
|
66
|
-
const z2 = positions[i2 + 2];
|
|
67
|
-
let xm = (x1 + x2) / 2;
|
|
68
|
-
let ym = (y1 + y2) / 2;
|
|
69
|
-
let zm = (z1 + z2) / 2;
|
|
70
|
-
const len = Math.sqrt(xm * xm + ym * ym + zm * zm);
|
|
71
|
-
|
|
72
|
-
xm /= len;
|
|
73
|
-
ym /= len;
|
|
74
|
-
zm /= len;
|
|
75
|
-
|
|
76
|
-
positions.push(xm, ym, zm);
|
|
77
|
-
|
|
78
|
-
const pointIndex = positions.length / 3 - 1;
|
|
79
|
-
pointMemo[key] = pointIndex;
|
|
80
|
-
return pointIndex;
|
|
81
|
-
};
|
|
82
|
-
})();
|
|
83
|
-
|
|
84
|
-
for (let i = 0; i < iterations; i++) {
|
|
85
|
-
const indices2: number[] = [];
|
|
86
|
-
for (let j = 0; j < indices.length; j += 3) {
|
|
87
|
-
const a = getMiddlePoint(indices[j + 0], indices[j + 1]);
|
|
88
|
-
const b = getMiddlePoint(indices[j + 1], indices[j + 2]);
|
|
89
|
-
const c = getMiddlePoint(indices[j + 2], indices[j + 0]);
|
|
90
|
-
|
|
91
|
-
indices2.push(c, indices[j + 0], a, a, indices[j + 1], b, b, indices[j + 2], c, a, b, c);
|
|
92
|
-
}
|
|
93
|
-
indices = indices2;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Calculate texCoords and normals
|
|
97
|
-
const normals = new Array(positions.length);
|
|
98
|
-
const texCoords = new Array((positions.length / 3) * 2);
|
|
99
|
-
|
|
100
|
-
const l = indices.length;
|
|
101
|
-
for (let i = l - 3; i >= 0; i -= 3) {
|
|
102
|
-
const i1 = indices[i + 0];
|
|
103
|
-
const i2 = indices[i + 1];
|
|
104
|
-
const i3 = indices[i + 2];
|
|
105
|
-
const in1 = i1 * 3;
|
|
106
|
-
const in2 = i2 * 3;
|
|
107
|
-
const in3 = i3 * 3;
|
|
108
|
-
const iu1 = i1 * 2;
|
|
109
|
-
const iu2 = i2 * 2;
|
|
110
|
-
const iu3 = i3 * 2;
|
|
111
|
-
const x1 = positions[in1 + 0];
|
|
112
|
-
const y1 = positions[in1 + 1];
|
|
113
|
-
const z1 = positions[in1 + 2];
|
|
114
|
-
const theta1 = Math.acos(z1 / Math.sqrt(x1 * x1 + y1 * y1 + z1 * z1));
|
|
115
|
-
const phi1 = Math.atan2(y1, x1) + PI;
|
|
116
|
-
const v1 = theta1 / PI;
|
|
117
|
-
const u1 = 1 - phi1 / PI2;
|
|
118
|
-
const x2 = positions[in2 + 0];
|
|
119
|
-
const y2 = positions[in2 + 1];
|
|
120
|
-
const z2 = positions[in2 + 2];
|
|
121
|
-
const theta2 = Math.acos(z2 / Math.sqrt(x2 * x2 + y2 * y2 + z2 * z2));
|
|
122
|
-
const phi2 = Math.atan2(y2, x2) + PI;
|
|
123
|
-
const v2 = theta2 / PI;
|
|
124
|
-
const u2 = 1 - phi2 / PI2;
|
|
125
|
-
const x3 = positions[in3 + 0];
|
|
126
|
-
const y3 = positions[in3 + 1];
|
|
127
|
-
const z3 = positions[in3 + 2];
|
|
128
|
-
const theta3 = Math.acos(z3 / Math.sqrt(x3 * x3 + y3 * y3 + z3 * z3));
|
|
129
|
-
const phi3 = Math.atan2(y3, x3) + PI;
|
|
130
|
-
const v3 = theta3 / PI;
|
|
131
|
-
const u3 = 1 - phi3 / PI2;
|
|
132
|
-
const vec1 = [x3 - x2, y3 - y2, z3 - z2];
|
|
133
|
-
const vec2 = [x1 - x2, y1 - y2, z1 - z2];
|
|
134
|
-
const normal = new Vector3(vec1).cross(vec2).normalize();
|
|
135
|
-
let newIndex;
|
|
136
|
-
|
|
137
|
-
if (
|
|
138
|
-
(u1 === 0 || u2 === 0 || u3 === 0) &&
|
|
139
|
-
(u1 === 0 || u1 > 0.5) &&
|
|
140
|
-
(u2 === 0 || u2 > 0.5) &&
|
|
141
|
-
(u3 === 0 || u3 > 0.5)
|
|
142
|
-
) {
|
|
143
|
-
positions.push(positions[in1 + 0], positions[in1 + 1], positions[in1 + 2]);
|
|
144
|
-
newIndex = positions.length / 3 - 1;
|
|
145
|
-
indices.push(newIndex);
|
|
146
|
-
texCoords[newIndex * 2 + 0] = 1;
|
|
147
|
-
texCoords[newIndex * 2 + 1] = v1;
|
|
148
|
-
normals[newIndex * 3 + 0] = normal.x;
|
|
149
|
-
normals[newIndex * 3 + 1] = normal.y;
|
|
150
|
-
normals[newIndex * 3 + 2] = normal.z;
|
|
151
|
-
|
|
152
|
-
positions.push(positions[in2 + 0], positions[in2 + 1], positions[in2 + 2]);
|
|
153
|
-
newIndex = positions.length / 3 - 1;
|
|
154
|
-
indices.push(newIndex);
|
|
155
|
-
texCoords[newIndex * 2 + 0] = 1;
|
|
156
|
-
texCoords[newIndex * 2 + 1] = v2;
|
|
157
|
-
normals[newIndex * 3 + 0] = normal.x;
|
|
158
|
-
normals[newIndex * 3 + 1] = normal.y;
|
|
159
|
-
normals[newIndex * 3 + 2] = normal.z;
|
|
160
|
-
|
|
161
|
-
positions.push(positions[in3 + 0], positions[in3 + 1], positions[in3 + 2]);
|
|
162
|
-
newIndex = positions.length / 3 - 1;
|
|
163
|
-
indices.push(newIndex);
|
|
164
|
-
texCoords[newIndex * 2 + 0] = 1;
|
|
165
|
-
texCoords[newIndex * 2 + 1] = v3;
|
|
166
|
-
normals[newIndex * 3 + 0] = normal.x;
|
|
167
|
-
normals[newIndex * 3 + 1] = normal.y;
|
|
168
|
-
normals[newIndex * 3 + 2] = normal.z;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
normals[in1 + 0] = normals[in2 + 0] = normals[in3 + 0] = normal.x;
|
|
172
|
-
normals[in1 + 1] = normals[in2 + 1] = normals[in3 + 1] = normal.y;
|
|
173
|
-
normals[in1 + 2] = normals[in2 + 2] = normals[in3 + 2] = normal.z;
|
|
174
|
-
|
|
175
|
-
texCoords[iu1 + 0] = u1;
|
|
176
|
-
texCoords[iu1 + 1] = v1;
|
|
177
|
-
|
|
178
|
-
texCoords[iu2 + 0] = u2;
|
|
179
|
-
texCoords[iu2 + 1] = v2;
|
|
180
|
-
|
|
181
|
-
texCoords[iu3 + 0] = u3;
|
|
182
|
-
texCoords[iu3 + 1] = v3;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return {
|
|
186
|
-
indices: {size: 1, value: new Uint16Array(indices)},
|
|
187
|
-
attributes: {
|
|
188
|
-
POSITION: {size: 3, value: new Float32Array(positions)},
|
|
189
|
-
NORMAL: {size: 3, value: new Float32Array(normals)},
|
|
190
|
-
TEXCOORD_0: {size: 2, value: new Float32Array(texCoords)}
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
// luma.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import {Geometry} from '../geometry/geometry';
|
|
6
|
-
import {unpackIndexedGeometry} from '../geometry/geometry-utils';
|
|
7
|
-
import {uid} from '../utils/uid';
|
|
8
|
-
|
|
9
|
-
export type PlaneGeometryProps = {
|
|
10
|
-
id?: string;
|
|
11
|
-
radius?: number;
|
|
12
|
-
attributes?: any;
|
|
13
|
-
type?: 'x,y' | 'x,z' | 'y,z';
|
|
14
|
-
offset?: number;
|
|
15
|
-
flipCull?: boolean;
|
|
16
|
-
unpack?: boolean;
|
|
17
|
-
xlen?: number;
|
|
18
|
-
ylen?: number;
|
|
19
|
-
zlen?: number;
|
|
20
|
-
nx?: number;
|
|
21
|
-
ny?: number;
|
|
22
|
-
nz?: number;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
// Primitives inspired by TDL http://code.google.com/p/webglsamples/,
|
|
26
|
-
// copyright 2011 Google Inc. new BSD License
|
|
27
|
-
// (http://www.opensource.org/licenses/bsd-license.php).
|
|
28
|
-
export class PlaneGeometry extends Geometry {
|
|
29
|
-
constructor(props: PlaneGeometryProps = {}) {
|
|
30
|
-
const {id = uid('plane-geometry')} = props;
|
|
31
|
-
|
|
32
|
-
const {indices, attributes} = tesselatePlane(props);
|
|
33
|
-
super({
|
|
34
|
-
...props,
|
|
35
|
-
id,
|
|
36
|
-
topology: 'triangle-list',
|
|
37
|
-
indices,
|
|
38
|
-
attributes: {...attributes, ...props.attributes}
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/* eslint-disable complexity, max-statements */
|
|
44
|
-
function tesselatePlane(props: any) {
|
|
45
|
-
const {type = 'x,y', offset = 0, flipCull = false, unpack = false} = props;
|
|
46
|
-
|
|
47
|
-
const coords = type.split(',');
|
|
48
|
-
// width, height
|
|
49
|
-
let c1len = props[`${coords[0]}len`] || 1;
|
|
50
|
-
const c2len = props[`${coords[1]}len`] || 1;
|
|
51
|
-
// subdivisionsWidth, subdivisionsDepth
|
|
52
|
-
const subdivisions1 = props[`n${coords[0]}`] || 1;
|
|
53
|
-
const subdivisions2 = props[`n${coords[1]}`] || 1;
|
|
54
|
-
const numVertices = (subdivisions1 + 1) * (subdivisions2 + 1);
|
|
55
|
-
|
|
56
|
-
const positions = new Float32Array(numVertices * 3);
|
|
57
|
-
const normals = new Float32Array(numVertices * 3);
|
|
58
|
-
const texCoords = new Float32Array(numVertices * 2);
|
|
59
|
-
|
|
60
|
-
if (flipCull) {
|
|
61
|
-
c1len = -c1len;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
let i2 = 0;
|
|
65
|
-
let i3 = 0;
|
|
66
|
-
for (let z = 0; z <= subdivisions2; z++) {
|
|
67
|
-
for (let x = 0; x <= subdivisions1; x++) {
|
|
68
|
-
const u = x / subdivisions1;
|
|
69
|
-
const v = z / subdivisions2;
|
|
70
|
-
texCoords[i2 + 0] = flipCull ? 1 - u : u;
|
|
71
|
-
texCoords[i2 + 1] = v;
|
|
72
|
-
|
|
73
|
-
switch (type) {
|
|
74
|
-
case 'x,y':
|
|
75
|
-
positions[i3 + 0] = c1len * u - c1len * 0.5;
|
|
76
|
-
positions[i3 + 1] = c2len * v - c2len * 0.5;
|
|
77
|
-
positions[i3 + 2] = offset;
|
|
78
|
-
|
|
79
|
-
normals[i3 + 0] = 0;
|
|
80
|
-
normals[i3 + 1] = 0;
|
|
81
|
-
normals[i3 + 2] = flipCull ? 1 : -1;
|
|
82
|
-
break;
|
|
83
|
-
|
|
84
|
-
case 'x,z':
|
|
85
|
-
positions[i3 + 0] = c1len * u - c1len * 0.5;
|
|
86
|
-
positions[i3 + 1] = offset;
|
|
87
|
-
positions[i3 + 2] = c2len * v - c2len * 0.5;
|
|
88
|
-
|
|
89
|
-
normals[i3 + 0] = 0;
|
|
90
|
-
normals[i3 + 1] = flipCull ? 1 : -1;
|
|
91
|
-
normals[i3 + 2] = 0;
|
|
92
|
-
break;
|
|
93
|
-
|
|
94
|
-
case 'y,z':
|
|
95
|
-
positions[i3 + 0] = offset;
|
|
96
|
-
positions[i3 + 1] = c1len * u - c1len * 0.5;
|
|
97
|
-
positions[i3 + 2] = c2len * v - c2len * 0.5;
|
|
98
|
-
|
|
99
|
-
normals[i3 + 0] = flipCull ? 1 : -1;
|
|
100
|
-
normals[i3 + 1] = 0;
|
|
101
|
-
normals[i3 + 2] = 0;
|
|
102
|
-
break;
|
|
103
|
-
|
|
104
|
-
default:
|
|
105
|
-
throw new Error('PlaneGeometry: unknown type');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
i2 += 2;
|
|
109
|
-
i3 += 3;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const numVertsAcross = subdivisions1 + 1;
|
|
114
|
-
const indices = new Uint16Array(subdivisions1 * subdivisions2 * 6);
|
|
115
|
-
|
|
116
|
-
for (let z = 0; z < subdivisions2; z++) {
|
|
117
|
-
for (let x = 0; x < subdivisions1; x++) {
|
|
118
|
-
const index = (z * subdivisions1 + x) * 6;
|
|
119
|
-
// Make triangle 1 of quad.
|
|
120
|
-
indices[index + 0] = (z + 0) * numVertsAcross + x;
|
|
121
|
-
indices[index + 1] = (z + 1) * numVertsAcross + x;
|
|
122
|
-
indices[index + 2] = (z + 0) * numVertsAcross + x + 1;
|
|
123
|
-
|
|
124
|
-
// Make triangle 2 of quad.
|
|
125
|
-
indices[index + 3] = (z + 1) * numVertsAcross + x;
|
|
126
|
-
indices[index + 4] = (z + 1) * numVertsAcross + x + 1;
|
|
127
|
-
indices[index + 5] = (z + 0) * numVertsAcross + x + 1;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const geometry = {
|
|
132
|
-
indices: {size: 1, value: indices},
|
|
133
|
-
attributes: {
|
|
134
|
-
POSITION: {size: 3, value: positions},
|
|
135
|
-
NORMAL: {size: 3, value: normals},
|
|
136
|
-
TEXCOORD_0: {size: 2, value: texCoords}
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
// Optionally, unpack indexed geometry
|
|
141
|
-
return unpack ? unpackIndexedGeometry(geometry) : geometry;
|
|
142
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
// luma.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import {Geometry} from '../geometry/geometry';
|
|
6
|
-
import {uid} from '../utils/uid';
|
|
7
|
-
|
|
8
|
-
export type SphereGeometryProps = {
|
|
9
|
-
id?: string;
|
|
10
|
-
radius?: number;
|
|
11
|
-
nlat?: number;
|
|
12
|
-
nlong?: number;
|
|
13
|
-
attributes?: any;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// Primitives inspired by TDL http://code.google.com/p/webglsamples/,
|
|
17
|
-
// copyright 2011 Google Inc. new BSD License
|
|
18
|
-
// (http://www.opensource.org/licenses/bsd-license.php).
|
|
19
|
-
export class SphereGeometry extends Geometry {
|
|
20
|
-
constructor(props: SphereGeometryProps = {}) {
|
|
21
|
-
const {id = uid('sphere-geometry')} = props;
|
|
22
|
-
const {indices, attributes} = tesselateSphere(props);
|
|
23
|
-
super({
|
|
24
|
-
...props,
|
|
25
|
-
id,
|
|
26
|
-
topology: 'triangle-list',
|
|
27
|
-
indices,
|
|
28
|
-
attributes: {...attributes, ...props.attributes}
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/* eslint-disable max-statements, complexity */
|
|
34
|
-
function tesselateSphere(props: SphereGeometryProps) {
|
|
35
|
-
const {nlat = 10, nlong = 10} = props;
|
|
36
|
-
|
|
37
|
-
const startLat = 0;
|
|
38
|
-
const endLat = Math.PI;
|
|
39
|
-
const latRange = endLat - startLat;
|
|
40
|
-
const startLong = 0;
|
|
41
|
-
const endLong = 2 * Math.PI;
|
|
42
|
-
const longRange = endLong - startLong;
|
|
43
|
-
const numVertices = (nlat + 1) * (nlong + 1);
|
|
44
|
-
|
|
45
|
-
const radius = (n1: number, n2: number, n3: number, u: number, v: number) => props.radius || 1;
|
|
46
|
-
|
|
47
|
-
const positions = new Float32Array(numVertices * 3);
|
|
48
|
-
const normals = new Float32Array(numVertices * 3);
|
|
49
|
-
const texCoords = new Float32Array(numVertices * 2);
|
|
50
|
-
|
|
51
|
-
const IndexType = numVertices > 0xffff ? Uint32Array : Uint16Array;
|
|
52
|
-
const indices = new IndexType(nlat * nlong * 6);
|
|
53
|
-
|
|
54
|
-
// Create positions, normals and texCoords
|
|
55
|
-
for (let y = 0; y <= nlat; y++) {
|
|
56
|
-
for (let x = 0; x <= nlong; x++) {
|
|
57
|
-
const u = x / nlong;
|
|
58
|
-
const v = y / nlat;
|
|
59
|
-
|
|
60
|
-
const index = x + y * (nlong + 1);
|
|
61
|
-
const i2 = index * 2;
|
|
62
|
-
const i3 = index * 3;
|
|
63
|
-
|
|
64
|
-
const theta = longRange * u;
|
|
65
|
-
const phi = latRange * v;
|
|
66
|
-
const sinTheta = Math.sin(theta);
|
|
67
|
-
const cosTheta = Math.cos(theta);
|
|
68
|
-
const sinPhi = Math.sin(phi);
|
|
69
|
-
const cosPhi = Math.cos(phi);
|
|
70
|
-
const ux = cosTheta * sinPhi;
|
|
71
|
-
const uy = cosPhi;
|
|
72
|
-
const uz = sinTheta * sinPhi;
|
|
73
|
-
|
|
74
|
-
const r = radius(ux, uy, uz, u, v);
|
|
75
|
-
|
|
76
|
-
positions[i3 + 0] = r * ux;
|
|
77
|
-
positions[i3 + 1] = r * uy;
|
|
78
|
-
positions[i3 + 2] = r * uz;
|
|
79
|
-
|
|
80
|
-
normals[i3 + 0] = ux;
|
|
81
|
-
normals[i3 + 1] = uy;
|
|
82
|
-
normals[i3 + 2] = uz;
|
|
83
|
-
|
|
84
|
-
texCoords[i2 + 0] = u;
|
|
85
|
-
texCoords[i2 + 1] = 1 - v;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Create indices
|
|
90
|
-
const numVertsAround = nlong + 1;
|
|
91
|
-
for (let x = 0; x < nlong; x++) {
|
|
92
|
-
for (let y = 0; y < nlat; y++) {
|
|
93
|
-
const index = (x * nlat + y) * 6;
|
|
94
|
-
|
|
95
|
-
indices[index + 0] = y * numVertsAround + x;
|
|
96
|
-
indices[index + 1] = y * numVertsAround + x + 1;
|
|
97
|
-
indices[index + 2] = (y + 1) * numVertsAround + x;
|
|
98
|
-
|
|
99
|
-
indices[index + 3] = (y + 1) * numVertsAround + x;
|
|
100
|
-
indices[index + 4] = y * numVertsAround + x + 1;
|
|
101
|
-
indices[index + 5] = (y + 1) * numVertsAround + x + 1;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return {
|
|
106
|
-
indices: {size: 1, value: indices},
|
|
107
|
-
attributes: {
|
|
108
|
-
POSITION: {size: 3, value: positions},
|
|
109
|
-
NORMAL: {size: 3, value: normals},
|
|
110
|
-
TEXCOORD_0: {size: 2, value: texCoords}
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
// luma.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import {Geometry} from '../geometry/geometry';
|
|
6
|
-
import {uid} from '../utils/uid';
|
|
7
|
-
|
|
8
|
-
const INDEX_OFFSETS = {
|
|
9
|
-
x: [2, 0, 1],
|
|
10
|
-
y: [0, 1, 2],
|
|
11
|
-
z: [1, 2, 0]
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type TruncatedConeGeometryProps = {
|
|
15
|
-
topRadius?: number;
|
|
16
|
-
bottomRadius?: number;
|
|
17
|
-
topCap?: boolean;
|
|
18
|
-
bottomCap?: boolean;
|
|
19
|
-
height?: number;
|
|
20
|
-
nradial?: number;
|
|
21
|
-
nvertical?: number;
|
|
22
|
-
verticalAxis?: 'x' | 'y' | 'z';
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Primitives inspired by TDL http://code.google.com/p/webglsamples/,
|
|
27
|
-
* copyright 2011 Google Inc. new BSD License
|
|
28
|
-
* (http://www.opensource.org/licenses/bsd-license.php).
|
|
29
|
-
*/
|
|
30
|
-
export class TruncatedConeGeometry extends Geometry {
|
|
31
|
-
constructor(props: TruncatedConeGeometryProps & {id?: string; attributes?: any} = {}) {
|
|
32
|
-
const {id = uid('truncated-code-geometry')} = props;
|
|
33
|
-
const {indices, attributes} = tesselateTruncatedCone(props);
|
|
34
|
-
super({
|
|
35
|
-
...props,
|
|
36
|
-
id,
|
|
37
|
-
topology: 'triangle-list',
|
|
38
|
-
indices,
|
|
39
|
-
attributes: {
|
|
40
|
-
POSITION: {size: 3, value: attributes.POSITION},
|
|
41
|
-
NORMAL: {size: 3, value: attributes.NORMAL},
|
|
42
|
-
TEXCOORD_0: {size: 2, value: attributes.TEXCOORD_0},
|
|
43
|
-
...props.attributes
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/* eslint-disable max-statements, complexity */
|
|
50
|
-
function tesselateTruncatedCone(props: TruncatedConeGeometryProps = {}) {
|
|
51
|
-
const {
|
|
52
|
-
bottomRadius = 0,
|
|
53
|
-
topRadius = 0,
|
|
54
|
-
height = 1,
|
|
55
|
-
nradial = 10,
|
|
56
|
-
nvertical = 10,
|
|
57
|
-
verticalAxis = 'y',
|
|
58
|
-
topCap = false,
|
|
59
|
-
bottomCap = false
|
|
60
|
-
} = props;
|
|
61
|
-
|
|
62
|
-
const extra = (topCap ? 2 : 0) + (bottomCap ? 2 : 0);
|
|
63
|
-
const numVertices = (nradial + 1) * (nvertical + 1 + extra);
|
|
64
|
-
|
|
65
|
-
const slant = Math.atan2(bottomRadius - topRadius, height);
|
|
66
|
-
const msin = Math.sin;
|
|
67
|
-
const mcos = Math.cos;
|
|
68
|
-
const mpi = Math.PI;
|
|
69
|
-
const cosSlant = mcos(slant);
|
|
70
|
-
const sinSlant = msin(slant);
|
|
71
|
-
const start = topCap ? -2 : 0;
|
|
72
|
-
const end = nvertical + (bottomCap ? 2 : 0);
|
|
73
|
-
const vertsAroundEdge = nradial + 1;
|
|
74
|
-
|
|
75
|
-
const indices = new Uint16Array(nradial * (nvertical + extra) * 6);
|
|
76
|
-
const indexOffset = INDEX_OFFSETS[verticalAxis];
|
|
77
|
-
|
|
78
|
-
const positions = new Float32Array(numVertices * 3);
|
|
79
|
-
const normals = new Float32Array(numVertices * 3);
|
|
80
|
-
const texCoords = new Float32Array(numVertices * 2);
|
|
81
|
-
|
|
82
|
-
let i3 = 0;
|
|
83
|
-
let i2 = 0;
|
|
84
|
-
for (let i = start; i <= end; i++) {
|
|
85
|
-
let v = i / nvertical;
|
|
86
|
-
let y = height * v;
|
|
87
|
-
let ringRadius;
|
|
88
|
-
|
|
89
|
-
if (i < 0) {
|
|
90
|
-
y = 0;
|
|
91
|
-
v = 1;
|
|
92
|
-
ringRadius = bottomRadius;
|
|
93
|
-
} else if (i > nvertical) {
|
|
94
|
-
y = height;
|
|
95
|
-
v = 1;
|
|
96
|
-
ringRadius = topRadius;
|
|
97
|
-
} else {
|
|
98
|
-
ringRadius = bottomRadius + (topRadius - bottomRadius) * (i / nvertical);
|
|
99
|
-
}
|
|
100
|
-
if (i === -2 || i === nvertical + 2) {
|
|
101
|
-
ringRadius = 0;
|
|
102
|
-
v = 0;
|
|
103
|
-
}
|
|
104
|
-
y -= height / 2;
|
|
105
|
-
for (let j = 0; j < vertsAroundEdge; j++) {
|
|
106
|
-
const sin = msin((j * mpi * 2) / nradial);
|
|
107
|
-
const cos = mcos((j * mpi * 2) / nradial);
|
|
108
|
-
|
|
109
|
-
positions[i3 + indexOffset[0]] = sin * ringRadius;
|
|
110
|
-
positions[i3 + indexOffset[1]] = y;
|
|
111
|
-
positions[i3 + indexOffset[2]] = cos * ringRadius;
|
|
112
|
-
|
|
113
|
-
normals[i3 + indexOffset[0]] = i < 0 || i > nvertical ? 0 : sin * cosSlant;
|
|
114
|
-
normals[i3 + indexOffset[1]] = i < 0 ? -1 : i > nvertical ? 1 : sinSlant;
|
|
115
|
-
normals[i3 + indexOffset[2]] = i < 0 || i > nvertical ? 0 : cos * cosSlant;
|
|
116
|
-
|
|
117
|
-
texCoords[i2 + 0] = j / nradial;
|
|
118
|
-
texCoords[i2 + 1] = v;
|
|
119
|
-
|
|
120
|
-
i2 += 2;
|
|
121
|
-
i3 += 3;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
for (let i = 0; i < nvertical + extra; i++) {
|
|
126
|
-
for (let j = 0; j < nradial; j++) {
|
|
127
|
-
const index = (i * nradial + j) * 6;
|
|
128
|
-
indices[index + 0] = vertsAroundEdge * (i + 0) + 0 + j;
|
|
129
|
-
indices[index + 1] = vertsAroundEdge * (i + 0) + 1 + j;
|
|
130
|
-
indices[index + 2] = vertsAroundEdge * (i + 1) + 1 + j;
|
|
131
|
-
indices[index + 3] = vertsAroundEdge * (i + 0) + 0 + j;
|
|
132
|
-
indices[index + 4] = vertsAroundEdge * (i + 1) + 1 + j;
|
|
133
|
-
indices[index + 5] = vertsAroundEdge * (i + 1) + 0 + j;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return {
|
|
138
|
-
indices,
|
|
139
|
-
attributes: {
|
|
140
|
-
POSITION: positions,
|
|
141
|
-
NORMAL: normals,
|
|
142
|
-
TEXCOORD_0: texCoords
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
}
|