GSoC 2025 - Week 7
I made the following progress this week:
- PR #903 (merged)
- Open PR from last week
- Fixed a couple of bugs: drawing 2d text using normalized viewport coords, overwritten function signatures of the dynamic annotation add methods
- PR #905 (merged)
- Added support for using
AtomGroup
selections through the API (in addition to string based selection phrases) - This works seamlessly with the GUI. GUI shows an indication if the underlying blender property is not being used with the option to override the selection with a selection phrase if desired
- Added support for using
- PR #906 (merged)
- Added support for text depth. With this, the annotation text size varies depending on the distance from the 3D viewport creating a perception of depth and reduces overlapping clutter
- An additional text falloff factor controls how the text size falls off from the viewport. This helps reduce the clutter for dense text significantly making it more readable
- PR #907 (merged)
- Added support to draw circles and arcs in 3D space
- Added the canonical dihedrals annotation for Trajectories
- Arcs are used to depict the angle between the two planes
Here is a video that shows the annotation text depth effect and canonical dihedrals:
Here are some learning from this week:
- When using a common factory instantiation method for different dynamic functions with dynamic signatures, ensure that the common method is wrapped under a dynamic wrapper to ensure that the custom signatures are retained for each and not the last one set
- Using a custom property in the
getter
andsetter
of a blender properties interface allows the use of both blender property types and any custom types for API use. We use this trick to supportAtomGroup
selections through the API. Blender property update callbacks being different from the API basedgetter
/setter
allows for this to work seamlessly - Python’s
typing.get_origin
can be used to determine if the type is of typetyping.Union
(eg: when usingtyping.Union[str | AtomGroup]
). Regulartype()
can be used fortypes.UnionType
(eg: when usingstr | AtomGroup
). The__args__
attribute in the union type can be iterated to get each of the union types. (Note thateval_str
should be set toTrue
ininspect.get_annotations()
to get the evaluated class types and not just strings) - The
view_matrix
of Blender’s region data can be used to determine the distance of a 3D point to the virtual 3D viewport camera. This works for both theothographic
and the more commonperspective
projection modes. A range of the distance values for an object can be determined by calculating the min and max of the object’s bounding box vertices (8 of them). This allows for a really fast way to determine on a normalized scale how far a point in the object space is from the 3D viewport. We use this to adjust the text size of annotations to create a perception of depth. This can also have other use cases later because we can determine the points closest to the viewport camera - Blender’s
Vector
andMatrix
(along with others) methods in themathutils
package make a lot of 3D computations really easy
Next week, I plan to work on the rendering support for annotations which needs rendering to a PIL
image and compositing with the actual render image. I will take a look at a few 2D viewport annotations like the universe info etc if time permits.
This post is licensed under CC BY 4.0 by the author.