mirror of
https://github.com/leozide/leocad
synced 2024-12-25 21:58:23 +01:00
Merged property serialization functions.
This commit is contained in:
parent
d6499bfeb0
commit
2f40cf5bc7
5 changed files with 83 additions and 94 deletions
|
@ -24,9 +24,9 @@ lcCamera::lcCamera(bool Simple)
|
|||
mState |= LC_CAMERA_SIMPLE;
|
||||
else
|
||||
{
|
||||
mPosition.Reset(lcVector3(-250.0f, -250.0f, 75.0f));
|
||||
mTargetPosition.Reset(lcVector3(0.0f, 0.0f, 0.0f));
|
||||
mUpVector.Reset(lcVector3(-0.2357f, -0.2357f, 0.94281f));
|
||||
mPosition.SetValue(lcVector3(-250.0f, -250.0f, 75.0f));
|
||||
mTargetPosition.SetValue(lcVector3(0.0f, 0.0f, 0.0f));
|
||||
mUpVector.SetValue(lcVector3(-0.2357f, -0.2357f, 0.94281f));
|
||||
|
||||
UpdatePosition(1);
|
||||
}
|
||||
|
@ -47,9 +47,9 @@ lcCamera::lcCamera(float ex, float ey, float ez, float tx, float ty, float tz)
|
|||
|
||||
Initialize();
|
||||
|
||||
mPosition.Reset(lcVector3(ex, ey, ez));
|
||||
mTargetPosition.Reset(lcVector3(tx, ty, tz));
|
||||
mUpVector.Reset(UpVector);
|
||||
mPosition.SetValue(lcVector3(ex, ey, ez));
|
||||
mTargetPosition.SetValue(lcVector3(tx, ty, tz));
|
||||
mUpVector.SetValue(UpVector);
|
||||
|
||||
UpdatePosition(1);
|
||||
}
|
||||
|
@ -138,9 +138,9 @@ void lcCamera::SaveLDraw(QTextStream& Stream) const
|
|||
|
||||
Stream << QLatin1String("0 !LEOCAD CAMERA FOV ") << m_fovy << QLatin1String(" ZNEAR ") << m_zNear << QLatin1String(" ZFAR ") << m_zFar << LineEnding;
|
||||
|
||||
mPosition.Save(Stream, "CAMERA", "POSITION");
|
||||
mTargetPosition.Save(Stream, "CAMERA", "TARGET_POSITION");
|
||||
mUpVector.Save(Stream, "CAMERA", "UP_VECTOR");
|
||||
mPosition.Save(Stream, "CAMERA", "POSITION", true);
|
||||
mTargetPosition.Save(Stream, "CAMERA", "TARGET_POSITION", true);
|
||||
mUpVector.Save(Stream, "CAMERA", "UP_VECTOR", true);
|
||||
|
||||
Stream << QLatin1String("0 !LEOCAD CAMERA ");
|
||||
|
||||
|
@ -630,9 +630,9 @@ bool lcCamera::HasKeyFrame(lcObjectPropertyId PropertyId, lcStep Time) const
|
|||
|
||||
void lcCamera::RemoveKeyFrames()
|
||||
{
|
||||
mPosition.Reset();
|
||||
mTargetPosition.Reset();
|
||||
mUpVector.Reset();
|
||||
mPosition.RemoveAllKeys();
|
||||
mTargetPosition.RemoveAllKeys();
|
||||
mUpVector.RemoveAllKeys();
|
||||
}
|
||||
|
||||
void lcCamera::RayTest(lcObjectRayTest& ObjectRayTest) const
|
||||
|
|
|
@ -3,14 +3,12 @@
|
|||
#include "lc_math.h"
|
||||
|
||||
#define LC_OBJECT_PROPERTY(T) \
|
||||
template void lcObjectProperty<T>::SaveKeysLDraw(QTextStream& Stream, const char* ObjectName, const char* VariableName) const; \
|
||||
template void lcObjectProperty<T>::LoadKeysLDraw(QTextStream& Stream); \
|
||||
template void lcObjectProperty<T>::Update(lcStep Step); \
|
||||
template void lcObjectProperty<T>::ChangeKey(const T& Value, lcStep Step, bool AddKey); \
|
||||
template void lcObjectProperty<T>::InsertTime(lcStep Start, lcStep Time); \
|
||||
template void lcObjectProperty<T>::RemoveTime(lcStep Start, lcStep Time); \
|
||||
template bool lcObjectProperty<T>::HasKeyFrame(lcStep Time) const; \
|
||||
template void lcObjectProperty<T>::Save(QTextStream& Stream, const char* ObjectName, const char* VariableName) const; \
|
||||
template void lcObjectProperty<T>::Save(QTextStream& Stream, const char* ObjectName, const char* VariableName, bool SaveEmpty) const; \
|
||||
template bool lcObjectProperty<T>::Load(QTextStream& Stream, const QString& Token, const char* VariableName);
|
||||
|
||||
LC_OBJECT_PROPERTY(float)
|
||||
|
@ -56,36 +54,6 @@ void lcObjectPropertyLoadValue(QTextStream& Stream, lcVector2i& Value)
|
|||
Stream >> ((int*)&Value)[ValueIdx];
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void lcObjectProperty<T>::SaveKeysLDraw(QTextStream& Stream, const char* ObjectName, const char* VariableName) const
|
||||
{
|
||||
for (const lcObjectPropertyKey<T>& Key : mKeys)
|
||||
{
|
||||
Stream << QLatin1String("0 !LEOCAD ") << ObjectName << ' ' << VariableName << "_KEY " << Key.Step << ' ';
|
||||
|
||||
lcObjectPropertySaveValue(Stream, Key.Value);
|
||||
|
||||
Stream << QLatin1String("\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void lcObjectProperty<T>::LoadKeysLDraw(QTextStream& Stream)
|
||||
{
|
||||
QString Token;
|
||||
Stream >> Token;
|
||||
|
||||
const int Step = Token.toInt();
|
||||
T Value;
|
||||
|
||||
constexpr int Count = sizeof(T) / sizeof(float);
|
||||
|
||||
for (int ValueIdx = 0; ValueIdx < Count; ValueIdx++)
|
||||
Stream >> ((float*)&Value)[ValueIdx];
|
||||
|
||||
ChangeKey(Value, Step, true);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void lcObjectProperty<T>::Update(lcStep Step)
|
||||
{
|
||||
|
@ -209,18 +177,30 @@ bool lcObjectProperty<T>::HasKeyFrame(lcStep Time) const
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
void lcObjectProperty<T>::Save(QTextStream& Stream, const char* ObjectName, const char* VariableName) const
|
||||
void lcObjectProperty<T>::Save(QTextStream& Stream, const char* ObjectName, const char* VariableName, bool SaveEmpty) const
|
||||
{
|
||||
if (mKeys.empty())
|
||||
{
|
||||
Stream << QLatin1String("0 !LEOCAD ") << ObjectName << ' ' << VariableName << ' ';
|
||||
if (SaveEmpty)
|
||||
{
|
||||
Stream << QLatin1String("0 !LEOCAD ") << ObjectName << ' ' << VariableName << ' ';
|
||||
|
||||
lcObjectPropertySaveValue(Stream, mValue);
|
||||
lcObjectPropertySaveValue(Stream, mValue);
|
||||
|
||||
Stream << QLatin1String("\r\n");
|
||||
Stream << QLatin1String("\r\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
SaveKeysLDraw(Stream, ObjectName, VariableName);
|
||||
{
|
||||
for (const lcObjectPropertyKey<T>& Key : mKeys)
|
||||
{
|
||||
Stream << QLatin1String("0 !LEOCAD ") << ObjectName << ' ' << VariableName << "_KEY " << Key.Step << ' ';
|
||||
|
||||
lcObjectPropertySaveValue(Stream, Key.Value);
|
||||
|
||||
Stream << QLatin1String("\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -235,7 +215,18 @@ bool lcObjectProperty<T>::Load(QTextStream& Stream, const QString& Token, const
|
|||
|
||||
if (Token.endsWith(QLatin1String("_KEY")) && Token.leftRef(Token.size() - 4) == VariableName)
|
||||
{
|
||||
LoadKeysLDraw(Stream);
|
||||
QString StepString;
|
||||
Stream >> StepString;
|
||||
|
||||
const int Step = StepString.toInt();
|
||||
T Value;
|
||||
|
||||
constexpr int Count = sizeof(T) / sizeof(float);
|
||||
|
||||
for (int ValueIdx = 0; ValueIdx < Count; ValueIdx++)
|
||||
Stream >> ((float*)&Value)[ValueIdx];
|
||||
|
||||
ChangeKey(Value, Step, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -71,14 +71,13 @@ public:
|
|||
return mValue;
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
mKeys.clear();
|
||||
}
|
||||
|
||||
void Reset(const T& Value)
|
||||
void SetValue(const T& Value)
|
||||
{
|
||||
mValue = Value;
|
||||
}
|
||||
|
||||
void RemoveAllKeys()
|
||||
{
|
||||
mKeys.clear();
|
||||
}
|
||||
|
||||
|
@ -88,10 +87,8 @@ public:
|
|||
void RemoveTime(lcStep Start, lcStep Time);
|
||||
bool HasKeyFrame(lcStep Time) const;
|
||||
|
||||
void Save(QTextStream& Stream, const char* ObjectName, const char* VariableName) const;
|
||||
void Save(QTextStream& Stream, const char* ObjectName, const char* VariableName, bool SaveEmpty) const;
|
||||
bool Load(QTextStream& Stream, const QString& Token, const char* VariableName);
|
||||
void SaveKeysLDraw(QTextStream& Stream, const char* ObjectName, const char* VariableName) const;
|
||||
void LoadKeysLDraw(QTextStream& Stream);
|
||||
|
||||
protected:
|
||||
T mValue;
|
||||
|
|
|
@ -23,7 +23,7 @@ static const std::array<QLatin1String, static_cast<int>(lcLightAreaShape::Count)
|
|||
lcLight::lcLight(const lcVector3& Position, lcLightType LightType)
|
||||
: lcObject(lcObjectType::Light), mLightType(LightType)
|
||||
{
|
||||
mPosition.Reset(Position);
|
||||
mPosition.SetValue(Position);
|
||||
|
||||
UpdateLightType();
|
||||
|
||||
|
@ -52,7 +52,8 @@ void lcLight::UpdateLightType()
|
|||
break;
|
||||
}
|
||||
|
||||
mSize.Reset(Size);
|
||||
mSize.RemoveAllKeys();
|
||||
mSize.SetValue(Size);
|
||||
}
|
||||
|
||||
QString lcLight::GetLightTypeString(lcLightType LightType)
|
||||
|
@ -128,13 +129,13 @@ void lcLight::SaveLDraw(QTextStream& Stream) const
|
|||
if (!mCastShadow)
|
||||
Stream << QLatin1String("0 !LEOCAD LIGHT SHADOWLESS") << 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");
|
||||
mAttenuationDistance.Save(Stream, "LIGHT", "ATTENUATION_DISTANCE");
|
||||
mAttenuationPower.Save(Stream, "LIGHT", "ATTENUATION_POWER");
|
||||
mPosition.Save(Stream, "LIGHT", "POSITION", true);
|
||||
mRotation.Save(Stream, "LIGHT", "ROTATION", true);
|
||||
mColor.Save(Stream, "LIGHT", "COLOR", true);
|
||||
mSize.Save(Stream, "LIGHT", "SIZE", true);
|
||||
mPower.Save(Stream, "LIGHT", "POWER", true);
|
||||
mAttenuationDistance.Save(Stream, "LIGHT", "ATTENUATION_DISTANCE", true);
|
||||
mAttenuationPower.Save(Stream, "LIGHT", "ATTENUATION_POWER", true);
|
||||
|
||||
switch (mLightType)
|
||||
{
|
||||
|
@ -143,9 +144,9 @@ void lcLight::SaveLDraw(QTextStream& Stream) const
|
|||
break;
|
||||
|
||||
case lcLightType::Spot:
|
||||
mSpotConeAngle.Save(Stream, "LIGHT", "SPOT_CONE_ANGLE");
|
||||
mSpotPenumbraAngle.Save(Stream, "LIGHT", "SPOT_PENUMBRA_ANGLE");
|
||||
mSpotTightness.Save(Stream, "LIGHT", "SPOT_TIGHTNESS");
|
||||
mSpotConeAngle.Save(Stream, "LIGHT", "SPOT_CONE_ANGLE", true);
|
||||
mSpotPenumbraAngle.Save(Stream, "LIGHT", "SPOT_PENUMBRA_ANGLE", true);
|
||||
mSpotTightness.Save(Stream, "LIGHT", "SPOT_TIGHTNESS", true);
|
||||
break;
|
||||
|
||||
case lcLightType::Directional:
|
||||
|
@ -153,7 +154,7 @@ void lcLight::SaveLDraw(QTextStream& Stream) const
|
|||
|
||||
case lcLightType::Area:
|
||||
Stream << QLatin1String("0 !LEOCAD LIGHT AREA_SHAPE ") << gLightAreaShapes[static_cast<int>(mAreaShape)] << LineEnding;
|
||||
mAreaGrid.Save(Stream, "LIGHT", "AREA_GRID");
|
||||
mAreaGrid.Save(Stream, "LIGHT", "AREA_GRID", true);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1121,15 +1122,15 @@ bool lcLight::HasKeyFrame(lcObjectPropertyId PropertyId, lcStep Time) const
|
|||
|
||||
void lcLight::RemoveKeyFrames()
|
||||
{
|
||||
mPosition.Reset();
|
||||
mRotation.Reset();
|
||||
mColor.Reset();
|
||||
mSpotConeAngle.Reset();
|
||||
mSpotPenumbraAngle.Reset();
|
||||
mSpotTightness.Reset();
|
||||
mAreaGrid.Reset();
|
||||
mSize.Reset();
|
||||
mPower.Reset();
|
||||
mAttenuationDistance.Reset();
|
||||
mAttenuationPower.Reset();
|
||||
mPosition.RemoveAllKeys();
|
||||
mRotation.RemoveAllKeys();
|
||||
mColor.RemoveAllKeys();
|
||||
mSpotConeAngle.RemoveAllKeys();
|
||||
mSpotPenumbraAngle.RemoveAllKeys();
|
||||
mSpotTightness.RemoveAllKeys();
|
||||
mAreaGrid.RemoveAllKeys();
|
||||
mSize.RemoveAllKeys();
|
||||
mPower.RemoveAllKeys();
|
||||
mAttenuationDistance.RemoveAllKeys();
|
||||
mAttenuationPower.RemoveAllKeys();
|
||||
}
|
||||
|
|
|
@ -118,8 +118,8 @@ void lcPiece::SaveLDraw(QTextStream& Stream) const
|
|||
Stream << LineEnding;
|
||||
}
|
||||
|
||||
mPosition.SaveKeysLDraw(Stream, "PIECE", "POSITION");
|
||||
mRotation.SaveKeysLDraw(Stream, "PIECE", "ROTATION");
|
||||
mPosition.Save(Stream, "PIECE", "POSITION", false);
|
||||
mRotation.Save(Stream, "PIECE", "ROTATION", false);
|
||||
|
||||
Stream << "1 " << mColorCode << ' ';
|
||||
|
||||
|
@ -155,10 +155,10 @@ bool lcPiece::ParseLDrawLine(QTextStream& Stream)
|
|||
mPivotMatrix = PivotMatrix;
|
||||
mPivotPointValid = true;
|
||||
}
|
||||
else if (Token == QLatin1String("POSITION_KEY"))
|
||||
mPosition.LoadKeysLDraw(Stream);
|
||||
else if (Token == QLatin1String("ROTATION_KEY"))
|
||||
mRotation.LoadKeysLDraw(Stream);
|
||||
else if (mPosition.Load(Stream, Token, "POSITION"))
|
||||
continue;
|
||||
else if (mRotation.Load(Stream, Token, "ROTATION"))
|
||||
continue;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -378,8 +378,8 @@ void lcPiece::Initialize(const lcMatrix44& WorldMatrix, lcStep Step)
|
|||
{
|
||||
mStepShow = Step;
|
||||
|
||||
mPosition.Reset(WorldMatrix.GetTranslation());
|
||||
mRotation.Reset(lcMatrix33(WorldMatrix));
|
||||
mPosition.SetValue(WorldMatrix.GetTranslation());
|
||||
mRotation.SetValue(lcMatrix33(WorldMatrix));
|
||||
|
||||
UpdatePosition(Step);
|
||||
}
|
||||
|
@ -708,8 +708,8 @@ bool lcPiece::HasKeyFrame(lcObjectPropertyId PropertyId, lcStep Time) const
|
|||
|
||||
void lcPiece::RemoveKeyFrames()
|
||||
{
|
||||
mPosition.Reset();
|
||||
mRotation.Reset();
|
||||
mPosition.RemoveAllKeys();
|
||||
mRotation.RemoveAllKeys();
|
||||
}
|
||||
|
||||
void lcPiece::AddMainModelRenderMeshes(lcScene* Scene, bool Highlight, bool Fade) const
|
||||
|
|
Loading…
Reference in a new issue