Skip to content

Commit

Permalink
Delete trailing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
mariansam committed Apr 13, 2021
1 parent 69a26c7 commit 451448e
Show file tree
Hide file tree
Showing 10 changed files with 789 additions and 792 deletions.
402 changes: 201 additions & 201 deletions ViroFBX/Nodes.pb.cc

Large diffs are not rendered by default.

402 changes: 201 additions & 201 deletions ViroFBX/Nodes.pb.h

Large diffs are not rendered by default.

570 changes: 284 additions & 286 deletions ViroFBX/VROFBXExporter.cpp

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions ViroFBX/VROFBXExporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static const int kMaxBoneInfluences = 4;

/*
Maximum number of bones in a node. Keep in sync with:
ViroRenderer::VROBoneUBO.h and
ViroRenderer::skinning_vsh.glsl
*/
Expand All @@ -32,7 +32,7 @@ class VROBoneIndexWeight {
public:
int index;
float weight;

VROBoneIndexWeight(int i, float w) :
index(i), weight(w) {}
};
Expand All @@ -47,27 +47,27 @@ class VROControlPointMetadata {
};

class VROFBXExporter {

public:

VROFBXExporter();
virtual ~VROFBXExporter();

void exportFBX(std::string fbxPath, std::string protoPath, bool compressTextures);
void debugPrint(std::string fbxPath);

private:

FbxManager *_fbxManager;
FbxScene *loadFBX(std::string fbxPath);

/*
The path of the file we're currently exporting.
*/
std::string _fbxPath;

#pragma mark - Export Methods

void exportNode(FbxScene *scene, FbxNode *node, int depth, bool compressTextures,
const std::vector<FbxNode *> &boneNodes, viro::Node::Skeleton *outSkeleton, viro::Node *outNode);
void exportGeometry(FbxNode *node, int depth, bool compressTextures, viro::Node::Geometry *geo);
Expand All @@ -77,38 +77,38 @@ class VROFBXExporter {
void exportSkeleton(FbxNode *rootNode, std::vector<FbxNode *> *outBoneNodes, viro::Node::Skeleton *outSkeleton);
void exportSkeletonRecursive(FbxNode *node, int depth, int index, int parentIndex, std::vector<FbxNode *> *outBoneNodes, viro::Node::Skeleton *outSkeleton);
void exportSkin(FbxNode *node, const std::vector<FbxNode *> &boneNodes, viro::Node::Skeleton *outSkeleton, viro::Node::Geometry::Skin *outSkin);

void exportKeyframeAnimations(FbxScene *scene, FbxNode *node, viro::Node *outNode);
void exportSampledKeyframeAnimations(FbxScene *scene, FbxNode *node, viro::Node *outNode);
void exportSkeletalAnimations(FbxScene *scene, FbxNode *node, const std::vector<FbxNode *> &boneNodes,
viro::Node *outNode);
void exportBlendShapeAnimations(FbxScene *scene, FbxNode *node, viro::Node *outNode);

#pragma mark - Export Helpers

FbxVector4 readNormal(FbxMesh *mesh, int controlPointIndex, int cornerCounter);
FbxVector4 readTangent(FbxMesh *mesh, int controlPointIndex, int cornerCounter);
std::vector<int> readMaterialToMeshMapping(FbxMesh *mesh, int numPolygons);
unsigned int findBoneIndex(FbxNode *node, const std::vector<FbxNode *> &boneNodes);
bool isExportableNode(FbxNode *node);
FbxAMatrix getGeometryMatrix(FbxNode *node);

viro::Node_Geometry_Material_Visual_WrapMode convert(FbxTexture::EWrapMode wrapMode);

#pragma mark - Texture Compression

bool compressTexture(std::string textureName);

#pragma mark - Print Methods

int _numTabs;
void printNode(FbxNode *pNode);
void printAttribute(FbxNodeAttribute *pAttribute);
void printGeometry(FbxGeometry *pGeometry);
void printTabs();

#pragma mark - Utils

std::string extractTextureName(FbxFileTexture *texture);
std::string getFileName(std::string file);
std::string getFileExtension(std::string file);
Expand All @@ -120,7 +120,7 @@ class VROFBXExporter {
std::string parseTexture(FbxProperty property);
bool parseBool(FbxProperty property);
float parseFloat(FbxProperty property);

};

#endif /* VROFBXExporter_h */
92 changes: 46 additions & 46 deletions ViroFBX/VROFbxToObjConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ NSLog(@#message, ##__VA_ARGS__); \

VROFbxToObjConverter::VROFbxToObjConverter() {
_fbxManager = FbxManager::Create();

}

VROFbxToObjConverter::~VROFbxToObjConverter() {
Expand All @@ -34,48 +34,48 @@ VROFbxToObjConverter::~VROFbxToObjConverter() {

FbxScene *VROFbxToObjConverter::loadFBX(std::string fbxPath) {
_fbxPath = fbxPath;

FbxIOSettings *ios = FbxIOSettings::Create(_fbxManager, IOSROOT);
_fbxManager->SetIOSettings(ios);

FbxImporter *importer = FbxImporter::Create(_fbxManager, "");

pinfo("Loading file [%s]", fbxPath.c_str());
bool importStatus = importer->Initialize(fbxPath.c_str());
if (!importStatus) {
pinfo("Call to FBXImporter::Initialize() failed");
pinfo("Error returned: %s", importer->GetStatus().GetErrorString());

return nullptr;
}
else {
pinfo("Import successful");
}

FbxScene *scene = FbxScene::Create(_fbxManager, "scene");
importer->Import(scene);
importer->Destroy();

/*
Convert the file to the default axis sytem.
*/
FbxAxisSystem axisSystem;
static const FbxAxisSystem::EUpVector defaultUpAxis = FbxAxisSystem::eYAxis;
static const FbxAxisSystem::EFrontVector defaultFrontAxis = FbxAxisSystem::eParityOdd;
static const FbxAxisSystem::ECoordSystem defaultCoordSystem = FbxAxisSystem::eRightHanded;

FbxAxisSystem origAxisSystem = scene->GetGlobalSettings().GetAxisSystem();
int upAxisSign;
FbxAxisSystem::EUpVector upAxis = origAxisSystem.GetUpVector(upAxisSign);
pinfo(" Original up axis %d, sign %d", (int)upAxis, upAxisSign);

int forwardAxisSign;
FbxAxisSystem::EFrontVector forwardAxis = origAxisSystem.GetFrontVector(forwardAxisSign);
pinfo(" Original forward axis %d, sign %d", (int)forwardAxis, forwardAxisSign);

FbxAxisSystem::ECoordSystem coordSystem = origAxisSystem.GetCoorSystem();
pinfo(" Coordinate system %d", (int)coordSystem);

FbxAxisSystem axis(defaultUpAxis, defaultFrontAxis, defaultCoordSystem);
axis.ConvertScene(scene);
return scene;
Expand All @@ -88,14 +88,14 @@ void VROFbxToObjConverter::convertToObj(std::string fbxPath, std::string outPath
if (scene == nullptr) {
return;
}

pinfo("Triangulating scene...");

FbxGeometryConverter converter(_fbxManager);
converter.Triangulate(scene, true);

pinfo("Exporting FBX to OBJ...");

FbxNode *rootNode = scene->GetRootNode();
if (rootNode) {
for (int i = 0; i < rootNode->GetChildCount(); i++) {
Expand All @@ -112,46 +112,46 @@ bool VROFbxToObjConverter::isExportableNode(FbxNode *node) {
pinfo("Encountered node with no attribute type -- skipping");
return false;
}

// Do not export skeleton nodes here (processed separately)
if (node->GetNodeAttribute()->GetAttributeType() == FbxNodeAttribute::eSkeleton) {
return false;
}

// Skip camera and light nodes
if (node->GetNodeAttribute()->GetAttributeType() == FbxNodeAttribute::eCamera ||
node->GetNodeAttribute()->GetAttributeType() == FbxNodeAttribute::eLight) {
return false;
}

// Skip invisible nodes
if (!node->GetVisibility()) {
if (node->GetMesh() != nullptr) {
pinfo("Not exporting geometry of node [%s] -- visibility is false", node->GetName());
}
return false;
}

// Skip nodes with no mesh
if (node->GetMesh() == nullptr) {
return false;
}

return true;
}

void VROFbxToObjConverter::convertToObj(FbxNode *node, std::string outPath) {
std::stringstream ss;
ss << "File converted from FBX" << "\n" << "\n";

FbxMesh *mesh = node->GetMesh();
if (!mesh) {
pinfo("Failed to export, null mesh!");
}

mesh->GenerateTangentsData(0);
int cornerCounter = 0;

/*
Get the UV set names. For now we only use the first one.
*/
Expand All @@ -160,11 +160,11 @@ void VROFbxToObjConverter::convertToObj(FbxNode *node, std::string outPath) {
if (layerCount > 0) {
for (int uvLayerIndex = 0; uvLayerIndex < layerCount; uvLayerIndex++) {
FbxLayer *layer = mesh->GetLayer(uvLayerIndex);

// One layer can have multiple UV sets
int uvSetCount = layer->GetUVSetCount();
FbxArray<const FbxLayerElementUV *> sets = layer->GetUVSets();

for (int uvIndex = 0; uvIndex < uvSetCount; uvIndex++) {
FbxLayerElementUV const* elementUV = sets[uvIndex];
if (elementUV) {
Expand All @@ -173,97 +173,97 @@ void VROFbxToObjConverter::convertToObj(FbxNode *node, std::string outPath) {
}
}
}

pinfo(" UV set name %s", uvSetName);

/*
Export the vertex, normal, tex-coord, and tangent data (the geometry
sources).
*/
std::vector<double> vertices;

int numVertices = mesh->GetControlPointsCount();
pinfo(" Vertices count %d", numVertices);
ss << "# " << numVertices << " vertices" << "\n";

for (int i = 0; i < numVertices; i++) {
FbxVector4 vertex = mesh->GetControlPointAt(i);
ss << "v " << vertex.mData[0] << " " << vertex.mData[1] << " " << vertex.mData[2] << "\n";
}
ss << "\n";

int numPolygons = mesh->GetPolygonCount();
pinfo(" Polygon count %d", numPolygons);

std::vector<std::pair<double, double>> texcoords;
std::vector<std::vector<double>> normals;
std::vector<int> vertexIndices;
std::vector<int> texNormalIndices;

for (unsigned int i = 0; i < numPolygons; i++) {
// We only support triangles
int polygonSize = mesh->GetPolygonSize(i);
passert (polygonSize == 3);

for (int j = 0; j < polygonSize; j++) {
int vertexIndex = mesh->GetPolygonVertex(i, j);
vertexIndices.push_back(vertexIndex + 1);
texNormalIndices.push_back((int) texNormalIndices.size() + 1);

FbxVector2 uv;
bool unmapped;
bool hasUV = mesh->GetPolygonVertexUV(i, j, uvSetName, uv, unmapped);
passert (hasUV && !unmapped);

texcoords.push_back({ uv.mData[0], uv.mData[1] });
// ? 1 - uv.mData[1];

FbxVector4 normal;
bool hasNormal = mesh->GetPolygonVertexNormal(i, j, normal);
passert (hasNormal);

normals.push_back({ normal.mData[0], normal.mData[1], normal.mData[2] });
++cornerCounter;
}
}

int numTexcoords = (int) texcoords.size();
pinfo(" Texcoords count %d", numTexcoords);
ss << "# " << numTexcoords << " texcoords" << "\n";

for (int i = 0; i < numTexcoords; i++) {
std::pair<double, double> texcoord = texcoords[i];
ss << "vt " << texcoord.first << " " << texcoord.second << " 0" << "\n";
}
ss << "\n";

int numNormals = (int) normals.size();
pinfo(" Normals count %d", numNormals);
ss << "# " << numNormals << " normals" << "\n";

for (int i = 0; i < numNormals; i++) {
std::vector<double> normal = normals[i];
ss << "vn " << normal[0] << " " << normal[1] << " " << normal[2] << "\n";
}
ss << "\n";

int numFaces = (int) vertexIndices.size() / 3;
pinfo(" Faces count %d", numFaces);
ss << "# " << numFaces << " faces" << "\n";
passert (vertexIndices.size() == texNormalIndices.size());

for (int i = 0; i < numFaces; i++) {
int v0 = vertexIndices[i * 3 + 0];
int v1 = vertexIndices[i * 3 + 1];
int v2 = vertexIndices[i * 3 + 2];

int tn0 = texNormalIndices[i * 3 + 0];
int tn1 = texNormalIndices[i * 3 + 1];
int tn2 = texNormalIndices[i * 3 + 2];

ss << "f " << v0 << "/" << tn0 << "/" << tn0 << " " << v1 << "/" << tn1 << "/" << tn1 << " " << v2 << "/" << tn2 << "/" << tn2 << "\n";
}

std::ofstream outFile;
outFile.open(outPath);
outFile << ss.rdbuf();
Expand Down
Loading

0 comments on commit 451448e

Please sign in to comment.