Changed POV area lights to take the x/y vectors correctly.

This commit is contained in:
Leonardo Zide 2023-10-22 18:48:08 -07:00
parent c2199eb6b0
commit 0a48e30ec0
5 changed files with 13 additions and 74 deletions

View file

@ -33,7 +33,6 @@ lcLight::lcLight(const lcVector3& Position, lcLightType LightType)
mSpotExponent = 10.0f; mSpotExponent = 10.0f;
mPOVRayExponent = 1.0f; mPOVRayExponent = 1.0f;
mSpotCutoff = LightType != lcLightType::Directional ? 40.0f : 0.0f; mSpotCutoff = LightType != lcLightType::Directional ? 40.0f : 0.0f;
mAreaGrid = lcVector2(10.0f, 10.0f);
UpdateLightType(); UpdateLightType();
@ -50,7 +49,6 @@ lcLight::lcLight(const lcVector3& Position, lcLightType LightType)
mLightSpecularKeys.ChangeKey(mLightSpecular, 1, true); mLightSpecularKeys.ChangeKey(mLightSpecular, 1, true);
mSpotCutoffKeys.ChangeKey(mSpotCutoff, 1, true); mSpotCutoffKeys.ChangeKey(mSpotCutoff, 1, true);
mSpotExponentKeys.ChangeKey(mSpotExponent, 1, true); mSpotExponentKeys.ChangeKey(mSpotExponent, 1, true);
mAreaGridKeys.ChangeKey(mAreaGrid, 1, true);
UpdatePosition(1); UpdatePosition(1);
} }
@ -190,11 +188,7 @@ void lcLight::SaveLDraw(QTextStream& Stream) const
break; break;
case lcLightType::Area: case lcLightType::Area:
if (mPOVRayLight)
SaveAttribute(Stream, mAreaGrid, mAreaGridKeys, "LIGHT", "AREA_GRID");
Stream << QLatin1String("0 !LEOCAD LIGHT AREA_SHAPE ") << gLightAreaShapes[static_cast<int>(mAreaShape)] << LineEnding; Stream << QLatin1String("0 !LEOCAD LIGHT AREA_SHAPE ") << gLightAreaShapes[static_cast<int>(mAreaShape)] << LineEnding;
break; break;
} }
@ -344,18 +338,6 @@ bool lcLight::ParseLDrawLine(QTextStream& Stream)
// mSpotExponentKeys.ChangeKey(mSpotExponent, 1, true); // mSpotExponentKeys.ChangeKey(mSpotExponent, 1, true);
// } // }
// } // }
else if (Token == QLatin1String("AREA_ROWS"))
{
mPOVRayLight = true;
Stream >> mAreaGrid[0];
mAreaGridKeys.ChangeKey(mAreaGrid, 1, true);
}
else if (Token == QLatin1String("AREA_COLUMNS"))
{
mPOVRayLight = true;
Stream >> mAreaGrid[1];
mAreaGridKeys.ChangeKey(mAreaGrid, 1, true);
}
else if (Token == QLatin1String("DIFFUSE")) else if (Token == QLatin1String("DIFFUSE"))
{ {
Stream >>mLightDiffuse; Stream >>mLightDiffuse;
@ -396,8 +378,6 @@ bool lcLight::ParseLDrawLine(QTextStream& Stream)
} }
else if ((Token == QLatin1String("POWER_KEY")) || (Token == QLatin1String("STRENGTH_KEY"))) else if ((Token == QLatin1String("POWER_KEY")) || (Token == QLatin1String("STRENGTH_KEY")))
mSpotExponentKeys.LoadKeysLDraw(Stream); mSpotExponentKeys.LoadKeysLDraw(Stream);
else if (Token == QLatin1String("AREA_GRID_KEY"))
mAreaGridKeys.LoadKeysLDraw(Stream);
else if (Token == QLatin1String("DIFFUSE_KEY")) else if (Token == QLatin1String("DIFFUSE_KEY"))
mLightDiffuseKeys.LoadKeysLDraw(Stream); mLightDiffuseKeys.LoadKeysLDraw(Stream);
else if (Token == QLatin1String("SPECULAR_KEY")) else if (Token == QLatin1String("SPECULAR_KEY"))
@ -470,10 +450,6 @@ void lcLight::UpdateLight(lcStep Step, lcLightProperties Props, int Property)
mSpotExponentKeys.ChangeKey(mSpotExponent, Step, false); mSpotExponentKeys.ChangeKey(mSpotExponent, Step, false);
} }
break; break;
case LC_LIGHT_AREA_GRID:
mAreaGrid = Props.mAreaGrid;
mAreaGridKeys.ChangeKey(mAreaGrid, Step, false);
break;
case LC_LIGHT_CUTOFF: case LC_LIGHT_CUTOFF:
mSpotCutoff = Props.mSpotCutoff; mSpotCutoff = Props.mSpotCutoff;
mSpotCutoffKeys.ChangeKey(mSpotCutoff, Step, false); mSpotCutoffKeys.ChangeKey(mSpotCutoff, Step, false);
@ -754,7 +730,6 @@ void lcLight::InsertTime(lcStep Start, lcStep Time)
mLightSpecularKeys.InsertTime(Start, Time); mLightSpecularKeys.InsertTime(Start, Time);
mSpotCutoffKeys.InsertTime(Start, Time); mSpotCutoffKeys.InsertTime(Start, Time);
mSpotExponentKeys.InsertTime(Start, Time); mSpotExponentKeys.InsertTime(Start, Time);
mAreaGridKeys.InsertTime(Start, Time);
} }
void lcLight::RemoveTime(lcStep Start, lcStep Time) void lcLight::RemoveTime(lcStep Start, lcStep Time)
@ -773,7 +748,6 @@ void lcLight::RemoveTime(lcStep Start, lcStep Time)
mLightSpecularKeys.RemoveTime(Start, Time); mLightSpecularKeys.RemoveTime(Start, Time);
mSpotCutoffKeys.RemoveTime(Start, Time); mSpotCutoffKeys.RemoveTime(Start, Time);
mSpotExponentKeys.RemoveTime(Start, Time); mSpotExponentKeys.RemoveTime(Start, Time);
mAreaGridKeys.RemoveTime(Start, Time);
} }
void lcLight::UpdatePosition(lcStep Step) void lcLight::UpdatePosition(lcStep Step)
@ -803,7 +777,6 @@ void lcLight::UpdatePosition(lcStep Step)
mLightSpecular = mLightSpecularKeys.CalculateKey(Step); mLightSpecular = mLightSpecularKeys.CalculateKey(Step);
mSpotCutoff = mSpotCutoffKeys.CalculateKey(Step); mSpotCutoff = mSpotCutoffKeys.CalculateKey(Step);
mSpotExponent = mSpotExponentKeys.CalculateKey(Step); mSpotExponent = mSpotExponentKeys.CalculateKey(Step);
mAreaGrid = mAreaGridKeys.CalculateKey(Step);
} }
void lcLight::DrawInterface(lcContext* Context, const lcScene& Scene) const void lcLight::DrawInterface(lcContext* Context, const lcScene& Scene) const
@ -1254,9 +1227,6 @@ void lcLight::RemoveKeyFrames()
mSpotExponentKeys.RemoveAll(); mSpotExponentKeys.RemoveAll();
mSpotExponentKeys.ChangeKey(mSpotExponent, 1, true); mSpotExponentKeys.ChangeKey(mSpotExponent, 1, true);
mAreaGridKeys.RemoveAll();
mAreaGridKeys.ChangeKey(mAreaGrid, 1, true);
} }
bool lcLight::Setup(int LightIndex) bool lcLight::Setup(int LightIndex)

