Exemple #1
0
static void h_deque_read_at_xml(t_h_deque *x, t_symbol *s, int argc, t_atom *argv)
{
  string symbol;
  int index=0;

  switch(argc)
    {
    default:
      post("h_deque read: only two argument are possible!");
      break;
    case 2:
      symbol = argv[0].a_w.w_symbol->s_name;
      index = (int)argv[1].a_w.w_float;
      break; 
    case 1:
      symbol = argv[0].a_w.w_symbol->s_name;
      index = 0;
      break;
    case 0:
      post("h_deque read: no filename!");
    }

  // make correct path
  char filnam[MAXPDSTRING];
  char filename[MAXPDSTRING];
  canvas_makefilename(x->x_canvas, (char*)symbol.c_str(), filnam, MAXPDSTRING);
  sys_bashfilename(filnam, filename);

  if(!x->hdeque->readFromFile2XML(filename,index))
    post("h_deque: couldn't read from file %s",s->s_name);
}
Exemple #2
0
/////////////////////////////////////////////////////////
// openFile
//
/////////////////////////////////////////////////////////
void pix_file_read :: openFile(t_symbol *filename)
{
  closeFile();

  // make the right filename
  char tmp_buff[MAXPDSTRING];
  char *path=tmp_buff;
  canvas_makefilename(getCanvas(), filename->s_name, tmp_buff, MAXPDSTRING);
  if (FILE*fd=fopen(tmp_buff, "r")) fclose(fd);
  else path=filename->s_name;

  // TODO: actually the fileReader should be returned based on the <file>
  // and not the other way round...

  fileReader = m_kernel.getFileReadServer().getPlugin();

  if(fileReader) {
    // get GEM framerate
    fileReader->setHostFramerate( GemMan::getFramerate() );

    // open file
    if(!(fileReader->openFile(path)))
      {
        error("could not open file %s", path);
        closeFile();
        return;
      }
    reallocate_m_image();
    infoSize();
  } else {
    error("couldn't find (suitable) VideoIO plugin for reading '%s'", path);
    return;
  }
}
Exemple #3
0
void pix_movieDS::openMess(t_symbol *filename, int format)
{
//	if (filename == x_filename)
//	{
//		return;
//	}

	x_filename	= filename;

	if (format)
	{
		m_colorspace	= format;
	}

	char buf[MAXPDSTRING];
	canvas_makefilename(getCanvas(), filename->s_name, buf, MAXPDSTRING);

	// Clean up any open files
	closeMess();

	realOpen(buf);

	if (FALSE == m_haveMovie)
	{
		return;
	}

	t_atom	ap[3];

	SETFLOAT(ap, m_numFrames);
	SETFLOAT(ap+1, m_xsize);
	SETFLOAT(ap+2, m_ysize);

	m_newFilm	= 1;
}
Exemple #4
0
/* CHECKED empty sequence stored as an empty file */
static void mtr_dowrite(t_mtr *x, t_mtrack *source, t_symbol *fname)
{
    int failed = 0;
    char path[MAXPDSTRING];
    FILE *fp;
    if (x->x_glist)
	canvas_makefilename(x->x_glist, fname->s_name, path, MAXPDSTRING);
    else
    {
    	strncpy(path, fname->s_name, MAXPDSTRING);
    	path[MAXPDSTRING-1] = 0;
    }
    /* CHECKED no global message */
    if (fp = sys_fopen(path, "w"))
    {
	/* CHECKED single-track writing does not seem to work (a bug?) */
	if (source) failed = mtr_writetrack(x, source, fp);
	else
	{
	    int id;
	    t_mtrack **tpp;
	    for (id = 0, tpp = x->x_tracks; id < x->x_ntracks; id++, tpp++)
		if (failed = mtr_writetrack(x, *tpp, fp))
		    break;
	}
	if (failed) sys_unixerror(path);  /* LATER rethink */
	fclose(fp);
    }
    else
    {
	sys_unixerror(path);  /* LATER rethink */
	failed = 1;
    }
    if (failed) loud_error((t_pd *)x, "writing text file \"%s\" failed", path);
}
Exemple #5
0
void pix_file_write :: openFile(t_symbol *filename)
{
  closeFile();

  // make the right filename
  char tmp_buff[MAXPDSTRING];
  char *path=tmp_buff;
  canvas_makefilename(getCanvas(), filename->s_name, tmp_buff, MAXPDSTRING);
  if (FILE*fd=fopen(tmp_buff, "r")) fclose(fd);
  else path=filename->s_name;

  // get the FileWrite plugin
  // TODO: the fileWriter should be returned based on the <file>
  // and not the other way round...
  fileWriter = m_kernel.getFileWriteServer().getPlugin();

  if(fileWriter) {
    // open file
    if( !fileWriter->openFile(path) )
      {
        error("could not open file %s", path);
        closeFile();
        return;
      }
  } else {
    error("couldn't find (suitable) VideoIO plugin for writing '%s'!", path);
    return;
  }

}
Exemple #6
0
void pix_filmOS :: openMess(t_symbol *filename, int format)
{
  //  if (filename==x_filename)return;
  x_filename=filename;
  if (format)m_colorspace=format;

  char buf[MAXPDSTRING];
  canvas_makefilename(const_cast<t_canvas*>(getCanvas()), filename->s_name, buf, MAXPDSTRING);

  // Clean up any open files
  closeMess();

  m_haveMovie = GEM_MOVIE_NONE;
  realOpen(buf);
  if (m_haveMovie == GEM_MOVIE_NONE)return;
  
#ifndef __APPLE__
  createBuffer();
  prepareTexture();
#endif

  t_atom ap[3];
  SETFLOAT(ap, m_numFrames);
  SETFLOAT(ap+1, m_xsize);
  SETFLOAT(ap+2, m_ysize);

  m_newFilm = 1;
  post("loaded file: %s with %d frames (%dx%d)", buf, m_numFrames, m_xsize, m_ysize);
  outlet_list(m_outNumFrames, 0, 3, ap);
}
Exemple #7
0
    void photo_drawme(t_photo *x, t_glist *glist, int firsttime)
{
	if (firsttime) 
    {
		char fname[MAXPDSTRING];
		canvas_makefilename(glist_getcanvas(x->x_glist), x->filename->s_name,
							fname, MAXPDSTRING);

        sys_vgui("image create photo img%x -file {%s}\n", x, fname);
        sys_vgui(".x%x.c create image %d %d -image img%x -anchor nw -tags %xS\n", 
                 glist_getcanvas(glist),text_xpix(&x->x_obj, glist), 
                 text_ypix(&x->x_obj, glist),x,x);

        /* TODO callback from gui
           sys_vgui("photo_size logo");
        */
    }     
    else 
    {
        sys_vgui(".x%x.c coords %xS %d %d\n",
                 glist_getcanvas(glist), x,
                 text_xpix(&x->x_obj, glist), text_ypix(&x->x_obj, glist));
    }
	
}
Exemple #8
0
static void xeq_mfwrite(t_xeq *x, t_symbol *filename, t_symbol *tts)
{
    char buf[MAXPDSTRING];
    canvas_makefilename(x->x_canvas, filename->s_name,
			buf, MAXPDSTRING);
    if (mfbb_write(x->x_binbuf, buf, "", tts))
	error("%s: write failed", filename->s_name);
}
Exemple #9
0
static void h_multimap_read(t_h_multimap *x, t_symbol *s)
{
  // make correct path
  char filnam[MAXPDSTRING];
  char filename[MAXPDSTRING];
  canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING);
  sys_bashfilename(filnam, filename);

  if(!x->hmultimap->readFromFile(filename))
    post("h_multimap: couldn't read from file %s",s->s_name);
}
Exemple #10
0
static void lms_tilde_write(t_lms_tilde *x, t_symbol *s)
{
  // make correct path
  char filnam[MAXPDSTRING];
  char filename[MAXPDSTRING];
  canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING);
  sys_bashfilename(filnam, filename);

  // save to file
  adaptation_write(filename, x->N, x->mu, x->c);
}
Exemple #11
0
static void h_deque_read(t_h_deque *x, t_symbol *s, int argc, t_atom *argv)
{
  // make correct path
  char filnam[MAXPDSTRING];
  char filename[MAXPDSTRING];
  canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING);
  sys_bashfilename(filnam, filename);

  if(!x->hdeque->readFromFile(filename))
    post("h_deque: couldn't read from file %s",s->s_name);
}
Exemple #12
0
static void lms_tilde_read(t_lms_tilde *x, t_symbol *s)
{
  // make correct path
  char filnam[MAXPDSTRING];
  char filename[MAXPDSTRING];
  canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING);
  sys_bashfilename(filnam, filename);
  
  // read file
  adaptation_read(filename, &x->N, &x->mu, x->c, x->buf);
}
Exemple #13
0
static void h_list_read_xml(t_h_list *x, t_symbol *s)
{
  // make correct path
  char filnam[MAXPDSTRING];
  char filename[MAXPDSTRING];
  canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING);
  sys_bashfilename(filnam, filename);

  if(!x->hlist->readFromFileXML(filename))
    post("h_list: couldn't read from file %s",s->s_name);
}
Exemple #14
0
static void funbuff_dowrite(t_funbuff *x, t_symbol *fn)
{
    t_binbuf *bb = binbuf_new();
    char buf[MAXPDSTRING];
    t_hammernode *np;
    binbuf_addv(bb, "s", atom_getsymbol(binbuf_getvec(x->x_ob.te_binbuf)));
    for (np = x->x_tree.t_first; np; np = np->n_next)
        binbuf_addv(bb, "if", np->n_key, HAMMERNODE_GETFLOAT(np));
    canvas_makefilename(x->x_canvas, fn->s_name, buf, MAXPDSTRING);
    binbuf_write(bb, buf, "", 0);
    binbuf_free(bb);
}
static void qlist_write(t_qlist *x, t_symbol *filename, t_symbol *format)
{
    int cr = 0;
    char buf[MAXPDSTRING];
    canvas_makefilename(x->x_canvas, filename->s_name,
        buf, MAXPDSTRING);
    if (!strcmp(format->s_name, "cr"))
        cr = 1;
    else if (*format->s_name)
        pd_error(x, "qlist_read: unknown flag: %s", format->s_name);
    if (binbuf_write(x->x_binbuf, buf, "", cr))
            pd_error(x, "%s: write failed", filename->s_name);
}
Exemple #16
0
FILE *filewrite_open(char *filename, t_canvas *cv, int textmode)
{
    char path[MAXPDSTRING+2];
    if (cv)
	/* path arg is returned unbashed (system-independent) */
	canvas_makefilename(cv, filename, path, MAXPDSTRING);
    else
    {
    	strncpy(path, filename, MAXPDSTRING);
    	path[MAXPDSTRING-1] = 0;
    }
    return (sys_fopen(path, (textmode ? "w" : "wb")));
}
Exemple #17
0
static void h_list_save_xml(t_h_list *x, t_symbol *s)
{
  // make correct path
  char filnam[MAXPDSTRING];
  char filename[MAXPDSTRING];
  canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING);
  sys_bashfilename(filnam, filename);

  if(x->hlist->saveToFileXML(filename))
    post("h_list: data of namespace %s written to file %s",
         x->hlist->getNamespace().c_str(),s->s_name);
  else
    post("h_list: couldn't write to file %s",s->s_name);
}
Exemple #18
0
void image_doopen(t_image* x) {
	char fname[FILENAME_MAX];
	FILE *file;
	if (strlen(x->x_fname->s_name) == 0) {
		x->x_fname = gensym("@pd_extra/ggee/empty_image.png");
	}
	t_glist *glist = glist_getcanvas(x->x_glist);
	canvas_makefilename(glist_getcanvas(x->x_glist), x->x_fname->s_name, fname, FILENAME_MAX);
	// try to open the file
	if (file = fopen(fname, "r"))
    {
        fclose(file);
    } else {
     	x->x_fname = gensym("@pd_extra/ggee/empty_image.png");
    	canvas_makefilename(glist_getcanvas(x->x_glist), x->x_fname->s_name, fname, FILENAME_MAX);   	
    }
	sys_vgui(".x%lx.c itemconfigure %xS -image\n", glist, x);
	sys_vgui("catch {image delete $img%x}\n", x);
	sys_vgui("set img%x [image create photo -file {%s}]\n", x, fname);
	sys_vgui("if { [catch {image width $img%x} fid] } { pd [concat %s _imagesize 0 0 \\;] }\n", x, x->x_receive->s_name);
	sys_vgui(".x%lx.c itemconfigure %xS -image $img%x\n", glist, x, x);
	sys_vgui("pd [concat %s _imagesize [image width $img%x] [image height $img%x] \\;]\n",x->x_receive->s_name, x, x);
}
Exemple #19
0
static void ctw_set_file(void *x, int argc, t_atom *argv) {
	struct _ctw *common = x;
	t_symbol *filename;
	char buf[MAXPDSTRING];

	string_free(common->out_file, &common->out_file_len);
	if (argc == 0) {
		return;
	}
	filename = atom_getsymbol(argv);
	if (filename == 0) {
		pd_error(x, "not a filename");
		return;
	}
	canvas_makefilename(common->x_canvas, filename->s_name, buf, MAXPDSTRING);
	common->out_file = string_create(&(common->out_file_len), strlen(buf));
	strcpy(common->out_file, buf);
}
Exemple #20
0
/////////////////////////////////////////////////////////
// openMess
//
/////////////////////////////////////////////////////////
void model :: openMess(const std::string&filename)
{
    if(!m_loader) {
        error("no model loader backends found");
        return;
    }
    m_loader->close();
    m_loaded=false;

    char buf[MAXPDSTRING];
    canvas_makefilename(const_cast<t_canvas*>(getCanvas()), const_cast<char*>(filename.c_str()), buf, MAXPDSTRING);
    if(!m_loader->open(buf, m_properties)) {
        error("unable to read model '%s'", buf);
        return;
    }

    m_loaded=true;
    setModified();
}
Exemple #21
0
static void xeq_write(t_xeq *x, t_symbol *filename,
		      t_symbol *format, t_symbol *tts)
{
    int cr = 0;
    char buf[MAXPDSTRING];
    if (!strcmp(format->s_name, "cr"))
    	cr = 1;
    else if (!strcmp(format->s_name, "mf"))
    {
	xeq_mfwrite(x, filename, tts);
	return;
    }
    else if (*format->s_name)
    	error("xeq_read: unknown flag: %s", format->s_name);
    canvas_makefilename(x->x_canvas, filename->s_name,
    	buf, MAXPDSTRING);
    if (binbuf_write(x->x_binbuf, buf, "", cr))
	error("%s: write failed", filename->s_name);
}
Exemple #22
0
static void nlms2_tilde_read(t_nlms2_tilde *x, t_symbol *s)
{
  // make correct path
  char filnam[MAXPDSTRING];
  char filename[MAXPDSTRING];
  int n = x->N;
  canvas_makefilename(x->x_canvas, s->s_name, filnam, MAXPDSTRING);
  sys_bashfilename(filnam, filename);
  
  // read file
  adaptation_read(filename, &x->N, &x->mu, x->c, x->buf);
  
  // if length changes:
  if(x->N != n)
  {
    if(x->coef) freebytes(x->coef, sizeof(t_atom) * x->N);
    x->coef = (t_atom *)getbytes(sizeof(t_atom) * x->N);
  }
}
Exemple #23
0
/* tries to expand the given filename to it's full glory) */
t_symbol*get_filename(t_canvas*canvas, t_symbol*s) {
  int fd=0;
  char buf[MAXPDSTRING];
  char result[MAXPDSTRING];
  char*bufptr;

  if(!s || !s->s_name || !*s->s_name) {
    return NULL;
  }

  if ((fd=canvas_open(canvas, s->s_name, "", buf, &bufptr, MAXPDSTRING, 1))>=0){
    sys_close(fd);
    snprintf(result, MAXPDSTRING-1, "%s/%s", buf, bufptr);
    result[MAXPDSTRING-1]=0;
    return gensym(result);
  } else if(canvas) {
    canvas_makefilename(canvas, s->s_name, result, MAXPDSTRING);
    return gensym(result);
  }
  return s;
}
Exemple #24
0
static void funbuff_doread(t_funbuff *x, t_symbol *fn)
{
    t_binbuf *bb = binbuf_new();
    int ac;
    t_atom *av;
    char buf[MAXPDSTRING];
    /* FIXME use open_via_path() */
    canvas_makefilename(x->x_canvas, fn->s_name, buf, MAXPDSTRING);
    binbuf_read(bb, buf, "", 0);
    if ((ac = binbuf_getnatom(bb)) &&
            (av = binbuf_getvec(bb)) &&
            av->a_type == A_SYMBOL &&
            av->a_w.w_symbol == gensym("funbuff"))
    {
        post("funbuff_read: %s read successful", fn->s_name);  /* CHECKED */
        funbuff_set(x, 0, ac-1, av+1);
    }
    else  /* CHECKED no complaints... */
        loud_error((t_pd *)x, "invalid file %s", fn->s_name);
    binbuf_free(bb);
}
Exemple #25
0
  static std::string getFullfilename(const t_canvas*canvas, const char*filename, const char*ext) {
    std::string fullname_;

    char buf[MAXPDSTRING];
    char*bufptr;
    int fd=0;
    if ((fd=canvas_open(const_cast<t_canvas*>(canvas), filename, ext, buf, &bufptr, MAXPDSTRING, 1))>=0){
      ::close(fd);
      fullname_=buf;
      fullname_+="/";
      fullname_+=bufptr;
    } else {
      if(canvas) {
        canvas_makefilename(const_cast<t_canvas*>(canvas), const_cast<char*>(filename), buf, MAXPDSTRING);
        fullname_=buf;
      } else {
        return std::string("");
      }
    }
    return fullname_;
  }
