Author: ArcRiley
Date: 2008-03-20 03:35:51 -0400 (Thu, 20 Mar 2008)
New Revision: 1187

Added:
   trunk/pysoy/examples/BumpBlocks.py
   trunk/pysoy/examples/broken/bumpmap_example.py
   trunk/pysoy/examples/bumpblocks.py
Removed:
   trunk/pysoy/examples/bumpmap_example.py
Log:
Ticket #936 :
  * moving broken bumpmap_example to broken/ (I don't know why it's broken!)
  * created new BumpBlocks example
  * currently using forked blocks.py - bumpblocks.py should be merged
  * broken texcoord/normal/tangent calculation must be fixed


Added: trunk/pysoy/examples/BumpBlocks.py
===================================================================
--- trunk/pysoy/examples/BumpBlocks.py                          (rev 0)
+++ trunk/pysoy/examples/BumpBlocks.py  2008-03-20 07:35:51 UTC (rev 1187)
@@ -0,0 +1,70 @@
+#!/usr/bin/env python
+import soy
+import bumpblocks
+from time import sleep
+
+sce = soy.scenes.Scene()
+cam = soy.bodies.Camera(sce)
+cam.position = (0.0, 0.0, 3.0)
+lig = soy.bodies.Light(sce)
+lig.position = (-5.0,5.0,5.0)
+bks = bumpblocks.blocks(sce)
+fps = soy.textures.Print()
+
+scr = soy.Screen()
+win = soy.Window(scr, 'CollideBlocks', background=soy.colors.gray)
+pro = soy.widgets.Projector(win, camera=cam)
+can = soy.widgets.Canvas(win, texture=fps)
+
+def wireframeToggle() :
+  if cam.wireframe :
+    cam.wireframe = False
+  else :
+    cam.wireframe = True
+
+def fullscreenToggle() :
+  if scr.fullscreen :
+    scr.fullscreen = None
+  else :
+    scr.fullscreen = win
+
+def moreLight() :
+  lig.diffuse = lig.diffuse + 1.0
+  print lig.diffuse  
+
+def lessLight() :
+  lig.diffuse = lig.diffuse - 1.0
+  print lig.diffuse  
+
+key = soy.controllers.Keyboard(win)
+key['Q'] = soy.actions.Force(bks['Marble'], -100,    0,    0)
+key['R'] = soy.actions.Force(bks['Marble'],    0,  100,    0)
+key['S'] = soy.actions.Force(bks['Marble'],  100,    0,    0)
+key['T'] = soy.actions.Force(bks['Marble'],    0, -100,    0)
+key['U'] = soy.actions.Force(bks['Marble'],    0,    0, -100)
+key['V'] = soy.actions.Force(bks['Marble'],    0,    0,  100)
+key['q'] = soy.actions.Quit()
+key[ 1 ] = soy.actions.Quit() # 9 = esc key
+key['f'] = fullscreenToggle
+key['w'] = wireframeToggle
+key['['] = lessLight
+key[']'] = moreLight
+wcn = soy.controllers.Window(win)
+wcn['close'] = soy.actions.Quit()
+
+if __name__ == '__main__' :
+  while True:
+    sleep(.1)
+    fps.text = '%sfps' % str(int(cam.fps)).zfill(4)
+    for bk in bks :
+      p = bks[bk].position
+      v = bks[bk].velocity
+      v = [v[0], v[1], v[2]]
+      if abs(p[0]) > 5 and ((p[0]>0 and v[0]>0) or (p[0]<0 and v[0]< 0)) : 
+        v[0] = v[0]*-1
+      if abs(p[1]) > 5 and ((p[1]>0 and v[1]>0) or (p[1]<0 and v[1]< 0)) : 
+        v[1] = v[1]*-1
+      if abs(p[2]) > 5 and ((p[2]>0 and v[2]>0) or (p[2]<0 and v[2]< 0)) : 
+        v[2] = v[2]*-1
+      bks[bk].velocity = v
+


Property changes on: trunk/pysoy/examples/BumpBlocks.py
___________________________________________________________________
Name: svn:executable
   + *

