Skip to content

Commit

Permalink
Split pov ray area light grid into 2 separate keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
leozide committed Jul 4, 2024
1 parent 3a62411 commit 7451d33
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 19 deletions.
19 changes: 19 additions & 0 deletions common/lc_objectproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
template bool lcObjectProperty<T>::Load(QTextStream& Stream, const QString& Token, const char* VariableName);

LC_OBJECT_PROPERTY(float)
LC_OBJECT_PROPERTY(int)
LC_OBJECT_PROPERTY(lcVector2i)
LC_OBJECT_PROPERTY(lcVector2)
LC_OBJECT_PROPERTY(lcVector3)
Expand All @@ -28,6 +29,15 @@ static void lcObjectPropertySaveValue(QTextStream& Stream, const T& Value)
Stream << ((const float*)&Value)[ValueIndex] << ' ';
}

template<>
void lcObjectPropertySaveValue(QTextStream& Stream, const int& Value)
{
constexpr int Count = sizeof(int) / sizeof(int);

for (int ValueIndex = 0; ValueIndex < Count; ValueIndex++)
Stream << ((const int*)&Value)[ValueIndex] << ' ';
}

template<>
void lcObjectPropertySaveValue(QTextStream& Stream, const lcVector2i& Value)
{
Expand All @@ -46,6 +56,15 @@ static void lcObjectPropertyLoadValue(QTextStream& Stream, T& Value)
Stream >> ((float*)&Value)[ValueIdx];
}

template<>
void lcObjectPropertyLoadValue(QTextStream& Stream, int& Value)
{
constexpr int Count = sizeof(int) / sizeof(int);

for (int ValueIdx = 0; ValueIdx < Count; ValueIdx++)
Stream >> ((int*)&Value)[ValueIdx];
}

template<>
void lcObjectPropertyLoadValue(QTextStream& Stream, lcVector2i& Value)
{
Expand Down
46 changes: 32 additions & 14 deletions common/light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ void lcLight::SaveLDraw(QTextStream& Stream) const

case lcLightType::Area:
Stream << QLatin1String("0 !LEOCAD LIGHT AREA_SHAPE ") << gLightAreaShapes[static_cast<int>(mAreaShape)] << LineEnding;
mAreaPOVRayGrid.Save(Stream, "LIGHT", "POVRAY_AREA_GRID", true);
mAreaPOVRayGridX.Save(Stream, "LIGHT", "POVRAY_AREA_GRID_X", true);
mAreaPOVRayGridY.Save(Stream, "LIGHT", "POVRAY_AREA_GRID_Y", true);
break;
}

Expand Down Expand Up @@ -240,7 +241,9 @@ bool lcLight::ParseLDrawLine(QTextStream& Stream)
continue;
else if (mSpotPOVRayTightness.Load(Stream, Token, "POVRAY_SPOT_TIGHTNESS"))
continue;
else if (mAreaPOVRayGrid.Load(Stream, Token, "POVRAY_AREA_GRID"))
else if (mAreaPOVRayGridX.Load(Stream, Token, "POVRAY_AREA_GRID_X"))
continue;
else if (mAreaPOVRayGridY.Load(Stream, Token, "POVRAY_AREA_GRID_Y"))
continue;
else if (Token == QLatin1String("AREA_SHAPE"))
{
Expand Down Expand Up @@ -541,9 +544,16 @@ bool lcLight::SetAreaShape(lcLightAreaShape AreaShape)
return false;
}

bool lcLight::SetAreaPOVRayGrid(lcVector2i AreaGrid, lcStep Step, bool AddKey)
bool lcLight::SetAreaPOVRayGridX(int AreaGrid, lcStep Step, bool AddKey)
{
mAreaPOVRayGridX.ChangeKey(AreaGrid, Step, AddKey);

return true;
}

