Author: JaroslawTworek
Date: 2008-01-20 00:46:30 +0000 (Sun, 20 Jan 2008)
New Revision: 790

Modified:
   trunk/pysoy/examples/liquid_example.py
   trunk/pysoy/src/materials/Material.pxi
   trunk/pysoy/src/materials/soy.materials.pxd
   trunk/pysoy/src/meshes/Liquid.pxi
Log:
Few material enhancements


Modified: trunk/pysoy/examples/liquid_example.py
===================================================================
--- trunk/pysoy/examples/liquid_example.py      2008-01-20 00:19:09 UTC (rev 
789)
+++ trunk/pysoy/examples/liquid_example.py      2008-01-20 00:46:30 UTC (rev 
790)
@@ -8,14 +8,14 @@
     F = soy.atoms.Face
     #SIMPLE BOX:
     bottom_vertices = [
-            (-0.5,-0.25, 0.5),
-            ( 0.5,-0.25, 0.5),
-            (-0.5, 0.25, 0.5),
-            ( 0.5, 0.25, 0.5),
-            (-0.5,-0.25,-0.5),
-            ( 0.5,-0.25,-0.5),
-            (-0.5, 0.25,-0.5),
-            ( 0.5, 0.25,-0.5),
+            (-1.5,-0.25, 1.5),
+            ( 1.5,-0.25, 1.5),
+            (-1.5, 0.25, 1.5),
+            ( 1.5, 0.25, 1.5),
+            (-1.5,-0.25,-1.5),
+            ( 1.5,-0.25,-1.5),
+            (-1.5, 0.25,-1.5),
+            ( 1.5, 0.25,-1.5),
             ]
     bottom_normals = [
             ( 0, 0, 1), #FRONT
@@ -113,11 +113,15 @@
     bottom_b.position = (0,-1,0)
 
     water_mat = soy.materials.Material(water)
+    water_mat.ambient = soy.colors.Blue()
+    water_mat.diffuse = soy.colors.Blue()
+    water_mat.specular = soy.colors.Black()
+
     liquid = soy.meshes.Liquid(liquid_mat=water_mat)
     liquid_b = soy.bodies.Body(sce, mesh=liquid)
     liquid_b.position = (0, -1, 0)
 
-    liquid.size = (1, 0.5, 1)
+    liquid.size = (3, 0.5, 3)
 
     scr = soy.Screen()
     win = soy.Window(scr, 'Liquid example', background=soy.colors.Black(),

Modified: trunk/pysoy/src/materials/Material.pxi
===================================================================
--- trunk/pysoy/src/materials/Material.pxi      2008-01-20 00:19:09 UTC (rev 
789)
+++ trunk/pysoy/src/materials/Material.pxi      2008-01-20 00:46:30 UTC (rev 
790)
@@ -34,7 +34,7 @@
     if ambient :
       self._ambient = ambient
     else :
-      self._ambient = soy.colors.Gray()
+      self._ambient = soy.colors.White()
 
     if diffuse :
       self._diffuse = diffuse
@@ -50,6 +50,7 @@
 
     self._blend_func_src = gl.GL_SRC_ALPHA
     self._blend_func_dst = gl.GL_ONE_MINUS_SRC_ALPHA
+    self._shadeless      = 0
 
 
   def __repr__(self) :
@@ -89,31 +90,33 @@
     _white[2] = 1.0
     _white[3] = 1.0
 
+    (<soy.colors.Color> self._ambient)._getRGBA(_ambient)
+    (<soy.colors.Color> self._diffuse)._getRGBA(_diffuse)
+    (<soy.colors.Color> self._specular)._getRGBA(_specular)
+
     if self._shades == 0 :
       gl.glShadeModel(gl.GL_SMOOTH)
     else :
       gl.glShadeModel(gl.GL_FLAT)
 
-    (<soy.colors.Color> self._ambient)._getRGBA(_ambient)
-    (<soy.colors.Color> self._diffuse)._getRGBA(_diffuse)
-    (<soy.colors.Color> self._specular)._getRGBA(_specular)
+    if self._shadeless:
+        gl.glColor4f(_diffuse[0], _diffuse[1], _diffuse[2], _diffuse[3])
+    else: 
+        gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, _ambient)
+        gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, _diffuse)
+        gl.glMaterialf (gl.GL_FRONT, gl.GL_SHININESS, self._shininess)    
+        gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, _specular)
 
