我想在场景中放置静态背景。背景上下文存储用户通过投放区域上传的图像。
const BackgroundImage = () => {
const { background } = useContext(MainContext);
const texture = useTexture(background);
return <primitive attach="background" object={texture} />;
};
此代码引发错误:
未处理的运行时错误错误:无法加载:未定义(
我希望有人知道如何纠正这个问题。
我用useLoader 找到了解决方案
const BackgroundImage = ({ background }) => {
const texture = useLoader(
TextureLoader,
background
);
return <primitive attach="background" object={texture} />;
};