Skip to content

Commit

Permalink
port render server
Browse files Browse the repository at this point in the history
  • Loading branch information
fbxiang committed Nov 15, 2023
1 parent 0602082 commit ba296c4
Show file tree
Hide file tree
Showing 21 changed files with 2,230 additions and 3 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/build
*/build
/sapien_build
/docker_sapien_build
compile_commands.json
.vscode
.pyc
cmake-build-debug
/cmake-build-debug/
/.ccls-cache/
.ccls-cache/
/.dir-locals.el
/sapien.egg-info/
__pycache__
Expand All @@ -30,3 +31,7 @@ imgui.ini
/docker/cuda-11.4/

apidoc

*.pb.cc
*.pb.h
python/py_package/*.so
7 changes: 7 additions & 0 deletions include/sapien/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ class Scene : public std::enable_shared_from_this<Scene> {
void addSystem(std::shared_ptr<component::System> system);
std::shared_ptr<component::System> getSystem(std::string const &name) const;

template <class T> std::shared_ptr<T> getSystemWithType(std::string const &name) const {
if (auto s = std::dynamic_pointer_cast<T>(getSystem(name))) {
return s;
}
throw std::runtime_error("failed to get system: type mismatch");
}

std::vector<std::shared_ptr<Entity>> getEntities() const { return mEntities; };

// for convenience
Expand Down
1 change: 0 additions & 1 deletion pinocchio/cmake/pybind11.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG smart_holder
# GIT_TAG v2.10.4
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
Expand Down
2 changes: 1 addition & 1 deletion python/py_package/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ __all__ = [

def set_log_level(level: str) -> None:
pass
__version__ = '3.0.0.dev20231112'
__version__ = '3.0.0.dev20231115'
SceneConfig = sapien.pysapien.physx.PhysxSceneConfig
29 changes: 29 additions & 0 deletions render_server/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
project(sapien-render-server LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -g0 -Wall")
set(BUILD_SHARED_LIBS OFF CACHE BOOL "")

add_compile_definitions("$<$<CONFIG:DEBUG>:_DEBUG>")
add_compile_definitions("$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")

set(CMAKE_DEBUG_POSTFIX "")

list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(eigen)
include(grpc)
include(pybind11)

protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/proto proto/render_server.proto)
grpc_generate_cpp(GRPC_SRCS GRPC_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/proto proto/render_server.proto)

find_package(sapien REQUIRED)

file(GLOB_RECURSE RENDER_SERVER_SRC "src/*.cpp")

pybind11_add_module(pysapien_render_server ${RENDER_SERVER_SRC} ${PROTO_SRCS} ${GRPC_SRCS} NO_EXTRAS)
# add_library(sapien_render_server ${RENDER_SERVER_SRC} ${PROTO_SRCS} ${GRPC_SRCS})
target_link_libraries(pysapien_render_server PRIVATE grpc++ sapien::sapien eigen)
target_include_directories(pysapien_render_server PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
21 changes: 21 additions & 0 deletions render_server/cmake/eigen.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
if(TARGET Eigen3::Eigen)
return()
endif()

include(FetchContent)
FetchContent_Declare(
eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG 3.4.0
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
OVERRIDE_FIND_PACKAGE
)

set(EIGEN_BUILD_DOC OFF CACHE BOOL "" FORCE)
set(BUILD_TESTING OFF)
set(EIGEN_BUILD_PKGCONFIG OFF)

FetchContent_MakeAvailable(eigen)

set(Eigen3_DIR ${eigen_BINARY_DIR})
111 changes: 111 additions & 0 deletions render_server/cmake/grpc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
if(TARGET grpc++)
return()
endif()

set(gRPC_ZLIB_PROVIDER "package")
set(gRPC_BUILD_TESTS OFF CACHE BOOL "" FORCE)

set(CMAKE_CXX_STANDARD 14)

include(FetchContent)
FetchContent_Declare(
grpc
GIT_REPOSITORY https://github.com/grpc/grpc
GIT_TAG v1.51.1
)

set(FETCHCONTENT_QUIET OFF)
FetchContent_MakeAvailable(grpc)
set(FETCHCONTENT_QUIET ON)

set(CMAKE_CXX_STANDARD 20)

if (zlib_SOURCE_DIR)
target_include_directories(grpc PRIVATE ${zlib_SOURCE_DIR} ${zlib_BINARY_DIR})
target_include_directories(grpc++ PRIVATE ${zlib_SOURCE_DIR} ${zlib_BINARY_DIR})
endif()


# MIT License

# Copyright (c) 2018 Ivan Safonov

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

function(PROTOBUF_GENERATE_CPP SRCS HDRS DEST)
if(NOT ARGN)
message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files")
return()
endif()

set(${SRCS})
set(${HDRS})
foreach(FIL ${ARGN})
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
get_filename_component(FIL_WE ${FIL} NAME_WE)
get_filename_component(_protobuf_include_path ${ABS_FIL} DIRECTORY)

list(APPEND ${SRCS} "${DEST}/${FIL_WE}.pb.cc")
list(APPEND ${HDRS} "${DEST}/${FIL_WE}.pb.h")

add_custom_command(
OUTPUT "${DEST}/${FIL_WE}.pb.cc"
"${DEST}/${FIL_WE}.pb.h"
COMMAND protobuf::protoc
ARGS --cpp_out ${DEST} -I${_protobuf_include_path} ${ABS_FIL}
DEPENDS ${ABS_FIL} protobuf::protoc
COMMENT "Running C++ protocol buffer compiler on ${FIL}"
VERBATIM )
endforeach()
set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
set(${SRCS} ${${SRCS}} PARENT_SCOPE)
set(${HDRS} ${${HDRS}} PARENT_SCOPE)
endfunction()


function(GRPC_GENERATE_CPP SRCS HDRS DEST)
if(NOT ARGN)
message(SEND_ERROR "Error: GRPC_GENERATE_CPP() called without any proto files")
return()
endif()

set(${SRCS})
set(${HDRS})
foreach(FIL ${ARGN})
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
get_filename_component(FIL_WE ${FIL} NAME_WE)
get_filename_component(_protobuf_include_path ${ABS_FIL} DIRECTORY)

list(APPEND ${SRCS} "${DEST}/${FIL_WE}.grpc.pb.cc")
list(APPEND ${HDRS} "${DEST}/${FIL_WE}.grpc.pb.h")

add_custom_command(
OUTPUT "${DEST}/${FIL_WE}.grpc.pb.cc"
"${DEST}/${FIL_WE}.grpc.pb.h"
COMMAND protobuf::protoc
ARGS --grpc_out ${DEST} -I${_protobuf_include_path} --plugin=protoc-gen-grpc=$<TARGET_FILE:grpc_cpp_plugin> ${ABS_FIL}
DEPENDS ${ABS_FIL} protobuf::protoc grpc_cpp_plugin
COMMENT "Running C++ gRPC compiler on ${FIL}"
VERBATIM )
endforeach()

set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
set(${SRCS} ${${SRCS}} PARENT_SCOPE)
set(${HDRS} ${${HDRS}} PARENT_SCOPE)
endfunction()
14 changes: 14 additions & 0 deletions render_server/cmake/pybind11.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
if(TARGET pybind11)
return()
endif()

include(FetchContent)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG smart_holder
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)

FetchContent_MakeAvailable(pybind11)
Loading

0 comments on commit ba296c4

Please sign in to comment.