本文介绍了将Geometry转换为Three.js中的BufferGeometry会增加顶点的数量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用fromGeometry方法从常规Geometry对象制作BufferGeometry对象,并且我发现在转换过程中顶点的数量似乎增加了。例如,如果我做了类似的事情:

I've been using the fromGeometry method to make BufferGeometry objects from regular Geometry objects, and I've found that it seems the number of vertices increases during the conversion. For example if I do something like:

var geometry = new THREE.BoxGeometry(80,80,80,16,16,16);
var bGeometry = new THREE.BufferGeometry();
bGeometry.fromGeometry(geometry);
console.log(bGeometry.getAttribute('position'));
console.log(geometry.vertices.length);

我得到一个Float32Array [27648],除以3得到9216,而Geometry有1538个顶点。我理解THREE.BoxGeometry合并了一些顶点,所以我怀疑它可能与它有关,但我是否更正BoxGeometry对象有更多的顶点?或者几何对象在GPU中是未压缩的,所以它们实际上具有相同数量的顶点,而不是在我的Geometry对象中?

I get a Float32Array[27648], which divided by 3 yields 9216, while the Geometry has 1538 vertices. I understand THREE.BoxGeometry merges some vertices, so I suspect that might have to do with it, but am I correct that BoxGeometry objects have more vertices? Or are Geometry objects "uncompressed" in the GPU anyway so they actually have the same number of vertices, just not in my Geometry object?

我问的原因是我试图创建一个自定义属性,但是当我只迭代几何体中的顶点数时,我的数组太短了对象,认为两个对象中都有相同数量的顶点。

The reason I'm asking is that I was trying to create a custom attribute, but my array was too short when I only iterated over the number of vertices in my Geometry object, thinking that there would be the same amount of vertices in both objects.

推荐答案

找出答案的最佳方法这些问题只是为了查看three.js代码。它非常易于访问且通常很容易理解。

The best way to find out the answer to these questions is just to look at the three.js code. It is very accessible and generally easy to follow.

首先我们可以查找方法:

First we can look up the BufferGeometry.fromGeometry method:

fromGeometry: function ( geometry ) {

    geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );

    return this.fromDirectGeometry( geometry.__directGeometry );

}

您可以看到调用

fromGeometry: function ( geometry ) {
    // ...
    var vertices = geometry.vertices;
    // ...
    for ( var i = 0; i < faces.length; i ++ ) {
        // ...
        this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
        // ...
    }
    // ...
}

在这里,您可以清楚地看到它正在添加来自几何面属性的其他顶点。 gaitat的答案给出了一个很好的例子,说明为什么!

And here you can clearly see that it is adding additional vertices that come from the geometry faces property. The answer by gaitat gives a great example as to why that is!

这篇关于将Geometry转换为Three.js中的BufferGeometry会增加顶点的数量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 07:40