Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:syoyo/tinyusdz into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
syoyo committed Oct 16, 2023
2 parents ef47827 + 6d94dc8 commit 5e1bf80
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions examples/openglviewer/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include <thread>
#include <vector>

#if defined(_MSC_VER)
#include <direct.h> // _getcwd
#endif

// GL
//
// glad must be included before glfw3.h
Expand All @@ -28,6 +32,7 @@
// TinyUSDZ
// include relative to openglviewer example cmake top dir for clangd lsp.
#include "tinyusdz.hh"
#include "io-util.hh"
#include "tydra/render-data.hh"
#include "tydra/scene-access.hh"

Expand Down Expand Up @@ -861,6 +866,25 @@ static void MygluLookAt(float eye[3], float center[3], float up[3]) {
glTranslatef(-eye[0], -eye[1], -eye[2]);
}

std::string find_file(const std::string basefile, int max_parents = 8)
{
if (max_parents > 16) {
return std::string();
}

std::string filepath = basefile;

for (size_t i = 0; i < max_parents; i++) {
if (tinyusdz::io::FileExists(filepath)) {
return filepath;
}

filepath = "../" + filepath;
}

return std::string();
}

} // namespace

int main(int argc, char** argv) {
Expand Down Expand Up @@ -913,19 +937,27 @@ int main(int argc, char** argv) {
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);
#endif

std::string filename = "../../../models/suzanne.usdc";
std::string filename = "models/suzanne.usdc";
#if defined(_MSC_VER)
std::cout << "cwd: " << _getcwd(nullptr, 0) << "\n";
#endif

if (argc > 1) {
filename = std::string(argv[1]);
}

std::cout << "Loading USD file " << filename << "\n";
std::string full_filepath = find_file(filename);
if (full_filepath.empty()) {
std::cerr << "cannot find or file not exists: " << filename << "\n";
}

std::cout << "Loading USD file " << full_filepath << "\n";

std::string warn;
std::string err;
tinyusdz::Stage stage;

bool ret = tinyusdz::LoadUSDFromFile(filename, &stage, &warn, &err);
bool ret = tinyusdz::LoadUSDFromFile(full_filepath, &stage, &warn, &err);
if (!warn.empty()) {
std::cerr << "WARN : " << warn << "\n";
return EXIT_FAILURE;
Expand Down Expand Up @@ -1079,8 +1111,8 @@ int main(int argc, char** argv) {
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

//glFlush();
glfwSwapBuffers(window);
glFlush();

static int frameCount = 0;
static double currentTime = glfwGetTime();
Expand All @@ -1097,8 +1129,6 @@ int main(int argc, char** argv) {
previousTime = currentTime;
}

glfwSwapBuffers(window);

done = glfwWindowShouldClose(window);
};

Expand Down

0 comments on commit 5e1bf80

Please sign in to comment.