View file

@ -36,7 +36,6 @@ enum lcLightProperty
LC_LIGHT_DIFFUSE, LC_LIGHT_DIFFUSE,
LC_LIGHT_SPECULAR, LC_LIGHT_SPECULAR,
LC_LIGHT_EXPONENT, LC_LIGHT_EXPONENT,
LC_LIGHT_AREA_GRID,
LC_LIGHT_CUTOFF, LC_LIGHT_CUTOFF,
LC_LIGHT_USE_CUTOFF, LC_LIGHT_USE_CUTOFF,
LC_LIGHT_POVRAY LC_LIGHT_POVRAY
@ -44,7 +43,6 @@ enum lcLightProperty
struct lcLightProperties struct lcLightProperties
{ {
lcVector2 mAreaGrid;
float mLightDiffuse; float mLightDiffuse;
float mLightSpecular; float mLightSpecular;
float mSpotExponent; float mSpotExponent;
@ -221,6 +219,11 @@ public:
return -lcVector3(mWorldMatrix[2]); return -lcVector3(mWorldMatrix[2]);
} }
const lcMatrix44& GetWorldMatrix() const
{
return mWorldMatrix;
}
void SaveLDraw(QTextStream& Stream) const; void SaveLDraw(QTextStream& Stream) const;
bool ParseLDrawLine(QTextStream& Stream); bool ParseLDrawLine(QTextStream& Stream);
@ -321,14 +324,12 @@ public:
props.mSpotCutoff = mSpotCutoff; props.mSpotCutoff = mSpotCutoff;
props.mPOVRayLight = mPOVRayLight; props.mPOVRayLight = mPOVRayLight;
props.mEnableCutoff = mEnableCutoff; props.mEnableCutoff = mEnableCutoff;
props.mAreaGrid = mAreaGrid;
return props; return props;
} }
lcMatrix44 mWorldMatrix; lcMatrix44 mWorldMatrix;
lcVector3 mAttenuation; lcVector3 mAttenuation;
lcVector2 mAreaGrid;
bool mSpotBlendSet; bool mSpotBlendSet;
bool mSpotCutoffSet; bool mSpotCutoffSet;
bool mEnableCutoff; bool mEnableCutoff;
@ -379,7 +380,6 @@ protected:
lcObjectKeyArray<float> mSpotTightnessKeys; lcObjectKeyArray<float> mSpotTightnessKeys;
lcObjectKeyArray<lcVector3> mAttenuationKeys; lcObjectKeyArray<lcVector3> mAttenuationKeys;
lcObjectKeyArray<lcVector2> mAreaGridKeys;
lcObjectKeyArray<float> mLightSpecularKeys; lcObjectKeyArray<float> mLightSpecularKeys;
lcObjectKeyArray<float> mLightDiffuseKeys; lcObjectKeyArray<float> mLightDiffuseKeys;
lcObjectKeyArray<float> mSpotCutoffKeys; lcObjectKeyArray<float> mSpotCutoffKeys;