Copied: trunk/pysoy/examples/broken/bumpmap_example.py (from rev 1186, 
trunk/pysoy/examples/bumpmap_example.py)
===================================================================
--- trunk/pysoy/examples/broken/bumpmap_example.py                              
(rev 0)
+++ trunk/pysoy/examples/broken/bumpmap_example.py      2008-03-20 07:35:51 UTC 
(rev 1187)
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+
+import soy
+import cmath
+from time import sleep, time
+
+V = soy.atoms.Vertex
+F = soy.atoms.Face
+
+def calculate_trig_normal(v1,v2,v3):
+  v_1 = (v2[0]-v1[0], v2[1]-v1[1], v2[2]-v1[2])
+  v_2 = (v3[0]-v1[0], v3[1]-v1[1], v3[2]-v1[2])
+  cross_a = (v_1[1] * v_2[2] - v_1[2] * v_2[1],
+             v_1[2] * v_2[0] - v_1[0] * v_2[2],
+             v_1[0] * v_2[1] - v_1[1] * v_2[0])
+  lgt = abs( cmath.sqrt( cross_a[0]**2 + cross_a[1]**2 + cross_a[2]**2))
+  return (cross_a[0] / lgt, cross_a[1]  / lgt, cross_a[2] / lgt)
+
+def create_quad_mesh(mat):
+  mesh = soy.models.Mesh(material=mat)
+
+  scale=1
+
+  quad_vertices = [
+    ( 1*scale, 1*scale, 0),
+    ( 1*scale,-1*scale, 0),
+    (-1*scale,-1*scale, 0),
+    (-1*scale, 1*scale, 0)]
+  quad_faces = [
+    (0,1,2),
+    (2,3,0)]
+
+  V1 = lambda x,y : V(mesh, position=x, normal=y, texcoord=x, tangent=(0,1,0))
+  F1 = lambda x : F(mesh, verts=x, material=mat)
+
+  for f in quad_faces:
+    v1 = quad_vertices[ f[0] ]
+    v2 = quad_vertices[ f[1] ]
+    v3 = quad_vertices[ f[2] ]
+    n = calculate_trig_normal(v1,v2,v3)
+
+    vv1 = V1(v1,n)
+    vv2 = V1(v2,n)
+    vv3 = V1(v3,n)
+
+    face = F1([vv1,vv3,vv2])
+
+  return mesh
+    
+
+def main():
+  sce = soy.scenes.Scene()
+
+  cam = soy.bodies.Camera(sce)
+  cam.position = (0.0, 0.0, 15.0)
+    
+  lig = soy.bodies.Light(sce)
+  lig.position = (-5, -5, -5)
+
+  #decal_tex = soy.transports.File('media/decal.soy')['gimp']
+  #normal_tex = soy.transports.File('media/normal_map.soy')['gimp']
+  decal_tex = soy.transports.File('media/marble.soy')['gimp']
+  normal_tex = soy.transports.File('media/fieldstone-dot3.soy')['gimp']
+  decal_mat = soy.materials.Material(diffuse=soy.colors.blue)
+  #decal_mat.normal = normal_tex
+  #print decal_mat.color
+
+  test_mesh = create_quad_mesh(decal_mat)
+  test_mesh_b = soy.bodies.Body(sce, mesh=test_mesh)
+  test_mesh_b.rotation = (4.0,.0,1)
+
+  scr = soy.Screen()
+  win = soy.Window(scr, title='Bumpmap example', 
+                   size = (1024,768), background=soy.colors.gray)
+  pro = soy.widgets.Projector(win, camera=cam)
+
+  key = soy.controllers.Keyboard(win)
+  key[ 1 ] = soy.actions.Quit()
+
+  wcn = soy.controllers.Window(win)
+  wcn['close'] = soy.actions.Quit()
+
+  while True:
+    sleep(0.3)
+    #lig.position = (20*abs(cmath.sin(time())) - 10, 1, -2)
+    #test_mesh_b.position = (10*abs(cmath.sin( time()))- 6, 10*abs(cmath.sin( 
time()))- 6, 2)
+
+if __name__=='__main__':
+  main()

