Пример #1
0
carve::poly::Polyhedron *readModel(const std::string &file) {
  carve::poly::Polyhedron *poly;

  if (file == "") {
    if (options.obj) {
      poly = readOBJ(std::cin);
    } else if (options.vtk) {
      poly = readVTK(std::cin);
    } else {
      poly = readPLY(std::cin);
    }
  } else if (endswith(file, ".ply")) {
    poly = readPLY(file);
  } else if (endswith(file, ".vtk")) {
    poly = readVTK(file);
  } else if (endswith(file, ".obj")) {
    poly = readOBJ(file);
  }

  if (poly == NULL) return NULL;

  std::cerr << "loaded polyhedron " << poly << " has "
    << poly->vertices.size() << " vertices "
    << poly->faces.size() << " faces "
    << poly->manifold_is_closed.size() << " manifolds (" << std::count(poly->manifold_is_closed.begin(), poly->manifold_is_closed.end(), true) << " closed)" << std::endl;

  return poly;
}
Пример #2
0
B_Block *spawn_bb_rect(float x, float y, float z,float w, float h, float d){

  B_Block *rect = NULL;

	rect = newBBlock();
	if(rect == NULL){
		return NULL;
	}
  rect->position.x = x;
  rect->position.y = y;
  rect->position.z = z;
  rect->self = rect;
  rect->texture = sprite_load(const_cast<char *>("textures/block_tex.jpg"), 640, 640, 1);
  rect->normal_map = sprite_load(const_cast<char *>("textures/block_tex_normal.jpg"), 640, 640, 1);
  rect->shaderProgram = get_shader_program(NORMALMAP_SHADER);
  rect->update = b_update;
  rect->updateRate = 0;
  rect->mass = 10.0f;
  rect->halfExtents.x= w;
  rect->halfExtents.y= h;
  rect->halfExtents.z= d;

  rect->model = readOBJ(const_cast<char *>("textures/testblock.obj"));

  rect->body = add_new_box_to_world(rect->halfExtents.x,rect->halfExtents.y,rect->halfExtents.z,rect->mass,0.0f,0.0f,0.0f,1);
  //set_angular_props(rect->body,0,0,0,0,0,0);
  set_body_position(rect->body, x,  y, z);
  set_body_friction(rect->body, 1000000.0f);
  set_body_restitution(rect->body, 0.0f);
  set_damping(rect->body,0.0f,0.0f);
  set_sleeping_thresholds(rect->body,0.5f,0.5f);
  plEnableCallbacks(rect->body->body);
  return rect;
}
Пример #3
0
struct OBJ_Model * loadObj(char * directory,char * filename /*This does not have a .obj extension*/,int compileDisplayList)
{
    fprintf(stderr,"Starting to load  OBJ file %s \n",filename);
    struct OBJ_Model * obj = ( struct OBJ_Model * ) malloc(sizeof(struct OBJ_Model));
    if ( obj == 0 )  { fprintf(stderr,"Could not allocate enough space for model %s \n",filename);  return 0; }


    memset (obj,0,sizeof(struct OBJ_Model));
	obj->scale=1.0f;


    unsigned int directory_length = strlen(directory);
    if (directory_length > MAX_MODEL_PATHS ) { fprintf(stderr,"Huge directory filename provided , will not loadObject ( %u char limit ) \n",MAX_MODEL_PATHS); free(obj); return 0; }
	strncpy(obj->directory, directory, MAX_MODEL_PATHS );

    unsigned int file_name_length = strlen(filename);
    if (file_name_length > MAX_MODEL_PATHS ) { fprintf(stderr,"Huge filename provided , will not loadObject ( %u char limit ) \n",MAX_MODEL_PATHS); free(obj); return 0; }
	strncpy(obj->filename, filename, MAX_MODEL_PATHS );

    if (!readOBJ(obj) ) { fprintf(stderr," Could not read object %s \n",filename); unloadObj(obj); return 0;}
    if (!calculateBoundingBox(obj)) { fprintf(stderr," Could not calculate bounding box for object %s \n",filename); unloadObj(obj); return 0;}
    if (!prepareObject(obj))  { fprintf(stderr," Could not prepare object %s \n",filename); unloadObj(obj); return 0;}
    if (!calculateBoundingBox(obj)) { fprintf(stderr," Could not calculate bounding box for object %s \n",filename); unloadObj(obj); return 0;}

   if (compileDisplayList)
   {
     compileOBJList(obj);
   }


