2017-02-08 1 views
0

내 지오메트리의 속성을 추가하는 중에이 오류가 발생합니다. 나는 이미이 WebGL GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 1을 읽었으며 문제가 무엇인지 이해하지만 그 이유를 알 수 없습니다.THREE.JS glDrawElements : 속성 1의 범위를 벗어난 정점에 액세스하려고 시도합니다.

1000 개체에서 시작하는 Tree 인 BufferGeometry를 구축하고 있습니다. 300 개체가 LeafGeometry를 사용하고 있고, 700 개체가 BoxGeometry를 사용하고 있습니다.

버텍스가 트렁크 또는 단풍에 속하는지 알려주는 값을 포함하는 버퍼를 수행하고 싶습니다. 내가하고있는 일은 다음과 같다.

1) 먼저 버퍼의 크기를 계산한다. (여기 나는 잘못하고 있다고 생각한다.) getTotNumVertices (LeafGeometry.new (options), BoxGeometry.new 나는 정점의 총 수를했으면 옵션), 1000, 3000)

function getTotNumVertices(foliage_geometry, trunk_geometry, tot_objects, foliage_start_at){ 
    let n_vertices_in_leaf = foliage_geometry.vertices.length * 3; 
    let n_vertices_in_trunk = trunk_geometry.vertices.length * 3; 
    let n_vertices_in_leafs = foliage_start_at * n_vertices_in_leaf; 
    let n_vertices_in_stam = (tot_objects - foliage_start_at) * n_vertices_in_trunk; 
    return{ 
     tot_vertices: (n_vertices_in_stam + n_vertices_in_leafs), 
     n_vertices_leaf: n_vertices_in_leaf, 
     n_vertices_trunk: n_vertices_in_trunk 
    }; 
} 

2), 나는 1000 함께 병합,

function createBuffers(n_vert){ 
    // I'm returnin an array becuase in my real code I'm returning 
    // more than one buffer 
    return { 
     isLeafBuffer: new Float32Array(n_vert) 
    }; 
} 

3) 그럼 난 내 BufferGeometry을 구축 버퍼를 생성 객체 :

그리고 여기에 문제 49,는,의 값은 bufGeometry.attributes.position.counthash_vertex_info.tot_vertices의 값이 그릴 때, 308,940보다 값이 더 큰 접근하고 오류를 수행하려고 WebGL을 308940.

이다 623,616이다. 내가 뭘 잘못하고 있니?

기본적으로

, 나는이 같은 문제에 직면 데 잠시 후

/////////// 편집이 Does converting a Geometry to a BufferGeometry in Three.js increase the number of vertices?

내가 총 수를 계산해야이 질문에 설명 내 셰이더에 대한 값을 포함 할 버퍼를 생성하기 위해 꼭지점 수를 계산합니다. 이것은 내 코드입니다. 병합 된 지오메트리와 그로부터 얻은 버퍼 지오메트리간에 여전히 다른 정점의 수입니다.

let tot_objects = 100; 
let material = new THREE.MeshStandardMaterial({color: 0x00ff00}); 
let geometry = new THREE.BoxGeometry(5, 5, 5, 4, 4, 4); 
let objs = populateGroup(geometry, material, tot_objects); 

//let's merge all the objects in one geometry 
let mergedGeometry = new THREE.Geometry(); 
for (let i = 0; i < objs.length; i++){ 
    let mesh = objs[i]; 
    mesh.updateMatrix(); 
    mergedGeometry.merge(mesh.geometry, mesh.matrix); 
} 

let bufGeometry = new THREE.BufferGeometry().fromGeometry(mergedGeometry); 

let totVerticesMergedGeometry = (mergedGeometry.vertices.length) + (mergedGeometry.faces.length * 3); 
console.log(bufGeometry.attributes.position.count); // 57600 
console.log(totVerticesMergedGeometry); // 67400 !!! 
scene.add(new THREE.Mesh(bufGeometry, material)); 

function populateGroup(selected_geometry, selected_material, tot_objects) { 
    let objects = []; 
    for (var i = 0; i< tot_objects; i++) { 
     let coord = {x:i, y:i, z:i}; 
     let object = new THREE.Mesh(selected_geometry, selected_material); 
     object.position.set(coord.x, coord.y, coord.z); 
     object.rotateY((90 + 40 + i * 100/tot_objects) * -Math.PI/180.0); 
     objects.push(object); 
    } 
    return objects; 
} 

totVerticesMergedGeometry 및 bufGeometry.attributes.position.count 수가

가 동일해야하지만, 여전히 다른이다.

내 계산 방법이 잘못 되었습니까? 사실 https://github.com/mrdoob/three.js/blob/master/src/core/DirectGeometry.js#L166, 즉 (geometry.vertices.length) + (geometry.faces.length * 3)을 의미합니다.

+0

어쩌면 때문에 http://stackoverflow.com/questions/4998278/is-there-a-limit-of-vertices-in-webgl, https://forums.khronos.org /showthread.php/6762-Maximum-size-for-index-buffer-and-how-to-go-around-it – gaitat

+0

나는 똑같은 생각을했습니다. 개체 수를 1000 개에서 100 개로 줄 였지만 문제는 여전히 지속됩니다.이제 bufGeometry.attributes.position.count는 105216을 반환하지만 내가 만든 버퍼의 크기는 44340입니다. 그래서 문제는 내가 기하학의 정점을 계산하는 방식이라고 생각합니다. 하지만 geometry.vertices.length * 3은 올바른 방법이라고 생각합니다. – edap

+0

올바른 트랙을 발견했다고 생각합니다. http://stackoverflow.com/questions/33290544/does-converting-a-geometry-to -a-buffergeometry-in-three-js-increase-the-number-o 나는 나중에 업데이트를 게시 할 것이다. 나는 잘못된 방식으로 버퍼의 크기를 계산하고있다. @gaitat, 연결된 대답은 당신에게서 온다;) 내 문제를 해결하면 보자. – edap

답변

0

이다 MyObjectGeometry.faces.lenght으로 계산할 것이다 값의 배열 :

- var colors = new Float32Array(
+ var colors = new Float32Array([ 
     1.0, 0.0, 0.0, 
     0.0, 1.0, 0.0, 
     0.0, 0.0, 1.0, 
     1.0, 0.0, 1.0, 
     0.0, 1.0, 1.0, 
     1.0, 1.0, 1.0, 
- ); 
+ ]);