tag:blogger.com,1999:blog-1602211711429849259.post6222118685692299906..comments2017-04-14T22:28:17.814-07:00Comments on BezBlog: OpenSCAD Rendering Tricks, Part 3: Web viewerScott Bezekhttp://www.blogger.com/profile/04507582410689916458noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-1602211711429849259.post-52793540786069856092017-01-11T17:55:48.966-08:002017-01-11T17:55:48.966-08:00Thanks Scott.
What can be identified (mathematica...Thanks Scott.<br /><br />What can be identified (mathematically) when objects A and B are intersected is the boundary of the intersection (e.g. the semispherical surface in<br /><br />color([1,0,0]) <br />intersection() {<br />sphere(10,$fn=100,$fa=5);<br />translate([0,0,10]) sphere(3,$fn=100,$fa=5);<br />}<br /><br />). In Maya for example, this part of the mesh is given its own node, making material assignation easy. Of course, the boundary is a surface and so is not intelligible (perhaps?) to a cad system that deals only with solids. (The problem with Maya from the point of view of my project is that it's booleans are infuriatingly error-prone for complex surface meshes developed using recursive differences.)<br /><br />I recognise now that I have chosen the wrong platform, but I am still attracted to the idea of using CGAL's boolean engine, with all of its mathematical precision, to perform my sphere-scooping operations.<br /><br />Update: I've managed to cajole CGAL into working on my Windows machine; so now for the experimentation.<br /><br />JimSven Abelshttps://www.blogger.com/profile/08589372900885072138noreply@blogger.comtag:blogger.com,1999:blog-1602211711429849259.post-43276223260456149312017-01-05T10:23:19.224-08:002017-01-05T10:23:19.224-08:00That's a pretty interesting edge case. Multi-c...That's a pretty interesting edge case. Multi-color volumes are tricky, as mentioned in one of the OpenSCAD threads on color exports:<br /><br />"So the question then is, what do the CSG ops mean where there is a <br />material spec? Clearly for two objects A and B, if the material of A <br />and B is the same, then result of all ops is the same material. If A <br />and B are different, then their intersection creates a problem - what <br />material is it?" http://forum.openscad.org/Exporting-colors-tp2651p2672.html<br /><br />Unfortunately to simplify things my python code assumes that each volume is a single color, but in your example different surfaces of the same volume end up with distinct colors.<br /><br />Exporting that to be rendered "correctly" in three.js would probably require a fairly different approach. The approach I took exports a separate STL mesh per volume/color and applies the color in three.js to each STL-based mesh as it's loaded. But to support multiple colors, you would probably want to use something like a MultiMaterial (https://threejs.org/docs/api/materials/MultiMaterial.html) to apply multiple colors to a single mesh, but I'm still not quite sure how you'd programmatically identify which surfaces should be assigned which color based on the original OpenSCAD model.<br /><br />So I don't have any great suggestions for doing that correctly. A less "correct," hacky idea would be to try to split the volume into separate, overlapping, volumes per color. So for a difference() operation like your example, you would first keep the original difference and assign it the primary volume's color (white). Then, for each of the subtracted child volumes in the difference you would replicate the entire difference operation, but with a slightly "inset" primary volume and with all child volumes outset a tiny amount, except for the current one which is instead <i>inset</i> a tiny amount.<br /><br />This has the effect of creating overlapping volumes in different colors where the colored portions are only exposed along the intersection surface, and looks pretty similar to the "correct" rendering with a small enough inset/offset epsilon.<br /><br />Unfortunately there isn't a 3d offset/inset operator in OpenSCAD, so I don't know how to do this for the general case (and there may in fact be some edge cases where this general inset/offset approach doesn't work at all, since I've only been thinking through your simple spheres example), but in this example I've applied the inset/offset by just adjusting the sphere radius.<br /><br />eps=0.01;<br />color([1,1,1]) <br />difference() {<br /> sphere(10,$fn=100,$fa=5);<br /> translate([0,0,10]) sphere(3,$fn=100,$fa=5);<br /> translate([2,2,sqrt(92)]) sphere(3,$fn=100,$fa=5);<br />}<br />color([1,1,0])<br />difference() {<br /> sphere(10 - eps,$fn=100,$fa=5);<br /> translate([0,0,10]) sphere(3 - eps,$fn=100,$fa=5);<br /> translate([2,2,sqrt(92)]) sphere(3 + eps,$fn=100,$fa=5);<br />}<br />color([0,0,1])<br />difference() {<br /> sphere(10 - eps * 2,$fn=100,$fa=5);<br /> translate([0,0,10]) sphere(3 + eps,$fn=100,$fa=5);<br /> translate([2,2,sqrt(92)]) sphere(3 - eps,$fn=100,$fa=5);<br />}<br /><br />You can try changing the <i>eps</i> value to a larger value like 0.2 to better visualize what's going on.<br /><br />Hopefully that makes sense, it's definitely a tricky problem.Scott Bezekhttps://www.blogger.com/profile/04507582410689916458noreply@blogger.comtag:blogger.com,1999:blog-1602211711429849259.post-48874856832757233562017-01-04T19:42:51.046-08:002017-01-04T19:42:51.046-08:00Thanks Scott, I got the python scripting going. Bu...Thanks Scott, I got the python scripting going. But due to the solid nature of the OpenScad geometry, I was unable to work out a way to separate the regions in the below (experimantal) object by colour:<br /><br />difference() {<br /> color([1,1,1]) sphere(10,$fn=100,$fa=5);<br /> color([1,1,0]) translate([0,0,10]) sphere(3,$fn=100,$fa=5);<br /> color([0,0,1]) translate([2,2,sqrt(92)]) sphere(3,$fn=100,$fa=5);<br />} <br /><br />I tried using intersection with difference to create a hollow white sphere and two thin scoopy pieces (one yellow, the other blue), but the python method - perhaps not surprisingly - generated three complete spheres in separate stl files.<br /><br />Any ideas?<br /><br />Cheers,<br /><br />JimSven Abelshttps://www.blogger.com/profile/08589372900885072138noreply@blogger.comtag:blogger.com,1999:blog-1602211711429849259.post-25946530342064066752016-08-29T22:39:48.769-07:002016-08-29T22:39:48.769-07:00This is great! I've been settling for just exp...This is great! I've been settling for just exported images of my OpenSCAD projects when I blog about them, but I'm going to try this instead next time.Christopher Finkehttps://www.blogger.com/profile/04129723128838806165noreply@blogger.com