   return obj;
}
Пример #4
0
int main(int argc, char **argv) {
  options.parse(argc, argv);

  carve::input::Input inputs;
  std::vector<carve::mesh::MeshSet<3> *> polys;
  std::vector<carve::line::PolylineSet *> lines;
  std::vector<carve::point::PointSet *> points;

  if (options.file == "") {
    readPLY(std::cin, inputs);
  } else {
    if (endswith(options.file, ".ply")) {
      readPLY(options.file, inputs);
    } else if (endswith(options.file, ".vtk")) {
      readVTK(options.file, inputs);
    } else if (endswith(options.file, ".obj")) {
      readOBJ(options.file, inputs);
    }
  }

  for (std::list<carve::input::Data *>::const_iterator i = inputs.input.begin(); i != inputs.input.end(); ++i) {
    carve::mesh::MeshSet<3> *p;
    carve::point::PointSet *ps;
    carve::line::PolylineSet *l;

    if ((p = carve::input::Input::create<carve::mesh::MeshSet<3> >(*i)) != NULL)  {
      if (options.canonicalize) p->canonicalize();
      if (options.obj) {
        writeOBJ(std::cout, p);
      } else if (options.vtk) {
        writeVTK(std::cout, p);
      } else {
        writePLY(std::cout, p, options.ascii);
      }
      delete p;
    } else if ((l = carve::input::Input::create<carve::line::PolylineSet>(*i)) != NULL)  {
      if (options.obj) {
        writeOBJ(std::cout, l);
      } else if (options.vtk) {
        writeVTK(std::cout, l);
      } else {
        writePLY(std::cout, l, options.ascii);
      }
      delete l;
    } else if ((ps = carve::input::Input::create<carve::point::PointSet>(*i)) != NULL)  {
      if (options.obj) {
        std::cerr << "Can't write a point set in .obj format" << std::endl;
      } else if (options.vtk) {
        std::cerr << "Can't write a point set in .vtk format" << std::endl;
      } else {
        writePLY(std::cout, ps, options.ascii);
      }
      delete ps;
    }
  }

  return 0;
}
Пример #5
0
json WebMesh::exportMesh(bool writeHFile) {
	m_writeHeaderFile = writeHFile;


    //STEP 1: read OBJ file - this fills m_shapes and m_materials
    readOBJ(m_INFILE);

    vector<int> buffer_to_write;

    json metadata;
    json metaMeshes(json::an_array);
    json metaMaterials(json::an_array);

    //meshes
    for (int i = 0; i < m_shapes.size(); i++) {
        vector<int> vertices_one;
        vector<int> indices_one;
        json oneMesh = processOneShape(m_shapes[i], vertices_one, indices_one);

        buffer_to_write.insert(buffer_to_write.end(), vertices_one.begin(), vertices_one.end());
        buffer_to_write.insert(buffer_to_write.end(), indices_one.begin(), indices_one.end());

        metaMeshes.add(oneMesh);
    }
    
    //materials
    for (int i = 0; i < m_materials.size(); i++) {
        json oneMat = processOneMaterial(m_materials[i], i);
        metaMaterials.add(oneMat);
    }

    metadata["meshes"] = move(metaMeshes);
    metadata["materials"] = move(metaMaterials);



    if (m_writeHeaderFile) {
        ofstream jsonFile;
        jsonFile.open (m_OUT_ROOT + ".json");
        jsonFile << metadata;
        jsonFile.close();
    }
    
    if (m_meshEncoding == MeshEncoding::UTF)
        //filewriter::writeDataUTF(buffer_to_write, m_OUT_ROOT);
        printf("Sorry UTF writing is currently broken!!");
    else if (m_meshEncoding == MeshEncoding::PNG)
        filewriter::writeDataPNG(buffer_to_write, m_OUT_ROOT);
    else if (m_meshEncoding == MeshEncoding::VARINT)
        filewriter::writeDataVARINT(buffer_to_write, m_OUT_ROOT);

    return metadata;
}
Пример #6
0
int readOBG_file(void){
	if(!readOBJ(obj))
		return 0;
	if(!arrayListftoGLfloat(vertexDataList, outputVertexArray)){
		cleanrobj();
		return 0;
	}
	*vertexCount = vertexDataList->lenght;
	if(!arrayListuitoGLuint(elementDataList, outputElementArray)){
		cleanrobj();
		return 0;
	}
	*elementCount = elementDataList->lenght;
	cleanrobj();
	return closeOBJ(obj);
}
Пример #7
0
/**
 * reads a surface as a given format
 */