Added: trunk/pysoy/examples/bumpblocks.py
===================================================================
--- trunk/pysoy/examples/bumpblocks.py                          (rev 0)
+++ trunk/pysoy/examples/bumpblocks.py  2008-03-20 07:35:51 UTC (rev 1187)
@@ -0,0 +1,94 @@
+import soy
+from random import random
+
+mrbl = soy.transports.File('media/marble.soy')['gimp']
+dot3 = soy.transports.File('media/fieldstone-dot3.soy')['gimp']
+
+
+class BlockMesh(soy.models.Mesh) :
+  def __init__(self, mycol) :
+    black = soy.materials.Material()
+    black.ambient = soy.colors.black
+    black.diffuse = soy.colors.Color('#222')
+    black.specular= soy.colors.Color('#222')
+    black.shininess = 5.0
+    black.normal = dot3
+    Vert = VertexGroup(self)
+
+    # Create Faces
+    # 2 Halves
+    for a in (1.0, -1.0) :
+      # 3 Sides in each half
+      for b in (0, 1, 2) :
+        # 4 Quarters in each side
+        for c in (1.0, -1.0) :
+          for d in (1.0, -1.0) :
+            if a*c*d > 0 :
+              material = mycol
+            else :
+              material = black
+            points = (Vert(b, (.500*a, .000*c, .000*d), (a, 0, 0)),    # 0
+                      Vert(b, (.500*a, .000*c, .450*d), (a, 0, 0)),    # 1
+                      Vert(b, (.500*a, .450*c, .450*d), (a, 0, 0)),    # 2
+                      Vert(b, (.500*a, .450*c, .000*d), (a, 0, 0)),    # 3
+                      Vert(b, (.485*a, .485*c, .000*d), (.7071070*a,   # 4
+                                                         .7071070*c, 0)),
+                      Vert(b, (.485*a, .485*c, .450*d), (.7071070*a,   # 5
+                                                         .7071070*c, 0)),
+                      Vert(b, (.475*a, .475*c, .475*d), (.5773503*a,   # 6
+                                                         .5773503*c, 
+                                                         .5773503*d)),
+                      Vert(b, (.485*a, .450*c, .485*d), (.7071070*a,   # 7
+                                                         0, .7071070*d)),
+                      Vert(b, (.485*a, .000*c, .485*d), (.7071070*a,   # 8
+                                                         0, .7071070*d)))
+            faces = ([points[0], points[1], points[2]],
+                     [points[0], points[2], points[3]],
+                     [points[2], points[4], points[3]],
+                     [points[2], points[5], points[4]],
+                     [points[2], points[6], points[5]],
+                     [points[2], points[7], points[6]],
+                     [points[2], points[8], points[7]],
+                     [points[2], points[1], points[8]])
+            for face in faces :
+              if a*c*d==1 :
+                face.reverse()
+              f = soy.atoms.Face(self, verts=face, material=material)
+
+
+class VertexGroup :
+  def __init__(self, mesh) :
+    self.verts = {}
+    self.mesh  = mesh
+
+  def __call__(self, shift, coord, normal) :
+    if   shift == 1 :
+      coord = (coord[1], coord[2], coord[0])
+      normal = (normal[1], normal[2], normal[0])
+    elif shift == 2 :
+      coord = (coord[2], coord[0], coord[1])
+      normal = (normal[2], normal[0], normal[1]) 
+    if not self.verts.has_key(coord) :
+      self.verts[coord] = soy.atoms.Vertex(self.mesh,
+                                           position=coord, texcoord=coord,
+                                           normal=normal, tangent=(0,1,0))
+    return self.verts[coord]
+
+def srand() :
+  return random()-.5
+
+def blocks(sce):
+  colors = {
+    'Marble'     : (soy.materials.Material(color=mrbl, normal=dot3), (0,0,0)),
+  }
+  blocks = {}
+  for color in colors :
+    blocks[color] = soy.bodies.Body(sce,
+                                    model=BlockMesh(colors[color][0]),
+                                    position=colors[color][1])
+    #blocks[color].rotation = (srand(), srand(), srand())
+    blocks[color].rotation = (0,0,1)
+    blocks[color].shape = soy.shapes.Box(1,1,1)
+    t = -0.5
+    blocks[color].velocity = (blocks[color].position[0] * t, 
blocks[color].position[1] * t, blocks[color].position[2] * t)
+  return blocks


Property changes on: trunk/pysoy/examples/bumpblocks.py
___________________________________________________________________
Name: svn:executable
   + *

