Author: ArcRiley Date: 2007-07-08 15:51:39 -0400 (Sun, 08 Jul 2007) New Revision: 424
Added: trunk/pysoy/src/meshes/ trunk/pysoy/src/meshes/Mesh.pxi trunk/pysoy/src/meshes/soy.bodies._bodies.pxd Removed: trunk/pysoy/src/meshes/Mesh.pxi trunk/pysoy/src/meshes/soy.bodies._bodies.pxd Log: starting move for ticket #277 Copied: trunk/pysoy/src/meshes (from rev 421, trunk/pysoy/src/bodies._bodies) Property changes on: trunk/pysoy/src/meshes ___________________________________________________________________ Name: svn:ignore + soy.meshes.c Deleted: trunk/pysoy/src/meshes/Mesh.pxi =================================================================== --- trunk/pysoy/src/bodies._bodies/Mesh.pxi 2007-07-08 09:37:55 UTC (rev 421) +++ trunk/pysoy/src/meshes/Mesh.pxi 2007-07-08 19:51:39 UTC (rev 424) @@ -1,268 +0,0 @@ -# PySoy bodies.Mesh Class -# -# Copyright (C) 2006,2007 Team PySoy -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, see http://www.gnu.org/licenses -# -# $Id$ - -cdef class Mesh(Body) : - '''PySoy Mesh - - This is a body which renders a group of triangles called a "mesh". - ''' - def __new__(self, scene=None, *args, **keywords) : - self._cface = soy._internals.Children() - self._verts = soy._datatypes.VertexList(self) - - - def __repr__(self) : - return '<Mesh with %d verticies, %d faces, and %d materials>' % ( - len(self._verts), self._nface, self._nmate) - - - property faces : - '''Mesh.faces - - This is a list-like object for manipulating the faces of a Mesh. - ''' - def __get__(self) : - return soy._datatypes.FaceList(self) - - - property verts : - '''Mesh.verts - - This is a list-like object for manipulating the verticies of a Mesh. - ''' - def __get__(self) : - return self._verts - - - property textures : - '''Mesh.textures - - This is a list-like object for manipulating the textures of a Mesh. - ''' - def __get__(self) : - return soy._datatypes.TextureList(self) - - - # Rendering Pipeline : - # - # We start with the "original" vertex array. This does not change within - # _render, only from the Python side. When the Python side changes values - # the self._uvert is given the range needing to be recalculated. - # - # The next step is applying morph targets. The product of this must be - # saved because, often, morph will change infrequently. When no morphs are - # in use the "original" is simply copied here and updated whenever needed. - # - # After morphs we need to do bone transformations. Bone transformations - # from resting to current within the coordinate system of the Mesh's Body - # is aquired and a comparison of transformation from the last frame (ie, - # how much that bone has moved since last calculated) is made. - # - # Once all the bone transformations are calculated each vertex tests against - # the bones that it's attached to. First step of this is to multiply it's - # weight (0.0 - 1.0) against the amount of transformation and test to see if - # it's greater than the culling value (if it's changed enough to recalc). - # If so, calculate that vertex's transformation based on weights for each - # bone it's attached to and then apply the product of this. - # - # These are placed, one by one, into the final array with the appropriate - # VBO update array calculated. If VBO, the updated subarray range is sent, - # and in both VA and VBO this is transformed to the body's location and - # then rendered. - - cdef void _render(self) : - cdef ode.dReal *pos - cdef ode.dReal *rot - cdef gl.GLfloat mtx[16] - pos = <ode.dReal *> ode.dBodyGetPosition(self._bodyID) - rot = <ode.dReal *> ode.dBodyGetRotation(self._bodyID) - mtx[0] = rot[0] - mtx[1] = rot[4] - mtx[2] = rot[8] - mtx[3] = 0.0 - mtx[4] = rot[1] - mtx[5] = rot[5] - mtx[6] = rot[9] - mtx[7] = 0.0 - mtx[8] = rot[2] - mtx[9] = rot[6] - mtx[10] = rot[10] - mtx[11] = 0.0 - mtx[12] = pos[0] - mtx[13] = pos[1] - mtx[14] = pos[2] - mtx[15] = 1.0 - gl.glPushMatrix() - gl.glMultMatrixf(mtx) - if gl.GLEW_ARB_vertex_buffer_object : - self._renderVBO() - else : - self._renderVA() - gl.glPopMatrix() - - - cdef void _renderVA(self) : - cdef int i - self._verts._renderArray() - for i from 0 <= i < self._nmate : - (<soy.materials.Material> self._mates[i].mat)._bind() - gl.glDrawElements (gl.GL_TRIANGLES, self._mates[i].length*3, - gl.GL_UNSIGNED_SHORT, - self._faces + self._mates[i].offset) - (<soy.materials.Material> self._mates[i].mat)._unbind() - - - cdef void _renderVBO(self) : - cdef int i - if self._nface == 0 : - return - if self._bface == 0 : - self._createVBO() - gl.glBindBufferARB (gl.GL_ELEMENT_ARRAY_BUFFER_ARB, self._bface) - self._sendFaceVBO() - self._verts._renderBuffer() - for i from 0 <= i < self._nmate : - (<soy.materials.Material> self._mates[i].mat)._bind() - gl.glDrawElements (gl.GL_TRIANGLES, self._mates[i].length*3, - gl.GL_UNSIGNED_SHORT, - (<Face *> 0) + self._mates[i].offset) - (<soy.materials.Material> self._mates[i].mat)._unbind() - - - cdef void _createVBO(self) : - self._aface = self._mface - self._uface.offset = -1 - gl.glGenBuffersARB(1, &self._bface) - gl.glBindBufferARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, self._bface) - gl.glBufferDataARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, 6*self._aface, - self._faces, gl.GL_STATIC_DRAW_ARB) - self._verts._createBuffer() - - - cdef void _flagFaceVBO(self, int index) : - if index < self._uface.offset or self._uface.offset == -1 : - self._uface.offset = index - if index-self._uface.offset > self._uface.length : - self._uface.length = index-self._uface.offset - - - cdef void _sendFaceVBO(self) : - if self._uface.offset == -1 : - return - if self._uface.offset + self._uface.length > self._aface : - self._aface = self._mface - self._cface.lock() - gl.glBufferDataARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, 6*self._mface, - self._faces, gl.GL_STATIC_DRAW_ARB) - self._cface.unlock() - return - # If in the process of writing, wait until next cycle to send - if not self._cface.trylock() : - return - gl.glBufferSubDataARB(gl.GL_ELEMENT_ARRAY_BUFFER_ARB, - 6*self._uface.offset, - 6*(self._uface.length+1), - &self._faces[self._uface.offset]) - self._uface.offset = -1 - self._uface.length = 0 - self._cface.unlock() - - - cdef void *_alloc(self, int num, int* m, void* store, int size) : - if num == 0 : - m[0] = 0 - py.PyMem_Free(store) - return NULL - if m[0] == 0 : - m[0] = num + 15 - return py.PyMem_Malloc(m[0] * size) - if num > m[0] or num+120 < m[0] : - m[0] = num + 15 - return py.PyMem_Realloc(store, m[0] * size) - return store - - - cdef void _allocFaces(self, int num) : - self._faces = <Face *> self._alloc(num, &self._mface, - self._faces, sizeof(Face)) - - - cdef void _allocMates(self, int num) : - self._mates = <MatRange *> self._alloc(num, &self._mmate, - self._mates, sizeof(MatRange)) - - -cdef class Pyramid(Mesh) : - '''This is for testing only''' - def __new__(self, object scene=None, object tex=None, *args, **keywords) : - self._allocMates(3) - self._allocFaces(6) - self._nmate = 3 - self._nface = 6 - import soy.colors - 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 - self._mates[1].mat = <void *>self.mat1 - self._mates[2].mat = <void *>self.mat2 - self._mates[0].offset = 0 - self._mates[0].length = 2 - self._mates[1].offset = 2 - self._mates[1].length = 2 - self._mates[2].offset = 4 - self._mates[2].length = 2 - - self._faces[0].a = 0 - self._faces[0].b = 1 - self._faces[0].c = 2 - - self._faces[1].a = 0 - self._faces[1].b = 3 - self._faces[1].c = 4 - - self._faces[2].a = 0 - self._faces[2].b = 2 - self._faces[2].c = 3 - - self._faces[3].a = 0 - self._faces[3].b = 4 - self._faces[3].c = 1 - - self._faces[4].a = 3 - self._faces[4].b = 2 - self._faces[4].c = 1 - - self._faces[5].a = 4 - self._faces[5].b = 3 - self._faces[5].c = 1 - - soy.atoms.Vertex(self,position=(0,1,0), normal=(0,1,0), texcoord=(0,0,0)) - soy.atoms.Vertex(self,position=(-1,-1,1),normal=(-1,-1,1),texcoord=(0,0,0)) - soy.atoms.Vertex(self,position=(1,-1,1), normal=(1,-1,1), texcoord=(0,1,0)) - soy.atoms.Vertex(self,position=(1,-1,-1),normal=(1,-1,-1),texcoord=(1,1,0)) - soy.atoms.Vertex(self,position=(-1,-1,-1),normal=(0,-1,0),texcoord=(1,0,0)) - - - def __dealloc__(self) : - self._allocFaces(0) - self._allocMates(0) Copied: trunk/pysoy/src/meshes/Mesh.pxi (from rev 422, trunk/pysoy/src/bodies._bodies/Mesh.pxi) =================================================================== --- trunk/pysoy/src/meshes/Mesh.pxi (rev 0) +++ trunk/pysoy/src/meshes/Mesh.pxi 2007-07-08 19:51:39 UTC (rev 424) @@ -0,0 +1,180 @@ +# PySoy meshes.Mesh Class +# +# Copyright (C) 2006,2007 Team PySoy +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see http://www.gnu.org/licenses +# +# $Id$ + +cdef class Mesh(Body) : + '''PySoy Mesh + + This is a collection of triangles which may share verticies. + ''' + def __new__(self, *args, **keywords) : + self._faces = soy._datatypes.FaceList(self) + self._verts = soy._datatypes.VertexList(self) + + + def __repr__(self) : + return '<Mesh with %d verticies, %d faces, and %d materials>' % ( + len(self._verts), len(self._faces), self._nmate) + + + property faces : + '''Mesh.faces + + This is a list-like object for manipulating the faces of a Mesh. + ''' + def __get__(self) : + return self._faces + + + property verts : + '''Mesh.verts + + This is a list-like object for manipulating the verticies of a Mesh. + ''' + def __get__(self) : + return self._verts + + + property textures : + '''Mesh.textures + + This is a list-like object for manipulating the textures of a Mesh. + ''' + def __get__(self) : + return soy._datatypes.TextureList(self) + + + # Rendering Pipeline : + # + # We start with the "original" vertex array. + # + # The next step is applying morph targets. The product of this must be + # saved because, often, morph will change infrequently. When no morphs are + # in use the "original" is simply copied here and updated whenever needed. + # + # After morphs we need to do bone transformations. Bone transformations + # from resting to current within the coordinate system of the Mesh's Body + # is aquired and a comparison of transformation from the last frame (ie, + # how much that bone has moved since last calculated) is made. + # + # Once all the bone transformations are calculated each vertex tests against + # the bones that it's attached to. First step of this is to multiply it's + # weight (0.0 - 1.0) against the amount of transformation and test to see if + # it's greater than the culling value (if it's changed enough to recalc). + # If so, calculate that vertex's transformation based on weights for each + # bone it's attached to and then apply the product of this. + # + # These are placed, one by one, into the final array with the appropriate + # VBO update array calculated. If VBO, the updated subarray range is sent, + # and in both VA and VBO this is transformed to the body's location and + # then rendered. + + cdef void _render(self) : + if gl.GLEW_ARB_vertex_buffer_object : + self._renderVBO() + else : + self._renderVA() + + + cdef void _renderVA(self) : + cdef int i + self._verts._renderArray() + for i from 0 <= i < self._nmate : + (<soy.materials.Material> self._mates[i].mat)._bind() + self._faces._renderArray(self._mates[i].offset, self._mates[i].length) + (<soy.materials.Material> self._mates[i].mat)._unbind() + + + cdef void _renderVBO(self) : + cdef int i + if self._faces._arraySize == 0 : + return + if self._faces._buffer == 0 : + self._createVBO() + gl.glBindBufferARB (gl.GL_ELEMENT_ARRAY_BUFFER_ARB, self._faces._buffer) + self._faces._sendUpdated() + self._verts._renderBuffer() + for i from 0 <= i < self._nmate : + (<soy.materials.Material> self._mates[i].mat)._bind() + self._faces._renderBuffer(self._mates[i].offset, self._mates[i].length) + (<soy.materials.Material> self._mates[i].mat)._unbind() + + + cdef void _createVBO(self) : + self._faces._createBuffer() + self._verts._createBuffer() + + + cdef void *_alloc(self, int num, int* m, void* store, int size) : + if num == 0 : + m[0] = 0 + py.PyMem_Free(store) + return NULL + if m[0] == 0 : + m[0] = num + 15 + return py.PyMem_Malloc(m[0] * size) + if num > m[0] or num+120 < m[0] : + m[0] = num + 15 + return py.PyMem_Realloc(store, m[0] * size) + return store + + + cdef void _allocMates(self, int num) : + self._mates = <MatRange *> self._alloc(num, &self._mmate, + self._mates, sizeof(MatRange)) + + +cdef class Pyramid(Mesh) : + '''This is for testing only''' + def __new__(self, tex=None, *args, **keywords) : + cdef object a, b, c, d, e + self._allocMates(3) + self._nmate = 3 + import soy.colors + 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 + self._mates[1].mat = <void *>self.mat1 + self._mates[2].mat = <void *>self.mat2 + self._mates[0].offset = 0 + self._mates[0].length = 2 + self._mates[1].offset = 2 + self._mates[1].length = 2 + self._mates[2].offset = 4 + self._mates[2].length = 2 + + a = soy.atoms.Vertex(self,position=( 0, 1, 0), texcoord=(0,0,0)) + b = soy.atoms.Vertex(self,position=(-1,-1, 1), texcoord=(0,0,0)) + c = soy.atoms.Vertex(self,position=( 1,-1, 1), texcoord=(0,1,0)) + d = soy.atoms.Vertex(self,position=( 1,-1,-1), texcoord=(1,1,0)) + e = soy.atoms.Vertex(self,position=(-1,-1,-1), texcoord=(1,0,0)) + + soy.atoms.Face(self, verts=(a,b,c)) + soy.atoms.Face(self, verts=(a,d,e)) + soy.atoms.Face(self, verts=(a,c,d)) + soy.atoms.Face(self, verts=(a,e,b)) + soy.atoms.Face(self, verts=(d,c,b)) + soy.atoms.Face(self, verts=(e,d,b)) + + + def __dealloc__(self) : + self._allocMates(0) Deleted: trunk/pysoy/src/meshes/soy.bodies._bodies.pxd =================================================================== --- trunk/pysoy/src/bodies._bodies/soy.bodies._bodies.pxd 2007-07-08 09:37:55 UTC (rev 421) +++ trunk/pysoy/src/meshes/soy.bodies._bodies.pxd 2007-07-08 19:51:39 UTC (rev 424) @@ -1,104 +0,0 @@ -# PySoy bodies declarations -# -# Copyright (C) 2006,2007 Team PySoy -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, see http://www.gnu.org/licenses -# -# $Id$ - -cimport gl -cimport ode -cimport py -cimport stdio -cimport soy._core -cimport soy._datatypes -cimport soy._internals -cimport soy.materials -cimport soy.textures -cimport soy.shapes - -cdef struct Face : - unsigned short a - unsigned short b - unsigned short c - - -cdef struct Range : - int offset - int length - - -cdef struct MatRange : - void *mat - int offset - int length - - -cdef class Body : - cdef ode.dBodyID _bodyID - cdef soy._core.Scene _scene - cdef soy.shapes.Shape _shape - # for loading/saving - cdef ode.dMass _mass - cdef ode.dVector3 _position - cdef ode.dQuaternion _quaternion - cdef ode.dReal _linearVel[3] - cdef ode.dReal _angularVel[3] - # C functions - cdef void _create(self) - cdef void _destroy(self) - cdef int _isActive(self) - cdef void _render(self) - cdef void poke(self, vector) - - -cdef class Camera (Body) : - cdef float _fovy - cdef void _project(self) - - -cdef class Mesh (Body) : - # - # Face Data - cdef int _aface # Allocated buffer size - cdef gl.GLuint _bface # element array Buffer - cdef soy._internals.Children _cface # "Face" Children - cdef Range _uface # Updated vertex array - cdef unsigned int _nface # number of current _faces - cdef int _mface # malloc size of _faces - cdef Face *_faces # indices for each face - # - # Vertex Data - cdef soy._datatypes.VertexList _verts - # - # Texture Data - cdef unsigned int _nmate # number of - cdef int _mmate # malloced - cdef MatRange *_mates # material ranges - - # - # Mesh Functions - cdef void _renderVA (self) - cdef void _renderVBO (self) - cdef void _createVBO (self) - cdef void _flagFaceVBO (self, int) - cdef void _sendFaceVBO (self) - cdef void *_alloc (self, int, int*, void*, int) - cdef void _allocFaces (self, int) - cdef void _allocMates (self, int) - -cdef class Pyramid (Mesh) : - cdef soy.materials.Material mat0 - cdef soy.materials.Material mat1 - cdef soy.materials.Material mat2 Copied: trunk/pysoy/src/meshes/soy.bodies._bodies.pxd (from rev 422, trunk/pysoy/src/bodies._bodies/soy.bodies._bodies.pxd) =================================================================== --- trunk/pysoy/src/meshes/soy.bodies._bodies.pxd (rev 0) +++ trunk/pysoy/src/meshes/soy.bodies._bodies.pxd 2007-07-08 19:51:39 UTC (rev 424) @@ -0,0 +1,91 @@ +# PySoy bodies declarations +# +# Copyright (C) 2006,2007 Team PySoy +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see http://www.gnu.org/licenses +# +# $Id$ + +cimport gl +cimport ode +cimport py +cimport stdio +cimport soy._core +cimport soy._datatypes +cimport soy._internals +cimport soy.materials +cimport soy.textures +cimport soy.shapes + +cdef struct Face : + unsigned short a + unsigned short b + unsigned short c + + +cdef struct Range : + int offset + int length + + +cdef struct MatRange : + void *mat + int offset + int length + + +cdef class Body : + cdef ode.dBodyID _bodyID + cdef soy._core.Scene _scene + cdef soy.shapes.Shape _shape + # for loading/saving + cdef ode.dMass _mass + cdef ode.dVector3 _position + cdef ode.dQuaternion _quaternion + cdef ode.dReal _linearVel[3] + cdef ode.dReal _angularVel[3] + # C functions + cdef void _create(self) + cdef void _destroy(self) + cdef int _isActive(self) + cdef void _render(self) + cdef void poke(self, vector) + + +cdef class Camera (Body) : + cdef float _fovy + cdef void _project(self) + + +cdef class Mesh (Body) : + cdef soy._datatypes.FaceList _faces + cdef soy._datatypes.VertexList _verts + # + # Texture Data + cdef unsigned int _nmate # number of + cdef int _mmate # malloced + cdef MatRange *_mates # material ranges + + # + # Mesh Functions + cdef void _renderVA (self) + cdef void _renderVBO (self) + cdef void _createVBO (self) + cdef void *_alloc (self, int, int*, void*, int) + cdef void _allocMates (self, int) + +cdef class Pyramid (Mesh) : + cdef soy.materials.Material mat0 + cdef soy.materials.Material mat1 + cdef soy.materials.Material mat2 _______________________________________________ PySoy-SVN mailing list [email protected] http://www.pysoy.org/mailman/listinfo/pysoy-svn
