Hi Community,

I uploaded a file using STLLoader, which supports both Binary and ASCII files, and returns non-indexed BufferGeometry.

I have calculated the volume and distance using the following codes. When I compared the results to other results from online 3d calculators, in most cases, the volume matches. However, the distance is not matching at all.

Here is the codes:

```
var object;
let material = new THREE.MeshStandardMaterial({color: 0xE5E4E2, side: THREE.DoubleSide, wireframe: false});
var loader = new THREE.STLLoader();
loader.load(`trouser_clip.stl`, function(geometry){
object = new THREE.Mesh(geometry, material);
// object.position.set(0,-20,0);
var helper = new THREE.AxesHelper(5);
helper.position.set(0, 0, 0)
scene.add(object);
scene.add(helper);
console.log(geometry);
// getVolume(geometry);
getVolume(geometry);
volumeInput.value = getVolume(geometry).toFixed(2);
});
}
function signedVolumeOfTriangle(p1, p2, p3){
// return vol = p1.dot(p2.cross(p3))/6.0;
var v321 = p3.x*p2.y*p1.z;
var v231 = p2.x*p3.y*p1.z;
var v312 = p3.x*p1.y*p2.z;
var v132 = p1.x*p3.y*p2.z;
var v213 = p2.x*p1.y*p3.z;
var v123 = p1.x*p2.y*p3.z;
return (-v321 + v231 + v312 - v132 - v213 + v123)/6.0;
}
// Get volume
function getVolume(geometry){
if(!geometry.isBufferGeometry){
console.log("'geometry' must be an indexed or non-indexed buffer geometry");
return 0;
}
var isIndexed = geometry.index !==null;
let position = geometry.attributes.position;
let p1 = new THREE.Vector3(),
p2= new THREE.Vector3(),
p3 = new THREE.Vector3();
let sum = 0;
if(!isIndexed){
let faces = position.count/3;
for(let i=0; i<faces; i++){
p1.fromBufferAttribute(position, i * 3 + 0);
p2.fromBufferAttribute(position, i * 3 + 1);
p3.fromBufferAttribute(position, i * 3 + 2);
sum += signedVolumeOfTriangle(p1, p2, p3);
}
} else {
let index = geometry.index;
let faces = index.count / 3;
for (let i = 0; i < faces; i++){
p1.fromBufferAttribute(position, index.array[i * 3 + 0]);
p2.fromBufferAttribute(position, index.array[i * 3 + 1]);
p3.fromBufferAttribute(position, index.array[i * 3 + 2]);
sum += signedVolumeOfTriangle(p1, p2, p3);
}
}
var dist12 = p1.distanceTo(p2);
var dist13 = p1.distanceTo(p3);
var dist23 = p2.distanceTo(p3);
distInput12.value =dist12.toFixed(2);
distInput13.value =dist13.toFixed(2);
distInput23.value =dist23.toFixed(2);
// console.log({dist12})
// console.log({dist23})
// console.log({dist13})
// console.log({sum})
// console.log(geometry)
return sum;
}
```

Can anyone help me with this please. I don’t know what I’m doing wrong.

Thanks.