TDME2 1.9.121
PrototypeReader.cpp
Go to the documentation of this file.
2
3#include <string>
4
5#include <tdme/tdme.h>
36#include <tdme/math/Vector3.h>
49
50#include <ext/rapidjson/document.h>
51
52using std::string;
53
98
99using rapidjson::Document;
100using rapidjson::Value;
101
102vector<string> PrototypeReader::extensions = {"tenvmap", "tmodel", "tparticle", "tterrain", "ttrigger"};
103
104const vector<string>& PrototypeReader::getPrototypeExtensions() {
105 return extensions;
106}
107
108bool PrototypeReader::readThumbnail(const string& pathName, const string& fileName, vector<uint8_t>& pngData) {
109 try {
110 auto jsonContent = FileSystem::getInstance()->getContentAsString(pathName, fileName);
111
112 Document jPrototypeRoot;
113 jPrototypeRoot.Parse(jsonContent.c_str());
114
115 string thumbnail = jPrototypeRoot.FindMember("thumbnail") != jPrototypeRoot.MemberEnd()?jPrototypeRoot["thumbnail"].GetString():"";
116 if (thumbnail.empty() == true) return false;
117
118 Base64::decode(thumbnail, pngData);
119
120 return true;
121 } catch (Exception& exception) {
122 Console::println("PrototypeReader::readThumbnail(): An error occurred: " + pathName + "/" + fileName + ": " + exception.what());
123 return false;
124 }
125}
126
127Prototype* PrototypeReader::read(int id, const string& pathName, const string& fileName, PrototypeTransformFilter* transformFilter)
128{
129 auto jsonContent = FileSystem::getInstance()->getContentAsString(pathName, fileName);
130
131 Document jPrototypeRoot;
132 jPrototypeRoot.Parse(jsonContent.c_str());
133
134 auto prototype = read(id, pathName, jPrototypeRoot, transformFilter);
135 prototype->setFileName((pathName.empty() == false?pathName + "/":"") + fileName);
136 return prototype;
137}
138
139Prototype* PrototypeReader::read(int id, const string& pathName, Value& jPrototypeRoot, PrototypeTransformFilter* transformFilter)
140{
141 //
142 Prototype* prototype = nullptr;
143 auto pivot = Vector3(
144 static_cast<float>(jPrototypeRoot["px"].GetFloat()),
145 static_cast<float>(jPrototypeRoot["py"].GetFloat()),
146 static_cast<float>(jPrototypeRoot["pz"].GetFloat())
147 );
148 auto prototypeType = Prototype_Type::valueOf(jPrototypeRoot["type"].GetString());
149 auto thumbnail = jPrototypeRoot.FindMember("thumbnail") != jPrototypeRoot.MemberEnd()?jPrototypeRoot["thumbnail"].GetString():"";
150 auto name = (jPrototypeRoot["name"].GetString());
151 auto description = (jPrototypeRoot["descr"].GetString());
152 string modelFileName = "";
153 string modelPathName = "";
154 if (jPrototypeRoot.FindMember("file") != jPrototypeRoot.MemberEnd()) {
155 modelFileName = jPrototypeRoot["file"].GetString();
156 }
157 BaseProperties properties(name, description);
158 auto jProperties = jPrototypeRoot["properties"].GetArray();
159 for (auto i = 0; i < jProperties.Size(); i++) {
160 auto& jProperty = jProperties[i];
161 properties.addProperty(
162 (jProperty["name"].GetString()),
163 (jProperty["value"].GetString())
164 );
165 }
166 if (transformFilter != nullptr && transformFilter->filterEmptyTransform(properties) == true) {
167 prototypeType = Prototype_Type::EMPTY;
168 }
169 Model* model = nullptr;
170 if (prototypeType == Prototype_Type::EMPTY) {
171 model = ModelReader::read("resources/engine/models", "empty.tm");
172 } else
173 if (modelFileName.length() > 0) {
174 modelPathName = getResourcePathName(pathName, modelFileName);
175 model = ModelReader::read(
176 modelPathName,
177 FileSystem::getInstance()->getFileName(modelFileName)
178 );
179 }
180 prototype = new Prototype(
181 id,
182 prototypeType,
183 name,
184 description,
185 string(),
186 modelFileName.length() > 0?modelPathName + "/" + FileSystem::getInstance()->getFileName(modelFileName):"",
187 thumbnail,
188 model,
189 pivot
190 );
191 //
192 for (auto i = 0; i < properties.getPropertyCount(); i++) {
193 auto property = properties.getPropertyByIndex(i);
194 prototype->addProperty(property->getName(), property->getValue());
195 }
196 if (jPrototypeRoot.FindMember("bv") != jPrototypeRoot.MemberEnd()) {
197 auto boundingVolume = parseBoundingVolume(
198 0,
199 prototype,
200 pathName,
201 jPrototypeRoot["bv"]
202 );
203 if (boundingVolume->getBoundingVolume() != nullptr) prototype->addBoundingVolume(0, boundingVolume);
204 } else
205 if (jPrototypeRoot.FindMember("bvs") != jPrototypeRoot.MemberEnd()) {
206 auto jBoundingVolumes = jPrototypeRoot["bvs"].GetArray();
207 auto bvIdx = 0;
208 for (auto i = 0; i < jBoundingVolumes.Size(); i++) {
209 auto boundingVolume = parseBoundingVolume(bvIdx, prototype, pathName, jBoundingVolumes[i]);
210 if (boundingVolume->getBoundingVolume() != nullptr) prototype->addBoundingVolume(bvIdx++, boundingVolume);
211 }
212 }
213 if (jPrototypeRoot.FindMember("p") != jPrototypeRoot.MemberEnd() && prototype->getPhysics() != nullptr) {
214 auto physics = prototype->getPhysics();
215 auto& jPhysics = jPrototypeRoot["p"];
216 physics->setType(PrototypePhysics_BodyType::valueOf(jPhysics["type"].GetString()));
217 physics->setMass(static_cast<float>(jPhysics["mass"].GetFloat()));
218 physics->setRestitution(static_cast<float>(jPhysics["restitution"].GetFloat()));
219 physics->setFriction(static_cast<float>(jPhysics["friction"].GetFloat()));
220 physics->setInertiaTensor(
221 Vector3(
222 static_cast<float>(jPhysics["itx"].GetFloat()),
223 static_cast<float>(jPhysics["ity"].GetFloat()),
224 static_cast<float>(jPhysics["itz"].GetFloat())
225 )
226 );
227 }
228 if (jPrototypeRoot.FindMember("sd") != jPrototypeRoot.MemberEnd()) {
229 for (auto& jSound: jPrototypeRoot["sd"].GetArray()) {
230 auto id = jSound["i"].GetString();
231 auto sound = prototype->addSound(id);
232 if (sound == nullptr) continue;
233 sound->setAnimation(jSound["a"].GetString());
234 sound->setFileName(jSound["file"].GetString());
235 sound->setGain(static_cast<float>(jSound["g"].GetFloat()));
236 sound->setPitch(static_cast<float>(jSound["p"].GetFloat()));
237 sound->setOffset(static_cast<float>(jSound["o"].GetInt()));
238 sound->setLooping(jSound["l"].GetBool());
239 sound->setFixed(jSound["f"].GetBool());
240 }
241 }
242 if (prototypeType == Prototype_Type::MODEL) {
243 prototype->setTerrainMesh(jPrototypeRoot["tm"].GetBool());
244 if (jPrototypeRoot.FindMember("ll2") != jPrototypeRoot.MemberEnd()) prototype->setLODLevel2(parseLODLevel(pathName, jPrototypeRoot["ll2"]));
245 if (jPrototypeRoot.FindMember("ll3") != jPrototypeRoot.MemberEnd()) prototype->setLODLevel3(parseLODLevel(pathName, jPrototypeRoot["ll3"]));
246 if (jPrototypeRoot.FindMember("ll3") != jPrototypeRoot.MemberEnd()) prototype->setLODLevel3(parseLODLevel(pathName, jPrototypeRoot["ll3"]));
247 if (jPrototypeRoot.FindMember("il") != jPrototypeRoot.MemberEnd()) prototype->setImposterLOD(parseImposterLODLevel(pathName, jPrototypeRoot["il"]));
248 } else
249 if (prototypeType == Prototype_Type::PARTICLESYSTEM) {
250 if (jPrototypeRoot.FindMember("ps") != jPrototypeRoot.MemberEnd()) {
251 prototype->addParticleSystem();
252 parseParticleSystem(prototype->getParticleSystemAt(0), pathName, jPrototypeRoot["ps"]);
253 } else
254 if (jPrototypeRoot.FindMember("pss") != jPrototypeRoot.MemberEnd()) {
255 auto jParticleSystems = jPrototypeRoot["pss"].GetArray();
256 for (auto i = 0; i < jParticleSystems.Size(); i++) {
257 prototype->addParticleSystem();
258 parseParticleSystem(prototype->getParticleSystemAt(prototype->getParticleSystemsCount() - 1), pathName, jParticleSystems[i]);
259 }
260 }
261 }
262 if (jPrototypeRoot.FindMember("ds") != jPrototypeRoot.MemberEnd()) {
263 prototype->setContributesShadows(jPrototypeRoot["ds"].GetBool());
264 prototype->setReceivesShadows(jPrototypeRoot["ds"].GetBool());
265 } else
266 if (jPrototypeRoot.FindMember("cs") != jPrototypeRoot.MemberEnd() && jPrototypeRoot.FindMember("rs") != jPrototypeRoot.MemberEnd()) {
267 prototype->setContributesShadows(jPrototypeRoot["cs"].GetBool());
268 prototype->setReceivesShadows(jPrototypeRoot["rs"].GetBool());
269 }
270 prototype->setRenderGroups(jPrototypeRoot.FindMember("rg") != jPrototypeRoot.MemberEnd()?jPrototypeRoot["rg"].GetBool():false);
271 prototype->setShader(jPrototypeRoot.FindMember("s") != jPrototypeRoot.MemberEnd()?jPrototypeRoot["s"].GetString():"default");
272 prototype->setDistanceShader(jPrototypeRoot.FindMember("sds") != jPrototypeRoot.MemberEnd()?jPrototypeRoot["sds"].GetString():"default");
273 prototype->setDistanceShaderDistance(jPrototypeRoot.FindMember("sdsd") != jPrototypeRoot.MemberEnd()?static_cast<float>(jPrototypeRoot["sdsd"].GetFloat()):10000.0f);
274 if (jPrototypeRoot.FindMember("sps") != jPrototypeRoot.MemberEnd()) {
275 Value& jShaderParameters = jPrototypeRoot["sps"];
276 EntityShaderParameters shaderParameters;
277 shaderParameters.setShader(prototype->getShader());
278 for (auto jShaderParameterIt = jShaderParameters.MemberBegin(); jShaderParameterIt != jShaderParameters.MemberEnd(); ++jShaderParameterIt) {
279 shaderParameters.setShaderParameter(jShaderParameterIt->name.GetString(), string(jShaderParameterIt->value.GetString()));
280 }
281 prototype->setShaderParameters(shaderParameters);
282 }
283 if (jPrototypeRoot.FindMember("spds") != jPrototypeRoot.MemberEnd()) {
284 Value& jDistanceShaderParameters = jPrototypeRoot["spds"];
285 EntityShaderParameters distanceShaderParameters;
286 distanceShaderParameters.setShader(prototype->getDistanceShader());
287 for (auto jDistanceShaderParameterIt = jDistanceShaderParameters.MemberBegin(); jDistanceShaderParameterIt != jDistanceShaderParameters.MemberEnd(); ++jDistanceShaderParameterIt) {
288 distanceShaderParameters.setShaderParameter(jDistanceShaderParameterIt->name.GetString(), string(jDistanceShaderParameterIt->value.GetString()));
289 }
290 prototype->setDistanceShaderParameters(distanceShaderParameters);
291 }
292 if (prototype->getType() == Prototype_Type::ENVIRONMENTMAPPING) {
293 prototype->setEnvironmentMapRenderPassMask(jPrototypeRoot["emrpm"].GetInt());
294 prototype->setEnvironmentMapTimeRenderUpdateFrequency(jPrototypeRoot["emtf"].GetInt64());
295 }
296 //
297 if (prototype->getModel() != nullptr) ModelTools::prepareForShader(prototype->getModel(), prototype->getShader());
298
299 //
300 if (prototype->getType() == Prototype_Type::TERRAIN) {
301 auto terrain = prototype->getTerrain();
302 Value& jTerrain = jPrototypeRoot["t"];
303 {
304 terrain->setWidth(jTerrain["w"].GetFloat());
305 terrain->setDepth(jTerrain["d"].GetFloat());
306 auto jTerrainValues = jTerrain["t"].GetArray();
307 for (auto i = 0; i < jTerrainValues.Size(); i++) terrain->getHeightVector().push_back(jTerrainValues[i].GetFloat());
308 }
309 {
310 auto jWaterPositionMapsArray = jTerrain["W"].GetArray();
311 for (auto i = 0; i < jWaterPositionMapsArray.Size(); i++) {
312 auto waterPositionMapIdx = terrain->allocateWaterPositionMapIdx();
313 auto& jWaterPositionMap = jWaterPositionMapsArray[i];
314 auto& jWaterPositionMapData = jWaterPositionMap["w"];
315 terrain->setWaterPositionMapHeight(waterPositionMapIdx, jWaterPositionMap["h"].GetFloat());
316 for (auto jWaterPositionMapDataIt = jWaterPositionMapData.MemberBegin(); jWaterPositionMapDataIt != jWaterPositionMapData.MemberEnd(); ++jWaterPositionMapDataIt) {
317 auto z = Integer::parse(jWaterPositionMapDataIt->name.GetString());
318 auto xArray = jWaterPositionMapDataIt->value.GetArray();
319 for (auto j = 0; j < xArray.Size(); j++) {
320 auto x = xArray[j].GetFloat();
321 terrain->getWaterPositionMap(waterPositionMapIdx)[z].insert(x);
322 }
323 }
324 }
325 }
326 {
327 //
328 auto partitionsX = static_cast<int>(Math::ceil(terrain->getWidth() / Terrain2::PARTITION_SIZE));
329 auto partitionsZ = static_cast<int>(Math::ceil(terrain->getDepth() / Terrain2::PARTITION_SIZE));
330
331 //
332 auto& foliageMaps = prototype->getTerrain()->getFoliageMaps();
333 Terrain2::createFoliageMaps(terrain->getWidth(), terrain->getDepth(), foliageMaps);
334 auto& jFoliage = jTerrain["f"];
335 for (auto jFoliagePrototypeIt = jFoliage.MemberBegin(); jFoliagePrototypeIt != jFoliage.MemberEnd(); ++jFoliagePrototypeIt) {
336 auto& jFoliagePrototype = jFoliage[jFoliagePrototypeIt->name.GetString()];
337 auto jFoliagePrototypePartitions = jFoliagePrototype["t"].GetArray();
338
339
340 //
341 Prototype* foliagePrototype = nullptr;
342 try {
343 auto foliagePrototypeFileName = jFoliagePrototype["f"].GetString();
344 foliagePrototype = PrototypeReader::read(
345 getResourcePathName(pathName, foliagePrototypeFileName),
346 FileSystem::getInstance()->getFileName(foliagePrototypeFileName)
347 );
348 } catch (Exception& exception) {
349 Console::println(string("PrototypeReader::read(): An error occurred: ") + exception.what());
350 continue;
351 }
352
353 //
354 auto foliagePrototypeIndex = prototype->getTerrain()->getFoliagePrototypeIndex(foliagePrototype);
355
356 //
357 for (auto foliagePrototypePartitionIdx = 0; foliagePrototypePartitionIdx < jFoliagePrototypePartitions.Size(); foliagePrototypePartitionIdx++) {
358 //
359 auto partitionX = foliagePrototypePartitionIdx % partitionsX;
360 auto partitionZ = foliagePrototypePartitionIdx / partitionsX;
361
362 //
363 auto jFoliagePrototypePartitionTransformations = jFoliagePrototypePartitions[foliagePrototypePartitionIdx].GetArray();
364 auto& foliagePrototypePartitionTransformations = foliageMaps[foliagePrototypePartitionIdx][foliagePrototypeIndex];
365 for (auto jFoliagePrototypePartitionTransformationsIdx = 0; jFoliagePrototypePartitionTransformationsIdx < jFoliagePrototypePartitionTransformations.Size(); jFoliagePrototypePartitionTransformationsIdx++) {
366 Value& jFoliagePrototypeTransformations = jFoliagePrototypePartitionTransformations[jFoliagePrototypePartitionTransformationsIdx];
367 Transformations foliagePrototypeTransformations;
368 foliagePrototypeTransformations.setTranslation(
369 Vector3(
370 jFoliagePrototypeTransformations["tx"].GetFloat(),
371 jFoliagePrototypeTransformations["ty"].GetFloat(),
372 jFoliagePrototypeTransformations["tz"].GetFloat()
373 )
374 );
375 foliagePrototypeTransformations.addRotation(Rotation::Z_AXIS, jFoliagePrototypeTransformations["rz"].GetFloat());
376 foliagePrototypeTransformations.addRotation(Rotation::Y_AXIS, jFoliagePrototypeTransformations["ry"].GetFloat());
377 foliagePrototypeTransformations.addRotation(Rotation::X_AXIS, jFoliagePrototypeTransformations["rx"].GetFloat());
378 foliagePrototypeTransformations.setScale(
379 Vector3(
380 jFoliagePrototypeTransformations["sx"].GetFloat(),
381 jFoliagePrototypeTransformations["sy"].GetFloat(),
382 jFoliagePrototypeTransformations["sz"].GetFloat()
383 )
384 );
385 foliagePrototypeTransformations.update();
386 foliagePrototypePartitionTransformations.push_back(foliagePrototypeTransformations);
387 auto partitionLeft = partitionX * Terrain2::PARTITION_SIZE;
388 auto partitionTop = partitionZ * Terrain2::PARTITION_SIZE;
389 auto partitionRight = partitionX * Terrain2::PARTITION_SIZE + Terrain2::PARTITION_SIZE;
390 auto partitionBottom = partitionZ * Terrain2::PARTITION_SIZE + Terrain2::PARTITION_SIZE;
391 // just some debugging output if foliage is not in correct partition
392 if (foliagePrototypeTransformations.getTranslation().getX() < partitionLeft ||
393 foliagePrototypeTransformations.getTranslation().getZ() < partitionTop ||
394 foliagePrototypeTransformations.getTranslation().getX() > partitionRight ||
395 foliagePrototypeTransformations.getTranslation().getZ() > partitionBottom) {
396 Console::println(
397 "PrototypeReader::read(): foliage entity not in partition: " +
398 to_string(foliagePrototypeTransformations.getTranslation().getX()) + ", " + to_string(foliagePrototypeTransformations.getTranslation().getZ()) + " ! in " +
399 to_string(partitionLeft) + ", " + to_string(partitionTop) + ", " +
400 to_string(partitionRight) + ", " + to_string(partitionBottom)
401 );
402 }
403 }
404 }
405 }
406 }
407 {
408 auto jBrushesArray = jTerrain["b"].GetArray();
409 for (auto i = 0; i < jBrushesArray.Size(); i++) {
410 auto& jBrush = jBrushesArray[i];
411 auto brush = terrain->addBrush();
412 brush->setFileName(jBrush["f"].GetString());
413 brush->setSize(jBrush["s"].GetFloat());
414 brush->setDensity(jBrush["d"].GetFloat());
415 auto jPrototypeArray = jBrush["p"].GetArray();
416 for (auto i = 0; i < jPrototypeArray.Size(); i++) {
417 auto& jPrototype = jPrototypeArray[i];
418 auto prototype = brush->addPrototype();
419 prototype->setFileName(jPrototype["f"].GetString());
420 prototype->setCount(jPrototype["c"].GetFloat());
421 prototype->setNormalAlign(jPrototype["n"].GetBool());
422 prototype->setRotationXMin(jPrototype["xi"].GetFloat());
423 prototype->setRotationXMax(jPrototype["xa"].GetFloat());
424 prototype->setRotationYMin(jPrototype["yi"].GetFloat());
425 prototype->setRotationYMax(jPrototype["ya"].GetFloat());
426 prototype->setRotationZMin(jPrototype["zi"].GetFloat());
427 prototype->setRotationZMax(jPrototype["za"].GetFloat());
428 prototype->setScaleMin(jPrototype["si"].GetFloat());
429 prototype->setScaleMax(jPrototype["sa"].GetFloat());
430 prototype->setHeightMin(jPrototype["hi"].GetFloat());
431 prototype->setHeightMax(jPrototype["ha"].GetFloat());
432 prototype->setSlopeMin(jPrototype["li"].GetFloat());
433 prototype->setSlopeMax(jPrototype["la"].GetFloat());
434 }
435 }
436 }
437 }
438
439 //
440 return prototype;
441}
442
443const string PrototypeReader::getResourcePathName(const string& pathName, const string& fileName) {
444 string resourceFile = FileSystem::getInstance()->getCanonicalPath(
445 StringTools::startsWith(FileSystem::getInstance()->getPathName(fileName), "/") == true?
446 FileSystem::getInstance()->getPathName(fileName):
447 pathName + "/" + FileSystem::getInstance()->getPathName(fileName),
448 FileSystem::getInstance()->getFileName(fileName)
449 );
450 auto applicationRoot = Tools::getApplicationRootPathName(pathName);
451 auto resourceRelativeFileName = Tools::getRelativeResourcesFileName(applicationRoot, resourceFile);
452 auto resourcePathName = (applicationRoot.empty() == false?applicationRoot + "/":"") + Tools::getPathName(resourceRelativeFileName);
453 return resourcePathName;
454}
455
456PrototypeBoundingVolume* PrototypeReader::parseBoundingVolume(int idx, Prototype* prototype, const string& pathName, Value& jBv)
457{
458 auto prototypeBoundingVolume = new PrototypeBoundingVolume(idx, prototype);
459 BoundingVolume* bv;
460 auto bvTypeString = (jBv["type"].GetString());
461 if (StringTools::equalsIgnoreCase(bvTypeString, "none") == true) {
462 prototypeBoundingVolume->setupNone();
463 } else
464 if (StringTools::equalsIgnoreCase(bvTypeString, "sphere") == true) {
465 prototypeBoundingVolume->setupSphere(
466 Vector3(
467 static_cast<float>(jBv["cx"].GetFloat()),
468 static_cast<float>(jBv["cy"].GetFloat()),
469 static_cast<float>(jBv["cz"].GetFloat())
470 ),
471 static_cast<float>(jBv["r"].GetFloat())
472 );
473 } else
474 if (StringTools::equalsIgnoreCase(bvTypeString, "capsule") == true) {
475 prototypeBoundingVolume->setupCapsule(
476 Vector3(
477 static_cast<float>(jBv["ax"].GetFloat()),
478 static_cast<float>(jBv["ay"].GetFloat()),
479 static_cast<float>(jBv["az"].GetFloat())
480 ),
481 Vector3(
482 static_cast<float>(jBv["bx"].GetFloat()),
483 static_cast<float>(jBv["by"].GetFloat()),
484 static_cast<float>(jBv["bz"].GetFloat())
485 ),
486 static_cast<float>(jBv["r"].GetFloat())
487 );
488 } else
489 if (StringTools::equalsIgnoreCase(bvTypeString, "aabb") == true) {
490 prototypeBoundingVolume->setupAabb(
491 Vector3(
492 static_cast<float>(jBv["mix"].GetFloat()),
493 static_cast<float>(jBv["miy"].GetFloat()),
494 static_cast<float>(jBv["miz"].GetFloat())
495 ),
496 Vector3(
497 static_cast<float>(jBv["max"].GetFloat()),
498 static_cast<float>(jBv["may"].GetFloat()),
499 static_cast<float>(jBv["maz"].GetFloat())
500 )
501 );
502 } else
503 if (StringTools::equalsIgnoreCase(bvTypeString, "obb") == true) {
504 prototypeBoundingVolume->setupObb(
505 Vector3(
506 static_cast<float>(jBv["cx"].GetFloat()),
507 static_cast<float>(jBv["cy"].GetFloat()),
508 static_cast<float>(jBv["cz"].GetFloat())
509 ),
510 Vector3(
511 static_cast<float>(jBv["a0x"].GetFloat()),
512 static_cast<float>(jBv["a0y"].GetFloat()),
513 static_cast<float>(jBv["a0z"].GetFloat())
514 ),
515 Vector3(
516 static_cast<float>(jBv["a1x"].GetFloat()),
517 static_cast<float>(jBv["a1y"].GetFloat()),
518 static_cast<float>(jBv["a1z"].GetFloat())
519 ),
520 Vector3(
521 static_cast<float>(jBv["a2x"].GetFloat()),
522 static_cast<float>(jBv["a2y"].GetFloat()),
523 static_cast<float>(jBv["a2z"].GetFloat())
524 ),
525 Vector3(
526 static_cast<float>(jBv["hex"].GetFloat()),
527 static_cast<float>(jBv["hey"].GetFloat()),
528 static_cast<float>(jBv["hez"].GetFloat())
529 )
530 );
531 } else
532 if (StringTools::equalsIgnoreCase(bvTypeString, "convexmesh") == true) {
533 try {
534 string data = jBv.FindMember("data") != jBv.MemberEnd()?jBv["data"].GetString():string();
535 if (data.empty() == false) {
536 vector<uint8_t> tmData;
537 Base64::decode(data, tmData);
538 prototypeBoundingVolume->setupConvexMesh(tmData);
539 } else {
540 string fileName = jBv["file"].GetString();
541 prototypeBoundingVolume->setupConvexMesh(
542 getResourcePathName(pathName, fileName),
543 Tools::getFileName(fileName)
544 );
545 }
546 } catch (Exception& exception) {
547 Console::print(string("PrototypeReader::parseBoundingVolume(): An error occurred: "));
548 Console::println(string(exception.what()));
549 }
550 }
551 if (jBv.FindMember("g") != jBv.MemberEnd()) prototypeBoundingVolume->setGenerated(jBv["g"].GetBool());
552 return prototypeBoundingVolume;
553}
554
555PrototypeLODLevel* PrototypeReader::parseLODLevel(const string& pathName, Value& jLodLevel) {
556 auto lodType = static_cast<LODObject3D::LODLevelType>(jLodLevel["t"].GetInt());
557 auto lodLevel = new PrototypeLODLevel(
558 lodType,
559 lodType == LODObject3D::LODLEVELTYPE_MODEL?jLodLevel["f"].GetString():"",
560 nullptr,
561 static_cast<float>(jLodLevel["d"].GetFloat())
562 );
563 if (lodType == LODObject3D::LODLEVELTYPE_MODEL) {
564 auto modelFileName = lodLevel->getFileName();
565 auto modelPathName = getResourcePathName(pathName, modelFileName);
566 lodLevel->setModel(
567 ModelReader::read(
568 modelPathName,
569 FileSystem::getInstance()->getFileName(modelFileName)
570 )
571 );
572 lodLevel->setFileName(modelPathName + "/" + FileSystem::getInstance()->getFileName(modelFileName));
573 }
574 lodLevel->setColorAdd(
575 Color4(
576 static_cast<float>(jLodLevel["car"].GetFloat()),
577 static_cast<float>(jLodLevel["cag"].GetFloat()),
578 static_cast<float>(jLodLevel["cab"].GetFloat()),
579 static_cast<float>(jLodLevel["caa"].GetFloat())
580 )
581 );
582 lodLevel->setColorMul(
583 Color4(
584 static_cast<float>(jLodLevel["cmr"].GetFloat()),
585 static_cast<float>(jLodLevel["cmg"].GetFloat()),
586 static_cast<float>(jLodLevel["cmb"].GetFloat()),
587 static_cast<float>(jLodLevel["cma"].GetFloat())
588 )
589 );
590 return lodLevel;
591}
592
593PrototypeImposterLOD* PrototypeReader::parseImposterLODLevel(const string& pathName, Value& jImposterLOD) {
594 auto imposterLOD = new PrototypeImposterLOD(
595 {},
596 {},
597 static_cast<float>(jImposterLOD["d"].GetFloat())
598 );
599
600 //
601 vector<string> fileNames;
602 vector<Model*> models;
603 auto jFilesArray = jImposterLOD["f"].GetArray();
604 for (auto i = 0; i < jFilesArray.Size(); i++) {
605 auto fileName = jFilesArray[i].GetString();
606 auto modelFileName = fileName;
607 auto modelPathName = getResourcePathName(pathName, modelFileName);
608 models.push_back(
609 ModelReader::read(
610 modelPathName,
611 FileSystem::getInstance()->getFileName(modelFileName)
612 )
613 );
614 fileNames.push_back(fileName);
615 }
616
617 //
618 imposterLOD->setModels(models);
619 imposterLOD->setFileNames(fileNames);
620
621 //
622 imposterLOD->setColorAdd(
623 Color4(
624 static_cast<float>(jImposterLOD["car"].GetFloat()),
625 static_cast<float>(jImposterLOD["cag"].GetFloat()),
626 static_cast<float>(jImposterLOD["cab"].GetFloat()),
627 static_cast<float>(jImposterLOD["caa"].GetFloat())
628 )
629 );
630 imposterLOD->setColorMul(
631 Color4(
632 static_cast<float>(jImposterLOD["cmr"].GetFloat()),
633 static_cast<float>(jImposterLOD["cmg"].GetFloat()),
634 static_cast<float>(jImposterLOD["cmb"].GetFloat()),
635 static_cast<float>(jImposterLOD["cma"].GetFloat())
636 )
637 );
638 return imposterLOD;
639}
640
641void PrototypeReader::parseParticleSystem(PrototypeParticleSystem* particleSystem, const string& pathName, Value& jParticleSystem) {
642 particleSystem->setType(PrototypeParticleSystem_Type::valueOf((jParticleSystem["t"].GetString())));
643 {
644 auto v = particleSystem->getType();
645 if (v == PrototypeParticleSystem_Type::NONE) {
646 // no op
647 } else
648 if (v == PrototypeParticleSystem_Type::OBJECT_PARTICLE_SYSTEM) {
649 auto& jObjectParticleSystem = jParticleSystem["ops"];
650 auto objectParticleSystem = particleSystem->getObjectParticleSystem();
651 objectParticleSystem->setMaxCount(jObjectParticleSystem["mc"].GetInt());
652 objectParticleSystem->setScale(
653 Vector3(
654 static_cast<float>(jObjectParticleSystem["sx"].GetFloat()),
655 static_cast<float>(jObjectParticleSystem["sy"].GetFloat()),
656 static_cast<float>(jObjectParticleSystem["sz"].GetFloat())
657 )
658 );
659 objectParticleSystem->setAutoEmit(jObjectParticleSystem["ae"].GetBool());
660 try {
661 auto particleModelFile = (jObjectParticleSystem["mf"].GetString());
662 auto particleModelPath = getResourcePathName(pathName, particleModelFile);
663 objectParticleSystem->setModelFile(
664 particleModelPath + "/" + Tools::getFileName(particleModelFile)
665 );
666 } catch (Exception& exception) {
667 Console::print(string("PrototypeReader::doImport(): An error occurred: "));
668 Console::println(string(exception.what()));
669 }
670 } else
671 if (v == PrototypeParticleSystem_Type::POINT_PARTICLE_SYSTEM) {
672 auto pointParticleSystem = particleSystem->getPointParticleSystem();
673 auto& jPointParticleSystem = jParticleSystem["pps"];
674 pointParticleSystem->setMaxPoints(jPointParticleSystem["mp"].GetInt());
675 if (jPointParticleSystem.FindMember("ps") != jPointParticleSystem.MemberEnd()) pointParticleSystem->setPointSize(static_cast<float>(jPointParticleSystem["ps"].GetFloat()));
676 if (jPointParticleSystem.FindMember("t") != jPointParticleSystem.MemberEnd()) {
677 try {
678 auto particleTextureFileName = jPointParticleSystem["t"].GetString();
679 auto particleTexturePathName = getResourcePathName(pathName, particleTextureFileName);
680 auto particleTransparencyTextureFileName = string(jPointParticleSystem.FindMember("tt") != jPointParticleSystem.MemberEnd()?jPointParticleSystem["tt"].GetString():"");
681 auto particleTransparencyTexturePathName = particleTransparencyTextureFileName.size() == 0?string():getResourcePathName(pathName, particleTransparencyTextureFileName);
682 pointParticleSystem->setTextureFileName(
683 particleTexturePathName + "/" + Tools::getFileName(particleTextureFileName),
684 particleTransparencyTextureFileName.size() == 0?string():particleTransparencyTexturePathName + "/" + Tools::getFileName(particleTransparencyTextureFileName)
685 );
686 if (jPointParticleSystem.FindMember("ths") != jPointParticleSystem.MemberEnd()) pointParticleSystem->setTextureHorizontalSprites(jPointParticleSystem["ths"].GetInt());
687 if (jPointParticleSystem.FindMember("tvs") != jPointParticleSystem.MemberEnd()) pointParticleSystem->setTextureVerticalSprites(jPointParticleSystem["tvs"].GetInt());
688 if (jPointParticleSystem.FindMember("fps") != jPointParticleSystem.MemberEnd()) pointParticleSystem->setTextureSpritesFPS(jPointParticleSystem["fps"].GetFloat());
689 } catch (Exception& exception) {
690 Console::print(string("PrototypeReader::doImport(): An error occurred: "));
691 Console::println(string(exception.what()));
692 }
693 }
694 pointParticleSystem->setAutoEmit(jPointParticleSystem["ae"].GetBool());
695 } else
696 if (v == PrototypeParticleSystem_Type::FOG_PARTICLE_SYSTEM) {
697 auto fogParticleSystem = particleSystem->getFogParticleSystem();
698 auto& jFogParticleSystem = jParticleSystem["fps"];
699 fogParticleSystem->setMaxPoints(jFogParticleSystem["mp"].GetInt());
700 if (jFogParticleSystem.FindMember("ps") != jFogParticleSystem.MemberEnd()) fogParticleSystem->setPointSize(static_cast<float>(jFogParticleSystem["ps"].GetFloat()));
701 if (jFogParticleSystem.FindMember("t") != jFogParticleSystem.MemberEnd()) {
702 try {
703 auto particleTextureFileName = jFogParticleSystem["t"].GetString();
704 auto particleTexturePathName = getResourcePathName(pathName, particleTextureFileName);
705 auto particleTransparencyTextureFileName = jFogParticleSystem.FindMember("tt") != jFogParticleSystem.MemberEnd()?string():jFogParticleSystem["tt"].GetString();
706 auto particleTransparencyTexturePathName = particleTransparencyTextureFileName.size() == 0?string():getResourcePathName(pathName, particleTransparencyTextureFileName);
707 fogParticleSystem->setTextureFileName(
708 particleTexturePathName + "/" + Tools::getFileName(particleTextureFileName),
709 particleTransparencyTextureFileName.size() == 0?string():particleTransparencyTexturePathName + "/" + Tools::getFileName(particleTransparencyTextureFileName)
710 );
711 if (jFogParticleSystem.FindMember("ths") != jFogParticleSystem.MemberEnd()) fogParticleSystem->setTextureHorizontalSprites(jFogParticleSystem["ths"].GetInt());
712 if (jFogParticleSystem.FindMember("tvs") != jFogParticleSystem.MemberEnd()) fogParticleSystem->setTextureVerticalSprites(jFogParticleSystem["tvs"].GetInt());
713 if (jFogParticleSystem.FindMember("fps") != jFogParticleSystem.MemberEnd()) fogParticleSystem->setTextureSpritesFPS(jFogParticleSystem["fps"].GetFloat());
714 } catch (Exception& exception) {
715 Console::print(string("PrototypeReader::doImport(): An error occurred: "));
716 Console::println(string(exception.what()));
717 }
718 }
719 } else {
720 Console::println(
721 string(
722 "PrototypeWriter::export(): unknown particle system type '" +
723 particleSystem->getType()->getName() +
724 "'"
725 )
726 );
727 }
728 }
729
730 particleSystem->setEmitter(PrototypeParticleSystem_Emitter::valueOf((jParticleSystem["e"].GetString())));
731 {
732 auto v = particleSystem->getEmitter();
733 if (v == PrototypeParticleSystem_Emitter::NONE) {
734 // no op
735 } else
736 if (v == PrototypeParticleSystem_Emitter::POINT_PARTICLE_EMITTER) {
737 auto& jPointParticleEmitter = jParticleSystem["ppe"];
738 auto emitter = particleSystem->getPointParticleEmitter();
739 emitter->setCount(jPointParticleEmitter["c"].GetInt());
740 emitter->setLifeTime(jPointParticleEmitter["lt"].GetInt());
741 emitter->setLifeTimeRnd(jPointParticleEmitter["ltrnd"].GetInt());
742 emitter->setMass(static_cast<float>(jPointParticleEmitter["m"].GetFloat()));
743 emitter->setMassRnd(static_cast<float>(jPointParticleEmitter["mrnd"].GetFloat()));
744 emitter->setPosition(
745 Vector3(
746 static_cast<float>(jPointParticleEmitter["px"].GetFloat()),
747 static_cast<float>(jPointParticleEmitter["py"].GetFloat()),
748 static_cast<float>(jPointParticleEmitter["pz"].GetFloat())
749 )
750 );
751 emitter->setVelocity(
752 Vector3(
753 static_cast<float>(jPointParticleEmitter["vx"].GetFloat()),
754 static_cast<float>(jPointParticleEmitter["vy"].GetFloat()),
755 static_cast<float>(jPointParticleEmitter["vz"].GetFloat())
756 )
757 );
758 emitter->setVelocityRnd(
759 Vector3(
760 static_cast<float>(jPointParticleEmitter["vrndx"].GetFloat()),
761 static_cast<float>(jPointParticleEmitter["vrndy"].GetFloat()),
762 static_cast<float>(jPointParticleEmitter["vrndz"].GetFloat())
763 )
764 );
765 emitter->setColorStart(
766 Color4(
767 static_cast<float>(jPointParticleEmitter["csr"].GetFloat()),
768 static_cast<float>(jPointParticleEmitter["csg"].GetFloat()),
769 static_cast<float>(jPointParticleEmitter["csb"].GetFloat()),
770 static_cast<float>(jPointParticleEmitter["csa"].GetFloat())
771 )
772 );
773 emitter->setColorEnd(
774 Color4(
775 static_cast<float>(jPointParticleEmitter["cer"].GetFloat()),
776 static_cast<float>(jPointParticleEmitter["ceg"].GetFloat()),
777 static_cast<float>(jPointParticleEmitter["ceb"].GetFloat()),
778 static_cast<float>(jPointParticleEmitter["cea"].GetFloat())
779 )
780 );
781 } else
782 if (v == PrototypeParticleSystem_Emitter::BOUNDINGBOX_PARTICLE_EMITTER) {
783 auto& jBoundingBoxParticleEmitter = jParticleSystem["bbpe"];
784 auto emitter = particleSystem->getBoundingBoxParticleEmitters();
785 emitter->setCount(jBoundingBoxParticleEmitter["c"].GetInt());
786 emitter->setLifeTime(jBoundingBoxParticleEmitter["lt"].GetInt());
787 emitter->setLifeTimeRnd(jBoundingBoxParticleEmitter["ltrnd"].GetInt());
788 emitter->setMass(static_cast<float>(jBoundingBoxParticleEmitter["m"].GetFloat()));
789 emitter->setMassRnd(static_cast<float>(jBoundingBoxParticleEmitter["mrnd"].GetFloat()));
790 emitter->setVelocity(
791 Vector3(
792 static_cast<float>(jBoundingBoxParticleEmitter["vx"].GetFloat()),
793 static_cast<float>(jBoundingBoxParticleEmitter["vy"].GetFloat()),
794 static_cast<float>(jBoundingBoxParticleEmitter["vz"].GetFloat())
795 )
796 );
797 emitter->setVelocityRnd(
798 Vector3(
799 static_cast<float>(jBoundingBoxParticleEmitter["vrndx"].GetFloat()),
800 static_cast<float>(jBoundingBoxParticleEmitter["vrndy"].GetFloat()),
801 static_cast<float>(jBoundingBoxParticleEmitter["vrndz"].GetFloat())
802 )
803 );
804 emitter->setColorStart(
805 Color4(
806 static_cast<float>(jBoundingBoxParticleEmitter["csr"].GetFloat()),
807 static_cast<float>(jBoundingBoxParticleEmitter["csg"].GetFloat()),
808 static_cast<float>(jBoundingBoxParticleEmitter["csb"].GetFloat()),
809 static_cast<float>(jBoundingBoxParticleEmitter["csa"].GetFloat())
810 )
811 );
812 emitter->setColorEnd(
813 Color4(
814 static_cast<float>(jBoundingBoxParticleEmitter["cer"].GetFloat()),
815 static_cast<float>(jBoundingBoxParticleEmitter["ceg"].GetFloat()),
816 static_cast<float>(jBoundingBoxParticleEmitter["ceb"].GetFloat()),
817 static_cast<float>(jBoundingBoxParticleEmitter["cea"].GetFloat())
818 )
819 );
820 emitter->setObbCenter(
821 Vector3(
822 static_cast<float>(jBoundingBoxParticleEmitter["ocx"].GetFloat()),
823 static_cast<float>(jBoundingBoxParticleEmitter["ocy"].GetFloat()),
824 static_cast<float>(jBoundingBoxParticleEmitter["ocz"].GetFloat())
825 )
826 );
827 emitter->setObbHalfextension(
828 Vector3(
829 static_cast<float>(jBoundingBoxParticleEmitter["ohex"].GetFloat()),
830 static_cast<float>(jBoundingBoxParticleEmitter["ohey"].GetFloat()),
831 static_cast<float>(jBoundingBoxParticleEmitter["ohez"].GetFloat())
832 )
833 );
834 emitter->setObbAxis0(
835 Vector3(
836 static_cast<float>(jBoundingBoxParticleEmitter["oa0x"].GetFloat()),
837 static_cast<float>(jBoundingBoxParticleEmitter["oa0y"].GetFloat()),
838 static_cast<float>(jBoundingBoxParticleEmitter["oa0z"].GetFloat())
839 )
840 );
841 emitter->setObbAxis1(
842 Vector3(
843 static_cast<float>(jBoundingBoxParticleEmitter["oa1x"].GetFloat()),
844 static_cast<float>(jBoundingBoxParticleEmitter["oa1y"].GetFloat()),
845 static_cast<float>(jBoundingBoxParticleEmitter["oa1z"].GetFloat())
846 )
847 );
848 emitter->setObbAxis2(
849 Vector3(
850 static_cast<float>(jBoundingBoxParticleEmitter["oa2x"].GetFloat()),
851 static_cast<float>(jBoundingBoxParticleEmitter["oa2y"].GetFloat()),
852 static_cast<float>(jBoundingBoxParticleEmitter["oa2z"].GetFloat())
853 )
854 );
855 } else
856 if (v == PrototypeParticleSystem_Emitter::CIRCLE_PARTICLE_EMITTER) {
857 auto& jCircleParticleEmitter = jParticleSystem["cpe"];
858 auto emitter = particleSystem->getCircleParticleEmitter();
859 emitter->setCount(jCircleParticleEmitter["c"].GetInt());
860 emitter->setLifeTime(jCircleParticleEmitter["lt"].GetInt());
861 emitter->setLifeTimeRnd(jCircleParticleEmitter["ltrnd"].GetInt());
862 emitter->setMass(static_cast<float>(jCircleParticleEmitter["m"].GetFloat()));
863 emitter->setMassRnd(static_cast<float>(jCircleParticleEmitter["mrnd"].GetFloat()));
864 emitter->setVelocity(
865 Vector3(
866 static_cast<float>(jCircleParticleEmitter["vx"].GetFloat()),
867 static_cast<float>(jCircleParticleEmitter["vy"].GetFloat()),
868 static_cast<float>(jCircleParticleEmitter["vz"].GetFloat())
869 )
870 );
871 emitter->setVelocityRnd(
872 Vector3(
873 static_cast<float>(jCircleParticleEmitter["vrndx"].GetFloat()),
874 static_cast<float>(jCircleParticleEmitter["vrndy"].GetFloat()),
875 static_cast<float>(jCircleParticleEmitter["vrndz"].GetFloat())
876 )
877 );
878 emitter->setColorStart(
879 Color4(
880 static_cast<float>(jCircleParticleEmitter["csr"].GetFloat()),
881 static_cast<float>(jCircleParticleEmitter["csg"].GetFloat()),
882 static_cast<float>(jCircleParticleEmitter["csb"].GetFloat()),
883 static_cast<float>(jCircleParticleEmitter["csa"].GetFloat())
884 )
885 );
886 emitter->setColorEnd(
887 Color4(
888 static_cast<float>(jCircleParticleEmitter["cer"].GetFloat()),
889 static_cast<float>(jCircleParticleEmitter["ceg"].GetFloat()),
890 static_cast<float>(jCircleParticleEmitter["ceb"].GetFloat()),
891 static_cast<float>(jCircleParticleEmitter["cea"].GetFloat())
892 )
893 );
894 emitter->setCenter(
895 Vector3(
896 static_cast<float>(jCircleParticleEmitter["cx"].GetFloat()),
897 static_cast<float>(jCircleParticleEmitter["cy"].GetFloat()),
898 static_cast<float>(jCircleParticleEmitter["cz"].GetFloat())
899 )
900 );
901 emitter->setRadius(static_cast<float>(jCircleParticleEmitter["r"].GetFloat()));
902 emitter->setAxis0(
903 Vector3(
904 static_cast<float>(jCircleParticleEmitter["a0x"].GetFloat()),
905 static_cast<float>(jCircleParticleEmitter["a0y"].GetFloat()),
906 static_cast<float>(jCircleParticleEmitter["a0z"].GetFloat())
907 )
908 );
909 emitter->setAxis1(
910 Vector3(
911 static_cast<float>(jCircleParticleEmitter["a1x"].GetFloat()),
912 static_cast<float>(jCircleParticleEmitter["a1y"].GetFloat()),
913 static_cast<float>(jCircleParticleEmitter["a1z"].GetFloat())
914 )
915 );
916 } else
917 if (v == PrototypeParticleSystem_Emitter::CIRCLE_PARTICLE_EMITTER_PLANE_VELOCITY) {
918 auto& jCircleParticleEmitterPlaneVelocity = jParticleSystem["cpeev"];
919 auto emitter = particleSystem->getCircleParticleEmitterPlaneVelocity();
920 emitter->setCount(jCircleParticleEmitterPlaneVelocity["c"].GetInt());
921 emitter->setLifeTime(jCircleParticleEmitterPlaneVelocity["lt"].GetInt());
922 emitter->setLifeTimeRnd(jCircleParticleEmitterPlaneVelocity["ltrnd"].GetInt());
923 emitter->setMass(static_cast<float>(jCircleParticleEmitterPlaneVelocity["m"].GetFloat()));
924 emitter->setMassRnd(static_cast<float>(jCircleParticleEmitterPlaneVelocity["mrnd"].GetFloat()));
925 emitter->setVelocity(static_cast<float>(jCircleParticleEmitterPlaneVelocity["v"].GetFloat()));
926 emitter->setVelocityRnd(static_cast<float>(jCircleParticleEmitterPlaneVelocity["vrnd"].GetFloat()));
927 emitter->setColorStart(
928 Color4(
929 static_cast<float>(jCircleParticleEmitterPlaneVelocity["csr"].GetFloat()),
930 static_cast<float>(jCircleParticleEmitterPlaneVelocity["csg"].GetFloat()),
931 static_cast<float>(jCircleParticleEmitterPlaneVelocity["csb"].GetFloat()),
932 static_cast<float>(jCircleParticleEmitterPlaneVelocity["csa"].GetFloat())
933 )
934 );
935 emitter->setColorEnd(
936 Color4(
937 static_cast<float>(jCircleParticleEmitterPlaneVelocity["cer"].GetFloat()),
938 static_cast<float>(jCircleParticleEmitterPlaneVelocity["ceg"].GetFloat()),
939 static_cast<float>(jCircleParticleEmitterPlaneVelocity["ceb"].GetFloat()),
940 static_cast<float>(jCircleParticleEmitterPlaneVelocity["cea"].GetFloat())
941 )
942 );
943 emitter->setCenter(
944 Vector3(
945 static_cast<float>(jCircleParticleEmitterPlaneVelocity["cx"].GetFloat()),
946 static_cast<float>(jCircleParticleEmitterPlaneVelocity["cy"].GetFloat()),
947 static_cast<float>(jCircleParticleEmitterPlaneVelocity["cz"].GetFloat())
948 )
949 );
950 emitter->setRadius(static_cast<float>(jCircleParticleEmitterPlaneVelocity["r"].GetFloat()));
951 emitter->setAxis0(
952 Vector3(
953 static_cast<float>(jCircleParticleEmitterPlaneVelocity["a0x"].GetFloat()),
954 static_cast<float>(jCircleParticleEmitterPlaneVelocity["a0y"].GetFloat()),
955 static_cast<float>(jCircleParticleEmitterPlaneVelocity["a0z"].GetFloat())
956 )
957 );
958 emitter->setAxis1(
959 Vector3(
960 static_cast<float>(jCircleParticleEmitterPlaneVelocity["a1x"].GetFloat()),
961 static_cast<float>(jCircleParticleEmitterPlaneVelocity["a1y"].GetFloat()),
962 static_cast<float>(jCircleParticleEmitterPlaneVelocity["a1z"].GetFloat())
963 )
964 );
965 } else
966 if (v == PrototypeParticleSystem_Emitter::SPHERE_PARTICLE_EMITTER) {
967 auto& jSphereParticleEmitter = jParticleSystem["spe"];
968 auto emitter = particleSystem->getSphereParticleEmitter();
969 emitter->setCount(jSphereParticleEmitter["c"].GetInt());
970 emitter->setLifeTime(jSphereParticleEmitter["lt"].GetInt());
971 emitter->setLifeTimeRnd(jSphereParticleEmitter["ltrnd"].GetInt());
972 emitter->setMass(static_cast<float>(jSphereParticleEmitter["m"].GetFloat()));
973 emitter->setMassRnd(static_cast<float>(jSphereParticleEmitter["mrnd"].GetFloat()));
974 emitter->setVelocity(
975 Vector3(
976 static_cast<float>(jSphereParticleEmitter["vx"].GetFloat()),
977 static_cast<float>(jSphereParticleEmitter["vy"].GetFloat()),
978 static_cast<float>(jSphereParticleEmitter["vz"].GetFloat())
979 )
980 );
981 emitter->setVelocityRnd(
982 Vector3(
983 static_cast<float>(jSphereParticleEmitter["vrndx"].GetFloat()),
984 static_cast<float>(jSphereParticleEmitter["vrndy"].GetFloat()),
985 static_cast<float>(jSphereParticleEmitter["vrndz"].GetFloat())
986 )
987 );
988 emitter->setColorStart(
989 Color4(
990 static_cast<float>(jSphereParticleEmitter["csr"].GetFloat()),
991 static_cast<float>(jSphereParticleEmitter["csg"].GetFloat()),
992 static_cast<float>(jSphereParticleEmitter["csb"].GetFloat()),
993 static_cast<float>(jSphereParticleEmitter["csa"].GetFloat())
994 )
995 );
996 emitter->setColorEnd(
997 Color4(
998 static_cast<float>(jSphereParticleEmitter["cer"].GetFloat()),
999 static_cast<float>(jSphereParticleEmitter["ceg"].GetFloat()),
1000 static_cast<float>(jSphereParticleEmitter["ceb"].GetFloat()),
1001 static_cast<float>(jSphereParticleEmitter["cea"].GetFloat())
1002 )
1003 );
1004 emitter->setCenter(
1005 Vector3(
1006 static_cast<float>(jSphereParticleEmitter["cx"].GetFloat()),
1007 static_cast<float>(jSphereParticleEmitter["cy"].GetFloat()),
1008 static_cast<float>(jSphereParticleEmitter["cz"].GetFloat())
1009 )
1010 );
1011 emitter->setRadius(static_cast<float>(jSphereParticleEmitter["r"].GetFloat()));
1012 } else {
1013 Console::println(
1014 "PrototypeWriter::export(): unknown particle system emitter '" +
1015 particleSystem->getEmitter()->getName() +
1016 "'"
1017 );
1018 }
1019 }
1020}
TDME2 engine entity shader parameters.
void setShaderParameter(const string &parameterName, const ShaderParameter &parameterValue)
Set shader parameter for given parameter name.
void setShader(const string &shaderId)
Set shader.
LOD object 3D to be used with engine class.
Definition: LODObject3D.h:47
Rotation representation.
Definition: Rotation.h:18
static STATIC_DLL_IMPEXT Vector3 Y_AXIS
Definition: Rotation.h:22
static STATIC_DLL_IMPEXT Vector3 X_AXIS
Definition: Rotation.h:21
static STATIC_DLL_IMPEXT Vector3 Z_AXIS
Definition: Rotation.h:23
Shader parameter model class.
Transformations which contain scale, rotations and translation.
void setTranslation(const Vector3 &translation)
Set translation.
void setScale(const Vector3 &scale)
Set scale.
virtual void update()
Computes transformation matrix.
const Vector3 & getTranslation() const
void addRotation(const Vector3 &axis, const float angle)
Add rotation.
static PrototypeImposterLOD * parseImposterLODLevel(const string &pathName, Value &jImposterLOD)
Parse LOD level.
static PrototypeBoundingVolume * parseBoundingVolume(int idx, Prototype *prototype, const string &pathName, Value &jBv)
Parse bounding volume.
static PrototypeLODLevel * parseLODLevel(const string &pathName, Value &jLodLevel)
Parse LOD level.
static void parseParticleSystem(PrototypeParticleSystem *particleSystem, const string &pathName, Value &jParticleSystem)
Parse particle system.
static const string getResourcePathName(const string &pathName, const string &fileName)
Get resource path name.
static Prototype * read(const string &pathName, const string &fileName, PrototypeTransformFilter *transformFilter=nullptr)
Reads a prototype from file.
static bool readThumbnail(const string &pathName, const string &fileName, vector< uint8_t > &pngData)
Read thumbnail from file.
static STATIC_DLL_IMPEXT vector< string > extensions
Color 4 definition.
Definition: Color4.h:20
Representation of a 3d model.
Definition: Model.h:32
BaseProperty * getPropertyByIndex(int idx)
Get property by index.
bool addProperty(const string &name, const string &value)
Add a property.
Base property model class.
Definition: BaseProperty.h:16
Prototype audio definition.
void setAnimation(const string &animation)
Set animation.
Prototype LOD level definition.
PrototypeParticleSystem_PointParticleEmitter * getPointParticleEmitter()
PrototypeParticleSystem_CircleParticleEmitterPlaneVelocity * getCircleParticleEmitterPlaneVelocity()
PrototypeParticleSystem_PointParticleSystem * getPointParticleSystem()
void setEmitter(PrototypeParticleSystem_Emitter *emitter)
Set emitter.
PrototypeParticleSystem_CircleParticleEmitter * getCircleParticleEmitter()
void setType(PrototypeParticleSystem_Type *type)
Set particle system type.
PrototypeParticleSystem_BoundingBoxParticleEmitter * getBoundingBoxParticleEmitters()
PrototypeParticleSystem_ObjectParticleSystem * getObjectParticleSystem()
PrototypeParticleSystem_SphereParticleEmitter * getSphereParticleEmitter()
PrototypeParticleSystem_FogParticleSystem * getFogParticleSystem()
Prototype physics body definitions.
void setType(PrototypePhysics_BodyType *type)
Set type.
void setWidth(float width)
Set width.
vector< unordered_map< int, vector< Transformations > > > & getFoliageMaps()
int getFoliagePrototypeIndex(Prototype *prototype)
Get or allocate a foliage prototype index.
Prototype definition.
Definition: Prototype.h:49
PrototypeAudio * addSound(const string &id)
Add sound with given id.
Definition: Prototype.cpp:137
void setLODLevel3(PrototypeLODLevel *lodLevel)
Set LOD level 3.
Definition: Prototype.cpp:98
void setImposterLOD(PrototypeImposterLOD *imposterLOD)
Set imposter LOD.
Definition: Prototype.cpp:124
void setContributesShadows(bool contributesShadows)
Enable/disable contributes shadows.
Definition: Prototype.h:343
PrototypeParticleSystem * addParticleSystem()
Add particle system.
Definition: Prototype.h:303
void setFileName(const string &fileName)
Set up prototype file name including relative path.
Definition: Prototype.h:155
void setShader(const string &id)
Set shader.
Definition: Prototype.h:406
void setDistanceShaderParameters(const EntityShaderParameters &parameters)
Set distance shader parameters.
Definition: Prototype.h:472
const string & getShader()
Get shader.
Definition: Prototype.h:398
const string & getDistanceShader()
Get distance shader.
Definition: Prototype.h:415
bool addBoundingVolume(int idx, PrototypeBoundingVolume *prototypeBoundingVolume)
Add bounding volume at given index.
Definition: Prototype.cpp:71
void setDistanceShaderDistance(float distance)
Set distance shader distance.
Definition: Prototype.h:440
PrototypePhysics * getPhysics()
Definition: Prototype.h:244
void setTerrainMesh(bool terrainMesh)
Set terrain mesh.
Definition: Prototype.h:374
PrototypeParticleSystem * getParticleSystemAt(int idx)
Get particle system at given index.
Definition: Prototype.h:327
void setDistanceShader(const string &id)
Set distance shader.
Definition: Prototype.h:423
void setShaderParameters(EntityShaderParameters &parameters)
Set shader parameters.
Definition: Prototype.h:456
void setEnvironmentMapTimeRenderUpdateFrequency(int64_t frequency)
Set up environment map render update time frequency.
Definition: Prototype.h:554
PrototypeTerrain * getTerrain()
Definition: Prototype.h:561
void setRenderGroups(bool renderGroups)
Set using render groups.
Definition: Prototype.h:390
void setLODLevel2(PrototypeLODLevel *lodLevel)
Set LOD level 2.
Definition: Prototype.cpp:92
void setEnvironmentMapRenderPassMask(int renderPassMask)
Set up environment render pass mask.
Definition: Prototype.h:539
void setReceivesShadows(bool receivesShadows)
Enable/disable receives shadows.
Definition: Prototype.h:358
3D vector 3 class
Definition: Vector3.h:22
float getX() const
Definition: Vector3.h:103
float getZ() const
Definition: Vector3.h:136
File system singleton class.
Definition: FileSystem.h:14
Base64 encoding/decoding class.
Definition: Base64.h:16
Console class.
Definition: Console.h:26
const string & getName() const
Definition: Enum.h:30
Float class.
Definition: Float.h:23
Integer class.
Definition: Integer.h:26
Model tools functions class.
Definition: ModelTools.h:38
String tools class.
Definition: StringTools.h:20
Terrain 2 utility.
Definition: Terrain2.h:33
std::exception Exception
Exception base class.
Definition: Exception.h:19
virtual bool filterEmptyTransform(BaseProperties &properties)=0
Filter a prototype to be transformed to a empty depending on its properties.