sgenoud / replicad

The library to build browser based 3D models with code.
https://replicad.xyz
MIT License
323 stars 38 forks source link

shape intersection with complex object fails #88

Closed tve closed 10 months ago

tve commented 11 months ago

I have a complex object and am trying to cut out a section so I can print just that to test the fit, but the intersection fails. Here is a screen shot that shows the object 3 times:

image

But when I perform the intersection I get:

image

Somehow this cylinder piece is the intersection between the box and one of the cylinders that make up the complex object. Everything else is missing...

Model source: https://studio.replicad.xyz/workbench?code=UEsDBAoAAAAIABiL9lbruTHXfwUAAIQPAAAHAAAAY29kZS5qc41XW2%252FbNhR%252B96848F6kVJYdF8HWAh2WS7s9bGjQpkvaog%252BMRFlaaFKlqDhGkB%252B0v7FftsObRMl2tiCGeTnX73yHpOdz%252BFRvKp6ftXm%252BBfLAKKxFyxUUQgJh7bri7RrWpFEJ%252FHk8mc%252FhXNRbWa1KBf%252F8vVwsXyZwVQrZKMrhXnB4W2V3lE8m8yNYMXFLGEhasyojORzNcfUIflHbmua0gEfQI1FAta6FVNHUS05jeBqoTTLBGwUS3nTLfq3IFK4uJ%252FRB2wC7iNZJy9QlkWTd4PbjBABDX5OKmxxxqr8uKvIajl8lbvo75ThdLGCurfrVa8LYa3iZWBMl4bnRtwOj8mOgYZcvRRMsa71aNJWqEB%252FCBF%252F5IKz0KV8x%252Bhp%252BOjGSRM9ACWgYwTpYEWjrDZF5Y4NoGKX3RqYULO%252FLRB%252BUbBv0gmJWxsZ30sdnl21O1p8qsWKcNg1gJTa4AUQiA3L4BLUURWUCba%252BrXJUandRqbfRca0S3QimxxmE81LigtdF4aeRLaiijFZoqp82u%252FJWOA%252BXTPWE5MROex0BJyleqpLxCPHGXUTVXsjLwoQgOXT1d5ZpM0o3GjInsTmM2hEvvGj6cJH76vij6eERRNBTpJjHXjHJF5eRpMilanpmyZlhWeiol2UYkRmZLqlqJ1U7XpI4ogzc%252FA2WpkYpipPfEE9ZRFTpLmqRRHRvOWjabrkTmo607er5l2K5URnXqKIzFXSZgp5hynKIigBSKKBq9WiTwFT%252F6%252FxsOZ8duHKc6K2YwBGyLz%252BimaoyqkoQj%252BRT9MnQSGw2yBcERxpvPUCND6aSL01G1i1RgWyORogCbr8aBb0WnkLmUbNz%252FkWXXdy7PLlO%252FZbppmDR%252Bm7x3kp7dmKyRk0zTk21t09Hc91vsfByEJNmPicuyaWtd5Pkd3W7INsjvjDT0TDxEQT6%252BhKOKekfpOJJoFihbDZ1vnHjnd1zc%252BrH1%252BrEuqaR9BkfYzSfOshHKJdmcVzJju0LNHVVZ%252BZ5f6vyiOJX0XrB7Gn09ThaJRnZo5VKwrWn0kaEElov%252Fa%252BygJTiC3lbWqshKfqCZMu3fSwYoxmkPnSbEEN5nY%252FId82wJjNTAKLwI%252BYpB%252F0FUmWaiGXIVN2R68fbX5YfTi1gT7lvsXHWOPncaeLMcbPCBc8d7S3tTFyMPjfBtV4uKqwaZ3newvR3MyY1tXKf2EMc8lhhknfaXx0jD3A5Www6f09BH629i%252F5Hmj%252BE5sjkw%252FWI5rl6wOV%252B%252BcIp4YOtOj0fRdY76rutuxyTMeeDTwWxvlsg3oGabP3cO2cTsj5MOvaRDpSNQSCFfuh4pe%252BbsUmAWVqc%252FEnREHaZa11x3Nn%252B8BHV8CADHu0%252Bm70hG31ms47RyVJ%252FefJnqgyMtcCeyThJ4bHn1vcVnCd6R9KmHtDd5sOmwHPb2PRpWcTaq4qCG4wa0US0Hjq9E3fkdH1MBIgNwRwKHj%252Bt97mc%252Bk0EYGIMNJmWiUNeVKiOHisbQ0AU5aF8dWBjddQgtvoTF7V%252BIVn%252Bv41vr2ctSR564dvVIJto3nhBD%252B4pqtlP7gsDMspLiI6eoFD7UkC32hViNnoguIVT9iJpI4p1GWS4G%252FWEONAuI5vhiUF2zsq8CsxP9iQcOT03qCIB%252FEoWkdQENBZCu%252BObSKUZBxN2LaicdXaRducBKYNuA6V5s9oXyCE1JamS%252FluqyuYnw1wFe%252BZyscWuKe8iRTDAhcfZDUVD8m8JTMjKBVQxtzIZGcDewIlButceIJcFhM3Y%252FMHTL2j1mbL0Om7H7gZmVpJTvseMPnGdMeZHA2pYyJjbTsTWk1GE7uBniw6r7PXn5UvdabiFQrVtZs2d0kSY76rgWWMAfuZTtB9aResfA6YAj5pUZQvoNf0T8C1BLAQIUAAoAAAAIABiL9lbruTHXfwUAAIQPAAAHAAAAAAAAAAAAAAAAAAAAAABjb2RlLmpzUEsFBgAAAAABAAEANQAAAKQFAAAAAA%253D%253D

To see the result of the intersection select only the "testSect" object in the viewer.

sgenoud commented 10 months ago

There was two problems with your code! The main one is that you used makeCompound when you should have used some fusing. makeCompound keeps the different parts separated - but you want to fuse them into one. When you do an intersect on a compounded shape it gets confused.

There is also an issue with your knob - when you revolve your shape it creates some weird self intersections. It works with the sphere for instance.

Here is the code with my modifications.