Skip to content

Commit

Permalink
From - LuxCore Render Engine Example #505 (#727)
Browse files Browse the repository at this point in the history
* state of branch

Signed-off-by: Tomas Lorente <[email protected]>
Signed-off-by: William Lew <[email protected]>

* Update README.md

Signed-off-by: William Lew <[email protected]>

* Added render engine example

Signed-off-by: William Lew <[email protected]>

* Render white box

Signed-off-by: William Lew <[email protected]>

* Reverted simple demo

Signed-off-by: William Lew <[email protected]>

* Fixed camera image size

Signed-off-by: William Lew <[email protected]>

* Added lens trace example

Signed-off-by: William Lew <[email protected]>

* Added sample render for luxcore

Signed-off-by: William Lew <[email protected]>

* Added ProRender base plugin files

Signed-off-by: William Lew <[email protected]>

* Added dynamic scene creation with luxcore

Signed-off-by: William Lew <[email protected]>

* Added mesh class

Signed-off-by: William Lew <[email protected]>

* Split classes to separate files

Signed-off-by: William Lew <[email protected]>

* Add mesh to scene with factory

Signed-off-by: William Lew <[email protected]>

* Added plane

Signed-off-by: William Lew <[email protected]>

* Moved RenderSession to Camera

Signed-off-by: William Lew <[email protected]>

* Fixed luxcore initialization

Signed-off-by: William Lew <[email protected]>

* Wait for render to finish

Signed-off-by: William Lew <[email protected]>

* Fixed race condition

Signed-off-by: William Lew <[email protected]>

* Keep render session alive for accumulation

Signed-off-by: William Lew <[email protected]>

* Use CUDA for renders

Signed-off-by: William Lew <[email protected]>

* Added directional light

Signed-off-by: William Lew <[email protected]>

* Fixed camera tracking

Signed-off-by: William Lew <[email protected]>

* Added Duck model

Signed-off-by: William Lew <[email protected]>

* Added normals and UV coordinates to submeshes

Signed-off-by: William Lew <[email protected]>

* Updated format of examples

Signed-off-by: William Lew <[email protected]>

* Fixed header order error

Signed-off-by: William Lew <[email protected]>

* Remodev pro-render example

Signed-off-by: William Lew <[email protected]>

* Fixed versioning

Signed-off-by: William Lew <[email protected]>

* Cleaned code formatting

Signed-off-by: William Lew <[email protected]>

* Use cornell box for example

Signed-off-by: William Lew <[email protected]>

* Added environment variable warnings

Signed-off-by: William Lew <[email protected]>

* Undo edits to simple demo

Signed-off-by: William Lew <[email protected]>

* Removed lights outside of scene

Signed-off-by: William Lew <[email protected]>

* Removed outdated comments

Signed-off-by: William Lew <[email protected]>

* Added render engine output when running demo

Signed-off-by: William Lew <[email protected]>

* Added image maps with each mesh import

Signed-off-by: William Lew <[email protected]>

* Added textures into LuxCore SDL

Signed-off-by: William Lew <[email protected]>

* Fixed loading data from gz::common::image

Signed-off-by: William Lew <[email protected]>

* Added duck to cornell box

Signed-off-by: William Lew <[email protected]>

* PR review comments resolved

Signed-off-by: Sanjuksha Nirgude <[email protected]>

* allow user to configure render engine type

Signed-off-by: Ian Chen <[email protected]>

* PR review comments resolved

Signed-off-by: Sanjuksha Nirgude <[email protected]>

* Added Documentation

Signed-off-by: Sanjuksha Nirgude <[email protected]>

* update doc, style changes

Signed-off-by: Ian Chen <[email protected]>

Signed-off-by: Tomas Lorente <[email protected]>
Signed-off-by: William Lew <[email protected]>
Signed-off-by: Sanjuksha Nirgude <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Sanjuksha Nirgude <[email protected]>
Co-authored-by: Tomas Lorente <[email protected]>
Co-authored-by: William Lew <[email protected]>
Co-authored-by: Sanjuksha Nirgude <[email protected]>
Co-authored-by: Ian Chen <[email protected]>
  • Loading branch information
