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

Environment not working #305

Open
5 tasks done
KaliaJS opened this issue Dec 9, 2023 · 4 comments
Open
5 tasks done

Environment not working #305

KaliaJS opened this issue Dec 9, 2023 · 4 comments

Comments

@KaliaJS
Copy link

KaliaJS commented Dec 9, 2023

Describe the bug

Can someone explain to me how to make the environment work with a file? With the preset it works well. using useEnvironment doesn't work either.

I tried with a file in the public folder

<Environment
  path="/milkyway-4k.jpg"
  :background="true"
/>

but also by importing it from the assets folder.

import MilkyWayEnvironment from '@assets/environments/milkyway-4k.jpg'

<Environment
  :path="MilkyWayEnvironment"
  :background="true"
/>

When using the component I get only a warning :

[Vue warn]: expose() should be passed a plain object, received ref. 
  at <Component path="/milkyway-4k.jpg" background=true > 
  at <App>

When I use useEnvironments I get 2 warnings and 1 error :

[Vue warn]: injection "useTres" not found. 
Unhandled error during execution of setup function 
tres.js:431 Uncaught (in promise) Error: useTresContext must be used together with useTresContextProvider

I tried to import the environment image into Stackblitz but it doesn't work.

Reproduction

https://stackblitz.com/edit/tresjs-basic-8r1lk7

Steps to reproduce

No response

System Info

No response

Used Package Manager

yarn

Code of Conduct

Copy link

stackblitz bot commented Dec 9, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@alvarosabu
Copy link
Member

Hi @KaliaJS thanks for reaching out.

I tried with a file in the public folder

path is not the correct prop, you need to use files and accept and array of .jpeg or an hdr file, you cant pass only a jpg because Environment doesn't work that way, it only accepts a CubeMap of images or .hdr files

Check here for usage https://cientos.tresjs.org/guide/staging/environment.html#usage.

I tried to import the environment image into Stackblitz but it doesn't work.

Yeah that doesn't work most of the time when that happens you can create a reproduction repo based on https://github.com/Tresjs/starter so I can take a look 😊

@KaliaJS
Copy link
Author

KaliaJS commented Dec 13, 2023

@alvarosabu Okay thank you I understand better.

I had tried with an EXR file and thought the extension was not important. I thought we could also put a jpg if we wanted to use only the background.

@KaliaJS KaliaJS closed this as completed Dec 13, 2023
@KaliaJS
Copy link
Author

KaliaJS commented Dec 22, 2023

@alvarosabu It's working but I've a warning in the console saying :

expose() should be passed a plain object, received ref. 
  at <Component files= (6) ['/src/assets/environments/space-posx.jpg', '/src/assets/environments/space-negx.jpg', '/src/assets/environments/space-posy.jpg', '/src/assets/environments/space-negy.jpg', '/src/assets/environments/space-posz.jpg', '/src/assets/environments/space-negz.jpg'] background=true > 
  at <App>

Any idea why ?

<script setup>
import { CameraControls, Environment, Box } from '@tresjs/cientos'
import negx from '@assets/environments/space-negx.jpg'
import negy from '@assets/environments/space-negy.jpg'
import negz from '@assets/environments/space-negz.jpg'
import posx from '@assets/environments/space-posx.jpg'
import posy from '@assets/environments/space-posy.jpg'
import posz from '@assets/environments/space-posz.jpg'

const controlsState = reactive({
  minDistance: 0,
  maxDistance: 100,
})
</script>

<template>
  <TresCanvas
    window-size
    shadows
  >
    <TresPerspectiveCamera :position="[5, 5, 5]" />
    <CameraControls
      v-bind="controlsState"
      make-default
    />
    <Suspense>
      <Environment
        :files="[ posx, negx, posy, negy, posz, negz ]"
        :background="true"
      />
    </Suspense>
    <TresGridHelper :position="[0, -1, 0]" />
    <Box :scale="2">
      <TresMeshToonMaterial color="orange" />
    </Box>
    <TresAmbientLight />
    <TresDirectionalLight :position="[0, 2, 4]" />
  </TresCanvas>
</template>

@KaliaJS KaliaJS reopened this Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants