POVRay lights - lcLight

This commit is contained in:
Trevor SANDY 2023-08-07 13:22:59 +02:00
parent 415354bfe8
commit 201d7e870c
2 changed files with 279 additions and 56 deletions

View file

@ -50,6 +50,8 @@ void lcLight::Initialize(const lcVector3& Position, const lcVector3& TargetPosit
{ {
SetLightState(LightType); SetLightState(LightType);
mPOVRayLight = false;
mShadowless = false;
mEnableCutoff = false; mEnableCutoff = false;
mPosition = Position; mPosition = Position;
mTargetPosition = TargetPosition; mTargetPosition = TargetPosition;
@ -57,15 +59,21 @@ void lcLight::Initialize(const lcVector3& Position, const lcVector3& TargetPosit
mDiffuseColor = lcVector4(0.8f, 0.8f, 0.8f, 1.0f); mDiffuseColor = lcVector4(0.8f, 0.8f, 0.8f, 1.0f);
mSpecularColor = lcVector4(1.0f, 1.0f, 1.0f, 1.0f); mSpecularColor = lcVector4(1.0f, 1.0f, 1.0f, 1.0f);
mAttenuation = lcVector3(1.0f, 0.0f, 0.0f); mAttenuation = lcVector3(1.0f, 0.0f, 0.0f);
mLightColor = lcVector3(1.0f, 1.0f, 1.0f); //RGB - White mLightColor = lcVector3(1.0f, 1.0f, 1.0f); /*RGB - White*/
mLightType = LightType ? LightType : int(LC_POINTLIGHT); mLightType = LightType ? LightType : int(LC_POINTLIGHT);
mLightFactor[0] = LightType ? LightType == LC_SUNLIGHT ? 11.4f : 0.25f : 0.0f; mLightFactor[0] = LightType ? LightType == LC_SUNLIGHT ? 11.4f : 0.25f : 0.0f;
mLightFactor[1] = LightType == LC_AREALIGHT ? 0.25f : LightType == LC_SPOTLIGHT ? 0.150f : 0.0f; mLightFactor[1] = LightType == LC_AREALIGHT ? 0.25f : LightType == LC_SPOTLIGHT ? 0.150f : 0.0f;
mLightDiffuse = 1.0f;
mLightSpecular = 1.0f; mLightSpecular = 1.0f;
mSpotExponent = 10.0f;
mPOVRayExponent = 1.0f;
mSpotSize = 75.0f; mSpotSize = 75.0f;
mLightShape = 0 /*Square*/;
mSpotCutoff = LightType ? LightType != LC_SUNLIGHT ? 40.0f : 0.0f : 30.0f; mSpotCutoff = LightType ? LightType != LC_SUNLIGHT ? 40.0f : 0.0f : 30.0f;
mSpotExponent = 10.0f; /*Energy/Power*/ mSpotFalloff = 45.0f;
mSpotTightness = 0;
mAreaGrid = lcVector2(10.0f, 10.0f);
mAreaSize = lcVector2(200.0f, 200.0f);
mLightShape = LC_LIGHT_SHAPE_SQUARE;
mPositionKeys.ChangeKey(mPosition, 1, true); mPositionKeys.ChangeKey(mPosition, 1, true);
mTargetPositionKeys.ChangeKey(mTargetPosition, 1, true); mTargetPositionKeys.ChangeKey(mTargetPosition, 1, true);
@ -77,10 +85,14 @@ void lcLight::Initialize(const lcVector3& Position, const lcVector3& TargetPosit
mLightColorKeys.ChangeKey(mLightColor, 1, true); mLightColorKeys.ChangeKey(mLightColor, 1, true);
mLightTypeKeys.ChangeKey(mLightType, 1, true); mLightTypeKeys.ChangeKey(mLightType, 1, true);
mLightFactorKeys.ChangeKey(mLightFactor, 1, true); mLightFactorKeys.ChangeKey(mLightFactor, 1, true);
mLightDiffuseKeys.ChangeKey(mLightDiffuse, 1, true);
mLightSpecularKeys.ChangeKey(mLightSpecular, 1, true); mLightSpecularKeys.ChangeKey(mLightSpecular, 1, true);
mSpotCutoffKeys.ChangeKey(mSpotCutoff, 1, true); mSpotCutoffKeys.ChangeKey(mSpotCutoff, 1, true);
mSpotFalloffKeys.ChangeKey(mSpotFalloff, 1, true);
mSpotExponentKeys.ChangeKey(mSpotExponent, 1, true); mSpotExponentKeys.ChangeKey(mSpotExponent, 1, true);
mLightSpotSizeKeys.ChangeKey(mSpotSize, 1, true); mSpotSizeKeys.ChangeKey(mSpotSize, 1, true);
mSpotTightnessKeys.ChangeKey(mSpotTightness, 1, true);
mAreaGridKeys.ChangeKey(mAreaGrid, 1, true);
} }
lcLight::~lcLight() lcLight::~lcLight()
@ -91,46 +103,66 @@ void lcLight::SaveLDraw(QTextStream& Stream) const
{ {
const QLatin1String LineEnding("\r\n"); const QLatin1String LineEnding("\r\n");
if (mPOVRayLight)
Stream << QLatin1String("0 !LEOCAD LIGHT POV_RAY") << LineEnding;
if (mShadowless)
Stream << QLatin1String("0 !LEOCAD LIGHT SHADOWLESS") << LineEnding;
if (mPositionKeys.GetSize() > 1) if (mPositionKeys.GetSize() > 1)
mPositionKeys.SaveKeysLDraw(Stream, "LIGHT POSITION_KEY "); mPositionKeys.SaveKeysLDraw(Stream, "LIGHT POSITION_KEY ");
else else
Stream << QLatin1String("0 !LEOCAD LIGHT POSITION ") << mPosition[0] << ' ' << mPosition[1] << ' ' << mPosition[2] << LineEnding; Stream << QLatin1String("0 !LEOCAD LIGHT POSITION ") << mPosition[0] << ' ' << mPosition[1] << ' ' << mPosition[2] << LineEnding;
if (mTargetPositionKeys.GetSize() > 1) if (mLightType != LC_POINTLIGHT && !(mLightType == LC_AREALIGHT && mPOVRayLight))
mTargetPositionKeys.SaveKeysLDraw(Stream, "LIGHT TARGET_POSITION_KEY "); {
else if (mTargetPositionKeys.GetSize() > 1)
Stream << QLatin1String("0 !LEOCAD LIGHT TARGET_POSITION ") << mTargetPosition[0] << ' ' << mTargetPosition[1] << ' ' << mTargetPosition[2] << LineEnding; mTargetPositionKeys.SaveKeysLDraw(Stream, "LIGHT TARGET_POSITION_KEY ");
else
Stream << QLatin1String("0 !LEOCAD LIGHT TARGET_POSITION ") << mTargetPosition[0] << ' ' << mTargetPosition[1] << ' ' << mTargetPosition[2] << LineEnding;
}
if (mLightColorKeys.GetSize() > 1) if (mLightColorKeys.GetSize() > 1)
mLightColorKeys.SaveKeysLDraw(Stream, "LIGHT COLOR_RGB_KEY "); mLightColorKeys.SaveKeysLDraw(Stream, "LIGHT COLOR_RGB_KEY ");
else else
Stream << QLatin1String("0 !LEOCAD LIGHT COLOR_RGB ") << mLightColor[0] << ' ' << mLightColor[1] << ' ' << mLightColor[2] << LineEnding; Stream << QLatin1String("0 !LEOCAD LIGHT COLOR_RGB ") << mLightColor[0] << ' ' << mLightColor[1] << ' ' << mLightColor[2] << LineEnding;
if (mLightSpecularKeys.GetSize() > 1) if (!mPOVRayLight)
mLightSpecularKeys.SaveKeysLDraw(Stream, "LIGHT SPECULAR_KEY "); {
else if (mLightDiffuseKeys.GetSize() > 1)
Stream << QLatin1String("0 !LEOCAD LIGHT SPECULAR ") << mLightSpecular << LineEnding; mLightDiffuseKeys.SaveKeysLDraw(Stream, "LIGHT DIFFUSE_KEY ");
else
Stream << QLatin1String("0 !LEOCAD LIGHT DIFFUSE ") << mLightDiffuse << LineEnding;
if (mLightSpecularKeys.GetSize() > 1)
mLightSpecularKeys.SaveKeysLDraw(Stream, "LIGHT SPECULAR_KEY ");
else
Stream << QLatin1String("0 !LEOCAD LIGHT SPECULAR ") << mLightSpecular << LineEnding;
}
if (mLightType == LC_SUNLIGHT) if (mLightType == LC_SUNLIGHT)
{ {
if (mSpotExponentKeys.GetSize() > 1) if (mSpotExponentKeys.GetSize() > 1)
mSpotExponentKeys.SaveKeysLDraw(Stream, "LIGHT STRENGTH_KEY "); mSpotExponentKeys.SaveKeysLDraw(Stream, "LIGHT STRENGTH_KEY ");
else else
Stream << QLatin1String("0 !LEOCAD LIGHT STRENGTH ") << mSpotExponent << LineEnding; Stream << QLatin1String("0 !LEOCAD LIGHT STRENGTH ") << (mPOVRayLight ? mPOVRayExponent : mSpotExponent) << LineEnding;
if (mLightFactorKeys.GetSize() > 1) if (!mPOVRayLight)
mLightFactorKeys.SaveKeysLDraw(Stream, "LIGHT ANGLE_KEY "); {
else if (mLightFactorKeys.GetSize() > 1)
Stream << QLatin1String("0 !LEOCAD LIGHT ANGLE ") << mLightFactor[0] << LineEnding; mLightFactorKeys.SaveKeysLDraw(Stream, "LIGHT ANGLE_KEY ");
else
Stream << QLatin1String("0 !LEOCAD LIGHT ANGLE ") << mLightFactor[0] << LineEnding;
}
} }
else else
{ {
if (mSpotExponentKeys.GetSize() > 1) if (mSpotExponentKeys.GetSize() > 1)
mSpotExponentKeys.SaveKeysLDraw(Stream, "LIGHT POWER_KEY "); mSpotExponentKeys.SaveKeysLDraw(Stream, "LIGHT POWER_KEY ");
else else
Stream << QLatin1String("0 !LEOCAD LIGHT POWER ") << mSpotExponent << LineEnding; Stream << QLatin1String("0 !LEOCAD LIGHT POWER ") << (mPOVRayLight ? mPOVRayExponent : mSpotExponent) << LineEnding;
if (mEnableCutoff) if (mEnableCutoff && !mPOVRayLight)
{ {
if (mSpotCutoffKeys.GetSize() > 1) if (mSpotCutoffKeys.GetSize() > 1)
mSpotCutoffKeys.SaveKeysLDraw(Stream, "LIGHT CUTOFF_DISTANCE_KEY "); mSpotCutoffKeys.SaveKeysLDraw(Stream, "LIGHT CUTOFF_DISTANCE_KEY ");
@ -141,33 +173,69 @@ void lcLight::SaveLDraw(QTextStream& Stream) const
switch (mLightType) switch (mLightType)
{ {
case LC_POINTLIGHT: case LC_POINTLIGHT:
if (mLightFactorKeys.GetSize() > 1) if (!mPOVRayLight)
mLightFactorKeys.SaveKeysLDraw(Stream, "LIGHT RADIUS_KEY "); {
else if (mLightFactorKeys.GetSize() > 1)
Stream << QLatin1String("0 !LEOCAD LIGHT RADIUS ") << mLightFactor[0] << LineEnding; mLightFactorKeys.SaveKeysLDraw(Stream, "LIGHT RADIUS_KEY ");
else
Stream << QLatin1String("0 !LEOCAD LIGHT RADIUS ") << mLightFactor[0] << LineEnding;
}
break; break;
case LC_SPOTLIGHT: case LC_SPOTLIGHT:
if (mLightFactorKeys.GetSize() > 1) if (mPOVRayLight)
mLightFactorKeys.SaveKeysLDraw(Stream, "LIGHT RADIUS_AND_SPOT_BLEND_KEY "); {
if (mLightFactorKeys.GetSize() > 1)
mLightFactorKeys.SaveKeysLDraw(Stream, "LIGHT RADIUS_KEY ");
else
Stream << QLatin1String("0 !LEOCAD LIGHT RADIUS ") << (mSpotSize - mSpotFalloff) << LineEnding;
if (mSpotFalloffKeys.GetSize() > 1)
mSpotFalloffKeys.SaveKeysLDraw(Stream, "LIGHT SPOT_FALLOFF_KEY ");
else
Stream << QLatin1String("0 !LEOCAD LIGHT SPOT_FALLOFF ") << mSpotFalloff << LineEnding;
if (mSpotTightnessKeys.GetSize() > 1)
mSpotTightnessKeys.SaveKeysLDraw(Stream, "SPOT_TIGHTNESS_KEY ");
else
Stream << QLatin1String("0 !LEOCAD LIGHT SPOT_TIGHTNESS ") << mSpotTightness << LineEnding;
}
else else
{ {
Stream << QLatin1String("0 !LEOCAD LIGHT RADIUS ") << (mPOVRayLight ? SpotRadius : mLightFactor[0]) << LineEnding; if (mSpotSizeKeys.GetSize() > 1)
Stream << QLatin1String("0 !LEOCAD LIGHT SPOT_BLEND ") << mLightFactor[1] << LineEnding; mSpotSizeKeys.SaveKeysLDraw(Stream, "LIGHT SPOT_SIZE_KEY ");
else
Stream << QLatin1String("0 !LEOCAD LIGHT SPOT_SIZE ") << mSpotSize << LineEnding;
if (mLightFactorKeys.GetSize() > 1)
mLightFactorKeys.SaveKeysLDraw(Stream, "LIGHT RADIUS_AND_SPOT_BLEND_KEY ");
else
{
Stream << QLatin1String("0 !LEOCAD LIGHT RADIUS ") << mLightFactor[0] << LineEnding;
Stream << QLatin1String("0 !LEOCAD LIGHT SPOT_BLEND ") << mLightFactor[1] << LineEnding;
}
} }
if (mLightSpotSizeKeys.GetSize() > 1)
mLightSpotSizeKeys.SaveKeysLDraw(Stream, "LIGHT SPOT_SIZE_KEY ");
else
Stream << QLatin1String("0 !LEOCAD LIGHT SPOT_SIZE ") << mSpotSize << LineEnding;
break; break;
case LC_AREALIGHT: case LC_AREALIGHT:
if (mPOVRayLight)
{
if (mAreaGridKeys.GetSize() > 1)
mAreaGridKeys.SaveKeysLDraw(Stream, "LIGHT AREA_GRID_KEY ");
else
Stream << QLatin1String("0 !LEOCAD LIGHT AREA_ROWS ") << mAreaGrid[0] << QLatin1String(" AREA_COLUMNS ") << mAreaGrid[1] << LineEnding;
}
if (mLightFactorKeys.GetSize() > 1) if (mLightFactorKeys.GetSize() > 1)
mLightFactorKeys.SaveKeysLDraw(Stream, "LIGHT SIZE_KEY "); mLightFactorKeys.SaveKeysLDraw(Stream, "LIGHT SIZE_KEY ");
else else
{ {
if (mLightShape == LC_LIGHT_SHAPE_RECTANGLE || mLightShape == LC_LIGHT_SHAPE_ELLIPSE) if (mPOVRayLight)
Stream << QLatin1String("0 !LEOCAD LIGHT WIDTH ") << mLightFactor[0] << QLatin1String(" HEIGHT ") << mLightFactor[1] << LineEnding; {
Stream << QLatin1String("0 !LEOCAD LIGHT WIDTH ") << mAreaSize[0] << QLatin1String(" HEIGHT ") << mAreaSize[1] << LineEnding;
}
else else
Stream << QLatin1String("0 !LEOCAD LIGHT SIZE ") << mLightFactor[0] << LineEnding; {
if (mLightShape == LC_LIGHT_SHAPE_RECTANGLE || mLightShape == LC_LIGHT_SHAPE_ELLIPSE || mLightFactor[1] > 0)
Stream << QLatin1String("0 !LEOCAD LIGHT WIDTH ") << mLightFactor[0] << QLatin1String(" HEIGHT ") << mLightFactor[1] << LineEnding;
else
Stream << QLatin1String("0 !LEOCAD LIGHT SIZE ") << mLightFactor[0] << LineEnding;
}
} }
if (mLightShapeKeys.GetSize() > 1) if (mLightShapeKeys.GetSize() > 1)
mLightShapeKeys.SaveKeysLDraw(Stream, "LIGHT SHAPE_KEY "); mLightShapeKeys.SaveKeysLDraw(Stream, "LIGHT SHAPE_KEY ");
@ -182,7 +250,7 @@ void lcLight::SaveLDraw(QTextStream& Stream) const
Shape = QLatin1String("Square "); Shape = QLatin1String("Square ");
break; break;
case LC_LIGHT_SHAPE_DISK: case LC_LIGHT_SHAPE_DISK:
Shape = QLatin1String("Disk "); Shape = mPOVRayLight ? QLatin1String("Circle ") : QLatin1String("Disk ");
break; break;
case LC_LIGHT_SHAPE_RECTANGLE: case LC_LIGHT_SHAPE_RECTANGLE:
Shape = QLatin1String("Rectangle "); Shape = QLatin1String("Rectangle ");
@ -279,21 +347,64 @@ bool lcLight::ParseLDrawLine(QTextStream& Stream)
} }
else if (Token == QLatin1String("POWER") || Token == QLatin1String("STRENGTH")) else if (Token == QLatin1String("POWER") || Token == QLatin1String("STRENGTH"))
{ {
Stream >> mSpotExponent; if (mPOVRayLight)
mSpotExponentKeys.ChangeKey(mSpotExponent, 1, true); {
Stream >> mPOVRayExponent;
mSpotExponentKeys.ChangeKey(mPOVRayExponent, 1, true);
}
else
{
Stream >> mSpotExponent;
mSpotExponentKeys.ChangeKey(mSpotExponent, 1, true);
}
} }
else if (Token == QLatin1String("RADIUS") || Token == QLatin1String("SIZE") || Token == QLatin1String("WIDTH") || (mHeightSet = Token == QLatin1String("HEIGHT")) || (mSpotBlendSet = Token == QLatin1String("SPOT_BLEND")) || (mAngleSet = Token == QLatin1String("ANGLE"))) else if (Token == QLatin1String("RADIUS") || Token == QLatin1String("SIZE") || Token == QLatin1String("WIDTH") || (mHeightSet = Token == QLatin1String("HEIGHT")) || (mSpotBlendSet = Token == QLatin1String("SPOT_BLEND")) || (mAngleSet = Token == QLatin1String("ANGLE")))
{ {
if(Token == QLatin1String("HEIGHT") || Token == QLatin1String("SPOT_BLEND")) if (mPOVRayLight)
Stream >> mLightFactor[1]; {
if (Token == QLatin1String("WIDTH"))
Stream >> mAreaSize[0];
else if (Token == QLatin1String("HEIGHT"))
Stream >> mAreaSize[1];
mLightFactorKeys.ChangeKey(mAreaSize, 1, true);
}
else else
Stream >> mLightFactor[0]; {
mLightFactorKeys.ChangeKey(mLightFactor, 1, true); if(Token == QLatin1String("HEIGHT") || Token == QLatin1String("SPOT_BLEND"))
Stream >> mLightFactor[1];
else
Stream >> mLightFactor[0];
mLightFactorKeys.ChangeKey(mLightFactor, 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("SPOT_FALLOFF"))
{
mPOVRayLight = true;
Stream >> mSpotFalloff;
mSpotFalloffKeys.ChangeKey(mSpotFalloff, 1, true);
}
else if (Token == QLatin1String("SPOT_TIGHTNESS"))
{
mPOVRayLight = true;
Stream >> mSpotTightness;
mSpotTightnessKeys.ChangeKey(mSpotTightness, 1, true);
} }
else if (Token == QLatin1String("SPOT_SIZE")) else if (Token == QLatin1String("SPOT_SIZE"))
{ {
Stream >> mSpotSize; Stream >> mSpotSize;
mLightSpotSizeKeys.ChangeKey(mSpotSize, 1, true); mSpotSizeKeys.ChangeKey(mSpotSize, 1, true);
} }
else if (Token == QLatin1String("SHAPE")) else if (Token == QLatin1String("SHAPE"))
{ {
@ -310,6 +421,11 @@ bool lcLight::ParseLDrawLine(QTextStream& Stream)
mLightShape = LC_LIGHT_SHAPE_ELLIPSE; mLightShape = LC_LIGHT_SHAPE_ELLIPSE;
mLightShapeKeys.ChangeKey(mLightShape, 1, true); mLightShapeKeys.ChangeKey(mLightShape, 1, true);
} }
else if (Token == QLatin1String("DIFFUSE"))
{
Stream >>mLightDiffuse;
mLightDiffuseKeys.ChangeKey(mLightDiffuse, 1, true);
}
else if (Token == QLatin1String("SPECULAR")) else if (Token == QLatin1String("SPECULAR"))
{ {
Stream >>mLightSpecular; Stream >>mLightSpecular;
@ -347,6 +463,14 @@ bool lcLight::ParseLDrawLine(QTextStream& Stream)
Stream >> mTargetPosition[0] >> mTargetPosition[1] >> mTargetPosition[2]; Stream >> mTargetPosition[0] >> mTargetPosition[1] >> mTargetPosition[2];
mTargetPositionKeys.ChangeKey(mTargetPosition, 1, true); mTargetPositionKeys.ChangeKey(mTargetPosition, 1, true);
} }
else if (Token == QLatin1String("POV_RAY"))
{
mPOVRayLight = true;
}
else if (Token == QLatin1String("SHADOWLESS"))
{
mShadowless = true;
}
else if (Token == QLatin1String("COLOR_RGB_KEY")) else if (Token == QLatin1String("COLOR_RGB_KEY"))
mLightColorKeys.LoadKeysLDraw(Stream); mLightColorKeys.LoadKeysLDraw(Stream);
else if ((Token == QLatin1String("POWER_KEY")) || (Token == QLatin1String("STRENGTH_KEY"))) else if ((Token == QLatin1String("POWER_KEY")) || (Token == QLatin1String("STRENGTH_KEY")))
@ -354,9 +478,17 @@ bool lcLight::ParseLDrawLine(QTextStream& Stream)
else if ((Token == QLatin1String("ANGLE_KEY")) || (Token == QLatin1String("RADIUS_KEY")) || (Token == QLatin1String("SIZE_KEY")) || (Token == QLatin1String("RADIUS_AND_SPOT_BLEND_KEY"))) else if ((Token == QLatin1String("ANGLE_KEY")) || (Token == QLatin1String("RADIUS_KEY")) || (Token == QLatin1String("SIZE_KEY")) || (Token == QLatin1String("RADIUS_AND_SPOT_BLEND_KEY")))
mLightFactorKeys.LoadKeysLDraw(Stream); mLightFactorKeys.LoadKeysLDraw(Stream);
else if (Token == QLatin1String("SPOT_SIZE_KEY")) else if (Token == QLatin1String("SPOT_SIZE_KEY"))
mLightSpotSizeKeys.LoadKeysLDraw(Stream); mSpotSizeKeys.LoadKeysLDraw(Stream);
else if (Token == QLatin1String("SPOT_FALLOFF_KEY"))
mSpotFalloffKeys.LoadKeysLDraw(Stream);
else if (Token == QLatin1String("SPOT_TIGHTNESS_KEY"))
mSpotTightnessKeys.LoadKeysLDraw(Stream);
else if (Token == QLatin1String("AREA_GRID_KEY"))
mAreaGridKeys.LoadKeysLDraw(Stream);
else if (Token == QLatin1String("SHAPE_KEY")) else if (Token == QLatin1String("SHAPE_KEY"))
mLightShapeKeys.LoadKeysLDraw(Stream); mLightShapeKeys.LoadKeysLDraw(Stream);
else if (Token == QLatin1String("DIFFUSE_KEY"))
mLightDiffuseKeys.LoadKeysLDraw(Stream);
else if (Token == QLatin1String("SPECULAR_KEY")) else if (Token == QLatin1String("SPECULAR_KEY"))
mLightSpecularKeys.LoadKeysLDraw(Stream); mLightSpecularKeys.LoadKeysLDraw(Stream);
else if (Token == QLatin1String("CUTOFF_DISTANCE_KEY")) else if (Token == QLatin1String("CUTOFF_DISTANCE_KEY"))
@ -439,20 +571,55 @@ void lcLight::UpdateLight(lcStep Step, lcLightProperties Props, int Property)
mLightColorKeys.ChangeKey(mLightColor, Step, false); mLightColorKeys.ChangeKey(mLightColor, Step, false);
break; break;
case LC_LIGHT_FACTOR: case LC_LIGHT_FACTOR:
mLightFactor = Props.mLightFactor; if (Props.mPOVRayLight && mLightType == LC_AREALIGHT)
mLightFactorKeys.ChangeKey(mLightFactor, Step, false); {
mAreaSize = Props.mLightFactor;
mLightFactorKeys.ChangeKey(mAreaSize, 1, true);
}
else
{
mLightFactor = Props.mLightFactor;
mLightFactorKeys.ChangeKey(mLightFactor, 1, true);
}
break;
case LC_LIGHT_DIFFUSE:
mLightDiffuse = Props.mLightDiffuse;
mLightDiffuseKeys.ChangeKey(mLightDiffuse, Step, false);
break; break;
case LC_LIGHT_SPECULAR: case LC_LIGHT_SPECULAR:
mLightSpecular = Props.mLightSpecular; mLightSpecular = Props.mLightSpecular;
mLightSpecularKeys.ChangeKey(mLightSpecular, Step, false); mLightSpecularKeys.ChangeKey(mLightSpecular, Step, false);
break; break;
case LC_LIGHT_SHADOWLESS:
mShadowless = Props.mShadowless;
break;
case LC_LIGHT_EXPONENT: case LC_LIGHT_EXPONENT:
mSpotExponent = Props.mSpotExponent; if (Props.mPOVRayLight)
mSpotExponentKeys.ChangeKey(mSpotExponent, Step, false); {
mPOVRayExponent = Props.mSpotExponent;
mSpotExponentKeys.ChangeKey(mPOVRayExponent, Step, false);
}
else
{
mSpotExponent = Props.mSpotExponent;
mSpotExponentKeys.ChangeKey(mSpotExponent, Step, false);
}
break;
case LC_LIGHT_AREA_GRID:
mAreaGrid = Props.mAreaGrid;
mAreaGridKeys.ChangeKey(mAreaGrid, Step, false);
break; break;
case LC_LIGHT_SPOT_SIZE: case LC_LIGHT_SPOT_SIZE:
mSpotSize = Props.mSpotSize; mSpotSize = Props.mSpotSize;
mLightSpotSizeKeys.ChangeKey(mSpotSize, Step, false); mSpotSizeKeys.ChangeKey(mSpotSize, Step, false);
break;
case LC_LIGHT_SPOT_FALLOFF:
mSpotFalloff = Props.mSpotFalloff;
mSpotFalloffKeys.ChangeKey(mSpotFalloff, Step, false);
break;
case LC_LIGHT_SPOT_TIGHTNESS:
mSpotTightness = Props.mSpotTightness;
mSpotTightnessKeys.ChangeKey(mSpotTightness, Step, false);
break; break;
case LC_LIGHT_CUTOFF: case LC_LIGHT_CUTOFF:
mSpotCutoff = Props.mSpotCutoff; mSpotCutoff = Props.mSpotCutoff;
@ -461,6 +628,9 @@ void lcLight::UpdateLight(lcStep Step, lcLightProperties Props, int Property)
case LC_LIGHT_USE_CUTOFF: case LC_LIGHT_USE_CUTOFF:
mEnableCutoff = Props.mEnableCutoff; mEnableCutoff = Props.mEnableCutoff;
break; break;
case LC_LIGHT_POVRAY:
mPOVRayLight = Props.mPOVRayLight;
break;
} }
UpdatePosition(Step); UpdatePosition(Step);
} }
@ -591,10 +761,14 @@ void lcLight::InsertTime(lcStep Start, lcStep Time)
mLightColorKeys.InsertTime(Start, Time); mLightColorKeys.InsertTime(Start, Time);
mLightTypeKeys.InsertTime(Start, Time); mLightTypeKeys.InsertTime(Start, Time);
mLightFactorKeys.InsertTime(Start, Time); mLightFactorKeys.InsertTime(Start, Time);
mLightDiffuseKeys.InsertTime(Start, Time);
mLightSpecularKeys.InsertTime(Start, Time); mLightSpecularKeys.InsertTime(Start, Time);
mLightSpotSizeKeys.InsertTime(Start, Time); mSpotSizeKeys.InsertTime(Start, Time);
mSpotCutoffKeys.InsertTime(Start, Time); mSpotCutoffKeys.InsertTime(Start, Time);
mSpotExponentKeys.InsertTime(Start, Time); mSpotExponentKeys.InsertTime(Start, Time);
mSpotFalloffKeys.InsertTime(Start, Time);
mSpotTightnessKeys.InsertTime(Start, Time);
mAreaGridKeys.InsertTime(Start, Time);
} }
void lcLight::RemoveTime(lcStep Start, lcStep Time) void lcLight::RemoveTime(lcStep Start, lcStep Time)
@ -609,10 +783,14 @@ void lcLight::RemoveTime(lcStep Start, lcStep Time)
mLightColorKeys.RemoveTime(Start, Time); mLightColorKeys.RemoveTime(Start, Time);
mLightTypeKeys.RemoveTime(Start, Time); mLightTypeKeys.RemoveTime(Start, Time);
mLightFactorKeys.RemoveTime(Start, Time); mLightFactorKeys.RemoveTime(Start, Time);
mLightDiffuseKeys.RemoveTime(Start, Time);
mLightSpecularKeys.RemoveTime(Start, Time); mLightSpecularKeys.RemoveTime(Start, Time);
mLightSpotSizeKeys.RemoveTime(Start, Time); mSpotSizeKeys.RemoveTime(Start, Time);
mSpotCutoffKeys.RemoveTime(Start, Time); mSpotCutoffKeys.RemoveTime(Start, Time);
mSpotExponentKeys.RemoveTime(Start, Time); mSpotExponentKeys.RemoveTime(Start, Time);
mSpotFalloffKeys.RemoveTime(Start, Time);
mSpotTightnessKeys.RemoveTime(Start, Time);
mAreaGridKeys.RemoveTime(Start, Time);
} }
void lcLight::UpdatePosition(lcStep Step) void lcLight::UpdatePosition(lcStep Step)
@ -627,10 +805,14 @@ void lcLight::UpdatePosition(lcStep Step)
mLightColor = mLightColorKeys.CalculateKey(Step); mLightColor = mLightColorKeys.CalculateKey(Step);
mLightType = mLightTypeKeys.CalculateKey(Step); mLightType = mLightTypeKeys.CalculateKey(Step);
mLightFactor = mLightFactorKeys.CalculateKey(Step); mLightFactor = mLightFactorKeys.CalculateKey(Step);
mLightDiffuse = mLightDiffuseKeys.CalculateKey(Step);
mLightSpecular = mLightSpecularKeys.CalculateKey(Step); mLightSpecular = mLightSpecularKeys.CalculateKey(Step);
mSpotSize = mLightSpotSizeKeys.CalculateKey(Step); mSpotSize = mSpotSizeKeys.CalculateKey(Step);
mSpotCutoff = mSpotCutoffKeys.CalculateKey(Step); mSpotCutoff = mSpotCutoffKeys.CalculateKey(Step);
mSpotExponent = mSpotExponentKeys.CalculateKey(Step); mSpotExponent = mSpotExponentKeys.CalculateKey(Step);
mSpotFalloff = mSpotFalloffKeys.CalculateKey(Step);
mSpotTightness = mSpotTightnessKeys.CalculateKey(Step);
mAreaGrid = mAreaGridKeys.CalculateKey(Step);
if (IsPointLight()) if (IsPointLight())
{ {
@ -1146,17 +1328,29 @@ void lcLight::RemoveKeyFrames()
mLightTypeKeys.RemoveAll(); mLightTypeKeys.RemoveAll();
mLightTypeKeys.ChangeKey(mLightType, 1, true); mLightTypeKeys.ChangeKey(mLightType, 1, true);
mLightDiffuseKeys.RemoveAll();
mLightDiffuseKeys.ChangeKey(mLightDiffuse, 1, true);
mLightSpecularKeys.RemoveAll(); mLightSpecularKeys.RemoveAll();
mLightSpecularKeys.ChangeKey(mLightSpecular, 1, true); mLightSpecularKeys.ChangeKey(mLightSpecular, 1, true);
mLightSpotSizeKeys.RemoveAll(); mSpotSizeKeys.RemoveAll();
mLightSpotSizeKeys.ChangeKey(mSpotSize, 1, false); mSpotSizeKeys.ChangeKey(mSpotSize, 1, false);
mSpotCutoffKeys.RemoveAll(); mSpotCutoffKeys.RemoveAll();
mSpotCutoffKeys.ChangeKey(mSpotCutoff, 1, true); mSpotCutoffKeys.ChangeKey(mSpotCutoff, 1, true);
mSpotExponentKeys.RemoveAll(); mSpotExponentKeys.RemoveAll();
mSpotExponentKeys.ChangeKey(mSpotExponent, 1, true); mSpotExponentKeys.ChangeKey(mSpotExponent, 1, true);
mSpotFalloffKeys.RemoveAll();
mSpotFalloffKeys.ChangeKey(mSpotFalloff, 1, true);
mSpotTightnessKeys.RemoveAll();
mSpotTightnessKeys.ChangeKey(mSpotTightness, 1, true);
mAreaGridKeys.RemoveAll();
mAreaGridKeys.ChangeKey(mAreaGrid, 1, true);
} }
bool lcLight::Setup(int LightIndex) bool lcLight::Setup(int LightIndex)

View file

@ -45,22 +45,34 @@ enum lcLightProperty
LC_LIGHT_COLOR, LC_LIGHT_COLOR,
LC_LIGHT_TYPE, LC_LIGHT_TYPE,
LC_LIGHT_FACTOR, LC_LIGHT_FACTOR,
LC_LIGHT_DIFFUSE,
LC_LIGHT_SPECULAR, LC_LIGHT_SPECULAR,
LC_LIGHT_SHADOWLESS,
LC_LIGHT_EXPONENT, LC_LIGHT_EXPONENT,
LC_LIGHT_AREA_GRID,
LC_LIGHT_SPOT_SIZE, LC_LIGHT_SPOT_SIZE,
LC_LIGHT_SPOT_FALLOFF,
LC_LIGHT_SPOT_TIGHTNESS,
LC_LIGHT_CUTOFF, LC_LIGHT_CUTOFF,
LC_LIGHT_USE_CUTOFF LC_LIGHT_USE_CUTOFF,
LC_LIGHT_POVRAY
}; };
struct lcLightProperties struct lcLightProperties
{ {
lcVector3 mLightColor; lcVector3 mLightColor;
lcVector2 mLightFactor; lcVector2 mLightFactor;
lcVector2 mAreaGrid;
float mLightDiffuse;
float mLightSpecular; float mLightSpecular;
float mSpotExponent; float mSpotExponent;
float mSpotCutoff; float mSpotCutoff;
float mSpotFalloff;
float mSpotTightness;
float mSpotSize; float mSpotSize;
bool mEnableCutoff; bool mEnableCutoff;
bool mShadowless;
bool mPOVRayLight;
int mLightShape; int mLightShape;
}; };
@ -251,16 +263,21 @@ public:
lcLightProperties props; lcLightProperties props;
props.mLightColor = mLightColor; props.mLightColor = mLightColor;
props.mLightFactor = mLightFactor; props.mLightFactor = mLightFactor;
props.mLightDiffuse = mLightDiffuse;
props.mLightSpecular = mLightSpecular; props.mLightSpecular = mLightSpecular;
props.mSpotExponent = mSpotExponent; props.mSpotExponent = mSpotExponent;
props.mSpotCutoff = mSpotCutoff; props.mSpotCutoff = mSpotCutoff;
props.mSpotFalloff = mSpotFalloff;
props.mSpotTightness = mSpotTightness;
props.mSpotSize = mSpotSize; props.mSpotSize = mSpotSize;
props.mPOVRayLight = mPOVRayLight;
props.mEnableCutoff = mEnableCutoff; props.mEnableCutoff = mEnableCutoff;
props.mShadowless = mShadowless;
props.mAreaGrid = mAreaGrid;
props.mLightShape = mLightShape; props.mLightShape = mLightShape;
return props; return props;
} }
// Temporary parameters
lcMatrix44 mWorldLight; lcMatrix44 mWorldLight;
lcVector3 mPosition; lcVector3 mPosition;
lcVector3 mTargetPosition; lcVector3 mTargetPosition;
@ -270,17 +287,25 @@ public:
lcVector3 mAttenuation; lcVector3 mAttenuation;
lcVector3 mLightColor; lcVector3 mLightColor;
lcVector2 mLightFactor; lcVector2 mLightFactor;
lcVector2 mAreaGrid;
lcVector2 mAreaSize;
bool mAngleSet; bool mAngleSet;
bool mSpotBlendSet; bool mSpotBlendSet;
bool mSpotCutoffSet; bool mSpotCutoffSet;
bool mHeightSet; bool mHeightSet;
bool mEnableCutoff; bool mEnableCutoff;
bool mPOVRayLight;
bool mShadowless;
int mLightType; int mLightType;
int mLightShape; int mLightShape;
float mLightDiffuse;
float mLightSpecular; float mLightSpecular;
float mSpotSize; float mSpotSize;
float mSpotCutoff; float mSpotCutoff;
float mSpotFalloff;
float mSpotTightness;
float mSpotExponent; float mSpotExponent;
float mPOVRayExponent;
QString mName; QString mName;
protected: protected:
@ -292,12 +317,16 @@ protected:
lcObjectKeyArray<lcVector3> mAttenuationKeys; lcObjectKeyArray<lcVector3> mAttenuationKeys;
lcObjectKeyArray<lcVector3> mLightColorKeys; lcObjectKeyArray<lcVector3> mLightColorKeys;
lcObjectKeyArray<lcVector2> mLightFactorKeys; lcObjectKeyArray<lcVector2> mLightFactorKeys;
lcObjectKeyArray<lcVector2> mAreaGridKeys;
lcObjectKeyArray<int> mLightTypeKeys; lcObjectKeyArray<int> mLightTypeKeys;
lcObjectKeyArray<int> mLightShapeKeys; lcObjectKeyArray<int> mLightShapeKeys;
lcObjectKeyArray<float> mLightSpecularKeys; lcObjectKeyArray<float> mLightSpecularKeys;
lcObjectKeyArray<float> mLightSpotSizeKeys; lcObjectKeyArray<float> mLightDiffuseKeys;
lcObjectKeyArray<float> mSpotSizeKeys;
lcObjectKeyArray<float> mSpotCutoffKeys; lcObjectKeyArray<float> mSpotCutoffKeys;
lcObjectKeyArray<float> mSpotFalloffKeys;
lcObjectKeyArray<float> mSpotExponentKeys; lcObjectKeyArray<float> mSpotExponentKeys;
lcObjectKeyArray<float> mSpotTightnessKeys;
void Initialize(const lcVector3& Position, const lcVector3& TargetPosition, int LightType); void Initialize(const lcVector3& Position, const lcVector3& TargetPosition, int LightType);