-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0330a35
Showing
16 changed files
with
1,112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.venv | ||
.vscode | ||
TVPaint_SDK | ||
CMakeUserPresets.json | ||
|
||
tvpaint-ws-server.exp | ||
tvpaint-ws-server.lib | ||
|
||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
cmake_minimum_required(VERSION 3.25) | ||
project(tvpaint-rpc C CXX) | ||
|
||
# Set C++ standard version requirement | ||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED True) | ||
|
||
# Output build/compile_commands.json for clangd support | ||
option(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
|
||
# Microsoft Visual C++ | ||
if(MSVC) | ||
# Export symbols from a .dll that are not in any of its object files but are added by the linker from dependencies | ||
# See: https://cmake.org/cmake/help/latest/prop_tgt/WINDOWS_EXPORT_ALL_SYMBOLS.html | ||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) | ||
add_definitions(-D_CRT_SECURE_NO_WARNINGS) | ||
|
||
# Define WIN64 or WIN32 for TVPaint SDK | ||
if(CMAKE_SIZEOF_VOID_P EQUAL 8) | ||
message("64bit") | ||
add_definitions(-DWIN64) | ||
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) | ||
message("32bit") | ||
add_definitions(-DWIN32) | ||
endif() | ||
endif() | ||
|
||
# Use static boost libraries | ||
set(Boost_USE_STATIC_LIBS ON) | ||
|
||
# Check TVPaint C++ SDK folder | ||
set(TVPAINT_SDK_FOLDER "" CACHE INTERNAL "TVPaint C++ SDK folder location") | ||
if (TVPAINT_SDK_FOLDER STREQUAL "") | ||
message(FATAL_ERROR "Please provide the TVPaint C++ SDK folder.") | ||
endif() | ||
|
||
# Find dependencies | ||
find_package(nlohmann_json REQUIRED) | ||
find_package(websocketpp REQUIRED) | ||
find_package(spdlog REQUIRED) | ||
|
||
# Include TVPaint SDK | ||
include_directories("${TVPAINT_SDK_FOLDER}/include") | ||
|
||
# Search for source files and configure library | ||
file(GLOB SOURCES "src/*.cpp" "src/*.hpp") | ||
add_library(${PROJECT_NAME} SHARED ${SOURCES} library.def "${TVPAINT_SDK_FOLDER}/lib/dllx.c") | ||
|
||
# Link libraries | ||
target_link_libraries(${PROJECT_NAME} PRIVATE nlohmann_json::nlohmann_json) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE websocketpp::websocketpp) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE spdlog::spdlog) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
MIT License | ||
Copyright (c) 2024 BRUNCH Studio | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
# TVPaint RPC server plugin | ||
|
||
![](https://img.shields.io/github/license/brunchstudio/tvpaint-rpc) | ||
|
||
This TVPaint plugin runs a WebSocket server which listens for [JSON-RPC](https://www.jsonrpc.org/) messages mainly for executing George commands and getting the result. | ||
|
||
It's used as a communication layer for [Pytvpaint](https://github.com/brunchstudio/pytvpaint) which is the Python library that wraps George commands. | ||
|
||
## Setup | ||
|
||
To install the build dependencies, we use [Conan](https://conan.io/) which is a C/C++ package manager. | ||
|
||
To install it, use the virtualenv provided by [Poetry](https://python-poetry.org/): | ||
|
||
```shell | ||
$ poetry install --no-root # Installs Conan | ||
$ poetry shell # Enter a new venv shell | ||
``` | ||
|
||
Then configure your Conan compilation profile: | ||
|
||
```shell | ||
(venv) $ conan profile detect | ||
``` | ||
|
||
To compile the project with MSVC, an example configuration would be: | ||
|
||
```ini | ||
# C:\Users\$USER\.conan2\profiles\default | ||
|
||
[settings] | ||
arch=x86_64 | ||
build_type=Release | ||
compiler=msvc | ||
compiler.cppstd=17 | ||
compiler.runtime=static | ||
compiler.version=193 | ||
os=Windows | ||
``` | ||
|
||
- On MSVC, to check your `compiler.version`, run the command `cl` in a [Developer Command Prompt for VS](https://learn.microsoft.com/en-us/visualstudio/ide/reference/command-prompt-powershell?view=vs-2022) and check the `C/C++ Optimizing Compiler Version` for example `19.35.32215` | ||
|
||
To check if your profile is correct, use: | ||
|
||
```shell | ||
(venv) $ conan profile show | ||
``` | ||
|
||
## Install dependencies | ||
|
||
Install the dependencies specified in [`conanfile.txt`](./conanfile.txt): | ||
|
||
```shell | ||
(venv) $ conan install . --output-folder=build --build=missing | ||
``` | ||
|
||
The above command generates CMake build files that helps finding those libraries. | ||
|
||
## Build | ||
|
||
You first need to download the TVPaint C/C++ SDK in a local folder. | ||
|
||
Configure the project with CMake and Conan by going into the `build` folder: | ||
|
||
```shell | ||
$ cd build | ||
$ cmake .. -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake" -DTVPAINT_SDK_FOLDER="/path/to/TVPaint_SDK" | ||
``` | ||
|
||
(the above command assumes you are using `Visual Studio 17`, if not match that with your Conan profile) | ||
|
||
Build the project in release mode: | ||
|
||
``` | ||
$ cmake --build . --config Release | ||
``` | ||
|
||
## Install | ||
|
||
You can find the generated `.dll` file under `./build/Release/tvpaint-ws-server.dll` after compilation. | ||
|
||
To install it, copy the DLL into your `plugins` folder (depending on your TVPaint version): | ||
|
||
- On Windows: `C:/Program Files/TVPaint Developpement/TVPaint Animation 11.5 Pro (64bits)/plugins` | ||
|
||
## Usage | ||
|
||
The WebSocket server is launched at TVPaint's startup. | ||
|
||
By default it listens on the port `3000` but you can set the `TVP_RPC_WS_PORT` environment variable to set another port. | ||
|
||
The protocol used is [JSON RPC](https://www.jsonrpc.org/specification). It allows us to send a request that contains a method and some params to execute. | ||
|
||
For example: | ||
|
||
``` | ||
--> {"jsonrpc": "2.0", "method": "execute_george", "params": ["tv_version"], "id": 0} | ||
<-- {'id': 0, 'jsonrpc': '2.0', 'result': '"TVP Animation 11 Pro" 11.5.3 fr'} | ||
--> {"jsonrpc": "2.0", "method": "unknown_method", "params": [], "id": 0} | ||
<-- {'error': {'code': -32601, 'message': 'Method not found'}, 'id': 0, 'jsonrpc': '2.0'} | ||
``` | ||
|
||
You can use the `TVP_RPC_LOG_PATH` environment variable to set the log file directory (named `.tvpaint-rpc.log`). By default they are not logged to a file. | ||
|
||
## Limitations | ||
|
||
- This plugin is Windows only, the CMake configuration would need to be tested and updated | ||
- Due to UTF-8 handling when receiving results from TVPaint's George commands, some characters outside of UTF-16 range are not recognized (example: emoji characters in a layer name) | ||
|
||
## Libraries | ||
|
||
- TVPaint SDK (get it from customer support) | ||
- [JSON for Modern C++ (nlohmann/json)](https://json.nlohmann.me/) | ||
- [WebSocket++ (websocketpp)](https://github.com/zaphoyd/websocketpp/) | ||
- [spdlog](https://github.com/gabime/spdlog): Very fast, header-only/compiled, C++ logging library | ||
|
||
## Ressources | ||
|
||
- [Build a simple CMake project](https://docs.conan.io/2/tutorial/consuming_packages/build_simple_cmake_project.html) with Conan. | ||
- Ynput's [OpenPype TVPaint plugin](https://github.com/ynput/OpenPype/tree/develop/openpype/hosts/tvpaint/tvpaint_plugin/plugin_code) was a great inspiration | ||
|
||
## Contributing | ||
|
||
Pull requests are welcome. For major changes, please open an issue first | ||
to discuss what you would like to change. | ||
|
||
Please make sure to update tests as appropriate. | ||
|
||
## License | ||
|
||
[MIT](./LICENSE.md) | ||
|
||
<hr> | ||
|
||
Made with ❤️ at [BRUNCH Studio](https://brunchstudio.tv/) 🥐🍳 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[requires] | ||
nlohmann_json/3.11.2 | ||
websocketpp/0.8.2 | ||
spdlog/1.11.0 | ||
|
||
[generators] | ||
CMakeDeps | ||
CMakeToolchain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
LIBRARY tvpaint-rpc | ||
EXPORTS | ||
PI_Msg | ||
PI_Open | ||
PI_About | ||
PI_Parameters | ||
PI_Start | ||
PI_Work | ||
PI_Finish | ||
PI_Close |
Oops, something went wrong.