コード例 #1
0
ファイル: obj2ply.cpp プロジェクト: ingeyu/airengine
void	read_obj(const char* strName)
{
  int i,j,k;
  FILE *fp;
  int nwords;
  char *comment_ptr;
  char *first_word;
  float x,y,z,w;

  /* read from standard input */
  fp = fopen(strName,"r");

  while (1) {

    comment_ptr = fetch_line (fp);

    if (comment_ptr == (char *) -1)  /* end-of-file */
      break;

    /* did we get a comment? */
    if (comment_ptr) {
      make_comment (comment_ptr);
      continue;
    }

    /* if we get here, the line was not a comment */

    nwords = fetch_words();

    /* skip empty lines */
    if (nwords == 0)
      continue;

    first_word = words[0];

    if (equal_strings (first_word, "v")) {
      if (nwords < 4) {
		  fprintf (stderr, "Too few coordinates: '%s'", str_orig);
		  exit (-1);
      }
#ifdef	NEW_LOAD

	  float3 pos;
	  pos.x	=	atof (words[1]);
	  pos.y	=	atof (words[2]);
	  pos.z	=	atof (words[3]);
	  vPosition.push_back(pos);
#else
      x = atof (words[1]);
      y = atof (words[2]);
      z = atof (words[3]);
      if (nwords == 5) {
        w = atof (words[3]);

	has_w = 1;
      }
      else
        w = 1.0;
      make_vertex (x, y, z, w);
#endif
    }
    else if (equal_strings (first_word, "vn")) {
#ifdef	NEW_LOAD
		float3 n;
		n.x	=	atof (words[1]);
		n.y	=	atof (words[2]);
		n.z	=	atof (words[3]);
		vNormal.push_back(n);	
		has_normals	=	true;
#endif
    }
    else if (equal_strings (first_word, "vt")) {
#ifdef	NEW_LOAD
		float2 t;
		t.x	=	atof (words[1]);
		t.y	=	atof (words[2]);
		vUV.push_back(t);	
		texture_coords	=	true;
#endif
    }
    else if (equal_strings (first_word, "f")) {
#ifdef NEW_LOAD
		LoadFace(&words[1],nwords-1);
#else
      make_face (&words[1], nwords-1);
#endif
    }
    else {
      fprintf (stderr, "Do not recognize: '%s'\n", str_orig);
    }

  }

  nverts	=	vVertex.size();
  nfaces	=	vIndex.size()/3;
  fclose(fp);
}
コード例 #2
0
void read_obj ( void )

/******************************************************************************/
/*
  Purpose:

    READ_OBJ reads in a Wavefront OBJ file.

  Author:

    Greg Turk
*/
{
  char *comment_ptr;
  char *first_word;
  FILE *fp;
  int i;
  int j;
  int k;
  int nwords;
  float w;
  float x;
  float y;
  float z;
/*
  Read from standard input.
*/
  fp = stdin;

  while (1)
  {
    comment_ptr = fetch_line ( fp );
/*
  End of file?
*/
    if ( comment_ptr == ( char * ) -1 )
    {
      break;
    }
/*
  Did we actually get a comment?
*/
    if ( comment_ptr )
    {
      make_comment ( comment_ptr );
      continue;
    }
/*
  If we get here, the line was not a comment.
*/
    nwords = fetch_words ( );
/*
  Skip empty lines.
*/
    if ( nwords == 0 )
    {
      continue;
    }

    first_word = words[0];

    if (equal_strings (first_word, "v"))
    {
      if (nwords < 4)
      {
	    fprintf (stderr, "Too few coordinates: '%s'", str_orig);
	    exit (-1);
      }
      x = atof (words[1]);
      y = atof (words[2]);
      z = atof (words[3]);
      if (nwords == 5)
      {
        w = atof (words[3]);
	    has_w = 1;
      }
      else
      {
        w = 1.0;
      }
      make_vertex ( x, y, z, w );
    }
    else if (equal_strings (first_word, "vn"))
    {
    }
    else if (equal_strings (first_word, "vt"))
    {
    }
    else if (equal_strings (first_word, "f"))
    {
      make_face (&words[1], nwords-1);
    }
    else
    {
      fprintf (stderr, "Do not recognize: '%s'\n", str_orig);
    }
  }
  return;
}