mirror of
https://github.com/PixarAnimationStudios/OpenSubdiv
synced 2024-11-12 23:20:10 +00:00
Read/write .obj files in uniformEvaluator testing.
This commit is contained in:
parent
2dc8520938
commit
291040584f
10388
examples/projectTest/cow.obj
Normal file
10388
examples/projectTest/cow.obj
Normal file
File diff suppressed because it is too large
Load Diff
@ -88,7 +88,7 @@ createOsdMesh(char *inputFile, char *outputFile, std::string *errorMessage)
|
||||
return false;
|
||||
}
|
||||
|
||||
topology.refinementLevel = 3;
|
||||
topology.refinementLevel = 2;
|
||||
|
||||
std::cout << "Did read topology\n";
|
||||
|
||||
@ -104,47 +104,25 @@ createOsdMesh(char *inputFile, char *outputFile, std::string *errorMessage)
|
||||
uniformEvaluator.SetCoarsePositions(pointPositions, errorMessage);
|
||||
|
||||
// Refine with eight threads
|
||||
if (not uniformEvaluator.Refine(8, errorMessage)) {
|
||||
if (not uniformEvaluator.Refine(1, errorMessage)) {
|
||||
std::cout << "Refine failed with " << *errorMessage << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<int> refinedQuads;
|
||||
if (not uniformEvaluator.GetRefinedQuads(&refinedQuads, errorMessage)) {
|
||||
std::cout << "GetRefinedQuads failed with " << *errorMessage << std::endl;
|
||||
// Refine with eight threads
|
||||
PxOsdUtilSubdivTopology refinedTopology;
|
||||
const float *positions = NULL;
|
||||
|
||||
if (not uniformEvaluator.GetRefinedTopology(
|
||||
&refinedTopology, &positions, errorMessage)) {
|
||||
std::cout << "GetRefinedTopology failed with " << *errorMessage <<"\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
float *refinedPositions = NULL;
|
||||
int numFloats = 0;
|
||||
if (not uniformEvaluator.GetRefinedPositions(&refinedPositions, &numFloats, errorMessage)) {
|
||||
std::cout << "GetRefinedPositions failed with " << *errorMessage << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cout << "Quads = " << refinedQuads.size()/4 << std::endl;
|
||||
// for (int i=0; i<(int)refinedQuads.size(); i+=4) {
|
||||
// std::cout << "(" << refinedQuads[i] <<
|
||||
// ", " << refinedQuads[i+1] <<
|
||||
// ", " << refinedQuads[i+2] <<
|
||||
// ", " << refinedQuads[i+3] <<
|
||||
// ")\n";
|
||||
// }
|
||||
|
||||
std::cout << "Hot damn, it worked.\n";
|
||||
std::cout << "Positions = " << numFloats/3 << std::endl;
|
||||
// for (int i=0; i<numFloats; i+=3) {
|
||||
// std::cout << "(" << refinedPositions[i] <<
|
||||
// ", " << refinedPositions[i+1] <<
|
||||
// "," << refinedPositions[i+2] << ")\n";
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// if (not uniformEvaluator.WriteRefinedObj("foo.obj", errorMessage)) {
|
||||
// std::cout << errorMessage << std::endl;
|
||||
// }
|
||||
|
||||
if (not refinedTopology.WriteObjFile(
|
||||
outputFile, positions, errorMessage)) {
|
||||
std::cout << errorMessage << std::endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -270,3 +271,49 @@ PxOsdUtilSubdivTopology::ParseFromObjString(
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
PxOsdUtilSubdivTopology::WriteObjFile(
|
||||
const char *filename,
|
||||
const float *positions,
|
||||
std::string *errorMessage)
|
||||
{
|
||||
|
||||
ofstream file;
|
||||
|
||||
file.open (filename);
|
||||
|
||||
if (not file.is_open()) {
|
||||
stringstream ss;
|
||||
ss << "Could not open .obj file " << filename ;
|
||||
*errorMessage = ss.str();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
for (int i=0; i<numVertices*3; i+=3) {
|
||||
file << "v " << positions[i] << " " << positions[i+1]
|
||||
<< " " << positions[i+2] <<"\n";
|
||||
}
|
||||
|
||||
file << "\n";
|
||||
|
||||
int idx = 0;
|
||||
for (int i=0; i<(int)nverts.size(); ++i) {
|
||||
file << "f";
|
||||
for (int j=0; j<nverts[i]-1; ++j) {
|
||||
file << " " << indices[idx+j]+1;
|
||||
}
|
||||
idx += nverts[i];
|
||||
file << "\n";
|
||||
}
|
||||
|
||||
file << "\n";
|
||||
|
||||
file.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -93,7 +93,12 @@ class PxOsdUtilSubdivTopology {
|
||||
|
||||
bool ParseFromObjString( char const * shapestr, int axis,
|
||||
std::vector<float> *pointPositions,
|
||||
std::string *errorMessage = NULL);
|
||||
std::string *errorMessage = NULL);
|
||||
|
||||
bool WriteObjFile(
|
||||
const char *filename, const float *positions,
|
||||
std::string *errorMessage = NULL);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -238,7 +238,7 @@ PxOsdUtilUniformEvaluator::Refine(
|
||||
|
||||
bool
|
||||
PxOsdUtilUniformEvaluator::GetRefinedPositions(
|
||||
float **positions, int *numFloats,
|
||||
const float **positions, int *numFloats,
|
||||
string *errorMessage) const
|
||||
{
|
||||
|
||||
@ -325,3 +325,35 @@ PxOsdUtilUniformEvaluator::GetRefinedVVData(
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool
|
||||
PxOsdUtilUniformEvaluator::GetRefinedTopology(
|
||||
PxOsdUtilSubdivTopology *t,
|
||||
//positions will have three floats * t->numVertices
|
||||
const float **positions,
|
||||
std::string *errorMessage)
|
||||
{
|
||||
|
||||
if (not GetRefinedQuads(&t->indices, errorMessage)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int numQuads = t->indices.size()/4;
|
||||
t->nverts.resize(numQuads);
|
||||
for (int i=0; i<numQuads; ++i) {
|
||||
t->nverts[i] = 4;
|
||||
}
|
||||
|
||||
int numFloats = 0;
|
||||
if (not GetRefinedPositions(positions, &numFloats, errorMessage)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
t->name = GetTopology().name + "_refined";
|
||||
t->numVertices = numFloats/3;
|
||||
t->refinementLevel = GetTopology().refinementLevel;
|
||||
|
||||
return t->IsValid(errorMessage);
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ class PxOsdUtilUniformEvaluator {
|
||||
// packed as 3 floats per point. This doesn't involve a copy, the
|
||||
// pointer will be valid as long as _vertexBuffer exists.
|
||||
//
|
||||
bool GetRefinedPositions(float **positions, int *numFloats,
|
||||
bool GetRefinedPositions(const float **positions, int *numFloats,
|
||||
std::string *errorMessage = NULL) const;
|
||||
|
||||
// Grab vertex varying results of calling Refine, return by reference
|
||||
@ -136,12 +136,13 @@ class PxOsdUtilUniformEvaluator {
|
||||
std::string *errorMessage = NULL) const {
|
||||
return _refiner->GetRefinedPtexUvs(subfaceUvs, ptexIndices, errorMessage);
|
||||
}
|
||||
|
||||
|
||||
// Write the refined quad mesh to given filename, return false on error
|
||||
// bool WriteRefinedObj( const std::string &filename,
|
||||
// std::string *errorMessage = NULL) const;
|
||||
|
||||
bool GetRefinedTopology(
|
||||
PxOsdUtilSubdivTopology *t,
|
||||
//positions will have three floats * t->numVertices
|
||||
const float **positions,
|
||||
std::string *errorMessage = NULL);
|
||||
|
||||
// Forward these calls through to the refiner, which may forward
|
||||
// to the mesh. Make these top level API calls on the evaluator
|
||||
// so clients can talk to a single API
|
||||
|
Loading…
Reference in New Issue
Block a user