19 from _ost_gfx
import *
20 from py_gfx_obj
import PyGfxObj
44 DARKPURPLE=DARKMAGENTA
45 LIGHTPURPLE=LIGHTMAGENTA
55 :param mode: 0=off, 1=quad-buffered, 2=interlaced
57 :param flip: invert order of left/right display
59 :param alg: stereo algorithm (0 or 1)
63 Scene().SetStereoFlip(flip)
65 Scene().SetStereoAlg(alg)
67 Scene().SetStereoMode(mode)
69 def FitToScreen(gfx_ent, width=None, height=None, margin=0.05):
71 Setup camera such that it is centered on the graphical entity and the entity
72 fits the entire viewport. The longest axes of the entity are aligned along
73 the x- and y- axes of the screen.
75 :param gfx_ent: The graphical entity
76 :type gfx_ent: str or :class:`Entity`
84 returns the vectors in x, y and z direction respectively. The smallest
85 vector is in z, then y, and the largest along x.
87 rows=[axes.GetRow(i)
for i
in range(3)]
90 min_proj=
geom.Dot(axe, view.atoms[0].pos)
92 for atom
in view.atoms[1:]:
94 min_proj=min(proj, min_proj)
95 max_proj=max(proj, max_proj)
96 lengths.append(max_proj-min_proj)
98 return cmp(lhs[1], rhs[1])
99 sorted_axes=sorted(zip(rows, lengths), cmp_x)
100 return [r*l
for r,l
in sorted_axes]
102 if not isinstance(gfx_ent, Entity):
103 gfx_ent=scene[str(gfx_ent)]
104 width=width
and width
or scene.viewport.width
105 height=height
and height
or scene.viewport.height
106 atom_positions=
geom.Vec3List([atom.pos
for atom
in gfx_ent.view.atoms])
107 axes=atom_positions.principal_axes
108 sorted_axes=_XYZ(gfx_ent.view, axes)
125 rotation=
geom.Mat3(x_axes[0], x_axes[1], x_axes[2],
126 y_axes[0], y_axes[1], y_axes[2],
127 z_axes[0], z_axes[1], z_axes[2])
130 center=gfx_ent.center
131 aspect=float(width)/float(height)
132 factor_y=1.0/math.tan(math.radians(scene.fov))
133 factor_x=factor_y/aspect
140 rtc[3,2]=-(max(factor_x*(1+margin)*
geom.Length(sorted_axes[0]),
141 factor_y*(1+margin)*
geom.Length(sorted_axes[1]))+z_off)
152 yield getattr(node, self.
_name)
156 bound_method=getattr(node, self.
_name)
157 bound_method(*args, **kwargs)
164 if name.startswith(
'_'):
165 return super(GfxNodeListProxy, self).
__getattr__(name)
169 if name.startswith(
'_'):
170 super(GfxNodeListProxy, self).
__setattr__(name, value)
172 setattr(node, name, value)
174 def _Match(scene, pattern="*"):
177 def _Recurse(path, node, pattern):
179 for child
in node.children:
180 full_name=os.path.join(path, child.name)
181 if fnmatch.fnmatchcase(full_name, pattern):
182 matches.append(child)
183 matches.extend(_Recurse(full_name, child, pattern))
187 SceneSingleton.Match=_Match
191 if isinstance(p,ost.geom.Vec3):
195 return ost.geom.Vec3(p[0],p[1],p[2])
197 raise TypeError(
"expected either a sequence or a geom.Vec3 object")
200 def _primlist_add_point(self,pos,color=None):
204 self._add_point(pos,color)
206 def _primlist_add_line(self,pos1,pos2,color1=None,color2=None,color=None):
215 self._add_line(pos1,pos2,color1,color2)
217 def _primlist_add_sphere(self,cen,radius=1.0,color=None):
221 self._add_sphere(pos,radius,color)
223 def _primlist_add_cyl(self,pos1,pos2,radius1=None,radius2=None,radius=None,color1=None,color2=None,color=None,):
238 self._add_cyl(pos1,pos2,radius1,radius2,color1,color2)
240 def _primlist_add_text(self,text,pos,color=None,point_size=None):
246 self._add_text(text,pos,color,point_size)
248 PrimList.AddPoint=_primlist_add_point
249 PrimList.AddLine=_primlist_add_line
250 PrimList.AddSphere=_primlist_add_sphere
251 PrimList.AddCyl=_primlist_add_cyl
252 PrimList.AddText=_primlist_add_text
256 def _entity_reset(self,*args,**kwargs):
265 raise TypeError(
"Reset: more than one query string given")
269 raise TypeError(
"Reset: more than one entity handle given")
273 raise TypeError(
"Reset: more than one entity view given")
275 elif isinstance(a,str):
277 raise TypeError(
"Reset: more than one query string given")
279 elif isinstance(a,int):
281 raise TypeError(
"Reset: more than one QueryFlags given")
284 raise TypeError(
"Reset: unknown option of type '%s' given"%type(a))
286 for key,val
in kwargs.iteritems():
289 raise TypeError(
"Reset: expected mol.EntityHandle for 'entity' option")
291 raise TypeError(
"Reset: more than one entity handle given")
295 raise TypeError(
"Reset: expected mol.EntityView for 'view' option")
297 raise TypeError(
"Reset: more than one entity view given")
302 elif isinstance(val,str):
305 raise TypeError(
"Reset: expected mol.Query or string for 'query' option")
307 raise TypeError(
"Reset: more than one query string given")
309 elif key==
"query_flags":
310 if not isinstance(val,int):
311 raise TypeError(
"Reset: expected integer for 'query_flags' option")
313 raise TypeError(
"Reset: more than one query flags given")
316 raise TypeError(
"Reset: unknown key '%s'"%key)
319 raise TypeError(
"Reset: entity and view are mutually exclusive options")
325 eh = self.query_view.entity
327 qr = self.query_view.query
329 qf = self.query_view.GetFlags()
330 self._reset3(eh,qr,qf)
332 Entity.Reset=_entity_reset