Merge "Adding ability to strip geometry from collada files. Fixing element/type creation. Build test."
This commit is contained in:
committed by
Android (Google) Code Review
commit
cfa4dd40c5
@@ -200,4 +200,40 @@ bool ColladaConditioner::triangulate(const char *inputFile) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return convertSuceeded;
|
return convertSuceeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ColladaConditioner::stripGeometry(DAE *dae) {
|
||||||
|
bool convertSuceeded = true;
|
||||||
|
int geometryElementCount = (int)(dae->getDatabase()->getElementCount(NULL,
|
||||||
|
"library_geometries" ));
|
||||||
|
|
||||||
|
for(int currentGeometry = 0; currentGeometry < geometryElementCount; currentGeometry++) {
|
||||||
|
|
||||||
|
daeElement * element = 0;
|
||||||
|
int error = dae->getDatabase()->getElement(&element, currentGeometry,
|
||||||
|
NULL, "library_geometries");
|
||||||
|
daeBool removed = daeElement::removeFromParent(element);
|
||||||
|
convertSuceeded = convertSuceeded && removed;
|
||||||
|
}
|
||||||
|
return convertSuceeded;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ColladaConditioner::stripGeometry(const char *inputFile) {
|
||||||
|
DAE dae;
|
||||||
|
bool convertSuceeded = true;
|
||||||
|
domCOLLADA* root = dae.open(inputFile);
|
||||||
|
|
||||||
|
if (!root) {
|
||||||
|
printf("Failed to read file %s.\n", inputFile);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
stripGeometry(&dae);
|
||||||
|
|
||||||
|
dae.writeAll();
|
||||||
|
if(!convertSuceeded) {
|
||||||
|
printf("Encountered errors\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return convertSuceeded;
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ private:
|
|||||||
public:
|
public:
|
||||||
bool triangulate(DAE *dae);
|
bool triangulate(DAE *dae);
|
||||||
bool triangulate(const char *inputFile);
|
bool triangulate(const char *inputFile);
|
||||||
|
bool stripGeometry(DAE *dae);
|
||||||
|
bool stripGeometry(const char *inputFile);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //COLLADA_CONDITIONER
|
#endif //COLLADA_CONDITIONER
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ ColladaLoader::ColladaLoader() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ColladaLoader::~ColladaLoader() {
|
ColladaLoader::~ColladaLoader() {
|
||||||
|
if (mDae) {
|
||||||
|
delete mDae;
|
||||||
|
}
|
||||||
clearGeometry();
|
clearGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,13 +40,16 @@ void ColladaLoader::clearGeometry() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ColladaLoader::init(const char *colladaFile) {
|
bool ColladaLoader::init(const char *colladaFile) {
|
||||||
DAE dae;
|
if (mDae) {
|
||||||
|
delete mDae;
|
||||||
|
}
|
||||||
clearGeometry();
|
clearGeometry();
|
||||||
|
|
||||||
|
mDae = new DAE();
|
||||||
|
|
||||||
bool convertSuceeded = true;
|
bool convertSuceeded = true;
|
||||||
|
|
||||||
domCOLLADA* root = dae.open(colladaFile);
|
domCOLLADA* root = mDae->open(colladaFile);
|
||||||
if (!root) {
|
if (!root) {
|
||||||
fprintf(stderr, "Failed to read file %s.\n", colladaFile);
|
fprintf(stderr, "Failed to read file %s.\n", colladaFile);
|
||||||
return false;
|
return false;
|
||||||
@@ -51,7 +57,7 @@ bool ColladaLoader::init(const char *colladaFile) {
|
|||||||
|
|
||||||
// We only want to deal with triangulated meshes since rendering complex polygons is not feasible
|
// We only want to deal with triangulated meshes since rendering complex polygons is not feasible
|
||||||
ColladaConditioner conditioner;
|
ColladaConditioner conditioner;
|
||||||
conditioner.triangulate(&dae);
|
conditioner.triangulate(mDae);
|
||||||
|
|
||||||
domLibrary_geometries *allGeometry = daeSafeCast<domLibrary_geometries>(root->getDescendant("library_geometries"));
|
domLibrary_geometries *allGeometry = daeSafeCast<domLibrary_geometries>(root->getDescendant("library_geometries"));
|
||||||
|
|
||||||
@@ -102,3 +108,18 @@ bool ColladaLoader::convertGeometry(domGeometry *geometry) {
|
|||||||
|
|
||||||
return convertSuceeded;
|
return convertSuceeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ColladaLoader::stripGeometryAndSave() {
|
||||||
|
|
||||||
|
ColladaConditioner conditioner;
|
||||||
|
bool convertSuceeded = conditioner.stripGeometry(mDae);
|
||||||
|
|
||||||
|
mDae->writeAll();
|
||||||
|
if(!convertSuceeded) {
|
||||||
|
printf("Encountered errors\n");
|
||||||
|
} else {
|
||||||
|
printf("Stripped geometry data from collada file\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return convertSuceeded;
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
class DAE;
|
||||||
class domLibrary_geometries;
|
class domLibrary_geometries;
|
||||||
class domGeometry;
|
class domGeometry;
|
||||||
class ColladaGeometry;
|
class ColladaGeometry;
|
||||||
@@ -36,8 +37,10 @@ public:
|
|||||||
virtual uint32_t getNumMeshes() const {
|
virtual uint32_t getNumMeshes() const {
|
||||||
return mGeometries.size();
|
return mGeometries.size();
|
||||||
}
|
}
|
||||||
|
bool stripGeometryAndSave();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
DAE *mDae;
|
||||||
void clearGeometry();
|
void clearGeometry();
|
||||||
std::vector<ColladaGeometry*> mGeometries;
|
std::vector<ColladaGeometry*> mGeometries;
|
||||||
|
|
||||||
|
|||||||
@@ -75,22 +75,28 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate the element that describes our channel layout
|
// Generate the element that describes our channel layout
|
||||||
rsc->mStateElement.elementBuilderBegin();
|
Element::Builder vtxBuilder;
|
||||||
for (uint32_t c = 0; c < mChannels.size(); c ++) {
|
for (uint32_t c = 0; c < mChannels.size(); c ++) {
|
||||||
// Skip empty channels
|
// Skip empty channels
|
||||||
if (mChannels[c].mData.size() == 0) {
|
if (mChannels[c].mData.size() == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const Element *subElem = Element::create(rsc, RS_TYPE_FLOAT_32, RS_KIND_USER, false, mChannels[c].mStride);
|
ObjectBaseRef<const Element> subElem = Element::createRef(rsc,
|
||||||
rsc->mStateElement.elementBuilderAdd(subElem, mChannels[c].mName.c_str(), 1);
|
RS_TYPE_FLOAT_32,
|
||||||
|
RS_KIND_USER,
|
||||||
|
false,
|
||||||
|
mChannels[c].mStride);
|
||||||
|
vtxBuilder.add(subElem.get(), mChannels[c].mName.c_str(), 1);
|
||||||
}
|
}
|
||||||
const Element *vertexDataElem = rsc->mStateElement.elementBuilderCreate(rsc);
|
ObjectBaseRef<const Element> vertexDataElem = vtxBuilder.create(rsc);
|
||||||
|
|
||||||
uint32_t numVerts = mChannels[0].mData.size()/mChannels[0].mStride;
|
uint32_t numVerts = mChannels[0].mData.size()/mChannels[0].mStride;
|
||||||
Type *vertexDataType = Type::getType(rsc, vertexDataElem, numVerts, 0, 0, false, false);
|
ObjectBaseRef<Type> vertexDataType = Type::getTypeRef(rsc, vertexDataElem.get(),
|
||||||
|
numVerts, 0, 0, false, false);
|
||||||
vertexDataType->compute();
|
vertexDataType->compute();
|
||||||
|
|
||||||
Allocation *vertexAlloc = Allocation::createAllocation(rsc, vertexDataType, RS_ALLOCATION_USAGE_SCRIPT);
|
Allocation *vertexAlloc = Allocation::createAllocation(rsc, vertexDataType.get(),
|
||||||
|
RS_ALLOCATION_USAGE_SCRIPT);
|
||||||
|
|
||||||
uint32_t vertexSize = vertexDataElem->getSizeBytes()/sizeof(float);
|
uint32_t vertexSize = vertexDataElem->getSizeBytes()/sizeof(float);
|
||||||
// Fill this allocation with some data
|
// Fill this allocation with some data
|
||||||
@@ -112,7 +118,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now lets write index data
|
// Now lets write index data
|
||||||
const Element *indexElem = Element::create(rsc, RS_TYPE_UNSIGNED_16, RS_KIND_USER, false, 1);
|
ObjectBaseRef<const Element> indexElem = Element::createRef(rsc, RS_TYPE_UNSIGNED_16,
|
||||||
|
RS_KIND_USER, false, 1);
|
||||||
|
|
||||||
Mesh *mesh = new Mesh(rsc, 1, mTriangleLists.size());
|
Mesh *mesh = new Mesh(rsc, 1, mTriangleLists.size());
|
||||||
mesh->setName(mName.c_str());
|
mesh->setName(mName.c_str());
|
||||||
@@ -122,11 +129,13 @@ public:
|
|||||||
for (uint32_t pCount = 0; pCount < mTriangleLists.size(); pCount ++) {
|
for (uint32_t pCount = 0; pCount < mTriangleLists.size(); pCount ++) {
|
||||||
|
|
||||||
uint32_t numIndicies = mTriangleLists[pCount].size();
|
uint32_t numIndicies = mTriangleLists[pCount].size();
|
||||||
Type *indexType = Type::getType(rsc, indexElem, numIndicies, 0, 0, false, false );
|
ObjectBaseRef<Type> indexType = Type::getTypeRef(rsc, indexElem.get(),
|
||||||
|
numIndicies, 0, 0, false, false );
|
||||||
|
|
||||||
indexType->compute();
|
indexType->compute();
|
||||||
|
|
||||||
Allocation *indexAlloc = Allocation::createAllocation(rsc, indexType, RS_ALLOCATION_USAGE_SCRIPT);
|
Allocation *indexAlloc = Allocation::createAllocation(rsc, indexType.get(),
|
||||||
|
RS_ALLOCATION_USAGE_SCRIPT);
|
||||||
uint16_t *indexPtr = (uint16_t*)indexAlloc->getPtr();
|
uint16_t *indexPtr = (uint16_t*)indexAlloc->getPtr();
|
||||||
const std::vector<uint32_t> &indexList = mTriangleLists[pCount];
|
const std::vector<uint32_t> &indexList = mTriangleLists[pCount];
|
||||||
uint32_t numTries = numIndicies / 3;
|
uint32_t numTries = numIndicies / 3;
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ int main (int argc, char * const argv[]) {
|
|||||||
const char *objExt = ".obj";
|
const char *objExt = ".obj";
|
||||||
const char *daeExt = ".dae";
|
const char *daeExt = ".dae";
|
||||||
|
|
||||||
if(argc != 3) {
|
if(argc != 3 && argc != 4) {
|
||||||
printf("-----------------------------------------------------------------\n");
|
printf("-----------------------------------------------------------------\n");
|
||||||
printf("Usage:\n");
|
printf("Usage:\n");
|
||||||
printf("a3dconvert input_file a3d_output_file\n");
|
printf("a3dconvert input_file a3d_output_file\n");
|
||||||
@@ -105,10 +105,17 @@ int main (int argc, char * const argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool stripColladaGeo = false;
|
||||||
GeometryLoader *loader = NULL;
|
GeometryLoader *loader = NULL;
|
||||||
std::string ext = filename.substr(dotPos);
|
std::string ext = filename.substr(dotPos);
|
||||||
if (ext == daeExt) {
|
if (ext == daeExt) {
|
||||||
loader = new ColladaLoader();
|
loader = new ColladaLoader();
|
||||||
|
if (argc == 4) {
|
||||||
|
std::string option = argv[3];
|
||||||
|
if (option == "-d") {
|
||||||
|
stripColladaGeo = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (ext == objExt) {
|
} else if (ext == objExt) {
|
||||||
loader = new ObjLoader();
|
loader = new ObjLoader();
|
||||||
} else {
|
} else {
|
||||||
@@ -121,6 +128,11 @@ int main (int argc, char * const argv[]) {
|
|||||||
isSuccessful = convertToA3D(loader, argv[2]);
|
isSuccessful = convertToA3D(loader, argv[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isSuccessful && stripColladaGeo) {
|
||||||
|
ColladaLoader *colladaLoader = (ColladaLoader*)loader;
|
||||||
|
colladaLoader->stripGeometryAndSave();
|
||||||
|
}
|
||||||
|
|
||||||
delete loader;
|
delete loader;
|
||||||
|
|
||||||
if(isSuccessful) {
|
if(isSuccessful) {
|
||||||
|
|||||||
Reference in New Issue
Block a user