Added JSON export.

This commit is contained in:
leo 2014-08-29 23:52:42 +00:00
parent 73952870fd
commit 9a37302456
9 changed files with 209 additions and 2 deletions

View file

@ -102,6 +102,57 @@ void lcCamera::CreateName(const lcArray<lcCamera*>& Cameras)
sprintf(m_strName, "%s %d", Prefix, max+1);
}
QJsonObject lcCamera::Save()
{
QJsonObject Camera;
Camera[QStringLiteral("FOV")] = QString::number(m_fovy);
Camera[QStringLiteral("ZNear")] = QString::number(m_zNear);
Camera[QStringLiteral("ZFar")] = QString::number(m_zFar);
Camera[QStringLiteral("Name")] = QString::fromLatin1(m_strName); // todo: replace with qstring
if (IsHidden())
Camera[QStringLiteral("Hidden")] = QStringLiteral("true");
if (IsOrtho())
Camera[QStringLiteral("Orthographic")] = QStringLiteral("true");
QJsonArray PositionKeys, TargetPositionKeys, UpVectorKeys;
for (LC_OBJECT_KEY* Node = m_pInstructionKeys; Node; Node = Node->next)
{
QJsonObject Key;
Key[QStringLiteral("Step")] = QString::number(Node->Step);
Key["Value"] = QStringLiteral("%1 %2 %3").arg(QString::number(Node->param[0]), QString::number(Node->param[1]), QString::number(Node->param[2]));
if (Node->type == LC_CK_EYE)
PositionKeys.append(Key);
else if (Node->type == LC_CK_TARGET)
TargetPositionKeys.append(Key);
else if (Node->type == LC_CK_UP)
UpVectorKeys.append(Key);
}
if (PositionKeys.size() == 1 && TargetPositionKeys.size() == 1 && UpVectorKeys.size() == 1)
{
Camera[QStringLiteral("Position")] = PositionKeys.first().toObject()["Value"].toString();
Camera[QStringLiteral("TargetPosition")] = TargetPositionKeys.first().toObject()["Value"].toString();
Camera[QStringLiteral("UpVector")] = UpVectorKeys.first().toObject()["Value"].toString();
}
else
{
Camera["PositionKeys"] = PositionKeys;
Camera["TargetPositionKeys"] = TargetPositionKeys;
Camera["UpVectorKeys"] = UpVectorKeys;
}
return Camera;
}
void lcCamera::Load(QJsonObject Camera)
{
}
/////////////////////////////////////////////////////////////////////////////
// Camera save/load

View file

@ -228,6 +228,9 @@ public:
return lcVector3(0.0f, 0.0f, 0.0f);
}
QJsonObject Save();
void Load(QJsonObject Camera);
@ -242,6 +245,8 @@ public:
{ return m_nType < LC_CAMERA_MAIN; }
bool IsVisible() const
{ return (mState & LC_CAMERA_HIDDEN) == 0; }
bool IsHidden() const
{ return (mState & LC_CAMERA_HIDDEN) != 0; }
public:
virtual void RayTest(lcObjectRayTest& ObjectRayTest) const;

View file

@ -38,6 +38,53 @@ void lcModelProperties::SaveDefaults()
lcSetProfileInt(LC_PROFILE_DEFAULT_AMBIENT_COLOR, lcColorFromVector3(mAmbientColor));
}
QJsonObject lcModelProperties::Save()
{
QJsonObject Properties;
if (!mName.IsEmpty())
Properties[QStringLiteral("Name")] = QString::fromLatin1(mName.Buffer());
if (!mAuthor.IsEmpty())
Properties[QStringLiteral("Author")] = QString::fromLatin1(mAuthor.Buffer());
if (!mDescription.IsEmpty())
Properties[QStringLiteral("Description")] = QString::fromLatin1(mDescription.Buffer());
if (!mComments.IsEmpty())
Properties[QStringLiteral("Comments")] = QString::fromLatin1(mComments.Buffer());
switch (mBackgroundType)
{
case LC_BACKGROUND_SOLID:
Properties[QStringLiteral("Background")] = QStringLiteral("Solid");
break;
case LC_BACKGROUND_GRADIENT:
Properties[QStringLiteral("Background")] = QStringLiteral("Gradient");
break;
case LC_BACKGROUND_IMAGE:
Properties[QStringLiteral("Background")] = QStringLiteral("Image");
break;
}
Properties[QStringLiteral("BackgroundSolidColor")] = QStringLiteral("%1 %2 %3").arg(QString::number(mBackgroundSolidColor[0]), QString::number(mBackgroundSolidColor[1]), QString::number(mBackgroundSolidColor[2]));
Properties[QStringLiteral("BackgroundGradientColor1")] = QStringLiteral("%1 %2 %3").arg(QString::number(mBackgroundGradientColor1[0]), QString::number(mBackgroundGradientColor1[1]), QString::number(mBackgroundGradientColor1[2]));
Properties[QStringLiteral("BackgroundGradientColor2")] = QStringLiteral("%1 %2 %3").arg(QString::number(mBackgroundGradientColor2[0]), QString::number(mBackgroundGradientColor2[1]), QString::number(mBackgroundGradientColor2[2]));
if (!mBackgroundImage.IsEmpty())
Properties[QStringLiteral("BackgroundImage")] = QString::fromLatin1(mBackgroundImage.Buffer());
if (mBackgroundImageTile)
Properties[QStringLiteral("BackgroundImageTile")] = QStringLiteral("true");
if (mFogEnabled)
Properties[QStringLiteral("FogEnabled")] = QStringLiteral("true");
Properties[QStringLiteral("FogDensity")] = QString::number(mFogDensity);
Properties[QStringLiteral("FogColor")] = QStringLiteral("%1 %2 %3").arg(QString::number(mBackgroundSolidColor[0]), QString::number(mBackgroundSolidColor[1]), QString::number(mBackgroundSolidColor[2]));
Properties[QStringLiteral("AmbientColor")] = QStringLiteral("%1 %2 %3").arg(QString::number(mBackgroundSolidColor[0]), QString::number(mBackgroundSolidColor[1]), QString::number(mBackgroundSolidColor[2]));
return Properties;
}
void lcModelProperties::Load(QJsonObject Properties)
{
}
lcModel::lcModel()
{
mSavedHistory = NULL;
@ -47,6 +94,38 @@ lcModel::~lcModel()
{
}
QJsonObject lcModel::Save()
{
QJsonObject Model;
Model["Properties"] = mProperties.Save();
Model["CurrentStep"] = QString::number(mCurrentStep);
QJsonArray Pieces;
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
Pieces.append(mPieces[PieceIdx]->Save());
Model["Pieces"] = Pieces;
QJsonArray Cameras;
for (int CameraIdx = 0; CameraIdx < mCameras.GetSize(); CameraIdx++)
Cameras.append(mCameras[CameraIdx]->Save());
Model["Cameras"] = Cameras;
QJsonArray Lights;
for (int LightIdx = 0; LightIdx < mLights.GetSize(); LightIdx++)
Lights.append(mLights[LightIdx]->Save());
Model["Lights"] = Lights;
// lcArray<lcGroup*> mGroups;
return Model;
}
void lcModel::Load(QJsonObject Model)
{
}
lcStep lcModel::GetLastStep() const
{
lcStep Step = 1;

View file

@ -54,6 +54,9 @@ public:
return true;
}
QJsonObject Save();
void Load(QJsonObject Properties);
String mName;
String mAuthor;
String mDescription;
@ -134,6 +137,9 @@ public:
return mCurrentStep;
}
QJsonObject Save();
void Load(QJsonObject Model);
lcObject* GetFocusObject() const;
void FocusOrDeselectObject(const lcObjectSection& ObjectSection);
void ClearSelectionAndSetFocus(lcObject* Object, lcuint32 Section);

