From 5d5274b2b4d89ab15275f4a5f1000eab5ddec2dc Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sun, 7 Apr 2024 11:28:54 -0700 Subject: [PATCH] Split light power into different properties for Blender and POV-Ray. --- common/camera.cpp | 12 ++++++--- common/lc_model.cpp | 14 ++++++++-- common/lc_model.h | 3 ++- common/lc_objectproperty.h | 3 ++- common/lc_propertieswidget.cpp | 19 +++++++++----- common/light.cpp | 48 ++++++++++++++++++++++++---------- common/light.h | 16 +++++++++--- common/object.cpp | 7 +++-- common/piece.cpp | 12 ++++++--- common/project.cpp | 2 +- 10 files changed, 97 insertions(+), 39 deletions(-) diff --git a/common/camera.cpp b/common/camera.cpp index 683e1727..dc6178e3 100644 --- a/common/camera.cpp +++ b/common/camera.cpp @@ -642,7 +642,8 @@ QVariant lcCamera::GetPropertyValue(lcObjectPropertyId PropertyId) const case lcObjectPropertyId::LightName: case lcObjectPropertyId::LightType: case lcObjectPropertyId::LightColor: - case lcObjectPropertyId::LightPower: + case lcObjectPropertyId::LightBlenderPower: + case lcObjectPropertyId::LightPOVRayPower: case lcObjectPropertyId::LightCastShadow: case lcObjectPropertyId::LightPOVRayFadeDistance: case lcObjectPropertyId::LightPOVRayFadePower: @@ -705,7 +706,8 @@ bool lcCamera::SetPropertyValue(lcObjectPropertyId PropertyId, lcStep Step, bool case lcObjectPropertyId::LightName: case lcObjectPropertyId::LightType: case lcObjectPropertyId::LightColor: - case lcObjectPropertyId::LightPower: + case lcObjectPropertyId::LightBlenderPower: + case lcObjectPropertyId::LightPOVRayPower: case lcObjectPropertyId::LightCastShadow: case lcObjectPropertyId::LightPOVRayFadeDistance: case lcObjectPropertyId::LightPOVRayFadePower: @@ -767,7 +769,8 @@ bool lcCamera::HasKeyFrame(lcObjectPropertyId PropertyId, lcStep Time) const case lcObjectPropertyId::LightName: case lcObjectPropertyId::LightType: case lcObjectPropertyId::LightColor: - case lcObjectPropertyId::LightPower: + case lcObjectPropertyId::LightBlenderPower: + case lcObjectPropertyId::LightPOVRayPower: case lcObjectPropertyId::LightCastShadow: case lcObjectPropertyId::LightPOVRayFadeDistance: case lcObjectPropertyId::LightPOVRayFadePower: @@ -829,7 +832,8 @@ bool lcCamera::SetKeyFrame(lcObjectPropertyId PropertyId, lcStep Time, bool KeyF case lcObjectPropertyId::LightName: case lcObjectPropertyId::LightType: case lcObjectPropertyId::LightColor: - case lcObjectPropertyId::LightPower: + case lcObjectPropertyId::LightBlenderPower: + case lcObjectPropertyId::LightPOVRayPower: case lcObjectPropertyId::LightCastShadow: case lcObjectPropertyId::LightPOVRayFadeDistance: case lcObjectPropertyId::LightPOVRayFadePower: diff --git a/common/lc_model.cpp b/common/lc_model.cpp index 269f0d1e..be951329 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -3190,9 +3190,19 @@ void lcModel::SetLightSize(lcLight* Light, lcVector2 LightAreaSize) UpdateAllViews(); } -void lcModel::SetLightPower(lcLight* Light, float Power) +void lcModel::SetLightBlenderPower(lcLight* Light, float Power) { - Light->SetPower(Power, mCurrentStep, gMainWindow->GetAddKeys()); + Light->SetBlenderPower(Power, mCurrentStep, gMainWindow->GetAddKeys()); + Light->UpdatePosition(mCurrentStep); + + SaveCheckpoint(tr("Changing Light Power")); + gMainWindow->UpdateSelectedObjects(false); + UpdateAllViews(); +} + +void lcModel::SetLightPOVRayPower(lcLight* Light, float Power) +{ + Light->SetPOVRayPower(Power, mCurrentStep, gMainWindow->GetAddKeys()); Light->UpdatePosition(mCurrentStep); SaveCheckpoint(tr("Changing Light Power")); diff --git a/common/lc_model.h b/common/lc_model.h index 2ed52607..99a64c64 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -377,7 +377,8 @@ public: void SetSpotLightPenumbraAngle(lcLight* Light, float Angle); void SetSpotLightPOVRayTightness(lcLight* Light, float Tightness); void SetLightSize(lcLight* Light, lcVector2 LightAreaSize); - void SetLightPower(lcLight* Light, float Power); + void SetLightBlenderPower(lcLight* Light, float Power); + void SetLightPOVRayPower(lcLight* Light, float Power); void ShowPropertiesDialog(); void ShowSelectByNameDialog(); diff --git a/common/lc_objectproperty.h b/common/lc_objectproperty.h index 108cf64a..aba3f98c 100644 --- a/common/lc_objectproperty.h +++ b/common/lc_objectproperty.h @@ -25,7 +25,8 @@ enum class lcObjectPropertyId LightName, LightType, LightColor, - LightPower, + LightBlenderPower, + LightPOVRayPower, LightCastShadow, LightPOVRayFadeDistance, LightPOVRayFadePower, diff --git a/common/lc_propertieswidget.cpp b/common/lc_propertieswidget.cpp index 9f50384a..1ad0b6e0 100644 --- a/common/lc_propertieswidget.cpp +++ b/common/lc_propertieswidget.cpp @@ -372,9 +372,13 @@ void lcPropertiesWidget::FloatChanged() if (Light) { - if (PropertyId == lcObjectPropertyId::LightPower) + if (PropertyId == lcObjectPropertyId::LightBlenderPower) { - Model->SetLightPower(Light, Value); + Model->SetLightBlenderPower(Light, Value); + } + else if (PropertyId == lcObjectPropertyId::LightPOVRayPower) + { + Model->SetLightPOVRayPower(Light, Value); } else if (PropertyId == lcObjectPropertyId::LightPOVRayFadeDistance) { @@ -1031,7 +1035,8 @@ void lcPropertiesWidget::CreateWidgets() AddSpacing(); AddColorProperty(lcObjectPropertyId::LightColor, tr("Color"), tr("Light color"), true); - AddFloatProperty(lcObjectPropertyId::LightPower, tr("Power"), tr("Power of the light (Watts in Blender, multiplicative factor in POV-Ray)"), true, 0.0f, FLT_MAX); + AddFloatProperty(lcObjectPropertyId::LightBlenderPower, tr("Blender Power"), tr("Power of the light in Watts"), true, 0.0f, FLT_MAX); + AddFloatProperty(lcObjectPropertyId::LightPOVRayPower, tr("POV-Ray Power"), tr("Power of the light (multiplicative factor)"), true, 0.0f, FLT_MAX); AddFloatProperty(lcObjectPropertyId::LightPOVRayFadeDistance, tr("Fade Distance"), tr("The distance at which the full light intensity arrives (POV-Ray only)"), true, 0.0f, FLT_MAX); AddFloatProperty(lcObjectPropertyId::LightPOVRayFadePower, tr("Fade Power"), tr("Light falloff rate (POV-Ray only)"), true, 0.0f, FLT_MAX); AddBoolProperty(lcObjectPropertyId::LightCastShadow, tr("Cast Shadow"), tr("Cast a shadow from this light"), false); @@ -1258,7 +1263,7 @@ void lcPropertiesWidget::SetLight(const lcArray& Selection, lcObject* lcLightType LightType = lcLightType::Count; lcLightAreaShape LightAreaShape = lcLightAreaShape::Count; lcVector2 LightSize(0.0f, 0.0f); - float Power = 0.0f; + float BlenderPower = 0.0f, POVRayPower = 0.0f; float FadeDistance = 0.0f; float FadePower = 0.0f; lcVector3 Position(0.0f, 0.0f, 0.0f); @@ -1272,7 +1277,8 @@ void lcPropertiesWidget::SetLight(const lcArray& Selection, lcObject* Position = Light->GetPosition(); Rotation = lcMatrix44ToEulerAngles(Light->GetWorldMatrix()) * LC_RTOD; - Power = Light->GetPower(); + BlenderPower = Light->GetBlenderPower(); + POVRayPower = Light->GetPOVRayPower(); FadeDistance = Light->GetPOVRayFadeDistance(); FadePower = Light->GetPOVRayFadePower(); SpotConeAngle = Light->GetSpotConeAngle(); @@ -1319,7 +1325,8 @@ void lcPropertiesWidget::SetLight(const lcArray& Selection, lcObject* UpdateStringList(lcObjectPropertyId::LightType); UpdateColor(lcObjectPropertyId::LightColor); - UpdateFloat(lcObjectPropertyId::LightPower, Power); + UpdateFloat(lcObjectPropertyId::LightBlenderPower, BlenderPower); + UpdateFloat(lcObjectPropertyId::LightPOVRayPower, POVRayPower); UpdateBool(lcObjectPropertyId::LightCastShadow); UpdateFloat(lcObjectPropertyId::LightPOVRayFadeDistance, FadeDistance); diff --git a/common/light.cpp b/common/light.cpp index d01647a7..6c602c6e 100644 --- a/common/light.cpp +++ b/common/light.cpp @@ -133,7 +133,8 @@ void lcLight::SaveLDraw(QTextStream& Stream) const mRotation.Save(Stream, "LIGHT", "ROTATION", true); mColor.Save(Stream, "LIGHT", "COLOR", true); mSize.Save(Stream, "LIGHT", "SIZE", true); - mPower.Save(Stream, "LIGHT", "POWER", true); + mBlenderPower.Save(Stream, "LIGHT", "BLENDER_POWER", true); + mPOVRayPower.Save(Stream, "LIGHT", "POVRAY_POWER", true); mPOVRayFadeDistance.Save(Stream, "LIGHT", "POVRAY_FADE_DISTANCE", true); mPOVRayFadePower.Save(Stream, "LIGHT", "POVRAY_FADE_POWER", true); @@ -238,7 +239,9 @@ bool lcLight::ParseLDrawLine(QTextStream& Stream) continue; else if (mSize.Load(Stream, Token, "SIZE")) continue; - else if (mPower.Load(Stream, Token, "POWER")) + else if (mBlenderPower.Load(Stream, Token, "BLENDER_POWER")) + continue; + else if (mPOVRayPower.Load(Stream, Token, "POVRAY_POWER")) continue; else if (mPOVRayFadeDistance.Load(Stream, Token, "POVRAY_FADE_DISTANCE")) continue; @@ -568,9 +571,14 @@ void lcLight::SetSize(lcVector2 Size, lcStep Step, bool AddKey) mSize.ChangeKey(Size, Step, AddKey); } -void lcLight::SetPower(float Power, lcStep Step, bool AddKey) +void lcLight::SetBlenderPower(float Power, lcStep Step, bool AddKey) { - mPower.ChangeKey(Power, Step, AddKey); + mBlenderPower.ChangeKey(Power, Step, AddKey); +} + +void lcLight::SetPOVRayPower(float Power, lcStep Step, bool AddKey) +{ + mPOVRayPower.ChangeKey(Power, Step, AddKey); } bool lcLight::SetCastShadow(bool CastShadow) @@ -594,7 +602,8 @@ void lcLight::InsertTime(lcStep Start, lcStep Time) mSpotPOVRayTightness.InsertTime(Start, Time); mAreaPOVRayGrid.InsertTime(Start, Time); mSize.InsertTime(Start, Time); - mPower.InsertTime(Start, Time); + mBlenderPower.InsertTime(Start, Time); + mPOVRayPower.InsertTime(Start, Time); mPOVRayFadeDistance.InsertTime(Start, Time); mPOVRayFadePower.InsertTime(Start, Time); } @@ -609,7 +618,8 @@ void lcLight::RemoveTime(lcStep Start, lcStep Time) mSpotPOVRayTightness.RemoveTime(Start, Time); mAreaPOVRayGrid.RemoveTime(Start, Time); mSize.RemoveTime(Start, Time); - mPower.RemoveTime(Start, Time); + mBlenderPower.RemoveTime(Start, Time); + mPOVRayPower.RemoveTime(Start, Time); mPOVRayFadeDistance.RemoveTime(Start, Time); mPOVRayFadePower.RemoveTime(Start, Time); } @@ -624,7 +634,8 @@ void lcLight::UpdatePosition(lcStep Step) mSpotPOVRayTightness.Update(Step); mAreaPOVRayGrid.Update(Step); mSize.Update(Step); - mPower.Update(Step); + mBlenderPower.Update(Step); + mPOVRayPower.Update(Step); mPOVRayFadeDistance.Update(Step); mPOVRayFadePower.Update(Step); @@ -1081,7 +1092,8 @@ QVariant lcLight::GetPropertyValue(lcObjectPropertyId PropertyId) const case lcObjectPropertyId::LightColor: return QVariant::fromValue(GetColor()); - case lcObjectPropertyId::LightPower: + case lcObjectPropertyId::LightBlenderPower: + case lcObjectPropertyId::LightPOVRayPower: break; case lcObjectPropertyId::LightCastShadow: @@ -1155,7 +1167,8 @@ bool lcLight::SetPropertyValue(lcObjectPropertyId PropertyId, lcStep Step, bool case lcObjectPropertyId::LightColor: return SetColor(Value.value(), Step, AddKey); - case lcObjectPropertyId::LightPower: + case lcObjectPropertyId::LightBlenderPower: + case lcObjectPropertyId::LightPOVRayPower: break; case lcObjectPropertyId::LightCastShadow: @@ -1225,8 +1238,11 @@ bool lcLight::HasKeyFrame(lcObjectPropertyId PropertyId, lcStep Time) const case lcObjectPropertyId::LightColor: return mColor.HasKeyFrame(Time); - case lcObjectPropertyId::LightPower: - return mPower.HasKeyFrame(Time); + case lcObjectPropertyId::LightBlenderPower: + return mBlenderPower.HasKeyFrame(Time); + + case lcObjectPropertyId::LightPOVRayPower: + return mPOVRayPower.HasKeyFrame(Time); case lcObjectPropertyId::LightCastShadow: return false; @@ -1307,8 +1323,11 @@ bool lcLight::SetKeyFrame(lcObjectPropertyId PropertyId, lcStep Time, bool KeyFr case lcObjectPropertyId::LightColor: return mColor.SetKeyFrame(Time, KeyFrame); - case lcObjectPropertyId::LightPower: - return mPower.SetKeyFrame(Time, KeyFrame); + case lcObjectPropertyId::LightBlenderPower: + return mBlenderPower.SetKeyFrame(Time, KeyFrame); + + case lcObjectPropertyId::LightPOVRayPower: + return mPOVRayPower.SetKeyFrame(Time, KeyFrame); case lcObjectPropertyId::LightCastShadow: return false; @@ -1370,7 +1389,8 @@ void lcLight::RemoveKeyFrames() mSpotPOVRayTightness.RemoveAllKeys(); mAreaPOVRayGrid.RemoveAllKeys(); mSize.RemoveAllKeys(); - mPower.RemoveAllKeys(); + mBlenderPower.RemoveAllKeys(); + mPOVRayPower.RemoveAllKeys(); mPOVRayFadeDistance.RemoveAllKeys(); mPOVRayFadePower.RemoveAllKeys(); } diff --git a/common/light.h b/common/light.h index 7d4286f2..076efba9 100644 --- a/common/light.h +++ b/common/light.h @@ -290,11 +290,18 @@ public: return mSize; } - void SetPower(float Power, lcStep Step, bool AddKey); + void SetBlenderPower(float Power, lcStep Step, bool AddKey); - float GetPower() const + float GetBlenderPower() const { - return mPower; + return mBlenderPower; + } + + void SetPOVRayPower(float Power, lcStep Step, bool AddKey); + + float GetPOVRayPower() const + { + return mPOVRayPower; } bool SetCastShadow(bool CastShadow); @@ -338,7 +345,8 @@ protected: lcObjectProperty mRotation = lcObjectProperty(lcMatrix33Identity()); lcObjectProperty mColor = lcObjectProperty(lcVector3(1.0f, 1.0f, 1.0f)); lcObjectProperty mSize = lcObjectProperty(lcVector2(0.0f, 0.0f)); - lcObjectProperty mPower = lcObjectProperty(1.0f); + lcObjectProperty mBlenderPower = lcObjectProperty(10.0f); + lcObjectProperty mPOVRayPower = lcObjectProperty(1.0f); lcObjectProperty mPOVRayFadeDistance = lcObjectProperty(0.0f); lcObjectProperty mPOVRayFadePower = lcObjectProperty(0.0f); lcObjectProperty mSpotConeAngle = lcObjectProperty(80.0f); diff --git a/common/object.cpp b/common/object.cpp index 0ec9fb52..be7f683f 100644 --- a/common/object.cpp +++ b/common/object.cpp @@ -53,8 +53,11 @@ QString lcObject::GetCheckpointString(lcObjectPropertyId PropertyId) case lcObjectPropertyId::LightColor: return QT_TRANSLATE_NOOP("Checkpoint", "Changing Light Color"); - case lcObjectPropertyId::LightPower: - break; + case lcObjectPropertyId::LightBlenderPower: + return QT_TRANSLATE_NOOP("Checkpoint", "Changing Light Blender Power"); + + case lcObjectPropertyId::LightPOVRayPower: + return QT_TRANSLATE_NOOP("Checkpoint", "Changing Light POV-Ray Power"); case lcObjectPropertyId::LightCastShadow: return QT_TRANSLATE_NOOP("Checkpoint", "Changing Light Shadow"); diff --git a/common/piece.cpp b/common/piece.cpp index ecf75cdf..975d841e 100644 --- a/common/piece.cpp +++ b/common/piece.cpp @@ -687,7 +687,8 @@ QVariant lcPiece::GetPropertyValue(lcObjectPropertyId PropertyId) const case lcObjectPropertyId::LightName: case lcObjectPropertyId::LightType: case lcObjectPropertyId::LightColor: - case lcObjectPropertyId::LightPower: + case lcObjectPropertyId::LightBlenderPower: + case lcObjectPropertyId::LightPOVRayPower: case lcObjectPropertyId::LightCastShadow: case lcObjectPropertyId::LightPOVRayFadeDistance: case lcObjectPropertyId::LightPOVRayFadePower: @@ -748,7 +749,8 @@ bool lcPiece::SetPropertyValue(lcObjectPropertyId PropertyId, lcStep Step, bool case lcObjectPropertyId::LightName: case lcObjectPropertyId::LightType: case lcObjectPropertyId::LightColor: - case lcObjectPropertyId::LightPower: + case lcObjectPropertyId::LightBlenderPower: + case lcObjectPropertyId::LightPOVRayPower: case lcObjectPropertyId::LightCastShadow: case lcObjectPropertyId::LightPOVRayFadeDistance: case lcObjectPropertyId::LightPOVRayFadePower: @@ -802,7 +804,8 @@ bool lcPiece::HasKeyFrame(lcObjectPropertyId PropertyId, lcStep Time) const case lcObjectPropertyId::LightName: case lcObjectPropertyId::LightType: case lcObjectPropertyId::LightColor: - case lcObjectPropertyId::LightPower: + case lcObjectPropertyId::LightBlenderPower: + case lcObjectPropertyId::LightPOVRayPower: case lcObjectPropertyId::LightCastShadow: case lcObjectPropertyId::LightPOVRayFadeDistance: case lcObjectPropertyId::LightPOVRayFadePower: @@ -862,7 +865,8 @@ bool lcPiece::SetKeyFrame(lcObjectPropertyId PropertyId, lcStep Time, bool KeyFr case lcObjectPropertyId::LightName: case lcObjectPropertyId::LightType: case lcObjectPropertyId::LightColor: - case lcObjectPropertyId::LightPower: + case lcObjectPropertyId::LightBlenderPower: + case lcObjectPropertyId::LightPOVRayPower: case lcObjectPropertyId::LightCastShadow: case lcObjectPropertyId::LightPOVRayFadeDistance: case lcObjectPropertyId::LightPOVRayFadePower: diff --git a/common/project.cpp b/common/project.cpp index 289dbf66..baf67c28 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -2188,7 +2188,7 @@ bool Project::ExportPOVRay(const QString& FileName) const QString LightName = QString(Light->GetName()).replace(" ", "_"); LightType = Light->GetLightType(); Shadowless = Light->GetCastShadow() ? 0 : 1; - Power = Light->GetPower(); + Power = Light->GetPOVRayPower(); FadeDistance = Light->GetPOVRayFadeDistance(); FadePower = Light->GetPOVRayFadePower();