@luma.gl/engine 9.0.0-alpha.9 → 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/LICENSE +3 -1
- 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 +8 -8
- package/dist/animation/timeline.d.ts.map +1 -1
- package/dist/animation/timeline.js +95 -131
- package/dist/animation-loop/animation-loop-template.d.ts +23 -0
- package/dist/animation-loop/animation-loop-template.d.ts.map +1 -0
- package/dist/animation-loop/animation-loop-template.js +21 -0
- package/dist/{lib → animation-loop}/animation-loop.d.ts +31 -23
- package/dist/animation-loop/animation-loop.d.ts.map +1 -0
- package/dist/animation-loop/animation-loop.js +442 -0
- package/dist/{lib → animation-loop}/animation-props.d.ts +4 -5
- package/dist/animation-loop/animation-props.d.ts.map +1 -0
- package/dist/animation-loop/animation-props.js +1 -0
- package/dist/animation-loop/make-animation-loop.d.ts +6 -0
- package/dist/animation-loop/make-animation-loop.d.ts.map +1 -0
- package/dist/animation-loop/make-animation-loop.js +32 -0
- 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 +26 -0
- package/dist/debug/copy-texture-to-image.d.ts.map +1 -0
- package/dist/debug/copy-texture-to-image.js +43 -0
- package/dist/debug/debug-framebuffer.d.ts +11 -0
- package/dist/debug/debug-framebuffer.d.ts.map +1 -0
- package/dist/debug/debug-framebuffer.js +46 -0
- package/dist/debug/debug-shader-layout.d.ts +9 -0
- package/dist/debug/debug-shader-layout.d.ts.map +1 -0
- package/dist/debug/debug-shader-layout.js +27 -0
- package/dist/debug/pixel-data-utils.d.ts +24 -0
- package/dist/debug/pixel-data-utils.d.ts.map +1 -0
- package/dist/debug/pixel-data-utils.js +39 -0
- package/dist/dist.dev.js +9592 -0
- package/dist/dist.min.js +102 -0
- package/dist/geometries/cone-geometry.d.ts +2 -2
- package/dist/geometries/cone-geometry.d.ts.map +1 -1
- package/dist/geometries/cone-geometry.js +13 -18
- package/dist/geometries/cube-geometry.d.ts +2 -2
- package/dist/geometries/cube-geometry.d.ts.map +1 -1
- package/dist/geometries/cube-geometry.js +192 -57
- package/dist/geometries/cylinder-geometry.d.ts +2 -2
- package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
- package/dist/geometries/cylinder-geometry.js +11 -15
- package/dist/geometries/ico-sphere-geometry.d.ts +2 -2
- package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/ico-sphere-geometry.js +143 -171
- package/dist/geometries/plane-geometry.d.ts +2 -2
- package/dist/geometries/plane-geometry.d.ts.map +1 -1
- package/dist/geometries/plane-geometry.js +95 -122
- package/dist/geometries/sphere-geometry.d.ts +2 -2
- package/dist/geometries/sphere-geometry.d.ts.map +1 -1
- package/dist/geometries/sphere-geometry.js +78 -101
- package/dist/geometries/truncated-cone-geometry.d.ts +2 -4
- package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
- package/dist/geometries/truncated-cone-geometry.js +100 -134
- package/dist/geometry/geometry-table.d.ts +2 -2
- package/dist/geometry/geometry-table.d.ts.map +1 -1
- package/dist/geometry/geometry-table.js +3 -1
- package/dist/geometry/geometry-utils.d.ts.map +1 -1
- package/dist/geometry/geometry-utils.js +35 -41
- package/dist/geometry/geometry.d.ts +43 -43
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +82 -139
- package/dist/geometry/gpu-geometry.d.ts +37 -0
- package/dist/geometry/gpu-geometry.d.ts.map +1 -0
- package/dist/geometry/gpu-geometry.js +90 -0
- package/dist/geometry/gpu-table.d.ts +1 -0
- package/dist/geometry/gpu-table.d.ts.map +1 -0
- package/dist/geometry/gpu-table.js +42 -0
- package/dist/index.cjs +3444 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +43 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -15
- package/dist/lib/clip-space.d.ts +8 -0
- package/dist/lib/clip-space.d.ts.map +1 -1
- package/dist/lib/clip-space.js +43 -2
- package/dist/lib/pipeline-factory.d.ts +17 -51
- package/dist/lib/pipeline-factory.d.ts.map +1 -1
- package/dist/lib/pipeline-factory.js +84 -209
- 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 +219 -0
- package/dist/model/model.d.ts.map +1 -0
- package/dist/model/model.js +659 -0
- package/dist/scenegraph/group-node.d.ts +21 -0
- package/dist/scenegraph/group-node.d.ts.map +1 -0
- package/dist/scenegraph/group-node.js +84 -0
- package/dist/scenegraph/model-node.d.ts +18 -0
- package/dist/scenegraph/model-node.d.ts.map +1 -0
- package/dist/scenegraph/model-node.js +35 -0
- package/dist/scenegraph/scenegraph-node.d.ts +56 -0
- package/dist/scenegraph/scenegraph-node.d.ts.map +1 -0
- package/dist/scenegraph/scenegraph-node.js +153 -0
- package/dist/shader-inputs.d.ts +63 -0
- package/dist/shader-inputs.d.ts.map +1 -0
- package/dist/shader-inputs.js +107 -0
- package/dist/transform/buffer-transform.d.ts +35 -0
- package/dist/transform/buffer-transform.d.ts.map +1 -0
- package/dist/transform/buffer-transform.js +70 -0
- package/dist/transform/texture-transform.d.ts +57 -0
- package/dist/transform/texture-transform.d.ts.map +1 -0
- package/dist/transform/texture-transform.js +117 -0
- package/dist.min.js +25 -0
- package/package.json +24 -14
- package/src/animation/timeline.ts +35 -34
- package/src/animation-loop/animation-loop-template.ts +25 -0
- package/src/{lib → animation-loop}/animation-loop.ts +114 -93
- package/src/{lib → animation-loop}/animation-props.ts +2 -2
- package/src/animation-loop/make-animation-loop.ts +53 -0
- package/src/computation.ts +346 -0
- package/src/debug/copy-texture-to-image.ts +70 -0
- package/src/debug/debug-framebuffer.ts +70 -0
- package/src/debug/debug-shader-layout.ts +38 -0
- package/src/debug/pixel-data-utils.ts +54 -0
- package/src/geometries/cone-geometry.ts +1 -1
- package/src/geometries/cube-geometry.ts +62 -56
- package/src/geometries/cylinder-geometry.ts +2 -2
- package/src/geometries/ico-sphere-geometry.ts +6 -5
- package/src/geometries/plane-geometry.ts +5 -4
- package/src/geometries/sphere-geometry.ts +4 -3
- package/src/geometries/truncated-cone-geometry.ts +6 -14
- package/src/geometry/geometry-table.ts +10 -7
- package/src/geometry/geometry-utils.ts +19 -3
- package/src/geometry/geometry.ts +68 -110
- package/src/geometry/gpu-geometry.ts +132 -0
- package/src/geometry/gpu-table.ts +41 -0
- package/src/index.ts +37 -10
- package/src/lib/clip-space.ts +32 -34
- package/src/lib/pipeline-factory.ts +83 -193
- package/src/lib/shader-factory.ts +57 -0
- package/src/model/model.ts +835 -0
- package/src/scenegraph/group-node.ts +107 -0
- package/src/scenegraph/model-node.ts +50 -0
- package/src/scenegraph/scenegraph-node.ts +204 -0
- package/src/shader-inputs.ts +157 -0
- package/src/transform/buffer-transform.ts +102 -0
- package/src/transform/texture-transform.ts +168 -0
- package/dist/animation/key-frames.js.map +0 -1
- package/dist/animation/timeline.js.map +0 -1
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/bundle.js +0 -5
- 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.d.ts +0 -1
- package/dist/geometry/primitive-utils.d.ts.map +0 -1
- package/dist/geometry/primitive-utils.js +0 -2
- package/dist/geometry/primitive-utils.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/animation-loop.d.ts.map +0 -1
- package/dist/lib/animation-loop.js +0 -480
- package/dist/lib/animation-loop.js.map +0 -1
- package/dist/lib/animation-props.d.ts.map +0 -1
- package/dist/lib/animation-props.js +0 -2
- package/dist/lib/animation-props.js.map +0 -1
- package/dist/lib/clip-space.js.map +0 -1
- package/dist/lib/model-utils.d.ts +0 -5
- package/dist/lib/model-utils.d.ts.map +0 -1
- package/dist/lib/model-utils.js +0 -45
- package/dist/lib/model-utils.js.map +0 -1
- package/dist/lib/model.d.ts +0 -41
- package/dist/lib/model.d.ts.map +0 -1
- package/dist/lib/model.js +0 -182
- package/dist/lib/model.js.map +0 -1
- package/dist/lib/pipeline-factory.js.map +0 -1
- package/dist/lib/render-loop.d.ts +0 -14
- package/dist/lib/render-loop.d.ts.map +0 -1
- package/dist/lib/render-loop.js +0 -49
- package/dist/lib/render-loop.js.map +0 -1
- package/src/bundle.ts +0 -4
- package/src/geometry/primitive-utils.ts +0 -30
- package/src/lib/model-utils.ts +0 -124
- package/src/lib/model.ts +0 -183
- package/src/lib/render-loop.ts +0 -58
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plane-geometry.d.ts","sourceRoot":"","sources":["../../src/geometries/plane-geometry.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,
|
|
1
|
+
{"version":3,"file":"plane-geometry.d.ts","sourceRoot":"","sources":["../../src/geometries/plane-geometry.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,gCAA6B;AAG9C,MAAM,MAAM,kBAAkB,GAAG;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,GAAG,CAAC;CAClB,CAAC;AAKF,qBAAa,aAAc,SAAQ,QAAQ;gBAC7B,KAAK,GAAE,kBAAuB;CAY3C"}
|
|
@@ -1,129 +1,102 @@
|
|
|
1
|
-
import { uid } from '@luma.gl/
|
|
2
|
-
import Geometry from
|
|
3
|
-
import { unpackIndexedGeometry } from
|
|
1
|
+
import { uid } from '@luma.gl/core';
|
|
2
|
+
import { Geometry } from "../geometry/geometry.js";
|
|
3
|
+
import { unpackIndexedGeometry } from "../geometry/geometry-utils.js";
|
|
4
|
+
// Primitives inspired by TDL http://code.google.com/p/webglsamples/,
|
|
5
|
+
// copyright 2011 Google Inc. new BSD License
|
|
6
|
+
// (http://www.opensource.org/licenses/bsd-license.php).
|
|
4
7
|
export class PlaneGeometry extends Geometry {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
attributes: { ...attributes,
|
|
17
|
-
...props.attributes
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
8
|
+
constructor(props = {}) {
|
|
9
|
+
const { id = uid('plane-geometry') } = props;
|
|
10
|
+
const { indices, attributes } = tesselatePlane(props);
|
|
11
|
+
super({
|
|
12
|
+
...props,
|
|
13
|
+
id,
|
|
14
|
+
topology: 'triangle-list',
|
|
15
|
+
indices,
|
|
16
|
+
attributes: { ...attributes, ...props.attributes }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
22
19
|
}
|
|
23
|
-
|
|
20
|
+
/* eslint-disable complexity, max-statements */
|
|
24
21
|
function tesselatePlane(props) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const texCoords = new Float32Array(numVertices * 2);
|
|
40
|
-
|
|
41
|
-
if (flipCull) {
|
|
42
|
-
c1len = -c1len;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
let i2 = 0;
|
|
46
|
-
let i3 = 0;
|
|
47
|
-
|
|
48
|
-
for (let z = 0; z <= subdivisions2; z++) {
|
|
49
|
-
for (let x = 0; x <= subdivisions1; x++) {
|
|
50
|
-
const u = x / subdivisions1;
|
|
51
|
-
const v = z / subdivisions2;
|
|
52
|
-
texCoords[i2 + 0] = flipCull ? 1 - u : u;
|
|
53
|
-
texCoords[i2 + 1] = v;
|
|
54
|
-
|
|
55
|
-
switch (type) {
|
|
56
|
-
case 'x,y':
|
|
57
|
-
positions[i3 + 0] = c1len * u - c1len * 0.5;
|
|
58
|
-
positions[i3 + 1] = c2len * v - c2len * 0.5;
|
|
59
|
-
positions[i3 + 2] = offset;
|
|
60
|
-
normals[i3 + 0] = 0;
|
|
61
|
-
normals[i3 + 1] = 0;
|
|
62
|
-
normals[i3 + 2] = flipCull ? 1 : -1;
|
|
63
|
-
break;
|
|
64
|
-
|
|
65
|
-
case 'x,z':
|
|
66
|
-
positions[i3 + 0] = c1len * u - c1len * 0.5;
|
|
67
|
-
positions[i3 + 1] = offset;
|
|
68
|
-
positions[i3 + 2] = c2len * v - c2len * 0.5;
|
|
69
|
-
normals[i3 + 0] = 0;
|
|
70
|
-
normals[i3 + 1] = flipCull ? 1 : -1;
|
|
71
|
-
normals[i3 + 2] = 0;
|
|
72
|
-
break;
|
|
73
|
-
|
|
74
|
-
case 'y,z':
|
|
75
|
-
positions[i3 + 0] = offset;
|
|
76
|
-
positions[i3 + 1] = c1len * u - c1len * 0.5;
|
|
77
|
-
positions[i3 + 2] = c2len * v - c2len * 0.5;
|
|
78
|
-
normals[i3 + 0] = flipCull ? 1 : -1;
|
|
79
|
-
normals[i3 + 1] = 0;
|
|
80
|
-
normals[i3 + 2] = 0;
|
|
81
|
-
break;
|
|
82
|
-
|
|
83
|
-
default:
|
|
84
|
-
throw new Error('PlaneGeometry: unknown type');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
i2 += 2;
|
|
88
|
-
i3 += 3;
|
|
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;
|
|
89
36
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
+
}
|
|
104
76
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
value: normals
|
|
120
|
-
},
|
|
121
|
-
TEXCOORD_0: {
|
|
122
|
-
size: 2,
|
|
123
|
-
value: texCoords
|
|
124
|
-
}
|
|
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
|
+
}
|
|
125
91
|
}
|
|
126
|
-
|
|
127
|
-
|
|
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;
|
|
128
102
|
}
|
|
129
|
-
//# sourceMappingURL=plane-geometry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sphere-geometry.d.ts","sourceRoot":"","sources":["../../src/geometries/sphere-geometry.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,
|
|
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,107 +1,84 @@
|
|
|
1
|
-
import { uid } from '@luma.gl/
|
|
2
|
-
import Geometry from
|
|
1
|
+
import { uid } from '@luma.gl/core';
|
|
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
|
-
attributes: { ...attributes,
|
|
16
|
-
...props.attributes
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
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
|
+
}
|
|
21
18
|
}
|
|
22
|
-
|
|
19
|
+
/* eslint-disable max-statements, complexity */
|
|
23
20
|
function tesselateSphere(props) {
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
normals[i3 + 1] = uy;
|
|
66
|
-
normals[i3 + 2] = uz;
|
|
67
|
-
texCoords[i2 + 0] = u;
|
|
68
|
-
texCoords[i2 + 1] = 1 - v;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const numVertsAround = nlong + 1;
|
|
73
|
-
|
|
74
|
-
for (let x = 0; x < nlong; x++) {
|
|
75
|
-
for (let y = 0; y < nlat; y++) {
|
|
76
|
-
const index = (x * nlat + y) * 6;
|
|
77
|
-
indices[index + 0] = y * numVertsAround + x;
|
|
78
|
-
indices[index + 1] = y * numVertsAround + x + 1;
|
|
79
|
-
indices[index + 2] = (y + 1) * numVertsAround + x;
|
|
80
|
-
indices[index + 3] = (y + 1) * numVertsAround + x;
|
|
81
|
-
indices[index + 4] = y * numVertsAround + x + 1;
|
|
82
|
-
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
|
+
}
|
|
83
62
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
NORMAL: {
|
|
97
|
-
size: 3,
|
|
98
|
-
value: normals
|
|
99
|
-
},
|
|
100
|
-
TEXCOORD_0: {
|
|
101
|
-
size: 2,
|
|
102
|
-
value: texCoords
|
|
103
|
-
}
|
|
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
|
+
}
|
|
104
75
|
}
|
|
105
|
-
|
|
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
|
+
};
|
|
106
84
|
}
|
|
107
|
-
//# sourceMappingURL=sphere-geometry.js.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import Geometry from
|
|
2
|
-
|
|
3
|
-
export declare type TruncatedConeGeometryProps = {
|
|
1
|
+
import { Geometry } from "../geometry/geometry.js";
|
|
2
|
+
export type TruncatedConeGeometryProps = {
|
|
4
3
|
topRadius?: number;
|
|
5
4
|
bottomRadius?: number;
|
|
6
5
|
topCap?: boolean;
|
|
@@ -15,7 +14,6 @@ export declare type TruncatedConeGeometryProps = {
|
|
|
15
14
|
* copyright 2011 Google Inc. new BSD License
|
|
16
15
|
* (http://www.opensource.org/licenses/bsd-license.php).
|
|
17
16
|
*/
|
|
18
|
-
export declare function makeTruncatedConeGeometry(props?: TruncatedConeGeometryProps): GeometryTable;
|
|
19
17
|
export declare class TruncatedConeGeometry extends Geometry {
|
|
20
18
|
constructor(props?: TruncatedConeGeometryProps & {
|
|
21
19
|
id?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"truncated-cone-geometry.d.ts","sourceRoot":"","sources":["../../src/geometries/truncated-cone-geometry.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,
|
|
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"}
|