Author: ArcRiley Date: 2008-05-19 03:06:56 -0400 (Mon, 19 May 2008) New Revision: 1273
Added: trunk/pysoy/src/materials/Textured.pxi trunk/pysoy/src/materials/__init__.pym Modified: trunk/pysoy/src/materials/Material.pxi trunk/pysoy/src/materials/soy.materials.pyx Log: Ticket #955 : * initial Textured class * Material._texunits global added for all material classes to share Modified: trunk/pysoy/src/materials/Material.pxi =================================================================== --- trunk/pysoy/src/materials/Material.pxi 2008-05-18 19:28:37 UTC (rev 1272) +++ trunk/pysoy/src/materials/Material.pxi 2008-05-19 07:06:56 UTC (rev 1273) @@ -17,12 +17,6 @@ # # $Id$ -cimport soy.textures - -cdef soy.textures.NormalisationCubeMap _normalisation_cube_map -_normalisation_cube_map = soy.textures.NormalisationCubeMap() - - cdef class Material : '''PySoy Material Added: trunk/pysoy/src/materials/Textured.pxi =================================================================== --- trunk/pysoy/src/materials/Textured.pxi (rev 0) +++ trunk/pysoy/src/materials/Textured.pxi 2008-05-19 07:06:56 UTC (rev 1273) @@ -0,0 +1,237 @@ +# PySoy's materials.Textured 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: Material.pxi 1206 2008-03-22 18:42:26Z ArcRiley $ + +cdef class Textured(Material) : + '''soy.materials.Textured + + Textured materials support one or more basic textures in addition to the + 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. + ''' + + ############################################################################ + # + # Python functions + # + + def __cinit__(self, + soy.colors.Color ambient=None, + soy.colors.Color diffuse=None, + soy.colors.Color specular=None, + soy.colors.Color emissive=None, + float shininess=0.5, + soy.textures.Texture colormap=None, + soy.textures.Texture glowmap=None) : + ###################################### + # + # import soy.colors locally for setting defaults + # + import soy.colors + # + ###################################### + # + # assign each color as argument or default + # + # None should never be stored in these values so that + # we can use ._rgba without testing each first in _render + # + 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 + if emissive : + self._emissive = emissive + else : + self._emissive = soy.colors.black + # + ###################################### + # + # shininess is the size of the specularity dot + # + self._shininess = shininess + # + ###################################### + # + # store the texture arguments + # + self._colormap = colormap + self._glowmap = glowmap + # + ###################################### + + + ############################################################################ + # + # Properties + # + + property colormap : + '''soy.materials.Textured.colormap + + When a texture is assigned to this property a colormap texture is rendered. + + In OpenGL terms, this texture is set GL_MODULATE to the lit material color + which provides it's shading. Textures with an alpha component will be + translucent to the material's lit color, so to achieve actual translucency + this material's colors (ambient/diffuse) must also be translucent. + + Default is None (disabled). + ''' + + def __get__(self) : + return self._colormap + + def __set__(self, soy.textures.Texture _value) : + self._colormap = _value + + def __del__(self) : + self._colormap = None + + + property glowmap : + '''soy.materials.Textured.glowmap + + When a texture is assigned to this property a glowmap texture is rendered. + + In OpenGL terms, this texture is set GL_ADD. + + Default is None (disabled). + ''' + + def __get__(self) : + return self._glowmap + + def __set__(self, soy.textures.Texture _value) : + self._glowmap = _value + + def __del__(self) : + self._glowmap = None + + + ############################################################################ + # + # General C functions + # + cdef int _isTransparent(self): + # + # textures are only translucent to the colors, so if either lack + # translucency this check will return False + # + if self._colormap is not None and self._colormap._chans %2 == 1 : + return 0 + if self._ambient._rgba[3] != 1.0 : + return 1 + if self._diffuse._rgba[3] != 1.0 : + return 1 + return 0 + + + ############################################################################ + # + # WindowLoop functions + # + + cdef int _render(self, int _pass, float* _texcoords, float* _tslvs) nogil : + cdef int _i, _unit=0 + ###################################### + # + # Textured materials are 1-pass + # + if _pass == 0 : + #################################### + # + # 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._emissive._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.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.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 + # + #################################### + # + # disable what we're not using and return + # + # + for _i from _unit <= _i < 4 : + gl.glActiveTexture(_texunits[_i]) + gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY) + return 1 + # + ###################################### + # + # disable textures from last pass + # + else : + _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 + # + ###################################### Added: trunk/pysoy/src/materials/__init__.pym =================================================================== --- trunk/pysoy/src/materials/__init__.pym (rev 0) +++ trunk/pysoy/src/materials/__init__.pym 2008-05-19 07:06:56 UTC (rev 1273) @@ -0,0 +1,34 @@ +# PySoy's materials init +# +# 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: Material.pxi 1206 2008-03-22 18:42:26Z ArcRiley $ + +cimport soy.textures + +cdef int _texunits[8] +cdef soy.textures.NormalisationCubeMap _normalisation_cube_map + +_texunits[0] = gl.GL_TEXTURE0 +_texunits[1] = gl.GL_TEXTURE1 +_texunits[2] = gl.GL_TEXTURE2 +_texunits[3] = gl.GL_TEXTURE3 +_texunits[4] = gl.GL_TEXTURE4 +_texunits[5] = gl.GL_TEXTURE5 +_texunits[6] = gl.GL_TEXTURE6 +_texunits[7] = gl.GL_TEXTURE7 + +_normalisation_cube_map = soy.textures.NormalisationCubeMap() Modified: trunk/pysoy/src/materials/soy.materials.pyx =================================================================== --- trunk/pysoy/src/materials/soy.materials.pyx 2008-05-18 19:28:37 UTC (rev 1272) +++ trunk/pysoy/src/materials/soy.materials.pyx 2008-05-19 07:06:56 UTC (rev 1273) @@ -23,8 +23,7 @@ 'by '+'$Author$'[9:-2] __version__ = 'Trunk (r'+'$Rev$'[6:-2]+')' -import soy.colors - +include "__init__.pym" include "Material.pxi" include "A.pxi" include "B.pxi" _______________________________________________ PySoy-SVN mailing list PySoy-SVN@pysoy.org http://www.pysoy.org/mailman/listinfo/pysoy-svn