Author: ArcRiley
Date: 2007-07-03 23:07:24 -0400 (Tue, 03 Jul 2007)
New Revision: 345

Modified:
   trunk/pysoy/src/bodies._bodies/Mesh.pxi
   trunk/pysoy/src/materials/Material.pxi
   trunk/pysoy/src/materials/soy.materials.pxd
Log:
.color .ambient and .diffuse are now separate


Modified: trunk/pysoy/src/bodies._bodies/Mesh.pxi
===================================================================
--- trunk/pysoy/src/bodies._bodies/Mesh.pxi     2007-07-04 02:48:31 UTC (rev 
344)
+++ trunk/pysoy/src/bodies._bodies/Mesh.pxi     2007-07-04 03:07:24 UTC (rev 
345)
@@ -252,9 +252,10 @@
     self._nface = 6
     self._nvert = 5
     import soy.colors
-    self.mat0 = soy.materials.Material(color=soy.colors.BlueViolet())
-    self.mat1 = soy.materials.Material(color=soy.colors.YellowGreen())
-#    self.mat2 = soy.materials.Material(color=soy.colors.GoldenRod())
+    self.mat0 = soy.materials.Material(ambient=soy.colors.BlueViolet(),
+                                       diffuse=soy.colors.Cyan())
+    self.mat1 = soy.materials.Material(ambient=soy.colors.YellowGreen(),
+                                       diffuse=soy.colors.GoldenRod())
     self.mat2 = soy.materials.Material(color=tex)
 
     self._mates[0].mat = <void *>self.mat0

Modified: trunk/pysoy/src/materials/Material.pxi
===================================================================
--- trunk/pysoy/src/materials/Material.pxi      2007-07-04 02:48:31 UTC (rev 
344)
+++ trunk/pysoy/src/materials/Material.pxi      2007-07-04 03:07:24 UTC (rev 
345)
@@ -22,17 +22,25 @@
 
      shared material for many visible objects
   '''
-  def __new__(self, color=None, specular=None) :
+  def __new__(self, color=None, ambient=None, diffuse=None, specular=None) :
     import soy.colors
     if color :
       self.color = color
     else :
-      self._color = soy.colors.White()
-    self._shininess = .5
+      self._color = None
+    if ambient :
+      self._ambient = ambient
+    else :
+      self._ambient = soy.colors.Gray()
+    if diffuse :
+      self._diffuse = diffuse
+    else :
+      self._diffuse = soy.colors.White()
     if specular :
       self._specular = specular
     else :
       self._specular = soy.colors.White()
+    self._shininess = .5
 
 
   def __repr__(self) :
@@ -40,30 +48,20 @@
 
 
   cdef void _render(self) :
-    cdef float _white[4]
-    _white[0] = 1.0
-    _white[1] = 1.0
-    _white[2] = 1.0
-    _white[3] = 1.0
-    cdef float _grey[4]
-    _grey[0] = 0.5
-    _grey[1] = 0.5
-    _grey[2] = 0.5
-    _grey[3] = 0.5
-    if self._colorTex :
-      gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, _grey)
-      gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, _white)
+    if self._color :
       (<soy.textures.Texture> self._color)._bind()
     else :
       gl.glDisable(gl.GL_TEXTURE_1D)
       gl.glDisable(gl.GL_TEXTURE_2D)
       gl.glDisable(gl.GL_TEXTURE_3D)
-      gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT_AND_DIFFUSE, 
-                      (<soy.colors.Color> self._color)._getRGBA())
     if self._shades == 0 :
       gl.glShadeModel(gl.GL_SMOOTH)
     else :
       gl.glShadeModel(gl.GL_FLAT)
+    gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, 
+                    (<soy.colors.Color> self._ambient)._getRGBA())
+    gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, 
+                    (<soy.colors.Color> self._diffuse)._getRGBA())
     gl.glMaterialf (gl.GL_FRONT, gl.GL_SHININESS, self._shininess)    
     gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR,
                     (<soy.colors.Color> self._specular)._getRGBA())
@@ -72,20 +70,30 @@
   property color :
     def __get__(self) :
       return self._color
-    def __set__(self, val) :
-      if isinstance(val, soy.colors.Color) :
-        self._color=val
-        self._colorTex=0
-      elif isinstance(val, soy.textures.Texture) :
-        self._color=val
-        self._colorTex=1
-      else :
-        raise TypeError('must be EITHER a soy.color OR a soy.texture')
+    def __set__(self, soy.textures.Texture value) :
+      self._color = value
     def __del__(self) :
-      self._color=soy.colors.White()
-      self._colorTex=0
+      self._color = None
 
 
+  property ambient :
+    def __get__(self) :
+      return self._ambient
+    def __set__(self, soy.colors.Color value) :
+      self._ambient = value
+    def __del__(self) :
+      self._ambient = soy.colors.Gray()
+
+
+  property diffuse :
+    def __get__(self) :
+      return self._diffuse
+    def __set__(self, soy.colors.Color value) :
+      self._diffuse = value
+    def __del__(self) :
+      self._diffuse = soy.colors.White()
+
+
   property shades :
     '''Number of Shades
 

Modified: trunk/pysoy/src/materials/soy.materials.pxd
===================================================================
--- trunk/pysoy/src/materials/soy.materials.pxd 2007-07-04 02:48:31 UTC (rev 
344)
+++ trunk/pysoy/src/materials/soy.materials.pxd 2007-07-04 03:07:24 UTC (rev 
345)
@@ -23,10 +23,11 @@
 cimport soy.textures
 
 cdef class Material :
-  cdef object _color
-  cdef int    _colorTex
-  cdef int    _shades
-  cdef float  _shininess
-  cdef object _specular
+  cdef object           _color
+  cdef soy.colors.Color _ambient
+  cdef soy.colors.Color _diffuse
+  cdef int              _shades
+  cdef float            _shininess
+  cdef soy.colors.Color _specular
   # C Functions
   cdef void   _render(self)

_______________________________________________
PySoy-SVN mailing list
[email protected]
http://www.pysoy.org/mailman/listinfo/pysoy-svn

Reply via email to