Pārlūkot izejas kodu

feat(cientos): better typ support useEnvironment

alvarosabu 2 gadi atpakaļ
vecāks
revīzija
821b6a6b8e

+ 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 '.'
 import { useEnvironment } from '.'
 
 
-export const Environment = defineComponent({
+export const Environment = defineComponent<EnvironmentOptions>({
   name: 'Environment',
   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 }) {
   async setup(props, { expose }) {
     let texture: Texture | CubeTexture | null = null
     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'],
   files = ['/px.png', '/nx.png', '/py.png', '/ny.png', '/pz.png', '/nz.png'],
   blur = 0,
   blur = 0,
   background = false,
   background = false,
-  path = undefined,
+  path = '/',
   preset = undefined,
   preset = undefined,
   encoding = undefined,
   encoding = undefined,
 }: Partial<EnvironmentOptions>): Promise<Texture | CubeTexture> {
 }: Partial<EnvironmentOptions>): Promise<Texture | CubeTexture> {
@@ -64,10 +64,11 @@ export async function useEnvironment({
     texture.encoding = encoding ?? isCubeMap ? sRGBEncoding : LinearEncoding
     texture.encoding = encoding ?? isCubeMap ? sRGBEncoding : LinearEncoding
   }
   }
 
 
-  if (background && state.scene) {
+  if (state.scene) {
     state.scene.environment = texture
     state.scene.environment = texture
-    state.scene.background = texture
-
+    if (background !== undefined) {
+      state.scene.background = texture
+    }
     if (blur) {
     if (blur) {
       state.scene.backgroundBlurriness = blur | 0
       state.scene.backgroundBlurriness = blur | 0
     }
     }