View file

@ -2139,7 +2139,8 @@ bool Project::ExportPOVRay(const QString& FileName)
(CameraName.isEmpty() ? "Camera" : CameraName.toLatin1().constData())); (CameraName.isEmpty() ? "Camera" : CameraName.toLatin1().constData()));
POVFile.WriteLine(Line); POVFile.WriteLine(Line);
lcVector2 AreaSize(200.0f, 200.0f), AreaGrid(10.0f, 10.0f); lcVector3 AreaX(1.0f, 0.0f, 0.0f), AreaY(0.0f, 1.0f, 0.0f);
lcVector2 AreaSize(200.0f, 200.0f);
int AreaCircle = 0, Shadowless = 0; int AreaCircle = 0, Shadowless = 0;
lcLightType LightType = lcLightType::Area; lcLightType LightType = lcLightType::Area;
float Power = 0, SpotRadius = 0, SpotFalloff = 0, SpotTightness = 0; float Power = 0, SpotRadius = 0, SpotFalloff = 0, SpotTightness = 0;
@ -2157,7 +2158,7 @@ bool Project::ExportPOVRay(const QString& FileName)
for (int Idx = 0; Idx < 4; Idx++) for (int Idx = 0; Idx < 4; Idx++)
{ {
Power = Idx < 2 ? 0.75f : 0.5f; Power = Idx < 2 ? 0.75f : 0.5f;
sprintf(Line,"#ifndef (SkipLight%i)\nWriteLight(%i, %i, <%g, %g, %g>, <%g, %g, %g>, <%g, %g, %g>, %g, %g, %g, %g, %i, %i, %i, %i, %i)\n#end\n\n", sprintf(Line,"#ifndef (SkipLight%i)\nWriteLight(%i, %i, <%g, %g, %g>, <%g, %g, %g>, <%g, %g, %g>, %g, %g, %g, %g, %i, <%g, %g, %g>, <%g, %g, %g>, %i, %i)\n#end\n\n",
Idx, Idx,
LightType, LightType,
Shadowless, Shadowless,
@ -2166,7 +2167,7 @@ bool Project::ExportPOVRay(const QString& FileName)
LightColor[0], LightColor[1], LightColor[2], LightColor[0], LightColor[1], LightColor[2],
Power, Power,
SpotRadius, SpotFalloff, SpotTightness, SpotRadius, SpotFalloff, SpotTightness,
AreaCircle, (int)AreaSize[0], (int)AreaSize[1], (int)AreaGrid[0], (int)AreaGrid[1]); AreaCircle, AreaX[0], AreaX[1], AreaX[2], AreaY[0], AreaY[1], AreaY[2], (int)AreaSize[0], (int)AreaSize[1]);
POVFile.WriteLine(Line); POVFile.WriteLine(Line);
} }
} }
@ -2198,14 +2199,15 @@ bool Project::ExportPOVRay(const QString& FileName)
case lcLightType::Area: case lcLightType::Area:
AreaCircle = (Light->GetAreaShape() == lcLightAreaShape::Disk || Light->GetAreaShape() == lcLightAreaShape::Ellipse) ? 1 : 0; AreaCircle = (Light->GetAreaShape() == lcLightAreaShape::Disk || Light->GetAreaShape() == lcLightAreaShape::Ellipse) ? 1 : 0;
AreaSize = Light->GetSize(); AreaSize = Light->GetSize();
AreaGrid = Light->mAreaGrid; AreaX = lcVector3(Light->GetWorldMatrix()[0]);
AreaY = lcVector3(Light->GetWorldMatrix()[1]);
break; break;
case lcLightType::Count: case lcLightType::Count:
break; break;
} }
sprintf(Line,"#ifndef (Skip%s)\n WriteLight(%i, %i, <%g, %g, %g>, <%g, %g, %g>, <%g, %g, %g>, %g, %g, %g, %g, %i, %i, %i, %i, %i)\n#end\n\n", sprintf(Line,"#ifndef (Skip%s)\n WriteLight(%i, %i, <%g, %g, %g>, <%g, %g, %g>, <%g, %g, %g>, %g, %g, %g, %g, %i, <%g, %g, %g>, <%g, %g, %g>, %i, %i)\n#end\n\n",
LightName.toLatin1().constData(), LightName.toLatin1().constData(),
LightType, LightType,
Shadowless, Shadowless,
@ -2214,7 +2216,7 @@ bool Project::ExportPOVRay(const QString& FileName)
LightColor[0], LightColor[1], LightColor[2], LightColor[0], LightColor[1], LightColor[2],
Power, Power,
SpotRadius, SpotFalloff, SpotTightness, SpotRadius, SpotFalloff, SpotTightness,
AreaCircle, (int)AreaSize[0], (int)AreaSize[1], (int)AreaGrid[0], (int)AreaGrid[1]); AreaCircle, AreaX[0], AreaX[1], AreaX[2], AreaY[0], AreaY[1], AreaY[2], (int)AreaSize[0], (int)AreaSize[1]);
POVFile.WriteLine(Line); POVFile.WriteLine(Line);
} }
} }

