Commit aba05945 authored by IOhannes m zmölnig's avatar IOhannes m zmölnig
Browse files

added "draw" method to [model] and [multimodel]

Closes: https://sourceforge.net/p/pd-gem/feature-requests/54/
parent c2897fe1
......@@ -19,6 +19,16 @@
#include "plugins/modelloader.h"
#include <algorithm> // std::min
namespace {
static char mytolower(char in)
{
if(in<='Z' && in>='A') {
return in-('Z'-'z');
}
return in;
}
};
CPPEXTERN_NEW_WITH_ONE_ARG(model, t_symbol *, A_DEFSYM);
/////////////////////////////////////////////////////////
......@@ -37,8 +47,17 @@ model :: model(t_symbol *filename) :
m_texture (256,2),
m_color (256,4),
m_normal (256,3),
m_infoOut(gem::RTE::Outlet(this))
m_infoOut(gem::RTE::Outlet(this)),
m_drawType(GL_TRIANGLES)
{
m_drawTypes.clear();
m_drawTypes["default"]=m_drawType;
m_drawTypes["point"]=GL_POINTS;
m_drawTypes["points"]=GL_POINTS;
m_drawTypes["line"]=GL_LINES;
m_drawTypes["lines"]=GL_LINES;
m_drawTypes["fill"]=GL_TRIANGLES;
// make sure that there are some characters
if (filename&&filename->s_name&&*filename->s_name) {
openMess(filename->s_name);
......@@ -366,7 +385,7 @@ void model :: rescaleMess(bool state)
}
/////////////////////////////////////////////////////////
// matrialMess
// groupMess
//
/////////////////////////////////////////////////////////
void model :: groupMess(int state)
......@@ -376,6 +395,38 @@ void model :: groupMess(int state)
applyProperties();
}
/////////////////////////////////////////////////////////
// drawStyle
//
/////////////////////////////////////////////////////////
void model :: drawMess(int type)
{
/* raw */
m_drawType = type;
}
void model :: drawMess(std::string name)
{
if(0==m_drawTypes.size()) {
error("unable to change drawstyle");
return;
}
std::transform(name.begin(), name.end(), name.begin(), mytolower);
std::map<std::string, GLenum>::iterator it=m_drawTypes.find(name);
if(m_drawTypes.end() == it) {
error ("unknown draw style '%s'... possible values are:", name.c_str());
it=m_drawTypes.begin();
while(m_drawTypes.end() != it) {
error("\t %s", it->first.c_str());
++it;
}
return;
}
m_drawType=it->second;
}
/////////////////////////////////////////////////////////
// backendMess
//
......@@ -513,7 +564,7 @@ void model :: render(GemState *state)
if ( sizeList.size() > 0 ) {
unsigned int npoints = *std::min_element(sizeList.begin(),sizeList.end());
glDrawArrays(GL_TRIANGLES, 0, npoints);
glDrawArrays(m_drawType, 0, npoints);
}
if ( m_position.enabled ) {
......@@ -551,6 +602,9 @@ void model :: obj_setupCallback(t_class *classPtr)
CPPEXTERN_MSG0(classPtr, "enumProps", enumPropertyMess);
CPPEXTERN_MSG0(classPtr, "clearProps", clearPropertiesMess);
CPPEXTERN_MSG0(classPtr, "applyProps", applyProperties);
CPPEXTERN_MSG1(classPtr, "draw", drawMess, std::string);
CPPEXTERN_MSG1(classPtr, "type", drawMess, int);
}
void model :: createVBO(void)
......
......@@ -20,6 +20,8 @@
#include "Gem/VertexBuffer.h"
#include "RTE/Outlet.h"
#include <map>
/*-----------------------------------------------------------------
-------------------------------------------------------------------
CLASS
......@@ -89,6 +91,11 @@ protected:
// Set groups to render
virtual void groupMess(int group);
//////////
// draw type
virtual void drawMess(std::string);
virtual void drawMess(int);
//////////
// Set backend to use
virtual void backendMess(t_symbol*s, int argc, t_atom*argv);
......@@ -112,6 +119,9 @@ protected:
gem::RTE::Outlet m_infoOut;
std::vector<std::string> m_backends;
GLenum m_drawType;
std::map<std::string, GLenum>m_drawTypes;
};
#endif // for header file
......@@ -21,6 +21,17 @@
#include <string.h>
#include <stdio.h>
namespace {
static char mytolower(char in)
{
if(in<='Z' && in>='A') {
return in-('Z'-'z');
}
return in;
}
};
CPPEXTERN_NEW_WITH_FOUR_ARGS(multimodel, t_symbol *, A_DEFSYM, t_floatarg,
A_DEFFLOAT, t_floatarg, A_DEFFLOAT, t_floatarg, A_DEFFLOAT);
......@@ -40,10 +51,18 @@ multimodel :: multimodel(t_symbol *filename, t_floatarg baseModel,
m_texture (256,2),
m_color (256,4),
m_normal (256,3),
m_infoOut(gem::RTE::Outlet(this))
m_infoOut(gem::RTE::Outlet(this)),
m_drawType(GL_TRIANGLES)
{
m_drawTypes.clear();
m_drawTypes["default"]=m_drawType;
m_drawTypes["point"]=GL_POINTS;
m_drawTypes["points"]=GL_POINTS;
m_drawTypes["line"]=GL_LINES;
m_drawTypes["lines"]=GL_LINES;
m_drawTypes["fill"]=GL_TRIANGLES;
inlet_new(this->x_obj, &this->x_obj->ob_pd, &s_float, gensym("mdl_num"));
post("MULTIMODEL");
// make sure that there are some characters
if (filename&&filename->s_name&&*filename->s_name) {
......@@ -106,7 +125,7 @@ void multimodel :: materialMess(int material)
}
/////////////////////////////////////////////////////////
// materialMess
// textureMess
//
/////////////////////////////////////////////////////////
void multimodel :: textureMess(int state)
......@@ -145,7 +164,7 @@ void multimodel :: smoothMess(t_float fsmooth)
}
/////////////////////////////////////////////////////////
// rescaleMess
// reverseMess
//
/////////////////////////////////////////////////////////
void multimodel :: reverseMess(bool reverse)
......@@ -166,7 +185,7 @@ void multimodel :: rescaleMess(bool state)
}
/////////////////////////////////////////////////////////
// matrialMess
// groupMess
//
/////////////////////////////////////////////////////////
void multimodel :: groupMess(int state)
......@@ -176,6 +195,39 @@ void multimodel :: groupMess(int state)
applyProperties();
}
/////////////////////////////////////////////////////////
// drawStyle
//
/////////////////////////////////////////////////////////
void multimodel :: drawMess(int type)
{
/* raw */
m_drawType = type;
}
void multimodel :: drawMess(std::string name)
{
if(0==m_drawTypes.size()) {
error("unable to change drawstyle");
return;
}
std::transform(name.begin(), name.end(), name.begin(), mytolower);
std::map<std::string, GLenum>::iterator it=m_drawTypes.find(name);
if(m_drawTypes.end() == it) {
error ("unknown draw style '%s'... possible values are:", name.c_str());
it=m_drawTypes.begin();
while(m_drawTypes.end() != it) {
error("\t %s", it->first.c_str());
++it;
}
return;
}
m_drawType=it->second;
}
/////////////////////////////////////////////////////////
// backendMess
//
......@@ -413,7 +465,7 @@ void multimodel :: render(GemState *state)
if ( sizeList.size() > 0 ) {
unsigned int npoints = *std::min_element(sizeList.begin(),sizeList.end());
glDrawArrays(GL_TRIANGLES, 0, npoints);
glDrawArrays(m_drawType, 0, npoints);
}
if ( m_position.enabled ) {
......@@ -436,9 +488,7 @@ void multimodel :: render(GemState *state)
/////////////////////////////////////////////////////////
void multimodel :: obj_setupCallback(t_class *classPtr)
{
class_addmethod(classPtr,
reinterpret_cast<t_method>(&multimodel::openMessCallback),
gensym("open"), A_SYMBOL, A_FLOAT, A_DEFFLOAT, A_DEFFLOAT, A_NULL);
CPPEXTERN_MSG4(classPtr, "open", openMess, std::string, float, float, float);
CPPEXTERN_MSG1(classPtr, "mdl_num", changeModel, int);
CPPEXTERN_MSG1(classPtr, "rescale", rescaleMess, bool);
......@@ -448,15 +498,9 @@ void multimodel :: obj_setupCallback(t_class *classPtr)
CPPEXTERN_MSG1(classPtr, "texture", textureMess, int);
CPPEXTERN_MSG1(classPtr, "group", groupMess, int);
CPPEXTERN_MSG (classPtr, "loader", backendMess);
}
void multimodel :: openMessCallback(void *data, t_symbol *filesymbol,
t_float baseModel,
t_floatarg topModel, t_floatarg skipRate)
{
GetMyClass(data)->openMess(filesymbol->s_name, baseModel, topModel,
skipRate);
}
CPPEXTERN_MSG1(classPtr, "draw", drawMess, std::string);
}
void multimodel :: createVBO(void)
{
......
......@@ -20,6 +20,8 @@
#include "Gem/VertexBuffer.h"
#include "RTE/Outlet.h"
#include <map>
/*-----------------------------------------------------------------
-------------------------------------------------------------------
CLASS
......@@ -94,6 +96,12 @@ protected:
// Set groups to render
virtual void groupMess(int group);
//////////
// draw type
virtual void drawMess(std::string);
virtual void drawMess(int);
//////////
// Set backend to use
virtual void backendMess(t_symbol*s, int argc, t_atom*argv);
......@@ -120,12 +128,8 @@ protected:
gem::RTE::Outlet m_infoOut;
std::vector<std::string> m_backends;
private:
//////////
// static member functions
static void openMessCallback(void *data, t_symbol *filename,
t_float baseModel, t_float topModel, t_float skipRate);
GLenum m_drawType;
std::map<std::string, GLenum>m_drawTypes;
};
#endif // for header file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment