@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cylinder-geometry.js","names":["uid","TruncatedConeGeometry","CylinderGeometry","constructor","props","arguments","length","undefined","id","radius","bottomRadius","topRadius"],"sources":["../../../src/geometries/cylinder-geometry.ts"],"sourcesContent":["import {uid} from '@luma.gl/api';\nimport {TruncatedConeGeometry} from './truncated-cone-geometry';\n\nexport type CylinderGeometryProps = {\n id?: string;\n radius?: number;\n attributes?: any;\n};\n\nexport class CylinderGeometry extends TruncatedConeGeometry {\n constructor(props: CylinderGeometryProps = {}) {\n const {id = uid('cylinder-geometry'), radius = 1} = props;\n super({\n ...props,\n id,\n bottomRadius: radius,\n topRadius: radius\n });\n }\n}\n"],"mappings":"AAAA,SAAQA,GAAG,QAAO,cAAc;AAChC,SAAQC,qBAAqB,QAAO,2BAA2B;AAQ/D,OAAO,MAAMC,gBAAgB,SAASD,qBAAqB,CAAC;EAC1DE,WAAWA,CAAA,EAAoC;IAAA,IAAnCC,KAA4B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAC3C,MAAM;MAACG,EAAE,GAAGR,GAAG,CAAC,mBAAmB,CAAC;MAAES,MAAM,GAAG;IAAC,CAAC,GAAGL,KAAK;IACzD,KAAK,CAAC;MACJ,GAAGA,KAAK;MACRI,EAAE;MACFE,YAAY,EAAED,MAAM;MACpBE,SAAS,EAAEF;IACb,CAAC,CAAC;EACJ;AACF"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { uid } from '@luma.gl/api';
|
|
2
|
+
import { Vector3 } from '@math.gl/core';
|
|
3
|
+
import Geometry from '../geometry/geometry';
|
|
4
|
+
const ICO_POSITIONS = [-1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 1, 0, -1, 0, 1, 0, 0];
|
|
5
|
+
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
|
+
export class IcoSphereGeometry extends Geometry {
|
|
7
|
+
constructor() {
|
|
8
|
+
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
9
|
+
const {
|
|
10
|
+
id = uid('ico-sphere-geometry')
|
|
11
|
+
} = props;
|
|
12
|
+
const {
|
|
13
|
+
indices,
|
|
14
|
+
attributes
|
|
15
|
+
} = tesselateIcosaHedron(props);
|
|
16
|
+
super({
|
|
17
|
+
...props,
|
|
18
|
+
id,
|
|
19
|
+
indices,
|
|
20
|
+
attributes: {
|
|
21
|
+
...attributes,
|
|
22
|
+
...props.attributes
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function tesselateIcosaHedron(props) {
|
|
28
|
+
const {
|
|
29
|
+
iterations = 0
|
|
30
|
+
} = props;
|
|
31
|
+
const PI = Math.PI;
|
|
32
|
+
const PI2 = PI * 2;
|
|
33
|
+
const positions = [...ICO_POSITIONS];
|
|
34
|
+
let indices = [...ICO_INDICES];
|
|
35
|
+
positions.push();
|
|
36
|
+
indices.push();
|
|
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
|
+
if (key in pointMemo) {
|
|
46
|
+
return pointMemo[key];
|
|
47
|
+
}
|
|
48
|
+
const x1 = positions[i1];
|
|
49
|
+
const y1 = positions[i1 + 1];
|
|
50
|
+
const z1 = positions[i1 + 2];
|
|
51
|
+
const x2 = positions[i2];
|
|
52
|
+
const y2 = positions[i2 + 1];
|
|
53
|
+
const z2 = positions[i2 + 2];
|
|
54
|
+
let xm = (x1 + x2) / 2;
|
|
55
|
+
let ym = (y1 + y2) / 2;
|
|
56
|
+
let zm = (z1 + z2) / 2;
|
|
57
|
+
const len = Math.sqrt(xm * xm + ym * ym + zm * zm);
|
|
58
|
+
xm /= len;
|
|
59
|
+
ym /= len;
|
|
60
|
+
zm /= len;
|
|
61
|
+
positions.push(xm, ym, zm);
|
|
62
|
+
return pointMemo[key] = positions.length / 3 - 1;
|
|
63
|
+
};
|
|
64
|
+
})();
|
|
65
|
+
for (let i = 0; i < iterations; i++) {
|
|
66
|
+
const indices2 = [];
|
|
67
|
+
for (let j = 0; j < indices.length; j += 3) {
|
|
68
|
+
const a = getMiddlePoint(indices[j + 0], indices[j + 1]);
|
|
69
|
+
const b = getMiddlePoint(indices[j + 1], indices[j + 2]);
|
|
70
|
+
const c = getMiddlePoint(indices[j + 2], indices[j + 0]);
|
|
71
|
+
indices2.push(c, indices[j + 0], a, a, indices[j + 1], b, b, indices[j + 2], c, a, b, c);
|
|
72
|
+
}
|
|
73
|
+
indices = indices2;
|
|
74
|
+
}
|
|
75
|
+
const normals = new Array(positions.length);
|
|
76
|
+
const texCoords = new Array(positions.length / 3 * 2);
|
|
77
|
+
const l = indices.length;
|
|
78
|
+
for (let i = l - 3; i >= 0; i -= 3) {
|
|
79
|
+
const i1 = indices[i + 0];
|
|
80
|
+
const i2 = indices[i + 1];
|
|
81
|
+
const i3 = indices[i + 2];
|
|
82
|
+
const in1 = i1 * 3;
|
|
83
|
+
const in2 = i2 * 3;
|
|
84
|
+
const in3 = i3 * 3;
|
|
85
|
+
const iu1 = i1 * 2;
|
|
86
|
+
const iu2 = i2 * 2;
|
|
87
|
+
const iu3 = i3 * 2;
|
|
88
|
+
const x1 = positions[in1 + 0];
|
|
89
|
+
const y1 = positions[in1 + 1];
|
|
90
|
+
const z1 = positions[in1 + 2];
|
|
91
|
+
const theta1 = Math.acos(z1 / Math.sqrt(x1 * x1 + y1 * y1 + z1 * z1));
|
|
92
|
+
const phi1 = Math.atan2(y1, x1) + PI;
|
|
93
|
+
const v1 = theta1 / PI;
|
|
94
|
+
const u1 = 1 - phi1 / PI2;
|
|
95
|
+
const x2 = positions[in2 + 0];
|
|
96
|
+
const y2 = positions[in2 + 1];
|
|
97
|
+
const z2 = positions[in2 + 2];
|
|
98
|
+
const theta2 = Math.acos(z2 / Math.sqrt(x2 * x2 + y2 * y2 + z2 * z2));
|
|
99
|
+
const phi2 = Math.atan2(y2, x2) + PI;
|
|
100
|
+
const v2 = theta2 / PI;
|
|
101
|
+
const u2 = 1 - phi2 / PI2;
|
|
102
|
+
const x3 = positions[in3 + 0];
|
|
103
|
+
const y3 = positions[in3 + 1];
|
|
104
|
+
const z3 = positions[in3 + 2];
|
|
105
|
+
const theta3 = Math.acos(z3 / Math.sqrt(x3 * x3 + y3 * y3 + z3 * z3));
|
|
106
|
+
const phi3 = Math.atan2(y3, x3) + PI;
|
|
107
|
+
const v3 = theta3 / PI;
|
|
108
|
+
const u3 = 1 - phi3 / PI2;
|
|
109
|
+
const vec1 = [x3 - x2, y3 - y2, z3 - z2];
|
|
110
|
+
const vec2 = [x1 - x2, y1 - y2, z1 - z2];
|
|
111
|
+
const normal = new Vector3(vec1).cross(vec2).normalize();
|
|
112
|
+
let newIndex;
|
|
113
|
+
if ((u1 === 0 || u2 === 0 || u3 === 0) && (u1 === 0 || u1 > 0.5) && (u2 === 0 || u2 > 0.5) && (u3 === 0 || u3 > 0.5)) {
|
|
114
|
+
positions.push(positions[in1 + 0], positions[in1 + 1], positions[in1 + 2]);
|
|
115
|
+
newIndex = positions.length / 3 - 1;
|
|
116
|
+
indices.push(newIndex);
|
|
117
|
+
texCoords[newIndex * 2 + 0] = 1;
|
|
118
|
+
texCoords[newIndex * 2 + 1] = v1;
|
|
119
|
+
normals[newIndex * 3 + 0] = normal.x;
|
|
120
|
+
normals[newIndex * 3 + 1] = normal.y;
|
|
121
|
+
normals[newIndex * 3 + 2] = normal.z;
|
|
122
|
+
positions.push(positions[in2 + 0], positions[in2 + 1], positions[in2 + 2]);
|
|
123
|
+
newIndex = positions.length / 3 - 1;
|
|
124
|
+
indices.push(newIndex);
|
|
125
|
+
texCoords[newIndex * 2 + 0] = 1;
|
|
126
|
+
texCoords[newIndex * 2 + 1] = v2;
|
|
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[in3 + 0], positions[in3 + 1], positions[in3 + 2]);
|
|
131
|
+
newIndex = positions.length / 3 - 1;
|
|
132
|
+
indices.push(newIndex);
|
|
133
|
+
texCoords[newIndex * 2 + 0] = 1;
|
|
134
|
+
texCoords[newIndex * 2 + 1] = v3;
|
|
135
|
+
normals[newIndex * 3 + 0] = normal.x;
|
|
136
|
+
normals[newIndex * 3 + 1] = normal.y;
|
|
137
|
+
normals[newIndex * 3 + 2] = normal.z;
|
|
138
|
+
}
|
|
139
|
+
normals[in1 + 0] = normals[in2 + 0] = normals[in3 + 0] = normal.x;
|
|
140
|
+
normals[in1 + 1] = normals[in2 + 1] = normals[in3 + 1] = normal.y;
|
|
141
|
+
normals[in1 + 2] = normals[in2 + 2] = normals[in3 + 2] = normal.z;
|
|
142
|
+
texCoords[iu1 + 0] = u1;
|
|
143
|
+
texCoords[iu1 + 1] = v1;
|
|
144
|
+
texCoords[iu2 + 0] = u2;
|
|
145
|
+
texCoords[iu2 + 1] = v2;
|
|
146
|
+
texCoords[iu3 + 0] = u3;
|
|
147
|
+
texCoords[iu3 + 1] = v3;
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
indices: {
|
|
151
|
+
size: 1,
|
|
152
|
+
value: new Uint16Array(indices)
|
|
153
|
+
},
|
|
154
|
+
attributes: {
|
|
155
|
+
POSITION: {
|
|
156
|
+
size: 3,
|
|
157
|
+
value: new Float32Array(positions)
|
|
158
|
+
},
|
|
159
|
+
NORMAL: {
|
|
160
|
+
size: 3,
|
|
161
|
+
value: new Float32Array(normals)
|
|
162
|
+
},
|
|
163
|
+
TEXCOORD_0: {
|
|
164
|
+
size: 2,
|
|
165
|
+
value: new Float32Array(texCoords)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=ico-sphere-geometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ico-sphere-geometry.js","names":["uid","Vector3","Geometry","ICO_POSITIONS","ICO_INDICES","IcoSphereGeometry","constructor","props","arguments","length","undefined","id","indices","attributes","tesselateIcosaHedron","iterations","PI","Math","PI2","positions","push","getMiddlePoint","pointMemo","i1","i2","mini","maxi","key","concat","x1","y1","z1","x2","y2","z2","xm","ym","zm","len","sqrt","i","indices2","j","a","b","c","normals","Array","texCoords","l","i3","in1","in2","in3","iu1","iu2","iu3","theta1","acos","phi1","atan2","v1","u1","theta2","phi2","v2","u2","x3","y3","z3","theta3","phi3","v3","u3","vec1","vec2","normal","cross","normalize","newIndex","x","y","z","size","value","Uint16Array","POSITION","Float32Array","NORMAL","TEXCOORD_0"],"sources":["../../../src/geometries/ico-sphere-geometry.ts"],"sourcesContent":["import {uid} from '@luma.gl/api';\nimport {Vector3} from '@math.gl/core';\nimport Geometry from '../geometry/geometry';\n\n/* eslint-disable comma-spacing, max-statements, complexity */\n\nconst ICO_POSITIONS = [-1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 1, 0, -1, 0, 1, 0, 0];\nconst 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];\n\nexport type IcoSphereGeometryProps = {\n id?: string;\n radius?: number;\n iterations?: number;\n attributes?: any\n};\n\nexport class IcoSphereGeometry extends Geometry {\n constructor(props: IcoSphereGeometryProps = {}) {\n const {id = uid('ico-sphere-geometry')} = props;\n const {indices, attributes} = tesselateIcosaHedron(props);\n super({\n ...props,\n id,\n indices,\n attributes: {...attributes, ...props.attributes}\n });\n }\n}\n\nfunction tesselateIcosaHedron(props: IcoSphereGeometryProps) {\n const {iterations = 0} = props;\n\n const PI = Math.PI;\n const PI2 = PI * 2;\n\n const positions = [...ICO_POSITIONS];\n let indices = [...ICO_INDICES];\n\n positions.push();\n indices.push();\n\n const getMiddlePoint = (() => {\n const pointMemo: Record<string, number> = {};\n\n return (i1: number, i2: number) => {\n i1 *= 3;\n i2 *= 3;\n const mini = i1 < i2 ? i1 : i2;\n const maxi = i1 > i2 ? i1 : i2;\n const key = `${mini}|${maxi}`;\n\n if (key in pointMemo) {\n return pointMemo[key];\n }\n\n const x1 = positions[i1];\n const y1 = positions[i1 + 1];\n const z1 = positions[i1 + 2];\n const x2 = positions[i2];\n const y2 = positions[i2 + 1];\n const z2 = positions[i2 + 2];\n let xm = (x1 + x2) / 2;\n let ym = (y1 + y2) / 2;\n let zm = (z1 + z2) / 2;\n const len = Math.sqrt(xm * xm + ym * ym + zm * zm);\n\n xm /= len;\n ym /= len;\n zm /= len;\n\n positions.push(xm, ym, zm);\n\n return (pointMemo[key] = positions.length / 3 - 1);\n };\n })();\n\n for (let i = 0; i < iterations; i++) {\n const indices2: number[] = [];\n for (let j = 0; j < indices.length; j += 3) {\n const a = getMiddlePoint(indices[j + 0], indices[j + 1]);\n const b = getMiddlePoint(indices[j + 1], indices[j + 2]);\n const c = getMiddlePoint(indices[j + 2], indices[j + 0]);\n\n indices2.push(c, indices[j + 0], a, a, indices[j + 1], b, b, indices[j + 2], c, a, b, c);\n }\n indices = indices2;\n }\n\n // Calculate texCoords and normals\n const normals = new Array(positions.length);\n const texCoords = new Array((positions.length / 3) * 2);\n\n const l = indices.length;\n for (let i = l - 3; i >= 0; i -= 3) {\n const i1 = indices[i + 0];\n const i2 = indices[i + 1];\n const i3 = indices[i + 2];\n const in1 = i1 * 3;\n const in2 = i2 * 3;\n const in3 = i3 * 3;\n const iu1 = i1 * 2;\n const iu2 = i2 * 2;\n const iu3 = i3 * 2;\n const x1 = positions[in1 + 0];\n const y1 = positions[in1 + 1];\n const z1 = positions[in1 + 2];\n const theta1 = Math.acos(z1 / Math.sqrt(x1 * x1 + y1 * y1 + z1 * z1));\n const phi1 = Math.atan2(y1, x1) + PI;\n const v1 = theta1 / PI;\n const u1 = 1 - phi1 / PI2;\n const x2 = positions[in2 + 0];\n const y2 = positions[in2 + 1];\n const z2 = positions[in2 + 2];\n const theta2 = Math.acos(z2 / Math.sqrt(x2 * x2 + y2 * y2 + z2 * z2));\n const phi2 = Math.atan2(y2, x2) + PI;\n const v2 = theta2 / PI;\n const u2 = 1 - phi2 / PI2;\n const x3 = positions[in3 + 0];\n const y3 = positions[in3 + 1];\n const z3 = positions[in3 + 2];\n const theta3 = Math.acos(z3 / Math.sqrt(x3 * x3 + y3 * y3 + z3 * z3));\n const phi3 = Math.atan2(y3, x3) + PI;\n const v3 = theta3 / PI;\n const u3 = 1 - phi3 / PI2;\n const vec1 = [x3 - x2, y3 - y2, z3 - z2];\n const vec2 = [x1 - x2, y1 - y2, z1 - z2];\n const normal = new Vector3(vec1).cross(vec2).normalize();\n let newIndex;\n\n if (\n (u1 === 0 || u2 === 0 || u3 === 0) &&\n (u1 === 0 || u1 > 0.5) &&\n (u2 === 0 || u2 > 0.5) &&\n (u3 === 0 || u3 > 0.5)\n ) {\n positions.push(positions[in1 + 0], positions[in1 + 1], positions[in1 + 2]);\n newIndex = positions.length / 3 - 1;\n indices.push(newIndex);\n texCoords[newIndex * 2 + 0] = 1;\n texCoords[newIndex * 2 + 1] = v1;\n normals[newIndex * 3 + 0] = normal.x;\n normals[newIndex * 3 + 1] = normal.y;\n normals[newIndex * 3 + 2] = normal.z;\n\n positions.push(positions[in2 + 0], positions[in2 + 1], positions[in2 + 2]);\n newIndex = positions.length / 3 - 1;\n indices.push(newIndex);\n texCoords[newIndex * 2 + 0] = 1;\n texCoords[newIndex * 2 + 1] = v2;\n normals[newIndex * 3 + 0] = normal.x;\n normals[newIndex * 3 + 1] = normal.y;\n normals[newIndex * 3 + 2] = normal.z;\n\n positions.push(positions[in3 + 0], positions[in3 + 1], positions[in3 + 2]);\n newIndex = positions.length / 3 - 1;\n indices.push(newIndex);\n texCoords[newIndex * 2 + 0] = 1;\n texCoords[newIndex * 2 + 1] = v3;\n normals[newIndex * 3 + 0] = normal.x;\n normals[newIndex * 3 + 1] = normal.y;\n normals[newIndex * 3 + 2] = normal.z;\n }\n\n normals[in1 + 0] = normals[in2 + 0] = normals[in3 + 0] = normal.x;\n normals[in1 + 1] = normals[in2 + 1] = normals[in3 + 1] = normal.y;\n normals[in1 + 2] = normals[in2 + 2] = normals[in3 + 2] = normal.z;\n\n texCoords[iu1 + 0] = u1;\n texCoords[iu1 + 1] = v1;\n\n texCoords[iu2 + 0] = u2;\n texCoords[iu2 + 1] = v2;\n\n texCoords[iu3 + 0] = u3;\n texCoords[iu3 + 1] = v3;\n }\n\n return {\n indices: {size: 1, value: new Uint16Array(indices)},\n attributes: {\n POSITION: {size: 3, value: new Float32Array(positions)},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GAAGW,EAAE;IACvBlB,SAAS,CAACO,GAAG,GAAG,CAAC,CAAC,GAAGU,EAAE;IAEvBjB,SAAS,CAACQ,GAAG,GAAG,CAAC,CAAC,GAAGiB,EAAE;IACvBzB,SAAS,CAACQ,GAAG,GAAG,CAAC,CAAC,GAAGgB,EAAE;EACzB;EAEA,OAAO;IACL5D,OAAO,EAAE;MAACuE,IAAI,EAAE,CAAC;MAAEC,KAAK,EAAE,IAAIC,WAAW,CAACzE,OAAO;IAAC,CAAC;IACnDC,UAAU,EAAE;MACVyE,QAAQ,EAAE;QAACH,IAAI,EAAE,CAAC;QAAEC,KAAK,EAAE,IAAIG,YAAY,CAACpE,SAAS;MAAC,CAAC;MACvDqE,MAAM,EAAE;QAACL,IAAI,EAAE,CAAC;QAAEC,KAAK,EAAE,IAAIG,YAAY,CAACzC,OAAO;MAAC,CAAC;MACnD2C,UAAU,EAAE;QAACN,IAAI,EAAE,CAAC;QAAEC,KAAK,EAAE,IAAIG,YAAY,CAACvC,SAAS;MAAC;IAC1D;EACF,CAAC;AACH"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { uid } from '@luma.gl/api';
|
|
2
|
+
import Geometry from '../geometry/geometry';
|
|
3
|
+
import { unpackIndexedGeometry } from '../geometry/geometry-utils';
|
|
4
|
+
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
|
+
indices,
|
|
18
|
+
attributes: {
|
|
19
|
+
...attributes,
|
|
20
|
+
...props.attributes
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function tesselatePlane(props) {
|
|
26
|
+
const {
|
|
27
|
+
type = 'x,y',
|
|
28
|
+
offset = 0,
|
|
29
|
+
flipCull = false,
|
|
30
|
+
unpack = false
|
|
31
|
+
} = props;
|
|
32
|
+
const coords = type.split(',');
|
|
33
|
+
let c1len = props["".concat(coords[0], "len")] || 1;
|
|
34
|
+
const c2len = props["".concat(coords[1], "len")] || 1;
|
|
35
|
+
const subdivisions1 = props["n".concat(coords[0])] || 1;
|
|
36
|
+
const subdivisions2 = props["n".concat(coords[1])] || 1;
|
|
37
|
+
const numVertices = (subdivisions1 + 1) * (subdivisions2 + 1);
|
|
38
|
+
const positions = new Float32Array(numVertices * 3);
|
|
39
|
+
const normals = new Float32Array(numVertices * 3);
|
|
40
|
+
const texCoords = new Float32Array(numVertices * 2);
|
|
41
|
+
if (flipCull) {
|
|
42
|
+
c1len = -c1len;
|
|
43
|
+
}
|
|
44
|
+
let i2 = 0;
|
|
45
|
+
let i3 = 0;
|
|
46
|
+
for (let z = 0; z <= subdivisions2; z++) {
|
|
47
|
+
for (let x = 0; x <= subdivisions1; x++) {
|
|
48
|
+
const u = x / subdivisions1;
|
|
49
|
+
const v = z / subdivisions2;
|
|
50
|
+
texCoords[i2 + 0] = flipCull ? 1 - u : u;
|
|
51
|
+
texCoords[i2 + 1] = v;
|
|
52
|
+
switch (type) {
|
|
53
|
+
case 'x,y':
|
|
54
|
+
positions[i3 + 0] = c1len * u - c1len * 0.5;
|
|
55
|
+
positions[i3 + 1] = c2len * v - c2len * 0.5;
|
|
56
|
+
positions[i3 + 2] = offset;
|
|
57
|
+
normals[i3 + 0] = 0;
|
|
58
|
+
normals[i3 + 1] = 0;
|
|
59
|
+
normals[i3 + 2] = flipCull ? 1 : -1;
|
|
60
|
+
break;
|
|
61
|
+
case 'x,z':
|
|
62
|
+
positions[i3 + 0] = c1len * u - c1len * 0.5;
|
|
63
|
+
positions[i3 + 1] = offset;
|
|
64
|
+
positions[i3 + 2] = c2len * v - c2len * 0.5;
|
|
65
|
+
normals[i3 + 0] = 0;
|
|
66
|
+
normals[i3 + 1] = flipCull ? 1 : -1;
|
|
67
|
+
normals[i3 + 2] = 0;
|
|
68
|
+
break;
|
|
69
|
+
case 'y,z':
|
|
70
|
+
positions[i3 + 0] = offset;
|
|
71
|
+
positions[i3 + 1] = c1len * u - c1len * 0.5;
|
|
72
|
+
positions[i3 + 2] = c2len * v - c2len * 0.5;
|
|
73
|
+
normals[i3 + 0] = flipCull ? 1 : -1;
|
|
74
|
+
normals[i3 + 1] = 0;
|
|
75
|
+
normals[i3 + 2] = 0;
|
|
76
|
+
break;
|
|
77
|
+
default:
|
|
78
|
+
throw new Error('PlaneGeometry: unknown type');
|
|
79
|
+
}
|
|
80
|
+
i2 += 2;
|
|
81
|
+
i3 += 3;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const numVertsAcross = subdivisions1 + 1;
|
|
85
|
+
const indices = new Uint16Array(subdivisions1 * subdivisions2 * 6);
|
|
86
|
+
for (let z = 0; z < subdivisions2; z++) {
|
|
87
|
+
for (let x = 0; x < subdivisions1; x++) {
|
|
88
|
+
const index = (z * subdivisions1 + x) * 6;
|
|
89
|
+
indices[index + 0] = (z + 0) * numVertsAcross + x;
|
|
90
|
+
indices[index + 1] = (z + 1) * numVertsAcross + x;
|
|
91
|
+
indices[index + 2] = (z + 0) * numVertsAcross + x + 1;
|
|
92
|
+
indices[index + 3] = (z + 1) * numVertsAcross + x;
|
|
93
|
+
indices[index + 4] = (z + 1) * numVertsAcross + x + 1;
|
|
94
|
+
indices[index + 5] = (z + 0) * numVertsAcross + x + 1;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const geometry = {
|
|
98
|
+
indices: {
|
|
99
|
+
size: 1,
|
|
100
|
+
value: indices
|
|
101
|
+
},
|
|
102
|
+
attributes: {
|
|
103
|
+
POSITION: {
|
|
104
|
+
size: 3,
|
|
105
|
+
value: positions
|
|
106
|
+
},
|
|
107
|
+
NORMAL: {
|
|
108
|
+
size: 3,
|
|
109
|
+
value: normals
|
|
110
|
+
},
|
|
111
|
+
TEXCOORD_0: {
|
|
112
|
+
size: 2,
|
|
113
|
+
value: texCoords
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
return unpack ? unpackIndexedGeometry(geometry) : geometry;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=plane-geometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plane-geometry.js","names":["uid","Geometry","unpackIndexedGeometry","PlaneGeometry","constructor","props","arguments","length","undefined","id","indices","attributes","tesselatePlane","type","offset","flipCull","unpack","coords","split","c1len","concat","c2len","subdivisions1","subdivisions2","numVertices","positions","Float32Array","normals","texCoords","i2","i3","z","x","u","v","Error","numVertsAcross","Uint16Array","index","geometry","size","value","POSITION","NORMAL","TEXCOORD_0"],"sources":["../../../src/geometries/plane-geometry.ts"],"sourcesContent":["import {uid} from '@luma.gl/api';\nimport Geometry from '../geometry/geometry';\nimport {unpackIndexedGeometry} from '../geometry/geometry-utils';\n\nexport type PlaneGeometryProps = {\n id?: string;\n radius?: number;\n attributes?: any\n};\n\n// Primitives inspired by TDL http://code.google.com/p/webglsamples/,\n// copyright 2011 Google Inc. new BSD License\n// (http://www.opensource.org/licenses/bsd-license.php).\nexport class PlaneGeometry extends Geometry {\n constructor(props: PlaneGeometryProps = {}) {\n const {id = uid('plane-geometry')} = props;\n\n const {indices, attributes} = tesselatePlane(props);\n super({\n ...props,\n id,\n indices,\n attributes: {...attributes, ...props.attributes}\n });\n }\n}\n\n/* eslint-disable complexity, max-statements */\nfunction tesselatePlane(props: any) {\n const {type = 'x,y', offset = 0, flipCull = false, unpack = false} = props;\n\n const coords = type.split(',');\n // width, height\n let c1len = props[`${coords[0]}len`] || 1;\n const c2len = props[`${coords[1]}len`] || 1;\n // subdivisionsWidth, subdivisionsDepth\n const subdivisions1 = props[`n${coords[0]}`] || 1;\n const subdivisions2 = props[`n${coords[1]}`] || 1;\n const numVertices = (subdivisions1 + 1) * (subdivisions2 + 1);\n\n const positions = new Float32Array(numVertices * 3);\n const normals = new Float32Array(numVertices * 3);\n const texCoords = new Float32Array(numVertices * 2);\n\n if (flipCull) {\n c1len = -c1len;\n }\n\n let i2 = 0;\n let i3 = 0;\n for (let z = 0; z <= subdivisions2; z++) {\n for (let x = 0; x <= subdivisions1; x++) {\n const u = x / subdivisions1;\n const v = z / subdivisions2;\n texCoords[i2 + 0] = flipCull ? 1 - u : u;\n texCoords[i2 + 1] = v;\n\n switch (type) {\n case 'x,y':\n positions[i3 + 0] = c1len * u - c1len * 0.5;\n positions[i3 + 1] = c2len * v - c2len * 0.5;\n positions[i3 + 2] = offset;\n\n normals[i3 + 0] = 0;\n normals[i3 + 1] = 0;\n normals[i3 + 2] = flipCull ? 1 : -1;\n break;\n\n case 'x,z':\n positions[i3 + 0] = c1len * u - c1len * 0.5;\n positions[i3 + 1] = offset;\n positions[i3 + 2] = c2len * v - c2len * 0.5;\n\n normals[i3 + 0] = 0;\n normals[i3 + 1] = flipCull ? 1 : -1;\n normals[i3 + 2] = 0;\n break;\n\n case 'y,z':\n positions[i3 + 0] = offset;\n positions[i3 + 1] = c1len * u - c1len * 0.5;\n positions[i3 + 2] = c2len * v - c2len * 0.5;\n\n normals[i3 + 0] = flipCull ? 1 : -1;\n normals[i3 + 1] = 0;\n normals[i3 + 2] = 0;\n break;\n\n default:\n throw new Error('PlaneGeometry: unknown type');\n }\n\n i2 += 2;\n i3 += 3;\n }\n }\n\n const numVertsAcross = subdivisions1 + 1;\n const indices = new Uint16Array(subdivisions1 * subdivisions2 * 6);\n\n for (let z = 0; z < subdivisions2; z++) {\n for (let x = 0; x < subdivisions1; x++) {\n const index = (z * subdivisions1 + x) * 6;\n // Make triangle 1 of quad.\n indices[index + 0] = (z + 0) * numVertsAcross + x;\n indices[index + 1] = (z + 1) * numVertsAcross + x;\n indices[index + 2] = (z + 0) * numVertsAcross + x + 1;\n\n // Make triangle 2 of quad.\n indices[index + 3] = (z + 1) * numVertsAcross + x;\n indices[index + 4] = (z + 1) * numVertsAcross + x + 1;\n indices[index + 5] = (z + 0) * numVertsAcross + x + 1;\n }\n }\n\n const geometry = {\n indices: {size: 1, value: indices},\n attributes: {\n POSITION: {size: 3, value: positions},\n NORMAL: {size: 3, value: normals},\n TEXCOORD_0: {size: 2, value: texCoords}\n }\n };\n\n // Optionally, unpack indexed geometry\n return unpack ? unpackIndexedGeometry(geometry) : geometry;\n}\n"],"mappings":"AAAA,SAAQA,GAAG,QAAO,cAAc;AAChC,OAAOC,QAAQ,MAAM,sBAAsB;AAC3C,SAAQC,qBAAqB,QAAO,4BAA4B;AAWhE,OAAO,MAAMC,aAAa,SAASF,QAAQ,CAAC;EAC1CG,WAAWA,CAAA,EAAiC;IAAA,IAAhCC,KAAyB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IACxC,MAAM;MAACG,EAAE,GAAGT,GAAG,CAAC,gBAAgB;IAAC,CAAC,GAAGK,KAAK;IAE1C,MAAM;MAACK,OAAO;MAAEC;IAAU,CAAC,GAAGC,cAAc,CAACP,KAAK,CAAC;IACnD,KAAK,CAAC;MACJ,GAAGA,KAAK;MACRI,EAAE;MACFC,OAAO;MACPC,UAAU,EAAE;QAAC,GAAGA,UAAU;QAAE,GAAGN,KAAK,CAACM;MAAU;IACjD,CAAC,CAAC;EACJ;AACF;AAGA,SAASC,cAAcA,CAACP,KAAU,EAAE;EAClC,MAAM;IAACQ,IAAI,GAAG,KAAK;IAAEC,MAAM,GAAG,CAAC;IAAEC,QAAQ,GAAG,KAAK;IAAEC,MAAM,GAAG;EAAK,CAAC,GAAGX,KAAK;EAE1E,MAAMY,MAAM,GAAGJ,IAAI,CAACK,KAAK,CAAC,GAAG,CAAC;EAE9B,IAAIC,KAAK,GAAGd,KAAK,IAAAe,MAAA,CAAIH,MAAM,CAAC,CAAC,C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P,CAAC,GAAG,CAAC,IAAIK,cAAc,GAAGJ,CAAC,GAAG,CAAC;IACvD;EACF;EAEA,MAAMO,QAAQ,GAAG;IACf7B,OAAO,EAAE;MAAC8B,IAAI,EAAE,CAAC;MAAEC,KAAK,EAAE/B;IAAO,CAAC;IAClCC,UAAU,EAAE;MACV+B,QAAQ,EAAE;QAACF,IAAI,EAAE,CAAC;QAAEC,KAAK,EAAEhB;MAAS,CAAC;MACrCkB,MAAM,EAAE;QAACH,IAAI,EAAE,CAAC;QAAEC,KAAK,EAAEd;MAAO,CAAC;MACjCiB,UAAU,EAAE;QAACJ,IAAI,EAAE,CAAC;QAAEC,KAAK,EAAEb;MAAS;IACxC;EACF,CAAC;EAGD,OAAOZ,MAAM,GAAGd,qBAAqB,CAACqC,QAAQ,CAAC,GAAGA,QAAQ;AAC5D"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { uid } from '@luma.gl/api';
|
|
2
|
+
import Geometry from '../geometry/geometry';
|
|
3
|
+
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
|
+
indices,
|
|
17
|
+
attributes: {
|
|
18
|
+
...attributes,
|
|
19
|
+
...props.attributes
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function tesselateSphere(props) {
|
|
25
|
+
const {
|
|
26
|
+
nlat = 10,
|
|
27
|
+
nlong = 10
|
|
28
|
+
} = props;
|
|
29
|
+
const startLat = 0;
|
|
30
|
+
const endLat = Math.PI;
|
|
31
|
+
const latRange = endLat - startLat;
|
|
32
|
+
const startLong = 0;
|
|
33
|
+
const endLong = 2 * Math.PI;
|
|
34
|
+
const longRange = endLong - startLong;
|
|
35
|
+
const numVertices = (nlat + 1) * (nlong + 1);
|
|
36
|
+
const radius = (n1, n2, n3, u, v) => props.radius || 1;
|
|
37
|
+
const positions = new Float32Array(numVertices * 3);
|
|
38
|
+
const normals = new Float32Array(numVertices * 3);
|
|
39
|
+
const texCoords = new Float32Array(numVertices * 2);
|
|
40
|
+
const IndexType = numVertices > 0xffff ? Uint32Array : Uint16Array;
|
|
41
|
+
const indices = new IndexType(nlat * nlong * 6);
|
|
42
|
+
for (let y = 0; y <= nlat; y++) {
|
|
43
|
+
for (let x = 0; x <= nlong; x++) {
|
|
44
|
+
const u = x / nlong;
|
|
45
|
+
const v = y / nlat;
|
|
46
|
+
const index = x + y * (nlong + 1);
|
|
47
|
+
const i2 = index * 2;
|
|
48
|
+
const i3 = index * 3;
|
|
49
|
+
const theta = longRange * u;
|
|
50
|
+
const phi = latRange * v;
|
|
51
|
+
const sinTheta = Math.sin(theta);
|
|
52
|
+
const cosTheta = Math.cos(theta);
|
|
53
|
+
const sinPhi = Math.sin(phi);
|
|
54
|
+
const cosPhi = Math.cos(phi);
|
|
55
|
+
const ux = cosTheta * sinPhi;
|
|
56
|
+
const uy = cosPhi;
|
|
57
|
+
const uz = sinTheta * sinPhi;
|
|
58
|
+
const r = radius(ux, uy, uz, u, v);
|
|
59
|
+
positions[i3 + 0] = r * ux;
|
|
60
|
+
positions[i3 + 1] = r * uy;
|
|
61
|
+
positions[i3 + 2] = r * uz;
|
|
62
|
+
normals[i3 + 0] = ux;
|
|
63
|
+
normals[i3 + 1] = uy;
|
|
64
|
+
normals[i3 + 2] = uz;
|
|
65
|
+
texCoords[i2 + 0] = u;
|
|
66
|
+
texCoords[i2 + 1] = 1 - v;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const numVertsAround = nlong + 1;
|
|
70
|
+
for (let x = 0; x < nlong; x++) {
|
|
71
|
+
for (let y = 0; y < nlat; y++) {
|
|
72
|
+
const index = (x * nlat + y) * 6;
|
|
73
|
+
indices[index + 0] = y * numVertsAround + x;
|
|
74
|
+
indices[index + 1] = y * numVertsAround + x + 1;
|
|
75
|
+
indices[index + 2] = (y + 1) * numVertsAround + x;
|
|
76
|
+
indices[index + 3] = (y + 1) * numVertsAround + x;
|
|
77
|
+
indices[index + 4] = y * numVertsAround + x + 1;
|
|
78
|
+
indices[index + 5] = (y + 1) * numVertsAround + x + 1;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
indices: {
|
|
83
|
+
size: 1,
|
|
84
|
+
value: indices
|
|
85
|
+
},
|
|
86
|
+
attributes: {
|
|
87
|
+
POSITION: {
|
|
88
|
+
size: 3,
|
|
89
|
+
value: positions
|
|
90
|
+
},
|
|
91
|
+
NORMAL: {
|
|
92
|
+
size: 3,
|
|
93
|
+
value: normals
|
|
94
|
+
},
|
|
95
|
+
TEXCOORD_0: {
|
|
96
|
+
size: 2,
|
|
97
|
+
value: texCoords
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=sphere-geometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sphere-geometry.js","names":["uid","Geometry","SphereGeometry","constructor","props","arguments","length","undefined","id","indices","attributes","tesselateSphere","nlat","nlong","startLat","endLat","Math","PI","latRange","startLong","endLong","longRange","numVertices","radius","n1","n2","n3","u","v","positions","Float32Array","normals","texCoords","IndexType","Uint32Array","Uint16Array","y","x","index","i2","i3","theta","phi","sinTheta","sin","cosTheta","cos","sinPhi","cosPhi","ux","uy","uz","r","numVertsAround","size","value","POSITION","NORMAL","TEXCOORD_0"],"sources":["../../../src/geometries/sphere-geometry.ts"],"sourcesContent":["import {uid} from '@luma.gl/api';\nimport Geometry from '../geometry/geometry';\n\nexport type SphereGeometryProps = {\n id?: string;\n radius?: number;\n nlat?: number;\n nlong?: number;\n attributes?: any\n};\n\n// Primitives inspired by TDL http://code.google.com/p/webglsamples/,\n// copyright 2011 Google Inc. new BSD License\n// (http://www.opensource.org/licenses/bsd-license.php).\nexport class SphereGeometry extends Geometry {\n constructor(props: SphereGeometryProps = {}) {\n const {id = uid('sphere-geometry')} = props;\n const {indices, attributes} = tesselateSphere(props);\n super({\n ...props,\n id,\n indices,\n attributes: {...attributes, ...props.attributes}\n });\n }\n}\n\n/* eslint-disable max-statements, complexity */\nfunction tesselateSphere(props: SphereGeometryProps) {\n const {nlat = 10, nlong = 10} = props;\n\n const startLat = 0;\n const endLat = Math.PI;\n const latRange = endLat - startLat;\n const startLong = 0;\n const endLong = 2 * Math.PI;\n const longRange = endLong - startLong;\n const numVertices = (nlat + 1) * (nlong + 1);\n\n const radius = (n1: number, n2: number, n3: number, u: number, v: number) => props.radius || 1;\n\n const positions = new Float32Array(numVertices * 3);\n const normals = new Float32Array(numVertices * 3);\n const texCoords = new Float32Array(numVertices * 2);\n\n const IndexType = numVertices > 0xffff ? Uint32Array : Uint16Array;\n const indices = new IndexType(nlat * nlong * 6);\n\n // Create positions, normals and texCoords\n for (let y = 0; y <= nlat; y++) {\n for (let x = 0; x <= nlong; x++) {\n const u = x / nlong;\n const v = y / nlat;\n\n const index = x + y * (nlong + 1);\n const i2 = index * 2;\n const i3 = index * 3;\n\n const theta = longRange * u;\n const phi = latRange * v;\n const sinTheta = Math.sin(theta);\n const cosTheta = Math.cos(theta);\n const sinPhi = Math.sin(phi);\n const cosPhi = Math.cos(phi);\n const ux = cosTheta * sinPhi;\n const uy = cosPhi;\n const uz = sinTheta * sinPhi;\n\n const r = radius(ux, uy, uz, u, v);\n\n positions[i3 + 0] = r * ux;\n positions[i3 + 1] = r * uy;\n positions[i3 + 2] = r * uz;\n\n normals[i3 + 0] = ux;\n normals[i3 + 1] = uy;\n normals[i3 + 2] = uz;\n\n texCoords[i2 + 0] = u;\n texCoords[i2 + 1] = 1 - v;\n }\n }\n\n // Create indices\n const numVertsAround = nlong + 1;\n for (let x = 0; x < nlong; x++) {\n for (let y = 0; y < nlat; y++) {\n const index = (x * nlat + y) * 6;\n\n indices[index + 0] = y * numVertsAround + x;\n indices[index + 1] = y * numVertsAround + x + 1;\n indices[index + 2] = (y + 1) * numVertsAround + x;\n\n indices[index + 3] = (y + 1) * numVertsAround + x;\n indices[index + 4] = y * numVertsAround + x + 1;\n indices[index + 5] = (y + 1) * numVertsAround + x + 1;\n }\n }\n\n return {\n indices: {size: 1, value: indices},\n attributes: {\n POSITION: {size: 3, value: positions},\n NORMAL: {size: 3, value: normals},\n TEXCOORD_0: {size: 2, value: texCoords}\n }\n };\n}\n"],"mappings":"AAAA,SAAQA,GAAG,QAAO,cAAc;AAChC,OAAOC,QAAQ,MAAM,sBAAsB;AAa3C,OAAO,MAAMC,cAAc,SAASD,QAAQ,CAAC;EAC3CE,WAAWA,CAAA,EAAkC;IAAA,IAAjCC,KAA0B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IACzC,MAAM;MAACG,EAAE,GAAGR,GAAG,CAAC,iBAAiB;IAAC,CAAC,GAAGI,KAAK;IAC3C,MAAM;MAACK,OAAO;MAAEC;IAAU,CAAC,GAAGC,eAAe,CAACP,KAAK,CAAC;IACpD,KAAK,CAAC;MACJ,GAAGA,KAAK;MACRI,EAAE;MACFC,OAAO;MACPC,UAAU,EAAE;QAAC,GAAGA,UAAU;QAAE,GAAGN,KAAK,CAACM;MAAU;IACjD,CAAC,CAAC;EACJ;AACF;AAGA,SAASC,eAAeA,CAACP,KAA0B,EAAE;EACnD,MAAM;IAACQ,IAAI,GAAG,EAAE;IAAEC,KAAK,GAAG;EAAE,CAAC,GAAGT,KAAK;EAErC,MAAMU,QAAQ,GAAG,CAAC;EAClB,MAAMC,MAAM,GAAGC,IAAI,CAACC,EAAE;EACtB,MAAMC,QAAQ,GAAGH,MAAM,GAAGD,QAAQ;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ry';
|
|
3
|
+
const INDEX_OFFSETS = {
|
|
4
|
+
x: [2, 0, 1],
|
|
5
|
+
y: [0, 1, 2],
|
|
6
|
+
z: [1, 2, 0]
|
|
7
|
+
};
|
|
8
|
+
export function makeTruncatedConeGeometry(props) {
|
|
9
|
+
const {
|
|
10
|
+
indices,
|
|
11
|
+
attributes
|
|
12
|
+
} = tesselateTruncatedCone(props);
|
|
13
|
+
return {
|
|
14
|
+
length: indices.length,
|
|
15
|
+
indices,
|
|
16
|
+
attributes
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export class TruncatedConeGeometry extends Geometry {
|
|
20
|
+
constructor() {
|
|
21
|
+
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
22
|
+
const {
|
|
23
|
+
id = uid('truncated-code-geometry')
|
|
24
|
+
} = props;
|
|
25
|
+
const {
|
|
26
|
+
indices,
|
|
27
|
+
attributes
|
|
28
|
+
} = tesselateTruncatedCone(props);
|
|
29
|
+
super({
|
|
30
|
+
...props,
|
|
31
|
+
id,
|
|
32
|
+
indices,
|
|
33
|
+
attributes: {
|
|
34
|
+
POSITION: {
|
|
35
|
+
size: 3,
|
|
36
|
+
value: attributes.POSITION
|
|
37
|
+
},
|
|
38
|
+
NORMAL: {
|
|
39
|
+
size: 3,
|
|
40
|
+
value: attributes.NORMAL
|
|
41
|
+
},
|
|
42
|
+
TEXCOORD_0: {
|
|
43
|
+
size: 2,
|
|
44
|
+
value: attributes.TEXCOORD_0
|
|
45
|
+
},
|
|
46
|
+
...props.attributes
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function tesselateTruncatedCone() {
|
|
52
|
+
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
53
|
+
const {
|
|
54
|
+
bottomRadius = 0,
|
|
55
|
+
topRadius = 0,
|
|
56
|
+
height = 1,
|
|
57
|
+
nradial = 10,
|
|
58
|
+
nvertical = 10,
|
|
59
|
+
verticalAxis = 'y',
|
|
60
|
+
topCap = false,
|
|
61
|
+
bottomCap = false
|
|
62
|
+
} = props;
|
|
63
|
+
const extra = (topCap ? 2 : 0) + (bottomCap ? 2 : 0);
|
|
64
|
+
const numVertices = (nradial + 1) * (nvertical + 1 + extra);
|
|
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
|
+
const indices = new Uint16Array(nradial * (nvertical + extra) * 6);
|
|
75
|
+
const indexOffset = INDEX_OFFSETS[verticalAxis];
|
|
76
|
+
const positions = new Float32Array(numVertices * 3);
|
|
77
|
+
const normals = new Float32Array(numVertices * 3);
|
|
78
|
+
const texCoords = new Float32Array(numVertices * 2);
|
|
79
|
+
let i3 = 0;
|
|
80
|
+
let i2 = 0;
|
|
81
|
+
for (let i = start; i <= end; i++) {
|
|
82
|
+
let v = i / nvertical;
|
|
83
|
+
let y = height * v;
|
|
84
|
+
let ringRadius;
|
|
85
|
+
if (i < 0) {
|
|
86
|
+
y = 0;
|
|
87
|
+
v = 1;
|
|
88
|
+
ringRadius = bottomRadius;
|
|
89
|
+
} else if (i > nvertical) {
|
|
90
|
+
y = height;
|
|
91
|
+
v = 1;
|
|
92
|
+
ringRadius = topRadius;
|
|
93
|
+
} else {
|
|
94
|
+
ringRadius = bottomRadius + (topRadius - bottomRadius) * (i / nvertical);
|
|
95
|
+
}
|
|
96
|
+
if (i === -2 || i === nvertical + 2) {
|
|
97
|
+
ringRadius = 0;
|
|
98
|
+
v = 0;
|
|
99
|
+
}
|
|
100
|
+
y -= height / 2;
|
|
101
|
+
for (let j = 0; j < vertsAroundEdge; j++) {
|
|
102
|
+
const sin = msin(j * mpi * 2 / nradial);
|
|
103
|
+
const cos = mcos(j * mpi * 2 / nradial);
|
|
104
|
+
positions[i3 + indexOffset[0]] = sin * ringRadius;
|
|
105
|
+
positions[i3 + indexOffset[1]] = y;
|
|
106
|
+
positions[i3 + indexOffset[2]] = cos * ringRadius;
|
|
107
|
+
normals[i3 + indexOffset[0]] = i < 0 || i > nvertical ? 0 : sin * cosSlant;
|
|
108
|
+
normals[i3 + indexOffset[1]] = i < 0 ? -1 : i > nvertical ? 1 : sinSlant;
|
|
109
|
+
normals[i3 + indexOffset[2]] = i < 0 || i > nvertical ? 0 : cos * cosSlant;
|
|
110
|
+
texCoords[i2 + 0] = j / nradial;
|
|
111
|
+
texCoords[i2 + 1] = v;
|
|
112
|
+
i2 += 2;
|
|
113
|
+
i3 += 3;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
for (let i = 0; i < nvertical + extra; i++) {
|
|
117
|
+
for (let j = 0; j < nradial; j++) {
|
|
118
|
+
const index = (i * nradial + j) * 6;
|
|
119
|
+
indices[index + 0] = vertsAroundEdge * (i + 0) + 0 + j;
|
|
120
|
+
indices[index + 1] = vertsAroundEdge * (i + 0) + 1 + j;
|
|
121
|
+
indices[index + 2] = vertsAroundEdge * (i + 1) + 1 + j;
|
|
122
|
+
indices[index + 3] = vertsAroundEdge * (i + 0) + 0 + j;
|
|
123
|
+
indices[index + 4] = vertsAroundEdge * (i + 1) + 1 + j;
|
|
124
|
+
indices[index + 5] = vertsAroundEdge * (i + 1) + 0 + j;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
indices,
|
|
129
|
+
attributes: {
|
|
130
|
+
POSITION: positions,
|
|
131
|
+
NORMAL: normals,
|
|
132
|
+
TEXCOORD_0: texCoords
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=truncated-cone-geometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"truncated-cone-geometry.js","names":["uid","Geometry","INDEX_OFFSETS","x","y","z","makeTruncatedConeGeometry","props","indices","attributes","tesselateTruncatedCone","length","TruncatedConeGeometry","constructor","arguments","undefined","id","POSITION","size","value","NORMAL","TEXCOORD_0","bottomRadius","topRadius","height","nradial","nvertical","verticalAxis","topCap","bottomCap","extra","numVertices","slant","Math","atan2","msin","sin","mcos","cos","mpi","PI","cosSlant","sinSlant","start","end","vertsAroundEdge","Uint16Array","indexOffset","positions","Float32Array","normals","texCoords","i3","i2","i","v","ringRadius","j","index"],"sources":["../../../src/geometries/truncated-cone-geometry.ts"],"sourcesContent":["import {uid} from '@luma.gl/api';\nimport Geometry from '../geometry/geometry';\nimport {GeometryTable} from '../geometry/geometry-table';\n\nconst INDEX_OFFSETS = {\n x: [2, 0, 1],\n y: [0, 1, 2],\n z: [1, 2, 0]\n};\n\nexport type TruncatedConeGeometryProps = {\n topRadius?: number;\n bottomRadius?: number;\n topCap?: boolean;\n bottomCap?: boolean;\n height?: number;\n nradial?: number;\n nvertical?: number;\n verticalAxis?: 'x' | 'y' | 'z';\n};\n\n/**\n * Primitives inspired by TDL http://code.google.com/p/webglsamples/,\n * copyright 2011 Google Inc. new BSD License\n * (http://www.opensource.org/licenses/bsd-license.php).\n */\nexport function makeTruncatedConeGeometry(props?: TruncatedConeGeometryProps): GeometryTable {\n const {indices, attributes} = tesselateTruncatedCone(props);\n return {\n length: indices.length,\n indices,\n attributes\n };\n}\n\nexport class TruncatedConeGeometry extends Geometry {\n constructor(props: TruncatedConeGeometryProps & {id?: string; attributes?: any} = {}) {\n const {id = uid('truncated-code-geometry')} = props;\n const {indices, attributes} = tesselateTruncatedCone(props);\n super({\n ...props,\n id,\n indices,\n attributes: {\n POSITION: {size: 3, value: attributes.POSITION},\n NORMAL: {size: 3, value: attributes.NORMAL},\n TEXCOORD_0: {size: 2, value: attributes.TEXCOORD_0},\n ...props.attributes}\n });\n }\n}\n\n/* eslint-disable max-statements, complexity */\nfunction tesselateTruncatedCone(props: TruncatedConeGeometryProps = {}) {\n const {\n bottomRadius = 0,\n topRadius = 0,\n height = 1,\n nradial = 10,\n nvertical = 10,\n verticalAxis = 'y',\n topCap = false,\n bottomCap = false\n } = props;\n\n const extra = (topCap ? 2 : 0) + (bottomCap ? 2 : 0);\n const numVertices = (nradial + 1) * (nvertical + 1 + extra);\n\n const slant = Math.atan2(bottomRadius - topRadius, height);\n const msin = Math.sin;\n const mcos = Math.cos;\n const mpi = Math.PI;\n const cosSlant = mcos(slant);\n const sinSlant = msin(slant);\n const start = topCap ? -2 : 0;\n const end = nvertical + (bottomCap ? 2 : 0);\n const vertsAroundEdge = nradial + 1;\n\n const indices = new Uint16Array(nradial * (nvertical + extra) * 6);\n const indexOffset = INDEX_OFFSETS[verticalAxis];\n\n const positions = new Float32Array(numVertices * 3);\n const normals = new Float32Array(numVertices * 3);\n const texCoords = new Float32Array(numVertices * 2);\n\n let i3 = 0;\n let i2 = 0;\n for (let i = start; i <= end; i++) {\n let v = i / nvertical;\n let y = height * v;\n let ringRadius;\n\n if (i < 0) {\n y = 0;\n v = 1;\n ringRadius = bottomRadius;\n } else if (i > nvertical) {\n y = height;\n v = 1;\n ringRadius = topRadius;\n } else {\n ringRadius = bottomRadius + (topRadius - bottomRadius) * (i / nvertical);\n }\n if (i === -2 || i === nvertical + 2) {\n ringRadius = 0;\n v = 0;\n }\n y -= height / 2;\n for (let j = 0; j < vertsAroundEdge; j++) {\n const sin = msin((j * mpi * 2) / nradial);\n const cos = mcos((j * mpi * 2) / nradial);\n\n positions[i3 + indexOffset[0]] = sin * ringRadius;\n positions[i3 + indexOffset[1]] = y;\n positions[i3 + indexOffset[2]] = cos * ringRadius;\n\n normals[i3 + indexOffset[0]] = i < 0 || i > nvertical ? 0 : sin * cosSlant;\n normals[i3 + indexOffset[1]] = i < 0 ? -1 : i > nvertical ? 1 : sinSlant;\n normals[i3 + indexOffset[2]] = i < 0 || i > nvertical ? 0 : cos * cosSlant;\n\n texCoords[i2 + 0] = j / nradial;\n texCoords[i2 + 1] = v;\n\n i2 += 2;\n i3 += 3;\n }\n }\n\n for (let i = 0; i < nvertical + extra; i++) {\n for (let j = 0; j < nradial; j++) {\n const index = (i * nradial + j) * 6;\n indices[index + 0] = vertsAroundEdge * (i + 0) + 0 + j;\n indices[index + 1] = vertsAroundEdge * (i + 0) + 1 + j;\n indices[index + 2] = vertsAroundEdge * (i + 1) + 1 + j;\n indices[index + 3] = vertsAroundEdge * (i + 0) + 0 + j;\n indices[index + 4] = vertsAroundEdge * (i + 1) + 1 + j;\n indices[index + 5] = vertsAroundEdge * (i + 1) + 0 + j;\n }\n }\n\n return {\n indices,\n attributes: {\n POSITION: positions,\n NORMAL: normals,\n TEXCOORD_0: texCoords\n }\n };\n}\n"],"mappings":"AAAA,SAAQA,GAAG,QAAO,cAAc;AAChC,OAAOC,QAAQ,MAAM,sBAAsB;AAG3C,MAAMC,aAAa,GAAG;EACpBC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;EACZC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;EACZC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AACb,CAAC;AAkBD,OAAO,SAASC,yBAAyBA,CAACC,KAAkC,EAAiB;EAC3F,MAAM;IAACC,OAAO;IAAEC;EAAU,CAAC,GAAGC,sBAAsB,CAACH,KAAK,CAAC;EAC3D,OAAO;IACLI,MAAM,EAAEH,OAAO,CAACG,MAAM;IACtBH,OAAO;IACPC;EACF,CAAC;AACH;AAEA,OAAO,MAAMG,qBAAqB,SAASX,QAAQ,CAAC;EAClDY,WAAWA,CAAA,EAA2E;IAAA,IAA1EN,KAAmE,GAAAO,SAAA,CAAAH,MAAA,QAAAG,SAAA,QAAAC,SAAA,GAAAD,SAAA,MAAG,CAAC,CAAC;IAClF,MAAM;MAACE,EAAE,GAAGhB,GA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AAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAGG,CAAC;IACxD;EACF;EAEA,OAAO;IACLjD,OAAO;IACPC,UAAU,EAAE;MACVQ,QAAQ,EAAE+B,SAAS;MACnB5B,MAAM,EAAE8B,OAAO;MACf7B,UAAU,EAAE8B;IACd;EACF,CAAC;AACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry-table.js","names":[],"sources":["../../../src/geometry/geometry-table.ts"],"sourcesContent":["// luma.gl, MIT license\nimport type {TypedArray, VertexFormat} from '@luma.gl/api';\n\n/** Holds one geometry */\nexport type GeometryTable = {\n length: number;\n schema?: Record<string, VertexFormat>;\n attributes: {\n POSITION: TypedArray,\n NORMAL: TypedArray,\n TEXCOORD_0: TypedArray,\n [key: string]: TypedArray,\n };\n indices?: Uint16Array | Uint32Array;\n topology?: 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip';\n}\n"],"mappings":""}
|