Está en la página 1de 8
eno? ‘Converting POV: Ray Shapes to Tangle Mesh for 3-0 Printing | CY's Art and Graghies CY's Art and Graphics Sharing my Ray-Traced Artwork and How I Create It Home My blogs ‘You aes: Cyber Home> Crs At and Graphics > Converting sOVRay Shapes to Tena Mesh for 3-0 Pts Converting POV-Ray Shapes to Triangle Mesh for 3-D Printing Posted on October 28, 2016 by ey ‘The Persistence of Vision Ray Tracer or POV-Ray is an open source free ray tracing rendering engine that uses a special text based scene description language for moceling and rendering objects. Unlike many CAD programs that use triangle meshes ta define it shapes, POV-Ray uses mathematical formulas to define its primitive shapas. In addition to traditional primitive objects such as sphere, box, and torus it includes blobs, fractals and polynomial based objec, It does alse support cresting objects out of triangle meshes but there’s no way to convert other POV-Ray objects into triangle meshes. If you want to 3-D print an abject you've designed In POV-Ray or transfer It to seme ether CAD program that only supports meshes there's no surefire way to do that POV-Ray does cive you the ability within its scene description language te fire a ray at any ebject and determine its Intersection point and surface normal at that polnt. We can use this feature to fre rays at an object In a grid and create @ set of points called a “point cloud’. These points can be output toa text fle and then imported into otner software that wil create a triangle mesh based on this collection of points. This method is not useful fer exporting an entire scene with many objects and lots of detalls. But if you have one of those organic blob, fractal, or polynomial primitive shapes that you want to convert to a mesh it does give you a reasonably accurate representation of the anginal shape We have created a set of macros called "pov2mesh” that automates ths process for you. In this tutorial we will describe how to use this software along with other free programs to scan a POV-Ray abject, create a set of points, and convert It to STL files sutable for import into other modeling software and eventual 3-0 printing ‘The part of the process is the POV-Ray vector function “trace” which is used as follows: Beeclare Worw=<0,,055 1 ‘eeclare Hitstnece(Object, Location, Direction Nona); AiFevLength(orn)) ‘eebug concatcuste(3, Hit," ",0,6), "Wn"? send Hl ‘The function returns a three element vector containing the XYZ coordinates of where the ray his. You pass i the object you want to trace, the inital locaton, the direction of the ray, and @ vector variable that it wil use to return the surface normal. You have to pre-iiialize @ vector for the surface normal. The function mocifies that parameter to return the Value, If the length ofthat normal vector is zere then the ray did not hit. Tf the length is nonzero we then output the values to a text file using the # debug statement, Each point Is output to a single line separated by spaces. ‘The macros we are supplying use this code to fire rays at your object in 2 grid pattern of parallel rays. We also have a eylincrical pattern which we will describe later, The grid macro is a5 follows: TGrld_TraceCObjece, Sear Ena Dela DR, 1 2 ‘StartC;Endc,Del tac 0: ComlCon, Doth) ‘The first parameter is the object you want to sean, The scan Is done in rows and columns. You specify the start coordinate of the row, the end coordinate, the increment or celta value tat is the di direction ofthe row, This Is followed by the stat, end, delta, and erection of the columns, If you want to visualize where ‘the hit occurs the inal parameter isthe radius ofa tiny sphere which wl be renderec atthe intersection paint. IF you ass zero then the spheres are not created, Here Is an example of how you would invoke this macro tance between the rows, ané the ([LerReTraceO Object, 3.3.0, Bx 02, 81D 1 ‘This uses rons in the Y direction from -3 to +3 in 0.25 increments. It goes from -4 to +4 anc 0.25 increments in the x direction, The ray starts at -10*z and is emitted inthe +2 direction, The racius of the dots is 0.1. thpdgranies.cyborgScom/2016110729'conveting-pov-ray-shapes-o-Fiangle-mesivior-3-é-prnting| ve eno? ‘Converting POV: Ray Shapes to Tangle Mesh for 3-0 Printing | CY's Art and Graghies ‘The trace function only gives you the first hit where the ray intersects the object. Therefore itis generally necessary 1 fire the rays from mulple directions. We also provide a cylincrical pattern that you would Invoke as follows: T Cyn TraceCOb ject, Start End Delta, OTR, 1 z ‘Start End Del tal0: rH ComL,ConD, Doth) ‘The second through fifth parameters are the starting angle of rotation, ending angle, the increment in degrees, and the direction of rotation. The next four parameters the start, end, increment, and direction ofthe height ofthe cylindrical scan, “The other parameters are as with te grid trace version of the macro. Here Is a typical way to invoke It (Teyinctrace GHy_Ob eck, 0,360.7, PCCD 1 59K ‘This does a cylindrical scan going from 0 to 360 degrees rotating about the y-axis in 2 degree increments. It oes {ror ~4 to +4 along the y-axis in 0.25 increments, The ray starts out at location 10x and points inwards in the -x direction, “That location is what's rotated If you wanted to scan from the inside out those parameters would be <0,0,0>,x which would put the camera on the origin and point ousward in the +x direction, ‘We also give you a combination macro which wil fire rays from the top, bottom, lef, right, front, and back as well as ‘rlindrcal scans outside in and inside out It is defined as follows: [iA Tsce(Wojace, Ged, Gra, dees, Del zag, Dot) 1 ‘The parameters GridMin and GridMax are vectors defining the bounds of the area to be scanned. Deltas is the Increment for grid scan and Deltating is the increment in degrees forthe cylindrical scans, You would invoke it as follows: Ae ORS SES, OT OD 1 You can download the sample code from GitHub atthe following link, htps://oithub.com/cyborg5/pov2mesh It contains ‘three les. The frst file "test_platform.pov" Is 2 standard camera and lighting system that I use when testing objects. The file ‘pov2mesh.pov" contains the macros. Finally there is a sample scene “blob. pov” using blob shapes that we will use to ilustrate the process of converting the data into a mesh. Here is that scene Haeclare Gert_con_loe=c0,20, 5; 1 include "test.platfors.pov" include "povznesh. pov | declare Strength = 1-0 fdeclore Rodiust = 1 declare My Ooject= | i Radiusl, strength scale <1,1,0.5> n Radiust, Strength} | 12 Sprerete Radish, Strengin} 3 Seales He Plmerctrge.0.0 | 6 1? object My ovject} | 1B ALL-Tracelip- Object, <6,-6,-6>,6,6,65,0.2,2,0.05) 439 background {rgb 2} You should render this scene and redirect the debug output to a text file using the following command line switch ‘46Dbl0b. asc”. The "-asc" extension is simply an ASCII text file which we wil Import toa free program called Mesh Lab. Here is where you put the switch to redirect the outout = Prove Poe Prove fnelade “test oe ‘Recirect output with +GD switch eclace mcbject= heshar4, 0,6 Sphere‘ egg Oe Radius. strength scale <1,1,0.59) Pranent (rade, 0,0) » object ny. objece) SN rracetiy"dbSeze,<-0,-0, ~5> <6,646>,0.2,2,0.05) aceon ear thpgranies.cyborg6com/2016110:291conveting-pov-ray-shapes-o-Fiangle-mesivior-3-d-prnting| eno? ‘Converting POV: Ray Shapes to Tangle Mesh for 3-0 Printing | CY's Art and Graghies Here is the image ereated which shows you the dots on your object, The box around the object illustrates the ‘minimum and maximum areas forthe grid scan. We don’t really need the Image that was rendered. We are only Inerestee in the text file containing the points ‘This isan example of a few lines of the file we creates 1-2, 209800 5 o0000 2 4209000 73°400000 5 “4200000 “3! 200000 4 5 reas Asana? 76401 ‘200080 —2/ 980000 ‘200000 -2s00008 We will now import this fle inte Mesh Lab. Its a free program available on multiple platforms which you can download here, http://meshiab.sourceforge,net/ You can click on the images ‘throughout this blog to see larger versions. Open Mesh Lab and click on the File -> Import Mesh menu. A smal dialog box will pen and you should use the default settings. You will then see the point cloud you have impertec: Because our scanning method could have produced identical points or points that were extremely close to one anot Simplification and Recorstruction-> Clustering Decimation tem. A dialog box will pop up and you should enter a number in the first field "Call Size” I recommen entering a world unit of 0.1 which means that any points which are closer together to Fiter them out using @ "Clustering Decimation” filter You should click on the menu Filter-> Remeshing, than 0.2 units will be combined into an average locaton ofa single point, This value should be equal to or perhaps less than the increments you used when creating the scan of points in POV Ray. You also have an alternative percentage value that yu can set if you would rather doit that way. You then click on the “apply” and “close” buttons. thpgranies.cyborg6com/2016110:291conveting-pov-ray-shapes-o-Fiangle-mesivior-3-d-prnting| eno? ‘Converting POV: Ray Shapes to Tangle Mesh or $-D Printing | CY's Art and Graghies esos onen r csr teat late td ne Next we need to compute the normal for each of the vertices. Although the POV Ray “trace” function gave us the normal, we have rot yet figured out how to import that information into Mesh Lat. Click onthe menu Filter-> Normals, curvatures and Orientation-> Compute normals for point sets, You can use the default settings inthis dialog box. Click on ‘the “apply and “close” buttons. OF oe We are now ready to actully construct the faces of the mesh using the points. On the menu select Fiter->Remeshing, Simplification and Reconstruction-> Surface Reconstruction Poisson. Note that there are two other methods of surface reconstruction availabe. The others are “Ball Pivoting” and "VCG". Te be honest I don't understand what any of these three options mean, The Poisson method was recommended by a website I found and it works for me so use it. You can probably Use the default settings in the dialog box that pops up. Again I'm not relly sure what these values do, At times I've tried experimenting By increasing the first twa values from the 6 to 8 and the samples fram 1 ta 2 and at times it gave me slightly better results, Or you can just click on “apply” and "close" aa >| ecco se ‘Feracomsrace ation cosh ee a Creede ere seep te | ponerse *| tectonic Seteceoectins [2 thpgranies.cyborg6com/2016110729'conveting-pov-ray-shapes-o-Fiangl-mesivior-3-é-printing| amano ‘Converting POV: Ray Shapes to Tangle Mesh for 3-0 Printing | CY's Art and Graghies ‘You should now see your object shaded gray like the image below We seree TOD IOP OMe ss Mith x. However if it comes out very dark or black like the Image below, It mears thatthe service normals of the faces somehow got inverted and we need to force them to flip over ‘To invert the face normals use the menu Filters-> Normals, Curvatures and Orientation-> Invert Faces Orientation. Use the derault values on the dialog box and make sure that "Force Flip" Is checked. Click an “apply” and “close” thpdgranies.cyborgscom/20161107291conveting-pov-ray-shapes-o-Fiangle-mesivior-3-é-prnting| amano ‘Converting POV: Ray Shapes to Tangle Mesh for $-D Printing | CY's Art and Graghies Shaan met ines renter, Sgt ‘ston Frege tm te rahe Pager and cue Nowapionecs Sac Birrere Torben edacue toa Finally we already to export our newly creates mesh as an STL file. On the menu select File-> Export Mesh. Give it @ filename and under the Files of type: choose STL File Format (Ofieae fer fens View Vindour New my rjc. CaN pen pro cmo. Seer cans tn _[iSieeianieseriaieat Cle Pect 3 come Roms, pot Mab, iced iced catsheer i Many CAD programs and 2-D printing slicing sofbware ean import and manipulate and arint STL fles. We like to use Blender 30 for edting files and designing models. You can obtain it at https//mm,blender.oral We're nat going to go ino any detall on how to use Blender because there are plenty of online tutorials available especially en YouTube. Also you may be using otner software, In Blender balance to you can click on the menu File-> Import-> STL format, You'll probably notice that your object isnot in the orientation that you expecte thpdgranies.cyborgscom/20161107291conveting-pov-ray-shapes-o-Fiangle-mesivior-3-é-prnting| eno? ‘Converting POV: Ray Shapes to Tangle Mesh or 3-0 Printing | CY's Art and Graghies ‘That is because the POV Ray coordinate system has the y-axis pointing upwards and the z-axis pointed into the screen, Most CAD pragrams have the y-axis pointing away from you ané the z-axis pointing upwards. So you may have to rotate and/or mirror flip te get your object oriented properly. decimation modifier to reduce the number of triangles in relatively smooth areas while retaining detail in areas with Light radius Uniess you use extremely small increments, you may lose detail in converting your object, Sharp edges are never going to be completely sharp using any scanning method. You may have to do some retouching In another programm. This ‘method is really only intended for those bizarre shapes that POV Ray can render that are not available in ether CAD programs, Here is a link to another article describing how I used this software to 3-D print a POV-Ray abject that I ereated many years ago. It includes a YouTube video that shows an animated ception of how the scanning process works. thpdgranies.cyborgscom/20161107291conveting-pov-ray-shapes-o-Fiangle-mesivior-3-é-prnting| 8 eno? ‘Converting POV-Ray Shapes to Triangle Mesh for 3D Printing | CY's Art and Graphs ‘This entry was posted in Ray tracing by cy. Bookmark the permalink [http:/ /araphics.cyborg5.com/2016/10/29 /converting-pov-ray-shapes-to-triangle-mesh-for-3-d-printing/] thpdgranies.cyborgscom/20161107291conveting-pov-ray-shapes-o-Fiangle-mesivior-3-é-prnting|

También podría gustarte