Use lcObjectProperty in Piece.

This commit is contained in:
Leonardo Zide 2023-12-28 10:21:52 -08:00
parent eeabc06c49
commit e4f4df4376
6 changed files with 55 additions and 110 deletions

View file

@ -254,7 +254,7 @@ public:
void SetUpVector(const lcVector3& UpVector, lcStep Step, bool AddKey)
{
mPositionKeys.ChangeKey(UpVector, Step, AddKey);
mUpVectorKeys.ChangeKey(UpVector, Step, AddKey);
}
float GetOrthoHeight() const

View file

@ -112,22 +112,8 @@ void lcLight::SaveLDraw(QTextStream& Stream) const
if (!mCastShadow)
Stream << QLatin1String("0 !LEOCAD LIGHT SHADOWLESS") << LineEnding;
const float* Matrix = mWorldMatrix;
const float Numbers[12] = { Matrix[12], -Matrix[14], Matrix[13], Matrix[0], -Matrix[8], Matrix[4], -Matrix[2], Matrix[10], -Matrix[6], Matrix[1], -Matrix[9], Matrix[5] };
if (mPosition.GetSize() > 1)
mPosition.SaveKeysLDraw(Stream, "LIGHT", "POSITION");
else
Stream << QLatin1String("0 !LEOCAD LIGHT POSITION ") << Numbers[0] << ' ' << Numbers[1] << ' ' << Numbers[2] << LineEnding;
if (!IsPointLight())
{
if (mRotation.GetSize() > 1)
mRotation.SaveKeysLDraw(Stream, "LIGHT", "ROTATION");
else
Stream << QLatin1String("0 !LEOCAD LIGHT ROTATION ") << Numbers[3] << ' ' << Numbers[4] << ' ' << Numbers[5] << ' ' << Numbers[6] << ' ' << Numbers[7] << ' ' << Numbers[8] << ' ' << Numbers[9] << ' ' << Numbers[10] << ' ' << Numbers[11] << LineEnding;
}
mPosition.Save(Stream, "LIGHT", "POSITION");
mRotation.Save(Stream, "LIGHT", "ROTATION");
mColor.Save(Stream, "LIGHT", "COLOR");
mSize.Save(Stream, "LIGHT", "SIZE");
mPower.Save(Stream, "LIGHT", "POWER");
@ -227,40 +213,10 @@ bool lcLight::ParseLDrawLine(QTextStream& Stream)
QString Token;
Stream >> Token;
if (Token == QLatin1String("POSITION"))
{
lcVector3 Position;
Stream >> Position[0] >> Position[1] >> Position[2];
Position = lcVector3LDrawToLeoCAD(Position);
mWorldMatrix.SetTranslation(Position);
mPosition.ChangeKey(Position, 1, true);
}
else if (Token == QLatin1String("POSITION_KEY"))
mPosition.LoadKeysLDraw(Stream); // todo: convert from ldraw
else if (Token == QLatin1String("ROTATION"))
{
float Numbers[9];
for (int TokenIdx = 0; TokenIdx < 9; TokenIdx++)
Stream >> Numbers[TokenIdx];
float* Matrix = mWorldMatrix;
Matrix[0] = Numbers[0];
Matrix[8] = -Numbers[1];
Matrix[4] = Numbers[2];
Matrix[2] = -Numbers[3];
Matrix[10] = Numbers[4];
Matrix[6] = -Numbers[5];
Matrix[1] = Numbers[6];
Matrix[9] = -Numbers[7];
Matrix[5] = Numbers[8];
mRotation.ChangeKey(lcMatrix33(mWorldMatrix), 1, true);
}
else if (Token == QLatin1String("ROTATION_KEY"))
mRotation.LoadKeysLDraw(Stream); // todo: convert from ldraw
if (mPosition.Load(Stream, Token, "POSITION"))
continue;
else if (mRotation.Load(Stream, Token, "ROTATION"))
continue;
else if (mColor.Load(Stream, Token, "COLOR"))
continue;
else if (mSize.Load(Stream, Token, "SIZE"))

View file

