Skip to content

Commit

Permalink
Merge pull request #28730 from jeongseok-meta/vulkanscenegraph
Browse files Browse the repository at this point in the history
Add VulkanSceneGraph and vsgXchange
  • Loading branch information
xhochy authored Jan 23, 2025
2 parents ebd9d2e + 484103e commit 68c5f2d
Show file tree
Hide file tree
Showing 11 changed files with 316 additions and 0 deletions.
12 changes: 12 additions & 0 deletions recipes/VulkanSceneGraph/bld.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@echo on

cmake %SRC_DIR% ^
%CMAKE_ARGS% ^
-B build ^
-DBUILD_SHARED_LIBS=ON

cmake --build build --parallel --config Release
if errorlevel 1 exit 1

cmake --install build --config Release
if errorlevel 1 exit 1
14 changes: 14 additions & 0 deletions recipes/VulkanSceneGraph/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -exo pipefail

cmake $SRC_DIR \
${CMAKE_ARGS} \
-G Ninja \
-B build \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_BUILD_TYPE=Release

cmake --build build --parallel

cmake --install build --strip
63 changes: 63 additions & 0 deletions recipes/VulkanSceneGraph/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{% set name = "VulkanSceneGraph" %}
{% set version = "1.1.8" %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
- url: /~https://github.com/vsg-dev/VulkanSceneGraph/archive/v{{ version }}.tar.gz
sha256: 94a3cebdfddf4759d17bbf0cc9f3278851eb899bdc660eb4681960e4cdd2ad6a
patches:
- patches/ignore-vulkan-version.patch

build:
number: 0
run_exports:
- {{ pin_subpackage('vulkanscenegraph', max_pin='x.x') }}

requirements:
build:
- {{ compiler('cxx') }}
- {{ stdlib('c') }}
- cmake
- ninja # [not win]
- pkgconfig # [linux]
host:
- glslang
- libvulkan-headers
- libvulkan-loader
- libxcb # [linux]
- xorg-xproto # [linux]
run:
- libvulkan-headers
- libvulkan-loader
- libxcb # [linux]
- xorg-xproto # [linux]

test:
commands:
- test -f $PREFIX/include/vsg/all.h # [not win]
- test -f $PREFIX/lib/libvsg${SHLIB_EXT} # [not win]
- test -f $PREFIX/lib/cmake/vsg/vsgConfig.cmake # [not win]
- if not exist %PREFIX%\\Library\\include\\vsg\\all.h exit 1 # [win]
- if not exist %PREFIX%\\Library\\lib\\vsg.lib exit 1 # [win]
- if not exist %PREFIX%\\Library\\bin\\vsg-14.dll exit 1 # [win]
- if not exist %PREFIX%\\Library\\lib\\cmake\\vsg\\vsgConfig.cmake exit 1 # [win]
downstreams:
- vsgxchange

about:
home: https://vsg-dev.github.io/vsg-dev.io/
summary: Vulkan & C++17 based Scene Graph Project
description: |
VulkanSceneGraph (VSG), is a modern, cross platform, high performance scene
graph library built upon Vulkan graphics/compute API. The software is
written in C++17, and follows the CppCoreGuidelines and FOSS Best Practices.
license: MIT
license_file: LICENSE.md
dev_url: /~https://github.com/vsg-dev/VulkanSceneGraph

extra:
recipe-maintainers:
- jeongseok-meta
13 changes: 13 additions & 0 deletions recipes/VulkanSceneGraph/patches/ignore-vulkan-version.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a75f15d8..6a7a0c91 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,7 +7,7 @@ project(vsg
)
set(VSG_SOVERSION 14)
SET(VSG_RELEASE_CANDIDATE 0)
-set(Vulkan_MIN_VERSION 1.1.70.0)
+set(Vulkan_MIN_VERSION )

set(VSG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "Root source directory of VulkanSceneGraph.")
set(VSG_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE INTERNAL "Root binary directory of VulkanSceneGraph.")
12 changes: 12 additions & 0 deletions recipes/vsgXchange/bld.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@echo on

cmake %SRC_DIR% ^
%CMAKE_ARGS% ^
-B build ^
-DBUILD_SHARED_LIBS=ON

cmake --build build --parallel --config Release
if errorlevel 1 exit 1

cmake --install build --config Release
if errorlevel 1 exit 1
14 changes: 14 additions & 0 deletions recipes/vsgXchange/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -exo pipefail

cmake $SRC_DIR \
${CMAKE_ARGS} \
-G Ninja \
-B build \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_BUILD_TYPE=Release

cmake --build build --parallel

cmake --install build --strip
62 changes: 62 additions & 0 deletions recipes/vsgXchange/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{% set name = "vsgXchange" %}
{% set version = "1.1.4" %}

package:
name: {{ name|lower }}
version: {{ version }}

source:
- url: /~https://github.com/vsg-dev/vsgXchange/archive/v{{ version }}.tar.gz
sha256: 0b79369ddcb3676b6998a6660fcf938314ae34eea9fbababf8471e0b94502597

build:
number: 0
run_exports:
- {{ pin_subpackage('vsgxchange', max_pin='x.x') }}

requirements:
build:
- {{ compiler('cxx') }}
- {{ stdlib('c') }}
- cmake
- ninja # [not win]
- pkgconfig # [linux]
host:
- freetype
- libcurl
- libvulkan-headers
- libvulkan-loader
- vulkanscenegraph
run:
- libvulkan-loader
- vulkanscenegraph

test:
commands:
- test -f $PREFIX/include/vsgXchange/all.h # [not win]
- test -f $PREFIX/lib/libvsgXchange${SHLIB_EXT} # [not win]
- test -f $PREFIX/lib/cmake/vsgXchange/vsgXchangeConfig.cmake # [not win]
- if not exist %PREFIX%\\Library\\include\\vsgXchange\\all.h exit 1 # [win]
- if not exist %PREFIX%\\Library\\lib\\vsgXchange.lib exit 1 # [win]
- if not exist %PREFIX%\\Library\\bin\\vsgXchange.dll exit 1 # [win]
- if not exist %PREFIX%\\Library\\bin\\vsgconv.exe exit 1 # [win]
- if not exist %PREFIX%\\Library\\lib\\cmake\\vsgXchange\\vsgXchangeConfig.cmake exit 1 # [win]
requires:
- {{ compiler("c") }}
- {{ compiler("cxx") }}
- cmake
- ninja # [not win]
- pkgconfig # [linux]
files:
- tests/

about:
home: https://vsg-dev.github.io/vsg-dev.io/
summary: Utility library for converting data+materials to/from VulkanSceneGraph
license: MIT
license_file: LICENSE.md
dev_url: /~https://github.com/vsg-dev/vsgXchange

extra:
recipe-maintainers:
- jeongseok-meta
10 changes: 10 additions & 0 deletions recipes/vsgXchange/run_test.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@echo on

cmake tests ^
%CMAKE_ARGS% ^
-B tests/build ^
-DBUILD_SHARED_LIBS=ON
if errorlevel 1 exit 1

cmake --build tests/build --parallel --config Release
if errorlevel 1 exit 1
12 changes: 12 additions & 0 deletions recipes/vsgXchange/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -exo pipefail

cmake tests \
${CMAKE_ARGS} \
-G Ninja \
-B tests/build \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_BUILD_TYPE=Release

cmake --build tests/build --parallel
13 changes: 13 additions & 0 deletions recipes/vsgXchange/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.7)

project(vsghelloworld)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

find_package(vsg CONFIG REQUIRED)
find_package(vsgXchange CONFIG REQUIRED)

add_executable(vsghelloworld main.cpp)
target_link_libraries(vsghelloworld PRIVATE vsg::vsg vsgXchange::vsgXchange)
91 changes: 91 additions & 0 deletions recipes/vsgXchange/tests/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include <vsg/all.h>
#include <vsgXchange/all.h>

#include <iostream>

int main(int argc, char** argv)
{
// set up defaults and read command line arguments to override them
vsg::CommandLine arguments(&argc, argv);

// set up vsg::Options to pass in filepaths, ReaderWriters and other IO related options to use when reading and writing files.
auto options = vsg::Options::create(vsgXchange::all::create());
options->fileCache = vsg::getEnv("VSG_FILE_CACHE");
options->paths = vsg::getEnvPaths("VSG_FILE_PATH");
arguments.read(options);

vsg::Path filename = "models/openstreetmap.vsgt";
if (argc > 1) filename = arguments[1];

if (arguments.errors()) return arguments.writeErrorMessages(std::cerr);

// load the scene graph
vsg::ref_ptr<vsg::Node> vsg_scene = vsg::read_cast<vsg::Node>(filename, options);
if (!vsg_scene) return 0;

// create the viewer and assign window(s) to it
auto windowTraits = vsg::WindowTraits::create();
windowTraits->windowTitle = "Hello World";
auto viewer = vsg::Viewer::create();
auto window = vsg::Window::create(windowTraits);
if (!window)
{
std::cout << "Could not create window." << std::endl;
return 1;
}

viewer->addWindow(window);

// compute the bounds of the scene graph to help position camera
vsg::ComputeBounds computeBounds;
vsg_scene->accept(computeBounds);
vsg::dvec3 centre = (computeBounds.bounds.min + computeBounds.bounds.max) * 0.5;
double radius = vsg::length(computeBounds.bounds.max - computeBounds.bounds.min) * 0.6;
double nearFarRatio = 0.001;

// set up the camera
auto lookAt = vsg::LookAt::create(centre + vsg::dvec3(0.0, -radius * 3.5, 0.0), centre, vsg::dvec3(0.0, 0.0, 1.0));

vsg::ref_ptr<vsg::ProjectionMatrix> perspective;
auto ellipsoidModel = vsg_scene->getRefObject<vsg::EllipsoidModel>("EllipsoidModel");
if (ellipsoidModel)
{
double horizonMountainHeight = 0.0;
perspective = vsg::EllipsoidPerspective::create(lookAt, ellipsoidModel, 30.0, static_cast<double>(window->extent2D().width) / static_cast<double>(window->extent2D().height), nearFarRatio, horizonMountainHeight);
}
else
{
perspective = vsg::Perspective::create(30.0, static_cast<double>(window->extent2D().width) / static_cast<double>(window->extent2D().height), nearFarRatio * radius, radius * 4.5);
}

auto camera = vsg::Camera::create(perspective, lookAt, vsg::ViewportState::create(window->extent2D()));

// add close handler to respond to the close window button and pressing escape
viewer->addEventHandler(vsg::CloseHandler::create(viewer));

// add trackball to control the Camera
viewer->addEventHandler(vsg::Trackball::create(camera, ellipsoidModel));

// add the CommandGraph to render the scene
auto commandGraph = vsg::createCommandGraphForView(window, camera, vsg_scene);
viewer->assignRecordAndSubmitTaskAndPresentation({commandGraph});

// compile all Vulkan objects and transfer image, vertex and primitive data to GPU
viewer->compile();

// rendering main loop
while (viewer->advanceToNextFrame())
{
// pass any events into EventHandlers assigned to the Viewer
viewer->handleEvents();

viewer->update();

viewer->recordAndSubmit();

viewer->present();
}

// clean up done automatically thanks to ref_ptr<>
return 0;
}

0 comments on commit 68c5f2d

Please sign in to comment.