Rendering - ZackWilde27/Z3dPy GitHub Wiki

Functions

Rendering can be done automatically with different functions depending on what you need.

for tri in Render(*sort_key, *b_reverse):
    # Renders all things in z3dpy.layers, and each emitter's particles in z3dpy.emitters

for tri in DebugRender(*train, *sortKey, *bReverse, *clearRays):
    # Visualizes light sources, hitboxes, rays, emitters, dots, and trains.

for tri in RenderMeshList(meshList, *sortKey, *bReverse):
    # Render a list of meshes

for tri in RenderThings(things, *emitters, *sortKey, *bReverse):
    # Render a list of things, and a list of emitters.

Each tri will have pre-calculated normals, and world-position (centre point in world space). Colour and id will be based on the mesh it came from.

SortKey and bReverse

The function for sorting, and whether or not to reverse. There are 3 built-in sort keys:

  • TriSortAverage (default) Sorts by the center point of each triangle

  • TriSortClosest Sorts by the closest point to the camera

  • TriSortFurthest Sorts by the furthest point from the camera

bReverse will reverse sorting. Normally it should be True so that triangles are drawn back to front

Internal List

Render() uses an internal list of things, which can be manipulated with AddThing() and RemoveThing()

# AddThing(thing, *layer)
z3dpy.AddThing(myCharacter)
z3dpy.AddThings([thatTree, thatOtherTree])

# RemoveThing(thing, *layer)
# The layer must be the same, so it's also default
z3dpy.RemoveThing(thatOtherTree)

Layers

Layers can make sure that certain things are drawn over others, regardless of depth.

z3dpy.AddThing(myCharacter, 2)
z3dpy.AddThing(floor, 1)
# myCharacter will always be drawn over floor, regardless of depth.

# By default the layer setup looks like this
z3dpy.layers = ([], [], [defaultLayer], [])
# You've got one foreground and two background layers surrounding the default one.

# Redefine the layers list to add or remove layers
z3dpy.layers = ([], [], [], [], [], [], ...)