@ -331,17 +331,17 @@ protected:
QString mName;
lcLightType mLightType = lcLightType::Point;
bool mCastShadow = true;
lcObjectProperty<lcVector3> mPosition = lcVector3(0.0f, 0.0f, 0.0f);
lcObjectProperty<lcMatrix33> mRotation = lcMatrix33Identity();
lcObjectProperty<lcVector3> mColor = lcVector3(1.0f, 1.0f, 1.0f);
lcObjectProperty<lcVector2> mSize = lcVector2(0.0f, 0.0f);
lcObjectProperty<float> mPower = 1.0f;
lcObjectProperty<float> mAttenuationDistance = 0.0f;
lcObjectProperty<float> mAttenuationPower = 0.0f;
lcObjectProperty<float> mSpotConeAngle = 80.0f;
lcObjectProperty<float> mSpotPenumbraAngle = 0.0f;
lcObjectProperty<float> mSpotTightness = 0.0f;
lcObjectProperty<lcVector2i> mAreaGrid = lcVector2i(2, 2);
lcObjectProperty<lcVector3> mPosition = lcObjectProperty<lcVector3>(lcVector3(0.0f, 0.0f, 0.0f));
lcObjectProperty<lcMatrix33> mRotation = lcObjectProperty<lcMatrix33>(lcMatrix33Identity());
lcObjectProperty<lcVector3> mColor = lcObjectProperty<lcVector3>(lcVector3(1.0f, 1.0f, 1.0f));
lcObjectProperty<lcVector2> mSize = lcObjectProperty<lcVector2>(lcVector2(0.0f, 0.0f));
lcObjectProperty<float> mPower = lcObjectProperty<float>(1.0f);
lcObjectProperty<float> mAttenuationDistance = lcObjectProperty<float>(0.0f);
lcObjectProperty<float> mAttenuationPower = lcObjectProperty<float>(0.0f);
lcObjectProperty<float> mSpotConeAngle = lcObjectProperty<float>(80.0f);
lcObjectProperty<float> mSpotPenumbraAngle = lcObjectProperty<float>(0.0f);
lcObjectProperty<float> mSpotTightness = lcObjectProperty<float>(0.0f);
lcObjectProperty<lcVector2i> mAreaGrid = lcObjectProperty<lcVector2i>(lcVector2i(2, 2));
lcLightAreaShape mAreaShape = lcLightAreaShape::Rectangle;
quint32 mState = 0;

View file