bool lcLight::SetAreaPOVRayGridY(int AreaGrid, lcStep Step, bool AddKey)
{
mAreaPOVRayGrid.ChangeKey(AreaGrid, Step, AddKey);
mAreaPOVRayGridY.ChangeKey(AreaGrid, Step, AddKey);

return true;
}
Expand Down Expand Up @@ -602,7 +612,8 @@ void lcLight::InsertTime(lcStep Start, lcStep Time)
mSpotConeAngle.InsertTime(Start, Time);
mSpotPenumbraAngle.InsertTime(Start, Time);
mSpotPOVRayTightness.InsertTime(Start, Time);
mAreaPOVRayGrid.InsertTime(Start, Time);
mAreaPOVRayGridX.InsertTime(Start, Time);
mAreaPOVRayGridY.InsertTime(Start, Time);
mPointBlenderRadius.InsertTime(Start, Time);
mSpotBlenderRadius.InsertTime(Start, Time);
mDirectionalBlenderAngle.InsertTime(Start, Time);
Expand All @@ -622,7 +633,8 @@ void lcLight::RemoveTime(lcStep Start, lcStep Time)
mSpotConeAngle.RemoveTime(Start, Time);
mSpotPenumbraAngle.RemoveTime(Start, Time);
mSpotPOVRayTightness.RemoveTime(Start, Time);
mAreaPOVRayGrid.RemoveTime(Start, Time);
mAreaPOVRayGridX.RemoveTime(Start, Time);
mAreaPOVRayGridY.RemoveTime(Start, Time);
mPointBlenderRadius.RemoveTime(Start, Time);
mSpotBlenderRadius.RemoveTime(Start, Time);
mDirectionalBlenderAngle.RemoveTime(Start, Time);
Expand All @@ -642,7 +654,8 @@ void lcLight::UpdatePosition(lcStep Step)
mSpotConeAngle.Update(Step);
mSpotPenumbraAngle.Update(Step);
mSpotPOVRayTightness.Update(Step);
mAreaPOVRayGrid.Update(Step);
mAreaPOVRayGridX.Update(Step);
mAreaPOVRayGridY.Update(Step);
mPointBlenderRadius.Update(Step);
mSpotBlenderRadius.Update(Step);
mDirectionalBlenderAngle.Update(Step);
Expand Down Expand Up @@ -1149,10 +1162,10 @@ QVariant lcLight::GetPropertyValue(lcObjectPropertyId PropertyId) const
return static_cast<int>(GetAreaShape());

case lcObjectPropertyId::LightAreaPOVRayGridX:
return GetAreaPOVRayGrid().x;
return GetAreaPOVRayGridX();

case lcObjectPropertyId::LightAreaPOVRayGridY:
return GetAreaPOVRayGrid().y;
return GetAreaPOVRayGridY();

