Ajout de Jolt Physics + 1ere version des factory entitecomposants - camera, transform, rigidbody, collider, renderer

This commit is contained in:
Tom Ray
2026-03-22 00:28:03 +01:00
parent 6695d46bcd
commit 48348936a8
1147 changed files with 214331 additions and 353 deletions

View File

@@ -0,0 +1,31 @@
# Root
set(JOLT_VIEWER_ROOT ${PHYSICS_REPO_ROOT}/JoltViewer)
# Source files
set(JOLT_VIEWER_SRC_FILES
${JOLT_VIEWER_ROOT}/JoltViewer.cmake
${JOLT_VIEWER_ROOT}/JoltViewer.cpp
${JOLT_VIEWER_ROOT}/JoltViewer.h
)
# Group source files
source_group(TREE ${JOLT_VIEWER_ROOT} FILES ${JOLT_VIEWER_SRC_FILES})
# Create JoltViewer executable
if ("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
# Icon
set(JPH_ICON "${CMAKE_CURRENT_SOURCE_DIR}/macOS/icon.icns")
set_source_files_properties(${JPH_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
add_executable(JoltViewer MACOSX_BUNDLE ${JOLT_VIEWER_SRC_FILES} ${TEST_FRAMEWORK_ASSETS} ${JPH_ICON})
set_property(TARGET JoltViewer PROPERTY MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/iOS/JoltViewerInfo.plist")
set_property(TARGET JoltViewer PROPERTY XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.joltphysics.joltviewer")
set_property(TARGET JoltViewer PROPERTY BUILD_RPATH "/usr/local/lib" INSTALL_RPATH "/usr/local/lib") # to find the Vulkan shared lib
else()
add_executable(JoltViewer ${JOLT_VIEWER_SRC_FILES})
endif()
target_include_directories(JoltViewer PUBLIC ${JOLT_VIEWER_ROOT})
target_link_libraries(JoltViewer LINK_PUBLIC TestFramework)
# Set the correct working directory
set_property(TARGET JoltViewer PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${PHYSICS_REPO_ROOT}")

View File

@@ -0,0 +1,148 @@
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
// SPDX-License-Identifier: MIT
#include <TestFramework.h>
#include <JoltViewer.h>
#include <Jolt/Core/StreamWrapper.h>
#include <Application/EntryPoint.h>
#include <Renderer/DebugRendererImp.h>
#include <UI/UIManager.h>
#include <Application/DebugUI.h>
#include <Utils/Log.h>
JPH_SUPPRESS_WARNINGS_STD_BEGIN
#include <fstream>
JPH_SUPPRESS_WARNINGS_STD_END
JPH_GCC_SUPPRESS_WARNING("-Wswitch")
#ifndef JPH_DEBUG_RENDERER
// Hack to still compile DebugRenderer inside the test framework when Jolt is compiled without
#define JPH_DEBUG_RENDERER
#include <Jolt/Renderer/DebugRendererRecorder.cpp>
#include <Jolt/Renderer/DebugRendererPlayback.cpp>
#undef JPH_DEBUG_RENDERER
#endif
JoltViewer::JoltViewer(const String &inCommandLine) :
Application("Jolt Viewer", inCommandLine)
{
// Get file name from command line
Array<String> args;
StringToVector(inCommandLine, args, " ");
// Check arguments
if (args.size() != 2 || args[1].empty())
FatalError("Usage: JoltViewer <recording filename>");
// Open file
ifstream stream(args[1].c_str(), ifstream::in | ifstream::binary);
if (!stream.is_open())
FatalError("Could not open recording file");
// Parse the stream
StreamInWrapper wrapper(stream);
mRendererPlayback.Parse(wrapper);
if (mRendererPlayback.GetNumFrames() == 0)
FatalError("Recording file did not contain any frames");
// Draw the first frame
mRendererPlayback.DrawFrame(0);
// Start paused
Pause(true);
// Create UI
UIElement *main_menu = mDebugUI->CreateMenu();
mDebugUI->CreateTextButton(main_menu, "Help", [this](){
UIElement *help = mDebugUI->CreateMenu();
mDebugUI->CreateStaticText(help,
"ESC: Back to previous menu.\n"
"WASD + Mouse: Fly around. Hold Shift to speed up, Ctrl to slow down.\n"
"P: Pause / unpause simulation.\n"
"O: Single step simulation.\n"
",: Step back.\n"
".: Step forward.\n"
"Shift + ,: Play reverse.\n"
"Shift + .: Replay forward."
);
mDebugUI->ShowMenu(help);
});
mDebugUI->ShowMenu(main_menu);
}
bool JoltViewer::UpdateFrame(float inDeltaTime)
{
// If no frames were read, abort
if (mRendererPlayback.GetNumFrames() == 0)
return false;
// Handle keyboard input
bool shift = mKeyboard->IsKeyPressed(EKey::LShift) || mKeyboard->IsKeyPressed(EKey::RShift);
for (EKey key = mKeyboard->GetFirstKey(); key != EKey::Invalid; key = mKeyboard->GetNextKey())
switch (key)
{
case EKey::R:
// Restart
mCurrentFrame = 0;
mPlaybackMode = EPlaybackMode::Play;
Pause(true);
break;
case EKey::O:
// Step
mPlaybackMode = EPlaybackMode::Play;
SingleStep();
break;
case EKey::Comma:
// Back
mPlaybackMode = shift? EPlaybackMode::Rewind : EPlaybackMode::StepBack;
Pause(false);
break;
case EKey::Period:
// Forward
mPlaybackMode = shift? EPlaybackMode::Play : EPlaybackMode::StepForward;
Pause(false);
break;
}
// If paused, do nothing
if (inDeltaTime > 0.0f)
{
// Determine new frame number
switch (mPlaybackMode)
{
case EPlaybackMode::StepForward:
mPlaybackMode = EPlaybackMode::Stop;
[[fallthrough]];
case EPlaybackMode::Play:
if (mCurrentFrame + 1 < mRendererPlayback.GetNumFrames())
++mCurrentFrame;
break;
case EPlaybackMode::StepBack:
mPlaybackMode = EPlaybackMode::Stop;
[[fallthrough]];
case EPlaybackMode::Rewind:
if (mCurrentFrame > 0)
--mCurrentFrame;
break;
case EPlaybackMode::Stop:
break;
}
// Render the frame
mRendererPlayback.DrawFrame(mCurrentFrame);
}
return true;
}
ENTRY_POINT(JoltViewer, RegisterDefaultAllocator)

View File

@@ -0,0 +1,46 @@
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
// SPDX-License-Identifier: MIT
#pragma once
#include <Application/Application.h>
#ifdef JPH_DEBUG_RENDERER
#include <Jolt/Renderer/DebugRendererPlayback.h>
#else
// Hack to still compile DebugRenderer inside the test framework when Jolt is compiled without
#define JPH_DEBUG_RENDERER
// Make sure the debug renderer symbols don't get imported or exported
#define JPH_DEBUG_RENDERER_EXPORT
#include <Jolt/Renderer/DebugRendererPlayback.h>
#undef JPH_DEBUG_RENDERER
#undef JPH_DEBUG_RENDERER_EXPORT
#endif
using namespace std;
// Application that views recordings produced by DebugRendererRecorder
class JoltViewer : public Application
{
public:
// Constructor / destructor
JoltViewer(const String &inCommandLine);
// Update the application
virtual bool UpdateFrame(float inDeltaTime) override;
private:
enum class EPlaybackMode
{
Rewind,
StepBack,
Stop,
StepForward,
Play
};
DebugRendererPlayback mRendererPlayback { *mDebugRenderer };
EPlaybackMode mPlaybackMode = EPlaybackMode::Play; // Current playback state. Indicates if we're playing or scrubbing back/forward.
uint mCurrentFrame = 0;
};