Skip to content

Commit

Permalink
Fix model structure transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Feb 14, 2024
1 parent 9bae854 commit 6a5e5d7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/bsp/Bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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++)
{
Expand Down
30 changes: 20 additions & 10 deletions src/editor/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ Renderer::Renderer()

hoverAxis = -1;
saveTranformResult = false;
deltaMoveOffset = vec3();
}

Renderer::~Renderer()
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2635,7 +2646,6 @@ void Renderer::updateDragAxes(vec3 delta)

scaleAxes.origin = modelOrigin;
scaleAxes.origin += ent->origin;
scaleAxes.origin += delta;
}
}
else
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/editor/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScalableTexinfo> scaleTexinfos; // texture coordinates to scale
bool textureLock = false;
bool moveOrigin = true;
Expand Down Expand Up @@ -293,7 +294,7 @@ class Renderer

vec3 getAxisDragPoint(vec3 origin);

void updateDragAxes(vec3 delta = vec3());
void updateDragAxes();
void updateModelVerts();
void updateSelectionSize();
void updateEntConnections();
Expand Down

0 comments on commit 6a5e5d7

Please sign in to comment.