Building interior walls created with editor

This commit is contained in:
2026-01-02 01:41:58 +03:00
parent d6d61229f8
commit 49fc547295
8 changed files with 1733 additions and 205 deletions

View File

@@ -360,7 +360,7 @@ class App : public OgreBites::ApplicationContext {
SkyBoxRenderer *sky;
bool mGrab;
KeyboardListener mKbd;
SceneData mEditorNormalScene, mEditorAltScene;
SceneData mEditorNormalScene;
public:
App()
@@ -377,7 +377,6 @@ public:
OgreBites::ApplicationContext::setup();
Ogre::Root *root = getRoot();
mEditorNormalScene.setup(root, getOverlaySystem());
mEditorAltScene.setup(root, getOverlaySystem());
}
bool isWindowGrab()
{
@@ -407,7 +406,6 @@ public:
{
// and tell it to render into the main window
mEditorNormalScene.initCamera("fps_camera");
mEditorNormalScene.initCamera("alt_camera");
mViewport = getRenderWindow()->addViewport(
mEditorNormalScene.mCamera);
}
@@ -420,7 +418,6 @@ public:
<< "\n";
Ogre::Root *root = getRoot();
mEditorNormalScene.setupRTSS();
mEditorAltScene.setupRTSS();
setWindowGrab(false);
std::cout << "Init camera"
<< "\n";
@@ -455,26 +452,6 @@ public:
ECS::get().modified<ECS::GUI>();
}
ECS::update(delta);
#if 0
if (switchWindow) {
int scene = ECS::get<ECS::EditorSceneSwitch>().scene;
mEditorNormalScene.mScnMgr->removeRenderQueueListener(
getOverlaySystem());
mEditorAltScene.mScnMgr->removeRenderQueueListener(
getOverlaySystem());
mViewport->setOverlaysEnabled(false);
if (scene == 0)
mViewport->setCamera(
mEditorNormalScene.mCamera);
else if (scene == 1)
mViewport->setCamera(mEditorAltScene.mCamera);
mViewport->setOverlaysEnabled(true);
mEditorNormalScene.mScnMgr->addRenderQueueListener(
getOverlaySystem());
mEditorAltScene.mScnMgr->addRenderQueueListener(
getOverlaySystem());
}
#endif
}
class InputListenerChainFlexible : public OgreBites::InputListener {
protected:
@@ -632,10 +609,6 @@ public:
mEditorNormalScene.mScnMgr,
/*mDynWorld.get(), */ mEditorNormalScene.mCameraNode,
mEditorNormalScene.mCamera, getRenderWindow());
ECS::setupEditorAlt(
mEditorAltScene.mScnMgr,
/*mDynWorld.get(), */ mEditorAltScene.mCameraNode,
mEditorAltScene.mCamera, getRenderWindow());
ECS::get().import <ECS::EditorGizmoModule>();
ECS::get().import <ECS::EditorInputModule>();
ECS::get().set<ECS::RenderWindow>(
@@ -667,14 +640,6 @@ public:
nullptr,
{ getImGuiInputListener(), &mKbd } });
ECS::get().add<ECS::EditorDebugMaterial>();
#if 0
ECS::get()
.observer<ECS::EditorSceneSwitch>("UpdateEditorScene")
.event(flecs::OnSet)
.each([&](ECS::EditorSceneSwitch &sw) {
switchWindow = true;
});
#endif
std::shared_ptr<Ogre::ManualObject> manualObj(
mEditorNormalScene.mScnMgr->createManualObject(
"EditorGizmo"));
@@ -684,79 +649,6 @@ public:
gizmoNode->attachObject(manualObj.get());
manualObj->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY);
ECS::get().set<ECS::EditorGizmo>({ manualObj, gizmoNode });
#if 0
ECS::get()
.system<const ECS::EngineData, ECS::Camera,
const ECS::Input>("UpdateEditorCamera")
.kind(flecs::OnUpdate)
.each([&](const ECS::EngineData &eng,
ECS::Camera &camera,
const ECS::Input &input) {
if (!camera.configured) {
// create a pivot at roughly the character's shoulder
camera.mCameraPivot =
eng.mScnMgr->getRootSceneNode()
->createChildSceneNode();
camera.mCameraGoal =
camera.mCameraPivot
->createChildSceneNode(
Ogre::Vector3(
0, 2,
0));
camera.mCameraNode->setPosition(
camera.mCameraPivot
->getPosition() +
camera.mCameraGoal
->getPosition());
camera.mCameraGoal->lookAt(
Ogre::Vector3(0, 0, -10),
Ogre::Node::TS_PARENT);
camera.mCameraPivot->setFixedYawAxis(
true);
camera.mCameraGoal->setFixedYawAxis(
true);
camera.mCameraNode->setFixedYawAxis(
true);
// our model is quite small, so reduce the clipping planes
camera.mCamera->setNearClipDistance(
0.1f);
camera.mCamera->setFarClipDistance(700);
camera.mPivotPitch = 0;
camera.configured = true;
} else {
// place the camera pivot roughly at the character's shoulder
#if 0
camera.mCameraPivot->setPosition(
ch.mBodyNode->getPosition() +
Ogre::Vector3::UNIT_Y * CAM_HEIGHT);
#endif
// move the camera smoothly to the goal
Ogre::Vector3 goalOffset =
camera.mCameraGoal
->_getDerivedPosition() -
camera.mCameraNode
->getPosition();
camera.mCameraNode->translate(
goalOffset * eng.delta * 9.0f);
// always look at the pivot
#if 0
camera.mCameraNode->lookAt(
camera.mCameraPivot
->_getDerivedPosition(),
Ogre::Node::TS_PARENT);
#endif
camera.mCameraNode->_setDerivedOrientation(
camera.mCameraGoal
->_getDerivedOrientation());
}
if (input.control & 512 && input.mouse_moved) {
mCameraPivot->yaw(
Ogre::Radian(-input.mouse.x *
3.0f * eng.delta));
}
});
#endif
}
bool get_gui_active()
{

View File

@@ -259,9 +259,4 @@ bool Vector3::zeroLength() const
return (l < 1e-06 * 1e-06);
}
void setupEditorAlt(Ogre::SceneManager *scnMgr, Ogre::SceneNode *cameraNode,
Ogre::Camera *camera, Ogre::RenderWindow *window)
{
}
}

