فهرست منبع

add rtc center suppor

Garrett Johnson 4 سال پیش
والد
کامیت
78100657f4
2فایلهای تغییر یافته به همراه28 افزوده شده و 9 حذف شده
  1. 12 5
      example/b3dmExample.js
  2. 16 4
      src/three/B3DMLoader.js

+ 12 - 5
example/b3dmExample.js

@@ -1,6 +1,7 @@
 import { B3DMLoader } from '../src/index.js';
 import {
 	Scene,
+	Group,
 	DirectionalLight,
 	AmbientLight,
 	WebGLRenderer,
@@ -17,8 +18,8 @@ import {
 } from 'three';
 import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
 
-let camera, controls, scene, renderer;
-let box, dirLight;
+let camera, controls, scene, renderer, offsetGroup;
+let dirLight;
 let raycaster, mouse;
 let model;
 let infoEl;
@@ -116,7 +117,8 @@ function init() {
 	const ambLight = new AmbientLight( 0xffffff, 0.05 );
 	scene.add( ambLight );
 
-	box = new Box3();
+	offsetGroup = new Group();
+	scene.add( offsetGroup );
 
 	new B3DMLoader()
 		.load( 'https://raw.githubusercontent.com/CesiumGS/3d-tiles-samples/master/tilesets/TilesetWithRequestVolume/city/lr.b3dm' )
@@ -124,12 +126,17 @@ function init() {
 
 			console.log( res );
 			model = res.scene;
-			scene.add( res.scene );
+			offsetGroup.add( model );
+
+			const box = new Box3();
+			box.setFromObject( model );
+			box.getCenter( offsetGroup.position ).multiplyScalar( - 1 );
+
 
 			// reassign the material to use the batchid highlight variant.
 			// in practice this should copy over any needed uniforms from the
 			// original material.
-			res.scene.traverse( c => {
+			model.traverse( c => {
 
 				if ( c.isMesh ) {
 

+ 16 - 4
src/three/B3DMLoader.js

@@ -21,11 +21,23 @@ export class B3DMLoader extends B3DMLoaderBase {
 			const loader = manager.getHandler( 'path.gltf' ) || new GLTFLoader( manager );
 			loader.parse( gltfBuffer, null, model => {
 
-				model.batchTable = b3dm.batchTable;
-				model.featureTable = b3dm.featureTable;
+				const { batchTable, featureTable } = b3dm;
+				const { scene } = model
 
-				model.scene.batchTable = b3dm.batchTable;
-				model.scene.featureTable = b3dm.featureTable;
+				const rtcCenter = featureTable.getData( 'RTC_CENTER' );
+				if ( rtcCenter ) {
+
+					scene.position.x += rtcCenter[ 0 ];
+					scene.position.y += rtcCenter[ 1 ];
+					scene.position.z += rtcCenter[ 2 ];
+
+				}
+
+				model.batchTable = batchTable;
+				model.featureTable = featureTable;
+
+				scene.batchTable = batchTable;
+				scene.featureTable = featureTable;
 
 				resolve( model );