View file

@ -886,16 +886,6 @@ void lcQPropertiesTree::slotReturnPressed()
Model->UpdateLight(Light, Props, LC_LIGHT_CUTOFF); Model->UpdateLight(Light, Props, LC_LIGHT_CUTOFF);
} }
else if (Item == lightAreaGridRows || Item == lightAreaGridColumns)
{
float Value = lcParseValueLocalized(Editor->text());
if (Item == lightAreaGridRows)
Props.mAreaGrid[0] = Value;
else if (Item == lightAreaGridColumns)
Props.mAreaGrid[1] = Value;
Model->UpdateLight(Light, Props, LC_LIGHT_AREA_GRID);
}
else if (Item == mLightNameItem) else if (Item == mLightNameItem)
{ {
QString Value = Editor->text(); QString Value = Editor->text();
@ -1114,8 +1104,6 @@ void lcQPropertiesTree::SetEmpty()
mLightSizeYItem = nullptr; mLightSizeYItem = nullptr;
lightFormat = nullptr; lightFormat = nullptr;
mLightCastShadowItem = nullptr; mLightCastShadowItem = nullptr;
lightAreaGridRows = nullptr;
lightAreaGridColumns = nullptr;
mPositionItem = nullptr; mPositionItem = nullptr;
mPositionXItem = nullptr; mPositionXItem = nullptr;
@ -1379,7 +1367,6 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
lcVector3 Position(0.0f, 0.0f, 0.0f); lcVector3 Position(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);
if (Light) if (Light)
{ {
@ -1440,7 +1427,6 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
Cutoff = Light->mSpotCutoff; Cutoff = Light->mSpotCutoff;
EnableCutoff = Light->mEnableCutoff; EnableCutoff = Light->mEnableCutoff;
SpotTightness = Light->GetSpotTightness(); SpotTightness = Light->GetSpotTightness();
AreaGrid = Light->mAreaGrid;
} }
if (mWidgetMode != LC_PROPERTY_WIDGET_LIGHT || mLightType != LightType || mPOVRayLight != POVRayLight) if (mWidgetMode != LC_PROPERTY_WIDGET_LIGHT || mLightType != LightType || mPOVRayLight != POVRayLight)
@ -1512,12 +1498,6 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
case lcLightAreaShape::Count: case lcLightAreaShape::Count:
break; break;
} }
if (POVRayLight)
{
lightAreaGridRows = addProperty(mLightAttributesItem, tr("Grid Rows"), PropertyFloat);
lightAreaGridColumns = addProperty(mLightAttributesItem, tr("Grid Columns"), PropertyFloat);
}
break; break;
case lcLightType::Count: case lcLightType::Count:
@ -1650,17 +1630,6 @@ void lcQPropertiesTree::SetLight(lcObject* Focus)
case lcLightType::Area: case lcLightType::Area:
mLightAreaShapeItem->setText(1, lcLight::GetAreaShapeString(LightAreaShape)); mLightAreaShapeItem->setText(1, lcLight::GetAreaShapeString(LightAreaShape));
mLightAreaShapeItem->setData(0, PropertyValueRole, static_cast<int>(LightAreaShape)); mLightAreaShapeItem->setData(0, PropertyValueRole, static_cast<int>(LightAreaShape));
if (POVRayLight)
{
lightAreaGridRows->setText(1, lcFormatValueLocalized(AreaGrid[0]));
lightAreaGridRows->setData(0, PropertyValueRole, AreaGrid[0]);
lightAreaGridRows->setToolTip(1, tr("The number of sample rows in the area light."));
lightAreaGridColumns->setText(1, lcFormatValueLocalized(AreaGrid[1]));
lightAreaGridColumns->setData(0, PropertyValueRole, AreaGrid[1]);
lightAreaGridColumns->setToolTip(1, tr("The number of sample columns in the area light."));
}
break; break;
case lcLightType::Count: case lcLightType::Count:

View file

@ -133,8 +133,6 @@ protected:
QTreeWidgetItem* mLightNameItem; QTreeWidgetItem* mLightNameItem;
QTreeWidgetItem* lightFormat; QTreeWidgetItem* lightFormat;
QTreeWidgetItem* mLightCastShadowItem; QTreeWidgetItem* mLightCastShadowItem;
QTreeWidgetItem* lightAreaGridRows;
QTreeWidgetItem* lightAreaGridColumns;
QTreeWidgetItem* mPositionItem; QTreeWidgetItem* mPositionItem;
QTreeWidgetItem* mPositionXItem; QTreeWidgetItem* mPositionXItem;