easy-three-utils 0.0.1
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/package.json +12 -0
- package/src/common/index.ts +24 -0
- package/src/common/useLine2.ts +87 -0
- package/src/common/useLoader.ts +184 -0
- package/src/common/useLocationCalculator.ts +145 -0
- package/src/common/useMark.ts +42 -0
- package/src/common/useTween.ts +86 -0
- package/src/core/basic/camera.ts +28 -0
- package/src/core/basic/clock.ts +11 -0
- package/src/core/basic/control.ts +32 -0
- package/src/core/basic/index.ts +35 -0
- package/src/core/basic/labelRenderer.ts +26 -0
- package/src/core/basic/light.ts +63 -0
- package/src/core/basic/renderer.ts +37 -0
- package/src/core/basic/scene.ts +11 -0
- package/src/core/basic/stats.ts +16 -0
- package/src/core/event.ts +74 -0
- package/src/core/index.ts +11 -0
- package/src/core/main.ts +389 -0
- package/src/draco/README.md +32 -0
- package/src/draco/draco_decoder.js +34 -0
- package/src/draco/draco_decoder.wasm +0 -0
- package/src/draco/draco_encoder.js +33 -0
- package/src/draco/draco_wasm_wrapper.js +117 -0
- package/src/draco/gltf/draco_decoder.js +33 -0
- package/src/draco/gltf/draco_decoder.wasm +0 -0
- package/src/draco/gltf/draco_encoder.js +33 -0
- package/src/draco/gltf/draco_wasm_wrapper.js +116 -0
- package/src/tileRenderer/base/Tile.d.ts +50 -0
- package/src/tileRenderer/base/TileBase.d.ts +76 -0
- package/src/tileRenderer/base/TileInternal.d.ts +36 -0
- package/src/tileRenderer/base/TilesRendererBase.d.ts +35 -0
- package/src/tileRenderer/base/TilesRendererBase.js +847 -0
- package/src/tileRenderer/base/Tileset.d.ts +66 -0
- package/src/tileRenderer/base/constants.d.ts +6 -0
- package/src/tileRenderer/base/constants.js +16 -0
- package/src/tileRenderer/base/loaders/B3DMLoaderBase.d.ts +18 -0
- package/src/tileRenderer/base/loaders/B3DMLoaderBase.js +85 -0
- package/src/tileRenderer/base/loaders/CMPTLoaderBase.d.ts +22 -0
- package/src/tileRenderer/base/loaders/CMPTLoaderBase.js +61 -0
- package/src/tileRenderer/base/loaders/I3DMLoaderBase.d.ts +21 -0
- package/src/tileRenderer/base/loaders/I3DMLoaderBase.js +130 -0
- package/src/tileRenderer/base/loaders/LoaderBase.d.ts +10 -0
- package/src/tileRenderer/base/loaders/LoaderBase.js +73 -0
- package/src/tileRenderer/base/loaders/PNTSLoaderBase.d.ts +17 -0
- package/src/tileRenderer/base/loaders/PNTSLoaderBase.js +82 -0
- package/src/tileRenderer/base/plugins/ImplicitTilingPlugin.js +12 -0
- package/src/tileRenderer/base/traverseFunctions.js +468 -0
- package/src/tileRenderer/gltf.js +144 -0
- package/src/tileRenderer/index.d.ts +41 -0
- package/src/tileRenderer/index.js +44 -0
- package/src/tileRenderer/plugins/README.md +578 -0
- package/src/tileRenderer/plugins/base/ImplicitTilingPlugin.d.ts +2 -0
- package/src/tileRenderer/plugins/base/ImplicitTilingPlugin.js +84 -0
- package/src/tileRenderer/plugins/base/SUBTREELoader.js +876 -0
- package/src/tileRenderer/plugins/index.d.ts +17 -0
- package/src/tileRenderer/plugins/index.js +17 -0
- package/src/tileRenderer/plugins/three/CesiumIonAuthPlugin.d.ts +9 -0
- package/src/tileRenderer/plugins/three/CesiumIonAuthPlugin.js +175 -0
- package/src/tileRenderer/plugins/three/DebugTilesPlugin.d.ts +29 -0
- package/src/tileRenderer/plugins/three/DebugTilesPlugin.js +677 -0
- package/src/tileRenderer/plugins/three/GLTFExtensionsPlugin.d.ts +18 -0
- package/src/tileRenderer/plugins/three/GLTFExtensionsPlugin.js +86 -0
- package/src/tileRenderer/plugins/three/GoogleAttributionsManager.js +62 -0
- package/src/tileRenderer/plugins/three/GoogleCloudAuthPlugin.d.ts +5 -0
- package/src/tileRenderer/plugins/three/GoogleCloudAuthPlugin.js +200 -0
- package/src/tileRenderer/plugins/three/ReorientationPlugin.d.ts +12 -0
- package/src/tileRenderer/plugins/three/ReorientationPlugin.js +136 -0
- package/src/tileRenderer/plugins/three/TileCompressionPlugin.d.ts +18 -0
- package/src/tileRenderer/plugins/three/TileCompressionPlugin.js +223 -0
- package/src/tileRenderer/plugins/three/UpdateOnChangePlugin.d.ts +5 -0
- package/src/tileRenderer/plugins/three/UpdateOnChangePlugin.js +87 -0
- package/src/tileRenderer/plugins/three/fade/FadeManager.js +370 -0
- package/src/tileRenderer/plugins/three/fade/TilesFadePlugin.d.ts +9 -0
- package/src/tileRenderer/plugins/three/fade/TilesFadePlugin.js +318 -0
- package/src/tileRenderer/plugins/three/gltf/GLTFCesiumRTCExtension.d.ts +5 -0
- package/src/tileRenderer/plugins/three/gltf/GLTFCesiumRTCExtension.js +27 -0
- package/src/tileRenderer/plugins/three/gltf/GLTFMeshFeaturesExtension.d.ts +30 -0
- package/src/tileRenderer/plugins/three/gltf/GLTFMeshFeaturesExtension.js +76 -0
- package/src/tileRenderer/plugins/three/gltf/GLTFStructuralMetadataExtension.d.ts +49 -0
- package/src/tileRenderer/plugins/three/gltf/GLTFStructuralMetadataExtension.js +147 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/classes/ClassProperty.js +149 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/classes/MeshFeatures.js +215 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/classes/PropertyAttributeAccessor.js +107 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/classes/PropertySetAccessor.js +45 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/classes/PropertyTableAccessor.js +209 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/classes/PropertyTextureAccessor.js +244 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/classes/StructuralMetadata.js +202 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/math/Matrix2.js +55 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/utilities/ClassPropertyHelpers.js +495 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/utilities/TexCoordUtilities.js +72 -0
- package/src/tileRenderer/plugins/three/gltf/metadata/utilities/TextureReadUtility.js +154 -0
- package/src/tileRenderer/plugins/three/objects/EllipsoidRegionHelper.js +186 -0
- package/src/tileRenderer/plugins/three/objects/SphereHelper.js +55 -0
- package/src/tileRenderer/r3f/README.md +238 -0
- package/src/tileRenderer/r3f/components/CameraControls.jsx +132 -0
- package/src/tileRenderer/r3f/components/CameraTransition.jsx +177 -0
- package/src/tileRenderer/r3f/components/CanvasDOMOverlay.jsx +54 -0
- package/src/tileRenderer/r3f/components/CompassGizmo.jsx +260 -0
- package/src/tileRenderer/r3f/components/TilesAttributionOverlay.jsx +110 -0
- package/src/tileRenderer/r3f/components/TilesRenderer.jsx +239 -0
- package/src/tileRenderer/r3f/index.jsx +6 -0
- package/src/tileRenderer/r3f/utilities/useForceUpdate.jsx +8 -0
- package/src/tileRenderer/r3f/utilities/useObjectDep.jsx +59 -0
- package/src/tileRenderer/r3f/utilities/useOptions.jsx +143 -0
- package/src/tileRenderer/three/DebugTilesRenderer.d.ts +28 -0
- package/src/tileRenderer/three/DebugTilesRenderer.js +58 -0
- package/src/tileRenderer/three/TilesGroup.d.ts +9 -0
- package/src/tileRenderer/three/TilesGroup.js +91 -0
- package/src/tileRenderer/three/TilesRenderer.d.ts +37 -0
- package/src/tileRenderer/three/TilesRenderer.js +1049 -0
- package/src/tileRenderer/three/controls/CameraTransitionManager.js +305 -0
- package/src/tileRenderer/three/controls/EnvironmentControls.js +1295 -0
- package/src/tileRenderer/three/controls/GlobeControls.js +684 -0
- package/src/tileRenderer/three/controls/PivotPointMesh.js +104 -0
- package/src/tileRenderer/three/controls/PointerTracker.js +257 -0
- package/src/tileRenderer/three/controls/utils.js +113 -0
- package/src/tileRenderer/three/loaders/B3DMLoader.d.ts +26 -0
- package/src/tileRenderer/three/loaders/B3DMLoader.js +85 -0
- package/src/tileRenderer/three/loaders/CMPTLoader.d.ts +19 -0
- package/src/tileRenderer/three/loaders/CMPTLoader.js +97 -0
- package/src/tileRenderer/three/loaders/GLTFExtensionLoader.d.ts +11 -0
- package/src/tileRenderer/three/loaders/GLTFExtensionLoader.js +68 -0
- package/src/tileRenderer/three/loaders/I3DMLoader.d.ts +26 -0
- package/src/tileRenderer/three/loaders/I3DMLoader.js +256 -0
- package/src/tileRenderer/three/loaders/PNTSLoader.d.ts +25 -0
- package/src/tileRenderer/three/loaders/PNTSLoader.js +202 -0
- package/src/tileRenderer/three/loaders/gltf/GLTFCesiumRTCExtension.js +12 -0
- package/src/tileRenderer/three/loaders/gltf/GLTFMeshFeaturesExtension.js +12 -0
- package/src/tileRenderer/three/loaders/gltf/GLTFStructuralMetadataExtension.js +12 -0
- package/src/tileRenderer/three/math/Ellipsoid.d.ts +31 -0
- package/src/tileRenderer/three/math/Ellipsoid.js +337 -0
- package/src/tileRenderer/three/math/EllipsoidRegion.d.ts +23 -0
- package/src/tileRenderer/three/math/EllipsoidRegion.js +178 -0
- package/src/tileRenderer/three/math/ExtendedFrustum.js +65 -0
- package/src/tileRenderer/three/math/GeoConstants.d.ts +4 -0
- package/src/tileRenderer/three/math/GeoConstants.js +5 -0
- package/src/tileRenderer/three/math/GeoUtils.d.ts +9 -0
- package/src/tileRenderer/three/math/GeoUtils.js +106 -0
- package/src/tileRenderer/three/math/OBB.js +179 -0
- package/src/tileRenderer/three/math/TileBoundingVolume.js +272 -0
- package/src/tileRenderer/three/plugins/CesiumIonAuthPlugin.js +12 -0
- package/src/tileRenderer/three/plugins/DebugTilesPlugin.js +26 -0
- package/src/tileRenderer/three/plugins/GoogleCloudAuthPlugin.js +12 -0
- package/src/tileRenderer/three/raycastTraverse.js +178 -0
- package/src/tileRenderer/three/renderers/CesiumIonTilesRenderer.d.ts +14 -0
- package/src/tileRenderer/three/renderers/CesiumIonTilesRenderer.js +21 -0
- package/src/tileRenderer/three/renderers/GoogleTilesRenderer.d.ts +43 -0
- package/src/tileRenderer/three/renderers/GoogleTilesRenderer.js +48 -0
- package/src/tileRenderer/three/utilities.js +54 -0
- package/src/tileRenderer/utilities/BatchTable.d.ts +24 -0
- package/src/tileRenderer/utilities/BatchTable.js +82 -0
- package/src/tileRenderer/utilities/BatchTableHierarchyExtension.js +127 -0
- package/src/tileRenderer/utilities/FeatureTable.d.ts +30 -0
- package/src/tileRenderer/utilities/FeatureTable.js +159 -0
- package/src/tileRenderer/utilities/LRUCache.d.ts +8 -0
- package/src/tileRenderer/utilities/LRUCache.js +385 -0
- package/src/tileRenderer/utilities/PriorityQueue.d.ts +16 -0
- package/src/tileRenderer/utilities/PriorityQueue.js +137 -0
- package/src/tileRenderer/utilities/arrayToString.js +7 -0
- package/src/tileRenderer/utilities/readMagicBytes.js +29 -0
- package/src/tileRenderer/utilities/rgb565torgb.js +22 -0
- package/src/tileRenderer/utilities/urlExtension.js +34 -0
- package/tsconfig.json +42 -0
- package/tsconfig.node.json +11 -0
- package/typings/three.d.ts +27 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Spherical, Vector3, MathUtils } from 'three';
|
|
2
|
+
|
|
3
|
+
const _spherical = new Spherical();
|
|
4
|
+
const _vec = new Vector3();
|
|
5
|
+
const _geoResults = {};
|
|
6
|
+
|
|
7
|
+
// Cesium / 3D tiles Spheroid:
|
|
8
|
+
// - Up is Z at 90 degrees latitude
|
|
9
|
+
// - 0, 0 latitude, longitude is X axis
|
|
10
|
+
// Z
|
|
11
|
+
// |
|
|
12
|
+
// |
|
|
13
|
+
// .----- Y
|
|
14
|
+
// /
|
|
15
|
+
// X
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
// Three.js Spherical Coordinates
|
|
19
|
+
// - Up is Y at 90 degrees latitude
|
|
20
|
+
// - 0, 0 latitude, longitude is Z
|
|
21
|
+
// Y
|
|
22
|
+
// |
|
|
23
|
+
// |
|
|
24
|
+
// .----- X
|
|
25
|
+
// /
|
|
26
|
+
// Z
|
|
27
|
+
|
|
28
|
+
export function swapToGeoFrame( target ) {
|
|
29
|
+
|
|
30
|
+
const { x, y, z } = target;
|
|
31
|
+
target.x = z;
|
|
32
|
+
target.y = x;
|
|
33
|
+
target.z = y;
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function swapToThreeFrame( target ) {
|
|
38
|
+
|
|
39
|
+
const { x, y, z } = target;
|
|
40
|
+
target.z = x;
|
|
41
|
+
target.x = y;
|
|
42
|
+
target.y = z;
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function sphericalPhiToLatitude( phi ) {
|
|
47
|
+
|
|
48
|
+
return - ( phi - Math.PI / 2 );
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function latitudeToSphericalPhi( latitude ) {
|
|
53
|
+
|
|
54
|
+
return - latitude + Math.PI / 2;
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function correctGeoCoordWrap( lat, lon, target = {} ) {
|
|
59
|
+
|
|
60
|
+
_spherical.theta = lon;
|
|
61
|
+
_spherical.phi = latitudeToSphericalPhi( lat );
|
|
62
|
+
_vec.setFromSpherical( _spherical );
|
|
63
|
+
|
|
64
|
+
_spherical.setFromVector3( _vec );
|
|
65
|
+
target.lat = sphericalPhiToLatitude( _spherical.phi );
|
|
66
|
+
target.lon = _spherical.theta;
|
|
67
|
+
return target;
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function toHoursMinutesSecondsString( value, pos = 'E', neg = 'W' ) {
|
|
72
|
+
|
|
73
|
+
const direction = value < 0 ? neg : pos;
|
|
74
|
+
value = Math.abs( value );
|
|
75
|
+
|
|
76
|
+
const hours = ~ ~ value;
|
|
77
|
+
|
|
78
|
+
const minDec = ( value - hours ) * 60;
|
|
79
|
+
const minutes = ~ ~ minDec;
|
|
80
|
+
|
|
81
|
+
const secDec = ( minDec - minutes ) * 60;
|
|
82
|
+
const seconds = ~ ~ secDec;
|
|
83
|
+
|
|
84
|
+
return `${ hours }° ${ minutes }' ${ seconds }" ${ direction }`;
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function toLatLonString( lat, lon, decimalFormat = false ) {
|
|
89
|
+
|
|
90
|
+
const result = correctGeoCoordWrap( lat, lon, _geoResults );
|
|
91
|
+
let latString, lonString;
|
|
92
|
+
if ( decimalFormat ) {
|
|
93
|
+
|
|
94
|
+
latString = `${ ( MathUtils.RAD2DEG * result.lat ).toFixed( 4 ) }°`;
|
|
95
|
+
lonString = `${ ( MathUtils.RAD2DEG * result.lon ).toFixed( 4 ) }°`;
|
|
96
|
+
|
|
97
|
+
} else {
|
|
98
|
+
|
|
99
|
+
latString = toHoursMinutesSecondsString( MathUtils.RAD2DEG * result.lat, 'N', 'S' );
|
|
100
|
+
lonString = toHoursMinutesSecondsString( MathUtils.RAD2DEG * result.lon, 'E', 'W' );
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return `${ latString } ${ lonString }`;
|
|
105
|
+
|
|
106
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { Matrix4, Box3, Vector3, Plane, Ray } from 'three';
|
|
2
|
+
|
|
3
|
+
const _worldMin = new Vector3();
|
|
4
|
+
const _worldMax = new Vector3();
|
|
5
|
+
const _norm = new Vector3();
|
|
6
|
+
const _ray = new Ray();
|
|
7
|
+
|
|
8
|
+
export class OBB {
|
|
9
|
+
|
|
10
|
+
constructor( box = new Box3(), transform = new Matrix4() ) {
|
|
11
|
+
|
|
12
|
+
this.box = box.clone();
|
|
13
|
+
this.transform = transform.clone();
|
|
14
|
+
this.inverseTransform = new Matrix4();
|
|
15
|
+
this.points = new Array( 8 ).fill().map( () => new Vector3() );
|
|
16
|
+
this.planes = new Array( 6 ).fill().map( () => new Plane() );
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Clamps the given point within the bounds of this OBB
|
|
22
|
+
* @param {Vector3} point
|
|
23
|
+
* @param {Vector3} result
|
|
24
|
+
* @returns {Vector3}
|
|
25
|
+
*/
|
|
26
|
+
clampPoint( point, result ) {
|
|
27
|
+
|
|
28
|
+
return result.copy( point )
|
|
29
|
+
.applyMatrix4( this.inverseTransform )
|
|
30
|
+
.clamp( this.box.min, this.box.max )
|
|
31
|
+
.applyMatrix4( this.transform );
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Returns the distance from any edge of this OBB to the specified point.
|
|
37
|
+
* If the point lies inside of this box, the distance will be 0.
|
|
38
|
+
* @param {Vector3} point
|
|
39
|
+
* @returns {number}
|
|
40
|
+
*/
|
|
41
|
+
distanceToPoint( point ) {
|
|
42
|
+
|
|
43
|
+
return this.clampPoint( point, _norm ).distanceTo( point );
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
containsPoint( point ) {
|
|
48
|
+
|
|
49
|
+
_norm.copy( point ).applyMatrix4( this.inverseTransform );
|
|
50
|
+
return this.box.containsPoint( _norm );
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// returns boolean indicating whether the ray has intersected the obb
|
|
55
|
+
intersectsRay( ray ) {
|
|
56
|
+
|
|
57
|
+
_ray.copy( ray ).applyMatrix4( this.inverseTransform );
|
|
58
|
+
return _ray.intersectsBox( this.box );
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Sets "target" equal to the intersection point.
|
|
63
|
+
// Returns "null" if no intersection found.
|
|
64
|
+
intersectRay( ray, target ) {
|
|
65
|
+
|
|
66
|
+
_ray.copy( ray ).applyMatrix4( this.inverseTransform );
|
|
67
|
+
if ( _ray.intersectBox( this.box, target ) ) {
|
|
68
|
+
|
|
69
|
+
target.applyMatrix4( this.transform );
|
|
70
|
+
return target;
|
|
71
|
+
|
|
72
|
+
} else {
|
|
73
|
+
|
|
74
|
+
return null;
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
update() {
|
|
81
|
+
|
|
82
|
+
const { points, inverseTransform, transform, box } = this;
|
|
83
|
+
inverseTransform.copy( transform ).invert();
|
|
84
|
+
|
|
85
|
+
const { min, max } = box;
|
|
86
|
+
let index = 0;
|
|
87
|
+
for ( let x = - 1; x <= 1; x += 2 ) {
|
|
88
|
+
|
|
89
|
+
for ( let y = - 1; y <= 1; y += 2 ) {
|
|
90
|
+
|
|
91
|
+
for ( let z = - 1; z <= 1; z += 2 ) {
|
|
92
|
+
|
|
93
|
+
points[ index ].set(
|
|
94
|
+
x < 0 ? min.x : max.x,
|
|
95
|
+
y < 0 ? min.y : max.y,
|
|
96
|
+
z < 0 ? min.z : max.z,
|
|
97
|
+
).applyMatrix4( transform );
|
|
98
|
+
index ++;
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this.updatePlanes();
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
updatePlanes() {
|
|
111
|
+
|
|
112
|
+
_worldMin.copy( this.box.min ).applyMatrix4( this.transform );
|
|
113
|
+
_worldMax.copy( this.box.max ).applyMatrix4( this.transform );
|
|
114
|
+
|
|
115
|
+
_norm.set( 0, 0, 1 ).transformDirection( this.transform );
|
|
116
|
+
this.planes[ 0 ].setFromNormalAndCoplanarPoint( _norm, _worldMin );
|
|
117
|
+
this.planes[ 1 ].setFromNormalAndCoplanarPoint( _norm, _worldMax ).negate();
|
|
118
|
+
|
|
119
|
+
_norm.set( 0, 1, 0 ).transformDirection( this.transform );
|
|
120
|
+
this.planes[ 2 ].setFromNormalAndCoplanarPoint( _norm, _worldMin );
|
|
121
|
+
this.planes[ 3 ].setFromNormalAndCoplanarPoint( _norm, _worldMax ).negate();
|
|
122
|
+
|
|
123
|
+
_norm.set( 1, 0, 0 ).transformDirection( this.transform );
|
|
124
|
+
this.planes[ 4 ].setFromNormalAndCoplanarPoint( _norm, _worldMin );
|
|
125
|
+
this.planes[ 5 ].setFromNormalAndCoplanarPoint( _norm, _worldMax ).negate();
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// based on three.js' Box3 "intersects frustum" function
|
|
130
|
+
intersectsFrustum( frustum ) {
|
|
131
|
+
|
|
132
|
+
const { points } = this;
|
|
133
|
+
const { planes } = frustum;
|
|
134
|
+
for ( let i = 0; i < 6; i ++ ) {
|
|
135
|
+
|
|
136
|
+
const plane = planes[ i ];
|
|
137
|
+
let maxDistance = - Infinity;
|
|
138
|
+
for ( let j = 0; j < 8; j ++ ) {
|
|
139
|
+
|
|
140
|
+
const v = points[ j ];
|
|
141
|
+
const dist = plane.distanceToPoint( v );
|
|
142
|
+
maxDistance = maxDistance < dist ? dist : maxDistance;
|
|
143
|
+
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if ( maxDistance < 0 ) {
|
|
147
|
+
|
|
148
|
+
return false;
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// do the opposite check using the obb planes to avoid false positives
|
|
155
|
+
for ( let i = 0; i < 6; i ++ ) {
|
|
156
|
+
|
|
157
|
+
const plane = this.planes[ i ];
|
|
158
|
+
let maxDistance = - Infinity;
|
|
159
|
+
for ( let j = 0; j < 8; j ++ ) {
|
|
160
|
+
|
|
161
|
+
const v = frustum.points[ j ];
|
|
162
|
+
const dist = plane.distanceToPoint( v );
|
|
163
|
+
maxDistance = maxDistance < dist ? dist : maxDistance;
|
|
164
|
+
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if ( maxDistance < 0 ) {
|
|
168
|
+
|
|
169
|
+
return false;
|
|
170
|
+
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return true;
|
|
176
|
+
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { Vector3, Sphere } from 'three';
|
|
2
|
+
import { OBB } from './OBB.js';
|
|
3
|
+
import { EllipsoidRegion } from './EllipsoidRegion.js';
|
|
4
|
+
|
|
5
|
+
const _vecX = new Vector3();
|
|
6
|
+
const _vecY = new Vector3();
|
|
7
|
+
const _vecZ = new Vector3();
|
|
8
|
+
const _sphereVec = new Vector3();
|
|
9
|
+
const _obbVec = new Vector3();
|
|
10
|
+
|
|
11
|
+
// TODO: check region more precisely in all functions
|
|
12
|
+
export class TileBoundingVolume {
|
|
13
|
+
|
|
14
|
+
constructor() {
|
|
15
|
+
|
|
16
|
+
this.sphere = null;
|
|
17
|
+
this.obb = null;
|
|
18
|
+
this.region = null;
|
|
19
|
+
|
|
20
|
+
this.regionObb = null;
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
intersectsRay( ray ) {
|
|
25
|
+
|
|
26
|
+
const sphere = this.sphere;
|
|
27
|
+
const obb = this.obb || this.regionObb;
|
|
28
|
+
|
|
29
|
+
// Early out if we don't hit this tile sphere
|
|
30
|
+
if ( sphere && ! ray.intersectsSphere( sphere ) ) {
|
|
31
|
+
|
|
32
|
+
return false;
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Early out if we don't this this tile box
|
|
37
|
+
if ( obb && ! obb.intersectsRay( ray ) ) {
|
|
38
|
+
|
|
39
|
+
return false;
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return true;
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
intersectRay( ray, target = null ) {
|
|
48
|
+
|
|
49
|
+
const sphere = this.sphere;
|
|
50
|
+
const obb = this.obb || this.regionObb;
|
|
51
|
+
|
|
52
|
+
let sphereDistSq = - Infinity;
|
|
53
|
+
let obbDistSq = - Infinity;
|
|
54
|
+
|
|
55
|
+
if ( sphere ) {
|
|
56
|
+
|
|
57
|
+
if ( ray.intersectSphere( sphere, _sphereVec ) ) {
|
|
58
|
+
|
|
59
|
+
sphereDistSq = sphere.containsPoint( ray.origin ) ? 0 : ray.origin.distanceToSquared( _sphereVec );
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if ( obb ) {
|
|
66
|
+
|
|
67
|
+
if ( obb.intersectRay( ray, _obbVec ) ) {
|
|
68
|
+
|
|
69
|
+
obbDistSq = obb.containsPoint( ray.origin ) ? 0 : ray.origin.distanceToSquared( _obbVec );
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// if we didn't hit anything then exit
|
|
76
|
+
const furthestDist = Math.max( sphereDistSq, obbDistSq );
|
|
77
|
+
if ( furthestDist === - Infinity ) {
|
|
78
|
+
|
|
79
|
+
return null;
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// get the furthest hit point if needed
|
|
84
|
+
ray.at( Math.sqrt( furthestDist ), target );
|
|
85
|
+
return target;
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
distanceToPoint( point ) {
|
|
90
|
+
|
|
91
|
+
const sphere = this.sphere;
|
|
92
|
+
const obb = this.obb || this.regionObb;
|
|
93
|
+
|
|
94
|
+
let sphereDistance = - Infinity;
|
|
95
|
+
let obbDistance = - Infinity;
|
|
96
|
+
|
|
97
|
+
if ( sphere ) {
|
|
98
|
+
|
|
99
|
+
// Sphere#distanceToPoint is negative inside the sphere, whereas Box3#distanceToPoint is
|
|
100
|
+
// zero inside the box. Clipping the distance to a minimum of zero ensures that both
|
|
101
|
+
// types of bounding volume behave the same way.
|
|
102
|
+
sphereDistance = Math.max( sphere.distanceToPoint( point ), 0 );
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if ( obb ) {
|
|
107
|
+
|
|
108
|
+
obbDistance = obb.distanceToPoint( point );
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// return the further distance of the two volumes
|
|
113
|
+
return sphereDistance > obbDistance ? sphereDistance : obbDistance;
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
intersectsFrustum( frustum ) {
|
|
118
|
+
|
|
119
|
+
const obb = this.obb || this.regionObb;
|
|
120
|
+
const sphere = this.sphere;
|
|
121
|
+
if ( sphere && ! frustum.intersectsSphere( sphere ) ) {
|
|
122
|
+
|
|
123
|
+
return false;
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if ( obb && ! obb.intersectsFrustum( frustum ) ) {
|
|
128
|
+
|
|
129
|
+
return false;
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// if we don't have a sphere or obb then just say we did intersect
|
|
134
|
+
return Boolean( sphere || obb );
|
|
135
|
+
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
getOBB( targetBox, targetMatrix ) {
|
|
139
|
+
|
|
140
|
+
const obb = this.obb || this.regionObb;
|
|
141
|
+
if ( obb ) {
|
|
142
|
+
|
|
143
|
+
targetBox.copy( obb.box );
|
|
144
|
+
targetMatrix.copy( obb.transform );
|
|
145
|
+
|
|
146
|
+
} else {
|
|
147
|
+
|
|
148
|
+
this.getAABB( targetBox );
|
|
149
|
+
targetMatrix.identity();
|
|
150
|
+
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
getAABB( target ) {
|
|
156
|
+
|
|
157
|
+
if ( this.sphere ) {
|
|
158
|
+
|
|
159
|
+
this.sphere.getBoundingBox( target );
|
|
160
|
+
|
|
161
|
+
} else {
|
|
162
|
+
|
|
163
|
+
const obb = this.obb || this.regionObb;
|
|
164
|
+
target.copy( obb.box ).applyMatrix4( obb.transform );
|
|
165
|
+
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
getSphere( target ) {
|
|
171
|
+
|
|
172
|
+
if ( this.sphere ) {
|
|
173
|
+
|
|
174
|
+
target.copy( this.sphere );
|
|
175
|
+
|
|
176
|
+
} else if ( this.region ) {
|
|
177
|
+
|
|
178
|
+
this.region.getBoundingSphere( target );
|
|
179
|
+
|
|
180
|
+
} else {
|
|
181
|
+
|
|
182
|
+
const obb = this.obb || this.regionObb;
|
|
183
|
+
obb.box.getBoundingSphere( target );
|
|
184
|
+
target.applyMatrix4( obb.transform );
|
|
185
|
+
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
setObbData( data, transform ) {
|
|
191
|
+
|
|
192
|
+
const obb = new OBB();
|
|
193
|
+
|
|
194
|
+
// get the extents of the bounds in each axis
|
|
195
|
+
_vecX.set( data[ 3 ], data[ 4 ], data[ 5 ] );
|
|
196
|
+
_vecY.set( data[ 6 ], data[ 7 ], data[ 8 ] );
|
|
197
|
+
_vecZ.set( data[ 9 ], data[ 10 ], data[ 11 ] );
|
|
198
|
+
|
|
199
|
+
const scaleX = _vecX.length();
|
|
200
|
+
const scaleY = _vecY.length();
|
|
201
|
+
const scaleZ = _vecZ.length();
|
|
202
|
+
|
|
203
|
+
_vecX.normalize();
|
|
204
|
+
_vecY.normalize();
|
|
205
|
+
_vecZ.normalize();
|
|
206
|
+
|
|
207
|
+
// handle the case where the box has a dimension of 0 in one axis
|
|
208
|
+
if ( scaleX === 0 ) {
|
|
209
|
+
|
|
210
|
+
_vecX.crossVectors( _vecY, _vecZ );
|
|
211
|
+
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if ( scaleY === 0 ) {
|
|
215
|
+
|
|
216
|
+
_vecY.crossVectors( _vecX, _vecZ );
|
|
217
|
+
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if ( scaleZ === 0 ) {
|
|
221
|
+
|
|
222
|
+
_vecZ.crossVectors( _vecX, _vecY );
|
|
223
|
+
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// create the oriented frame that the box exists in
|
|
227
|
+
obb.transform
|
|
228
|
+
.set(
|
|
229
|
+
_vecX.x, _vecY.x, _vecZ.x, data[ 0 ],
|
|
230
|
+
_vecX.y, _vecY.y, _vecZ.y, data[ 1 ],
|
|
231
|
+
_vecX.z, _vecY.z, _vecZ.z, data[ 2 ],
|
|
232
|
+
0, 0, 0, 1
|
|
233
|
+
)
|
|
234
|
+
.premultiply( transform );
|
|
235
|
+
|
|
236
|
+
// scale the box by the extents
|
|
237
|
+
obb.box.min.set( - scaleX, - scaleY, - scaleZ );
|
|
238
|
+
obb.box.max.set( scaleX, scaleY, scaleZ );
|
|
239
|
+
obb.update();
|
|
240
|
+
this.obb = obb;
|
|
241
|
+
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
setSphereData( x, y, z, radius, transform ) {
|
|
245
|
+
|
|
246
|
+
const sphere = new Sphere();
|
|
247
|
+
sphere.center.set( x, y, z );
|
|
248
|
+
sphere.radius = radius;
|
|
249
|
+
sphere.applyMatrix4( transform );
|
|
250
|
+
this.sphere = sphere;
|
|
251
|
+
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
setRegionData( ellipsoid, west, south, east, north, minHeight, maxHeight ) {
|
|
255
|
+
|
|
256
|
+
const region = new EllipsoidRegion(
|
|
257
|
+
...ellipsoid.radius,
|
|
258
|
+
south, north,
|
|
259
|
+
west, east,
|
|
260
|
+
minHeight, maxHeight,
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
const obb = new OBB();
|
|
264
|
+
region.getBoundingBox( obb.box, obb.transform );
|
|
265
|
+
obb.update();
|
|
266
|
+
|
|
267
|
+
this.region = region;
|
|
268
|
+
this.regionObb = obb;
|
|
269
|
+
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CesiumIonAuthPlugin as CesiumIonAuthPluginImpl } from '../../plugins/index.js';
|
|
2
|
+
|
|
3
|
+
export class CesiumIonAuthPlugin extends CesiumIonAuthPluginImpl {
|
|
4
|
+
|
|
5
|
+
constructor( ...args ) {
|
|
6
|
+
|
|
7
|
+
super( ...args );
|
|
8
|
+
console.warn( 'CesiumIonAuthPlugin: Plugins should now be imported from "3d-tiles-renderer/plugins" path.' );
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DebugTilesPlugin as DebugTilesPluginImpl } from '../../plugins/three/DebugTilesPlugin.js';
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
NONE,
|
|
5
|
+
SCREEN_ERROR,
|
|
6
|
+
GEOMETRIC_ERROR,
|
|
7
|
+
DISTANCE,
|
|
8
|
+
DEPTH,
|
|
9
|
+
RELATIVE_DEPTH,
|
|
10
|
+
IS_LEAF,
|
|
11
|
+
RANDOM_COLOR,
|
|
12
|
+
RANDOM_NODE_COLOR,
|
|
13
|
+
CUSTOM_COLOR,
|
|
14
|
+
LOAD_ORDER,
|
|
15
|
+
} from '../../plugins/three/DebugTilesPlugin.js';
|
|
16
|
+
|
|
17
|
+
export class DebugTilesPlugin extends DebugTilesPluginImpl {
|
|
18
|
+
|
|
19
|
+
constructor( ...args ) {
|
|
20
|
+
|
|
21
|
+
super( ...args );
|
|
22
|
+
console.warn( 'DebugTilesPlugin: Plugins should now be imported from "3d-tiles-renderer/plugins" path.' );
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { GoogleCloudAuthPlugin as GoogleCloudAuthPluginImpl } from '../../plugins/index.js';
|
|
2
|
+
|
|
3
|
+
export class GoogleCloudAuthPlugin extends GoogleCloudAuthPluginImpl {
|
|
4
|
+
|
|
5
|
+
constructor( ...args ) {
|
|
6
|
+
|
|
7
|
+
super( ...args );
|
|
8
|
+
console.warn( 'GoogleCloudAuthPlugin: Plugins should now be imported from "3d-tiles-renderer/plugins" path.' );
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
}
|