Author: ArcRiley Date: 2008-03-22 05:48:24 -0400 (Sat, 22 Mar 2008) New Revision: 1204
Modified: trunk/pysoy/src/materials/Material.pxi Log: Ticket #950 : * reordering of materials.Material Modified: trunk/pysoy/src/materials/Material.pxi =================================================================== --- trunk/pysoy/src/materials/Material.pxi 2008-03-22 09:44:37 UTC (rev 1203) +++ trunk/pysoy/src/materials/Material.pxi 2008-03-22 09:48:24 UTC (rev 1204) @@ -1,4 +1,4 @@ -# PySoy materials.Material class +# PySoy's materials.Material class # # Copyright (C) 2006,2007,2008 PySoy Group # @@ -28,8 +28,14 @@ shared material for many visible objects ''' - def __cinit__(self, color=None, ambient=None, diffuse=None, specular=None, normal=None, normalisation_cube_map=None) : + ############################################################################ + # + # Python functions + # + + def __cinit__(self, color=None, ambient=None, diffuse=None, specular=None, + normal=None, normalisation_cube_map=None) : if color : self._color = color else : @@ -67,115 +73,41 @@ def __repr__(self) : return '<Material>' - cdef int _isTransparent(self): - # - # check color texture - if self._color and (<soy.textures.Texture> self._color)._chans %2 == 0 : - return 1 - if (<soy.colors.Color> self._ambient)._rgba[3] != 1.0 : - return 1 - if (<soy.colors.Color> self._diffuse)._rgba[3] != 1.0 : - return 1 - if (<soy.colors.Color> self._specular)._rgba[3] != 1.0 : - return 1 - return 0 + ############################################################################ + # + # Properties + # - cdef void _coreBind(self) : - # - # set _shades value - if self._shades == 0 : - gl.glShadeModel(gl.GL_SMOOTH) - else : - gl.glShadeModel(gl.GL_FLAT) - # - # - if self._shadeless: - gl.glDisable(gl.GL_LIGHTING) - gl.glColor4f(self._diffuse._rgba[0], self._diffuse._rgba[1], - self._diffuse._rgba[2], self._diffuse._rgba[3]) - else: - 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._emissive._rgba) - gl.glMaterialf (gl.GL_FRONT, gl.GL_SHININESS, self._shininess) - - if self._color : - (<soy.textures.Texture> self._color)._enable() - - if self._normal : - 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) - elif self._isTransparent(): - gl.glEnable(gl.GL_BLEND) - gl.glBlendFunc(self._blend_func_src, self._blend_func_dst) - - - cdef void _coreUnBind(self) : - if self._color : - (<soy.textures.Texture> self._color)._disable() - if self._normal : - gl.glDisable(gl.GL_BLEND) - gl.glDisable(gl.GL_POLYGON_OFFSET_FILL) - gl.glPolygonOffset(0,0) - elif self._isTransparent(): - gl.glDisable(gl.GL_BLEND) - - if self._shadeless: - gl.glEnable(gl.GL_LIGHTING) - - cdef void _coreBindBumpPass(self) : - if not self._normal : - return - if not _normalisation_cube_map._was_created : - _normalisation_cube_map._generate(32,32) - gl.glActiveTexture(gl.GL_TEXTURE0) - (<soy.textures.Texture> self._normal)._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); - gl.glActiveTexture(gl.GL_TEXTURE1) - _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_COMBINE_RGB, gl.GL_DOT3_RGB); - gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_SOURCE1_RGB, gl.GL_PREVIOUS); - gl.glActiveTexture(gl.GL_TEXTURE0) - - cdef void _coreUnBindBumpPass(self) : - if not self._normal : - return - gl.glActiveTexture(gl.GL_TEXTURE0) - (<soy.textures.Texture> self._normal)._disable() - gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_MODULATE) - gl.glActiveTexture(gl.GL_TEXTURE1) - _normalisation_cube_map._disable() - gl.glActiveTexture(gl.GL_TEXTURE0) - property color : def __get__(self) : return self._color + def __set__(self, soy.textures.Texture value) : self._color = value + def __del__(self) : self._color = None + property normal: def __get__(self): return self._normal + def __set__(self, soy.textures.Texture val): self._normal = val + def __del__(self): self._normal = 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 @@ -183,8 +115,10 @@ 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 @@ -200,11 +134,13 @@ ''' def __get__(self) : return self._shades + def __set__(self, int value) : if value<1 or value>1 : self._shades = 0 else : self._shades = value + def __del__(self) : self._shades = 0 @@ -216,8 +152,10 @@ ''' def __get__(self) : return self._shininess + def __set__(self, float value) : self._shininess = value + def __del__(self) : self._shininess = 0.0 @@ -225,36 +163,46 @@ property specular : def __get__(self) : return self._specular + def __set__(self, val) : if isinstance(val, soy.colors.Color) : self._specular=val else : raise TypeError('must be a soy.color') + def __del__(self) : self._specular=soy.colors.white + property emissive : def __get__(self) : return self._emissive + def __set__(self, val) : if isinstance(val, soy.colors.Color) : self._emissive=val else : raise TypeError('must be a soy.color') + def __del__(self) : self._emissive=soy.colors.black + property blend_func_src: def __get__(self): return self._blend_func_src + def __set__(self,val): self._blend_func_src = val + property blend_func_dst: def __get__(self): return self._blend_func_dst + def __set__(self,val): self._blend_func_dst = val + property transparent: def __get__(self): @@ -264,5 +212,100 @@ property shadeless: def __get__(self): return self._shadeless + def __set__(self,val): self._shadeless = val + + + ############################################################################ + # + # WindowLoop functions + # + + cdef int _isTransparent(self): + # + # check color texture + if self._color and (<soy.textures.Texture> self._color)._chans %2 == 0 : + return 1 + if (<soy.colors.Color> self._ambient)._rgba[3] != 1.0 : + return 1 + if (<soy.colors.Color> self._diffuse)._rgba[3] != 1.0 : + return 1 + if (<soy.colors.Color> self._specular)._rgba[3] != 1.0 : + return 1 + return 0 + + + cdef void _coreBind(self) : + # + # set _shades value + if self._shades == 0 : + gl.glShadeModel(gl.GL_SMOOTH) + else : + gl.glShadeModel(gl.GL_FLAT) + # + # + if self._shadeless: + gl.glDisable(gl.GL_LIGHTING) + gl.glColor4f(self._diffuse._rgba[0], self._diffuse._rgba[1], + self._diffuse._rgba[2], self._diffuse._rgba[3]) + else: + 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._emissive._rgba) + gl.glMaterialf (gl.GL_FRONT, gl.GL_SHININESS, self._shininess) + + if self._color : + (<soy.textures.Texture> self._color)._enable() + + if self._normal : + 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) + elif self._isTransparent(): + gl.glEnable(gl.GL_BLEND) + gl.glBlendFunc(self._blend_func_src, self._blend_func_dst) + + + cdef void _coreUnBind(self) : + if self._color : + (<soy.textures.Texture> self._color)._disable() + if self._normal : + gl.glDisable(gl.GL_BLEND) + gl.glDisable(gl.GL_POLYGON_OFFSET_FILL) + gl.glPolygonOffset(0,0) + elif self._isTransparent(): + gl.glDisable(gl.GL_BLEND) + + if self._shadeless: + gl.glEnable(gl.GL_LIGHTING) + + cdef void _coreBindBumpPass(self) : + if not self._normal : + return + if not _normalisation_cube_map._was_created : + _normalisation_cube_map._generate(32,32) + gl.glActiveTexture(gl.GL_TEXTURE0) + (<soy.textures.Texture> self._normal)._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); + gl.glActiveTexture(gl.GL_TEXTURE1) + _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_COMBINE_RGB, gl.GL_DOT3_RGB); + gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_SOURCE1_RGB, gl.GL_PREVIOUS); + gl.glActiveTexture(gl.GL_TEXTURE0) + + cdef void _coreUnBindBumpPass(self) : + if not self._normal : + return + gl.glActiveTexture(gl.GL_TEXTURE0) + (<soy.textures.Texture> self._normal)._disable() + gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_MODULATE) + gl.glActiveTexture(gl.GL_TEXTURE1) + _normalisation_cube_map._disable() + gl.glActiveTexture(gl.GL_TEXTURE0) _______________________________________________ PySoy-SVN mailing list PySoy-SVN@pysoy.org http://www.pysoy.org/mailman/listinfo/pysoy-svn