Преглед на файлове

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

alvarosabu преди 2 години
родител
ревизия
25e55be669
променени са 2 файла, в които са добавени 4 реда и са изтрити 2 реда
  1. 2 1
      packages/tres/src/core/useCamera/index.ts
  2. 2 1
      packages/tres/src/core/useTres/index.ts

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

@@ -129,7 +129,7 @@ export function useCamera(): UseCameraReturn {
         far: 1000,
         far: 1000,
         fov: VERTICAL_FIELD_OF_VIEW,
         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)
       state.cameras?.push(camera as PerspectiveCamera)
     } else {
     } else {
       const { left, right, top, bottom, near, far } = (options as OrthographicCameraOptions) || {
       const { left, right, top, bottom, near, far } = (options as OrthographicCameraOptions) || {
@@ -146,6 +146,7 @@ export function useCamera(): UseCameraReturn {
     state.camera = camera
     state.camera = camera
 
 
     setState('camera', state.camera)
     setState('camera', state.camera)
+
     return 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 { 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'
 import { Camera } from '/@/core'
 
 
 export interface TresState {
 export interface TresState {
@@ -93,6 +93,7 @@ export interface TresState {
 const state: TresState = shallowReactive({
 const state: TresState = shallowReactive({
   camera: undefined,
   camera: undefined,
   cameras: [],
   cameras: [],
+  aspectRatio: computed(() => window.innerWidth / window.innerHeight),
 })
 })
 
 
 /**
 /**