Classes - ZackWilde27/Z3dPy GitHub Wiki

Everything is a list or tuple for the sake of speed, so most of the time there are two ways to retrieve variables: object functions, or accessing the lists directly. For all object functions, see the functions page

Basic

z3dpy.Vector(x, y, z)

Standard 3 point vector, could also be used as RGB

[0] - [2] are the x y and z

# Vector(x, y, z)
myVector = [22.0, 34.0, 58.0]
# is the same as myVector = z3dpy.Vector(22, 34, 58)

print(myVector[1])
# result: 34

z3dpy.Vector2(u, v)

2D Vector for textures

[0] is u, [1] is v

myVector2 = [54.0, 32.0]

print(myVector[1])
# result: 32

z3dpy.Vector4(x, y, z, w)

Vector with a W component for matrix math.

[0] - [2] are the x y and z, [3] is the w

# Vector4(x, y, z, w)
myVector4 = [0.0, 1.0, 2.0, 3.0]

print(myVector4[2] + myVector4[3])
# result 5

z3dpy.VectorUV(x, y, z)

A vector containing UV information and normal

[0] - [2] are the x, y, and z [3] is the normal [4] is the UV

# VectorUV(x, y, z)
myVectorUV = z3dpy.VectorUV(0.0, 2.0, 1.0)

myVectorUV[4] = z3dpy.Vector2(15.0, 30.0)

z3dpy.Tri(point1, point2, point3)

A triangle is made up of 3 vectors

[0] - [2] are the 3 points [3] is the normal [4] is world position [5] is baked shade [6] is colour [7] is id

# Tri(v1, v2, v3)
myTriangle = z3dpy.Tri([0.0, 0.0, 1.0], [0.0, 2.0, 0.0], [3.0, 0.0, 0.0])

print(myTriangle[0][2])
# result: 1

Meshes

z3dpy.Mesh(triangles, vPos)

A mesh is composed of a list of triangles, and has it's own x, y, and z

[0] is the list of triangles [1] is the position [2] is the rotation [3] is the colour [4] is the id [5] is always -1 to indicate it's not an animMesh [6] is the user variable [7] is wether or not back-faces are culled.

# Mesh(triangleList, vPos)
# I'm not going to write it manually, just use the LoadMesh() function
# LoadMesh(filename, *vPos, *VScale)
myMesh = z3dpy.LoadMesh("engine/mesh/plane.obj")

myMesh[2][0] += 5
myMesh[3] = [255, 0, 0]

z3dpy.AniMesh(frames, x, y, z)

an AniMesh is the same as a mesh except animated. Instead of a list of tris, it's a list of frames.

[0] is the list of frames [1] is the position [2] is rotation [3] is colour [4] is id [5] is frame number [6] is the user variable [7] is wether or not back-faces are culled

myAniMesh = z3dpy.LoadAniMesh("directory-to-obj.obj")

# Setting location
myAniMesh[1] = [25, 30, 35]

# Setting colour
myAniMesh[3] = (255, 0, 0)

# Printing the frame that is jumped to after frame 4, or -1
print(myAniMesh[0][3][1])

Things

z3dpy.Thing(meshList, vPos)

A Thing is what you would typically refer to as an object, it can have multiple meshes and supports collisions.

Since meshes have their own pos and rot, think of it like a global and relative transform.

[0] is the list of meshes [1] is position [2] is rotation [3] is hitbox [4] is physics body [5] is bMovable [6] is the internal id [7] is the user variable

myThing = z3dpy.Thing([myMesh, myOtherMesh], [0.0, 0.0, 0.0])

myThing[5] = False

myThing[3] = z3dpy.Hitbox()

print(myThing[1])

z3dpy.Hitbox(*type, *id, *radius, *height)

Hitbox object given to Things for collision. All of the arguments are optional, by default creates a 1x1x1 cube

[0] is the type [1] is the id [2] is the radius [3] is the height [4] is the hitbox mesh for drawing

myCharacter[4] = z3dpy.Hitbox(2, 0, 1.0, 1.0)

print(myCharacter[4][0])
# result: 2

z3dpy.PhysicsBody()

Physics body given to Things for simulating physics.

