コード例 #1
0
ファイル: rtest.cpp プロジェクト: wildparky/ptex
int main(int /*argc*/, char** /*argv*/)
{
    Ptex::String error;
    PtexPtr<PtexCache> c(PtexCache::create());
    c->setSearchPath("foo/bar:.");
    PtexPtr<PtexTexture> r(c->get("test.ptx", error));

    if (!r) {
	std::cerr << error.c_str() << std::endl;
	return 1;
    }
    std::cout << "meshType: " << Ptex::MeshTypeName(r->meshType()) << std::endl;
    std::cout << "dataType: " << Ptex::DataTypeName(r->dataType()) << std::endl;
    std::cout << "numChannels: " << r->numChannels() << std::endl;
    std::cout << "alphaChannel: ";
    if (r->alphaChannel() == -1) std::cout << "(none)" << std::endl;
    else std::cout << r->alphaChannel() << std::endl;
    std::cout << "numFaces: " << r->numFaces() << std::endl;

    PtexMetaData* meta = r->getMetaData();
    std::cout << "numMetaKeys: " << meta->numKeys() << std::endl;
    if (meta->numKeys()) DumpMetaData(meta);
    meta->release();

    int nfaces = r->numFaces();
    for (int i = 0; i < nfaces; i++) {
	const Ptex::FaceInfo& f = r->getFaceInfo(i);
	std::cout << "face " << i << ":\n"
		  << "  res: " << int(f.res.ulog2) << ' ' << int(f.res.vlog2) << "\n"
		  << "  adjface: " 
		  << f.adjfaces[0] << ' '
		  << f.adjfaces[1] << ' '
		  << f.adjfaces[2] << ' '
		  << f.adjfaces[3] << "\n"
		  << "  adjedge: " 
		  << f.adjedge(0) << ' '
		  << f.adjedge(1) << ' '
		  << f.adjedge(2) << ' '
		  << f.adjedge(3) << "\n"
		  << "  flags: " << int(f.flags) << "\n";

	Ptex::Res res = f.res;
	while (res.ulog2 > 0 || res.vlog2 > 0) {
	    PtexFaceData* dh = r->getData(i, res);
	    if (!dh) break;
	    DumpData(r->dataType(), r->numChannels(), dh, "  ");
	    bool isconst = dh->isConstant();
	    dh->release();
	    if (isconst) break;
	    if (res.ulog2) res.ulog2--;
	    if (res.vlog2) res.vlog2--;
	}
	PtexFaceData* dh = r->getData(i, Ptex::Res(0,0));
	DumpData(r->dataType(), r->numChannels(), dh, "  ");
	dh->release();
    }

    return 0;
}
コード例 #2
0
ファイル: ptxview.cpp プロジェクト: DINKIN/ptexutils
bool mesh::loadFromMetaData(PtexTexture* r)
{
    PtexMetaData* meta = r->getMetaData();
    if (meta->numKeys()<3) return false;
    
    triangles = r->meshType()==Ptex::mt_triangle;

    const float* vf;
    const int *vif, *fvc;
    int vertcount, indexcount, facevertcount;

    meta->getValue("PtexFaceVertCounts",fvc,facevertcount);
    if (facevertcount==0) return false;
    meta->getValue("PtexVertPositions",vf,vertcount);
    if (vertcount==0) return false;
    meta->getValue("PtexFaceVertIndices",vif,indexcount);
    if (indexcount==0) return false;
    
    for (int i=0; i<vertcount; i+=3) addVertex(&vf[i]);
        
    int* fviptr = (int*) vif;
    int* nvptr = (int*) fvc;
    for (int i=0; i<facevertcount; i++)
    {
        int nverts = *nvptr;
        if (triangles)
        {
            if (nverts!=3) return false;
            polygon q;
            q.indices[0] = fviptr[0];
            q.indices[1] = fviptr[1];
            q.indices[2] = fviptr[2];
            q.indices[3] = -1;
            addFace(q);
        }
        else if (nverts==4)
        {
            polygon q;
            q.indices[0] = fviptr[0];
            q.indices[1] = fviptr[1];
            q.indices[2] = fviptr[2];
            q.indices[3] = fviptr[3];
            addFace(q);
        }
        else
        {
            int vib = verts.size();

            // Add new vertices at edge midpoints and polygon center
            Vec3f cp = Vec3f(0,0,0);
            for (int v=0; v<nverts; v++)
            {
                verts.push_back((verts[fviptr[v]] + verts[fviptr[(v+1)%nverts]])/2);
                cp += verts[fviptr[v]];
            }
            verts.push_back(cp/nverts);

            // Add the new sub-faces
            for (int v=0; v<nverts; v++)
            {
                polygon q;
                q.indices[0] = fviptr[v];
                q.indices[1] = vib+v;
                q.indices[2] = verts.size()-1;
                q.indices[3] = vib+(v+nverts-1)%nverts;
                addFace(q);
            }
        }
        fviptr+=nverts;
        nvptr++;
    }
    
    if ((int)polys.size()!=r->numFaces())
    {
        verts.clear();
        polys.clear();
        return false;
    }
    
    return true;
}
コード例 #3
0
ファイル: viewer.cpp プロジェクト: mbdriscoll/OpenSubdiv
OpenSubdiv::HbrMesh<T> * createPTexGeo(PtexTexture * r)
{
  PtexMetaData* meta = r->getMetaData();
  if(meta->numKeys()<3) return NULL;

  const float* vp;
  const int *vi, *vc;
  int nvp, nvi, nvc;

  meta->getValue("PtexFaceVertCounts", vc, nvc);
  if (nvc==0)
      return NULL;

  meta->getValue("PtexVertPositions", vp, nvp);
  if (nvp==0)
      return NULL;

  meta->getValue("PtexFaceVertIndices", vi, nvi);
  if (nvi==0)
      return NULL;

  static OpenSubdiv::HbrCatmarkSubdivision<T>  _catmark;
  static OpenSubdiv::HbrBilinearSubdivision<T>  _bilinear;
  OpenSubdiv::HbrMesh<T> * mesh;
  if(g_scheme == 0)
      mesh = new OpenSubdiv::HbrMesh<T>(&_catmark);
  else
      mesh = new OpenSubdiv::HbrMesh<T>(&_bilinear);

  g_positions.clear();
  g_positions.reserve(nvp);

  // compute model bounding
  float min[3] = {vp[0], vp[1], vp[2]};
  float max[3] = {vp[0], vp[1], vp[2]};
  for (int i=0; i<nvp/3; ++i) {
      for(int j=0; j<3; ++j) {
          float v = vp[i*3+j];
          g_positions.push_back(v);
          min[j] = std::min(min[j], v);
          max[j] = std::max(max[j], v);
      }
      mesh->NewVertex(i, T());
  }
  for (int j=0; j<3; ++j) {
      g_center[j] = (min[j] + max[j]) * 0.5f;
      g_size += (max[j]-min[j])*(max[j]-min[j]);
  }
  g_size = sqrtf(g_size);

  const int *fv = vi;
  for (int i=0, ptxidx=0; i<nvc; ++i) {
      int nv = vc[i];
      OpenSubdiv::HbrFace<T> * face = mesh->NewFace(nv, (int *)fv, 0);

      face->SetPtexIndex(ptxidx);
      if(nv != 4)
          ptxidx+=nv;
      else
          ptxidx++;

      fv += nv;
  }
  mesh->SetInterpolateBoundaryMethod( OpenSubdiv::HbrMesh<T>::k_InterpolateBoundaryEdgeOnly );
//  set creases here
//  applyTags<T>( mesh, sh );
  mesh->Finish();

  return mesh;
}