[GEM-dev] mesh object for gem
Matthias Neuenhofer
neuenhofer at khm.de
Wed Dec 19 19:25:49 CET 2007
Hallo,
great see this new object.
For vertex displacement i worked with curve3d before but the
mesh_square interpolate smoother.
But when you change the grid the texture stays to the initial
arguments given to the object.
see the patch with displacement based on the luminance of texture.
lg
mn
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mesh-curve3d.zip
Type: application/zip
Size: 57411 bytes
Desc: not available
URL: <http://lists.puredata.info/pipermail/gem-dev/attachments/20071219/e2822ff4/attachment.zip>
-------------- next part --------------
Am 16.12.2007 um 13:39 schrieb cyrille henry:
> hello,
>
> here is a square mesh generator object i made mixing code from a
> square and newWave, disigned to be used with vertex shader.
> i don't know if it should go from -1 to 1 (gem standart), or from 0
> to 1 (best for vertex shader)
> i also don't know if texture coordinate should be precomputed (like
> in newWave) or not.
>
> so, tell me what you think.
>
> maybe i should accept cvs write access and commit this myself...
>
> cyrille
>
> /*-----------------------------------------------------------------
> LOG
> GEM - Graphics Environment for Multimedia
>
> A mesh_square
>
> Copyright (c) 1997-2000 Mark Danks. mark at danks.org
> Copyright (c) G?nther Geiger. geiger at epy.co.at
> Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f?r::uml?ute.
> IEM. zmoelnig at iem.kug.ac.at
> For information on usage and redistribution, and for a DISCLAIMER
> OF ALL
> WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
>
> -----------------------------------------------------------------*/
>
> #ifndef INCLUDE_mesh_square_H_
> #define INCLUDE_mesh_square_H_
>
> #include "Base/GemShape.h"
>
>
> #define MAXGRID 1000
>
> /*-----------------------------------------------------------------
> -------------------------------------------------------------------
> CLASS
> mesh_square
>
> Creates a mesh_square
>
> KEYWORDS
> geo
>
> DESCRIPTION
>
> -----------------------------------------------------------------*/
> class GEM_EXTERN mesh_square : public GemShape
> {
> CPPEXTERN_HEADER(mesh_square, GemShape)
>
> public:
>
> //////////
> // Constructor
> mesh_square(t_floatarg sizeX,t_floatarg sizeY);
>
> protected:
>
> //////////
> // Destructor
> virtual ~mesh_square();
>
> int m_blend;
>
>
> //////////
> // Do the rendering
> virtual void render(GemState *state);
> static void blendMessCallback(void *data, t_floatarg size);
> static void gridMessCallback(void *data, t_floatarg size);
> static void gridXMessCallback(void *data, t_floatarg size);
> static void gridYMessCallback(void *data, t_floatarg size);
>
>
> //////////
> // getStuff
> int gridX, gridY;
> float xsize, xsize0, ysize, ysize0;
> int alreadyInit;
> void setSize( int valueX, int valueY );
> void getTexCoords(void);
> float texCoords[MAXGRID][MAXGRID][2];
> };
>
> #endif // for header file
> ////////////////////////////////////////////////////////
> //
> // GEM - Graphics Environment for Multimedia
> //
> // zmoelnig at iem.kug.ac.at
> //
> // Implementation file
> //
> // Copyright (c) 1997-2000 Mark Danks.
> // Copyright (c) G?nther Geiger.
> // Copyright (c) 2001-2002 IOhannes m zmoelnig.
> forum::f?r::uml?ute. IEM
> // For information on usage and redistribution, and for a
> DISCLAIMER OF ALL
> // WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this
> distribution.
> //
> /////////////////////////////////////////////////////////
>
> #include "mesh_square.h"
>
> #include "Base/GemState.h"
>
> CPPEXTERN_NEW_WITH_TWO_ARGS(mesh_square, t_floatarg, A_DEFFLOAT,
> t_floatarg, A_DEFFLOAT)
>
> /////////////////////////////////////////////////////////
> //
> // mesh_square
> //
> /////////////////////////////////////////////////////////
> // Constructor
> //
> /////////////////////////////////////////////////////////
> mesh_square :: mesh_square(t_floatarg sizeX, t_floatarg sizeY)
> : GemShape(1)
> {
> m_linewidth=1.0;
> // m_drawType = GL_QUADS;
> m_blend=0;
> setSize((int)sizeX,(int)sizeY);
> }
>
> /////////////////////////////////////////////////////////
> // Destructor
> //
> /////////////////////////////////////////////////////////
> mesh_square :: ~mesh_square()
> { }
>
> /////////////////////////////////////////////////////////
> // getTexCoords
> //
> /////////////////////////////////////////////////////////
> void mesh_square :: getTexCoords(void)
> {
> for ( int i = 0; i < gridX; ++i)
> {
> for ( int j = 0; j < gridY; ++j)
> {
> texCoords[i][j][0] = ((xsize*(float)i/(float)(gridX-1)) +
> xsize0 );
> texCoords[i][j][1] = ((ysize*(float)j/(float)(gridY-1)) + ysize0 );
> //post("texCoords[%d][%d] = %f\t%f",i,j,texCoords[i][j]
> [0],texCoords[i][j][1]);
> }
> }
> }
>
> /////////////////////////////////////////////////////////
> // setSize
> //
> /////////////////////////////////////////////////////////
> void mesh_square :: setSize( int valueX, int valueY )
> {
> if(valueX>1) gridX = valueX;
> else gridX = 5;
>
> if(valueY>1) gridY = valueY;
> else gridY = gridX;
>
> getTexCoords();
> }
>
>
> /////////////////////////////////////////////////////////
> // render
> //
> /////////////////////////////////////////////////////////
> void mesh_square :: render(GemState *state)
> {
> int i,j;
> GLfloat sizeX = 2. / (GLfloat)(gridX-1);
> GLfloat sizeY = 2. / (GLfloat)(gridY-1);
>
> if(m_drawType==GL_DEFAULT_GEM)m_drawType=GL_TRIANGLE_STRIP;
> //m_drawType=GL_LINES;
>
> glNormal3f(0.0f, 0.0f, 1.0f);
> if (m_drawType == GL_LINE_LOOP)
> m_drawType = GL_LINES;
>
> if (m_drawType == GL_LINES)
> glLineWidth(m_linewidth);
>
> if (m_blend) {
> glEnable(GL_POLYGON_SMOOTH);
> glEnable(GL_BLEND);
> glBlendFunc(GL_SRC_ALPHA,GL_ONE);
> glHint(GL_POLYGON_SMOOTH_HINT,GL_DONT_CARE);
> }
>
> glNormal3f( 0.0f, 0.0f, 1.0f);
>
> if (state->texture && state->numTexCoords>=3)
> {
> if ((xsize0!= state->texCoords[0].s) ||
> (xsize != state->texCoords[1].s-xsize0) ||
> (ysize0!= state->texCoords[1].t) ||
> (ysize != state->texCoords[2].t-ysize0))
> alreadyInit = 0;
>
> if (!alreadyInit)
> {
> xsize0 = state->texCoords[0].s;
> xsize = state->texCoords[1].s-xsize0;
> ysize0 = state->texCoords[1].t;
> ysize = state->texCoords[2].t-ysize0;
>
> setSize( gridX, gridY );
> alreadyInit = 1;
> }
>
> for (int i=0; i<(gridX-1) ; i++)
> {
> glBegin(m_drawType);
> for (int j = 0; j < gridY ; j++)
> {
> glTexCoord2fv( texCoords[i][j] );
> glVertex3f( m_size * (i*sizeX - 1), m_size * (j*sizeY
> -1) , 0);
>
> glTexCoord2fv( texCoords[i+1][j] );
> glVertex3f( m_size * ((i+1)*sizeX - 1), m_size *
> (j*sizeY -1), 0);
> }
> glEnd();
> }
> }else
> {
> if (!alreadyInit)
> {
> xsize = 1;
> ysize = 1;
> ysize0= 0;
> xsize0= 0;
>
> setSize( gridX, gridY);
> alreadyInit = 1;
> }
>
> for ( i = 0; i<(gridX -1); i++)
> {
> glBegin(m_drawType);
> for ( j = 0; j < gridY ; j++)
> {
> glTexCoord2fv( texCoords[i][j] );
> glVertex3f( m_size * (i*sizeX -1), m_size * (j*sizeY
> -1), 0 );
>
> glTexCoord2fv( texCoords[i+1][j] );
> glVertex3f( m_size * ((i+1)*sizeX -1), m_size *
> (j*sizeY -1), 0 );
> }
> glEnd();
> }
> }
>
> if (m_blend) {
> glDisable(GL_POLYGON_SMOOTH);
> glDisable(GL_BLEND);
> }
> }
>
> /////////////////////////////////////////////////////////
> // static member function
> //
> /////////////////////////////////////////////////////////
> void mesh_square :: obj_setupCallback(t_class *classPtr)
> { class_addmethod(classPtr,
> (t_method)&mesh_square::blendMessCallback,
> gensym("blend"), A_FLOAT, A_NULL);
> class_addmethod(classPtr, (t_method)&mesh_square::gridMessCallback,
> gensym("grid"), A_FLOAT, A_NULL);
> class_addmethod(classPtr,
> (t_method)&mesh_square::gridXMessCallback,
> gensym("gridX"), A_FLOAT, A_NULL);
> class_addmethod(classPtr,
> (t_method)&mesh_square::gridYMessCallback,
> gensym("gridY"), A_FLOAT, A_NULL);
> }
>
> void mesh_square :: blendMessCallback(void *data, t_floatarg blend)
> {
> GetMyClass(data)->m_blend=((int)blend);
> }
>
> void mesh_square :: gridMessCallback(void *data, t_floatarg grid)
> {
> GetMyClass(data)->gridX=(int)grid;
> GetMyClass(data)->gridY=(int)grid;
> }
>
> void mesh_square :: gridXMessCallback(void *data, t_floatarg grid)
> {
> GetMyClass(data)->gridX=(int)grid;
> }
>
> void mesh_square :: gridYMessCallback(void *data, t_floatarg grid)
> {
> GetMyClass(data)->gridY=(int)grid;
> }
>
>
> <mesh_square-help.pd>_______________________________________________
> GEM-dev mailing list
> GEM-dev at iem.at
> http://lists.puredata.info/listinfo/gem-dev
More information about the GEM-dev
mailing list