三.js 的 3DTiles 查看器
A faster 3DTiles viewer for three.js, now with OGC3DTiles 1.1 support.
Oh, also it supports gaussian splats! ( currently via KHR_gaussian_splatting_compression_spz )
contextsplat.xyz is a web tool that let's you convert 3dgs to OGC3DTILES directly in the browser, view them in a geospatial context and download them or a starter three.js app.
Getting started vanilla js:
app
code
Google Tiles overlay overlay high quality meshes over google tiles with some shader magic to avoid overlap
Windows desktop viewer A viewer for windows based on flutter and this library
Google Map Tile API google tiles in a geospatial framework ULTRAGLOBE
Photogrametry Some tiles converted from OBJ via proprietary ULTRAMESH tool
PBR material (GlTF conversion)
Occlusion culling (IFC conversion) Occlusion culling applied at the tile-loading level. This isn't just GPU occlusion culling, hidden tiles aren't even downloaded.
Instanced Tileset A multitude of identical meshes, each with its own LOD hiearchy but duplicate tiles are instanced
install the library:
npm install three @jdultra/threedtilesAdding a tileset to a scene is as easy as :
import { OGC3DTile } from '@jdultra/threedtiles';
...
const ogc3DTile = new OGC3DTile({
url: "https://storage.googleapis.com/ogc-3d-tiles/ayutthaya/tileset.json",
renderer: renderer
});
scene.add(ogc3DTile);It's up to the user to call updates on the tileset.
function animate() {
requestAnimationFrame(animate);
ogc3DTile.update(camera); // computes what tiles need to be refined and what tiles can be disposed.
ogc3DTile.tileLoader.update(); // downloads, loads and caches tiles in optimal order.
...
}It is discouraged to call the update functions outside the render loop in a setInterval for example. While that may work fine on desktop, mobile browsers tend to block an entire frame when a timeout triggers in it.
If you need to convert meshes to 3DTiles, from small assets to gigabytes of data, contact me for a trial on UltraMesh tool. It works for all types of meshes: photogrametry, BIM, colored or textured meshes with a single texture atlas or many individual textures. There's support for OBJ, IFC, Collada and glTF meshes and las/laz point clouds. I aim for optimal quality in terms of mesh, texture and tileset structure and for optimal streaming speed, with no limit to the size of the input data. Contact: [email protected]
OGC3DTiles 1.1 are supported. There is no plan to support .pnts, .i3dm or .cmpt tiles as these formats are deprecated in favor of glb/gltf tiles.
The geometric error multiplier allows you to multiply the geometric error by a factor.
tileset.setGeometricErrorMultiplier(1.5);you may also set this value at initialization:
const ogc3DTile = new OGC3DTile({
url: "https://storage.googleapis.com/ogc-3d-tiles/ayutthaya/tileset.json",
renderer: renderer,
geometricErrorMultiplier: 2.0
});A lower value will result in lower detail tiles being loaded and a higher value results in higher detail tiles being loaded. A value of 1.0 is the default.
Many viewers use the maxScreenSpaceError instead of a geometric error multiplier and there is a direct correspondance. A geometricErrorMultiplier of 1 corresponds to a maxScreenSpaceError of 16. A geometricErrorMultiplier of 0.5 corresponds to a maxScreenSpaceError of 32.
The distance bias allows loading more or less detail close to the camera relative to further away. The distance bias simply applies an exponent on tile distance to the camera so you have to balance it out manually with the geometricErrorMultiplier.
For example, if you want to load more detail close to the camera, you might do something like this:
const ogc3DTile = new OGC3DTile({
url: "https://storage.googleapis.com/ogc-3d-tiles/ayutthaya/tileset.json",
renderer: renderer,
geometricErrorMultiplier: 10.0,
distanceBias: 1.5
});In this case the higher distance bias will cause less detail to be loaded overall since all calculated distances get raised to the power 1.5. To compensate, the geometricErrorMultiplier is set at a higher value.
These values need to be adjusted manually based on what is considered relatively close or far from the camera and truly depends on your scene and the relative distance of the camera to the tiles during normal navigation. In other words, it's impossible to have magic bullet values the LOD switch distance can be fine-tuned through those parameters.
You can change the distance bias for a tileset at any time:
tileset.setDistanceBias(1.5);Incremental loading is the default and loads all intermediate levels incrementally and keeps them in memory. While this gives a direct feedback on loading progress, the CPU memory footprint is large and overall loading speed is slower than with "immediate" mode.
To explicitely set the incremental loading strategy:
const ogc3DTile = new OGC3DTile({
url: "https://storage.googleapis.com/ogc-3d-tiles/ayutthaya/tileset.json",
renderer: renderer,
loadingStrategy: "INTERMEDIATE"
});Immediate loading skips intermediate LODs and immediately loads the ideal LOD. Less data is downloaded (faster load time) and less data is kept in CPU memory but holes will appear until the tiles are loaded.
To set the immediate loading strategy:
const ogc3DTile = new OGC3DTile({
url: "https://storage.googleapis.com/ogc-3d-tiles/ayutthaya/tileset.json",
renderer: renderer,
loadingStrategy: "IMMEDIATE"
});PERLEVEL loading loads all required tiles of a given level before moving to the higher level of detail tiles.
To set the PERLEVEL loading strategy:
const ogc3DTile = new OGC3DTile({
url: "https://storage.googleapis.com/ogc-3d-tiles/ayutthaya/tileset.json",
renderer: renderer,
loadingStrategy: "PERLEVEL"
});By default, only the tiles that intersect the view frustum are loaded. When the camera moves, the scene will have to load the missing tiles and the user might see some holes in the model. Instead of this behaviour, you can force the lowest possible LODs to be loaded for tiles outside the view so that there are no gaps in the mesh when the camera moves. This also allows displaying shadows from parts of the scene that are not in the view.
const ogc3DTile = new OGC3DTile({
url: "https://storage.googleapis.com/ogc-3d-tiles/ayutthaya/tileset.json",
renderer: renderer,
loadOutsideView: true
});Draw bounding volumes around visible tiles
const ogc3DTile = new OGC3DTile({
url: "https://storage.googleapis.com/ogc-3d-tiles/ayutthaya/tileset.json",
renderer: renderer,
drawBoundingVolume: true
});Google maps 3DTiles can be loaded similarly. The API key mechanism requires that a token be passed as a query param to all fetched tiles.
const ogc3DTile = new OGC3DTile({
url: "https://tile.googleapis.com/v1/3dtiles/root.json",
queryParams: { key: "Insert your own google maps API key here" },
yUp: false, // this value is normally true by default
renderer: renderer,
loadOutsideView: true
});This is mostly specific to google tiles but may be used by other vendors.
Google requires that, copyright info for producers of the 3D data be displayed. A global function #getOGC3DTilesCopyrightInfo returns the list of vendors that need to be displayed.
import { OGC3DTile, getOGC3DTilesCopyrightInfo } from "@jdultra/threedtiles';
...
animate(){
requestAnimationFrame( animate );
googleTiles.update(camera);
tileLoader.update();
...
console.log(getOGC3DTilesCopyrightInfo());
}
Add a callback that is called once when the first tile is loaded and geometry is available. This can be useful to position the tileset at a specific location when it is not centered on origin for example.
const ogc3DTile = new OGC3DTile({
url: "https://storage.googleapis.com/ogc-3d-tiles/ayutthaya/tileset.json",
renderer: renderer,
onLoadCallback: tileset => {
console.log(tileset.json.boundingVolume);
}
});Note that the callback is called with the OGC3DTile object as parameter and that this object has a "json" property giving you access to the original tileset.json with it's transform, geometric error, bounding volume, etc...
Add a callback on loaded tiles in order to set a material or do some logic on the meshes.
const ogc3DTile = new OGC3DTile({
url: "https://storage.googleapis.com/ogc-3d-tiles/ayutthaya/tileset.json",
renderer: renderer,
meshCallback: mesh => {
mesh.material.wireframe = true;
mesh.material.side = THREE.DoubleSide;
}
});Calling OGC3DTile#update gives a direct feedback on the state of the tileset:
function animate() {
requestAnimationFrame(animate);
ogc3DTile.update(camera); // computes what tiles need to be refined and what tiles can be disposed.
const state = ogc3DTile.tileLoader.update(); // downloads, loads and caches tiles in optimal order.
}In the example above, the "state" object may look like this:
{
numTilesLoaded: 82,
numTilesRendered: 82,
maxLOD: 9,
percentageLoaded: 1
}暂无开放 Issues,或尚未同步最近议题。