diff --git a/common/lc_model.cpp b/common/lc_model.cpp index d6bdf293..37836427 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -3237,6 +3237,16 @@ void lcModel::SetLightSize(lcLight* Light, lcVector2 LightAreaSize) UpdateAllViews(); } +void lcModel::SetLightPower(lcLight* Light, float Power) +{ + Light->SetPower(Power, mCurrentStep, gMainWindow->GetAddKeys()); + Light->UpdatePosition(mCurrentStep); + + SaveCheckpoint(tr("Changing Light Power")); + gMainWindow->UpdateSelectedObjects(false); + UpdateAllViews(); +} + void lcModel::SetLightCastShadow(lcLight* Light, bool CastShadow) { if (!Light->SetCastShadow(CastShadow)) diff --git a/common/lc_model.h b/common/lc_model.h index 71fb0e5b..7ec1349b 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -375,6 +375,7 @@ public: void SetSpotLightTightness(lcLight* Light, float Tightness); void SetAreaLightShape(lcLight* Light, lcLightAreaShape LightAreaShape); void SetLightSize(lcLight* Light, lcVector2 LightAreaSize); + void SetLightPower(lcLight* Light, float Power); void SetLightCastShadow(lcLight* Light, bool CastShadow); void SetLightName(lcLight* Light, const QString& Name); void UpdateLight(lcLight* Light, const lcLightProperties Props, int Property); diff --git a/common/light.cpp b/common/light.cpp index 53d28909..db09a6f2 100644 --- a/common/light.cpp +++ b/common/light.cpp @@ -40,6 +40,7 @@ lcLight::lcLight(const lcVector3& Position, lcLightType LightType) mPositionKeys.ChangeKey(mWorldMatrix.GetTranslation(), 1, true); mRotationKeys.ChangeKey(lcMatrix33(mWorldMatrix), 1, true); mColorKeys.ChangeKey(mColor, 1, true); + mPowerKeys.ChangeKey(mPower, 1, true); mSpotConeAngleKeys.ChangeKey(mSpotConeAngle, 1, true); mSpotPenumbraAngleKeys.ChangeKey(mSpotPenumbraAngle, 1, true); mSpotTightnessKeys.ChangeKey(mSpotTightness, 1, true); @@ -785,6 +786,11 @@ void lcLight::SetSize(lcVector2 Size, lcStep Step, bool AddKey) mSizeKeys.ChangeKey(Size, Step, AddKey); } +void lcLight::SetPower(float Power, lcStep Step, bool AddKey) +{ + mPowerKeys.ChangeKey(Power, Step, AddKey); +} + bool lcLight::SetCastShadow(bool CastShadow) { if (mCastShadow != CastShadow) @@ -805,6 +811,7 @@ void lcLight::InsertTime(lcStep Start, lcStep Time) mSpotPenumbraAngleKeys.InsertTime(Start, Time); mSpotTightnessKeys.InsertTime(Start, Time); mSizeKeys.InsertTime(Start, Time); + mPowerKeys.InsertTime(Start, Time); mAttenuationKeys.InsertTime(Start, Time); mLightDiffuseKeys.InsertTime(Start, Time); @@ -823,6 +830,7 @@ void lcLight::RemoveTime(lcStep Start, lcStep Time) mSpotPenumbraAngleKeys.RemoveTime(Start, Time); mSpotTightnessKeys.RemoveTime(Start, Time); mSizeKeys.RemoveTime(Start, Time); + mPowerKeys.RemoveTime(Start, Time); mAttenuationKeys.RemoveTime(Start, Time); mLightDiffuseKeys.RemoveTime(Start, Time); @@ -852,6 +860,7 @@ void lcLight::UpdatePosition(lcStep Step) mSpotPenumbraAngle = mSpotPenumbraAngleKeys.CalculateKey(Step); mSpotTightness = mSpotTightnessKeys.CalculateKey(Step); mSize = mSizeKeys.CalculateKey(Step); + mPower = mPowerKeys.CalculateKey(Step); mAttenuation = mAttenuationKeys.CalculateKey(Step); mLightDiffuse = mLightDiffuseKeys.CalculateKey(Step); @@ -1292,6 +1301,9 @@ void lcLight::RemoveKeyFrames() mSizeKeys.RemoveAll(); mSizeKeys.ChangeKey(mSize, 1, true); + mPowerKeys.RemoveAll(); + mPowerKeys.ChangeKey(mPower, 1, true); + mAttenuationKeys.RemoveAll(); mAttenuationKeys.ChangeKey(mAttenuation, 1, true); diff --git a/common/light.h b/common/light.h index 2b2e1e4e..7646e29f 100644 --- a/common/light.h +++ b/common/light.h @@ -280,6 +280,13 @@ public: return mSize; } + void SetPower(float Power, lcStep Step, bool AddKey); + + float GetPower() const + { + return mPower; + } + bool SetCastShadow(bool CastShadow); bool GetCastShadow() const @@ -351,6 +358,7 @@ protected: bool mCastShadow = true; lcVector3 mColor = lcVector3(1.0f, 1.0f, 1.0f); lcVector2 mSize = lcVector2(0.0f, 0.0f); + float mPower = 1.0f; float mSpotConeAngle = 80.0f; float mSpotPenumbraAngle = 0.0f; float mSpotTightness = 0.0f; @@ -365,6 +373,7 @@ protected: lcObjectKeyArray mRotationKeys; lcObjectKeyArray mColorKeys; lcObjectKeyArray mSizeKeys; + lcObjectKeyArray mPowerKeys; lcObjectKeyArray mSpotConeAngleKeys; lcObjectKeyArray mSpotPenumbraAngleKeys; lcObjectKeyArray mSpotTightnessKeys; diff --git a/qt/lc_qpropertiestree.cpp b/qt/lc_qpropertiestree.cpp index a648a179..bf1c2046 100644 --- a/qt/lc_qpropertiestree.cpp +++ b/qt/lc_qpropertiestree.cpp @@ -447,9 +447,6 @@ QWidget* lcQPropertiesTree::createEditor(QWidget* Parent, QTreeWidgetItem* Item) return Editor; } - case PropertyFloatReadOnly: - return nullptr; - case PropertyStep: { QLineEdit* Editor = new QLineEdit(Parent); @@ -859,6 +856,12 @@ void lcQPropertiesTree::slotReturnPressed() Model->SetLightSize(Light, Value); } + else if (Item == mLightPowerItem) + { + float Value = lcParseValueLocalized(Editor->text()); + + Model->SetLightPower(Light, Value); + } else if (Item == lightDiffuse) { Props.mLightDiffuse = lcParseValueLocalized(Editor->text()); @@ -1049,10 +1052,7 @@ QTreeWidgetItem *lcQPropertiesTree::addProperty(QTreeWidgetItem *parent, const Q newItem = new QTreeWidgetItem(this, QStringList(label)); newItem->setData(0, PropertyTypeRole, QVariant(propertyType)); - - if (propertyType != PropertyFloatReadOnly) - newItem->setFlags(newItem->flags() | Qt::ItemIsEditable); - + newItem->setFlags(newItem->flags() | Qt::ItemIsEditable); newItem->setExpanded(true); if (propertyType == PropertyGroup) @@ -1097,6 +1097,7 @@ void lcQPropertiesTree::SetEmpty() lightConfiguration = nullptr; mLightColorItem = nullptr; + mLightPowerItem = nullptr; mLightAttributesItem = nullptr; lightDiffuse = nullptr; lightSpecular = nullptr; @@ -1366,6 +1367,7 @@ void lcQPropertiesTree::SetLight(lcObject* Focus) lcLightType LightType = lcLightType::Point; lcLightAreaShape LightAreaShape = lcLightAreaShape::Rectangle; lcVector2 LightSize(0.0f, 0.0f); + float Power = 0.0f; int FormatIndex = 0; float Diffuse = 0.0f; float Specular = 0.0f; @@ -1390,6 +1392,7 @@ void lcQPropertiesTree::SetLight(lcObject* Focus) CastShadow = Light->GetCastShadow(); Position = Light->GetPosition(); Color = lcQColorFromVector3(Light->GetColor()); + Power = Light->GetPower(); SpotConeAngle = Light->GetSpotConeAngle(); SpotPenumbraAngle = Light->GetSpotPenumbraAngle(); @@ -1419,7 +1422,6 @@ void lcQPropertiesTree::SetLight(lcObject* Focus) break; } - Diffuse = Light->mLightDiffuse; Specular = Light->mLightSpecular; @@ -1449,7 +1451,13 @@ void lcQPropertiesTree::SetLight(lcObject* Focus) mLightAttributesItem = addProperty(nullptr, tr("Light Attributes"), PropertyGroup); mLightNameItem = addProperty(mLightAttributesItem, tr("Name"), PropertyString); mLightTypeItem = addProperty(mLightAttributesItem, tr("Type"), PropertyStringList); + mLightColorItem = addProperty(mLightAttributesItem, tr("Color"), PropertyColor); + mLightColorItem->setToolTip(1, tr("Color of the emitted light.")); + + mLightPowerItem = addProperty(mLightAttributesItem, tr("Power"), PropertyFloat); + mLightPowerItem->setToolTip(1, tr("Power of the light in Watts (Blender only).")); + mLightCastShadowItem = addProperty(mLightAttributesItem, tr("Cast Shadows"), PropertyBool); switch (LightType) @@ -1592,6 +1600,9 @@ void lcQPropertiesTree::SetLight(lcObject* Focus) mLightColorItem->setText(1, Color.name().toUpper()); mLightColorItem->setData(0, PropertyValueRole, Color); + mLightPowerItem->setText(1, lcFormatValueLocalized(Power)); + mLightPowerItem->setData(0, PropertyValueRole, Power); + lightFormat->setText(1, Format); lightFormat->setData(0, PropertyValueRole, FormatIndex); diff --git a/qt/lc_qpropertiestree.h b/qt/lc_qpropertiestree.h index e63d6474..2bdd490b 100644 --- a/qt/lc_qpropertiestree.h +++ b/qt/lc_qpropertiestree.h @@ -45,7 +45,6 @@ public: PropertyGroup, PropertyBool, PropertyFloat, - PropertyFloatReadOnly, PropertyStep, PropertyString, PropertyStringList, @@ -117,6 +116,7 @@ protected: QTreeWidgetItem* lightConfiguration; QTreeWidgetItem* mLightColorItem; + QTreeWidgetItem* mLightPowerItem; QTreeWidgetItem* mLightAttributesItem; QTreeWidgetItem* lightDiffuse; QTreeWidgetItem* lightSpecular;