我正在尝试添加法线贴图(在这种情况下是木材纹理)到我使用THREE.BufferGeometry()和顶点创建的自定义部分。
对于这个特定的部分:
//edit initially I left out this part while posting. My script sees this folder and gives no errors
const woodPattern = new THREE.TextureLoader();
const woodTexture = woodPattern.load('/textures/wood_pattern.jpg');
const frame_upper_part_geometry = new THREE.BufferGeometry();
const frame_upper_part_positions = [
0.8, 0.8, 0.95,
-0.8, 0.8, 0.95,
-0.8, 0.8, 0.75,
-0.8, 0.8, 0.75,
0.8, 0.8, 0.75,
0.8, 0.8, 0.95,
0.6, 0.6, 0.95,
-0.6, 0.6, 0.95,
-0.6, 0.6, 0.75,
-0.6, 0.6, 0.75,
0.6, 0.6, 0.75,
0.6, 0.6, 0.95,
0.8, 0.8, 0.95,
0.6, 0.6, 0.95,
0.6, 0.6, 0.75,
0.6, 0.6, 0.75,
0.8, 0.8, 0.75,
0.8, 0.8, 0.95,
-0.8, 0.8, 0.95,
-0.6, 0.6, 0.95,
-0.6, 0.6, 0.75,
-0.6, 0.6, 0.75,
-0.8, 0.8, 0.75,
-0.8, 0.8, 0.95,
0.8, 0.8, 0.75,
-0.8, 0.8, 0.75,
-0.6, 0.6, 0.75,
-0.6, 0.6, 0.75,
0.6, 0.6, 0.75,
0.8, 0.8, 0.75,
];
frame_upper_part_geometry.setAttribute(
'position',
new THREE.Float32BufferAttribute( frame_upper_part_positions, 3 )
);
frame_upper_part_geometry.computeVertexNormals();
const frame_material = new THREE.MeshStandardMaterial({normalMap:woodTexture})
frame_material.side = THREE.DoubleSide;
frame_material.color = new THREE.Color(0x654321)
const frame_upper_part = new THREE.Mesh(frame_upper_part_geometry, frame_material)
scene.add(frame_upper_part)
我没有得到任何错误,但是添加法线贴图似乎并没有改变一件事,即使我添加它相同的方式与预定义的几何在三个本身,它应该工作。我错过什么了吗?
我得到的结果,没有错误,但是法线贴图的效果不存在。
您没有为自定义几何体生成任何纹理坐标。因此,应用纹理不会像预期的那样工作。纹理坐标存储在称为uv
buffer的属性中。