mirror of
https://github.com/leozide/leocad
synced 2025-01-13 08:01:38 +01:00
Made light type editable.
This commit is contained in:
parent
9d60160f6a
commit
7d289f2cfe
6 changed files with 99 additions and 21 deletions
|
@ -3113,6 +3113,16 @@ void lcModel::SetCameraName(lcCamera* Camera, const QString& Name)
|
||||||
gMainWindow->UpdateCameraMenu();
|
gMainWindow->UpdateCameraMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lcModel::SetLightType(lcLight* Light, lcLightType LightType)
|
||||||
|
{
|
||||||
|
Light->SetLightType(LightType);
|
||||||
|
Light->UpdatePosition(mCurrentStep);
|
||||||
|
|
||||||
|
SaveCheckpoint(tr("Changing Light Type"));
|
||||||
|
gMainWindow->UpdateSelectedObjects(false);
|
||||||
|
UpdateAllViews();
|
||||||
|
}
|
||||||
|
|
||||||
void lcModel::SetLightColor(lcLight* Light, const lcVector3& Color)
|
void lcModel::SetLightColor(lcLight* Light, const lcVector3& Color)
|
||||||
{
|
{
|
||||||
if (Light->GetColor() == Color)
|
if (Light->GetColor() == Color)
|
||||||
|
@ -4190,6 +4200,9 @@ void lcModel::BeginDirectionalLightTool(const lcVector3& Position, const lcVecto
|
||||||
case lcLightType::Area:
|
case lcLightType::Area:
|
||||||
SaveCheckpoint(tr("New Area Light"));
|
SaveCheckpoint(tr("New Area Light"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case lcLightType::Count:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -368,6 +368,7 @@ public:
|
||||||
void SetCameraZFar(lcCamera* Camera, float ZFar);
|
void SetCameraZFar(lcCamera* Camera, float ZFar);
|
||||||
void SetCameraName(lcCamera* Camera, const QString& Name);
|
void SetCameraName(lcCamera* Camera, const QString& Name);
|
||||||
|
|
||||||
|
void SetLightType(lcLight* Light, lcLightType LightType);
|
||||||
void SetLightColor(lcLight* Light, const lcVector3& Color);
|
void SetLightColor(lcLight* Light, const lcVector3& Color);
|
||||||
void SetLightName(lcLight* Light, const QString& Name);
|
void SetLightName(lcLight* Light, const QString& Name);
|
||||||
void UpdateLight(lcLight* Light, const lcLightProperties Props, int Property);
|
void UpdateLight(lcLight* Light, const lcLightProperties Props, int Property);
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
#define LC_LIGHT_POSITION_EDGE 7.5f
|
#define LC_LIGHT_POSITION_EDGE 7.5f
|
||||||
|
|
||||||
static const std::array<QLatin1String, 4> gLightTypes = { QLatin1String("POINT"), QLatin1String("SPOT"), QLatin1String("DIRECTIONAL"), QLatin1String("AREA") };
|
static const std::array<QLatin1String, static_cast<int>(lcLightType::Count)> gLightTypes = { QLatin1String("POINT"), QLatin1String("SPOT"), QLatin1String("DIRECTIONAL"), QLatin1String("AREA") };
|
||||||
|
|
||||||
lcLight::lcLight(const lcVector3& Position, const lcVector3& TargetPosition, lcLightType LightType)
|
lcLight::lcLight(const lcVector3& Position, const lcVector3& TargetPosition, lcLightType LightType)
|
||||||
: lcObject(lcObjectType::Light), mLightType(LightType)
|
: lcObject(lcObjectType::Light), mLightType(LightType)
|
||||||
|
@ -78,6 +78,29 @@ lcLight::lcLight(const lcVector3& Position, const lcVector3& TargetPosition, lcL
|
||||||
UpdatePosition(1);
|
UpdatePosition(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString lcLight::GetLightTypeString(lcLightType LightType)
|
||||||
|
{
|
||||||
|
switch (LightType)
|
||||||
|
{
|
||||||
|
case lcLightType::Point:
|
||||||
|
return QT_TRANSLATE_NOOP("Light Names", "Point Light");
|
||||||
|
|
||||||
|
case lcLightType::Spot:
|
||||||
|
return QT_TRANSLATE_NOOP("Light Names", "Spotlight");
|
||||||
|
|
||||||
|
case lcLightType::Directional:
|
||||||
|
return QT_TRANSLATE_NOOP("Light Names", "Directional Light");
|
||||||
|
|
||||||
|
case lcLightType::Area:
|
||||||
|
return QT_TRANSLATE_NOOP("Light Names", "Area Light");
|
||||||
|
|
||||||
|
case lcLightType::Count:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
void lcLight::SaveLDraw(QTextStream& Stream) const
|
void lcLight::SaveLDraw(QTextStream& Stream) const
|
||||||
{
|
{
|
||||||
const QLatin1String LineEnding("\r\n");
|
const QLatin1String LineEnding("\r\n");
|
||||||
|
@ -142,6 +165,9 @@ void lcLight::SaveLDraw(QTextStream& Stream) const
|
||||||
|
|
||||||
switch (mLightType)
|
switch (mLightType)
|
||||||
{
|
{
|
||||||
|
case lcLightType::Count:
|
||||||
|
break;
|
||||||
|
|
||||||
case lcLightType::Point:
|
case lcLightType::Point:
|
||||||
if (!mPOVRayLight)
|
if (!mPOVRayLight)
|
||||||
{
|
{
|
||||||
|
@ -225,6 +251,7 @@ void lcLight::SaveLDraw(QTextStream& Stream) const
|
||||||
Stream << QLatin1String("0 !LEOCAD LIGHT SHAPE ");
|
Stream << QLatin1String("0 !LEOCAD LIGHT SHAPE ");
|
||||||
|
|
||||||
QString Shape = QLatin1String("UNDEFINED ");
|
QString Shape = QLatin1String("UNDEFINED ");
|
||||||
|
|
||||||
switch (mLightShape)
|
switch (mLightShape)
|
||||||
{
|
{
|
||||||
case LC_LIGHT_SHAPE_SQUARE:
|
case LC_LIGHT_SHAPE_SQUARE:
|
||||||
|
@ -275,7 +302,7 @@ void lcLight::CreateName(const lcArray<lcLight*>& Lights)
|
||||||
switch (mLightType)
|
switch (mLightType)
|
||||||
{
|
{
|
||||||
case lcLightType::Point:
|
case lcLightType::Point:
|
||||||
Prefix = QLatin1String("Pointlight ");
|
Prefix = QLatin1String("Point Light ");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case lcLightType::Spot:
|
case lcLightType::Spot:
|
||||||
|
@ -283,11 +310,14 @@ void lcLight::CreateName(const lcArray<lcLight*>& Lights)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case lcLightType::Directional:
|
case lcLightType::Directional:
|
||||||
Prefix = QLatin1String("Directionallight ");
|
Prefix = QLatin1String("Directional Light ");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case lcLightType::Area:
|
case lcLightType::Area:
|
||||||
Prefix = QLatin1String("Arealight ");
|
Prefix = QLatin1String("Area Light ");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case lcLightType::Count:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -522,6 +552,9 @@ bool lcLight::ParseLDrawLine(QTextStream& Stream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case lcLightType::Count:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -831,6 +864,14 @@ void lcLight::MoveSelected(lcStep Step, bool AddKey, const lcVector3& Distance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lcLight::SetLightType(lcLightType LightType)
|
||||||
|
{
|
||||||
|
if (static_cast<int>(LightType) < 0 || LightType >= lcLightType::Count)
|
||||||
|
return;
|
||||||
|
|
||||||
|
mLightType = LightType;
|
||||||
|
}
|
||||||
|
|
||||||
void lcLight::SetColor(const lcVector3& Color, lcStep Step, bool AddKey)
|
void lcLight::SetColor(const lcVector3& Color, lcStep Step, bool AddKey)
|
||||||
{
|
{
|
||||||
mColorKeys.ChangeKey(Color, Step, AddKey);
|
mColorKeys.ChangeKey(Color, Step, AddKey);
|
||||||
|
@ -948,6 +989,9 @@ void lcLight::DrawInterface(lcContext* Context, const lcScene& Scene) const
|
||||||
case lcLightType::Area:
|
case lcLightType::Area:
|
||||||
DrawAreaLight(Context);
|
DrawAreaLight(Context);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case lcLightType::Count:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,8 @@ enum class lcLightType
|
||||||
Point,
|
Point,
|
||||||
Spot,
|
Spot,
|
||||||
Directional,
|
Directional,
|
||||||
Area
|
Area,
|
||||||
|
Count
|
||||||
};
|
};
|
||||||
|
|
||||||
enum lcLightShape
|
enum lcLightShape
|
||||||
|
@ -86,6 +87,8 @@ public:
|
||||||
lcLight& operator=(const lcLight&) = delete;
|
lcLight& operator=(const lcLight&) = delete;
|
||||||
lcLight& operator=(lcLight&&) = delete;
|
lcLight& operator=(lcLight&&) = delete;
|
||||||
|
|
||||||
|
static QString GetLightTypeString(lcLightType LightType);
|
||||||
|
|
||||||
bool IsPointLight() const
|
bool IsPointLight() const
|
||||||
{
|
{
|
||||||
return mLightType == lcLightType::Point;
|
return mLightType == lcLightType::Point;
|
||||||
|
@ -111,6 +114,8 @@ public:
|
||||||
return mLightType;
|
return mLightType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetLightType(lcLightType LightType);
|
||||||
|
|
||||||
int GetLightShape() const
|
int GetLightShape() const
|
||||||
{
|
{
|
||||||
return mLightShape;
|
return mLightShape;
|
||||||
|
@ -158,6 +163,9 @@ public:
|
||||||
case lcLightType::Area:
|
case lcLightType::Area:
|
||||||
mState |= LC_LIGHT_POSITION_SELECTED | LC_LIGHT_TARGET_SELECTED | LC_LIGHT_UPVECTOR_SELECTED;
|
mState |= LC_LIGHT_POSITION_SELECTED | LC_LIGHT_TARGET_SELECTED | LC_LIGHT_UPVECTOR_SELECTED;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case lcLightType::Count:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -524,8 +524,21 @@ QWidget *lcQPropertiesTree::createEditor(QWidget *parent, QTreeWidgetItem *item)
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
case PropertyStringLightReadOnly:
|
case PropertyStringList:
|
||||||
return nullptr;
|
{
|
||||||
|
QComboBox* editor = new QComboBox(parent);
|
||||||
|
|
||||||
|
if (item == mLightTypeItem)
|
||||||
|
for (int LightTypeIndex = 0; LightTypeIndex < static_cast<int>(lcLightType::Count); LightTypeIndex++)
|
||||||
|
editor->addItem(lcLight::GetLightTypeString(static_cast<lcLightType>(LightTypeIndex)));
|
||||||
|
|
||||||
|
int value = item->data(0, PropertyValueRole).toInt();
|
||||||
|
editor->setCurrentIndex(value);
|
||||||
|
|
||||||
|
connect(editor, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSetValue(int)));
|
||||||
|
|
||||||
|
return editor;
|
||||||
|
}
|
||||||
|
|
||||||
case PropertyLightFormat:
|
case PropertyLightFormat:
|
||||||
{
|
{
|
||||||
|
@ -1023,13 +1036,17 @@ void lcQPropertiesTree::slotSetValue(int Value)
|
||||||
else if (mWidgetMode == LC_PROPERTY_WIDGET_LIGHT)
|
else if (mWidgetMode == LC_PROPERTY_WIDGET_LIGHT)
|
||||||
{
|
{
|
||||||
lcObject* Focus = Model->GetFocusObject();
|
lcObject* Focus = Model->GetFocusObject();
|
||||||
|
|
||||||
lcLight* Light = (Focus && Focus->IsLight()) ? (lcLight*)Focus : nullptr;
|
lcLight* Light = (Focus && Focus->IsLight()) ? (lcLight*)Focus : nullptr;
|
||||||
|
|
||||||
if (Light)
|
if (Light)
|
||||||
{
|
{
|
||||||
lcLightProperties Props = Light->GetLightProperties();
|
lcLightProperties Props = Light->GetLightProperties();
|
||||||
if (Item == lightShape)
|
|
||||||
|
if (Item == mLightTypeItem)
|
||||||
|
{
|
||||||
|
Model->SetLightType(Light, static_cast<lcLightType>(Value));
|
||||||
|
}
|
||||||
|
else if (Item == lightShape)
|
||||||
{
|
{
|
||||||
Props.mLightShape = static_cast<lcLightShape>(Value);
|
Props.mLightShape = static_cast<lcLightShape>(Value);
|
||||||
Model->UpdateLight(Light, Props, LC_LIGHT_SHAPE);
|
Model->UpdateLight(Light, Props, LC_LIGHT_SHAPE);
|
||||||
|
@ -1129,7 +1146,7 @@ QTreeWidgetItem *lcQPropertiesTree::addProperty(QTreeWidgetItem *parent, const Q
|
||||||
newItem->setIcon(0, m_expandIcon);
|
newItem->setIcon(0, m_expandIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (propertyType == PropertyStringLightReadOnly || propertyType == PropertyFloatReadOnly)
|
if (propertyType == PropertyFloatReadOnly)
|
||||||
newItem->setFlags(newItem->flags() & ~Qt::ItemIsEditable);
|
newItem->setFlags(newItem->flags() & ~Qt::ItemIsEditable);
|
||||||
|
|
||||||
return newItem;
|
return newItem;
|
||||||
|
@ -1193,7 +1210,7 @@ void lcQPropertiesTree::SetEmpty()
|
||||||
lightCutoff = nullptr;
|
lightCutoff = nullptr;
|
||||||
lightEnableCutoff = nullptr;
|
lightEnableCutoff = nullptr;
|
||||||
lightExponent = nullptr;
|
lightExponent = nullptr;
|
||||||
lightType = nullptr;
|
mLightTypeItem = nullptr;
|
||||||
lightFactorA = nullptr;
|
lightFactorA = nullptr;
|
||||||
lightFactorB = nullptr;
|
lightFactorB = nullptr;
|
||||||
lightName = nullptr;
|
lightName = nullptr;
|
||||||
|
@ -1439,7 +1456,6 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
|
||||||
QString Name = tr("Light");
|
QString Name = tr("Light");
|
||||||
QString ExponentLabel = tr("Exponent");
|
QString ExponentLabel = tr("Exponent");
|
||||||
QString FactorALabel = QLatin1String("FactorA");
|
QString FactorALabel = QLatin1String("FactorA");
|
||||||
QString Type = QLatin1String("Undefined");
|
|
||||||
QString Format, Shape, SpotSizeToolTip, ExponentToolTip, FactorAToolTip, FactorBToolTip;
|
QString Format, Shape, SpotSizeToolTip, ExponentToolTip, FactorAToolTip, FactorBToolTip;
|
||||||
lcLightType LightType = lcLightType::Point;
|
lcLightType LightType = lcLightType::Point;
|
||||||
lcLightShape ShapeIndex = LC_LIGHT_SHAPE_UNDEFINED;
|
lcLightShape ShapeIndex = LC_LIGHT_SHAPE_UNDEFINED;
|
||||||
|
@ -1480,13 +1496,11 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
|
||||||
switch(LightType)
|
switch(LightType)
|
||||||
{
|
{
|
||||||
case lcLightType::Point:
|
case lcLightType::Point:
|
||||||
Type = tr("Point");
|
|
||||||
FactorALabel = tr("Radius (m)");
|
FactorALabel = tr("Radius (m)");
|
||||||
FactorAToolTip = tr("The light size for shadow sampling in metres.");
|
FactorAToolTip = tr("The light size for shadow sampling in metres.");
|
||||||
ExponentLabel = tr("Exponent");
|
ExponentLabel = tr("Exponent");
|
||||||
break;
|
break;
|
||||||
case lcLightType::Spot:
|
case lcLightType::Spot:
|
||||||
Type = tr("Spot");
|
|
||||||
FactorBToolTip = tr("The softness of the spotlight edge.");
|
FactorBToolTip = tr("The softness of the spotlight edge.");
|
||||||
ExponentLabel = tr("Power");
|
ExponentLabel = tr("Power");
|
||||||
|
|
||||||
|
@ -1506,13 +1520,11 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case lcLightType::Directional:
|
case lcLightType::Directional:
|
||||||
Type = tr("Directional");
|
|
||||||
FactorALabel = tr("Angle (°)");
|
FactorALabel = tr("Angle (°)");
|
||||||
FactorAToolTip = tr("Angular diamater of the sun as seen from the Earth.");
|
FactorAToolTip = tr("Angular diamater of the sun as seen from the Earth.");
|
||||||
ExponentLabel = tr("Strength");
|
ExponentLabel = tr("Strength");
|
||||||
break;
|
break;
|
||||||
case lcLightType::Area:
|
case lcLightType::Area:
|
||||||
Type = tr("Area");
|
|
||||||
ExponentLabel = tr("Power");
|
ExponentLabel = tr("Power");
|
||||||
|
|
||||||
if (POVRayLight)
|
if (POVRayLight)
|
||||||
|
@ -1609,7 +1621,7 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
lightProperties = addProperty(nullptr, tr("Properties"), PropertyGroup);
|
lightProperties = addProperty(nullptr, tr("Properties"), PropertyGroup);
|
||||||
lightType = addProperty(lightProperties, tr("Type"), PropertyStringLightReadOnly);
|
mLightTypeItem = addProperty(lightProperties, tr("Type"), PropertyStringList);
|
||||||
lightShadowless = addProperty(lightProperties, tr("Shadowless"), PropertyBool);
|
lightShadowless = addProperty(lightProperties, tr("Shadowless"), PropertyBool);
|
||||||
lightExponent = addProperty(lightProperties, ExponentLabel, PropertyFloat);
|
lightExponent = addProperty(lightProperties, ExponentLabel, PropertyFloat);
|
||||||
|
|
||||||
|
@ -1712,8 +1724,8 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
|
||||||
lightFormat->setText(1, Format);
|
lightFormat->setText(1, Format);
|
||||||
lightFormat->setData(0, PropertyValueRole, FormatIndex);
|
lightFormat->setData(0, PropertyValueRole, FormatIndex);
|
||||||
|
|
||||||
lightType->setText(1, Type);
|
mLightTypeItem->setText(1, lcLight::GetLightTypeString(LightType));
|
||||||
lightType->setData(0, PropertyValueRole, Type);
|
mLightTypeItem->setData(0, PropertyValueRole, static_cast<int>(LightType));
|
||||||
|
|
||||||
lightShadowless->setText(1, Shadowless ? "True" : "False");
|
lightShadowless->setText(1, Shadowless ? "True" : "False");
|
||||||
lightShadowless->setData(0, PropertyValueRole, Shadowless);
|
lightShadowless->setData(0, PropertyValueRole, Shadowless);
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
PropertyFloatLightSpotFalloff,
|
PropertyFloatLightSpotFalloff,
|
||||||
PropertyStep,
|
PropertyStep,
|
||||||
PropertyString,
|
PropertyString,
|
||||||
PropertyStringLightReadOnly,
|
PropertyStringList,
|
||||||
PropertyLightFormat,
|
PropertyLightFormat,
|
||||||
PropertyLightShape,
|
PropertyLightShape,
|
||||||
PropertyLightColor,
|
PropertyLightColor,
|
||||||
|
@ -145,7 +145,7 @@ protected:
|
||||||
QTreeWidgetItem *lightCutoff;
|
QTreeWidgetItem *lightCutoff;
|
||||||
QTreeWidgetItem *lightEnableCutoff;
|
QTreeWidgetItem *lightEnableCutoff;
|
||||||
QTreeWidgetItem *lightExponent;
|
QTreeWidgetItem *lightExponent;
|
||||||
QTreeWidgetItem *lightType;
|
QTreeWidgetItem *mLightTypeItem;
|
||||||
QTreeWidgetItem *lightSpotSize;
|
QTreeWidgetItem *lightSpotSize;
|
||||||
QTreeWidgetItem *lightShape;
|
QTreeWidgetItem *lightShape;
|
||||||
QTreeWidgetItem *lightFactorA;
|
QTreeWidgetItem *lightFactorA;
|
||||||
|
|
Loading…
Reference in a new issue