View file

@ -84,6 +84,16 @@ lcLight::~lcLight()
{
}
QJsonObject lcLight::Save()
{
return QJsonObject();
}
void lcLight::Load(QJsonObject Light)
{
}
bool lcLight::FileLoad(lcFile& file)
{
return true;

View file

@ -185,6 +185,9 @@ public:
return lcVector3(0.0f, 0.0f, 0.0f);
}
QJsonObject Save();
void Load(QJsonObject Light);
public:
virtual void RayTest(lcObjectRayTest& ObjectRayTest) const;
virtual void BoxTest(lcObjectBoxTest& ObjectBoxTest) const;

View file

@ -122,8 +122,6 @@ public:
protected:
void RegisterKeys(float *values[], LC_OBJECT_KEY_INFO* info, int count);
void CalculateKeys(lcStep Step);
private:
void RemoveKeys();
LC_OBJECT_KEY* m_pInstructionKeys;

View file

@ -56,6 +56,58 @@ lcPiece::~lcPiece()
mPieceInfo->Release();
}
QJsonObject lcPiece::Save()
{
QJsonObject Piece;
Piece[QStringLiteral("ID")] = QString::fromLatin1(mPieceInfo->m_strName);
Piece[QStringLiteral("Color")] = QString::number(mColorCode);
Piece[QStringLiteral("Step")] = QString::number(mStepShow);
if (mStepHide != LC_STEP_MAX)
Piece[QStringLiteral("StepHide")] = QString::number(mStepHide);
Piece[QStringLiteral("Name")] = QString::fromLatin1(m_strName); // todo: replace with qstring
if (IsHidden())
Piece[QStringLiteral("Hidden")] = QStringLiteral("true");
QJsonArray PositionKeys, RotationKeys;
for (LC_OBJECT_KEY* Node = m_pInstructionKeys; Node; Node = Node->next)
{
QJsonObject Key;
Key[QStringLiteral("Step")] = QString::number(Node->Step);
if (Node->type == LC_PK_POSITION)
{
Key["Value"] = QStringLiteral("%1 %2 %3").arg(QString::number(Node->param[0]), QString::number(Node->param[1]), QString::number(Node->param[2]));
PositionKeys.append(Key);
}
else if (Node->type == LC_PK_ROTATION)
{
Key["Value"] = QStringLiteral("%1 %2 %3 %4").arg(QString::number(Node->param[0]), QString::number(Node->param[1]), QString::number(Node->param[2]), QString::number(Node->param[3]));
RotationKeys.append(Key);
}
}
if (PositionKeys.size() == 1 && RotationKeys.size() == 1)
{
Piece[QStringLiteral("Position")] = PositionKeys.first().toObject()["Value"].toString();
Piece[QStringLiteral("Rotation")] = RotationKeys.first().toObject()["Value"].toString();
}
else
{
Piece["PositionKeys"] = PositionKeys;
Piece["RotationKeys"] = RotationKeys;
}
return Piece;
}
void lcPiece::Load(QJsonObject Piece)
{
}
/////////////////////////////////////////////////////////////////////////////
// Piece save/load

View file

@ -95,6 +95,9 @@ public:
return lcVector3(0.0f, 0.0f, 0.0f);
}
QJsonObject Save();
void Load(QJsonObject Piece);
virtual void RayTest(lcObjectRayTest& ObjectRayTest) const;
virtual void BoxTest(lcObjectBoxTest& ObjectBoxTest) const;