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

feat(cientos): better typ support useEnvironment

alvarosabu преди 2 години
родител
ревизия
821b6a6b8e
променени са 2 файла, в които са добавени 11 реда и са изтрити 24 реда
  1. 6 20
      packages/cientos/src/core/useEnvironment/component.ts
  2. 5 4
      packages/cientos/src/core/useEnvironment/index.ts

+ 6 - 20
packages/cientos/src/core/useEnvironment/component.ts

@@ -1,27 +1,13 @@
-import { EnvironmentOptions, EnvironmentPresetsType } from './const'
-import { CubeTexture, Texture, TextureEncoding } from 'three'
-import { defineComponent, PropType } from 'vue'
+import { EnvironmentOptions } from './const'
+import { CubeTexture, Texture } from 'three'
+import { defineComponent } from 'vue'
 
 import { useEnvironment } from '.'
 
-export const Environment = defineComponent({
+export const Environment = defineComponent<EnvironmentOptions>({
   name: 'Environment',
-  props: {
-    background: {
-      type: Boolean,
-      default: false,
-    },
-    blur: {
-      type: Number,
-      default: 0,
-    },
-    files: {
-      type: [String, Array],
-    },
-    encoding: Object as PropType<TextureEncoding>,
-    path: String,
-    preset: Object as PropType<EnvironmentPresetsType>,
-  },
+  props: ['background', 'blur', 'files', 'encoding', 'path', 'preset'] as unknown as undefined,
+
   async setup(props, { expose }) {
     let texture: Texture | CubeTexture | null = null
 

+ 5 - 4
packages/cientos/src/core/useEnvironment/index.ts

@@ -30,7 +30,7 @@ export async function useEnvironment({
   files = ['/px.png', '/nx.png', '/py.png', '/ny.png', '/pz.png', '/nz.png'],
   blur = 0,
   background = false,
-  path = undefined,
+  path = '/',
   preset = undefined,
   encoding = undefined,
 }: Partial<EnvironmentOptions>): Promise<Texture | CubeTexture> {
@@ -64,10 +64,11 @@ export async function useEnvironment({
     texture.encoding = encoding ?? isCubeMap ? sRGBEncoding : LinearEncoding
   }
 
-  if (background && state.scene) {
+  if (state.scene) {
     state.scene.environment = texture
-    state.scene.background = texture
-
+    if (background !== undefined) {
+      state.scene.background = texture
+    }
     if (blur) {
       state.scene.backgroundBlurriness = blur | 0
     }