@@ -33,7 +33,7 @@ const updateRendererSize = () => {
3333 const width = canvasHost .value .clientWidth ;
3434 const height = Math .min (Math .max (canvasHost .value .clientHeight , 280 ), 420 );
3535
36- renderer .setSize (width , height , false );
36+ renderer .setSize (width , height , true );
3737 camera .aspect = width / height ;
3838 camera .updateProjectionMatrix ();
3939};
@@ -66,18 +66,25 @@ const fitCameraToModel = (root: THREE.Object3D) => {
6666 return ;
6767 }
6868
69+ root .updateMatrixWorld (true );
6970 const box = new THREE .Box3 ().setFromObject (root );
71+ if (box .isEmpty ()) {
72+ return ;
73+ }
74+
7075 const size = box .getSize (new THREE .Vector3 ());
7176 const center = box .getCenter (new THREE .Vector3 ());
7277 const maxSize = Math .max (size .x , size .y , size .z , 0.1 );
7378
74- camera .position .x = center .x ;
79+ camera .position .set ( center . x , center . y + maxSize * 0.4 , center .z + maxSize * 1.8 ) ;
7580 camera .near = Math .max (maxSize / 200 , 0.01 );
7681 camera .far = Math .max (maxSize * 200 , 1000 );
7782 camera .updateProjectionMatrix ();
83+ camera .lookAt (center );
7884
79- controls .target .x = center . x ;
85+ controls .target .copy ( center ) ;
8086 controls .update ();
87+ controls .saveState ();
8188};
8289
8390const loadPreviewModel = async (path : string , options : ConvertOptions ) => {
@@ -163,6 +170,9 @@ onMounted(() => {
163170 controls .enableDamping = true ;
164171 controls .minDistance = 0.2 ;
165172 controls .maxDistance = 50 ;
173+ controls .target .set (0 , 0 , 0 );
174+ camera .lookAt (controls .target );
175+ controls .update ();
166176
167177 const ambient = new THREE .HemisphereLight (0xffffff , 0x444444 , 0.9 );
168178 scene .add (ambient );
0 commit comments