@ -52,17 +52,12 @@ template<typename T>
class lcObjectProperty : public lcObjectKeyArray<T>
{
public:
lcObjectProperty(const T& DefaultValue)
explicit lcObjectProperty(const T& DefaultValue)
: mValue(DefaultValue)
{
ChangeKey(mValue, 1, true);
}
lcObjectProperty(const lcObjectProperty&) = delete;
lcObjectProperty(lcObjectProperty&&) = delete;
lcObjectProperty& operator=(const lcObjectProperty&) = delete;
lcObjectProperty& operator=(lcObjectProperty&&) = delete;
operator const T&() const
{
return mValue;

View file

@ -20,38 +20,32 @@ constexpr float LC_PIECE_CONTROL_POINT_SIZE = 10.0f;
lcPiece::lcPiece(PieceInfo* Info)
: lcObject(lcObjectType::Piece)
{
mMesh = nullptr;
SetPieceInfo(Info, QString(), true);
mFocusedSection = LC_PIECE_SECTION_INVALID;
mColorIndex = gDefaultColor;
mColorCode = 16;
mStepShow = 1;
mStepHide = LC_STEP_MAX;
mGroup = nullptr;
mFileLine = -1;
mPivotMatrix = lcMatrix44Identity();
}
lcPiece::lcPiece(const lcPiece& Other)
: lcObject(lcObjectType::Piece)
{
mMesh = nullptr;
SetPieceInfo(Other.mPieceInfo, Other.mID, true);
mHidden = Other.mHidden;
mSelected = Other.mSelected;
mFocusedSection = LC_PIECE_SECTION_INVALID;
mColorIndex = Other.mColorIndex;
mColorCode = Other.mColorCode;
mStepShow = Other.mStepShow;
mStepHide = Other.mStepHide;
mGroup = Other.mGroup;
mFileLine = -1;
mPivotMatrix = Other.mPivotMatrix;
mPivotPointValid = Other.mPivotPointValid;
mPositionKeys = Other.mPositionKeys;
mRotationKeys = Other.mRotationKeys;
mPosition = Other.mPosition;
mRotation = Other.mRotation;
mControlPoints = Other.mControlPoints;
UpdateMesh();
@ -124,11 +118,11 @@ void lcPiece::SaveLDraw(QTextStream& Stream) const
Stream << LineEnding;
}
if (mPositionKeys.GetSize() > 1)
mPositionKeys.SaveKeysLDraw(Stream, "PIECE", "POSITION");
if (mPosition.GetSize() > 1)
mPosition.SaveKeysLDraw(Stream, "PIECE", "POSITION");
if (mRotationKeys.GetSize() > 1)
mRotationKeys.SaveKeysLDraw(Stream, "PIECE", "ROTATION");
if (mRotation.GetSize() > 1)
mRotation.SaveKeysLDraw(Stream, "PIECE", "ROTATION");
Stream << "1 " << mColorCode << ' ';
@ -165,9 +159,9 @@ bool lcPiece::ParseLDrawLine(QTextStream& Stream)
mPivotPointValid = true;
}
else if (Token == QLatin1String("POSITION_KEY"))
mPositionKeys.LoadKeysLDraw(Stream);
mPosition.LoadKeysLDraw(Stream);
else if (Token == QLatin1String("ROTATION_KEY"))
mRotationKeys.LoadKeysLDraw(Stream);
mRotation.LoadKeysLDraw(Stream);
}
return false;
@ -202,9 +196,9 @@ bool lcPiece::FileLoad(lcFile& file)
file.ReadU8(&type, 1);
if (type == 0)
mPositionKeys.ChangeKey(lcVector3(param[0], param[1], param[2]) * PositionScale, time, true);
mPosition.ChangeKey(lcVector3(param[0], param[1], param[2]) * PositionScale, time, true);
else if (type == 1)
mRotationKeys.ChangeKey(lcMatrix33FromAxisAngle(lcVector3(param[0], param[1], param[2]), param[3] * LC_DTOR), time, true);
mRotation.ChangeKey(lcMatrix33FromAxisAngle(lcVector3(param[0], param[1], param[2]), param[3] * LC_DTOR), time, true);
}
file.ReadU32(&n, 1);
@ -234,9 +228,9 @@ bool lcPiece::FileLoad(lcFile& file)
file.ReadU8(&type, 1);
if (type == 0)
mPositionKeys.ChangeKey(lcVector3(param[0], param[1], param[2]) * PositionScale, time, true);
mPosition.ChangeKey(lcVector3(param[0], param[1], param[2]) * PositionScale, time, true);
else if (type == 1)
mRotationKeys.ChangeKey(lcMatrix33FromAxisAngle(lcVector3(param[0], param[1], param[2]), param[3] * LC_DTOR), time, true);
mRotation.ChangeKey(lcMatrix33FromAxisAngle(lcVector3(param[0], param[1], param[2]), param[3] * LC_DTOR), time, true);
}
file.ReadU32(&keys, 1);
@ -275,8 +269,8 @@ bool lcPiece::FileLoad(lcFile& file)
file.ReadU8(&b, 1);
time = b;
mPositionKeys.ChangeKey(ModelWorld.GetTranslation() * PositionScale, 1, true);
mRotationKeys.ChangeKey(lcMatrix33(ModelWorld), time, true);
mPosition.ChangeKey(ModelWorld.GetTranslation() * PositionScale, 1, true);
mRotation.ChangeKey(lcMatrix33(ModelWorld), time, true);
qint32 bl;
file.ReadS32(&bl, 1);
@ -291,8 +285,8 @@ bool lcPiece::FileLoad(lcFile& file)
lcMatrix44 ModelWorld = lcMatrix44Translation(Translation);
ModelWorld = lcMul(lcMatrix44RotationZ(Rotation[2] * LC_DTOR), lcMul(lcMatrix44RotationY(Rotation[1] * LC_DTOR), lcMul(lcMatrix44RotationX(Rotation[0] * LC_DTOR), ModelWorld)));
mPositionKeys.ChangeKey(lcVector3(ModelWorld.r[3][0], ModelWorld.r[3][1], ModelWorld.r[3][2]) * PositionScale, 1, true);
mRotationKeys.ChangeKey(lcMatrix33(ModelWorld), 1, true);
mPosition.ChangeKey(lcVector3(ModelWorld.r[3][0], ModelWorld.r[3][1], ModelWorld.r[3][2]) * PositionScale, 1, true);
mRotation.ChangeKey(lcMatrix33(ModelWorld), 1, true);
}
}
}
@ -387,10 +381,10 @@ void lcPiece::Initialize(const lcMatrix44& WorldMatrix, lcStep Step)
{
mStepShow = Step;
if (mPositionKeys.IsEmpty())
mPositionKeys.ChangeKey(WorldMatrix.GetTranslation(), 1, true);
if (mRotationKeys.IsEmpty())
mRotationKeys.ChangeKey(lcMatrix33(WorldMatrix), 1, true);
if (mPosition.IsEmpty())
mPosition.ChangeKey(WorldMatrix.GetTranslation(), 1, true);
if (mRotation.IsEmpty())
mRotation.ChangeKey(lcMatrix33(WorldMatrix), 1, true);
UpdatePosition(Step);
}
@ -424,8 +418,8 @@ void lcPiece::InsertTime(lcStep Start, lcStep Time)
}
}
mPositionKeys.InsertTime(Start, Time);
mRotationKeys.InsertTime(Start, Time);
mPosition.InsertTime(Start, Time);
mRotation.InsertTime(Start, Time);
}
void lcPiece::RemoveTime(lcStep Start, lcStep Time)
@ -457,8 +451,8 @@ void lcPiece::RemoveTime(lcStep Start, lcStep Time)
}
}
mPositionKeys.RemoveTime(Start, Time);
mRotationKeys.RemoveTime(Start, Time);
mPosition.RemoveTime(Start, Time);
mRotation.RemoveTime(Start, Time);
}
void lcPiece::RayTest(lcObjectRayTest& ObjectRayTest) const
@ -659,8 +653,8 @@ void lcPiece::DrawInterface(lcContext* Context, const lcScene& Scene) const
void lcPiece::RemoveKeyFrames()
{
mPositionKeys.Reset(mModelWorld.GetTranslation());
mRotationKeys.Reset(lcMatrix33(mModelWorld));
mPosition.Reset();
mRotation.Reset();
}
void lcPiece::AddMainModelRenderMeshes(lcScene* Scene, bool Highlight, bool Fade) const
@ -991,10 +985,10 @@ lcGroup* lcPiece::GetTopGroup()
void lcPiece::UpdatePosition(lcStep Step)
{
const lcVector3 Position = mPositionKeys.CalculateKey(Step);
const lcMatrix33 Rotation = mRotationKeys.CalculateKey(Step);
mPosition.Update(Step);
mRotation.Update(Step);
mModelWorld = lcMatrix44(Rotation, Position);
mModelWorld = lcMatrix44(mRotation, mPosition);
}
void lcPiece::UpdateMesh()

