Now I’m lost. We were talking about the thickness of a model and now you’re saying that you want to find model’s volume.
Moreover, once again, could you provide a live code example with the model?
Use an appropriate type of geometry for the algorithm. The appropriate type is a non-indexed buffer geometry. And the loader already returns the geometry of this type.
//stl file
var loader = new THREE.STLLoader();
loader.load(“file5.stl”, function (geometry1) {
material = new THREE.MeshPhongMaterial({ color: 0x5C98BD});
mesh = new THREE.Mesh(geometry1,material);
scene.add(mesh);
//your code
var minDist = 0.6;
var raycaster = new THREE.Raycaster();
var intersects = ;
var positions = geometry1.attributes.position; //console.log(positions);
var ori = new THREE.Vector3();
var dir = new THREE.Vector3();
var trc = new THREE.Vector3();
var a = new THREE.Vector3(),
b = new THREE.Vector3(),
c = new THREE.Vector3(),
midPoint = new THREE.Vector3(),
tri = new THREE.Triangle();
var closest = new THREE.Vector3();
var faces = positions.count / 3;
console.log(faces);
for (let i = 0; i < faces; i++) {
a.fromBufferAttribute(positions, i * 3 + 0);
b.fromBufferAttribute(positions, i * 3 + 1);
c.fromBufferAttribute(positions, i * 3 + 2);
tri.set(a,b,c);
tri.getMidpoint(ori);
tri.getNormal(dir)
raycaster.set(ori,dir.negate());
alert(intersects.length);
intersects = raycaster.intersectObject(mesh);
minDist = Math.min(minDist, intersects[1].distance);
console.log(minDist);
}
console.log("printable:", minDist >= 0.6);
});
As per previous discussion,
Now i have load STL file which is type of non-indexed buffer geometry.
But still i am unable to know whether stl file is printable or not?Here
console.log(“printable:”, minDist >= 0.6);
Could you please suggest where is changes required in my code.
Hello, thank you for your solution…I have modified your JSFiddle to set color on each face based on the distance. The color function is just to show you the specific faces that the measured wall thickness for them is incorrect. The image shows the dimensions, and if you use the console, you can see that the measurement for 4 faces (two walls that are black-colored) are 110 instead if 10, and that is why they are black instead of red. I was wondering if you could give your opinion on why this happens. Many thanks! https://jsfiddle.net/hesamoy/r7u1aqk8/40/
Well, obviously, the algorithm is imperfect and works not correctly, thus it needs to be improved.
Looks like, it’s because of float precision, rays just go between two triangles.
Any thoughts on improvement?
Thank you, by ‘between two triangles’ you mean rays pass through the first triangle and just intersects with the next one? so I might need to look into the ray and how it works in order to improve it?
Hi,
i have read all discussion going on, and i am also facing such kind of problem.
below is my current code:
var minDist = 0.6;
var raycaster = new THREE.Raycaster();
var intersects = [];
var pos = threejsobject.position; //positions of geometry
var ori = new THREE.Vector3();
var dir = new THREE.Vector3();
var trc = new THREE.Vector3();
var a = new THREE.Vector3(),
b = new THREE.Vector3(),
c = new THREE.Vector3(),
midPoint = new THREE.Vector3(),
tri = new THREE.Triangle();
var closest = new THREE.Vector3();
var faces = threejsobject.positioncount; // faces of geometry
console.log(“Faces:”+faces);
for (let i = 0; i < faces; i++) {
a.fromBufferAttribute(pos, i * 3 + 0);
b.fromBufferAttribute(pos, i * 3 + 1);
c.fromBufferAttribute(pos, i * 3 + 2);
tri.set(a, b, c);
console.log(tri);
// tri.getMidpoint(ori);
// get some random point on face
let r0 = 0.33 * Math.random();
let r1 = 0.33 * Math.random();
let r2 = 1.0 - r0 - r1;
I used to work for a distributed manufacturing company (3d printing, CNC). We had a team of computational geometry engineers, with a few PHDs among them working on the problems of identifying thin walls on 3d models. They worked with c++, i was hired as a WebGL expert to visualize the data that they would end up computing. With our wages, benefits, office space in SF etc. this could have easily been $1.000.000 a year to solve. And we were solving it for a couple of years.
What i want to say is that i’m surprised that people are tackling this with three.js and would suggest other tools for this. Between javascript, the browser and three.js i wouldn’t be able to tell which tool is less suited for this kind of a task
(threejs is great at visualizing thin walls on the web, not computing them)