@luma.gl/engine 10.0.0-alpha.2 → 10.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compute/computation.d.ts +2 -0
- package/dist/compute/computation.d.ts.map +1 -1
- package/dist/compute/computation.js +5 -1
- package/dist/compute/computation.js.map +1 -1
- package/dist/dist.dev.js +1033 -1320
- package/dist/dist.min.js +23 -23
- package/dist/geometry/edge-geometry.d.ts +17 -0
- package/dist/geometry/edge-geometry.d.ts.map +1 -0
- package/dist/geometry/edge-geometry.js +160 -0
- package/dist/geometry/edge-geometry.js.map +1 -0
- package/dist/geometry/geometry-primitives.d.ts +54 -0
- package/dist/geometry/geometry-primitives.d.ts.map +1 -0
- package/dist/geometry/geometry-primitives.js +153 -0
- package/dist/geometry/geometry-primitives.js.map +1 -0
- package/dist/geometry/geometry-utils.d.ts +7 -15
- package/dist/geometry/geometry-utils.d.ts.map +1 -1
- package/dist/geometry/geometry-utils.js +9 -55
- package/dist/geometry/geometry-utils.js.map +1 -1
- package/dist/geometry/geometry.d.ts +9 -69
- package/dist/geometry/geometry.d.ts.map +1 -1
- package/dist/geometry/geometry.js +27 -93
- package/dist/geometry/geometry.js.map +1 -1
- package/dist/geometry/gpu-geometry.d.ts +4 -2
- package/dist/geometry/gpu-geometry.d.ts.map +1 -1
- package/dist/geometry/gpu-geometry.js +3 -3
- package/dist/geometry/gpu-geometry.js.map +1 -1
- package/dist/geometry/stroke-geometry.d.ts +15 -0
- package/dist/geometry/stroke-geometry.d.ts.map +1 -0
- package/dist/geometry/stroke-geometry.js +168 -0
- package/dist/geometry/stroke-geometry.js.map +1 -0
- package/dist/index.cjs +554 -1309
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +17 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -7
- package/dist/index.js.map +1 -1
- package/dist/model/model.d.ts +6 -1
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +11 -4
- package/dist/model/model.js.map +1 -1
- package/dist/models/clip-space.d.ts +4 -1
- package/dist/models/clip-space.d.ts.map +1 -1
- package/dist/models/clip-space.js +16 -13
- package/dist/models/clip-space.js.map +1 -1
- package/dist/models/directional-light-model.js +1 -1
- package/dist/models/directional-light-model.js.map +1 -1
- package/dist/models/point-light-model.js +1 -1
- package/dist/models/point-light-model.js.map +1 -1
- package/dist/models/spot-light-model.js +1 -1
- package/dist/models/spot-light-model.js.map +1 -1
- package/package.json +7 -6
- package/src/compute/computation.ts +7 -0
- package/src/geometry/edge-geometry.ts +208 -0
- package/src/geometry/geometry-primitives.ts +215 -0
- package/src/geometry/geometry-utils.ts +16 -71
- package/src/geometry/geometry.ts +36 -163
- package/src/geometry/gpu-geometry.ts +9 -4
- package/src/geometry/stroke-geometry.ts +236 -0
- package/src/index.ts +21 -14
- package/src/model/model.ts +19 -6
- package/src/models/clip-space.ts +21 -14
- package/src/models/directional-light-model.ts +1 -1
- package/src/models/point-light-model.ts +1 -1
- package/src/models/spot-light-model.ts +1 -1
- package/dist/geometries/cone-geometry.d.ts +0 -12
- package/dist/geometries/cone-geometry.d.ts.map +0 -1
- package/dist/geometries/cone-geometry.js +0 -19
- package/dist/geometries/cone-geometry.js.map +0 -1
- package/dist/geometries/cube-geometry.d.ts +0 -14
- package/dist/geometries/cube-geometry.d.ts.map +0 -1
- package/dist/geometries/cube-geometry.js +0 -222
- package/dist/geometries/cube-geometry.js.map +0 -1
- package/dist/geometries/cylinder-geometry.d.ts +0 -11
- package/dist/geometries/cylinder-geometry.d.ts.map +0 -1
- package/dist/geometries/cylinder-geometry.js +0 -17
- package/dist/geometries/cylinder-geometry.js.map +0 -1
- package/dist/geometries/ico-sphere-geometry.d.ts +0 -11
- package/dist/geometries/ico-sphere-geometry.d.ts.map +0 -1
- package/dist/geometries/ico-sphere-geometry.js +0 -158
- package/dist/geometries/ico-sphere-geometry.js.map +0 -1
- package/dist/geometries/plane-geometry.d.ts +0 -20
- package/dist/geometries/plane-geometry.d.ts.map +0 -1
- package/dist/geometries/plane-geometry.js +0 -106
- package/dist/geometries/plane-geometry.js.map +0 -1
- package/dist/geometries/sphere-geometry.d.ts +0 -12
- package/dist/geometries/sphere-geometry.d.ts.map +0 -1
- package/dist/geometries/sphere-geometry.js +0 -88
- package/dist/geometries/sphere-geometry.js.map +0 -1
- package/dist/geometries/truncated-cone-geometry.d.ts +0 -23
- package/dist/geometries/truncated-cone-geometry.d.ts.map +0 -1
- package/dist/geometries/truncated-cone-geometry.js +0 -112
- package/dist/geometries/truncated-cone-geometry.js.map +0 -1
- package/src/geometries/cone-geometry.ts +0 -31
- package/src/geometries/cube-geometry.ts +0 -258
- package/src/geometries/cylinder-geometry.ts +0 -28
- package/src/geometries/ico-sphere-geometry.ts +0 -193
- package/src/geometries/plane-geometry.ts +0 -142
- package/src/geometries/sphere-geometry.ts +0 -113
- package/src/geometries/truncated-cone-geometry.ts +0 -145
package/dist/dist.dev.js
CHANGED
|
@@ -72,16 +72,16 @@ var __exports__ = (() => {
|
|
|
72
72
|
BufferTransform: () => BufferTransform,
|
|
73
73
|
ClipSpace: () => ClipSpace,
|
|
74
74
|
Computation: () => Computation,
|
|
75
|
-
ConeGeometry: () =>
|
|
76
|
-
CubeGeometry: () =>
|
|
77
|
-
CylinderGeometry: () =>
|
|
75
|
+
ConeGeometry: () => ConeGeometry2,
|
|
76
|
+
CubeGeometry: () => CubeGeometry2,
|
|
77
|
+
CylinderGeometry: () => CylinderGeometry2,
|
|
78
78
|
DirectionalLightModel: () => DirectionalLightModel,
|
|
79
79
|
DynamicBuffer: () => DynamicBuffer,
|
|
80
80
|
DynamicTexture: () => DynamicTexture,
|
|
81
81
|
GPUGeometry: () => GPUGeometry,
|
|
82
|
-
Geometry: () =>
|
|
82
|
+
Geometry: () => Geometry2,
|
|
83
83
|
GroupNode: () => GroupNode,
|
|
84
|
-
IcoSphereGeometry: () =>
|
|
84
|
+
IcoSphereGeometry: () => IcoSphereGeometry2,
|
|
85
85
|
Kernel: () => Kernel,
|
|
86
86
|
KeyFrames: () => KeyFrames,
|
|
87
87
|
LegacyPickingManager: () => LegacyPickingManager,
|
|
@@ -91,20 +91,20 @@ var __exports__ = (() => {
|
|
|
91
91
|
ModelNode: () => ModelNode,
|
|
92
92
|
OrbitControls: () => OrbitControls,
|
|
93
93
|
PickingManager: () => PickingManager,
|
|
94
|
-
PlaneGeometry: () =>
|
|
94
|
+
PlaneGeometry: () => PlaneGeometry2,
|
|
95
95
|
PointLightModel: () => PointLightModel,
|
|
96
96
|
RenderKernel: () => RenderKernel,
|
|
97
97
|
ScenegraphNode: () => ScenegraphNode,
|
|
98
98
|
ShaderInputs: () => ShaderInputs,
|
|
99
99
|
ShaderPassRenderer: () => ShaderPassRenderer,
|
|
100
|
-
SphereGeometry: () =>
|
|
100
|
+
SphereGeometry: () => SphereGeometry2,
|
|
101
101
|
SpotLightModel: () => SpotLightModel,
|
|
102
102
|
Swap: () => Swap,
|
|
103
103
|
SwapBuffers: () => SwapBuffers,
|
|
104
104
|
SwapFramebuffers: () => SwapFramebuffers,
|
|
105
105
|
TextureTransform: () => TextureTransform,
|
|
106
106
|
Timeline: () => Timeline,
|
|
107
|
-
TruncatedConeGeometry: () =>
|
|
107
|
+
TruncatedConeGeometry: () => TruncatedConeGeometry2,
|
|
108
108
|
VideoTexture: () => VideoTexture,
|
|
109
109
|
_resolveLoadFileUrl: () => _resolveLoadFileUrl,
|
|
110
110
|
applyMorphTargets: () => applyMorphTargets,
|
|
@@ -119,8 +119,11 @@ var __exports__ = (() => {
|
|
|
119
119
|
loadImage: () => loadImage,
|
|
120
120
|
loadImageBitmap: () => loadImageBitmap,
|
|
121
121
|
makeAnimationLoop: () => makeAnimationLoop,
|
|
122
|
+
makeEdgeGeometry: () => makeEdgeGeometry,
|
|
123
|
+
makeEdgeGeometryFromGeometries: () => makeEdgeGeometryFromGeometries,
|
|
122
124
|
makeInterleavedGeometry: () => makeInterleavedGeometry,
|
|
123
125
|
makeRandomGenerator: () => makeRandomGenerator,
|
|
126
|
+
makeStrokeGeometry: () => makeStrokeGeometry,
|
|
124
127
|
picking: () => picking4,
|
|
125
128
|
requestAnimationFramePolyfill: () => requestAnimationFramePolyfill,
|
|
126
129
|
resolvePickingBackend: () => resolvePickingBackend,
|
|
@@ -613,105 +616,489 @@ var __exports__ = (() => {
|
|
|
613
616
|
}
|
|
614
617
|
};
|
|
615
618
|
|
|
616
|
-
//
|
|
617
|
-
var
|
|
618
|
-
|
|
619
|
-
// src/utils/uid.ts
|
|
620
|
-
var uidCounters = {};
|
|
621
|
-
function uid(id = "id") {
|
|
622
|
-
uidCounters[id] = uidCounters[id] || 1;
|
|
623
|
-
const count = uidCounters[id]++;
|
|
624
|
-
return `${id}-${count}`;
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
// src/geometry/geometry.ts
|
|
619
|
+
// ../../node_modules/@math.gl/geometry/dist/lib/geometry.js
|
|
620
|
+
var geometryId = 0;
|
|
628
621
|
var Geometry = class {
|
|
629
|
-
/** Application-provided or generated identifier. */
|
|
630
|
-
id;
|
|
631
|
-
/** Determines how vertices are assembled into primitives. */
|
|
632
|
-
topology;
|
|
633
|
-
/** Resolved draw vertex count. */
|
|
634
|
-
vertexCount;
|
|
635
|
-
/** Optional index attribute. */
|
|
636
|
-
indices;
|
|
637
|
-
/** CPU attributes, keyed by caller-provided source attribute name. */
|
|
638
|
-
attributes;
|
|
639
|
-
/** Buffer layout matching the geometry attributes. Always populated. */
|
|
640
|
-
bufferLayout;
|
|
641
|
-
/** Application-owned metadata. */
|
|
642
|
-
userData = {};
|
|
643
|
-
/** Creates a CPU geometry and wraps raw typed arrays into attribute records. */
|
|
644
622
|
constructor(props) {
|
|
645
|
-
|
|
646
|
-
this.id = props.id ||
|
|
623
|
+
this.userData = {};
|
|
624
|
+
this.id = props.id || `geometry-${++geometryId}`;
|
|
647
625
|
this.topology = props.topology;
|
|
648
|
-
if (indices) {
|
|
649
|
-
this.indices = ArrayBuffer.isView(indices) ? { value: indices, size: 1 } : indices;
|
|
650
|
-
}
|
|
651
626
|
this.attributes = {};
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
if (attributeName === "indices") {
|
|
663
|
-
if (this.indices) {
|
|
664
|
-
throw new Error("Multiple indices detected");
|
|
665
|
-
}
|
|
666
|
-
this.indices = attribute;
|
|
627
|
+
let indices = props.indices ? normalizeAttribute(props.indices) : void 0;
|
|
628
|
+
for (const [name, input] of Object.entries(props.attributes || {})) {
|
|
629
|
+
const attribute = normalizeAttribute(input);
|
|
630
|
+
if (name === "POSITION" || name === "positions") {
|
|
631
|
+
attribute.size || (attribute.size = 3);
|
|
632
|
+
}
|
|
633
|
+
if (name === "indices") {
|
|
634
|
+
if (indices)
|
|
635
|
+
throw new Error("Geometry has multiple index attributes");
|
|
636
|
+
indices = attribute;
|
|
667
637
|
} else {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
}
|
|
675
|
-
this.attributes[attributeName] = attribute;
|
|
638
|
+
this.attributes[name] = attribute;
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
if (indices) {
|
|
642
|
+
if (!(indices.value instanceof Uint16Array || indices.value instanceof Uint32Array)) {
|
|
643
|
+
throw new Error("Geometry indices must be a Uint16Array or Uint32Array");
|
|
676
644
|
}
|
|
645
|
+
indices.size = 1;
|
|
646
|
+
this.indices = indices;
|
|
647
|
+
validateIndices(indices, this.attributes);
|
|
677
648
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
649
|
+
this.vertexCount = props.vertexCount ?? calculateVertexCount(this.attributes, this.indices);
|
|
650
|
+
if (!Number.isInteger(this.vertexCount) || this.vertexCount < 0) {
|
|
651
|
+
throw new Error("Geometry vertexCount must be a non-negative integer");
|
|
681
652
|
}
|
|
682
|
-
this.vertexCount = vertexCount || this._calculateVertexCount(this.attributes, this.indices);
|
|
683
|
-
this.bufferLayout = props.bufferLayout || getBufferLayoutFromGeometryAttributes(this.attributes);
|
|
684
653
|
}
|
|
685
|
-
/** Returns the resolved draw vertex count. */
|
|
686
654
|
getVertexCount() {
|
|
687
655
|
return this.vertexCount;
|
|
688
656
|
}
|
|
689
|
-
/** Returns all attributes, including `indices` when index data is present. */
|
|
690
657
|
getAttributes() {
|
|
691
658
|
return this.indices ? { indices: this.indices, ...this.attributes } : this.attributes;
|
|
692
659
|
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
660
|
+
};
|
|
661
|
+
function normalizeAttribute(input) {
|
|
662
|
+
const attribute = isTypedArray(input) ? { value: input } : { ...input };
|
|
663
|
+
if (!isTypedArray(attribute.value)) {
|
|
664
|
+
throw new Error("Geometry attributes must contain a typed-array value");
|
|
696
665
|
}
|
|
697
|
-
|
|
698
|
-
|
|
666
|
+
if (attribute.size !== void 0 && (!Number.isInteger(attribute.size) || attribute.size < 1)) {
|
|
667
|
+
throw new Error("Geometry attribute size must be a positive integer");
|
|
699
668
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
669
|
+
if (attribute.size && attribute.value.length % attribute.size !== 0) {
|
|
670
|
+
throw new Error("Geometry attribute length must be divisible by its size");
|
|
671
|
+
}
|
|
672
|
+
return attribute;
|
|
673
|
+
}
|
|
674
|
+
function isTypedArray(value) {
|
|
675
|
+
return ArrayBuffer.isView(value) && !(value instanceof DataView);
|
|
676
|
+
}
|
|
677
|
+
function validateIndices(indices, attributes) {
|
|
678
|
+
let maximumIndex = -1;
|
|
679
|
+
for (const index of indices.value)
|
|
680
|
+
maximumIndex = Math.max(maximumIndex, Number(index));
|
|
681
|
+
for (const [name, attribute] of Object.entries(attributes)) {
|
|
682
|
+
if (!attribute.constant && attribute.size) {
|
|
683
|
+
const attributeVertexCount = attribute.value.length / attribute.size;
|
|
684
|
+
if (maximumIndex >= attributeVertexCount) {
|
|
685
|
+
throw new Error(`Geometry index ${maximumIndex} exceeds ${name} vertex count ${attributeVertexCount}`);
|
|
686
|
+
}
|
|
703
687
|
}
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
function calculateVertexCount(attributes, indices) {
|
|
691
|
+
if (indices)
|
|
692
|
+
return indices.value.length;
|
|
693
|
+
let count = Infinity;
|
|
694
|
+
for (const attribute of Object.values(attributes)) {
|
|
695
|
+
if (!attribute.constant && attribute.size) {
|
|
696
|
+
count = Math.min(count, attribute.value.length / attribute.size);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
if (!Number.isFinite(count))
|
|
700
|
+
throw new Error("Geometry has no countable attributes");
|
|
701
|
+
return count;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
// ../../node_modules/@math.gl/geometry/dist/lib/geometry-utils.js
|
|
705
|
+
function unpackIndexedGeometry(geometry) {
|
|
706
|
+
if (!geometry.indices)
|
|
707
|
+
return geometry;
|
|
708
|
+
const indices = geometry.indices.value;
|
|
709
|
+
const attributes = {};
|
|
710
|
+
for (const [name, attribute] of Object.entries(geometry.attributes)) {
|
|
711
|
+
if (!attribute)
|
|
712
|
+
continue;
|
|
713
|
+
if (attribute.constant || !attribute.size) {
|
|
714
|
+
attributes[name] = attribute;
|
|
715
|
+
continue;
|
|
716
|
+
}
|
|
717
|
+
const ArrayType = attribute.value.constructor;
|
|
718
|
+
const value = new ArrayType(indices.length * attribute.size);
|
|
719
|
+
for (let i = 0; i < indices.length; i++) {
|
|
720
|
+
for (let component = 0; component < attribute.size; component++) {
|
|
721
|
+
value[i * attribute.size + component] = attribute.value[Number(indices[i]) * attribute.size + component];
|
|
708
722
|
}
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
723
|
+
}
|
|
724
|
+
attributes[name] = { ...attribute, value };
|
|
725
|
+
}
|
|
726
|
+
return { attributes };
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// ../../node_modules/@math.gl/geometry/dist/geometries/geometry-helpers.js
|
|
730
|
+
function assertPositive(value, name) {
|
|
731
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
732
|
+
throw new Error(`${name} must be greater than zero`);
|
|
733
|
+
}
|
|
734
|
+
function assertNonNegative(value, name) {
|
|
735
|
+
if (!Number.isFinite(value) || value < 0)
|
|
736
|
+
throw new Error(`${name} must be non-negative`);
|
|
737
|
+
}
|
|
738
|
+
function assertSegments(value, name, minimum = 1) {
|
|
739
|
+
if (!Number.isInteger(value) || value < minimum)
|
|
740
|
+
throw new Error(`${name} must be an integer >= ${minimum}`);
|
|
741
|
+
}
|
|
742
|
+
function makeIndices(vertexCount, values) {
|
|
743
|
+
return vertexCount > 65535 ? new Uint32Array(values) : new Uint16Array(values);
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// ../../node_modules/@math.gl/geometry/dist/geometries/box-geometry.js
|
|
747
|
+
var BoxGeometry = class extends Geometry {
|
|
748
|
+
constructor(props = {}) {
|
|
749
|
+
const size = props.size || [1, 1, 1];
|
|
750
|
+
assertPositive(size[0], "size[0]");
|
|
751
|
+
assertPositive(size[1], "size[1]");
|
|
752
|
+
assertPositive(size[2], "size[2]");
|
|
753
|
+
const half = [size[0] / 2, size[1] / 2, size[2] / 2];
|
|
754
|
+
const positions = [];
|
|
755
|
+
const normals = [];
|
|
756
|
+
const texCoords = [];
|
|
757
|
+
const indices = [];
|
|
758
|
+
const faces = [
|
|
759
|
+
{ n: [1, 0, 0], u: [0, 0, -1], v: [0, 1, 0], h1: half[2], h2: half[1] },
|
|
760
|
+
{ n: [-1, 0, 0], u: [0, 0, 1], v: [0, 1, 0], h1: half[2], h2: half[1] },
|
|
761
|
+
{ n: [0, 1, 0], u: [1, 0, 0], v: [0, 0, -1], h1: half[0], h2: half[2] },
|
|
762
|
+
{ n: [0, -1, 0], u: [1, 0, 0], v: [0, 0, 1], h1: half[0], h2: half[2] },
|
|
763
|
+
{ n: [0, 0, 1], u: [1, 0, 0], v: [0, 1, 0], h1: half[0], h2: half[1] },
|
|
764
|
+
{ n: [0, 0, -1], u: [-1, 0, 0], v: [0, 1, 0], h1: half[0], h2: half[1] }
|
|
765
|
+
];
|
|
766
|
+
for (const face of faces) {
|
|
767
|
+
const base = positions.length / 3;
|
|
768
|
+
for (const [s, t, u, v] of [
|
|
769
|
+
[-1, -1, 0, 0],
|
|
770
|
+
[1, -1, 1, 0],
|
|
771
|
+
[1, 1, 1, 1],
|
|
772
|
+
[-1, 1, 0, 1]
|
|
773
|
+
]) {
|
|
774
|
+
positions.push(face.n[0] * half[0] + face.u[0] * face.h1 * s + face.v[0] * face.h2 * t, face.n[1] * half[1] + face.u[1] * face.h1 * s + face.v[1] * face.h2 * t, face.n[2] * half[2] + face.u[2] * face.h1 * s + face.v[2] * face.h2 * t);
|
|
775
|
+
normals.push(...face.n);
|
|
776
|
+
texCoords.push(u, v);
|
|
777
|
+
}
|
|
778
|
+
indices.push(base, base + 1, base + 2, base, base + 2, base + 3);
|
|
779
|
+
}
|
|
780
|
+
super({
|
|
781
|
+
id: props.id,
|
|
782
|
+
topology: "triangle-list",
|
|
783
|
+
indices: makeIndices(24, indices),
|
|
784
|
+
attributes: {
|
|
785
|
+
POSITION: { size: 3, value: new Float32Array(positions) },
|
|
786
|
+
NORMAL: { size: 3, value: new Float32Array(normals) },
|
|
787
|
+
TEXCOORD_0: { size: 2, value: new Float32Array(texCoords) },
|
|
788
|
+
...props.attributes
|
|
712
789
|
}
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
var CubeGeometry = class extends BoxGeometry {
|
|
794
|
+
constructor(props = {}) {
|
|
795
|
+
const size = props.size ?? 1;
|
|
796
|
+
super({ ...props, size: [size, size, size] });
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
|
|
800
|
+
// ../../node_modules/@math.gl/geometry/dist/geometries/surface-of-revolution.js
|
|
801
|
+
function makeSurfaceOfRevolution(rings, nradial) {
|
|
802
|
+
const positions = [];
|
|
803
|
+
const normals = [];
|
|
804
|
+
const texCoords = [];
|
|
805
|
+
const indices = [];
|
|
806
|
+
const stride = nradial + 1;
|
|
807
|
+
for (let ringIndex = 0; ringIndex < rings.length; ringIndex++) {
|
|
808
|
+
const ring = rings[ringIndex];
|
|
809
|
+
for (let radial = 0; radial <= nradial; radial++) {
|
|
810
|
+
const u = radial / nradial;
|
|
811
|
+
const angle2 = u * Math.PI * 2;
|
|
812
|
+
const sin = Math.sin(angle2);
|
|
813
|
+
const cos = Math.cos(angle2);
|
|
814
|
+
positions.push(sin * ring.radius, ring.y, cos * ring.radius);
|
|
815
|
+
normals.push(sin * ring.normalRadius, ring.normalY, cos * ring.normalRadius);
|
|
816
|
+
texCoords.push(u, ringIndex / (rings.length - 1));
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
for (let ring = 0; ring < rings.length - 1; ring++) {
|
|
820
|
+
for (let radial = 0; radial < nradial; radial++) {
|
|
821
|
+
const a = ring * stride + radial;
|
|
822
|
+
const b = a + 1;
|
|
823
|
+
const c = a + stride;
|
|
824
|
+
const d = c + 1;
|
|
825
|
+
indices.push(a, b, d, a, d, c);
|
|
713
826
|
}
|
|
714
|
-
|
|
827
|
+
}
|
|
828
|
+
return {
|
|
829
|
+
...{ positions, normals, texCoords, indices },
|
|
830
|
+
indexArray: makeIndices(positions.length / 3, indices)
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
// ../../node_modules/@math.gl/geometry/dist/geometries/truncated-cone-geometry.js
|
|
835
|
+
var TruncatedConeGeometry = class extends Geometry {
|
|
836
|
+
constructor(props = {}) {
|
|
837
|
+
const { topRadius = 0, bottomRadius = 0, topCap = false, bottomCap = false, height = 1, nradial = 10, nvertical = 1, verticalAxis = "y" } = props;
|
|
838
|
+
assertNonNegative(topRadius, "topRadius");
|
|
839
|
+
assertNonNegative(bottomRadius, "bottomRadius");
|
|
840
|
+
if (topRadius === 0 && bottomRadius === 0)
|
|
841
|
+
throw new Error("At least one radius must be greater than zero");
|
|
842
|
+
assertPositive(height, "height");
|
|
843
|
+
assertSegments(nradial, "nradial", 3);
|
|
844
|
+
assertSegments(nvertical, "nvertical");
|
|
845
|
+
const positions = [];
|
|
846
|
+
const normals = [];
|
|
847
|
+
const texCoords = [];
|
|
848
|
+
const indices = [];
|
|
849
|
+
const stride = nradial + 1;
|
|
850
|
+
const slope = (bottomRadius - topRadius) / height;
|
|
851
|
+
const normalScale = 1 / Math.hypot(1, slope);
|
|
852
|
+
const addRing = (radius, y, normalRadius, normalY, v) => {
|
|
853
|
+
const ring = positions.length / 3 / stride;
|
|
854
|
+
for (let radial = 0; radial <= nradial; radial++) {
|
|
855
|
+
const u = radial / nradial;
|
|
856
|
+
const angle2 = u * Math.PI * 2;
|
|
857
|
+
const sin = Math.sin(angle2);
|
|
858
|
+
const cos = Math.cos(angle2);
|
|
859
|
+
const point = orient([sin * radius, y, cos * radius], verticalAxis);
|
|
860
|
+
const normal = orient([sin * normalRadius, normalY, cos * normalRadius], verticalAxis);
|
|
861
|
+
positions.push(...point);
|
|
862
|
+
normals.push(...normal);
|
|
863
|
+
texCoords.push(u, v);
|
|
864
|
+
}
|
|
865
|
+
return ring;
|
|
866
|
+
};
|
|
867
|
+
const connect = (lower, upper) => {
|
|
868
|
+
for (let radial = 0; radial < nradial; radial++) {
|
|
869
|
+
const a = lower * stride + radial;
|
|
870
|
+
const b = a + 1;
|
|
871
|
+
const c = upper * stride + radial;
|
|
872
|
+
const d = c + 1;
|
|
873
|
+
indices.push(a, b, d, a, d, c);
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
let previous;
|
|
877
|
+
if (bottomCap) {
|
|
878
|
+
const center = addRing(0, -height / 2, 0, -1, 0);
|
|
879
|
+
const edge = addRing(bottomRadius, -height / 2, 0, -1, 1);
|
|
880
|
+
connect(center, edge);
|
|
881
|
+
previous = addRing(bottomRadius, -height / 2, normalScale, slope * normalScale, 0);
|
|
882
|
+
}
|
|
883
|
+
for (let vertical = 0; vertical <= nvertical; vertical++) {
|
|
884
|
+
const v = vertical / nvertical;
|
|
885
|
+
const radius = bottomRadius + (topRadius - bottomRadius) * v;
|
|
886
|
+
const ring = addRing(radius, (v - 0.5) * height, normalScale, slope * normalScale, v);
|
|
887
|
+
if (previous !== void 0 && !(bottomCap && vertical === 0))
|
|
888
|
+
connect(previous, ring);
|
|
889
|
+
previous = ring;
|
|
890
|
+
}
|
|
891
|
+
if (topCap && previous !== void 0) {
|
|
892
|
+
const edge = addRing(topRadius, height / 2, 0, 1, 1);
|
|
893
|
+
const center = addRing(0, height / 2, 0, 1, 0);
|
|
894
|
+
connect(edge, center);
|
|
895
|
+
}
|
|
896
|
+
const vertexCount = positions.length / 3;
|
|
897
|
+
super({
|
|
898
|
+
id: props.id,
|
|
899
|
+
topology: "triangle-list",
|
|
900
|
+
indices: makeIndices(vertexCount, indices),
|
|
901
|
+
attributes: {
|
|
902
|
+
POSITION: { size: 3, value: new Float32Array(positions) },
|
|
903
|
+
NORMAL: { size: 3, value: new Float32Array(normals) },
|
|
904
|
+
TEXCOORD_0: { size: 2, value: new Float32Array(texCoords) },
|
|
905
|
+
...props.attributes
|
|
906
|
+
}
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
};
|
|
910
|
+
function orient(vector, axis) {
|
|
911
|
+
switch (axis) {
|
|
912
|
+
case "x":
|
|
913
|
+
return [vector[1], vector[2], vector[0]];
|
|
914
|
+
case "z":
|
|
915
|
+
return [vector[2], vector[0], vector[1]];
|
|
916
|
+
default:
|
|
917
|
+
return [vector[0], vector[1], vector[2]];
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// ../../node_modules/@math.gl/geometry/dist/geometries/plane-geometry.js
|
|
922
|
+
var PlaneGeometry = class extends Geometry {
|
|
923
|
+
constructor(props) {
|
|
924
|
+
const { sizeX, sizeZ, nx = 1, nz = 1 } = props;
|
|
925
|
+
assertPositive(sizeX, "sizeX");
|
|
926
|
+
assertPositive(sizeZ, "sizeZ");
|
|
927
|
+
assertSegments(nx, "nx");
|
|
928
|
+
assertSegments(nz, "nz");
|
|
929
|
+
const positions = [];
|
|
930
|
+
const normals = [];
|
|
931
|
+
const texCoords = [];
|
|
932
|
+
const indexValues = [];
|
|
933
|
+
for (let z = 0; z <= nz; z++) {
|
|
934
|
+
const v = z / nz;
|
|
935
|
+
for (let x = 0; x <= nx; x++) {
|
|
936
|
+
const u = x / nx;
|
|
937
|
+
positions.push((u - 0.5) * sizeX, 0, (0.5 - v) * sizeZ);
|
|
938
|
+
normals.push(0, 1, 0);
|
|
939
|
+
texCoords.push(u, v);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
const stride = nx + 1;
|
|
943
|
+
for (let z = 0; z < nz; z++) {
|
|
944
|
+
for (let x = 0; x < nx; x++) {
|
|
945
|
+
const a = z * stride + x;
|
|
946
|
+
const b = a + 1;
|
|
947
|
+
const c = a + stride;
|
|
948
|
+
const d = c + 1;
|
|
949
|
+
indexValues.push(a, b, d, a, d, c);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
const vertexCount = positions.length / 3;
|
|
953
|
+
super({
|
|
954
|
+
id: props.id,
|
|
955
|
+
topology: "triangle-list",
|
|
956
|
+
indices: makeIndices(vertexCount, indexValues),
|
|
957
|
+
attributes: {
|
|
958
|
+
POSITION: { size: 3, value: new Float32Array(positions) },
|
|
959
|
+
NORMAL: { size: 3, value: new Float32Array(normals) },
|
|
960
|
+
TEXCOORD_0: { size: 2, value: new Float32Array(texCoords) },
|
|
961
|
+
...props.attributes
|
|
962
|
+
}
|
|
963
|
+
});
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
// ../../node_modules/@math.gl/geometry/dist/geometries/sphere-geometry.js
|
|
968
|
+
var SphereGeometry = class extends Geometry {
|
|
969
|
+
constructor(props = {}) {
|
|
970
|
+
const { radius = 0.5, nlat = 10, nlong = 10 } = props;
|
|
971
|
+
assertPositive(radius, "radius");
|
|
972
|
+
assertSegments(nlat, "nlat", 2);
|
|
973
|
+
assertSegments(nlong, "nlong", 3);
|
|
974
|
+
const rings = [];
|
|
975
|
+
for (let latitude = 0; latitude <= nlat; latitude++) {
|
|
976
|
+
const angle2 = -Math.PI / 2 + latitude / nlat * Math.PI;
|
|
977
|
+
const normalRadius = Math.cos(angle2);
|
|
978
|
+
const normalY = Math.sin(angle2);
|
|
979
|
+
rings.push({ radius: radius * normalRadius, y: radius * normalY, normalRadius, normalY });
|
|
980
|
+
}
|
|
981
|
+
const mesh = makeSurfaceOfRevolution(rings, nlong);
|
|
982
|
+
super({
|
|
983
|
+
id: props.id,
|
|
984
|
+
topology: "triangle-list",
|
|
985
|
+
indices: mesh.indexArray,
|
|
986
|
+
attributes: {
|
|
987
|
+
POSITION: { size: 3, value: new Float32Array(mesh.positions) },
|
|
988
|
+
NORMAL: { size: 3, value: new Float32Array(mesh.normals) },
|
|
989
|
+
TEXCOORD_0: { size: 2, value: new Float32Array(mesh.texCoords) },
|
|
990
|
+
...props.attributes
|
|
991
|
+
}
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
};
|
|
995
|
+
|
|
996
|
+
// ../../node_modules/@math.gl/geometry/dist/geometries/ico-sphere-geometry.js
|
|
997
|
+
var IcoSphereGeometry = class extends Geometry {
|
|
998
|
+
constructor(props = {}) {
|
|
999
|
+
const { radius = 0.5, iterations = 0 } = props;
|
|
1000
|
+
assertPositive(radius, "radius");
|
|
1001
|
+
assertSegments(iterations, "iterations", 0);
|
|
1002
|
+
if (iterations > 8)
|
|
1003
|
+
throw new Error("iterations must be <= 8");
|
|
1004
|
+
const t = (1 + Math.sqrt(5)) / 2;
|
|
1005
|
+
const vertices = [
|
|
1006
|
+
[-1, t, 0],
|
|
1007
|
+
[1, t, 0],
|
|
1008
|
+
[-1, -t, 0],
|
|
1009
|
+
[1, -t, 0],
|
|
1010
|
+
[0, -1, t],
|
|
1011
|
+
[0, 1, t],
|
|
1012
|
+
[0, -1, -t],
|
|
1013
|
+
[0, 1, -t],
|
|
1014
|
+
[t, 0, -1],
|
|
1015
|
+
[t, 0, 1],
|
|
1016
|
+
[-t, 0, -1],
|
|
1017
|
+
[-t, 0, 1]
|
|
1018
|
+
].map(normalize);
|
|
1019
|
+
let faces = [
|
|
1020
|
+
[0, 11, 5],
|
|
1021
|
+
[0, 5, 1],
|
|
1022
|
+
[0, 1, 7],
|
|
1023
|
+
[0, 7, 10],
|
|
1024
|
+
[0, 10, 11],
|
|
1025
|
+
[1, 5, 9],
|
|
1026
|
+
[5, 11, 4],
|
|
1027
|
+
[11, 10, 2],
|
|
1028
|
+
[10, 7, 6],
|
|
1029
|
+
[7, 1, 8],
|
|
1030
|
+
[3, 9, 4],
|
|
1031
|
+
[3, 4, 2],
|
|
1032
|
+
[3, 2, 6],
|
|
1033
|
+
[3, 6, 8],
|
|
1034
|
+
[3, 8, 9],
|
|
1035
|
+
[4, 9, 5],
|
|
1036
|
+
[2, 4, 11],
|
|
1037
|
+
[6, 2, 10],
|
|
1038
|
+
[8, 6, 7],
|
|
1039
|
+
[9, 8, 1]
|
|
1040
|
+
].map((face) => face.map((index) => vertices[index]));
|
|
1041
|
+
for (let iteration = 0; iteration < iterations; iteration++) {
|
|
1042
|
+
const subdivided = [];
|
|
1043
|
+
for (const [a, b, c] of faces) {
|
|
1044
|
+
const ab = normalize([a[0] + b[0], a[1] + b[1], a[2] + b[2]]);
|
|
1045
|
+
const bc = normalize([b[0] + c[0], b[1] + c[1], b[2] + c[2]]);
|
|
1046
|
+
const ca = normalize([c[0] + a[0], c[1] + a[1], c[2] + a[2]]);
|
|
1047
|
+
subdivided.push([a, ab, ca], [b, bc, ab], [c, ca, bc], [ab, bc, ca]);
|
|
1048
|
+
}
|
|
1049
|
+
faces = subdivided;
|
|
1050
|
+
}
|
|
1051
|
+
const positions = [];
|
|
1052
|
+
const normals = [];
|
|
1053
|
+
const texCoords = [];
|
|
1054
|
+
for (const face of faces) {
|
|
1055
|
+
for (const normal of face) {
|
|
1056
|
+
positions.push(normal[0] * radius, normal[1] * radius, normal[2] * radius);
|
|
1057
|
+
normals.push(...normal);
|
|
1058
|
+
texCoords.push(0.5 + Math.atan2(normal[0], normal[2]) / (2 * Math.PI), 0.5 - Math.asin(normal[1]) / Math.PI);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
super({
|
|
1062
|
+
id: props.id,
|
|
1063
|
+
topology: "triangle-list",
|
|
1064
|
+
attributes: {
|
|
1065
|
+
POSITION: { size: 3, value: new Float32Array(positions) },
|
|
1066
|
+
NORMAL: { size: 3, value: new Float32Array(normals) },
|
|
1067
|
+
TEXCOORD_0: { size: 2, value: new Float32Array(texCoords) },
|
|
1068
|
+
...props.attributes
|
|
1069
|
+
}
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
function normalize(vector) {
|
|
1074
|
+
const length = Math.hypot(...vector);
|
|
1075
|
+
return vector.map((component) => component / length);
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
// src/geometry/geometry.ts
|
|
1079
|
+
var import_core2 = __toESM(require_core(), 1);
|
|
1080
|
+
var Geometry2 = class extends Geometry {
|
|
1081
|
+
bufferLayout;
|
|
1082
|
+
constructor(props) {
|
|
1083
|
+
const attributes = {};
|
|
1084
|
+
const sourceNames = /* @__PURE__ */ new Map();
|
|
1085
|
+
for (const [name, attribute] of Object.entries(props.attributes)) {
|
|
1086
|
+
const shaderName = getGeometryShaderAttributeName(name);
|
|
1087
|
+
const previousName = sourceNames.get(shaderName);
|
|
1088
|
+
if (previousName) delete attributes[previousName];
|
|
1089
|
+
sourceNames.set(shaderName, name);
|
|
1090
|
+
attributes[name] = attribute;
|
|
1091
|
+
}
|
|
1092
|
+
const sourceIndices = props.indices;
|
|
1093
|
+
const indices = sourceIndices instanceof Uint8Array ? new Uint16Array(sourceIndices) : sourceIndices && !ArrayBuffer.isView(sourceIndices) && sourceIndices.value instanceof Uint8Array ? { ...sourceIndices, value: new Uint16Array(sourceIndices.value) } : sourceIndices;
|
|
1094
|
+
super({ ...props, attributes, indices });
|
|
1095
|
+
for (const [name, input] of Object.entries(attributes)) {
|
|
1096
|
+
if (!ArrayBuffer.isView(input) && Object.isExtensible(input) && name !== "indices") {
|
|
1097
|
+
Object.assign(input, this.attributes[name]);
|
|
1098
|
+
this.attributes[name] = input;
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
this.bufferLayout = props.bufferLayout || getBufferLayoutFromGeometryAttributes(this.attributes);
|
|
715
1102
|
}
|
|
716
1103
|
};
|
|
717
1104
|
function getGeometryShaderAttributeName(attributeName) {
|
|
@@ -750,37 +1137,6 @@ var __exports__ = (() => {
|
|
|
750
1137
|
|
|
751
1138
|
// src/geometry/geometry-utils.ts
|
|
752
1139
|
var import_core3 = __toESM(require_core(), 1);
|
|
753
|
-
function unpackIndexedGeometry(geometry) {
|
|
754
|
-
const { indices, attributes } = geometry;
|
|
755
|
-
if (!indices) {
|
|
756
|
-
return geometry;
|
|
757
|
-
}
|
|
758
|
-
const vertexCount = indices.value.length;
|
|
759
|
-
const unpackedAttributes = {};
|
|
760
|
-
for (const attributeName in attributes) {
|
|
761
|
-
const attribute = attributes[attributeName];
|
|
762
|
-
if (!attribute) {
|
|
763
|
-
continue;
|
|
764
|
-
}
|
|
765
|
-
const { value, size } = attribute;
|
|
766
|
-
const constant = attribute["constant"];
|
|
767
|
-
if (constant || !size) {
|
|
768
|
-
continue;
|
|
769
|
-
}
|
|
770
|
-
const ArrayType = value.constructor;
|
|
771
|
-
const unpackedValue = new ArrayType(vertexCount * size);
|
|
772
|
-
for (let x = 0; x < vertexCount; ++x) {
|
|
773
|
-
const index = indices.value[x];
|
|
774
|
-
for (let i = 0; i < size; i++) {
|
|
775
|
-
unpackedValue[x * size + i] = value[index * size + i];
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
unpackedAttributes[attributeName] = { size, value: unpackedValue };
|
|
779
|
-
}
|
|
780
|
-
return {
|
|
781
|
-
attributes: Object.assign({}, attributes, unpackedAttributes)
|
|
782
|
-
};
|
|
783
|
-
}
|
|
784
1140
|
function makeInterleavedGeometry(geometry, options = {}) {
|
|
785
1141
|
const bufferName = options.bufferName || "geometry";
|
|
786
1142
|
if (isInterleavedGeometry(geometry, bufferName)) {
|
|
@@ -832,7 +1188,7 @@ var __exports__ = (() => {
|
|
|
832
1188
|
for (const attribute of interleavedAttributes) {
|
|
833
1189
|
writeInterleavedAttribute(arrayBuffer, attributeVertexCount, byteStride, attribute);
|
|
834
1190
|
}
|
|
835
|
-
return new
|
|
1191
|
+
return new Geometry2({
|
|
836
1192
|
id: geometry.id,
|
|
837
1193
|
topology: geometry.topology || "triangle-list",
|
|
838
1194
|
vertexCount: geometry.vertexCount,
|
|
@@ -859,17 +1215,20 @@ var __exports__ = (() => {
|
|
|
859
1215
|
});
|
|
860
1216
|
}
|
|
861
1217
|
function isInterleavedGeometry(geometry, bufferName) {
|
|
862
|
-
if (geometry.bufferLayout
|
|
1218
|
+
if (geometry.bufferLayout?.length !== 1) {
|
|
863
1219
|
return false;
|
|
864
1220
|
}
|
|
865
1221
|
const bufferLayout = geometry.bufferLayout[0];
|
|
866
1222
|
return bufferLayout.name === bufferName && Boolean(bufferLayout.attributes?.length) && Boolean(geometry.attributes[bufferName]);
|
|
867
1223
|
}
|
|
868
1224
|
function getInterleavedSourceAttributes(geometry, attributeNames) {
|
|
869
|
-
|
|
870
|
-
|
|
1225
|
+
const attributes = /* @__PURE__ */ new Map();
|
|
1226
|
+
const sourceNames = attributeNames || Object.keys(geometry.attributes);
|
|
1227
|
+
for (const name of sourceNames) {
|
|
1228
|
+
const attribute = geometry.attributes[name];
|
|
1229
|
+
if (attribute) attributes.set(getGeometryShaderAttributeName(name), [name, attribute]);
|
|
871
1230
|
}
|
|
872
|
-
return
|
|
1231
|
+
return Array.from(attributes.values());
|
|
873
1232
|
}
|
|
874
1233
|
function writeInterleavedAttribute(arrayBuffer, vertexCount, byteStride, attribute) {
|
|
875
1234
|
const ArrayType = attribute.value.constructor;
|
|
@@ -962,7 +1321,7 @@ var __exports__ = (() => {
|
|
|
962
1321
|
attributes[attributeName] = { ...source4, value: encodeMorphTargetAttribute(source4, values) };
|
|
963
1322
|
}
|
|
964
1323
|
}
|
|
965
|
-
const morphedGeometry = new
|
|
1324
|
+
const morphedGeometry = new Geometry2({
|
|
966
1325
|
id: geometry.id,
|
|
967
1326
|
topology: geometry.topology || "triangle-list",
|
|
968
1327
|
vertexCount: geometry.vertexCount,
|
|
@@ -4129,6 +4488,16 @@ var __exports__ = (() => {
|
|
|
4129
4488
|
|
|
4130
4489
|
// src/geometry/gpu-geometry.ts
|
|
4131
4490
|
var import_core7 = __toESM(require_core(), 1);
|
|
4491
|
+
|
|
4492
|
+
// src/utils/uid.ts
|
|
4493
|
+
var uidCounters = {};
|
|
4494
|
+
function uid(id = "id") {
|
|
4495
|
+
uidCounters[id] = uidCounters[id] || 1;
|
|
4496
|
+
const count = uidCounters[id]++;
|
|
4497
|
+
return `${id}-${count}`;
|
|
4498
|
+
}
|
|
4499
|
+
|
|
4500
|
+
// src/geometry/gpu-geometry.ts
|
|
4132
4501
|
var GPUGeometry = class {
|
|
4133
4502
|
/** Application-provided or generated identifier. */
|
|
4134
4503
|
id;
|
|
@@ -4207,7 +4576,7 @@ var __exports__ = (() => {
|
|
|
4207
4576
|
function getAttributeBuffersFromGeometry(device, geometry) {
|
|
4208
4577
|
const attributes = {};
|
|
4209
4578
|
for (const [attributeName, attribute] of Object.entries(geometry.attributes)) {
|
|
4210
|
-
const name = geometry.bufferLayout
|
|
4579
|
+
const name = geometry.bufferLayout?.find((bufferLayout) => bufferLayout.name === attributeName)?.name || getGeometryShaderAttributeName(attributeName);
|
|
4211
4580
|
if (attribute) {
|
|
4212
4581
|
attributes[name] = device.createBuffer({
|
|
4213
4582
|
data: attribute.value,
|
|
@@ -4217,7 +4586,7 @@ var __exports__ = (() => {
|
|
|
4217
4586
|
}
|
|
4218
4587
|
return {
|
|
4219
4588
|
attributes,
|
|
4220
|
-
bufferLayout: geometry.bufferLayout,
|
|
4589
|
+
bufferLayout: geometry.bufferLayout || getBufferLayoutFromGeometryAttributes(geometry.attributes),
|
|
4221
4590
|
vertexCount: geometry.vertexCount
|
|
4222
4591
|
};
|
|
4223
4592
|
}
|
|
@@ -4567,7 +4936,7 @@ var __exports__ = (() => {
|
|
|
4567
4936
|
var import_shadertools2 = __toESM(require_shadertools(), 1);
|
|
4568
4937
|
|
|
4569
4938
|
// ../../node_modules/@math.gl/types/dist/is-array.js
|
|
4570
|
-
function
|
|
4939
|
+
function isTypedArray2(value) {
|
|
4571
4940
|
return ArrayBuffer.isView(value) && !(value instanceof DataView);
|
|
4572
4941
|
}
|
|
4573
4942
|
function isNumberArray(value) {
|
|
@@ -4577,7 +4946,7 @@ var __exports__ = (() => {
|
|
|
4577
4946
|
return false;
|
|
4578
4947
|
}
|
|
4579
4948
|
function isNumericArray(value) {
|
|
4580
|
-
return
|
|
4949
|
+
return isTypedArray2(value) || isNumberArray(value);
|
|
4581
4950
|
}
|
|
4582
4951
|
|
|
4583
4952
|
// src/model/split-uniforms-and-bindings.ts
|
|
@@ -5184,6 +5553,7 @@ var __exports__ = (() => {
|
|
|
5184
5553
|
static defaultProps = {
|
|
5185
5554
|
...import_core13.RenderPipeline.defaultProps,
|
|
5186
5555
|
source: void 0,
|
|
5556
|
+
sourceLanguage: void 0,
|
|
5187
5557
|
vs: null,
|
|
5188
5558
|
fs: null,
|
|
5189
5559
|
id: "unnamed",
|
|
@@ -5339,6 +5709,7 @@ var __exports__ = (() => {
|
|
|
5339
5709
|
source: source4,
|
|
5340
5710
|
getUniforms: getUniforms2,
|
|
5341
5711
|
bindingTable,
|
|
5712
|
+
entryPoints = {},
|
|
5342
5713
|
shaderLayout: assembledShaderLayout
|
|
5343
5714
|
} = shaderAssembler.assembleWGSLShader({
|
|
5344
5715
|
platformInfo,
|
|
@@ -5350,6 +5721,8 @@ var __exports__ = (() => {
|
|
|
5350
5721
|
pluginVaryings: resolvedPlugins.varyings
|
|
5351
5722
|
});
|
|
5352
5723
|
this.source = source4;
|
|
5724
|
+
this.props.vertexEntryPoint = entryPoints.vertex || this.props.vertexEntryPoint;
|
|
5725
|
+
this.props.fragmentEntryPoint = entryPoints.fragment || this.props.fragmentEntryPoint;
|
|
5353
5726
|
this._getModuleUniforms = getUniforms2;
|
|
5354
5727
|
this._bindingTable = bindingTable;
|
|
5355
5728
|
const scannedOrReflectedShaderLayout = assembledShaderLayout ?? device.getShaderLayout?.(
|
|
@@ -5715,6 +6088,8 @@ var __exports__ = (() => {
|
|
|
5715
6088
|
}
|
|
5716
6089
|
/**
|
|
5717
6090
|
* Sets attributes (buffers)
|
|
6091
|
+
* @param options.byteOffsets Optional byte offsets, keyed by buffer name, where each buffer's
|
|
6092
|
+
* vertex data starts. Buffers without an entry are bound at offset 0.
|
|
5718
6093
|
* @note Overrides any attributes previously set with the same name
|
|
5719
6094
|
*/
|
|
5720
6095
|
setAttributes(buffers, options) {
|
|
@@ -5753,11 +6128,13 @@ var __exports__ = (() => {
|
|
|
5753
6128
|
}
|
|
5754
6129
|
continue;
|
|
5755
6130
|
}
|
|
5756
|
-
|
|
6131
|
+
const byteOffset = options?.byteOffsets?.[bufferName] ?? 0;
|
|
6132
|
+
this.vertexArray.setBuffer(bufferSlot, resolvedBuffer, byteOffset);
|
|
5757
6133
|
if (buffer instanceof DynamicBuffer) {
|
|
5758
6134
|
this._dynamicAttributeBufferSources[bufferSlot] = {
|
|
5759
6135
|
source: buffer,
|
|
5760
|
-
generation: buffer.generation
|
|
6136
|
+
generation: buffer.generation,
|
|
6137
|
+
byteOffset
|
|
5761
6138
|
};
|
|
5762
6139
|
} else {
|
|
5763
6140
|
delete this._dynamicAttributeBufferSources[bufferSlot];
|
|
@@ -6075,7 +6452,7 @@ var __exports__ = (() => {
|
|
|
6075
6452
|
}
|
|
6076
6453
|
for (const [locationKey, entry] of Object.entries(this._dynamicAttributeBufferSources)) {
|
|
6077
6454
|
if (entry.generation !== entry.source.generation) {
|
|
6078
|
-
this.vertexArray.setBuffer(Number(locationKey), entry.source.buffer);
|
|
6455
|
+
this.vertexArray.setBuffer(Number(locationKey), entry.source.buffer, entry.byteOffset);
|
|
6079
6456
|
entry.generation = entry.source.generation;
|
|
6080
6457
|
this.setNeedsRedraw("dynamic attribute buffer");
|
|
6081
6458
|
}
|
|
@@ -6669,26 +7046,30 @@ void main(void) {
|
|
|
6669
7046
|
}
|
|
6670
7047
|
`
|
|
6671
7048
|
);
|
|
6672
|
-
var
|
|
7049
|
+
var QUAD_POSITIONS = [-1, -1, 1, -1, -1, 1, 1, 1];
|
|
7050
|
+
var TRIANGLE_POSITIONS = [-1, -1, 3, -1, -1, 3];
|
|
6673
7051
|
var ClipSpace = class extends Model {
|
|
6674
7052
|
constructor(device, props) {
|
|
6675
|
-
const
|
|
6676
|
-
|
|
6677
|
-
|
|
6678
|
-
|
|
7053
|
+
const { geometryType = "quad", ...modelProps } = props;
|
|
7054
|
+
const positions = geometryType === "triangle" ? TRIANGLE_POSITIONS : QUAD_POSITIONS;
|
|
7055
|
+
const textureCoordinates = positions.map((position) => (position + 1) / 2);
|
|
7056
|
+
const vertexCount = positions.length / 2;
|
|
7057
|
+
if (modelProps.source) {
|
|
7058
|
+
modelProps.source = `${CLIPSPACE_VERTEX_SHADER_WGSL}
|
|
7059
|
+
${modelProps.source}`;
|
|
6679
7060
|
}
|
|
6680
7061
|
super(device, {
|
|
6681
|
-
id:
|
|
6682
|
-
...
|
|
7062
|
+
id: modelProps.id || uid("clip-space"),
|
|
7063
|
+
...modelProps,
|
|
6683
7064
|
vs: CLIPSPACE_VERTEX_SHADER,
|
|
6684
|
-
vertexCount
|
|
6685
|
-
geometry: new
|
|
6686
|
-
topology: "triangle-strip",
|
|
6687
|
-
vertexCount
|
|
7065
|
+
vertexCount,
|
|
7066
|
+
geometry: new Geometry2({
|
|
7067
|
+
topology: geometryType === "triangle" ? "triangle-list" : "triangle-strip",
|
|
7068
|
+
vertexCount,
|
|
6688
7069
|
attributes: {
|
|
6689
|
-
clipSpacePositions: { size: 2, value: new Float32Array(
|
|
6690
|
-
texCoords: { size: 2, value: new Float32Array(
|
|
6691
|
-
coordinates: { size: 2, value: new Float32Array(
|
|
7070
|
+
clipSpacePositions: { size: 2, value: new Float32Array(positions) },
|
|
7071
|
+
texCoords: { size: 2, value: new Float32Array(textureCoordinates) },
|
|
7072
|
+
coordinates: { size: 2, value: new Float32Array(textureCoordinates) }
|
|
6692
7073
|
}
|
|
6693
7074
|
})
|
|
6694
7075
|
});
|
|
@@ -7503,82 +7884,144 @@ void main(void) {
|
|
|
7503
7884
|
}
|
|
7504
7885
|
};
|
|
7505
7886
|
|
|
7506
|
-
// src/
|
|
7507
|
-
var
|
|
7887
|
+
// src/geometry/geometry-primitives.ts
|
|
7888
|
+
var CubeGeometry2 = class extends Geometry2 {
|
|
7508
7889
|
constructor(props = {}) {
|
|
7509
|
-
const
|
|
7510
|
-
const
|
|
7890
|
+
const source4 = new CubeGeometry({ size: 2 });
|
|
7891
|
+
const faceIndices = new Uint32Array(24);
|
|
7892
|
+
const faceOrder = [4, 5, 2, 3, 0, 1];
|
|
7893
|
+
for (let vertexIndex = 0; vertexIndex < faceIndices.length; vertexIndex++) {
|
|
7894
|
+
faceIndices[vertexIndex] = faceOrder[Math.floor(vertexIndex / 4)];
|
|
7895
|
+
}
|
|
7896
|
+
source4.attributes["faceIndex"] = { size: 1, value: faceIndices };
|
|
7897
|
+
if (props.indices === false) {
|
|
7898
|
+
source4.attributes["COLOR_0"] = {
|
|
7899
|
+
size: 3,
|
|
7900
|
+
value: new Float32Array(
|
|
7901
|
+
Array.from(source4.attributes["POSITION"].value, (value) => (value + 1) / 2)
|
|
7902
|
+
)
|
|
7903
|
+
};
|
|
7904
|
+
}
|
|
7905
|
+
const data = props.indices === false ? unpackIndexedGeometry(source4) : source4;
|
|
7511
7906
|
super({
|
|
7907
|
+
id: props.id,
|
|
7908
|
+
topology: source4.topology,
|
|
7909
|
+
indices: props.indices === false ? void 0 : source4.indices,
|
|
7910
|
+
attributes: mergeAttributes(data.attributes, props.attributes)
|
|
7911
|
+
});
|
|
7912
|
+
}
|
|
7913
|
+
};
|
|
7914
|
+
var SphereGeometry2 = class extends Geometry2 {
|
|
7915
|
+
constructor(props = {}) {
|
|
7916
|
+
const source4 = new SphereGeometry({
|
|
7512
7917
|
...props,
|
|
7513
|
-
|
|
7514
|
-
|
|
7515
|
-
|
|
7516
|
-
|
|
7918
|
+
attributes: void 0,
|
|
7919
|
+
radius: props.radius ?? 1
|
|
7920
|
+
});
|
|
7921
|
+
for (const name of ["POSITION", "NORMAL"]) {
|
|
7922
|
+
const values = source4.attributes[name].value;
|
|
7923
|
+
for (let index = 0; index < values.length; index += 3) {
|
|
7924
|
+
const horizontal = values[index];
|
|
7925
|
+
values[index] = values[index + 2];
|
|
7926
|
+
values[index + 2] = horizontal;
|
|
7927
|
+
}
|
|
7928
|
+
}
|
|
7929
|
+
const indices = source4.indices?.value;
|
|
7930
|
+
if (indices) {
|
|
7931
|
+
for (let index = 0; index < indices.length; index += 3) {
|
|
7932
|
+
const second = indices[index + 1];
|
|
7933
|
+
indices[index + 1] = indices[index + 2];
|
|
7934
|
+
indices[index + 2] = second;
|
|
7935
|
+
}
|
|
7936
|
+
}
|
|
7937
|
+
super({ ...source4, attributes: { ...source4.attributes, ...props.attributes } });
|
|
7938
|
+
}
|
|
7939
|
+
};
|
|
7940
|
+
var IcoSphereGeometry2 = class extends Geometry2 {
|
|
7941
|
+
constructor(props = {}) {
|
|
7942
|
+
const source4 = new IcoSphereGeometry({ ...props, radius: props.radius ?? 1 });
|
|
7943
|
+
super({ ...source4, attributes: source4.attributes });
|
|
7944
|
+
}
|
|
7945
|
+
};
|
|
7946
|
+
var TruncatedConeGeometry2 = class extends Geometry2 {
|
|
7947
|
+
constructor(props = {}) {
|
|
7948
|
+
const source4 = new TruncatedConeGeometry({ ...props, bottomRadius: props.bottomRadius ?? 1 });
|
|
7949
|
+
super({ ...source4, attributes: source4.attributes });
|
|
7950
|
+
}
|
|
7951
|
+
};
|
|
7952
|
+
var CylinderGeometry2 = class extends TruncatedConeGeometry2 {
|
|
7953
|
+
constructor(props = {}) {
|
|
7954
|
+
const radius = props.radius ?? 1;
|
|
7955
|
+
super({ ...props, topRadius: radius, bottomRadius: radius });
|
|
7956
|
+
}
|
|
7957
|
+
};
|
|
7958
|
+
var ConeGeometry2 = class extends TruncatedConeGeometry2 {
|
|
7959
|
+
constructor(props = {}) {
|
|
7960
|
+
const cap = props.cap ?? true;
|
|
7961
|
+
super({ ...props, topRadius: 0, bottomRadius: props.radius ?? 1, topCap: cap, bottomCap: cap });
|
|
7962
|
+
}
|
|
7963
|
+
};
|
|
7964
|
+
var PlaneGeometry2 = class extends Geometry2 {
|
|
7965
|
+
constructor(props = {}) {
|
|
7966
|
+
const { type = "x,y", offset = 0, flipCull = false } = props;
|
|
7967
|
+
const planeAxes = {
|
|
7968
|
+
"x,y": { sizeX: props.xlen, sizeZ: props.ylen, nx: props.nx, nz: props.ny },
|
|
7969
|
+
"x,z": { sizeX: props.xlen, sizeZ: props.zlen, nx: props.nx, nz: props.nz },
|
|
7970
|
+
"y,z": { sizeX: props.ylen, sizeZ: props.zlen, nx: props.ny, nz: props.nz }
|
|
7971
|
+
}[type];
|
|
7972
|
+
if (!planeAxes) throw new Error("Invalid plane axes");
|
|
7973
|
+
const source4 = new PlaneGeometry({
|
|
7974
|
+
sizeX: planeAxes.sizeX || 1,
|
|
7975
|
+
sizeZ: planeAxes.sizeZ || 1,
|
|
7976
|
+
nx: planeAxes.nx || 1,
|
|
7977
|
+
nz: planeAxes.nz || 1
|
|
7978
|
+
});
|
|
7979
|
+
orientPlane(source4, type, offset, flipCull);
|
|
7980
|
+
const data = props.unpack ? unpackIndexedGeometry(source4) : source4;
|
|
7981
|
+
super({
|
|
7982
|
+
id: props.id,
|
|
7983
|
+
topology: source4.topology,
|
|
7984
|
+
indices: props.unpack ? void 0 : source4.indices,
|
|
7985
|
+
attributes: mergeAttributes(data.attributes, props.attributes)
|
|
7517
7986
|
});
|
|
7518
7987
|
}
|
|
7519
7988
|
};
|
|
7520
|
-
function
|
|
7521
|
-
const
|
|
7522
|
-
const
|
|
7523
|
-
const
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
|
|
7529
|
-
|
|
7530
|
-
|
|
7531
|
-
|
|
7532
|
-
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
7538
|
-
const v = y / nlat;
|
|
7539
|
-
const index = x + y * (nlong + 1);
|
|
7540
|
-
const i2 = index * 2;
|
|
7541
|
-
const i3 = index * 3;
|
|
7542
|
-
const theta = longRange * u;
|
|
7543
|
-
const phi = latRange * v;
|
|
7544
|
-
const sinTheta = Math.sin(theta);
|
|
7545
|
-
const cosTheta = Math.cos(theta);
|
|
7546
|
-
const sinPhi = Math.sin(phi);
|
|
7547
|
-
const cosPhi = Math.cos(phi);
|
|
7548
|
-
const ux = cosTheta * sinPhi;
|
|
7549
|
-
const uy = cosPhi;
|
|
7550
|
-
const uz = sinTheta * sinPhi;
|
|
7551
|
-
const r = radius(ux, uy, uz, u, v);
|
|
7552
|
-
positions[i3 + 0] = r * ux;
|
|
7553
|
-
positions[i3 + 1] = r * uy;
|
|
7554
|
-
positions[i3 + 2] = r * uz;
|
|
7555
|
-
normals[i3 + 0] = ux;
|
|
7556
|
-
normals[i3 + 1] = uy;
|
|
7557
|
-
normals[i3 + 2] = uz;
|
|
7558
|
-
texCoords[i2 + 0] = u;
|
|
7559
|
-
texCoords[i2 + 1] = 1 - v;
|
|
7560
|
-
}
|
|
7561
|
-
}
|
|
7562
|
-
const numVertsAround = nlong + 1;
|
|
7563
|
-
for (let x = 0; x < nlong; x++) {
|
|
7564
|
-
for (let y = 0; y < nlat; y++) {
|
|
7565
|
-
const index = (x * nlat + y) * 6;
|
|
7566
|
-
indices[index + 0] = y * numVertsAround + x;
|
|
7567
|
-
indices[index + 1] = y * numVertsAround + x + 1;
|
|
7568
|
-
indices[index + 2] = (y + 1) * numVertsAround + x;
|
|
7569
|
-
indices[index + 3] = (y + 1) * numVertsAround + x;
|
|
7570
|
-
indices[index + 4] = y * numVertsAround + x + 1;
|
|
7571
|
-
indices[index + 5] = (y + 1) * numVertsAround + x + 1;
|
|
7989
|
+
function orientPlane(geometry, type, offset, flipCull) {
|
|
7990
|
+
const positions = geometry.attributes["POSITION"].value;
|
|
7991
|
+
const normals = geometry.attributes["NORMAL"].value;
|
|
7992
|
+
const texCoords = geometry.attributes["TEXCOORD_0"].value;
|
|
7993
|
+
for (let vertexIndex = 0; vertexIndex < positions.length / 3; vertexIndex++) {
|
|
7994
|
+
const positionIndex = vertexIndex * 3;
|
|
7995
|
+
const horizontal = Number(positions[positionIndex]) * (flipCull ? -1 : 1);
|
|
7996
|
+
const vertical = -Number(positions[positionIndex + 2]);
|
|
7997
|
+
const normal = flipCull ? 1 : -1;
|
|
7998
|
+
if (type === "x,y") {
|
|
7999
|
+
positions.set([horizontal, vertical, offset], positionIndex);
|
|
8000
|
+
normals.set([0, 0, normal], positionIndex);
|
|
8001
|
+
} else if (type === "x,z") {
|
|
8002
|
+
positions.set([horizontal, offset, vertical], positionIndex);
|
|
8003
|
+
normals.set([0, normal, 0], positionIndex);
|
|
8004
|
+
} else {
|
|
8005
|
+
positions.set([offset, horizontal, vertical], positionIndex);
|
|
8006
|
+
normals.set([normal, 0, 0], positionIndex);
|
|
7572
8007
|
}
|
|
8008
|
+
if (flipCull) texCoords[vertexIndex * 2] = 1 - Number(texCoords[vertexIndex * 2]);
|
|
7573
8009
|
}
|
|
7574
|
-
|
|
7575
|
-
indices
|
|
7576
|
-
|
|
7577
|
-
|
|
7578
|
-
|
|
7579
|
-
|
|
8010
|
+
if (type !== "x,z" && geometry.indices) {
|
|
8011
|
+
const indices = geometry.indices.value;
|
|
8012
|
+
for (let index = 0; index < indices.length; index += 3) {
|
|
8013
|
+
const second = indices[index + 1];
|
|
8014
|
+
indices[index + 1] = indices[index + 2];
|
|
8015
|
+
indices[index + 2] = second;
|
|
7580
8016
|
}
|
|
7581
|
-
}
|
|
8017
|
+
}
|
|
8018
|
+
}
|
|
8019
|
+
function mergeAttributes(source4, overrides = {}) {
|
|
8020
|
+
const attributes = {};
|
|
8021
|
+
for (const [name, attribute] of Object.entries(source4)) {
|
|
8022
|
+
if (attribute) attributes[name] = attribute;
|
|
8023
|
+
}
|
|
8024
|
+
return { ...attributes, ...overrides };
|
|
7582
8025
|
}
|
|
7583
8026
|
|
|
7584
8027
|
// src/models/light-model-utils.ts
|
|
@@ -7990,7 +8433,7 @@ void main(void) {
|
|
|
7990
8433
|
}
|
|
7991
8434
|
|
|
7992
8435
|
// src/models/point-light-model.ts
|
|
7993
|
-
var POINT_LIGHT_GEOMETRY = new
|
|
8436
|
+
var POINT_LIGHT_GEOMETRY = new SphereGeometry2({
|
|
7994
8437
|
nlat: 8,
|
|
7995
8438
|
nlong: 12,
|
|
7996
8439
|
radius: 1
|
|
@@ -8007,132 +8450,8 @@ void main(void) {
|
|
|
8007
8450
|
}
|
|
8008
8451
|
};
|
|
8009
8452
|
|
|
8010
|
-
// src/geometries/truncated-cone-geometry.ts
|
|
8011
|
-
var INDEX_OFFSETS = {
|
|
8012
|
-
x: [2, 0, 1],
|
|
8013
|
-
y: [0, 1, 2],
|
|
8014
|
-
z: [1, 2, 0]
|
|
8015
|
-
};
|
|
8016
|
-
var TruncatedConeGeometry = class extends Geometry {
|
|
8017
|
-
constructor(props = {}) {
|
|
8018
|
-
const { id = uid("truncated-code-geometry") } = props;
|
|
8019
|
-
const { indices, attributes } = tesselateTruncatedCone(props);
|
|
8020
|
-
super({
|
|
8021
|
-
...props,
|
|
8022
|
-
id,
|
|
8023
|
-
topology: "triangle-list",
|
|
8024
|
-
indices,
|
|
8025
|
-
attributes: {
|
|
8026
|
-
POSITION: { size: 3, value: attributes.POSITION },
|
|
8027
|
-
NORMAL: { size: 3, value: attributes.NORMAL },
|
|
8028
|
-
TEXCOORD_0: { size: 2, value: attributes.TEXCOORD_0 },
|
|
8029
|
-
...props.attributes
|
|
8030
|
-
}
|
|
8031
|
-
});
|
|
8032
|
-
}
|
|
8033
|
-
};
|
|
8034
|
-
function tesselateTruncatedCone(props = {}) {
|
|
8035
|
-
const {
|
|
8036
|
-
bottomRadius = 0,
|
|
8037
|
-
topRadius = 0,
|
|
8038
|
-
height = 1,
|
|
8039
|
-
nradial = 10,
|
|
8040
|
-
nvertical = 10,
|
|
8041
|
-
verticalAxis = "y",
|
|
8042
|
-
topCap = false,
|
|
8043
|
-
bottomCap = false
|
|
8044
|
-
} = props;
|
|
8045
|
-
const extra = (topCap ? 2 : 0) + (bottomCap ? 2 : 0);
|
|
8046
|
-
const numVertices = (nradial + 1) * (nvertical + 1 + extra);
|
|
8047
|
-
const slant = Math.atan2(bottomRadius - topRadius, height);
|
|
8048
|
-
const msin = Math.sin;
|
|
8049
|
-
const mcos = Math.cos;
|
|
8050
|
-
const mpi = Math.PI;
|
|
8051
|
-
const cosSlant = mcos(slant);
|
|
8052
|
-
const sinSlant = msin(slant);
|
|
8053
|
-
const start = topCap ? -2 : 0;
|
|
8054
|
-
const end = nvertical + (bottomCap ? 2 : 0);
|
|
8055
|
-
const vertsAroundEdge = nradial + 1;
|
|
8056
|
-
const indices = new Uint16Array(nradial * (nvertical + extra) * 6);
|
|
8057
|
-
const indexOffset = INDEX_OFFSETS[verticalAxis];
|
|
8058
|
-
const positions = new Float32Array(numVertices * 3);
|
|
8059
|
-
const normals = new Float32Array(numVertices * 3);
|
|
8060
|
-
const texCoords = new Float32Array(numVertices * 2);
|
|
8061
|
-
let i3 = 0;
|
|
8062
|
-
let i2 = 0;
|
|
8063
|
-
for (let i = start; i <= end; i++) {
|
|
8064
|
-
let v = i / nvertical;
|
|
8065
|
-
let y = height * v;
|
|
8066
|
-
let ringRadius;
|
|
8067
|
-
if (i < 0) {
|
|
8068
|
-
y = 0;
|
|
8069
|
-
v = 1;
|
|
8070
|
-
ringRadius = bottomRadius;
|
|
8071
|
-
} else if (i > nvertical) {
|
|
8072
|
-
y = height;
|
|
8073
|
-
v = 1;
|
|
8074
|
-
ringRadius = topRadius;
|
|
8075
|
-
} else {
|
|
8076
|
-
ringRadius = bottomRadius + (topRadius - bottomRadius) * (i / nvertical);
|
|
8077
|
-
}
|
|
8078
|
-
if (i === -2 || i === nvertical + 2) {
|
|
8079
|
-
ringRadius = 0;
|
|
8080
|
-
v = 0;
|
|
8081
|
-
}
|
|
8082
|
-
y -= height / 2;
|
|
8083
|
-
for (let j = 0; j < vertsAroundEdge; j++) {
|
|
8084
|
-
const sin = msin(j * mpi * 2 / nradial);
|
|
8085
|
-
const cos = mcos(j * mpi * 2 / nradial);
|
|
8086
|
-
positions[i3 + indexOffset[0]] = sin * ringRadius;
|
|
8087
|
-
positions[i3 + indexOffset[1]] = y;
|
|
8088
|
-
positions[i3 + indexOffset[2]] = cos * ringRadius;
|
|
8089
|
-
normals[i3 + indexOffset[0]] = i < 0 || i > nvertical ? 0 : sin * cosSlant;
|
|
8090
|
-
normals[i3 + indexOffset[1]] = i < 0 ? -1 : i > nvertical ? 1 : sinSlant;
|
|
8091
|
-
normals[i3 + indexOffset[2]] = i < 0 || i > nvertical ? 0 : cos * cosSlant;
|
|
8092
|
-
texCoords[i2 + 0] = j / nradial;
|
|
8093
|
-
texCoords[i2 + 1] = v;
|
|
8094
|
-
i2 += 2;
|
|
8095
|
-
i3 += 3;
|
|
8096
|
-
}
|
|
8097
|
-
}
|
|
8098
|
-
for (let i = 0; i < nvertical + extra; i++) {
|
|
8099
|
-
for (let j = 0; j < nradial; j++) {
|
|
8100
|
-
const index = (i * nradial + j) * 6;
|
|
8101
|
-
indices[index + 0] = vertsAroundEdge * (i + 0) + 0 + j;
|
|
8102
|
-
indices[index + 1] = vertsAroundEdge * (i + 0) + 1 + j;
|
|
8103
|
-
indices[index + 2] = vertsAroundEdge * (i + 1) + 1 + j;
|
|
8104
|
-
indices[index + 3] = vertsAroundEdge * (i + 0) + 0 + j;
|
|
8105
|
-
indices[index + 4] = vertsAroundEdge * (i + 1) + 1 + j;
|
|
8106
|
-
indices[index + 5] = vertsAroundEdge * (i + 1) + 0 + j;
|
|
8107
|
-
}
|
|
8108
|
-
}
|
|
8109
|
-
return {
|
|
8110
|
-
indices,
|
|
8111
|
-
attributes: {
|
|
8112
|
-
POSITION: positions,
|
|
8113
|
-
NORMAL: normals,
|
|
8114
|
-
TEXCOORD_0: texCoords
|
|
8115
|
-
}
|
|
8116
|
-
};
|
|
8117
|
-
}
|
|
8118
|
-
|
|
8119
|
-
// src/geometries/cone-geometry.ts
|
|
8120
|
-
var ConeGeometry = class extends TruncatedConeGeometry {
|
|
8121
|
-
constructor(props = {}) {
|
|
8122
|
-
const { id = uid("cone-geometry"), radius = 1, cap = true } = props;
|
|
8123
|
-
super({
|
|
8124
|
-
...props,
|
|
8125
|
-
id,
|
|
8126
|
-
topRadius: 0,
|
|
8127
|
-
topCap: Boolean(cap),
|
|
8128
|
-
bottomCap: Boolean(cap),
|
|
8129
|
-
bottomRadius: radius
|
|
8130
|
-
});
|
|
8131
|
-
}
|
|
8132
|
-
};
|
|
8133
|
-
|
|
8134
8453
|
// src/models/spot-light-model.ts
|
|
8135
|
-
var SPOT_LIGHT_GEOMETRY = new
|
|
8454
|
+
var SPOT_LIGHT_GEOMETRY = new ConeGeometry2({
|
|
8136
8455
|
cap: true,
|
|
8137
8456
|
nradial: 16,
|
|
8138
8457
|
nvertical: 1,
|
|
@@ -8151,7 +8470,7 @@ void main(void) {
|
|
|
8151
8470
|
};
|
|
8152
8471
|
|
|
8153
8472
|
// src/models/directional-light-model.ts
|
|
8154
|
-
var DIRECTIONAL_LIGHT_GEOMETRY = new
|
|
8473
|
+
var DIRECTIONAL_LIGHT_GEOMETRY = new ConeGeometry2({
|
|
8155
8474
|
cap: true,
|
|
8156
8475
|
nradial: 12,
|
|
8157
8476
|
nvertical: 1,
|
|
@@ -8511,13 +8830,332 @@ void main(void) {
|
|
|
8511
8830
|
return areScenegraphBoundsDefined(instancedBounds) ? instancedBounds : null;
|
|
8512
8831
|
}
|
|
8513
8832
|
|
|
8514
|
-
// src/geometry/
|
|
8833
|
+
// src/geometry/edge-geometry.ts
|
|
8515
8834
|
var import_core23 = __toESM(require_core(), 1);
|
|
8835
|
+
function makeEdgeGeometry(geometry, options = {}) {
|
|
8836
|
+
const { angleThreshold = 30, weldTolerance = 0, positionAttribute = "POSITION" } = options;
|
|
8837
|
+
const positions = getTrianglePositions(geometry, positionAttribute);
|
|
8838
|
+
(0, import_core23.assert)(Number.isFinite(weldTolerance) && weldTolerance >= 0);
|
|
8839
|
+
(0, import_core23.assert)(Number.isFinite(angleThreshold) && angleThreshold >= 0 && angleThreshold <= 180);
|
|
8840
|
+
const sourceIndices = geometry.indices?.value;
|
|
8841
|
+
const sourceCount = positions.value.length / 3;
|
|
8842
|
+
const representatives = /* @__PURE__ */ new Map();
|
|
8843
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
8844
|
+
const faces = /* @__PURE__ */ new Set();
|
|
8845
|
+
const edges = /* @__PURE__ */ new Map();
|
|
8846
|
+
const cosineThreshold = Math.cos(angleThreshold * Math.PI / 180);
|
|
8847
|
+
const toleranceSquared = weldTolerance * weldTolerance;
|
|
8848
|
+
function readPosition(index) {
|
|
8849
|
+
return [
|
|
8850
|
+
positions.value[index * 3],
|
|
8851
|
+
positions.value[index * 3 + 1],
|
|
8852
|
+
positions.value[index * 3 + 2]
|
|
8853
|
+
];
|
|
8854
|
+
}
|
|
8855
|
+
function weldPosition(index) {
|
|
8856
|
+
const cached = representatives.get(index);
|
|
8857
|
+
if (cached !== void 0) return cached;
|
|
8858
|
+
(0, import_core23.assert)(Number.isInteger(index) && index >= 0 && index < sourceCount);
|
|
8859
|
+
const position = readPosition(index);
|
|
8860
|
+
(0, import_core23.assert)(position.every(Number.isFinite));
|
|
8861
|
+
const cell = weldTolerance > 0 ? position.map((value) => Math.floor(value / weldTolerance)) : position;
|
|
8862
|
+
const radius = weldTolerance > 0 ? 1 : 0;
|
|
8863
|
+
for (let east = -radius; east <= radius; east++) {
|
|
8864
|
+
for (let north = -radius; north <= radius; north++) {
|
|
8865
|
+
for (let up = -radius; up <= radius; up++) {
|
|
8866
|
+
const candidates = buckets.get(`${cell[0] + east},${cell[1] + north},${cell[2] + up}`);
|
|
8867
|
+
for (const candidate of candidates || []) {
|
|
8868
|
+
const other = readPosition(candidate);
|
|
8869
|
+
const distanceSquared = (position[0] - other[0]) ** 2 + (position[1] - other[1]) ** 2 + (position[2] - other[2]) ** 2;
|
|
8870
|
+
if (distanceSquared <= toleranceSquared) {
|
|
8871
|
+
representatives.set(index, candidate);
|
|
8872
|
+
return candidate;
|
|
8873
|
+
}
|
|
8874
|
+
}
|
|
8875
|
+
}
|
|
8876
|
+
}
|
|
8877
|
+
}
|
|
8878
|
+
const key = cell.join(",");
|
|
8879
|
+
const bucket = buckets.get(key) || [];
|
|
8880
|
+
bucket.push(index);
|
|
8881
|
+
buckets.set(key, bucket);
|
|
8882
|
+
representatives.set(index, index);
|
|
8883
|
+
return index;
|
|
8884
|
+
}
|
|
8885
|
+
function addEdge(first, second, normal) {
|
|
8886
|
+
const start = Math.min(first, second);
|
|
8887
|
+
const end = Math.max(first, second);
|
|
8888
|
+
const key = `${start},${end}`;
|
|
8889
|
+
const edge = edges.get(key);
|
|
8890
|
+
if (edge) {
|
|
8891
|
+
edge.faceCount++;
|
|
8892
|
+
const cosine = normal[0] * edge.normal[0] + normal[1] * edge.normal[1] + normal[2] * edge.normal[2];
|
|
8893
|
+
edge.crease ||= cosine < 1 - 1e-7 && cosine <= cosineThreshold + 1e-7;
|
|
8894
|
+
} else {
|
|
8895
|
+
edges.set(key, { start, end, normal, faceCount: 1, crease: false });
|
|
8896
|
+
}
|
|
8897
|
+
}
|
|
8898
|
+
for (let offset = 0; offset < geometry.vertexCount; offset += 3) {
|
|
8899
|
+
const first = weldPosition(sourceIndices?.[offset] ?? offset);
|
|
8900
|
+
const second = weldPosition(sourceIndices?.[offset + 1] ?? offset + 1);
|
|
8901
|
+
const third = weldPosition(sourceIndices?.[offset + 2] ?? offset + 2);
|
|
8902
|
+
if (first === second || second === third || third === first) continue;
|
|
8903
|
+
const faceKey = [first, second, third].sort((left, right) => left - right).join(",");
|
|
8904
|
+
if (faces.has(faceKey)) continue;
|
|
8905
|
+
faces.add(faceKey);
|
|
8906
|
+
const start = readPosition(first);
|
|
8907
|
+
const end = readPosition(second);
|
|
8908
|
+
const corner = readPosition(third);
|
|
8909
|
+
const firstDirection = end.map((value, axis) => value - start[axis]);
|
|
8910
|
+
const secondDirection = corner.map((value, axis) => value - start[axis]);
|
|
8911
|
+
const normal = [
|
|
8912
|
+
firstDirection[1] * secondDirection[2] - firstDirection[2] * secondDirection[1],
|
|
8913
|
+
firstDirection[2] * secondDirection[0] - firstDirection[0] * secondDirection[2],
|
|
8914
|
+
firstDirection[0] * secondDirection[1] - firstDirection[1] * secondDirection[0]
|
|
8915
|
+
];
|
|
8916
|
+
const magnitude = Math.hypot(...normal);
|
|
8917
|
+
if (magnitude === 0) continue;
|
|
8918
|
+
normal[0] /= magnitude;
|
|
8919
|
+
normal[1] /= magnitude;
|
|
8920
|
+
normal[2] /= magnitude;
|
|
8921
|
+
addEdge(first, second, normal);
|
|
8922
|
+
addEdge(second, third, normal);
|
|
8923
|
+
addEdge(third, first, normal);
|
|
8924
|
+
}
|
|
8925
|
+
const selected = [...edges.values()].filter((edge) => options.includeCoplanarEdges || edge.faceCount !== 2 || edge.crease).sort((left, right) => left.start - right.start || left.end - right.end);
|
|
8926
|
+
return new Geometry2({
|
|
8927
|
+
id: `${geometry.id}-edges`,
|
|
8928
|
+
topology: "line-list",
|
|
8929
|
+
attributes: { [positionAttribute]: positions },
|
|
8930
|
+
indices: new Uint32Array(selected.flatMap((edge) => [edge.start, edge.end]))
|
|
8931
|
+
});
|
|
8932
|
+
}
|
|
8933
|
+
function makeEdgeGeometryFromGeometries(geometries, options = {}) {
|
|
8934
|
+
(0, import_core23.assert)(geometries.length > 0);
|
|
8935
|
+
const positionAttribute = options.positionAttribute ?? "POSITION";
|
|
8936
|
+
const attributes = geometries.map((geometry) => getTrianglePositions(geometry, positionAttribute));
|
|
8937
|
+
const firstAttribute = attributes[0];
|
|
8938
|
+
(0, import_core23.assert)(
|
|
8939
|
+
attributes.every(
|
|
8940
|
+
(attribute) => attribute.value.constructor === firstAttribute.value.constructor && Boolean(attribute["normalized"]) === Boolean(firstAttribute["normalized"])
|
|
8941
|
+
)
|
|
8942
|
+
);
|
|
8943
|
+
const PositionArray = firstAttribute.value.constructor;
|
|
8944
|
+
const positions = new PositionArray(
|
|
8945
|
+
attributes.reduce((count, attribute) => count + attribute.value.length, 0)
|
|
8946
|
+
);
|
|
8947
|
+
const indices = new Uint32Array(
|
|
8948
|
+
geometries.reduce((count, geometry) => count + geometry.vertexCount, 0)
|
|
8949
|
+
);
|
|
8950
|
+
let positionOffset = 0;
|
|
8951
|
+
let indexOffset = 0;
|
|
8952
|
+
for (const [geometryIndex, geometry] of geometries.entries()) {
|
|
8953
|
+
const attribute = attributes[geometryIndex];
|
|
8954
|
+
positions.set(attribute.value, positionOffset);
|
|
8955
|
+
for (let offset = 0; offset < geometry.vertexCount; offset++) {
|
|
8956
|
+
const index = geometry.indices?.value[offset] ?? offset;
|
|
8957
|
+
(0, import_core23.assert)(Number.isInteger(index) && index >= 0 && index < attribute.value.length / 3);
|
|
8958
|
+
indices[indexOffset++] = index + positionOffset / 3;
|
|
8959
|
+
}
|
|
8960
|
+
positionOffset += attribute.value.length;
|
|
8961
|
+
}
|
|
8962
|
+
return makeEdgeGeometry(
|
|
8963
|
+
new Geometry2({
|
|
8964
|
+
id: `${geometries[0].id}-batch`,
|
|
8965
|
+
topology: "triangle-list",
|
|
8966
|
+
attributes: { [positionAttribute]: { ...firstAttribute, value: positions } },
|
|
8967
|
+
indices
|
|
8968
|
+
}),
|
|
8969
|
+
options
|
|
8970
|
+
);
|
|
8971
|
+
}
|
|
8972
|
+
function getTrianglePositions(geometry, positionAttribute) {
|
|
8973
|
+
const positions = geometry.attributes[positionAttribute];
|
|
8974
|
+
(0, import_core23.assert)(geometry.topology === "triangle-list" && positions?.size === 3);
|
|
8975
|
+
(0, import_core23.assert)(positions.value.length % 3 === 0 && geometry.vertexCount % 3 === 0);
|
|
8976
|
+
(0, import_core23.assert)(
|
|
8977
|
+
!positions["byteStride"] || positions["byteStride"] === positions.value.BYTES_PER_ELEMENT * 3
|
|
8978
|
+
);
|
|
8979
|
+
(0, import_core23.assert)(
|
|
8980
|
+
geometry.vertexCount >= 0 && geometry.vertexCount <= (geometry.indices?.value.length ?? positions.value.length / 3)
|
|
8981
|
+
);
|
|
8982
|
+
return positions;
|
|
8983
|
+
}
|
|
8984
|
+
|
|
8985
|
+
// src/geometry/stroke-geometry.ts
|
|
8986
|
+
var import_core24 = __toESM(require_core(), 1);
|
|
8987
|
+
function makeStrokeGeometry(path, options = {}) {
|
|
8988
|
+
const { width = 1, cap = "butt", join = "miter", miterLimit = 4, roundSegments = 16 } = options;
|
|
8989
|
+
(0, import_core24.assert)(Number.isFinite(width) && width >= 0 && Number.isFinite(miterLimit) && miterLimit >= 1);
|
|
8990
|
+
(0, import_core24.assert)(Number.isInteger(roundSegments) && roundSegments >= 2 && roundSegments <= 256);
|
|
8991
|
+
const points = [];
|
|
8992
|
+
for (const position of path) {
|
|
8993
|
+
(0, import_core24.assert)(
|
|
8994
|
+
Number.isFinite(position[0]) && Number.isFinite(position[1]) && Number.isFinite(position[2] ?? 0)
|
|
8995
|
+
);
|
|
8996
|
+
const previous = points.at(-1);
|
|
8997
|
+
if (!previous || previous[0] !== position[0] || previous[1] !== position[1])
|
|
8998
|
+
points.push([position[0], position[1], position[2] ?? 0]);
|
|
8999
|
+
}
|
|
9000
|
+
if (options.closed && points.length > 1 && points[0][0] === points.at(-1)[0] && points[0][1] === points.at(-1)[1])
|
|
9001
|
+
points.pop();
|
|
9002
|
+
const closed = Boolean(options.closed && points.length > 2);
|
|
9003
|
+
const positions = [];
|
|
9004
|
+
const coordinates = [];
|
|
9005
|
+
const halfWidth = width / 2;
|
|
9006
|
+
if (points.length > 1 && width > 0) {
|
|
9007
|
+
const segments = [];
|
|
9008
|
+
const distances = [0];
|
|
9009
|
+
for (let index = 0; index < points.length - (closed ? 0 : 1); index++) {
|
|
9010
|
+
const start = points[index];
|
|
9011
|
+
const end = points[(index + 1) % points.length];
|
|
9012
|
+
const horizontal = end[0] - start[0];
|
|
9013
|
+
const vertical = end[1] - start[1];
|
|
9014
|
+
const length = Math.hypot(horizontal, vertical);
|
|
9015
|
+
segments.push({ direction: [horizontal / length, vertical / length], length });
|
|
9016
|
+
distances.push(distances.at(-1) + length);
|
|
9017
|
+
}
|
|
9018
|
+
const corners = points.map((point, index) => {
|
|
9019
|
+
const previous = segments[(index - 1 + segments.length) % segments.length];
|
|
9020
|
+
const next = segments[index % segments.length];
|
|
9021
|
+
const distance = distances[index];
|
|
9022
|
+
if (!closed && (index === 0 || index === points.length - 1)) {
|
|
9023
|
+
const direction = index === 0 ? next.direction : previous.direction;
|
|
9024
|
+
const extension = cap === "square" ? index === 0 ? -halfWidth : halfWidth : 0;
|
|
9025
|
+
const left = createVertex(point, direction, halfWidth, extension, distance + extension);
|
|
9026
|
+
const right = createVertex(point, direction, -halfWidth, extension, distance + extension);
|
|
9027
|
+
if (cap === "round") appendCap(point, direction, distance, index === 0);
|
|
9028
|
+
return { incomingLeft: left, outgoingLeft: left, incomingRight: right, outgoingRight: right };
|
|
9029
|
+
}
|
|
9030
|
+
const incoming = previous.direction;
|
|
9031
|
+
const outgoing = next.direction;
|
|
9032
|
+
const turn = incoming[0] * outgoing[1] - incoming[1] * outgoing[0];
|
|
9033
|
+
const cosine = incoming[0] * outgoing[0] + incoming[1] * outgoing[1];
|
|
9034
|
+
const result = {
|
|
9035
|
+
incomingLeft: createVertex(point, incoming, halfWidth, 0, distance),
|
|
9036
|
+
incomingRight: createVertex(point, incoming, -halfWidth, 0, distance),
|
|
9037
|
+
outgoingLeft: createVertex(point, outgoing, halfWidth, 0, distance),
|
|
9038
|
+
outgoingRight: createVertex(point, outgoing, -halfWidth, 0, distance)
|
|
9039
|
+
};
|
|
9040
|
+
if (1 + cosine < 1e-8) {
|
|
9041
|
+
if (join === "round") {
|
|
9042
|
+
appendCap(point, incoming, distance, false);
|
|
9043
|
+
appendCap(point, outgoing, distance, true);
|
|
9044
|
+
}
|
|
9045
|
+
return result;
|
|
9046
|
+
}
|
|
9047
|
+
const miter = [
|
|
9048
|
+
-(incoming[1] + outgoing[1]) * halfWidth / (1 + cosine),
|
|
9049
|
+
(incoming[0] + outgoing[0]) * halfWidth / (1 + cosine)
|
|
9050
|
+
];
|
|
9051
|
+
const miterLength = Math.hypot(...miter);
|
|
9052
|
+
if (Math.abs(turn) < 1e-8 || join === "miter" && miterLength <= miterLimit * halfWidth) {
|
|
9053
|
+
const left = offsetVertex(point, miter, distance, halfWidth);
|
|
9054
|
+
const right = offsetVertex(point, [-miter[0], -miter[1]], distance, -halfWidth);
|
|
9055
|
+
return { incomingLeft: left, outgoingLeft: left, incomingRight: right, outgoingRight: right };
|
|
9056
|
+
}
|
|
9057
|
+
const innerSide = Math.sign(turn);
|
|
9058
|
+
const innerScale = Math.min(1, Math.min(previous.length, next.length) / (2 * miterLength));
|
|
9059
|
+
const inner = offsetVertex(
|
|
9060
|
+
point,
|
|
9061
|
+
[miter[0] * innerSide * innerScale, miter[1] * innerSide * innerScale],
|
|
9062
|
+
distance,
|
|
9063
|
+
halfWidth * innerSide
|
|
9064
|
+
);
|
|
9065
|
+
if (innerSide > 0) {
|
|
9066
|
+
result.incomingLeft = inner;
|
|
9067
|
+
result.outgoingLeft = inner;
|
|
9068
|
+
} else {
|
|
9069
|
+
result.incomingRight = inner;
|
|
9070
|
+
result.outgoingRight = inner;
|
|
9071
|
+
}
|
|
9072
|
+
const outerStart = innerSide > 0 ? result.incomingRight : result.incomingLeft;
|
|
9073
|
+
const outerEnd = innerSide > 0 ? result.outgoingRight : result.outgoingLeft;
|
|
9074
|
+
if (join === "round") {
|
|
9075
|
+
const sweep = Math.atan2(turn, cosine);
|
|
9076
|
+
const startAngle = Math.atan2(
|
|
9077
|
+
outerStart.position[1] - point[1],
|
|
9078
|
+
outerStart.position[0] - point[0]
|
|
9079
|
+
);
|
|
9080
|
+
const steps = Math.max(1, Math.ceil(Math.abs(sweep) / Math.PI * roundSegments));
|
|
9081
|
+
let previousOuter = outerStart;
|
|
9082
|
+
for (let step = 1; step <= steps; step++) {
|
|
9083
|
+
const angle2 = startAngle + sweep * step / steps;
|
|
9084
|
+
const currentOuter = step === steps ? outerEnd : offsetVertex(
|
|
9085
|
+
point,
|
|
9086
|
+
[Math.cos(angle2) * halfWidth, Math.sin(angle2) * halfWidth],
|
|
9087
|
+
distance,
|
|
9088
|
+
-halfWidth * innerSide
|
|
9089
|
+
);
|
|
9090
|
+
appendTriangle(inner, previousOuter, currentOuter);
|
|
9091
|
+
previousOuter = currentOuter;
|
|
9092
|
+
}
|
|
9093
|
+
} else appendTriangle(inner, outerStart, outerEnd);
|
|
9094
|
+
return result;
|
|
9095
|
+
});
|
|
9096
|
+
segments.forEach((_segment, index) => {
|
|
9097
|
+
const start = corners[index];
|
|
9098
|
+
const end = corners[(index + 1) % corners.length];
|
|
9099
|
+
const closing = closed && index === segments.length - 1;
|
|
9100
|
+
const endLeft = closing ? { ...end.incomingLeft, distance: distances.at(-1) } : end.incomingLeft;
|
|
9101
|
+
const endRight = closing ? { ...end.incomingRight, distance: distances.at(-1) } : end.incomingRight;
|
|
9102
|
+
appendTriangle(start.outgoingLeft, start.outgoingRight, endLeft);
|
|
9103
|
+
appendTriangle(start.outgoingRight, endRight, endLeft);
|
|
9104
|
+
});
|
|
9105
|
+
}
|
|
9106
|
+
return new Geometry2({
|
|
9107
|
+
id: options.id,
|
|
9108
|
+
topology: "triangle-list",
|
|
9109
|
+
attributes: {
|
|
9110
|
+
POSITION: { size: 3, value: new Float32Array(positions) },
|
|
9111
|
+
TEXCOORD_0: { size: 2, value: new Float32Array(coordinates) }
|
|
9112
|
+
}
|
|
9113
|
+
});
|
|
9114
|
+
function appendTriangle(first, second, third) {
|
|
9115
|
+
const area = (second.position[0] - first.position[0]) * (third.position[1] - first.position[1]) - (second.position[1] - first.position[1]) * (third.position[0] - first.position[0]);
|
|
9116
|
+
if (area === 0) return;
|
|
9117
|
+
for (const vertex of area > 0 ? [first, second, third] : [first, third, second]) {
|
|
9118
|
+
positions.push(...vertex.position);
|
|
9119
|
+
coordinates.push(vertex.distance, vertex.across);
|
|
9120
|
+
}
|
|
9121
|
+
}
|
|
9122
|
+
function offsetVertex(point, offset, distance, across) {
|
|
9123
|
+
return { position: [point[0] + offset[0], point[1] + offset[1], point[2]], distance, across };
|
|
9124
|
+
}
|
|
9125
|
+
function createVertex(point, direction, across, along, distance) {
|
|
9126
|
+
return offsetVertex(
|
|
9127
|
+
point,
|
|
9128
|
+
[-direction[1] * across + direction[0] * along, direction[0] * across + direction[1] * along],
|
|
9129
|
+
distance,
|
|
9130
|
+
across
|
|
9131
|
+
);
|
|
9132
|
+
}
|
|
9133
|
+
function appendCap(point, direction, distance, start) {
|
|
9134
|
+
const center = { position: point, distance, across: 0 };
|
|
9135
|
+
const startAngle = Math.atan2(direction[1], direction[0]) + (start ? -Math.PI / 2 : Math.PI / 2);
|
|
9136
|
+
let previous;
|
|
9137
|
+
for (let step = 0; step <= roundSegments; step++) {
|
|
9138
|
+
const angle2 = startAngle - Math.PI * step / roundSegments;
|
|
9139
|
+
const offset = [Math.cos(angle2) * halfWidth, Math.sin(angle2) * halfWidth];
|
|
9140
|
+
const current = offsetVertex(
|
|
9141
|
+
point,
|
|
9142
|
+
offset,
|
|
9143
|
+
distance + offset[0] * direction[0] + offset[1] * direction[1],
|
|
9144
|
+
-offset[0] * direction[1] + offset[1] * direction[0]
|
|
9145
|
+
);
|
|
9146
|
+
if (previous) appendTriangle(center, previous, current);
|
|
9147
|
+
previous = current;
|
|
9148
|
+
}
|
|
9149
|
+
}
|
|
9150
|
+
}
|
|
9151
|
+
|
|
9152
|
+
// src/geometry/mesh-simplification.ts
|
|
9153
|
+
var import_core25 = __toESM(require_core(), 1);
|
|
8516
9154
|
var QUADRIC_COMPONENTS = 10;
|
|
8517
9155
|
var BOUNDARY_COLLINEAR_TOLERANCE = 1e-10;
|
|
8518
9156
|
function simplifyMesh(options) {
|
|
8519
9157
|
const { positions, indices, attributes = [], preserveBoundary = true } = options;
|
|
8520
|
-
(0,
|
|
9158
|
+
(0, import_core25.assert)(indices.length % 3 === 0 && positions.length % 3 === 0);
|
|
8521
9159
|
const targetIndexCount = Math.max(
|
|
8522
9160
|
0,
|
|
8523
9161
|
Math.min(
|
|
@@ -8610,7 +9248,7 @@ void main(void) {
|
|
|
8610
9248
|
const firstVertex = indices[indexOffset2];
|
|
8611
9249
|
const secondVertex = indices[indexOffset2 + 1];
|
|
8612
9250
|
const thirdVertex = indices[indexOffset2 + 2];
|
|
8613
|
-
(0,
|
|
9251
|
+
(0, import_core25.assert)(firstVertex < vertexCount && secondVertex < vertexCount && thirdVertex < vertexCount);
|
|
8614
9252
|
const triangle = {
|
|
8615
9253
|
vertices: [firstVertex, secondVertex, thirdVertex],
|
|
8616
9254
|
active: false
|
|
@@ -8883,936 +9521,6 @@ void main(void) {
|
|
|
8883
9521
|
return first.cost - second.cost || first.retainedVertex - second.retainedVertex || first.removedVertex - second.removedVertex;
|
|
8884
9522
|
}
|
|
8885
9523
|
|
|
8886
|
-
// src/geometries/cube-geometry.ts
|
|
8887
|
-
var CubeGeometry = class extends Geometry {
|
|
8888
|
-
constructor(props = {}) {
|
|
8889
|
-
const { id = uid("cube-geometry"), indices = true } = props;
|
|
8890
|
-
super(
|
|
8891
|
-
indices ? {
|
|
8892
|
-
...props,
|
|
8893
|
-
id,
|
|
8894
|
-
topology: "triangle-list",
|
|
8895
|
-
indices: { size: 1, value: CUBE_INDICES },
|
|
8896
|
-
attributes: { ...ATTRIBUTES, ...props.attributes }
|
|
8897
|
-
} : {
|
|
8898
|
-
...props,
|
|
8899
|
-
id,
|
|
8900
|
-
topology: "triangle-list",
|
|
8901
|
-
indices: void 0,
|
|
8902
|
-
attributes: { ...NON_INDEXED_ATTRIBUTES, ...props.attributes }
|
|
8903
|
-
}
|
|
8904
|
-
);
|
|
8905
|
-
}
|
|
8906
|
-
};
|
|
8907
|
-
var CUBE_INDICES = new Uint16Array([
|
|
8908
|
-
0,
|
|
8909
|
-
1,
|
|
8910
|
-
2,
|
|
8911
|
-
0,
|
|
8912
|
-
2,
|
|
8913
|
-
3,
|
|
8914
|
-
4,
|
|
8915
|
-
5,
|
|
8916
|
-
6,
|
|
8917
|
-
4,
|
|
8918
|
-
6,
|
|
8919
|
-
7,
|
|
8920
|
-
8,
|
|
8921
|
-
9,
|
|
8922
|
-
10,
|
|
8923
|
-
8,
|
|
8924
|
-
10,
|
|
8925
|
-
11,
|
|
8926
|
-
12,
|
|
8927
|
-
13,
|
|
8928
|
-
14,
|
|
8929
|
-
12,
|
|
8930
|
-
14,
|
|
8931
|
-
15,
|
|
8932
|
-
16,
|
|
8933
|
-
17,
|
|
8934
|
-
18,
|
|
8935
|
-
16,
|
|
8936
|
-
18,
|
|
8937
|
-
19,
|
|
8938
|
-
20,
|
|
8939
|
-
21,
|
|
8940
|
-
22,
|
|
8941
|
-
20,
|
|
8942
|
-
22,
|
|
8943
|
-
23
|
|
8944
|
-
]);
|
|
8945
|
-
var CUBE_POSITIONS = new Float32Array([
|
|
8946
|
-
-1,
|
|
8947
|
-
-1,
|
|
8948
|
-
1,
|
|
8949
|
-
1,
|
|
8950
|
-
-1,
|
|
8951
|
-
1,
|
|
8952
|
-
1,
|
|
8953
|
-
1,
|
|
8954
|
-
1,
|
|
8955
|
-
-1,
|
|
8956
|
-
1,
|
|
8957
|
-
1,
|
|
8958
|
-
-1,
|
|
8959
|
-
-1,
|
|
8960
|
-
-1,
|
|
8961
|
-
-1,
|
|
8962
|
-
1,
|
|
8963
|
-
-1,
|
|
8964
|
-
1,
|
|
8965
|
-
1,
|
|
8966
|
-
-1,
|
|
8967
|
-
1,
|
|
8968
|
-
-1,
|
|
8969
|
-
-1,
|
|
8970
|
-
-1,
|
|
8971
|
-
1,
|
|
8972
|
-
-1,
|
|
8973
|
-
-1,
|
|
8974
|
-
1,
|
|
8975
|
-
1,
|
|
8976
|
-
1,
|
|
8977
|
-
1,
|
|
8978
|
-
1,
|
|
8979
|
-
1,
|
|
8980
|
-
1,
|
|
8981
|
-
-1,
|
|
8982
|
-
-1,
|
|
8983
|
-
-1,
|
|
8984
|
-
-1,
|
|
8985
|
-
1,
|
|
8986
|
-
-1,
|
|
8987
|
-
-1,
|
|
8988
|
-
1,
|
|
8989
|
-
-1,
|
|
8990
|
-
1,
|
|
8991
|
-
-1,
|
|
8992
|
-
-1,
|
|
8993
|
-
1,
|
|
8994
|
-
1,
|
|
8995
|
-
-1,
|
|
8996
|
-
-1,
|
|
8997
|
-
1,
|
|
8998
|
-
1,
|
|
8999
|
-
-1,
|
|
9000
|
-
1,
|
|
9001
|
-
1,
|
|
9002
|
-
1,
|
|
9003
|
-
1,
|
|
9004
|
-
-1,
|
|
9005
|
-
1,
|
|
9006
|
-
-1,
|
|
9007
|
-
-1,
|
|
9008
|
-
-1,
|
|
9009
|
-
-1,
|
|
9010
|
-
-1,
|
|
9011
|
-
1,
|
|
9012
|
-
-1,
|
|
9013
|
-
1,
|
|
9014
|
-
1,
|
|
9015
|
-
-1,
|
|
9016
|
-
1,
|
|
9017
|
-
-1
|
|
9018
|
-
]);
|
|
9019
|
-
var CUBE_NORMALS = new Float32Array([
|
|
9020
|
-
// Front face
|
|
9021
|
-
0,
|
|
9022
|
-
0,
|
|
9023
|
-
1,
|
|
9024
|
-
0,
|
|
9025
|
-
0,
|
|
9026
|
-
1,
|
|
9027
|
-
0,
|
|
9028
|
-
0,
|
|
9029
|
-
1,
|
|
9030
|
-
0,
|
|
9031
|
-
0,
|
|
9032
|
-
1,
|
|
9033
|
-
// Back face
|
|
9034
|
-
0,
|
|
9035
|
-
0,
|
|
9036
|
-
-1,
|
|
9037
|
-
0,
|
|
9038
|
-
0,
|
|
9039
|
-
-1,
|
|
9040
|
-
0,
|
|
9041
|
-
0,
|
|
9042
|
-
-1,
|
|
9043
|
-
0,
|
|
9044
|
-
0,
|
|
9045
|
-
-1,
|
|
9046
|
-
// Top face
|
|
9047
|
-
0,
|
|
9048
|
-
1,
|
|
9049
|
-
0,
|
|
9050
|
-
0,
|
|
9051
|
-
1,
|
|
9052
|
-
0,
|
|
9053
|
-
0,
|
|
9054
|
-
1,
|
|
9055
|
-
0,
|
|
9056
|
-
0,
|
|
9057
|
-
1,
|
|
9058
|
-
0,
|
|
9059
|
-
// Bottom face
|
|
9060
|
-
0,
|
|
9061
|
-
-1,
|
|
9062
|
-
0,
|
|
9063
|
-
0,
|
|
9064
|
-
-1,
|
|
9065
|
-
0,
|
|
9066
|
-
0,
|
|
9067
|
-
-1,
|
|
9068
|
-
0,
|
|
9069
|
-
0,
|
|
9070
|
-
-1,
|
|
9071
|
-
0,
|
|
9072
|
-
// Right face
|
|
9073
|
-
1,
|
|
9074
|
-
0,
|
|
9075
|
-
0,
|
|
9076
|
-
1,
|
|
9077
|
-
0,
|
|
9078
|
-
0,
|
|
9079
|
-
1,
|
|
9080
|
-
0,
|
|
9081
|
-
0,
|
|
9082
|
-
1,
|
|
9083
|
-
0,
|
|
9084
|
-
0,
|
|
9085
|
-
// Left face
|
|
9086
|
-
-1,
|
|
9087
|
-
0,
|
|
9088
|
-
0,
|
|
9089
|
-
-1,
|
|
9090
|
-
0,
|
|
9091
|
-
0,
|
|
9092
|
-
-1,
|
|
9093
|
-
0,
|
|
9094
|
-
0,
|
|
9095
|
-
-1,
|
|
9096
|
-
0,
|
|
9097
|
-
0
|
|
9098
|
-
]);
|
|
9099
|
-
var CUBE_TEX_COORDS = new Float32Array([
|
|
9100
|
-
// Front face
|
|
9101
|
-
0,
|
|
9102
|
-
0,
|
|
9103
|
-
1,
|
|
9104
|
-
0,
|
|
9105
|
-
1,
|
|
9106
|
-
1,
|
|
9107
|
-
0,
|
|
9108
|
-
1,
|
|
9109
|
-
// Back face
|
|
9110
|
-
1,
|
|
9111
|
-
0,
|
|
9112
|
-
1,
|
|
9113
|
-
1,
|
|
9114
|
-
0,
|
|
9115
|
-
1,
|
|
9116
|
-
0,
|
|
9117
|
-
0,
|
|
9118
|
-
// Top face
|
|
9119
|
-
0,
|
|
9120
|
-
1,
|
|
9121
|
-
0,
|
|
9122
|
-
0,
|
|
9123
|
-
1,
|
|
9124
|
-
0,
|
|
9125
|
-
1,
|
|
9126
|
-
1,
|
|
9127
|
-
// Bottom face
|
|
9128
|
-
1,
|
|
9129
|
-
1,
|
|
9130
|
-
0,
|
|
9131
|
-
1,
|
|
9132
|
-
0,
|
|
9133
|
-
0,
|
|
9134
|
-
1,
|
|
9135
|
-
0,
|
|
9136
|
-
// Right face
|
|
9137
|
-
1,
|
|
9138
|
-
0,
|
|
9139
|
-
1,
|
|
9140
|
-
1,
|
|
9141
|
-
0,
|
|
9142
|
-
1,
|
|
9143
|
-
0,
|
|
9144
|
-
0,
|
|
9145
|
-
// Left face
|
|
9146
|
-
0,
|
|
9147
|
-
0,
|
|
9148
|
-
1,
|
|
9149
|
-
0,
|
|
9150
|
-
1,
|
|
9151
|
-
1,
|
|
9152
|
-
0,
|
|
9153
|
-
1
|
|
9154
|
-
]);
|
|
9155
|
-
var CUBE_FACE_INDICES = new Uint32Array([
|
|
9156
|
-
0,
|
|
9157
|
-
0,
|
|
9158
|
-
0,
|
|
9159
|
-
0,
|
|
9160
|
-
1,
|
|
9161
|
-
1,
|
|
9162
|
-
1,
|
|
9163
|
-
1,
|
|
9164
|
-
2,
|
|
9165
|
-
2,
|
|
9166
|
-
2,
|
|
9167
|
-
2,
|
|
9168
|
-
3,
|
|
9169
|
-
3,
|
|
9170
|
-
3,
|
|
9171
|
-
3,
|
|
9172
|
-
4,
|
|
9173
|
-
4,
|
|
9174
|
-
4,
|
|
9175
|
-
4,
|
|
9176
|
-
5,
|
|
9177
|
-
5,
|
|
9178
|
-
5,
|
|
9179
|
-
5
|
|
9180
|
-
]);
|
|
9181
|
-
var CUBE_NON_INDEXED_POSITIONS = new Float32Array([
|
|
9182
|
-
1,
|
|
9183
|
-
-1,
|
|
9184
|
-
1,
|
|
9185
|
-
-1,
|
|
9186
|
-
-1,
|
|
9187
|
-
1,
|
|
9188
|
-
-1,
|
|
9189
|
-
-1,
|
|
9190
|
-
-1,
|
|
9191
|
-
1,
|
|
9192
|
-
-1,
|
|
9193
|
-
-1,
|
|
9194
|
-
1,
|
|
9195
|
-
-1,
|
|
9196
|
-
1,
|
|
9197
|
-
-1,
|
|
9198
|
-
-1,
|
|
9199
|
-
-1,
|
|
9200
|
-
1,
|
|
9201
|
-
1,
|
|
9202
|
-
1,
|
|
9203
|
-
1,
|
|
9204
|
-
-1,
|
|
9205
|
-
1,
|
|
9206
|
-
1,
|
|
9207
|
-
-1,
|
|
9208
|
-
-1,
|
|
9209
|
-
1,
|
|
9210
|
-
1,
|
|
9211
|
-
-1,
|
|
9212
|
-
1,
|
|
9213
|
-
1,
|
|
9214
|
-
1,
|
|
9215
|
-
1,
|
|
9216
|
-
-1,
|
|
9217
|
-
-1,
|
|
9218
|
-
-1,
|
|
9219
|
-
1,
|
|
9220
|
-
1,
|
|
9221
|
-
1,
|
|
9222
|
-
1,
|
|
9223
|
-
1,
|
|
9224
|
-
1,
|
|
9225
|
-
1,
|
|
9226
|
-
-1,
|
|
9227
|
-
-1,
|
|
9228
|
-
1,
|
|
9229
|
-
-1,
|
|
9230
|
-
-1,
|
|
9231
|
-
1,
|
|
9232
|
-
1,
|
|
9233
|
-
1,
|
|
9234
|
-
1,
|
|
9235
|
-
-1,
|
|
9236
|
-
-1,
|
|
9237
|
-
-1,
|
|
9238
|
-
1,
|
|
9239
|
-
-1,
|
|
9240
|
-
1,
|
|
9241
|
-
1,
|
|
9242
|
-
-1,
|
|
9243
|
-
1,
|
|
9244
|
-
-1,
|
|
9245
|
-
-1,
|
|
9246
|
-
-1,
|
|
9247
|
-
-1,
|
|
9248
|
-
-1,
|
|
9249
|
-
-1,
|
|
9250
|
-
1,
|
|
9251
|
-
-1,
|
|
9252
|
-
1,
|
|
9253
|
-
-1,
|
|
9254
|
-
1,
|
|
9255
|
-
1,
|
|
9256
|
-
1,
|
|
9257
|
-
-1,
|
|
9258
|
-
1,
|
|
9259
|
-
1,
|
|
9260
|
-
-1,
|
|
9261
|
-
-1,
|
|
9262
|
-
1,
|
|
9263
|
-
-1,
|
|
9264
|
-
-1,
|
|
9265
|
-
1,
|
|
9266
|
-
1,
|
|
9267
|
-
-1,
|
|
9268
|
-
1,
|
|
9269
|
-
1,
|
|
9270
|
-
1,
|
|
9271
|
-
1,
|
|
9272
|
-
1,
|
|
9273
|
-
-1,
|
|
9274
|
-
-1,
|
|
9275
|
-
-1,
|
|
9276
|
-
-1,
|
|
9277
|
-
-1,
|
|
9278
|
-
-1,
|
|
9279
|
-
1,
|
|
9280
|
-
-1,
|
|
9281
|
-
1,
|
|
9282
|
-
1,
|
|
9283
|
-
-1,
|
|
9284
|
-
1,
|
|
9285
|
-
-1,
|
|
9286
|
-
-1,
|
|
9287
|
-
-1,
|
|
9288
|
-
1,
|
|
9289
|
-
-1
|
|
9290
|
-
]);
|
|
9291
|
-
var CUBE_NON_INDEXED_TEX_COORDS = new Float32Array([
|
|
9292
|
-
1,
|
|
9293
|
-
1,
|
|
9294
|
-
0,
|
|
9295
|
-
1,
|
|
9296
|
-
0,
|
|
9297
|
-
0,
|
|
9298
|
-
1,
|
|
9299
|
-
0,
|
|
9300
|
-
1,
|
|
9301
|
-
1,
|
|
9302
|
-
0,
|
|
9303
|
-
0,
|
|
9304
|
-
1,
|
|
9305
|
-
1,
|
|
9306
|
-
0,
|
|
9307
|
-
1,
|
|
9308
|
-
0,
|
|
9309
|
-
0,
|
|
9310
|
-
1,
|
|
9311
|
-
0,
|
|
9312
|
-
1,
|
|
9313
|
-
1,
|
|
9314
|
-
0,
|
|
9315
|
-
0,
|
|
9316
|
-
1,
|
|
9317
|
-
1,
|
|
9318
|
-
0,
|
|
9319
|
-
1,
|
|
9320
|
-
0,
|
|
9321
|
-
0,
|
|
9322
|
-
1,
|
|
9323
|
-
0,
|
|
9324
|
-
1,
|
|
9325
|
-
1,
|
|
9326
|
-
0,
|
|
9327
|
-
0,
|
|
9328
|
-
1,
|
|
9329
|
-
1,
|
|
9330
|
-
0,
|
|
9331
|
-
1,
|
|
9332
|
-
0,
|
|
9333
|
-
0,
|
|
9334
|
-
1,
|
|
9335
|
-
0,
|
|
9336
|
-
1,
|
|
9337
|
-
1,
|
|
9338
|
-
0,
|
|
9339
|
-
0,
|
|
9340
|
-
1,
|
|
9341
|
-
1,
|
|
9342
|
-
0,
|
|
9343
|
-
1,
|
|
9344
|
-
0,
|
|
9345
|
-
0,
|
|
9346
|
-
0,
|
|
9347
|
-
0,
|
|
9348
|
-
1,
|
|
9349
|
-
0,
|
|
9350
|
-
1,
|
|
9351
|
-
1,
|
|
9352
|
-
1,
|
|
9353
|
-
1,
|
|
9354
|
-
0,
|
|
9355
|
-
1,
|
|
9356
|
-
0,
|
|
9357
|
-
0,
|
|
9358
|
-
1,
|
|
9359
|
-
0,
|
|
9360
|
-
1,
|
|
9361
|
-
1,
|
|
9362
|
-
0,
|
|
9363
|
-
0
|
|
9364
|
-
]);
|
|
9365
|
-
var CUBE_NON_INDEXED_COLORS = new Float32Array([
|
|
9366
|
-
1,
|
|
9367
|
-
0,
|
|
9368
|
-
1,
|
|
9369
|
-
1,
|
|
9370
|
-
0,
|
|
9371
|
-
0,
|
|
9372
|
-
1,
|
|
9373
|
-
1,
|
|
9374
|
-
0,
|
|
9375
|
-
0,
|
|
9376
|
-
0,
|
|
9377
|
-
1,
|
|
9378
|
-
1,
|
|
9379
|
-
0,
|
|
9380
|
-
0,
|
|
9381
|
-
1,
|
|
9382
|
-
1,
|
|
9383
|
-
0,
|
|
9384
|
-
1,
|
|
9385
|
-
1,
|
|
9386
|
-
0,
|
|
9387
|
-
0,
|
|
9388
|
-
0,
|
|
9389
|
-
1,
|
|
9390
|
-
1,
|
|
9391
|
-
1,
|
|
9392
|
-
1,
|
|
9393
|
-
1,
|
|
9394
|
-
1,
|
|
9395
|
-
0,
|
|
9396
|
-
1,
|
|
9397
|
-
1,
|
|
9398
|
-
1,
|
|
9399
|
-
0,
|
|
9400
|
-
0,
|
|
9401
|
-
1,
|
|
9402
|
-
1,
|
|
9403
|
-
1,
|
|
9404
|
-
0,
|
|
9405
|
-
1,
|
|
9406
|
-
1,
|
|
9407
|
-
1,
|
|
9408
|
-
1,
|
|
9409
|
-
1,
|
|
9410
|
-
1,
|
|
9411
|
-
0,
|
|
9412
|
-
0,
|
|
9413
|
-
1,
|
|
9414
|
-
0,
|
|
9415
|
-
1,
|
|
9416
|
-
1,
|
|
9417
|
-
1,
|
|
9418
|
-
1,
|
|
9419
|
-
1,
|
|
9420
|
-
1,
|
|
9421
|
-
1,
|
|
9422
|
-
1,
|
|
9423
|
-
1,
|
|
9424
|
-
0,
|
|
9425
|
-
1,
|
|
9426
|
-
0,
|
|
9427
|
-
1,
|
|
9428
|
-
0,
|
|
9429
|
-
1,
|
|
9430
|
-
0,
|
|
9431
|
-
1,
|
|
9432
|
-
1,
|
|
9433
|
-
1,
|
|
9434
|
-
1,
|
|
9435
|
-
1,
|
|
9436
|
-
0,
|
|
9437
|
-
1,
|
|
9438
|
-
0,
|
|
9439
|
-
0,
|
|
9440
|
-
1,
|
|
9441
|
-
1,
|
|
9442
|
-
0,
|
|
9443
|
-
1,
|
|
9444
|
-
1,
|
|
9445
|
-
1,
|
|
9446
|
-
0,
|
|
9447
|
-
1,
|
|
9448
|
-
0,
|
|
9449
|
-
1,
|
|
9450
|
-
0,
|
|
9451
|
-
0,
|
|
9452
|
-
0,
|
|
9453
|
-
1,
|
|
9454
|
-
0,
|
|
9455
|
-
0,
|
|
9456
|
-
1,
|
|
9457
|
-
1,
|
|
9458
|
-
0,
|
|
9459
|
-
1,
|
|
9460
|
-
0,
|
|
9461
|
-
1,
|
|
9462
|
-
1,
|
|
9463
|
-
1,
|
|
9464
|
-
1,
|
|
9465
|
-
1,
|
|
9466
|
-
0,
|
|
9467
|
-
1,
|
|
9468
|
-
1,
|
|
9469
|
-
1,
|
|
9470
|
-
0,
|
|
9471
|
-
0,
|
|
9472
|
-
1,
|
|
9473
|
-
1,
|
|
9474
|
-
0,
|
|
9475
|
-
0,
|
|
9476
|
-
1,
|
|
9477
|
-
1,
|
|
9478
|
-
1,
|
|
9479
|
-
0,
|
|
9480
|
-
1,
|
|
9481
|
-
1,
|
|
9482
|
-
1,
|
|
9483
|
-
1,
|
|
9484
|
-
1,
|
|
9485
|
-
1,
|
|
9486
|
-
1,
|
|
9487
|
-
0,
|
|
9488
|
-
0,
|
|
9489
|
-
1,
|
|
9490
|
-
0,
|
|
9491
|
-
0,
|
|
9492
|
-
0,
|
|
9493
|
-
1,
|
|
9494
|
-
0,
|
|
9495
|
-
1,
|
|
9496
|
-
0,
|
|
9497
|
-
1,
|
|
9498
|
-
1,
|
|
9499
|
-
1,
|
|
9500
|
-
0,
|
|
9501
|
-
1,
|
|
9502
|
-
1,
|
|
9503
|
-
0,
|
|
9504
|
-
0,
|
|
9505
|
-
1,
|
|
9506
|
-
0,
|
|
9507
|
-
1,
|
|
9508
|
-
0,
|
|
9509
|
-
1
|
|
9510
|
-
]);
|
|
9511
|
-
var CUBE_NON_INDEXED_FACE_INDICES = new Uint32Array([
|
|
9512
|
-
3,
|
|
9513
|
-
3,
|
|
9514
|
-
3,
|
|
9515
|
-
3,
|
|
9516
|
-
3,
|
|
9517
|
-
3,
|
|
9518
|
-
4,
|
|
9519
|
-
4,
|
|
9520
|
-
4,
|
|
9521
|
-
4,
|
|
9522
|
-
4,
|
|
9523
|
-
4,
|
|
9524
|
-
2,
|
|
9525
|
-
2,
|
|
9526
|
-
2,
|
|
9527
|
-
2,
|
|
9528
|
-
2,
|
|
9529
|
-
2,
|
|
9530
|
-
5,
|
|
9531
|
-
5,
|
|
9532
|
-
5,
|
|
9533
|
-
5,
|
|
9534
|
-
5,
|
|
9535
|
-
5,
|
|
9536
|
-
0,
|
|
9537
|
-
0,
|
|
9538
|
-
0,
|
|
9539
|
-
0,
|
|
9540
|
-
0,
|
|
9541
|
-
0,
|
|
9542
|
-
1,
|
|
9543
|
-
1,
|
|
9544
|
-
1,
|
|
9545
|
-
1,
|
|
9546
|
-
1,
|
|
9547
|
-
1
|
|
9548
|
-
]);
|
|
9549
|
-
var ATTRIBUTES = {
|
|
9550
|
-
POSITION: { size: 3, value: CUBE_POSITIONS },
|
|
9551
|
-
NORMAL: { size: 3, value: CUBE_NORMALS },
|
|
9552
|
-
TEXCOORD_0: { size: 2, value: CUBE_TEX_COORDS },
|
|
9553
|
-
faceIndex: { size: 1, value: CUBE_FACE_INDICES }
|
|
9554
|
-
};
|
|
9555
|
-
var NON_INDEXED_ATTRIBUTES = {
|
|
9556
|
-
POSITION: { size: 3, value: CUBE_NON_INDEXED_POSITIONS },
|
|
9557
|
-
// NORMAL: {size: 3, value: CUBE_NON_INDEXED_NORMALS},
|
|
9558
|
-
TEXCOORD_0: { size: 2, value: CUBE_NON_INDEXED_TEX_COORDS },
|
|
9559
|
-
COLOR_0: { size: 3, value: CUBE_NON_INDEXED_COLORS },
|
|
9560
|
-
faceIndex: { size: 1, value: CUBE_NON_INDEXED_FACE_INDICES }
|
|
9561
|
-
};
|
|
9562
|
-
|
|
9563
|
-
// src/geometries/cylinder-geometry.ts
|
|
9564
|
-
var CylinderGeometry = class extends TruncatedConeGeometry {
|
|
9565
|
-
constructor(props = {}) {
|
|
9566
|
-
const { id = uid("cylinder-geometry"), radius = 1 } = props;
|
|
9567
|
-
super({
|
|
9568
|
-
...props,
|
|
9569
|
-
id,
|
|
9570
|
-
bottomRadius: radius,
|
|
9571
|
-
topRadius: radius
|
|
9572
|
-
});
|
|
9573
|
-
}
|
|
9574
|
-
};
|
|
9575
|
-
|
|
9576
|
-
// src/geometries/ico-sphere-geometry.ts
|
|
9577
|
-
var ICO_POSITIONS = [-1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 1, 0, -1, 0, 1, 0, 0];
|
|
9578
|
-
var 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];
|
|
9579
|
-
var IcoSphereGeometry = class extends Geometry {
|
|
9580
|
-
constructor(props = {}) {
|
|
9581
|
-
const { id = uid("ico-sphere-geometry") } = props;
|
|
9582
|
-
const { indices, attributes } = tesselateIcosaHedron(props);
|
|
9583
|
-
super({
|
|
9584
|
-
...props,
|
|
9585
|
-
id,
|
|
9586
|
-
topology: "triangle-list",
|
|
9587
|
-
indices,
|
|
9588
|
-
attributes: { ...attributes, ...props.attributes }
|
|
9589
|
-
});
|
|
9590
|
-
}
|
|
9591
|
-
};
|
|
9592
|
-
function tesselateIcosaHedron(props) {
|
|
9593
|
-
const { iterations = 0 } = props;
|
|
9594
|
-
const PI = Math.PI;
|
|
9595
|
-
const PI2 = PI * 2;
|
|
9596
|
-
const positions = [...ICO_POSITIONS];
|
|
9597
|
-
let indices = [...ICO_INDICES];
|
|
9598
|
-
positions.push();
|
|
9599
|
-
indices.push();
|
|
9600
|
-
const getMiddlePoint = /* @__PURE__ */ (() => {
|
|
9601
|
-
const pointMemo = {};
|
|
9602
|
-
return (i1, i2) => {
|
|
9603
|
-
i1 *= 3;
|
|
9604
|
-
i2 *= 3;
|
|
9605
|
-
const mini = i1 < i2 ? i1 : i2;
|
|
9606
|
-
const maxi = i1 > i2 ? i1 : i2;
|
|
9607
|
-
const key = `${mini}|${maxi}`;
|
|
9608
|
-
if (key in pointMemo) {
|
|
9609
|
-
return pointMemo[key];
|
|
9610
|
-
}
|
|
9611
|
-
const x1 = positions[i1];
|
|
9612
|
-
const y1 = positions[i1 + 1];
|
|
9613
|
-
const z1 = positions[i1 + 2];
|
|
9614
|
-
const x2 = positions[i2];
|
|
9615
|
-
const y2 = positions[i2 + 1];
|
|
9616
|
-
const z2 = positions[i2 + 2];
|
|
9617
|
-
let xm = (x1 + x2) / 2;
|
|
9618
|
-
let ym = (y1 + y2) / 2;
|
|
9619
|
-
let zm = (z1 + z2) / 2;
|
|
9620
|
-
const len = Math.sqrt(xm * xm + ym * ym + zm * zm);
|
|
9621
|
-
xm /= len;
|
|
9622
|
-
ym /= len;
|
|
9623
|
-
zm /= len;
|
|
9624
|
-
positions.push(xm, ym, zm);
|
|
9625
|
-
const pointIndex = positions.length / 3 - 1;
|
|
9626
|
-
pointMemo[key] = pointIndex;
|
|
9627
|
-
return pointIndex;
|
|
9628
|
-
};
|
|
9629
|
-
})();
|
|
9630
|
-
for (let i = 0; i < iterations; i++) {
|
|
9631
|
-
const indices2 = [];
|
|
9632
|
-
for (let j = 0; j < indices.length; j += 3) {
|
|
9633
|
-
const a = getMiddlePoint(indices[j + 0], indices[j + 1]);
|
|
9634
|
-
const b = getMiddlePoint(indices[j + 1], indices[j + 2]);
|
|
9635
|
-
const c = getMiddlePoint(indices[j + 2], indices[j + 0]);
|
|
9636
|
-
indices2.push(c, indices[j + 0], a, a, indices[j + 1], b, b, indices[j + 2], c, a, b, c);
|
|
9637
|
-
}
|
|
9638
|
-
indices = indices2;
|
|
9639
|
-
}
|
|
9640
|
-
const normals = new Array(positions.length);
|
|
9641
|
-
const texCoords = new Array(positions.length / 3 * 2);
|
|
9642
|
-
const l = indices.length;
|
|
9643
|
-
for (let i = l - 3; i >= 0; i -= 3) {
|
|
9644
|
-
const i1 = indices[i + 0];
|
|
9645
|
-
const i2 = indices[i + 1];
|
|
9646
|
-
const i3 = indices[i + 2];
|
|
9647
|
-
const in1 = i1 * 3;
|
|
9648
|
-
const in2 = i2 * 3;
|
|
9649
|
-
const in3 = i3 * 3;
|
|
9650
|
-
const iu1 = i1 * 2;
|
|
9651
|
-
const iu2 = i2 * 2;
|
|
9652
|
-
const iu3 = i3 * 2;
|
|
9653
|
-
const x1 = positions[in1 + 0];
|
|
9654
|
-
const y1 = positions[in1 + 1];
|
|
9655
|
-
const z1 = positions[in1 + 2];
|
|
9656
|
-
const theta1 = Math.acos(z1 / Math.sqrt(x1 * x1 + y1 * y1 + z1 * z1));
|
|
9657
|
-
const phi1 = Math.atan2(y1, x1) + PI;
|
|
9658
|
-
const v1 = theta1 / PI;
|
|
9659
|
-
const u1 = 1 - phi1 / PI2;
|
|
9660
|
-
const x2 = positions[in2 + 0];
|
|
9661
|
-
const y2 = positions[in2 + 1];
|
|
9662
|
-
const z2 = positions[in2 + 2];
|
|
9663
|
-
const theta2 = Math.acos(z2 / Math.sqrt(x2 * x2 + y2 * y2 + z2 * z2));
|
|
9664
|
-
const phi2 = Math.atan2(y2, x2) + PI;
|
|
9665
|
-
const v2 = theta2 / PI;
|
|
9666
|
-
const u2 = 1 - phi2 / PI2;
|
|
9667
|
-
const x3 = positions[in3 + 0];
|
|
9668
|
-
const y3 = positions[in3 + 1];
|
|
9669
|
-
const z3 = positions[in3 + 2];
|
|
9670
|
-
const theta3 = Math.acos(z3 / Math.sqrt(x3 * x3 + y3 * y3 + z3 * z3));
|
|
9671
|
-
const phi3 = Math.atan2(y3, x3) + PI;
|
|
9672
|
-
const v3 = theta3 / PI;
|
|
9673
|
-
const u3 = 1 - phi3 / PI2;
|
|
9674
|
-
const vec1 = [x3 - x2, y3 - y2, z3 - z2];
|
|
9675
|
-
const vec2 = [x1 - x2, y1 - y2, z1 - z2];
|
|
9676
|
-
const normal = new Vector3(vec1).cross(vec2).normalize();
|
|
9677
|
-
let newIndex;
|
|
9678
|
-
if ((u1 === 0 || u2 === 0 || u3 === 0) && (u1 === 0 || u1 > 0.5) && (u2 === 0 || u2 > 0.5) && (u3 === 0 || u3 > 0.5)) {
|
|
9679
|
-
positions.push(positions[in1 + 0], positions[in1 + 1], positions[in1 + 2]);
|
|
9680
|
-
newIndex = positions.length / 3 - 1;
|
|
9681
|
-
indices.push(newIndex);
|
|
9682
|
-
texCoords[newIndex * 2 + 0] = 1;
|
|
9683
|
-
texCoords[newIndex * 2 + 1] = v1;
|
|
9684
|
-
normals[newIndex * 3 + 0] = normal.x;
|
|
9685
|
-
normals[newIndex * 3 + 1] = normal.y;
|
|
9686
|
-
normals[newIndex * 3 + 2] = normal.z;
|
|
9687
|
-
positions.push(positions[in2 + 0], positions[in2 + 1], positions[in2 + 2]);
|
|
9688
|
-
newIndex = positions.length / 3 - 1;
|
|
9689
|
-
indices.push(newIndex);
|
|
9690
|
-
texCoords[newIndex * 2 + 0] = 1;
|
|
9691
|
-
texCoords[newIndex * 2 + 1] = v2;
|
|
9692
|
-
normals[newIndex * 3 + 0] = normal.x;
|
|
9693
|
-
normals[newIndex * 3 + 1] = normal.y;
|
|
9694
|
-
normals[newIndex * 3 + 2] = normal.z;
|
|
9695
|
-
positions.push(positions[in3 + 0], positions[in3 + 1], positions[in3 + 2]);
|
|
9696
|
-
newIndex = positions.length / 3 - 1;
|
|
9697
|
-
indices.push(newIndex);
|
|
9698
|
-
texCoords[newIndex * 2 + 0] = 1;
|
|
9699
|
-
texCoords[newIndex * 2 + 1] = v3;
|
|
9700
|
-
normals[newIndex * 3 + 0] = normal.x;
|
|
9701
|
-
normals[newIndex * 3 + 1] = normal.y;
|
|
9702
|
-
normals[newIndex * 3 + 2] = normal.z;
|
|
9703
|
-
}
|
|
9704
|
-
normals[in1 + 0] = normals[in2 + 0] = normals[in3 + 0] = normal.x;
|
|
9705
|
-
normals[in1 + 1] = normals[in2 + 1] = normals[in3 + 1] = normal.y;
|
|
9706
|
-
normals[in1 + 2] = normals[in2 + 2] = normals[in3 + 2] = normal.z;
|
|
9707
|
-
texCoords[iu1 + 0] = u1;
|
|
9708
|
-
texCoords[iu1 + 1] = v1;
|
|
9709
|
-
texCoords[iu2 + 0] = u2;
|
|
9710
|
-
texCoords[iu2 + 1] = v2;
|
|
9711
|
-
texCoords[iu3 + 0] = u3;
|
|
9712
|
-
texCoords[iu3 + 1] = v3;
|
|
9713
|
-
}
|
|
9714
|
-
return {
|
|
9715
|
-
indices: { size: 1, value: new Uint16Array(indices) },
|
|
9716
|
-
attributes: {
|
|
9717
|
-
POSITION: { size: 3, value: new Float32Array(positions) },
|
|
9718
|
-
NORMAL: { size: 3, value: new Float32Array(normals) },
|
|
9719
|
-
TEXCOORD_0: { size: 2, value: new Float32Array(texCoords) }
|
|
9720
|
-
}
|
|
9721
|
-
};
|
|
9722
|
-
}
|
|
9723
|
-
|
|
9724
|
-
// src/geometries/plane-geometry.ts
|
|
9725
|
-
var PlaneGeometry = class extends Geometry {
|
|
9726
|
-
constructor(props = {}) {
|
|
9727
|
-
const { id = uid("plane-geometry") } = props;
|
|
9728
|
-
const { indices, attributes } = tesselatePlane(props);
|
|
9729
|
-
super({
|
|
9730
|
-
...props,
|
|
9731
|
-
id,
|
|
9732
|
-
topology: "triangle-list",
|
|
9733
|
-
indices,
|
|
9734
|
-
attributes: { ...attributes, ...props.attributes }
|
|
9735
|
-
});
|
|
9736
|
-
}
|
|
9737
|
-
};
|
|
9738
|
-
function tesselatePlane(props) {
|
|
9739
|
-
const { type = "x,y", offset = 0, flipCull = false, unpack = false } = props;
|
|
9740
|
-
const coords = type.split(",");
|
|
9741
|
-
let c1len = props[`${coords[0]}len`] || 1;
|
|
9742
|
-
const c2len = props[`${coords[1]}len`] || 1;
|
|
9743
|
-
const subdivisions1 = props[`n${coords[0]}`] || 1;
|
|
9744
|
-
const subdivisions2 = props[`n${coords[1]}`] || 1;
|
|
9745
|
-
const numVertices = (subdivisions1 + 1) * (subdivisions2 + 1);
|
|
9746
|
-
const positions = new Float32Array(numVertices * 3);
|
|
9747
|
-
const normals = new Float32Array(numVertices * 3);
|
|
9748
|
-
const texCoords = new Float32Array(numVertices * 2);
|
|
9749
|
-
if (flipCull) {
|
|
9750
|
-
c1len = -c1len;
|
|
9751
|
-
}
|
|
9752
|
-
let i2 = 0;
|
|
9753
|
-
let i3 = 0;
|
|
9754
|
-
for (let z = 0; z <= subdivisions2; z++) {
|
|
9755
|
-
for (let x = 0; x <= subdivisions1; x++) {
|
|
9756
|
-
const u = x / subdivisions1;
|
|
9757
|
-
const v = z / subdivisions2;
|
|
9758
|
-
texCoords[i2 + 0] = flipCull ? 1 - u : u;
|
|
9759
|
-
texCoords[i2 + 1] = v;
|
|
9760
|
-
switch (type) {
|
|
9761
|
-
case "x,y":
|
|
9762
|
-
positions[i3 + 0] = c1len * u - c1len * 0.5;
|
|
9763
|
-
positions[i3 + 1] = c2len * v - c2len * 0.5;
|
|
9764
|
-
positions[i3 + 2] = offset;
|
|
9765
|
-
normals[i3 + 0] = 0;
|
|
9766
|
-
normals[i3 + 1] = 0;
|
|
9767
|
-
normals[i3 + 2] = flipCull ? 1 : -1;
|
|
9768
|
-
break;
|
|
9769
|
-
case "x,z":
|
|
9770
|
-
positions[i3 + 0] = c1len * u - c1len * 0.5;
|
|
9771
|
-
positions[i3 + 1] = offset;
|
|
9772
|
-
positions[i3 + 2] = c2len * v - c2len * 0.5;
|
|
9773
|
-
normals[i3 + 0] = 0;
|
|
9774
|
-
normals[i3 + 1] = flipCull ? 1 : -1;
|
|
9775
|
-
normals[i3 + 2] = 0;
|
|
9776
|
-
break;
|
|
9777
|
-
case "y,z":
|
|
9778
|
-
positions[i3 + 0] = offset;
|
|
9779
|
-
positions[i3 + 1] = c1len * u - c1len * 0.5;
|
|
9780
|
-
positions[i3 + 2] = c2len * v - c2len * 0.5;
|
|
9781
|
-
normals[i3 + 0] = flipCull ? 1 : -1;
|
|
9782
|
-
normals[i3 + 1] = 0;
|
|
9783
|
-
normals[i3 + 2] = 0;
|
|
9784
|
-
break;
|
|
9785
|
-
default:
|
|
9786
|
-
throw new Error("PlaneGeometry: unknown type");
|
|
9787
|
-
}
|
|
9788
|
-
i2 += 2;
|
|
9789
|
-
i3 += 3;
|
|
9790
|
-
}
|
|
9791
|
-
}
|
|
9792
|
-
const numVertsAcross = subdivisions1 + 1;
|
|
9793
|
-
const indices = new Uint16Array(subdivisions1 * subdivisions2 * 6);
|
|
9794
|
-
for (let z = 0; z < subdivisions2; z++) {
|
|
9795
|
-
for (let x = 0; x < subdivisions1; x++) {
|
|
9796
|
-
const index = (z * subdivisions1 + x) * 6;
|
|
9797
|
-
indices[index + 0] = (z + 0) * numVertsAcross + x;
|
|
9798
|
-
indices[index + 1] = (z + 1) * numVertsAcross + x;
|
|
9799
|
-
indices[index + 2] = (z + 0) * numVertsAcross + x + 1;
|
|
9800
|
-
indices[index + 3] = (z + 1) * numVertsAcross + x;
|
|
9801
|
-
indices[index + 4] = (z + 1) * numVertsAcross + x + 1;
|
|
9802
|
-
indices[index + 5] = (z + 0) * numVertsAcross + x + 1;
|
|
9803
|
-
}
|
|
9804
|
-
}
|
|
9805
|
-
const geometry = {
|
|
9806
|
-
indices: { size: 1, value: indices },
|
|
9807
|
-
attributes: {
|
|
9808
|
-
POSITION: { size: 3, value: positions },
|
|
9809
|
-
NORMAL: { size: 3, value: normals },
|
|
9810
|
-
TEXCOORD_0: { size: 2, value: texCoords }
|
|
9811
|
-
}
|
|
9812
|
-
};
|
|
9813
|
-
return unpack ? unpackIndexedGeometry(geometry) : geometry;
|
|
9814
|
-
}
|
|
9815
|
-
|
|
9816
9524
|
// src/application-utils/random.ts
|
|
9817
9525
|
function makeRandomGenerator() {
|
|
9818
9526
|
let s = 1;
|
|
@@ -9875,7 +9583,7 @@ void main(void) {
|
|
|
9875
9583
|
}
|
|
9876
9584
|
|
|
9877
9585
|
// src/dynamic-texture/video-texture.ts
|
|
9878
|
-
var
|
|
9586
|
+
var import_core26 = __toESM(require_core(), 1);
|
|
9879
9587
|
var VideoTexture = class {
|
|
9880
9588
|
/** Device used to create copied and native external texture bindings. */
|
|
9881
9589
|
device;
|
|
@@ -9924,7 +9632,7 @@ void main(void) {
|
|
|
9924
9632
|
* @param props Live video source and copied texture options.
|
|
9925
9633
|
*/
|
|
9926
9634
|
constructor(device, props) {
|
|
9927
|
-
(0,
|
|
9635
|
+
(0, import_core26.assert)(isHTMLVideoElementSource(props?.source) || isVideoFrameSource(props?.source));
|
|
9928
9636
|
this.device = device;
|
|
9929
9637
|
this.id = props.id || uid("video-texture");
|
|
9930
9638
|
this._source = props.source;
|
|
@@ -9938,7 +9646,7 @@ void main(void) {
|
|
|
9938
9646
|
* @param source Next caller-owned video source to follow.
|
|
9939
9647
|
*/
|
|
9940
9648
|
setSource(source4) {
|
|
9941
|
-
(0,
|
|
9649
|
+
(0, import_core26.assert)(isHTMLVideoElementSource(source4) || isVideoFrameSource(source4));
|
|
9942
9650
|
this._destroyExternalTexture();
|
|
9943
9651
|
this._source = source4;
|
|
9944
9652
|
this._sourceVersion++;
|
|
@@ -10016,7 +9724,7 @@ void main(void) {
|
|
|
10016
9724
|
width: size.width,
|
|
10017
9725
|
height: size.height,
|
|
10018
9726
|
format: "rgba8unorm",
|
|
10019
|
-
usage:
|
|
9727
|
+
usage: import_core26.Texture.SAMPLE | import_core26.Texture.COPY_DST,
|
|
10020
9728
|
mipLevels: 1,
|
|
10021
9729
|
sampler: this._sampler
|
|
10022
9730
|
});
|
|
@@ -10051,7 +9759,7 @@ void main(void) {
|
|
|
10051
9759
|
*/
|
|
10052
9760
|
_getResolvedSize() {
|
|
10053
9761
|
const size = getVideoTextureSourceSize(this._source);
|
|
10054
|
-
(0,
|
|
9762
|
+
(0, import_core26.assert)(size.width > 0 && size.height > 0);
|
|
10055
9763
|
return size;
|
|
10056
9764
|
}
|
|
10057
9765
|
/** Observes current source readiness and frame identity before binding resolution. */
|
|
@@ -10116,11 +9824,11 @@ void main(void) {
|
|
|
10116
9824
|
}
|
|
10117
9825
|
|
|
10118
9826
|
// src/passes/shader-pass-renderer.ts
|
|
10119
|
-
var
|
|
9827
|
+
var import_core29 = __toESM(require_core(), 1);
|
|
10120
9828
|
var import_shadertools7 = __toESM(require_shadertools(), 1);
|
|
10121
9829
|
|
|
10122
9830
|
// src/compute/swap.ts
|
|
10123
|
-
var
|
|
9831
|
+
var import_core27 = __toESM(require_core(), 1);
|
|
10124
9832
|
var Swap = class {
|
|
10125
9833
|
id;
|
|
10126
9834
|
/** The current resource - usually the source for renders or computations */
|
|
@@ -10152,7 +9860,7 @@ void main(void) {
|
|
|
10152
9860
|
(colorAttachment) => typeof colorAttachment !== "string" ? colorAttachment : device.createTexture({
|
|
10153
9861
|
id: `${props.id}-texture-0`,
|
|
10154
9862
|
format: colorAttachment,
|
|
10155
|
-
usage:
|
|
9863
|
+
usage: import_core27.Texture.SAMPLE | import_core27.Texture.RENDER | import_core27.Texture.COPY_SRC | import_core27.Texture.COPY_DST,
|
|
10156
9864
|
width,
|
|
10157
9865
|
height
|
|
10158
9866
|
})
|
|
@@ -10162,7 +9870,7 @@ void main(void) {
|
|
|
10162
9870
|
(colorAttachment) => typeof colorAttachment !== "string" ? colorAttachment : device.createTexture({
|
|
10163
9871
|
id: `${props.id}-texture-1`,
|
|
10164
9872
|
format: colorAttachment,
|
|
10165
|
-
usage:
|
|
9873
|
+
usage: import_core27.Texture.SAMPLE | import_core27.Texture.RENDER | import_core27.Texture.COPY_SRC | import_core27.Texture.COPY_DST,
|
|
10166
9874
|
width,
|
|
10167
9875
|
height
|
|
10168
9876
|
})
|
|
@@ -10226,7 +9934,7 @@ void main(void) {
|
|
|
10226
9934
|
};
|
|
10227
9935
|
|
|
10228
9936
|
// src/compute/computation.ts
|
|
10229
|
-
var
|
|
9937
|
+
var import_core28 = __toESM(require_core(), 1);
|
|
10230
9938
|
var import_shadertools6 = __toESM(require_shadertools(), 1);
|
|
10231
9939
|
var LOG_DRAW_PRIORITY2 = 2;
|
|
10232
9940
|
var LOG_DRAW_TIMEOUT2 = 1e4;
|
|
@@ -10238,13 +9946,13 @@ void main(void) {
|
|
|
10238
9946
|
* constructor remains the synchronous compatibility path.
|
|
10239
9947
|
*/
|
|
10240
9948
|
static async createAsync(device, props) {
|
|
10241
|
-
const ownsCompilation = !
|
|
10242
|
-
const asyncCompilation = ownsCompilation ?
|
|
9949
|
+
const ownsCompilation = !import_core28.PipelineFactory.getAsyncCompilation(device);
|
|
9950
|
+
const asyncCompilation = ownsCompilation ? import_core28.PipelineFactory.beginAsyncCompilation(device) : import_core28.PipelineFactory.getAsyncCompilation(device);
|
|
10243
9951
|
let computation;
|
|
10244
9952
|
try {
|
|
10245
9953
|
computation = new _Computation(device, props);
|
|
10246
9954
|
} finally {
|
|
10247
|
-
if (ownsCompilation)
|
|
9955
|
+
if (ownsCompilation) import_core28.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
|
|
10248
9956
|
}
|
|
10249
9957
|
try {
|
|
10250
9958
|
if (ownsCompilation) {
|
|
@@ -10259,11 +9967,12 @@ void main(void) {
|
|
|
10259
9967
|
}
|
|
10260
9968
|
}
|
|
10261
9969
|
static defaultProps = {
|
|
10262
|
-
...
|
|
9970
|
+
...import_core28.ComputePipeline.defaultProps,
|
|
10263
9971
|
id: "unnamed",
|
|
10264
9972
|
handle: void 0,
|
|
10265
9973
|
userData: {},
|
|
10266
9974
|
source: "",
|
|
9975
|
+
sourceLanguage: void 0,
|
|
10267
9976
|
modules: [],
|
|
10268
9977
|
defines: {},
|
|
10269
9978
|
plugins: [],
|
|
@@ -10324,30 +10033,34 @@ void main(void) {
|
|
|
10324
10033
|
const modules = mergeShaderModules(this.props.modules, this.shaderInputs?.getModules());
|
|
10325
10034
|
const defines = { ...resolvedPlugins.defines, ...this.props.defines };
|
|
10326
10035
|
this.props.shaderLayout = mergeShaderModuleBindingsIntoLayout(this.props.shaderLayout, modules) || null;
|
|
10327
|
-
this.pipelineFactory = props.pipelineFactory ||
|
|
10328
|
-
this.shaderFactory = props.shaderFactory ||
|
|
10036
|
+
this.pipelineFactory = props.pipelineFactory || import_core28.PipelineFactory.getDefaultPipelineFactory(this.device);
|
|
10037
|
+
this.shaderFactory = props.shaderFactory || import_core28.ShaderFactory.getDefaultShaderFactory(this.device);
|
|
10329
10038
|
const shaderAssembler = this.props.shaderAssembler;
|
|
10330
|
-
(0,
|
|
10039
|
+
(0, import_core28.assert)(shaderAssembler instanceof import_shadertools6.WGSLShaderAssembler);
|
|
10331
10040
|
const {
|
|
10332
10041
|
source: source4,
|
|
10333
10042
|
getUniforms: getUniforms2,
|
|
10043
|
+
entryPoints = {},
|
|
10334
10044
|
shaderLayout: assembledShaderLayout
|
|
10335
10045
|
} = shaderAssembler.assembleWGSLShader({
|
|
10336
10046
|
platformInfo,
|
|
10337
10047
|
...this.props,
|
|
10338
10048
|
modules,
|
|
10339
10049
|
defines,
|
|
10050
|
+
shaderStage: "compute",
|
|
10051
|
+
computeEntryPoint: this.props.entryPoint,
|
|
10340
10052
|
scanVertexAttributes: false,
|
|
10341
10053
|
pluginInjections: resolvedPlugins.injections
|
|
10342
10054
|
});
|
|
10343
10055
|
this.source = source4;
|
|
10056
|
+
this.props.entryPoint = entryPoints.compute || this.props.entryPoint;
|
|
10344
10057
|
this._getModuleUniforms = getUniforms2;
|
|
10345
10058
|
const inferredShaderLayout = assembledShaderLayout ?? device.getShaderLayout?.(this.source, { scanVertexAttributes: false });
|
|
10346
10059
|
this.props.shaderLayout = mergeShaderModuleBindingsIntoLayout(
|
|
10347
10060
|
this.props.shaderLayout || inferredShaderLayout || null,
|
|
10348
10061
|
modules
|
|
10349
10062
|
) || null;
|
|
10350
|
-
const asyncCompilation =
|
|
10063
|
+
const asyncCompilation = import_core28.PipelineFactory.getAsyncCompilation(this.device);
|
|
10351
10064
|
if (asyncCompilation) {
|
|
10352
10065
|
this._pipelineInitialization = this._updatePipelineAsync();
|
|
10353
10066
|
asyncCompilation.push(this._pipelineInitialization);
|
|
@@ -10414,7 +10127,7 @@ void main(void) {
|
|
|
10414
10127
|
}
|
|
10415
10128
|
setShaderInputs(shaderInputs) {
|
|
10416
10129
|
this.shaderInputs = shaderInputs;
|
|
10417
|
-
this._uniformStore = new
|
|
10130
|
+
this._uniformStore = new import_core28.UniformStore(this.device, this.shaderInputs.modules);
|
|
10418
10131
|
for (const [moduleName, module] of Object.entries(this.shaderInputs.modules)) {
|
|
10419
10132
|
if (shaderModuleHasUniforms(module)) {
|
|
10420
10133
|
const uniformBuffer = this._uniformStore.getManagedUniformBuffer(moduleName);
|
|
@@ -10483,7 +10196,7 @@ void main(void) {
|
|
|
10483
10196
|
if (!this._pipelineNeedsUpdate) return null;
|
|
10484
10197
|
const previousShader = this.pipeline ? this.shader : null;
|
|
10485
10198
|
if (this.pipeline) {
|
|
10486
|
-
|
|
10199
|
+
import_core28.log.log(1, `Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)();
|
|
10487
10200
|
}
|
|
10488
10201
|
this._pipelineNeedsUpdate = false;
|
|
10489
10202
|
this.shader = this.shaderFactory.createShader({
|
|
@@ -10501,27 +10214,27 @@ void main(void) {
|
|
|
10501
10214
|
_lastLogTime = 0;
|
|
10502
10215
|
_logOpen = false;
|
|
10503
10216
|
_logDrawCallStart() {
|
|
10504
|
-
const logDrawTimeout =
|
|
10505
|
-
if (
|
|
10217
|
+
const logDrawTimeout = import_core28.log.level > 3 ? 0 : LOG_DRAW_TIMEOUT2;
|
|
10218
|
+
if (import_core28.log.level < 2 || Date.now() - this._lastLogTime < logDrawTimeout) {
|
|
10506
10219
|
return;
|
|
10507
10220
|
}
|
|
10508
10221
|
this._lastLogTime = Date.now();
|
|
10509
10222
|
this._logOpen = true;
|
|
10510
|
-
|
|
10223
|
+
import_core28.log.group(LOG_DRAW_PRIORITY2, `>>> DRAWING MODEL ${this.id}`, { collapsed: import_core28.log.level <= 2 })();
|
|
10511
10224
|
}
|
|
10512
10225
|
_logDrawCallEnd() {
|
|
10513
10226
|
if (this._logOpen) {
|
|
10514
10227
|
const uniformTable = this.shaderInputs.getDebugTable();
|
|
10515
|
-
|
|
10516
|
-
|
|
10228
|
+
import_core28.log.table(LOG_DRAW_PRIORITY2, uniformTable)();
|
|
10229
|
+
import_core28.log.groupEnd(LOG_DRAW_PRIORITY2)();
|
|
10517
10230
|
this._logOpen = false;
|
|
10518
10231
|
}
|
|
10519
10232
|
}
|
|
10520
10233
|
_drawCount = 0;
|
|
10521
10234
|
// TODO - fix typing of luma data types
|
|
10522
10235
|
_getBufferOrConstantValues(attribute, dataType) {
|
|
10523
|
-
const TypedArrayConstructor =
|
|
10524
|
-
const typedArray = attribute instanceof
|
|
10236
|
+
const TypedArrayConstructor = import_core28.dataTypeDecoder.getTypedArrayConstructor(dataType);
|
|
10237
|
+
const typedArray = attribute instanceof import_core28.Buffer ? new TypedArrayConstructor(attribute.debugData) : attribute;
|
|
10525
10238
|
return typedArray.toString();
|
|
10526
10239
|
}
|
|
10527
10240
|
};
|
|
@@ -11089,7 +10802,7 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
|
|
|
11089
10802
|
this.parameterBuffer = device.createBuffer({
|
|
11090
10803
|
id: `${optimization.name}-parameters`,
|
|
11091
10804
|
byteLength: Math.max(Math.ceil(optimization.uniformNames.length / 4) * 16, 16),
|
|
11092
|
-
usage:
|
|
10805
|
+
usage: import_core29.Buffer.UNIFORM | import_core29.Buffer.COPY_DST
|
|
11093
10806
|
});
|
|
11094
10807
|
const outputBindings = Object.entries(optimization.outputs).map(
|
|
11095
10808
|
([bindingName, targetName], outputIndex) => ({
|
|
@@ -11374,7 +11087,7 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
|
|
|
11374
11087
|
width: targetSize[0],
|
|
11375
11088
|
height: targetSize[1],
|
|
11376
11089
|
format: spec.format || device.preferredColorFormat,
|
|
11377
|
-
usage:
|
|
11090
|
+
usage: import_core29.Texture.SAMPLE | import_core29.Texture.RENDER | import_core29.Texture.COPY_SRC | import_core29.Texture.COPY_DST | (spec.storage && device.type === "webgpu" && device.getTextureFormatCapabilities(spec.format || device.preferredColorFormat).store ? import_core29.Texture.STORAGE : 0),
|
|
11378
11091
|
...spec.sampler ? { sampler: spec.sampler } : {}
|
|
11379
11092
|
});
|
|
11380
11093
|
const framebuffer = device.createFramebuffer({
|
|
@@ -11429,17 +11142,17 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
|
|
|
11429
11142
|
}
|
|
11430
11143
|
|
|
11431
11144
|
// src/compute/kernel.ts
|
|
11432
|
-
var
|
|
11145
|
+
var import_core30 = __toESM(require_core(), 1);
|
|
11433
11146
|
var Kernel = class _Kernel {
|
|
11434
11147
|
/** Creates a kernel while allowing the backend to compile its pipeline asynchronously. */
|
|
11435
11148
|
static async createAsync(device, props) {
|
|
11436
|
-
const ownsCompilation = !
|
|
11437
|
-
const asyncCompilation = ownsCompilation ?
|
|
11149
|
+
const ownsCompilation = !import_core30.PipelineFactory.getAsyncCompilation(device);
|
|
11150
|
+
const asyncCompilation = ownsCompilation ? import_core30.PipelineFactory.beginAsyncCompilation(device) : import_core30.PipelineFactory.getAsyncCompilation(device);
|
|
11438
11151
|
let kernel;
|
|
11439
11152
|
try {
|
|
11440
11153
|
kernel = new _Kernel(device, props);
|
|
11441
11154
|
} finally {
|
|
11442
|
-
if (ownsCompilation)
|
|
11155
|
+
if (ownsCompilation) import_core30.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
|
|
11443
11156
|
}
|
|
11444
11157
|
try {
|
|
11445
11158
|
if (ownsCompilation) {
|
|
@@ -11470,8 +11183,8 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
|
|
|
11470
11183
|
this.device = device;
|
|
11471
11184
|
this.id = props.id ?? "kernel";
|
|
11472
11185
|
this.source = source4;
|
|
11473
|
-
this.pipelineFactory = pipelineFactory ??
|
|
11474
|
-
this.shaderFactory = shaderFactory ??
|
|
11186
|
+
this.pipelineFactory = pipelineFactory ?? import_core30.PipelineFactory.getDefaultPipelineFactory(device);
|
|
11187
|
+
this.shaderFactory = shaderFactory ?? import_core30.ShaderFactory.getDefaultShaderFactory(device);
|
|
11475
11188
|
this.shader = this.shaderFactory.createShader({
|
|
11476
11189
|
id: `${this.id}-compute`,
|
|
11477
11190
|
stage: "compute",
|
|
@@ -11479,7 +11192,7 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
|
|
|
11479
11192
|
debugShaders
|
|
11480
11193
|
});
|
|
11481
11194
|
const computePipelineProps = { ...pipelineProps, shader: this.shader };
|
|
11482
|
-
const asyncCompilation =
|
|
11195
|
+
const asyncCompilation = import_core30.PipelineFactory.getAsyncCompilation(device);
|
|
11483
11196
|
if (asyncCompilation) {
|
|
11484
11197
|
const pipelineInitialization = this.pipelineFactory.createComputePipelineAsync(computePipelineProps);
|
|
11485
11198
|
this._pipelineInitialization = pipelineInitialization;
|
|
@@ -11516,17 +11229,17 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
|
|
|
11516
11229
|
};
|
|
11517
11230
|
|
|
11518
11231
|
// src/compute/render-kernel.ts
|
|
11519
|
-
var
|
|
11232
|
+
var import_core31 = __toESM(require_core(), 1);
|
|
11520
11233
|
var RenderKernel = class _RenderKernel {
|
|
11521
11234
|
/** Creates a render kernel while allowing the backend to compile its pipeline asynchronously. */
|
|
11522
11235
|
static async createAsync(device, props) {
|
|
11523
|
-
const ownsCompilation = !
|
|
11524
|
-
const asyncCompilation = ownsCompilation ?
|
|
11236
|
+
const ownsCompilation = !import_core31.PipelineFactory.getAsyncCompilation(device);
|
|
11237
|
+
const asyncCompilation = ownsCompilation ? import_core31.PipelineFactory.beginAsyncCompilation(device) : import_core31.PipelineFactory.getAsyncCompilation(device);
|
|
11525
11238
|
let kernel;
|
|
11526
11239
|
try {
|
|
11527
11240
|
kernel = new _RenderKernel(device, props);
|
|
11528
11241
|
} finally {
|
|
11529
|
-
if (ownsCompilation)
|
|
11242
|
+
if (ownsCompilation) import_core31.PipelineFactory.endAsyncCompilation(device, asyncCompilation);
|
|
11530
11243
|
}
|
|
11531
11244
|
try {
|
|
11532
11245
|
if (ownsCompilation) {
|
|
@@ -11567,8 +11280,8 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
|
|
|
11567
11280
|
this.id = props.id ?? "render-kernel";
|
|
11568
11281
|
this.vertexSource = vertexSource;
|
|
11569
11282
|
this.fragmentSource = fragmentSource;
|
|
11570
|
-
this.pipelineFactory = pipelineFactory ??
|
|
11571
|
-
this.shaderFactory = shaderFactory ??
|
|
11283
|
+
this.pipelineFactory = pipelineFactory ?? import_core31.PipelineFactory.getDefaultPipelineFactory(device);
|
|
11284
|
+
this.shaderFactory = shaderFactory ?? import_core31.ShaderFactory.getDefaultShaderFactory(device);
|
|
11572
11285
|
this.vertexShader = this.shaderFactory.createShader({
|
|
11573
11286
|
id: `${this.id}-vertex`,
|
|
11574
11287
|
stage: "vertex",
|
|
@@ -11586,7 +11299,7 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
|
|
|
11586
11299
|
vs: this.vertexShader,
|
|
11587
11300
|
fs: this.fragmentShader
|
|
11588
11301
|
};
|
|
11589
|
-
const asyncCompilation =
|
|
11302
|
+
const asyncCompilation = import_core31.PipelineFactory.getAsyncCompilation(device);
|
|
11590
11303
|
if (asyncCompilation) {
|
|
11591
11304
|
const pipelineInitialization = this.pipelineFactory.createRenderPipelineAsync(renderPipelineProps);
|
|
11592
11305
|
this._pipelineInitialization = pipelineInitialization;
|
|
@@ -11633,7 +11346,7 @@ vec2 shaderPassRenderer_getRenderTargetUV(vec2 textureUV) {
|
|
|
11633
11346
|
};
|
|
11634
11347
|
|
|
11635
11348
|
// src/modules/picking/picking-manager.ts
|
|
11636
|
-
var
|
|
11349
|
+
var import_core32 = __toESM(require_core(), 1);
|
|
11637
11350
|
|
|
11638
11351
|
// src/modules/picking/picking-uniforms.ts
|
|
11639
11352
|
var DEFAULT_HIGHLIGHT_COLOR = [0, 1, 1, 1];
|
|
@@ -11897,13 +11610,13 @@ layout(std140) uniform pickingUniforms {
|
|
|
11897
11610
|
format: "rgba8unorm",
|
|
11898
11611
|
width: 1,
|
|
11899
11612
|
height: 1,
|
|
11900
|
-
usage:
|
|
11613
|
+
usage: import_core32.Texture.RENDER_ATTACHMENT
|
|
11901
11614
|
});
|
|
11902
11615
|
const pickingTexture = this.device.createTexture({
|
|
11903
11616
|
format: "rg32sint",
|
|
11904
11617
|
width: 1,
|
|
11905
11618
|
height: 1,
|
|
11906
|
-
usage:
|
|
11619
|
+
usage: import_core32.Texture.RENDER_ATTACHMENT | import_core32.Texture.COPY_SRC
|
|
11907
11620
|
});
|
|
11908
11621
|
return this.device.createFramebuffer({
|
|
11909
11622
|
colorAttachments: [colorTexture, pickingTexture],
|
|
@@ -11915,7 +11628,7 @@ layout(std140) uniform pickingUniforms {
|
|
|
11915
11628
|
format: "rgba8unorm",
|
|
11916
11629
|
width: 1,
|
|
11917
11630
|
height: 1,
|
|
11918
|
-
usage:
|
|
11631
|
+
usage: import_core32.Texture.RENDER_ATTACHMENT | import_core32.Texture.COPY_SRC
|
|
11919
11632
|
});
|
|
11920
11633
|
return this.device.createFramebuffer({
|
|
11921
11634
|
colorAttachments: [pickingTexture],
|
|
@@ -11937,7 +11650,7 @@ layout(std140) uniform pickingUniforms {
|
|
|
11937
11650
|
const layout = pickTexture.computeMemoryLayout({ width: 1, height: 1 });
|
|
11938
11651
|
const readBuffer = this.device.createBuffer({
|
|
11939
11652
|
byteLength: layout.byteLength,
|
|
11940
|
-
usage:
|
|
11653
|
+
usage: import_core32.Buffer.COPY_DST | import_core32.Buffer.MAP_READ
|
|
11941
11654
|
});
|
|
11942
11655
|
try {
|
|
11943
11656
|
pickTexture.readBuffer(
|
|
@@ -11973,7 +11686,7 @@ layout(std140) uniform pickingUniforms {
|
|
|
11973
11686
|
const layout = pickTexture.computeMemoryLayout({ width: 1, height: 1 });
|
|
11974
11687
|
const readBuffer = this.device.createBuffer({
|
|
11975
11688
|
byteLength: layout.byteLength,
|
|
11976
|
-
usage:
|
|
11689
|
+
usage: import_core32.Buffer.COPY_DST | import_core32.Buffer.MAP_READ
|
|
11977
11690
|
});
|
|
11978
11691
|
try {
|
|
11979
11692
|
pickTexture.readBuffer(
|