26#include <ext/rapidjson/document.h>
27#include <ext/rapidjson/stringbuffer.h>
28#include <ext/rapidjson/writer.h>
30using std::ostringstream;
51using rapidjson::Document;
52using rapidjson::StringBuffer;
53using rapidjson::Value;
54using rapidjson::Writer;
56void SceneWriter::write(
const string& pathName,
const string& fileName,
Scene* scene)
58 scene->
setFileName((pathName.empty() ==
false?pathName +
"/":
"") + fileName);
61 jDocument.SetObject();
62 auto& jAllocator = jDocument.GetAllocator();
63 jDocument.AddMember(
"version", Value(
"1.99", jAllocator), jAllocator);
71 jLight.AddMember(
"id", Value(i), jAllocator);
72 jLight.AddMember(
"ar", Value(light->getAmbient().getRed()), jAllocator);
73 jLight.AddMember(
"ag", Value(light->getAmbient().getGreen()), jAllocator);
74 jLight.AddMember(
"ab", Value(light->getAmbient().getBlue()), jAllocator);
75 jLight.AddMember(
"aa", Value(light->getAmbient().getAlpha()), jAllocator);
76 jLight.AddMember(
"dr", Value(light->getDiffuse().getRed()), jAllocator);
77 jLight.AddMember(
"dg", Value(light->getDiffuse().getGreen()), jAllocator);
78 jLight.AddMember(
"db", Value(light->getDiffuse().getBlue()), jAllocator);
79 jLight.AddMember(
"da", Value(light->getDiffuse().getAlpha()), jAllocator);
80 jLight.AddMember(
"sr", Value(light->getSpecular().getRed()), jAllocator);
81 jLight.AddMember(
"sg", Value(light->getSpecular().getGreen()), jAllocator);
82 jLight.AddMember(
"sb", Value(light->getSpecular().getBlue()), jAllocator);
83 jLight.AddMember(
"sa", Value(light->getSpecular().getAlpha()), jAllocator);
84 jLight.AddMember(
"px", Value(light->getPosition().getX()), jAllocator);
85 jLight.AddMember(
"py", Value(light->getPosition().getY()), jAllocator);
86 jLight.AddMember(
"pz", Value(light->getPosition().getZ()), jAllocator);
87 jLight.AddMember(
"pw", Value(light->getPosition().getW()), jAllocator);
88 jLight.AddMember(
"sdx", Value(light->getSpotDirection().getX()), jAllocator);
89 jLight.AddMember(
"sdy", Value(light->getSpotDirection().getY()), jAllocator);
90 jLight.AddMember(
"sdz", Value(light->getSpotDirection().getZ()), jAllocator);
91 jLight.AddMember(
"se", Value(light->getSpotExponent()), jAllocator);
92 jLight.AddMember(
"sco", Value(light->getSpotCutOff()), jAllocator);
93 jLight.AddMember(
"ca", Value(light->getConstantAttenuation()), jAllocator);
94 jLight.AddMember(
"la", Value(light->getLinearAttenuation()), jAllocator);
95 jLight.AddMember(
"qa", Value(light->getQuadraticAttenuation()), jAllocator);
96 jLight.AddMember(
"e", Value(light->isEnabled()), jAllocator);
97 jLights.PushBack(jLight, jAllocator);
99 jDocument.AddMember(
"lights", jLights, jAllocator);
101 jSceneLibrary.SetArray();
102 for (
auto i = 0; i < sceneLibrary->getPrototypeCount(); i++) {
103 auto prototype = sceneLibrary->getPrototypeAt(i);
105 jPrototype.SetObject();
106 if (prototype->isEmbedded() ==
true) {
107 Value jEmbeddedPrototype;
108 jEmbeddedPrototype.SetObject();
109 PrototypeWriter::write(
114 jPrototype.AddMember(
"type", Value(prototype->getType()->getName(), jAllocator), jAllocator);
115 jPrototype.AddMember(
"entity", jEmbeddedPrototype, jAllocator);
117 jPrototype.AddMember(
"id", Value().SetInt(prototype->getId()), jAllocator);
118 jPrototype.AddMember(
"e", Value(prototype->isEmbedded()), jAllocator);
119 jPrototype.AddMember(
"pf", Value(prototype->getFileName(), jAllocator), jAllocator);
120 jSceneLibrary.PushBack(jPrototype, jAllocator);
122 jDocument.AddMember(
"models", jSceneLibrary, jAllocator);
123 Value jSceneProperties;
124 jSceneProperties.SetArray();
127 Value jSceneProperty;
128 jSceneProperty.SetObject();
129 jSceneProperty.AddMember(
"name", Value(sceneProperty->getName(), jAllocator), jAllocator);
130 jSceneProperty.AddMember(
"value", Value(sceneProperty->getValue(), jAllocator), jAllocator);
131 jSceneProperties.PushBack(jSceneProperty, jAllocator);
133 jDocument.AddMember(
"properties", jSceneProperties, jAllocator);
142 auto& scale = transformations.getScale();
146 jObject.AddMember(
"id", Value(sceneEntity->getId(), jAllocator), jAllocator);
147 jObject.AddMember(
"descr", Value(sceneEntity->getDescription(), jAllocator), jAllocator);;
148 jObject.AddMember(
"mid", Value(sceneEntity->getPrototype()->getId()), jAllocator);
149 jObject.AddMember(
"tx", Value(translation.getX()), jAllocator);
150 jObject.AddMember(
"ty", Value(translation.getY()), jAllocator);
151 jObject.AddMember(
"tz", Value(translation.getZ()), jAllocator);
152 jObject.AddMember(
"sx", Value(scale.getX()), jAllocator);
153 jObject.AddMember(
"sy", Value(scale.getY()), jAllocator);
154 jObject.AddMember(
"sz", Value(scale.getZ()), jAllocator);
155 jObject.AddMember(
"rx", Value(rotationAroundXAxis.getAngle()), jAllocator);
156 jObject.AddMember(
"ry", Value(rotationAroundYAxis.getAngle()), jAllocator);
157 jObject.AddMember(
"rz", Value(rotationAroundZAxis.getAngle()), jAllocator);
158 jObject.AddMember(
"r", Value(sceneEntity->getReflectionEnvironmentMappingId(), jAllocator), jAllocator);
159 Value jEntityProperties;
160 jEntityProperties.SetArray();
161 for (
auto i = 0; i < sceneEntity->getPropertyCount(); i++) {
162 auto sceneEntityProperty = sceneEntity->getPropertyByIndex(i);
163 Value jSceneEntityProperty;
164 jSceneEntityProperty.SetObject();
165 jSceneEntityProperty.AddMember(
"name", Value(sceneEntityProperty->getName(), jAllocator), jAllocator);
166 jSceneEntityProperty.AddMember(
"value", Value(sceneEntityProperty->getValue(), jAllocator), jAllocator);
167 jEntityProperties.PushBack(jSceneEntityProperty, jAllocator);
169 jObject.AddMember(
"properties", jEntityProperties, jAllocator);
170 jObjects.PushBack(jObject, jAllocator);
172 jDocument.AddMember(
"objects", jObjects, jAllocator);
173 jDocument.AddMember(
"objects_eidx", Value(scene->
getEntityIdx()), jAllocator);
181 jDocument.AddMember(
"sky", jSky, jAllocator);
184 Writer<StringBuffer> writer(strbuf);
185 jDocument.Accept(writer);
187 FileSystem::getInstance()->setContentFromString(pathName, fileName, strbuf.GetString());
Represents rotation orders of a model.
int32_t getAxisXIndex() const
int32_t getAxisYIndex() const
int32_t getAxisZIndex() const
BaseProperty * getPropertyByIndex(int idx)
Get property by index.
Base property model class.
Transformations & getTransformations()
Scene prototype library definition.
const Vector3 & getSkyModelScale()
void setFileName(const string &fileName)
Set up scene file name including relative path.
SceneLibrary * getLibrary()
RotationOrder * getRotationOrder()
SceneLight * getLightAt(int i)
Get light at given index.
SceneEntity * getEntityAt(int idx)
Returns entity at given index.
const string & getSkyModelFileName()
File system singleton class.
const string & getName() const