如何使用纹理与斑点上的反应三纤维



我想在场景中放置静态背景。背景上下文存储用户通过投放区域上传的图像。

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} />;
};

最新更新