Skip to content

Commit

Permalink
Add (Rust) MM Scene Graph proto-type.
Browse files Browse the repository at this point in the history
Issue #114
  • Loading branch information
david-cattermole committed Dec 25, 2021
1 parent ad33a4c commit eaa1dff
Show file tree
Hide file tree
Showing 20 changed files with 1,513 additions and 10 deletions.
4 changes: 4 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ Required:
- [CMinpack 1.3.8](https://github.com/devernay/cminpack/releases/tag/v1.3.8)
- [Python 2.7.x or 3.x](https://www.python.org/) (for build scripts)
- [Sphinx 1.8.3+](http://www.sphinx-doc.org/en/master/index.html) (for building documentation)
- [Rust 1.43+](https://www.rust-lang.org/) for MM Scene Graph features.
- [cxx-bridge](https://cxx.rs/) for Rust/C++ bindings.
- See the 'Cargo.toml' files for a full list of (automatically)
installed dependencies.

Optional Solver:
- [levmar 2.6](http://users.ics.forth.gr/~lourakis/levmar/)
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
# time.
set(BUILD_PLUGIN 1 CACHE BOOL
"Do you want to build the plug-in?")
set(BUILD_MMSCENEGRAPH 1 CACHE BOOL
"Do you want to build with the mmSceneGraph feature?")
set(BUILD_PYTHON 1 CACHE BOOL
"Do you want to build and install the Python API and tools?")
set(BUILD_MEL 1 CACHE BOOL
Expand Down
96 changes: 96 additions & 0 deletions cmake/modules/MMSceneGraphUtils.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Copyright (C) 2020, 2021 David Cattermole.
#
# This file is part of mmSolver.
#
# mmSolver is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# mmSolver is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with mmSolver. If not, see <https://www.gnu.org/licenses/>.
# ---------------------------------------------------------------------
#
# CMake utilities for mmSolver using Rust.
#


# Find the Rust compiled library
function(find_rust_library lib_name build_dir out_linktime_file)
if (MSVC)
set(staticlib_name "${lib_name}.lib")

# Get the Rust Library .lib (for Windows).
message(STATUS "Finding: ${staticlib_name}")
message(STATUS "RUST BUILD DIR: ${build_dir}")
find_path(linktime_dir ${staticlib_name}
HINTS ${build_dir}
PATHS ${build_dir}
)
if(EXISTS ${linktime_dir})
set(${out_linktime_file} ${linktime_dir}/${staticlib_name} PARENT_SCOPE)
endif()

elseif (UNIX)
set(archive_name "lib${lib_name}.a")

# Get the Rust Library .a (for Linux).
message(STATUS "Finding: ${archive_name}")
message(DEBUG "RUST BUILD DIR: ${build_dir}")
find_path(linktime_dir ${archive_name}
HINTS ${build_dir}
PATHS ${build_dir}
)
if(EXISTS ${linktime_dir})
set(${out_linktime_file} ${linktime_dir}/${archive_name} PARENT_SCOPE)
endif()

else ()
message(FATAL_ERROR "Only Linux and Windows are supported.")
endif ()
endfunction()


macro(set_relative_library_rpath target relative_path)
# HACK: We must change the RPATH variable for the library so that a
# binary can find the shared object, even if it's not in the
# $LD_LIBRARY_PATH.
if (UNIX)
# We must escape the '$' symbol to make sure it is passed to the
# compiler.
set_target_properties(${target} PROPERTIES
BUILD_WITH_INSTALL_RPATH ON
INSTALL_RPATH "\$ORIGIN/${relative_path}"
)
endif ()
endmacro()


macro(set_rpath_to_cwd target)
# HACK: We must change the RPATH variable for the library so that a
# binary can find the shared object, even if it's not in the
# $LD_LIBRARY_PATH.
if (UNIX)
# We must escape the '$' symbol to make sure it is passed to the
# compiler.
set_target_properties(${target} PROPERTIES
BUILD_WITH_INSTALL_RPATH ON
INSTALL_RPATH "\$ORIGIN/."
)
endif ()
endmacro()


function(add_target_link_library_names target names)
string(STRIP ${names} names_strip)
string(REPLACE " " ";" names_list ${names_strip})
foreach (name IN LISTS names_list)
target_link_libraries(${target} ${name})
endforeach ()
endfunction()

21 changes: 11 additions & 10 deletions cmake/modules/MMSolverUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,17 @@ function(set_target_as_maya_plugin_library target)
set_target_properties(${target} PROPERTIES SUFFIX ${maya_plugin_suffix})
endfunction()



# Output the target to the Module plug-ins directory.
function(install_target_to_module target module_dir)
# On Windows, the Plug-In is treated as a 'RUNTIME' type,
# on Linux, it's a 'LIBRARY' type.
set_target_properties(${target} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${module_dir}"
LIBRARY_OUTPUT_DIRECTORY "${module_dir}"
ARCHIVE_OUTPUT_DIRECTORY "${module_dir}")
install(TARGETS ${target}
RUNTIME DESTINATION "${module_dir}/lib"
LIBRARY DESTINATION "${module_dir}/lib")
endfunction()


# Install the Plug-In.
function(install_target_plugin_to_module target module_dir)
set_target_as_maya_plugin_library(mmSolver)
set_target_as_maya_plugin_library(${target})

if(CMAKE_SYSTEM_NAME STREQUAL Linux)
# HACK: On Linux, LD_LIBRARY_PATH cannot be modified at runtime (on
Expand All @@ -193,7 +188,13 @@ function(install_target_plugin_to_module target module_dir)
)
endif ()

install_target_to_module(${target} ${module_dir})
# On Windows, the Plug-In is treated as a 'RUNTIME' type,
# on Linux, it's a 'LIBRARY' type.
set_target_properties(${target} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${module_dir}"
LIBRARY_OUTPUT_DIRECTORY "${module_dir}"
ARCHIVE_OUTPUT_DIRECTORY "${module_dir}")

install(TARGETS ${target}
RUNTIME DESTINATION "${MODULE_FULL_NAME}/plug-ins"
LIBRARY DESTINATION "${MODULE_FULL_NAME}/plug-ins")
Expand Down
27 changes: 27 additions & 0 deletions scripts/build_mmSolver_windows64_maya2018.bat
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ SET BUILD_TYPE=Release
:: Build options, to allow faster compilation times. (not to be used by
:: users wanting to build this project.)
SET BUILD_PLUGIN=1
SET BUILD_MMSCENEGRAPH=1
SET BUILD_PYTHON=1
SET BUILD_MEL=1
SET BUILD_3DEQUALIZER=1
Expand Down Expand Up @@ -93,6 +94,12 @@ SET GFLAGS_ROOT="%PROJECT_ROOT%\external\install\libmv"
SET GFLAGS_INCLUDE_DIR="%PROJECT_ROOT%\external\install\libmv\include\third_party\gflags"
SET GFLAGS_LIB_PATH="%PROJECT_ROOT%\external\install\libmv\lib"

:: Where to find the mmSceneGraph Rust libraries and headers.
SET MMSCENEGRAPH_RUST_DIR=%PROJECT_ROOT%\src\mmscenegraph\rust
SET MMSCENEGRAPH_CPP_DIR=%PROJECT_ROOT%\src\mmscenegraph\cppbind
SET MMSCENEGRAPH_RUST_BUILD_DIR="%MMSCENEGRAPH_CPP_DIR%\target\release"
SET MMSCENEGRAPH_INCLUDE_DIR="%MMSCENEGRAPH_CPP_DIR%\include"

:: MinGW is a common install for developers on Windows and
:: if installed and used it will cause build conflicts and
:: errors, so we disable it.
Expand All @@ -101,6 +108,23 @@ IF EXIST "C:\MinGW" (
SET IGNORE_INCLUDE_DIRECTORIES="C:\MinGW\bin;C:\MinGW\include"
)

IF "%BUILD_MMSCENEGRAPH%"=="1" (
ECHO Building mmSceneGraph...

:: Install the needed cxxbridge.exe command to be installed with
:: the exact version we need.
cargo install cxxbridge-cmd --version 1.0.60

ECHO Building C++ Bindings... (%MMSCENEGRAPH_CPP_DIR%)
CHDIR "%MMSCENEGRAPH_CPP_DIR%"
:: Assumes 'cxxbridge' (cxxbridge-cmd) is installed.
ECHO Generating C++ Headers...
cxxbridge --header --output "%MMSCENEGRAPH_CPP_DIR%\include\mmscenegraph\_cxx.h"
cargo build --release

CHDIR "%PROJECT_ROOT%"
)

:: Build project
SET BUILD_DIR_NAME=build_windows64_maya%MAYA_VERSION%_%BUILD_TYPE%
SET BUILD_DIR=%PROJECT_ROOT%\%BUILD_DIR_NAME%
Expand All @@ -119,6 +143,7 @@ cmake -G "NMake Makefiles" ^
-DCMAKE_INSTALL_PREFIX=%INSTALL_MODULE_DIR% ^
-DCMAKE_IGNORE_PATH=%IGNORE_INCLUDE_DIRECTORIES% ^
-DBUILD_PLUGIN=%BUILD_PLUGIN% ^
-DBUILD_MMSCENEGRAPH=%BUILD_MMSCENEGRAPH% ^
-DBUILD_PYTHON=%BUILD_PYTHON% ^
-DBUILD_MEL=%BUILD_MEL% ^
-DBUILD_3DEQUALIZER=%BUILD_3DEQUALIZER% ^
Expand All @@ -139,6 +164,8 @@ cmake -G "NMake Makefiles" ^
-DGLOG_INCLUDE_DIR=%GLOG_INCLUDE_DIR% ^
-DGFLAGS_ROOT=%GFLAGS_ROOT% ^
-DGFLAGS_INCLUDE_DIR=%GFLAGS_INCLUDE_DIR% ^
-DMMSCENEGRAPH_RUST_BUILD_DIR=%MMSCENEGRAPH_RUST_BUILD_DIR% ^
-DMMSCENEGRAPH_INCLUDE_DIR=%MMSCENEGRAPH_INCLUDE_DIR% ^
-DMAYA_LOCATION=%MAYA_LOCATION% ^
-DMAYA_VERSION=%MAYA_VERSION% ^
..
Expand Down
8 changes: 8 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ include(MMSolverUtils)

set_global_maya_plugin_compile_options()

if (BUILD_MMSCENEGRAPH)
add_subdirectory(mmscenegraph)
endif ()

# 'mmSolver' maya plugin library
if (APPLE)
add_library(mmSolver MODULE ${SOURCE_FILES})
Expand All @@ -136,6 +140,10 @@ target_include_directories(mmSolver
PRIVATE ${CERES_INCLUDE_DIRS}
PRIVATE ${LIBMV_INCLUDE_DIRS}
)
target_link_libraries(mmSolver
PRIVATE
mmscenegraph
)
target_link_libraries(mmSolver
PUBLIC
${MAYA_OpenMaya_LIBRARY}
Expand Down
26 changes: 26 additions & 0 deletions src/MMSolverCmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <core/bundleAdjust_defines.h>
#include <core/bundleAdjust_data.h>
#include <mayaUtils.h>
#include <mmscenegraph/mmscenegraph.h>

// STL
#include <cmath>
Expand Down Expand Up @@ -436,6 +437,31 @@ MStatus MMSolverCmd::doIt(const MArgList &args) {
//
MStatus status = MStatus::kSuccess;

mmscenegraph::foo(1);
mmscenegraph::foo(2);
mmscenegraph::foo(3);
mmscenegraph::foo(42);
auto cpp_string_1 = mmscenegraph::foobar(1);
auto cpp_string_2 = mmscenegraph::foobar(2);
auto cpp_string_3 = mmscenegraph::foobar(3);
auto cpp_string_42 = mmscenegraph::foobar(42);
MStreamUtils::stdErrorStream()
<< "mmSolver: Rust result: "
<< cpp_string_1
<< '\n';
MStreamUtils::stdErrorStream()
<< "mmSolver: Rust result: "
<< cpp_string_2
<< '\n';
MStreamUtils::stdErrorStream()
<< "mmSolver: Rust result: "
<< cpp_string_3
<< '\n';
MStreamUtils::stdErrorStream()
<< "mmSolver: Rust result: "
<< cpp_string_42
<< '\n';

// Mouse cursor spinning...
// MGlobal::executeCommand("waitCursor -state on;");

Expand Down
21 changes: 21 additions & 0 deletions src/mmscenegraph/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (C) 2021 David Cattermole.
#
# This file is part of mmSolver.
#
# mmSolver is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# mmSolver is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with mmSolver. If not, see <https://www.gnu.org/licenses/>.
# ---------------------------------------------------------------------
#
#

add_subdirectory(cppbind)
10 changes: 10 additions & 0 deletions src/mmscenegraph/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# MM Scene Graph

MatchMove Scene Graph (MM Scene Graph or 'mmscenegraph') is for representing a 3D Scene
Graph for MatchMove solving.

Solving MatchMove cameras and objects for Visual Effects (VFX) may
require the use of a 3D transform a hierarchy, known as a DAG
(Directed Acyclic Graph). The MM Scene Graph is designed to model the
Scene Graph for MatchMove tasks and provide efficent functions for
evaluation.
4 changes: 4 additions & 0 deletions src/mmscenegraph/cppbind/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/*.rs.bk
Cargo.lock
*~
*target/*
22 changes: 22 additions & 0 deletions src/mmscenegraph/cppbind/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (C) 2020, 2021 David Cattermole.
#
# This file is part of mmSolver.
#
# mmSolver is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# mmSolver is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with mmSolver. If not, see <https://www.gnu.org/licenses/>.
# ---------------------------------------------------------------------
#

set(target_release_lib_name "mmscenegraph")

add_subdirectory(src)
27 changes: 27 additions & 0 deletions src/mmscenegraph/cppbind/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "mmscenegraph_cppbind"
version = "0.1.0"
authors = ["david-cattermole <cattermole91@gmail.com>"]
edition = "2018"
publish = false

[lib]
name = "mmscenegraph"
path = "./src/lib.rs"
# NOTE: 'lib' is used to link with Rust crates, staticlib' is used to
# link with C++.
crate_type = ["staticlib"]

[dependencies]
cxx = "=1.0.60"

[profile.release]
opt-level = 2
debug = false
rpath = false
lto = false
# NOTE: If we use 'panic = "abort"' then we are unable to produce tests.
# # https://github.com/rust-lang/cargo/issues/6313
#
# panic = "abort"
debug-assertions = false
Loading

0 comments on commit eaa1dff

Please sign in to comment.