[chimera-dev] patch to bld2vrml for .transparency

David A. C. Beck dacb at u.washington.edu
Tue Dec 9 09:12:07 PST 2008


I've been doing a lot of analysis rendering over proteins in Chimera 
lately.  Bild (via VRML) has worked quite well for this.  I wanted the 
ability to specify a transparency value (from 0 to 1) for the shape 
objects (boxes, arrows, etc.).  The attached patch 'bld2vrml.diff' adds a 
.transparency 'command' to the bild format that sets the 'transparency' 
attribute on subsequent objects' 'Material' element in the generated 
VRML.  A sample input file 'test.bild' (see below) and image 'test.png' 
are also attached.

Example input below:
.color green
.transparency 0.0
.box 5 5 5 10 10 10
.transparency 0.25
.box 0 0 0 5 5 5
.transparency 0.5
.box -5 -5 -5 0 0 0
.transparency 0.75
.box -5 -5 -5 -10 -10 -10
.transparency 0.9
.box -10 -10 -10 -15 -15 -15

--
David A. C. Beck, Ph.D.
dacb at u.washington.edu
Valerie Daggett Laboratory
University of Washington, Seattle
-------------- next part --------------
diff -ur chimera.1.2540/share/Bld2VRML/bld2vrml.py chimera/share/Bld2VRML/bld2vrml.py
--- chimera.1.2540/share/Bld2VRML/bld2vrml.py	2008-12-09 09:01:01.000000000 -0800
+++ chimera/share/Bld2VRML/bld2vrml.py	2008-12-09 09:01:42.000000000 -0800
@@ -67,6 +67,7 @@
 		self.geomObjs = []
 		self.polyObjs = []
 		self.color = (1.0, 1.0, 1.0)
+		self.transparency = 0
 		self.tCoords = (0, 0, 0)
 		self.fontSize = 5
 		self.fontStyle = "PLAIN"
@@ -107,6 +108,12 @@
 			if color:
 				color = tuple(map(float, color))
 				self.color = color
+		elif line[0] == "transparency":
+			try:
+				transparency = float(line[1])
+			except:
+				transparency = 0
+			self.transparency = transparency
 		elif line[0] == "box":
 			obj = Object(shape = "box")
 			p1 = (float(line[1]), float(line[2]), float(line[3]))
@@ -116,6 +123,7 @@
 			obj.height = p2[1] - p1[1]
 			obj.depth = p2[2] - p1[2]
 			obj.color = self.color
+			obj.transparency = self.transparency
 			obj.transforms = self.transformStack[:]
 			obj.transforms.append(Object(to=pCentre, form='translate'))
 			self.geomObjs.append(obj)
@@ -129,6 +137,7 @@
 			if len(line) < 9: obj.closed = True
 			elif lower(line[8]) == "open": obj.closed = False
 			obj.color = self.color
+			obj.transparency = self.transparency
 			obj.transforms = self.transformStack[:]
 			fTheta = asin( (p2[2] - p1[2]) / obj.height )
 			try:
@@ -149,6 +158,7 @@
 			if len(line) < 9: obj.closed = True
 			elif lower(line[8]) == "open": obj.closed = False
 			obj.color = self.color
+			obj.transparency = self.transparency
 			obj.transforms = self.transformStack[:]
 			fTheta = asin( (p2[2] - p1[2]) / obj.height )
 			try:
@@ -221,6 +231,7 @@
 				z = float(line[i + 2])
 				obj.vertices.append( (x, y, z) )
 			obj.color = self.color
+			obj.transparency = self.transparency
 			obj.transforms = self.transformStack[:]
 			self.polyObjs.append(obj)
 		elif line[0] == "pop":
@@ -245,12 +256,14 @@
 			pCentre = (float(line[1]), float(line[2]), float(line[3]))
 			obj.radius = float(line[4])
 			obj.color = self.color
+			obj.transparency = self.transparency
 			obj.transforms = self.transformStack[:]
 			obj.transforms.append(Object(to=pCentre, form='translate'))
 			self.geomObjs.append(obj)
 		elif line[0] == "text":
 			obj = Object(shape = "text")
 			obj.color = self.color
+			obj.transparency = self.transparency
 			obj.string = join(line[1:])
 			obj.fontSize = self.fontSize
 			obj.fontStyle = self.fontStyle
@@ -361,6 +374,7 @@
 			o <  "appearance Appearance {"
 			o <   "material Material {"
 			o <    "diffuseColor %f %f %f" % obj.color
+			o <    "transparency %f" % obj.transparency
 			o <   "}"
 			o <  "}"
 
-------------- next part --------------
.color green
.transparency 0.0
.box 5 5 5 10 10 10
.transparency 0.25
.box 0 0 0 5 5 5
.transparency 0.5
.box -5 -5 -5 0 0 0
.transparency 0.75
.box -5 -5 -5 -10 -10 -10 
.transparency 0.9
.box -10 -10 -10 -15 -15 -15
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.png
Type: image/png
Size: 7152 bytes
Desc: 
URL: <http://plato.cgl.ucsf.edu/pipermail/chimera-dev/attachments/20081209/4ad1e256/attachment.png>


More information about the Chimera-dev mailing list