5 people authored Oct 14, 2022
1 parent 75bb0d0 commit 18e69f0
Show file tree
Hide file tree
Showing 33 changed files with 3,919 additions and 0 deletions.
69 changes: 69 additions & 0 deletions examples/lux_core_engine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

set(IGN_PLUGIN_VER 1)
set(IGN_COMMON_VER 4)

find_package(ignition-rendering6 REQUIRED)
find_package(ignition-plugin1 REQUIRED COMPONENTS all)

if (NOT DEFINED ENV{LUXCORE_SDK_PATH})
message(FATAL_ERROR "Must define LUXCORE_SDK_PATH")
endif ()

include_directories($ENV{LUXCORE_SDK_PATH}/include)
find_library(LUXCORE_LIBRARY luxcore HINTS $ENV{LUXCORE_SDK_PATH}/lib/)

add_library(LuxCoreEngine SHARED
LuxCoreEngineObject.cc
LuxCoreEngineMaterial.cc
LuxCoreEngineRenderTarget.cc
LuxCoreEngineNode.cc
LuxCoreEngineSensor.cc
LuxCoreEngineCamera.cc
LuxCoreEngineGeometry.cc
LuxCoreEngineVisual.cc
LuxCoreEngineMesh.cc
LuxCoreEngineMeshFactory.cc
LuxCoreEngineScene.cc
LuxCoreEngineLight.cc
LuxCoreEngine.cc)

target_link_libraries(LuxCoreEngine
PUBLIC
${ignition-common${IGN_COMMON_VER}_LIBRARIES}
${IGNITION-RENDERING_LIBRARIES}
${LUXCORE_LIBRARY}
PRIVATE
ignition-plugin${IGN_PLUGIN_VER}::register
)

find_package(GLUT REQUIRED)
include_directories(SYSTEM ${GLUT_INCLUDE_DIRS})
link_directories(${GLUT_LIBRARY_DIRS})

find_package(OpenGL REQUIRED)
include_directories(SYSTEM ${OpenGL_INCLUDE_DIRS})
link_directories(${OpenGL_LIBRARY_DIRS})

if (NOT APPLE)
find_package(GLEW REQUIRED)
include_directories(SYSTEM ${GLEW_INCLUDE_DIRS})
link_directories(${GLEW_LIBRARY_DIRS})
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")

add_executable(luxcore_demo Main.cc GlutWindow.cc)

target_link_libraries(luxcore_demo
${GLUT_LIBRARIES}
${OPENGL_LIBRARIES}
${GLEW_LIBRARIES}
${IGNITION-RENDERING_LIBRARIES}
)

add_custom_target(copy_resources
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/media ${CMAKE_CURRENT_BINARY_DIR}/media
)

add_dependencies(luxcore_demo copy_resources)
200 changes: 200 additions & 0 deletions examples/lux_core_engine/GlutWindow.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#if __APPLE__
#include <GLUT/glut.h>
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#else
#include <GL/glew.h>
#include <GL/glut.h>
#include <GL/gl.h>
#endif

#if !defined(__APPLE__) && !defined(_WIN32)
#include <GL/glx.h>
#endif

#include <mutex>

#include <ignition/common/Console.hh>
#include <ignition/rendering/Camera.hh>
#include <ignition/rendering/Image.hh>
#include <ignition/rendering/Scene.hh>

#include "GlutWindow.hh"

#define KEY_ESC 27
#define KEY_TAB 9

//////////////////////////////////////////////////
unsigned int imgw = 0;
unsigned int imgh = 0;

std::vector<ir::CameraPtr> g_cameras;
ir::CameraPtr g_camera;
ir::CameraPtr g_currCamera;
unsigned int g_cameraIndex = 0;
ir::ImagePtr g_image;

bool g_initContext = false;

#if __APPLE__
CGLContextObj g_context;
CGLContextObj g_glutContext;
#elif _WIN32
#else
GLXContext g_context;
Display *g_display;
GLXDrawable g_drawable;
GLXContext g_glutContext;
Display *g_glutDisplay;
GLXDrawable g_glutDrawable;
#endif

double g_offset = M_PI * 0.5;
bool isRotating = true;

