@@ -6,6 +6,7 @@ import { TrackballControls } from "three/examples/jsm/controls/TrackballControls
66import { OrbitControls } from "three/examples/jsm/controls/OrbitControls" ;
77import { GLTF } from "three/examples/jsm/loaders/GLTFLoader" ;
88import { copperGltfLoader } from "../Loader/copperGltfLoader" ;
9+ import { objLoader } from "../Loader/copperOBJLoader" ;
910import { isPickedModel , throttle } from "../Utils/raycaster" ;
1011import {
1112 mouseMovePositionType ,
@@ -17,6 +18,7 @@ import { isIOS } from "../Utils/utils";
1718
1819import commonScene from "./commonSceneMethod" ;
1920
21+
2022const IS_IOS = isIOS ( ) ;
2123
2224export default class copperMScene extends commonScene {
@@ -66,8 +68,10 @@ export default class copperMScene extends commonScene {
6668 this . vignette . mesh . renderOrder = - 1 ;
6769
6870 this . copperControl = new Controls ( this . camera ) ;
69- // this.controls = new TrackballControls(this.camera, container);
70- this . controls = new OrbitControls ( this . camera , this . container ) ;
71+ this . controls = new TrackballControls ( this . camera , this . container ) ;
72+ this . controls . rotateSpeed = 0.02 ;
73+ this . controls . staticMoving = true
74+ // this.controls = new OrbitControls(this.camera, this.container);
7175 this . preRenderCallbackFunctions = {
7276 index : 0 ,
7377 cache : [ ] ,
@@ -126,6 +130,7 @@ export default class copperMScene extends commonScene {
126130 default :
127131 this . controls = new TrackballControls ( this . camera , this . container ) ;
128132 this . controls . rotateSpeed = 0.01 ;
133+ this . controls . staticMoving = true
129134 break ;
130135 }
131136 }
@@ -251,6 +256,53 @@ export default class copperMScene extends commonScene {
251256 copperNrrdLoader1 ( url , this . scene , this . container , callback ) ;
252257 }
253258
259+ loadOBJ ( url : string , callback ?: ( mesh : THREE . Group ) => void ) {
260+ objLoader . load (
261+ url ,
262+ ( obj ) => {
263+ obj . traverse ( ( child ) => {
264+ if ( ( child as THREE . Mesh ) . isMesh ) {
265+ // (child as THREE.Mesh).material = new THREE.MeshStandardMaterial({
266+ // side: THREE.DoubleSide,
267+ // color: 0xffffff,
268+ // });
269+ // ((child as THREE.Mesh).material as THREE.MeshPhongMaterial).color =
270+ // new THREE.Color(0xffffff);
271+ }
272+ } ) ;
273+ const box = new THREE . Box3 ( ) . setFromObject ( obj ) ;
274+ const size = box . getSize ( new THREE . Vector3 ( ) ) . length ( ) ;
275+ const center = box . getCenter ( new THREE . Vector3 ( ) ) ;
276+
277+ this . controls . maxDistance = size * 10 ;
278+ obj . position . x += obj . position . x - center . x ;
279+ obj . position . y += obj . position . y - center . y ;
280+ obj . position . z += obj . position . z - center . z ;
281+
282+ if ( ! this . cameraPositionFlag ) {
283+ this . camera . position . copy ( center ) ;
284+ this . camera . position . x += size / 2.0 ;
285+ this . camera . position . y += size / 5.0 ;
286+ this . camera . position . z += size / 2.0 ;
287+ this . camera . lookAt ( center ) ;
288+ this . viewPoint = this . setViewPoint (
289+ this . camera as THREE . PerspectiveCamera ,
290+ [ center . x , center . y , center . z ]
291+ ) ;
292+ }
293+ this . scene . add ( obj ) ;
294+ ! ! callback && callback ( obj ) ;
295+ } , // called when loading is in progresses
296+ ( xhr : any ) => {
297+ // console.log((xhr.loaded / xhr.total) * 100 + "% loaded");
298+ } ,
299+ // called when loading has errors
300+ ( error : any ) => {
301+ console . log ( "An error happened" ) ;
302+ }
303+ ) ;
304+ }
305+
254306 drawWholeNrrd ( nrrdSlices : nrrdSliceType ) {
255307 getWholeSlices (
256308 nrrdSlices ,
0 commit comments