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
This commit is contained in:
AzaezelX 2025-02-24 17:10:23 -06:00
parent 0ebb2e9115
commit db42149fb5
2 changed files with 45 additions and 0 deletions

View file

@ -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<SceneObject*>(*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<PhysicsShape*>(child);
if (childPS)
childPS->storeRestorePos();
}
}
updatePath();
}
Parent::setTransform(mat);
}
void Path::addObject(SimObject* obj)
{
Parent::addObject(obj);

View file

@ -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");