无法在MacOSX上使用Sketchup框架slapi获得任何面孔

时间:2014-08-08 20:39:16

标签: macos frameworks sketchup

我终于可以将MacOSX上的32位测试程序与Sketchup slapi框架链接起来,但是SUEntitiesGetNumFaces总是会返回0个面,即使是来自Trimble样本的模型也可以使用Sketchup查看器打开...

该程序是slapi框架附带的测试程序...... 我没有日志,没有内存错误,没有库错误...只有零面... 我不知道我现在可以检查的女巫设置......

以下是示例程序:

#include <slapi/slapi.h>
#include <slapi/geometry.h>
#include <slapi/initialize.h>
#include <slapi/unicodestring.h>
#include <slapi/model/model.h>
#include <slapi/model/entities.h>
#include <slapi/model/face.h>
#include <slapi/model/edge.h>
#include <slapi/model/vertex.h>
#include <vector>

static int _load (char * filename) {
  char * sname = strrchr (filename, '/');
  if (sname) sname++;
  else sname = filename;
  fprintf (stderr, "\n%s: loading\n", sname);

  // Load the model from a file
  SUModelRef model = SU_INVALID;
  SUResult res = SUModelCreateFromFile(&model, filename);

  // It's best to always check the return code from each SU function call.
  // Only showing this check once to keep this example short.
  if (res != SU_ERROR_NONE)
    return 0;

  // Get the entity container of the model.
  SUEntitiesRef entities = SU_INVALID;
  SUModelGetEntities(model, &entities);

  // Get all the faces from the entities object
  size_t faceCount = 0;
  SUEntitiesGetNumFaces(entities, &faceCount);
  size_t materialCount = 0;
  SUModelGetNumMaterials (model, & materialCount);
  fprintf (stderr, "- %s: the model has %ld faces, %ld materials\n",
           sname, faceCount, materialCount);

  if (faceCount > 0) {
    std::vector<SUFaceRef> faces(faceCount);
    SUEntitiesGetFaces(entities, faceCount, &faces[0], &faceCount);

    // Get all the edges in this face
    for (size_t i = 0; i < faceCount; i++) {
      size_t edgeCount = 0;
      SUFaceGetNumEdges(faces[i], &edgeCount);
      if (edgeCount > 0) {
        std::vector<SUEdgeRef> edges(edgeCount);
        SUFaceGetEdges(faces[i], edgeCount, &edges[0], &edgeCount);

        // Get the vertex positions for each edge
        for (size_t j = 0; j < edgeCount; j++) {
          SUVertexRef startVertex = SU_INVALID;
          SUVertexRef endVertex = SU_INVALID;
          SUEdgeGetStartVertex(edges[j], &startVertex);
          SUEdgeGetEndVertex(edges[j], &endVertex);
          SUPoint3D start;
          SUPoint3D end;
          SUVertexGetPosition(startVertex, &start);
          SUVertexGetPosition(endVertex, &end);
          // Now do something with the point data
        }
      }
    }
  }

  // Get model name
  SUStringRef name = SU_INVALID;
  SUStringCreate(&name);
  SUModelGetName(model, &name);
  size_t name_length = 0;
  SUStringGetUTF8Length(name, &name_length);
  char* name_utf8 = new char[name_length + 1];
  SUStringGetUTF8(name, name_length + 1, name_utf8, &name_length);

  fprintf (stderr, "- %s: unloading...\n", sname);

  // Now we have the name in a form we can use
  SUStringRelease(&name);
  delete []name_utf8;

  // Must release the model or there will be memory leaks
  SUModelRelease(&model);

  return 1;
}

int main (int argc, char * argv[]) {
  // Always initialize the API before using it
  SUInitialize();

  size_t major, minor;
  SUGetAPIVersion (& major, & minor);
  char * ptr = strrchr (argv[0], '/');
  if (! ptr) ptr = argv[0];
  else ptr++;
  fprintf (stderr, "%s - slapi %ld.%ld\n", ptr, major, minor);

  // Load the model from a file
  for (int i = 1; i < argc; i++) {
    _load (argv[i]);
  }

  // Always terminate the API when done using it
  SUTerminate();
  return 0;
}

0 个答案:

没有答案