Functions - ZackWilde27/Z3dPy GitHub Wiki
Table of Contents:
- Object Functions
- Universal
- Triangles
- Meshes
- Things
- Lights
- Rays
- Emitters
- Particles
- Cameras
- Hits
- Vector Functions
- VectorUV Functions
- Triangle Functions
- Matrix Functions
- Mesh Functions
- Thing Functions
- Collisions and Physics Functions
- Train Functions
- Raster Functions
- Drawing and Shader Functions
- PyGame
- Tkinter
- Lighting
- "Rastering"
- Custom Pipeline Functions
- Misc. Functions
Arguments marked with a * are optional
Unless it returns void, functions that change an input (such as VectorAdd) will return a new object without updating the originals.
Quite a few parameters specify the type of variable expected, with a starting letter:
f for float, i for integer, v for vector, msh for mesh.
Normalized parameters use capital letters, like F or V, expecting an input between 0-1 or -1 to 1
These functions are for setting and accessing variables inside "objects"
returns the position of a Thing, Mesh/AnimMesh, Cam, Ray, Light, Particle, or Emitter
sets the position of a Thing, Mesh/AnimMesh, Cam, Ray, Light, Particle, or Emitter
returns the rotation of a Thing, Cam, or Mesh/AnimMesh
sets the rotation of a Thing, Cam, or Mesh/AnimMesh
returns the list from a Thing, Emitter, Mesh/AnimMesh, or Frame.
For Things it's a list of meshes
For Emitters it's a tuple of active particles
For Meshes/Frames it's a tuple of tris
For AnimMeshes it's a list of frames
sets the list of a Thing, Emitter, Mesh/AnimMesh, or Frame.
returns the first point of a triangle.
returns the second point of a triangle.
returns the third point of a triangle.
returns the normal of the triangle.
TriGetNormal() will retrieve the stored normal, wheras GetNormal() will calculate a new one.
sets the normal of the triangle (set automatically during rasterization)
returns the colour of the triangle.
sets the colour of the triangle (set automatically during rasterization)
returns the world position of the triangle
sets the world position of a triangle (set automatically during rasterization)
returns the baked lighting colour of the triangle
sets the baked lighting colour of a triangle
returns the id of the triangle
sets the id of a triangle (set automatically during rasterization)
returns the mesh's list of triangles
Sets the tris of the given mesh
returns the position of the given mesh
Sets the position of the given mesh
returns the rotation of the mesh
Sets the rotation of the mesh
Adds rotation to the mesh by the x, y, and z separately
Subtracts the rotation of the mesh by the x, y, and z separately
Multiplies the rotation of the mesh by the x, y, and z separately
Divides mesh rotation by the x, y and z separately
returns the colour of the mesh
sets the colour of the mesh
returns the id of the mesh
sets the id of the mesh
returns wether or not back-faces are culled for this mesh
sets wether or not back-faces are culled for this mesh
returns the frame counter, or -1 for regular mesh
sets the frame counter
increments the frame counter
decrements the frame counter
returns the position of the mesh
returns the x position of a thing
returns the y position of a thing
returns the z position of a thing
sets the position of a thing
sets the x position of a thing
sets the y position of a thing
sets the z position of a thing
adds to the x position of a thing
adds to the y position of a thing
adds to the z position of a thing
returns the rotation of a thing
sets the rotation of a thing
adds rotation to a thing
subtracts rotation from a thing
multiplies a thing's rotation by a vector
divides a thing's rotation by a vector
returns the pitch of a thing
returns the roll of a thing
returns the yaw of a thing
sets the pitch of a thing
sets the roll of a thing
sets the yaw of a thing
returns the id of a thing
sets the id of a thing
returns wether or not a thing is movable
sets wether or not a thing is movable
returns the user variable of a thing
sets the user variable of a thing
increments the frame counter of all animMeshes in a thing
gives the thing a hitbox
changes the collision data of a thing and replaces the hitbox mesh.
returns the hitbox mesh of a thing
returns the height of a thing's hitbox
returns the hitbox radius of a thing
returns the collision id of a thing
returns the type of hitbox (0 = sphere, 1 = cylinder, 2 = cube)
gives the thing a physics body
returns the physics body of a thing
sets the velocity of a thing
sets the x velocity of a thing
sets the y velocity of a thing
sets the z velocity of a thing
returns the velocity of a thing
returns the x velocity of a thing
returns the y velocity of a thing
returns the z velocity of a thing
adds velocity to a thing
subtracts velocity from a thing
sets the acceleration of a thing
returns the acceleration of a thing
sets the mass of a thing
returns the mass of a thing
sets the friction of a thing
returns the friction of a thing
sets the bounciness of a thing
returns the bounciness of a thing
returns the rotational velocity of a thing
sets the rotational velocity of a thing
adds to the rotational velocity of a thing
returns the rotational acceleration of a thing
sets the rotational acceleration of a thing
adds to the rotational acceleration of a thing
sets velocity and acceleration of a thing to 0
returns the type of light. (0 for point, 1 for sun)
returns the position of a light
sets the position of a light
sets the x position of a light
sets the y position of a light
sets the z position of a light
returns the strength of a light
sets the strength of a light (0 - 1)
returns the radius of a light
sets the radius of a thing
returns the colour of a light
sets the colour of a light.
returns the user variable of a light
sets the user variable of a light
returns the start position of a ray
sets the start position of a ray
returns the end position of a ray
sets the end position of a ray
returns the direction of a ray
returns the length of a ray
returns wether or not the ray is an arrow
sets wether or not the ray is an arrow
returns the position of an emitter
sets the position of an emitter
returns the template mesh of an emitter
sets the template mesh of an emitter
returns the starting velocity of an emitter
sets the starting velocity of an emitter
returns the max number of particles for an emitter
sets the max number of particles for an emitter
returns the particle lifetime of an emitter
sets the particle lifetime of an emitter
returns wether or not an emitter is active
sets wether or not an emitter is active
returns the emitter's gravity
sets the emitter's gravity
returns the time left of a particle
sets the time left of a particle. I made a mistake and it says iLayer, but it's a float.
returns the position of a particle
sets the position of a particle
returns the velocity of a particle
sets the velocity of a particle
returns the position of a camera
returns the x position of a camera
returns the y position of a camera
returns the z position of a camera
sets the position of a camera
sets the x position of a camera
sets the y position of a camera
sets the z position of a camera
adds the vector to the camera's position
subtracts position from the camera
multiplies the camera's position by a vector
divides the camera's position by a vector
divides the camera's position by a float
causes a camera to "chase" a location rather than directly setting.
returns the pitch of a camera
returns the roll of a camera
returns the yaw of a camera
sets the pitch of a camera
sets the roll of a camera
sets the yaw of a camera
returns the rotation of a camera
sets the rotation of a camera
adds rotation to a camera
subtracts rotation from a camera
multiplies the rotation of a camera by a vector
divides the rotation of a camera by a vector
divides the rotation of a camera by a float
returns the near clip of a camera
sets the near clip of a camera
returns the far clip of a camera
sets the far clip of a camera
returns the location a camera is looking at.
sets the location a camera will look at
returns the direction a camera is looking
sets the direction a camera will look
uses the camera's rotation to determine target direction, for an easy first person camera.
returns the direction to the right of the camera.
returns the user variable
sets the user variable of a camera
returns wether or not it hit.
and if so...
returns the position of the hit
returns the distance between the ray start and the hit
returns the normal of the triangle that was hit
returns the world pos of the triangle that was hit
Almost all of these return new vectors, does not modify the original
returns the sum of the vectors
returns a vector with the float added to each axis
returns the first vector subtracted by the second vector
returns the first vector multiplied by the second
returns the vector multiplied by the float
returns the first vector divided by the second
returns a vector, divided by the float
returns a vector with each axis modulo'd individually
returns a vector with each axis modulo'd by the float.
returns the cross product of 2 vectors
returns the dot product of 2 vectors
returns a vector with each axis math.floor()'d
returns a vector with each axis abs()'d
returns the axis of a vector added together
returns the vector rotated around the x axis
returns the vector rotated around the y axis
returns the vector rotated around the z axis
returns true if the vectors are equal
returns wether or not vector1 is greater than vector2, in terms of absolute magnitude
returns the negated vector
returns a vector with the strongest axis being 1, others are 0
returns a vector where all axis below the threshold are 0
returns the distance between the two vectors
returns the direction from the first vector towards the second
returns the point where a line intersects a plane
returns the closest point on the plane to the startPoint
returns the length of a vector
returns the normalized vector
shortcut for using a max() on each axis individually.
shortcut for using a min() on each axis individually.
shortcut for using a max() on each axis.
shortcut for using a min() on each axis.
returns a rot with each axis wrapped to 0-359
returns the target direction rotated, used to get anything's up, forward, right, or anything-in-between vector
The second vector does not have to be a vectorUV. The first vector's normal and UV are carried.
adds the second vector to the first.
subtracts the second vector from the first.
multiplies the first vector by the second.
multiplies the vectorUV by a float
divides the first vector by the second
divides the vectorUV by a float
Most of these return new triangles, does not modify the original
Shortcut instead of VectorAdd-ing each point
Shortcut instead of VectorSub-ing each point
You get the point
Calculates the normal of a triangle. (TriangleGetNormal() will return the currently stored normal)
returns the center point of the triangle
returns a list of triangles, either containing the original triangle if it's in front of the plane, split up triangles that clip the plane, or no triangles if it's behind the plane.
does a TriClipAgainstPlane(), for the camera's near clip plane
does a TriClipAgainstPlane(), for all 4 edges of the screen.
returns the average point's distance from the camera. A key for sorting triangles.
returns the furthest point from the camera. A key for sorting triangles.
returns the closest point from the camera. A key for sorting triangles.
My version of a matrix is just a list of lists, to set or retrive a value it's myMatrix[x][y]
multiplies the vector by the matrix and returns the vectorUV
multiplies the vector by the matrix and returns the vector4
returns the multiplied matrixes
Shortcut for multiplying a matrix by each point of a triangle
returns a point at matrix, given a position, target location, and up direction
returns a look at matrix given a position, target location, and up direction. used during the ViewTriangles() stage of rastering
returns an X rotation matrix given an angle value in degrees
returns an Y rotation matrix given an angle value in degrees
returns an Z rotation matrix given an angle value in degrees
returns the projection matrix, given a camera. Not used
loads the mesh from filename and returns it. If the filename is not found, loads the NOPE mesh
loads the animMesh from filename and returns it.
adds a thing to the specified layer (third layer by default)
adds a list of things to the specified layer (third layer by default)
removes a thing from the specified layer (third layer by default)
returns a list of all things in all layers.
Adds a dupe to the global list in the iLayer, and returns it.
If iLayer is -1, doesn't add to global list.
returns a list of things that are colliding
takes the list from GatherCollisions() and sets the position of things to try and separate them.
sets the position of things based on their physics calculations. Gravity is included, so there's a floor that things won't fall past. (0 unless specified.)
same as HandlePhysicsFloor() except uses a train to determine height.
will GatherCollisions(), then applies velocity to separate any collisions. Will only push objects that have a physics body.
blurs terrain into smooth hills. overwrites the original.
returns the height at a certain location, interpolating between values.
computes the view matrix for the ViewTriangles stage of rendering. This needs to be done when the camera moves or otherwise changes.
returns a list of triangles to draw to the screen, given a list of meshes, and a camera to render from.
sorting method has 3 options: triSortAverage, triSortFurthest, and triSortClosest.
reverseSort is wether or not to reverse sorting. Should be True, except when using the PgPixelShader
returns a list of triangles to draw to the screen, given a list of things. sorts using z3dpy.triSortAverage by default
same thing as RasterThings() but uses the internal list
returns a list of triangles to draw to the screen, including hitboxes, lights, rays, and other debug things.
returns a list of triangles to draw to the screen, rendered with the C++ extension
same as RasterThings(), but using the C++ extension
draws a triangle to a PyGame surface, with dynamic flat lighting
draws a triangle to a PyGame surface, with baked flat lighting.
draws a triangle to a PyGame surface. it's a vector so xyz is rgb
draws a triangle to a PyGame surface. converts 0-1 to 0-255
draws a triangle to a PyGame surface. uses the float for all channels, so it's grayscale
draws a triangle to a PyGame surface. multiplies the float by the triangle's colour to produce shading
draws a triangle to a PyGame surface. only draws the outline and converts 0-1 to 0-255
draws a textured triangle to a PyGame pixel array. Still early on and definitely not the fastest.
draws a triangle to a Tkinter canvas, with dynamic flat lighting
draws a triangle to a Tkinter canvas, with baked flat lighting
draws a triangle to a Tkinter canvas. it's a vector so xyz is rgb
draws a triangle to a Tkinter canvas. converts 0-1 to 0-255
draws a triangle to a Tkinter canvas. uses the float for all channels, so it's grayscale
draws a triangle to a Tkinter canvas. multiplies the float by the triangle's colour to produce shading
draws a triangle to a Tkinter canvas. only draws the outline and converts 0-1 to 0-255
returns the shade of a triangle, using cheap direction based lighting. optionally you can specify whether or not to add to the global rays list for drawing. (False by default)
returns the shade of a triangle, using an expensive technique that checks for shadows.
returns the shade of a triangle, cheaply retrived from it's shade variable
saves the lighting calculations to each triangle's shade variable. optional parameter to specify expensive lighting. Shadowcasters is the list of Things to check for collisions.
technically Rastering is converting triangles to lines or pixels, so here are those functions.
returns a tuple of lines to draw, given a triangle. Each line is a ray, with a start position and end position.
returns a tuple of pixels to draw, given a triangle. Each line is a Vector2, with an x and y
rotates triangles in world space, given a position, target location, and up direction.
the old method of transforming triangles
the old method of translating triangles
moves and distorts triangles in front of [0, 0, 0] as if the camera was moving.
projects a list of triangles to 2D
These functions should be done in order, so first Transform, then Translate, then View, then Project.
interpolates between numbers in a list based on fIndex
returns the list, with the index removed, for temporary exclusion, or for replacing the list to act as a better remove()
returns the sign of the input, positive, negative, or 0