gpt4 book ai didi

javascript - 向 BufferGeometry 添加索引不起作用?

转载 作者:行者123 更新时间:2023-11-29 16:08:34 24 4
gpt4 key购买 nike

我一直在尝试使用 THREE.BufferGeometry() 绘制一个非常基本的矩形。这是代码-

var geometry = new THREE.BufferGeometry();
var material = new THREE.MeshBasicMaterial({color: 'rgb(255, 0, 0)'});


var verticesArray = [20, 0, 0, 0, 20, 0, -20, 0, 0, 0, -20, 0];
var vertices = new Float32Array(verticesArray, 0, 12);

var indicesArray = [0, 1, 2, 0, 2, 3];
var indices = new Uint16Array(indicesArray, 0, 6);

geometry.addAttribute('position', new THREE.BufferAttribute(vertices, 3));
//geometry.addAttribute('index', new THREE.BufferAttribute(indices, 3));
geometry.setIndex(new THREE.BufferAttribute(indices, 3));


var mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);

不幸的是,它不起作用。它也没有抛出任何异常。据我了解,我所做的一切都是正确的。我有四个顶点,我已经按逆时针顺序描述了两组索引。

谁能告诉我这里哪里出了问题?

最佳答案

应该是geometry.setIndex(new THREE.BufferAttribute(indices, 1));

关于javascript - 向 BufferGeometry 添加索引不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34484720/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com