• Stars
    star
    108
  • Rank 319,466 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python 3D library.

three.py

Python 3D library

The aim of this project is to create an easy to use 3D library for Python.

This project was inspired by Three.js, and attempts to follow the effective and reliable class structure from that project whenever possible.

Three.py was originally designed for educational purposes, and rendering efficiency and optimization will occasionally be sacrificed for simplicity and clarity.

To see what the Three.py library is capable of, see the list of examples or watch the sample projects video.

Three.py video

This project was initially developed by Lee Stemkoski and Michael Pascale.

This project uses the MIT license.

Usage

Three.py uses the Python libraries PyGame, PyOpenGL, and NumPy.

The following code creates a scene, a camera, ambient and directional lights, and adds a light blue cube to the scene. It animates (spins) the cube, and allows the user to move the camera with first-person controls.

from core import *
from cameras import *
from lights import *
from geometry import *
from material import *

class TestCube(Base):
    
    def initialize(self):

        self.setWindowTitle('Cube')
        self.setWindowSize(800,600)

        self.renderer = Renderer()
        self.renderer.setViewportSize(800,600)
        self.renderer.setClearColor(0.25,0.25,0.25)
        
        self.scene = Scene()
        
        self.camera = PerspectiveCamera()
        self.camera.transform.setPosition(0, 1, 7)
        self.camera.transform.lookAt(0, 0, 0)
        self.cameraControls = FirstPersonController(self.input, self.camera)

        self.scene.add( AmbientLight(strength=0.25) )
        self.scene.add( DirectionalLight(direction=[-1,-1,-1]) )

        self.cube = Mesh( BoxGeometry(), SurfaceLightMaterial(color=[0.5,0.5,1.0]) )
        self.scene.add(self.cube)
        
    def update(self):
        
        self.cameraControls.update()

        if self.input.resize():
            size = self.input.getWindowSize()
            self.camera.setAspectRatio( size["width"]/size["height"] )
            self.renderer.setViewportSize(size["width"], size["height"])
                
        self.cube.transform.rotateX(0.02, Matrix.LOCAL)
        self.cube.transform.rotateY(0.03, Matrix.LOCAL)
        
        self.renderer.render(self.scene, self.camera)
                    
# instantiate and run the program
TestCube().run()

In case you are having difficulties related to versions of the dependencies (PyGame, PyOpenGL, NumPy), a pipenv pipfile is provided to set up a virtualenv. It can be used as follows:

pip install pipenv
pipenv install
pipenv shell
cd three.py
python TestAnimatedDayNight.py

More Repositories

1

stemkoski.github.com

JavaScript
1,777
star
2

AR-Examples

Augmented Reality examples for the web.
JavaScript
559
star
3

A-Frame-Examples

A collection of examples using the A-Frame library.
JavaScript
154
star
4

AR.js-examples

Examples using the AR.js library
JavaScript
61
star
5

HTML-Joysticks

Simple joystick-style controls with HTML/Javascript, supporting desktop/touchscreen and multiple joysticks.
HTML
35
star
6

VR-NES

NES emulation for VR
JavaScript
8
star
7

B.A.G.E.L.-Java

The Basic Adaptable Game Engine Library; code repository from video tutorial series.
Java
7
star
8

Graphics-Framework-Java

Developing a 3D graphics framework for Java with LWJGL and OpenGL.
Java
7
star
9

CubeWorld-AR

JavaScript
5
star
10

MathBox-Examples

MathBox examples
JavaScript
4
star
11

VR-AR-class-examples

Examples from Adelphi University's graduate VR/AR course (CSC 633)
JavaScript
4
star
12

BAGEL-Javascript

The Basic Adaptable Game Engine Library, written in JavaScript.
HTML
4
star
13

Geolocation

Testing Geolocation Functions
CSS
3
star
14

LibGDX-Jam

LibGDX game jam entry.
Java
3
star
15

Art-Gallery-Demo

Interactive Art Gallery.
HTML
3
star
16

MoleculeViewJS

A simple molecule visualization tool.
JavaScript
3
star
17

EMARI

Exploratory Mathematical and Artistic Rendering Interface
JavaScript
2
star
18

BAGEL-Java

B.A.G.E.L. (Basic Adaptable Game Engine Library) for Java
Java
2
star
19

Shadow-Experiments

a collection of examples building up to interactive 3D applications involving shadows
JavaScript
2
star
20

WebGL-experiments

running basic shader code in Javascript
HTML
2
star
21

Java-Graphics-Course-2022

Repository for Adelphi University course in Computer Graphics, Fall 2022 semester
Java
2
star
22

ThreeJS-Experiments

Some simple experiments with three.js.
JavaScript
2
star
23

BAGEL-Python

B.A.G.E.L. (Basic Adaptable Game Engine Library) for Python
Python
1
star
24

BAGEL-factory

JavaScript
1
star
25

GamepadJS

Experiments with the Gamepad API.
HTML
1
star
26

PythonTurtleControls

A keyboard-based interface for the Python turtle package.
Python
1
star
27

Arduboy

Games created for the Arduboy system.
Assembly
1
star
28

MusicJavascriptExamples

Examples of interactive music-themed webpages.
JavaScript
1
star