Explorar o código

fix(core): fix initial aspect-ratio wjen using window-size

alvarosabu %!s(int64=2) %!d(string=hai) anos
pai
achega
25e55be669

+ 2 - 1
packages/tres/src/core/useCamera/index.ts

@@ -129,7 +129,7 @@ export function useCamera(): UseCameraReturn {
         far: 1000,
         fov: VERTICAL_FIELD_OF_VIEW,
       }
-      camera = new PerspectiveCamera(fov, state.aspectRatio?.value || 1, near, far)
+      camera = new PerspectiveCamera(fov, state.aspectRatio?.value || window.innerWidth / window.innerHeight, near, far)
       state.cameras?.push(camera as PerspectiveCamera)
     } else {
       const { left, right, top, bottom, near, far } = (options as OrthographicCameraOptions) || {
@@ -146,6 +146,7 @@ export function useCamera(): UseCameraReturn {
     state.camera = camera
 
     setState('camera', state.camera)
+
     return camera
   }
 

+ 2 - 1
packages/tres/src/core/useTres/index.ts

@@ -1,5 +1,5 @@
 import { Clock, EventDispatcher, Raycaster, Scene, Vector2, WebGLRenderer } from 'three'
-import { ComputedRef, shallowReactive, toRefs } from 'vue'
+import { computed, ComputedRef, shallowReactive, toRefs } from 'vue'
 import { Camera } from '/@/core'
 
 export interface TresState {
@@ -93,6 +93,7 @@ export interface TresState {
 const state: TresState = shallowReactive({
   camera: undefined,
   cameras: [],
+  aspectRatio: computed(() => window.innerWidth / window.innerHeight),
 })
 
 /**