【问题标题】:Adding normal maps to bufferGeometry shapes in THREE在三个中将法线贴图添加到 bufferGeometry 形状
【发布时间】:2023-04-04 00:50:01
【问题描述】:

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

【问题讨论】:

    标签: javascript three.js textures


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-06-11
      • 1970-01-01
      • 2019-03-15
      • 2022-12-24
      • 2021-01-15
      • 1970-01-01
      • 1970-01-01
      • 2014-03-09
      • 1970-01-01
      相关资源
      最近更新 更多