home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / gprim / mesh / meshcopy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-26  |  2.2 KB  |  78 lines

  1. /* Copyright (c) 1992 The Geometry Center; University of Minnesota
  2.    1300 South Second Street;  Minneapolis, MN  55454, USA;
  3.    
  4. This file is part of geomview/OOGL. geomview/OOGL is free software;
  5. you can redistribute it and/or modify it only under the terms given in
  6. the file COPYING, which you should have received along with this file.
  7. This and other related software may be obtained via anonymous ftp from
  8. geom.umn.edu; email: software@geom.umn.edu. */
  9.  
  10. /* Authors: Charlie Gunn, Stuart Levy, Tamara Munzner, Mark Phillips */
  11.  
  12. #include "meshP.h"
  13.  
  14. Mesh *
  15. MeshCopy(obj)
  16.     Mesh *obj;
  17. {
  18.     register Mesh  *m;
  19.     register Mesh  *om = obj;
  20.     register int    n;
  21.  
  22.     if (om == NULL) return (NULL);
  23.  
  24.     if ( (m = GeomNew(Mesh)) == NULL ) {
  25.            GeomError(0,"Can't allocate space for mesh");
  26.            return (NULL);
  27.         }
  28.  
  29.     *m = *om; /* copy scalar fields */
  30.     n = m->nu * m->nv;
  31.     if ((m->p = GeomNewN(HPoint3, n)) == NULL) {
  32.            GeomError(0,"Can't allocate space for mesh vertices");
  33.            return (NULL);
  34.         }
  35.     bcopy(om->p, m->p, n * sizeof(HPoint3));
  36.  
  37.     if (m->flag & MESH_N) {
  38.            if ((m->n = GeomNewN(Point3, n)) == NULL) {
  39.                 GeomError(0,"Can't allocate space for mesh normals");
  40.                 return(NULL);
  41.            }
  42.            bcopy(om->n, m->n, n * sizeof(Point3));
  43.     } else
  44.         m->n = NULL;
  45.  
  46.     if (m->flag & MESH_C) {
  47.            if ((m->c = GeomNewN(ColorA, n)) == NULL) {
  48.                 GeomError(0,"Can't allocate space for mesh colors");
  49.                 return(NULL);
  50.            }
  51.        bcopy(om->c, m->c, n * sizeof(ColorA));
  52.     } else
  53.         m->c = NULL;
  54.  
  55.     if (m->flag & MESH_U) {
  56.            if ((m->u = GeomNewN(Point3, n)) == NULL) {
  57.                 GeomError(0,"Can't allocate space for mesh texture");
  58.                 return(NULL);
  59.            }
  60.        bcopy(om->u, m->u, n * sizeof(Point3));
  61.     } else
  62.                 m->u = NULL;
  63.  
  64.     if (m->flag & MESH_D) {
  65.        if ((m->d = GeomNewN(float, n)) == NULL
  66.             || (m->nd = GeomNewN(Point3, n)) == NULL) {
  67.               GeomError(0,"Can't allocate space for mesh d/nd");
  68.               return(NULL);
  69.            }
  70.        bcopy(om->nd, m->nd, n * sizeof(Point3));
  71.        bcopy(om->d, m->d, n * sizeof(float));
  72.     } else {
  73.         m->d = NULL;
  74.         m->nd = NULL;
  75.     }
  76.     return m;
  77. }
  78.