Browse Source

Added ion documentation

PetterGs 4 năm trước cách đây
mục cha
commit
ca77b8cf76
1 tập tin đã thay đổi với 57 bổ sung0 xóa
  1. 57 0
      README.md

+ 57 - 0
README.md

@@ -148,6 +148,63 @@ tilesRenderer.manager.addHandler( /\.gltf$/, {
 } );
 ```
 
+## Loading from Cesium Ion
+
+Loading from Cesium Ion requires some extra fetching of the ion url endpoint, as well as a temporary bearer access token. A full example is found in the iosExample.js file in the examples folder.
+
+Set the desired assetId as well as your Ion AccessToken. [More reading is provided by the Cesium Rest documentation.](https://cesium.com/docs/rest-api/)
+
+```js
+
+url = new URL( `https://api.cesium.com/v1/assets/${assetId}/endpoint` );
+url.searchParams.append( 'access_token', accessToken );
+
+fetch( url, { mode: 'cors' } )
+	.then( ( res ) => {
+		if ( res.ok ) {
+			return res.json();
+		} else {
+			return Promise.reject( `${res.status} : ${res.statusText}` );
+		}
+	} )
+	.then( ( json ) => {
+		url = new URL( json.url );
+		const version = url.searchParams.get( 'v' );
+		tiles = new TilesRenderer( url );
+		tiles.fetchOptions.headers = {};
+		tiles.fetchOptions.headers.Authorization = `Bearer ${json.accessToken}`;
+		
+		// Prefilter each model fetch by setting the cesium Ion version to the search parameters of the url
+		tiles.onPreprocessURL = uri => {
+			uri = new URL( uri );
+			uri.searchParams.append( 'v', version );
+			return uri;
+		};
+		
+		// Correct the rotation and position if your Ion asset happens to be on the surface of an ellipsoid i.e. is georeferenced.
+		tiles.onLoadTileSet = () => {
+			const matrix = new Matrix4();
+			tiles.getBoundsTransform( matrix );
+			const position = new Vector3().setFromMatrixPosition( matrix );
+			const distanceToEllipsoidCenter = position.length();
+
+			const surfaceDirection = position.normalize();
+			const up = new Vector3( 0, 1, 0 );
+			const rotationToNorthPole = rotationBetweenDirections( surfaceDirection, up ); //This function can be found in the ionExample file
+
+			tiles.group.quaternion.x = rotationToNorthPole.x;
+			tiles.group.quaternion.y = rotationToNorthPole.y;
+			tiles.group.quaternion.z = rotationToNorthPole.z;
+			tiles.group.quaternion.w = rotationToNorthPole.w;
+
+			tiles.group.position.y = - distanceToEllipsoidCenter;
+		};
+
+		// Setup draco compression etc. here
+
+	} )
+```
+
 ## Render On Change
 
 The tile set and model load callbacks can be used to detect when the data has changed and a new render is necessary.