diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 00000000..232b7489 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,10 @@ +LDFLAGS:=-lfilament -lbackend -lfilameshio -lviewer -lfilamat -lgeometry -lutils -lfilabridge -lgltfio_core -lfilament-iblprefilter -limage -limageio -ltinyexr -lgltfio_core -lfilaflat -ldracodec -libl -lktxreader -lpng -lz -lstb -luberzlib -lsmol-v -luberarchive -lzstd -lvkshaders -lbluegl -lbluevk -lbasis_transcoder -lmeshoptimizer -L../macos/lib -framework CoreFoundation -framework Foundation -framework CoreVideo -framework Metal -framework QuartzCore -framework Cocoa + +clean: + rm ./out/test +run: build + ./out/test +build: cpp/test.cpp + mkdir -p out + clang++ -I../ios/include/filament -I../ios/include/ cpp/test.cpp ../macos/src/SceneManager.cpp --std=c++17 $(LDFLAGS) -o out/test + diff --git a/test/cpp/test.cpp b/test/cpp/test.cpp new file mode 100644 index 00000000..8612b512 --- /dev/null +++ b/test/cpp/test.cpp @@ -0,0 +1,77 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "SceneManager.hpp" + +#include "ResourceBuffer.hpp" + +using namespace filament; +using namespace flutter_filament; +using namespace std; + +int _i = 0; + +ResourceBuffer loadResource(const char* name) { + + std::cout << "LOADING RESOURCE" << std::endl; + + char cwd[PATH_MAX]; + if (getcwd(cwd, sizeof(cwd)) != NULL) { + std::cout << "Current working dir: " << cwd << std::endl; + } + + string name_str(name); + auto id = _i++; + + name_str = string(cwd) + string("/") + name_str; + + std::cout << "Loading resource at " << name_str.c_str() << std::endl; + + streampos length; + ifstream is(name_str, ios::binary); + ResourceBuffer rb { nullptr, -1, 0 }; + if(!is) { + std::cout << "Failed to find resource at file path " << name_str.c_str() << std::endl; + return rb; + } + is.seekg (0, ios::end); + length = is.tellg(); + char * buffer; + buffer = new char [length]; + is.seekg (0, ios::beg); + is.read (buffer, length); + is.close(); + return ResourceBuffer { buffer, static_cast(length), id }; +} + +void freeResource(ResourceBuffer rb) { + +} + +int main(int argc, char** argv) { + auto engine = Engine::create(); + auto scene = engine->createScene(); + auto loader = ResourceLoaderWrapper(loadResource, freeResource); + + auto sceneManager = SceneManager(&loader, engine, scene, nullptr); + + auto shapes = sceneManager.loadGlb("../example/assets/shapes/shapes.glb", 1); + + auto morphTargetNames = sceneManager.getMorphTargetNames(shapes, "Cylinder"); + assert(morphTargetNames->size() == 4); + + morphTargetNames = sceneManager.getMorphTargetNames(shapes, "Cube"); + assert(morphTargetNames->size() == 2); + + morphTargetNames = sceneManager.getMorphTargetNames(shapes, "Cone"); + assert(morphTargetNames->size() == 8); + sceneManager.destroyAll(); +} \ No newline at end of file