From 96523c39b9324e7b324126d7360cb4394a244854 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sun, 1 Oct 2023 12:49:35 -0700 Subject: [PATCH] Show light rotation in properties. --- qt/lc_qpropertiestree.cpp | 257 ++++++++++++++++---------------------- qt/lc_qpropertiestree.h | 26 ++-- 2 files changed, 119 insertions(+), 164 deletions(-) diff --git a/qt/lc_qpropertiestree.cpp b/qt/lc_qpropertiestree.cpp index 643d869e..a648a179 100644 --- a/qt/lc_qpropertiestree.cpp +++ b/qt/lc_qpropertiestree.cpp @@ -667,50 +667,54 @@ void lcQPropertiesTree::slotReturnPressed() QTreeWidgetItem* Item = mDelegate->editedItem(); 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) { - lcPiece* Piece = (mFocus && mFocus->IsPiece()) ? (lcPiece*)mFocus : nullptr; - - 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) + if (Item == partShow) { bool Ok = false; lcStep Step = Editor->text().toUInt(&Ok); @@ -819,49 +823,11 @@ void lcQPropertiesTree::slotReturnPressed() } else if (mWidgetMode == LC_PROPERTY_WIDGET_LIGHT) { - lcLight* Light = (mFocus && mFocus->IsLight()) ? (lcLight*)mFocus : nullptr; - if (Light) { lcLightProperties Props = Light->GetLightProperties(); - QString Name = Light->GetName(); - - 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) + if (Item == mLightSpotConeAngleItem) { float Value = lcParseValueLocalized(Editor->text()); @@ -1103,14 +1069,6 @@ void lcQPropertiesTree::SetEmpty() clear(); mPieceAttributesItem = nullptr; - partPosition = nullptr; - partPositionX = nullptr; - partPositionY = nullptr; - partPositionZ = nullptr; - partRotation = nullptr; - partRotationX = nullptr; - partRotationY = nullptr; - partRotationZ = nullptr; partVisibility = nullptr; partShow = nullptr; partHide = nullptr; @@ -1138,14 +1096,6 @@ void lcQPropertiesTree::SetEmpty() mCameraNameItem = nullptr; lightConfiguration = nullptr; - lightPosition = nullptr; - lightPositionX = nullptr; - lightPositionY = nullptr; - lightPositionZ = nullptr; - lightTarget = nullptr; - lightTargetX = nullptr; - lightTargetY = nullptr; - lightTargetZ = nullptr; mLightColorItem = nullptr; mLightAttributesItem = nullptr; lightDiffuse = nullptr; @@ -1166,6 +1116,15 @@ void lcQPropertiesTree::SetEmpty() lightAreaGridRows = nullptr; lightAreaGridColumns = nullptr; + mPositionItem = nullptr; + mPositionXItem = nullptr; + mPositionYItem = nullptr; + mPositionZItem = nullptr; + mRotationItem = nullptr; + mRotationXItem = nullptr; + mRotationYItem = nullptr; + mRotationZItem = nullptr; + mWidgetMode = LC_PROPERTY_WIDGET_EMPTY; mFocus = nullptr; } @@ -1184,15 +1143,15 @@ void lcQPropertiesTree::SetPiece(const lcArray& Selection, lcObject* partShow = addProperty(partVisibility, tr("Show"), PropertyStep); partHide = addProperty(partVisibility, tr("Hide"), PropertyStep); - partPosition = addProperty(nullptr, tr("Position"), PropertyGroup); - partPositionX = addProperty(partPosition, tr("X"), PropertyFloat); - partPositionY = addProperty(partPosition, tr("Y"), PropertyFloat); - partPositionZ = addProperty(partPosition, tr("Z"), PropertyFloat); + mPositionItem = addProperty(nullptr, tr("Position"), PropertyGroup); + mPositionXItem = addProperty(mPositionItem, tr("X"), PropertyFloat); + mPositionYItem = addProperty(mPositionItem, tr("Y"), PropertyFloat); + mPositionZItem = addProperty(mPositionItem, tr("Z"), PropertyFloat); - partRotation = addProperty(nullptr, tr("Rotation"), PropertyGroup); - partRotationX = addProperty(partRotation, tr("X"), PropertyFloat); - partRotationY = addProperty(partRotation, tr("Y"), PropertyFloat); - partRotationZ = addProperty(partRotation, tr("Z"), PropertyFloat); + mRotationItem = addProperty(nullptr, tr("Rotation"), PropertyGroup); + mRotationXItem = addProperty(mRotationItem, tr("X"), PropertyFloat); + mRotationYItem = addProperty(mRotationItem, tr("Y"), PropertyFloat); + mRotationZItem = addProperty(mRotationItem, tr("Z"), PropertyFloat); mWidgetMode = LC_PROPERTY_WIDGET_PIECE; } @@ -1203,25 +1162,29 @@ void lcQPropertiesTree::SetPiece(const lcArray& Selection, lcObject* lcVector3 Position; lcMatrix33 RelativeRotation; + Model->GetMoveRotateTransform(Position, RelativeRotation); - partPositionX->setText(1, lcFormatValueLocalized(Position[0])); - partPositionX->setData(0, PropertyValueRole, Position[0]); - partPositionY->setText(1, lcFormatValueLocalized(Position[1])); - partPositionY->setData(0, PropertyValueRole, Position[1]); - partPositionZ->setText(1, lcFormatValueLocalized(Position[2])); - partPositionZ->setData(0, PropertyValueRole, Position[2]); + + mPositionXItem->setText(1, lcFormatValueLocalized(Position[0])); + mPositionXItem->setData(0, PropertyValueRole, Position[0]); + mPositionYItem->setText(1, lcFormatValueLocalized(Position[1])); + mPositionYItem->setData(0, PropertyValueRole, Position[1]); + mPositionZItem->setText(1, lcFormatValueLocalized(Position[2])); + mPositionZItem->setData(0, PropertyValueRole, Position[2]); lcVector3 Rotation; + if (Piece) Rotation = lcMatrix44ToEulerAngles(Piece->mModelWorld) * LC_RTOD; else Rotation = lcVector3(0.0f, 0.0f, 0.0f); - partRotationX->setText(1, lcFormatValueLocalized(Rotation[0])); - partRotationX->setData(0, PropertyValueRole, Rotation[0]); - partRotationY->setText(1, lcFormatValueLocalized(Rotation[1])); - partRotationY->setData(0, PropertyValueRole, Rotation[1]); - partRotationZ->setText(1, lcFormatValueLocalized(Rotation[2])); - partRotationZ->setData(0, PropertyValueRole, Rotation[2]); + + 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]); lcStep Show = 0; lcStep Hide = 0; @@ -1411,9 +1374,7 @@ void lcQPropertiesTree::SetLight(lcObject* Focus) bool EnableCutoff = false; bool POVRayLight = false; bool CastShadow = true; - PropertyType TargetProperty = PropertyFloat; lcVector3 Position(0.0f, 0.0f, 0.0f); - lcVector3 Target(0.0f, 0.0f, 0.0f); QColor Color(Qt::white); float SpotConeAngle = 0.0f, SpotPenumbraAngle = 0.0f, SpotTightness = 0.0f; lcVector2 AreaGrid(0.0f, 0.0f); @@ -1428,7 +1389,6 @@ void lcQPropertiesTree::SetLight(lcObject* Focus) CastShadow = Light->GetCastShadow(); Position = Light->GetPosition(); -// Target = Light->mTargetPosition; Color = lcQColorFromVector3(Light->GetColor()); SpotConeAngle = Light->GetSpotConeAngle(); SpotPenumbraAngle = Light->GetSpotPenumbraAngle(); @@ -1477,12 +1437,11 @@ void lcQPropertiesTree::SetLight(lcObject* Focus) ExponentLabel = LightType == lcLightType::Directional ? tr("Strength") : tr("Power"); Cutoff = Light->mSpotCutoff; EnableCutoff = Light->mEnableCutoff; - TargetProperty = LightType != lcLightType::Point ? PropertyFloat : PropertyFloatReadOnly; SpotTightness = Light->GetSpotTightness(); 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(); @@ -1575,44 +1534,48 @@ void lcQPropertiesTree::SetLight(lcObject* Focus) lightConfiguration = addProperty(nullptr, tr("Configuration"), PropertyGroup); lightFormat = addProperty(lightConfiguration, tr("Format"), PropertyLightFormat); - // Position - lightPosition = addProperty(nullptr, tr("Position"), PropertyGroup); - lightPositionX = addProperty(lightPosition, tr("X"), PropertyFloat); - lightPositionY = addProperty(lightPosition, tr("Y"), PropertyFloat); - lightPositionZ = addProperty(lightPosition, tr("Z"), PropertyFloat); + mPositionItem = addProperty(nullptr, tr("Position"), PropertyGroup); + mPositionXItem = addProperty(mPositionItem, tr("X"), PropertyFloat); + mPositionYItem = addProperty(mPositionItem, tr("Y"), PropertyFloat); + mPositionZItem = addProperty(mPositionItem, tr("Z"), PropertyFloat); - // Target Position - if (LightType != lcLightType::Point && !(LightType == lcLightType::Area && POVRayLight)) + if (LightType != lcLightType::Point) { - lightTarget = addProperty(nullptr, tr("Target"), PropertyGroup); - lightTargetX = addProperty(lightTarget, tr("X"), TargetProperty); - lightTargetY = addProperty(lightTarget, tr("Y"), TargetProperty); - lightTargetZ = addProperty(lightTarget, tr("Z"), TargetProperty); + mRotationItem = addProperty(nullptr, tr("Rotation"), PropertyGroup); + mRotationXItem = addProperty(mRotationItem, tr("X"), PropertyFloat); + mRotationYItem = addProperty(mRotationItem, tr("Y"), PropertyFloat); + mRotationZItem = addProperty(mRotationItem, tr("Z"), PropertyFloat); } mWidgetMode = LC_PROPERTY_WIDGET_LIGHT; mLightType = LightType; - mLightAreaShape = LightAreaShape; mPOVRayLight = POVRayLight; } mFocus = Light; - lightPositionX->setText(1, lcFormatValueLocalized(Position[0])); - lightPositionX->setData(0, PropertyValueRole, Position[0]); - lightPositionY->setText(1, lcFormatValueLocalized(Position[1])); - lightPositionY->setData(0, PropertyValueRole, Position[1]); - lightPositionZ->setText(1, lcFormatValueLocalized(Position[2])); - lightPositionZ->setData(0, PropertyValueRole, Position[2]); + mPositionXItem->setText(1, lcFormatValueLocalized(Position[0])); + mPositionXItem->setData(0, PropertyValueRole, Position[0]); + mPositionYItem->setText(1, lcFormatValueLocalized(Position[1])); + mPositionYItem->setData(0, PropertyValueRole, Position[1]); + mPositionZItem->setText(1, lcFormatValueLocalized(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])); - lightTargetX->setData(0, PropertyValueRole, Target[0]); - lightTargetY->setText(1, lcFormatValueLocalized(Target[1])); - lightTargetY->setData(0, PropertyValueRole, Target[1]); - lightTargetZ->setText(1, lcFormatValueLocalized(Target[2])); - lightTargetZ->setData(0, PropertyValueRole, Target[2]); + lcVector3 Rotation; + + if (Light) + Rotation = lcMatrix44ToEulerAngles(Light->mWorldMatrix) * LC_RTOD; + else + 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); diff --git a/qt/lc_qpropertiestree.h b/qt/lc_qpropertiestree.h index 1c7428dd..e63d6474 100644 --- a/qt/lc_qpropertiestree.h +++ b/qt/lc_qpropertiestree.h @@ -78,7 +78,6 @@ protected: void SetMultiple(); lcLightType mLightType; - lcLightAreaShape mLightAreaShape; bool mPOVRayLight; lcPropertyWidgetMode mWidgetMode; @@ -90,14 +89,6 @@ protected: QIcon m_uncheckedIcon; QTreeWidgetItem* mPieceAttributesItem; - QTreeWidgetItem* partPosition; - QTreeWidgetItem* partPositionX; - QTreeWidgetItem* partPositionY; - QTreeWidgetItem* partPositionZ; - QTreeWidgetItem* partRotation; - QTreeWidgetItem* partRotationX; - QTreeWidgetItem* partRotationY; - QTreeWidgetItem* partRotationZ; QTreeWidgetItem* partVisibility; QTreeWidgetItem* partShow; QTreeWidgetItem* partHide; @@ -125,14 +116,6 @@ protected: QTreeWidgetItem* mCameraNameItem; QTreeWidgetItem* lightConfiguration; - QTreeWidgetItem* lightPosition; - QTreeWidgetItem* lightPositionX; - QTreeWidgetItem* lightPositionY; - QTreeWidgetItem* lightPositionZ; - QTreeWidgetItem* lightTarget; - QTreeWidgetItem* lightTargetX; - QTreeWidgetItem* lightTargetY; - QTreeWidgetItem* lightTargetZ; QTreeWidgetItem* mLightColorItem; QTreeWidgetItem* mLightAttributesItem; QTreeWidgetItem* lightDiffuse; @@ -152,6 +135,15 @@ protected: QTreeWidgetItem* mLightCastShadowItem; QTreeWidgetItem* lightAreaGridRows; QTreeWidgetItem* lightAreaGridColumns; + + QTreeWidgetItem* mPositionItem; + QTreeWidgetItem* mPositionXItem; + QTreeWidgetItem* mPositionYItem; + QTreeWidgetItem* mPositionZItem; + QTreeWidgetItem* mRotationItem; + QTreeWidgetItem* mRotationXItem; + QTreeWidgetItem* mRotationYItem; + QTreeWidgetItem* mRotationZItem; }; class lcQPropertiesTreeDelegate : public QItemDelegate