8000 GitHub - underpig1/Pyn3D: A Python 3D Game Engine and Renderer - With Mesh Tools
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

underpig1/Pyn3D

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

Pyn3D

A Python 3D Game Engine and Renderer - Now With Mesh Tools

What Is Pyn?

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

Documentation

Contents


Introduction to Pyn

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.

Getting Started

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

Init

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.

Mouse

The Mouse object is needed to determine the properties and position of the mouse or cursor.

Mouse(pos, visible, lock, cursor)
Position:
  • Vector2 tuple
  • The starting position of the cursor
Mouse(pos = (0, 0))
Visible:
  • 0 or 1 integer
  • Visibility of the cursor
Mouse(visible = 0)
Lock:
  • 0 or 1 integer
  • Locks cursor to window
Mouse(lock = 1)
Cursor:
  • Pygame cursor
  • Cursor display
Mouse(cursor = pygame.cursors.arrow)

Window

The window() function updates the window to your specifications.

window(camera, background, light)
Camera:
  • Camera object
  • Camera perspective displayed in the window
window(camera = cam)
Background:
  • RGB tuple
  • Background color of the window
window(background = (255, 255, 255))
Light:
  • Bool
  • Determines whether the background color is affected by Light objects
window(light = True)

Camera

Cameras are needed in Pyn programs for visualization.

Camera(pos, rot, fly, fixed, spd)
Position:
  • Vector3 tuple
  • The position of the camera
Camera(pos = (0, 0, -5))
Rotation:
  • Vector2 tuple
  • The rotation of the camera
Camera(rot = (0, 0))
Flight:
  • Bool
  • If the camera can fly using Q and E keys
Camera(fly = False)
Fixed:
  • Bool
  • If the camera cannot move using W, A, S, and D keys
Camera(fixed = False)
Speed:
  • Float
  • Speed of the camera when moving
Camera(spd = 0.5)
Bounding Box:
  • 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)]
Check Collisions:
  • Object
  • Checks collisions with other object
cam.checkCollisions(cube)

Objects

Objects are empty 3D objects which can be used for displaying visuals.

Object(pos, size, material, parent, physic)
Position:
  • Vector3 tuple
  • The position of the object
Object(pos = (0, 0, -5))
Size:
  • Float
  • The size of the object
Object(size = 5)
Material:
  • Material object index
  • The size of the object
Object(material = 0)
Parent:
  • Parent object
  • The parent of the object
Object(parent = cam)
Physic:
  • Physic list
  • The physics properties of the object
Object(physics = ["softbody", "gravity", "collider"])
Check Collisions:
  • Object
  • Checks collisions with other object
object.checkCollisions(cube)
Rotate:
  • X, Y, Z floats
  • Rotates object
object.rotate((10, 10, 10))
Move:
  • X, Y, Z floats
  • Moves object
object.move(0, 10, 0)
Place:
  • X, Y, Z floats
  • Places object
object.place(0, 0, 10)
Scale:
  • X, Y, Z floats
  • Scales object
object.scale(10, 0, 0)

Meshes

Meshes are pre-built meshes which come with Pyn and already-made coordinates.

Some pre-made meshes:

Cube()
Plane()
Point()
Line()
Circle()

Polygons

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

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

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.

Position:
  • Vector3 tuple
  • The position of the object
Light(pos = (0, 0, 0))
Strength:
  • Integer
  • The strength of the light
Light(strength = 10)

Materials

Materials are objects for materializing meshes.

Material(color, emmission)

Materials can then be assigned to meshes.

Color:
  • RBG float
  • The color of the material
Light(color = (0, 0, 0))
Emmision:
  • Integer
  • The emission factor of the material
Light(emmission = 1)

Texturing

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

Image Textures are texture objects for texturing meshes using images.

Texture(path)
Path:
  • String
  • The path of the image
Texture(path = "myImage.png")

Map Textures

Map Textures are texture objects based on a pixel map.

Texture()

Map textures can also be based on image textures.

Pixmap:
  • List of RGB tuples
  • The pixel map of the texture
texture.pixmap = [(0, 0, 0), (10, 10, 10), (0, 0, 0), (10, 10, 10)]

Using Materials

Materials can be assigned though meshes' material variable.

myMaterial = Material(color = (0, 10, 0), emmision = 10)
Object(material = myMaterial)

Change Color

The changeColor() function brightens or darkens a color.

changeColor(rgb, scale)
RGB:
  • RBG float
  • The color of the UI object
changeColor(rgb = (100, 100, 100))
Scale:
  • Integer
  • Amount to darken or lighten
