Author: ArcRiley
Date: 2008-05-20 03:30:51 -0400 (Tue, 20 May 2008)
New Revision: 1292

Added:
   trunk/pysoy/examples/RainbowBlocks.py
   trunk/pysoy/src/materials/Rainbow.pym
Modified:
   trunk/pysoy/src/materials/Textured.pym
   trunk/pysoy/src/materials/soy.materials.pyx
Log:
Ticket #955 :
  * this is sort of a joke, RainbowBlocks shows TSLVs via normalisation cubemap
  * not really a joke, as it shows how to build spiffy new materials!


Added: trunk/pysoy/examples/RainbowBlocks.py
===================================================================
--- trunk/pysoy/examples/RainbowBlocks.py                               (rev 0)
+++ trunk/pysoy/examples/RainbowBlocks.py       2008-05-20 07:30:51 UTC (rev 
1292)
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+import soy
+import blocks
+from time import sleep
+
+sce = soy.scenes.Scene()
+cam = soy.bodies.Camera(sce)
+cam.position = (0.0, 0.0, 15.0)
+lig = soy.bodies.Light(sce)
+lig.position = (-10.0,10.0,2.0)
+
+rbow = soy.materials.Rainbow()
+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
+colors = {
+  'Aventurine'     : (rbow, black, ( 0, 0, 0)),
+  'Basalt'         : (rbow, black, ( 4,-1,-4)),
+  'Copper'         : (rbow, black, (-3,-2,-2)),
+  'CopperSulfate'  : (rbow, black, ( 0,-2,-1)),
+  'DarkWood'       : (rbow, black, ( 5, 3,-6)),
+  'Pearl'          : (rbow, black, (-1, 2,-3)),
+  'Rhodonite'      : (rbow, black, (-4, 1,-5)),
+  'VelvetyRed'     : (rbow, black, ( 3, 0,-8)),
+}
+
+bks = blocks.blocks(sce, colors)
+
+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['Pearl'], -100,    0,    0)
+key['R'] = soy.actions.Force(bks['Pearl'],    0,  100,    0)
+key['S'] = soy.actions.Force(bks['Pearl'],  100,    0,    0)
+key['T'] = soy.actions.Force(bks['Pearl'],    0, -100,    0)
+key['U'] = soy.actions.Force(bks['Pearl'],    0,    0, -100)
+key['V'] = soy.actions.Force(bks['Pearl'],    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/RainbowBlocks.py
___________________________________________________________________
Added: svn:executable
   + *

Copied: trunk/pysoy/src/materials/Rainbow.pym (from rev 1291, 
trunk/pysoy/src/materials/Bumpmapped.pym)
===================================================================
--- trunk/pysoy/src/materials/Rainbow.pym                               (rev 0)
+++ trunk/pysoy/src/materials/Rainbow.pym       2008-05-20 07:30:51 UTC (rev 
1292)
@@ -0,0 +1,69 @@
+# PySoy's materials.Bumpmapped class
+#
+# Copyright (C) 2006,2007,2008 PySoy Group
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU Affero General Public License as published
+#  by the Free Software Foundation, either version 3 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU Affero General Public License for more details.
+#
+#  You should have received a copy of the GNU Affero General Public License
+#  along with this program; if not, see http://www.gnu.org/licenses
+#
+# $Id$
+
+cdef class Rainbow(Material) :
+  '''soy.materials.Rainbow
+
+    This is a bit of a joke, but also help to visually see how tslv works
+  '''
+
+  ############################################################################
+  #
+  # General C functions
+  #
+  cdef int _needsTSLVs(self) nogil :
+    ######################################
+    #
+    # this material usually needs TSLV
+    #
+    return 1
+    #
+    ######################################
+
+
+  ############################################################################
+  #
+  # WindowLoop functions
+  #
+
+  cdef int _render(self, int _pass, float* _texcoords, float* _tslvs) nogil :
+    if _pass == 0 :
+      gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT,   self._ambient._rgba)
+      gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE,   self._diffuse._rgba)
+      gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR,  self._specular._rgba)
+      gl.glMaterialfv(gl.GL_FRONT, gl.GL_EMISSION,  self._emission._rgba)
+      gl.glMaterialf (gl.GL_FRONT, gl.GL_SHININESS, self._shininess)
+      #gl.glActiveTexture(_texunits[0])
+      gl.glClientActiveTexture(_texunits[0])
+      _normalisation_cube_map._enable()
+      gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
+      gl.glTexCoordPointer(3,  gl.GL_FLOAT,  0, _tslvs)
+      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_MODULATE)
+      return 1
+    #
+    ######################################
+    #
+    # disable texture from last pass
+    #
+    else :
+      gl.glClientActiveTexture(_texunits[0])
+      _normalisation_cube_map._disable()
+      return 0
+    #
+    ######################################

Modified: trunk/pysoy/src/materials/Textured.pym
===================================================================
--- trunk/pysoy/src/materials/Textured.pym      2008-05-20 07:07:36 UTC (rev 
1291)
+++ trunk/pysoy/src/materials/Textured.pym      2008-05-20 07:30:51 UTC (rev 
1292)
@@ -154,7 +154,7 @@
       # render the colormap
       #
       if self._colormap is not None :
-        gl.glActiveTexture(_texunits[_unit])
+        gl.glClientActiveTexture(_texunits[_unit])
         gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
         gl.glTexCoordPointer(3,  gl.GL_FLOAT, 48, _texcoords)
         gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_MODULATE)
@@ -166,7 +166,7 @@
       # render the glowmap
       #
       if self._glowmap is not None :
-        gl.glActiveTexture(_texunits[_unit])
+        gl.glClientActiveTexture(_texunits[_unit])
         gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
         gl.glTexCoordPointer(3,  gl.GL_FLOAT, 48, _texcoords)
         gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_ADD)
@@ -188,11 +188,11 @@
     else :
       _unit = 0
       if self._colormap is not None :
-        gl.glActiveTexture(_texunits[_unit])
+        gl.glClientActiveTexture(_texunits[_unit])
         self._colormap._disable()
         _unit += 1
       if self._glowmap is not None :
-        gl.glActiveTexture(_texunits[_unit])
+        gl.glClientActiveTexture(_texunits[_unit])
         self._glowmap._disable()
       return 0
     #

Modified: trunk/pysoy/src/materials/soy.materials.pyx
===================================================================
--- trunk/pysoy/src/materials/soy.materials.pyx 2008-05-20 07:07:36 UTC (rev 
1291)
+++ trunk/pysoy/src/materials/soy.materials.pyx 2008-05-20 07:30:51 UTC (rev 
1292)
@@ -27,5 +27,6 @@
 include "Material.pym"
 include "Textured.pym"
 include "Bumpmapped.pym"
+include "Rainbow.pym"
 include "_normalisationCubemap.pym"
 include "_postinit.pym"

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

Reply via email to