dgInt32 AddFilterFace(dgUnsigned32 count, dgInt32* const pool)
  {
    BeginFace();
    _ASSERTE(count);
    bool reduction = true;
    while (reduction && !AddFace(dgInt32(count), pool))
    {
      reduction = false;
      if (count > 3)
      {
        for (dgUnsigned32 i = 0; i < count; i++)
        {
          for (dgUnsigned32 j = i + 1; j < count; j++)
          {
            if (pool[j] == pool[i])
            {
              for (i = j; i < count - 1; i++)
              {
                pool[i] = pool[i + 1];
              }
              count--;
              i = count;
              reduction = true;
              break;
            }
          }
        }
      }
    }
    EndFace();

    _ASSERTE(reduction);
    return reduction ? dgInt32(count) : 0;
  }
	hacd::HaI32 AddFilterFace (hacd::HaU32 count, hacd::HaI32* const pool)
	{
		BeginFace();
		HACD_ASSERT (count);
		bool reduction = true;
		while (reduction && !AddFace (hacd::HaI32 (count), pool)) {
			reduction = false;
			if (count >3) {
				for (hacd::HaU32 i = 0; i < count; i ++) {
					for (hacd::HaU32 j = i + 1; j < count; j ++) {
						if (pool[j] == pool[i]) {
							for (i = j; i < count - 1; i ++) {
								pool[i] =  pool[i + 1];
							}
							count --;
							i = count;
							reduction = true;
							break;
						}
					}
				}
			}
		}
		EndFace();

		HACD_ASSERT (reduction);
		return reduction ? hacd::HaI32 (count) : 0;
	}
示例#3
0
static void ReadOBJ(const char *filename) {
    FILE *fp = fopen(filename, "r");
     if (fp == NULL)
         sreFatalError("Could not open file %s.", filename);
    for (;;) {
        char *str = GetWords(fp);
        if (str == NULL)
            // End of file.
            break;
        RemoveComments();
        if (nu_words == 0)
            continue;
        int command = - 1;
        if (strcmp(words[0], "v") == 0)
           command = 0;
        else if (strcmp(words[0], "vn") == 0)
           command = 1;
        else if (strcmp(words[0], "vt") == 0)
           command = 2;
        else if (strcmp(words[0], "f") == 0)
           command = 3;
        if (command < 0)
            // First word not recognized.
            continue;
        if (command <= 2) {
           // Get up to four coordinates.
           float coord[4];
           int n = GetCoordinates(1, coord);
           if (command == 0)
               AddVertexAttribute(SRE_ATTRIBUTE_POSITION, coord, n);
           else if (command == 1)
               AddVertexAttribute(SRE_ATTRIBUTE_NORMAL, coord, n);
           else
               AddVertexAttribute(SRE_ATTRIBUTE_TEXCOORDS, coord, n);
        }
        else {
            // Face defition.
            BeginFace(4, SRE_POSITION_MASK | SRE_NORMAL_MASK | SRE_TEXCOORDS_MASK);
            for (int word_index = 1; word_index < nu_words; word_index++) {
                int vertex_index[3];
                DecodeOBJFaceIndices(words[word_index], vertex_index);
                for (int k = 0; k < 3; k++) {
                    // Special value INT_MAX means not used; AddFace expects - 1
                    // for unused attributes.
                    if (vertex_index[k] == INT_MAX)
                        vertex_index[k] = - 1;
                     else {
                        if (vertex_index[k] > 0)
                            // Regular index; counting starts at 1 in OBJ files.
                            vertex_index[k]--;
                        else if (vertex_index[k] < 0)
                            // Negative numer is relative index.
                            vertex_index[k] += nu_attribute_vertices[OBJ_attributes[k]];
                        else
                            ModelFileReadError("Vertex index of 0 not allowed in OBJ file");
                    }
                }
                AddFaceVertex(OBJ_attributes, vertex_index);
            }
            EndFace();
        }
    }
    fclose(fp);
}