将法线贴图添加到三个缓冲区几何形状

时间:2021-08-01 15:14:22

标签: javascript three.js textures

我正在尝试将法线贴图(在本例中为木材纹理)添加到我使用 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)

我没有收到任何错误,但是添加法线贴图似乎并没有改变任何事情,即使我以相同的方式在三本身中使用预定义的几何体添加它,它也应该可以工作。我错过了什么吗?

result I'm getting, no errors, however effects of normal map are not present.

1 个答案:

答案 0 :(得分:0)

您没有为自定义几何体生成任何纹理坐标。因此,应用纹理不会按预期工作。纹理坐标存储在调用的 uv 缓冲区属性中。