Author: ArcRiley
Date: 2008-05-20 15:59:07 -0400 (Tue, 20 May 2008)
New Revision: 1295

Removed:
   trunk/pysoy/src/materials/Bumpmapped.pym
Modified:
   trunk/pysoy/examples/TexBlocks.py
   trunk/pysoy/include/soy.materials.pxd
   trunk/pysoy/src/materials/Textured.pym
   trunk/pysoy/src/materials/soy.materials.pyx
Log:
Ticket #955 :
  * merged Bumpmapped into Textured


Modified: trunk/pysoy/examples/TexBlocks.py
===================================================================
--- trunk/pysoy/examples/TexBlocks.py   2008-05-20 19:36:23 UTC (rev 1294)
+++ trunk/pysoy/examples/TexBlocks.py   2008-05-20 19:59:07 UTC (rev 1295)
@@ -12,7 +12,7 @@
 mrbl = soy.transports.File('media/marble.soy')['gimp']
 dot3 = soy.transports.File('media/fieldstone-dot3.soy')['gimp']
 colors = {
-  'Marble' : (soy.materials.Bumpmapped(colormap=mrbl, bumpmap=dot3),
+  'Marble' : (soy.materials.Textured(colormap=mrbl, bumpmap=dot3),
               soy.materials.Material(ambient=soy.colors.black,
                                      diffuse=soy.colors.Color('#222'),
                                      specular=soy.colors.Color('#222'),

Modified: trunk/pysoy/include/soy.materials.pxd
===================================================================
--- trunk/pysoy/include/soy.materials.pxd       2008-05-20 19:36:23 UTC (rev 
1294)
+++ trunk/pysoy/include/soy.materials.pxd       2008-05-20 19:59:07 UTC (rev 
1295)
@@ -38,8 +38,6 @@
   cdef int                  _render         ( self, int, float*, float* ) nogil
 
 cdef class Textured (Material) :
+  cdef soy.textures.Texture _bumpmap
   cdef soy.textures.Texture _colormap
   cdef soy.textures.Texture _glowmap
-
-cdef class Bumpmapped (Textured) :
-  cdef soy.textures.Texture _bumpmap

Deleted: trunk/pysoy/src/materials/Bumpmapped.pym
===================================================================
--- trunk/pysoy/src/materials/Bumpmapped.pym    2008-05-20 19:36:23 UTC (rev 
1294)
+++ trunk/pysoy/src/materials/Bumpmapped.pym    2008-05-20 19:59:07 UTC (rev 
1295)
@@ -1,272 +0,0 @@
-# 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 Bumpmapped(Textured) :
-  '''soy.materials.Bumpmapped
-
-    Bumpmapped materials add support for bumpmap textures to the basic
-    Textured material.  These classes are split so that other classes can
-    inherit Textured which are incompatible with bumpmapped textures.
-    
-    Currently .colormap, .glowmap, and .bumpmap are supported.
-  '''
-
-  ############################################################################
-  #
-  # Python functions
-  #
-
-  def __cinit__(self, 
-                soy.colors.Color ambient=None,
-                soy.colors.Color diffuse=None,
-                soy.colors.Color specular=None,
-                soy.colors.Color emission=None,
-                float shininess=0.5,
-                soy.textures.Texture colormap=None,
-                soy.textures.Texture glowmap=None,
-                soy.textures.Texture bumpmap=None,
-                *args, **keywords) :
-    ######################################
-    #
-    # store the bumpmap
-    #
-    self._bumpmap = bumpmap
-    #
-    ######################################
-
-
-  ############################################################################
-  #
-  # Properties
-  #
-
-  property bumpmap :
-    '''soy.materials.Textured.bumpmap
-
-    When a texture is assigned to this property a bumpmap texture is rendered.
-
-    This allows artists to add fine-grained detail to 3d objects or the give
-    otherwise smooth/flat surfaces a pattered appearance that changes with
-    the angle of light (shadows/highlights).
-
-    In OpenGL terms, this texture is a dot3 normal map in tangent-space which
-    is mapped to object space by combining it with a normalisation cubemap.
-
-    Default is None (disabled).
-    '''
-    
-    def __get__(self) :
-      return self._bumpmap
-
-    def __set__(self, soy.textures.Texture _value) :
-      if _value._chans != 3 :
-        raise ValueError('bumpmaps must be RGB')
-      self._bumpmap = _value
-
-    def __del__(self) :
-      self._bumpmap = None
-
-
-  ############################################################################
-  #
-  # 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 :
-    cdef int _i, _bump, _unit
-    _unit = 0
-    ######################################
-    #
-    # if there's no bumpmap, render it like a textured material
-    #
-    if self._bumpmap is None :
-      _pass += 1
-    else :
-      _bump = 1
-    #
-    ######################################
-    #
-    # this will only be true if _pass==0 and bumpmap is not None
-    #
-    if _pass == 0 :
-      ####################################
-      #
-      # Texture1 - the normalisation cubemap
-      #
-      gl.glActiveTexture(gl.GL_TEXTURE1)
-      gl.glClientActiveTexture(gl.GL_TEXTURE1)
-      gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
-      gl.glTexCoordPointer(3,  gl.GL_FLOAT,  0, _tslvs)
-      _normalisation_cube_map._enable()
-      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_COMBINE)
-      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_SOURCE0_RGB,  gl.GL_TEXTURE)
-      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_SOURCE1_RGB,  gl.GL_PREVIOUS)
-      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_COMBINE_RGB,  gl.GL_DOT3_RGB)
-      gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP,
-                         gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
-      gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP, 
-                         gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR)
-      gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP,
-                         gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE)
-      gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP, 
-                         gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE)
-      gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP,
-                         gl.GL_TEXTURE_WRAP_R, gl.GL_CLAMP_TO_EDGE)
-      #
-      ####################################
-      #
-      # Texture0 - the dot3 normal map (bumpmap)
-      #
-      gl.glActiveTexture(gl.GL_TEXTURE0)
-      gl.glClientActiveTexture(gl.GL_TEXTURE0)
-      gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
-      gl.glTexCoordPointer(3,  gl.GL_FLOAT, 48, _texcoords)
-      self._bumpmap._enable()
-      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_COMBINE)
-      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_SOURCE0_RGB,      gl.GL_TEXTURE)
-      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_COMBINE_RGB,      gl.GL_REPLACE)
-      #             
-      ####################################
-      #
-      # either return now and render 2-pass or play a trick
-      # no tricks yet
-      #
-      return 1
-      #      
-    ######################################
-    #
-    # Render non-bumpmap passes
-    #
-    if _pass == 1 :
-      if _bump :    
-        ##################################
-        #
-        # start by cleaning up from last pass
-        #
-        gl.glActiveTexture(gl.GL_TEXTURE1)
-        gl.glClientActiveTexture(gl.GL_TEXTURE1)
-        _normalisation_cube_map._disable()
-        gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY)
-        gl.glActiveTexture(gl.GL_TEXTURE0)
-        gl.glClientActiveTexture(gl.GL_TEXTURE0)
-        self._bumpmap._disable()
-        #
-        ##################################
-        #
-        # also setup blending for this pass
-        #
-        gl.glEnable(gl.GL_BLEND)
-        gl.glBlendFunc(gl.GL_DST_COLOR, gl.GL_ZERO)
-        gl.glEnable(gl.GL_POLYGON_OFFSET_FILL)
-        gl.glPolygonOffset(0,-2)
-        #
-      ####################################
-      #
-      # number of shades, currently just 0 or 1
-      #
-      if self._shades == 0 :
-        gl.glShadeModel(gl.GL_SMOOTH)
-      else :
-        gl.glShadeModel(gl.GL_FLAT)
-      #
-      ####################################
-      #
-      # lit material colors and settings
-      #
-      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)    
-      #
-      ####################################
-      #
-      # 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)
-        self._colormap._enable()
-        _unit += 1
-      #
-      ####################################
-      #
-      # 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)
-        gl.glEnable(gl.GL_BLEND)
-        gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE)
-        self._glowmap._enable()
-        _unit += 1
-      #
-      ####################################
-      #
-      # return 1
-      #
-      return 1
-    #
-    ######################################
-    #
-    # disable textures from last pass
-    #
-    else :
-      if _bump :
-        ##################################
-        #
-        # disable bump-blending
-        #
-        gl.glDisable(gl.GL_BLEND)
-        gl.glDisable(gl.GL_POLYGON_OFFSET_FILL)
-        gl.glPolygonOffset(0,0)
-        #
-      ####################################
-      #
-      _unit = 0
-      if self._colormap is not None :
-        gl.glActiveTexture(_texunits[_unit])
-        self._colormap._disable()
-        _unit += 1
-      if self._glowmap is not None :
-        gl.glActiveTexture(_texunits[_unit])
-        self._glowmap._disable()
-      return 0
-    #
-    ######################################