View File

@@ -347,8 +347,8 @@ public:
break;
long x = collider_queue.front().x;
long y = collider_queue.front().y;
std::cout << x << " " << y << " "
<< collider_queue.size() << std::endl;
// std::cout << x << " " << y << " "
// << collider_queue.size() << std::endl;
Ogre::Terrain *terrain = group->getTerrain(x, y);
Ogre::Vector3 worldPos;
group->convertTerrainSlotToWorldPosition(x, y,

View File

@@ -13,6 +13,7 @@
#include "TerrainModule.h"
#include "physics.h"
#include "PhysicsModule.h"
#include "LuaData.h"
#include "harbour.h"
#include "temple.h"
#include "town.h"
@@ -30,6 +31,92 @@ void showItemPopup(const std::pair<flecs::entity, Ogre::String> &item)
StaticGeometryModule::getItemProperties(item.first);
nlohmann::json j = nlohmann::json::parse(prop);
Ogre::String itemType = j["type"].get<Ogre::String>();
bool changed = false;
bool set = false;
bool offset = false;
Ogre::Vector3 offsetVal(0, 0, 0);
int i;
struct OffsetButton {
Ogre::String label;
Ogre::Vector3 offset;
ImGuiDir direction;
};
struct OffsetButton buttons_large[] = {
{ "ElevateUp", { 0, 1, 0 }, ImGuiDir::ImGuiDir_Up },
{ "ElevateDown", { 0, -1, 0 }, ImGuiDir::ImGuiDir_Down },
{ "X+", { 1, 0, 0 }, ImGuiDir::ImGuiDir_None },
{ "X-", { -1, 0, 0 }, ImGuiDir::ImGuiDir_None },
{ "Z+", { 0, 0, 1 }, ImGuiDir::ImGuiDir_None },
{ "Z-", { 0, 0, -1 }, ImGuiDir::ImGuiDir_None },
};
struct OffsetButton buttons_small[] = {
{ "SmallElevateUp",
{ 0, 0.1f, 0 },
ImGuiDir::ImGuiDir_Up },
{ "SmallElevateDown",
{ 0, -0.1f, 0 },
ImGuiDir::ImGuiDir_Down },
{ "0.1 X+", { 0.1f, 0, 0 }, ImGuiDir::ImGuiDir_None },
{ "0.1 X-", { -0.1f, 0, 0 }, ImGuiDir::ImGuiDir_None },
{ "0.1 Z+", { 0, 0, 0.1f }, ImGuiDir::ImGuiDir_None },
{ "0.1 Z-", { 0, 0, -0.1f }, ImGuiDir::ImGuiDir_None },
};
if (ImGui::SmallButton("Set position from cursor")) {
changed = true;
set = true;
}
auto buttonGroup = [&](struct OffsetButton *button, int count) {
int i;
for (i = 0; i < count; i++) {
if (i > 0)
ImGui::SameLine();
if (button[i].direction !=
ImGuiDir::ImGuiDir_None) {
if (ImGui::ArrowButton(
button[i].label.c_str(),
button[i].direction)) {
offsetVal = button[i].offset;
offset = true;
changed = true;
}
} else {
if (ImGui::SmallButton(
button[i].label.c_str())) {
offsetVal = button[i].offset;
offset = true;
changed = true;
}
}
}
};
buttonGroup(buttons_large,
sizeof(buttons_large) / sizeof(buttons_large[0]));
buttonGroup(buttons_small,
sizeof(buttons_small) / sizeof(buttons_small[0]));
if (changed) {
Ogre::Vector3 position =
item.first.get<TerrainItem>().position;
Ogre::Quaternion orientation =
item.first.get<TerrainItem>().orientation;
if (set) {
position = ECS::get<EditorGizmo>()
.sceneNode
->_getDerivedPosition();
orientation =
ECS::get<EditorGizmo>()
.sceneNode
->_getDerivedOrientation();
} else if (offset)
position += offsetVal;
item.first.get_mut<TerrainItem>().position = position;
item.first.get_mut<TerrainItem>().orientation =
orientation;
item.first.modified<TerrainItem>();
StaticGeometryModule::saveItems();
StaticGeometryModule::destroyItemGeometry(item.first);
StaticGeometryModule::createItemGeometry(item.first);
}
if (itemType == "harbour")
createHarbourPopup(item);
else if (itemType == "temple")
@@ -82,8 +169,9 @@ void createItemsMenu()
if (ImGui::BeginMenu("Town")) {
Items::createTownMenu();
ImGui::EndMenu();
}
}
}
}
namespace Geometry
{
@@ -220,4 +308,4 @@ flecs::entity createMeshGeometry(const Ogre::String &meshName,
}
}
}
}

