itowns 2.45.1-next.0 → 2.45.1-next.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/dist/455.js +2 -0
- package/dist/455.js.map +1 -0
- package/dist/debug.js +3 -0
- package/dist/debug.js.LICENSE.txt +13 -0
- package/dist/debug.js.map +1 -0
- package/dist/itowns.js +3 -0
- package/dist/itowns.js.LICENSE.txt +5 -0
- package/dist/itowns.js.map +1 -0
- package/dist/itowns_lasparser.js +2 -0
- package/dist/itowns_lasparser.js.map +1 -0
- package/dist/itowns_lasworker.js +2 -0
- package/dist/itowns_lasworker.js.map +1 -0
- package/dist/itowns_potree2worker.js +2 -0
- package/dist/itowns_potree2worker.js.map +1 -0
- package/dist/itowns_widgets.js +2 -0
- package/dist/itowns_widgets.js.map +1 -0
- package/lib/Controls/FirstPersonControls.js +308 -0
- package/lib/Controls/FlyControls.js +175 -0
- package/lib/Controls/GlobeControls.js +1178 -0
- package/lib/Controls/PlanarControls.js +1025 -0
- package/lib/Controls/StateControl.js +432 -0
- package/lib/Controls/StreetControls.js +392 -0
- package/lib/Converter/Feature2Mesh.js +612 -0
- package/lib/Converter/Feature2Texture.js +174 -0
- package/lib/Converter/convertToTile.js +70 -0
- package/lib/Converter/textureConverter.js +43 -0
- package/lib/Core/3DTiles/C3DTBatchTable.js +131 -0
- package/lib/Core/3DTiles/C3DTBatchTableHierarchyExtension.js +96 -0
- package/lib/Core/3DTiles/C3DTBoundingVolume.js +156 -0
- package/lib/Core/3DTiles/C3DTExtensions.js +97 -0
- package/lib/Core/3DTiles/C3DTFeature.js +110 -0
- package/lib/Core/3DTiles/C3DTilesEnums.js +20 -0
- package/lib/Core/3DTiles/C3DTileset.js +99 -0
- package/lib/Core/3DTiles/utils/BinaryPropertyAccessor.js +100 -0
- package/lib/Core/AnimationPlayer.js +142 -0
- package/lib/Core/CopcNode.js +174 -0
- package/lib/Core/Deprecated/Undeprecator.js +74 -0
- package/lib/Core/EntwinePointTileNode.js +126 -0
- package/lib/Core/Feature.js +488 -0
- package/lib/Core/Geographic/GeoidGrid.js +108 -0
- package/lib/Core/Label.js +222 -0
- package/lib/Core/MainLoop.js +209 -0
- package/lib/Core/Picking.js +255 -0
- package/lib/Core/PointCloudNode.js +42 -0
- package/lib/Core/Potree2Node.js +206 -0
- package/lib/Core/Potree2PointAttributes.js +139 -0
- package/lib/Core/PotreeNode.js +101 -0
- package/lib/Core/Prefab/Globe/Atmosphere.js +293 -0
- package/lib/Core/Prefab/Globe/GlobeLayer.js +152 -0
- package/lib/Core/Prefab/Globe/GlobeTileBuilder.js +110 -0
- package/lib/Core/Prefab/Globe/SkyShader.js +78 -0
- package/lib/Core/Prefab/GlobeView.js +155 -0
- package/lib/Core/Prefab/Planar/PlanarLayer.js +59 -0
- package/lib/Core/Prefab/Planar/PlanarTileBuilder.js +71 -0
- package/lib/Core/Prefab/PlanarView.js +62 -0
- package/lib/Core/Prefab/TileBuilder.js +82 -0
- package/lib/Core/Prefab/computeBufferTileGeometry.js +248 -0
- package/lib/Core/Scheduler/Cache.js +17 -0
- package/lib/Core/Scheduler/CancelledCommandException.js +15 -0
- package/lib/Core/Scheduler/Scheduler.js +294 -0
- package/lib/Core/Style.js +660 -0
- package/lib/Core/StyleOptions.js +486 -0
- package/lib/Core/System/Capabilities.js +63 -0
- package/lib/Core/Tile/Tile.js +205 -0
- package/lib/Core/Tile/TileGrid.js +49 -0
- package/lib/Core/TileGeometry.js +124 -0
- package/lib/Core/TileMesh.js +108 -0
- package/lib/Core/View.js +1115 -0
- package/lib/Layer/C3DTilesLayer.js +459 -0
- package/lib/Layer/ColorLayer.js +154 -0
- package/lib/Layer/CopcLayer.js +63 -0
- package/lib/Layer/ElevationLayer.js +139 -0
- package/lib/Layer/EntwinePointTileLayer.js +71 -0
- package/lib/Layer/FeatureGeometryLayer.js +77 -0
- package/lib/Layer/GeoidLayer.js +80 -0
- package/lib/Layer/GeometryLayer.js +233 -0
- package/lib/Layer/InfoLayer.js +64 -0
- package/lib/Layer/LabelLayer.js +469 -0
- package/lib/Layer/Layer.js +335 -0
- package/lib/Layer/LayerUpdateState.js +89 -0
- package/lib/Layer/LayerUpdateStrategy.js +80 -0
- package/lib/Layer/OGC3DTilesLayer.js +543 -0
- package/lib/Layer/OrientedImageLayer.js +227 -0
- package/lib/Layer/PointCloudLayer.js +405 -0
- package/lib/Layer/Potree2Layer.js +171 -0
- package/lib/Layer/PotreeLayer.js +72 -0
- package/lib/Layer/RasterLayer.js +37 -0
- package/lib/Layer/ReferencingLayerProperties.js +62 -0
- package/lib/Layer/TiledGeometryLayer.js +459 -0
- package/lib/Loader/LASLoader.js +193 -0
- package/lib/Loader/Potree2BrotliLoader.js +261 -0
- package/lib/Loader/Potree2Loader.js +207 -0
- package/lib/Main.js +113 -0
- package/lib/MainBundle.js +4 -0
- package/lib/Parser/B3dmParser.js +174 -0
- package/lib/Parser/CameraCalibrationParser.js +94 -0
- package/lib/Parser/GDFParser.js +72 -0
- package/lib/Parser/GTXParser.js +75 -0
- package/lib/Parser/GeoJsonParser.js +212 -0
- package/lib/Parser/GpxParser.js +25 -0
- package/lib/Parser/ISGParser.js +71 -0
- package/lib/Parser/KMLParser.js +25 -0
- package/lib/Parser/LASParser.js +137 -0
- package/lib/Parser/MapBoxUrlParser.js +83 -0
- package/lib/Parser/PntsParser.js +131 -0
- package/lib/Parser/Potree2BinParser.js +92 -0
- package/lib/Parser/PotreeBinParser.js +106 -0
- package/lib/Parser/PotreeCinParser.js +29 -0
- package/lib/Parser/ShapefileParser.js +78 -0
- package/lib/Parser/VectorTileParser.js +215 -0
- package/lib/Parser/XbilParser.js +120 -0
- package/lib/Parser/deprecated/LegacyGLTFLoader.js +1386 -0
- package/lib/Parser/iGLTFLoader.js +168 -0
- package/lib/Process/3dTilesProcessing.js +304 -0
- package/lib/Process/FeatureProcessing.js +76 -0
- package/lib/Process/LayeredMaterialNodeProcessing.js +229 -0
- package/lib/Process/ObjectRemovalHelper.js +97 -0
- package/lib/Process/handlerNodeError.js +23 -0
- package/lib/Provider/3dTilesProvider.js +149 -0
- package/lib/Provider/DataSourceProvider.js +24 -0
- package/lib/Provider/Fetcher.js +233 -0
- package/lib/Provider/PointCloudProvider.js +45 -0
- package/lib/Provider/TileProvider.js +16 -0
- package/lib/Provider/URLBuilder.js +116 -0
- package/lib/Renderer/Camera.js +281 -0
- package/lib/Renderer/Color.js +56 -0
- package/lib/Renderer/ColorLayersOrdering.js +115 -0
- package/lib/Renderer/CommonMaterial.js +31 -0
- package/lib/Renderer/Label2DRenderer.js +192 -0
- package/lib/Renderer/LayeredMaterial.js +243 -0
- package/lib/Renderer/OBB.js +150 -0
- package/lib/Renderer/OrientedImageCamera.js +118 -0
- package/lib/Renderer/OrientedImageMaterial.js +167 -0
- package/lib/Renderer/PointsMaterial.js +485 -0
- package/lib/Renderer/RasterTile.js +243 -0
- package/lib/Renderer/RenderMode.js +31 -0
- package/lib/Renderer/Shader/ShaderChunk.js +160 -0
- package/lib/Renderer/Shader/ShaderUtils.js +47 -0
- package/lib/Renderer/SphereHelper.js +17 -0
- package/lib/Renderer/WebXR.js +51 -0
- package/lib/Renderer/c3DEngine.js +214 -0
- package/lib/Source/C3DTilesGoogleSource.js +74 -0
- package/lib/Source/C3DTilesIonSource.js +54 -0
- package/lib/Source/C3DTilesSource.js +30 -0
- package/lib/Source/CopcSource.js +126 -0
- package/lib/Source/EntwinePointTileSource.js +72 -0
- package/lib/Source/FileSource.js +188 -0
- package/lib/Source/OGC3DTilesGoogleSource.js +29 -0
- package/lib/Source/OGC3DTilesIonSource.js +34 -0
- package/lib/Source/OGC3DTilesSource.js +21 -0
- package/lib/Source/OrientedImageSource.js +59 -0
- package/lib/Source/Potree2Source.js +167 -0
- package/lib/Source/PotreeSource.js +82 -0
- package/lib/Source/Source.js +202 -0
- package/lib/Source/TMSSource.js +144 -0
- package/lib/Source/VectorTilesSource.js +182 -0
- package/lib/Source/WFSSource.js +170 -0
- package/lib/Source/WMSSource.js +167 -0
- package/lib/Source/WMTSSource.js +92 -0
- package/lib/ThreeExtended/capabilities/WebGL.js +69 -0
- package/lib/ThreeExtended/libs/ktx-parse.module.js +506 -0
- package/lib/ThreeExtended/libs/zstddec.module.js +29 -0
- package/lib/ThreeExtended/loaders/DDSLoader.js +200 -0
- package/lib/ThreeExtended/loaders/DRACOLoader.js +400 -0
- package/lib/ThreeExtended/loaders/GLTFLoader.js +2879 -0
- package/lib/ThreeExtended/loaders/KTX2Loader.js +709 -0
- package/lib/ThreeExtended/math/ColorSpaces.js +59 -0
- package/lib/ThreeExtended/utils/BufferGeometryUtils.js +846 -0
- package/lib/ThreeExtended/utils/WorkerPool.js +70 -0
- package/lib/Utils/CameraUtils.js +554 -0
- package/lib/Utils/DEMUtils.js +350 -0
- package/lib/Utils/FeaturesUtils.js +156 -0
- package/lib/Utils/Gradients.js +16 -0
- package/lib/Utils/ThreeUtils.js +115 -0
- package/lib/Utils/gui/C3DTilesStyle.js +218 -0
- package/lib/Utils/gui/Main.js +7 -0
- package/lib/Utils/gui/Minimap.js +152 -0
- package/lib/Utils/gui/Navigation.js +245 -0
- package/lib/Utils/gui/Scale.js +104 -0
- package/lib/Utils/gui/Searchbar.js +234 -0
- package/lib/Utils/gui/Widget.js +80 -0
- package/lib/Utils/placeObjectOnGround.js +136 -0
- package/lib/Worker/LASLoaderWorker.js +19 -0
- package/lib/Worker/Potree2Worker.js +21 -0
- package/package.json +2 -2
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { TileGeometry } from "../Core/TileGeometry.js";
|
|
3
|
+
import { GlobeTileBuilder } from "../Core/Prefab/Globe/GlobeTileBuilder.js";
|
|
4
|
+
import { CRS, Coordinates } from '@itowns/geographic';
|
|
5
|
+
|
|
6
|
+
// get oriented bounding box of tile
|
|
7
|
+
const builder = new GlobeTileBuilder({
|
|
8
|
+
uvCount: 1
|
|
9
|
+
});
|
|
10
|
+
const size = new THREE.Vector3();
|
|
11
|
+
const dimension = new THREE.Vector2();
|
|
12
|
+
const center = new THREE.Vector3();
|
|
13
|
+
const coord = new Coordinates('EPSG:4326', 0, 0, 0);
|
|
14
|
+
let obb;
|
|
15
|
+
|
|
16
|
+
// it could be considered to remove THREE.Object3D extend.
|
|
17
|
+
/**
|
|
18
|
+
* Oriented bounding box
|
|
19
|
+
* @extends THREE.Object3D
|
|
20
|
+
*/
|
|
21
|
+
class OBB extends THREE.Object3D {
|
|
22
|
+
/**
|
|
23
|
+
* @param {THREE.Vector3} min representing the lower (x, y, z) boundary of the box. Default is ( + Infinity, + Infinity, + Infinity ).
|
|
24
|
+
* @param {THREE.Vector3} max representing the lower upper (x, y, z) boundary of the box. Default is ( - Infinity, - Infinity, - Infinity ).
|
|
25
|
+
*/
|
|
26
|
+
constructor() {
|
|
27
|
+
let min = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new THREE.Vector3(+Infinity, +Infinity, +Infinity);
|
|
28
|
+
let max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new THREE.Vector3(-Infinity, -Infinity, -Infinity);
|
|
29
|
+
super();
|
|
30
|
+
this.box3D = new THREE.Box3(min.clone(), max.clone());
|
|
31
|
+
this.natBox = this.box3D.clone();
|
|
32
|
+
this.z = {
|
|
33
|
+
min: 0,
|
|
34
|
+
max: 0,
|
|
35
|
+
scale: 1.0
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new instance of the object with same properties than original.
|
|
41
|
+
*
|
|
42
|
+
* @return {OBB} Copy of this object.
|
|
43
|
+
*/
|
|
44
|
+
clone() {
|
|
45
|
+
return new OBB().copy(this);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Copy the property of OBB
|
|
50
|
+
*
|
|
51
|
+
* @param {OBB} cOBB OBB to copy
|
|
52
|
+
* @return {OBB} the copy
|
|
53
|
+
*/
|
|
54
|
+
copy(cOBB) {
|
|
55
|
+
super.copy(cOBB);
|
|
56
|
+
this.box3D.copy(cOBB.box3D);
|
|
57
|
+
this.natBox.copy(cOBB.natBox);
|
|
58
|
+
this.z.min = cOBB.z.min;
|
|
59
|
+
this.z.max = cOBB.z.max;
|
|
60
|
+
this.z.scale = cOBB.z.scale;
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Update z min, z max and z scale of oriented bounding box
|
|
66
|
+
*
|
|
67
|
+
* @param {Object} [elevation={}]
|
|
68
|
+
* @param {number} [elevation.min] The minimum of oriented bounding box
|
|
69
|
+
* @param {number} [elevation.max] The maximum of oriented bounding box
|
|
70
|
+
* @param {number} [elevation.scale] The scale of oriented bounding box Z axis
|
|
71
|
+
* @param {number} [elevation.geoidHeight] The geoid height added to ellipsoid.
|
|
72
|
+
*/
|
|
73
|
+
updateZ() {
|
|
74
|
+
let elevation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
75
|
+
this.z.min = elevation.min ?? this.z.min;
|
|
76
|
+
this.z.max = elevation.max ?? this.z.max;
|
|
77
|
+
this.z.scale = elevation.scale > 0 ? elevation.scale : this.z.scale;
|
|
78
|
+
this.z.delta = Math.abs(this.z.max - this.z.min) * this.z.scale;
|
|
79
|
+
const geoidHeight = elevation.geoidHeight || 0;
|
|
80
|
+
this.box3D.min.z = this.natBox.min.z + this.z.min * this.z.scale + geoidHeight;
|
|
81
|
+
this.box3D.max.z = this.natBox.max.z + this.z.max * this.z.scale + geoidHeight;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Determines if the sphere is above the XY space of the box
|
|
86
|
+
*
|
|
87
|
+
* @param {Sphere} sphere The sphere
|
|
88
|
+
* @return {boolean} True if sphere is above the XY space of the box, False otherwise.
|
|
89
|
+
*/
|
|
90
|
+
isSphereAboveXYBox(sphere) {
|
|
91
|
+
const localSpherePosition = this.worldToLocal(sphere.center);
|
|
92
|
+
// get obb closest point to sphere center by clamping
|
|
93
|
+
const x = Math.max(this.box3D.min.x, Math.min(localSpherePosition.x, this.box3D.max.x));
|
|
94
|
+
const y = Math.max(this.box3D.min.y, Math.min(localSpherePosition.y, this.box3D.max.y));
|
|
95
|
+
|
|
96
|
+
// this is the same as isPointInsideSphere.position
|
|
97
|
+
const distance = Math.sqrt((x - localSpherePosition.x) * (x - localSpherePosition.x) + (y - localSpherePosition.y) * (y - localSpherePosition.y));
|
|
98
|
+
return distance < sphere.radius;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Compute OBB from extent.
|
|
103
|
+
* The OBB resulted can be only in the system 'EPSG:3946'.
|
|
104
|
+
*
|
|
105
|
+
* @param {Extent} extent The extent (with crs 'EPSG:4326') to compute oriented bounding box
|
|
106
|
+
* @param {number} minHeight The minimum height of OBB
|
|
107
|
+
* @param {number} maxHeight The maximum height of OBB
|
|
108
|
+
* @return {OBB} return this object
|
|
109
|
+
*/
|
|
110
|
+
setFromExtent(extent) {
|
|
111
|
+
let minHeight = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : extent.min || 0;
|
|
112
|
+
let maxHeight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : extent.max || 0;
|
|
113
|
+
if (extent.crs == 'EPSG:4326') {
|
|
114
|
+
const {
|
|
115
|
+
shareableExtent,
|
|
116
|
+
quaternion,
|
|
117
|
+
position
|
|
118
|
+
} = builder.computeShareableExtent(extent);
|
|
119
|
+
// Compute the minimum count of segment to build tile
|
|
120
|
+
const segments = Math.max(Math.floor(shareableExtent.planarDimensions(dimension).x / 90 + 1), 2);
|
|
121
|
+
const geometry = new TileGeometry(builder, {
|
|
122
|
+
extent: shareableExtent,
|
|
123
|
+
level: 0,
|
|
124
|
+
segments,
|
|
125
|
+
disableSkirt: true
|
|
126
|
+
});
|
|
127
|
+
obb.box3D.copy(geometry.boundingBox);
|
|
128
|
+
obb.natBox.copy(geometry.boundingBox);
|
|
129
|
+
this.copy(obb);
|
|
130
|
+
this.updateZ({
|
|
131
|
+
min: minHeight,
|
|
132
|
+
max: maxHeight
|
|
133
|
+
});
|
|
134
|
+
this.position.copy(position);
|
|
135
|
+
this.quaternion.copy(quaternion);
|
|
136
|
+
this.updateMatrixWorld(true);
|
|
137
|
+
} else if (CRS.isMetricUnit(extent.crs)) {
|
|
138
|
+
extent.center(coord).toVector3(this.position);
|
|
139
|
+
extent.planarDimensions(dimension);
|
|
140
|
+
size.set(dimension.x, dimension.y, Math.abs(maxHeight - minHeight));
|
|
141
|
+
this.box3D.setFromCenterAndSize(center, size);
|
|
142
|
+
this.updateMatrixWorld(true);
|
|
143
|
+
} else {
|
|
144
|
+
throw new Error('Unsupported extent crs');
|
|
145
|
+
}
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
obb = new OBB();
|
|
150
|
+
export default OBB;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
class Distortion {
|
|
3
|
+
constructor(size) {
|
|
4
|
+
this.size = size;
|
|
5
|
+
this.pps = null;
|
|
6
|
+
this.polynom = null;
|
|
7
|
+
this.l1l2 = null;
|
|
8
|
+
}
|
|
9
|
+
setFromMicmacCalibration(distortion) {
|
|
10
|
+
let imageYDown = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
11
|
+
this.pps = new THREE.Vector2().fromArray(distortion.pps);
|
|
12
|
+
this.polynom = new THREE.Vector4().fromArray(distortion.poly357);
|
|
13
|
+
this.l1l2 = new THREE.Vector3();
|
|
14
|
+
// inverse Y pps convention image micmac
|
|
15
|
+
this.pps.y = imageYDown ? this.size.y - this.pps.y : this.pps.y;
|
|
16
|
+
this.polynom.w = distortion.limit ** 2;
|
|
17
|
+
if (distortion.l1l2) {
|
|
18
|
+
this.l1l2.fromArray(distortion.l1l2);
|
|
19
|
+
this.l1l2.z = distortion.etats;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
clone() {
|
|
23
|
+
const dest = new Distortion(this.size.clone());
|
|
24
|
+
dest.pps = this.pps.clone();
|
|
25
|
+
dest.polynom = this.polynom.clone();
|
|
26
|
+
dest.l1l2 = this.l1l2.clone();
|
|
27
|
+
return dest;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const zoom = new THREE.Vector3();
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* OrientedImageCamera is a ThreeJs camera adapted to photogrammetric description.
|
|
34
|
+
* So we can build a ThreeJs perspective camera from size and focal information.
|
|
35
|
+
*/
|
|
36
|
+
class OrientedImageCamera extends THREE.PerspectiveCamera {
|
|
37
|
+
/**
|
|
38
|
+
* @param {number|Vector2} size - image size in pixels (default: x=1024, y=x)
|
|
39
|
+
* @param {number|Vector2} focal - focal length in pixels (default: x=1024, y=x)
|
|
40
|
+
* @param {Vector2} center - principal point in pixels (default: size/2)
|
|
41
|
+
* @param {number} near - Camera frustum near plane (default: see THREE.PerspectiveCamera).
|
|
42
|
+
* @param {number} far - Camera frustum far plane (default: see THREE.PerspectiveCamera).
|
|
43
|
+
* @param {number} skew - shear transform parameter (default: 0)
|
|
44
|
+
* @param {number} aspect - aspect ratio of the camera (default: size.x/size.y).
|
|
45
|
+
*/
|
|
46
|
+
constructor() {
|
|
47
|
+
let size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1024;
|
|
48
|
+
let focal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1024;
|
|
49
|
+
let center = arguments.length > 2 ? arguments[2] : undefined;
|
|
50
|
+
let near = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0.1;
|
|
51
|
+
let far = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 10000;
|
|
52
|
+
let skew = arguments.length > 5 ? arguments[5] : undefined;
|
|
53
|
+
let aspect = arguments.length > 6 ? arguments[6] : undefined;
|
|
54
|
+
size = size.isVector2 ? size : new THREE.Vector2(size, size);
|
|
55
|
+
aspect = aspect || size.x / size.y;
|
|
56
|
+
super(undefined, aspect, near, far);
|
|
57
|
+
this.size = size;
|
|
58
|
+
this.focal = focal.isVector2 ? focal : new THREE.Vector2(focal, focal);
|
|
59
|
+
this.center = center || size.clone().multiplyScalar(0.5);
|
|
60
|
+
this.skew = skew || 0;
|
|
61
|
+
this.textureMatrixWorldInverse = new THREE.Matrix4();
|
|
62
|
+
Object.defineProperty(this, 'fov', {
|
|
63
|
+
get: () => 2 * THREE.MathUtils.radToDeg(Math.atan2(this.size.y, 2 * this.focal.y)),
|
|
64
|
+
// setting the fov overwrites focal.x and focal.y
|
|
65
|
+
set: fov => {
|
|
66
|
+
const focal = 0.5 * this.size.y / Math.tan(THREE.MathUtils.degToRad(fov * 0.5));
|
|
67
|
+
this.focal.x = focal;
|
|
68
|
+
this.focal.y = focal;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
this.distortion = new Distortion(this.size);
|
|
72
|
+
this.maskPath = undefined;
|
|
73
|
+
this.mask = undefined;
|
|
74
|
+
this.updateProjectionMatrix();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// we override PerspectiveCamera.updateProjectionMatrix to
|
|
78
|
+
// update the projection matrix depending on other variables
|
|
79
|
+
// focal, center and size...
|
|
80
|
+
updateProjectionMatrix() {
|
|
81
|
+
if (!this.focal) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const near = this.near;
|
|
85
|
+
const sx = near / this.focal.x;
|
|
86
|
+
const sy = near / this.focal.y;
|
|
87
|
+
const left = -sx * this.center.x;
|
|
88
|
+
const bottom = -sy * this.center.y;
|
|
89
|
+
const right = left + sx * this.size.x;
|
|
90
|
+
const top = bottom + sy * this.size.y;
|
|
91
|
+
this.projectionMatrix.makePerspective(left, right, top, bottom, near, this.far);
|
|
92
|
+
this.projectionMatrix.elements[4] = 2 * this.skew / this.size.x;
|
|
93
|
+
|
|
94
|
+
// take zoom and aspect into account
|
|
95
|
+
const textureAspect = this.size.x / this.size.y;
|
|
96
|
+
const aspectRatio = this.aspect / textureAspect;
|
|
97
|
+
zoom.set(this.zoom, this.zoom, 1);
|
|
98
|
+
if (aspectRatio > 1) {
|
|
99
|
+
zoom.x /= aspectRatio;
|
|
100
|
+
} else {
|
|
101
|
+
zoom.y *= aspectRatio;
|
|
102
|
+
}
|
|
103
|
+
this.projectionMatrix.scale(zoom);
|
|
104
|
+
}
|
|
105
|
+
copy(source, recursive) {
|
|
106
|
+
super.copy(source, recursive);
|
|
107
|
+
this.size = source.size.clone();
|
|
108
|
+
this.focal = source.focal.clone();
|
|
109
|
+
this.center = source.center.clone();
|
|
110
|
+
this.distortion = source.distortion.clone();
|
|
111
|
+
this.textureMatrixWorldInverse = source.textureMatrixWorldInverse.clone();
|
|
112
|
+
this.skew = source.skew;
|
|
113
|
+
this.maskPath = source.maskPath;
|
|
114
|
+
this.mask = source.mask;
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export default OrientedImageCamera;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import Capabilities from "../Core/System/Capabilities.js";
|
|
3
|
+
import ShaderUtils from "./Shader/ShaderUtils.js";
|
|
4
|
+
/* babel-plugin-inline-import './Shader/ProjectiveTextureVS.glsl' */
|
|
5
|
+
const textureVS = "#include <itowns/precision_qualifier>\n#include <itowns/projective_texturing_pars_vertex>\n#include <common>\n#include <logdepthbuf_pars_vertex>\n\nvarying vec3 vNormal;\n\nvoid main() {\n #include <begin_vertex>\n #include <project_vertex>\n vNormal = normal;\n #include <itowns/projective_texturing_vertex>\n #include <logdepthbuf_vertex>\n}\n";
|
|
6
|
+
/* babel-plugin-inline-import './Shader/ProjectiveTextureFS.glsl' */
|
|
7
|
+
const textureFS = "#include <itowns/precision_qualifier>\n#include <logdepthbuf_pars_fragment>\n#include <itowns/projective_texturing_pars_fragment>\nvarying vec3 vNormal;\n\n#ifdef USE_BASE_MATERIAL\nstruct noPT {\n vec3 lightDirection;\n vec3 ambient;\n float opacity;\n};\n\nuniform noPT noProjectiveMaterial;\n#endif\n\nvoid main(void)\n{\n #include <logdepthbuf_fragment>\n #ifdef USE_BASE_MATERIAL\n float nDotVP = (max(0.1, dot(vNormal, normalize(noProjectiveMaterial.lightDirection))));\n vec4 color = vec4(noProjectiveMaterial.ambient + nDotVP, 0.0);\n #else\n vec4 color = vec4(0.0);\n #endif\n\n #pragma unroll_loop\n for (int i = 0; i < ORIENTED_IMAGES_COUNT; i++) {\n color = projectiveTextureColor(projectiveTextureCoords[ ORIENTED_IMAGES_COUNT - 1 - i ], projectiveTextureDistortion[ ORIENTED_IMAGES_COUNT - 1 - i ], projectiveTexture[ ORIENTED_IMAGES_COUNT - 1 - i ], mask[ORIENTED_IMAGES_COUNT - 1 - i], color);\n }\n\n #ifdef USE_BASE_MATERIAL\n color.a = color.a < 1.0 ? max(noProjectiveMaterial.opacity, color.a) : 1.0 ;\n gl_FragColor = vec4(color.rgb, color.a * opacity);\n #else\n gl_FragColor = vec4(color.rgb / color.a, opacity);\n #endif\n\n}\n";
|
|
8
|
+
const ndcToTextureMatrix = new THREE.Matrix4(1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 2, 0, 0, 0, 0, 2);
|
|
9
|
+
const noMask = new THREE.DataTexture(new Uint8Array([255, 255, 255, 255]), 1, 1, THREE.RGBAFormat, THREE.UnsignedByteType);
|
|
10
|
+
noMask.needsUpdate = true;
|
|
11
|
+
const noTexture = new THREE.Texture();
|
|
12
|
+
const shaderMaterial = new THREE.ShaderMaterial();
|
|
13
|
+
/**
|
|
14
|
+
* OrientedImageMaterial is a custom shader material used to do projective texture mapping.<br/>
|
|
15
|
+
*
|
|
16
|
+
* This Material is designed to project many textures simultaneously.
|
|
17
|
+
* Each projected texture setting is stored as an {@link OrientedImageCamera}.<br/>
|
|
18
|
+
* <br/>
|
|
19
|
+
* All cameras settings, like distorsion, can be specified in a configuration file.
|
|
20
|
+
* See [CameraCalibrationParser]{@link module:CameraCalibrationParser.parse}
|
|
21
|
+
* used to parse a configuration file and create an array of camera.<br/>
|
|
22
|
+
* <br/>
|
|
23
|
+
* The current implementation supports the following distortion models : <br/>
|
|
24
|
+
* - no distortion (polynom==vec3(0),l1l2==vec2(0))<br/>
|
|
25
|
+
* - radial distortion (polynom!=vec3(0),l1l2==vec2(0)) (see <b>15.2.2 Radial Model</b> in [MicMac doc](https://github.com/micmacIGN/Documentation/blob/master/DocMicMac.pdf)) </br>
|
|
26
|
+
* - equilinear fish eye distortion (polynom!=vec3(0),l1l2 != vec2(0)) (see <b>15.3.4 Fish eye models</b> in [MicMac doc](https://github.com/micmacIGN/Documentation/blob/master/DocMicMac.pdf)) </br>
|
|
27
|
+
* (Note: radial decentric parameters P1 are P2 not supported and assumed to be 0).<br/>
|
|
28
|
+
* <br/>
|
|
29
|
+
* To get a more comprehensive support of camera Micmac models, you can consider using [three-photogrammetric-camera]{@link https://github.com/mbredif/three-photogrammetric-camera} instead.
|
|
30
|
+
*/
|
|
31
|
+
class OrientedImageMaterial extends THREE.ShaderMaterial {
|
|
32
|
+
/**
|
|
33
|
+
* @param { OrientedImageCamera[]} cameras - Array of {@link OrientedImageCamera}. Each camera will project a texture.
|
|
34
|
+
* [CameraCalibrationParser]{@link module:CameraCalibrationParser.parse} can used to create this array of camera from a configuration file.
|
|
35
|
+
* @param {Object} [options={}] - Object with one or more properties defining the material's appearance.
|
|
36
|
+
* Any property of the material (including any property inherited from
|
|
37
|
+
* [THREE.Material]{@link https://threejs.org/docs/#api/en/materials/Material} and
|
|
38
|
+
* [THREE.ShaderMaterial]{@link https://threejs.org/docs/#api/en/materials/ShaderMaterial}) can be passed in here.
|
|
39
|
+
* @param {Number} [options.side=THREE.DoubleSide] - We override default
|
|
40
|
+
* [THREE.Material.side]{@link https://threejs.org/docs/#api/en/materials/Material.side} from FrontSide to DoubleSide.
|
|
41
|
+
* @param {Boolean} [options.transparent=true] - We override default
|
|
42
|
+
* [THREE.Material.transparent]{@link https://threejs.org/docs/#api/en/materials/Material.transparent} from false to true.
|
|
43
|
+
* @param {Number} [options.opacity=0.1] - We override default
|
|
44
|
+
* [THREE.Material.opacity]{@link https://threejs.org/docs/#api/en/materials/Material.opacity} from 1 to 0.1.
|
|
45
|
+
* @param {Number} [options.alphaBorder=20] - Part of the texture that is blended, when texture crosses each other.
|
|
46
|
+
* For example, 10 means a border as large as 1 / 10 of the size of the texture is used to blend colors.
|
|
47
|
+
* @param {Number} [options.debugAlphaBorder=0] - Set this option to 1 to see influence of alphaBorder option.
|
|
48
|
+
*/
|
|
49
|
+
constructor(cameras) {
|
|
50
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
51
|
+
options.side = options.side ?? THREE.DoubleSide;
|
|
52
|
+
options.transparent = options.transparent ?? true;
|
|
53
|
+
options.opacity = options.opacity ?? 1;
|
|
54
|
+
|
|
55
|
+
// Filter out non-ShaderMaterial options
|
|
56
|
+
const shaderMaterialOptions = {};
|
|
57
|
+
for (const key in options) {
|
|
58
|
+
if (Object.prototype.hasOwnProperty.call(options, key)) {
|
|
59
|
+
const currentValue = shaderMaterial[key];
|
|
60
|
+
if (currentValue !== undefined) {
|
|
61
|
+
shaderMaterialOptions[key] = options[key];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
super(shaderMaterialOptions);
|
|
66
|
+
this.defines.ORIENTED_IMAGES_COUNT = options.OrientedImagesCount ?? cameras.length;
|
|
67
|
+
|
|
68
|
+
// verify that number of textures doesn't exceed GPU capabilities
|
|
69
|
+
const maxTexturesUnits = Capabilities.getMaxTextureUnitsCount();
|
|
70
|
+
if (this.defines.ORIENTED_IMAGES_COUNT > maxTexturesUnits) {
|
|
71
|
+
console.warn(`OrientedImageMaterial: Can't project ${cameras.length} textures, because it's more than GPU capabilities maximum texture units (${maxTexturesUnits})`);
|
|
72
|
+
|
|
73
|
+
// Clamp number of textures used
|
|
74
|
+
this.defines.ORIENTED_IMAGES_COUNT = maxTexturesUnits - 1;
|
|
75
|
+
console.warn(`OrientedImageMaterial: We'll use only the first ${this.defines.ORIENTED_IMAGES_COUNT} cameras.`);
|
|
76
|
+
}
|
|
77
|
+
if (options.useBaseMaterial) {
|
|
78
|
+
this.defines.USE_BASE_MATERIAL = true;
|
|
79
|
+
}
|
|
80
|
+
this.defines.USE_DISTORTION = Number(cameras.some(camera => camera.distortion.pps !== null));
|
|
81
|
+
this.alphaBorder = options.alphaBorder | 20;
|
|
82
|
+
this.defines.DEBUG_ALPHA_BORDER = options.debugAlphaBorder | 0;
|
|
83
|
+
this.cameras = cameras;
|
|
84
|
+
const textureMatrix = [];
|
|
85
|
+
const texture = [];
|
|
86
|
+
const mask = [];
|
|
87
|
+
const distortion = [];
|
|
88
|
+
this.group = new THREE.Group();
|
|
89
|
+
for (let i = 0; i < this.defines.ORIENTED_IMAGES_COUNT; ++i) {
|
|
90
|
+
texture[i] = noTexture;
|
|
91
|
+
mask[i] = noMask;
|
|
92
|
+
textureMatrix[i] = new THREE.Matrix4();
|
|
93
|
+
cameras[i].needsUpdate = true;
|
|
94
|
+
distortion[i] = cameras[i].distortion;
|
|
95
|
+
this.group.add(cameras[i]);
|
|
96
|
+
}
|
|
97
|
+
this.uniforms.opacity = new THREE.Uniform(this.opacity);
|
|
98
|
+
this.uniforms.projectiveTextureAlphaBorder = new THREE.Uniform(this.alphaBorder);
|
|
99
|
+
this.uniforms.projectiveTextureDistortion = new THREE.Uniform(distortion);
|
|
100
|
+
this.uniforms.projectiveTextureMatrix = new THREE.Uniform(textureMatrix);
|
|
101
|
+
this.uniforms.projectiveTexture = new THREE.Uniform(texture);
|
|
102
|
+
this.uniforms.mask = new THREE.Uniform(mask);
|
|
103
|
+
this.uniforms.boostLight = new THREE.Uniform(false);
|
|
104
|
+
this.uniforms.noProjectiveMaterial = new THREE.Uniform({
|
|
105
|
+
lightDirection: new THREE.Vector3(0.5, 0.5, -0.5),
|
|
106
|
+
ambient: new THREE.Color(0.1, 0.1, 0.1),
|
|
107
|
+
opacity: 0.75
|
|
108
|
+
});
|
|
109
|
+
this.vertexShader = textureVS;
|
|
110
|
+
// three loop unrolling of ShaderMaterial only supports integer bounds,
|
|
111
|
+
// see https://github.com/mrdoob/three.js/issues/28020
|
|
112
|
+
this.fragmentShader = ShaderUtils.unrollLoops(textureFS, this.defines);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Set new textures and new position/orientation of the camera set.
|
|
117
|
+
* @param {THREE.Texture} textures - Array of [THREE.Texture]{@link https://threejs.org/docs/#api/en/textures/Texture}.
|
|
118
|
+
* @param {Object} feature - New position / orientation of the set of cameras
|
|
119
|
+
* @param {THREE.Vector3} feature.position - New position.
|
|
120
|
+
* @param {THREE.Quaternion} feature.quaternion - New orientation.
|
|
121
|
+
* @param {Array} camerasNames - camera names of panoramic feature
|
|
122
|
+
*/
|
|
123
|
+
setTextures(textures, feature, camerasNames) {
|
|
124
|
+
if (!textures) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
this.group.position.copy(feature.position);
|
|
128
|
+
this.group.quaternion.copy(feature.quaternion);
|
|
129
|
+
for (let i = 0; i < textures.length && i < this.defines.ORIENTED_IMAGES_COUNT; ++i) {
|
|
130
|
+
this.uniforms.projectiveTexture.value[i].dispose();
|
|
131
|
+
this.uniforms.projectiveTexture.value[i] = textures[i];
|
|
132
|
+
|
|
133
|
+
// check camera changes
|
|
134
|
+
if (camerasNames) {
|
|
135
|
+
const currentCamera = this.group.children[i];
|
|
136
|
+
if (camerasNames[i] != currentCamera.name) {
|
|
137
|
+
const camera = this.cameras.find(cam => cam.name === camerasNames[i]);
|
|
138
|
+
this.uniforms.mask.value[i] = camera.maskTexture || noMask;
|
|
139
|
+
this.uniforms.mask.value[i].needsUpdate = true;
|
|
140
|
+
this.uniforms.projectiveTextureDistortion.value[i] = camera.distortion;
|
|
141
|
+
this.group.children[i] = camera;
|
|
142
|
+
camera.parent = this.group;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
this.group.children[i].needsUpdate = true;
|
|
146
|
+
}
|
|
147
|
+
this.group.updateMatrixWorld(true); // update the matrixWorldInverse of the cameras
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Udate the uniforms using the current value of camera.matrixWorld.
|
|
152
|
+
* Need to be called when the camera of the scene has changed.
|
|
153
|
+
* @param {THREE.Camera} viewCamera - Camera of the scene.
|
|
154
|
+
*/
|
|
155
|
+
updateUniforms(viewCamera) {
|
|
156
|
+
for (let i = 0; i < this.group.children.length; ++i) {
|
|
157
|
+
const camera = this.group.children[i];
|
|
158
|
+
if (camera.needsUpdate) {
|
|
159
|
+
camera.textureMatrixWorldInverse.multiplyMatrices(ndcToTextureMatrix, camera.projectionMatrix);
|
|
160
|
+
camera.textureMatrixWorldInverse.multiply(camera.matrixWorldInverse);
|
|
161
|
+
camera.needsUpdate = false;
|
|
162
|
+
}
|
|
163
|
+
this.uniforms.projectiveTextureMatrix.value[i].multiplyMatrices(camera.textureMatrixWorldInverse, viewCamera.matrixWorld);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
export default OrientedImageMaterial;
|