surface *readSurface(char *filename, enum SURFACE_FORMAT format) {
  switch(format) {
    case OFF:
      return readOFF(filename);
      break;
    case OBJ:
      return readOBJ(filename);
      break;
    case MGHSURF:
      return readMGHsurf(filename);
      break;
    default:
      fprintf(stderr,"readSurface(): unsupported format\n");
      break;
  }

  return NULL;
}
Пример #8
0
static carve::mesh::MeshSet<3> *load(const std::string &file) {
  carve::input::Input inputs;

  if (file == "-") {
    readPLY(std::cin, inputs);
  } else if (endswith(file, ".ply")) {
    readPLY(file, inputs);
  } else if (endswith(file, ".vtk")) {
    readVTK(file, inputs);
  } else if (endswith(file, ".obj")) {
    readOBJ(file, inputs);
  }

  carve::mesh::MeshSet<3> *poly = NULL;

  for (std::list<carve::input::Data *>::const_iterator i = inputs.input.begin();
       poly == NULL && i != inputs.input.end();
       ++i) {
    poly = inputs.create<carve::mesh::MeshSet<3> >(*i, carve::input::Options());
  }

  return poly;
}
Пример #9
0
int main(int argc, char **argv) {
  TestScene *scene = new TestScene(argc, argv, std::min(1, argc - 1));
  options.parse(argc, argv);

  size_t count = 0;

  carve::input::Input inputs;
  std::vector<carve::mesh::MeshSet<3> *> polys;
  std::vector<carve::line::PolylineSet *> lines;
  std::vector<carve::point::PointSet *> points;

  if (options.files.size() == 0) {
    if (options.obj) {
      readOBJ(std::cin, inputs);
    } else if (options.vtk) {
      readVTK(std::cin, inputs);
    } else {
      readPLY(std::cin, inputs);
    }

  } else {
    for (size_t idx = 0; idx < options.files.size(); ++idx) {
      std::string &s(options.files[idx]);
      std::string::size_type i = s.rfind(".");

      if (i != std::string::npos) {
        std::string ext = s.substr(i, s.size() - i);
        if (!strcasecmp(ext.c_str(), ".obj")) {
          readOBJ(s, inputs);
        } else if (!strcasecmp(ext.c_str(), ".vtk")) {
          readVTK(s, inputs);
        } else {
          readPLY(s, inputs);
        }
      } else {
        readPLY(s, inputs);
      }
    }
  }

  for (std::list<carve::input::Data *>::const_iterator i = inputs.input.begin(); i != inputs.input.end(); ++i) {
    carve::mesh::MeshSet<3> *p;
    carve::point::PointSet *ps;
    carve::line::PolylineSet *l;

    if ((p = carve::input::Input::create<carve::mesh::MeshSet<3> >(*i, carve::input::opts("avoid_cavities", "true"))) != NULL)  {
      polys.push_back(p);
      std::cerr << "loaded polyhedron "
                << polys.back() << " has " << polys.back()->meshes.size()
                << " manifolds (" << std::count_if(polys.back()->meshes.begin(),
                                                   polys.back()->meshes.end(),
                                                   carve::mesh::Mesh<3>::IsClosed()) << " closed)" << std::endl; 

      std::cerr << "closed:    ";
      for (size_t i = 0; i < polys.back()->meshes.size(); ++i) {
        std::cerr << (polys.back()->meshes[i]->isClosed() ? '+' : '-');
      }
      std::cerr << std::endl;

      std::cerr << "negative:  ";
      for (size_t i = 0; i < polys.back()->meshes.size(); ++i) {
        std::cerr << (polys.back()->meshes[i]->isNegative() ? '+' : '-');
      }
      std::cerr << std::endl;

    } else if ((l = carve::input::Input::create<carve::line::PolylineSet>(*i)) != NULL)  {
      lines.push_back(l);
      std::cerr << "loaded polyline set "
                << lines.back() << std::endl; 
    } else if ((ps = carve::input::Input::create<carve::point::PointSet>(*i)) != NULL)  {
      points.push_back(ps);
      std::cerr << "loaded point set "
                << points.back() << std::endl; 
    }
  }

  scene->draw_list_base = genSceneDisplayList(polys, lines, points, &count, scene->is_wireframe);
  scene->draw_flags.assign(count, true);

  scene->run();

  delete scene;

  return 0;
}