View File

@@ -86,4 +86,4 @@ static void from_json(const nlohmann::json &j, Ogre::Quaternion &orientation)
orientation.z = j["z"].get<float>();
}
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -12,10 +12,16 @@ void createTownPopup(const std::pair<flecs::entity, Ogre::String> item);
}
namespace Geometry
{
void createCells(flecs::entity e, const nlohmann::json &jdistrict, int index,
Ogre::SceneNode *sceneNode, Ogre::StaticGeometry *geo);
void createTown(flecs::entity e, Ogre::SceneNode *sceneNode,
Ogre::StaticGeometry *geo);
void createTownPlazza(flecs::entity e, const nlohmann::json &jdistrict,
Ogre::SceneNode *sceneNode, Ogre::StaticGeometry *geo);
int index, Ogre::SceneNode *sceneNode,
Ogre::StaticGeometry *geo);
void createTownLots(flecs::entity e, const nlohmann::json &jdistrict,
int index, Ogre::SceneNode *sceneNode,
Ogre::StaticGeometry *geo);
}
}
#endif
#endif

View File

@@ -895,8 +895,14 @@ public:
msp.ScaleToMass(mass);
bodySettings.mMassPropertiesOverride = msp;
}
return createBody(bodySettings, listener);
}
JPH::BodyID id = createBody(bodySettings, listener);
if (shape->GetType() == JPH::EShapeType::HeightField) {
JPH::BodyInterface &body_interface =
physics_system.GetBodyInterface();
body_interface.SetFriction(id, 1.0f);
}
return id;
}
JPH::BodyID createBody(const JPH::Shape *shape, float mass,
Ogre::SceneNode *node, JPH::EMotionType motion,
JPH::ObjectLayer layer,
@@ -906,20 +912,8 @@ public:
const Ogre::Quaternion &rotation =
node->_getDerivedOrientation();
std::cout << "body position: " << position << std::endl;
JPH::BodyCreationSettings bodySettings(
shape, JoltPhysics::convert(position),
JoltPhysics::convert(rotation), motion, layer);
if (mass > 0.001f) {
JPH::MassProperties msp;
msp.ScaleToMass(mass);
bodySettings.mMassPropertiesOverride = msp;
}
JPH::BodyID id = createBody(bodySettings, listener);
if (shape->GetType() == JPH::EShapeType::HeightField) {
JPH::BodyInterface &body_interface =
physics_system.GetBodyInterface();
body_interface.SetFriction(id, 1.0f);
}
JPH::BodyID id = createBody(shape, mass, position, rotation,
motion, layer, listener);
id2node[id] = node;
node2id[node] = id;
return id;