From db42149fb5e726d3addb46f26bdefd8cf65252cc Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Mon, 24 Feb 2025 17:10:23 -0600 Subject: [PATCH] Path class augs adds the following behaviours: onPostAdd, send an updatePath event so that paths created post-pathOnMissionLoadDone command can register with clients (like say when they are loaded from a submis) for editing tool purposes, allow Path::SetTransform to impact child objects so that pre-existing ones can be copy/pasted without the markers ending up in the same spot, or so that you can shift the entire path around and have those move in a relative manner --- Engine/source/scene/simPath.cpp | 43 +++++++++++++++++++++++++++++++++ Engine/source/scene/simPath.h | 2 ++ 2 files changed, 45 insertions(+) diff --git a/Engine/source/scene/simPath.cpp b/Engine/source/scene/simPath.cpp index b726caa8e..1e12a5adf 100644 --- a/Engine/source/scene/simPath.cpp +++ b/Engine/source/scene/simPath.cpp @@ -35,6 +35,7 @@ #include "renderInstance/renderPassManager.h" #include "console/engineAPI.h" #include "T3D/pathShape.h" +#include "T3D/physics/physicsShape.h" #include "T3D/Scene.h" @@ -197,6 +198,12 @@ bool Path::onAdd() return true; } +void Path::onPostAdd() +{ + Parent::onPostAdd(); + if (isServerObject()) + updatePath(); +} IMPLEMENT_CALLBACK(Path, onAdd, void, (SimObjectId ID), (ID), "Called when this ScriptGroup is added to the system.\n" "@param ID Unique object ID assigned when created (%this in script).\n" @@ -252,6 +259,42 @@ void Path::updatePath() gServerPathManager->updatePath(mPathIndex, positions, rotations, times, smoothingTypes, mIsLooping); } +void Path::setTransform(const MatrixF& mat) +{ + if (isServerObject()) + { + MatrixF newXform = mat; + MatrixF oldXform = getTransform(); + oldXform.affineInverse(); + + MatrixF offset; + offset.mul(newXform, oldXform); + + // Update all child transforms + for (SimSetIterator itr(this); *itr; ++itr) + { + SceneObject* child = dynamic_cast(*itr); + if (child) + { + MatrixF childMat; + + //add the "offset" caused by the parents change, and add it to it's own + // This is needed by objects that update their own render transform thru interpolate tick + // Mostly for stationary objects. + childMat.mul(offset, child->getTransform()); + child->setTransform(childMat); + + PhysicsShape* childPS = dynamic_cast(child); + if (childPS) + childPS->storeRestorePos(); + } + } + updatePath(); + } + + Parent::setTransform(mat); +} + void Path::addObject(SimObject* obj) { Parent::addObject(obj); diff --git a/Engine/source/scene/simPath.h b/Engine/source/scene/simPath.h index 244cf7154..4c95f6771 100644 --- a/Engine/source/scene/simPath.h +++ b/Engine/source/scene/simPath.h @@ -76,12 +76,14 @@ class Path : public GameBase ~Path(); void addObject(SimObject*) override; + void onPostAdd() override; void removeObject(SimObject*) override; void sortMarkers(); void updatePath(); bool isLooping() { return mIsLooping; } U32 getPathIndex() const; + void setTransform(const MatrixF& mat) override; DECLARE_CONOBJECT(Path); DECLARE_CATEGORY("Cinematic");