home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Raytrace & Morphing / SOS-RAYTRACE.ISO / programm / utility / dos / cchem03 / readme.doc < prev    next >
Encoding:
Text File  |  1992-10-14  |  17.2 KB  |  388 lines

  1.  
  2.                            C I N E C H E M
  3.     Molecular Rendering and Animation with HyperChem and 3D Studio
  4.  
  5.                              --- with ---
  6.  
  7.                            S T I N G R A Y
  8.                           Stingy Ray Tracer
  9.  
  10.                           Distribution Notes
  11.                   Release 0.3  --  13th October 1992
  12.  
  13.  
  14. CONTENTS OF THE DISTRIBUTION
  15. ============================
  16.  
  17. When you copy the CINECHEM release disc or unpack the ZIPped archive,
  18. you should find the following files:
  19.  
  20.   Cinechem:
  21.     CINECHEM.EXE    CINECHEM 386 DOS Extender executable
  22.     CINECHEM.DOC    CINECHEM user documentation
  23.  
  24.   Sample input files:
  25.     C60.HIN         Sample molecule for still rendering (Buckminsterfullerine)
  26.     PADAM.HIN       Sample molecule for animation (Adamantine)
  27.     PADAM.SNP       Sample snapshot file for animation
  28.     GAUDY.CFG       Sample configuration file
  29.  
  30.   StingRay:
  31.     STINGRAY.EXE    STINGRAY 386 DOS Extender executable
  32.     NFF.DOC         SringRay input file format documentation
  33.  
  34.   Piclab:
  35.     PICLAB.ZIP      PICLAB public domain image processor archive
  36.  
  37.   And last but not least:
  38.     README.DOC      This document
  39.  
  40.  
  41. SAMPLE MOLECULE AND ANIMATION
  42. =============================
  43.  
  44. In case you don't have a copy of HyperChem but would still like to try
  45. CINECHEM,  I've included two ready to render sample molecules: one for
  46. a still rendering and the other an animation.
  47.  
  48. To demonstrate still rendering, try:
  49.  
  50.     CINECHEM C60
  51.  
  52. This  will  create  C60.3DS,  a  3D  Studio  model  of  the ubiquitous
  53. Buckminsterfullerine molecule.  Try loading this model into 3D  Studio
  54. and  rendering  it  in  various  ways.   This  is  a  "space  filling"
  55. representation of the molecule; for a "stick and ball" rendering, try:
  56.  
  57.     CINECHEM -S C60
  58.  
  59. Next, try an creating an animation from the sample molecular  dynamics
  60. simulation   included.   This  is  a  totally  physically  unrealistic
  61. simulation of the relaxation of a molecule of adamantine (which can be
  62. thought of as the smallest possible diamond), when one of the bonds to
  63. a surface hydrogen has been stretched  by  Kelvin's  Atomic  Tweezers.
  64. The  HyperChem-generated snapshots of the simulation are stored in the
  65. files PADAM.HIN and PADAM.SNP.  Create the animation from these  files
  66. with the command:
  67.  
  68.     CINECHEM -S PADAM
  69.  
  70. Molecular dynamics simulations generally look better when rendered  as
  71. stick  and  ball  models.   Load  the resulting PADAM.3DS file into 3D
  72. Studio, move to the Keyframer, convert one of  the  viewports  into  a
  73. Camera  viewport by clicking it then pressing "C" on the keyboard, and
  74. try moving the frame number slider along the  bottom  of  the  screen.
  75. Neat, huh?  Finally, go ahead and make an animation of the simulation,
  76. if you like.
  77.  
  78. Each atom in a snapshot animation (and  in  a  simple  model,  if  you
  79. specify the "-K" option when you call CINECHEM) is made a child object
  80. to a dummy Keyframer object representing  the  molecule.   Thus,  it's
  81. very  easy  to  manually  animate  the  components  of  multi-molecule
  82. systems, for example to detach a molecule from  its  binding  site  on
  83. another for an "exploded view" of the site.
  84.  
  85.  
  86. DEVELOPMENT LOG
  87. ===============
  88.  
  89. Changes in CINECHEM 0.3
  90. -----------------------
  91.  
  92. Major  code  cleanup  and  ANSI-compilance  fixes  all  over StingRay.
  93. StingRay now builds without warnings and runs  correctly  on  the  Sun
  94. SPARCStation,  including the ability to create Microsoft .BMP files in
  95. the correct (Intel) byte order.  Building StingRay on the Sun requires
  96. ACC.
  97.  
  98. When generating a StingRay format (.NFF) output file, I added comments
  99. to the "f" (material properties) statements which identify each atom's
  100. element  type by chemical symbol and each bond by the bond letter code
  101. followed by a "-B" ("S-B" for single  bond,  "D-B"  for  double  bond,
  102. "T-B" for triple bond, and "A-B" for aromatic bond).  StingRay's input
  103. language lacks the nice macro facilties we exploit in 3D Studio  (when
  104. the "-M" option is specified) and in POV to permit easy after-the-fact
  105. experimentation with different  material  types.   But,  by  including
  106. these  guaranteed-unique  comment  strings  in the .NFF file, a clever
  107. user can use a text editor or a utility like AWK to scan the file  and
  108. selectively  replace  the  material  property  definitions for a given
  109. element and/or bond type.
  110.  
  111. I  modified  StingRay so that when it's generating either a Targa or a
  112. Microsoft BMP file, it always writes the complete pixel  area  of  the
  113. file  at  the start, filling it with grey pixels, then returns to fill
  114. in the actual pixels as they are calculated.  This  has  two  salutary
  115. benefits.  First of all, if there isn't enough disc space to write the
  116. output image file, it's a lot better to discover  this  right  at  the
  117. outset  instead  of 60 hours into a ray-trace; writing the file at the
  118. beginning guarantees that space  is  reserved  for  it  on  the  disc.
  119. Second,  taking  advantage  of  the fact that we don't compress either
  120. form of file, partially completed files are 100% valid throughout  the
  121. process  of  generation.   This  permits the user with a multi-tasking
  122. system to "vulch" on the process of ray-tracing: view the file, as  it
  123. is  being created, with any .TGA or .BMP display program.  This allows
  124. "quick looks" at  the  file  which  can  on  occasion  avert  tragedy.
  125. Second,  if  something  terrible  happens and the trace is aborted, at
  126. least the portion completed will remain on the disc in viewable form.
  127.  
  128. There was bug in StingRay's .BMP file output which caused the image to
  129. be shifted up one pixel, with the bottom pixel row left black.  Fixed.
  130.  
  131. Viewpoint  calculation  for  RenderMan was *still* screwed up--in some
  132. cases the camera roll angle had the wrong sign.   (Do  these  renderer
  133. makers  make  up  such  weird ways of specifying the viewing transform
  134. just to give their users fits?  No two renderers I know of  share  the
  135. same  kind  of  projection  and  viewpoint specifications!).  Fixed (I
  136. think).
  137.  
  138. I added a new "-K" switch to CINECHEM which forces keyframe data to be
  139. created even if the input is a static model  (.HIN-only)  file  rather
  140. than  a snapshot (.HIN/.SNP pair).  This option affects only 3D Studio
  141. output.  By creating the keyframe  data  for  a  void  animation,  the
  142. hierarchy  of  atoms  and bonds to molecules can be established.  This
  143. allows easy after-the-fact animations  to  be  created  by  specifying
  144. keyframe  data for the various molecules.  For example, you might show
  145. a molecule bound to the active site of a receptor molecule, then  move
  146. it outward for a close-up of the binding site.
  147.  
  148. I  took  a  run  at  CINECHEM  with  SMARTALLOC  and  MALLOC_DEBUG and
  149. discovered that when the "-K" option was specified, OUT3DS was freeing
  150. three  buffers  it  never  allocated  (plus  closing  a  file it never
  151. opened), and that PURGESYS forgot to release molecule  names  and  the
  152. header for the entire system.  All fixed.
  153.  
  154. Still  more  fixes  to  viewpoints  and  keyframer information for 3DS
  155. format, both to logic in  CINECHEM  and  to  correct  bugs  in  3DSLIB
  156. itself.   CINECHEM  was  calculating  the  relationship  between "lens
  157. length" and camera field of view (needed because 3D Studio can't  make
  158. up  its  mind  which  format it prefers; lens length is used in the 3D
  159. Editor, but field of view is specified in the Keyframer) by performing
  160. the   correct   geometrical  calculation  as  described  in  the  book
  161. "RenderMan Companion".  Unfortunately, 3D Studio uses a totally  bogus
  162. linear  interpolation  of this highly nonlinear (tangent) function, so
  163. the accurate numbers I was generating didn't agree with those used  in
  164. 3DS.  I converted my code to call the  new  3DSLIB  routine  FOVToLens
  165. (note  that  the function is *not* called FOVToLens_3ds, as documented
  166. to be on page 28 of the 3DSLIB manual), which reproduces the erroneous
  167. values used in 3D Studio.
  168.  
  169. The  very  confusion in 3DS about whether it's lens length or field of
  170. view tripped up the camera motion specification function in the 3DSLIB
  171. module  CAMM_3DS.C.  When it was creating the initial (frame 0) motion
  172. key for the camera, it retrieved the lens  length  from  the  camera's
  173. record  for  the 3D Editor and jammed it into a cell that was supposed
  174. to be a field of view.  You have to add the code:
  175.  
  176.     /* ***FIX***  Translate camera "lens length" into field of view as
  177.                   used in the keyframer. */
  178.    {    double dstfov;
  179.         LensToFOV(*stfov, &dstfov);
  180.         *stfov = dstfov;
  181.    }
  182.  
  183. right before the return from the  internal  function  InitCamState  to
  184. correct  this.   Note that LensToFOV() returns its result in a double,
  185. unlike FOVToLens() which expects  a  pointer  to  a  float.   Is  this
  186. obscure or what?
  187.  
  188. The dummy objects  I  created  to  link  the  atoms  to  their  parent
  189. molecules weren't being treated as dummy objects.  Turns out DUMMYNAME
  190. in  3DS.H  was defined as "$$DUMMY" instead of "$$$DUMMY" as 3D Studio
  191. expects.   This  is  also documented incorrectly on pages 36 and 43 of
  192. the 3DSLIB manual in the descriptions of the  header  definitions  and
  193. the  KF_MESH  structure, but is correctly given on page 75 of the same
  194. manual in the documentation of the NODE_HDR chunk.
  195.  
  196. When animating a snapshot, the "active segment" in  the  Keyframer  is
  197. set  to run from frame 1 through the number of snapshots.  This avoids
  198. the user's seeing the weird basic geometry of the bonds  in  frame  0.
  199. But  when creating a keyframe hierarchy for manual animation (with the
  200. -K switch), we want the segment to start  at  frame  0  so  the  basic
  201. geometry  is accessible.  I added a special case for that, and set the
  202. initial animation length to 30 frames, just as 3D Studio assumes.
  203.  
  204. Note that the SetCurrent_3ds() and SetSegment_3ds() functions are both
  205. incorrectly  documented  on page 32 of the 3DSLIB manual; to reproduce
  206. the default animation created by 3D Studio from a model, you  have  to
  207. start  both  the  segment  and set the current frame number to 0.  The
  208. manual says the range of valid frame numbers is 1-32000, but  in  fact
  209. the functions correctly accept frame number 0.
  210.  
  211. As   soon  as  I  implemented  the  object  hierarchy  for  molecules,
  212. everything went totally weird, and it took me the  better  part  of  a
  213. week  to chase down the 3DSLIB bug that was causing it.  The author of
  214. 3DSLIB was tripped up by  some  additional  bizarre  behaviour  in  3D
  215. Studio.   When  you're  creating  the keyframer data for a mesh object
  216. with ObjectMotion_3ds(), an initial rotation key must be generated for
  217. frame  0  (regardless of whether you've specified any rotation keys of
  218. your own).  The code that created this key, in OBJM_3DS.C, was:
  219.  
  220.     strot.angle = PI * 0.5;
  221.     strot.x = 1.0;
  222.     strot.y = 0.0;
  223.     strot.z = 0.0;
  224.  
  225. Now that looks pretty weird to start with, 'cause on page  77  of  the
  226. 3DSLIB   manual,  the  angle  field  of  the  ROT_TRACK_TAG  chunk  is
  227. documented as being "Rotation angle in degrees".  Okay, so  I  changed
  228. the  PI * 0.5 to 90.  Things got *much* worse.  After a lengthy period
  229. of cybernetic psychoanalysis, I finally established that  the  correct
  230. code to set the angle should be the following:
  231.  
  232.     strot.angle = (strcmp(obj->name, DUMMYNAME) == 0) ?  0 : (PI / 2);
  233.  
  234. Why  is the initial rotation of objects imported from the 3D Editor 90
  235. degrees  (in  radians,  of course), but zero for dummy objects?  Beats
  236. the shit out of me, but go and make some of your own in 3D Studio  and
  237. look  at  the  Key  data  it generates for them.  That's how I finally
  238. figured it out.
  239.  
  240. Note also that the documentation of the KF_ROT structure on page 43 of
  241. the  3DSLIB  manual  (which  is  what we're talking about initialising
  242. above) doesn't mention whether the rotation angle should be  specified
  243. in  degrees  or  radians.  It's degrees, notwithstanding the fact that
  244. the internal database stores it in radians, notwithstanding  the  fact
  245. that page 77 documents it as degrees.
  246.  
  247. As I mentioned in the notes for  CINECHEM  0.2,  I  defy  anybody  who
  248. attempts  to  use  3DSLIB to generate non-trivial camera placements or
  249. camera motion without having access to the following code:
  250.  
  251.  
  252.     /*  CAMUPVECTOR  --  Calculate camera up vector used by 3D  Studio
  253.                          given camera location, target point, and bank
  254.                          angle.  This  code  kindly  provided  by  Dan
  255.                          Silva, (dsilva@Autodesk.com).  */
  256.  
  257.     static void CamUpVector(
  258.                             point cam,        /* camera position */
  259.                             point targ,       /* target position */
  260.                             double bnkang,    /* bank angle (radians) */
  261.                             point up          /* output: up vector */
  262.     ) {
  263.         double x, y, z, A, B, C, cA, cB, cC, sA, sB, sC;
  264.  
  265.         x = targ[X] - cam[X];
  266.         y = targ[Y] - cam[Y];
  267.         z = targ[Z] - cam[Z];
  268.  
  269.         if (y == 0 && x == 0) {
  270.             /* Camera is pointed directly along the Z axis. */
  271.             A = 0;
  272.         } else {
  273.             A = atan2(y, x);                /* yaw */
  274.         }
  275.         B = atan2(-z, sqrt(x * x + y * y)); /* pitch */
  276.         C = bnkang;                         /* roll */
  277.         cA = cos(A); sA = sin(A);
  278.         cB = cos(B); sB = sin(B);
  279.         cC = cos(C); sC = sin(C);
  280.      
  281.         /* Then the Up vector is (let's hope) */
  282.  
  283.         up[X] = cC * sB *cA + sC * sA;
  284.         up[Y] = cC * sB *sA - sC * cA;
  285.         up[Z] = cB * cC;
  286.     }
  287.  
  288. This  code,  accompanied  by a thorough tutorial-style introduction in
  289. how to use it in the manual, absolutely belongs  as  part  of  3DSLIB.
  290. Without it, application developers will simply give up and require the
  291. user  to  place  the camera himself in 3DS, or else one by one request
  292. this algorithm from Autodesk.  This is the  3D  Studio  equivalent  of
  293. AutoCAD's  "arbaxis"  algorithm,  and  you  simply have to know how it
  294. works to get your code right.
  295.  
  296. Any  while  we're  at  it,  campers,  here's  the  code  that  turns a
  297. rationally specified camera (in terms of  camera  and  target  points,
  298. plus  normalised  world-space  camera  up  and right vectors) into the
  299. weird stuff that 3D Studio expects, using the function above.
  300.  
  301.     Given:
  302.         point camera, target, up, right; /* All 3-vectors of doubles */
  303.  
  304.     Then proceed as follows:
  305.         double xzlen, yrot, eyr, a, zrot, fa, fb;
  306.         point p, eax, cup, cx;
  307.         DPOINT p1, p2;
  308.  
  309.         Cpoint(p1, camera);               /* Copy doubles to floats for 3DS */
  310.         Cpoint(p2, target);
  311.  
  312.         vecsub(p, target, camera);
  313.         vecnorm(p, p);
  314.  
  315.         /* Calculate rotation about the Y axis to turn the Z
  316.            axis (camera view direction) to the proper azimuth
  317.            in the X-Z plane. */
  318.  
  319.         xzlen = sqrt(p[X] * p[X] + p[Z] * p[Z]);
  320.         if (xzlen == 0.0) {
  321.             yrot = (p[Y] < 0) ? 180.0 : 0.0;
  322.         } else {
  323.             yrot = todeg(acos(p[Z] / xzlen));
  324.         }
  325.  
  326.         /* Calculate rotation about Z axis to align the X axis of
  327.            the co-ordinate system (still in the X-Z plane)
  328.            with the "right" vector of the camera. */
  329.  
  330.         eyr = p[X] > 0 ? -yrot : yrot;
  331.         Spoint(eax, cos(torad(eyr)), 0, sin(torad(eyr)));
  332.         a = vecdot(eax, right);
  333.         zrot = todeg(acos(a));
  334.         if ((p[X] * right[X]) < 0) {
  335.             zrot = -zrot;
  336.         }
  337.         CamUpVector(camera, target, 0.0, cup);
  338.         veccross(cx, cup, up);
  339.         fa = vecmag(cx);
  340.         fb = todeg(asin(fa));
  341.         twist = fb * ((cx[Z] * p[Z]) > 0 ? 1 : -1);
  342.         AddCamera_3ds("Camera1", p1, p2, twist, lens, TRUE);
  343.  
  344. SMARTALLOC  revealed  that INIT_3DS.C is allocating a temporary buffer
  345. for the file name but not bothering to  release  it.   In  INIT_3DS.C,
  346. change the file open code to:
  347.  
  348.     mainfp = fopen( cp, "w+b" );
  349.     free(cp);
  350.     if (mainfp == NULL)
  351.         return FAIL_3DS;
  352.  
  353.  
  354. Changes in CINECHEM 0.2
  355. -----------------------
  356.  
  357. The  definitions  of the GOLD and COPPER material types for triple and
  358. aromatic bonds when the "-M" option was specified were  incorrect  and
  359. unaesthetic.   I  fixed  them  to  correspond  closely to the GOLD and
  360. COPPER  material  definitions  in  the  3D  Studio  standard  material
  361. library.
  362.  
  363. CINECHEM  got  all shook up if the generation of atoms were suppressed
  364. while generating an animation (for example, you turn off hydrogens  or
  365. water  molecules  for  a  less  cluttered  animation of a simulation).
  366. Fixed.
  367.  
  368. Support  was  added  for  the  following  new  output file formats and
  369. renderers:
  370.  
  371.         NFF     StingRay
  372.         RIB     Autodesk RenderMan
  373.         POV     Persistence of Vision Raytracer
  374.  
  375. StingRay is now included in the CINECHEM distribution.
  376.  
  377. Since  the  DOS Extender version now works in the Windows DOS box, any
  378. system which can run HyperChem should be able to execute CINECHEM  and
  379. StingRay in a DOS window.  Consequently, the real-mode DOS versions of
  380. these programs have been discontinued.  Note that thanks to the gentle
  381. ministrations  of  DPMI, you can run CINECHEM from the DOS shell of 3D
  382. Studio.
  383.  
  384. Thanks  to  Dan  Silva,  who  gave  me the code that 3D Studio uses to
  385. calculate the default camera up vector, correct twist angles  are  now
  386. generated  based  on  the viewing transform found in the .HIN file (at
  387. least for all the cases I've tried!).
  388.