[0] is the velocity [1] is the acceleration [2] is the mass [3] is the friction [4] is the bounciness

z3dpy.SetupPhysics(myCharacter)

while True:
    # HandlePhysics(thingList, floorHeight)
    z3dpy.HandlePhysics([myCharacter], 2)

z3dpy.Dupe(iIndex, vPos, vRot)

A Dupe is a duplicate of a Thing, has it's own position and rotation but for everything else it points at the index of the OG

[0] is the index of the original Thing [1] is position [2] is rotation [3]-[5] are unused, they're user vars now [6] is -1 to indicate it's a dupe

z3dpy.AddThing(thatTree)

z3dpy.AddDupe(thatTree, [3, 5, 0], [0, 45, 0])
z3dpy.AddDupe(thatTree, [6, 2, 1], [0, 20, 0])
z3dpy.AddDupe(thatTree, [8, 1, 2], [0, 60, 0])

Camera

z3dpy.Cam(vPos, *width, *height)

Camera object, for rendering.

[0] is the user variable [1] is the position [2] is rotation [3] is near clip [4] is far clip [5] is target location [6] is up vector

myCamera = z3dpy.Cam([0, 0, 0])

myOtherCamera = z3dpy.Cam([5, 15, 25])

# Cameras pointing at eachother
myCamera[5] = myOtherCamera[1]
myOtherCamera[5] = myCamera[1]

print(myCamera[2])

cam = True

if cam:
    z3dpy.SetInternalCam(myCamera)
else:
    z3dpy.SetInternalCam(myOtherCamera)

Particles

z3dpy.Emitter(vPosition, mshTemplate, iMax, vVelocity, fLifetime, vGravity)

Emitter object, for spawning particles.

[0] is the tuple of currently active particles [1] is position [2] is the template mesh [3] is the velocity [4] is the max # of particles [5] is the lifetime [6] is wether or not it's active

myEmitter = z3dpy.Emitter([0, 0, 0], myMesh, 150, [0, -5, 2], 15.0, [0, 9.8, 0])

myEmitter[1] = z3dpy.ThingGetPos(thatTree)

print(myEmitter[6])

z3dpy.Part(vPosition, vVelocity, fTime)

Particle object, spawned through emitters with HandleEmitters().

[0] is the time left [1] is position [2] is velocity

myParticle = z3dpy.Part([0, 0, 0], [0, -5, 0], 5.0)

myParticle[1] = z3dpy.VectorAdd(myParticle[1], myParticle[2])

print(myParticle[0])

Lights

z3dpy.Light_Point(vPos, FStrength, fRadius, *vColour)

Point Light

[0] is type (0 for point light) [1] is position [2] is strength [3] is radius [4] is colour [5] is internal id - forgot to remove it, dang it. [6] is user variable

myLight = z3dpy.Light_Point([1.0, 2.0, 3.0], 0.8, 15, (255, 0, 0))

myLight[4] = (0, 0, 255)
myLight[3] = 1500
myLight[1] = [4.0, 5.0, 6.0]

z3dpy.Light_Sun(vRot, FStrength, fRadius, *vColour)

Sun Light

[0] is type (1 for sun light) [1] is position [2] is strength [3] is radius [4] is colour [5] is internal id [6] is user variable

myLight = z3dpy.Light_Sun((45.0, 0.0, 0.0), 0.8, 0, (255, 0, 0))

myLight[4] = (0, 0, 255)
myLight[1] = [1.0, 0.5, 0.75]

Collision

z3dpy.Ray(vStart, vEnd, *bIsArrow)

Rays for drawing or collisions

[0] is wether or not it's drawn as an arrow [1] is start position [2] is end position

myRay = z3dpy.Ray([1.0, 2.0, 3.0], [4.0, 5.0, 6.0], True)

myRay[1] = [0.0, 0.0, 0.0]
print(myRay[2])

Hit

Hits don't have a function, they are returned by RayIntersect functions

[0] is whether or not it hit and if so: [1] is location of hit [2] is distance of hit. [3] is normal of the hit triangle


myHit = z3dpy.RayIntersectThingComplex(myRay, myThing)

if myHit[0]:
    print(myHit[1])
    print(myHit[2])