Modified: trunk/pysoy/src/materials/Textured.pym
===================================================================
--- trunk/pysoy/src/materials/Textured.pym      2008-05-20 19:36:23 UTC (rev 
1294)
+++ trunk/pysoy/src/materials/Textured.pym      2008-05-20 19:59:07 UTC (rev 
1295)
@@ -24,7 +24,7 @@
     standard Material colors (ambient, diffuse, specular, emission) which
     are multiplied by the texture color to provide light-based shading.
     
-    Currently .colormap and .glowmap are supported.
+    Currently .bumpmap .colormap and .glowmap are supported.
   '''
 
   ############################################################################
@@ -38,6 +38,7 @@
                 soy.colors.Color specular=None,
                 soy.colors.Color emission=None,
                 float shininess=0.5,
+                soy.textures.Texture bumpmap=None,
                 soy.textures.Texture colormap=None,
                 soy.textures.Texture glowmap=None,
                 *args, **keywords) :
@@ -45,6 +46,7 @@
     #
     # store the texture arguments
     #
+    self._bumpmap  = bumpmap
     self._colormap = colormap
     self._glowmap  = glowmap
     #
@@ -99,6 +101,33 @@
       self._glowmap = None
 
 
+  property bumpmap :
+    '''soy.materials.Textured.bumpmap
+
+    When a texture is assigned to this property a bumpmap texture is rendered.
+
+    This allows artists to add fine-grained detail to 3d objects or the give
+    otherwise smooth/flat surfaces a pattered appearance that changes with
+    the angle of light (shadows/highlights).
+
+    In OpenGL terms, this texture is a dot3 normal map in tangent-space which
+    is mapped to object space by combining it with a normalisation cubemap.
+
+    Default is None (disabled).
+    '''
+
+    def __get__(self) :
+      return self._bumpmap
+
+    def __set__(self, soy.textures.Texture _value) :
+      if _value._chans != 3 :
+        raise ValueError('bumpmaps must be RGB')
+      self._bumpmap = _value
+
+    def __del__(self) :
+      self._bumpmap = None
+
+
   ############################################################################
   #
   # General C functions
@@ -117,21 +146,111 @@
     return 0
 
 
+  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 :
-    cdef int _i, _unit
+    cdef int _i, _bump, _unit
     _unit = 0
     ######################################
     #
-    # Textured materials are 1-pass
+    # if there's no bumpmap, render it like a textured material
     #
+    if self._bumpmap is None :
+      _pass += 1
+    else :
+      _bump = 1
+    #
+    ######################################
+    #
+    # this will only be true if _pass==0 and bumpmap is not None
+    #
     if _pass == 0 :
       ####################################
       #
+      # Texture1 - the normalisation cubemap
+      #
+      gl.glActiveTexture(gl.GL_TEXTURE1)
+      gl.glClientActiveTexture(gl.GL_TEXTURE1)
+      gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
+      gl.glTexCoordPointer(3,  gl.GL_FLOAT,  0, _tslvs)
+      _normalisation_cube_map._enable()
+      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_COMBINE)
+      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_SOURCE0_RGB,  gl.GL_TEXTURE)
+      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_SOURCE1_RGB,  gl.GL_PREVIOUS)
+      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_COMBINE_RGB,  gl.GL_DOT3_RGB)
+      gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP,
+                         gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR)
+      gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP, 
+                         gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR)
+      gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP,
+                         gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE)
+      gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP, 
+                         gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE)
+      gl.glTexParameteri(gl.GL_TEXTURE_CUBE_MAP,
+                         gl.GL_TEXTURE_WRAP_R, gl.GL_CLAMP_TO_EDGE)
+      #
+      ####################################
+      #
+      # Texture0 - the dot3 normal map (bumpmap)
+      #
+      gl.glActiveTexture(gl.GL_TEXTURE0)
+      gl.glClientActiveTexture(gl.GL_TEXTURE0)
+      gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY)
+      gl.glTexCoordPointer(3,  gl.GL_FLOAT, 48, _texcoords)
+      self._bumpmap._enable()
+      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_COMBINE)
+      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_SOURCE0_RGB,      gl.GL_TEXTURE)
+      gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_COMBINE_RGB,      gl.GL_REPLACE)
+      #             
+      ####################################
+      #
+      # either return now and render 2-pass or play a trick
+      # no tricks yet
+      #
+      return 1
+      #      
+    ######################################
+    #
+    # Render non-bumpmap passes
+    #
+    if _pass == 1 :
+      if _bump :    
+        ##################################
+        #
+        # start by cleaning up from last pass
+        #
+        gl.glActiveTexture(gl.GL_TEXTURE1)
+        gl.glClientActiveTexture(gl.GL_TEXTURE1)
+        _normalisation_cube_map._disable()
+        gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY)
+        gl.glActiveTexture(gl.GL_TEXTURE0)
+        gl.glClientActiveTexture(gl.GL_TEXTURE0)
+        self._bumpmap._disable()
+        #
+        ##################################
+        #
+        # also setup blending for this pass
+        #
+        gl.glEnable(gl.GL_BLEND)
+        gl.glBlendFunc(gl.GL_DST_COLOR, gl.GL_ZERO)
+        gl.glEnable(gl.GL_POLYGON_OFFSET_FILL)
+        gl.glPolygonOffset(0,-2)
+        #
+      ####################################
+      #
       # number of shades, currently just 0 or 1
       #
       if self._shades == 0 :
@@ -154,10 +273,10 @@
       # 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.glActiveTexture(_texunits[_unit])
         gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_MODULATE)
         self._colormap._enable()
         _unit += 1
@@ -167,14 +286,14 @@
       # 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.glActiveTexture(_texunits[_unit])
-        self._glowmap._enable()
         gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_ADD)
         gl.glEnable(gl.GL_BLEND)
         gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE)
+        self._glowmap._enable()
         _unit += 1
       #
       ####################################
@@ -188,6 +307,17 @@
     # disable textures from last pass
     #
     else :
+      if _bump :
+        ##################################
+        #
+        # disable bump-blending
+        #
+        gl.glDisable(gl.GL_BLEND)
+        gl.glDisable(gl.GL_POLYGON_OFFSET_FILL)
+        gl.glPolygonOffset(0,0)
+        #
+      ####################################
+      #
       _unit = 0
       if self._colormap is not None :
         gl.glActiveTexture(_texunits[_unit])

Modified: trunk/pysoy/src/materials/soy.materials.pyx
===================================================================
--- trunk/pysoy/src/materials/soy.materials.pyx 2008-05-20 19:36:23 UTC (rev 
1294)
+++ trunk/pysoy/src/materials/soy.materials.pyx 2008-05-20 19:59:07 UTC (rev 
1295)
@@ -26,7 +26,6 @@
 include "__init__.pym"
 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