Functions 0.4 - ZackWilde27/Z3dPy GitHub Wiki

Table of Contents:

  • List Object Functions
    • Triangles
    • Rays
    • Particles
    • Hits
  • Vector Functions
  • VectorUV Functions
  • Triangle Functions
  • Matrix Functions
  • Mesh Functions
  • Thing Functions
  • Collisions and Physics Functions
  • Train Functions
  • Lighting
  • Rastering
  • Custom Pipeline Functions
  • Misc. Functions



Legend:

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, v for vector, Capitals mean normalized.




List Object Functions

A few objects are still lists, so these are more human-friendly ways to access properties.



Triangles


TriGetP1(tri)

returns the first point of a triangle.


TriGetP2(tri)

returns the second point of a triangle.


TriGetP3(tri)

returns the third point of a triangle.


TriGetNormal(tri) -> vector

returns the normal of the triangle.

TriGetNormal() will retrieve the stored normal, wheras GetNormal() will calculate a new one.


TriSetNormal(tri, vector) -> void

sets the normal of the triangle (set automatically during rasterization)


TriGetColour(tri) -> vector

returns the colour of the triangle.


TriSetColour(tri, vector) -> void

sets the colour of the triangle


TriGetWPos(tri) -> vector

returns the world position of the triangle


TriSetWPos(tri, vector) -> void

sets the world position of a triangle


TriGetShade(tri) -> vector

returns the baked lighting colour of the triangle


TriSetShade(tri, VColour) -> void

sets the baked lighting colour of a triangle


TriGetId(tri) -> int

returns the id of the triangle


TriSetId(tri, id) -> void

sets the id of a triangle (set automatically during rasterization)


Rays


RayGetStart(ray) -> vector

returns the start position of a ray


RaySetStart(ray, vector) -> void

sets the start position of a ray


RayGetEnd(ray) -> vector

returns the end position of a ray


RaySetEnd(ray, vector) -> void

sets the end position of a ray


RayGetDirection(ray) -> vector

returns the direction of a ray


RayGetLength(ray) -> float

returns the length of a ray


RayGetIsArrow(ray) -> bool

returns wether or not the ray is an arrow


RaySetIsArrow(ray, bIsArrow) -> void

sets wether or not the ray is an arrow


Particles


PartGetTime(particle) -> float

returns the time left of a particle


PartSetTime(particle, float) -> void

sets the time left of a particle. I made a mistake and it says iLayer, but it's a float.


PartGetPos(particle) -> vector

returns the position of a particle


PartSetPos(particle, vector) -> void

sets the position of a particle


PartGetVelocity(particle) -> vector

returns the velocity of a particle


PartSetVelocity(particle, vector) -> void

sets the velocity of a particle


Hits


HitCheck(hit) -> bool

returns wether or not it hit.

and if so...


HitGetPos(hit) -> vector

returns the position of the hit


HitGetDistance(hit) -> float

returns the distance between the ray start and the hit


HitGetNormal(hit) -> vector

returns the normal of the triangle that was hit


HitGetTri(hit) -> tri

returns the triangle that was hit





Vector Functions



VectorAdd(vector1, vector2) -> vector

returns the sum of the vectors


VectorAddF(vector, float) -> vector

returns a vector with the float added to each axis


VectorSub(vector1, vector2) -> vector

returns the first vector subtracted by the second vector


VectorMul(vector1, vector2) -> vector

returns the first vector multiplied by the second


VectorMulF(vector, float) -> vector

returns the vector multiplied by the float


VectorDiv(vector, vector) -> vector

returns the first vector divided by the second


VectorDivF(vector, float) -> vector

returns a vector, divided by the float


VectorMod(vector1, vector2) -> vector

returns a vector with each axis modulo'd individually


VectorModF(vector, int) -> vector

returns a vector with each axis modulo'd by the int (I meant I instead of F).


CrossProduct(vector1, vector2) -> vector

returns the cross product of 2 vectors


DotProduct(vector1, vector2) -> float

returns the dot product of 2 vectors


VectorFloor(vector) -> vector

returns a vector with each axis floor()'d


VectorABS(vector) -> vector

returns a vector with each axis abs()'d


VectorComb(vector) -> float

returns the axis of a vector added together


VectorRotateX(vector, degrees) -> vector

returns the vector rotated around the x axis


VectorRotateY(vector, degrees) -> vector

returns the vector rotated around the y axis


