19 from _ost_gfx
import *
20 from py_gfx_obj
import PyGfxObj
22 WHITE=
RGB(1.0,1.0,1.0)
23 BLACK=
RGB(0.0,0.0,0.0)
26 DARKRED=
RGB(0.5,0.0,0.0)
27 LIGHTRED=
RGB(1.0,0.5,0.5)
28 GREEN=
RGB(0.0,1.0,0.0)
29 DARKGREEN=
RGB(0.0,0.5,0.0)
30 LIGHTGREEN=
RGB(0.5,1.0,0.5)
32 DARKBLUE=
RGB(0.0,0.0,0.5)
33 LIGHTBLUE=
RGB(0.5,0.5,1.0)
34 YELLOW=
RGB(1.0,1.0,0.0)
35 DARKYELLOW=
RGB(0.5,0.5,0.0)
36 LIGHTYELLOW=
RGB(1.0,1.0,0.5)
38 DARKCYAN=
RGB(0.0,0.5,0.5)
39 LIGHTCYAN=
RGB(0.5,1.0,1.0)
40 MAGENTA=
RGB(1.0,0.0,1.0)
41 DARKMAGENTA=
RGB(0.5,0.0,0.5)
42 LIGHTMAGENTA=
RGB(1.0,0.5,1.0)
44 DARKPURPLE=DARKMAGENTA
45 LIGHTPURPLE=LIGHTMAGENTA
46 ORANGE=
RGB(1.0,0.5,0.0)
47 DARKORANGE=
RGB(0.5,0.25,0.0)
48 LIGHTORANGE=
RGB(1.0,0.75,0.5)
54 :param mode: 0=off, 1=quad-buffered, 2=interlaced
56 :param flip: invert order of left/right display
58 :param alg: stereo algorithm (0 or 1)
62 Scene().SetStereoFlip(flip)
64 Scene().SetStereoAlg(alg)
66 Scene().SetStereoMode(mode)
68 def FitToScreen(gfx_ent, width=None, height=None, margin=0.05):
70 Setup camera such that it is centered on the graphical entity and the entity
71 fits the entire viewport. The longest axes of the entity are aligned along
72 the x- and y- axes of the screen.
74 :param gfx_ent: The graphical entity
75 :type gfx_ent: str or :class:`Entity`
83 returns the vectors in x, y and z direction respectively. The smallest
84 vector is in z, then y, and the largest along x.
86 rows=[axes.GetRow(i)
for i
in range(3)]
89 min_proj=
geom.Dot(axe, view.atoms[0].pos)
91 for atom
in view.atoms[1:]:
93 min_proj=min(proj, min_proj)
94 max_proj=max(proj, max_proj)
95 lengths.append(max_proj-min_proj)
97 return cmp(lhs[1], rhs[1])
98 sorted_axes=sorted(zip(rows, lengths), cmp_x)
99 return [r*l
for r,l
in sorted_axes]
101 if not isinstance(gfx_ent, Entity):
102 gfx_ent=scene[str(gfx_ent)]
103 width=width
and width
or scene.viewport.width
104 height=height
and height
or scene.viewport.height
105 atom_positions=
geom.Vec3List([atom.pos
for atom
in gfx_ent.view.atoms])
106 axes=atom_positions.principal_axes
107 sorted_axes=_XYZ(gfx_ent.view, axes)
124 rotation=
geom.Mat3(x_axes[0], x_axes[1], x_axes[2],
125 y_axes[0], y_axes[1], y_axes[2],
126 z_axes[0], z_axes[1], z_axes[2])
129 center=gfx_ent.center
130 aspect=float(width)/float(height)
131 factor_y=1.0/math.tan(math.radians(scene.fov))
132 factor_x=factor_y/aspect
139 rtc[3,2]=-(max(factor_x*(1+margin)*
geom.Length(sorted_axes[0]),
140 factor_y*(1+margin)*
geom.Length(sorted_axes[1]))+z_off)
151 yield getattr(node, self.
_name)
155 bound_method=getattr(node, self.
_name)
156 bound_method(*args, **kwargs)
163 if name.startswith(
'_'):
164 return super(GfxNodeListProxy, self).
__getattr__(name)
168 if name.startswith(
'_'):
169 super(GfxNodeListProxy, self).
__setattr__(name, value)
171 setattr(node, name, value)
173 def _Match(scene, pattern="*"):
176 def _Recurse(path, node, pattern):
178 for child
in node.children:
179 full_name=os.path.join(path, child.name)
180 if fnmatch.fnmatchcase(full_name, pattern):
181 matches.append(child)
182 matches.extend(_Recurse(full_name, child, pattern))
186 SceneSingleton.Match=_Match
190 if isinstance(p,ost.geom.Vec3):
194 return ost.geom.Vec3(p[0],p[1],p[2])
196 raise TypeError(
"expected either a sequence or a geom.Vec3 object")
199 def _primlist_add_point(self,pos,color=None):
203 self._add_point(pos,color)
205 def _primlist_add_line(self,pos1,pos2,color1=None,color2=None,color=None):
214 self._add_line(pos1,pos2,color1,color2)
216 def _primlist_add_sphere(self,cen,radius=1.0,color=None):
220 self._add_sphere(pos,radius,color)
222 def _primlist_add_cyl(self,pos1,pos2,radius1=None,radius2=None,radius=None,color1=None,color2=None,color=None,):
237 self._add_cyl(pos1,pos2,radius1,radius2,color1,color2)
239 def _primlist_add_text(self,text,pos,color=None,point_size=None):
245 self._add_text(text,pos,color,point_size)
247 PrimList.AddPoint=_primlist_add_point
248 PrimList.AddLine=_primlist_add_line
249 PrimList.AddSphere=_primlist_add_sphere
250 PrimList.AddCyl=_primlist_add_cyl
251 PrimList.AddText=_primlist_add_text
255 def _entity_reset(self,*args,**kwargs):
264 raise TypeError(
"Reset: more than one query string given")
268 raise TypeError(
"Reset: more than one entity handle given")
272 raise TypeError(
"Reset: more than one entity view given")
274 elif isinstance(a,str):
276 raise TypeError(
"Reset: more than one query string given")
278 elif isinstance(a,int):
280 raise TypeError(
"Reset: more than one QueryFlags given")
283 raise TypeError(
"Reset: unknown option of type '%s' given"%type(a))
285 for key,val
in kwargs.iteritems():
288 raise TypeError(
"Reset: expected mol.EntityHandle for 'entity' option")
290 raise TypeError(
"Reset: more than one entity handle given")
294 raise TypeError(
"Reset: expected mol.EntityView for 'view' option")
296 raise TypeError(
"Reset: more than one entity view given")
301 elif isinstance(val,str):
304 raise TypeError(
"Reset: expected mol.Query or string for 'query' option")
306 raise TypeError(
"Reset: more than one query string given")
308 elif key==
"query_flags":
309 if not isinstance(val,int):
310 raise TypeError(
"Reset: expected integer for 'query_flags' option")
312 raise TypeError(
"Reset: more than one query flags given")
315 raise TypeError(
"Reset: unknown key '%s'"%key)
318 raise TypeError(
"Reset: entity and view are mutually exclusive options")
324 eh = self.query_view.entity
326 qr = self.query_view.query
328 qf = self.query_view.GetFlags()
329 self._reset3(eh,qr,qf)
331 Entity.Reset=_entity_reset