Trains - ZackWilde27/Z3dPy GitHub Wiki

z3dpy.Train( iWidth, iHeight )

myTrain = z3dpy.Train(32, 32)

Trains are Z3dPy's terrain system, it's a 2D list of heights, that is then smoothed and converted to a mesh with BakeTrain().

Say we had this basic scene involving physics with a flat floor:


myCharacter.physics = z3dpy.PhysicsBody()

z3dpy.AddThing(myCharacter)

# Then in the draw loop...

    z3dpy.HandlePhysicsFloor([myCharacter], 2)

    for tri in z3dpy.Render():
        # Draw Code

At the beginning of the script, a train needs to be created and baked.

# Making a 16x16 plane
# To create a mesh out of it, it has to be an even width and height
myTrain = z3dpy.Train(16, 16)

# Setting height at certain locations
myTrain[5][2] = 32.6
myTrain[10][8] = -54.2

# Baking will blur points into smooth hills, and create a mesh out of the points
# BakeTrain(train, *iPasses, *FStrength, *FAmplitude)
z3dpy.BakeTrain(myTrain)
  • Passes

    How many times to perform the blur (1 time by default)

  • Strength

    Strength of the blur (1.0 by default)

  • Amplitude

    Used to amplify the final output (1.0 by default)

Now that the train is created, HandlePhysicsFloor() can be replaced with HandlePhysicsTrain()

# Then in the draw loop...

    z3dpy.HandlePhysicsTrain([myCharacter], myTrain)

    for tri in z3dpy.RenderThings([myCharacter]):
        # Draw Code

The new mesh is written to z3dpy.trainMesh.

This mesh is automatically drawn underneath everything in Render(), but you can put it in RenderMeshList() or put it in a Thing

z3dpy.BakeTrain()

myTrainThing = z3dpy.Thing([z3dpy.trainMesh], [0.0, 0.0, 0.0])