浏览代码

Pass through and use fetch options

Garrett Johnson 4 年之前
父节点
当前提交
097976e3ee
共有 4 个文件被更改,包括 42 次插入0 次删除
  1. 20 0
      src/three/B3DMLoader.js
  2. 1 0
      src/three/CMPTLoader.js
  3. 20 0
      src/three/I3DMLoader.js
  4. 1 0
      src/three/TilesRenderer.js

+ 20 - 0
src/three/B3DMLoader.js

@@ -18,7 +18,27 @@ export class B3DMLoader extends B3DMLoaderBase {
 		return new Promise( ( resolve, reject ) => {
 
 			const manager = this.manager;
+			const fetchOptions = this.fetchOptions;
 			const loader = manager.getHandler( 'path.gltf' ) || new GLTFLoader( manager );
+
+			if ( fetchOptions.credentials === 'include' && fetchOptions.mode === 'cors' ) {
+
+				loader.setCrossOrigin( 'use-credentials' );
+
+			}
+
+			if ( 'credentials' in fetchOptions ) {
+
+				loader.setWithCredentials( fetchOptions.credentials === 'include' );
+
+			}
+
+			if ( fetchOptions.header ) {
+
+				loader.setRequestHeader( fetchOptions.header );
+
+			}
+
 			loader.parse( gltfBuffer, this.workingPath, model => {
 
 				const { batchTable, featureTable } = b3dm;

+ 1 - 0
src/three/CMPTLoader.js

@@ -29,6 +29,7 @@ export class CMPTLoader extends CMPTLoaderBase {
 					const slicedBuffer = buffer.slice();
 					const loader = new B3DMLoader( manager );
 					loader.workingPath = this.workingPath;
+					loader.fetchOptions = this.fetchOptions;
 
 					const promise = loader.parse( slicedBuffer.buffer );
 					promises.push( promise );

+ 20 - 0
src/three/I3DMLoader.js

@@ -34,8 +34,28 @@ export class I3DMLoader extends I3DMLoaderBase {
 				const gltfBuffer = i3dm.glbBytes.slice().buffer;
 				return new Promise( ( resolve, reject ) => {
 
+					const fetchOptions = this.fetchOptions;
 					const manager = this.manager;
 					const loader = manager.getHandler( 'path.gltf' ) || new GLTFLoader( manager );
+
+					if ( fetchOptions.credentials === 'include' && fetchOptions.mode === 'cors' ) {
+
+						loader.setCrossOrigin( 'use-credentials' );
+
+					}
+
+					if ( 'credentials' in fetchOptions ) {
+
+						loader.setWithCredentials( fetchOptions.credentials === 'include' );
+
+					}
+
+					if ( fetchOptions.header ) {
+
+						loader.setRequestHeader( fetchOptions.header );
+
+					}
+
 					loader.parse( gltfBuffer, this.workingPath, model => {
 
 						const INSTANCES_LENGTH = featureTable.getData( 'INSTANCES_LENGTH' );

+ 1 - 0
src/three/TilesRenderer.js

@@ -524,6 +524,7 @@ export class TilesRenderer extends TilesRendererBase {
 			case 'b3dm':
 				const loader = new B3DMLoader( manager );
 				loader.workingPath = workingPath;
+				loader.fetchOptions = fetchOptions;
 				promise = loader
 					.parse( buffer )
 					.then( res => res.scene );