Skip to content

Commit

Permalink
Merge pull request #386 from Tresjs/fix/eslint-issues
Browse files Browse the repository at this point in the history
refactor(tools): Fix some eslint issues
  • Loading branch information
JaimeTorrealba committed Apr 23, 2024
2 parents 47eb747 + 1a13ada commit a0b2a84
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
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

0 comments on commit a0b2a84

Please sign in to comment.