Skip to content

Instantly share code, notes, and snippets.

@JossWhittle
Created July 7, 2016 15:15
Show Gist options
  • Select an option

  • Save JossWhittle/dd8323f60e602deeff2465cb3b070365 to your computer and use it in GitHub Desktop.

Select an option

Save JossWhittle/dd8323f60e602deeff2465cb3b070365 to your computer and use it in GitHub Desktop.
#pragma once
#include <vector>
#include <string>
#include "../RenderingEssentials/maths/Vec.hpp"
#include "../RenderingEssentials/maths/Common.hpp"
#include "../RenderingEssentials/geom/Geom.hpp"
#include "../RenderingEssentials/utils/Loader.hpp"
#include "../RenderingEssentials/utils/Exporter.hpp"
using namespace std;
int main(int argc, char *argv[]) {
if (argc < 3) return 0;
vector<Geom> mesh = Loader::loadOBJ(argv[1]);
printf("Computing Bounds ... \n");
BBox bounds{ { INF, INF, INF }, { -INF, -INF, -INF } };
for (const auto &g : mesh) {
bounds = BBox::Union(bounds, g.boundingBox());
}
printf("Normalization ... \n");
for (auto &g : mesh) {
g.V0 = ((g.V0 - bounds.min) * (1.0 / bounds.maxDimension())) - (((bounds.max - bounds.min) * (1.0 / bounds.maxDimension())) * Vec{ 0.5, 0, 0.5 });
g.V1 = ((g.V1 - bounds.min) * (1.0 / bounds.maxDimension())) - (((bounds.max - bounds.min) * (1.0 / bounds.maxDimension())) * Vec{ 0.5, 0, 0.5 });
g.V2 = ((g.V2 - bounds.min) * (1.0 / bounds.maxDimension())) - (((bounds.max - bounds.min) * (1.0 / bounds.maxDimension())) * Vec{ 0.5, 0, 0.5 });
}
Exporter::exportOBJ(argv[2], mesh);
return 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment