#include <vsg/all.h>
#include "assimp/ReaderWriter_assimp.h"
#include "stbi/ReaderWriter_stbi.h"
int main(int argc, char **argv)
{
auto windowTraits = vsg::WindowTraits::create();
windowTraits->windowTitle = "MyFirstVsgApplication";
auto window = vsg::Window::create(windowTraits);
auto viewport = vsg::ViewportState::create(0, 0, window->extent2D().width, window->extent2D().height);
auto perspective = vsg::Perspective::create(60.0, static_cast<double>(window->extent2D().width) / static_cast<double>(window->extent2D().height), 1.0, 100.0);
auto lookAt = vsg::LookAt::create(vsg::dvec3(0.0, -50.0, 0.0), vsg::dvec3(0.0, 0.0, 0.0), vsg::dvec3(0.0, 0.0, 1.0));
auto camera = vsg::Camera::create(perspective, lookAt, viewport);
auto scene = vsg::Group::create();
//
//
//
auto options = vsg::Options::create();
auto composite = vsg::CompositeReaderWriter::create();
composite->add(vsgXchange::ReaderWriter_stbi::create());
composite->add(vsgXchange::ReaderWriter_assimp::create());
options->readerWriter = composite;
vsg::Path path = "Path to the DamagedHelmet.glb";
auto object = vsg::read(path, options);
if (auto node = object.cast<vsg::Node>(); node)
{
std::cerr << "Node" << std::endl;
scene->addChild(node);
}
else if (auto data = object.cast<vsg::Data>(); data)
{
std::cerr << "Data" << std::endl;
}
else if (object)
{
std::cout << "Unable to view object of type " << object->className() << std::endl;
}
else
{
std::cout << "Unable to load model from file " << path << std::endl;
}
//
//
//
auto viewer = vsg::Viewer::create();
viewer->addWindow(window);
auto commandGraph = vsg::createCommandGraphForView(window, camera, scene);
viewer->assignRecordAndSubmitTaskAndPresentation({commandGraph});
viewer->compile();
viewer->addEventHandler(vsg::WindowResizeHandler::create());
viewer->addEventHandler(vsg::CloseHandler::create(viewer));
viewer->addEventHandler(vsg::Trackball::create(camera));
while (viewer->advanceToNextFrame())
{
viewer->handleEvents();
viewer->update();
viewer->recordAndSubmit();
viewer->present();
}
return 0;
}