Exemple #26
0
std::string CPPExtern::findFile(const std::string f, const std::string e) const {
    char buf[MAXPDSTRING], buf2[MAXPDSTRING];
    char*bufptr=0;
    std::string result="";
    int fd=-1;

    t_canvas*canvas=const_cast<t_canvas*>(getCanvas());
    char*filename=const_cast<char*>(f.c_str());
    char*ext=const_cast<char*>(e.c_str());

    if ((fd=open_via_path(canvas_getdir(canvas)->s_name, filename, ext,
                          buf2, &bufptr, MAXPDSTRING, 1))>=0) {
        sys_close(fd);
        result=buf2;
        result+="/";
        result+=bufptr;
    } else {
        canvas_makefilename(canvas, filename, buf, MAXPDSTRING);
        result=buf;
    }
    return result;
}
Exemple #27
0
static void capture_dowrite(t_capture *x, t_symbol *fn)
{
    FILE *fp = 0;
    int count = x->x_count;
    char buf[MAXPDSTRING];
    canvas_makefilename(glist_getcanvas(x->x_glist),
			fn->s_name, buf, MAXPDSTRING);
    if (fp = sys_fopen(buf, "w"))  /* LATER ask if overwriting, CHECKME */
    {
	int col = 0;
	if (x->x_mode == 'f' || count < x->x_bufsize)
	{
	    float *bp = x->x_buffer;
	    while (count--)
		if ((col = capture_writefloat(x, *bp++, buf, col, fp)) < 0)
		    goto fail;
	}
	else
	{
	    float *bp = x->x_buffer + x->x_head;
	    count = x->x_bufsize - x->x_head;
	    while (count--)
		if ((col = capture_writefloat(x, *bp++, buf, col, fp)) < 0)
		    goto fail;
	    bp = x->x_buffer;
	    count = x->x_head;
	    while (count--)
		if ((col = capture_writefloat(x, *bp++, buf, col, fp)) < 0)
		    goto fail;
	}
	if (col) fputc('\n', fp);
	fclose(fp);
	return;
    }
fail:
    if (fp) fclose(fp);
    loud_syserror((t_pd *)x, 0);
}
Exemple #28
0
  bool open(std::string name, const t_canvas*canvas) {
    bool loud=false;
    const char*hookname="plugMain";
    if(name.empty())
      return false;

    if(m_plugin)
      close();

    FF_Main_FuncPtr plugmain = NULL;

    char buf[MAXPDSTRING];
    char buf2[MAXPDSTRING];
    char *bufptr=NULL;

    const char *extension=
#ifdef _WIN32
      ".dll";
#elif defined __APPLE__
    "";
#else
    ".so";
#endif

#ifdef __APPLE__
    char buf3[MAXPDSTRING];
#ifdef DL_OPEN
    snprintf(buf3, MAXPDSTRING, "%s.frf/Contents/MacOS/%s", name.c_str(), name.c_str());
#else
    // this can never work...
    snprintf(buf3, MAXPDSTRING, "%s.frf/%s", name.c_str(), name.c_str());
#endif
    buf3[MAXPDSTRING-1]=0;
    name=buf3;
#endif

    int fd=-1;
    if ((fd=canvas_open(const_cast<t_canvas*>(canvas), name.c_str(), extension, buf2, &bufptr, MAXPDSTRING, 1))>=0){
      ::close(fd);
#if defined __APPLE__ && 0
      snprintf(buf, MAXPDSTRING, "%s", buf2);
#else
      snprintf(buf, MAXPDSTRING, "%s/%s", buf2, bufptr);
#endif
      buf[MAXPDSTRING-1]=0;
    } else {
      if(canvas) {
        canvas_makefilename(const_cast<t_canvas*>(canvas), const_cast<char*>(name.c_str()), buf, MAXPDSTRING);
      } else {
        if(loud)::error("pix_freeframe[%s]: unfindeable", name.c_str());
        return false;
      }
    }
    name=buf;
    std::string libname = name;

    if(loud)::post("trying to load %s", buf);

#ifdef DL_OPEN
    if(loud)::post("dlopen %s", libname.c_str());
    m_dlhandle=dlopen(libname.c_str(), RTLD_NOW);
    if(!m_dlhandle){
      if(loud)::error("pix_freeframe[%s]: %s", libname.c_str(), dlerror());
      return NULL;
    }
    dlerror();

    plugmain = reinterpret_cast<FF_Main_FuncPtr>(dlsym(m_dlhandle, hookname));

#elif defined __APPLE__
    CFURLRef bundleURL = NULL;
    CFBundleRef theBundle = NULL;
    CFStringRef plugin = CFStringCreateWithCString(NULL,
                                                   libname.c_str(), kCFStringEncodingMacRoman);

    bundleURL = CFURLCreateWithFileSystemPath( kCFAllocatorSystemDefault,
                                               plugin,
                                               kCFURLPOSIXPathStyle,
                                               true );
    theBundle = CFBundleCreate( kCFAllocatorSystemDefault, bundleURL );

    // Get a pointer to the function.
    if (theBundle){
      plugmain = reinterpret_cast<FF_Main_FuncPtr>(CFBundleGetFunctionPointerForName(
                                                                                     theBundle, CFSTR("plugMain") )
                                                   );
    }else{
      if(loud)::post("%s: couldn't load", libname.c_str());
      return 0;
    }
    if(bundleURL != NULL) CFRelease( bundleURL );
    if(theBundle != NULL) CFRelease( theBundle );
    if(plugin != NULL)    CFRelease( plugin );
#elif defined _WIN32
    char buffer[MAXPDSTRING];
    sys_bashfilename(libname.c_str(), buffer);
    libname=buffer;
    m_w32handle = LoadLibrary(libname.c_str());
    if (!m_w32handle) {
      if(loud)::post("%s: couldn't load", libname.c_str());
      return false;
    }
    plugmain = reinterpret_cast<FF_Main_FuncPtr>(GetProcAddress(m_w32handle, hookname));
#else
# error no way to load dynamic linked libraries on this OS
#endif

    m_plugin=plugmain;
    return (NULL!=m_plugin);
  }
