Pyn is a Python 3D game engine and renderer. It is great for creating your own 3D games from scratch with Python, and includes great mesh tools and environmental features. Pyn allows simple physics and easy manipulation to create 3D visualizers, games, and more. Pyn has lighting, materials, and textures, and is completely free and open-source. It is very easy to use and create your own meshes and renders, as well as built-in mesh tools to manipulate your meshes.
For more information, see the documentation wiki
Install Pyn
Try a Project
Pyn is a Python 3D game engine and renderer. It is great for creating your own 3D games from scratch with Python, and includes great mesh tools and environmental features. Pyn allows simple physics and easy manipulation to create 3D visualizers, games, and more. Pyn has lighting, materials, and textures, and is completely free and open-source. It is very easy to use and create your own meshes and renders, as well as built-in mesh tools to manipulate your meshes.
Starting with Pyn is very simple:
from Pyn3D import *
All Pyn programs must begin with the init()
script.
The Camera
class creates a camera in your scene.
The Mouse
class creates a mouse, and allows editing of the cursor and other properties.
The window()
function creates and updates the window with your specifications.
Simple example program:
from Pyn3D import *
init()
# initialize window
cam = Camera(pos = (0, 0, -5))
mouse = Mouse()
# creates a camera and mouse object
Light(pos = (0, 3, 0), strength = 10)
Cube(pos = (0, 0, 0))
# creates a light and cube object
while True:
window(cam)
# updates the window
Starting with Pyn needs the init script to create a window.
init(width, height)
The width and height properties determine the window's width and height. The default width and height is 400 by 400.
The Mouse object is needed to determine the properties and position of the mouse or cursor.
Mouse(pos, visible, lock, cursor)
- Vector2 tuple
- The starting position of the cursor
Mouse(pos = (0, 0))
- 0 or 1 integer
- Visibility of the cursor
Mouse(visible = 0)
- 0 or 1 integer
- Locks cursor to window
Mouse(lock = 1)
- Pygame cursor
- Cursor display
Mouse(cursor = pygame.cursors.arrow)
The window()
function updates the window to your specifications.
window(camera, background, light)
- Camera object
- Camera perspective displayed in the window
window(camera = cam)
- RGB tuple
- Background color of the window
window(background = (255, 255, 255))
- Bool
- Determines whether the background color is affected by Light objects
window(light = True)
Cameras are needed in Pyn programs for visualization.
Camera(pos, rot, fly, fixed, spd)
- Vector3 tuple
- The position of the camera
Camera(pos = (0, 0, -5))
- Vector2 tuple
- The rotation of the camera
Camera(rot = (0, 0))
- Bool
- If the camera can fly using Q and E keys
Camera(fly = False)
- Bool
- If the camera cannot move using W, A, S, and D keys
Camera(fixed = False)
- Float
- Speed of the camera when moving
Camera(spd = 0.5)
- List of Vector3 tuples
- Bounding box vertices for collision detection
cam.bbox = [(-0.5, -0.5, -0.5), (0.5, -0.5, -0.5), (0.5, 0.5, -0.5), (-0.5, 0.5, -0.5), (-0.5, -0.5, 0.5), (0.5, -0.5, 0.5), (0.5, 0.5, 0.5), (-0.5, 0.5, 0.5)]
- Object
- Checks collisions with other object
cam.checkCollisions(cube)
Objects are empty 3D objects which can be used for displaying visuals.
Object(pos, size, material, parent, physic)
- Vector3 tuple
- The position of the object
Object(pos = (0, 0, -5))
- Float
- The size of the object
Object(size = 5)
- Material object index
- The size of the object
Object(material = 0)
- Parent object
- The parent of the object
Object(parent = cam)
- Physic list
- The physics properties of the object
Object(physics = ["softbody", "gravity", "collider"])
- Object
- Checks collisions with other object
object.checkCollisions(cube)
- X, Y, Z floats
- Rotates object
object.rotate((10, 10, 10))
- X, Y, Z floats
- Moves object
object.move(0, 10, 0)
- X, Y, Z floats
- Places object
object.place(0, 0, 10)
- X, Y, Z floats
- Scales object
object.scale(10, 0, 0)
Meshes are pre-built meshes which come with Pyn and already-made coordinates.
Some pre-made meshes:
Cube()
Plane()
Point()
Line()
Circle()
Polygons are 3D buildable objects based on Vector3D tuple X, Y, Z coordinates.
Example:
Polygon(args = [(0, 0, 0), (10, 10, 10), (0, 10, 0), (0, 0, 0)])
# creates a polygon mesh face based on X, Y, Z coordinates
Custom Meshes are buildable 3D meshes based on vertices, faces, and default face colors.
Example
class MyMesh(Object):
vertices = [(-4, -1, -1), (1, -1, -1), (1, 1, -1), (-3, 1, -1), (-4, -1, 1), (1, -1, 1), (1, 1, 1), (-3, 1, 1)]
faces = [(0, 1, 2, 3), (4, 5, 6, 7), (0, 1, 5, 4), (2, 3, 7, 6), (0, 3, 7, 4), (1, 2, 6, 5)]
colors = [(100, 0, 0), (50, 50, 10), (100, 50, 50), (50, 100, 50), (50, 100, 100), (50, 50, 100), (50, 10, 100), (50, 100, 100), (50, 100, 10), (10, 50, 100)]
Custom Meshes must be an instance of the Object class.
Lights are needed for lighting effects.
Light(pos, strength)
Lights can cause changes in color and brightness for objects, as well as the window background color.
- Vector3 tuple
- The position of the object
Light(pos = (0, 0, 0))
- Integer
- The strength of the light
Light(strength = 10)
Materials are objects for materializing meshes.
Material(color, emmission)
Materials can then be assigned to meshes.
- RBG float
- The color of the material
Light(color = (0, 0, 0))
- Integer
- The emission factor of the material
Light(emmission = 1)
Texturing is a method of assigning an image or pixel map texture to the mesh using materials. Textures are texture objects for texturing meshes.
Texture()
Textures can be created using pixel maps or images, and must be assigned to the object by colors, each pixel being assigned a certain color. Mesh Tools are required for pixelating the mesh to add the pixel map to the mesh.
Image Textures are texture objects for texturing meshes using images.
Texture(path)
- String
- The path of the image
Texture(path = "myImage.png")
Map Textures are texture objects based on a pixel map.
Texture()
Map textures can also be based on image textures.
- List of RGB tuples
- The pixel map of the texture
texture.pixmap = [(0, 0, 0), (10, 10, 10), (0, 0, 0), (10, 10, 10)]
Materials can be assigned though meshes' material variable.
myMaterial = Material(color = (0, 10, 0), emmision = 10)
Object(material = myMaterial)
The changeColor()
function brightens or darkens a color.
changeColor(rgb, scale)
- RBG float
- The color of the UI object
changeColor(rgb = (100, 100, 100))
- Integer
- Amount to darken or lighten
changeColor(scale = 10)
UI objects are displayed on top of the graphics for 2D menus, buttons, and more.
UI(pos)
- Vector2 tuple
- The position of the UI object
UI(pos = (0, 0))
- X, Y, Z floats
- Moves the UI object
ui.move(10, 10, 10)
UI Polygons are 2D UI polygons.
UIPolygon(pos, color, points)
- Vector2 tuple
- The position of the UI object
UIPolygon(pos = (0, 0))
- RBG float
- The color of the UI object
UIPolygon(color = (0, 0, 0))
- List of Vector3 tuples
- The points of the UI object
UIPolygon(points = [(0, 0, 0), (10, 10, 10), (0, 10, 0), (0, 0, 0)])
UI Text objects are 2D UI text displays.
UIText(pos, color, text, font, size)
- Vector2 tuple
- The position of the UI object
UIText(pos = (0, 0))
- RBG float
- The color of the UI object
UIText(color = (0, 0, 0))
- String
- The text of the UI object
UIText(text = "WELCOME")
- String
- The font name of the UI object
UIText(font = "Sans Serif")
- Integer
- The font size of the UI object
UIText(size = 10)
UI objects have a hover bool variable, which determines if the mouse is over the UI object, for buttons and menus.
ui.hover
Example:
ui = UIPolygon(pos = (100, 100), color = (100, 100, 100))
if ui.hover:
ui.color = changeColor(ui.color, 10)
# if hovered, the button brightens
Physics Worlds are needed for object physics, as they determine the physics of the world.
PhysicsWorld(gravity, force)
- Float
- The gravity of the world
PhysicsWorld(gravity = 0.5)
- Vector3 tuple
- The force direction and power of the world
PhysicsWorld(force = (0, 10, 0))
Physics can be applied to objects using the physic variable.
Object(physic = ["softbody", "gravity"])
object.physic = ["softbody", "gravity"]
Some useful physics attributes:
"softbody" # adds softbody
"gravity" # adds gravity for falling
"collider" # adds a collider for collisions
"bounce" # adds bounce for feathery objects or softbody objects
"force" # adds force for moving objects
"weight" # adds weight for heavy objects
Object physics depend on Physics Worlds.
For an object's physics to work, the object's physics must be constantly updated through the use of the physics()
function:
while True:
object.physics()
Collisions and Colliders can be used in object physics for colliding objects or other collisions. Colliders are a physics attribute that can be applied to objects. Two objects must have colliders in order for them to collide.
Object(physic = ["collider"])
To create other events when two objects collide, the checkCollisions()
function checks the object's collisions with other objects, and returns a bool.
object.checkCollisions(otherObject)
Mesh Tools are a collection of tools used for modifying meshes inside of Pyn. It can be used to create ocean meshes, animated meshes, mountain meshes, and house meshes. The Pyn Mesh Tools Library maximizes the usefulness of Pyn, and lets you create incredible creations with Pyn.
Mesh Tools Library
object.rotate(X, Y, Z)
object.move(X, Y, Z)
object.place(X, Y, Z)
object.scale(X, Y, Z)
object.moveFace(face, X, Y, Z)
- Face index
- The face index of the face to move
object.moveFace(face = 0)
object.rotateFace(face, X, Y, Z)
- Face index
- The face index of the face to rotate
object.rotateFace(face = 0)
object.scaleFace(face, X, Y, Z)
- Face index
- The face index of the face to scale
object.scaleFace(face = 0)
object.extrude(face, X, Y, Z)
- Face index
- The face index of the face to extrude
object.extrude(face = 0)
object.deleteFace(face, X, Y, Z)
- Face index
- The face index of the face to delete
object.deleteFace(face = 0)
object.moveVertex(vert, X, Y, Z)
- Vertex index
- The vertex index of the vertex to move
object.moveVertex(vert = 0)
- Subdivides the face
object.subdivide(face)
- Face index
- The face index of the face to subdivide
object.subdivide(face = 0)
- Pixelates the face
object.pixelate(face)
- Face index
- The face index of the face to pixelate
object.pixelate(face = 0)
- Displaces the face
object.displace(face, amount, damping)
- Face index
- The face index of the face to displace
object.displace(face = 0)
- Integer
- The amount to displace
object.displace(amount = 10)
- Integer
- The amount to damp from the displacement
object.displace(damping = 100)
Particle Systems create particles for smoke effects, explosions, and more.
ParticleSystem(obj, pos, spread, interval, movement)
- Object
- The object to clone for particles
ParticleSystem(obj = cube)
- Vector3 tuple
- The position of the Particle System
ParticleSystem(pos = (0, 0, 0))
- Integer
- The spread of the particles in the Particle System
ParticleSystem(spread = 10)
- Integer
- Wait between summoning of particles
ParticleSystem(interval = 10)
- Integer
- Speed of particle movement
ParticleSystem(movement = 10)
- Updates the Particle System
particles.step()
- Clears the particles in the Particle System
particles.clear()
Pyn Meshes are a specific file type, which can store mesh data and other properties of a mesh.
myMesh.pyn
To open and download Pyn Meshes, use the open()
and download()
functions.
open(file)
# open a Pyn Mesh through a .pyn file
download(name, obj)
# download a Pyn Mesh as the name and object
Now go try it yourself or try a project!
Download the source
pip install git+https://github.com/underpig1/Pyn3D#egg=Pyn3D