Three.js 缓冲具有超过40k个顶点的几何体
我在Three.js 缓冲具有超过40k个顶点的几何体,three.js,Three.js,我在BufferGeometry中加载了超过40k个顶点 它起作用了,但几何体并没有完全渲染。将几何体分解为40k个独立的40k个顶点后,它就开始工作了。我使用的是版本r86 这与我正在使用的硬件有关还是与三个js有关 下面是我用来创建BufferGeometry(normalgeom是作为参数传递的几何体)的代码的改编 更新:在@TheJim01的注释之后,分割几何体的代码如下 function makebuffered(normalgeom) { var retArrays = ne
BufferGeometry
中加载了超过40k个顶点
它起作用了,但几何体并没有完全渲染。将几何体分解为40k个独立的40k个顶点
后,它就开始工作了。我使用的是版本r86
这与我正在使用的硬件有关还是与三个js
有关
下面是我用来创建BufferGeometry
(normalgeom是作为参数传递的几何体)的代码的改编
更新:在@TheJim01的注释之后,分割几何体的代码如下
function makebuffered(normalgeom)
{
var retArrays = new Array();
var chunkLength = normalgeom.vertices.length;
console.log("nr vertices:" + chunkLength);
var remainingVertices = chunkLength;
var processedVertices = 0;
if(chunkLength > 40000)
{
chunkLength = 40000;
}
while(remainingVertices > 0)
{
if(remainingVertices <= chunkLength)
{
chunkLength = remainingVertices;
}
var positions = new Float32Array(chunkLength * 3);
var indices = new Uint32Array(chunkLength);
for (var i = 0; i < chunkLength; i++)
{
var posInNormalGeom = processedVertices + i;
positions[i * 3] = normalgeom.vertices[posInNormalGeom].x;
positions[i * 3 + 1] = normalgeom.vertices[posInNormalGeom].y;
positions[i * 3 + 2] = normalgeom.vertices[posInNormalGeom].z;
indices[i] = i;
}
var buffGeom = new THREE.BufferGeometry();
buffGeom.addAttribute('position', new THREE.BufferAttribute(positions, 3));
buffGeom.setIndex(new THREE.BufferAttribute(new Uint32Array(indices), 1));
retArrays.push(buffGeom);
remainingVertices -= chunkLength;
processedVertices += chunkLength;
}
return retArrays;
}
函数makebuffered(normalgeom)
{
var retarray=新数组();
var chunkLength=normalgeom.vertices.length;
log(“nr顶点:+chunkLength”);
var remainingVertices=chunkLength;
var processedVertices=0;
如果(chunkLength>40000)
{
chunkLength=40000;
}
同时(剩余顶点>0)
{
如果(remainingVertices您有847666个顶点,这导致847666个索引,远远超出了uint16阵列的界限(max=65535)
为了缓解这一问题,请改用uint32数组。所有现代浏览器(无论后果如何)都支持WebGL缓冲区的32位数组。您有847666个顶点,这导致847666个索引,远远超出uint16数组的界限(最大值=65535)
为了缓解这种情况,请改用uint32阵列。所有现代浏览器(无论后果如何)支持WebGL缓冲区的32位数组。你能解释一下你是如何导入数据的吗?也许可以添加一个代码示例?我用代码示例更新了这个问题。尝试使用uint32数组作为索引。你可能超过了uint16数组
的最大值,这将导致面丢失。@TheJim01:既然你提到了这很有道理。谢谢。我没有注意到我使用的是16位索引。@sandualuclopotaru为什么要将几何体分解成块?如果不共享顶点,为什么要设置索引?能否解释一下如何导入数据?也许可以添加一个代码示例?我用代码示例更新了问题。尝试使用uint32数组用于索引。您可能超出了Uint16Array
的最大值,这将导致面丢失。@TheJim01:既然您提到了,这是有道理的。谢谢。我没有注意到我使用的是16位索引。@sandualuclopotaru为什么要将几何体拆分为块?如果您是n,为什么要设置索引共享顶点?
var lineSegs = new THREE.LineSegments(buffGeom, material);
scene.add(lineSegs);
function makebuffered(normalgeom)
{
var retArrays = new Array();
var chunkLength = normalgeom.vertices.length;
console.log("nr vertices:" + chunkLength);
var remainingVertices = chunkLength;
var processedVertices = 0;
if(chunkLength > 40000)
{
chunkLength = 40000;
}
while(remainingVertices > 0)
{
if(remainingVertices <= chunkLength)
{
chunkLength = remainingVertices;
}
var positions = new Float32Array(chunkLength * 3);
var indices = new Uint32Array(chunkLength);
for (var i = 0; i < chunkLength; i++)
{
var posInNormalGeom = processedVertices + i;
positions[i * 3] = normalgeom.vertices[posInNormalGeom].x;
positions[i * 3 + 1] = normalgeom.vertices[posInNormalGeom].y;
positions[i * 3 + 2] = normalgeom.vertices[posInNormalGeom].z;
indices[i] = i;
}
var buffGeom = new THREE.BufferGeometry();
buffGeom.addAttribute('position', new THREE.BufferAttribute(positions, 3));
buffGeom.setIndex(new THREE.BufferAttribute(new Uint32Array(indices), 1));
retArrays.push(buffGeom);
remainingVertices -= chunkLength;
processedVertices += chunkLength;
}
return retArrays;
}