@playcanvas/react
Version:
A React renderer for PlayCanvas – build interactive 3D applications using React's declarative paradigm.
28 lines • 949 B
JavaScript
"use client";
import { useLayoutEffect } from "react";
import { useApp } from "../hooks";
/**
* An environment atlas is a texture for rendering a skybox and global reflections.
*/
export const EnvAtlas = ({ asset, intensity = 1, showSkybox = true }) => {
const app = useApp();
useLayoutEffect(() => {
if (!asset?.resource)
return;
app.scene.envAtlas = asset.resource;
return () => {
if (app && app.scene) {
// @ts-expect-error `envAtlas` has an incorrect type ot @type {Texture}
app.scene.envAtlas = null;
}
};
}, [app, asset?.resource]);
useLayoutEffect(() => {
const layer = app?.scene?.layers?.getLayerByName('Skybox');
if (layer)
layer.enabled = showSkybox;
app.scene.skyboxIntensity = intensity;
}, [app, showSkybox, intensity]);
return null;
};
//# sourceMappingURL=EnvAtlas.js.map