Since r125, there is no Geometry
class anymore. All geometries are BufferGeometry
now. Thus, vertices are stored in geometry.attributes.position
.
BufferGeometry can be indexed or non-indexed:
- Indexed means that faces defined with triplets of incides of
vertices.
- Non-indexed means that faces defined with triplets of
vertices.
So, this part of code:
var a = new THREE.Vector3(),
b = new THREE.Vector3(),
c = new THREE.Vector3();
obj.geometry.faces.forEach(function(face) {
obj.localToWorld(a.copy(obj.geometry.vertices[face.a]));
obj.localToWorld(b.copy(obj.geometry.vertices[face.b]));
obj.localToWorld(c.copy(obj.geometry.vertices[face.c]));
lineAB = new THREE.Line3(a, b);
lineBC = new THREE.Line3(b, c);
lineCA = new THREE.Line3(c, a);
setPointOfIntersection(lineAB, mathPlane);
setPointOfIntersection(lineBC, mathPlane);
setPointOfIntersection(lineCA, mathPlane);
});
needs some changes.
var a = new THREE.Vector3(),
b = new THREE.Vector3(),
c = new THREE.Vector3();
var isIndexed = obj.geometry.index != null; // if geometry is indexed or non-indexed
var pos = obj.geometry.attributes.position; // attribute with positions
var idx = obj.geometry.index; // index
var faceCount = (isIndexed ? idx.count : pos.count) / 3; // amount of faces
for(let i = 0; i < faceCount; i++) {
let baseIdx = i * 3;
let idxA = baseIdx + 0;
a.fromBufferAttribute(pos, isIndexed ? idx.getX(idxA) : idxA);
// .fromBufferAttribute is a method of Vector3
// .getX is a method of BufferAttribute
let idxB = baseIdx + 1;
b.fromBufferAttribute(pos, isIndexed ? idx.getX(idxB) : idxB);
let idxC = baseIdx + 2;
c.fromBufferAttribute(pos, isIndexed ? idx.getX(idxC) : idxC);
obj.localToWorld(a);
obj.localToWorld(b);
obj.localToWorld(c);
lineAB = new THREE.Line3(a, b);
lineBC = new THREE.Line3(b, c);
lineCA = new THREE.Line3(c, a);
setPointOfIntersection(lineAB, mathPlane);
setPointOfIntersection(lineBC, mathPlane);
setPointOfIntersection(lineCA, mathPlane);
});
PS Haven't tested this snippet, changes from scratch. Possible typos.