I recently got a color 3D printer that only accepts color
output from vrml files.

Attached is a patch for current CVS that does the following:

1) When a surface display is shown, it dumps the surface to a
VRML 2.0 file in /tmp/pymol.wrl

2) everytime the color scheme of the surface is changed, it
rewrites that wrl file.

I know this isn't a very elegant way to add a feature like this
(should have GUI elements, etc), but it was the quickest way
to get the job done for me, with my very limited knowledge of
the source code.

Here's some pics involving the demo file 1tii.pdb file, using
the "chainbow" coloring scheme:

http://bebop.cns.ualberta.ca/~cwant/pymol_wrl/pymol_1tii.jpg
http://bebop.cns.ualberta.ca/~cwant/pymol_wrl/pymol_1tii_print.jpg

Anyways, maybe somebody else will find the patch useful ...

Regards,
Chris


--
 ____________________________________________________________________
( Chris Want                                                         )
( Research Computing Support                                         )
( Academic Information and Communication Technologies (AICT)         )
( University of Alberta                                              )
( Tel: 1-780-492-9418                                                )
 --------------------------------------------------------------------
Index: layer2/RepSurface.c
===================================================================
RCS file: /cvsroot/pymol/pymol/layer2/RepSurface.c,v
retrieving revision 1.89
diff -u -p -r1.89 RepSurface.c
--- layer2/RepSurface.c 30 Dec 2005 18:40:29 -0000      1.89
+++ layer2/RepSurface.c 27 Jan 2006 18:30:10 -0000
@@ -966,6 +966,70 @@ int RepSurfaceSameVis(RepSurface *I,Coor
   return(same);
 }
 
+static void DumpWRL(char *filename, RepSurface *I) {
+  FILE *fpWRL;
+  float *x;
+  int a;
+
+  if ( (!I->V) || (!I->T) ) return;
+
+  fpWRL = fopen(filename, "wb");
+  fprintf(fpWRL, "#VRML V2.0\n" );
+
+  fprintf(fpWRL, "Transform {\n");
+  fprintf(fpWRL, "  translation 0.0 0.0 0.0\n");
+  fprintf(fpWRL, "  children [\n");
+  fprintf(fpWRL, "  Shape {\n");
+  fprintf(fpWRL, "    appearance Appearance {\n");
+  fprintf(fpWRL, "      material Material {\n");
+  fprintf(fpWRL, "        diffuseColor     1.0 1.0 1.0\n");
+  fprintf(fpWRL, "        ambientIntensity 0.0\n");
+  fprintf(fpWRL, "        specularColor    1.0 1.0 1.0\n");
+  fprintf(fpWRL, "        emissiveColor    0.0 0.0 0.0\n");
+  fprintf(fpWRL, "        shininess        0.0\n");
+  fprintf(fpWRL, "        transparency     0.0\n");
+  fprintf(fpWRL, "      }\n"); /* material */
+  fprintf(fpWRL, "    }\n");   /* appearance */
+  fprintf(fpWRL, "    geometry IndexedFaceSet {\n");
+  fprintf(fpWRL, "      solid TRUE\n");
+
+  fprintf(fpWRL, "      coord Coordinate {\n");
+  fprintf(fpWRL, "        point [\n");
+
+  for (a=0; a < I->N; ++a) {
+    x = I->V + 3*a;
+    fprintf(fpWRL, "%f %f %f,\n", x[0], x[1], x[2]);
+  }
+  fprintf(fpWRL, "        ]\n"); /* point */
+  fprintf(fpWRL, "      }\n");   /* coord */
+
+  fprintf(fpWRL, "      coordIndex [\n");
+  for (a=0; a < I->NT; ++a) {
+    fprintf(fpWRL, "%d %d %d -1,\n", I->T[3*a], I->T[3*a+1], I->T[3*a+2]);
+  }
+  fprintf(fpWRL, "      ]\n"); /* coordIndex */
+
+  if (I->VC) {
+    fprintf(fpWRL, "      colorPerVertex TRUE\n");
+    fprintf(fpWRL, "      color Color {\n");
+    fprintf(fpWRL, "        color [\n");
+    for (a=0; a < I->N; ++a) {
+      x = I->VC + 3*a;
+      fprintf(fpWRL, "%f %f %f,\n", x[0], x[1], x[2]);
+    }
+    fprintf(fpWRL, "        ]\n"); /* color */
+    fprintf(fpWRL, "      }\n"); /* color */
+  }
+
+  fprintf(fpWRL, "    }\n");   /* geometry */
+  fprintf(fpWRL, "  }\n");     /* shape */
+  fprintf(fpWRL, "  ]\n");     /* children */
+  fprintf(fpWRL, "}\n");       /* transform */
+
+  fclose(fpWRL);
+
+}
+
 void RepSurfaceColor(RepSurface *I,CoordSet *cs)
 {
   PyMOLGlobals *G=cs->State.G;
@@ -1259,6 +1323,7 @@ void RepSurfaceColor(RepSurface *I,Coord
       }
     }
   }
+  DumpWRL("/tmp/pymol.wrl", I);
   if(carve_map)
     MapFree(carve_map);
   VLAFreeP(carve_vla);
@@ -1931,6 +1996,7 @@ Rep *RepSurfaceNew(CoordSet *cs,int stat
         PRINTFB(G,FB_RepSurface,FB_Blather)
           " RepSurface: %i triangles.\n",I->NT
           ENDFB(G);
+          DumpWRL("/tmp/pymol.wrl", I);
       }
     } else {
       I->V = ReallocForSure(I->V,float,1);

Reply via email to