brianzinn / react-babylonjs

React for Babylon 3D engine
https://brianzinn.github.io/react-babylonjs/
812 stars 102 forks source link

EnvironmentTextureTools.CreateEnvTextureAsync() compatibility #213

Closed slash9494 closed 1 month ago

slash9494 commented 2 years ago

i have tried to generate '.env' file by EnvironmentTextureTools of babylonjs

after generating buffer through it, it throw error and scene is out

i just refer to "generating texture" of babylonjs sandbox and only difference is to generate after loading texture through useEffect

but i'm not sure react-babylonjs environment cause it

i have tried it on textures/pbr.stories.js and i also changed environment url for hdr file

스크린샷 2022-03-18 오후 12 09 49

스크린샷 2022-03-18 오후 12 39 48

brianzinn commented 2 years ago

It looks like you don't have a camera created on that render - are you able to share more code?

slash9494 commented 2 years ago

This code is created on your storybook section texture/pbr.stories.js So other code is same with that component I just add above code on that and remove cubeTexture component for adding .hdr file So on useEffect, i create new hdrCubeTexture and try to convert it to .envfile

brianzinn commented 2 years ago

is there a camera in your <Scene .../>? I don't know if there is a potential race condition when the callback is called (potentially too early) or if you have not created a camera.

slash9494 commented 2 years ago

Yeah in the scene, arcRotateCamera is created

I could not check the scene reloaded earlier than camera when converting is succeeded

But on the babylon sandbox or pure Babylon scene, nothing is going to happen

brianzinn commented 2 years ago

sorry for late reply - is there any way you can repro this using something like code sandbox?

slash9494 commented 2 years ago

here is sample situation on code sandbox https://codesandbox.io/s/strange-sun-e824l5?file=/src/App.tsx

brianzinn commented 2 years ago

That method is creating a camera: https://github.com/BabylonJS/Babylon.js/blob/fdbf393d1d7699dc7cc69cec1dca0819ebd2622a/packages/dev/core/src/Misc/environmentTextureTools.ts#L252

I will see about how I can fix that. I may need a guard clause on the default render loop. I started a discussion on the forum and see if any suggestions are posted: https://forum.babylonjs.com/t/fun-with-createenvtextureasync/28901

brianzinn commented 2 years ago

For now you’ll need to create your own runRenderLoop (call ‘clear’ method first). I’ll make sure this is fixed for next release.

slash9494 commented 2 years ago

thank you for informing babylonjs of it and i will try this method on my renderLoop

brianzinn commented 1 month ago

Closing from inactivity. I think I solved this by checking there is a camera in render loop.