Added camera command line options.

This commit is contained in:
Leonardo Zide 2020-12-12 15:03:06 -08:00
parent 70d5daaac4
commit 847cbfeb87
5 changed files with 117 additions and 5 deletions

View file

@ -1058,6 +1058,25 @@ void lcCamera::SetViewpoint(const lcVector3& Position)
UpdatePosition(1);
}
void lcCamera::SetViewpoint(const lcVector3& Position, const lcVector3& Target, const lcVector3& Up)
{
mPosition = Position;
mTargetPosition = Target;
lcVector3 Direction = Target - Position;
lcVector3 UpVector, SideVector;
SideVector = lcCross(Direction, Up);
UpVector = lcCross(SideVector, Direction);
UpVector.Normalize();
mUpVector = Up;
ChangeKey(mPositionKeys, mPosition, 1, false);
ChangeKey(mTargetPositionKeys, mTargetPosition, 1, false);
ChangeKey(mUpVectorKeys, mUpVector, 1, false);
UpdatePosition(1);
}
void lcCamera::SetAngles(float Latitude, float Longitude, float Distance)
{
mPosition = lcVector3(0, -1, 0);

View file

@ -273,7 +273,6 @@ public:
void RemoveTime(lcStep Start, lcStep Time);
bool FileLoad(lcFile& file);
void Select(bool bSelecting, bool bFocus, bool bMultiple);
void CompareBoundingBox(lcVector3& Min, lcVector3& Max);
void UpdatePosition(lcStep Step);
@ -291,6 +290,7 @@ public:
void MoveRelative(const lcVector3& Distance, lcStep Step, bool AddKey);
void SetViewpoint(lcViewpoint Viewpoint);
void SetViewpoint(const lcVector3& Position);
void SetViewpoint(const lcVector3& Position, const lcVector3& Target, const lcVector3& Up);
void GetAngles(float& Latitude, float& Longitude, float& Distance) const;
void SetAngles(float Latitude, float Longitude, float Distance);

View file

@ -331,7 +331,10 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
bool SaveCOLLADA = false;
bool SaveHTML = false;
bool SetCameraAngles = false;
bool SetCameraPosition = false;
bool Orthographic = false;
bool SetFoV = false;
bool SetZPlanes = false;
bool SetFadeStepsColor = false;
bool SetHighlightColor = false;
bool FadeSteps = mPreferences.mFadeSteps;
@ -342,7 +345,10 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
int StudLogo = lcGetProfileInt(LC_PROFILE_STUD_LOGO);
int ImageStart = 0;
int ImageEnd = 0;
float CameraPosition[9] = {};
float CameraLatitude = 0.0f, CameraLongitude = 0.0f;
float FoV = 0.0f;
float ZNear = 0.0f, ZFar = 0.0f;
quint32 FadeStepsColor = mPreferences.mFadeStepsColor;
quint32 HighlightColor = mPreferences.mHighlightNewPartsColor;
QString ImageName;
@ -405,15 +411,20 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
{
bool Ok = false;
ArgIdx++;
int NewValue = Arguments[ArgIdx].toFloat(&Ok);
float NewValue = Arguments[ArgIdx].toFloat(&Ok);
if (Ok)
{
Value = NewValue;
return true;
}
else
printf("Invalid value specified for the '%s' argument.\n", Arguments[ArgIdx - 1].toLatin1().constData());
}
else
printf("Not enough parameters for the '%s' argument.\n", Arguments[ArgIdx].toLatin1().constData());
return false;
};
auto ParseVector2 = [&ArgIdx, &Arguments, NumArguments](float& Value1, float& Value2)
@ -442,6 +453,33 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
return false;
};
auto ParseFloatArray = [&ArgIdx, &Arguments, NumArguments](int Count, float* ValueArray)
{
if (ArgIdx + Count >= NumArguments)
{
printf("Not enough parameters for the '%s' argument.\n", Arguments[ArgIdx].toLatin1().constData());
return false;
}
for (int ParseIndex = 0; ParseIndex < Count; ParseIndex++)
{
bool Ok = false;
float NewValue = Arguments[ArgIdx+ParseIndex+1].toFloat(&Ok);
if (Ok)
*(ValueArray++) = NewValue;
else
{
printf("Invalid value specified for the '%s' argument: '%s'.\n", Arguments[ArgIdx].toLatin1().constData(), Arguments[ArgIdx+ParseIndex+1].toLatin1().constData());
ArgIdx += 1 + Count;
return false;
}
}
ArgIdx += Count;
return true;
};
auto ParseColor = [&ArgIdx, &Arguments, NumArguments](quint32& Color)
{
if (ArgIdx + 1 >= NumArguments)
@ -493,8 +531,14 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
ParseString(ViewpointName, true);
else if (Param == QLatin1String("--camera-angles"))
SetCameraAngles = ParseVector2(CameraLatitude, CameraLongitude);
else if (Param == QLatin1String("--camera-position"))
SetCameraPosition = ParseFloatArray(9, CameraPosition);
else if (Param == QLatin1String("--orthographic"))
Orthographic = true;
else if (Param == QLatin1String("--fov"))
SetFoV = ParseFloat(FoV);
else if (Param == QLatin1String("--zplanes"))
SetZPlanes = ParseVector2(ZNear, ZFar);
else if (Param == QLatin1String("--fade-steps"))
FadeSteps = true;
else if (Param == QLatin1String("--no-fade-steps"))
@ -572,7 +616,6 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
#else
printf("LeoCAD Version " LC_VERSION_TEXT "\n");
#endif
printf("LeoCAD Version " LC_VERSION_TEXT "\n");
printf("Compiled " __DATE__ "\n");
ShowWindow = false;
@ -593,7 +636,10 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
printf(" -sl, --stud-logo <type>: Set the stud logo type 0 - 5, 0 is no logo.\n");
printf(" --viewpoint <front|back|left|right|top|bottom|home>: Set the viewpoint.\n");
printf(" --camera-angles <latitude> <longitude>: Set the camera angles in degrees around the model.\n");
printf(" --orthographic: Make the view orthographic.\n");
printf(" --camera-position <x> <y> <z> <tx> <ty> <tz> <ux> <uy> <uz>: Set the camera position, target and up vector.\n");
printf(" --orthographic: Render images using an orthographic projection.\n");
printf(" --fov <degrees>: Set the vertical field of view used to render images.\n");
printf(" --zplanes <near> <far>: Set the near and far clipping planes used to render images.\n");
printf(" --fade-steps: Render parts from prior steps faded.\n");
printf(" --no-fade-steps: Do not render parts from prior steps faded.\n");
printf(" --fade-steps-color <rgba>: Renderinng color for prior step parts (#AARRGGBB).\n");
@ -666,6 +712,9 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
if (SetCameraAngles)
printf("Warning: --camera-angles is ignored when --camera is set.\n");
if (SetCameraPosition)
printf("Warning: --camera-position is ignored when --camera is set.\n");
}
else
{
@ -690,11 +739,36 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
if (SetCameraAngles)
printf("Warning: --camera-angles is ignored when --viewpoint is set.\n");
if (SetCameraPosition)
printf("Warning: --camera-position is ignored when --viewpoint is set.\n");
}
else if (SetCameraAngles)
{
ActiveView->SetCameraAngles(CameraLatitude, CameraLongitude);
if (SetCameraPosition)
printf("Warning: --camera-position is ignored when --camera-angles is set.\n");
}
else if (SetCameraPosition)
{
ActiveView->SetViewpoint(lcVector3(CameraPosition[0], CameraPosition[1], CameraPosition[2]),
lcVector3(CameraPosition[3], CameraPosition[4], CameraPosition[5]),
lcVector3(CameraPosition[6], CameraPosition[7], CameraPosition[8]));
}
ActiveView->SetProjection(Orthographic);
if (SetFoV)
ActiveView->GetCamera()->m_fovy = FoV;
if (SetZPlanes)
{
lcCamera* Camera = ActiveView->GetCamera();
Camera->m_zNear = ZNear;
Camera->m_zFar = ZFar;
}
}
if (SaveImage)
@ -742,7 +816,7 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
mPreferences.mHighlightNewParts = ImageHighlight;
mPreferences.mHighlightNewPartsColor = HighlightColor;
ActiveModel->SaveStepImages(Frame, ImageStart != ImageEnd, CameraName == nullptr, ImageWidth, ImageHeight, ImageStart, ImageEnd);
ActiveModel->SaveStepImages(Frame, ImageStart != ImageEnd, CameraName.isEmpty() && !SetCameraPosition, ImageWidth, ImageHeight, ImageStart, ImageEnd);
}
if (SaveWavefront)

View file

@ -345,6 +345,24 @@ void View::SetViewpoint(const lcVector3& Position)
gMainWindow->UpdateCurrentCamera(-1);
}
void View::SetViewpoint(const lcVector3& Position, const lcVector3& Target, const lcVector3& Up)
{
if (!mCamera || !mCamera->IsSimple())
{
lcCamera* OldCamera = mCamera;
mCamera = new lcCamera(true);
if (OldCamera)
mCamera->CopySettings(OldCamera);
}
mCamera->SetViewpoint(Position, Target, Up);
Redraw();
gMainWindow->UpdateCurrentCamera(-1);
}
void View::SetCameraAngles(float Latitude, float Longitude)
{
if (!mCamera || !mCamera->IsSimple())

View file

@ -63,6 +63,7 @@ public:
void SetCameraIndex(int Index);
void SetViewpoint(lcViewpoint Viewpoint);
void SetViewpoint(const lcVector3& Position);
void SetViewpoint(const lcVector3& Position, const lcVector3& Target, const lcVector3& Up);
void SetCameraAngles(float Latitude, float Longitude);
void SetDefaultCamera();
void ShowContextMenu() const;