mirror of
https://github.com/wahyd4/three.js.git
synced 2026-08-09 04:56:01 +10:00
Included corresponding compressor in "utils/exporters/utf8" (prebuilt exe for Windows plus slightly modified C++ source code). Use UTF8 format with caution, it is very neat but has quite a few limitations: - number of vertices < 65536 (this is after optimizations in compressor, input OBJ may have even less) - models must have normals and texture coordinates - texture coordinates must be only from <0,1> - no materials support yet - models are scaled and offset (copy numbers from compressor and use them as parameters in UTF8Loader.load() )
62 lines
2.1 KiB
C++
62 lines
2.1 KiB
C++
#if 0 // A cute trick to making this .cc self-building from shell.
|
|
g++ $0 -O2 -Wall -Werror -o `basename $0 .cc`;
|
|
exit;
|
|
#endif
|
|
// Copyright 2011 Google Inc. All Rights Reserved.
|
|
//
|
|
// 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.
|
|
|
|
#include "mesh.h"
|
|
|
|
const bool kQuantize = true;
|
|
const bool kOptimize = true;
|
|
|
|
int main(int argc, char* argv[]) {
|
|
if (argc < 2 || argc > 3) {
|
|
fprintf(stderr, "Usage: %s in.obj [out.utf8]\n\n"
|
|
"\tIf 'out' is specified, then attempt to write out a compressed,\n"
|
|
"\tUTF-8 version to 'out.'\n\n"
|
|
"\tIf not, write a JSON version to STDOUT.\n\n",
|
|
argv[0]);
|
|
return -1;
|
|
}
|
|
FILE* fp = fopen(argv[1], "r");
|
|
WavefrontObjFile obj(fp);
|
|
fclose(fp);
|
|
std::vector<DrawMesh> meshes;
|
|
obj.CreateDrawMeshes(&meshes);
|
|
if (kQuantize) {
|
|
QuantizedAttribList attribs;
|
|
AttribsToQuantizedAttribs(meshes[0].interleaved_attribs, &attribs);
|
|
if (kOptimize) {
|
|
QuantizedAttribList optimized_attribs;
|
|
IndexList optimized_indices;
|
|
VertexOptimizer vertex_optimizer(attribs, meshes[0].triangle_indices);
|
|
vertex_optimizer.GetOptimizedMesh(&optimized_attribs, &optimized_indices);
|
|
if (argc == 3) {
|
|
CompressMeshToFile(optimized_attribs, optimized_indices, argv[2]);
|
|
} else {
|
|
DumpJsonFromQuantizedAttribs(optimized_attribs);
|
|
DumpJsonFromIndices(optimized_indices);
|
|
}
|
|
return 0;
|
|
} else {
|
|
DumpJsonFromQuantizedAttribs(attribs);
|
|
}
|
|
} else {
|
|
DumpJsonFromInterleavedAttribs(meshes[0].interleaved_attribs);
|
|
}
|
|
DumpJsonFromIndices(meshes[0].triangle_indices);
|
|
return 0;
|
|
}
|