Browse Source

Merge pull request #282 from peiyu7921/feature/cesium_rtc

add gltf extension cesium_rtc
Garrett Johnson 3 năm trước cách đây
mục cha
commit
254110d229

+ 8 - 0
src/three/GLTFCesiumRTCExtension.d.ts

@@ -0,0 +1,8 @@
+import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader';
+
+export default class GLTFCesiumRTCExtension{
+	name: 'CESIUM_RTC';
+
+	afterRoot(result: GLTF): null
+
+}

+ 19 - 0
src/three/GLTFCesiumRTCExtension.js

@@ -0,0 +1,19 @@
+
+export default class GLTFCesiumRTCExtension {
+
+	constructor() {
+
+		this.name = 'CESIUM_RTC';
+
+	}
+
+	afterRoot( res ) {
+
+		const { center } = res.parser.json.extensions.CESIUM_RTC;
+		res.scene.position.x += center[ 0 ];
+		res.scene.position.y += center[ 1 ];
+		res.scene.position.z += center[ 2 ];
+
+	}
+
+}

+ 3 - 0
src/three/GLTFExtensionLoader.js

@@ -1,6 +1,7 @@
 import { DefaultLoadingManager } from 'three';
 import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
 import { LoaderBase } from '../base/LoaderBase.js';
+import GLTFCesiumRTCExtension from './GLTFCesiumRTCExtension.js';
 
 export class GLTFExtensionLoader extends LoaderBase {
 
@@ -22,6 +23,8 @@ export class GLTFExtensionLoader extends LoaderBase {
 			if ( ! loader ) {
 
 				loader = new GLTFLoader( manager );
+
+				loader.register( () => new GLTFCesiumRTCExtension() );
 				if ( fetchOptions.credentials === 'include' && fetchOptions.mode === 'cors' ) {
 
 					loader.setCrossOrigin( 'use-credentials' );