我正在尝试使用 react-three-fiber 渲染一个 3d 对象。我能够导入自定义 3d 对象,但无法在对象上应用自定义材质。任何帮助将非常感激。以下是我到目前为止尝试过的代码
let mat = useLoader(MTLLoader,'/public/IronMan.mtl')
const objec = useLoader(OBJLoader,url, object =>
{
object.setMaterials(mat)
console.log(object)
})
const loader = new OBJLoader();
loader.load(url,
function(obj)
{
console.log("loaded")
// console.log(obj)
});
// const objec = useLoader(OBJLoader,url)
console.log(objec)
loader.setMaterials(mat)
// console.log(loader)
//console.log(mat)
//objec.setMaterials(mat)
//let mtlLoader = new MTLLoader();
//let objLoader = new OBJLoader();
// mtlLoader.load('/public/IronMan.mtl', (materials) => {
// materials.preload()
// objLoader.setMaterials(materials)
// objLoader.load('./test.obj', (object) => {
// scene.add(object)
// })
// })
return (
<mesh material-color='red'>
<primitive object={objec}/>
<meshBasicMaterial attach="material" color="yellow" transparent />
</mesh>
)