Show light rotation in properties.

This commit is contained in:
Leonardo Zide 2023-10-01 12:49:35 -07:00
parent a27694a594
commit 96523c39b9
2 changed files with 119 additions and 164 deletions

View file

@ -667,50 +667,54 @@ void lcQPropertiesTree::slotReturnPressed()
QTreeWidgetItem* Item = mDelegate->editedItem(); QTreeWidgetItem* Item = mDelegate->editedItem();
lcModel* Model = gMainWindow->GetActiveModel(); lcModel* Model = gMainWindow->GetActiveModel();
lcPiece* Piece = (mFocus && mFocus->IsPiece()) ? (lcPiece*)mFocus : nullptr;
lcLight* Light = (mFocus && mFocus->IsLight()) ? (lcLight*)mFocus : nullptr;
if (Item == mPositionXItem || Item == mPositionYItem || Item == mPositionZItem)
{
lcVector3 Center;
lcMatrix33 RelativeRotation;
Model->GetMoveRotateTransform(Center, RelativeRotation);
lcVector3 Position = Center;
float Value = lcParseValueLocalized(Editor->text());
if (Item == mPositionXItem)
Position[0] = Value;
else if (Item == mPositionYItem)
Position[1] = Value;
else if (Item == mPositionZItem)
Position[2] = Value;
lcVector3 Distance = Position - Center;
Model->MoveSelectedObjects(Distance, Distance, false, true, true, true);
}
else if (Item == mRotationXItem || Item == mRotationYItem || Item == mRotationZItem)
{
lcVector3 InitialRotation(0.0f, 0.0f, 0.0f);
if (Piece)
InitialRotation = lcMatrix44ToEulerAngles(Piece->mModelWorld) * LC_RTOD;
else if (Light)
InitialRotation = lcMatrix44ToEulerAngles(Light->mWorldMatrix) * LC_RTOD;
lcVector3 Rotation = InitialRotation;
float Value = lcParseValueLocalized(Editor->text());
if (Item == mRotationXItem)
Rotation[0] = Value;
else if (Item == mRotationYItem)
Rotation[1] = Value;
else if (Item == mRotationZItem)
Rotation[2] = Value;
Model->RotateSelectedObjects(Rotation - InitialRotation, true, false, true, true);
}
if (mWidgetMode == LC_PROPERTY_WIDGET_PIECE) if (mWidgetMode == LC_PROPERTY_WIDGET_PIECE)
{ {
lcPiece* Piece = (mFocus && mFocus->IsPiece()) ? (lcPiece*)mFocus : nullptr; if (Item == partShow)
if (Item == partPositionX || Item == partPositionY || Item == partPositionZ)
{
lcVector3 Center;
lcMatrix33 RelativeRotation;
Model->GetMoveRotateTransform(Center, RelativeRotation);
lcVector3 Position = Center;
float Value = lcParseValueLocalized(Editor->text());
if (Item == partPositionX)
Position[0] = Value;
else if (Item == partPositionY)
Position[1] = Value;
else if (Item == partPositionZ)
Position[2] = Value;
lcVector3 Distance = Position - Center;
Model->MoveSelectedObjects(Distance, Distance, false, false, true, true);
}
else if (Item == partRotationX || Item == partRotationY || Item == partRotationZ)
{
lcVector3 InitialRotation;
if (Piece)
InitialRotation = lcMatrix44ToEulerAngles(Piece->mModelWorld) * LC_RTOD;
else
InitialRotation = lcVector3(0.0f, 0.0f, 0.0f);
lcVector3 Rotation = InitialRotation;
float Value = lcParseValueLocalized(Editor->text());
if (Item == partRotationX)
Rotation[0] = Value;
else if (Item == partRotationY)
Rotation[1] = Value;
else if (Item == partRotationZ)
Rotation[2] = Value;
Model->RotateSelectedObjects(Rotation - InitialRotation, true, false, true, true);
}
else if (Item == partShow)
{ {
bool Ok = false; bool Ok = false;
lcStep Step = Editor->text().toUInt(&Ok); lcStep Step = Editor->text().toUInt(&Ok);
@ -819,49 +823,11 @@ void lcQPropertiesTree::slotReturnPressed()
} }
else if (mWidgetMode == LC_PROPERTY_WIDGET_LIGHT) else if (mWidgetMode == LC_PROPERTY_WIDGET_LIGHT)
{ {
lcLight* Light = (mFocus && mFocus->IsLight()) ? (lcLight*)mFocus : nullptr;
if (Light) if (Light)
{ {
lcLightProperties Props = Light->GetLightProperties(); lcLightProperties Props = Light->GetLightProperties();
QString Name = Light->GetName(); if (Item == mLightSpotConeAngleItem)
if (Item == lightPositionX || Item == lightPositionY || Item == lightPositionZ)
{
lcVector3 Center = Light->GetPosition();
lcVector3 Position = Center;
float Value = lcParseValueLocalized(Editor->text());
if (Item == lightPositionX)
Position[0] = Value;
else if (Item == lightPositionY)
Position[1] = Value;
else if (Item == lightPositionZ)
Position[2] = Value;
lcVector3 Distance = Position - Center;
Model->MoveSelectedObjects(Distance, Distance, false, false, true, true);
}
else if (Item == lightTargetX || Item == lightTargetY || Item == lightTargetZ)
{
// lcVector3 Center = Light->mTargetPosition;
// lcVector3 Position = Center;
// float Value = lcParseValueLocalized(Editor->text());
// if (Item == lightTargetX)
// Position[0] = Value;
// else if (Item == lightTargetY)
// Position[1] = Value;
// else if (Item == lightTargetZ)
// Position[2] = Value;
//
// lcVector3 Distance = Position - Center;
//
// Model->MoveSelectedObjects(Distance, Distance, false, false, true, true);
}
else if (Item == mLightSpotConeAngleItem)
{ {
float Value = lcParseValueLocalized(Editor->text()); float Value = lcParseValueLocalized(Editor->text());
@ -1103,14 +1069,6 @@ void lcQPropertiesTree::SetEmpty()
clear(); clear();
mPieceAttributesItem = nullptr; mPieceAttributesItem = nullptr;
partPosition = nullptr;
partPositionX = nullptr;
partPositionY = nullptr;
partPositionZ = nullptr;
partRotation = nullptr;
partRotationX = nullptr;
partRotationY = nullptr;
partRotationZ = nullptr;
partVisibility = nullptr; partVisibility = nullptr;
partShow = nullptr; partShow = nullptr;
partHide = nullptr; partHide = nullptr;
@ -1138,14 +1096,6 @@ void lcQPropertiesTree::SetEmpty()
mCameraNameItem = nullptr; mCameraNameItem = nullptr;
lightConfiguration = nullptr; lightConfiguration = nullptr;
lightPosition = nullptr;
lightPositionX = nullptr;
lightPositionY = nullptr;
lightPositionZ = nullptr;
lightTarget = nullptr;
lightTargetX = nullptr;
lightTargetY = nullptr;
lightTargetZ = nullptr;
mLightColorItem = nullptr; mLightColorItem = nullptr;
mLightAttributesItem = nullptr; mLightAttributesItem = nullptr;
lightDiffuse = nullptr; lightDiffuse = nullptr;
@ -1166,6 +1116,15 @@ void lcQPropertiesTree::SetEmpty()
lightAreaGridRows = nullptr; lightAreaGridRows = nullptr;
lightAreaGridColumns = nullptr; lightAreaGridColumns = nullptr;
mPositionItem = nullptr;
mPositionXItem = nullptr;
mPositionYItem = nullptr;
mPositionZItem = nullptr;
mRotationItem = nullptr;
mRotationXItem = nullptr;
mRotationYItem = nullptr;
mRotationZItem = nullptr;
mWidgetMode = LC_PROPERTY_WIDGET_EMPTY; mWidgetMode = LC_PROPERTY_WIDGET_EMPTY;
mFocus = nullptr; mFocus = nullptr;
} }
@ -1184,15 +1143,15 @@ void lcQPropertiesTree::SetPiece(const lcArray<lcObject*>& Selection, lcObject*
partShow = addProperty(partVisibility, tr("Show"), PropertyStep); partShow = addProperty(partVisibility, tr("Show"), PropertyStep);
partHide = addProperty(partVisibility, tr("Hide"), PropertyStep); partHide = addProperty(partVisibility, tr("Hide"), PropertyStep);
partPosition = addProperty(nullptr, tr("Position"), PropertyGroup); mPositionItem = addProperty(nullptr, tr("Position"), PropertyGroup);
partPositionX = addProperty(partPosition, tr("X"), PropertyFloat); mPositionXItem = addProperty(mPositionItem, tr("X"), PropertyFloat);
partPositionY = addProperty(partPosition, tr("Y"), PropertyFloat); mPositionYItem = addProperty(mPositionItem, tr("Y"), PropertyFloat);
partPositionZ = addProperty(partPosition, tr("Z"), PropertyFloat); mPositionZItem = addProperty(mPositionItem, tr("Z"), PropertyFloat);
partRotation = addProperty(nullptr, tr("Rotation"), PropertyGroup); mRotationItem = addProperty(nullptr, tr("Rotation"), PropertyGroup);
partRotationX = addProperty(partRotation, tr("X"), PropertyFloat); mRotationXItem = addProperty(mRotationItem, tr("X"), PropertyFloat);
partRotationY = addProperty(partRotation, tr("Y"), PropertyFloat); mRotationYItem = addProperty(mRotationItem, tr("Y"), PropertyFloat);
partRotationZ = addProperty(partRotation, tr("Z"), PropertyFloat); mRotationZItem = addProperty(mRotationItem, tr("Z"), PropertyFloat);
mWidgetMode = LC_PROPERTY_WIDGET_PIECE; mWidgetMode = LC_PROPERTY_WIDGET_PIECE;
} }
@ -1203,25 +1162,29 @@ void lcQPropertiesTree::SetPiece(const lcArray<lcObject*>& Selection, lcObject*
lcVector3 Position; lcVector3 Position;
lcMatrix33 RelativeRotation; lcMatrix33 RelativeRotation;
Model->GetMoveRotateTransform(Position, RelativeRotation); Model->GetMoveRotateTransform(Position, RelativeRotation);
partPositionX->setText(1, lcFormatValueLocalized(Position[0]));
partPositionX->setData(0, PropertyValueRole, Position[0]); mPositionXItem->setText(1, lcFormatValueLocalized(Position[0]));
partPositionY->setText(1, lcFormatValueLocalized(Position[1])); mPositionXItem->setData(0, PropertyValueRole, Position[0]);
partPositionY->setData(0, PropertyValueRole, Position[1]); mPositionYItem->setText(1, lcFormatValueLocalized(Position[1]));
partPositionZ->setText(1, lcFormatValueLocalized(Position[2])); mPositionYItem->setData(0, PropertyValueRole, Position[1]);
partPositionZ->setData(0, PropertyValueRole, Position[2]); mPositionZItem->setText(1, lcFormatValueLocalized(Position[2]));
mPositionZItem->setData(0, PropertyValueRole, Position[2]);
lcVector3 Rotation; lcVector3 Rotation;
if (Piece) if (Piece)
Rotation = lcMatrix44ToEulerAngles(Piece->mModelWorld) * LC_RTOD; Rotation = lcMatrix44ToEulerAngles(Piece->mModelWorld) * LC_RTOD;
else else
Rotation = lcVector3(0.0f, 0.0f, 0.0f); Rotation = lcVector3(0.0f, 0.0f, 0.0f);
partRotationX->setText(1, lcFormatValueLocalized(Rotation[0]));
partRotationX->setData(0, PropertyValueRole, Rotation[0]); mRotationXItem->setText(1, lcFormatValueLocalized(Rotation[0]));
partRotationY->setText(1, lcFormatValueLocalized(Rotation[1])); mRotationXItem->setData(0, PropertyValueRole, Rotation[0]);
partRotationY->setData(0, PropertyValueRole, Rotation[1]); mRotationYItem->setText(1, lcFormatValueLocalized(Rotation[1]));
partRotationZ->setText(1, lcFormatValueLocalized(Rotation[2])); mRotationYItem->setData(0, PropertyValueRole, Rotation[1]);
partRotationZ->setData(0, PropertyValueRole, Rotation[2]); mRotationZItem->setText(1, lcFormatValueLocalized(Rotation[2]));
mRotationZItem->setData(0, PropertyValueRole, Rotation[2]);
lcStep Show = 0; lcStep Show = 0;
lcStep Hide = 0; lcStep Hide = 0;
@ -1411,9 +1374,7 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
bool EnableCutoff = false; bool EnableCutoff = false;
bool POVRayLight = false; bool POVRayLight = false;
bool CastShadow = true; bool CastShadow = true;
PropertyType TargetProperty = PropertyFloat;
lcVector3 Position(0.0f, 0.0f, 0.0f); lcVector3 Position(0.0f, 0.0f, 0.0f);
lcVector3 Target(0.0f, 0.0f, 0.0f);
QColor Color(Qt::white); QColor Color(Qt::white);
float SpotConeAngle = 0.0f, SpotPenumbraAngle = 0.0f, SpotTightness = 0.0f; float SpotConeAngle = 0.0f, SpotPenumbraAngle = 0.0f, SpotTightness = 0.0f;
lcVector2 AreaGrid(0.0f, 0.0f); lcVector2 AreaGrid(0.0f, 0.0f);
@ -1428,7 +1389,6 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
CastShadow = Light->GetCastShadow(); CastShadow = Light->GetCastShadow();
Position = Light->GetPosition(); Position = Light->GetPosition();
// Target = Light->mTargetPosition;
Color = lcQColorFromVector3(Light->GetColor()); Color = lcQColorFromVector3(Light->GetColor());
SpotConeAngle = Light->GetSpotConeAngle(); SpotConeAngle = Light->GetSpotConeAngle();
SpotPenumbraAngle = Light->GetSpotPenumbraAngle(); SpotPenumbraAngle = Light->GetSpotPenumbraAngle();
@ -1477,12 +1437,11 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
ExponentLabel = LightType == lcLightType::Directional ? tr("Strength") : tr("Power"); ExponentLabel = LightType == lcLightType::Directional ? tr("Strength") : tr("Power");
Cutoff = Light->mSpotCutoff; Cutoff = Light->mSpotCutoff;
EnableCutoff = Light->mEnableCutoff; EnableCutoff = Light->mEnableCutoff;
TargetProperty = LightType != lcLightType::Point ? PropertyFloat : PropertyFloatReadOnly;
SpotTightness = Light->GetSpotTightness(); SpotTightness = Light->GetSpotTightness();
AreaGrid = Light->mAreaGrid; AreaGrid = Light->mAreaGrid;
} }
if (mWidgetMode != LC_PROPERTY_WIDGET_LIGHT || mLightType != LightType || mLightAreaShape != LightAreaShape || mPOVRayLight != POVRayLight) if (mWidgetMode != LC_PROPERTY_WIDGET_LIGHT || mLightType != LightType || mPOVRayLight != POVRayLight)
{ {
SetEmpty(); SetEmpty();
@ -1575,44 +1534,48 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
lightConfiguration = addProperty(nullptr, tr("Configuration"), PropertyGroup); lightConfiguration = addProperty(nullptr, tr("Configuration"), PropertyGroup);
lightFormat = addProperty(lightConfiguration, tr("Format"), PropertyLightFormat); lightFormat = addProperty(lightConfiguration, tr("Format"), PropertyLightFormat);
// Position mPositionItem = addProperty(nullptr, tr("Position"), PropertyGroup);
lightPosition = addProperty(nullptr, tr("Position"), PropertyGroup); mPositionXItem = addProperty(mPositionItem, tr("X"), PropertyFloat);
lightPositionX = addProperty(lightPosition, tr("X"), PropertyFloat); mPositionYItem = addProperty(mPositionItem, tr("Y"), PropertyFloat);
lightPositionY = addProperty(lightPosition, tr("Y"), PropertyFloat); mPositionZItem = addProperty(mPositionItem, tr("Z"), PropertyFloat);
lightPositionZ = addProperty(lightPosition, tr("Z"), PropertyFloat);
// Target Position if (LightType != lcLightType::Point)
if (LightType != lcLightType::Point && !(LightType == lcLightType::Area && POVRayLight))
{ {
lightTarget = addProperty(nullptr, tr("Target"), PropertyGroup); mRotationItem = addProperty(nullptr, tr("Rotation"), PropertyGroup);
lightTargetX = addProperty(lightTarget, tr("X"), TargetProperty); mRotationXItem = addProperty(mRotationItem, tr("X"), PropertyFloat);
lightTargetY = addProperty(lightTarget, tr("Y"), TargetProperty); mRotationYItem = addProperty(mRotationItem, tr("Y"), PropertyFloat);
lightTargetZ = addProperty(lightTarget, tr("Z"), TargetProperty); mRotationZItem = addProperty(mRotationItem, tr("Z"), PropertyFloat);
} }
mWidgetMode = LC_PROPERTY_WIDGET_LIGHT; mWidgetMode = LC_PROPERTY_WIDGET_LIGHT;
mLightType = LightType; mLightType = LightType;
mLightAreaShape = LightAreaShape;
mPOVRayLight = POVRayLight; mPOVRayLight = POVRayLight;
} }
mFocus = Light; mFocus = Light;
lightPositionX->setText(1, lcFormatValueLocalized(Position[0])); mPositionXItem->setText(1, lcFormatValueLocalized(Position[0]));
lightPositionX->setData(0, PropertyValueRole, Position[0]); mPositionXItem->setData(0, PropertyValueRole, Position[0]);
lightPositionY->setText(1, lcFormatValueLocalized(Position[1])); mPositionYItem->setText(1, lcFormatValueLocalized(Position[1]));
lightPositionY->setData(0, PropertyValueRole, Position[1]); mPositionYItem->setData(0, PropertyValueRole, Position[1]);
lightPositionZ->setText(1, lcFormatValueLocalized(Position[2])); mPositionZItem->setText(1, lcFormatValueLocalized(Position[2]));
lightPositionZ->setData(0, PropertyValueRole, Position[2]); mPositionZItem->setData(0, PropertyValueRole, Position[2]);
if (LightType != lcLightType::Point && !(LightType == lcLightType::Area && POVRayLight)) if (LightType != lcLightType::Point)
{ {
lightTargetX->setText(1, lcFormatValueLocalized(Target[0])); lcVector3 Rotation;
lightTargetX->setData(0, PropertyValueRole, Target[0]);
lightTargetY->setText(1, lcFormatValueLocalized(Target[1])); if (Light)
lightTargetY->setData(0, PropertyValueRole, Target[1]); Rotation = lcMatrix44ToEulerAngles(Light->mWorldMatrix) * LC_RTOD;
lightTargetZ->setText(1, lcFormatValueLocalized(Target[2])); else
lightTargetZ->setData(0, PropertyValueRole, Target[2]); Rotation = lcVector3(0.0f, 0.0f, 0.0f);
mRotationXItem->setText(1, lcFormatValueLocalized(Rotation[0]));
mRotationXItem->setData(0, PropertyValueRole, Rotation[0]);
mRotationYItem->setText(1, lcFormatValueLocalized(Rotation[1]));
mRotationYItem->setData(0, PropertyValueRole, Rotation[1]);
mRotationZItem->setText(1, lcFormatValueLocalized(Rotation[2]));
mRotationZItem->setData(0, PropertyValueRole, Rotation[2]);
} }
QImage ColorImage(16, 16, QImage::Format_ARGB32); QImage ColorImage(16, 16, QImage::Format_ARGB32);

View file

@ -78,7 +78,6 @@ protected:
void SetMultiple(); void SetMultiple();
lcLightType mLightType; lcLightType mLightType;
lcLightAreaShape mLightAreaShape;
bool mPOVRayLight; bool mPOVRayLight;
lcPropertyWidgetMode mWidgetMode; lcPropertyWidgetMode mWidgetMode;
@ -90,14 +89,6 @@ protected:
QIcon m_uncheckedIcon; QIcon m_uncheckedIcon;
QTreeWidgetItem* mPieceAttributesItem; QTreeWidgetItem* mPieceAttributesItem;
QTreeWidgetItem* partPosition;
QTreeWidgetItem* partPositionX;
QTreeWidgetItem* partPositionY;
QTreeWidgetItem* partPositionZ;
QTreeWidgetItem* partRotation;
QTreeWidgetItem* partRotationX;
QTreeWidgetItem* partRotationY;
QTreeWidgetItem* partRotationZ;
QTreeWidgetItem* partVisibility; QTreeWidgetItem* partVisibility;
QTreeWidgetItem* partShow; QTreeWidgetItem* partShow;
QTreeWidgetItem* partHide; QTreeWidgetItem* partHide;
@ -125,14 +116,6 @@ protected:
QTreeWidgetItem* mCameraNameItem; QTreeWidgetItem* mCameraNameItem;
QTreeWidgetItem* lightConfiguration; QTreeWidgetItem* lightConfiguration;
QTreeWidgetItem* lightPosition;
QTreeWidgetItem* lightPositionX;
QTreeWidgetItem* lightPositionY;
QTreeWidgetItem* lightPositionZ;
QTreeWidgetItem* lightTarget;
QTreeWidgetItem* lightTargetX;
QTreeWidgetItem* lightTargetY;
QTreeWidgetItem* lightTargetZ;
QTreeWidgetItem* mLightColorItem; QTreeWidgetItem* mLightColorItem;
QTreeWidgetItem* mLightAttributesItem; QTreeWidgetItem* mLightAttributesItem;
QTreeWidgetItem* lightDiffuse; QTreeWidgetItem* lightDiffuse;
@ -152,6 +135,15 @@ protected:
QTreeWidgetItem* mLightCastShadowItem; QTreeWidgetItem* mLightCastShadowItem;
QTreeWidgetItem* lightAreaGridRows; QTreeWidgetItem* lightAreaGridRows;
QTreeWidgetItem* lightAreaGridColumns; QTreeWidgetItem* lightAreaGridColumns;
QTreeWidgetItem* mPositionItem;
QTreeWidgetItem* mPositionXItem;
QTreeWidgetItem* mPositionYItem;
QTreeWidgetItem* mPositionZItem;
QTreeWidgetItem* mRotationItem;
QTreeWidgetItem* mRotationXItem;
QTreeWidgetItem* mRotationYItem;
QTreeWidgetItem* mRotationZItem;
}; };
class lcQPropertiesTreeDelegate : public QItemDelegate class lcQPropertiesTreeDelegate : public QItemDelegate