Refactor Pre Rotation from spline model and spline collider into Pre Transform for more control
This commit is contained in:
@@ -28,16 +28,16 @@ SplineModel::~SplineModel()
|
||||
Allocator::Free(_deformationBufferData);
|
||||
}
|
||||
|
||||
Quaternion SplineModel::GetPreRotation() const
|
||||
Transform SplineModel::GetPreTransform() const
|
||||
{
|
||||
return _preRotation;
|
||||
return _preTransform;
|
||||
}
|
||||
|
||||
void SplineModel::SetPreRotation(const Quaternion& value)
|
||||
void SplineModel::SetPreTransform(const Transform& value)
|
||||
{
|
||||
if (_preRotation == value)
|
||||
if (_preTransform == value)
|
||||
return;
|
||||
_preRotation = value;
|
||||
_preTransform = value;
|
||||
OnSplineUpdated();
|
||||
}
|
||||
|
||||
@@ -135,8 +135,8 @@ void SplineModel::OnSplineUpdated()
|
||||
for (int32 i = 0; i < 8; i++)
|
||||
{
|
||||
// Transform mesh corner using pre-transform but use double-precision to prevent issues when rotating model
|
||||
Vector3 tmp = corners[i];
|
||||
double rotation[4] = { (double)_preRotation.X, (double)_preRotation.Y, (double)_preRotation.Z, (double)_preRotation.W };
|
||||
Vector3 tmp = corners[i] * _preTransform.Scale;
|
||||
double rotation[4] = { (double)_preTransform.Orientation.X, (double)_preTransform.Orientation.Y, (double)_preTransform.Orientation.Z, (double)_preTransform.Orientation.W };
|
||||
const double length = sqrt(rotation[0] * rotation[0] + rotation[1] * rotation[1] + rotation[2] * rotation[2] + rotation[3] * rotation[3]);
|
||||
const double inv = 1.0 / length;
|
||||
rotation[0] *= inv;
|
||||
@@ -157,9 +157,9 @@ void SplineModel::OnSplineUpdated()
|
||||
const double yz = rotation[1] * z;
|
||||
const double zz = rotation[2] * z;
|
||||
tmp = Vector3(
|
||||
(float)(pos[0] * (1.0 - yy - zz) + pos[1] * (xy - wz) + pos[2] * (xz + wy)),
|
||||
(float)(pos[0] * (xy + wz) + pos[1] * (1.0 - xx - zz) + pos[2] * (yz - wx)),
|
||||
(float)(pos[0] * (xz - wy) + pos[1] * (yz + wx) + pos[2] * (1.0 - xx - yy)));
|
||||
(float)(pos[0] * (1.0 - yy - zz) + pos[1] * (xy - wz) + pos[2] * (xz + wy)) + _preTransform.Translation.X,
|
||||
(float)(pos[0] * (xy + wz) + pos[1] * (1.0 - xx - zz) + pos[2] * (yz - wx)) + _preTransform.Translation.Y,
|
||||
(float)(pos[0] * (xz - wy) + pos[1] * (yz + wx) + pos[2] * (1.0 - xx - yy)) + _preTransform.Translation.Z);
|
||||
|
||||
localModelBounds.Minimum = Vector3::Min(localModelBounds.Minimum, tmp);
|
||||
localModelBounds.Maximum = Vector3::Max(localModelBounds.Maximum, tmp);
|
||||
@@ -359,7 +359,7 @@ void SplineModel::Draw(RenderContext& renderContext)
|
||||
drawCall.Deformable.MeshMaxZ = _meshMaxZ;
|
||||
drawCall.Deformable.GeometrySize = _box.GetSize();
|
||||
drawCall.PerInstanceRandom = GetPerInstanceRandom();
|
||||
Matrix::RotationQuaternion(_preRotation, drawCall.Deformable.LocalMatrix);
|
||||
_preTransform.GetWorld(drawCall.Deformable.LocalMatrix);
|
||||
const Transform splineTransform = GetTransform();
|
||||
splineTransform.GetWorld(drawCall.World);
|
||||
drawCall.ObjectPosition = drawCall.World.GetTranslation() + drawCall.Deformable.LocalMatrix.GetTranslation();
|
||||
@@ -445,7 +445,7 @@ void SplineModel::Serialize(SerializeStream& stream, const void* otherObj)
|
||||
SERIALIZE_MEMBER(BoundsScale, _boundsScale);
|
||||
SERIALIZE_MEMBER(LODBias, _lodBias);
|
||||
SERIALIZE_MEMBER(ForcedLOD, _forcedLod);
|
||||
SERIALIZE_MEMBER(PreRotation, _preRotation)
|
||||
SERIALIZE_MEMBER(PreTransform, _preTransform)
|
||||
SERIALIZE(Model);
|
||||
SERIALIZE(DrawModes);
|
||||
|
||||
@@ -462,7 +462,7 @@ void SplineModel::Deserialize(DeserializeStream& stream, ISerializeModifier* mod
|
||||
DESERIALIZE_MEMBER(BoundsScale, _boundsScale);
|
||||
DESERIALIZE_MEMBER(LODBias, _lodBias);
|
||||
DESERIALIZE_MEMBER(ForcedLOD, _forcedLod);
|
||||
DESERIALIZE_MEMBER(PreRotation, _preRotation);
|
||||
DESERIALIZE_MEMBER(PreTransform, _preTransform);
|
||||
DESERIALIZE(Model);
|
||||
DESERIALIZE(DrawModes);
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ private:
|
||||
char _forcedLod = -1;
|
||||
bool _deformationDirty = false;
|
||||
Array<Instance> _instances;
|
||||
Quaternion _preRotation = Quaternion::Identity;
|
||||
Transform _preTransform = Transform::Identity;
|
||||
Spline* _spline = nullptr;
|
||||
GPUBuffer* _deformationBuffer = nullptr;
|
||||
void* _deformationBufferData = nullptr;
|
||||
@@ -43,15 +43,15 @@ public:
|
||||
AssetReference<Model> Model;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rotation applied to the model geometry before placing it over the spline. Can be used to change the way model goes over the spline.
|
||||
/// Gets the transformation applied to the model geometry before placing it over the spline. Can be used to change the way model goes over the spline.
|
||||
/// </summary>
|
||||
API_PROPERTY(Attributes="EditorOrder(21), EditorDisplay(\"Model\")")
|
||||
Quaternion GetPreRotation() const;
|
||||
Transform GetPreTransform() const;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the rotation applied to the model geometry before placing it over the spline. Can be used to change the way model goes over the spline.
|
||||
/// Sets the transformation applied to the model geometry before placing it over the spline. Can be used to change the way model goes over the spline.
|
||||
/// </summary>
|
||||
API_PROPERTY() void SetPreRotation(const Quaternion& value);
|
||||
API_PROPERTY() void SetPreTransform(const Transform& value);
|
||||
|
||||
/// <summary>
|
||||
/// The draw passes to use for rendering this object.
|
||||
|
||||
@@ -22,16 +22,16 @@ SplineCollider::SplineCollider(const SpawnParams& params)
|
||||
CollisionData.Loaded.Bind<SplineCollider, &SplineCollider::OnCollisionDataLoaded>(this);
|
||||
}
|
||||
|
||||
Quaternion SplineCollider::GetPreRotation() const
|
||||
Transform SplineCollider::GetPreTransform() const
|
||||
{
|
||||
return _preRotation;
|
||||
return _preTransform;
|
||||
}
|
||||
|
||||
void SplineCollider::SetPreRotation(const Quaternion& value)
|
||||
void SplineCollider::SetPreTransform(const Transform& value)
|
||||
{
|
||||
if (_preRotation == value)
|
||||
if (_preTransform == value)
|
||||
return;
|
||||
_preRotation = value;
|
||||
_preTransform = value;
|
||||
UpdateGeometry();
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ void SplineCollider::Serialize(SerializeStream& stream, const void* otherObj)
|
||||
SERIALIZE_GET_OTHER_OBJ(SplineCollider);
|
||||
|
||||
SERIALIZE(CollisionData);
|
||||
SERIALIZE_MEMBER(PreRotation, _preRotation)
|
||||
SERIALIZE_MEMBER(PreTransform, _preTransform)
|
||||
}
|
||||
|
||||
void SplineCollider::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
|
||||
@@ -139,7 +139,7 @@ void SplineCollider::Deserialize(DeserializeStream& stream, ISerializeModifier*
|
||||
Collider::Deserialize(stream, modifier);
|
||||
|
||||
DESERIALIZE(CollisionData);
|
||||
DESERIALIZE_MEMBER(PreRotation, _preRotation);
|
||||
DESERIALIZE_MEMBER(PreTransform, _preTransform);
|
||||
}
|
||||
|
||||
void SplineCollider::OnParentChanged()
|
||||
@@ -205,10 +205,10 @@ void SplineCollider::GetGeometry(PxGeometryHolder& geometry)
|
||||
}
|
||||
|
||||
// Apply local mesh transformation
|
||||
if (!_preRotation.IsIdentity())
|
||||
if (!_preTransform.IsIdentity())
|
||||
{
|
||||
for (int32 i = 0; i < collisionVertices.Count(); i++)
|
||||
collisionVertices[i] = Vector3::Transform(collisionVertices[i], _preRotation);
|
||||
collisionVertices[i] = _preTransform.LocalToWorld(collisionVertices[i]);
|
||||
}
|
||||
|
||||
// Find collision geometry local bounds
|
||||
|
||||
@@ -21,7 +21,7 @@ private:
|
||||
PxTriangleMesh* _triangleMesh = nullptr;
|
||||
Array<Vector3> _vertexBuffer;
|
||||
Array<int32> _indexBuffer;
|
||||
Quaternion _preRotation = Quaternion::Identity;
|
||||
Transform _preTransform = Transform::Identity;
|
||||
|
||||
public:
|
||||
|
||||
@@ -32,15 +32,15 @@ public:
|
||||
AssetReference<CollisionData> CollisionData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rotation applied to the collision data model geometry before placing it over the spline. Can be used to change the way model goes over the spline.
|
||||
/// Gets the transformation applied to the collision data model geometry before placing it over the spline. Can be used to change the way model goes over the spline.
|
||||
/// </summary>
|
||||
API_PROPERTY(Attributes="EditorOrder(101), EditorDisplay(\"Collider\")")
|
||||
Quaternion GetPreRotation() const;
|
||||
Transform GetPreTransform() const;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the rotation applied to the collision data model geometry before placing it over the spline. Can be used to change the way model goes over the spline.
|
||||
/// Sets the transformation applied to the collision data model geometry before placing it over the spline. Can be used to change the way model goes over the spline.
|
||||
/// </summary>
|
||||
API_PROPERTY() void SetPreRotation(const Quaternion& value);
|
||||
API_PROPERTY() void SetPreTransform(const Transform& value);
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
|
||||
Reference in New Issue
Block a user