Deleted: trunk/pysoy/examples/bumpmap_example.py
===================================================================
--- trunk/pysoy/examples/bumpmap_example.py     2008-03-20 07:25:17 UTC (rev 
1186)
+++ trunk/pysoy/examples/bumpmap_example.py     2008-03-20 07:35:51 UTC (rev 
1187)
@@ -1,89 +0,0 @@
-#!/usr/bin/env python
-
-import soy
-import cmath
-from time import sleep, time
-
-V = soy.atoms.Vertex
-F = soy.atoms.Face
-
-def calculate_trig_normal(v1,v2,v3):
-  v_1 = (v2[0]-v1[0], v2[1]-v1[1], v2[2]-v1[2])
-  v_2 = (v3[0]-v1[0], v3[1]-v1[1], v3[2]-v1[2])
-  cross_a = (v_1[1] * v_2[2] - v_1[2] * v_2[1],
-             v_1[2] * v_2[0] - v_1[0] * v_2[2],
-             v_1[0] * v_2[1] - v_1[1] * v_2[0])
-  lgt = abs( cmath.sqrt( cross_a[0]**2 + cross_a[1]**2 + cross_a[2]**2))
-  return (cross_a[0] / lgt, cross_a[1]  / lgt, cross_a[2] / lgt)
-
-def create_quad_mesh(mat):
-  mesh = soy.models.Mesh(material=mat)
-
-  scale=1
-
-  quad_vertices = [
-    ( 1*scale, 1*scale, 0),
-    ( 1*scale,-1*scale, 0),
-    (-1*scale,-1*scale, 0),
-    (-1*scale, 1*scale, 0)]
-  quad_faces = [
-    (0,1,2),
-    (2,3,0)]
-
-  V1 = lambda x,y : V(mesh, position=x, normal=y, texcoord=x, tangent=(0,1,0))
-  F1 = lambda x : F(mesh, verts=x, material=mat)
-
-  for f in quad_faces:
-    v1 = quad_vertices[ f[0] ]
-    v2 = quad_vertices[ f[1] ]
-    v3 = quad_vertices[ f[2] ]
-    n = calculate_trig_normal(v1,v2,v3)
-
-    vv1 = V1(v1,n)
-    vv2 = V1(v2,n)
-    vv3 = V1(v3,n)
-
-    face = F1([vv1,vv3,vv2])
-
-  return mesh
-    
-
-def main():
-  sce = soy.scenes.Scene()
-
-  cam = soy.bodies.Camera(sce)
-  cam.position = (0.0, 0.0, 15.0)
-    
-  lig = soy.bodies.Light(sce)
-  lig.position = (-5, -5, -5)
-
-  #decal_tex = soy.transports.File('media/decal.soy')['gimp']
-  #normal_tex = soy.transports.File('media/normal_map.soy')['gimp']
-  decal_tex = soy.transports.File('media/marble.soy')['gimp']
-  normal_tex = soy.transports.File('media/fieldstone-dot3.soy')['gimp']
-  decal_mat = soy.materials.Material(diffuse=soy.colors.blue)
-  #decal_mat.normal = normal_tex
-  #print decal_mat.color
-
-  test_mesh = create_quad_mesh(decal_mat)
-  test_mesh_b = soy.bodies.Body(sce, mesh=test_mesh)
-  test_mesh_b.rotation = (4.0,.0,1)
-
-  scr = soy.Screen()
-  win = soy.Window(scr, title='Bumpmap example', 
-                   size = (1024,768), background=soy.colors.gray)
-  pro = soy.widgets.Projector(win, camera=cam)
-
-  key = soy.controllers.Keyboard(win)
-  key[ 1 ] = soy.actions.Quit()
-
-  wcn = soy.controllers.Window(win)
-  wcn['close'] = soy.actions.Quit()
-
-  while True:
-    sleep(0.3)
-    #lig.position = (20*abs(cmath.sin(time())) - 10, 1, -2)
-    #test_mesh_b.position = (10*abs(cmath.sin( time()))- 6, 10*abs(cmath.sin( 
time()))- 6, 2)
-
-if __name__=='__main__':
-  main()

_______________________________________________
PySoy-SVN mailing list
PySoy-SVN@pysoy.org
http://www.pysoy.org/mailman/listinfo/pysoy-svn

Reply via email to