Exemple #29
0
/////////////////////////////////////////////////////////
// openMess
//
/////////////////////////////////////////////////////////
void vertex_model :: openMess(t_symbol *filename)
{
 GLMgroup*  	group;
 GLMtriangle*  	triangle;
 float*	tritext;  //texture coords for a triangle
 float*	trivert;  //vertices of one point in a triangle
 float*  trinorm;
 int src2,src3, src4,numvertices;
 unsigned int i;

 m_haveModel = 0;
  //cleanModel();
 
  char buf[MAXPDSTRING];
  canvas_makefilename(const_cast<t_canvas*>(getCanvas()), filename->s_name, buf, MAXPDSTRING);
  // read the object in
  m_model = glmReadOBJ(buf);

  if (!m_model) return;    

  // set the size to -1 to 1
  if (m_rescaleModel)
    glmUnitize(m_model);

  group = m_model->groups;
  glmFacetNormals (m_model);
  glmVertexNormals(m_model, 90);
  glmTexture(m_model, GLM_TEX_DEFAULT, 1, 1);
 
  post("model->numtriangles %d",m_model->numtriangles);
  post("model->numgroups %d",m_model->numgroups);
  post("model->numvertices %d",m_model->numvertices);
  post("model->numnormals %d",m_model->numnormals);
  post("model->numtexcoords %d",m_model->numtexcoords);
 
  numvertices = static_cast<int>(m_model->numtriangles * m_model->numgroups * 3);
  m_vertcount = numvertices;

  // would it be a bad idea to make all arrays equally sized ?
  // (fill up the missing elements with zeros

  delete [] m_VertexArray;
  m_VertexArray = new float[numvertices * 4];  // x, y, z, w
  delete [] m_ColorArray;
  m_ColorArray = new float[numvertices * 4];   // r, g, b, a
  delete [] m_TexCoordArray;
  m_TexCoordArray = new float[numvertices * 2];// u, v
  delete [] m_NormalArray;
  m_NormalArray = new float[numvertices * 3];  // x, y, z

  delete [] m_tempVA;
  m_tempVA = new float[numvertices * 4];
  delete [] m_tempCA;
  m_tempCA = new float[numvertices * 4];
  delete [] m_tempTA;
  m_tempTA = new float[numvertices * 2];
  delete [] m_tempNA;
  m_tempNA = new float[numvertices * 3];
  
  src2 = 0;
  src3 = 0;
  src4 = 0;
  while(group){
    for (i = 0; i < group->numtriangles; i++) {
        triangle = &T(group->triangles[i]);
        trivert = &m_model->vertices[3 * triangle->vindices[0]];
        m_VertexArray[src4] = trivert[0];
        m_VertexArray[src4+1] = trivert[1];
        m_VertexArray[src4+2] = trivert[2];
        m_VertexArray[src4+3] = 1;
        m_ColorArray[src4] = 1;
        m_ColorArray[src4+1] = 1;
        m_ColorArray[src4+2] = 1;
        m_ColorArray[src4+3] = 1;
        tritext = &m_model->texcoords[2 * triangle->tindices[0]];
        m_TexCoordArray[src2] = tritext[0];
        m_TexCoordArray[src2+1] = tritext[1];
        trinorm = &m_model->normals[3 * triangle->nindices[0]];
        m_NormalArray[src3] = trinorm[0];
        m_NormalArray[src3+1] = trinorm[1];
        m_NormalArray[src3+2] = trinorm[2];
        src3 += 3;
        src2 += 2;
        src4 += 4;
        trivert = &m_model->vertices[3 * triangle->vindices[1]];
        m_VertexArray[src4] = trivert[0];
        m_VertexArray[src4+1] = trivert[1];
        m_VertexArray[src4+2] = trivert[2];
        m_VertexArray[src4+3] = 1;
        m_ColorArray[src4] = 1;
        m_ColorArray[src4+1] = 1;
        m_ColorArray[src4+2] = 1;
        m_ColorArray[src4+3] = 1;
        tritext = &m_model->texcoords[2 * triangle->tindices[1]];
        m_TexCoordArray[src2] = tritext[0];
        m_TexCoordArray[src2+1] = tritext[1];
        trinorm = &m_model->normals[3 * triangle->nindices[1]];
        m_NormalArray[src3] = trinorm[0];
        m_NormalArray[src3+1] = trinorm[1];
        m_NormalArray[src3+2] = trinorm[2];
        src3 += 3;
        src2 += 2;
        src4 += 4;
        trivert = &m_model->vertices[3 * triangle->vindices[2]];
        m_VertexArray[src4] = trivert[0];
        m_VertexArray[src4+1] = trivert[1];
        m_VertexArray[src4+2] = trivert[2];
        m_VertexArray[src4+3] = 1;
        m_ColorArray[src4] = 1;
        m_ColorArray[src4+1] = 1;
        m_ColorArray[src4+2] = 1;
        m_ColorArray[src4+3] = 1;
        tritext = &m_model->texcoords[2 * triangle->tindices[2]];
        m_TexCoordArray[src2] = tritext[0];
        m_TexCoordArray[src2+1] = tritext[1];
        trinorm = &m_model->normals[3 * triangle->nindices[2]];
        m_NormalArray[src3] = trinorm[0];
        m_NormalArray[src3+1] = trinorm[1];
        m_NormalArray[src3+2] = trinorm[2];
        src3 += 3;
        src2 += 2;
        src4 += 4;
        
        }
    group = group->next;
   }
  
  src4 = src4/4;
  src2 = src2/4;
  post("i %d",i);
  post("src2 %d",src2);
  post("src4 %d",src4);

  m_haveModel = 1;
  this->setModified();
}
Exemple #30
0
/////////////////////////////////////////////////////////
// openMess
//
/////////////////////////////////////////////////////////
void pix_multiimage :: openMess(t_symbol *filename, int baseImage, int topImage, int skipRate)
{
    cleanImages();

    if (m_cache&&m_cache->m_magic!=GEMCACHE_MAGIC)
      m_cache=NULL;
    /*
    if (!topImage)
    {
    	error("requires an int for number of images");
        return;
    }
    */
    if (baseImage > topImage)
    {
        error("Top range less than base image");
        return;
    }
    if (skipRate < 1) skipRate = 1;

    // have we already loaded the image?
    multiImageCache *cache = s_imageCache;
    int found = 0;
    while (!found && cache)
    {
        if (baseImage == cache->baseImage &&
            topImage == cache->topImage &&
            skipRate == cache->skipRate &&
            !strcmp(filename->s_name, cache->imageName)) found = 1;
        else cache = cache->next;
    }

    // yep, we have it
    if (found)
    {
        m_loadedCache = cache;
        m_loadedCache->refCount++;
        m_curImage = 0;
        m_numImages = m_loadedCache->numImages;
        m_loadedCache->images[m_curImage]->copy2Image(&m_pixBlock.image);
        m_pixBlock.newimage = 1;
        if (m_cache) m_cache->resendImage = 1;
        return;
    }

    // nope, so create the new cache
    // find the * in the filename
    char preName[256];
    char postName[256];

    int i = 0;
    char *strPtr = filename->s_name;
    while (strPtr[i] && strPtr[i] != '*')
    {
    	preName[i] = strPtr[i];
    	i++;
    }

    if (!strPtr[i])
    {
    	error("Unable to find * in file name");
    	return;
    }

    preName[i] = '\0';
    strcpy(postName, &(strPtr[i+1]));

    // need to figure out how many filenames there are to load
    m_numImages = (topImage + 1 - baseImage) / skipRate;

    // create the new cache
    multiImageCache *newCache = new multiImageCache(filename->s_name);
    newCache->images = new imageStruct*[m_numImages];
    newCache->numImages = m_numImages;
    newCache->baseImage = baseImage;
    newCache->topImage = topImage;
    newCache->skipRate = skipRate;

    int realNum = baseImage;
    char bufName[MAXPDSTRING];
    canvas_makefilename(const_cast<t_canvas*>(getCanvas()), preName, bufName, MAXPDSTRING);

    // allocate texture bindings for OpenGL
    newCache->textBind = new unsigned int[m_numImages];

    for (i = 0; i < m_numImages; i++, realNum += skipRate)
    {
        char newName[MAXPDSTRING];
	    sprintf(newName, "%s%d%s", bufName, realNum, postName);
		newCache->textBind[i] = 0;
        if ( !(newCache->images[i] = image2mem(newName)) )
	    {
            // a load failed, blow away the cache
            newCache->numImages = i;
            delete newCache;
    	    m_numImages = 0;
	        return;
	    }
    }

    m_curImage = 0;
    newCache->images[m_curImage]->copy2Image(&m_pixBlock.image);
    m_pixBlock.newimage = 1;
    if (m_cache) m_cache->resendImage = 1;

    m_loadedCache = newCache;
    newCache->refCount++;

    // insert the cache at the end of the linked list
    multiImageCache *ptr = s_imageCache;

    if (!ptr) s_imageCache = newCache;
    else
    {
        while(ptr->next) ptr = ptr->next;
        ptr->next = newCache;
    }

    post("loaded images: %s %s from %d to %d skipping %d",
                bufName, postName, baseImage, topImage, skipRate);
}