Skip to content

Commit

Permalink
Merge branch 'develop' as 1.3 (alpha)
Browse files Browse the repository at this point in the history
  • Loading branch information
paddywwoof committed Sep 19, 2013
2 parents 8497e1c + ac30f19 commit 5295eb2
Show file tree
Hide file tree
Showing 22 changed files with 367 additions and 300 deletions.
8 changes: 8 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ Tim Skillman, Patrick Gaunt, Tom Ritchford

Date Amends

v1.3
2013-19-06 Memory leak with Textures reappeared and fixed. Bug in Pillow
looks like it will not be fixed for 2.2.0 so added a hack to
Font. LodSprite allows segmentation of a simple plane for
texture sampling in the vertex shader. Additional Textures can
be passed to PostProcess __init__ for use by filter shaders.
Additional filters added to pi3d_demos

v1.2
2013-09-06 PostProcess added to allow effect shaders to be applied to
a rendered scene. OffScreenTexture system streamlined to take
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pi3d/shape/EnvironmentCube.py
pi3d/shape/Extrude.py
pi3d/shape/Helix.py
pi3d/shape/Lathe.py
pi3d/shape/LodSprite.py
pi3d/shape/MergeShape.py
pi3d/shape/Model.py
pi3d/shape/Plane.py
Expand Down
Empty file removed __init__.py
Empty file.
21 changes: 2 additions & 19 deletions pi3d/Display.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ def loop_running(self):
def resize(self, x=0, y=0, w=0, h=0):
"""Reshape the window with the given coordinates."""
if w <= 0:
w = display.max_width
w = self.max_width
if h <= 0:
h = display.max_height
h = self.max_height
self.width = w
self.height = h

Expand Down Expand Up @@ -424,23 +424,6 @@ def update(self):
display.mouse = Mouse(width=w, height=h, restrict=False)
display.mouse.start()

# This code now replaced by camera 'lens'
# opengles.glMatrixMode(GL_PROJECTION)
# Utility.load_identity()
# if is_3d:
# hht = near * math.tan(math.radians(aspect / 2.0))
# hwd = hht * w / h
# opengles.glFrustumf(c_float(-hwd), c_float(hwd), c_float(-hht), c_float(hht),
# c_float(near), c_float(far))
# opengles.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
# else:
# opengles.glOrthof(c_float(0), c_float(w), c_float(0), c_float(h),
# c_float(near), c_float(far))

#opengles.glMatrixMode(GL_MODELVIEW)
#Utility.load_identity()


if background:
display.set_background(*background)

Expand Down
11 changes: 0 additions & 11 deletions pi3d/Shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,17 +585,6 @@ def rotateIncZ(self, v):
self.roz[1, 0] = -s
self.MFlg = True

def _add_vertex(self, vert, norm, texc):
"""add vertex,normal and tex_coords ..."""
self.verts.append(vert)
self.norms.append(norm)
self.texcoords.append(texc)


def _add_tri(self, indx):
"""add triangle refs."""
self.inds.append(indx)

