Skip to content

Commit

Permalink
feat(cientos): better typ support useEnvironment
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosabu committed Mar 6, 2023
1 parent aee7ea9 commit 821b6a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
26 changes: 6 additions & 20 deletions packages/cientos/src/core/useEnvironment/component.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down
9 changes: 5 additions & 4 deletions packages/cientos/src/core/useEnvironment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 821b6a6

Please sign in to comment.