Things 0.4 - ZackWilde27/Z3dPy GitHub Wiki

z3dpy.Thing(meshList, vPos)


myThing = z3dpy.Thing([myMesh, myOtherMesh], [12.0, 45.0, 23.52])

Properties

  • meshes

  • position

  • rotation Measured in degrees

  • scale

  • hitbox

  • physics

  • movableWether or not the transformation stage of rendering is performed. Setting to false can provide a speed boost for things that won't move.

  • visible

  • internalidThe location of a thing in the global things list. Used when removing, I wouldn't recommend changing it

  • user

Functions

  • IncrementFrames()Increments the frame counter for all AniMeshes in a Thing.

  • DecrementFrames()Decrements the frame counter for all AniMeshes in a Thing.

  • AddPos(vector)Adds to the position of a Thing, to replace myThing.position = VectorAdd(myThing.position ...).

  • AddRot(vector)Adds to the rotation of a Thing.

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.

Creating Things

# LoadMesh(filename)
myMesh = z3dpy.LoadMesh("z3dpy/mesh/susanne.obj")

# Thing(meshList, vPos)
myThing = z3dpy.Thing([myMesh], [1, 2, 3])

myThing.rotation =  [90, 0, 0]

print(myThing.position)

Objects with multiple colours can be made by separating a mesh into pieces, and grouping it into a Thing.


sword_metal = z3dpy.LoadMesh("directory-to-obj.obj")
sword_wood = z3dpy.LoadMesh("directory-to-obj.obj")

sword_metal.SetColour([219, 219, 219])
sword_wood.SetColour([190, 128, 82])

sword = z3dpy.Thing([sword_metal, sword_wood], [0, 0, 0])

Hitboxes

Things can be given a hitbox for gathering collisions:

myThing.hitbox = z3dpy.Hitbox(type, id, radius, height)
# Type:
# either HITBOX_BOX, or HITBOX_SPHERE
# I'd go with box as it's the most stable

# Id:
# things will only collide if their IDs match.

# Radius:
# Radius of the sphere or length/width of the box

# Height:
# Height of the box

Details can be found on the collisions page

Physics

Things can also be given a physics body for simulating physics:

myThing.physics = z3dpy.PhysicsBody()

# Then in the draw loop...

    # Tick the physics
    # HandlePhysicsFloor(thingList, floorHeight)
    z3dpy.HandlePhysicsFloor([myThing], 0)

The physics system also does collisions.

myThing.physics = z3dpy.PhysicsBody()

myThing.hitbox = z3dpy.Hitbox(z3dpy.HITBOX_BOX, 0, 2.0, 2.0)

# Then in the draw loop...

    # 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