def _lathe(self, path, sides=12, rise=0.0, loops=1.0):
"""Returns a Buffer object by rotating the points defined in path.
Expand Down
44 changes: 25 additions & 19 deletions pi3d/Texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
from pi3d.util.Ctypes import c_ints
from pi3d.util.Loadable import Loadable

MAX_SIZE = 1024
MAX_SIZE = 1920
DEFER_TEXTURE_LOADING = True
WIDTHS = [4, 8, 16, 32, 48, 64, 72, 96, 128, 144, 192, 256,
288, 384, 512, 576, 640, 720, 768, 800, 960, 1024]
288, 384, 512, 576, 640, 720, 768, 800, 960, 1024, 1080, 1920]

def round_up_to_power_of_2(x):
p = 1
Expand Down Expand Up @@ -71,12 +71,13 @@ def __init__(self, file_string, blend=False, flip=False, size=0,

def __del__(self):
super(Texture, self).__del__()
if not self.opengl_loaded:
return True
from pi3d.Display import Display
if Display.INSTANCE:
Display.INSTANCE.textures_dict[str(self._tex)][1] = 1
Display.INSTANCE.tidy_needed = True
try:
from pi3d.Display import Display
if Display.INSTANCE:
Display.INSTANCE.textures_dict[str(self._tex)][1] = 1
Display.INSTANCE.tidy_needed = True
except:
print("couldn't set to delete") #TODO debug messages here

def tex(self):
"""do the deferred opengl work and return texture"""
Expand Down Expand Up @@ -128,7 +129,7 @@ def _load_disk(self):

def _load_opengl(self):
"""overrides method of Loadable"""
opengles.glGenTextures(1, ctypes.byref(self._tex), 0)
opengles.glGenTextures(4, ctypes.byref(self._tex), 0)
from pi3d.Display import Display
if Display.INSTANCE:
Display.INSTANCE.textures_dict[str(self._tex)] = [self._tex, 0]
Expand All @@ -137,19 +138,24 @@ def _load_opengl(self):
opengles.glTexImage2D(GL_TEXTURE_2D, 0, RGBv, self.ix, self.iy, 0, RGBv,
GL_UNSIGNED_BYTE,
ctypes.string_at(self.image, len(self.image)))
opengles.glEnable(GL_TEXTURE_2D)
opengles.glGenerateMipmap(GL_TEXTURE_2D)
opengles.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
if self.mipmap:
opengles.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
ctypes.c_float(GL_LINEAR_MIPMAP_NEAREST))
opengles.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
ctypes.c_float(GL_LINEAR_MIPMAP_NEAREST))
opengles.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_NEAREST)
opengles.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_LINEAR)
else:
opengles.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
ctypes.c_float(GL_NEAREST))
opengles.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
ctypes.c_float(GL_NEAREST))
opengles.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST)
opengles.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_NEAREST)
opengles.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
GL_MIRRORED_REPEAT)
opengles.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
GL_MIRRORED_REPEAT)

opengles.glGenerateMipmap(GL_TEXTURE_2D)
opengles.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

def _unload_opengl(self):
"""clear it out"""
Expand Down
1 change: 1 addition & 0 deletions pi3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from pi3d.shape.Extrude import Extrude
from pi3d.shape.Helix import Helix
from pi3d.shape.Lathe import Lathe
from pi3d.shape.LodSprite import LodSprite
from pi3d.shape.MergeShape import MergeShape
from pi3d.shape.Model import Model
from pi3d.shape.Plane import Plane
Expand Down
2 changes: 1 addition & 1 deletion pi3d/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pi3d.constants contains constant values, mainly integers, from OpenGL ES 2.0.
"""

VERSION = '1.0'
VERSION = '1.3'

