Things - ZackWilde27/Z3dPy GitHub Wiki
z3dpy.Thing(meshList, vPos)
Things are objects in the game world, have a list of meshes and can be given a hitbox/physics body.
Since meshes have their own position and rotation, it's like a global and local transform.
Translation happens after rotation, so position offsets are in world space, not considering rotation.
myThing = z3dpy.Thing([myMesh, myOtherMesh], [12.0, 45.0, 23.52])
Creating Things
# LoadMesh(filename)
myMesh = z3dpy.LoadMesh("z3dpy/mesh/susanne.obj")
# Thing(meshList, vPos)
myThing = z3dpy.Thing([myMesh], [1, 2, 3])
# ThingSetRot(thing, vector)
z3dpy.ThingSetRot(myThing, [90, 0, 0])
print(z3dpy.ThingGetPos(myThing))
Objects with multiple colours can be made by separating a mesh into pieces.
sword_metal = z3dpy.LoadMesh("directory-to-obj.obj")
sword_wood = z3dpy.LoadMesh("directory-to-obj.obj")
z3dpy.MeshSetColour(sword_metal, [219, 219, 219])
z3dpy.MeshSetColour(sword_wood, [190, 128, 82])
sword = z3dpy.Thing([sword_metal, sword_wood], [0, 0, 0])
Hitboxes
Things can be given a hitbox for gathering collisions:
z3dpy.ThingSetupHitbox(myThing)
# ThingSetCollision(thing, type, id, radius, height)
z3dpy.ThingSetCollision(myThing, 2, 0, 1, 1)
# These are also optional parameters for ThingSetupHitbox()
# Type:
# 0 is sphere, and 2 is box
# I'd go with box as it's the most stable
# Id:
# 2 things will only collide if their IDs match.
# Radius:
# Radius of the sphere or length/width of the box
# Height:
# Height of the box
# Collisions can be handled either manually or with the physics system.
# (more on the physics system below)
# Manually:
for collision in z3dpy.GatherCollisions([myThing, myOtherThing]):
thing1 = collision[0]
thing2 = collision[1]
# Your code here
Details can be found on the collisions page
Physics
Things can also be given a physics body for simulating physics:
z3dpy.ThingSetupPhysics(myThing)
while True:
# HandlePhysicsFloor(thingList, floorHeight)
z3dpy.HandlePhysicsFloor([myThing], 0)
The physics system also does collisions.
z3dpy.ThingSetupPhysics(myThing)
z3dpy.ThingSetupHitbox(myThing)
while True:
# HandlePhysicsFloor(thingList, floorHeight)
z3dpy.HandlePhysicsFloor([myThing], 0)
# PhysicsCollisions(thingList)
z3dpy.PhysicsCollisions([myThing, myOtherThing])
PhysicsCollisions() will GatherCollisions(), then applies an outward force to whichever ones have physics bodies
Details can be found on the physics page