From 6a5e5d7479ccdaaf63c327f29e63c7e097b95d85 Mon Sep 17 00:00:00 2001 From: Unreal Karaulov Date: Wed, 14 Feb 2024 12:54:31 +0300 Subject: [PATCH] Fix model structure transformation --- src/bsp/Bsp.cpp | 4 ++-- src/editor/Renderer.cpp | 30 ++++++++++++++++++++---------- src/editor/Renderer.h | 3 ++- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/bsp/Bsp.cpp b/src/bsp/Bsp.cpp index 2b0a7096..782572c6 100644 --- a/src/bsp/Bsp.cpp +++ b/src/bsp/Bsp.cpp @@ -948,7 +948,7 @@ bool Bsp::move(vec3 offset, int modelIdx, bool onlyModel, bool forceMove, bool l // for submodels. All other data is ignored. bspguy will reuse world leaves in submodels to // save space, which means moving leaves for those models would likely break something else. // So, don't move leaves for submodels. - bool dontMoveLeaves = !movingWorld; + // bool dontMoveLeaves = !movingWorld; if (!forceMove && does_model_use_shared_structures(modelIdx)) split_shared_model_structures(modelIdx); @@ -996,7 +996,7 @@ bool Bsp::move(vec3 offset, int modelIdx, bool onlyModel, bool forceMove, bool l } STRUCTUSAGE shouldBeMoved(this); - mark_model_structures(modelIdx, &shouldBeMoved, dontMoveLeaves); + mark_model_structures(modelIdx, &shouldBeMoved, false /*dontMoveLeaves*/); for (int i = 0; i < nodeCount; i++) { diff --git a/src/editor/Renderer.cpp b/src/editor/Renderer.cpp index 892f9f2e..823e52d4 100644 --- a/src/editor/Renderer.cpp +++ b/src/editor/Renderer.cpp @@ -343,6 +343,7 @@ Renderer::Renderer() hoverAxis = -1; saveTranformResult = false; + deltaMoveOffset = vec3(); } Renderer::~Renderer() @@ -1959,9 +1960,11 @@ bool Renderer::transformAxisControls() Entity* ent = map->ents[entIdx[0]]; int modelIdx = ent->getBspModelIdx(); // axis handle dragging + if (showDragAxes && !movingEnt && hoverAxis != -1 && curLeftMouse == GLFW_PRESS && oldLeftMouse == GLFW_RELEASE) { + deltaMoveOffset = vec3(); axisDragEntOriginStart = getEntOrigin(map, ent); axisDragStart = getAxisDragPoint(axisDragEntOriginStart); } @@ -2038,11 +2041,10 @@ bool Renderer::transformAxisControls() } else { - vertPickCount++; + deltaMoveOffset += delta; + /*vertPickCount++; map->move(delta, modelIdx, true, false, false); - map->getBspRender()->refreshEnt((int)entIdx[0]); - //map->getBspRender()->refreshModel(modelIdx); - updateEntConnectionPositions(); + updateEntConnectionPositions();*/ } } else if (transformTarget == TRANSFORM_ORIGIN) @@ -2122,11 +2124,20 @@ bool Renderer::transformAxisControls() else { saveTranformResult = false; + vec3 neworigin = gridSnappingEnabled ? snapToGrid(deltaMoveOffset) : deltaMoveOffset; + if (!neworigin.IsZero()) + { + map->move(neworigin, modelIdx, true, false, false); + } + deltaMoveOffset = vec3(); map->resize_all_lightmaps(); + + applyTransform(map, true); + map->regenerate_clipnodes(modelIdx, -1); + map->getBspRender()->refreshEnt((int)entIdx[0]); map->getBspRender()->refreshModel(modelIdx); map->getBspRender()->refreshModelClipnodes(modelIdx); - applyTransform(map, true); updateEntConnectionPositions(); map->getBspRender()->pushModelUndoState("Move Model", EDIT_MODEL_LUMPS | FL_ENTITIES); } @@ -2574,7 +2585,7 @@ vec3 Renderer::getEntOffset(Bsp* map, Entity* ent) return vec3(); } -void Renderer::updateDragAxes(vec3 delta) +void Renderer::updateDragAxes() { Bsp* map = SelectedMap; Entity* ent = NULL; @@ -2635,7 +2646,6 @@ void Renderer::updateDragAxes(vec3 delta) scaleAxes.origin = modelOrigin; scaleAxes.origin += ent->origin; - scaleAxes.origin += delta; } } else @@ -2668,12 +2678,12 @@ void Renderer::updateDragAxes(vec3 delta) else moveAxes.origin = ent->origin; - moveAxes.origin += delta; + moveAxes.origin += deltaMoveOffset; } else { moveAxes.origin = getEntOrigin(map, ent); - moveAxes.origin += delta; + moveAxes.origin += deltaMoveOffset; } } @@ -2705,7 +2715,7 @@ void Renderer::updateDragAxes(vec3 delta) if (selectTotal != 0) { moveAxes.origin = min + (max - min) * 0.5f; - moveAxes.origin += delta; + moveAxes.origin += deltaMoveOffset; } } } diff --git a/src/editor/Renderer.h b/src/editor/Renderer.h index 6b1c7b0c..ff6faa00 100644 --- a/src/editor/Renderer.h +++ b/src/editor/Renderer.h @@ -199,6 +199,7 @@ class Renderer bool pickClickHeld = true; // true if the mouse button is still held after picking an object vec3 axisDragStart; vec3 axisDragEntOriginStart; + vec3 deltaMoveOffset; std::vector scaleTexinfos; // texture coordinates to scale bool textureLock = false; bool moveOrigin = true; @@ -293,7 +294,7 @@ class Renderer vec3 getAxisDragPoint(vec3 origin); - void updateDragAxes(vec3 delta = vec3()); + void updateDragAxes(); void updateModelVerts(); void updateSelectionSize(); void updateEntConnections();