View file

@ -269,12 +269,12 @@ public:
void SetPosition(const lcVector3& Position, lcStep Step, bool AddKey)
{
mPositionKeys.ChangeKey(Position, Step, AddKey);
mPosition.SetValue(Position, Step, AddKey);
}
void SetRotation(const lcMatrix33& Rotation, lcStep Step, bool AddKey)
{
mRotationKeys.ChangeKey(Rotation, Step, AddKey);
mRotation.SetValue(Rotation, Step, AddKey);
}
lcVector3 GetRotationCenter() const
@ -352,10 +352,10 @@ protected:
return IsSelected();
}
lcObjectKeyArray<lcVector3> mPositionKeys;
lcObjectKeyArray<lcMatrix33> mRotationKeys;
lcObjectProperty<lcVector3> mPosition = lcObjectProperty<lcVector3>(lcVector3(0.0f, 0.0f, 0.0f));
lcObjectProperty<lcMatrix33> mRotation = lcObjectProperty<lcMatrix33>(lcMatrix33Identity());
int mFileLine;
int mFileLine = -1;
QString mID;
lcGroup* mGroup;
@ -369,7 +369,7 @@ protected:
bool mPivotPointValid = false;
bool mHidden = false;
bool mSelected = false;
quint32 mFocusedSection;
quint32 mFocusedSection = LC_PIECE_SECTION_INVALID;
lcArray<lcPieceControlPoint> mControlPoints;
lcMesh* mMesh;
lcMesh* mMesh = nullptr;
};