case lcObjectPropertyId::ObjectPositionX:
case lcObjectPropertyId::ObjectPositionY:
Expand Down Expand Up @@ -1243,10 +1256,10 @@ bool lcLight::SetPropertyValue(lcObjectPropertyId PropertyId, lcStep Step, bool
return SetAreaShape(static_cast<lcLightAreaShape>(Value.toInt()));

case lcObjectPropertyId::LightAreaPOVRayGridX:
return SetAreaPOVRayGrid(lcVector2i(Value.toInt(), GetAreaPOVRayGrid().y), Step, AddKey);
return SetAreaPOVRayGridX(Value.toInt(), Step, AddKey);

case lcObjectPropertyId::LightAreaPOVRayGridY:
return SetAreaPOVRayGrid(lcVector2i(GetAreaPOVRayGrid().x, Value.toInt()), Step, AddKey);
return SetAreaPOVRayGridY(Value.toInt(), Step, AddKey);

case lcObjectPropertyId::ObjectPositionX:
case lcObjectPropertyId::ObjectPositionY:
Expand Down Expand Up @@ -1333,8 +1346,10 @@ bool lcLight::HasKeyFrame(lcObjectPropertyId PropertyId, lcStep Time) const
return false;

case lcObjectPropertyId::LightAreaPOVRayGridX:
return mAreaPOVRayGridX.HasKeyFrame(Time);

case lcObjectPropertyId::LightAreaPOVRayGridY:
return mAreaPOVRayGrid.HasKeyFrame(Time);
return mAreaPOVRayGridY.HasKeyFrame(Time);

case lcObjectPropertyId::ObjectPositionX:
case lcObjectPropertyId::ObjectPositionY:
Expand Down Expand Up @@ -1425,8 +1440,10 @@ bool lcLight::SetKeyFrame(lcObjectPropertyId PropertyId, lcStep Time, bool KeyFr
return false;

case lcObjectPropertyId::LightAreaPOVRayGridX:
return mAreaPOVRayGridX.SetKeyFrame(Time, KeyFrame);

case lcObjectPropertyId::LightAreaPOVRayGridY:
return mAreaPOVRayGrid.SetKeyFrame(Time, KeyFrame);
return mAreaPOVRayGridY.SetKeyFrame(Time, KeyFrame);

case lcObjectPropertyId::ObjectPositionX:
case lcObjectPropertyId::ObjectPositionY:
Expand All @@ -1453,7 +1470,8 @@ void lcLight::RemoveKeyFrames()
mSpotConeAngle.RemoveAllKeys();
mSpotPenumbraAngle.RemoveAllKeys();
mSpotPOVRayTightness.RemoveAllKeys();
mAreaPOVRayGrid.RemoveAllKeys();
mAreaPOVRayGridX.RemoveAllKeys();
mAreaPOVRayGridY.RemoveAllKeys();
mPointBlenderRadius.RemoveAllKeys();
mSpotBlenderRadius.RemoveAllKeys();
mDirectionalBlenderAngle.RemoveAllKeys();
Expand Down
16 changes: 12 additions & 4 deletions common/light.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,18 @@ class lcLight : public lcObject
return mAreaShape;
}

bool SetAreaPOVRayGrid(lcVector2i AreaGrid, lcStep Step, bool AddKey);
bool SetAreaPOVRayGridX(int AreaGrid, lcStep Step, bool AddKey);

lcVector2i GetAreaPOVRayGrid() const
int GetAreaPOVRayGridX() const
{
return mAreaPOVRayGrid;
return mAreaPOVRayGridX;
}

bool SetAreaPOVRayGridY(int AreaGrid, lcStep Step, bool AddKey);

int GetAreaPOVRayGridY() const
{
return mAreaPOVRayGridY;
}

bool SetPointBlenderRadius(float Radius, lcStep Step, bool AddKey);
Expand Down Expand Up @@ -382,7 +389,8 @@ class lcLight : public lcObject
lcObjectProperty<float> mSpotConeAngle = lcObjectProperty<float>(80.0f);
lcObjectProperty<float> mSpotPenumbraAngle = lcObjectProperty<float>(0.0f);
lcObjectProperty<float> mSpotPOVRayTightness = lcObjectProperty<float>(0.0f);
lcObjectProperty<lcVector2i> mAreaPOVRayGrid = lcObjectProperty<lcVector2i>(lcVector2i(2, 2));
lcObjectProperty<int> mAreaPOVRayGridX = lcObjectProperty<int>(2);
lcObjectProperty<int> mAreaPOVRayGridY = lcObjectProperty<int>(2);
lcLightAreaShape mAreaShape = lcLightAreaShape::Rectangle;

quint32 mState = 0;
Expand Down
2 changes: 1 addition & 1 deletion common/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2206,7 +2206,7 @@ bool Project::ExportPOVRay(const QString& FileName)
AreaCircle = (Light->GetAreaShape() == lcLightAreaShape::Disk || Light->GetAreaShape() == lcLightAreaShape::Ellipse) ? 1 : 0;
AreaX = lcVector3(Light->GetWorldMatrix()[0]) * Light->GetAreaSizeX();
AreaY = lcVector3(Light->GetWorldMatrix()[1]) * Light->GetAreaSizeY();
AreaGrid = Light->GetAreaPOVRayGrid();
AreaGrid = lcVector2i(Light->GetAreaPOVRayGridX(), Light->GetAreaPOVRayGridY());
break;

case lcLightType::Count:
Expand Down

0 comments on commit 7451d33

Please sign in to comment.