VectorRotateZ(vector, degrees) -> vector

returns the vector rotated around the z axis


VectorEqual(vector1, vector2) -> bool

returns whether or not the vectors are equal


VectorCompare(vector1, vector2) -> bool

returns whether or not vector1 is greater than vector2, in terms of absolute magnitude


VectorNegate(vector) -> vector

returns the negated vector


VectorPureDirection(vector) -> vector

returns a vector with the strongest axis being 1, others are 0


VectorZero(vector, fThreshold) -> vector

returns a vector where all axis below the fThreshold are 0


DistanceBetweenVectors(vector1, vector2) -> float

returns the distance between the two vectors


DirectionBetweenVectors(vector1, vector2) -> vector

returns the direction from the first vector towards the second


VectorIntersectPlane(planePos, planeNrm, lineStart, lineEnd) -> vector

returns the point where a line intersects a plane


ShortestPointToPlane(startPoint, planeNrm, planePos) -> float

returns a float from -1 to 1 indicating which side of the plane the given point lies on.


VectorGetLength(vector) -> float

returns the length of a vector


VectorNormalize(vector) -> vector

returns the normalized vector


VectorMax(v1, v2) -> vector

shortcut for using a max() on each axis individually.


VectorMin(v1, v2) -> vector

shortcut for using a min() on each axis individually.


VectorMaxF(v, f) -> vector

shortcut for using a max() on each axis.


VectorMinF(v, f) -> vector

shortcut for using a min() on each axis.


VectorAverage(list_of_vectors) -> vector

returns the average of a given list of vectors.


WrapRot(vRot) -> vector

returns a rot with each axis wrapped to 0-359


RotTo(vRot, VTarget) -> vector

returns the rotated target direction, used to get anything's up, forward, right, or anything-in-between vector




VectorUV Functions

The second vector does not have to be a vectorUV. The first vector's normal and UV are carried.



VectorUVAdd(v1, v2) -> VectorUV

adds the second vector to the first.


VectorUVSub(v1, v2) -> VectorUV

subtracts the second vector from the first.


VectorUVMul(v1, v2) -> VectorUV

multiplies the first vector by the second.


VectorUVMulF(v, f) -> VectorUV

multiplies the vectorUV by a float


VectorUVDiv(v1, v2) -> VectorUV

divides the first vector by the second


VectorUVDivF(v, f) -> VectorUV

divides the vectorUV by a float

VectorUVIntersectPlane(pPos, pNrm, lSta, lEnd) -> vectorUV

returns the point where a line intersects a plane, with interpolated UV coordinates


VectorUVFloor(vectorUV) -> vectorUV

Shortcut instead of floor()-ing each axis




Triangle Functions



TriAdd(triangle, vector) -> triangle

Shortcut instead of VectorAdd-ing each point


TriSub(triangle, vector) -> triangle

Shortcut instead of VectorSub-ing each point


TriMul(triangle, vector) -> triangle

You get the point


TriMulF(triangle, float) -> triangle


TriDivF(triangle, float) -> triangle


GetNormal(triangle) -> vector

Calculates the normal of a triangle.


TriAverage(triangle) -> vector

returns the center point of a triangle


TriClipAgainstPlane(planePosition, planeNormal, tri)

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.


TriClipAgainstZ(tri, camera)

does a TriClipAgainstPlane(), for the camera's near clip plane


TriClipAgainstScreenEdges(tri, camera)

does a TriClipAgainstPlane(), for all 4 edges of the screen.


TriSortAverage(triangle) -> float

returns the average point's distance from the camera. A key for sorting triangles.


TriSortFurthest(triangle) -> float

returns the furthest point from the camera. A key for sorting triangles.


TriSortClosest(triangle) -> float

returns the closest point from the camera. A key for sorting triangles.


Triangulate(list_of_vectors) -> list of tris

returns a list of tris, given a list of vectors





Matrix Functions



VecMatrixMul(vectorUV, matrix) -> vectorUV

multiplies the vector by the matrix and returns the vectorUV


Vec3MatrixMul(vector, matrix) -> vector

returns the vector by the matrix


MatrixMatrixMul(matrix1, matrix2) -> matrix

returns the multiplied matrixes


TriMatrixMul(triangle, matrix) -> triangle

Shortcut for multiplying a matrix by each point of a triangle


PointAtMatrix(pos, target, up) -> matrix

returns a point-at matrix, given a position, target location, and up direction


