示例#1
0
void ColorMesh::apply_color(Texture &tex)
{
    for (int i = 0; i < mesh.vertex_count(); i++) {
        Vertex v = mesh.get_vertex(i);
        float coord,loc_dim;
        float f1,f2,t;
        if (use_4d) {
            v.x = v.x / fg4d.get_spacing(0);
            v.y = v.y / fg4d.get_spacing(1);
            v.z = v.z / fg4d.get_spacing(2);
        } else {
            v.x = v.x / fg.get_spacing(0);
            v.y = v.y / fg.get_spacing(1);
            v.z = v.z / fg.get_spacing(2);
        }
        choose_edge(v, f1, f2, t);
        loc_dim = lerp(f1, f2, t);
        if (loc_dim <= low) {
            coord = 0;
        } else if (loc_dim >= high) {
            coord = 1;
        } else {
            coord = (loc_dim - low) / (high-low);
        }       
        colors[i] = tex[coord];
    }
    write_off();
}
示例#2
0
bool write_mesh(const Surface_mesh& mesh, const std::string& filename)
{
  // extract file extension
  std::string::size_type dot(filename.rfind("."));
  if (dot == std::string::npos) return false;
  std::string ext = filename.substr(dot+1, filename.length()-dot-1);
  std::transform(ext.begin(), ext.end(), ext.begin(), tolower);


  // extension determines reader
  if (ext == "off")
  {
      return write_off(mesh, filename);
  }


  // we didn't find a writer module
  return false;
}