mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-10 05:49:00 +08:00
W.I.P. alembic to gltf converter.
This commit is contained in:
parent
fcaacde94c
commit
8d6fc9ece6
11
examples/alembic_to_gltf/Makefile
Normal file
11
examples/alembic_to_gltf/Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
ABC_INC := -I${HOME}/work/alembic-dist/usr/local/include
|
||||
ABC_LDFLAGS := -L${HOME}/work/alembic-dist/usr/local/lib -lAlembic
|
||||
|
||||
ILMBASE_INC := -I/usr/include/OpenEXR
|
||||
|
||||
# Suppress some C++ warnings(in clang).
|
||||
EXTRA_CXXFLAGS := -Wno-deprecated-register
|
||||
|
||||
|
||||
all:
|
||||
clang++ -std=c++11 -g -o abc2gltf $(ABC_INC) $(ILMBASE_INC) $(EXTRA_CXXFLAGS) main.cc $(ABC_LDFLAGS)
|
74
examples/alembic_to_gltf/main.cc
Normal file
74
examples/alembic_to_gltf/main.cc
Normal file
@ -0,0 +1,74 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include <Alembic/AbcGeom/All.h>
|
||||
#include <Alembic/AbcCoreOgawa/All.h>
|
||||
#include <Alembic/AbcCoreFactory/All.h>
|
||||
|
||||
static void
|
||||
VisitObject(const Alembic::AbcGeom::IObject& obj)
|
||||
{
|
||||
std::string path = obj.getFullName();
|
||||
|
||||
if (path.compare("/") != 0) {
|
||||
std::cout << "Object: path = " << path << std::endl;
|
||||
}
|
||||
|
||||
Alembic::AbcGeom::ICompoundProperty props = obj.getProperties();
|
||||
|
||||
for (size_t i = 0; i < obj.getNumChildren(); i++) {
|
||||
const Alembic::AbcGeom::ObjectHeader &header = obj.getChildHeader(i);
|
||||
|
||||
if (Alembic::AbcGeom::IPolyMesh::matches(header)) {
|
||||
// Polygon
|
||||
Alembic::AbcGeom::IPolyMesh pmesh(obj, header.getName());
|
||||
|
||||
Alembic::AbcGeom::ISampleSelector ss(0.0f, Alembic::AbcGeom::ISampleSelector::kNearIndex);
|
||||
Alembic::AbcGeom::IPolyMeshSchema::Sample psample;
|
||||
Alembic::AbcGeom::IPolyMeshSchema &ps = pmesh.getSchema();
|
||||
|
||||
std::cout << " # of samples = " << ps.getNumSamples() << std::endl;
|
||||
|
||||
if (ps.getNumSamples() > 0) {
|
||||
ps.get(psample, ss);
|
||||
Alembic::Abc::P3fArraySamplePtr P = psample.getPositions();
|
||||
std::cout << " # of positions = " << P->size() << std::endl;
|
||||
std::cout << " # of face counts = " << psample.getFaceCounts()->size() << std::endl;
|
||||
|
||||
} else {
|
||||
std::cout << "Warning: # of samples = 0" << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
main(
|
||||
int argc,
|
||||
char **argv)
|
||||
{
|
||||
std::string abc_filename;
|
||||
std::string gltf_filename;
|
||||
|
||||
if (argc < 3) {
|
||||
std::cerr << "Usage: gltf2abc input.gltf output.abc" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
gltf_filename = std::string(argv[1]);
|
||||
abc_filename = std::string(argv[2]);
|
||||
|
||||
Alembic::AbcCoreFactory::IFactory factory;
|
||||
Alembic::AbcGeom::IArchive archive = factory.getArchive(abc_filename);
|
||||
|
||||
Alembic::AbcGeom::IObject root = archive.getTop();
|
||||
|
||||
std::cout << "# of children " << root.getNumChildren() << std::endl;
|
||||
|
||||
VisitObject(root);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user