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