Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(tools): Fix some eslint issues #386

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions playground/src/pages/staging/EnvironmentDemo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const { background, blur, preset, lightformers } = useControls({
],
value: 'sunset',
},
lightformers: false
lightformers: false,
})

const environmentRef = ref(null)
Expand Down Expand Up @@ -89,12 +89,31 @@ const { progress, hasFinishLoading } = await useProgress()
<Environment
:background="background.value"
:blur="blur.value"
:preset="preset.value">
:preset="preset.value"
>
<TresGroup v-if="lightformers.value">
<Lightformer :intensity="0.75" :rotation-x="Math.PI / 2" :position="[0, 5, -9]" :scale="[10, 10, 1]" />
<Lightformer :intensity="4" :rotation-y="Math.PI / 2" :position="[-5, 1, -1]" :scale="[20, 0.1, 1]" />
<Lightformer :rotation-y="Math.PI / 2" :position="[-5, -1, -1]" :scale="[20, 0.5, 1]" />
<Lightformer :rotation-y="-Math.PI / 2" :position="[10, 1, 0]" :scale="[20, 11, 1]" />
<Lightformer
:intensity="0.75"
:rotation-x="Math.PI / 2"
:position="[0, 5, -9]"
:scale="[10, 10, 1]"
/>
<Lightformer
:intensity="4"
:rotation-y="Math.PI / 2"
:position="[-5, 1, -1]"
:scale="[20, 0.1, 1]"
/>
<Lightformer
:rotation-y="Math.PI / 2"
:position="[-5, -1, -1]"
:scale="[20, 0.5, 1]"
/>
<Lightformer
:rotation-y="-Math.PI / 2"
:position="[10, 1, 0]"
:scale="[20, 11, 1]"
/>
</TresGroup>
</Environment>
</Suspense>
Expand Down
12 changes: 8 additions & 4 deletions src/core/staging/useEnvironment/component.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defineExpose({ texture })

const { extend, renderer, scene } = useTresContext()
let slots = null as any
let fbo = ref(null as null | WebGLCubeRenderTarget)
const fbo = ref(null as null | WebGLCubeRenderTarget)
let cubeCamera = null as null | CubeCamera

const envSence = ref<EnvSence | null>(null)
Expand All @@ -50,7 +50,8 @@ const setTextureEnvAndBG = (fbo: WebGLCubeRenderTarget) => {
if (props.background) {
scene.value.background = fbo.texture
}
} else {
}
else {
scene.value.environment = useEnvironmentTexture.value
if (props.background) {
scene.value.background = useEnvironmentTexture.value
Expand All @@ -66,7 +67,7 @@ watch(useEnvironmentTexture, (value) => {
watch(useSlots().default, (value) => {
if (value) {
slots = value
if (Array.isArray(slots)&&slots.length>0) {
if (Array.isArray(slots) && slots.length > 0) {
if (typeof slots[0]?.type !== 'symbol') {
extend({ EnvSence })
fbo.value = new WebGLCubeRenderTarget(props.resolution)
Expand All @@ -85,7 +86,10 @@ texture.value = useEnvironmentTexture
</script>

<template>
<TresEnvSence v-if="fbo" ref="envSence">
<TresEnvSence
v-if="fbo"
ref="envSence"
>
<slot />
</TresEnvSence>
</template>
9 changes: 6 additions & 3 deletions src/core/staging/useEnvironment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useLoader, useTresContext } from '@tresjs/core'
import type {
CubeTexture,
Texture,
WebGLCubeRenderTarget
WebGLCubeRenderTarget,
} from 'three'
import {
CubeReflectionMapping,
Expand Down Expand Up @@ -32,7 +32,10 @@ import { environmentPresets } from './const'

// eslint-disable-next-line max-len
const PRESET_ROOT = 'https://raw.githubusercontent.com/Tresjs/assets/main/textures/hdr/'
export async function useEnvironment(options: Partial<EnvironmentOptions>, fbo: Ref<WebGLCubeRenderTarget | undefined>): Promise<Texture | CubeTexture> {
export async function useEnvironment(
options: Partial<EnvironmentOptions>,
fbo: Ref<WebGLCubeRenderTarget | undefined>,
): Promise<Texture | CubeTexture> {
const { scene } = useTresContext()

const {
Expand Down Expand Up @@ -83,7 +86,7 @@ export async function useEnvironment(options: Partial<EnvironmentOptions>, fbo:

watch(() => [background.value, texture.value], ([_background, _texture]) => {
if (scene.value) {
let bTexture = fbo?.value? fbo.value.texture : _texture
const bTexture = fbo?.value ? fbo.value.texture : _texture
scene.value.background = _background ? bTexture : undefined as unknown as Texture
}
}, {
Expand Down
Loading