STARTUP_MESSAGE = """
Expand Down
1 change: 1 addition & 0 deletions pi3d/shaders/post_base.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ varying vec2 texcoordout;
uniform sampler2D tex0;
uniform vec3 unif[20];
//uniform vec3 custom use ==> unif[16] to unif[19]
//in this example unif[16][0] is used to alter the sampling distance

void main(void) {
///////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion pi3d/shaders/post_base.vs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ varying float dist;

void main(void) {
texcoordout = texcoord * unib[2].xy + unib[3].xy;
texcoordout.y = -texcoordout.y;
texcoordout.y = 1.0 - texcoordout.y;
gl_Position = modelviewmatrix[1] * vec4(vertex,1.0);
}
12 changes: 7 additions & 5 deletions pi3d/shape/Disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ def __init__(self, camera=None, light=None, radius=1, sides=12, name="", x=0.0,

st = 2 * pi / sides
for j in range(-1, 1):
self._add_vertex((0.0, -0.1*j, 0.0), (0.0, -j, 0.0), (0.5, 0.5))
self.verts.append((0.0, -0.1*j, 0.0))
self.norms.append((0.0, -j, 0.0))
self.texcoords.append((0.5, 0.5))
for r in range(sides+1):
ca, sa = Utility.from_polar_rad(r * st)
self._add_vertex((radius * sa, 0.0, radius * ca),
(0.0, -j - 0.1*j, 0.0), (sa * 0.5 + 0.5, ca * 0.5 + 0.5))
self.verts.append((radius * sa, 0.0, radius * ca))
self.norms.append((0.0, -j - 0.1*j, 0.0))
self.texcoords.append((sa * 0.5 + 0.5, ca * 0.5 + 0.5))
if j == -1:
v0, v1, v2 = 0, 1, 2
else:
v0, v1, v2 = sides + 2, sides + 4, sides + 3 # i.e. reverse direction to show on back
for r in range(sides):
self._add_tri((v0, r + v1, r + v2))
self.inds.append((v0, r + v1, r + v2))

self.but = []
self.buf.append(Buffer(self, self.verts, self.texcoords, self.inds, self.norms))

5 changes: 2 additions & 3 deletions pi3d/shape/ElevationMap.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ def clashTest(self, px, py, pz, rad):
minLoc = (i, j)
#now find the distance between the point and the plane perpendicular
#to the normal at this vertex
pDist = Utility.dotproduct((px - vertp[0]), (py - vertp[1]), (pz - vertp[2]),
-normp[0], -normp[1], -normp[2])
pDist = dot([px - vertp[0], py - vertp[1], pz - vertp[2]],
[-normp[0], -normp[1], -normp[2]])
#and the position where the normal from point crosses the plane
xIsect = px - normp[0]*pDist
zIsect = pz - normp[2]*pDist
Expand Down Expand Up @@ -341,7 +341,6 @@ def intersect_triangle(v1, v2, v3, pos):
tuple (x,y,z) defining the x,z of the vertical line intersecting triangle
"""
#calc normal from two edge vectors v2-v1 and v3-v1
#nVec = Utility.crossproduct(v2[0]-v1[0], v2[1]-v1[1], v2[2]-v1[2], v3[0]-v1[0], v3[1]-v1[1], v3[2]-v1[2])
nVec = cross(subtract(v2, v1), subtract(v3, v1))
#equation of plane: Ax + By + Cz = kVal where A,B,C are components of normal. x,y,z for point v1 to find kVal
kVal = dot(nVec,v1)
Expand Down
60 changes: 60 additions & 0 deletions pi3d/shape/LodSprite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from pi3d.constants import *
from pi3d.Texture import Texture
from pi3d.Buffer import Buffer
from pi3d.Shape import Shape

class LodSprite(Shape):
""" 3d model inherits from Shape, differs from Plane in being single sided"""
def __init__(self, camera=None, light=None, w=1.0, h=1.0, name="",
x=0.0, y=0.0, z=20.0,
rx=0.0, ry=0.0, rz=0.0,
sx=1.0, sy=1.0, sz=1.0,
cx=0.0, cy=0.0, cz=0.0, n=1):
"""Uses standard constructor for Shape. Extra Keyword arguments:
*w*
Width.
*h*
Height.
"""
super(LodSprite, self).__init__(camera, light, name, x, y, z, rx, ry, rz,
sx, sy, sz, cx, cy, cz)
self.width = w
self.height = h
self.ttype = GL_TRIANGLES
self.verts = []
self.norms = []
self.texcoords = []
self.inds = []

ww = w / 2.0
hh = h / 2.0

for a in range(n):
j = float(a)
for b in range(n):
i = float(b)
c = [[i / n, (n - j) / n],
[(i + 1.0) / n, (n - j) / n],
[(i + 1.0) / n, (n - 1.0 - j) / n],
[i / n, (n - 1.0 - j) / n]]
self.verts.extend([[-ww + c[0][0] * w, -hh + c[0][1] * h, 0.0],
[-ww + c[1][0] * w, -hh + c[1][1] * h, 0.0],
[-ww + c[2][0] * w, -hh + c[2][1] * h, 0.0],
[-ww + c[3][0] * w, -hh + c[3][1] * h, 0.0]])
self.norms.extend([[0.0, 0.0, -1.0],
[0.0, 0.0, -1.0],
[0.0, 0.0, -1.0],
[0.0, 0.0, -1.0]])
self.texcoords.extend([[c[0][0], 1.0 - c[0][1]],
[c[1][0], 1.0 - c[1][1]],
[c[2][0], 1.0 - c[2][1]],
[c[3][0], 1.0 - c[3][1]]])
tri_n = (a * n + b) * 4 # integers
self.inds.extend([[tri_n , tri_n + 1, tri_n + 3],
[tri_n + 1, tri_n + 2, tri_n + 3]])
self.buf = []
self.buf.append(Buffer(self, self.verts, self.texcoords, self.inds, self.norms))