-    gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, _ambient)
-    gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, _diffuse)
-    gl.glMaterialf (gl.GL_FRONT, gl.GL_SHININESS, self._shininess)    
-    gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, _specular)
-
     if self._color :
       # for some reason _white works here while _getRGBA does not,
       # even though it works for non-textured
-      gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT_AND_DIFFUSE, _white)
+      #gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT_AND_DIFFUSE, _white)
       (<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)
+    #else :
+    #  gl.glDisable(gl.GL_TEXTURE_1D)
+    #  gl.glDisable(gl.GL_TEXTURE_2D)
+    #  gl.glDisable(gl.GL_TEXTURE_3D)
 
-
     if self._is_transparent():
         gl.glEnable(gl.GL_BLEND)
         gl.glBlendFunc(self._blend_func_src, self._blend_func_dst)
@@ -212,4 +215,10 @@
       def __get__(self):
           return self._is_transparent()
 
+  property shadeless:
+      def __get__(self):
+          return self._shadeless
+      def __set__(self,val):
+          self._shadeless = val
 
+

Modified: trunk/pysoy/src/materials/soy.materials.pxd
===================================================================
--- trunk/pysoy/src/materials/soy.materials.pxd 2008-01-20 00:19:09 UTC (rev 
789)
+++ trunk/pysoy/src/materials/soy.materials.pxd 2008-01-20 00:46:30 UTC (rev 
790)
@@ -31,6 +31,7 @@
 
   cdef int              _shades
   cdef float            _shininess
+  cdef int              _shadeless
 
   cdef int              _blend_func_src
   cdef int              _blend_func_dst

Modified: trunk/pysoy/src/meshes/Liquid.pxi
===================================================================
--- trunk/pysoy/src/meshes/Liquid.pxi   2008-01-20 00:19:09 UTC (rev 789)
+++ trunk/pysoy/src/meshes/Liquid.pxi   2008-01-20 00:46:30 UTC (rev 790)
@@ -1,11 +1,8 @@
 import soy.colors
 
 cdef class Liquid(Mesh):
-    def __cinit__(self, liquid_size=(1,1,1), **kwargs ):
-        if kwargs.has_key('liquid_mat'):
-            self._liquid_mat = kwargs['liquid_mat']
-        else:
-            self._liquid_mat = soy.materials.StainlessSteel()
+    def __cinit__(self, liquid_size=(1,1,1), 
liquid_mat=soy.materials.StainlessSteel()   ):
+        self._liquid_mat = liquid_mat
 
         self._liquid_size[0] = liquid_size[0]
         self._liquid_size[1] = liquid_size[1]
@@ -51,36 +48,13 @@
             self._liquid_size[1] = newval[1]
             self._liquid_size[2] = newval[2]
 
-    property two_sided:
+    property liquid_mat:
         def __get__(self):
-            return self._two_sided
+            return self._liquid_mat
         def __set__(self, newval):
-            self._two_sided = newval
+            self._liquid_mat = newval
 
-    property background_mat:
-        def __get__(self):
-            return self._background_mat
-        def __set__(self, newval):
-            self._background_mat = newval
 
-    property liquid_opacity:
-        def __get__(self):
-            return self._liquid_opacity
-        def __set__(self, newval):
-            self._liquid_opacity = newval
 
-    property liquid_color:
-        def __get__(self):
-            return self._liquid_color
-        def __set__(self, newval):
-            self._liquid_color = newval
 
-    property liquid_tex:
-        def __get__(self):
-            return self._liquid_tex
-        def __set__(self, newval):
-            self._liquid_tex = newval
 
-
-
-

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

Reply via email to