//////////////////////////////////////////////////
//! [update camera]
void updateCameras()
{
double angle = g_offset / 2 * M_PI;
double x = sin(angle) * 12.0;
double y = cos(angle) * 12.0;
for (ir::CameraPtr camera : g_cameras) {
camera->SetLocalPosition(x, y, 1.0);
}

g_offset += 0.005;
}
//! [update camera]

//////////////////////////////////////////////////
void displayCB() {
#if __APPLE__
CGLSetCurrentContext(g_context);
#elif _WIN32
#else
if (g_display) {
glXMakeCurrent(g_display, g_drawable, g_context);
}
#endif

g_cameras[g_cameraIndex]->Capture(*g_image);

#if __APPLE__
CGLSetCurrentContext(g_glutContext);
#elif _WIN32
#else
glXMakeCurrent(g_glutDisplay, g_glutDrawable, g_glutContext);
#endif

unsigned char *data = g_image->Data<unsigned char>();

glClearColor(0.5, 0.5, 0.5, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPixelZoom(1, -1);
glRasterPos2f(-1, 1);
glDrawPixels(imgw, imgh, GL_RGB, GL_UNSIGNED_BYTE, data);

glutSwapBuffers();

if (isRotating) {
updateCameras();
}
}

//////////////////////////////////////////////////
void idleCB() { glutPostRedisplay(); }

//////////////////////////////////////////////////
void keyboardCB(unsigned char _key, int, int)
{
if (_key == KEY_ESC || _key == 'q' || _key == 'Q') {
exit(0);
} else if (_key == KEY_TAB) {
isRotating = !isRotating;
}
}

//////////////////////////////////////////////////
void initCamera(ir::CameraPtr _camera)
{
g_camera = _camera;
imgw = g_camera->ImageWidth();
imgh = g_camera->ImageHeight();
ir::Image image = g_camera->CreateImage();
g_image = std::make_shared<ir::Image>(image);
g_camera->Capture(*g_image);
}

//////////////////////////////////////////////////
void initContext()
{
glutInitDisplayMode(GLUT_DOUBLE);
glutInitWindowPosition(0, 0);
glutInitWindowSize(imgw, imgh);
glutCreateWindow("LuxCore Demo");
glutDisplayFunc(displayCB);
glutIdleFunc(idleCB);
glutKeyboardFunc(keyboardCB);
}

//////////////////////////////////////////////////
void printUsage()
{
std::cout << "===============================" << std::endl;
std::cout << " TAB - Pause and bake scene " << std::endl;
std::cout << " ESC - Exit " << std::endl;
std::cout << "===============================" << std::endl;
}

//////////////////////////////////////////////////
void run(std::vector<ir::CameraPtr> _cameras)
{
if (_cameras.empty())
{
ignerr << "No cameras found. Scene will not be rendered" << std::endl;
return;
}

#if __APPLE__
g_context = CGLGetCurrentContext();
#elif _WIN32
#else
g_context = glXGetCurrentContext();
g_display = glXGetCurrentDisplay();
g_drawable = glXGetCurrentDrawable();
#endif

g_cameras = _cameras;
initCamera(_cameras[0]);
initContext();
printUsage();

#if __APPLE__
g_glutContext = CGLGetCurrentContext();
#elif _WIN32
#else
g_glutDisplay = glXGetCurrentDisplay();
g_glutDrawable = glXGetCurrentDrawable();
g_glutContext = glXGetCurrentContext();
#endif

glutMainLoop();
}
29 changes: 29 additions & 0 deletions examples/lux_core_engine/GlutWindow.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef IGNITION_RENDERING_EXAMPLES_SIMPLE_DEMO_GLUTWINDOW_HH_
#define IGNITION_RENDERING_EXAMPLES_SIMPLE_DEMO_GLUTWINDOW_HH_

#include "ignition/rendering/RenderTypes.hh"
#include <vector>

namespace ir = ignition::rendering;

/// \brief Run the demo and render the scene from the cameras
/// \param[in] _cameras Cameras in the scene
void run(std::vector<ir::CameraPtr> _cameras);

#endif
Loading

0 comments on commit 18e69f0

Please sign in to comment.