19 from ._ost_gfx
import *
20 from .py_gfx_obj
import PyGfxObj
23 WHITE=
RGB(1.0,1.0,1.0)
24 BLACK=
RGB(0.0,0.0,0.0)
27 DARKRED=
RGB(0.5,0.0,0.0)
28 LIGHTRED=
RGB(1.0,0.5,0.5)
29 GREEN=
RGB(0.0,1.0,0.0)
30 DARKGREEN=
RGB(0.0,0.5,0.0)
31 LIGHTGREEN=
RGB(0.5,1.0,0.5)
33 DARKBLUE=
RGB(0.0,0.0,0.5)
34 LIGHTBLUE=
RGB(0.5,0.5,1.0)
35 YELLOW=
RGB(1.0,1.0,0.0)
36 DARKYELLOW=
RGB(0.5,0.5,0.0)
37 LIGHTYELLOW=
RGB(1.0,1.0,0.5)
39 DARKCYAN=
RGB(0.0,0.5,0.5)
40 LIGHTCYAN=
RGB(0.5,1.0,1.0)
41 MAGENTA=
RGB(1.0,0.0,1.0)
42 DARKMAGENTA=
RGB(0.5,0.0,0.5)
43 LIGHTMAGENTA=
RGB(1.0,0.5,1.0)
45 DARKPURPLE=DARKMAGENTA
46 LIGHTPURPLE=LIGHTMAGENTA
47 ORANGE=
RGB(1.0,0.5,0.0)
48 DARKORANGE=
RGB(0.5,0.25,0.0)
49 LIGHTORANGE=
RGB(1.0,0.75,0.5)
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)
100 return (lhs[1] > rhs[1]) - (lhs[1] < rhs[1])
101 sorted_axes=sorted(zip(rows, lengths), key=functools.cmp_to_key(cmp_x))
102 return [r*l
for r,l
in sorted_axes]
104 if not isinstance(gfx_ent, Entity):
105 gfx_ent=scene[str(gfx_ent)]
106 width=width
and width
or scene.viewport.width
107 height=height
and height
or scene.viewport.height
108 atom_positions=
geom.Vec3List([atom.pos
for atom
in gfx_ent.view.atoms])
109 axes=atom_positions.principal_axes
110 sorted_axes=_XYZ(gfx_ent.view, axes)
127 rotation=
geom.Mat3(x_axes[0], x_axes[1], x_axes[2],
128 y_axes[0], y_axes[1], y_axes[2],
129 z_axes[0], z_axes[1], z_axes[2])
132 center=gfx_ent.center
133 aspect=float(width)/float(height)
134 factor_y=1.0/math.tan(math.radians(scene.fov))
135 factor_x=factor_y/aspect
142 rtc[3,2]=-(max(factor_x*(1+margin)*
geom.Length(sorted_axes[0]),
143 factor_y*(1+margin)*
geom.Length(sorted_axes[1]))+z_off)
154 yield getattr(node, self.
_name)
158 bound_method=getattr(node, self.
_name)
159 bound_method(*args, **kwargs)
166 if name.startswith(
'_'):
167 return super(GfxNodeListProxy, self).
__getattr__(name)
171 if name.startswith(
'_'):
172 super(GfxNodeListProxy, self).
__setattr__(name, value)
174 setattr(node, name, value)
176 def _Match(scene, pattern="*"):
179 def _Recurse(path, node, pattern):
181 for child
in node.children:
182 full_name=os.path.join(path, child.name)
183 if fnmatch.fnmatchcase(full_name, pattern):
184 matches.append(child)
185 matches.extend(_Recurse(full_name, child, pattern))
189 SceneSingleton.Match=_Match
193 if isinstance(p,ost.geom.Vec3):
197 return ost.geom.Vec3(p[0],p[1],p[2])
199 raise TypeError(
"expected either a sequence or a geom.Vec3 object")
202 def _primlist_add_point(self,pos,color=None):
206 self._add_point(pos,color)
208 def _primlist_add_line(self,pos1,pos2,color1=None,color2=None,color=None):
217 self._add_line(pos1,pos2,color1,color2)
219 def _primlist_add_sphere(self,cen,radius=1.0,color=None):
223 self._add_sphere(pos,radius,color)
225 def _primlist_add_cyl(self,pos1,pos2,radius1=None,radius2=None,radius=None,color1=None,color2=None,color=None,):
240 self._add_cyl(pos1,pos2,radius1,radius2,color1,color2)
242 def _primlist_add_text(self,text,pos,color=None,point_size=None):
248 self._add_text(text,pos,color,point_size)
250 PrimList.AddPoint=_primlist_add_point
251 PrimList.AddLine=_primlist_add_line
252 PrimList.AddSphere=_primlist_add_sphere
253 PrimList.AddCyl=_primlist_add_cyl
254 PrimList.AddText=_primlist_add_text
258 def _entity_reset(self,*args,**kwargs):
267 raise TypeError(
"Reset: more than one query string given")
271 raise TypeError(
"Reset: more than one entity handle given")
275 raise TypeError(
"Reset: more than one entity view given")
277 elif isinstance(a,str):
279 raise TypeError(
"Reset: more than one query string given")
281 elif isinstance(a,int):
283 raise TypeError(
"Reset: more than one QueryFlags given")
286 raise TypeError(
"Reset: unknown option of type '%s' given"%type(a))
288 for key,val
in kwargs.items():
291 raise TypeError(
"Reset: expected mol.EntityHandle for 'entity' option")
293 raise TypeError(
"Reset: more than one entity handle given")
297 raise TypeError(
"Reset: expected mol.EntityView for 'view' option")
299 raise TypeError(
"Reset: more than one entity view given")
304 elif isinstance(val,str):
307 raise TypeError(
"Reset: expected mol.Query or string for 'query' option")
309 raise TypeError(
"Reset: more than one query string given")
311 elif key==
"query_flags":
312 if not isinstance(val,int):
313 raise TypeError(
"Reset: expected integer for 'query_flags' option")
315 raise TypeError(
"Reset: more than one query flags given")
318 raise TypeError(
"Reset: unknown key '%s'"%key)
321 raise TypeError(
"Reset: entity and view are mutually exclusive options")
327 eh = self.query_view.entity
329 qr = self.query_view.query
331 qf = self.query_view.GetFlags()
332 self._reset3(eh,qr,qf)
334 Entity.Reset=_entity_reset
336 def _scene_export(self,*args,**kwargs):
338 scene.Export(Exporter)
339 scene.Export("file.png")
340 scene.Export("file.png",(width,height),samples=0,transparency=False)
342 scene.Export("file.png",width,height,samples=0,transparency=False)
343 scene.Export("file.png",width,height,transparency)
350 if "transparency" in kwargs:
351 tp=int(kwargs[
"transparency"])
352 if "samples" in kwargs:
353 sa=int(kwargs[
"samples"])
356 if isinstance(args[0],Exporter):
357 scene._export_via_exporter(args[0])
359 elif type(args[0])==type(
""):
360 scene._export_screen(args[0],tp)
363 if type(args[0]==type(
"")):
365 width=int(args[1][0])
366 height=int(args[1][1])
367 scene._export_buffer(args[0],width,height,sa,tp)
370 if type(args[0]==type(
"")):
373 scene._export_buffer(args[0],width,height,sa,tp)
376 if type(args[0]==type(
"")):
380 scene._export_buffer(args[0],width,height,sa,tp)
383 raise RuntimeError(
"""invalid arguments to scene.Export; expected one of
386 Export('file.png',(width,height),samples=0, transparency=False)
387 Export('file.png',width,height,samples=0, transparency=False) -> deprecated
388 Export('file.png',width,height,transparency) -> deprecated
391 SceneSingleton.Export=_scene_export
393 import __main__
as main_mod
394 main_mod.scene=
Scene()
395 main_mod.scene.Stereo=Stereo
397 import ost
as ost_mod
398 ost_mod.scene=
Scene()
399 ost_mod.scene.Stereo=Stereo
402 e=GostExporter_(file)
404 e.to_origin=to_origin
408 e=ColladaExporter_(file)
410 e.to_origin=to_origin
414 return go.IsVisible()
416 def _go_set_vis(go,flag):
422 GfxObj.visible=property(_go_get_vis,_go_set_vis)
main class for organization and root for the graphical display
Real Dot(const Vec4 &v1, const Vec4 &v2)
vector dot product
Color DLLEXPORT_OST_GFX RGB(float r, float g, float b)
RGB color spec from floats (0.0-1.0)
Vec3 Cross(const Vec3 &v1, const Vec3 &v2)
vector cross product
Vec4 Normalize(const Vec4 &v)
Real Length(const Vec4 &v)
returns length of vector