objcompress.cc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #if 0 // A cute trick to making this .cc self-building from shell.
  2. g++ $0 -O2 -Wall -Werror -o `basename $0 .cc`;
  3. exit;
  4. #endif
  5. // Copyright 2011 Google Inc. All Rights Reserved.
  6. //
  7. // Licensed under the Apache License, Version 2.0 (the "License"); you
  8. // may not use this file except in compliance with the License. You
  9. // may obtain a copy of the License at
  10. //
  11. // http://www.apache.org/licenses/LICENSE-2.0
  12. //
  13. // Unless required by applicable law or agreed to in writing, software
  14. // distributed under the License is distributed on an "AS IS" BASIS,
  15. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  16. // implied. See the License for the specific language governing
  17. // permissions and limitations under the License.
  18. #include "mesh.h"
  19. const bool kQuantize = true;
  20. const bool kOptimize = true;
  21. int main(int argc, char* argv[]) {
  22. if (argc < 2 || argc > 3) {
  23. fprintf(stderr, "Usage: %s in.obj [out.utf8]\n\n"
  24. "\tIf 'out' is specified, then attempt to write out a compressed,\n"
  25. "\tUTF-8 version to 'out.'\n\n"
  26. "\tIf not, write a JSON version to STDOUT.\n\n",
  27. argv[0]);
  28. return -1;
  29. }
  30. FILE* fp = fopen(argv[1], "r");
  31. WavefrontObjFile obj(fp);
  32. fclose(fp);
  33. std::vector<DrawMesh> meshes;
  34. obj.CreateDrawMeshes(&meshes);
  35. if (kQuantize) {
  36. QuantizedAttribList attribs;
  37. AttribsToQuantizedAttribs(meshes[0].interleaved_attribs, &attribs);
  38. if (kOptimize) {
  39. QuantizedAttribList optimized_attribs;
  40. IndexList optimized_indices;
  41. VertexOptimizer vertex_optimizer(attribs, meshes[0].triangle_indices);
  42. vertex_optimizer.GetOptimizedMesh(&optimized_attribs, &optimized_indices);
  43. if (argc == 3) {
  44. CompressMeshToFile(optimized_attribs, optimized_indices, argv[2]);
  45. } else {
  46. DumpJsonFromQuantizedAttribs(optimized_attribs);
  47. DumpJsonFromIndices(optimized_indices);
  48. }
  49. return 0;
  50. } else {
  51. DumpJsonFromQuantizedAttribs(attribs);
  52. }
  53. } else {
  54. DumpJsonFromInterleavedAttribs(meshes[0].interleaved_attribs);
  55. }
  56. DumpJsonFromIndices(meshes[0].triangle_indices);
  57. return 0;
  58. }