LookAtMatrix(pos, target, up) -> matrix

returns the inverse of the point-at matrix given a position, target location, and up direction.


MatrixMakeProjection(fov) -> matrix

returns a projection matrix, given an FOV


MatrixMakeRotX(angle) -> matrix

returns an X rotation matrix given an angle value in degrees


MatrixMakeRotY(angle) -> matrix

returns an Y rotation matrix given an angle value in degrees


MatrixMakeRotZ(angle) -> matrix

returns an Z rotation matrix given an angle value in degrees





Mesh Functions



LoadMesh(filename, *vPos, *VScale) -> mesh

Creates a mesh from an OBJ, DAE, X3D, PLY, or STL file.


LoadAniMesh(filename, *vPos, *VScale) -> mesh

Creates an animated mesh from an OBJ sequence or AnimatedOBJ file





Thing Functions



AddThing(thing, *iLayer) -> void

adds a thing to the specified layer (third layer by default)


AddThings(thingList, *iLayer) -> void

adds a list of things to the specified layer (third layer by default)


RemoveThing(thing, *iLayer) -> void

removes a thing from the specified layer (third layer by default)


GatherThings() -> list

returns a list of all things in all layers.


AddDupe(thing, position, rotation, *iLayer) -> dupe

Adds a dupe to the global list in the iLayer, and returns it.
If iLayer is -1, doesn't add to global list.





Collisions and Physics Functions



GatherCollisions(thingList) -> collisionList

returns a list of things that are colliding


BasicHandleCollisions(collision) -> void

takes the list from GatherCollisions() and sets the position of things to try and separate them.


HandlePhysicsFloor(thingList, *floorHeight) -> void

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.)


HandlePhysicsTrain(thingList, train) -> void

same as HandlePhysicsFloor() except uses a train to determine height.


PhysicsCollisions(thingList) -> void

will GatherCollisions(), then applies velocity to separate any collisions. Will only push objects that have a physics body.




Train Functions



BakeTrain(train, *iPasses, *FStrength, *fAmplitude) -> void

Blurs the terrain into smooth hills and creates a mesh out of the points, stored in z3dpy.trainMesh


TrainInterpolate(train, x, y) -> float

returns the height at a certain location, interpolating between values.




Lighting



CheapLighting(tri, *drawRay) -> float

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)


ExpensiveLighting(tri) -> float

returns the shade of a triangle, using an expensive technique that checks for shadows.


BakeLighting(thingList, *bExpensive, *lightList, *shadowcasterList) -> void

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.




Rastering



TriToLines(tri, draw) -> void

converts a triangle to lines, and gives them to the draw function as they are calculated.


TriToPixels(tri, draw) -> void

converts a triangle to pixels, and gives them to the draw function as they are calculated.


TriToTexels(tri, draw) -> void

converts a triangle to pixels with Affine-mapped UVs, and gives them to the draw function as they are calculated.




Custom Render Pipeline Functions



TransformTris(triangleList, pos, target, up, *scale, *bCull, *material) -> triangle list

Turns local triangles into world triangles, executing the material's shaders before and after.


WTransformTris(triangleList, rot) -> triangle list

The old method of transforming triangles, with a rotation matrix. (needs a TranslateTris() afterwards)


TranslateTris(triangleList, pos) -> triangle list

WTransformTris() only does rotation, so TranslateTris() is needed afterwards


ViewTris(triangleList) -> triangle list

Turns world triangles into view triangles


ProjectTris(triangleList) -> triangle list

Turns view triangles into screen-space triangles.





Misc. Functions



RGBToHex(vColour) -> string

returns the hex form of a colour, prefixed with a '#'


ListInterpolate(list, fIndex) -> float

interpolates between numbers in a list based on fIndex


ListExclude(list, index) -> list

returns the list, with the index removed, for temporary exclusion, or for replacing the list as a solution to remove()


ListNDFlatten(list_of_lists) -> list

flattens an N-dimensional list.


StringSweepUntil(string, start, symbols, *step) -> int

It's like find but with multiple options, sweeps through the string until any of the characters in the symbols string are encountered.


Sign(float) -> 1, 0, or -1

returns the sign of the input, positive, negative, or 0


TripleEquals(a, b) -> bool

returns if a and b are pointing at the same object, does not compare value. This might not work depending on the interpreter.

⚠️ **GitHub.com Fallback** ⚠️