【问题标题】:How to convert THREE.Geometry to THREE.BufferGeometry from Face3?如何从 Face3 将 THREE.Geometry 转换为 THREE.BufferGeometry?
【发布时间】:2022-12-19 21:09:41
【问题描述】:

我正在尝试转换/更新 THREE.Geometry 对 THREE.BufferGeometry 的调用,当该几何构造也使用已弃用的 THREE.Face3 调用时,我找不到任何整洁的解决方案

来源:https://github.com/juniorxsound/Depthkit.js/blob/master/README.md

DepthKit.geo = new THREE.Geometry();

    for (let y = 0; y < VERTS_TALL; y++) {
        for (let x = 0; x < VERTS_WIDE; x++) {
            DepthKit.geo.vertices.push(new THREE.Vector3(x, y, 0));
        }
    }
    for (let y = 0; y < VERTS_TALL - 1; y++) {
        for (let x = 0; x < VERTS_WIDE - 1; x++) {
            DepthKit.geo.faces.push(
                new THREE.Face3(
                    x + y * VERTS_WIDE,
                    x + (y + 1) * VERTS_WIDE,
                    (x + 1) + y * (VERTS_WIDE)
                ));
            DepthKit.geo.faces.push(
                new THREE.Face3(
                    x + 1 + y * VERTS_WIDE,
                    x + (y + 1) * VERTS_WIDE,
                    (x + 1) + (y + 1) * (VERTS_WIDE)
                ));
        }
    }

我可以使用指导 here 将 Vector3 数组制作为“点”并使用它在缓冲区几何上设置点,但我无法将每个点之间的面写入任何类似的上面THREE.Face3的方法......有什么想法吗?

我不是那个坚持了一年多的only person

【问题讨论】:

    标签: three.js


    【解决方案1】:

    const geometry = new THREE.BufferGeometry();
    
    // create an array of vertices
    const vertices = [];
    for (let y = 0; y < VERTS_TALL; y++) {
        for (let x = 0; x < VERTS_WIDE; x++) {
            vertices.push(x, y, 0);
        }
    }
    
    // create an array of faces
    const faces = [];
    for (let y = 0; y < VERTS_TALL - 1; y++) {
        for (let x = 0; x < VERTS_WIDE - 1; x++) {
            faces.push(
                x + y * VERTS_WIDE,
                x + (y + 1) * VERTS_WIDE,
                (x + 1) + y * (VERTS_WIDE),
                x + 1 + y * VERTS_WIDE,
                x + (y + 1) * VERTS_WIDE,
                (x + 1) + (y + 1) * (VERTS_WIDE)
            );
        }
    }
    
    // set the attributes of the geometry
    geometry.setAttribute('position', new THREE.Float32BufferAttribute(vertices, 3));
    geometry.setIndex(new THREE.Uint16BufferAttribute(faces, 1));
    
    DepthKit.geo = geometry;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-12
      • 1970-01-01
      • 1970-01-01
      • 2011-06-03
      • 1970-01-01
      • 2018-04-05
      • 2013-03-03
      相关资源
      最近更新 更多