changeColor(scale = 10)

UI

UI objects are displayed on top of the graphics for 2D menus, buttons, and more.

UI(pos)
Position:
  • Vector2 tuple
  • The position of the UI object
UI(pos = (0, 0))
Move:
  • X, Y, Z floats
  • Moves the UI object
ui.move(10, 10, 10)

UI Polygons

UI Polygons are 2D UI polygons.

UIPolygon(pos, color, points)
Position:
  • Vector2 tuple
  • The position of the UI object
UIPolygon(pos = (0, 0))
Color:
  • RBG float
  • The color of the UI object
UIPolygon(color = (0, 0, 0))
Points:
  • 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

UI Text objects are 2D UI text displays.

UIText(pos, color, text, font, size)
Position:
  • Vector2 tuple
  • The position of the UI object
UIText(pos = (0, 0))
Color:
  • RBG float
  • The color of the UI object
UIText(color = (0, 0, 0))
Text:
  • String
  • The text of the UI object
UIText(text = "WELCOME")
Font:
  • String
  • The font name of the UI object
UIText(font = "Sans Serif")
Size:
  • Integer
  • The font size of the UI object
UIText(size = 10)

Hover

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 World

Physics Worlds are needed for object physics, as they determine the physics of the world.

PhysicsWorld(gravity, force)
Gravity:
  • Float
  • The gravity of the world
PhysicsWorld(gravity = 0.5)
Force:
  • Vector3 tuple
  • The force direction and power of the world
PhysicsWorld(force = (0, 10, 0))

Physics

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

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

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 Tools

Rotate

object.rotate(X, Y, Z)

Move

object.move(X, Y, Z)

Place

object.place(X, Y, Z)

Scale

object.scale(X, Y, Z)

Face Tools

Move Face

object.moveFace(face, X, Y, Z)
Face:
  • Face index
  • The face index of the face to move
object.moveFace(face = 0)

Rotate Face

object.rotateFace(face, X, Y, Z)
Face:
  • Face index
  • The face index of the face to rotate
object.rotateFace(face = 0)

Scale Face

object.scaleFace(face, X, Y, Z)
Face:
  • Face index
  • The face index of the face to scale
object.scaleFace(face = 0)

Extrude

object.extrude(face, X, Y, Z)
Face:
  • Face index
  • The face index of the face to extrude
object.extrude(face = 0)

Delete Face

object.deleteFace(face, X, Y, Z)
Face:
  • Face index
  • The face index of the face to delete
object.deleteFace(face = 0)

Vertex Tools

Move Vertex

object.moveVertex(vert, X, Y, Z)
Vert:
  • Vertex index
  • The vertex index of the vertex to move
object.moveVertex(vert = 0)

Advanced Tools

Subdivide

  • Subdivides the face
object.subdivide(face)
Face:
  • Face index
  • The face index of the face to subdivide
object.subdivide(face = 0)

Pixelate

  • Pixelates the face
object.pixelate(face)
Face:
  • Face index
  • The face index of the face to pixelate
object.pixelate(face = 0)

Displace

  • Displaces the face
object.displace(face, amount, damping)
Face:
  • Face index
  • The face index of the face to displace
object.displace(face = 0)
Amount:
  • Integer
  • The amount to displace
object.displace(amount = 10)
Damping:
  • Integer
  • The amount to damp from the displacement
object.displace(damping = 100)

Particle Systems

Particle Systems create particles for smoke effects, explosions, and more.

ParticleSystem(obj, pos, spread, interval, movement)
Object:
  • Object
  • The object to clone for particles
ParticleSystem(obj = cube)
Position:
  • Vector3 tuple
  • The position of the Particle System
ParticleSystem(pos = (0, 0, 0))
Spread:
  • Integer
  • The spread of the particles in the Particle System
ParticleSystem(spread = 10)
Interval:
  • Integer
  • Wait between summoning of particles
ParticleSystem(interval = 10)
Movement:
  • Integer
  • Speed of particle movement
ParticleSystem(movement = 10)
Step:
  • Updates the Particle System
particles.step()
Clear:
  • Clears the particles in the Particle System
particles.clear()

Pyn Meshes

Pyn Meshes are a specific file type, which can store mesh data and other properties of a mesh.

myMesh.pyn

Open and Download

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

Congratulations!

You made it to the end of the documentation!


Download the source
Install through pip:
pip install git+https://github.com/underpig1/Pyn3D#egg=Pyn3D

About

A Python 3D Game Engine and Renderer - With Mesh Tools

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0