Compare commits
67 commits
feature/pa
...
master
Author | SHA1 | Date | |
---|---|---|---|
20420e28ef | |||
78d2466efd | |||
3a6fb2ada2 | |||
219ca94ded | |||
bea19b21d7 | |||
3dfc3abaf8 | |||
2f0f507051 | |||
7f36a84938 | |||
ded96d4e1f | |||
0bd6acb7fa | |||
cbeaa4d2bb | |||
f16f3a8b79 | |||
187308be90 | |||
dac8d0f4bd | |||
497cbc51e0 | |||
cba770c4af | |||
089fd02899 | |||
5f57622466 | |||
3e6e1fad5f | |||
d0635e7472 | |||
e777284120 | |||
577ad312b8 | |||
4c0f24066c | |||
7352b53a94 | |||
bb81aff4fd | |||
d922dd3727 | |||
16f973c9c2 | |||
![]() |
5b5006eb90 | ||
e2054a51a8 | |||
93984ce1c0 | |||
6803a659cb | |||
a619fa3afc | |||
43e41caebf | |||
1bd9b00c47 | |||
ae9a4adf67 | |||
7bd3e70c3a | |||
52cfa69a6e | |||
62743d8998 | |||
2fec4cc7f2 | |||
56ffc3f88c | |||
384c249874 | |||
692bb17d44 | |||
2ed8c83ec3 | |||
801b00ad97 | |||
4940b07403 | |||
2f09c6eb9c | |||
3521f50d1b | |||
11df6595c0 | |||
44c28b6825 | |||
92ab9f6fb9 | |||
b117f3cd4d | |||
d086cf629b | |||
143d3769c7 | |||
243af95a3b | |||
3df575314e | |||
8d5fb3b2c6 | |||
471b2472e3 | |||
be324e0aa8 | |||
330f128dd3 | |||
8b8776cbd7 | |||
74a4a01ebf | |||
12fc8906bc | |||
6d95cc8e1a | |||
6e387a72d2 | |||
d79d4e3b4a | |||
4b6fa1d3ff | |||
259c14294c |
119 changed files with 8420 additions and 1308 deletions
1
.clangd
1
.clangd
|
@ -1,2 +1,3 @@
|
|||
CompileFlags:
|
||||
Add: [-std=c++20]
|
||||
Remove: [-mno-direct-extern-access]
|
7
.vscode/launch.json
vendored
7
.vscode/launch.json
vendored
|
@ -4,6 +4,13 @@
|
|||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "gdb",
|
||||
"request": "launch",
|
||||
"name": "Debug (gdb)",
|
||||
"program": "${workspaceFolder}/build/bin/editor",
|
||||
"cwd": "${workspaceFolder}",
|
||||
},
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
|
|
32
BUILD.md
32
BUILD.md
|
@ -1,20 +1,27 @@
|
|||
# Building on Linux
|
||||
|
||||
For pre-requisite packages, check [deps.txt](./deps.txt)
|
||||
You will need to install Qt and LLVM/libclang beforehand. All other packages will automatically be obtained through CPM.
|
||||
|
||||
If your distribution does not provide ReactPhysics3D, you will have to build (and install) it yourself prior to this step
|
||||
ccache is highly recommended.
|
||||
|
||||
Use the following to generate the build files:
|
||||
|
||||
cmake -Bbuild .
|
||||
|
||||
> [!NOTE]
|
||||
> Add -DCMAKE_BUILD_TYPE=Release to produce a release build
|
||||
|
||||
Then build the project using:
|
||||
|
||||
cmake --build build
|
||||
|
||||
The compiled binaries should then be located in `./build/bin/` and should be ready for redistribution without any further work.
|
||||
|
||||
If any of the compilation steps fail, or the binaries fail to execute, please create an issue so that this can be corrected.
|
||||
|
||||
# Building on Windows
|
||||
|
||||
The project will be built using VCPKG and MSVC
|
||||
The process is very similar on Windows
|
||||
|
||||
## Pre-requisites
|
||||
|
||||
|
@ -22,6 +29,7 @@ The project will be built using VCPKG and MSVC
|
|||
* Qt 6.8.3 or higher, with MSVC toolchain
|
||||
* CMake
|
||||
* Git (for cloning the repo, optional)
|
||||
* LLVM/libclang 18.1.8+ (from https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.8/LLVM-18.1.8-win64.exe)
|
||||
* QScintilla already built (see [docs/qscintilla.md](./docs/qscintilla.md)) *\*likely temporary\**
|
||||
|
||||
To start, clone the repository:
|
||||
|
@ -34,18 +42,18 @@ Once in the directory, add Qt to the `CMAKE_PREFIX_PATH` variable (for instance,
|
|||
|
||||
set CMAKE_PREFIX_PATH=C:\Qt\6.8.3\msvc2022_64
|
||||
|
||||
Now, generate the build files with cmake via the vcpkg preset:
|
||||
Now, generate the build files:
|
||||
|
||||
cmake -Bbuild . --preset vcpkg
|
||||
cmake -Bbuild .
|
||||
|
||||
Then, finally, build in release mode\*:
|
||||
Then, finally build:
|
||||
|
||||
cmake --build build --config Release
|
||||
cmake --build build
|
||||
|
||||
The compiled binaries should then be placed in `./build/bin/` and should be ready for redistribution without any further work.
|
||||
> [!NOTE]
|
||||
> To build in release mode, add -DCMAKE_BUILD_TYPE=Release to the configure (first) command,
|
||||
> and add --config Release to the build (second) command
|
||||
|
||||
If any of the compilation steps fail, or the binaries fail to execute, please create an issue so that this can be corrected.
|
||||
The compiled binaries should then be located in `./build/bin/[Debug|Release]` and should be ready for redistribution without any further work.
|
||||
|
||||
\* Release mode is necessary as debug mode copies DLLs that are not linked to the output binary
|
||||
|
||||
DEVELOPER NOTE: AKA Not for you. If you get CUSTOM COMMAND BUILD errors just keep rerunning build
|
||||
If any of the compilation steps fail, or the binaries fail to execute, please create an issue so that this can be corrected.
|
|
@ -10,6 +10,7 @@ else()
|
|||
endif()
|
||||
|
||||
set( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" )
|
||||
set(USE_CCACHE ON)
|
||||
|
||||
add_subdirectory(autogen)
|
||||
|
||||
|
@ -24,4 +25,6 @@ add_subdirectory(client)
|
|||
add_subdirectory(editor)
|
||||
|
||||
|
||||
install(FILES $<TARGET_RUNTIME_DLLS:editor> TYPE BIN)
|
||||
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests )
|
||||
enable_testing()
|
||||
add_subdirectory(tests)
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
{
|
||||
"version": 2,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "vcpkg",
|
||||
"generator": "Visual Studio 17 2022",
|
||||
"binaryDir": "${sourceDir}/build",
|
||||
"cacheVariables": {
|
||||
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "vcpkg-linux",
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/build",
|
||||
"cacheVariables": {
|
||||
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
"version": 2,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "default",
|
||||
"inherits": "vcpkg",
|
||||
"environment": {
|
||||
"VCPKG_ROOT": "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\vcpkg\\vcpkg.exe"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -54,11 +54,14 @@ uniform int numPointLights;
|
|||
uniform DirLight sunLight;
|
||||
uniform Material material;
|
||||
uniform sampler2DArray studs;
|
||||
uniform samplerCube skybox;
|
||||
uniform float transparency;
|
||||
uniform float reflectance;
|
||||
uniform vec3 texScale;
|
||||
|
||||
// Functions
|
||||
|
||||
// Functions
|
||||
vec3 calculateReflection();
|
||||
vec3 calculateDirectionalLight(DirLight light);
|
||||
vec3 calculatePointLight(PointLight light);
|
||||
mat3 lookAlong(vec3 pos, vec3 forward, vec3 up);
|
||||
|
@ -68,6 +71,7 @@ mat3 lookAlong(vec3 pos, vec3 forward, vec3 up);
|
|||
void main() {
|
||||
vec3 result = vec3(0.0);
|
||||
|
||||
result += calculateReflection();
|
||||
result += calculateDirectionalLight(sunLight);
|
||||
|
||||
for (int i = 0; i < numPointLights; i++) {
|
||||
|
@ -95,6 +99,25 @@ mat3 lookAlong(vec3 pos, vec3 forward, vec3 up) {
|
|||
return mat3(s, u, f);
|
||||
}
|
||||
|
||||
|
||||
vec3 sampleSkybox()
|
||||
{
|
||||
vec3 norm = normalize(vNormal);
|
||||
vec3 viewDir = normalize(viewPos - vPos);
|
||||
vec3 reflectDir = reflect(-viewDir, norm);
|
||||
|
||||
return textureLod(skybox,reflectDir, 5.0 * (1.0-material.shininess)).rgb;
|
||||
}
|
||||
|
||||
vec3 calculateReflection() {
|
||||
vec3 norm = normalize(vNormal);
|
||||
vec3 viewDir = normalize(viewPos - vPos);
|
||||
vec3 reflectDir = reflect(viewDir, norm);
|
||||
float fresnel = (pow(1.0-max(dot(viewDir, norm), 0.0), 5.0));
|
||||
vec3 result = sampleSkybox() * mix(/* TEMPORARY: will be replaced by setting */ 0 * /* /TEMPORARY */ fresnel * material.specular, vec3(1.0), reflectance);
|
||||
return result;
|
||||
}
|
||||
|
||||
vec3 calculateDirectionalLight(DirLight light) {
|
||||
// Calculate diffuse
|
||||
vec3 norm = normalize(vNormal);
|
||||
|
@ -105,10 +128,13 @@ vec3 calculateDirectionalLight(DirLight light) {
|
|||
vec3 viewDir = normalize(viewPos - vPos);
|
||||
vec3 reflectDir = reflect(-lightDir, norm);
|
||||
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
|
||||
// float fresnel = (pow(1.0-max(dot(viewDir, norm), 0.0), 5.0));
|
||||
|
||||
vec3 ambient = light.ambient * material.diffuse;
|
||||
vec3 diffuse = light.diffuse * diff * material.diffuse;
|
||||
|
||||
vec3 ambient = light.ambient * (material.diffuse * (1.0-reflectance));
|
||||
vec3 diffuse = light.diffuse * diff * (material.diffuse * (1.0-reflectance));
|
||||
vec3 specular = light.specular * spec * material.specular;
|
||||
// specular += sampleSkybox() * fresnel * material.specular;
|
||||
|
||||
return (ambient + diffuse + specular);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ int processHeader(fs::path srcRoot, fs::path srcPath, fs::path outPath) {
|
|||
std::string srcRootStr = string_of(srcRoot);
|
||||
std::string srcPathStr = string_of(srcPath);
|
||||
std::string outPathStr = string_of(outPath);
|
||||
std::string logFileStr = outPathStr + ".log";
|
||||
|
||||
const char* cargs[] = { "-xc++", "-std=c++17", "-I", srcRootStr.c_str(), "-D__AUTOGEN__", 0 };
|
||||
// THANK YOU SO MUCH THIS STACKOVERFLOW ANSWER IS SO HELPFUL
|
||||
|
@ -42,17 +43,26 @@ int processHeader(fs::path srcRoot, fs::path srcPath, fs::path outPath) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
fs::create_directories(outPath.parent_path()); // Make sure generated dir exists before we try writing to it
|
||||
|
||||
// We write to a special log file instead of stdout/stderr to
|
||||
// 1. avoid confusion
|
||||
// 2. prevent MSBuild from reading the word "error" and detecting there's a problem with the program (there isn't)
|
||||
FILE* logout = fopen(logFileStr.c_str(), "w");
|
||||
|
||||
// Print errors
|
||||
int ndiags = clang_getNumDiagnostics(unit);
|
||||
for (int i = 0; i < ndiags; i++) {
|
||||
CXDiagnostic diag = clang_getDiagnostic(unit, i);
|
||||
CXString str = clang_formatDiagnostic(diag, 0);
|
||||
fprintf(stderr, "diag: %s\n", clang_getCString(str));
|
||||
fprintf(logout, "diag: %s\n", clang_getCString(str));
|
||||
|
||||
clang_disposeString(str);
|
||||
clang_disposeDiagnostic(diag);
|
||||
}
|
||||
|
||||
fclose(logout);
|
||||
|
||||
CXCursor cursor = clang_getTranslationUnitCursor(unit);
|
||||
|
||||
object::AnalysisState objectAnlyState;
|
||||
|
@ -66,8 +76,6 @@ int processHeader(fs::path srcRoot, fs::path srcPath, fs::path outPath) {
|
|||
data::analyzeClasses(cursor, srcRootStr, &dataAnlyState);
|
||||
enum_::analyzeClasses(cursor, srcRootStr, &enumAnlyState);
|
||||
|
||||
fs::create_directories(outPath.parent_path()); // Make sure generated dir exists before we try writing to it
|
||||
|
||||
printf("[AUTOGEN] Generating file %s...\n", relpathStr.c_str());
|
||||
std::ofstream outStream(outPathStr);
|
||||
|
||||
|
@ -104,5 +112,7 @@ int main(int argc, char** argv) {
|
|||
fs::path srcPath = argv[2];
|
||||
fs::path outPath = argv[3];
|
||||
|
||||
// fprintf(stderr, "Some error here\n");
|
||||
// return 0;
|
||||
return processHeader(srcRoot, srcPath, outPath);
|
||||
}
|
|
@ -1,8 +1,24 @@
|
|||
find_package(SDL2 REQUIRED)
|
||||
include_directories(${SDL2_INCLUDE_DIRS})
|
||||
|
||||
find_package(glfw3 REQUIRED)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/deps.cmake)
|
||||
|
||||
add_executable(client "src/main.cpp")
|
||||
target_link_libraries(client PRIVATE ${SDL2_LIBRARIES} openblocks glfw)
|
||||
add_dependencies(client openblocks)
|
||||
target_link_libraries(client PRIVATE openblocks glfw)
|
||||
add_dependencies(client openblocks)
|
||||
|
||||
if(WIN32)
|
||||
# Copy assets
|
||||
add_custom_command(
|
||||
TARGET client POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_SOURCE_DIR}/assets
|
||||
$<TARGET_FILE_DIR:client>/assets)
|
||||
endif()
|
||||
|
||||
set_target_properties(client PROPERTIES
|
||||
WIN32_EXECUTABLE ON
|
||||
)
|
||||
|
||||
# https://stackoverflow.com/a/73899349/16255372
|
||||
if (WIN32)
|
||||
# /ENTRY:mainCRTStartup keeps the same "main" function instead of requiring "WinMain"
|
||||
target_link_options(client PRIVATE "/ENTRY:mainCRTStartup")
|
||||
endif()
|
12
client/deps.cmake
Normal file
12
client/deps.cmake
Normal file
|
@ -0,0 +1,12 @@
|
|||
# Declare/fetch packages
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
glfw3
|
||||
GIT_REPOSITORY https://github.com/glfw/glfw
|
||||
GIT_TAG 3.4
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(glfw3)
|
||||
|
||||
# Find/include packages
|
|
@ -1,8 +1,12 @@
|
|||
#include <GL/glew.h>
|
||||
#include <glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include "logger.h"
|
||||
#include "objects/part/part.h"
|
||||
#include "panic.h"
|
||||
#include "physics/world.h"
|
||||
#include "rendering/renderer.h"
|
||||
#include "common.h"
|
||||
#include "version.h"
|
||||
|
||||
void errorCatcher(int id, const char* str);
|
||||
|
||||
|
@ -22,20 +26,29 @@ int main() {
|
|||
|
||||
glfwSetErrorCallback(errorCatcher);
|
||||
|
||||
std::string title = std::string() + "Openblocks Client " + BUILD_VERSION;
|
||||
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_SAMPLES, 4);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); // Valid only in OpenGL 3.2+, see: https://stackoverflow.com/a/70519392/16255372
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
GLFWwindow *window = glfwCreateWindow(1200, 900, "OpenBlocks Client ALPHA", NULL, NULL);
|
||||
GLFWwindow *window = glfwCreateWindow(1200, 900, title.c_str(), NULL, NULL);
|
||||
glfwSetKeyCallback(window, keyCallback);
|
||||
glfwSetMouseButtonCallback(window, mouseButtonCallback);
|
||||
glfwSetCursorPosCallback(window, mouseCallback);
|
||||
glfwSetFramebufferSizeCallback(window, resizeCallback);
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
glewInit();
|
||||
int version = gladLoadGL(glfwGetProcAddress);
|
||||
if (version == 0) {
|
||||
Logger::fatalError("Failed to initialize OpenGL context");
|
||||
panic();
|
||||
} else {
|
||||
Logger::debugf("Initialized GL context version %d.%d", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
|
||||
}
|
||||
|
||||
physicsInit();
|
||||
gDataModel->Init();
|
||||
renderInit(1200, 900);
|
||||
|
||||
|
@ -75,12 +88,13 @@ int main() {
|
|||
glfwPollEvents();
|
||||
} while(!glfwWindowShouldClose(window));
|
||||
|
||||
physicsDeinit();
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void errorCatcher(int id, const char* str) {
|
||||
Logger::fatalErrorf("GLFW Error: [{}] {}", id, str);
|
||||
Logger::fatalErrorf("GLFW Error: [%d] %s", id, str);
|
||||
}
|
||||
|
||||
float lastTime;
|
||||
|
|
23
cmake/CPM.cmake
Normal file
23
cmake/CPM.cmake
Normal file
|
@ -0,0 +1,23 @@
|
|||
set(CPM_DOWNLOAD_VERSION 0.42.0)
|
||||
# Patch support is broken in CPM upstream atm, so we have to use a fork
|
||||
set(CPM_HASH_SUM "f7d92592a257d184fd8de6fb496a711ce393676ed68999b96043aab2e5e6f9e6")
|
||||
# set(CPM_HASH_SUM "2020b4fc42dba44817983e06342e682ecfc3d2f484a581f11cc5731fbe4dce8a")
|
||||
|
||||
if(CPM_SOURCE_CACHE)
|
||||
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
|
||||
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
|
||||
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
|
||||
else()
|
||||
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
|
||||
endif()
|
||||
|
||||
# Expand relative path. This is important if the provided path contains a tilde (~)
|
||||
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
|
||||
|
||||
file(DOWNLOAD
|
||||
https://raw.githubusercontent.com/BohdanBuinich/CPM.cmake/refs/heads/feat/fix_patch_command/cmake/CPM.cmake
|
||||
# https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
|
||||
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
|
||||
)
|
||||
|
||||
include(${CPM_DOWNLOAD_LOCATION})
|
60
cmake/FindQScintilla6.cmake
Normal file
60
cmake/FindQScintilla6.cmake
Normal file
|
@ -0,0 +1,60 @@
|
|||
# Modified from QGIS' FindQScintilla.cmake by Thomas Moenicke, Larry Schaffer
|
||||
|
||||
add_library(QScintilla::QScintilla UNKNOWN IMPORTED)
|
||||
|
||||
### NECESSARY TO PREVENT staticMetaObject ERROR!!! See qscintilla.prf AKA qmake config
|
||||
if(WIN32)
|
||||
add_compile_definitions(QSCINTILLA_DLL)
|
||||
endif()
|
||||
|
||||
FIND_PATH(QSCINTILLA_INCLUDE_DIR
|
||||
NAMES Qsci/qsciglobal.h
|
||||
PATHS
|
||||
${Qt6Core_INCLUDE_DIRS}
|
||||
$ENV{LIB_DIR}/include
|
||||
/usr/local/include
|
||||
/usr/include
|
||||
${VCPKG_INSTALLED_DIR}/x64-windows/include
|
||||
PATH_SUFFIXES ${QSCINTILLA_PATH_SUFFIXES}
|
||||
)
|
||||
|
||||
set(QSCINTILLA_LIBRARY_NAMES
|
||||
qscintilla2-qt6
|
||||
qscintilla2_qt6
|
||||
libqt6scintilla2
|
||||
libqscintilla2-qt6
|
||||
qt6scintilla2
|
||||
libqscintilla2-qt6.dylib
|
||||
qscintilla2
|
||||
)
|
||||
|
||||
|
||||
find_library(QSCINTILLA_LIBRARY
|
||||
NAMES ${QSCINTILLA_LIBRARY_NAMES}
|
||||
PATHS
|
||||
"${QT_LIBRARY_DIR}"
|
||||
$ENV{LIB_DIR}/lib
|
||||
/usr/local/lib
|
||||
/usr/local/lib/qt6
|
||||
/usr/lib
|
||||
/usr/lib64
|
||||
/usr/lib32
|
||||
${VCPKG_INSTALLED_DIR}/x64-windows/lib
|
||||
)
|
||||
|
||||
get_filename_component(QSCINTILLA_LIB_DIR ${QSCINTILLA_LIBRARY} DIRECTORY)
|
||||
list(TRANSFORM QSCINTILLA_LIBRARY_NAMES APPEND ".dll" OUTPUT_VARIABLE QSCINTILLA_DLL_NAMES)
|
||||
|
||||
find_file(QSCINTILLA_DLLS
|
||||
NAMES ${QSCINTILLA_DLL_NAMES}
|
||||
PATHS
|
||||
"${QT_LIBRARY_DIR}"
|
||||
$ENV{LIB_DIR}/lib
|
||||
/usr/local/lib
|
||||
/usr/local/lib/qt6
|
||||
/usr/lib64
|
||||
/usr/lib32
|
||||
/usr/lib
|
||||
${QSCINTILLA_LIB_DIR}
|
||||
${VCPKG_INSTALLED_DIR}/x64-windows/lib
|
||||
)
|
|
@ -1,30 +0,0 @@
|
|||
# Distributed under the OSI-approved BSD 3-Clause License.
|
||||
# Copyright Stefano Sinigardi
|
||||
|
||||
#.rst:
|
||||
# FindStb
|
||||
# ------------
|
||||
#
|
||||
# Find the Stb include headers.
|
||||
#
|
||||
# Result Variables
|
||||
# ^^^^^^^^^^^^^^^^
|
||||
#
|
||||
# This module defines the following variables:
|
||||
#
|
||||
# ``Stb_FOUND``
|
||||
# True if Stb library found
|
||||
#
|
||||
# ``Stb_INCLUDE_DIR``
|
||||
# Location of Stb headers
|
||||
#
|
||||
|
||||
include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
|
||||
include(${CMAKE_ROOT}/Modules/SelectLibraryConfigurations.cmake)
|
||||
|
||||
if(NOT Stb_INCLUDE_DIR)
|
||||
find_path(Stb_INCLUDE_DIR NAMES stb_image.h PATHS ${Stb_DIR} PATH_SUFFIXES include stb include/stb)
|
||||
endif()
|
||||
|
||||
find_package_handle_standard_args(Stb DEFAULT_MSG Stb_INCLUDE_DIR)
|
||||
mark_as_advanced(Stb_INCLUDE_DIR)
|
40
cmake/gitversion.cmake
Normal file
40
cmake/gitversion.cmake
Normal file
|
@ -0,0 +1,40 @@
|
|||
|
||||
# https://jonathanhamberg.com/post/cmake-embedding-git-hash/
|
||||
|
||||
# Detect current version from git
|
||||
execute_process(
|
||||
COMMAND git rev-parse HEAD
|
||||
OUTPUT_VARIABLE GIT_COMMIT_HASH RESULT_VARIABLE GIT_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
|
||||
|
||||
execute_process(
|
||||
COMMAND git describe --abbrev=0
|
||||
OUTPUT_VARIABLE GIT_VERSION RESULT_VARIABLE GIT_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
|
||||
|
||||
execute_process(
|
||||
COMMAND git describe --dirty
|
||||
OUTPUT_VARIABLE GIT_VERSION_LONG RESULT_VARIABLE GIT_RESULT OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
|
||||
|
||||
# For some reason, CMake sets CMAKE_*_DIR all to be CMAKE_CURRENT_BINARY_DIR
|
||||
# so we have to bypass this by passing in custom "orig_" variables
|
||||
if (NOT GIT_STATE_WITHIN)
|
||||
# Re-run this target always so that the version can be checked
|
||||
add_custom_target(recheck_git_version ALL COMMAND ${CMAKE_COMMAND}
|
||||
-DGIT_STATE_WITHIN=1
|
||||
-DORIG_BINARY_DIR=${CMAKE_BINARY_DIR}
|
||||
-DORIG_CURRENT_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}
|
||||
-DORIG_SOURCE_DIR=${CMAKE_SOURCE_DIR}
|
||||
-DORIG_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}
|
||||
-P ${CMAKE_MODULE_PATH}/gitversion.cmake
|
||||
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/src/version.cpp
|
||||
)
|
||||
else ()
|
||||
# # Set defaults if the git commands fail
|
||||
if (NOT GIT_RESULT EQUAL 0)
|
||||
set(GIT_COMMIT_HASH "unknown")
|
||||
set(GIT_VERSION "unknown")
|
||||
set(GIT_VERSION_LONG "unknown")
|
||||
endif ()
|
||||
|
||||
# configure_file only touches the file if it has been changed, so no caching is necessary
|
||||
configure_file(${ORIG_CURRENT_SOURCE_DIR}/src/version.cpp.in ${ORIG_CURRENT_BINARY_DIR}/src/version.cpp @ONLY)
|
||||
endif ()
|
|
@ -1,29 +1,177 @@
|
|||
find_package(OpenGL REQUIRED COMPONENTS OpenGL)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/deps.cmake)
|
||||
|
||||
find_package(GLEW REQUIRED)
|
||||
include_directories(${GLEW_INCLUDE_DIRS})
|
||||
## Sources
|
||||
set(SOURCES
|
||||
src/stb.cpp
|
||||
src/glad.cpp
|
||||
|
||||
find_package(OpenGL)
|
||||
find_package(glm CONFIG REQUIRED)
|
||||
find_package(ReactPhysics3D REQUIRED)
|
||||
find_package(pugixml 1.15 REQUIRED)
|
||||
find_package(Freetype)
|
||||
src/ptr_helpers.h
|
||||
src/enum/part.h
|
||||
src/enum/surface.cpp
|
||||
src/enum/meta.h
|
||||
src/enum/annotation.h
|
||||
src/enum/surface.h
|
||||
src/camera.cpp
|
||||
src/datatypes/vector.cpp
|
||||
src/datatypes/variant.h
|
||||
src/datatypes/cframe.cpp
|
||||
src/datatypes/signal.cpp
|
||||
src/datatypes/base.h
|
||||
src/datatypes/enum.h
|
||||
src/datatypes/enum.cpp
|
||||
src/datatypes/primitives.h
|
||||
src/datatypes/cframe.h
|
||||
src/datatypes/variant.cpp
|
||||
src/datatypes/vector.h
|
||||
src/datatypes/color3.h
|
||||
src/datatypes/annotation.h
|
||||
src/datatypes/color3.cpp
|
||||
src/datatypes/primitives.cpp
|
||||
src/datatypes/ref.cpp
|
||||
src/datatypes/ref.h
|
||||
src/datatypes/signal.h
|
||||
src/common.cpp
|
||||
src/utils.h
|
||||
src/platform.h
|
||||
src/math_helper.cpp
|
||||
src/rendering/skybox.cpp
|
||||
src/rendering/mesh2d.cpp
|
||||
src/rendering/torus.cpp
|
||||
src/rendering/mesh.h
|
||||
src/rendering/font.cpp
|
||||
src/rendering/debug/debugrenderer.cpp
|
||||
src/rendering/texture.h
|
||||
src/rendering/shader.h
|
||||
src/rendering/defaultmeshes.cpp
|
||||
src/rendering/skybox.h
|
||||
src/rendering/mesh2d.h
|
||||
src/rendering/light.h
|
||||
src/rendering/renderer.cpp
|
||||
src/rendering/texture3d.h
|
||||
src/rendering/texture.cpp
|
||||
src/rendering/renderer.h
|
||||
src/rendering/shader.cpp
|
||||
src/rendering/mesh.cpp
|
||||
src/rendering/material.h
|
||||
src/rendering/torus.h
|
||||
src/rendering/font.h
|
||||
src/rendering/defaultmeshes.h
|
||||
src/rendering/texture3d.cpp
|
||||
src/physics/world.h
|
||||
src/physics/world.cpp
|
||||
src/logger.cpp
|
||||
src/handles.h
|
||||
src/timeutil.h
|
||||
src/error/error.h
|
||||
src/error/result.h
|
||||
src/error/instance.h
|
||||
src/error/data.h
|
||||
src/partassembly.h
|
||||
src/objects/service/jointsservice.cpp
|
||||
src/objects/service/script/serverscriptservice.h
|
||||
src/objects/service/script/serverscriptservice.cpp
|
||||
src/objects/service/script/scriptcontext.h
|
||||
src/objects/service/script/scriptcontext.cpp
|
||||
src/objects/service/workspace.cpp
|
||||
src/objects/service/selection.cpp
|
||||
src/objects/service/selection.h
|
||||
src/objects/service/jointsservice.h
|
||||
src/objects/service/workspace.h
|
||||
src/objects/datamodel.cpp
|
||||
src/objects/script.h
|
||||
src/objects/joint/snap.h
|
||||
src/objects/joint/jointinstance.h
|
||||
src/objects/joint/rotatev.h
|
||||
src/objects/joint/weld.cpp
|
||||
src/objects/joint/jointinstance.cpp
|
||||
src/objects/joint/rotate.cpp
|
||||
src/objects/joint/rotate.h
|
||||
src/objects/joint/weld.h
|
||||
src/objects/joint/snap.cpp
|
||||
src/objects/joint/rotatev.cpp
|
||||
src/objects/base/service.h
|
||||
src/objects/base/member.h
|
||||
src/objects/base/instance.h
|
||||
src/objects/base/service.cpp
|
||||
src/objects/base/instance.cpp
|
||||
src/objects/base/refstate.h
|
||||
src/objects/message.h
|
||||
src/objects/pvinstance.cpp
|
||||
src/objects/hint.cpp
|
||||
src/objects/pvinstance.h
|
||||
src/objects/base.h
|
||||
src/objects/folder.cpp
|
||||
src/objects/model.cpp
|
||||
src/objects/datamodel.h
|
||||
src/objects/folder.h
|
||||
src/objects/meta.cpp
|
||||
src/objects/model.h
|
||||
src/objects/part/part.cpp
|
||||
src/objects/part/part.h
|
||||
src/objects/part/wedgepart.h
|
||||
src/objects/part/basepart.cpp
|
||||
src/objects/part/wedgepart.cpp
|
||||
src/objects/part/basepart.h
|
||||
src/objects/meta.h
|
||||
src/objects/hint.h
|
||||
src/objects/annotation.h
|
||||
src/objects/message.cpp
|
||||
src/objects/script.cpp
|
||||
src/partassembly.cpp
|
||||
src/panic.cpp
|
||||
src/logger.h
|
||||
src/camera.h
|
||||
src/handles.cpp
|
||||
src/version.h
|
||||
src/common.h
|
||||
src/platform.cpp
|
||||
src/panic.h
|
||||
src/lua/instancelib.cpp
|
||||
src/timeutil.cpp
|
||||
src/luaapis.h
|
||||
src/math_helper.h
|
||||
)
|
||||
|
||||
find_package(Stb REQUIRED)
|
||||
include_directories(${Stb_INCLUDE_DIR})
|
||||
set(AUTOGEN_SOURCES
|
||||
# Objects
|
||||
src/objects/service/script/serverscriptservice.h
|
||||
src/objects/service/script/scriptcontext.h
|
||||
src/objects/service/selection.h
|
||||
src/objects/service/jointsservice.h
|
||||
src/objects/service/workspace.h
|
||||
src/objects/script.h
|
||||
src/objects/joint/snap.h
|
||||
src/objects/joint/jointinstance.h
|
||||
src/objects/joint/rotatev.h
|
||||
src/objects/joint/rotate.h
|
||||
src/objects/joint/weld.h
|
||||
src/objects/message.h
|
||||
src/objects/pvinstance.h
|
||||
src/objects/base.h
|
||||
src/objects/datamodel.h
|
||||
src/objects/folder.h
|
||||
src/objects/model.h
|
||||
src/objects/part/part.h
|
||||
src/objects/part/wedgepart.h
|
||||
src/objects/part/basepart.h
|
||||
src/objects/meta.h
|
||||
src/objects/hint.h
|
||||
# Enum
|
||||
src/enum/part.h
|
||||
src/enum/surface.h
|
||||
# Data types
|
||||
src/datatypes/enum.h
|
||||
src/datatypes/cframe.h
|
||||
src/datatypes/vector.h
|
||||
src/datatypes/color3.h
|
||||
)
|
||||
|
||||
# PkgConfig packages
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(LUAJIT REQUIRED luajit)
|
||||
link_directories(${LUAJIT_LIBRARY_DIRS})
|
||||
|
||||
# Run autogen
|
||||
file(GLOB_RECURSE AUTOGEN_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/src" "src/objects/*.h" "src/datatypes/*.h" "src/enum/*.h")
|
||||
### Autogen
|
||||
|
||||
# https://cmake.org/cmake/help/book/mastering-cmake/chapter/Custom%20Commands.html
|
||||
foreach (SRC ${AUTOGEN_SOURCES})
|
||||
string(REGEX REPLACE "[.]h$" ".cpp" OUT_SRC_NAME ${SRC})
|
||||
set(SRC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/${SRC}")
|
||||
set(SRC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${SRC}")
|
||||
set(OUT_PATH "${CMAKE_BINARY_DIR}/generated/${OUT_SRC_NAME}")
|
||||
|
||||
add_custom_command(
|
||||
|
@ -36,17 +184,22 @@ foreach (SRC ${AUTOGEN_SOURCES})
|
|||
list(APPEND AUTOGEN_OUTS "${OUT_PATH}")
|
||||
endforeach()
|
||||
|
||||
### /Autogen
|
||||
|
||||
# Add version info into the build
|
||||
include(gitversion)
|
||||
|
||||
add_custom_target(autogen_build ALL
|
||||
DEPENDS ${AUTOGEN_OUTS}
|
||||
)
|
||||
|
||||
file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.h")
|
||||
list(APPEND SOURCES ${AUTOGEN_OUTS})
|
||||
list(APPEND SOURCES ${CMAKE_CURRENT_BINARY_DIR}/src/version.cpp)
|
||||
add_library(openblocks STATIC ${SOURCES})
|
||||
set_target_properties(openblocks PROPERTIES OUTPUT_NAME "openblocks")
|
||||
target_link_directories(openblocks PUBLIC ${LUAJIT_LIBRARY_DIRS})
|
||||
target_link_libraries(openblocks ${GLEW_LIBRARIES} ${LUAJIT_LIBRARIES} OpenGL::GL ReactPhysics3D::ReactPhysics3D pugixml::pugixml Freetype::Freetype)
|
||||
target_include_directories(openblocks PUBLIC "src" "../include" ${LUAJIT_INCLUDE_DIRS})
|
||||
target_link_libraries(openblocks Jolt pugixml::pugixml Freetype::Freetype glm::glm libluajit ${LuaJIT_LIBRARIES})
|
||||
target_include_directories(openblocks PUBLIC "src" "../include" "${CMAKE_SOURCE_DIR}/external/glad" ${LUAJIT_INCLUDE_DIRS} ${stb_SOURCE_DIR})
|
||||
add_dependencies(openblocks autogen_build autogen)
|
||||
|
||||
# Windows-specific dependencies
|
||||
|
|
30
core/deps.cmake
Normal file
30
core/deps.cmake
Normal file
|
@ -0,0 +1,30 @@
|
|||
|
||||
include(CPM)
|
||||
|
||||
# Some packages will build helper binaries. This keeps them out of our own build output
|
||||
set (PREV_BIN_PATH ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
unset (CMAKE_RUNTIME_OUTPUT_DIRECTORY)
|
||||
|
||||
CPMAddPackage("gh:g-truc/glm#1.0.1")
|
||||
CPMAddPackage(NAME Jolt GIT_REPOSITORY "https://github.com/jrouwe/JoltPhysics" VERSION 5.3.0 SOURCE_SUBDIR "Build")
|
||||
CPMAddPackage("gh:zeux/pugixml@1.15")
|
||||
|
||||
CPMAddPackage(
|
||||
NAME freetype
|
||||
GIT_REPOSITORY https://github.com/aseprite/freetype2.git
|
||||
GIT_TAG VER-2-10-0
|
||||
VERSION 2.10.0
|
||||
PATCHES ${CMAKE_SOURCE_DIR}/patches/freetype_cmakever.patch
|
||||
)
|
||||
|
||||
if (freetype_ADDED)
|
||||
add_library(Freetype::Freetype ALIAS freetype)
|
||||
endif()
|
||||
|
||||
CPMAddPackage("gh:nothings/stb#8cfb1605c02aee9fb6eb5d8ea559017745bd9a16") # 2.14
|
||||
CPMAddPackage("gh:WohlSoft/LuaJIT#a5da8f4a31972b74254f00969111b8b7a07cf584") # v2.1
|
||||
set(LUAJIT_INCLUDE_DIRS ${LuaJIT_SOURCE_DIR}/src)
|
||||
|
||||
CPMAddPackage("gh:mackron/miniaudio#0.11.22")
|
||||
|
||||
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PREV_BIN_PATH})
|
|
@ -8,9 +8,8 @@
|
|||
#include <memory>
|
||||
|
||||
class Instance;
|
||||
// typedef std::function<void(std::shared_ptr<Instance> element, std::optional<std::shared_ptr<Instance>> newParent)> HierarchyUpdateHandler;
|
||||
typedef std::function<void(std::shared_ptr<Instance> object, std::optional<std::shared_ptr<Instance>> oldParent, std::optional<std::shared_ptr<Instance>> newParent)> HierarchyPreUpdateHandler;
|
||||
typedef std::function<void(std::shared_ptr<Instance> object, std::optional<std::shared_ptr<Instance>> oldParent, std::optional<std::shared_ptr<Instance>> newParent)> HierarchyPostUpdateHandler;
|
||||
typedef std::function<void(std::shared_ptr<Instance> object, nullable std::shared_ptr<Instance> oldParent, nullable std::shared_ptr<Instance> newParent)> HierarchyPreUpdateHandler;
|
||||
typedef std::function<void(std::shared_ptr<Instance> object, nullable std::shared_ptr<Instance> oldParent, nullable std::shared_ptr<Instance> newParent)> HierarchyPostUpdateHandler;
|
||||
typedef std::function<void(std::shared_ptr<Instance> instance, std::string property, Variant newValue)> PropertyUpdateHandler;
|
||||
|
||||
// TEMPORARY COMMON DATA FOR VARIOUS INTERNAL COMPONENTS
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
#include "cframe.h"
|
||||
#include "datatypes/vector.h"
|
||||
#include "error/data.h"
|
||||
#include "physics/util.h"
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/gtc/matrix_inverse.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/matrix.hpp>
|
||||
#include <reactphysics3d/mathematics/Transform.h>
|
||||
#include "datatypes/variant.h"
|
||||
#include <pugixml.hpp>
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
|
@ -40,9 +38,6 @@ CFrame::CFrame(Vector3 position, glm::quat quat)
|
|||
, rotation(quat) {
|
||||
}
|
||||
|
||||
CFrame::CFrame(const rp::Transform& transform) : CFrame::CFrame(rpToGlm(transform.getPosition()), rpToGlm(transform.getOrientation())) {
|
||||
}
|
||||
|
||||
glm::mat3 lookAt(Vector3 position, Vector3 lookAt, Vector3 up) {
|
||||
// https://github.com/sgorsten/linalg/issues/29#issuecomment-743989030
|
||||
Vector3 f = (lookAt - position).Unit(); // Forward/Look
|
||||
|
@ -77,10 +72,6 @@ CFrame::operator glm::mat4() const {
|
|||
return glm::translate(glm::mat4(1.0f), this->translation) * glm::mat4(this->rotation);
|
||||
}
|
||||
|
||||
CFrame::operator rp::Transform() const {
|
||||
return rp::Transform(glmToRp(translation), glmToRp(rotation));
|
||||
}
|
||||
|
||||
Vector3 CFrame::ToEulerAnglesXYZ() {
|
||||
float x;
|
||||
float y;
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
#include <glm/gtc/matrix_access.hpp>
|
||||
#include <glm/matrix.hpp>
|
||||
|
||||
namespace reactphysics3d { class Transform; };
|
||||
|
||||
class DEF_DATA_(name="CoordinateFrame") CFrame {
|
||||
AUTOGEN_PREAMBLE_DATA
|
||||
|
||||
|
@ -24,7 +22,6 @@ public:
|
|||
DEF_DATA_CTOR CFrame();
|
||||
DEF_DATA_CTOR CFrame(float x, float y, float z, float R00, float R01, float R02, float R10, float R11, float R12, float R20, float R21, float R22);
|
||||
DEF_DATA_CTOR CFrame(Vector3 , Vector3 lookAt, Vector3 up = Vector3(0, 1, 0));
|
||||
CFrame(const reactphysics3d::Transform&);
|
||||
CFrame(Vector3 position, glm::quat quat);
|
||||
virtual ~CFrame();
|
||||
|
||||
|
@ -46,11 +43,11 @@ public:
|
|||
static void PushLuaLibrary(lua_State*);
|
||||
|
||||
operator glm::mat4() const;
|
||||
operator reactphysics3d::Transform() const;
|
||||
|
||||
//inline static CFrame identity() { }
|
||||
DEF_DATA_PROP inline Vector3 Position() const { return translation; }
|
||||
DEF_DATA_PROP inline CFrame Rotation() const { return CFrame { glm::vec3(0, 0, 0), rotation }; }
|
||||
inline glm::mat3 RotMatrix() const { return rotation; }
|
||||
DEF_DATA_METHOD CFrame Inverse() const;
|
||||
DEF_DATA_PROP inline float X() const { return translation.x; }
|
||||
DEF_DATA_PROP inline float Y() const { return translation.y; }
|
||||
|
|
|
@ -68,7 +68,7 @@ void Bool_PushLuaValue(Variant self, lua_State* L) {
|
|||
result<Variant, LuaCastError> Bool_FromLuaValue(lua_State* L, int idx) {
|
||||
if (!lua_isboolean(L, idx))
|
||||
return LuaCastError(lua_typename(L, idx), "boolean");
|
||||
return Variant(lua_toboolean(L, idx));
|
||||
return Variant((bool)lua_toboolean(L, idx));
|
||||
}
|
||||
|
||||
const TypeDesc BOOL_TYPE {
|
||||
|
|
|
@ -151,9 +151,9 @@ static int inst_index(lua_State* L) {
|
|||
}
|
||||
|
||||
// Look for child
|
||||
std::optional<std::shared_ptr<Instance>> child = inst->FindFirstChild(key);
|
||||
nullable std::shared_ptr<Instance> child = inst->FindFirstChild(key);
|
||||
if (child) {
|
||||
InstanceRef(child.value()).PushLuaValue(L);
|
||||
InstanceRef(child).PushLuaValue(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ static int inst_newindex(lua_State* L) {
|
|||
if (meta->flags & PROP_READONLY)
|
||||
return luaL_error(L, "'%s' of %s is read-only", key.c_str(), inst->GetClass()->className.c_str());
|
||||
if (key == "Parent" && inst->IsParentLocked())
|
||||
return luaL_error(L, "Cannot set property Parent (%s) of %s, parent is locked", inst->GetParent() ? inst->GetParent().value()->name.c_str() : "NULL", inst->GetClass()->className.c_str());
|
||||
return luaL_error(L, "Cannot set property Parent (%s) of %s, parent is locked", inst->GetParent() ? inst->GetParent()->name.c_str() : "NULL", inst->GetClass()->className.c_str());
|
||||
|
||||
// TODO: Make this work for enums, this is not a solution!!
|
||||
result<Variant, LuaCastError> value = meta->type.descriptor->fromLuaValue(L, -1);
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include <cstdlib>
|
||||
#include <glm/ext/quaternion_geometric.hpp>
|
||||
#include <iomanip>
|
||||
#include <reactphysics3d/mathematics/Vector3.h>
|
||||
#include <string>
|
||||
#include <pugixml.hpp>
|
||||
#include "datatypes/base.h"
|
||||
|
@ -11,11 +10,8 @@
|
|||
#include "error/data.h"
|
||||
#include <sstream>
|
||||
|
||||
namespace rp = reactphysics3d;
|
||||
|
||||
Vector3::Vector3() : vector(glm::vec3(0, 0, 0)) {};
|
||||
Vector3::Vector3(const glm::vec3& src) : vector(src) {};
|
||||
Vector3::Vector3(const rp::Vector3& src) : vector(glm::vec3(src.x, src.y, src.z)) {};
|
||||
Vector3::Vector3(float x, const float y, float z) : vector(glm::vec3(x, y, z)) {};
|
||||
|
||||
Vector3::~Vector3() = default;
|
||||
|
@ -31,7 +27,6 @@ const std::string Vector3::ToString() const {
|
|||
}
|
||||
|
||||
Vector3::operator glm::vec3() const { return vector; };
|
||||
Vector3::operator rp::Vector3() const { return rp::Vector3(X(), Y(), Z()); };
|
||||
|
||||
// Operators
|
||||
|
||||
|
|
|
@ -5,9 +5,6 @@
|
|||
#include "error/data.h"
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <glm/geometric.hpp>
|
||||
#include <reactphysics3d/mathematics/Vector3.h>
|
||||
|
||||
// namespace reactphysics3d { class Vector3; };
|
||||
|
||||
class DEF_DATA Vector3 {
|
||||
AUTOGEN_PREAMBLE_DATA
|
||||
|
@ -18,7 +15,6 @@ public:
|
|||
DEF_DATA_CTOR Vector3(float x, float y, float z);
|
||||
inline Vector3(float value) : Vector3(value, value, value) {}
|
||||
Vector3(const glm::vec3&);
|
||||
Vector3(const reactphysics3d::Vector3&);
|
||||
virtual ~Vector3();
|
||||
|
||||
DEF_DATA_PROP static Vector3 ZERO;
|
||||
|
@ -33,7 +29,6 @@ public:
|
|||
static void PushLuaLibrary(lua_State*);
|
||||
|
||||
operator glm::vec3() const;
|
||||
operator reactphysics3d::Vector3() const;
|
||||
|
||||
DEF_DATA_PROP inline float X() const { return vector.x; }
|
||||
DEF_DATA_PROP inline float Y() const { return vector.y; }
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
enum class DEF_ENUM PartType {
|
||||
Ball = 0,
|
||||
Block = 1,
|
||||
Cylinder = 2,
|
||||
};
|
||||
|
||||
namespace EnumType {
|
||||
|
|
2
core/src/glad.cpp
Normal file
2
core/src/glad.cpp
Normal file
|
@ -0,0 +1,2 @@
|
|||
#define GLAD_GL_IMPLEMENTATION
|
||||
#include <glad/gl.h>
|
|
@ -8,10 +8,6 @@
|
|||
#include <glm/ext/scalar_common.hpp>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <reactphysics3d/collision/RaycastInfo.h>
|
||||
#include <reactphysics3d/engine/PhysicsCommon.h>
|
||||
#include <reactphysics3d/engine/PhysicsWorld.h>
|
||||
#include <reactphysics3d/mathematics/Transform.h>
|
||||
|
||||
HandleFace HandleFace::XPos(0, glm::vec3(1,0,0));
|
||||
HandleFace HandleFace::XNeg(1, glm::vec3(-1,0,0));
|
||||
|
@ -23,10 +19,6 @@ std::array<HandleFace, 6> HandleFace::Faces { HandleFace::XPos, HandleFace::XNeg
|
|||
|
||||
static CFrame XYZToZXY(glm::vec3(0, 0, 0), -glm::vec3(1, 0, 0), glm::vec3(0, 0, 1));
|
||||
|
||||
// Shitty solution
|
||||
static rp3d::PhysicsCommon common;
|
||||
static rp3d::PhysicsWorld* world = common.createPhysicsWorld();
|
||||
|
||||
std::shared_ptr<BasePart> getHandleAdornee() {
|
||||
std::shared_ptr<Selection> selection = gDataModel->GetService<Selection>();
|
||||
for (std::weak_ptr<Instance> inst : selection->Get()) {
|
||||
|
@ -52,24 +44,25 @@ CFrame partCFrameFromHandlePos(HandleFace face, Vector3 newPos) {
|
|||
return adornee->cframe.Rotation() + newPartPos;
|
||||
}
|
||||
|
||||
std::optional<HandleFace> raycastHandle(rp3d::Ray ray) {
|
||||
std::optional<HandleFace> raycastHandle(Vector3 rayStart, Vector3 rayEnd) {
|
||||
std::optional<HandleFace> closestFace = {};
|
||||
float closestDistance = -1;
|
||||
|
||||
for (HandleFace face : HandleFace::Faces) {
|
||||
CFrame cframe = getHandleCFrame(face);
|
||||
// Implement manual detection via boxes instead of... this shit
|
||||
// This code also hardly works, and is not good at all... Hooo nope.
|
||||
rp3d::RigidBody* body = world->createRigidBody(CFrame::IDENTITY + cframe.Position());
|
||||
body->addCollider(common.createBoxShape(cframe.Rotation() * Vector3(handleSize(face) / 2.f)), rp3d::Transform::identity());
|
||||
|
||||
rp3d::RaycastInfo info;
|
||||
if (body->raycast(ray, info)) {
|
||||
world->destroyRigidBody(body);
|
||||
return face;
|
||||
}
|
||||
Vector3 halfSize = (cframe.Rotation() * Vector3(handleSize(face) / 2.f)).Abs();
|
||||
Vector3 minB = cframe.Position() - halfSize, maxB = cframe.Position() + halfSize;
|
||||
|
||||
world->destroyRigidBody(body);
|
||||
glm::vec3 hitPoint;
|
||||
bool hit = HitBoundingBox(minB, maxB, rayStart, (rayEnd - rayStart).Unit(), hitPoint);
|
||||
float distance = ((Vector3)hitPoint - rayStart).Magnitude();
|
||||
|
||||
if (hit && (closestDistance == -1 || distance < closestDistance))
|
||||
closestFace = face, closestDistance = distance;
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
return closestFace;
|
||||
}
|
||||
|
||||
Vector3 handleSize(HandleFace face) {
|
||||
|
|
|
@ -40,7 +40,7 @@ std::shared_ptr<BasePart> getHandleAdornee();
|
|||
CFrame getHandleCFrame(HandleFace face);
|
||||
CFrame partCFrameFromHandlePos(HandleFace face, Vector3 newPos);
|
||||
Vector3 handleSize(HandleFace face);
|
||||
std::optional<HandleFace> raycastHandle(rp3d::Ray ray);
|
||||
std::optional<HandleFace> raycastHandle(Vector3 rayStart, Vector3 rayEnd);
|
||||
|
||||
// Gets the cframe of the handle local to the center of the selected objects
|
||||
CFrame getLocalHandleCFrame(HandleFace face);
|
||||
|
|
|
@ -10,18 +10,26 @@
|
|||
static std::ofstream logStream;
|
||||
static std::vector<Logger::LogListener> logListeners;
|
||||
std::string Logger::currentLogDir = "NULL";
|
||||
static std::stringstream* rawOutputBuffer = nullptr;
|
||||
|
||||
void Logger::init() {
|
||||
initProgramLogsDir();
|
||||
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
const auto nows = std::chrono::floor<std::chrono::seconds>(now);
|
||||
|
||||
std::string fileName = std::format("log_{0:%Y%m%d}_{0:%H%M%S}.txt", now);
|
||||
std::string fileName = std::format("log_{0:%Y%m%d}_{0:%H%M%S}.txt", nows);
|
||||
|
||||
logStream = std::ofstream(currentLogDir = (getProgramLogsDir() + "/" + fileName));
|
||||
Logger::debug("Logger initialized");
|
||||
}
|
||||
|
||||
// Initializes the logger in a "void" mode for testing.
|
||||
// It is not necessary to call Logger::finish
|
||||
void Logger::initTest(std::stringstream* outputBuffer) {
|
||||
rawOutputBuffer = outputBuffer;
|
||||
}
|
||||
|
||||
void Logger::finish() {
|
||||
Logger::debug("Closing logger...");
|
||||
logStream.close();
|
||||
|
@ -41,6 +49,7 @@ void Logger::log(std::string message, Logger::LogLevel logLevel, ScriptSource so
|
|||
|
||||
logStream << formattedLogLine << std::endl;
|
||||
printf("%s\n", formattedLogLine.c_str());
|
||||
if (rawOutputBuffer != nullptr) *rawOutputBuffer << logLevelStr << ": " << message << "\n";
|
||||
|
||||
for (Logger::LogListener listener : logListeners) {
|
||||
listener(logLevel, message, source);
|
||||
|
@ -53,4 +62,8 @@ void Logger::log(std::string message, Logger::LogLevel logLevel, ScriptSource so
|
|||
|
||||
void Logger::addLogListener(Logger::LogListener listener) {
|
||||
logListeners.push_back(listener);
|
||||
}
|
||||
|
||||
void Logger::resetLogListeners() {
|
||||
logListeners.clear();
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
class Script;
|
||||
|
@ -26,8 +27,10 @@ namespace Logger {
|
|||
extern std::string currentLogDir;
|
||||
|
||||
void init();
|
||||
void initTest(std::stringstream* out); // Testing only!
|
||||
void finish();
|
||||
void addLogListener(LogListener);
|
||||
void resetLogListeners(); // Testing only!
|
||||
|
||||
void log(std::string message, LogLevel logLevel, ScriptSource source = {});
|
||||
inline void info(std::string message) { log(message, LogLevel::INFO); }
|
||||
|
|
|
@ -6,6 +6,8 @@ extern "C" {
|
|||
#include <lua.h>
|
||||
}
|
||||
|
||||
LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);
|
||||
|
||||
inline const char* x_luaL_udatatname (lua_State *L, int ud) {
|
||||
void *p = lua_touserdata(L, ud);
|
||||
if (p != NULL) {
|
||||
|
@ -16,4 +18,6 @@ inline const char* x_luaL_udatatname (lua_State *L, int ud) {
|
|||
return str;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#define LUA_OK 0
|
|
@ -2,9 +2,65 @@
|
|||
|
||||
#define CMP_EPSILON 0.00001
|
||||
|
||||
|
||||
void expandAABB(glm::vec3& min, glm::vec3& max, glm::vec3 point) {
|
||||
min = glm::vec3(glm::min(min.x, point.x), glm::min(min.y, point.y), glm::min(min.z, point.z));
|
||||
max = glm::vec3(glm::max(max.x, point.x), glm::max(max.y, point.y), glm::max(max.z, point.z));
|
||||
}
|
||||
|
||||
void computeAABBFromPoints(glm::vec3& min, glm::vec3& max, glm::vec3* points, int count) {
|
||||
if (count == 0) return;
|
||||
|
||||
min = points[0];
|
||||
max = points[0];
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
min = glm::vec3(glm::min(min.x, points[i].x), glm::min(min.y, points[i].y), glm::min(min.z, points[i].z));
|
||||
max = glm::vec3(glm::max(max.x, points[i].x), glm::max(max.y, points[i].y), glm::max(max.z, points[i].z));
|
||||
}
|
||||
}
|
||||
|
||||
void getAABBCoords(glm::vec3 &pos, glm::vec3 &size, glm::vec3 min, glm::vec3 max) {
|
||||
pos = (max + min) / 2.f;
|
||||
size = (max - min);
|
||||
}
|
||||
|
||||
|
||||
// ==================== THIRD-PARTY SOURCE CODE ==================== //
|
||||
|
||||
// After a long time researching, I was able to use and adapt Godot's implementation of movable handles (godot/editor/plugins/gizmos/gizmo_3d_helper.cpp)
|
||||
// All thanks goes to them and David Eberly for his algorithm.
|
||||
|
||||
/**************************************************************************/
|
||||
/* geometry_3d.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* 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. */
|
||||
/**************************************************************************/
|
||||
|
||||
void get_closest_points_between_segments(const glm::vec3 &p_p0, const glm::vec3 &p_p1, const glm::vec3 &p_q0, const glm::vec3 &p_q1, glm::vec3 &r_ps, glm::vec3 &r_qt) {
|
||||
// Based on David Eberly's Computation of Distance Between Line Segments algorithm.
|
||||
|
||||
|
@ -102,24 +158,83 @@ void get_closest_points_between_segments(const glm::vec3 &p_p0, const glm::vec3
|
|||
r_qt = (1 - t) * p_q0 + t * p_q1;
|
||||
}
|
||||
|
||||
void expandAABB(glm::vec3& min, glm::vec3& max, glm::vec3 point) {
|
||||
min = glm::vec3(glm::min(min.x, point.x), glm::min(min.y, point.y), glm::min(min.z, point.z));
|
||||
max = glm::vec3(glm::max(max.x, point.x), glm::max(max.y, point.y), glm::max(max.z, point.z));
|
||||
}
|
||||
// https://github.com/erich666/GraphicsGems/tree/master?tab=License-1-ov-file#readme
|
||||
// Note: The code below predates open source
|
||||
|
||||
void computeAABBFromPoints(glm::vec3& min, glm::vec3& max, glm::vec3* points, int count) {
|
||||
if (count == 0) return;
|
||||
/*
|
||||
* EULA: The Graphics Gems code is copyright-protected. In other words, you cannot claim the text of the code as your own
|
||||
* and resell it. Using the code is permitted in any program, product, or library, non-commercial or commercial. Giving
|
||||
* credit is not required, though is a nice gesture. The code comes as-is, and if there are any flaws or problems with
|
||||
* any Gems code, nobody involved with Gems - authors, editors, publishers, or webmasters - are to be held responsible.
|
||||
* Basically, don't be a jerk, and remember that anything free comes with no guarantee.
|
||||
*/
|
||||
|
||||
min = points[0];
|
||||
max = points[0];
|
||||
/*
|
||||
Fast Ray-Box Intersection
|
||||
by Andrew Woo
|
||||
from "Graphics Gems", Academic Press, 1990
|
||||
*/
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
min = glm::vec3(glm::min(min.x, points[i].x), glm::min(min.y, points[i].y), glm::min(min.z, points[i].z));
|
||||
max = glm::vec3(glm::max(max.x, points[i].x), glm::max(max.y, points[i].y), glm::max(max.z, points[i].z));
|
||||
#define RIGHT 0
|
||||
#define LEFT 1
|
||||
#define MIDDLE 2
|
||||
|
||||
bool HitBoundingBox(
|
||||
glm::vec3 minB, glm::vec3 maxB, /*box */
|
||||
glm::vec3 origin, glm::vec3 dir, /*ray */
|
||||
glm::vec3 &coord /* hit point */
|
||||
) {
|
||||
bool inside = true;
|
||||
glm::vec3 quadrant;
|
||||
int i;
|
||||
int whichPlane;
|
||||
glm::vec3 maxT;
|
||||
glm::vec3 candidatePlane;
|
||||
|
||||
/* Find candidate planes; this loop can be avoided if
|
||||
rays cast all from the eye(assume perpsective view) */
|
||||
for (i = 0; i < 3; i++)
|
||||
if(origin[i] < minB[i]) {
|
||||
quadrant[i] = LEFT;
|
||||
candidatePlane[i] = minB[i];
|
||||
inside = false;
|
||||
}else if (origin[i] > maxB[i]) {
|
||||
quadrant[i] = RIGHT;
|
||||
candidatePlane[i] = maxB[i];
|
||||
inside = false;
|
||||
}else {
|
||||
quadrant[i] = MIDDLE;
|
||||
}
|
||||
|
||||
/* Ray origin inside bounding box */
|
||||
if (inside) {
|
||||
coord = origin;
|
||||
return (true);
|
||||
}
|
||||
}
|
||||
|
||||
void getAABBCoords(glm::vec3 &pos, glm::vec3 &size, glm::vec3 min, glm::vec3 max) {
|
||||
pos = (max + min) / 2.f;
|
||||
size = (max - min);
|
||||
|
||||
/* Calculate T distances to candidate planes */
|
||||
for (i = 0; i < 3; i++)
|
||||
if (quadrant[i] != MIDDLE && dir[i] !=0.)
|
||||
maxT[i] = (candidatePlane[i]-origin[i]) / dir[i];
|
||||
else
|
||||
maxT[i] = -1.;
|
||||
|
||||
/* Get largest of the maxT's for final choice of intersection */
|
||||
whichPlane = 0;
|
||||
for (i = 1; i < 3; i++)
|
||||
if (maxT[whichPlane] < maxT[i])
|
||||
whichPlane = i;
|
||||
|
||||
/* Check final candidate actually inside box */
|
||||
if (maxT[whichPlane] < 0.) return (false);
|
||||
for (i = 0; i < 3; i++)
|
||||
if (whichPlane != i) {
|
||||
coord[i] = origin[i] + maxT[whichPlane] * dir[i];
|
||||
if (coord[i] < minB[i] || coord[i] > maxB[i])
|
||||
return (false);
|
||||
} else {
|
||||
coord[i] = candidatePlane[i];
|
||||
}
|
||||
return true; /* ray hits box */
|
||||
}
|
|
@ -1,9 +1,20 @@
|
|||
#pragma once
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
void expandAABB(glm::vec3& min, glm::vec3& max, glm::vec3 point);
|
||||
void computeAABBFromPoints(glm::vec3& min, glm::vec3& max, glm::vec3* points, int count);
|
||||
void getAABBCoords(glm::vec3& pos, glm::vec3& size, glm::vec3 min, glm::vec3 max);
|
||||
|
||||
// From godot/editor/plugins/gizmos/gizmo_3d_helper.h
|
||||
void get_closest_points_between_segments(const glm::vec3 &p_p0, const glm::vec3 &p_p1, const glm::vec3 &p_q0, const glm::vec3 &p_q1, glm::vec3 &r_ps, glm::vec3 &r_qt);
|
||||
|
||||
void expandAABB(glm::vec3& min, glm::vec3& max, glm::vec3 point);
|
||||
void computeAABBFromPoints(glm::vec3& min, glm::vec3& max, glm::vec3* points, int count);
|
||||
void getAABBCoords(glm::vec3& pos, glm::vec3& size, glm::vec3 min, glm::vec3 max);
|
||||
/*
|
||||
Fast Ray-Box Intersection
|
||||
by Andrew Woo
|
||||
from "Graphics Gems", Academic Press, 1990
|
||||
*/
|
||||
bool HitBoundingBox(
|
||||
glm::vec3 minB, glm::vec3 maxB, /*box */
|
||||
glm::vec3 origin, glm::vec3 dir, /*ray */
|
||||
glm::vec3 &coord /* hit point */
|
||||
);
|
|
@ -44,21 +44,16 @@ Instance::Instance(const InstanceType* type) {
|
|||
Instance::~Instance () {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::weak_ptr<T> optional_to_weak(std::optional<std::shared_ptr<T>> a) {
|
||||
return a ? a.value() : std::weak_ptr<T>();
|
||||
}
|
||||
|
||||
// TODO: Test this
|
||||
bool Instance::ancestryContinuityCheck(std::optional<std::shared_ptr<Instance>> newParent) {
|
||||
for (std::optional<std::shared_ptr<Instance>> currentParent = newParent; currentParent.has_value(); currentParent = currentParent.value()->GetParent()) {
|
||||
if (currentParent.value() == this->shared_from_this())
|
||||
bool Instance::ancestryContinuityCheck(nullable std::shared_ptr<Instance> newParent) {
|
||||
for (std::shared_ptr<Instance> currentParent = newParent; currentParent != nullptr; currentParent = currentParent->GetParent()) {
|
||||
if (currentParent == this->shared_from_this())
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Instance::SetParent(std::optional<std::shared_ptr<Instance>> newParent) {
|
||||
bool Instance::SetParent(nullable std::shared_ptr<Instance> newParent) {
|
||||
if (this->parentLocked || !ancestryContinuityCheck(newParent))
|
||||
return false;
|
||||
|
||||
|
@ -70,10 +65,10 @@ bool Instance::SetParent(std::optional<std::shared_ptr<Instance>> newParent) {
|
|||
oldParent->children.erase(std::find(oldParent->children.begin(), oldParent->children.end(), this->shared_from_this()));
|
||||
}
|
||||
// Add ourselves to the new parent
|
||||
if (newParent.has_value()) {
|
||||
newParent.value()->children.push_back(this->shared_from_this());
|
||||
if (newParent != nullptr) {
|
||||
newParent->children.push_back(this->shared_from_this());
|
||||
}
|
||||
this->parent = optional_to_weak(newParent);
|
||||
this->parent = newParent;
|
||||
// TODO: Add code for sending signals for parent updates
|
||||
// TODO: Yeahhh maybe this isn't the best way of doing this?
|
||||
if (hierarchyPostUpdateHandler.has_value()) hierarchyPostUpdateHandler.value()(this->shared_from_this(), lastParent, newParent);
|
||||
|
@ -85,21 +80,21 @@ bool Instance::SetParent(std::optional<std::shared_ptr<Instance>> newParent) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void Instance::updateAncestry(std::optional<std::shared_ptr<Instance>> updatedChild, std::optional<std::shared_ptr<Instance>> newParent) {
|
||||
void Instance::updateAncestry(nullable std::shared_ptr<Instance> updatedChild, nullable std::shared_ptr<Instance> newParent) {
|
||||
auto oldDataModel = _dataModel;
|
||||
auto oldWorkspace = _workspace;
|
||||
|
||||
// Update parent data model and workspace, if applicable
|
||||
if (GetParent()) {
|
||||
this->_dataModel = GetParent().value()->GetClass() == &DataModel::TYPE ? std::dynamic_pointer_cast<DataModel>(GetParent().value()) : GetParent().value()->_dataModel;
|
||||
this->_workspace = GetParent().value()->GetClass() == &Workspace::TYPE ? std::dynamic_pointer_cast<Workspace>(GetParent().value()) : GetParent().value()->_workspace;
|
||||
if (GetParent() != nullptr) {
|
||||
this->_dataModel = GetParent()->GetClass() == &DataModel::TYPE ? std::dynamic_pointer_cast<DataModel>(GetParent()) : GetParent()->_dataModel;
|
||||
this->_workspace = GetParent()->GetClass() == &Workspace::TYPE ? std::dynamic_pointer_cast<Workspace>(GetParent()) : GetParent()->_workspace;
|
||||
} else {
|
||||
this->_dataModel = {};
|
||||
this->_workspace = {};
|
||||
}
|
||||
|
||||
OnAncestryChanged(updatedChild, newParent);
|
||||
AncestryChanged->Fire({updatedChild.has_value() ? InstanceRef(updatedChild.value()) : InstanceRef(), newParent.has_value() ? InstanceRef(newParent.value()) : InstanceRef()});
|
||||
AncestryChanged->Fire({updatedChild != nullptr ? InstanceRef(updatedChild) : InstanceRef(), newParent != nullptr ? InstanceRef(newParent) : InstanceRef()});
|
||||
|
||||
// Old workspace used to exist, and workspaces differ
|
||||
if (!oldWorkspace.expired() && oldWorkspace != _workspace) {
|
||||
|
@ -108,7 +103,7 @@ void Instance::updateAncestry(std::optional<std::shared_ptr<Instance>> updatedCh
|
|||
|
||||
// New workspace exists, and workspaces differ
|
||||
if (!_workspace.expired() && (_workspace != oldWorkspace)) {
|
||||
OnWorkspaceAdded(!oldWorkspace.expired() ? std::make_optional(oldWorkspace.lock()) : std::nullopt, _workspace.lock());
|
||||
OnWorkspaceAdded(oldWorkspace.expired() ? nullptr : oldWorkspace.lock(), _workspace.lock());
|
||||
}
|
||||
|
||||
// Update ancestry in descendants
|
||||
|
@ -117,23 +112,22 @@ void Instance::updateAncestry(std::optional<std::shared_ptr<Instance>> updatedCh
|
|||
}
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<DataModel>> Instance::dataModel() {
|
||||
return (_dataModel.expired()) ? std::nullopt : std::make_optional(_dataModel.lock());
|
||||
nullable std::shared_ptr<DataModel> Instance::dataModel() {
|
||||
return _dataModel.expired() ? nullptr : _dataModel.lock();
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<Workspace>> Instance::workspace() {
|
||||
return (_workspace.expired()) ? std::nullopt : std::make_optional(_workspace.lock());
|
||||
nullable std::shared_ptr<Workspace> Instance::workspace() {
|
||||
return _workspace.expired() ? nullptr : _workspace.lock();
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<Instance>> Instance::GetParent() {
|
||||
if (parent.expired()) return std::nullopt;
|
||||
return parent.lock();
|
||||
nullable std::shared_ptr<Instance> Instance::GetParent() {
|
||||
return parent.expired() ? nullptr : parent.lock();
|
||||
}
|
||||
|
||||
void Instance::Destroy() {
|
||||
if (parentLocked) return;
|
||||
// TODO: Implement proper distruction stuff
|
||||
SetParent(std::nullopt);
|
||||
SetParent(nullptr);
|
||||
parentLocked = true;
|
||||
}
|
||||
|
||||
|
@ -143,12 +137,12 @@ bool Instance::IsA(std::string className) {
|
|||
return cur != nullptr;
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<Instance>> Instance::FindFirstChild(std::string name) {
|
||||
nullable std::shared_ptr<Instance> Instance::FindFirstChild(std::string name) {
|
||||
for (auto child : children) {
|
||||
if (child->name == name)
|
||||
return child;
|
||||
}
|
||||
return std::nullopt;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static std::shared_ptr<Instance> DUMMY_INSTANCE;
|
||||
|
@ -164,15 +158,15 @@ bool Instance::IsParentLocked() {
|
|||
return this->parentLocked;
|
||||
}
|
||||
|
||||
void Instance::OnParentUpdated(std::optional<std::shared_ptr<Instance>> oldParent, std::optional<std::shared_ptr<Instance>> newParent) {
|
||||
void Instance::OnParentUpdated(nullable std::shared_ptr<Instance> oldParent, nullable std::shared_ptr<Instance> newParent) {
|
||||
// Empty stub
|
||||
}
|
||||
|
||||
void Instance::OnAncestryChanged(std::optional<std::shared_ptr<Instance>> child, std::optional<std::shared_ptr<Instance>> newParent) {
|
||||
void Instance::OnAncestryChanged(nullable std::shared_ptr<Instance> child, nullable std::shared_ptr<Instance> newParent) {
|
||||
// Empty stub
|
||||
}
|
||||
|
||||
void Instance::OnWorkspaceAdded(std::optional<std::shared_ptr<Workspace>> oldWorkspace, std::shared_ptr<Workspace> newWorkspace) {
|
||||
void Instance::OnWorkspaceAdded(nullable std::shared_ptr<Workspace> oldWorkspace, std::shared_ptr<Workspace> newWorkspace) {
|
||||
// Empty stub
|
||||
}
|
||||
|
||||
|
@ -230,7 +224,7 @@ fallible<MemberNotFound, AssignToReadOnlyMember> Instance::InternalSetPropertyVa
|
|||
this->name = (std::string)value.get<std::string>();
|
||||
} else if (name == "Parent") {
|
||||
std::weak_ptr<Instance> ref = value.get<InstanceRef>();
|
||||
SetParent(ref.expired() ? std::nullopt : std::make_optional(ref.lock()));
|
||||
SetParent(ref.expired() ? nullptr : ref.lock());
|
||||
} else if (name == "ClassName") {
|
||||
return AssignToReadOnlyMember(GetClass()->className, name);
|
||||
} else {
|
||||
|
@ -430,9 +424,9 @@ DescendantsIterator::self_type DescendantsIterator::operator++(int _) {
|
|||
}
|
||||
|
||||
// If we've hit the end of this item's children, move one up
|
||||
while (current->GetParent() && current->GetParent().value()->GetChildren().size() <= size_t(siblingIndex.back() + 1)) {
|
||||
while (current->GetParent() != nullptr && current->GetParent()->GetChildren().size() <= size_t(siblingIndex.back() + 1)) {
|
||||
siblingIndex.pop_back();
|
||||
current = current->GetParent().value();
|
||||
current = current->GetParent();
|
||||
|
||||
// But not if one up is null or the root element
|
||||
if (!current->GetParent() || current == root) {
|
||||
|
@ -443,12 +437,12 @@ DescendantsIterator::self_type DescendantsIterator::operator++(int _) {
|
|||
|
||||
// Now move to the next sibling
|
||||
siblingIndex.back()++;
|
||||
current = current->GetParent().value()->GetChildren()[siblingIndex.back()];
|
||||
current = current->GetParent()->GetChildren()[siblingIndex.back()];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<Instance>> Instance::Clone(RefStateClone state) {
|
||||
nullable std::shared_ptr<Instance> Instance::Clone(RefStateClone state) {
|
||||
if (state == nullptr) state = std::make_shared<__RefStateClone>();
|
||||
std::shared_ptr<Instance> newInstance = GetClass()->constructor();
|
||||
|
||||
|
@ -494,9 +488,9 @@ std::optional<std::shared_ptr<Instance>> Instance::Clone(RefStateClone state) {
|
|||
|
||||
// Clone children
|
||||
for (std::shared_ptr<Instance> child : GetChildren()) {
|
||||
std::optional<std::shared_ptr<Instance>> clonedChild = child->Clone(state);
|
||||
nullable std::shared_ptr<Instance> clonedChild = child->Clone(state);
|
||||
if (clonedChild)
|
||||
newInstance->AddChild(clonedChild.value());
|
||||
newInstance->AddChild(clonedChild);
|
||||
}
|
||||
|
||||
return newInstance;
|
||||
|
@ -521,12 +515,12 @@ std::vector<std::pair<std::string, std::shared_ptr<Instance>>> Instance::GetRefe
|
|||
|
||||
std::string Instance::GetFullName() {
|
||||
std::string currentName = name;
|
||||
std::optional<std::shared_ptr<Instance>> currentParent = GetParent();
|
||||
nullable std::shared_ptr<Instance> currentParent = GetParent();
|
||||
|
||||
while (currentParent.has_value() && !currentParent.value()->IsA("DataModel")) {
|
||||
currentName = currentParent.value()->name + "." + currentName;
|
||||
while (currentParent && !currentParent->IsA("DataModel")) {
|
||||
currentName = currentParent->name + "." + currentName;
|
||||
|
||||
currentParent = currentParent.value()->GetParent();
|
||||
currentParent = currentParent->GetParent();
|
||||
}
|
||||
|
||||
return currentName;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "error/result.h"
|
||||
#include "member.h"
|
||||
#include "objects/base/refstate.h"
|
||||
#include "utils.h"
|
||||
|
||||
class Instance;
|
||||
typedef std::shared_ptr<Instance>(*InstanceConstructor)();
|
||||
|
@ -59,8 +60,8 @@ private:
|
|||
std::weak_ptr<DataModel> _dataModel;
|
||||
std::weak_ptr<Workspace> _workspace;
|
||||
|
||||
bool ancestryContinuityCheck(std::optional<std::shared_ptr<Instance>> newParent);
|
||||
void updateAncestry(std::optional<std::shared_ptr<Instance>> child, std::optional<std::shared_ptr<Instance>> newParent);
|
||||
bool ancestryContinuityCheck(nullable std::shared_ptr<Instance> newParent);
|
||||
void updateAncestry(nullable std::shared_ptr<Instance> child, nullable std::shared_ptr<Instance> newParent);
|
||||
|
||||
friend JointInstance; // This isn't ideal, but oh well
|
||||
protected:
|
||||
|
@ -75,17 +76,17 @@ protected:
|
|||
virtual void InternalUpdateProperty(std::string name);
|
||||
virtual std::vector<std::string> InternalGetProperties();
|
||||
|
||||
virtual void OnParentUpdated(std::optional<std::shared_ptr<Instance>> oldParent, std::optional<std::shared_ptr<Instance>> newParent);
|
||||
virtual void OnAncestryChanged(std::optional<std::shared_ptr<Instance>> child, std::optional<std::shared_ptr<Instance>> newParent);
|
||||
virtual void OnWorkspaceAdded(std::optional<std::shared_ptr<Workspace>> oldWorkspace, std::shared_ptr<Workspace> newWorkspace);
|
||||
virtual void OnParentUpdated(nullable std::shared_ptr<Instance> oldParent, nullable std::shared_ptr<Instance> newParent);
|
||||
virtual void OnAncestryChanged(nullable std::shared_ptr<Instance> child, nullable std::shared_ptr<Instance> newParent);
|
||||
virtual void OnWorkspaceAdded(nullable std::shared_ptr<Workspace> oldWorkspace, std::shared_ptr<Workspace> newWorkspace);
|
||||
virtual void OnWorkspaceRemoved(std::shared_ptr<Workspace> oldWorkspace);
|
||||
|
||||
// The root data model this object is a descendant of
|
||||
std::optional<std::shared_ptr<DataModel>> dataModel();
|
||||
nullable std::shared_ptr<DataModel> dataModel();
|
||||
// The root workspace this object is a descendant of
|
||||
// NOTE: This value is not necessarily present if dataModel is present
|
||||
// Objects under services other than workspace will NOT have this field set
|
||||
std::optional<std::shared_ptr<Workspace>> workspace();
|
||||
nullable std::shared_ptr<Workspace> workspace();
|
||||
public:
|
||||
const static InstanceType TYPE;
|
||||
std::string name;
|
||||
|
@ -96,8 +97,8 @@ public:
|
|||
// Instance is abstract, so it should not implement GetClass directly
|
||||
virtual const InstanceType* GetClass() = 0;
|
||||
static void PushLuaLibrary(lua_State*); // Defined in lua/instancelib.cpp
|
||||
bool SetParent(std::optional<std::shared_ptr<Instance>> newParent);
|
||||
std::optional<std::shared_ptr<Instance>> GetParent();
|
||||
bool SetParent(nullable std::shared_ptr<Instance> newParent);
|
||||
nullable std::shared_ptr<Instance> GetParent();
|
||||
bool IsParentLocked();
|
||||
inline const std::vector<std::shared_ptr<Instance>> GetChildren() { return children; }
|
||||
void Destroy();
|
||||
|
@ -111,7 +112,7 @@ public:
|
|||
DescendantsIterator GetDescendantsEnd();
|
||||
// Utility functions
|
||||
inline void AddChild(std::shared_ptr<Instance> object) { object->SetParent(this->shared_from_this()); }
|
||||
std::optional<std::shared_ptr<Instance>> FindFirstChild(std::string);
|
||||
nullable std::shared_ptr<Instance> FindFirstChild(std::string);
|
||||
std::string GetFullName();
|
||||
|
||||
// Properties
|
||||
|
@ -136,7 +137,7 @@ public:
|
|||
// Serialization
|
||||
void Serialize(pugi::xml_node parent, RefStateSerialize state = {});
|
||||
static result<std::shared_ptr<Instance>, NoSuchInstance> Deserialize(pugi::xml_node node, RefStateDeserialize state = {});
|
||||
std::optional<std::shared_ptr<Instance>> Clone(RefStateClone state = {});
|
||||
nullable std::shared_ptr<Instance> Clone(RefStateClone state = {});
|
||||
};
|
||||
|
||||
// https://gist.github.com/jeetsukumaran/307264
|
||||
|
@ -158,7 +159,7 @@ public:
|
|||
|
||||
self_type operator++(int _);
|
||||
private:
|
||||
std::optional<std::shared_ptr<Instance>> root;
|
||||
nullable std::shared_ptr<Instance> root;
|
||||
std::shared_ptr<Instance> current;
|
||||
std::vector<int> siblingIndex;
|
||||
};
|
|
@ -7,9 +7,9 @@
|
|||
Service::Service(const InstanceType* type) : Instance(type) {}
|
||||
|
||||
// Fail if parented to non-datamodel, otherwise lock parent
|
||||
void Service::OnParentUpdated(std::optional<std::shared_ptr<Instance>> oldParent, std::optional<std::shared_ptr<Instance>> newParent) {
|
||||
if (!newParent || newParent.value()->GetClass() != &DataModel::TYPE) {
|
||||
Logger::fatalErrorf("Service %s was parented to object of type %s", GetClass()->className.c_str(), newParent ? newParent.value()->GetClass()->className.c_str() : "NULL");
|
||||
void Service::OnParentUpdated(nullable std::shared_ptr<Instance> oldParent, nullable std::shared_ptr<Instance> newParent) {
|
||||
if (!newParent || newParent->GetClass() != &DataModel::TYPE) {
|
||||
Logger::fatalErrorf("Service %s was parented to object of type %s", GetClass()->className.c_str(), newParent ? newParent->GetClass()->className.c_str() : "NULL");
|
||||
panic();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ protected:
|
|||
virtual void InitService();
|
||||
virtual void OnRun();
|
||||
|
||||
void OnParentUpdated(std::optional<std::shared_ptr<Instance>> oldParent, std::optional<std::shared_ptr<Instance>> newParent) override;
|
||||
void OnParentUpdated(nullable std::shared_ptr<Instance> oldParent, nullable std::shared_ptr<Instance> newParent) override;
|
||||
|
||||
friend class DataModel;
|
||||
};
|
|
@ -20,6 +20,12 @@ DataModel::DataModel()
|
|||
this->name = "Place";
|
||||
}
|
||||
|
||||
DataModel::~DataModel() {
|
||||
#ifndef NDEBUG
|
||||
printf("Datamodel successfully destroyed\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
void DataModel::Init(bool runMode) {
|
||||
// Create default services
|
||||
GetService<Workspace>();
|
||||
|
@ -107,14 +113,14 @@ result<std::shared_ptr<Service>, NoSuchService> DataModel::GetService(std::strin
|
|||
return std::dynamic_pointer_cast<Service>(services[className]);
|
||||
}
|
||||
|
||||
result<std::optional<std::shared_ptr<Service>>, NoSuchService> DataModel::FindService(std::string className) {
|
||||
result<nullable std::shared_ptr<Service>, NoSuchService> DataModel::FindService(std::string className) {
|
||||
if (!INSTANCE_MAP[className] || (INSTANCE_MAP[className]->flags ^ (INSTANCE_NOTCREATABLE | INSTANCE_SERVICE)) != 0) {
|
||||
return NoSuchService(className);
|
||||
}
|
||||
|
||||
if (services.count(className) != 0)
|
||||
return std::make_optional(std::dynamic_pointer_cast<Service>(services[className]));
|
||||
return (std::optional<std::shared_ptr<Service>>)std::nullopt;
|
||||
return std::dynamic_pointer_cast<Service>(services[className]);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<DataModel> DataModel::CloneModel() {
|
||||
|
@ -166,11 +172,11 @@ std::shared_ptr<DataModel> DataModel::CloneModel() {
|
|||
if (!result)
|
||||
continue;
|
||||
|
||||
newModel->AddChild(result.value());
|
||||
newModel->AddChild(result);
|
||||
|
||||
// Special case: Ignore instances parented to DataModel which are not services
|
||||
if (child->GetClass()->flags & INSTANCE_SERVICE) {
|
||||
newModel->services[child->GetClass()->className] = std::dynamic_pointer_cast<Service>(result.value());
|
||||
newModel->services[child->GetClass()->className] = std::dynamic_pointer_cast<Service>(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,12 +24,13 @@ public:
|
|||
std::optional<std::string> currentFile;
|
||||
|
||||
DataModel();
|
||||
~DataModel();
|
||||
void Init(bool runMode = false);
|
||||
|
||||
static inline std::shared_ptr<DataModel> New() { return std::make_shared<DataModel>(); };
|
||||
|
||||
result<std::shared_ptr<Service>, NoSuchService> GetService(std::string className);
|
||||
result<std::optional<std::shared_ptr<Service>>, NoSuchService> FindService(std::string className);
|
||||
result<nullable std::shared_ptr<Service>, NoSuchService> FindService(std::string className);
|
||||
|
||||
template <typename T>
|
||||
std::shared_ptr<T> GetService() {
|
||||
|
@ -38,10 +39,10 @@ public:
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
std::optional<std::shared_ptr<T>> FindService() {
|
||||
nullable std::shared_ptr<T> FindService() {
|
||||
auto result = FindService(T::TYPE.className).expect("FindService<T>() was called with a non-service instance type");
|
||||
if (!result) return std::nullopt;
|
||||
return std::dynamic_pointer_cast<T>(result.value());
|
||||
if (!result) return nullptr;
|
||||
return std::dynamic_pointer_cast<T>(result);
|
||||
}
|
||||
|
||||
// Saving/loading
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
#include "jointinstance.h"
|
||||
|
||||
#include "datatypes/cframe.h"
|
||||
#include "datatypes/ref.h"
|
||||
#include "objects/datamodel.h"
|
||||
#include "objects/service/jointsservice.h"
|
||||
#include "objects/part/part.h"
|
||||
#include "objects/part/basepart.h"
|
||||
#include "objects/service/workspace.h"
|
||||
#include <memory>
|
||||
#include <reactphysics3d/constraint/FixedJoint.h>
|
||||
#include <reactphysics3d/engine/PhysicsWorld.h>
|
||||
#include "ptr_helpers.h"
|
||||
|
||||
JointInstance::JointInstance(const InstanceType* type): Instance(type) {
|
||||
}
|
||||
|
@ -17,43 +13,49 @@ JointInstance::JointInstance(const InstanceType* type): Instance(type) {
|
|||
JointInstance::~JointInstance() {
|
||||
}
|
||||
|
||||
void JointInstance::OnAncestryChanged(std::optional<std::shared_ptr<Instance>>, std::optional<std::shared_ptr<Instance>>) {
|
||||
// Destroy and rebuild the joint, it's the simplest solution that actually works
|
||||
|
||||
breakJoint();
|
||||
buildJoint();
|
||||
void JointInstance::OnAncestryChanged(nullable std::shared_ptr<Instance>, nullable std::shared_ptr<Instance>) {
|
||||
Update();
|
||||
}
|
||||
|
||||
void JointInstance::onUpdated(std::string property) {
|
||||
// Add ourselves to the attached parts, or remove, if applicable
|
||||
void JointInstance::OnPartParamsUpdated() {
|
||||
}
|
||||
|
||||
// Parts differ, delete
|
||||
if (part0 != oldPart0 && !oldPart0.expired()) {
|
||||
oldPart0.lock()->untrackJoint(shared<JointInstance>());
|
||||
void JointInstance::Update() {
|
||||
// To keep it simple compared to our previous algorithm, this one is pretty barebones:
|
||||
// 1. Every time we update, (whether our parent changed, or a property), destroy the current joints
|
||||
// 2. If the new configuration is valid, rebuild our joints
|
||||
|
||||
if (!jointWorkspace.expired()) {
|
||||
jointWorkspace.lock()->DestroyJoint(joint);
|
||||
if (!oldPart0.expired())
|
||||
oldPart0.lock()->untrackJoint(shared<JointInstance>());
|
||||
if (!oldPart1.expired())
|
||||
oldPart1.lock()->untrackJoint(shared<JointInstance>());
|
||||
}
|
||||
|
||||
if (part1 != oldPart1 && !oldPart1.expired()) {
|
||||
oldPart1.lock()->untrackJoint(shared<JointInstance>());
|
||||
}
|
||||
|
||||
// Parts differ, add
|
||||
if (part0 != oldPart0 && !part0.expired()) {
|
||||
part0.lock()->trackJoint(shared<JointInstance>());
|
||||
}
|
||||
|
||||
if (part1 != oldPart1 && !part1.expired()) {
|
||||
part1.lock()->trackJoint(shared<JointInstance>());
|
||||
}
|
||||
|
||||
// Destroy and rebuild the joint, if applicable
|
||||
|
||||
breakJoint();
|
||||
buildJoint();
|
||||
|
||||
oldPart0 = part0;
|
||||
oldPart1 = part1;
|
||||
|
||||
// Don't build the joint if we're not part of either a workspace or JointsService
|
||||
if ((!GetParent() || GetParent()->GetClass() != &JointsService::TYPE) && !workspace()) return;
|
||||
|
||||
// If either part is invalid or they are part of separate worlds, fail
|
||||
if (part0.expired()
|
||||
|| part1.expired()
|
||||
|| !workspaceOfPart(part0.lock())
|
||||
|| !workspaceOfPart(part1.lock())
|
||||
|| workspaceOfPart(part0.lock()) != workspaceOfPart(part1.lock())
|
||||
) return;
|
||||
|
||||
// TODO: Add joint continuity check here
|
||||
|
||||
// Finally, build the joint
|
||||
buildJoint();
|
||||
|
||||
part0.lock()->trackJoint(shared<JointInstance>());
|
||||
part1.lock()->trackJoint(shared<JointInstance>());
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<Workspace>> JointInstance::workspaceOfPart(std::shared_ptr<BasePart> part) {
|
||||
nullable std::shared_ptr<Workspace> JointInstance::workspaceOfPart(std::shared_ptr<BasePart> part) {
|
||||
return part->workspace();
|
||||
}
|
|
@ -3,14 +3,16 @@
|
|||
#include "objects/base/instance.h"
|
||||
#include "../annotation.h"
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include "datatypes/cframe.h"
|
||||
#include "physics/world.h"
|
||||
|
||||
//this is necessary ebcause we use std::weak_ptr<Part> without including it in this file
|
||||
#ifdef __AUTOGEN_EXTRA_INCLUDES__
|
||||
#include "objects/part/part.h"
|
||||
#endif
|
||||
|
||||
#define DEF_PROP_PHYS DEF_PROP_(on_update=onUpdated)
|
||||
|
||||
class BasePart;
|
||||
class Workspace;
|
||||
|
||||
|
@ -22,20 +24,25 @@ class DEF_INST_ABSTRACT JointInstance : public Instance {
|
|||
protected:
|
||||
// The workspace the joint was created in, if it exists
|
||||
std::weak_ptr<Workspace> jointWorkspace;
|
||||
PhysJoint joint;
|
||||
|
||||
void OnAncestryChanged(std::optional<std::shared_ptr<Instance>>, std::optional<std::shared_ptr<Instance>>) override;
|
||||
void OnAncestryChanged(nullable std::shared_ptr<Instance>, nullable std::shared_ptr<Instance>) override;
|
||||
|
||||
nullable std::shared_ptr<Workspace> workspaceOfPart(std::shared_ptr<BasePart>);
|
||||
inline void onUpdated(std::string property) { Update(); };
|
||||
|
||||
std::optional<std::shared_ptr<Workspace>> workspaceOfPart(std::shared_ptr<BasePart>);
|
||||
void onUpdated(std::string property);
|
||||
virtual void buildJoint() = 0;
|
||||
virtual void breakJoint() = 0;
|
||||
public:
|
||||
void Update();
|
||||
virtual void OnPartParamsUpdated();
|
||||
|
||||
DEF_PROP_(on_update=onUpdated) std::weak_ptr<BasePart> part0;
|
||||
DEF_PROP_(on_update=onUpdated) std::weak_ptr<BasePart> part1;
|
||||
DEF_PROP_(on_update=onUpdated) CFrame c0;
|
||||
DEF_PROP_(on_update=onUpdated) CFrame c1;
|
||||
DEF_PROP_PHYS std::weak_ptr<BasePart> part0;
|
||||
DEF_PROP_PHYS std::weak_ptr<BasePart> part1;
|
||||
DEF_PROP_PHYS CFrame c0;
|
||||
DEF_PROP_PHYS CFrame c1;
|
||||
|
||||
JointInstance(const InstanceType*);
|
||||
~JointInstance();
|
||||
};
|
||||
};
|
||||
|
||||
#undef DEF_PROP_PHYS
|
|
@ -3,7 +3,6 @@
|
|||
#include "objects/part/part.h"
|
||||
#include "objects/service/workspace.h"
|
||||
#include "rendering/renderer.h"
|
||||
#include <reactphysics3d/constraint/HingeJoint.h>
|
||||
|
||||
Rotate::Rotate(): JointInstance(&TYPE) {
|
||||
}
|
||||
|
@ -13,35 +12,15 @@ Rotate::~Rotate() {
|
|||
static CFrame XYZToZXY(glm::vec3(0, 0, 0), -glm::vec3(1, 0, 0), glm::vec3(0, 0, 1));
|
||||
|
||||
void Rotate::buildJoint() {
|
||||
// Only if both parts are set, are not the same part, are part of a workspace, and are part of the same workspace, we build the joint
|
||||
if (part0.expired() || part1.expired() || part0.lock() == part1.lock() || !workspaceOfPart(part0.lock()) || workspaceOfPart(part0.lock()) != workspaceOfPart(part1.lock())) return;
|
||||
|
||||
// Don't build the joint if we're not part of either a workspace or JointsService
|
||||
if ((!GetParent() || GetParent().value()->GetClass() != &JointsService::TYPE) && !workspace()) return;
|
||||
|
||||
std::shared_ptr<Workspace> workspace = workspaceOfPart(part0.lock()).value();
|
||||
std::shared_ptr<Workspace> workspace = workspaceOfPart(part0.lock());
|
||||
|
||||
// Update Part1's rotation and cframe prior to creating the joint as reactphysics3d locks rotation based on how it
|
||||
// used to be rather than specifying an anchor rotation, so whatever.
|
||||
CFrame newFrame = part0.lock()->cframe * (c0 * c1.Inverse());
|
||||
part1.lock()->cframe = newFrame;
|
||||
workspace->SyncPartPhysics(part1.lock());
|
||||
|
||||
// Do NOT use Abs() in this scenario. For some reason that breaks it
|
||||
rp::HingeJointInfo jointInfo(part0.lock()->rigidBody, part1.lock()->rigidBody, (part0.lock()->cframe * c0).Position(), -(part0.lock()->cframe * c0).LookVector().Unit());
|
||||
this->joint = dynamic_cast<rp::HingeJoint*>(workspace->CreateJoint(jointInfo));
|
||||
PhysRotatingJointInfo jointInfo(c0, c1);
|
||||
this->joint = workspace->CreateJoint(jointInfo, part0.lock(), part1.lock());
|
||||
jointWorkspace = workspace;
|
||||
|
||||
// part1.lock()->rigidBody->getCollider(0)->setCollideWithMaskBits(0b10);
|
||||
// part1.lock()->rigidBody->getCollider(0)->setCollisionCategoryBits(0b10);
|
||||
// part0.lock()->rigidBody->getCollider(0)->setCollideWithMaskBits(0b01);
|
||||
// part0.lock()->rigidBody->getCollider(0)->setCollisionCategoryBits(0b01);
|
||||
}
|
||||
|
||||
// !!! REMINDER: This has to be called manually when parts are destroyed/removed from the workspace, or joints will linger
|
||||
void Rotate::breakJoint() {
|
||||
// If the joint doesn't exist, or its workspace expired (not our problem anymore), then no need to do anything
|
||||
if (!this->joint || jointWorkspace.expired()) return;
|
||||
|
||||
jointWorkspace.lock()->DestroyJoint(this->joint);
|
||||
this->joint = nullptr;
|
||||
}
|
|
@ -5,15 +5,10 @@
|
|||
#include "objects/joint/jointinstance.h"
|
||||
#include <memory>
|
||||
|
||||
namespace reactphysics3d { class HingeJoint; }
|
||||
|
||||
class DEF_INST Rotate : public JointInstance {
|
||||
AUTOGEN_PREAMBLE
|
||||
|
||||
reactphysics3d::HingeJoint* joint = nullptr;
|
||||
|
||||
virtual void buildJoint() override;
|
||||
virtual void breakJoint() override;
|
||||
public:
|
||||
Rotate();
|
||||
~Rotate();
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include "objects/part/part.h"
|
||||
#include "objects/service/workspace.h"
|
||||
#include "rendering/renderer.h"
|
||||
#include <reactphysics3d/constraint/HingeJoint.h>
|
||||
|
||||
#define PI 3.14159
|
||||
|
||||
|
@ -15,39 +14,21 @@ RotateV::~RotateV() {
|
|||
static CFrame XYZToZXY(glm::vec3(0, 0, 0), -glm::vec3(1, 0, 0), glm::vec3(0, 0, 1));
|
||||
|
||||
void RotateV::buildJoint() {
|
||||
// Only if both parts are set, are not the same part, are part of a workspace, and are part of the same workspace, we build the joint
|
||||
if (part0.expired() || part1.expired() || part0.lock() == part1.lock() || !workspaceOfPart(part0.lock()) || workspaceOfPart(part0.lock()) != workspaceOfPart(part1.lock())) return;
|
||||
|
||||
// Don't build the joint if we're not part of either a workspace or JointsService
|
||||
if ((!GetParent() || GetParent().value()->GetClass() != &JointsService::TYPE) && !workspace()) return;
|
||||
|
||||
std::shared_ptr<Workspace> workspace = workspaceOfPart(part0.lock()).value();
|
||||
|
||||
std::shared_ptr<Workspace> workspace = workspaceOfPart(part0.lock());
|
||||
|
||||
// Update Part1's rotation and cframe prior to creating the joint as reactphysics3d locks rotation based on how it
|
||||
// used to be rather than specifying an anchor rotation, so whatever.
|
||||
CFrame newFrame = part0.lock()->cframe * (c0 * c1.Inverse());
|
||||
part1.lock()->cframe = newFrame;
|
||||
workspace->SyncPartPhysics(part1.lock());
|
||||
// Do NOT use Abs() in this scenario. For some reason that breaks it
|
||||
rp::HingeJointInfo jointInfo(part0.lock()->rigidBody, part1.lock()->rigidBody, (part0.lock()->cframe * c0).Position(), -(part0.lock()->cframe * c0).LookVector().Unit());
|
||||
float vel = part0.lock()->GetSurfaceParamB(-c0.LookVector().Unit()) * 6.28;
|
||||
PhysRotatingJointInfo jointInfo(c0, c1, vel);
|
||||
|
||||
jointInfo.isCollisionEnabled = false;
|
||||
|
||||
this->joint = dynamic_cast<rp::HingeJoint*>(workspace->CreateJoint(jointInfo));
|
||||
this->joint = workspace->CreateJoint(jointInfo, part0.lock(), part1.lock());
|
||||
jointWorkspace = workspace;
|
||||
|
||||
|
||||
// part1.lock()->rigidBody->getCollider(0)->setCollideWithMaskBits(0b10);
|
||||
// part1.lock()->rigidBody->getCollider(0)->setCollisionCategoryBits(0b10);
|
||||
// part0.lock()->rigidBody->getCollider(0)->setCollideWithMaskBits(0b01);
|
||||
// part0.lock()->rigidBody->getCollider(0)->setCollisionCategoryBits(0b01);
|
||||
}
|
||||
|
||||
void RotateV::breakJoint() {
|
||||
// If the joint doesn't exist, or its workspace expired (not our problem anymore), then no need to do anything
|
||||
if (!this->joint || jointWorkspace.expired()) return;
|
||||
|
||||
jointWorkspace.lock()->DestroyJoint(this->joint);
|
||||
this->joint = nullptr;
|
||||
void RotateV::OnPartParamsUpdated() {
|
||||
float vel = part0.lock()->GetSurfaceParamB(-c0.LookVector().Unit()) * 6.28;
|
||||
this->joint.setAngularVelocity(vel);
|
||||
}
|
|
@ -4,19 +4,17 @@
|
|||
#include "objects/base/instance.h"
|
||||
#include "objects/joint/jointinstance.h"
|
||||
#include <memory>
|
||||
namespace reactphysics3d { class HingeJoint; }
|
||||
|
||||
class DEF_INST RotateV : public JointInstance {
|
||||
AUTOGEN_PREAMBLE
|
||||
|
||||
reactphysics3d::HingeJoint* joint = nullptr;
|
||||
|
||||
virtual void buildJoint() override;
|
||||
virtual void breakJoint() override;
|
||||
public:
|
||||
RotateV();
|
||||
~RotateV();
|
||||
|
||||
void OnPartParamsUpdated() override;
|
||||
|
||||
static inline std::shared_ptr<RotateV> New() { return std::make_shared<RotateV>(); };
|
||||
static inline std::shared_ptr<Instance> Create() { return std::make_shared<RotateV>(); };
|
||||
};
|
|
@ -6,9 +6,8 @@
|
|||
#include "objects/service/jointsservice.h"
|
||||
#include "objects/part/part.h"
|
||||
#include "objects/service/workspace.h"
|
||||
#include "physics/world.h"
|
||||
#include <memory>
|
||||
#include <reactphysics3d/constraint/FixedJoint.h>
|
||||
#include <reactphysics3d/engine/PhysicsWorld.h>
|
||||
|
||||
Snap::Snap(): JointInstance(&TYPE) {
|
||||
}
|
||||
|
@ -17,30 +16,14 @@ Snap::~Snap() {
|
|||
}
|
||||
|
||||
void Snap::buildJoint() {
|
||||
// Only if both parts are set, are not the same part, are part of a workspace, and are part of the same workspace, we build the joint
|
||||
if (part0.expired() || part1.expired() || part0.lock() == part1.lock() || !workspaceOfPart(part0.lock()) || workspaceOfPart(part0.lock()) != workspaceOfPart(part1.lock())) return;
|
||||
|
||||
// Don't build the joint if we're not part of either a workspace or JointsService
|
||||
if ((!GetParent() || GetParent().value()->GetClass() != &JointsService::TYPE) && !workspace()) return;
|
||||
|
||||
std::shared_ptr<Workspace> workspace = workspaceOfPart(part0.lock()).value();
|
||||
std::shared_ptr<Workspace> workspace = workspaceOfPart(part0.lock());
|
||||
|
||||
// Update Part1's rotation and cframe prior to creating the joint as reactphysics3d locks rotation based on how it
|
||||
// used to be rather than specifying an anchor rotation, so whatever.
|
||||
CFrame newFrame = part0.lock()->cframe * (c0 * c1.Inverse());
|
||||
part1.lock()->cframe = newFrame;
|
||||
workspace->SyncPartPhysics(part1.lock());
|
||||
|
||||
rp::FixedJointInfo jointInfo(part0.lock()->rigidBody, part1.lock()->rigidBody, (c0.Inverse() * c1).Position());
|
||||
this->joint = dynamic_cast<rp::FixedJoint*>(workspace->CreateJoint(jointInfo));
|
||||
PhysFixedJointInfo jointInfo(c0, c1);
|
||||
this->joint = workspace->CreateJoint(jointInfo, part0.lock(), part1.lock());
|
||||
jointWorkspace = workspace;
|
||||
}
|
||||
|
||||
// !!! REMINDER: This has to be called manually when parts are destroyed/removed from the workspace, or joints will linger
|
||||
void Snap::breakJoint() {
|
||||
// If the joint doesn't exist, or its workspace expired (not our problem anymore), then no need to do anything
|
||||
if (!this->joint || jointWorkspace.expired()) return;
|
||||
|
||||
jointWorkspace.lock()->DestroyJoint(this->joint);
|
||||
this->joint = nullptr;
|
||||
}
|
|
@ -5,15 +5,10 @@
|
|||
#include "objects/joint/jointinstance.h"
|
||||
#include <memory>
|
||||
|
||||
namespace reactphysics3d { class FixedJoint; }
|
||||
|
||||
class DEF_INST Snap : public JointInstance {
|
||||
AUTOGEN_PREAMBLE
|
||||
|
||||
reactphysics3d::FixedJoint* joint = nullptr;
|
||||
|
||||
virtual void buildJoint() override;
|
||||
virtual void breakJoint() override;
|
||||
public:
|
||||
Snap();
|
||||
~Snap();
|
||||
|
|
|
@ -6,9 +6,8 @@
|
|||
#include "objects/service/jointsservice.h"
|
||||
#include "objects/part/part.h"
|
||||
#include "objects/service/workspace.h"
|
||||
#include "physics/world.h"
|
||||
#include <memory>
|
||||
#include <reactphysics3d/constraint/FixedJoint.h>
|
||||
#include <reactphysics3d/engine/PhysicsWorld.h>
|
||||
|
||||
Weld::Weld(): JointInstance(&TYPE) {
|
||||
}
|
||||
|
@ -17,30 +16,14 @@ Weld::~Weld() {
|
|||
}
|
||||
|
||||
void Weld::buildJoint() {
|
||||
// Only if both parts are set, are not the same part, are part of a workspace, and are part of the same workspace, we build the joint
|
||||
if (part0.expired() || part1.expired() || part0.lock() == part1.lock() || !workspaceOfPart(part0.lock()) || workspaceOfPart(part0.lock()) != workspaceOfPart(part1.lock())) return;
|
||||
|
||||
// Don't build the joint if we're not part of either a workspace or JointsService
|
||||
if ((!GetParent() || GetParent().value()->GetClass() != &JointsService::TYPE) && !workspace()) return;
|
||||
|
||||
std::shared_ptr<Workspace> workspace = workspaceOfPart(part0.lock()).value();
|
||||
std::shared_ptr<Workspace> workspace = workspaceOfPart(part0.lock());
|
||||
|
||||
// Update Part1's rotation and cframe prior to creating the joint as reactphysics3d locks rotation based on how it
|
||||
// used to be rather than specifying an anchor rotation, so whatever.
|
||||
CFrame newFrame = part0.lock()->cframe * (c0 * c1.Inverse());
|
||||
part1.lock()->cframe = newFrame;
|
||||
workspace->SyncPartPhysics(part1.lock());
|
||||
|
||||
rp::FixedJointInfo jointInfo(part0.lock()->rigidBody, part1.lock()->rigidBody, (c0.Inverse() * c1).Position());
|
||||
this->joint = dynamic_cast<rp::FixedJoint*>(workspace->CreateJoint(jointInfo));
|
||||
PhysFixedJointInfo jointInfo(c0, c1);
|
||||
this->joint = workspace->CreateJoint(jointInfo, part0.lock(), part1.lock());
|
||||
jointWorkspace = workspace;
|
||||
}
|
||||
|
||||
// !!! REMINDER: This has to be called manually when parts are destroyed/removed from the workspace, or joints will linger
|
||||
void Weld::breakJoint() {
|
||||
// If the joint doesn't exist, or its workspace expired (not our problem anymore), then no need to do anything
|
||||
if (!this->joint || jointWorkspace.expired()) return;
|
||||
|
||||
jointWorkspace.lock()->DestroyJoint(this->joint);
|
||||
this->joint = nullptr;
|
||||
}
|
|
@ -5,15 +5,10 @@
|
|||
#include "objects/joint/jointinstance.h"
|
||||
#include <memory>
|
||||
|
||||
namespace reactphysics3d { class FixedJoint; }
|
||||
|
||||
class DEF_INST Weld : public JointInstance {
|
||||
AUTOGEN_PREAMBLE
|
||||
|
||||
reactphysics3d::FixedJoint* joint = nullptr;
|
||||
|
||||
virtual void buildJoint() override;
|
||||
virtual void breakJoint() override;
|
||||
public:
|
||||
Weld();
|
||||
~Weld();
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "objects/joint/snap.h"
|
||||
#include "rendering/renderer.h"
|
||||
#include "enum/surface.h"
|
||||
#include <cstdio>
|
||||
#include <glm/common.hpp>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
@ -27,20 +26,17 @@ BasePart::BasePart(const InstanceType* type, PartConstructParams params): PVInst
|
|||
}
|
||||
|
||||
BasePart::~BasePart() {
|
||||
// This relies on physicsCommon still existing. Be very careful.
|
||||
if (this->rigidBody && workspace()) {
|
||||
workspace().value()->DestroyRigidBody(rigidBody);
|
||||
this->rigidBody = nullptr;
|
||||
if (workspace() != nullptr) {
|
||||
workspace()->RemoveBody(shared<BasePart>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BasePart::OnAncestryChanged(std::optional<std::shared_ptr<Instance>> child, std::optional<std::shared_ptr<Instance>> newParent) {
|
||||
if (this->rigidBody)
|
||||
this->rigidBody->setIsActive(workspace().has_value());
|
||||
void BasePart::OnAncestryChanged(nullable std::shared_ptr<Instance> child, nullable std::shared_ptr<Instance> newParent) {
|
||||
this->rigidBody.setActive(workspace() != nullptr);
|
||||
|
||||
if (workspace())
|
||||
workspace().value()->SyncPartPhysics(std::dynamic_pointer_cast<BasePart>(this->shared_from_this()));
|
||||
if (workspace() != nullptr)
|
||||
workspace()->SyncPartPhysics(std::dynamic_pointer_cast<BasePart>(this->shared_from_this()));
|
||||
|
||||
// Destroy joints
|
||||
if (!workspace()) BreakJoints();
|
||||
|
@ -48,28 +44,41 @@ void BasePart::OnAncestryChanged(std::optional<std::shared_ptr<Instance>> child,
|
|||
// TODO: Sleeping bodies that touch this one also need to be updated
|
||||
}
|
||||
|
||||
void BasePart::OnWorkspaceAdded(std::optional<std::shared_ptr<Workspace>> oldWorkspace, std::shared_ptr<Workspace> newWorkspace) {
|
||||
void BasePart::OnWorkspaceAdded(nullable std::shared_ptr<Workspace> oldWorkspace, std::shared_ptr<Workspace> newWorkspace) {
|
||||
newWorkspace->AddBody(shared<BasePart>());
|
||||
}
|
||||
|
||||
void BasePart::OnWorkspaceRemoved(std::shared_ptr<Workspace> oldWorkspace) {
|
||||
if (simulationTicket.has_value())
|
||||
oldWorkspace->RemoveBody(shared<BasePart>());
|
||||
BreakJoints();
|
||||
oldWorkspace->RemoveBody(shared<BasePart>());
|
||||
}
|
||||
|
||||
void BasePart::onUpdated(std::string property) {
|
||||
// Reset velocity
|
||||
if (property != "Velocity")
|
||||
velocity = Vector3::ZERO;
|
||||
bool reset = property == "Position" || property == "Rotation" || property == "CFrame" || property == "Size" || property == "Shape";
|
||||
|
||||
if (workspace())
|
||||
workspace().value()->SyncPartPhysics(std::dynamic_pointer_cast<BasePart>(this->shared_from_this()));
|
||||
// Sanitize size
|
||||
// TODO: Replace this with a validator instead
|
||||
if (property == "Size") {
|
||||
size = glm::max((glm::vec3)size, glm::vec3(0.1f, 0.1f, 0.1f));
|
||||
}
|
||||
|
||||
if (workspace() != nullptr)
|
||||
workspace()->SyncPartPhysics(std::dynamic_pointer_cast<BasePart>(this->shared_from_this()));
|
||||
|
||||
// When position/rotation/size is manually edited, break all joints, they don't apply anymore
|
||||
if (property != "Anchored")
|
||||
if (reset)
|
||||
BreakJoints();
|
||||
}
|
||||
|
||||
void BasePart::onParamUpdated(std::string property) {
|
||||
// Send signal to joints to update themselves
|
||||
for (std::weak_ptr<JointInstance> joint : primaryJoints) {
|
||||
if (joint.expired()) continue;
|
||||
|
||||
joint.lock()->OnPartParamsUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
// Expands provided extents to fit point
|
||||
static void expandMaxExtents(Vector3* min, Vector3* max, Vector3 point) {
|
||||
*min = Vector3(glm::min(min->X(), point.X()), glm::min(min->Y(), point.Y()), glm::min(min->Z(), point.Z()));
|
||||
|
@ -208,7 +217,7 @@ bool BasePart::checkSurfacesTouching(CFrame surfaceFrame, Vector3 size, Vector3
|
|||
return horizOverlap && vertOverlap;
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<JointInstance>> makeJointFromSurfaces(SurfaceType a, SurfaceType b) {
|
||||
nullable std::shared_ptr<JointInstance> makeJointFromSurfaces(SurfaceType a, SurfaceType b) {
|
||||
if (a == SurfaceType::Weld || b == SurfaceType::Weld || a == SurfaceType::Glue || b == SurfaceType::Glue) return Weld::New();
|
||||
if ((a == SurfaceType::Studs && (b == SurfaceType::Inlet || b == SurfaceType::Universal))
|
||||
|| (a == SurfaceType::Inlet && (b == SurfaceType::Studs || b == SurfaceType::Universal))
|
||||
|
@ -218,7 +227,7 @@ std::optional<std::shared_ptr<JointInstance>> makeJointFromSurfaces(SurfaceType
|
|||
return Rotate::New();
|
||||
if (a == SurfaceType::Motor)
|
||||
return RotateV::New();
|
||||
return std::nullopt;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void BasePart::MakeJoints() {
|
||||
|
@ -233,7 +242,7 @@ void BasePart::MakeJoints() {
|
|||
|
||||
// TEMPORARY
|
||||
// TODO: Use more efficient algorithm to *actually* find nearby parts)
|
||||
for (auto it = workspace().value()->GetDescendantsStart(); it != workspace().value()->GetDescendantsEnd(); it++) {
|
||||
for (auto it = workspace()->GetDescendantsStart(); it != workspace()->GetDescendantsEnd(); it++) {
|
||||
std::shared_ptr<Instance> obj = *it;
|
||||
if (obj == shared_from_this()) continue; // Skip ourselves
|
||||
if (!obj->IsA<BasePart>()) continue;
|
||||
|
@ -280,15 +289,17 @@ void BasePart::MakeJoints() {
|
|||
|
||||
auto joint_ = makeJointFromSurfaces(mySurface, otherSurface);
|
||||
if (!joint_) continue;
|
||||
std::shared_ptr<JointInstance> joint = joint_.value();
|
||||
std::shared_ptr<JointInstance> joint = joint_;
|
||||
joint->part0 = shared<BasePart>();
|
||||
joint->part1 = otherPart->shared<BasePart>();
|
||||
joint->c0 = contact0;
|
||||
joint->c1 = contact1;
|
||||
dataModel().value()->GetService<JointsService>()->AddChild(joint);
|
||||
// // If both parts touch directly, this can cause friction in Rotate and RotateV joints, so we leave a little extra space
|
||||
// if (joint->IsA("Rotate") || joint->IsA("RotateV"))
|
||||
// joint->c1 = joint->c1 + joint->c1.LookVector() * 0.02f,
|
||||
// joint->c0 = joint->c0 - joint->c0.LookVector() * 0.02f;
|
||||
dataModel()->GetService<JointsService>()->AddChild(joint);
|
||||
joint->UpdateProperty("Part0");
|
||||
|
||||
Logger::debugf("Made joint between %s and %s!\n", name.c_str(), otherPart->name.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
@ -10,16 +9,14 @@
|
|||
#include "datatypes/vector.h"
|
||||
#include "objects/base/instance.h"
|
||||
#include "enum/surface.h"
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <reactphysics3d/body/RigidBody.h>
|
||||
#include <reactphysics3d/engine/PhysicsCommon.h>
|
||||
#include <reactphysics3d/reactphysics3d.h>
|
||||
#include <vector>
|
||||
#include "objects/annotation.h"
|
||||
#include "objects/pvinstance.h"
|
||||
#include "physics/world.h"
|
||||
|
||||
namespace rp = reactphysics3d;
|
||||
// Common macro for part properties
|
||||
#define DEF_PROP_PHYS DEF_PROP_(on_update=onUpdated)
|
||||
#define DEF_PROP_PHYSPARAM DEF_PROP_(on_update=onParamUpdated)
|
||||
|
||||
// For easy construction from C++. Maybe should be removed?
|
||||
struct PartConstructParams {
|
||||
|
@ -32,13 +29,7 @@ struct PartConstructParams {
|
|||
bool locked = false;
|
||||
};
|
||||
|
||||
class Workspace;
|
||||
|
||||
#ifndef __SIMULATION_TICKET
|
||||
#define __SIMULATION_TICKET
|
||||
class BasePart;
|
||||
typedef std::list<std::shared_ptr<BasePart>>::iterator SimulationTicket;
|
||||
#endif
|
||||
class PhysWorld;
|
||||
|
||||
class DEF_INST_ABSTRACT_(explorer_icon="part") BasePart : public PVInstance {
|
||||
AUTOGEN_PREAMBLE
|
||||
|
@ -58,35 +49,35 @@ protected:
|
|||
bool checkSurfacesTouching(CFrame surfaceFrame, Vector3 size, Vector3 myFace, Vector3 otherFace, std::shared_ptr<BasePart> otherPart);
|
||||
|
||||
friend JointInstance;
|
||||
friend Workspace;
|
||||
friend PhysWorld;
|
||||
|
||||
virtual void OnWorkspaceAdded(std::optional<std::shared_ptr<Workspace>> oldWorkspace, std::shared_ptr<Workspace> newWorkspace) override;
|
||||
virtual void OnWorkspaceAdded(nullable std::shared_ptr<Workspace> oldWorkspace, std::shared_ptr<Workspace> newWorkspace) override;
|
||||
virtual void OnWorkspaceRemoved(std::shared_ptr<Workspace> oldWorkspace) override;
|
||||
void OnAncestryChanged(std::optional<std::shared_ptr<Instance>> child, std::optional<std::shared_ptr<Instance>> newParent) override;
|
||||
void OnAncestryChanged(nullable std::shared_ptr<Instance> child, nullable std::shared_ptr<Instance> newParent) override;
|
||||
void onUpdated(std::string);
|
||||
|
||||
virtual void updateCollider(rp::PhysicsCommon* common) = 0;
|
||||
void onParamUpdated(std::string);
|
||||
|
||||
BasePart(const InstanceType*);
|
||||
BasePart(const InstanceType*, PartConstructParams params);
|
||||
public:
|
||||
DEF_PROP_CATEGORY(DATA)
|
||||
DEF_PROP_(on_update=onUpdated) Vector3 velocity;
|
||||
DEF_PROP_PHYS Vector3 velocity;
|
||||
[[ def_prop(name="CFrame", on_update=onUpdated), cframe_position_prop(name="Position"), cframe_rotation_prop(name="Rotation") ]]
|
||||
CFrame cframe;
|
||||
|
||||
DEF_PROP_CATEGORY(PART)
|
||||
// Special compatibility changes for this property were made in
|
||||
// Instance::Serialize
|
||||
DEF_PROP_(on_update=onUpdated) Vector3 size;
|
||||
DEF_PROP_PHYS Vector3 size;
|
||||
|
||||
DEF_PROP_CATEGORY(APPEARANCE)
|
||||
DEF_PROP Color3 color;
|
||||
DEF_PROP float transparency = 0.f;
|
||||
DEF_PROP float reflectance = 0.f;
|
||||
|
||||
DEF_PROP_CATEGORY(BEHAVIOR)
|
||||
DEF_PROP_(on_update=onUpdated) bool anchored = false;
|
||||
DEF_PROP_(on_update=onUpdated) bool canCollide = true;
|
||||
DEF_PROP_PHYS bool anchored = false;
|
||||
DEF_PROP_PHYS bool canCollide = true;
|
||||
DEF_PROP bool locked = false;
|
||||
|
||||
DEF_PROP_CATEGORY(SURFACE)
|
||||
|
@ -98,26 +89,24 @@ public:
|
|||
DEF_PROP SurfaceType backSurface = SurfaceType::Smooth;
|
||||
|
||||
DEF_PROP_CATEGORY(SURFACE_INPUT)
|
||||
DEF_PROP float topParamA = -0.5;
|
||||
DEF_PROP float bottomParamA = -0.5;
|
||||
DEF_PROP float leftParamA = -0.5;
|
||||
DEF_PROP float rightParamA = -0.5;
|
||||
DEF_PROP float frontParamA = -0.5;
|
||||
DEF_PROP float backParamA = -0.5;
|
||||
DEF_PROP_PHYSPARAM float topParamA = -0.5;
|
||||
DEF_PROP_PHYSPARAM float bottomParamA = -0.5;
|
||||
DEF_PROP_PHYSPARAM float leftParamA = -0.5;
|
||||
DEF_PROP_PHYSPARAM float rightParamA = -0.5;
|
||||
DEF_PROP_PHYSPARAM float frontParamA = -0.5;
|
||||
DEF_PROP_PHYSPARAM float backParamA = -0.5;
|
||||
|
||||
DEF_PROP float topParamB = 0.5;
|
||||
DEF_PROP float bottomParamB = 0.5;
|
||||
DEF_PROP float leftParamB = 0.5;
|
||||
DEF_PROP float rightParamB = 0.5;
|
||||
DEF_PROP float frontParamB = 0.5;
|
||||
DEF_PROP float backParamB = 0.5;
|
||||
DEF_PROP_PHYSPARAM float topParamB = 0.5;
|
||||
DEF_PROP_PHYSPARAM float bottomParamB = 0.5;
|
||||
DEF_PROP_PHYSPARAM float leftParamB = 0.5;
|
||||
DEF_PROP_PHYSPARAM float rightParamB = 0.5;
|
||||
DEF_PROP_PHYSPARAM float frontParamB = 0.5;
|
||||
DEF_PROP_PHYSPARAM float backParamB = 0.5;
|
||||
|
||||
DEF_SIGNAL SignalSource Touched;
|
||||
DEF_SIGNAL SignalSource TouchEnded;
|
||||
|
||||
rp::RigidBody* rigidBody = nullptr;
|
||||
std::optional<SimulationTicket> simulationTicket;
|
||||
bool rigidBodyDirty = true;
|
||||
PhysRigidBody rigidBody;
|
||||
|
||||
inline SurfaceType GetSurfaceFromFace(NormalId face) { return surfaceFromFace(face); }
|
||||
float GetSurfaceParamA(Vector3 face);
|
||||
|
@ -133,4 +122,7 @@ public:
|
|||
|
||||
// Calculate size of axis-aligned bounding box
|
||||
Vector3 GetAABB();
|
||||
};
|
||||
};
|
||||
|
||||
#undef DEF_PROP_PHYS
|
||||
#undef DEF_PROP_PHYSPARAM
|
|
@ -1,42 +1,22 @@
|
|||
#include "part.h"
|
||||
#include "enum/part.h"
|
||||
#include "physics/util.h"
|
||||
#include <glm/common.hpp>
|
||||
|
||||
Part::Part(): BasePart(&TYPE) {
|
||||
_lastShape = shape;
|
||||
_lastSize = size;
|
||||
}
|
||||
|
||||
Part::Part(PartConstructParams params): BasePart(&TYPE, params) {
|
||||
_lastShape = shape;
|
||||
_lastSize = size;
|
||||
}
|
||||
|
||||
void Part::updateCollider(rp::PhysicsCommon* common) {
|
||||
rp::CollisionShape* physShape;
|
||||
if (shape == PartType::Ball) {
|
||||
physShape = common->createSphereShape(glm::min(size.X(), size.Y(), size.Z()) * 0.5f);
|
||||
} else if (shape == PartType::Block) {
|
||||
physShape = common->createBoxShape(glmToRp(size * glm::vec3(0.5f)));
|
||||
}
|
||||
|
||||
// Recreate the rigidbody if the shape changes
|
||||
if (rigidBody->getNbColliders() > 0 && (_lastShape != shape || _lastSize != size)) {
|
||||
// TODO: This causes Touched to get called twice. Fix this.
|
||||
rigidBody->removeCollider(rigidBody->getCollider(0));
|
||||
rigidBody->addCollider(physShape, rp::Transform());
|
||||
}
|
||||
|
||||
if (rigidBody->getNbColliders() == 0)
|
||||
rigidBody->addCollider(physShape, rp::Transform());
|
||||
|
||||
|
||||
_lastShape = shape;
|
||||
_lastSize = size;
|
||||
Part::Part(PartConstructParams params): BasePart(&TYPE, params) {
|
||||
}
|
||||
|
||||
Vector3 Part::GetEffectiveSize() {
|
||||
return shape == PartType::Ball ? (Vector3)glm::vec3(glm::min(size.X(), size.Y(), size.Z())) : size;
|
||||
|
||||
float diameter;
|
||||
switch (shape) {
|
||||
case PartType::Ball:
|
||||
return (Vector3)glm::vec3(glm::min(size.X(), size.Y(), size.Z()));
|
||||
case PartType::Cylinder:
|
||||
diameter = glm::min(size.Y(), size.Z());
|
||||
return Vector3(size.X(), diameter, diameter);
|
||||
default:
|
||||
return size;
|
||||
}
|
||||
}
|
|
@ -6,11 +6,7 @@
|
|||
|
||||
class DEF_INST Part : public BasePart {
|
||||
AUTOGEN_PREAMBLE
|
||||
|
||||
PartType _lastShape;
|
||||
Vector3 _lastSize;
|
||||
protected:
|
||||
void updateCollider(rp::PhysicsCommon* common) override;
|
||||
|
||||
public:
|
||||
Part();
|
||||
|
|
|
@ -1,91 +1,6 @@
|
|||
#include "wedgepart.h"
|
||||
#include "physics/util.h"
|
||||
#include <reactphysics3d/collision/ConvexMesh.h>
|
||||
#include <reactphysics3d/collision/shapes/ConvexMeshShape.h>
|
||||
|
||||
rp::ConvexMesh* wedgePhysMesh;
|
||||
|
||||
WedgePart::WedgePart(): BasePart(&TYPE) {
|
||||
}
|
||||
|
||||
WedgePart::WedgePart(PartConstructParams params): BasePart(&TYPE, params) {
|
||||
|
||||
}
|
||||
|
||||
void WedgePart::updateCollider(rp::PhysicsCommon* common) {
|
||||
rp::ConvexMeshShape* shape = common->createConvexMeshShape(wedgePhysMesh, glmToRp(size * glm::vec3(0.5f)));
|
||||
|
||||
// Recreate the rigidbody if the shape changes
|
||||
if (rigidBody->getNbColliders() > 0
|
||||
&& dynamic_cast<rp::ConvexMeshShape*>(rigidBody->getCollider(0)->getCollisionShape())->getScale() != shape->getScale()) {
|
||||
// TODO: This causes Touched to get called twice. Fix this.
|
||||
rigidBody->removeCollider(rigidBody->getCollider(0));
|
||||
rigidBody->addCollider(shape, rp::Transform());
|
||||
}
|
||||
|
||||
if (rigidBody->getNbColliders() == 0)
|
||||
rigidBody->addCollider(shape, rp::Transform());
|
||||
}
|
||||
|
||||
void WedgePart::createWedgeShape(rp::PhysicsCommon* common) {
|
||||
// https://www.reactphysics3d.com/documentation/index.html#creatingbody
|
||||
float vertices[] = {
|
||||
// X Y Z
|
||||
/*0*/ -1, 1, 1, // 0
|
||||
/*1*/ -1, -1, 1, // |
|
||||
/*2*/ -1, -1, -1, // 1---2
|
||||
|
||||
/*3*/ 1, 1, 1,
|
||||
/*4*/ 1, -1, 1,
|
||||
/*5*/ 1, -1, -1,
|
||||
};
|
||||
|
||||
// -x +x
|
||||
// +z 1----------4
|
||||
// | bottom |
|
||||
// -z 2----------5
|
||||
|
||||
// -x +x
|
||||
// +y 0----------3
|
||||
// | front |
|
||||
// -y 1----------4
|
||||
|
||||
// -x +x
|
||||
// +yz 0----------3
|
||||
// | slope |
|
||||
// -yz 2----------5
|
||||
|
||||
int indices[] = {
|
||||
// Base
|
||||
1, 2, 5, 4,
|
||||
|
||||
// Back-face
|
||||
0, 1, 4, 3,
|
||||
// 4, 1, 0, 3,
|
||||
|
||||
// Slope
|
||||
0, 2, 5, 3,
|
||||
// 3, 5, 2, 0,
|
||||
|
||||
// Sides
|
||||
0, 1, 2,
|
||||
3, 4, 5,
|
||||
};
|
||||
|
||||
// Description of the six faces of the convex mesh
|
||||
rp::PolygonVertexArray::PolygonFace* polygonFaces = new rp::PolygonVertexArray::PolygonFace[5];
|
||||
polygonFaces[0] = { 4, 0 }; // Bottom
|
||||
polygonFaces[1] = { 4, 4 }; // Front
|
||||
polygonFaces[2] = { 4, 8 }; // Slope
|
||||
polygonFaces[3] = { 3, 12 }; // Side
|
||||
polygonFaces[4] = { 3, 15 }; // Side
|
||||
|
||||
// Create the polygon vertex array
|
||||
rp::PolygonVertexArray polygonVertexArray(6, vertices, 3 * sizeof(float), indices, sizeof(int), 5, polygonFaces,
|
||||
rp::PolygonVertexArray::VertexDataType::VERTEX_FLOAT_TYPE,
|
||||
rp::PolygonVertexArray::IndexDataType::INDEX_INTEGER_TYPE);
|
||||
|
||||
// Create the convex mesh
|
||||
std::vector<rp3d::Message> messages;
|
||||
wedgePhysMesh = common->createConvexMesh(polygonVertexArray, messages);
|
||||
}
|
||||
WedgePart::WedgePart(PartConstructParams params): BasePart(&TYPE, params) {}
|
|
@ -6,11 +6,6 @@
|
|||
class DEF_INST WedgePart : public BasePart {
|
||||
AUTOGEN_PREAMBLE
|
||||
|
||||
protected:
|
||||
void updateCollider(rp::PhysicsCommon* common) override;
|
||||
static void createWedgeShape(rp::PhysicsCommon* common);
|
||||
|
||||
friend Workspace;
|
||||
public:
|
||||
WedgePart();
|
||||
WedgePart(PartConstructParams params);
|
||||
|
|
|
@ -23,7 +23,7 @@ Script::~Script() {
|
|||
}
|
||||
|
||||
void Script::Run() {
|
||||
std::shared_ptr<ScriptContext> scriptContext = dataModel().value()->GetService<ScriptContext>();
|
||||
std::shared_ptr<ScriptContext> scriptContext = dataModel()->GetService<ScriptContext>();
|
||||
|
||||
lua_State* L = scriptContext->state;
|
||||
int top = lua_gettop(L);
|
||||
|
|
|
@ -18,8 +18,8 @@ void JointsService::InitService() {
|
|||
}
|
||||
}
|
||||
|
||||
std::optional<std::shared_ptr<Workspace>> JointsService::jointWorkspace() {
|
||||
if (!dataModel()) return std::nullopt;
|
||||
nullable std::shared_ptr<Workspace> JointsService::jointWorkspace() {
|
||||
if (!dataModel()) return nullptr;
|
||||
|
||||
return dataModel().value()->FindService<Workspace>();
|
||||
return dataModel()->FindService<Workspace>();
|
||||
}
|
|
@ -3,10 +3,10 @@
|
|||
#include "objects/annotation.h"
|
||||
#include "objects/base/service.h"
|
||||
|
||||
class DEF_INST_SERVICE JointsService : public Service {
|
||||
class DEF_INST_SERVICE_(hidden) JointsService : public Service {
|
||||
AUTOGEN_PREAMBLE
|
||||
private:
|
||||
std::optional<std::shared_ptr<Workspace>> jointWorkspace();
|
||||
nullable std::shared_ptr<Workspace> jointWorkspace();
|
||||
protected:
|
||||
void InitService() override;
|
||||
bool initialized = false;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "objects/datamodel.h"
|
||||
#include "objects/service/workspace.h"
|
||||
#include "timeutil.h"
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include "luaapis.h" // IWYU pragma: keep
|
||||
|
@ -15,6 +16,7 @@ const char* WRAPPER_SRC = "local func, errhandler = ... return function(...) loc
|
|||
|
||||
int g_wait(lua_State*);
|
||||
int g_delay(lua_State*);
|
||||
int g_tick(lua_State*);
|
||||
static int g_print(lua_State*);
|
||||
static int g_require(lua_State*);
|
||||
static const luaL_Reg luaglobals [] = {
|
||||
|
@ -59,10 +61,10 @@ void ScriptContext::InitService() {
|
|||
// Add other globals
|
||||
lua_getglobal(state, "_G");
|
||||
|
||||
InstanceRef(dataModel().value()).PushLuaValue(state);
|
||||
InstanceRef(dataModel()).PushLuaValue(state);
|
||||
lua_setfield(state, -2, "game");
|
||||
|
||||
InstanceRef(dataModel().value()->GetService<Workspace>()).PushLuaValue(state);
|
||||
InstanceRef(dataModel()->GetService<Workspace>()).PushLuaValue(state);
|
||||
lua_setfield(state, -2, "workspace");
|
||||
|
||||
lua_pushlightuserdata(state, this);
|
||||
|
@ -73,6 +75,9 @@ void ScriptContext::InitService() {
|
|||
lua_pushcclosure(state, g_delay, 1);
|
||||
lua_setfield(state, -2, "delay");
|
||||
|
||||
lua_pushcclosure(state, g_tick, 0);
|
||||
lua_setfield(state, -2, "tick");
|
||||
|
||||
lua_pop(state, 1); // _G
|
||||
|
||||
// Add wrapper function
|
||||
|
@ -242,4 +247,14 @@ int g_delay(lua_State* L) {
|
|||
scriptContext->PushThreadSleep(Lt, secs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int g_tick(lua_State* L) {
|
||||
std::chrono::time_point now_local = std::chrono::current_zone()->to_local(std::chrono::system_clock::now());
|
||||
std::chrono::microseconds us = std::chrono::duration_cast<std::chrono::microseconds>(now_local.time_since_epoch());
|
||||
uint64_t _10millis = us.count() / 100;
|
||||
double secs = (double)_10millis / 10000;
|
||||
|
||||
lua_pushnumber(L, secs);
|
||||
return 1;
|
||||
}
|
|
@ -15,7 +15,7 @@ struct SleepingThread {
|
|||
|
||||
class Script;
|
||||
|
||||
class DEF_INST_SERVICE ScriptContext : public Service {
|
||||
class DEF_INST_SERVICE_(hidden) ScriptContext : public Service {
|
||||
AUTOGEN_PREAMBLE
|
||||
|
||||
std::vector<SleepingThread> sleepingThreads;
|
||||
|
|
|
@ -14,7 +14,7 @@ void ServerScriptService::InitService() {
|
|||
}
|
||||
|
||||
void ServerScriptService::OnRun() {
|
||||
auto workspace = dataModel().value()->GetService<Workspace>();
|
||||
auto workspace = dataModel()->GetService<Workspace>();
|
||||
for (auto it = workspace->GetDescendantsStart(); it != workspace->GetDescendantsEnd(); it++) {
|
||||
if (!it->IsA<Script>()) continue;
|
||||
it->CastTo<Script>().expect()->Run();
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
// Container class for server scripts
|
||||
// Also handles/manages running server scripts on run
|
||||
class DEF_INST_SERVICE_(explorer_icon="server-scripts") ServerScriptService : public Service {
|
||||
class DEF_INST_SERVICE_(explorer_icon="server-scripts", hidden) ServerScriptService : public Service {
|
||||
AUTOGEN_PREAMBLE
|
||||
protected:
|
||||
void InitService() override;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class DEF_INST_SERVICE Selection : public Service {
|
||||
class DEF_INST_SERVICE_(hidden) Selection : public Service {
|
||||
AUTOGEN_PREAMBLE
|
||||
private:
|
||||
std::vector<std::shared_ptr<Instance>> selection;
|
||||
|
|
|
@ -9,88 +9,27 @@
|
|||
#include "objects/service/jointsservice.h"
|
||||
#include "objects/joint/jointinstance.h"
|
||||
#include "objects/datamodel.h"
|
||||
#include "physics/util.h"
|
||||
#include "timeutil.h"
|
||||
#include <memory>
|
||||
#include <reactphysics3d/collision/CollisionCallback.h>
|
||||
#include <reactphysics3d/collision/OverlapCallback.h>
|
||||
#include <reactphysics3d/engine/PhysicsCommon.h>
|
||||
|
||||
rp::PhysicsCommon* Workspace::physicsCommon = new rp::PhysicsCommon;
|
||||
|
||||
Workspace::Workspace(): Service(&TYPE), physicsEventListener(this) {
|
||||
physicsWorld = physicsCommon->createPhysicsWorld();
|
||||
Workspace::Workspace(): Service(&TYPE), physicsWorld(std::make_shared<PhysWorld>()) {
|
||||
}
|
||||
|
||||
Workspace::~Workspace() {
|
||||
if (physicsCommon)
|
||||
physicsCommon->destroyPhysicsWorld(physicsWorld);
|
||||
}
|
||||
|
||||
PhysicsEventListener::PhysicsEventListener(Workspace* parent) : workspace(parent) {}
|
||||
|
||||
void PhysicsEventListener::onContact(const rp::CollisionCallback::CallbackData& data) {
|
||||
workspace->contactQueueLock.lock();
|
||||
for (size_t i = 0; i < data.getNbContactPairs(); i++) {
|
||||
auto pair = data.getContactPair(i);
|
||||
auto type = pair.getEventType();
|
||||
if (type == rp::CollisionCallback::ContactPair::EventType::ContactStay) continue;
|
||||
|
||||
if (type == reactphysics3d::CollisionCallback::ContactPair::EventType::ContactStay)
|
||||
continue;
|
||||
|
||||
ContactItem contact;
|
||||
contact.part0 = reinterpret_cast<BasePart*>(pair.getBody1()->getUserData())->shared<BasePart>();
|
||||
contact.part1 = reinterpret_cast<BasePart*>(pair.getBody2()->getUserData())->shared<BasePart>();
|
||||
contact.action = type == reactphysics3d::CollisionCallback::ContactPair::EventType::ContactStart ? ContactItem::CONTACTITEM_TOUCHED : ContactItem::CONTACTITEM_TOUCHENDED;
|
||||
|
||||
workspace->contactQueue.push(contact);
|
||||
}
|
||||
workspace->contactQueueLock.unlock();
|
||||
}
|
||||
|
||||
void PhysicsEventListener::onTrigger(const rp::OverlapCallback::CallbackData& data) {
|
||||
workspace->contactQueueLock.lock();
|
||||
for (size_t i = 0; i < data.getNbOverlappingPairs(); i++) {
|
||||
auto pair = data.getOverlappingPair(i);
|
||||
auto type = pair.getEventType();
|
||||
if (type == rp::OverlapCallback::OverlapPair::EventType::OverlapStay) continue;
|
||||
|
||||
auto part0 = reinterpret_cast<BasePart*>(pair.getBody1()->getUserData())->shared<BasePart>();
|
||||
auto part1 = reinterpret_cast<BasePart*>(pair.getBody2()->getUserData())->shared<BasePart>();
|
||||
|
||||
if (type == reactphysics3d::OverlapCallback::OverlapPair::EventType::OverlapStart) {
|
||||
part0->Touched->Fire({ (Variant)InstanceRef(part1) });
|
||||
part1->Touched->Fire({ (Variant)InstanceRef(part0) });
|
||||
} else if (type == reactphysics3d::OverlapCallback::OverlapPair::EventType::OverlapExit) {
|
||||
part0->TouchEnded->Fire({ (Variant)InstanceRef(part1) });
|
||||
part1->TouchEnded->Fire({ (Variant)InstanceRef(part0) });
|
||||
}
|
||||
}
|
||||
workspace->contactQueueLock.unlock();
|
||||
}
|
||||
Workspace::~Workspace() = default;
|
||||
|
||||
void Workspace::InitService() {
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
|
||||
physicsWorld->setGravity(rp::Vector3(0, -196.2, 0));
|
||||
// world->setContactsPositionCorrectionTechnique(rp3d::ContactsPositionCorrectionTechnique::BAUMGARTE_CONTACTS);
|
||||
physicsWorld->setNbIterationsPositionSolver(2000);
|
||||
physicsWorld->setNbIterationsVelocitySolver(2000);
|
||||
// physicsWorld->setSleepLinearVelocity(10);
|
||||
// physicsWorld->setSleepAngularVelocity(5);
|
||||
|
||||
physicsWorld->setEventListener(&physicsEventListener);
|
||||
|
||||
// Create meshes
|
||||
WedgePart::createWedgeShape(physicsCommon);
|
||||
// WedgePart::createWedgeShape(physicsCommon);
|
||||
}
|
||||
|
||||
// Sync all parts
|
||||
void Workspace::OnRun() {
|
||||
// Make joints
|
||||
for (auto it = this->GetDescendantsStart(); it != this->GetDescendantsEnd(); it++) {
|
||||
std::shared_ptr<Instance> obj = *it;
|
||||
if (!obj->IsA<BasePart>()) continue;
|
||||
std::shared_ptr<BasePart> part = obj->CastTo<BasePart>().expect();
|
||||
if (!it->IsA<BasePart>()) continue;
|
||||
std::shared_ptr<BasePart> part = it->CastTo<BasePart>().expect();
|
||||
part->MakeJoints();
|
||||
}
|
||||
|
||||
|
@ -102,211 +41,29 @@ void Workspace::InitService() {
|
|||
joint->UpdateProperty("Part0");
|
||||
}
|
||||
|
||||
for (auto obj : dataModel().value()->GetService<JointsService>()->GetChildren()) {
|
||||
for (auto obj : dataModel()->GetService<JointsService>()->GetChildren()) {
|
||||
if (!obj->IsA<JointInstance>()) continue;
|
||||
std::shared_ptr<JointInstance> joint = obj->CastTo<JointInstance>().expect();
|
||||
joint->UpdateProperty("Part0");
|
||||
}
|
||||
}
|
||||
|
||||
void Workspace::updatePartPhysics(std::shared_ptr<BasePart> part) {
|
||||
rp::Transform transform = part->cframe;
|
||||
if (!part->rigidBody) {
|
||||
part->rigidBody = physicsWorld->createRigidBody(transform);
|
||||
} else {
|
||||
part->rigidBody->setTransform(transform);
|
||||
}
|
||||
|
||||
part->updateCollider(physicsCommon);
|
||||
|
||||
part->rigidBody->setType(part->anchored ? rp::BodyType::STATIC : rp::BodyType::DYNAMIC);
|
||||
part->rigidBody->getCollider(0)->setCollisionCategoryBits(0b11);
|
||||
|
||||
part->rigidBody->getCollider(0)->setIsSimulationCollider(part->canCollide);
|
||||
part->rigidBody->getCollider(0)->setIsTrigger(!part->canCollide);
|
||||
|
||||
rp::Material& material = part->rigidBody->getCollider(0)->getMaterial();
|
||||
material.setFrictionCoefficient(0.35);
|
||||
material.setMassDensity(1.f);
|
||||
|
||||
//https://github.com/DanielChappuis/reactphysics3d/issues/170#issuecomment-691514860
|
||||
part->rigidBody->updateMassFromColliders();
|
||||
part->rigidBody->updateLocalInertiaTensorFromColliders();
|
||||
|
||||
part->rigidBody->setLinearVelocity(part->velocity);
|
||||
// part->rigidBody->setMass(density * part->size.x * part->size.y * part->size.z);
|
||||
|
||||
part->rigidBody->setUserData(&*part);
|
||||
}
|
||||
|
||||
void Workspace::ProcessContactEvents() {
|
||||
contactQueueLock.lock();
|
||||
while (!contactQueue.empty()) {
|
||||
ContactItem& contact = contactQueue.front();
|
||||
contactQueue.pop();
|
||||
if (contact.action == ContactItem::CONTACTITEM_TOUCHED) {
|
||||
contact.part0->Touched->Fire({ (Variant)InstanceRef(contact.part1) });
|
||||
contact.part1->Touched->Fire({ (Variant)InstanceRef(contact.part0) });
|
||||
} else if (contact.action == ContactItem::CONTACTITEM_TOUCHENDED) {
|
||||
contact.part0->TouchEnded->Fire({ (Variant)InstanceRef(contact.part1) });
|
||||
contact.part1->TouchEnded->Fire({ (Variant)InstanceRef(contact.part0) });
|
||||
}
|
||||
}
|
||||
contactQueueLock.unlock();
|
||||
}
|
||||
|
||||
void Workspace::SyncPartPhysics(std::shared_ptr<BasePart> part) {
|
||||
if (globalPhysicsLock.try_lock()) {
|
||||
updatePartPhysics(part);
|
||||
globalPhysicsLock.unlock();
|
||||
} else {
|
||||
part->rigidBodyDirty = true;
|
||||
}
|
||||
physicsWorld->syncBodyProperties(part);
|
||||
}
|
||||
|
||||
tu_time_t physTime;
|
||||
void Workspace::PhysicsStep(float deltaTime) {
|
||||
tu_time_t startTime = tu_clock_micros();
|
||||
|
||||
std::scoped_lock lock(globalPhysicsLock);
|
||||
physicsWorld->update(std::min(deltaTime / 2, (1/60.f)));
|
||||
|
||||
// Update queued objects
|
||||
queueLock.lock();
|
||||
for (QueueItem item : bodyQueue) {
|
||||
if (item.action == QueueItem::QUEUEITEM_ADD) {
|
||||
simulatedBodies.push_back(item.part);
|
||||
item.part->simulationTicket = --simulatedBodies.end();
|
||||
} else if (item.part->simulationTicket.has_value()) {
|
||||
simulatedBodies.erase(item.part->simulationTicket.value());
|
||||
item.part->simulationTicket = std::nullopt;
|
||||
}
|
||||
}
|
||||
queueLock.unlock();
|
||||
|
||||
// TODO: Add list of tracked parts in workspace based on their ancestry using inWorkspace property of Instance
|
||||
for (std::shared_ptr<BasePart> part : simulatedBodies) {
|
||||
// If the part's body is dirty, update it now instead
|
||||
if (part->rigidBodyDirty) {
|
||||
updatePartPhysics(part);
|
||||
part->rigidBodyDirty = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!part->rigidBody) continue;
|
||||
|
||||
// Sync properties
|
||||
const rp::Transform& transform = part->rigidBody->getTransform();
|
||||
part->cframe = CFrame(transform);
|
||||
part->velocity = part->rigidBody->getLinearVelocity();
|
||||
|
||||
// part->rigidBody->enableGravity(true);
|
||||
// RotateV/Motor joint
|
||||
for (auto& joint : part->secondaryJoints) {
|
||||
if (joint.expired() || !joint.lock()->IsA("RotateV")) continue;
|
||||
|
||||
std::shared_ptr<JointInstance> motor = joint.lock()->CastTo<JointInstance>().expect();
|
||||
float rate = motor->part0.lock()->GetSurfaceParamB(-motor->c0.LookVector().Unit()) * 30;
|
||||
// part->rigidBody->enableGravity(false);
|
||||
part->rigidBody->setAngularVelocity(-(motor->part0.lock()->cframe * motor->c0).LookVector() * rate);
|
||||
}
|
||||
physicsWorld->step(deltaTime);
|
||||
|
||||
for (std::shared_ptr<BasePart> part : physicsWorld->getSimulatedBodies()) {
|
||||
// Destroy fallen parts
|
||||
if (part->cframe.Position().Y() < this->fallenPartsDestroyHeight) {
|
||||
auto parent = part->GetParent();
|
||||
part->Destroy();
|
||||
|
||||
// If the parent of the part is a Model, destroy it too
|
||||
if (parent.has_value() && parent.value()->IsA("Model"))
|
||||
parent.value()->Destroy();
|
||||
if (parent != nullptr && parent->IsA("Model"))
|
||||
parent->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
physTime = tu_clock_micros() - startTime;
|
||||
}
|
||||
|
||||
|
||||
RaycastResult::RaycastResult(const rp::RaycastInfo& raycastInfo)
|
||||
: worldPoint(raycastInfo.worldPoint)
|
||||
, worldNormal(raycastInfo.worldNormal)
|
||||
, hitFraction(raycastInfo.hitFraction)
|
||||
, triangleIndex(raycastInfo.triangleIndex)
|
||||
, body(raycastInfo.body)
|
||||
, collider(raycastInfo.collider) {}
|
||||
|
||||
class NearestRayHit : public rp::RaycastCallback {
|
||||
rp::Vector3 startPos;
|
||||
std::optional<RaycastFilter> filter;
|
||||
|
||||
std::optional<RaycastResult> nearestHit;
|
||||
float nearestHitDistance = -1;
|
||||
|
||||
// Order is not guaranteed, so we have to figure out the nearest object using a more sophisticated algorith,
|
||||
rp::decimal notifyRaycastHit(const rp::RaycastInfo& raycastInfo) override {
|
||||
// If the detected object is further away than the nearest object, continue.
|
||||
int distance = (raycastInfo.worldPoint - startPos).length();
|
||||
if (nearestHitDistance != -1 && distance >= nearestHitDistance)
|
||||
return 1;
|
||||
|
||||
if (!filter) {
|
||||
nearestHit = raycastInfo;
|
||||
nearestHitDistance = distance;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::shared_ptr<BasePart> part = partFromBody(raycastInfo.body);
|
||||
FilterResult result = filter.value()(part);
|
||||
if (result == FilterResult::BLOCK) {
|
||||
nearestHit = std::nullopt;
|
||||
nearestHitDistance = distance;
|
||||
return 1;
|
||||
} else if (result == FilterResult::TARGET) {
|
||||
nearestHit = raycastInfo;
|
||||
nearestHitDistance = distance;
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
};
|
||||
|
||||
public:
|
||||
NearestRayHit(rp::Vector3 startPos, std::optional<RaycastFilter> filter = std::nullopt) : startPos(startPos), filter(filter) {}
|
||||
std::optional<const RaycastResult> getNearestHit() { return nearestHit; };
|
||||
};
|
||||
|
||||
std::optional<const RaycastResult> Workspace::CastRayNearest(glm::vec3 point, glm::vec3 rotation, float maxLength, std::optional<RaycastFilter> filter, unsigned short categoryMaskBits) {
|
||||
// std::scoped_lock lock(globalPhysicsLock);
|
||||
rp::Ray ray(glmToRp(point), glmToRp(glm::normalize(rotation)) * maxLength);
|
||||
NearestRayHit rayHit(glmToRp(point), filter);
|
||||
physicsWorld->raycast(ray, &rayHit, categoryMaskBits);
|
||||
return rayHit.getNearestHit();
|
||||
}
|
||||
|
||||
void Workspace::DestroyRigidBody(rp::RigidBody* rigidBody) {
|
||||
std::scoped_lock lock(globalPhysicsLock);
|
||||
physicsWorld->destroyRigidBody(rigidBody);
|
||||
}
|
||||
|
||||
void Workspace::DestroyJoint(rp::Joint* joint) {
|
||||
std::scoped_lock lock(globalPhysicsLock);
|
||||
physicsWorld->destroyJoint(joint);
|
||||
}
|
||||
|
||||
rp::Joint* Workspace::CreateJoint(const rp::JointInfo& jointInfo) {
|
||||
std::scoped_lock lock(globalPhysicsLock);
|
||||
rp::Joint* joint = physicsWorld->createJoint(jointInfo);
|
||||
|
||||
return joint;
|
||||
}
|
||||
|
||||
void Workspace::AddBody(std::shared_ptr<BasePart> part) {
|
||||
queueLock.lock();
|
||||
bodyQueue.push_back({part, QueueItem::QUEUEITEM_ADD});
|
||||
part->rigidBodyDirty = true;
|
||||
queueLock.unlock();
|
||||
}
|
||||
|
||||
void Workspace::RemoveBody(std::shared_ptr<BasePart> part) {
|
||||
queueLock.lock();
|
||||
bodyQueue.push_back({part, QueueItem::QUEUEITEM_REMOVE});
|
||||
queueLock.unlock();
|
||||
}
|
|
@ -2,35 +2,13 @@
|
|||
|
||||
#include "objects/annotation.h"
|
||||
#include "objects/base/service.h"
|
||||
#include "physics/world.h"
|
||||
#include "utils.h"
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <reactphysics3d/body/RigidBody.h>
|
||||
#include <reactphysics3d/engine/EventListener.h>
|
||||
#include <reactphysics3d/engine/PhysicsCommon.h>
|
||||
#include <reactphysics3d/engine/PhysicsWorld.h>
|
||||
|
||||
namespace rp = reactphysics3d;
|
||||
|
||||
struct RaycastResult {
|
||||
rp::Vector3 worldPoint;
|
||||
rp::Vector3 worldNormal;
|
||||
rp::decimal hitFraction;
|
||||
int triangleIndex;
|
||||
rp::Body* body;
|
||||
rp::Collider* collider;
|
||||
|
||||
RaycastResult(const rp::RaycastInfo& raycastInfo);
|
||||
};
|
||||
|
||||
enum FilterResult {
|
||||
TARGET, // The object is captured
|
||||
BLOCK, // The object blocks any objects behind it, but is not captured
|
||||
PASS, // The object is transparent, ignore it
|
||||
};
|
||||
|
||||
class BasePart;
|
||||
class Snap;
|
||||
|
@ -38,21 +16,6 @@ class Weld;
|
|||
class Rotate;
|
||||
class RotateV;
|
||||
|
||||
#ifndef __SIMULATION_TICKET
|
||||
#define __SIMULATION_TICKET
|
||||
typedef std::list<std::shared_ptr<BasePart>>::iterator SimulationTicket;
|
||||
#endif
|
||||
|
||||
typedef std::function<FilterResult(std::shared_ptr<BasePart>)> RaycastFilter;
|
||||
|
||||
struct QueueItem {
|
||||
std::shared_ptr<BasePart> part;
|
||||
enum {
|
||||
QUEUEITEM_ADD,
|
||||
QUEUEITEM_REMOVE,
|
||||
} action;
|
||||
};
|
||||
|
||||
struct ContactItem {
|
||||
std::shared_ptr<BasePart> part0;
|
||||
std::shared_ptr<BasePart> part1;
|
||||
|
@ -62,40 +25,23 @@ struct ContactItem {
|
|||
} action;
|
||||
};
|
||||
|
||||
class Workspace;
|
||||
class PhysicsEventListener : public rp::EventListener {
|
||||
friend Workspace;
|
||||
Workspace* workspace;
|
||||
|
||||
PhysicsEventListener(Workspace*);
|
||||
|
||||
void onContact(const rp::CollisionCallback::CallbackData&) override;
|
||||
void onTrigger(const rp::OverlapCallback::CallbackData&) override;
|
||||
};
|
||||
|
||||
class DEF_INST_SERVICE_(explorer_icon="workspace") Workspace : public Service {
|
||||
AUTOGEN_PREAMBLE
|
||||
|
||||
friend PhysicsEventListener;
|
||||
|
||||
std::list<std::shared_ptr<BasePart>> simulatedBodies;
|
||||
std::list<QueueItem> bodyQueue;
|
||||
std::queue<ContactItem> contactQueue;
|
||||
std::mutex contactQueueLock;
|
||||
rp::PhysicsWorld* physicsWorld;
|
||||
static rp::PhysicsCommon* physicsCommon;
|
||||
PhysicsEventListener physicsEventListener;
|
||||
|
||||
void updatePartPhysics(std::shared_ptr<BasePart> part);
|
||||
std::shared_ptr<PhysWorld> physicsWorld;
|
||||
friend PhysWorld;
|
||||
protected:
|
||||
void InitService() override;
|
||||
void OnRun() override;
|
||||
bool initialized = false;
|
||||
|
||||
public:
|
||||
Workspace();
|
||||
~Workspace();
|
||||
|
||||
std::mutex globalPhysicsLock;
|
||||
std::recursive_mutex queueLock;
|
||||
|
||||
DEF_PROP float fallenPartsDestroyHeight = -500;
|
||||
|
@ -103,15 +49,13 @@ public:
|
|||
// static inline std::shared_ptr<Workspace> New() { return std::make_shared<Workspace>(); };
|
||||
static inline std::shared_ptr<Instance> Create() { return std::make_shared<Workspace>(); };
|
||||
|
||||
void AddBody(std::shared_ptr<BasePart> part);
|
||||
void RemoveBody(std::shared_ptr<BasePart> part);
|
||||
void DestroyRigidBody(rp::RigidBody* rigidBody);
|
||||
inline void AddBody(std::shared_ptr<BasePart> part) { physicsWorld->addBody(part); }
|
||||
inline void RemoveBody(std::shared_ptr<BasePart> part) { physicsWorld->removeBody(part); }
|
||||
void SyncPartPhysics(std::shared_ptr<BasePart> part);
|
||||
|
||||
rp::Joint* CreateJoint(const rp::JointInfo& jointInfo);
|
||||
void DestroyJoint(rp::Joint* joint);
|
||||
inline PhysJoint CreateJoint(PhysJointInfo& info, std::shared_ptr<BasePart> part0, std::shared_ptr<BasePart> part1) { return physicsWorld->createJoint(info, part0, part1); }
|
||||
inline void DestroyJoint(PhysJoint joint) { physicsWorld->destroyJoint(joint); }
|
||||
|
||||
void ProcessContactEvents();
|
||||
void PhysicsStep(float deltaTime);
|
||||
std::optional<const RaycastResult> CastRayNearest(glm::vec3 point, glm::vec3 rotation, float maxLength, std::optional<RaycastFilter> filter = std::nullopt, unsigned short categoryMaskBits = 0xFFFF);
|
||||
inline std::optional<const RaycastResult> CastRayNearest(glm::vec3 point, glm::vec3 rotation, float maxLength, std::optional<RaycastFilter> filter = std::nullopt, unsigned short categoryMaskBits = 0xFFFF) { return physicsWorld->castRay(point, rotation, maxLength, filter, categoryMaskBits); }
|
||||
};
|
|
@ -1,13 +1,8 @@
|
|||
#include "panic.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include "logger.h"
|
||||
#include "platform.h"
|
||||
|
||||
#ifdef _NDEBUG
|
||||
#define NDEBUG
|
||||
#endif
|
||||
|
||||
bool trySafeAbort = false;
|
||||
void panic() {
|
||||
// We've already been here, safe aborting has failed.
|
||||
|
|
|
@ -61,14 +61,16 @@ PartAssembly PartAssembly::FromSelection(std::shared_ptr<Selection> selection) {
|
|||
|
||||
void PartAssembly::SetCollisionsEnabled(bool enabled) {
|
||||
for (auto part : parts) {
|
||||
part->rigidBody->getCollider(0)->setIsWorldQueryCollider(enabled);
|
||||
part->rigidBody.setCollisionsEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
void PartAssembly::SetOrigin(CFrame newOrigin) {
|
||||
for (auto part : parts) {
|
||||
part->cframe = newOrigin * (_assemblyOrigin.Inverse() * part->cframe);
|
||||
part->velocity = 0; // Reset velocity
|
||||
part->UpdateProperty("CFrame");
|
||||
part->UpdateProperty("Velocity");
|
||||
// sendPropertyUpdatedSignal(part, "CFrame", Variant(part->cframe));
|
||||
}
|
||||
|
||||
|
@ -78,12 +80,15 @@ void PartAssembly::SetOrigin(CFrame newOrigin) {
|
|||
void PartAssembly::TransformBy(CFrame transform) {
|
||||
for (auto part : parts) {
|
||||
part->cframe = transform * part->cframe;
|
||||
part->velocity = 0; // Reset velocity
|
||||
part->UpdateProperty("CFrame");
|
||||
part->UpdateProperty("Position");
|
||||
part->UpdateProperty("Rotation");
|
||||
part->UpdateProperty("Velocity");
|
||||
sendPropertyUpdatedSignal(part, "CFrame", Variant(part->cframe));
|
||||
sendPropertyUpdatedSignal(part, "Position", Variant(part->cframe));
|
||||
sendPropertyUpdatedSignal(part, "Rotation", Variant(part->cframe));
|
||||
sendPropertyUpdatedSignal(part, "Velocity", Variant(part->cframe));
|
||||
}
|
||||
|
||||
_assemblyOrigin = transform * _assemblyOrigin;
|
||||
|
@ -127,6 +132,7 @@ std::vector<PartTransformState> PartAssembly::GetCurrentTransforms() {
|
|||
t.part = part;
|
||||
t.cframe = part->cframe;
|
||||
t.size = part->size;
|
||||
t.velocity = part->velocity;
|
||||
transforms.push_back(t);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ class Selection;
|
|||
struct PartTransformState {
|
||||
std::shared_ptr<BasePart> part;
|
||||
Vector3 size;
|
||||
Vector3 velocity;
|
||||
CFrame cframe;
|
||||
};
|
||||
|
||||
|
|
44
core/src/physics/convert.h
Normal file
44
core/src/physics/convert.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
#pragma once
|
||||
#include "datatypes/cframe.h"
|
||||
#include "datatypes/vector.h"
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <glm/ext.hpp>
|
||||
|
||||
#include <Jolt/Jolt.h>
|
||||
|
||||
template <typename T, typename F>
|
||||
T convert(F vec) = delete;
|
||||
|
||||
// Vector3
|
||||
|
||||
template <>
|
||||
inline Vector3 convert<Vector3>(JPH::Vec3 vec) {
|
||||
return Vector3(vec.GetX(), vec.GetY(), vec.GetZ());
|
||||
}
|
||||
|
||||
template <>
|
||||
inline JPH::Vec3 convert<JPH::Vec3>(Vector3 vec) {
|
||||
return JPH::Vec3(vec.X(), vec.Y(), vec.Z());
|
||||
}
|
||||
|
||||
template <>
|
||||
inline glm::vec3 convert<glm::vec3>(JPH::Vec3 vec) {
|
||||
return glm::vec3(vec.GetX(), vec.GetY(), vec.GetZ());
|
||||
}
|
||||
|
||||
template <>
|
||||
inline JPH::Vec3 convert<JPH::Vec3>(glm::vec3 vec) {
|
||||
return JPH::Vec3(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
// Quaternion
|
||||
|
||||
template <>
|
||||
inline glm::quat convert<glm::quat>(JPH::Quat quat) {
|
||||
return glm::quat(quat.GetW(), quat.GetX(), quat.GetY(), quat.GetZ());
|
||||
}
|
||||
|
||||
template <>
|
||||
inline JPH::Quat convert<JPH::Quat>(glm::quat quat) {
|
||||
return JPH::Quat(quat.x, quat.y, quat.z, quat.w);
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
#pragma once
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <memory>
|
||||
#include <reactphysics3d/body/Body.h>
|
||||
#include <reactphysics3d/mathematics/Matrix3x3.h>
|
||||
#include <reactphysics3d/mathematics/Quaternion.h>
|
||||
#include <reactphysics3d/mathematics/Vector3.h>
|
||||
#include <reactphysics3d/mathematics/mathematics.h>
|
||||
#include <glm/ext.hpp>
|
||||
#include "objects/part/part.h"
|
||||
|
||||
namespace rp = reactphysics3d;
|
||||
|
||||
inline rp::Vector3 glmToRp(glm::vec3 vec) {
|
||||
return rp::Vector3(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
inline rp::Quaternion glmToRp(glm::quat quat) {
|
||||
return rp::Quaternion(quat.w, rp::Vector3(quat.x, quat.y, quat.z));
|
||||
}
|
||||
|
||||
// inline rp::Matrix3x3 glmToRp(glm::mat3 mat) {
|
||||
// return (rp::Quaternion)glmToRp((glm::quat)mat);
|
||||
// }
|
||||
|
||||
inline glm::vec3 rpToGlm(rp::Vector3 vec) {
|
||||
return glm::vec3(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
inline glm::quat rpToGlm(rp::Quaternion quat) {
|
||||
return glm::quat(quat.w, quat.x, quat.y, quat.z);
|
||||
}
|
||||
|
||||
// Make this std::optional
|
||||
inline std::shared_ptr<BasePart> partFromBody(rp::Body* body) {
|
||||
BasePart* raw = reinterpret_cast<BasePart*>(body->getUserData());
|
||||
std::shared_ptr<BasePart> shared = std::dynamic_pointer_cast<BasePart>(raw->shared_from_this());
|
||||
return shared;
|
||||
}
|
346
core/src/physics/world.cpp
Normal file
346
core/src/physics/world.cpp
Normal file
|
@ -0,0 +1,346 @@
|
|||
#include "world.h"
|
||||
#include "datatypes/vector.h"
|
||||
#include "enum/part.h"
|
||||
#include "logger.h"
|
||||
#include "objects/part/basepart.h"
|
||||
#include "objects/part/part.h"
|
||||
#include "objects/part/wedgepart.h"
|
||||
#include "objects/service/workspace.h"
|
||||
#include "physics/convert.h"
|
||||
#include "timeutil.h"
|
||||
|
||||
#include <Jolt/Jolt.h>
|
||||
#include <Jolt/Core/JobSystemThreadPool.h>
|
||||
#include <Jolt/Core/TempAllocator.h>
|
||||
#include <Jolt/Physics/Collision/BroadPhase/BroadPhaseLayer.h>
|
||||
#include <Jolt/Physics/Collision/ObjectLayer.h>
|
||||
#include <Jolt/Core/Factory.h>
|
||||
#include <Jolt/Core/Memory.h>
|
||||
#include <Jolt/Physics/Body/BodyCreationSettings.h>
|
||||
#include <Jolt/Physics/Body/BodyInterface.h>
|
||||
#include <Jolt/Physics/Body/MotionType.h>
|
||||
#include <Jolt/Physics/Collision/RayCast.h>
|
||||
#include <Jolt/Physics/Collision/Shape/BoxShape.h>
|
||||
#include <Jolt/Physics/Collision/Shape/SphereShape.h>
|
||||
#include <Jolt/Physics/Collision/Shape/CylinderShape.h>
|
||||
#include <Jolt/Physics/Collision/Shape/ScaledShape.h>
|
||||
#include <Jolt/Physics/Collision/Shape/ConvexHullShape.h>
|
||||
#include <Jolt/Physics/Collision/Shape/RotatedTranslatedShape.h>
|
||||
#include <Jolt/Physics/EActivation.h>
|
||||
#include <Jolt/Physics/PhysicsSettings.h>
|
||||
#include <Jolt/RegisterTypes.h>
|
||||
#include <Jolt/Physics/Collision/CollisionCollectorImpl.h>
|
||||
#include <Jolt/Physics/Collision/CastResult.h>
|
||||
#include <Jolt/Physics/Collision/Shape/SubShapeID.h>
|
||||
#include <Jolt/Physics/Body/BodyFilter.h>
|
||||
#include <Jolt/Physics/Body/BodyLockInterface.h>
|
||||
#include <Jolt/Physics/Collision/NarrowPhaseQuery.h>
|
||||
#include <Jolt/Physics/Constraints/FixedConstraint.h>
|
||||
#include <Jolt/Physics/Constraints/HingeConstraint.h>
|
||||
#include <memory>
|
||||
|
||||
static JPH::TempAllocator* allocator;
|
||||
static JPH::JobSystem* jobSystem;
|
||||
|
||||
namespace Layers
|
||||
{
|
||||
static constexpr JPH::ObjectLayer DYNAMIC = 0;
|
||||
static constexpr JPH::ObjectLayer ANCHORED = 1;
|
||||
static constexpr JPH::ObjectLayer NOCOLLIDE = 2;
|
||||
// static constexpr JPH::ObjectLayer NUM_LAYERS = 3;
|
||||
};
|
||||
|
||||
namespace BPLayers
|
||||
{
|
||||
static constexpr JPH::BroadPhaseLayer ANCHORED(0);
|
||||
static constexpr JPH::BroadPhaseLayer DYNAMIC(1);
|
||||
static constexpr JPH::BroadPhaseLayer NOCOLLIDE(2);
|
||||
static constexpr uint NUM_LAYERS(3);
|
||||
};
|
||||
|
||||
static JPH::Ref<JPH::Shape> wedgeShape;
|
||||
|
||||
void physicsInit() {
|
||||
JPH::RegisterDefaultAllocator();
|
||||
JPH::Factory::sInstance = new JPH::Factory();
|
||||
JPH::RegisterTypes();
|
||||
|
||||
allocator = new JPH::TempAllocatorImpl(10 * 1024 * 1024);
|
||||
jobSystem = new JPH::JobSystemThreadPool(JPH::cMaxPhysicsJobs, JPH::cMaxPhysicsBarriers, std::thread::hardware_concurrency() - 1);
|
||||
|
||||
// Create special shapes
|
||||
JPH::Array<JPH::Vec3> wedgeVerts;
|
||||
wedgeVerts.push_back({-1, -1, -1});
|
||||
wedgeVerts.push_back({ 1, -1, -1});
|
||||
wedgeVerts.push_back({-1, -1, 1});
|
||||
wedgeVerts.push_back({ 1, -1, 1});
|
||||
wedgeVerts.push_back({ 1, 1, 1});
|
||||
wedgeVerts.push_back({-1, 1, 1});
|
||||
// // Invisible bevel to avoid phasing
|
||||
// wedgeVerts.push_back({1, 1, 0.9});
|
||||
// wedgeVerts.push_back({0, 1, 0.9});
|
||||
|
||||
wedgeShape = JPH::ConvexHullShapeSettings(wedgeVerts).Create().Get();
|
||||
}
|
||||
|
||||
void physicsDeinit() {
|
||||
JPH::UnregisterTypes();
|
||||
delete JPH::Factory::sInstance;
|
||||
JPH::Factory::sInstance = nullptr;
|
||||
}
|
||||
|
||||
PhysWorld::PhysWorld() {
|
||||
worldImpl.Init(4096, 0, 4096, 4096, broadPhaseLayerInterface, objectBroadPhasefilter, objectLayerPairFilter);
|
||||
worldImpl.SetGravity(JPH::Vec3(0, -196, 0));
|
||||
JPH::PhysicsSettings settings = worldImpl.GetPhysicsSettings();
|
||||
// settings.mPointVelocitySleepThreshold = 0.04f; // Fix parts not sleeping
|
||||
// settings.mNumVelocitySteps *= 20;
|
||||
// settings.mNumPositionSteps *= 20;
|
||||
worldImpl.SetPhysicsSettings(settings);
|
||||
}
|
||||
|
||||
PhysWorld::~PhysWorld() {
|
||||
}
|
||||
|
||||
void PhysWorld::addBody(std::shared_ptr<BasePart> part) {
|
||||
syncBodyProperties(part);
|
||||
}
|
||||
|
||||
void PhysWorld::removeBody(std::shared_ptr<BasePart> part) {
|
||||
JPH::BodyInterface& interface = worldImpl.GetBodyInterface();
|
||||
|
||||
// https://jrouwe.github.io/JoltPhysics/index.html#sleeping-bodies
|
||||
// Wake sleeping bodies in its area before removing it
|
||||
Vector3 aabbSize = part->GetAABB();
|
||||
interface.ActivateBodiesInAABox(JPH::AABox(convert<JPH::Vec3>(part->position() - aabbSize), convert<JPH::Vec3>(part->position() + aabbSize)), {}, {});
|
||||
|
||||
interface.RemoveBody(part->rigidBody.bodyImpl->GetID());
|
||||
interface.DestroyBody(part->rigidBody.bodyImpl->GetID());
|
||||
part->rigidBody.bodyImpl = nullptr;
|
||||
}
|
||||
|
||||
JPH::Shape* makeShape(std::shared_ptr<BasePart> basePart) {
|
||||
if (std::shared_ptr<Part> part = std::dynamic_pointer_cast<Part>(basePart)) {
|
||||
switch (part->shape) {
|
||||
case PartType::Block:
|
||||
return new JPH::BoxShape(convert<JPH::Vec3>(part->size / 2.f), JPH::cDefaultConvexRadius);
|
||||
case PartType::Ball:
|
||||
return new JPH::SphereShape(glm::min(part->size.X(), part->size.Y(), part->size.Z()) / 2.f);
|
||||
case PartType::Cylinder:
|
||||
return new JPH::RotatedTranslatedShape(JPH::Vec3(), JPH::Quat::sEulerAngles(JPH::Vec3(0, 0, JPH::JPH_PI * 0.5)), new JPH::CylinderShape(part->size.X() / 2.f, glm::min(part->size.Z(), part->size.Y()) / 2.f));
|
||||
}
|
||||
} else if (std::shared_ptr<WedgePart> part = std::dynamic_pointer_cast<WedgePart>(basePart)) {
|
||||
return new JPH::ScaledShape(wedgeShape, convert<JPH::Vec3>(part->size / 2.f));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void PhysWorld::syncBodyProperties(std::shared_ptr<BasePart> part) {
|
||||
JPH::BodyInterface& interface = worldImpl.GetBodyInterface();
|
||||
|
||||
JPH::EMotionType motionType = part->anchored ? JPH::EMotionType::Static : JPH::EMotionType::Dynamic;
|
||||
JPH::EActivation activationMode = part->anchored ? JPH::EActivation::DontActivate : JPH::EActivation::Activate;
|
||||
JPH::ObjectLayer objectLayer = !part->canCollide ? Layers::NOCOLLIDE : (part->anchored ? Layers::ANCHORED : Layers::DYNAMIC);
|
||||
|
||||
JPH::Body* body = part->rigidBody.bodyImpl;
|
||||
|
||||
// Generate a new rigidBody
|
||||
if (body == nullptr) {
|
||||
JPH::Shape* shape = makeShape(part);
|
||||
JPH::BodyCreationSettings settings(shape, convert<JPH::Vec3>(part->position()), convert<JPH::Quat>((glm::quat)part->cframe.RotMatrix()), motionType, objectLayer);
|
||||
settings.mAllowDynamicOrKinematic = true;
|
||||
settings.mRestitution = 0.5;
|
||||
|
||||
body = interface.CreateBody(settings);
|
||||
body->SetUserData((JPH::uint64)part.get());
|
||||
part->rigidBody.bodyImpl = body;
|
||||
|
||||
interface.AddBody(body->GetID(), activationMode);
|
||||
interface.SetLinearVelocity(body->GetID(), convert<JPH::Vec3>(part->velocity));
|
||||
} else {
|
||||
std::shared_ptr<Part> part2 = std::dynamic_pointer_cast<Part>(part);
|
||||
bool shouldUpdateShape = (part2 != nullptr && part->rigidBody._lastShape != part2->shape) || part->rigidBody._lastSize == part->size;
|
||||
|
||||
if (shouldUpdateShape) {
|
||||
// const JPH::Shape* oldShape = body->GetShape();
|
||||
JPH::Shape* newShape = makeShape(part);
|
||||
|
||||
interface.SetShape(body->GetID(), newShape, true, activationMode);
|
||||
// Seems like Jolt manages its memory for us, so we don't need the below
|
||||
// delete oldShape;
|
||||
}
|
||||
|
||||
interface.SetObjectLayer(body->GetID(), objectLayer);
|
||||
interface.SetMotionType(body->GetID(), motionType, activationMode);
|
||||
interface.SetPositionRotationAndVelocity(body->GetID(), convert<JPH::Vec3>(part->position()), convert<JPH::Quat>((glm::quat)part->cframe.RotMatrix()), convert<JPH::Vec3>(part->velocity), /* Angular velocity is NYI: */ body->GetAngularVelocity());
|
||||
}
|
||||
|
||||
part->rigidBody._lastSize = part->size;
|
||||
if (std::shared_ptr<Part> part2 = std::dynamic_pointer_cast<Part>(part)) part->rigidBody._lastShape = part2->shape;
|
||||
}
|
||||
|
||||
tu_time_t physTime;
|
||||
void PhysWorld::step(float deltaTime) {
|
||||
tu_time_t startTime = tu_clock_micros();
|
||||
// Depending on the load, it may be necessary to call this with a differing collision step count
|
||||
// 5 seems to be a good number supporting the high gravity
|
||||
worldImpl.Update(deltaTime, 5, allocator, jobSystem);
|
||||
|
||||
JPH::BodyInterface& interface = worldImpl.GetBodyInterface();
|
||||
JPH::BodyIDVector bodyIDs;
|
||||
worldImpl.GetBodies(bodyIDs);
|
||||
for (JPH::BodyID bodyID : bodyIDs) {
|
||||
std::shared_ptr<BasePart> part = ((Instance*)interface.GetUserData(bodyID))->shared<BasePart>();
|
||||
part->cframe = CFrame(convert<Vector3>(interface.GetPosition(bodyID)), convert<glm::quat>(interface.GetRotation(bodyID)));
|
||||
}
|
||||
|
||||
physTime = tu_clock_micros() - startTime;
|
||||
}
|
||||
|
||||
PhysJoint PhysWorld::createJoint(PhysJointInfo& type, std::shared_ptr<BasePart> part0, std::shared_ptr<BasePart> part1) {
|
||||
if (part0->rigidBody.bodyImpl == nullptr
|
||||
|| part1->rigidBody.bodyImpl == nullptr
|
||||
|| !part0->workspace()
|
||||
|| !part1->workspace()
|
||||
|| part0->workspace()->physicsWorld != shared_from_this()
|
||||
|| part1->workspace()->physicsWorld != shared_from_this()
|
||||
) { Logger::fatalError("Failed to create joint between two parts due to the call being invalid"); panic(); };
|
||||
|
||||
JPH::TwoBodyConstraint* constraint;
|
||||
if (PhysFixedJointInfo* info = dynamic_cast<PhysFixedJointInfo*>(&type)) {
|
||||
JPH::FixedConstraintSettings settings;
|
||||
settings.mSpace = JPH::EConstraintSpace::LocalToBodyCOM;
|
||||
settings.mPoint1 = convert<JPH::Vec3>(info->c0.Position());
|
||||
settings.mAxisX1 = convert<JPH::Vec3>(info->c0.RightVector());
|
||||
settings.mAxisY1 = convert<JPH::Vec3>(info->c0.UpVector());
|
||||
settings.mPoint2 = convert<JPH::Vec3>(info->c1.Position());
|
||||
settings.mAxisX2 = convert<JPH::Vec3>(info->c1.RightVector());
|
||||
settings.mAxisY2 = convert<JPH::Vec3>(info->c1.UpVector());
|
||||
constraint = settings.Create(*part0->rigidBody.bodyImpl, *part1->rigidBody.bodyImpl);
|
||||
} else if (PhysRotatingJointInfo* info = dynamic_cast<PhysRotatingJointInfo*>(&type)) {
|
||||
JPH::HingeConstraintSettings settings;
|
||||
settings.mSpace = JPH::EConstraintSpace::LocalToBodyCOM;
|
||||
settings.mPoint1 = convert<JPH::Vec3>(info->c0.Position());
|
||||
settings.mNormalAxis1 = convert<JPH::Vec3>(info->c0.RightVector());
|
||||
settings.mHingeAxis1 = convert<JPH::Vec3>(info->c0.LookVector());
|
||||
settings.mPoint2 = convert<JPH::Vec3>(info->c1.Position());
|
||||
settings.mNormalAxis2 = convert<JPH::Vec3>(info->c1.RightVector());
|
||||
settings.mHingeAxis2 = convert<JPH::Vec3>(info->c1.LookVector());
|
||||
// settings.mMotorSettings = JPH::MotorSettings(1.0f, 1.0f);
|
||||
constraint = settings.Create(*part0->rigidBody.bodyImpl, *part1->rigidBody.bodyImpl);
|
||||
if (info->motorized) {
|
||||
static_cast<JPH::HingeConstraint*>(constraint)->SetMotorState(JPH::EMotorState::Velocity);
|
||||
static_cast<JPH::HingeConstraint*>(constraint)->SetTargetAngularVelocity(-info->initialVelocity);
|
||||
}
|
||||
} else {
|
||||
panic();
|
||||
}
|
||||
|
||||
worldImpl.AddConstraint(constraint);
|
||||
return { constraint };
|
||||
}
|
||||
|
||||
// WATCH OUT! This should only be called for HingeConstraints.
|
||||
// Can't use dynamic_cast because TwoBodyConstraint is not virtual
|
||||
void PhysJoint::setAngularVelocity(float velocity) {
|
||||
JPH::HingeConstraint* constraint = static_cast<JPH::HingeConstraint*>(jointImpl);
|
||||
if (!constraint) return;
|
||||
constraint->SetTargetAngularVelocity(-velocity);
|
||||
}
|
||||
|
||||
void PhysWorld::destroyJoint(PhysJoint joint) {
|
||||
worldImpl.RemoveConstraint(joint.jointImpl);
|
||||
}
|
||||
|
||||
class PhysRayCastBodyFilter : public JPH::BodyFilter {
|
||||
bool ShouldCollideLocked(const JPH::Body &inBody) const override {
|
||||
std::shared_ptr<BasePart> part = ((Instance*)inBody.GetUserData())->shared<BasePart>();
|
||||
|
||||
// Ignore specifically "hidden" parts from raycast
|
||||
// TODO: Replace this with a better system... Please.
|
||||
if (!part->rigidBody.isCollisionsEnabled()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
std::optional<const RaycastResult> PhysWorld::castRay(Vector3 point, Vector3 rotation, float maxLength, std::optional<RaycastFilter> filter, unsigned short categoryMaskBits) {
|
||||
if (filter != std::nullopt) { Logger::fatalError("The filter property of PhysWorld::castRay is not yet implemented"); panic(); };
|
||||
|
||||
const JPH::BodyLockInterface& lockInterface = worldImpl.GetBodyLockInterfaceNoLock();
|
||||
const JPH::BodyInterface& interface = worldImpl.GetBodyInterface();
|
||||
const JPH::NarrowPhaseQuery& query = worldImpl.GetNarrowPhaseQuery();
|
||||
|
||||
// First we cast a ray to find a matching part
|
||||
Vector3 end = point + rotation.Unit() * maxLength;
|
||||
JPH::RRayCast ray { convert<JPH::Vec3>(point), convert<JPH::Vec3>(end) };
|
||||
JPH::RayCastResult result;
|
||||
PhysRayCastBodyFilter bodyFilter;
|
||||
bool hitFound = query.CastRay(ray, result, {}, {}, bodyFilter);
|
||||
|
||||
// No matches found, return empty
|
||||
if (!hitFound) return std::nullopt;
|
||||
|
||||
// Next we cast a ray to find the hit surface and its world position and normal
|
||||
JPH::BodyID hitBodyId = result.mBodyID;
|
||||
std::shared_ptr<BasePart> part = ((Instance*)interface.GetUserData(hitBodyId))->shared<BasePart>();
|
||||
const JPH::Shape* shape = interface.GetShape(hitBodyId);
|
||||
|
||||
// Find the hit position and hence the surface normal of the shape at that specific point
|
||||
Vector3 hitPosition = point + rotation.Unit() * (maxLength * result.mFraction);
|
||||
JPH::Vec3 surfaceNormal = shape->GetSurfaceNormal(result.mSubShapeID2, convert<JPH::Vec3>(part->cframe.Inverse() * hitPosition));
|
||||
Vector3 worldNormal = part->cframe.Rotation() * convert<Vector3>(surfaceNormal);
|
||||
|
||||
return RaycastResult {
|
||||
.worldPoint = hitPosition,
|
||||
.worldNormal = worldNormal,
|
||||
.body = lockInterface.TryGetBody(hitBodyId),
|
||||
.hitPart = part,
|
||||
};
|
||||
}
|
||||
|
||||
uint BroadPhaseLayerInterface::GetNumBroadPhaseLayers() const {
|
||||
return BPLayers::NUM_LAYERS;
|
||||
}
|
||||
|
||||
JPH::BroadPhaseLayer BroadPhaseLayerInterface::GetBroadPhaseLayer(JPH::ObjectLayer inLayer) const {
|
||||
switch (inLayer) {
|
||||
case Layers::DYNAMIC: return BPLayers::DYNAMIC;
|
||||
case Layers::ANCHORED: return BPLayers::ANCHORED;
|
||||
case Layers::NOCOLLIDE: return BPLayers::NOCOLLIDE;
|
||||
default: panic();
|
||||
}
|
||||
}
|
||||
|
||||
const char * BroadPhaseLayerInterface::GetBroadPhaseLayerName(JPH::BroadPhaseLayer inLayer) const {
|
||||
using T = JPH::BroadPhaseLayer::Type;
|
||||
switch ((T)inLayer) {
|
||||
case (T)BPLayers::DYNAMIC: return "DYNAMIC";
|
||||
case (T)BPLayers::ANCHORED: return "ANCHORED";
|
||||
case (T)BPLayers::NOCOLLIDE: return "NOCOLLIDE";
|
||||
default: panic();
|
||||
}
|
||||
}
|
||||
|
||||
bool ObjectBroadPhaseFilter::ShouldCollide(JPH::ObjectLayer inLayer1, JPH::BroadPhaseLayer inLayer2) const {
|
||||
using T = JPH::BroadPhaseLayer::Type;
|
||||
switch ((T)inLayer2) {
|
||||
case (T)BPLayers::DYNAMIC: return true;
|
||||
case (T)BPLayers::ANCHORED: return true;
|
||||
case (T)BPLayers::NOCOLLIDE: return false;
|
||||
default: panic();
|
||||
}
|
||||
}
|
||||
|
||||
bool ObjectLayerPairFilter::ShouldCollide(JPH::ObjectLayer inLayer1, JPH::ObjectLayer inLayer2) const {
|
||||
switch (inLayer1) {
|
||||
case Layers::DYNAMIC:
|
||||
return true;
|
||||
case Layers::ANCHORED:
|
||||
return inLayer2 == Layers::DYNAMIC;
|
||||
case Layers::NOCOLLIDE:
|
||||
return false;
|
||||
default:
|
||||
panic();
|
||||
}
|
||||
}
|
126
core/src/physics/world.h
Normal file
126
core/src/physics/world.h
Normal file
|
@ -0,0 +1,126 @@
|
|||
#pragma once
|
||||
|
||||
#include "datatypes/cframe.h"
|
||||
#include "datatypes/vector.h"
|
||||
#include "enum/part.h"
|
||||
#include "utils.h"
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
#include <Jolt/Jolt.h>
|
||||
#include <Jolt/Physics/Body/Body.h>
|
||||
#include <Jolt/Physics/PhysicsSystem.h>
|
||||
#include <Jolt/Physics/Constraints/TwoBodyConstraint.h>
|
||||
|
||||
class BasePart;
|
||||
class PhysWorld;
|
||||
|
||||
struct PhysJointInfo { virtual ~PhysJointInfo() = default; protected: PhysJointInfo() = default; };
|
||||
|
||||
struct PhysFixedJointInfo : PhysJointInfo {
|
||||
CFrame c0;
|
||||
CFrame c1;
|
||||
|
||||
inline PhysFixedJointInfo(CFrame c0, CFrame c1) : c0(c0), c1(c1) {}
|
||||
};
|
||||
|
||||
struct PhysRotatingJointInfo : PhysJointInfo {
|
||||
CFrame c0;
|
||||
CFrame c1;
|
||||
bool motorized;
|
||||
float initialVelocity;
|
||||
|
||||
inline PhysRotatingJointInfo(CFrame c0, CFrame c1) : c0(c0), c1(c1), motorized(false), initialVelocity(0.f){}
|
||||
inline PhysRotatingJointInfo(CFrame c0, CFrame c1, float initialVelocity) : c0(c0), c1(c1), motorized(true), initialVelocity(initialVelocity) {}
|
||||
};
|
||||
|
||||
class PhysWorld;
|
||||
struct PhysJoint {
|
||||
public:
|
||||
JPH::TwoBodyConstraint* jointImpl;
|
||||
|
||||
void setAngularVelocity(float velocity);
|
||||
};
|
||||
|
||||
struct RaycastResult;
|
||||
class PhysRigidBody {
|
||||
JPH::Body* bodyImpl = nullptr;
|
||||
inline PhysRigidBody(JPH::Body* rigidBody) : bodyImpl(rigidBody) {}
|
||||
Vector3 _lastSize;
|
||||
PartType _lastShape;
|
||||
bool collisionsEnabled = true;
|
||||
|
||||
friend PhysWorld;
|
||||
friend RaycastResult;
|
||||
public:
|
||||
inline PhysRigidBody() {}
|
||||
|
||||
inline void setActive(bool active) { if (!bodyImpl) return; }
|
||||
inline void setCollisionsEnabled(bool enabled) { collisionsEnabled = enabled; }
|
||||
inline bool isCollisionsEnabled() { return collisionsEnabled; }
|
||||
void updateCollider(std::shared_ptr<BasePart>);
|
||||
};
|
||||
|
||||
// // Provides internal implementation-specific values from the raycast result
|
||||
// struct RaycastResultInternal {
|
||||
// rp::decimal hitFraction;
|
||||
// rp::Collider* collider;
|
||||
// };
|
||||
|
||||
struct RaycastResult {
|
||||
Vector3 worldPoint;
|
||||
Vector3 worldNormal;
|
||||
PhysRigidBody body;
|
||||
nullable std::shared_ptr<BasePart> hitPart;
|
||||
};
|
||||
|
||||
enum FilterResult {
|
||||
TARGET, // The object is captured
|
||||
BLOCK, // The object blocks any objects behind it, but is not captured
|
||||
PASS, // The object is transparent, ignore it
|
||||
};
|
||||
|
||||
class BasePart;
|
||||
typedef std::function<FilterResult(std::shared_ptr<BasePart>)> RaycastFilter;
|
||||
|
||||
class BroadPhaseLayerInterface : public JPH::BroadPhaseLayerInterface {
|
||||
uint GetNumBroadPhaseLayers() const override;
|
||||
JPH::BroadPhaseLayer GetBroadPhaseLayer(JPH::ObjectLayer inLayer) const override;
|
||||
const char * GetBroadPhaseLayerName(JPH::BroadPhaseLayer inLayer) const override;
|
||||
};
|
||||
|
||||
class ObjectBroadPhaseFilter : public JPH::ObjectVsBroadPhaseLayerFilter {
|
||||
bool ShouldCollide(JPH::ObjectLayer inLayer1, JPH::BroadPhaseLayer inLayer2) const override;
|
||||
};
|
||||
|
||||
class ObjectLayerPairFilter : public JPH::ObjectLayerPairFilter {
|
||||
bool ShouldCollide(JPH::ObjectLayer inLayer1, JPH::ObjectLayer inLayer2) const override;
|
||||
};
|
||||
|
||||
class PhysWorld : public std::enable_shared_from_this<PhysWorld> {
|
||||
BroadPhaseLayerInterface broadPhaseLayerInterface;
|
||||
ObjectBroadPhaseFilter objectBroadPhasefilter;
|
||||
ObjectLayerPairFilter objectLayerPairFilter;
|
||||
JPH::PhysicsSystem worldImpl;
|
||||
std::list<std::shared_ptr<BasePart>> simulatedBodies;
|
||||
|
||||
public:
|
||||
PhysWorld();
|
||||
~PhysWorld();
|
||||
|
||||
void step(float deltaTime);
|
||||
|
||||
void addBody(std::shared_ptr<BasePart>);
|
||||
void removeBody(std::shared_ptr<BasePart>);
|
||||
|
||||
PhysJoint createJoint(PhysJointInfo& type, std::shared_ptr<BasePart> part0, std::shared_ptr<BasePart> part1);
|
||||
void destroyJoint(PhysJoint joint);
|
||||
|
||||
inline const std::list<std::shared_ptr<BasePart>>& getSimulatedBodies() { return simulatedBodies; }
|
||||
void syncBodyProperties(std::shared_ptr<BasePart>);
|
||||
std::optional<const RaycastResult> castRay(Vector3 point, Vector3 rotation, float maxLength, std::optional<RaycastFilter> filter, unsigned short categoryMaskBits);
|
||||
};
|
||||
|
||||
void physicsInit();
|
||||
void physicsDeinit();
|
|
@ -1,8 +1,7 @@
|
|||
#include "rendering/shader.h"
|
||||
#include "rendering/texture.h"
|
||||
#include "timeutil.h"
|
||||
#include <GL/glew.h>
|
||||
#include <GL/gl.h>
|
||||
#include <glad/gl.h>
|
||||
#include <glm/ext/vector_float4.hpp>
|
||||
#include <string>
|
||||
|
||||
|
|
|
@ -2968,7 +2968,7 @@ static float OUTLINE_VERTICES[] = {
|
|||
|
||||
};
|
||||
|
||||
static float CYLINDER_VERTICES[] = {
|
||||
static float CYLINDER_CHEAP_VERTICES[] = {
|
||||
// positions // normals // texture coords
|
||||
|
||||
0.0, -0.5, 0.5, 0.2588, -0.9659, -0.0, 1.0, 0.5,
|
||||
|
@ -3106,11 +3106,391 @@ static float CYLINDER_VERTICES[] = {
|
|||
|
||||
};
|
||||
|
||||
|
||||
static float CYLINDER_VERTICES[] = {
|
||||
// positions // normals // texture coords
|
||||
|
||||
0.5, 0.0, -0.5, -0.0, -0.0, -1.0, 1.0, 0.5,
|
||||
0.5, 0.09754499999999999, -0.4903925, -0.0, 0.1951, -0.9808, 0.96875, 0.5,
|
||||
-0.5, 0.0, -0.5, -0.0, -0.0, -1.0, 1.0, 1.0,
|
||||
0.5, 0.09754499999999999, -0.4903925, -0.0, 0.1951, -0.9808, 0.96875, 0.5,
|
||||
0.5, 0.1913415, -0.46194, -0.0, 0.3827, -0.9239, 0.9375, 0.5,
|
||||
-0.5, 0.09754499999999999, -0.4903925, -0.0, 0.1951, -0.9808, 0.96875, 1.0,
|
||||
0.5, 0.1913415, -0.46194, -0.0, 0.3827, -0.9239, 0.9375, 0.5,
|
||||
0.5, 0.277785, -0.41573499999999997, -0.0, 0.5556, -0.8315, 0.90625, 0.5,
|
||||
-0.5, 0.1913415, -0.46194, -0.0, 0.3827, -0.9239, 0.9375, 1.0,
|
||||
0.5, 0.277785, -0.41573499999999997, -0.0, 0.5556, -0.8315, 0.90625, 0.5,
|
||||
0.5, 0.3535535, -0.3535535000000001, -0.0, 0.7071, -0.7071, 0.875, 0.5,
|
||||
-0.5, 0.277785, -0.41573499999999997, -0.0, 0.5556, -0.8315, 0.90625, 1.0,
|
||||
0.5, 0.3535535, -0.3535535000000001, -0.0, 0.7071, -0.7071, 0.875, 0.5,
|
||||
0.5, 0.415735, -0.27778499999999995, -0.0, 0.8315, -0.5556, 0.84375, 0.5,
|
||||
-0.5, 0.3535535, -0.3535535000000001, -0.0, 0.7071, -0.7071, 0.875, 1.0,
|
||||
0.5, 0.415735, -0.27778499999999995, -0.0, 0.8315, -0.5556, 0.84375, 0.5,
|
||||
0.5, 0.46194, -0.19134150000000005, -0.0, 0.9239, -0.3827, 0.8125, 0.5,
|
||||
-0.5, 0.415735, -0.27778499999999995, -0.0, 0.8315, -0.5556, 0.84375, 1.0,
|
||||
0.5, 0.46194, -0.19134150000000005, -0.0, 0.9239, -0.3827, 0.8125, 0.5,
|
||||
0.5, 0.4903925, -0.09754499999999999, -0.0, 0.9808, -0.1951, 0.78125, 0.5,
|
||||
-0.5, 0.4619395, -0.19134150000000005, -0.0, 0.9239, -0.3827, 0.8125, 1.0,
|
||||
0.5, 0.4903925, -0.09754499999999999, -0.0, 0.9808, -0.1951, 0.78125, 0.5,
|
||||
0.5, 0.5, 0.0, -0.0, 1.0, -0.0, 0.75, 0.5,
|
||||
-0.5, 0.4903925, -0.09754499999999999, -0.0, 0.9808, -0.1951, 0.78125, 1.0,
|
||||
0.5, 0.5, 0.0, -0.0, 1.0, -0.0, 0.75, 0.5,
|
||||
0.5, 0.4903925, 0.09754499999999999, -0.0, 0.9808, 0.1951, 0.71875, 0.5,
|
||||
-0.5, 0.5, 0.0, -0.0, 1.0, -0.0, 0.75, 1.0,
|
||||
0.5, 0.4903925, 0.09754499999999999, -0.0, 0.9808, 0.1951, 0.71875, 0.5,
|
||||
0.5, 0.46194, 0.1913415, -0.0, 0.9239, 0.3827, 0.6875, 0.5,
|
||||
-0.5, 0.4903925, 0.09754499999999999, -0.0, 0.9808, 0.1951, 0.71875, 1.0,
|
||||
0.5, 0.46194, 0.1913415, -0.0, 0.9239, 0.3827, 0.6875, 0.5,
|
||||
0.5, 0.415735, 0.277785, -0.0, 0.8315, 0.5556, 0.65625, 0.5,
|
||||
-0.5, 0.4619395, 0.1913415, -0.0, 0.9239, 0.3827, 0.6875, 1.0,
|
||||
0.5, 0.415735, 0.277785, -0.0, 0.8315, 0.5556, 0.65625, 0.5,
|
||||
0.5, 0.3535535, 0.3535535, -0.0, 0.7071, 0.7071, 0.625, 0.5,
|
||||
-0.5, 0.415735, 0.277785, -0.0, 0.8315, 0.5556, 0.65625, 1.0,
|
||||
0.5, 0.3535535, 0.3535535, -0.0, 0.7071, 0.7071, 0.625, 0.5,
|
||||
0.5, 0.277785, 0.415735, -0.0, 0.5556, 0.8315, 0.59375, 0.5,
|
||||
-0.5, 0.3535535, 0.3535535, -0.0, 0.7071, 0.7071, 0.625, 1.0,
|
||||
0.5, 0.277785, 0.415735, -0.0, 0.5556, 0.8315, 0.59375, 0.5,
|
||||
0.5, 0.1913415, 0.46194, -0.0, 0.3827, 0.9239, 0.5625, 0.5,
|
||||
-0.5, 0.277785, 0.415735, -0.0, 0.5556, 0.8315, 0.59375, 1.0,
|
||||
0.5, 0.1913415, 0.46194, -0.0, 0.3827, 0.9239, 0.5625, 0.5,
|
||||
0.5, 0.09754499999999999, 0.4903925, -0.0, 0.1951, 0.9808, 0.53125, 0.5,
|
||||
-0.5, 0.1913415, 0.46194, -0.0, 0.3827, 0.9239, 0.5625, 1.0,
|
||||
0.5, 0.09754499999999999, 0.4903925, -0.0, 0.1951, 0.9808, 0.53125, 0.5,
|
||||
0.5, 0.0, 0.5, -0.0, -0.0, 1.0, 0.5, 0.5,
|
||||
-0.5, 0.09754499999999999, 0.4903925, -0.0, 0.1951, 0.9808, 0.53125, 1.0,
|
||||
0.5, 0.0, 0.5, -0.0, -0.0, 1.0, 0.5, 0.5,
|
||||
0.5, -0.09754499999999999, 0.4903925, -0.0, -0.1951, 0.9808, 0.46875, 0.5,
|
||||
-0.5, 0.0, 0.5, -0.0, -0.0, 1.0, 0.5, 1.0,
|
||||
0.5, -0.09754499999999999, 0.4903925, -0.0, -0.1951, 0.9808, 0.46875, 0.5,
|
||||
0.5, -0.19134150000000005, 0.46194, -0.0, -0.3827, 0.9239, 0.4375, 0.5,
|
||||
-0.5, -0.09754499999999999, 0.4903925, -0.0, -0.1951, 0.9808, 0.46875, 1.0,
|
||||
0.5, -0.19134150000000005, 0.46194, -0.0, -0.3827, 0.9239, 0.4375, 0.5,
|
||||
0.5, -0.27778499999999995, 0.415735, -0.0, -0.5556, 0.8315, 0.40625, 0.5,
|
||||
-0.5, -0.19134150000000005, 0.46194, -0.0, -0.3827, 0.9239, 0.4375, 1.0,
|
||||
0.5, -0.27778499999999995, 0.415735, -0.0, -0.5556, 0.8315, 0.40625, 0.5,
|
||||
0.5, -0.3535535000000001, 0.3535535, -0.0, -0.7071, 0.7071, 0.375, 0.5,
|
||||
-0.5, -0.27778499999999995, 0.415735, -0.0, -0.5556, 0.8315, 0.40625, 1.0,
|
||||
0.5, -0.3535535000000001, 0.3535535, -0.0, -0.7071, 0.7071, 0.375, 0.5,
|
||||
0.5, -0.41573499999999997, 0.277785, -0.0, -0.8315, 0.5556, 0.34375, 0.5,
|
||||
-0.5, -0.3535535000000001, 0.3535535, -0.0, -0.7071, 0.7071, 0.375, 1.0,
|
||||
0.5, -0.41573499999999997, 0.277785, -0.0, -0.8315, 0.5556, 0.34375, 0.5,
|
||||
0.5, -0.46193949999999995, 0.1913415, -0.0, -0.9239, 0.3827, 0.3125, 0.5,
|
||||
-0.5, -0.41573499999999997, 0.277785, -0.0, -0.8315, 0.5556, 0.34375, 1.0,
|
||||
0.5, -0.46193949999999995, 0.1913415, -0.0, -0.9239, 0.3827, 0.3125, 0.5,
|
||||
0.5, -0.4903925, 0.09754499999999999, -0.0, -0.9808, 0.1951, 0.28125, 0.5,
|
||||
-0.5, -0.46194, 0.1913415, -0.0, -0.9239, 0.3827, 0.3125, 1.0,
|
||||
0.5, -0.4903925, 0.09754499999999999, -0.0, -0.9808, 0.1951, 0.28125, 0.5,
|
||||
0.5, -0.5, 0.0, -0.0, -1.0, -0.0, 0.25, 0.5,
|
||||
-0.5, -0.4903925, 0.09754499999999999, -0.0, -0.9808, 0.1951, 0.28125, 1.0,
|
||||
0.5, -0.5, 0.0, -0.0, -1.0, -0.0, 0.25, 0.5,
|
||||
0.5, -0.4903925, -0.09754499999999999, -0.0, -0.9808, -0.1951, 0.21875, 0.5,
|
||||
-0.5, -0.5, 0.0, -0.0, -1.0, -0.0, 0.25, 1.0,
|
||||
0.5, -0.4903925, -0.09754499999999999, -0.0, -0.9808, -0.1951, 0.21875, 0.5,
|
||||
0.5, -0.46193949999999995, -0.19134150000000005, -0.0, -0.9239, -0.3827, 0.1875, 0.5,
|
||||
-0.5, -0.4903925, -0.09754499999999999, -0.0, -0.9808, -0.1951, 0.21875, 1.0,
|
||||
0.5, -0.46193949999999995, -0.19134150000000005, -0.0, -0.9239, -0.3827, 0.1875, 0.5,
|
||||
0.5, -0.41573499999999997, -0.27778499999999995, -0.0, -0.8315, -0.5556, 0.15625, 0.5,
|
||||
-0.5, -0.46194, -0.19134150000000005, -0.0, -0.9239, -0.3827, 0.1875, 1.0,
|
||||
0.5, -0.41573499999999997, -0.27778499999999995, -0.0, -0.8315, -0.5556, 0.15625, 0.5,
|
||||
0.5, -0.3535535000000001, -0.3535535000000001, -0.0, -0.7071, -0.7071, 0.125, 0.5,
|
||||
-0.5, -0.41573499999999997, -0.27778499999999995, -0.0, -0.8315, -0.5556, 0.15625, 1.0,
|
||||
0.5, -0.3535535000000001, -0.3535535000000001, -0.0, -0.7071, -0.7071, 0.125, 0.5,
|
||||
0.5, -0.27778499999999995, -0.41573499999999997, -0.0, -0.5556, -0.8315, 0.09375, 0.5,
|
||||
-0.5, -0.3535535000000001, -0.3535535000000001, -0.0, -0.7071, -0.7071, 0.125, 1.0,
|
||||
0.5, -0.27778499999999995, -0.41573499999999997, -0.0, -0.5556, -0.8315, 0.09375, 0.5,
|
||||
0.5, -0.19134150000000005, -0.46194, -0.0, -0.3827, -0.9239, 0.0625, 0.5,
|
||||
-0.5, -0.27778499999999995, -0.41573499999999997, -0.0, -0.5556, -0.8315, 0.09375, 1.0,
|
||||
-0.5, 0.1913415, -0.46194, -1.0, -0.0, -0.0, 0.341844, 0.471731,
|
||||
-0.5, 0.4619395, 0.1913415, -1.0, -0.0, -0.0, 0.471731, 0.158156,
|
||||
-0.5, -0.19134150000000005, 0.46194, -1.0, -0.0, -0.0, 0.158156, 0.028269,
|
||||
0.5, -0.19134150000000005, -0.46194, -0.0, -0.3827, -0.9239, 0.0625, 0.5,
|
||||
0.5, -0.09754499999999999, -0.4903925, -0.0, -0.1951, -0.9808, 0.03125, 0.5,
|
||||
-0.5, -0.19134150000000005, -0.46194, -0.0, -0.3827, -0.9239, 0.0625, 1.0,
|
||||
0.5, -0.09754499999999999, -0.4903925, -0.0, -0.1951, -0.9808, 0.03125, 0.5,
|
||||
0.5, 0.0, -0.5, -0.0, -0.0, -1.0, 0.0, 0.5,
|
||||
-0.5, -0.09754499999999999, -0.4903925, -0.0, -0.1951, -0.9808, 0.03125, 1.0,
|
||||
0.5, -0.09754499999999999, -0.4903925, 1.0, -0.0, -0.0, 0.703178, 0.485388,
|
||||
0.5, -0.4903925, 0.09754499999999999, 1.0, -0.0, -0.0, 0.514612, 0.203178,
|
||||
0.5, 0.09754499999999999, 0.4903925, 1.0, -0.0, -0.0, 0.796822, 0.014612,
|
||||
0.5, 0.09754499999999999, -0.4903925, -0.0, 0.1951, -0.9808, 0.96875, 0.5,
|
||||
-0.5, 0.09754499999999999, -0.4903925, -0.0, 0.1951, -0.9808, 0.96875, 1.0,
|
||||
-0.5, 0.0, -0.5, -0.0, -0.0, -1.0, 1.0, 1.0,
|
||||
0.5, 0.1913415, -0.46194, -0.0, 0.3827, -0.9239, 0.9375, 0.5,
|
||||
-0.5, 0.1913415, -0.46194, -0.0, 0.3827, -0.9239, 0.9375, 1.0,
|
||||
-0.5, 0.09754499999999999, -0.4903925, -0.0, 0.1951, -0.9808, 0.96875, 1.0,
|
||||
0.5, 0.277785, -0.41573499999999997, -0.0, 0.5556, -0.8315, 0.90625, 0.5,
|
||||
-0.5, 0.277785, -0.41573499999999997, -0.0, 0.5556, -0.8315, 0.90625, 1.0,
|
||||
-0.5, 0.1913415, -0.46194, -0.0, 0.3827, -0.9239, 0.9375, 1.0,
|
||||
0.5, 0.3535535, -0.3535535000000001, -0.0, 0.7071, -0.7071, 0.875, 0.5,
|
||||
-0.5, 0.3535535, -0.3535535000000001, -0.0, 0.7071, -0.7071, 0.875, 1.0,
|
||||
-0.5, 0.277785, -0.41573499999999997, -0.0, 0.5556, -0.8315, 0.90625, 1.0,
|
||||
0.5, 0.415735, -0.27778499999999995, -0.0, 0.8315, -0.5556, 0.84375, 0.5,
|
||||
-0.5, 0.415735, -0.27778499999999995, -0.0, 0.8315, -0.5556, 0.84375, 1.0,
|
||||
-0.5, 0.3535535, -0.3535535000000001, -0.0, 0.7071, -0.7071, 0.875, 1.0,
|
||||
0.5, 0.46194, -0.19134150000000005, -0.0, 0.9239, -0.3827, 0.8125, 0.5,
|
||||
-0.5, 0.4619395, -0.19134150000000005, -0.0, 0.9239, -0.3827, 0.8125, 1.0,
|
||||
-0.5, 0.415735, -0.27778499999999995, -0.0, 0.8315, -0.5556, 0.84375, 1.0,
|
||||
0.5, 0.4903925, -0.09754499999999999, -0.0, 0.9808, -0.1951, 0.78125, 0.5,
|
||||
-0.5, 0.4903925, -0.09754499999999999, -0.0, 0.9808, -0.1951, 0.78125, 1.0,
|
||||
-0.5, 0.4619395, -0.19134150000000005, -0.0, 0.9239, -0.3827, 0.8125, 1.0,
|
||||
0.5, 0.5, 0.0, -0.0, 1.0, -0.0, 0.75, 0.5,
|
||||
-0.5, 0.5, 0.0, -0.0, 1.0, -0.0, 0.75, 1.0,
|
||||
-0.5, 0.4903925, -0.09754499999999999, -0.0, 0.9808, -0.1951, 0.78125, 1.0,
|
||||
0.5, 0.4903925, 0.09754499999999999, -0.0, 0.9808, 0.1951, 0.71875, 0.5,
|
||||
-0.5, 0.4903925, 0.09754499999999999, -0.0, 0.9808, 0.1951, 0.71875, 1.0,
|
||||
-0.5, 0.5, 0.0, -0.0, 1.0, -0.0, 0.75, 1.0,
|
||||
0.5, 0.46194, 0.1913415, -0.0, 0.9239, 0.3827, 0.6875, 0.5,
|
||||
-0.5, 0.4619395, 0.1913415, -0.0, 0.9239, 0.3827, 0.6875, 1.0,
|
||||
-0.5, 0.4903925, 0.09754499999999999, -0.0, 0.9808, 0.1951, 0.71875, 1.0,
|
||||
0.5, 0.415735, 0.277785, -0.0, 0.8315, 0.5556, 0.65625, 0.5,
|
||||
-0.5, 0.415735, 0.277785, -0.0, 0.8315, 0.5556, 0.65625, 1.0,
|
||||
-0.5, 0.4619395, 0.1913415, -0.0, 0.9239, 0.3827, 0.6875, 1.0,
|
||||
0.5, 0.3535535, 0.3535535, -0.0, 0.7071, 0.7071, 0.625, 0.5,
|
||||
-0.5, 0.3535535, 0.3535535, -0.0, 0.7071, 0.7071, 0.625, 1.0,
|
||||
-0.5, 0.415735, 0.277785, -0.0, 0.8315, 0.5556, 0.65625, 1.0,
|
||||
0.5, 0.277785, 0.415735, -0.0, 0.5556, 0.8315, 0.59375, 0.5,
|
||||
-0.5, 0.277785, 0.415735, -0.0, 0.5556, 0.8315, 0.59375, 1.0,
|
||||
-0.5, 0.3535535, 0.3535535, -0.0, 0.7071, 0.7071, 0.625, 1.0,
|
||||
0.5, 0.1913415, 0.46194, -0.0, 0.3827, 0.9239, 0.5625, 0.5,
|
||||
-0.5, 0.1913415, 0.46194, -0.0, 0.3827, 0.9239, 0.5625, 1.0,
|
||||
-0.5, 0.277785, 0.415735, -0.0, 0.5556, 0.8315, 0.59375, 1.0,
|
||||
0.5, 0.09754499999999999, 0.4903925, -0.0, 0.1951, 0.9808, 0.53125, 0.5,
|
||||
-0.5, 0.09754499999999999, 0.4903925, -0.0, 0.1951, 0.9808, 0.53125, 1.0,
|
||||
-0.5, 0.1913415, 0.46194, -0.0, 0.3827, 0.9239, 0.5625, 1.0,
|
||||
0.5, 0.0, 0.5, -0.0, -0.0, 1.0, 0.5, 0.5,
|
||||
-0.5, 0.0, 0.5, -0.0, -0.0, 1.0, 0.5, 1.0,
|
||||
-0.5, 0.09754499999999999, 0.4903925, -0.0, 0.1951, 0.9808, 0.53125, 1.0,
|
||||
0.5, -0.09754499999999999, 0.4903925, -0.0, -0.1951, 0.9808, 0.46875, 0.5,
|
||||
-0.5, -0.09754499999999999, 0.4903925, -0.0, -0.1951, 0.9808, 0.46875, 1.0,
|
||||
-0.5, 0.0, 0.5, -0.0, -0.0, 1.0, 0.5, 1.0,
|
||||
0.5, -0.19134150000000005, 0.46194, -0.0, -0.3827, 0.9239, 0.4375, 0.5,
|
||||
-0.5, -0.19134150000000005, 0.46194, -0.0, -0.3827, 0.9239, 0.4375, 1.0,
|
||||
-0.5, -0.09754499999999999, 0.4903925, -0.0, -0.1951, 0.9808, 0.46875, 1.0,
|
||||
0.5, -0.27778499999999995, 0.415735, -0.0, -0.5556, 0.8315, 0.40625, 0.5,
|
||||
-0.5, -0.27778499999999995, 0.415735, -0.0, -0.5556, 0.8315, 0.40625, 1.0,
|
||||
-0.5, -0.19134150000000005, 0.46194, -0.0, -0.3827, 0.9239, 0.4375, 1.0,
|
||||
0.5, -0.3535535000000001, 0.3535535, -0.0, -0.7071, 0.7071, 0.375, 0.5,
|
||||
-0.5, -0.3535535000000001, 0.3535535, -0.0, -0.7071, 0.7071, 0.375, 1.0,
|
||||
-0.5, -0.27778499999999995, 0.415735, -0.0, -0.5556, 0.8315, 0.40625, 1.0,
|
||||
0.5, -0.41573499999999997, 0.277785, -0.0, -0.8315, 0.5556, 0.34375, 0.5,
|
||||
-0.5, -0.41573499999999997, 0.277785, -0.0, -0.8315, 0.5556, 0.34375, 1.0,
|
||||
-0.5, -0.3535535000000001, 0.3535535, -0.0, -0.7071, 0.7071, 0.375, 1.0,
|
||||
0.5, -0.46193949999999995, 0.1913415, -0.0, -0.9239, 0.3827, 0.3125, 0.5,
|
||||
-0.5, -0.46194, 0.1913415, -0.0, -0.9239, 0.3827, 0.3125, 1.0,
|
||||
-0.5, -0.41573499999999997, 0.277785, -0.0, -0.8315, 0.5556, 0.34375, 1.0,
|
||||
0.5, -0.4903925, 0.09754499999999999, -0.0, -0.9808, 0.1951, 0.28125, 0.5,
|
||||
-0.5, -0.4903925, 0.09754499999999999, -0.0, -0.9808, 0.1951, 0.28125, 1.0,
|
||||
-0.5, -0.46194, 0.1913415, -0.0, -0.9239, 0.3827, 0.3125, 1.0,
|
||||
0.5, -0.5, 0.0, -0.0, -1.0, -0.0, 0.25, 0.5,
|
||||
-0.5, -0.5, 0.0, -0.0, -1.0, -0.0, 0.25, 1.0,
|
||||
-0.5, -0.4903925, 0.09754499999999999, -0.0, -0.9808, 0.1951, 0.28125, 1.0,
|
||||
0.5, -0.4903925, -0.09754499999999999, -0.0, -0.9808, -0.1951, 0.21875, 0.5,
|
||||
-0.5, -0.4903925, -0.09754499999999999, -0.0, -0.9808, -0.1951, 0.21875, 1.0,
|
||||
-0.5, -0.5, 0.0, -0.0, -1.0, -0.0, 0.25, 1.0,
|
||||
0.5, -0.46193949999999995, -0.19134150000000005, -0.0, -0.9239, -0.3827, 0.1875, 0.5,
|
||||
-0.5, -0.46194, -0.19134150000000005, -0.0, -0.9239, -0.3827, 0.1875, 1.0,
|
||||
-0.5, -0.4903925, -0.09754499999999999, -0.0, -0.9808, -0.1951, 0.21875, 1.0,
|
||||
0.5, -0.41573499999999997, -0.27778499999999995, -0.0, -0.8315, -0.5556, 0.15625, 0.5,
|
||||
-0.5, -0.41573499999999997, -0.27778499999999995, -0.0, -0.8315, -0.5556, 0.15625, 1.0,
|
||||
-0.5, -0.46194, -0.19134150000000005, -0.0, -0.9239, -0.3827, 0.1875, 1.0,
|
||||
0.5, -0.3535535000000001, -0.3535535000000001, -0.0, -0.7071, -0.7071, 0.125, 0.5,
|
||||
-0.5, -0.3535535000000001, -0.3535535000000001, -0.0, -0.7071, -0.7071, 0.125, 1.0,
|
||||
-0.5, -0.41573499999999997, -0.27778499999999995, -0.0, -0.8315, -0.5556, 0.15625, 1.0,
|
||||
0.5, -0.27778499999999995, -0.41573499999999997, -0.0, -0.5556, -0.8315, 0.09375, 0.5,
|
||||
-0.5, -0.27778499999999995, -0.41573499999999997, -0.0, -0.5556, -0.8315, 0.09375, 1.0,
|
||||
-0.5, -0.3535535000000001, -0.3535535000000001, -0.0, -0.7071, -0.7071, 0.125, 1.0,
|
||||
0.5, -0.19134150000000005, -0.46194, -0.0, -0.3827, -0.9239, 0.0625, 0.5,
|
||||
-0.5, -0.19134150000000005, -0.46194, -0.0, -0.3827, -0.9239, 0.0625, 1.0,
|
||||
-0.5, -0.27778499999999995, -0.41573499999999997, -0.0, -0.5556, -0.8315, 0.09375, 1.0,
|
||||
-0.5, 0.0, -0.5, -1.0, -0.0, -0.0, 0.25, 0.49,
|
||||
-0.5, 0.09754499999999999, -0.4903925, -1.0, -0.0, -0.0, 0.296822, 0.485388,
|
||||
-0.5, 0.1913415, -0.46194, -1.0, -0.0, -0.0, 0.341844, 0.471731,
|
||||
-0.5, 0.1913415, -0.46194, -1.0, -0.0, -0.0, 0.341844, 0.471731,
|
||||
-0.5, -0.09754499999999999, -0.4903925, -1.0, -0.0, -0.0, 0.203178, 0.485388,
|
||||
-0.5, 0.0, -0.5, -1.0, -0.0, -0.0, 0.25, 0.49,
|
||||
-0.5, 0.1913415, -0.46194, -1.0, -0.0, -0.0, 0.341844, 0.471731,
|
||||
-0.5, -0.19134150000000005, -0.46194, -1.0, -0.0, -0.0, 0.158156, 0.471731,
|
||||
-0.5, -0.09754499999999999, -0.4903925, -1.0, -0.0, -0.0, 0.203178, 0.485388,
|
||||
-0.5, -0.3535535000000001, -0.3535535000000001, -1.0, -0.0, -0.0, 0.080294, 0.419706,
|
||||
-0.5, -0.27778499999999995, -0.41573499999999997, -1.0, -0.0, -0.0, 0.116663, 0.449553,
|
||||
-0.5, -0.19134150000000005, -0.46194, -1.0, -0.0, -0.0, 0.158156, 0.471731,
|
||||
-0.5, -0.46194, -0.19134150000000005, -1.0, -0.0, -0.0, 0.028269, 0.341844,
|
||||
-0.5, -0.41573499999999997, -0.27778499999999995, -1.0, -0.0, -0.0, 0.050447, 0.383337,
|
||||
-0.5, -0.3535535000000001, -0.3535535000000001, -1.0, -0.0, -0.0, 0.080294, 0.419706,
|
||||
-0.5, -0.5, 0.0, -1.0, -0.0, -0.0, 0.01, 0.25,
|
||||
-0.5, -0.4903925, -0.09754499999999999, -1.0, -0.0, -0.0, 0.014612, 0.296822,
|
||||
-0.5, -0.46194, -0.19134150000000005, -1.0, -0.0, -0.0, 0.028269, 0.341844,
|
||||
-0.5, -0.46194, -0.19134150000000005, -1.0, -0.0, -0.0, 0.028269, 0.341844,
|
||||
-0.5, -0.4903925, 0.09754499999999999, -1.0, -0.0, -0.0, 0.014612, 0.203178,
|
||||
-0.5, -0.5, 0.0, -1.0, -0.0, -0.0, 0.01, 0.25,
|
||||
-0.5, -0.46194, -0.19134150000000005, -1.0, -0.0, -0.0, 0.028269, 0.341844,
|
||||
-0.5, -0.46194, 0.1913415, -1.0, -0.0, -0.0, 0.028269, 0.158156,
|
||||
-0.5, -0.4903925, 0.09754499999999999, -1.0, -0.0, -0.0, 0.014612, 0.203178,
|
||||
-0.5, -0.3535535000000001, 0.3535535, -1.0, -0.0, -0.0, 0.080294, 0.080294,
|
||||
-0.5, -0.41573499999999997, 0.277785, -1.0, -0.0, -0.0, 0.050447, 0.116663,
|
||||
-0.5, -0.46194, 0.1913415, -1.0, -0.0, -0.0, 0.028269, 0.158156,
|
||||
-0.5, -0.19134150000000005, 0.46194, -1.0, -0.0, -0.0, 0.158156, 0.028269,
|
||||
-0.5, -0.27778499999999995, 0.415735, -1.0, -0.0, -0.0, 0.116663, 0.050447,
|
||||
-0.5, -0.3535535000000001, 0.3535535, -1.0, -0.0, -0.0, 0.080294, 0.080294,
|
||||
-0.5, 0.1913415, 0.46194, -1.0, -0.0, -0.0, 0.341844, 0.028269,
|
||||
-0.5, -0.09754499999999999, 0.4903925, -1.0, -0.0, -0.0, 0.203178, 0.014612,
|
||||
-0.5, -0.19134150000000005, 0.46194, -1.0, -0.0, -0.0, 0.158156, 0.028269,
|
||||
-0.5, 0.1913415, 0.46194, -1.0, -0.0, -0.0, 0.341844, 0.028269,
|
||||
-0.5, 0.0, 0.5, -1.0, -0.0, -0.0, 0.25, 0.01,
|
||||
-0.5, -0.09754499999999999, 0.4903925, -1.0, -0.0, -0.0, 0.203178, 0.014612,
|
||||
-0.5, 0.1913415, 0.46194, -1.0, -0.0, -0.0, 0.341844, 0.028269,
|
||||
-0.5, 0.09754499999999999, 0.4903925, -1.0, -0.0, -0.0, 0.296822, 0.014612,
|
||||
-0.5, 0.0, 0.5, -1.0, -0.0, -0.0, 0.25, 0.01,
|
||||
-0.5, 0.3535535, 0.3535535, -1.0, -0.0, -0.0, 0.419706, 0.080294,
|
||||
-0.5, 0.277785, 0.415735, -1.0, -0.0, -0.0, 0.383337, 0.050447,
|
||||
-0.5, 0.1913415, 0.46194, -1.0, -0.0, -0.0, 0.341844, 0.028269,
|
||||
-0.5, 0.4619395, 0.1913415, -1.0, -0.0, -0.0, 0.471731, 0.158156,
|
||||
-0.5, 0.415735, 0.277785, -1.0, -0.0, -0.0, 0.449553, 0.116663,
|
||||
-0.5, 0.3535535, 0.3535535, -1.0, -0.0, -0.0, 0.419706, 0.080294,
|
||||
-0.5, 0.4619395, -0.19134150000000005, -1.0, -0.0, -0.0, 0.471731, 0.341844,
|
||||
-0.5, 0.4903925, 0.09754499999999999, -1.0, -0.0, -0.0, 0.485388, 0.203178,
|
||||
-0.5, 0.4619395, 0.1913415, -1.0, -0.0, -0.0, 0.471731, 0.158156,
|
||||
-0.5, 0.4619395, -0.19134150000000005, -1.0, -0.0, -0.0, 0.471731, 0.341844,
|
||||
-0.5, 0.5, 0.0, -1.0, -0.0, -0.0, 0.49, 0.25,
|
||||
-0.5, 0.4903925, 0.09754499999999999, -1.0, -0.0, -0.0, 0.485388, 0.203178,
|
||||
-0.5, 0.4619395, -0.19134150000000005, -1.0, -0.0, -0.0, 0.471731, 0.341844,
|
||||
-0.5, 0.4903925, -0.09754499999999999, -1.0, -0.0, -0.0, 0.485388, 0.296822,
|
||||
-0.5, 0.5, 0.0, -1.0, -0.0, -0.0, 0.49, 0.25,
|
||||
-0.5, 0.3535535, -0.3535535000000001, -1.0, -0.0, -0.0, 0.419706, 0.419706,
|
||||
-0.5, 0.415735, -0.27778499999999995, -1.0, -0.0, -0.0, 0.449553, 0.383337,
|
||||
-0.5, 0.4619395, -0.19134150000000005, -1.0, -0.0, -0.0, 0.471731, 0.341844,
|
||||
-0.5, 0.1913415, -0.46194, -1.0, -0.0, -0.0, 0.341844, 0.471731,
|
||||
-0.5, 0.277785, -0.41573499999999997, -1.0, -0.0, -0.0, 0.383337, 0.449553,
|
||||
-0.5, 0.3535535, -0.3535535000000001, -1.0, -0.0, -0.0, 0.419706, 0.419706,
|
||||
-0.5, 0.1913415, -0.46194, -1.0, -0.0, -0.0, 0.341844, 0.471731,
|
||||
-0.5, -0.3535535000000001, -0.3535535000000001, -1.0, -0.0, -0.0, 0.080294, 0.419706,
|
||||
-0.5, -0.19134150000000005, -0.46194, -1.0, -0.0, -0.0, 0.158156, 0.471731,
|
||||
-0.5, 0.1913415, -0.46194, -1.0, -0.0, -0.0, 0.341844, 0.471731,
|
||||
-0.5, -0.46194, -0.19134150000000005, -1.0, -0.0, -0.0, 0.028269, 0.341844,
|
||||
-0.5, -0.3535535000000001, -0.3535535000000001, -1.0, -0.0, -0.0, 0.080294, 0.419706,
|
||||
-0.5, -0.46194, -0.19134150000000005, -1.0, -0.0, -0.0, 0.028269, 0.341844,
|
||||
-0.5, -0.3535535000000001, 0.3535535, -1.0, -0.0, -0.0, 0.080294, 0.080294,
|
||||
-0.5, -0.46194, 0.1913415, -1.0, -0.0, -0.0, 0.028269, 0.158156,
|
||||
-0.5, -0.46194, -0.19134150000000005, -1.0, -0.0, -0.0, 0.028269, 0.341844,
|
||||
-0.5, -0.19134150000000005, 0.46194, -1.0, -0.0, -0.0, 0.158156, 0.028269,
|
||||
-0.5, -0.3535535000000001, 0.3535535, -1.0, -0.0, -0.0, 0.080294, 0.080294,
|
||||
-0.5, -0.19134150000000005, 0.46194, -1.0, -0.0, -0.0, 0.158156, 0.028269,
|
||||
-0.5, 0.3535535, 0.3535535, -1.0, -0.0, -0.0, 0.419706, 0.080294,
|
||||
-0.5, 0.1913415, 0.46194, -1.0, -0.0, -0.0, 0.341844, 0.028269,
|
||||
-0.5, -0.19134150000000005, 0.46194, -1.0, -0.0, -0.0, 0.158156, 0.028269,
|
||||
-0.5, 0.4619395, 0.1913415, -1.0, -0.0, -0.0, 0.471731, 0.158156,
|
||||
-0.5, 0.3535535, 0.3535535, -1.0, -0.0, -0.0, 0.419706, 0.080294,
|
||||
-0.5, 0.4619395, 0.1913415, -1.0, -0.0, -0.0, 0.471731, 0.158156,
|
||||
-0.5, 0.3535535, -0.3535535000000001, -1.0, -0.0, -0.0, 0.419706, 0.419706,
|
||||
-0.5, 0.4619395, -0.19134150000000005, -1.0, -0.0, -0.0, 0.471731, 0.341844,
|
||||
-0.5, 0.4619395, 0.1913415, -1.0, -0.0, -0.0, 0.471731, 0.158156,
|
||||
-0.5, 0.1913415, -0.46194, -1.0, -0.0, -0.0, 0.341844, 0.471731,
|
||||
-0.5, 0.3535535, -0.3535535000000001, -1.0, -0.0, -0.0, 0.419706, 0.419706,
|
||||
-0.5, -0.19134150000000005, 0.46194, -1.0, -0.0, -0.0, 0.158156, 0.028269,
|
||||
-0.5, -0.46194, -0.19134150000000005, -1.0, -0.0, -0.0, 0.028269, 0.341844,
|
||||
-0.5, 0.1913415, -0.46194, -1.0, -0.0, -0.0, 0.341844, 0.471731,
|
||||
0.5, -0.09754499999999999, -0.4903925, -0.0, -0.1951, -0.9808, 0.03125, 0.5,
|
||||
-0.5, -0.09754499999999999, -0.4903925, -0.0, -0.1951, -0.9808, 0.03125, 1.0,
|
||||
-0.5, -0.19134150000000005, -0.46194, -0.0, -0.3827, -0.9239, 0.0625, 1.0,
|
||||
0.5, 0.0, -0.5, -0.0, -0.0, -1.0, 0.0, 0.5,
|
||||
-0.5, 0.0, -0.5, -0.0, -0.0, -1.0, 0.0, 1.0,
|
||||
-0.5, -0.09754499999999999, -0.4903925, -0.0, -0.1951, -0.9808, 0.03125, 1.0,
|
||||
0.5, 0.09754499999999999, -0.4903925, 1.0, -0.0, -0.0, 0.796822, 0.485388,
|
||||
0.5, 0.0, -0.5, 1.0, -0.0, -0.0, 0.75, 0.49,
|
||||
0.5, -0.09754499999999999, -0.4903925, 1.0, -0.0, -0.0, 0.703178, 0.485388,
|
||||
0.5, 0.277785, -0.41573499999999997, 1.0, -0.0, -0.0, 0.883337, 0.449553,
|
||||
0.5, 0.1913415, -0.46194, 1.0, -0.0, -0.0, 0.841844, 0.471731,
|
||||
0.5, 0.09754499999999999, -0.4903925, 1.0, -0.0, -0.0, 0.796822, 0.485388,
|
||||
0.5, 0.415735, -0.27778499999999995, 1.0, -0.0, -0.0, 0.949553, 0.383337,
|
||||
0.5, 0.3535535, -0.3535535000000001, 1.0, -0.0, -0.0, 0.919706, 0.419706,
|
||||
0.5, 0.277785, -0.41573499999999997, 1.0, -0.0, -0.0, 0.883337, 0.449553,
|
||||
0.5, 0.4903925, -0.09754499999999999, 1.0, -0.0, -0.0, 0.985388, 0.296822,
|
||||
0.5, 0.46194, -0.19134150000000005, 1.0, -0.0, -0.0, 0.971731, 0.341844,
|
||||
0.5, 0.415735, -0.27778499999999995, 1.0, -0.0, -0.0, 0.949553, 0.383337,
|
||||
0.5, 0.4903925, 0.09754499999999999, 1.0, -0.0, -0.0, 0.985388, 0.203178,
|
||||
0.5, 0.5, 0.0, 1.0, -0.0, -0.0, 0.99, 0.25,
|
||||
0.5, 0.4903925, -0.09754499999999999, 1.0, -0.0, -0.0, 0.985388, 0.296822,
|
||||
0.5, 0.415735, 0.277785, 1.0, -0.0, -0.0, 0.949553, 0.116663,
|
||||
0.5, 0.46194, 0.1913415, 1.0, -0.0, -0.0, 0.971731, 0.158156,
|
||||
0.5, 0.4903925, 0.09754499999999999, 1.0, -0.0, -0.0, 0.985388, 0.203178,
|
||||
0.5, 0.277785, 0.415735, 1.0, -0.0, -0.0, 0.883337, 0.050447,
|
||||
0.5, 0.3535535, 0.3535535, 1.0, -0.0, -0.0, 0.919706, 0.080294,
|
||||
0.5, 0.415735, 0.277785, 1.0, -0.0, -0.0, 0.949553, 0.116663,
|
||||
0.5, 0.09754499999999999, 0.4903925, 1.0, -0.0, -0.0, 0.796822, 0.014612,
|
||||
0.5, 0.1913415, 0.46194, 1.0, -0.0, -0.0, 0.841844, 0.028269,
|
||||
0.5, 0.277785, 0.415735, 1.0, -0.0, -0.0, 0.883337, 0.050447,
|
||||
0.5, -0.09754499999999999, 0.4903925, 1.0, -0.0, -0.0, 0.703178, 0.014612,
|
||||
0.5, 0.0, 0.5, 1.0, -0.0, -0.0, 0.75, 0.01,
|
||||
0.5, 0.09754499999999999, 0.4903925, 1.0, -0.0, -0.0, 0.796822, 0.014612,
|
||||
0.5, -0.27778499999999995, 0.415735, 1.0, -0.0, -0.0, 0.616663, 0.050447,
|
||||
0.5, -0.19134150000000005, 0.46194, 1.0, -0.0, -0.0, 0.658156, 0.028269,
|
||||
0.5, -0.09754499999999999, 0.4903925, 1.0, -0.0, -0.0, 0.703178, 0.014612,
|
||||
0.5, -0.41573499999999997, 0.277785, 1.0, -0.0, -0.0, 0.550447, 0.116663,
|
||||
0.5, -0.3535535000000001, 0.3535535, 1.0, -0.0, -0.0, 0.580294, 0.080294,
|
||||
0.5, -0.27778499999999995, 0.415735, 1.0, -0.0, -0.0, 0.616663, 0.050447,
|
||||
0.5, -0.4903925, 0.09754499999999999, 1.0, -0.0, -0.0, 0.514612, 0.203178,
|
||||
0.5, -0.46193949999999995, 0.1913415, 1.0, -0.0, -0.0, 0.528269, 0.158156,
|
||||
0.5, -0.41573499999999997, 0.277785, 1.0, -0.0, -0.0, 0.550447, 0.116663,
|
||||
0.5, -0.4903925, -0.09754499999999999, 1.0, -0.0, -0.0, 0.514612, 0.296822,
|
||||
0.5, -0.5, 0.0, 1.0, -0.0, -0.0, 0.51, 0.25,
|
||||
0.5, -0.4903925, 0.09754499999999999, 1.0, -0.0, -0.0, 0.514612, 0.203178,
|
||||
0.5, -0.41573499999999997, -0.27778499999999995, 1.0, -0.0, -0.0, 0.550447, 0.383337,
|
||||
0.5, -0.46193949999999995, -0.19134150000000005, 1.0, -0.0, -0.0, 0.528269, 0.341844,
|
||||
0.5, -0.4903925, -0.09754499999999999, 1.0, -0.0, -0.0, 0.514612, 0.296822,
|
||||
0.5, -0.27778499999999995, -0.41573499999999997, 1.0, -0.0, -0.0, 0.616663, 0.449553,
|
||||
0.5, -0.3535535000000001, -0.3535535000000001, 1.0, -0.0, -0.0, 0.580294, 0.419706,
|
||||
0.5, -0.41573499999999997, -0.27778499999999995, 1.0, -0.0, -0.0, 0.550447, 0.383337,
|
||||
0.5, -0.09754499999999999, -0.4903925, 1.0, -0.0, -0.0, 0.703178, 0.485388,
|
||||
0.5, -0.19134150000000005, -0.46194, 1.0, -0.0, -0.0, 0.658156, 0.471731,
|
||||
0.5, -0.27778499999999995, -0.41573499999999997, 1.0, -0.0, -0.0, 0.616663, 0.449553,
|
||||
0.5, 0.4903925, -0.09754499999999999, 1.0, -0.0, -0.0, 0.985388, 0.296822,
|
||||
0.5, 0.09754499999999999, -0.4903925, 1.0, -0.0, -0.0, 0.796822, 0.485388,
|
||||
0.5, -0.09754499999999999, -0.4903925, 1.0, -0.0, -0.0, 0.703178, 0.485388,
|
||||
0.5, 0.4903925, -0.09754499999999999, 1.0, -0.0, -0.0, 0.985388, 0.296822,
|
||||
0.5, 0.277785, -0.41573499999999997, 1.0, -0.0, -0.0, 0.883337, 0.449553,
|
||||
0.5, 0.09754499999999999, -0.4903925, 1.0, -0.0, -0.0, 0.796822, 0.485388,
|
||||
0.5, 0.4903925, -0.09754499999999999, 1.0, -0.0, -0.0, 0.985388, 0.296822,
|
||||
0.5, 0.415735, -0.27778499999999995, 1.0, -0.0, -0.0, 0.949553, 0.383337,
|
||||
0.5, 0.277785, -0.41573499999999997, 1.0, -0.0, -0.0, 0.883337, 0.449553,
|
||||
0.5, 0.09754499999999999, 0.4903925, 1.0, -0.0, -0.0, 0.796822, 0.014612,
|
||||
0.5, 0.4903925, 0.09754499999999999, 1.0, -0.0, -0.0, 0.985388, 0.203178,
|
||||
0.5, 0.4903925, -0.09754499999999999, 1.0, -0.0, -0.0, 0.985388, 0.296822,
|
||||
0.5, 0.09754499999999999, 0.4903925, 1.0, -0.0, -0.0, 0.796822, 0.014612,
|
||||
0.5, 0.415735, 0.277785, 1.0, -0.0, -0.0, 0.949553, 0.116663,
|
||||
0.5, 0.4903925, 0.09754499999999999, 1.0, -0.0, -0.0, 0.985388, 0.203178,
|
||||
0.5, 0.09754499999999999, 0.4903925, 1.0, -0.0, -0.0, 0.796822, 0.014612,
|
||||
0.5, 0.277785, 0.415735, 1.0, -0.0, -0.0, 0.883337, 0.050447,
|
||||
0.5, 0.415735, 0.277785, 1.0, -0.0, -0.0, 0.949553, 0.116663,
|
||||
0.5, -0.4903925, 0.09754499999999999, 1.0, -0.0, -0.0, 0.514612, 0.203178,
|
||||
0.5, -0.09754499999999999, 0.4903925, 1.0, -0.0, -0.0, 0.703178, 0.014612,
|
||||
0.5, 0.09754499999999999, 0.4903925, 1.0, -0.0, -0.0, 0.796822, 0.014612,
|
||||
0.5, -0.4903925, 0.09754499999999999, 1.0, -0.0, -0.0, 0.514612, 0.203178,
|
||||
0.5, -0.27778499999999995, 0.415735, 1.0, -0.0, -0.0, 0.616663, 0.050447,
|
||||
0.5, -0.09754499999999999, 0.4903925, 1.0, -0.0, -0.0, 0.703178, 0.014612,
|
||||
0.5, -0.4903925, 0.09754499999999999, 1.0, -0.0, -0.0, 0.514612, 0.203178,
|
||||
0.5, -0.41573499999999997, 0.277785, 1.0, -0.0, -0.0, 0.550447, 0.116663,
|
||||
0.5, -0.27778499999999995, 0.415735, 1.0, -0.0, -0.0, 0.616663, 0.050447,
|
||||
0.5, -0.09754499999999999, -0.4903925, 1.0, -0.0, -0.0, 0.703178, 0.485388,
|
||||
0.5, -0.4903925, -0.09754499999999999, 1.0, -0.0, -0.0, 0.514612, 0.296822,
|
||||
0.5, -0.4903925, 0.09754499999999999, 1.0, -0.0, -0.0, 0.514612, 0.203178,
|
||||
0.5, -0.09754499999999999, -0.4903925, 1.0, -0.0, -0.0, 0.703178, 0.485388,
|
||||
0.5, -0.41573499999999997, -0.27778499999999995, 1.0, -0.0, -0.0, 0.550447, 0.383337,
|
||||
0.5, -0.4903925, -0.09754499999999999, 1.0, -0.0, -0.0, 0.514612, 0.296822,
|
||||
0.5, -0.09754499999999999, -0.4903925, 1.0, -0.0, -0.0, 0.703178, 0.485388,
|
||||
0.5, -0.27778499999999995, -0.41573499999999997, 1.0, -0.0, -0.0, 0.616663, 0.449553,
|
||||
0.5, -0.41573499999999997, -0.27778499999999995, 1.0, -0.0, -0.0, 0.550447, 0.383337,
|
||||
0.5, 0.09754499999999999, 0.4903925, 1.0, -0.0, -0.0, 0.796822, 0.014612,
|
||||
0.5, 0.4903925, -0.09754499999999999, 1.0, -0.0, -0.0, 0.985388, 0.296822,
|
||||
0.5, -0.09754499999999999, -0.4903925, 1.0, -0.0, -0.0, 0.703178, 0.485388,
|
||||
|
||||
};
|
||||
|
||||
Mesh* CUBE_MESH;
|
||||
Mesh* WEDGE_MESH;
|
||||
Mesh* SPHERE_MESH;
|
||||
Mesh* ARROW_MESH;
|
||||
Mesh* OUTLINE_MESH;
|
||||
Mesh* CYLINDER_CHEAP_MESH;
|
||||
Mesh* CYLINDER_MESH;
|
||||
|
||||
void initMeshes() {
|
||||
|
@ -3119,6 +3499,7 @@ void initMeshes() {
|
|||
SPHERE_MESH = new Mesh(sizeof(SPHERE_VERTICES) / sizeof(float) / 8, SPHERE_VERTICES);
|
||||
ARROW_MESH = new Mesh(sizeof(ARROW_VERTICES) / sizeof(float) / 8, ARROW_VERTICES);
|
||||
OUTLINE_MESH = new Mesh(sizeof(OUTLINE_VERTICES) / sizeof(float) / 8, OUTLINE_VERTICES);
|
||||
CYLINDER_CHEAP_MESH = new Mesh(sizeof(CYLINDER_CHEAP_VERTICES) / sizeof(float) / 8, CYLINDER_CHEAP_VERTICES);
|
||||
CYLINDER_MESH = new Mesh(sizeof(CYLINDER_VERTICES) / sizeof(float) / 8, CYLINDER_VERTICES);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,5 +7,6 @@ extern Mesh* SPHERE_MESH;
|
|||
extern Mesh* ARROW_MESH;
|
||||
extern Mesh* OUTLINE_MESH;
|
||||
extern Mesh* CYLINDER_MESH;
|
||||
extern Mesh* CYLINDER_CHEAP_MESH;
|
||||
|
||||
void initMeshes();
|
|
@ -3,8 +3,7 @@
|
|||
#include "panic.h"
|
||||
#include "rendering/shader.h"
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GL/gl.h>
|
||||
#include <glad/gl.h>
|
||||
#include <glm/ext/matrix_clip_space.hpp>
|
||||
#include <memory>
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include <GL/glew.h>
|
||||
#include <GL/gl.h>
|
||||
#include <glad/gl.h>
|
||||
|
||||
#include "mesh.h"
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include <GL/glew.h>
|
||||
#include <GL/gl.h>
|
||||
#include <glad/gl.h>
|
||||
|
||||
#include "mesh2d.h"
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include <GL/glew.h>
|
||||
#include <GL/gl.h>
|
||||
#include <glad/gl.h>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <glm/ext.hpp>
|
||||
#include <glm/ext/matrix_clip_space.hpp>
|
||||
#include <glm/ext/matrix_float4x4.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/ext/scalar_constants.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
@ -138,6 +138,7 @@ static void renderPart(std::shared_ptr<BasePart> part) {
|
|||
shader->set("normalMatrix", normalMatrix);
|
||||
shader->set("texScale", size);
|
||||
shader->set("transparency", part->transparency);
|
||||
shader->set("reflectance", part->reflectance);
|
||||
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Right) + "]", (int)part->rightSurface);
|
||||
shader->set("surfaces[" + std::to_string(NormalId::Top) + "]", (int)part->topSurface);
|
||||
|
@ -157,6 +158,10 @@ static void renderPart(std::shared_ptr<BasePart> part) {
|
|||
glFrontFace(GL_CW);
|
||||
CUBE_MESH->bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, CUBE_MESH->vertexCount);
|
||||
} else if (shape == PartType::Cylinder) {
|
||||
glFrontFace(GL_CW);
|
||||
CYLINDER_MESH->bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, CYLINDER_MESH->vertexCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,11 +189,14 @@ void renderParts() {
|
|||
shader->set("numPointLights", 0);
|
||||
studsTexture->activate(0);
|
||||
shader->set("studs", 0);
|
||||
skyboxTexture->activate(1);
|
||||
shader->set("skybox", 1);
|
||||
|
||||
// Pre-calculate the normal matrix for the shader
|
||||
|
||||
// Pass in the camera position
|
||||
shader->set("viewPos", camera.cameraPos);
|
||||
|
||||
|
||||
// Sort by nearest
|
||||
std::map<float, std::shared_ptr<BasePart>> sorted;
|
||||
|
@ -256,8 +264,8 @@ void renderSurfaceExtras() {
|
|||
model = glm::scale(model, glm::vec3(0.4,0.4,0.4));
|
||||
ghostShader->set("model", model);
|
||||
|
||||
CYLINDER_MESH->bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, CYLINDER_MESH->vertexCount);
|
||||
CYLINDER_CHEAP_MESH->bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, CYLINDER_CHEAP_MESH->vertexCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include <fstream>
|
||||
#include <GL/glew.h>
|
||||
#include <GL/gl.h>
|
||||
#include <glad/gl.h>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include "logger.h"
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include <GL/glew.h>
|
||||
#include <GL/gl.h>
|
||||
#include <glad/gl.h>
|
||||
#include <stb_image.h>
|
||||
|
||||
#include "logger.h"
|
||||
|
@ -23,6 +22,7 @@ Skybox::Skybox(std::array<std::string, 6> faces, unsigned int format) {
|
|||
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, format, width, height, 0, format,
|
||||
GL_UNSIGNED_BYTE, data);
|
||||
glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
|
||||
stbi_image_free(data);
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ Skybox::Skybox(std::array<std::string, 6> faces, unsigned int format) {
|
|||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
|
||||
// Interpolation
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
}
|
||||
|
||||
|
@ -42,5 +42,5 @@ Skybox::~Skybox() {
|
|||
|
||||
void Skybox::activate(unsigned int textureIdx) {
|
||||
glActiveTexture(GL_TEXTURE0 + textureIdx);
|
||||
glBindTexture(GL_TEXTURE_2D, this->ID);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, this->ID);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "texture.h"
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GL/gl.h>
|
||||
#include <glad/gl.h>
|
||||
#include <stb_image.h>
|
||||
|
||||
#include "panic.h"
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "texture3d.h"
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <GL/gl.h>
|
||||
#include <glad/gl.h>
|
||||
#include <stb_image.h>
|
||||
|
||||
#include "panic.h"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "torus.h"
|
||||
#include <cmath>
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <glad/gl.h>
|
||||
|
||||
#define PI 3.1415926535f
|
||||
|
||||
|
|
|
@ -4,9 +4,15 @@
|
|||
|
||||
tu_time_t TIME_STARTED_MICROS = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now()).time_since_epoch().count();
|
||||
|
||||
static tu_time_t timeOverride = -1UL;
|
||||
|
||||
tu_time_t tu_clock_micros() {
|
||||
if (timeOverride != -1UL) return timeOverride;
|
||||
tu_time_t now = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now()).time_since_epoch().count();;
|
||||
|
||||
return now - TIME_STARTED_MICROS;
|
||||
}
|
||||
|
||||
void tu_set_override(tu_time_t destTime) {
|
||||
timeOverride = destTime;
|
||||
}
|
|
@ -5,4 +5,8 @@
|
|||
typedef uint64_t tu_time_t;
|
||||
|
||||
// Provides a high-accuracy time since the program started in microseconds (via std::chrono)
|
||||
tu_time_t tu_clock_micros();
|
||||
tu_time_t tu_clock_micros();
|
||||
|
||||
#ifdef TU_TIME_EXPOSE_TEST
|
||||
void tu_set_override(tu_time_t destTime);
|
||||
#endif
|
5
core/src/version.cpp.in
Normal file
5
core/src/version.cpp.in
Normal file
|
@ -0,0 +1,5 @@
|
|||
#include "version.h"
|
||||
|
||||
const char* BUILD_COMMIT_HASH = "@GIT_COMMIT_HASH@"; // Commit hash of the current build
|
||||
const char* BUILD_VERSION = "@GIT_VERSION@"; // Short form of the build version v1.2.3
|
||||
const char* BUILD_VERSION_LONG = "@GIT_VERSION_LONG@"; // Long form of the build version v1.2.3-12-g1234567
|
8
core/src/version.h
Normal file
8
core/src/version.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
// Allows files to read the version of the current build from git
|
||||
// https://jonathanhamberg.com/post/cmake-embedding-git-hash/
|
||||
|
||||
extern const char* BUILD_COMMIT_HASH; // Commit hash of the current build
|
||||
extern const char* BUILD_VERSION; // Short form of the build version v1.2.3
|
||||
extern const char* BUILD_VERSION_LONG; // Long form of the build version v1.2.3-12-g1234567
|
3
deps.txt
3
deps.txt
|
@ -1,8 +1,7 @@
|
|||
opengl (Linux: glvnd, Windows: [built-in/none])
|
||||
glfw
|
||||
glew
|
||||
glad
|
||||
glm
|
||||
sdl2
|
||||
stb
|
||||
qt6
|
||||
reactphysics3d
|
||||
|
|
|
@ -4,7 +4,7 @@ To do this, first download the source archive from [`https://www.riverbankcomput
|
|||
|
||||
Next, launch the *x64 Native Tools Command Prompt for VS 2022*, and cd into the directory that you extracted the archive to
|
||||
|
||||
Now, run `qmake` from your Qt's bin directory to configure it
|
||||
Now, run `qmake src` from your Qt's bin directory to configure it
|
||||
|
||||
Once that's done, build and install the project using `nmake install`
|
||||
|
||||
|
|
|
@ -1,21 +1,12 @@
|
|||
cmake_minimum_required(VERSION 3.30.0)
|
||||
|
||||
project(editor VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(QT_VERSION_MAJOR 6)
|
||||
find_package(Qt6 REQUIRED COMPONENTS Widgets OpenGLWidgets REQUIRED)
|
||||
find_package(QScintilla6 REQUIRED)
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Multimedia LinguistTools)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Multimedia LinguistTools)
|
||||
find_package(QScintilla REQUIRED)
|
||||
|
||||
set(TS_FILES editor_en_US.ts)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/deps.cmake)
|
||||
|
||||
set(PROJECT_SOURCES
|
||||
main.cpp
|
||||
|
@ -47,59 +38,25 @@ set(PROJECT_SOURCES
|
|||
${TS_FILES}
|
||||
)
|
||||
|
||||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||
qt_add_executable(editor
|
||||
MANUAL_FINALIZATION
|
||||
${PROJECT_SOURCES}
|
||||
)
|
||||
# Define target properties for Android with Qt 6 as:
|
||||
# set_property(TARGET editor APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
|
||||
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
|
||||
qt_add_executable(editor MANUAL_FINALIZATION ${PROJECT_SOURCES})
|
||||
target_include_directories(editor PRIVATE .)
|
||||
target_link_libraries(editor PRIVATE openblocks Qt6::Widgets Qt6::OpenGLWidgets ${QSCINTILLA_LIBRARY} miniaudio QCursorConstraints)
|
||||
|
||||
qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
|
||||
else()
|
||||
if(ANDROID)
|
||||
add_library(editor SHARED
|
||||
${PROJECT_SOURCES}
|
||||
)
|
||||
# Define properties for Android with Qt 5 after find_package() calls as:
|
||||
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
|
||||
else()
|
||||
add_executable(editor
|
||||
${PROJECT_SOURCES}
|
||||
mainglwidget.h mainglwidget.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
|
||||
endif()
|
||||
|
||||
target_include_directories(editor PUBLIC "../core/src" "../include" ${QSCINTILLA_INCLUDE_DIR})
|
||||
target_link_libraries(editor PRIVATE openblocks Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Multimedia ${QSCINTILLA_LIBRARY})
|
||||
add_dependencies(editor openblocks)
|
||||
|
||||
# Qt6 does not include QOpenGLWidgets as part of Widgets base anymore, so
|
||||
# we have to include it manually
|
||||
if (${QT_VERSION} GREATER_EQUAL 6)
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS OpenGL OpenGLWidgets)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS OpenGL OpenGLWidgets)
|
||||
|
||||
target_include_directories(editor PUBLIC Qt6::OpenGL Qt6::OpenGLWidgets)
|
||||
target_link_libraries(editor PRIVATE Qt6::OpenGL Qt6::OpenGLWidgets)
|
||||
endif()
|
||||
|
||||
# Copy assets
|
||||
add_custom_command(
|
||||
TARGET editor POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_SOURCE_DIR}/assets
|
||||
$<TARGET_FILE_DIR:editor>/assets)
|
||||
set_target_properties(editor PROPERTIES
|
||||
WIN32_EXECUTABLE ON
|
||||
)
|
||||
|
||||
# Copy Qt files
|
||||
if (WIN32)
|
||||
#include("${QT_DEPLOY_SUPPORT}")
|
||||
|
||||
# Copy assets
|
||||
add_custom_command(
|
||||
TARGET editor POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_SOURCE_DIR}/assets
|
||||
$<TARGET_FILE_DIR:editor>/assets)
|
||||
|
||||
# Copy over QScintilla DLLs
|
||||
# TODO: Use a better approach?
|
||||
add_custom_command(
|
||||
|
@ -107,45 +64,37 @@ if (WIN32)
|
|||
COMMAND ${CMAKE_COMMAND} -E copy ${QSCINTILLA_DLLS} $<TARGET_FILE_DIR:editor>
|
||||
)
|
||||
|
||||
set(WINDEPLOYQT_OPTIONS
|
||||
--dir $<TARGET_FILE_DIR:editor>
|
||||
--translations en
|
||||
--no-compiler-runtime
|
||||
--no-opengl-sw # No sense adding opengl-sw given that hardware acceleration is necessary, anyway
|
||||
--no-system-d3d-compiler
|
||||
--plugindir $<TARGET_FILE_DIR:editor>/qtplugins
|
||||
# Also don't want to clutter with plugins, add only needed ones
|
||||
)
|
||||
|
||||
# We split these into two commands because
|
||||
# we might build a debug binary against a release qscintilla library
|
||||
# TODO: Add other translations
|
||||
add_custom_command(
|
||||
TARGET editor POST_BUILD
|
||||
COMMAND ${WINDEPLOYQT_EXECUTABLE} $<TARGET_FILE:editor> ${QSCINTILLA_DLLS} --dir $<TARGET_FILE_DIR:editor> --translations en --no-compiler-runtime --no-opengl-sw --no-system-d3d-compiler --plugindir $<TARGET_FILE_DIR:editor>/qtplugins
|
||||
COMMAND ${WINDEPLOYQT_EXECUTABLE} $<TARGET_FILE:editor>
|
||||
${WINDEPLOYQT_OPTIONS}
|
||||
)
|
||||
# No sense adding opengl-sw given that hardware acceleration is necessary, anyway
|
||||
# Also don't want to clutter with plugins, add only needed ones
|
||||
|
||||
# Copy QScintilla dependencies too
|
||||
add_custom_command(
|
||||
TARGET editor POST_BUILD
|
||||
COMMAND ${WINDEPLOYQT_EXECUTABLE} ${QSCINTILLA_DLLS}
|
||||
${WINDEPLOYQT_OPTIONS}
|
||||
)
|
||||
|
||||
# Copy qt.conf to override default plugins location
|
||||
add_custom_command(
|
||||
TARGET editor POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/qt.conf $<TARGET_FILE_DIR:editor>/qt.conf
|
||||
)
|
||||
endif ()
|
||||
|
||||
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
||||
# If you are developing for iOS or macOS you should consider setting an
|
||||
# explicit, fixed bundle identifier manually though.
|
||||
if(${QT_VERSION} VERSION_LESS 6.1.0)
|
||||
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.qtbasic)
|
||||
endif()
|
||||
set_target_properties(editor PROPERTIES
|
||||
${BUNDLE_ID_OPTION}
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||
MACOSX_BUNDLE TRUE
|
||||
WIN32_EXECUTABLE TRUE
|
||||
)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
install(TARGETS editor
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
|
||||
install(FILES $<TARGET_RUNTIME_DLLS:editor> TYPE BIN)
|
||||
|
||||
if(QT_VERSION_MAJOR EQUAL 6)
|
||||
qt_finalize_executable(editor)
|
||||
endif()
|
||||
qt_finalize_executable(editor)
|
|
@ -1,5 +1,6 @@
|
|||
#include "aboutdialog.h"
|
||||
#include "./ui_aboutdialog.h"
|
||||
#include "version.h"
|
||||
#include <qdialogbuttonbox.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qplaintextedit.h>
|
||||
|
@ -40,6 +41,9 @@ AboutDialog::AboutDialog(QWidget *parent)
|
|||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->titleString->setText(QString() + "Openblocks Engine " + BUILD_VERSION);
|
||||
ui->versionString->setText(BUILD_VERSION_LONG);
|
||||
|
||||
connect(ui->viewLicense, &QLabel::linkActivated, [this]() {
|
||||
(new LicenseDialog(this))->open();
|
||||
});
|
||||
|
|
|
@ -7,19 +7,19 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>582</width>
|
||||
<height>162</height>
|
||||
<height>200</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>582</width>
|
||||
<height>162</height>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>582</width>
|
||||
<height>162</height>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -29,7 +29,7 @@
|
|||
<property name="geometry">
|
||||
<rect>
|
||||
<x>220</x>
|
||||
<y>110</y>
|
||||
<y>140</y>
|
||||
<width>341</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
|
@ -57,7 +57,7 @@
|
|||
<pixmap resource="editor.qrc">:/placeholder-logo.png</pixmap>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<widget class="QLabel" name="titleString">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>110</x>
|
||||
|
@ -67,7 +67,7 @@
|
|||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Openblocks Engine ALPHA SNAPSHOT</string>
|
||||
<string>Openblocks Engine</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_3">
|
||||
|
@ -96,6 +96,32 @@
|
|||
<string><a href="/license">View license...</a></string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>110</y>
|
||||
<width>81</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Version:</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="versionString">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>110</x>
|
||||
<y>110</y>
|
||||
<width>451</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>unknown</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="editor.qrc"/>
|
||||
|
|
4
editor/deps.cmake
Normal file
4
editor/deps.cmake
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
include(CPM)
|
||||
|
||||
CPMAddPackage("gh:m-doescode/qcursorconstraints#eb674e1fab418c4c5ccb7c599c19bd2e8a062faf")
|
|
@ -1,31 +1,48 @@
|
|||
#include "mainwindow.h"
|
||||
|
||||
#include "logger.h"
|
||||
#include "physics/world.h"
|
||||
#include <QApplication>
|
||||
#include <QLocale>
|
||||
#include <QTranslator>
|
||||
#include <QStyleFactory>
|
||||
#include <QBasicTimer>
|
||||
#include <QSurfaceFormat>
|
||||
#include <cstdio>
|
||||
#include <qfont.h>
|
||||
#include <qsurfaceformat.h>
|
||||
#include <miniaudio.h>
|
||||
#include <qcursorconstraints.h>
|
||||
|
||||
ma_engine miniaudio;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Logger::init();
|
||||
physicsInit();
|
||||
// Has to happen before Qt application initializes or we get an error in WASAPI initialization
|
||||
ma_result res = ma_engine_init(NULL, &miniaudio);
|
||||
if (res != MA_SUCCESS) {
|
||||
Logger::fatalErrorf("Failed to initialize Miniaudio withe error [%d]", res);
|
||||
panic();
|
||||
}
|
||||
|
||||
QSurfaceFormat format;
|
||||
format.setSamples(4);
|
||||
format.setRenderableType(QSurfaceFormat::OpenGL);
|
||||
format.setVersion(3, 3);
|
||||
format.setProfile(QSurfaceFormat::CompatibilityProfile); // Valid only in OpenGL 3.2+, see: https://stackoverflow.com/a/70519392/16255372
|
||||
QSurfaceFormat::setDefaultFormat(format);
|
||||
|
||||
QApplication a(argc, argv);
|
||||
|
||||
Logger::init();
|
||||
QCursorConstraints::init();
|
||||
|
||||
MainWindow w;
|
||||
w.show();
|
||||
int result = a.exec();
|
||||
|
||||
ma_engine_uninit(&miniaudio);
|
||||
physicsDeinit();
|
||||
Logger::finish();
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
#include <GL/glew.h>
|
||||
#include <glad/gl.h>
|
||||
#include <glm/common.hpp>
|
||||
#include <glm/vector_relational.hpp>
|
||||
#include <memory>
|
||||
#include <miniaudio.h>
|
||||
#include <qcursorconstraints.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qsoundeffect.h>
|
||||
#include <qguiapplication.h>
|
||||
#include <string>
|
||||
#include "./ui_mainwindow.h"
|
||||
#include "mainglwidget.h"
|
||||
#include "datatypes/vector.h"
|
||||
#include "enum/surface.h"
|
||||
#include "handles.h"
|
||||
#include "logger.h"
|
||||
#include "mainwindow.h"
|
||||
|
@ -17,7 +20,6 @@
|
|||
#include "objects/pvinstance.h"
|
||||
#include "objects/service/selection.h"
|
||||
#include "partassembly.h"
|
||||
#include "physics/util.h"
|
||||
#include "rendering/renderer.h"
|
||||
#include "rendering/shader.h"
|
||||
#include "datatypes/variant.h"
|
||||
|
@ -34,15 +36,20 @@ MainGLWidget::MainGLWidget(QWidget* parent): QOpenGLWidget(parent), contextMenu(
|
|||
}
|
||||
|
||||
void MainGLWidget::initializeGL() {
|
||||
glewInit();
|
||||
int version = gladLoaderLoadGL();
|
||||
if (version == 0) {
|
||||
Logger::fatalError("Failed to initialize OpenGL context");
|
||||
panic();
|
||||
} else {
|
||||
Logger::debugf("Initialized GL context version %d.%d", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
|
||||
}
|
||||
renderInit(width(), height());
|
||||
}
|
||||
|
||||
extern ma_engine miniaudio;
|
||||
inline void playSound(QString path) {
|
||||
QSoundEffect *sound = new QSoundEffect;
|
||||
sound->setSource(QUrl::fromLocalFile(path));
|
||||
sound->play();
|
||||
sound->connect(sound, &QSoundEffect::playingChanged, [=]() { /* Thank you QSound source code! */ sound->deleteLater(); return false; });
|
||||
ma_engine_stop(&miniaudio);
|
||||
ma_engine_play_sound(&miniaudio, path.toStdString().c_str(), NULL);
|
||||
}
|
||||
|
||||
extern int vpx, vpy;
|
||||
|
@ -67,14 +74,11 @@ void MainGLWidget::paintGL() {
|
|||
}
|
||||
|
||||
bool isMouseRightDragging = false;
|
||||
QPoint lastMousePos;
|
||||
QPoint mouseLockedPos;
|
||||
void MainGLWidget::handleCameraRotate(QMouseEvent* evt) {
|
||||
if (!isMouseRightDragging) return;
|
||||
|
||||
camera.processRotation(evt->pos().x() - lastMousePos.x(), evt->pos().y() - lastMousePos.y());
|
||||
lastMousePos = evt->pos();
|
||||
|
||||
// QCursor::setPos(lastMousePos);
|
||||
camera.processRotation(evt->pos().x() - mouseLockedPos.x(), evt->pos().y() - mouseLockedPos.y());
|
||||
}
|
||||
|
||||
|
||||
|
@ -143,10 +147,10 @@ void MainGLWidget::handleObjectDrag(QMouseEvent* evt) {
|
|||
|
||||
if (!rayHit) return;
|
||||
|
||||
CFrame targetFrame = partFromBody(rayHit->body)->cframe;
|
||||
CFrame targetFrame = rayHit->hitPart->cframe;
|
||||
Vector3 surfaceNormal = targetFrame.Inverse().Rotation() * rayHit->worldNormal;
|
||||
Vector3 inverseSurfaceNormal = Vector3::ONE - surfaceNormal.Abs();
|
||||
glm::vec3 partSize = partFromBody(rayHit->body)->size;
|
||||
glm::vec3 partSize = rayHit->hitPart->size;
|
||||
Vector3 tFormedHitPos = targetFrame * ((targetFrame.Inverse() * initialHitPos) * inverseSurfaceNormal);
|
||||
Vector3 tFormedInitialPos = targetFrame * ((targetFrame.Inverse() * initialFrame.Position()) * inverseSurfaceNormal);
|
||||
Vector3 vec = rayHit->worldPoint + (tFormedInitialPos - tFormedHitPos);
|
||||
|
@ -238,6 +242,7 @@ void MainGLWidget::handleLinearTransform(QMouseEvent* evt) {
|
|||
if (glm::any(glm::lessThan(glm::vec3(selectionAssembly.size() + abs(draggingHandle->normal) * diff), glm::vec3(0.001f))))
|
||||
return;
|
||||
|
||||
// This causes the velocity to be reset even though it shouldn't, but it's not a huge deal, so whatevs.
|
||||
selectionAssembly.TransformBy(CFrame() + absDiff * 0.5f);
|
||||
selectionAssembly.Scale(selectionAssembly.size() + abs(draggingHandle->normal) * diff, diff > 0);
|
||||
}
|
||||
|
@ -317,10 +322,11 @@ void MainGLWidget::handleRotationalTransform(QMouseEvent* evt) {
|
|||
|
||||
std::optional<HandleFace> MainGLWidget::raycastHandle(glm::vec3 pointDir) {
|
||||
if (!editorToolHandles.active) return std::nullopt;
|
||||
return ::raycastHandle(rp3d::Ray(glmToRp(camera.cameraPos), glmToRp(glm::normalize(pointDir)) * 50000));
|
||||
return ::raycastHandle(camera.cameraPos, glm::normalize(pointDir) * 50000.f);
|
||||
}
|
||||
|
||||
void MainGLWidget::handleCursorChange(QMouseEvent* evt) {
|
||||
if (isMouseRightDragging) return; // Don't change the cursor while it is intentionally blank
|
||||
QPoint position = evt->pos();
|
||||
|
||||
glm::vec3 pointDir = camera.getScreenDirection(glm::vec2(position.x(), position.y()), glm::vec2(width(), height()));
|
||||
|
@ -331,7 +337,7 @@ void MainGLWidget::handleCursorChange(QMouseEvent* evt) {
|
|||
};
|
||||
|
||||
std::optional<const RaycastResult> rayHit = gWorkspace()->CastRayNearest(camera.cameraPos, pointDir, 50000);
|
||||
if (rayHit && !partFromBody(rayHit->body)->locked) {
|
||||
if (rayHit && !rayHit->hitPart->locked) {
|
||||
setCursor(Qt::OpenHandCursor);
|
||||
return;
|
||||
}
|
||||
|
@ -371,8 +377,10 @@ void MainGLWidget::mousePressEvent(QMouseEvent* evt) {
|
|||
switch(evt->button()) {
|
||||
// Camera drag
|
||||
case Qt::RightButton: {
|
||||
lastMousePos = evt->pos();
|
||||
mouseLockedPos = evt->pos();
|
||||
isMouseRightDragging = true;
|
||||
setCursor(Qt::BlankCursor);
|
||||
QCursorConstraints::lockCursor(window()->windowHandle());
|
||||
return;
|
||||
// Clicking on objects
|
||||
} case Qt::LeftButton: {
|
||||
|
@ -395,17 +403,17 @@ void MainGLWidget::mousePressEvent(QMouseEvent* evt) {
|
|||
// raycast part
|
||||
std::shared_ptr<Selection> selection = gDataModel->GetService<Selection>();
|
||||
std::optional<const RaycastResult> rayHit = gWorkspace()->CastRayNearest(camera.cameraPos, pointDir, 50000);
|
||||
if (!rayHit || !partFromBody(rayHit->body)) { selection->Set({}); return; }
|
||||
std::shared_ptr<BasePart> part = partFromBody(rayHit->body);
|
||||
if (!rayHit || !rayHit->hitPart) { selection->Set({}); return; }
|
||||
std::shared_ptr<BasePart> part = rayHit->hitPart;
|
||||
if (part->locked) { selection->Set({}); return; }
|
||||
|
||||
std::shared_ptr<PVInstance> selObject = part;
|
||||
|
||||
// Traverse to the root model
|
||||
if (~evt->modifiers() & Qt::AltModifier) {
|
||||
std::optional<std::shared_ptr<Instance>> nextParent = selObject->GetParent();
|
||||
while (nextParent.value() && nextParent.value()->IsA("Model")) {
|
||||
selObject = std::dynamic_pointer_cast<PVInstance>(nextParent.value()); nextParent = selObject->GetParent();
|
||||
nullable std::shared_ptr<Instance> nextParent = selObject->GetParent();
|
||||
while (nextParent && nextParent->IsA("Model")) {
|
||||
selObject = std::dynamic_pointer_cast<PVInstance>(nextParent); nextParent = selObject->GetParent();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -419,16 +427,14 @@ void MainGLWidget::mousePressEvent(QMouseEvent* evt) {
|
|||
Vector3 localNormal = part->cframe.Inverse().Rotation() * rayHit->worldNormal;
|
||||
NormalId face = faceFromNormal(localNormal);
|
||||
SurfaceType surface = SurfaceType(mainWindow()->selectedTool - TOOL_SMOOTH);
|
||||
std::string surfacePropertyName = EnumType::NormalId.FromValue(face)->Name() + "Surface";
|
||||
|
||||
switch (face) {
|
||||
case Right: part->rightSurface = surface; break;
|
||||
case Top: part->topSurface = surface; break;
|
||||
case Back: part->backSurface = surface; break;
|
||||
case Left: part->leftSurface = surface; break;
|
||||
case Bottom: part->bottomSurface = surface; break;
|
||||
case Front: part->frontSurface = surface; break;
|
||||
default: return;
|
||||
}
|
||||
// Get old surface and set new surface
|
||||
EnumItem newSurface = EnumType::SurfaceType.FromValue((int)surface).value();
|
||||
EnumItem oldSurface = part->GetProperty(surfacePropertyName).expect().get<EnumItem>();
|
||||
part->SetProperty(surfacePropertyName, newSurface).expect();
|
||||
|
||||
M_mainWindow->undoManager.PushState({UndoStatePropertyChanged { part, surfacePropertyName, oldSurface, newSurface }});
|
||||
|
||||
if (mainWindow()->editSoundEffects && QFile::exists("./assets/excluded/electronicpingshort.wav"))
|
||||
playSound("./assets/excluded/electronicpingshort.wav");
|
||||
|
@ -459,11 +465,13 @@ void MainGLWidget::mousePressEvent(QMouseEvent* evt) {
|
|||
}
|
||||
|
||||
void MainGLWidget::mouseReleaseEvent(QMouseEvent* evt) {
|
||||
QCursorConstraints::unlockCursor(window()->windowHandle());
|
||||
// if (isMouseDragging) draggingObject.lock()->rigidBody->getCollider(0)->setCollisionCategoryBits(0b11);
|
||||
isMouseRightDragging = false;
|
||||
isMouseDragging = false;
|
||||
draggingObject = {};
|
||||
draggingHandle = std::nullopt;
|
||||
setCursor(Qt::ArrowCursor);
|
||||
|
||||
if (!initialTransforms.empty()) {
|
||||
UndoState historyState;
|
||||
|
@ -471,6 +479,7 @@ void MainGLWidget::mouseReleaseEvent(QMouseEvent* evt) {
|
|||
for (auto t : initialTransforms) {
|
||||
historyState.push_back(UndoStatePropertyChanged { t.part, "CFrame", t.cframe, t.part->cframe });
|
||||
historyState.push_back(UndoStatePropertyChanged { t.part, "Size", t.size, t.part->size });
|
||||
historyState.push_back(UndoStatePropertyChanged { t.part, "Velocity", t.velocity, t.part->velocity });
|
||||
}
|
||||
|
||||
M_mainWindow->undoManager.PushState(historyState);
|
||||
|
|
|
@ -10,7 +10,10 @@
|
|||
#include "placedocument.h"
|
||||
#include "script/scriptdocument.h"
|
||||
#include "undohistory.h"
|
||||
#include "version.h"
|
||||
#include <memory>
|
||||
#include <QToolButton>
|
||||
#include <QSettings>
|
||||
#include <qclipboard.h>
|
||||
#include <qevent.h>
|
||||
#include <qglobal.h>
|
||||
|
@ -19,18 +22,16 @@
|
|||
#include <qmessagebox.h>
|
||||
#include <qmimedata.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qsoundeffect.h>
|
||||
#include <qstylefactory.h>
|
||||
#include <qstylehints.h>
|
||||
#include <qmdisubwindow.h>
|
||||
#include <pugixml.hpp>
|
||||
#include <qtextcursor.h>
|
||||
#include <qtextedit.h>
|
||||
#include <miniaudio.h>
|
||||
#include <qtoolbutton.h>
|
||||
#include <vector>
|
||||
|
||||
#ifdef _NDEBUG
|
||||
#define NDEBUG
|
||||
#endif
|
||||
#include <fstream>
|
||||
|
||||
bool worldSpaceTransforms = false;
|
||||
|
||||
|
@ -57,22 +58,24 @@ void logQtMessage(QtMsgType type, const QMessageLogContext &context, const QStri
|
|||
// if (defaultMessageHandler) defaultMessageHandler(type, context, msg);
|
||||
}
|
||||
|
||||
extern ma_engine miniaudio;
|
||||
inline void playSound(QString path) {
|
||||
QSoundEffect *sound = new QSoundEffect;
|
||||
sound->setSource(QUrl::fromLocalFile(path));
|
||||
sound->play();
|
||||
sound->connect(sound, &QSoundEffect::playingChanged, [=]() { /* Thank you QSound source code! */ sound->deleteLater(); return false; });
|
||||
ma_engine_play_sound(&miniaudio, path.toStdString().c_str(), NULL);
|
||||
}
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
loadState();
|
||||
|
||||
gDataModel->Init();
|
||||
|
||||
ui->setupUi(this);
|
||||
setMouseTracking(true);
|
||||
|
||||
setWindowTitle(QString() + "Openblocks Editor " + BUILD_VERSION);
|
||||
|
||||
ui->actionRedo->setShortcuts({QKeySequence("Ctrl+Shift+Z"), QKeySequence("Ctrl+Y")});
|
||||
|
||||
QIcon::setThemeSearchPaths(QIcon::themeSearchPaths() + QStringList { "./assets/icons" });
|
||||
|
@ -101,6 +104,28 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
|
||||
connectActionHandlers();
|
||||
|
||||
// Add open recents menu
|
||||
refreshRecentsMenu();
|
||||
for (QObject* child : ui->fileTools->children()) {
|
||||
if (auto toolButton = dynamic_cast<QToolButton*>(child)) {
|
||||
if (toolButton->defaultAction() != ui->actionOpen) continue;
|
||||
|
||||
// https://stackoverflow.com/a/12283957/16255372
|
||||
// https://stackoverflow.com/a/5365184/16255372
|
||||
|
||||
toolButton->setMenu(recentsMenu);
|
||||
toolButton->setPopupMode(QToolButton::MenuButtonPopup);
|
||||
}
|
||||
}
|
||||
|
||||
// Add open recents dropdown to file menu
|
||||
auto actions = ui->menuFile->actions();
|
||||
for (int i = 0; i < actions.size(); i++) {
|
||||
if (actions[i] != ui->actionOpen) continue;
|
||||
|
||||
ui->menuFile->insertMenu((i+1) < actions.size() ? actions[i+1] : nullptr, recentsMenu);
|
||||
}
|
||||
|
||||
// ui->explorerView->Init(ui);
|
||||
placeDocument = new PlaceDocument(this);
|
||||
placeDocument->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
|
@ -121,9 +146,22 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
});
|
||||
|
||||
setUpCommandBar();
|
||||
|
||||
#ifndef NDEBUG
|
||||
// https://stackoverflow.com/a/17631703/16255372
|
||||
// Add shortcut for reloading most recent file
|
||||
QAction* reloadMostRecent = new QAction();
|
||||
reloadMostRecent->setShortcut(Qt::Key_R | Qt::CTRL);
|
||||
connect(reloadMostRecent, &QAction::triggered, [this, reloadMostRecent]() {
|
||||
recentsMenu->actions()[0]->trigger();
|
||||
removeAction(reloadMostRecent);
|
||||
});
|
||||
addAction(reloadMostRecent);
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent* evt) {
|
||||
saveState();
|
||||
#ifdef NDEBUG
|
||||
// Ask if the user wants to save their changes
|
||||
// https://stackoverflow.com/a/33890731
|
||||
|
@ -146,6 +184,64 @@ void MainWindow::closeEvent(QCloseEvent* evt) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::refreshRecentsMenu() {
|
||||
if (!recentsMenu) recentsMenu = new QMenu();
|
||||
|
||||
recentsMenu->setTitle("Recent files...");
|
||||
|
||||
recentsMenu->clear(); // Actions not shown in any other menu are automatically deleted
|
||||
for (QString item : recentFiles) {
|
||||
QAction* itemAction = new QAction();
|
||||
itemAction->setText(item.split('/').last());
|
||||
recentsMenu->addAction(itemAction);
|
||||
|
||||
connect(itemAction, &QAction::triggered, [item, this]{
|
||||
if (!QFile::exists(item)) {
|
||||
QMessageBox::warning(this, "File not found", "The file '" + item + "' could not longer be found at that location.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<DataModel> newModel = DataModel::LoadFromFile(item.toStdString());
|
||||
editModeDataModel = newModel;
|
||||
gDataModel = newModel;
|
||||
newModel->Init();
|
||||
ui->explorerView->updateRoot(newModel);
|
||||
|
||||
// Reset running state
|
||||
placeDocument->setRunState(RUN_STOPPED);
|
||||
undoManager.Reset();
|
||||
updateToolbars();
|
||||
pushRecentFile(item);
|
||||
});
|
||||
}
|
||||
|
||||
if (recentsMenu->isEmpty()) {
|
||||
QAction* emptyAction = new QAction("No recents");
|
||||
emptyAction->setEnabled(false);
|
||||
recentsMenu->addAction(emptyAction);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::loadState() {
|
||||
QSettings settings("openblocks");
|
||||
recentFiles = settings.value("recentFiles").toStringList();
|
||||
}
|
||||
|
||||
void MainWindow::saveState() {
|
||||
QSettings settings("openblocks");
|
||||
settings.setValue("recentFiles", recentFiles);
|
||||
}
|
||||
|
||||
void MainWindow::pushRecentFile(QString file) {
|
||||
// https://www.walletfox.com/course/qtopenrecentfiles.php
|
||||
recentFiles.removeAll(file);
|
||||
recentFiles.prepend(file);
|
||||
while (recentFiles.size() > 10) recentFiles.removeLast();
|
||||
|
||||
refreshRecentsMenu();
|
||||
saveState();
|
||||
}
|
||||
|
||||
void MainWindow::setUpCommandBar() {
|
||||
CommandEdit* commandEdit;
|
||||
QToolBar* commandBar = ui->commandBar;
|
||||
|
@ -279,6 +375,7 @@ void MainWindow::connectActionHandlers() {
|
|||
}
|
||||
|
||||
editModeDataModel->SaveToFile(path);
|
||||
if (path) pushRecentFile(QString::fromStdString(path.value()));
|
||||
});
|
||||
|
||||
connect(ui->actionSaveAs, &QAction::triggered, this, [&]() {
|
||||
|
@ -286,6 +383,7 @@ void MainWindow::connectActionHandlers() {
|
|||
if (!path || path == "") return;
|
||||
|
||||
editModeDataModel->SaveToFile(path);
|
||||
if (path) pushRecentFile(QString::fromStdString(path.value()));
|
||||
});
|
||||
|
||||
connect(ui->actionOpen, &QAction::triggered, this, [&]() {
|
||||
|
@ -306,6 +404,7 @@ void MainWindow::connectActionHandlers() {
|
|||
placeDocument->setRunState(RUN_STOPPED);
|
||||
undoManager.Reset();
|
||||
updateToolbars();
|
||||
if (path) pushRecentFile(QString::fromStdString(path.value()));
|
||||
});
|
||||
|
||||
connect(ui->actionDelete, &QAction::triggered, this, [&]() {
|
||||
|
@ -313,8 +412,8 @@ void MainWindow::connectActionHandlers() {
|
|||
std::shared_ptr<Selection> selection = gDataModel->GetService<Selection>();
|
||||
for (std::weak_ptr<Instance> inst : selection->Get()) {
|
||||
if (inst.expired()) continue;
|
||||
historyState.push_back(UndoStateInstanceRemoved { inst.lock(), inst.lock()->GetParent().value() });
|
||||
inst.lock()->SetParent(std::nullopt);
|
||||
historyState.push_back(UndoStateInstanceRemoved { inst.lock(), inst.lock()->GetParent() });
|
||||
inst.lock()->SetParent(nullptr);
|
||||
}
|
||||
selection->Set({});
|
||||
historyState.push_back(UndoStateSelectionChanged {selection->Get(), {}});
|
||||
|
@ -343,9 +442,9 @@ void MainWindow::connectActionHandlers() {
|
|||
std::shared_ptr<Selection> selection = gDataModel->GetService<Selection>();
|
||||
for (std::weak_ptr<Instance> inst : selection->Get()) {
|
||||
if (inst.expired()) continue;
|
||||
historyState.push_back(UndoStateInstanceRemoved { inst.lock(), inst.lock()->GetParent().value() });
|
||||
historyState.push_back(UndoStateInstanceRemoved { inst.lock(), inst.lock()->GetParent() });
|
||||
inst.lock()->Serialize(rootDoc);
|
||||
inst.lock()->SetParent(std::nullopt);
|
||||
inst.lock()->SetParent(nullptr);
|
||||
}
|
||||
selection->Set({});
|
||||
historyState.push_back(UndoStateSelectionChanged {selection->Get(), {}});
|
||||
|
@ -412,8 +511,8 @@ void MainWindow::connectActionHandlers() {
|
|||
bool done = false;
|
||||
std::shared_ptr<Selection> selection = gDataModel->GetService<Selection>();
|
||||
for (auto object : selection->Get()) {
|
||||
if (firstParent == nullptr && object->GetParent().has_value()) firstParent = object->GetParent().value();
|
||||
historyState.push_back(UndoStateInstanceReparented { object, object->GetParent().value(), model });
|
||||
if (!firstParent && object->GetParent() != nullptr) firstParent = object->GetParent();
|
||||
historyState.push_back(UndoStateInstanceReparented { object, object->GetParent(), model });
|
||||
object->SetParent(model);
|
||||
done = true;
|
||||
}
|
||||
|
@ -445,13 +544,13 @@ void MainWindow::connectActionHandlers() {
|
|||
done = true;
|
||||
|
||||
for (auto object : model->GetChildren()) {
|
||||
historyState.push_back(UndoStateInstanceReparented { object, object->GetParent().value(), model->GetParent().value() });
|
||||
historyState.push_back(UndoStateInstanceReparented { object, object->GetParent(), model->GetParent() });
|
||||
object->SetParent(model->GetParent());
|
||||
newSelection.push_back(object);
|
||||
}
|
||||
|
||||
historyState.push_back(UndoStateInstanceRemoved { model, model->GetParent().value() });
|
||||
model->SetParent(std::nullopt);
|
||||
historyState.push_back(UndoStateInstanceRemoved { model, model->GetParent() });
|
||||
model->SetParent(nullptr);
|
||||
}
|
||||
|
||||
if (!done)
|
||||
|
|
|
@ -64,10 +64,18 @@ public:
|
|||
void openFile(std::string path);
|
||||
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
QMenu* recentsMenu = nullptr;
|
||||
QStringList recentFiles;
|
||||
void refreshRecentsMenu();
|
||||
void pushRecentFile(QString);
|
||||
|
||||
void loadState();
|
||||
void saveState();
|
||||
|
||||
friend PlaceDocument;
|
||||
private:
|
||||
PlaceDocument* placeDocument;
|
||||
PlaceDocument* placeDocument = nullptr;
|
||||
|
||||
void setUpCommandBar();
|
||||
void connectActionHandlers();
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1050</width>
|
||||
<width>1100</width>
|
||||
<height>750</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
|
|
@ -18,24 +18,24 @@ ExplorerModel::ExplorerModel(std::shared_ptr<Instance> dataRoot, QWidget *parent
|
|||
: QAbstractItemModel(parent)
|
||||
, rootItem(dataRoot) {
|
||||
// TODO: Don't use lambdas and handlers like that
|
||||
hierarchyPreUpdateHandler = [&](std::shared_ptr<Instance> object, std::optional<std::shared_ptr<Instance>> oldParent, std::optional<std::shared_ptr<Instance>> newParent) {
|
||||
if (oldParent.has_value()) {
|
||||
auto children = oldParent.value()->GetChildren();
|
||||
hierarchyPreUpdateHandler = [&](std::shared_ptr<Instance> object, nullable std::shared_ptr<Instance> oldParent, nullable std::shared_ptr<Instance> newParent) {
|
||||
if (oldParent) {
|
||||
auto children = oldParent->GetChildren();
|
||||
size_t idx = std::find(children.begin(), children.end(), object) - children.begin();
|
||||
beginRemoveRows(toIndex(oldParent.value()), idx, idx);
|
||||
beginRemoveRows(toIndex(oldParent), idx, idx);
|
||||
}
|
||||
|
||||
if (newParent.has_value()) {
|
||||
size_t size = newParent.value()->GetChildren().size();
|
||||
beginInsertRows(toIndex(newParent.value()), size, size);
|
||||
if (newParent) {
|
||||
size_t size = newParent->GetChildren().size();
|
||||
beginInsertRows(toIndex(newParent), size, size);
|
||||
} else {
|
||||
// TODO:
|
||||
}
|
||||
};
|
||||
|
||||
hierarchyPostUpdateHandler = [&](std::shared_ptr<Instance> object, std::optional<std::shared_ptr<Instance>> oldParent, std::optional<std::shared_ptr<Instance>> newParent) {
|
||||
if (newParent.has_value()) endInsertRows();
|
||||
if (oldParent.has_value()) endRemoveRows();
|
||||
hierarchyPostUpdateHandler = [&](std::shared_ptr<Instance> object, nullable std::shared_ptr<Instance> oldParent, nullable std::shared_ptr<Instance> newParent) {
|
||||
if (newParent) endInsertRows();
|
||||
if (oldParent) endRemoveRows();
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -49,16 +49,22 @@ QModelIndex ExplorerModel::index(int row, int column, const QModelIndex &parent)
|
|||
? static_cast<Instance*>(parent.internalPointer())
|
||||
: rootItem.get();
|
||||
|
||||
#ifdef NDEBUG
|
||||
if (parentItem->GetChildren().size() >= (size_t)row && !(parentItem->GetChildren()[row]->GetClass()->flags & INSTANCE_HIDDEN))
|
||||
return createIndex(row, column, parentItem->GetChildren()[row].get());
|
||||
#else
|
||||
// Don't hide in debug builds
|
||||
if (parentItem->GetChildren().size() >= (size_t)row)
|
||||
return createIndex(row, column, parentItem->GetChildren()[row].get());
|
||||
#endif
|
||||
return {};
|
||||
}
|
||||
|
||||
QModelIndex ExplorerModel::toIndex(std::shared_ptr<Instance> item) {
|
||||
if (item == rootItem || !item->GetParent().has_value())
|
||||
if (item == rootItem || !item->GetParent())
|
||||
return {};
|
||||
|
||||
std::shared_ptr<Instance> parentItem = item->GetParent().value();
|
||||
std::shared_ptr<Instance> parentItem = item->GetParent();
|
||||
// Check above ensures this item is not root, so value() must be valid
|
||||
for (size_t i = 0; i < parentItem->GetChildren().size(); i++)
|
||||
if (parentItem->GetChildren()[i] == item)
|
||||
|
@ -76,13 +82,13 @@ QModelIndex ExplorerModel::parent(const QModelIndex &index) const {
|
|||
|
||||
Instance* childItem = static_cast<Instance*>(index.internalPointer());
|
||||
// NORISK: The parent must exist if the child was obtained from it during this frame
|
||||
std::shared_ptr<Instance> parentItem = childItem->GetParent().value();
|
||||
std::shared_ptr<Instance> parentItem = childItem->GetParent();
|
||||
|
||||
if (parentItem == rootItem)
|
||||
return {};
|
||||
|
||||
// Check above ensures this item is not root, so value() must be valid
|
||||
std::shared_ptr<Instance> parentParent = parentItem->GetParent().value();
|
||||
std::shared_ptr<Instance> parentParent = parentItem->GetParent();
|
||||
for (size_t i = 0; i < parentParent->GetChildren().size(); i++)
|
||||
if (parentParent->GetChildren()[i] == parentItem)
|
||||
return createIndex(i, 0, parentItem.get());
|
||||
|
@ -97,7 +103,15 @@ int ExplorerModel::rowCount(const QModelIndex &parent) const {
|
|||
? static_cast<Instance*>(parent.internalPointer())
|
||||
: rootItem.get();
|
||||
|
||||
#ifdef NDEBUG
|
||||
// Trim trailing hidden items as they make the branches look weird
|
||||
int count = parentItem->GetChildren().size();
|
||||
while (count > 0 && parentItem->GetChildren()[count-1]->GetClass()->flags & INSTANCE_HIDDEN) count--;
|
||||
return count;
|
||||
#else
|
||||
// Don't hide in debug builds
|
||||
return parentItem->GetChildren().size();
|
||||
#endif
|
||||
}
|
||||
|
||||
int ExplorerModel::columnCount(const QModelIndex &parent) const {
|
||||
|
@ -223,7 +237,7 @@ bool ExplorerModel::dropMimeData(const QMimeData *data, Qt::DropAction action, i
|
|||
UndoState historyState;
|
||||
std::shared_ptr<Instance> parentInst = fromIndex(parent);
|
||||
for (std::shared_ptr<Instance> instance : slot->instances) {
|
||||
historyState.push_back(UndoStateInstanceReparented { instance, instance->GetParent().value_or(nullptr), parentInst });
|
||||
historyState.push_back(UndoStateInstanceReparented { instance, instance->GetParent(), parentInst });
|
||||
instance->SetParent(parentInst);
|
||||
}
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue