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) void SetUpVector(const lcVector3& UpVector, lcStep Step, bool AddKey)
{ {
mPositionKeys.ChangeKey(UpVector, Step, AddKey); mUpVectorKeys.ChangeKey(UpVector, Step, AddKey);
} }
float GetOrthoHeight() const float GetOrthoHeight() const

View file

@ -112,22 +112,8 @@ void lcLight::SaveLDraw(QTextStream& Stream) const
if (!mCastShadow) if (!mCastShadow)
Stream << QLatin1String("0 !LEOCAD LIGHT SHADOWLESS") << LineEnding; Stream << QLatin1String("0 !LEOCAD LIGHT SHADOWLESS") << LineEnding;
const float* Matrix = mWorldMatrix; mPosition.Save(Stream, "LIGHT", "POSITION");
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] }; mRotation.Save(Stream, "LIGHT", "ROTATION");
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;
}
mColor.Save(Stream, "LIGHT", "COLOR"); mColor.Save(Stream, "LIGHT", "COLOR");
mSize.Save(Stream, "LIGHT", "SIZE"); mSize.Save(Stream, "LIGHT", "SIZE");
mPower.Save(Stream, "LIGHT", "POWER"); mPower.Save(Stream, "LIGHT", "POWER");
@ -227,40 +213,10 @@ bool lcLight::ParseLDrawLine(QTextStream& Stream)
QString Token; QString Token;
Stream >> Token; Stream >> Token;
if (Token == QLatin1String("POSITION")) if (mPosition.Load(Stream, Token, "POSITION"))
{ continue;
lcVector3 Position; else if (mRotation.Load(Stream, Token, "ROTATION"))
Stream >> Position[0] >> Position[1] >> Position[2]; continue;
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
else if (mColor.Load(Stream, Token, "COLOR")) else if (mColor.Load(Stream, Token, "COLOR"))
continue; continue;
else if (mSize.Load(Stream, Token, "SIZE")) else if (mSize.Load(Stream, Token, "SIZE"))

View file

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

View file

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

View file

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

View file

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