schrodinger.graphics3d.common module¶
Utility functions for the graphics3d package.
The common module contains functions commonly used by the graphics3d modules. This includes the Group class, which is one clients use as a container for actual drawing primitive instances (like Arrow, etc.). See the Group class’ docstring for more details.
If you are adding new primtive modules, then you need do nothing other than conform to the list of required methods in your new primitive class:
_draw() (Code to draw out the primitive) _glSetup() (static, Configures the GL state for the specific primitive) _glReset() (static, Resets the GL state back to what it was prior to drawing)
This code will automatically keep track of and handle each instance that is added to a Group instance. For information on how to create a Group and add intances to the Group, see the class docstring for Group and the method docstring for Group’s add() method, respectively.
Copyright Schrodinger, LLC. All rights reserved.
-
schrodinger.graphics3d.common.
get_normalized
(v)¶ Calculate and return normalized vector.
- Arguments:
- v: List containing 3 floating values of x, y, z
- Returns:
- List of 3 floating values reprsenting the normalized vector.
-
schrodinger.graphics3d.common.
get_cross
(v, w)¶ Get the cross product of v and w
Return type: [float, floatg, float]
-
schrodinger.graphics3d.common.
create_normal
(vertices)¶ Method to create a normal for the polygon defined by specified vertices.
- Arguments:
- vertices: List of floating value lists of [x, y, z] representing
- a vertex.
- Returns:
- List of 3 floating values representing the normal
- FIXME: We use only the first three vertices to calculate the normal
- and currently ignore the rest. Other vertices won’t matter if all the vectors are in a plane, which is going to the be case most of the time.
-
schrodinger.graphics3d.common.
color_arg_to_rgb
(colorarg)¶ Returns a tuple of (r, g, b) [range 0.0-1.0 inclusive for each].
Arguments:
- colorarg: Can be one of the following types -
- Color: Color object instance string: Color name integer: Color index
-
class
schrodinger.graphics3d.common.
Primitive
(maestro_objects=[])¶ Bases:
object
All 3D objects derive from this class.
-
hide
()¶ Hide the object. It will not be drawn when the group is drawn.
-
show
()¶ Display this object, if it was hidden
-
groupHidden
()¶ Called when the group of this object is hidden. Hide the Maestro object(s).
-
groupShown
()¶ Called when the group of this object is shown. Show the Maestro object, if we are being shown.
-
isShown
()¶ Returns True if this object shown. False otherwise.
-
isGroupShown
()¶ Returns True if this object’s group is shown. False otherwise.
-
setEntryID
(entry_id)¶ Sets entry ID for Maestro object (necessary to render in tile-by-entry mode.
Parameters: entry_id (str) – Object’s entry ID.
-
setRightClickOnGObject
(pymodule, pyfunc)¶ Sets the python callback which should be called whenever given graphics object is right clicked.
Parameters: - pymodule (str) – Python module
- pyfunc (str) – Python function
-
setIsGlowing
(is_glowing)¶ Enables or disables glow effect for the object.
Parameters: is_glowing (bool) – Whether the object is glowing.
-
setGlowColor
(r, g, b)¶ Sets glow color for the object.
Parameters: - r (float) – Red component of glow color [0.0 .. 1.0]
- g (float) – Green component of glow color [0.0 .. 1.0]
- b (float) – Blue component of glow color [0.0 .. 1.0]
-
-
class
schrodinger.graphics3d.common.
Group
¶ Bases:
object
Class to group a bunch of primitives and draw them out.
Example for non-Maestro objects:
my_box1 = box.Box(…) my_box2 = box.Box(…) my_sphere = sphere.Sphere(…)
my_group = box.Group() (or sphere.Group(), etc) my_group.add(my_box1) my_group.add(my_box2) my_group.add(my_sphere)
# The following draw invocation would be in a separate # callback function registered with workspace_draw_function_add() my_group.draw()
-
getTotalTypes
()¶ Return the number of unique primitive types in this group. This differs from the standard length operation. That returns a count of all primitive instances.
-
draw
()¶ Invoke each item’s drawing method
The script should always call this method when the Workspace is drawn for every group it creates.
To hide the group so that it does not get drawn, use hide() method.
-
hide
()¶ Do not draw objects belonging to this group. Will also modify Maestro’s bounding rect to exclude these objects.
-
show
()¶ Cancel effect of hide() method, and draw the objects belonging to this group. Will modify Maestro’s bounding rect to exclude these objects.
-
isShown
()¶ Returns True if this group is shown; False otherwise.
-
add
(item)¶ Add a drawing primitive instance (Box, etc.) to this group.
-
remove
(item)¶ Remove a drawing primitive instance (Box, etc.) from this group.
-
clear
(item_type=None)¶ Clear up drawing instances.
Parameters: item_type – Can be one of the following: None, Arrow, Box, etc. Note:
- If item_type is None, all drawing instances will be removed; if
item_type is not None, all drawing instances of the
item_type
class will be removed. - No effects if there is no drawing instances of the
item_type
class.
- If item_type is None, all drawing instances will be removed; if
item_type is not None, all drawing instances of the
-
boundingBoxCallback
(r00, r01, r02, r03, r10, r11, r12, r13, r20, r21, r22, r23, r30, r31, r32, r33)¶ Called when the workspace is fit to screen
-
allPrimitives
()¶ Iterate through all the objects in this group and yield primitives.
-