def repaint(self, t):
self.draw()
3 changes: 0 additions & 3 deletions pi3d/shape/Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@ def __init__(self, camera=None, light=None, file_string=None,

if self.exf == 'egg':
self.model = loaderEgg.loadFileEGG(self, file_string)
return self.model
elif self.exf == 'obj':
self.model = loaderObj.loadFileOBJ(self, file_string)
return self.model
else:
print(self.exf, "file not supported")
return None

def clone(self, camera = None, light = None):
"""create a new Model but buf points to same array of Buffers
Expand Down
9 changes: 4 additions & 5 deletions pi3d/sprite/Ball.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pi3d.Display import Display
from pi3d.util import Utility
from numpy import dot

from pi3d.shape.Sprite import ImageSprite

Expand Down Expand Up @@ -34,7 +34,7 @@ def hit(self, otherball):
dx = (self.unif[0] + self.vx) - (otherball.unif[0] + otherball.vx)
dy = (self.unif[1] + self.vy) - (otherball.unif[1] + otherball.vy)
rd = self.radius + otherball.radius
return Utility.sqsum(dx, dy) <= (rd * rd)
return dot(dx, dy) < (rd * rd)

def bounce_collision(self, otherball):
"""work out resultant velocities using 17th.C phsyics"""
Expand All @@ -43,9 +43,8 @@ def bounce_collision(self, otherball):
dy = self.unif[1] - otherball.unif[1]
rd = self.radius + otherball.radius
# check sign of a.b to see if converging
dotP = Utility.dotproduct(dx, dy, 0,
(self.vx - otherball.vx),
(self.vy - otherball.vy), 0)
dotP = dot([dx, dy, 0.0],
[self.vx - otherball.vx, self.vy - otherball.vy, 0.0])
if dx * dx + dy * dy <= rd * rd and dotP < 0:
R = otherball.mass / self.mass #ratio of masses
"""Glancing angle for equating angular momentum before and after collision.
Expand Down
9 changes: 4 additions & 5 deletions pi3d/sprite/Ball_2d.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import ctypes
from numpy import dot

from pi3d.constants import *

from pi3d.Display import Display
from pi3d.util import Utility

class Ball_2d(object):
""" This class is used to take some of the functionality of the CollisionBalls
Expand Down Expand Up @@ -36,7 +36,7 @@ def hit(self, otherball):
dx = (self.x + self.vx) - (otherball.x + otherball.vx)
dy = (self.y + self.vy) - (otherball.y + otherball.vy)
rd = self.radius + otherball.radius
return Utility.sqsum(dx, dy) <= (rd * rd)
return dot(dx, dy) <= (rd * rd)

def bounce_collision(self, otherball):
"""work out resultant velocities using 17th.C phsyics"""
Expand All @@ -45,9 +45,8 @@ def bounce_collision(self, otherball):
dy = self.y - otherball.y
rd = self.radius + otherball.radius
# check sign of a.b to see if converging
dotP = Utility.dotproduct(dx, dy, 0,
(self.vx - otherball.vx),
(self.vy - otherball.vy), 0)
dotP = dot([dx, dy, 0],
[self.vx - otherball.vx, self.vy - otherball.vy, 0])
if dx * dx + dy * dy <= rd * rd and dotP < 0:
R = otherball.mass / self.mass #ratio of masses
"""Glancing angle for equating angular momentum before and after collision.
Expand Down
Loading

0 comments on commit 5295eb2

Please sign in to comment.