Some refactoring of the code.
Change-Id: I7b2aa13621c9a2e7a952efafbb1aaf4d86461fed
This commit is contained in:
@@ -27,8 +27,8 @@ public:
|
|||||||
ColladaGeometry();
|
ColladaGeometry();
|
||||||
bool init(domGeometryRef geometry);
|
bool init(domGeometryRef geometry);
|
||||||
|
|
||||||
Mesh *getMesh(Context *rsc) {
|
SimpleMesh *getMesh() {
|
||||||
return mConvertedMesh.getMesh(rsc);
|
return &mConvertedMesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -17,8 +17,6 @@
|
|||||||
#include "ColladaLoader.h"
|
#include "ColladaLoader.h"
|
||||||
#include "ColladaConditioner.h"
|
#include "ColladaConditioner.h"
|
||||||
#include "ColladaGeometry.h"
|
#include "ColladaGeometry.h"
|
||||||
#include "rsContext.h"
|
|
||||||
#include "rsFileA3D.h"
|
|
||||||
|
|
||||||
#include <dae.h>
|
#include <dae.h>
|
||||||
#include <dom/domCOLLADA.h>
|
#include <dom/domCOLLADA.h>
|
||||||
@@ -64,22 +62,8 @@ bool ColladaLoader::init(const char *colladaFile) {
|
|||||||
return convertSuceeded;
|
return convertSuceeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ColladaLoader::convertToA3D(const char *a3dFile) {
|
SimpleMesh *ColladaLoader::getMesh(uint32_t meshIndex) {
|
||||||
if (mGeometries.size() == 0) {
|
return mGeometries[meshIndex]->getMesh();
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Now write all this stuff out
|
|
||||||
Context rsc;
|
|
||||||
FileA3D file(&rsc);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < mGeometries.size(); i++) {
|
|
||||||
Mesh *exportedMesh = mGeometries[i]->getMesh(&rsc);
|
|
||||||
file.appendToFile(exportedMesh);
|
|
||||||
delete exportedMesh;
|
|
||||||
}
|
|
||||||
|
|
||||||
file.writeFile(a3dFile);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ColladaLoader::convertAllGeometry(domLibrary_geometries *allGeometry) {
|
bool ColladaLoader::convertAllGeometry(domLibrary_geometries *allGeometry) {
|
||||||
|
|||||||
@@ -22,14 +22,20 @@
|
|||||||
class domLibrary_geometries;
|
class domLibrary_geometries;
|
||||||
class domGeometry;
|
class domGeometry;
|
||||||
class ColladaGeometry;
|
class ColladaGeometry;
|
||||||
|
class SimpleMesh;
|
||||||
|
|
||||||
class ColladaLoader {
|
#include "GeometryLoader.h"
|
||||||
|
|
||||||
|
class ColladaLoader : public GeometryLoader {
|
||||||
public:
|
public:
|
||||||
ColladaLoader();
|
ColladaLoader();
|
||||||
~ColladaLoader();
|
virtual ~ColladaLoader();
|
||||||
|
|
||||||
bool init(const char *colladaFile);
|
virtual bool init(const char *colladaFile);
|
||||||
bool convertToA3D(const char *a3dFile);
|
virtual SimpleMesh *getMesh(uint32_t meshIndex);
|
||||||
|
virtual uint32_t getNumMeshes() const {
|
||||||
|
return mGeometries.size();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void clearGeometry();
|
void clearGeometry();
|
||||||
|
|||||||
31
tools/a3dconvert/GeometryLoader.h
Normal file
31
tools/a3dconvert/GeometryLoader.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2011 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _GEOMETRY_LOADER_H_
|
||||||
|
#define _GEOMETRY_LOADER_H_
|
||||||
|
|
||||||
|
#include "SimpleMesh.h"
|
||||||
|
|
||||||
|
class GeometryLoader {
|
||||||
|
public:
|
||||||
|
virtual ~GeometryLoader() {
|
||||||
|
}
|
||||||
|
virtual bool init(const char *file) = 0;
|
||||||
|
virtual uint32_t getNumMeshes() const = 0;
|
||||||
|
virtual SimpleMesh *getMesh(uint32_t meshIndex) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif _GEOMETRY_LOADER_H_
|
||||||
@@ -228,24 +228,6 @@ bool ObjLoader::init(const char *fileName) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ObjLoader::convertToA3D(const char *a3dFile) {
|
|
||||||
if (!getNumMeshes()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// Now write all this stuff out
|
|
||||||
Context rsc;
|
|
||||||
FileA3D file(&rsc);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < getNumMeshes(); i ++) {
|
|
||||||
Mesh *exportedMesh = getMesh(&rsc, i);
|
|
||||||
file.appendToFile(exportedMesh);
|
|
||||||
delete exportedMesh;
|
|
||||||
}
|
|
||||||
|
|
||||||
file.writeFile(a3dFile);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ObjLoader::reIndexGeometry() {
|
void ObjLoader::reIndexGeometry() {
|
||||||
// We want to know where each vertex lands
|
// We want to know where each vertex lands
|
||||||
mVertexRemap.resize(mObjPositions.size() / mPositionsStride);
|
mVertexRemap.resize(mObjPositions.size() / mPositionsStride);
|
||||||
|
|||||||
@@ -22,28 +22,28 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "SimpleMesh.h"
|
#include "GeometryLoader.h"
|
||||||
#include <rsContext.h>
|
|
||||||
|
|
||||||
using namespace android;
|
using namespace android;
|
||||||
using namespace android::renderscript;
|
using namespace android::renderscript;
|
||||||
|
|
||||||
#define MAX_INDEX 0xffffffff
|
#define MAX_INDEX 0xffffffff
|
||||||
|
|
||||||
class ObjLoader {
|
class ObjLoader : public GeometryLoader {
|
||||||
public:
|
public:
|
||||||
ObjLoader();
|
ObjLoader();
|
||||||
bool init(const char *objFile);
|
virtual ~ObjLoader() {
|
||||||
bool convertToA3D(const char *a3dFile);
|
|
||||||
private:
|
|
||||||
|
|
||||||
Mesh *getMesh(Context *rsc, uint32_t meshIndex) {
|
|
||||||
return mMeshes[meshIndex].getMesh(rsc);
|
|
||||||
}
|
}
|
||||||
uint32_t getNumMeshes() const {
|
virtual bool init(const char *objFile);
|
||||||
|
|
||||||
|
virtual SimpleMesh *getMesh(uint32_t meshIndex) {
|
||||||
|
return &mMeshes[meshIndex];
|
||||||
|
}
|
||||||
|
virtual uint32_t getNumMeshes() const {
|
||||||
return mMeshes.size();
|
return mMeshes.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
// .obj has a global list of vertex data
|
// .obj has a global list of vertex data
|
||||||
std::vector<float> mObjPositions;
|
std::vector<float> mObjPositions;
|
||||||
std::vector<float> mObjNormals;
|
std::vector<float> mObjNormals;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include <rsContext.h>
|
#include <rsContext.h>
|
||||||
#include <rsMesh.h>
|
#include <rsMesh.h>
|
||||||
|
#include <string>
|
||||||
using namespace android;
|
using namespace android;
|
||||||
using namespace android::renderscript;
|
using namespace android::renderscript;
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generates a renderscript mesh that could be used for a3d serialization
|
// Generates a renderscript mesh that could be used for a3d serialization
|
||||||
Mesh *getMesh(Context *rsc) {
|
Mesh *getRsMesh(Context *rsc) {
|
||||||
if (mChannels.size() == 0) {
|
if (mChannels.size() == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -113,19 +114,12 @@ 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);
|
const Element *indexElem = Element::create(rsc, RS_TYPE_UNSIGNED_16, RS_KIND_USER, false, 1);
|
||||||
|
|
||||||
Mesh *mesh = new Mesh(rsc);
|
Mesh *mesh = new Mesh(rsc, 1, mTriangleLists.size());
|
||||||
mesh->setName(mName.c_str());
|
mesh->setName(mName.c_str());
|
||||||
mesh->mVertexBufferCount = 1;
|
mesh->setVertexBuffer(vertexAlloc, 0);
|
||||||
mesh->mVertexBuffers = new ObjectBaseRef<Allocation>[1];
|
|
||||||
mesh->mVertexBuffers[0].set(vertexAlloc);
|
|
||||||
|
|
||||||
mesh->mPrimitivesCount = mTriangleLists.size();
|
|
||||||
mesh->mPrimitives = new Mesh::Primitive_t *[mesh->mPrimitivesCount];
|
|
||||||
|
|
||||||
// load all primitives
|
// load all primitives
|
||||||
for (uint32_t pCount = 0; pCount < mesh->mPrimitivesCount; pCount ++) {
|
for (uint32_t pCount = 0; pCount < mTriangleLists.size(); pCount ++) {
|
||||||
Mesh::Primitive_t *prim = new Mesh::Primitive_t;
|
|
||||||
mesh->mPrimitives[pCount] = prim;
|
|
||||||
|
|
||||||
uint32_t numIndicies = mTriangleLists[pCount].size();
|
uint32_t numIndicies = mTriangleLists[pCount].size();
|
||||||
Type *indexType = Type::getType(rsc, indexElem, numIndicies, 0, 0, false, false );
|
Type *indexType = Type::getType(rsc, indexElem, numIndicies, 0, 0, false, false );
|
||||||
@@ -143,8 +137,7 @@ public:
|
|||||||
indexPtr[i * 3 + 2] = (uint16_t)indexList[i * 3 + 2];
|
indexPtr[i * 3 + 2] = (uint16_t)indexList[i * 3 + 2];
|
||||||
}
|
}
|
||||||
indexAlloc->setName(mTriangleListNames[pCount].c_str());
|
indexAlloc->setName(mTriangleListNames[pCount].c_str());
|
||||||
prim->mIndexBuffer.set(indexAlloc);
|
mesh->setPrimitive(indexAlloc, RS_PRIMITIVE_TRIANGLE, pCount);
|
||||||
prim->mPrimitive = RS_PRIMITIVE_TRIANGLE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return mesh;
|
return mesh;
|
||||||
|
|||||||
@@ -19,6 +19,26 @@
|
|||||||
|
|
||||||
#include "ColladaLoader.h"
|
#include "ColladaLoader.h"
|
||||||
#include "ObjLoader.h"
|
#include "ObjLoader.h"
|
||||||
|
#include "rsContext.h"
|
||||||
|
#include "rsFileA3D.h"
|
||||||
|
|
||||||
|
bool convertToA3D(GeometryLoader *loader, const char *a3dFile) {
|
||||||
|
if (!loader->getNumMeshes()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Now write all this stuff out
|
||||||
|
Context rsc;
|
||||||
|
FileA3D file(&rsc);
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < loader->getNumMeshes(); i ++) {
|
||||||
|
Mesh *exportedMesh = loader->getMesh(i)->getRsMesh(&rsc);
|
||||||
|
file.appendToFile(exportedMesh);
|
||||||
|
delete exportedMesh;
|
||||||
|
}
|
||||||
|
|
||||||
|
file.writeFile(a3dFile);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int main (int argc, char * const argv[]) {
|
int main (int argc, char * const argv[]) {
|
||||||
const char *objExt = ".obj";
|
const char *objExt = ".obj";
|
||||||
@@ -42,24 +62,24 @@ int main (int argc, char * const argv[]) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GeometryLoader *loader = NULL;
|
||||||
std::string ext = filename.substr(dotPos);
|
std::string ext = filename.substr(dotPos);
|
||||||
if (ext == daeExt) {
|
if (ext == daeExt) {
|
||||||
ColladaLoader converter;
|
loader = new ColladaLoader();
|
||||||
isSuccessful = converter.init(argv[1]);
|
|
||||||
if (isSuccessful) {
|
|
||||||
isSuccessful = converter.convertToA3D(argv[2]);
|
|
||||||
}
|
|
||||||
} else if (ext == objExt) {
|
} else if (ext == objExt) {
|
||||||
ObjLoader objConv;
|
loader = new ObjLoader();
|
||||||
isSuccessful = objConv.init(argv[1]);
|
|
||||||
if (isSuccessful) {
|
|
||||||
isSuccessful = objConv.convertToA3D(argv[2]);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
printf("Invalid input. Currently .obj and .dae (collada) input files are accepted\n");
|
printf("Invalid input. Currently .obj and .dae (collada) input files are accepted\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isSuccessful = loader->init(argv[1]);
|
||||||
|
if (isSuccessful) {
|
||||||
|
isSuccessful = convertToA3D(loader, argv[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete loader;
|
||||||
|
|
||||||
if(isSuccessful) {
|
if(isSuccessful) {
|
||||||
printf("---All done---\n");
|
printf("---All done---\n");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user