Author: ArcRiley Date: 2008-05-19 16:24:10 -0400 (Mon, 19 May 2008) New Revision: 1276
Added: trunk/pysoy/src/materials/Bumpmapped.pym Log: Ticket #955 : * copying over Bumpmapped.pym so bumpmap procedures remain in Trunk Copied: trunk/pysoy/src/materials/Bumpmapped.pym (from rev 1275, trunk/pysoy/src/materials/Material.pym) =================================================================== --- trunk/pysoy/src/materials/Bumpmapped.pym (rev 0) +++ trunk/pysoy/src/materials/Bumpmapped.pym 2008-05-19 20:24:10 UTC (rev 1276) @@ -0,0 +1,307 @@ +# PySoy's materials.Material 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 Material : + '''PySoy Material + + shared material for many visible objects + ''' + + ############################################################################ + # + # Python functions + # + + def __cinit__(self, color=None, ambient=None, diffuse=None, specular=None, + shininess=0.5, + normal=None, normalisation_cube_map=None) : + import soy.colors + if color : + self._color = color + else : + self._color = None + + if normal : + self._normal = normal + else : + self._normal = None + + if ambient : + self._ambient = ambient + else : + self._ambient = soy.colors.white + + if diffuse : + self._diffuse = diffuse + else : + self._diffuse = soy.colors.white + + if specular : + self._specular = specular + else : + self._specular = soy.colors.white + + self._shininess = shininess + + self._blend_func_src = gl.GL_SRC_ALPHA + self._blend_func_dst = gl.GL_ONE_MINUS_SRC_ALPHA + self._shadeless = 0 + + self._emissive = soy.colors.black + + + def __repr__(self) : + return '<Material>' + + + ############################################################################ + # + # Properties + # + + 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 + + + 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 + + This property detirmines how many "shades" a face may have: + 0 == "smooth" + 1 == "flat" + + In the future 2+ will may be permitted for cartoon shading effects. + ''' + 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 + + + property shininess : + '''Shininess + + This property is how large the specular "dot" is between 0.0 and 1.0 + ''' + def __get__(self) : + return self._shininess + + def __set__(self, float value) : + self._shininess = value + + def __del__(self) : + self._shininess = 0.0 + + + 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): + return self._isTransparent() + + + 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