使用从.obj加载的BufferGeometry时,纹理贴图未应用于材质



我很难将纹理贴图应用到加载的对象
(从magica体素导出.obj(
我正在使用它的子几何体作为网格
加载对象并应用任何材质都很好
但是贴图(在这种情况下为法线、粗糙度(被完全忽略。

import { useLoader } from '@react-three/fiber'
import { useTexture } from '@react-three/drei'
import { OBJLoader } from 'three/examples/jsm/loaders/OBJLoader'
import CaseObject from '../object/case.obj'
import texture from '../texture/plastic/color.jpg'
import roughnessMap from '../texture/plastic/roughness_map.jpg'
import normalMap from '../texture/plastic/normal_map.jpg'
function Case (props) {
const object = useLoader(OBJLoader, CaseObject)
const geometry = object.children[0].geometry
const matProps = useTexture({
map: texture,
roughnessMap: roughnessMap,
normalMap: normalMap,
})
return <mesh
castShadow={true}
receiveShadow={true}
>
<bufferGeometry {...geometry} />
<meshStandardMaterial
{...matProps}
/>
</mesh>
}
export default Case

上面的人是对的。在添加图像之前,您必须通过以下操作进行加载:
new THREE.TextureLoader().load('../texture/plastic/normal_map.jpg')

我不知道react three fiber,但看起来你正在导入.jpg图像,并直接将其指定为粗糙度和法线贴图。这些属性需要THREE.Texture对象,而不是直接映像。如果import语句的结果是图像,请确保首先使用将它们转换为纹理

new THREE.Texture(normalMap)

但是,如果import的结果是包含图像地址的字符串,那么就必须用new THREE.TextureLoader().load(normalMap)加载它。