mattdesl / workshop-webgl-glsl

A workshop on WebGL and GLSL

Home Page:https://frontendmasters.com/courses/webgl-shaders/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

no vertices in the IcosahedronGeometry

abdulsalamalmahdi opened this issue · comments

in the video for drawing cricles into IcosahedronGeometry
when trying to access the vertices array on the IcosahedronGeometry objects it is undifined the array does noto exist.

commented

hey @abdulsalamalmahdi, I came across the same problem when following Matt's tutorial. The latest version of ThreeJS does not seem to allow an array of vertex coordinates to be accessed directly from the geometry i.e. new THREE.SomeGeometry().vertices. Instead I used the below workaround to extract vertices:

const someGeometry = new THREE.SomeGeometry();
const positionAttribute = someGeometry.getAttribute('position');

const vertices = [];

for ( let vertexIndex = 0; vertexIndex < positionAttribute.count; vertexIndex ++ ) {
  point = new THREE.Vector3().fromBufferAttribute( positionAttribute, vertexIndex );
  vertices.push(point);
}

Hope that helps