home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / DXF2HSH.ZIP / DXF2HSH.DOC < prev    next >
Text File  |  1994-05-15  |  14KB  |  251 lines

  1.                                  DXF2HSH
  2.                 DXF polyline/polygon to DXF 3D Face converter
  3.                          by Vance Gloster May 1994
  4.                                 based on
  5.                                  DXF2TRI
  6.                 DXF polyline/polygon to triangle converter
  7.                          by Tim Riley   Aug 1993
  8.                                 based on
  9.                 POLY2TRI - a polygon to triangle converter
  10.                          by Steve Anger Jan 1993
  11.  
  12. This program is commited to the public domain. Feel free to use all or part
  13. of this code in your own programs.  If you simply MUST show gratitude, send
  14. Animation Master .seg and .fig files for something cool you've created or a 
  15. favorite bitmapped texture to my internet email address, vance@netcom.com.
  16.  
  17. This is a utility that extracts polyline shapes from a DXF file and breaks
  18. them down into individual triangles. The polylines are assumed to be closed,
  19. planar (2D) polygons. This program only deals with POLYLINE entities and
  20. ignores all other entities in the DXF file. All properties (color, line type)
  21. are ignored. 
  22.  
  23. The input DXF file consists of one or more polylines with no more than 2000
  24. vertices. This limit is rather arbitrary and can be changed if necessary by
  25. changing POLYMAX.
  26.  
  27. The program uses the following syntax:
  28.  
  29.         DXF2HSH infile[.DXF] outfile[.DXF] [xy]
  30.  
  31. The xy switch when added at the end modifies the plane that it extracts the
  32. polygons from.  The software I use, 3d Font, ouputs DXF files in the XZ plane
  33. as do some other programs.  My understanding is that Corel Draw 4.0 outputs
  34. DXF files in the XY plane, so this switch should be used if you are exporting
  35. drawings from Corel.  Using the wrong setting on this switch usually results
  36. in the object that you import being just a line with a bunch of control points
  37. on it.
  38.  
  39. The output file is a DXF file which consists of 3D Face objects, one for each 
  40. triangle.
  41.  
  42. So what is the program good for?  The program I use to do 3D rendering is 
  43. Animation Master from Hash, Inc.who also make Playmation.  They have included
  44. a limited utility for importing DXF files.  This was designed to be used with
  45. DXF files created by a company (whose name I have forgotten) that makes high
  46. quality models of almost anything and sells them for more money than I can
  47. afford.  These models consist of triangles expressed as 3D Face objects.  
  48. Since the import utility was only designed to read this format, it does not
  49. read DXF files that have the more common POLYLINE objects.  
  50.  
  51. What *I* wanted to do was to import text using fancy fonts.  I found a Windows
  52. program called 3D Font by a company called Visual Software which will accept 
  53. text and output a DXF file using any TrueType font.  Unfortunately, these DXF
  54. files consist of POLYLINE objects.  To make a long story short (too late) my
  55. program converts the output of 3D Font into a format that you can import into
  56. Animation Master.
  57.  
  58. The code to read the POLYLINE DXF file and break it into triangles was in the
  59. program I derived this program from.   I merely modified the POLYLINE reader 
  60. to use either the y or the z as the second dimension of the POLYLINE construct 
  61. which 3D Font uses for some reason.  I added the code to output the 3D Face 
  62. objects.  To figure out what was required I merely created a couple of triangles 
  63. in the Sculpture module of Animation Master and output them as a DXF file and 
  64. emulated the form, assuming that whatever it could output it should be able to 
  65. input.  I was fortunate in finding a program that had most of the pieces I needed
  66. already done.  Thanks, Tim!  Thanks Steve!
  67.  
  68. This archive should contain the following:
  69.  
  70.         DXF2HSH.C       The source
  71.         DXF2HSH.EXE     The executable, compiled with Microsoft Visual  
  72.                         C++ 1.5, medium memory model. No extenders,
  73.                         no memory tricks, so you don't have to worry about
  74.                         EMM386 and it's ilk and it runs fine from within
  75.                         Windows.
  76.         DXF2HSH.MAK        Visual C++ make file.
  77.         DXF2HSH.DOC     This file.
  78.         V.DXF            The output of 3D Font of a capital V in Times New
  79.                         Roman font.
  80.         VH.DXF            V.DXF converted by DXF2HSH.
  81.         V.SEG            VH.DXF imported into the Sculpture module of Animation
  82.                         Master.
  83.  
  84. Here are the steps for using DXF2HSH with 3D Font and Animation Master.  
  85. A similar process should be possible with most Windows drawing programs 
  86. like Corel, Micrographix Designer, Adobe's drawing program, etc.
  87.  
  88. 1.        Use 3D Font to generate a DXF file of your text.  If you are using
  89.         some other package, make sure that you convert all curves to line
  90.         segments (POLYLINES).  3D Font does this automatically.  In 3D Font
  91.         use the "Save 2d..." option to create the file.  In any other 
  92.         package, make sure it creates a 2D DXF file, not a 3D DXF file.
  93.         Assume for the purposes of this example that you have created a DXF
  94.         file called MYTEXT.DXF.  My test was performed with version 2.0 of
  95.         3D Font.
  96.  
  97. 2.        Run the DXF2HSH utility.  For our example the command string is:
  98.  
  99.         DXF2HSH MYTEXT AMTEXT
  100.  
  101. 3.        Run the Sculpture module of Animation Master.  Under the File menu
  102.         select "Import DXF...".  Select AMTEXT.DXF in the dialog box that
  103.         comes up.  You will see your text appear.  Make sure that you
  104.         have version 2.04 or later of Sculpture (the version number is in
  105.         the About box) because previous versions had a bug in DXF import.
  106.  
  107. 4.        For best results, at this point select "Select All" from the Group
  108.         menu, and then Peak Grouped Points.  You can do this by either
  109.         typing 'K' or pressing the button with the icon that looks like
  110.         this: 
  111.           .
  112.         ./ \.
  113.  
  114.         with stright lines.  This makes the triangles operate the way they 
  115.         are supposed to with straight lines.
  116.  
  117. 5.        Since the imported object is only 2D, you will probably want to 
  118.         extrude it.  Since there are often LOTS of control points (because
  119.         these are triangles), this operation may be very sluggish.  Be
  120.         patient, if you wait long enough I have found that eventually
  121.         Animation Master does what it is supposed to.
  122.  
  123. 6.        Since the objects created this way have lots of control points they
  124.         tend to render a little slower.  I have had some luck simplifying
  125.         the models by removing control points and extra lines.  Simple 
  126.         fonts like Arial are not too bad.  The complex fonts like Chili
  127.         Pepper contain an amazing number of points.  Try doing this first 
  128.         with Arial before you get extreme.
  129.  
  130. Below are the directions that came with the program I derived DXF2HSH from.
  131. They may help people with using Corel, but the predecessor program was
  132. designed to create a format used by POV, a public domain raytracer.  I 
  133. have experimented a lot with the tools I have and have not encountered 
  134. the problems he tries to solve in step 2 below.  I have imported both 'O'
  135. and '&' without any difficulties.  He talks about an extrude function which
  136. is disabled in my program because Animation Master's extrude feature is
  137. more useful.  The code for extruding is still included in the source if
  138. you are an ambitions C programmer and need this feature.  
  139.  
  140. If you have problems with a particular DXF file, I make no promises about
  141. fixing it or providing support.  Your best shot is to create the SIMPLEST
  142. DXF file that exhibits the problem, and email it to me at my internet 
  143. address vance@netcom.com along with a BRIEF description of the problem.  I
  144. will fix it if I have time.  Good luck!
  145.  
  146. -Vance Gloster
  147.  May 15, 1994
  148.  
  149. (Documentation for DXF2TRI)
  150. To keep things straight forward, here is how I put text in a scene (NOTE:
  151. I am assuming a reasonable knowledge of CorelDraw. This method should be
  152. possible with other Windows draw (NOT paint) programs such as Micrographix,
  153. Adobe Draw (Designer?) and others, none of which I have any experience with,
  154. assuming they have the following capabilities:
  155.         *        can export a DXF file
  156.         *        converts curves to line segments (POLYLINES)
  157. otherwise, you're out of luck):
  158.  
  159. 1.      Use Corel (4.0) to generate the initial text. Overall size and
  160.         position is not important since you will scale and position it later
  161.         on. Line properties (type, thickness or color) are irrelevant since
  162.         they will be ignored, as well as fill properties.
  163.  
  164. 2.      Dealing with holes: re-entrant (concave) portions of a letter appear
  165.         to convert with no problems (the m and & of the test image seem to
  166.         prove this). Holes are another matter. In the simplest view, they are
  167.         another object/curve. Since the objects will be converted to 2D
  168.         triangles, CSG cannot be used to subtract them from the main object.
  169.         The easiest solution I have found is to make all holes part of the
  170.         main object's outline. This is accomplished in two steps:
  171.         a.      Convert the letter from text to a curve. Do this after you
  172.                 have done all of the transformations you care to do on your
  173.                 text. You cannot convert from curves back to text (well you
  174.                 can, in a way, but font creation is beyond to scope of this
  175.                 babble).
  176.         b.      Using the node edit tool, cut a channel of zero width between
  177.                 the hole and the outside of the curve/letter. This can be done
  178.                 anywhere. As long as the sides of the channel touch, there will
  179.                 be no visible effect on the finished product. For example:
  180.                 Turn:                           into:
  181.                              ***                            ***
  182.                           ***   ***                      ***   ***
  183.                         **         **                  **         **
  184.                       **     ***     **              **     ***     **
  185.                      *     **   **     *            *     **   **     *
  186.                     *    **       **    *          *    **       **    *
  187.                     *   *           *   *          *   *           *   *
  188.                     *   *           *   *          *   *           *   *
  189.                     *   *           *   *          *   *           *   *
  190.                     *    **       **    *          *    **       **    *
  191.                      *     **   **     *            *     **   **     *
  192.                       **     ***     **              **     * *     **
  193.                         **         **                  **   * *   **
  194.                           ***   ***                      **** ****
  195.                              ***                            * *
  196.                                 These segements overlap --->| |<---
  197.  
  198.                 If you want to be artistic, you can cut the channels in
  199.                 obvious places, where a curve intersects a straight segment,
  200.                 for example. I broke the ampersand in the following places:
  201.  
  202.                         ***
  203.                        *   *
  204.                        *   *
  205.                         * \
  206.                         \*
  207.                        *  * *
  208.                       *    *
  209.                       *   * *
  210.                        * *   *
  211.  
  212.                 and then removed the unnecessary nodes on the straight line
  213.                 segments. This has the added effect of reducing the number of
  214.                 vertices of the polyline, as well as the number of triangles
  215.                 and the complexity of the final object.
  216.  
  217. 3.      Export the text as a DXF file. The Corel 4.0 DXF filter converts all
  218.         curves to line segments. It allows you to choose the number of line
  219.         segments a curve is converted to. I chose 32 (the minimum value) to
  220.         minimize the complexity of the object. There is no visible degradation
  221.         to the object when rendered at 1024x768 (and, I suspect, greater).
  222.         Individual letters may be exported to separate DXF files if you want
  223.         to texture them separately. The COREL-DXF-RAW-POV conversion chain
  224.         retains the relative position of each letter, but they become separate
  225.         objects and inter-letter spacing becomes a problem unless you first
  226.         combine them as a composite in the scene file before performing any
  227.         transformation. If you are going to texture the text uniformly, it
  228.         is easier to export the text to a single DXF file and treat it as a
  229.         single object.
  230.  
  231. 4.      Run DXF2TRI on the DXF file to generate a RAW file. If you want to
  232.         extrude the letters, use the -e switch. If the back of the letters will
  233.         be visible (due to reflections or camera position), use the -b switch
  234.         to generate solid backs to the letters.
  235.  
  236. 5.      Run RAW2POV on the RAW file. RAW2POV will generate a POV file giving
  237.         the physical limits of the object(s) and an INC file consisting of
  238.         triangles, smooth triangles and bounding shapes. The rest is up to you.
  239.  
  240. No, its not overly easy or straight forward, but it works well and the results
  241. aren't bad. Before anyone has a chance to ask or comment, no it won't bevel,
  242. but I am thinking of it. A straight bevel should be possible, but a curved
  243. (routed) bevel will take some doing, since CSG won't work with triangles. Don't
  244. let me stop anyone else from working on the problem, since I have a lot of
  245. other things to keep me busy.
  246.  
  247. I assume NO responsibility for this program or its effects, but if you need to
  248. contact me, for whatever reason, I check in occasionally to The Graphics
  249. Alternative and my Internet address is: triley@its.bldrdoc.gov.
  250.  
  251. Doo dah.