50#include <ext/rapidjson/document.h>
99using rapidjson::Document;
100using rapidjson::Value;
102vector<string> PrototypeReader::extensions = {
"tenvmap",
"tmodel",
"tparticle",
"tterrain",
"ttrigger"};
104const vector<string>& PrototypeReader::getPrototypeExtensions() {
110 auto jsonContent = FileSystem::getInstance()->getContentAsString(pathName, fileName);
112 Document jPrototypeRoot;
113 jPrototypeRoot.Parse(jsonContent.c_str());
115 string thumbnail = jPrototypeRoot.FindMember(
"thumbnail") != jPrototypeRoot.MemberEnd()?jPrototypeRoot[
"thumbnail"].GetString():
"";
116 if (thumbnail.empty() ==
true)
return false;
118 Base64::decode(thumbnail, pngData);
122 Console::println(
"PrototypeReader::readThumbnail(): An error occurred: " + pathName +
"/" + fileName +
": " + exception.what());
129 auto jsonContent = FileSystem::getInstance()->getContentAsString(pathName, fileName);
131 Document jPrototypeRoot;
132 jPrototypeRoot.Parse(jsonContent.c_str());
134 auto prototype =
read(
id, pathName, jPrototypeRoot, transformFilter);
135 prototype->setFileName((pathName.empty() ==
false?pathName +
"/":
"") + fileName);
144 static_cast<float>(jPrototypeRoot[
"px"].GetFloat()),
145 static_cast<float>(jPrototypeRoot[
"py"].GetFloat()),
146 static_cast<float>(jPrototypeRoot[
"pz"].GetFloat())
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();
158 auto jProperties = jPrototypeRoot[
"properties"].GetArray();
159 for (
auto i = 0; i < jProperties.Size(); i++) {
160 auto& jProperty = jProperties[i];
162 (jProperty[
"name"].GetString()),
163 (jProperty[
"value"].GetString())
167 prototypeType = Prototype_Type::EMPTY;
169 Model* model =
nullptr;
170 if (prototypeType == Prototype_Type::EMPTY) {
171 model = ModelReader::read(
"resources/engine/models",
"empty.tm");
173 if (modelFileName.length() > 0) {
175 model = ModelReader::read(
177 FileSystem::getInstance()->getFileName(modelFileName)
186 modelFileName.length() > 0?modelPathName +
"/" + FileSystem::getInstance()->getFileName(modelFileName):
"",
194 prototype->
addProperty(property->getName(), property->getValue());
196 if (jPrototypeRoot.FindMember(
"bv") != jPrototypeRoot.MemberEnd()) {
203 if (boundingVolume->getBoundingVolume() !=
nullptr) prototype->
addBoundingVolume(0, boundingVolume);
205 if (jPrototypeRoot.FindMember(
"bvs") != jPrototypeRoot.MemberEnd()) {
206 auto jBoundingVolumes = jPrototypeRoot[
"bvs"].GetArray();
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);
213 if (jPrototypeRoot.FindMember(
"p") != jPrototypeRoot.MemberEnd() && prototype->
getPhysics() !=
nullptr) {
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(
222 static_cast<float>(jPhysics[
"itx"].GetFloat()),
223 static_cast<float>(jPhysics[
"ity"].GetFloat()),
224 static_cast<float>(jPhysics[
"itz"].GetFloat())
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;
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());
242 if (prototypeType == Prototype_Type::MODEL) {
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"]));
249 if (prototypeType == Prototype_Type::PARTICLESYSTEM) {
250 if (jPrototypeRoot.FindMember(
"ps") != jPrototypeRoot.MemberEnd()) {
254 if (jPrototypeRoot.FindMember(
"pss") != jPrototypeRoot.MemberEnd()) {
255 auto jParticleSystems = jPrototypeRoot[
"pss"].GetArray();
256 for (
auto i = 0; i < jParticleSystems.Size(); i++) {
262 if (jPrototypeRoot.FindMember(
"ds") != jPrototypeRoot.MemberEnd()) {
266 if (jPrototypeRoot.FindMember(
"cs") != jPrototypeRoot.MemberEnd() && jPrototypeRoot.FindMember(
"rs") != jPrototypeRoot.MemberEnd()) {
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"];
278 for (
auto jShaderParameterIt = jShaderParameters.MemberBegin(); jShaderParameterIt != jShaderParameters.MemberEnd(); ++jShaderParameterIt) {
279 shaderParameters.
setShaderParameter(jShaderParameterIt->name.GetString(),
string(jShaderParameterIt->value.GetString()));
283 if (jPrototypeRoot.FindMember(
"spds") != jPrototypeRoot.MemberEnd()) {
284 Value& jDistanceShaderParameters = jPrototypeRoot[
"spds"];
287 for (
auto jDistanceShaderParameterIt = jDistanceShaderParameters.MemberBegin(); jDistanceShaderParameterIt != jDistanceShaderParameters.MemberEnd(); ++jDistanceShaderParameterIt) {
288 distanceShaderParameters.
setShaderParameter(jDistanceShaderParameterIt->name.GetString(),
string(jDistanceShaderParameterIt->value.GetString()));
292 if (prototype->
getType() == Prototype_Type::ENVIRONMENTMAPPING) {
300 if (prototype->
getType() == Prototype_Type::TERRAIN) {
302 Value& jTerrain = jPrototypeRoot[
"t"];
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());
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);
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));
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();
343 auto foliagePrototypeFileName = jFoliagePrototype[
"f"].GetString();
346 FileSystem::getInstance()->getFileName(foliagePrototypeFileName)
349 Console::println(
string(
"PrototypeReader::read(): An error occurred: ") + exception.what());
357 for (
auto foliagePrototypePartitionIdx = 0; foliagePrototypePartitionIdx < jFoliagePrototypePartitions.Size(); foliagePrototypePartitionIdx++) {
359 auto partitionX = foliagePrototypePartitionIdx % partitionsX;
360 auto partitionZ = foliagePrototypePartitionIdx / partitionsX;
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];
370 jFoliagePrototypeTransformations[
"tx"].GetFloat(),
371 jFoliagePrototypeTransformations[
"ty"].GetFloat(),
372 jFoliagePrototypeTransformations[
"tz"].GetFloat()
378 foliagePrototypeTransformations.
setScale(
380 jFoliagePrototypeTransformations[
"sx"].GetFloat(),
381 jFoliagePrototypeTransformations[
"sy"].GetFloat(),
382 jFoliagePrototypeTransformations[
"sz"].GetFloat()
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;
397 "PrototypeReader::read(): foliage entity not in partition: " +
399 to_string(partitionLeft) +
", " + to_string(partitionTop) +
", " +
400 to_string(partitionRight) +
", " + to_string(partitionBottom)
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());
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)
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;
460 auto bvTypeString = (jBv[
"type"].GetString());
461 if (StringTools::equalsIgnoreCase(bvTypeString,
"none") ==
true) {
462 prototypeBoundingVolume->setupNone();
464 if (StringTools::equalsIgnoreCase(bvTypeString,
"sphere") ==
true) {
465 prototypeBoundingVolume->setupSphere(
467 static_cast<float>(jBv[
"cx"].GetFloat()),
468 static_cast<float>(jBv[
"cy"].GetFloat()),
469 static_cast<float>(jBv[
"cz"].GetFloat())
471 static_cast<float>(jBv[
"r"].GetFloat())
474 if (StringTools::equalsIgnoreCase(bvTypeString,
"capsule") ==
true) {
475 prototypeBoundingVolume->setupCapsule(
477 static_cast<float>(jBv[
"ax"].GetFloat()),
478 static_cast<float>(jBv[
"ay"].GetFloat()),
479 static_cast<float>(jBv[
"az"].GetFloat())
482 static_cast<float>(jBv[
"bx"].GetFloat()),
483 static_cast<float>(jBv[
"by"].GetFloat()),
484 static_cast<float>(jBv[
"bz"].GetFloat())
486 static_cast<float>(jBv[
"r"].GetFloat())
489 if (StringTools::equalsIgnoreCase(bvTypeString,
"aabb") ==
true) {
490 prototypeBoundingVolume->setupAabb(
492 static_cast<float>(jBv[
"mix"].GetFloat()),
493 static_cast<float>(jBv[
"miy"].GetFloat()),
494 static_cast<float>(jBv[
"miz"].GetFloat())
497 static_cast<float>(jBv[
"max"].GetFloat()),
498 static_cast<float>(jBv[
"may"].GetFloat()),
499 static_cast<float>(jBv[
"maz"].GetFloat())
503 if (StringTools::equalsIgnoreCase(bvTypeString,
"obb") ==
true) {
504 prototypeBoundingVolume->setupObb(
506 static_cast<float>(jBv[
"cx"].GetFloat()),
507 static_cast<float>(jBv[
"cy"].GetFloat()),
508 static_cast<float>(jBv[
"cz"].GetFloat())
511 static_cast<float>(jBv[
"a0x"].GetFloat()),
512 static_cast<float>(jBv[
"a0y"].GetFloat()),
513 static_cast<float>(jBv[
"a0z"].GetFloat())
516 static_cast<float>(jBv[
"a1x"].GetFloat()),
517 static_cast<float>(jBv[
"a1y"].GetFloat()),
518 static_cast<float>(jBv[
"a1z"].GetFloat())
521 static_cast<float>(jBv[
"a2x"].GetFloat()),
522 static_cast<float>(jBv[
"a2y"].GetFloat()),
523 static_cast<float>(jBv[
"a2z"].GetFloat())
526 static_cast<float>(jBv[
"hex"].GetFloat()),
527 static_cast<float>(jBv[
"hey"].GetFloat()),
528 static_cast<float>(jBv[
"hez"].GetFloat())
532 if (StringTools::equalsIgnoreCase(bvTypeString,
"convexmesh") ==
true) {
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);
540 string fileName = jBv[
"file"].GetString();
541 prototypeBoundingVolume->setupConvexMesh(
543 Tools::getFileName(fileName)
547 Console::print(
string(
"PrototypeReader::parseBoundingVolume(): An error occurred: "));
548 Console::println(
string(exception.what()));
551 if (jBv.FindMember(
"g") != jBv.MemberEnd()) prototypeBoundingVolume->setGenerated(jBv[
"g"].GetBool());
552 return prototypeBoundingVolume;
561 static_cast<float>(jLodLevel[
"d"].GetFloat())
564 auto modelFileName = lodLevel->getFileName();
569 FileSystem::getInstance()->getFileName(modelFileName)
572 lodLevel->setFileName(modelPathName +
"/" + FileSystem::getInstance()->getFileName(modelFileName));
574 lodLevel->setColorAdd(
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())
582 lodLevel->setColorMul(
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())
597 static_cast<float>(jImposterLOD[
"d"].GetFloat())
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;
611 FileSystem::getInstance()->getFileName(modelFileName)
614 fileNames.push_back(fileName);
618 imposterLOD->setModels(models);
619 imposterLOD->setFileNames(fileNames);
622 imposterLOD->setColorAdd(
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())
630 imposterLOD->setColorMul(
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())
642 particleSystem->
setType(PrototypeParticleSystem_Type::valueOf((jParticleSystem[
"t"].GetString())));
644 auto v = particleSystem->
getType();
645 if (v == PrototypeParticleSystem_Type::NONE) {
648 if (v == PrototypeParticleSystem_Type::OBJECT_PARTICLE_SYSTEM) {
649 auto& jObjectParticleSystem = jParticleSystem[
"ops"];
651 objectParticleSystem->
setMaxCount(jObjectParticleSystem[
"mc"].GetInt());
652 objectParticleSystem->setScale(
654 static_cast<float>(jObjectParticleSystem[
"sx"].GetFloat()),
655 static_cast<float>(jObjectParticleSystem[
"sy"].GetFloat()),
656 static_cast<float>(jObjectParticleSystem[
"sz"].GetFloat())
659 objectParticleSystem->setAutoEmit(jObjectParticleSystem[
"ae"].GetBool());
661 auto particleModelFile = (jObjectParticleSystem[
"mf"].GetString());
663 objectParticleSystem->setModelFile(
664 particleModelPath +
"/" + Tools::getFileName(particleModelFile)
667 Console::print(
string(
"PrototypeReader::doImport(): An error occurred: "));
668 Console::println(
string(exception.what()));
671 if (v == PrototypeParticleSystem_Type::POINT_PARTICLE_SYSTEM) {
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()) {
678 auto particleTextureFileName = jPointParticleSystem[
"t"].GetString();
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)
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());
690 Console::print(
string(
"PrototypeReader::doImport(): An error occurred: "));
691 Console::println(
string(exception.what()));
694 pointParticleSystem->setAutoEmit(jPointParticleSystem[
"ae"].GetBool());
696 if (v == PrototypeParticleSystem_Type::FOG_PARTICLE_SYSTEM) {
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()) {
703 auto particleTextureFileName = jFogParticleSystem[
"t"].GetString();
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)
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());
715 Console::print(
string(
"PrototypeReader::doImport(): An error occurred: "));
716 Console::println(
string(exception.what()));
722 "PrototypeWriter::export(): unknown particle system type '" +
730 particleSystem->
setEmitter(PrototypeParticleSystem_Emitter::valueOf((jParticleSystem[
"e"].GetString())));
733 if (v == PrototypeParticleSystem_Emitter::NONE) {
736 if (v == PrototypeParticleSystem_Emitter::POINT_PARTICLE_EMITTER) {
737 auto& jPointParticleEmitter = jParticleSystem[
"ppe"];
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(
746 static_cast<float>(jPointParticleEmitter[
"px"].GetFloat()),
747 static_cast<float>(jPointParticleEmitter[
"py"].GetFloat()),
748 static_cast<float>(jPointParticleEmitter[
"pz"].GetFloat())
751 emitter->setVelocity(
753 static_cast<float>(jPointParticleEmitter[
"vx"].GetFloat()),
754 static_cast<float>(jPointParticleEmitter[
"vy"].GetFloat()),
755 static_cast<float>(jPointParticleEmitter[
"vz"].GetFloat())
758 emitter->setVelocityRnd(
760 static_cast<float>(jPointParticleEmitter[
"vrndx"].GetFloat()),
761 static_cast<float>(jPointParticleEmitter[
"vrndy"].GetFloat()),
762 static_cast<float>(jPointParticleEmitter[
"vrndz"].GetFloat())
765 emitter->setColorStart(
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())
773 emitter->setColorEnd(
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())
782 if (v == PrototypeParticleSystem_Emitter::BOUNDINGBOX_PARTICLE_EMITTER) {
783 auto& jBoundingBoxParticleEmitter = jParticleSystem[
"bbpe"];
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(
792 static_cast<float>(jBoundingBoxParticleEmitter[
"vx"].GetFloat()),
793 static_cast<float>(jBoundingBoxParticleEmitter[
"vy"].GetFloat()),
794 static_cast<float>(jBoundingBoxParticleEmitter[
"vz"].GetFloat())
797 emitter->setVelocityRnd(
799 static_cast<float>(jBoundingBoxParticleEmitter[
"vrndx"].GetFloat()),
800 static_cast<float>(jBoundingBoxParticleEmitter[
"vrndy"].GetFloat()),
801 static_cast<float>(jBoundingBoxParticleEmitter[
"vrndz"].GetFloat())
804 emitter->setColorStart(
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())
812 emitter->setColorEnd(
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())
820 emitter->setObbCenter(
822 static_cast<float>(jBoundingBoxParticleEmitter[
"ocx"].GetFloat()),
823 static_cast<float>(jBoundingBoxParticleEmitter[
"ocy"].GetFloat()),
824 static_cast<float>(jBoundingBoxParticleEmitter[
"ocz"].GetFloat())
827 emitter->setObbHalfextension(
829 static_cast<float>(jBoundingBoxParticleEmitter[
"ohex"].GetFloat()),
830 static_cast<float>(jBoundingBoxParticleEmitter[
"ohey"].GetFloat()),
831 static_cast<float>(jBoundingBoxParticleEmitter[
"ohez"].GetFloat())
834 emitter->setObbAxis0(
836 static_cast<float>(jBoundingBoxParticleEmitter[
"oa0x"].GetFloat()),
837 static_cast<float>(jBoundingBoxParticleEmitter[
"oa0y"].GetFloat()),
838 static_cast<float>(jBoundingBoxParticleEmitter[
"oa0z"].GetFloat())
841 emitter->setObbAxis1(
843 static_cast<float>(jBoundingBoxParticleEmitter[
"oa1x"].GetFloat()),
844 static_cast<float>(jBoundingBoxParticleEmitter[
"oa1y"].GetFloat()),
845 static_cast<float>(jBoundingBoxParticleEmitter[
"oa1z"].GetFloat())
848 emitter->setObbAxis2(
850 static_cast<float>(jBoundingBoxParticleEmitter[
"oa2x"].GetFloat()),
851 static_cast<float>(jBoundingBoxParticleEmitter[
"oa2y"].GetFloat()),
852 static_cast<float>(jBoundingBoxParticleEmitter[
"oa2z"].GetFloat())
856 if (v == PrototypeParticleSystem_Emitter::CIRCLE_PARTICLE_EMITTER) {
857 auto& jCircleParticleEmitter = jParticleSystem[
"cpe"];
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(
866 static_cast<float>(jCircleParticleEmitter[
"vx"].GetFloat()),
867 static_cast<float>(jCircleParticleEmitter[
"vy"].GetFloat()),
868 static_cast<float>(jCircleParticleEmitter[
"vz"].GetFloat())
871 emitter->setVelocityRnd(
873 static_cast<float>(jCircleParticleEmitter[
"vrndx"].GetFloat()),
874 static_cast<float>(jCircleParticleEmitter[
"vrndy"].GetFloat()),
875 static_cast<float>(jCircleParticleEmitter[
"vrndz"].GetFloat())
878 emitter->setColorStart(
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())
886 emitter->setColorEnd(
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())
896 static_cast<float>(jCircleParticleEmitter[
"cx"].GetFloat()),
897 static_cast<float>(jCircleParticleEmitter[
"cy"].GetFloat()),
898 static_cast<float>(jCircleParticleEmitter[
"cz"].GetFloat())
901 emitter->setRadius(
static_cast<float>(jCircleParticleEmitter[
"r"].GetFloat()));
904 static_cast<float>(jCircleParticleEmitter[
"a0x"].GetFloat()),
905 static_cast<float>(jCircleParticleEmitter[
"a0y"].GetFloat()),
906 static_cast<float>(jCircleParticleEmitter[
"a0z"].GetFloat())
911 static_cast<float>(jCircleParticleEmitter[
"a1x"].GetFloat()),
912 static_cast<float>(jCircleParticleEmitter[
"a1y"].GetFloat()),
913 static_cast<float>(jCircleParticleEmitter[
"a1z"].GetFloat())
917 if (v == PrototypeParticleSystem_Emitter::CIRCLE_PARTICLE_EMITTER_PLANE_VELOCITY) {
918 auto& jCircleParticleEmitterPlaneVelocity = jParticleSystem[
"cpeev"];
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(
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())
935 emitter->setColorEnd(
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())
945 static_cast<float>(jCircleParticleEmitterPlaneVelocity[
"cx"].GetFloat()),
946 static_cast<float>(jCircleParticleEmitterPlaneVelocity[
"cy"].GetFloat()),
947 static_cast<float>(jCircleParticleEmitterPlaneVelocity[
"cz"].GetFloat())
950 emitter->setRadius(
static_cast<float>(jCircleParticleEmitterPlaneVelocity[
"r"].GetFloat()));
953 static_cast<float>(jCircleParticleEmitterPlaneVelocity[
"a0x"].GetFloat()),
954 static_cast<float>(jCircleParticleEmitterPlaneVelocity[
"a0y"].GetFloat()),
955 static_cast<float>(jCircleParticleEmitterPlaneVelocity[
"a0z"].GetFloat())
960 static_cast<float>(jCircleParticleEmitterPlaneVelocity[
"a1x"].GetFloat()),
961 static_cast<float>(jCircleParticleEmitterPlaneVelocity[
"a1y"].GetFloat()),
962 static_cast<float>(jCircleParticleEmitterPlaneVelocity[
"a1z"].GetFloat())
966 if (v == PrototypeParticleSystem_Emitter::SPHERE_PARTICLE_EMITTER) {
967 auto& jSphereParticleEmitter = jParticleSystem[
"spe"];
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(
976 static_cast<float>(jSphereParticleEmitter[
"vx"].GetFloat()),
977 static_cast<float>(jSphereParticleEmitter[
"vy"].GetFloat()),
978 static_cast<float>(jSphereParticleEmitter[
"vz"].GetFloat())
981 emitter->setVelocityRnd(
983 static_cast<float>(jSphereParticleEmitter[
"vrndx"].GetFloat()),
984 static_cast<float>(jSphereParticleEmitter[
"vrndy"].GetFloat()),
985 static_cast<float>(jSphereParticleEmitter[
"vrndz"].GetFloat())
988 emitter->setColorStart(
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())
996 emitter->setColorEnd(
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())
1006 static_cast<float>(jSphereParticleEmitter[
"cx"].GetFloat()),
1007 static_cast<float>(jSphereParticleEmitter[
"cy"].GetFloat()),
1008 static_cast<float>(jSphereParticleEmitter[
"cz"].GetFloat())
1011 emitter->setRadius(
static_cast<float>(jSphereParticleEmitter[
"r"].GetFloat()));
1014 "PrototypeWriter::export(): unknown particle system emitter '" +
TDME2 engine entity shader parameters.
void setShaderParameter(const string ¶meterName, const ShaderParameter ¶meterValue)
Set shader parameter for given parameter name.
void setShader(const string &shaderId)
Set shader.
LOD object 3D to be used with engine class.
static STATIC_DLL_IMPEXT Vector3 Y_AXIS
static STATIC_DLL_IMPEXT Vector3 X_AXIS
static STATIC_DLL_IMPEXT Vector3 Z_AXIS
Shader parameter model class.
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
Representation of a 3d model.
Bounding volume interface.
BaseProperty * getPropertyByIndex(int idx)
Get property by index.
bool addProperty(const string &name, const string &value)
Add a property.
Base property model class.
Prototype audio definition.
void setAnimation(const string &animation)
Set animation.
Prototype bounding volume definition.
Prototype LOD level definition.
Prototype bounding box particle emitter definition.
void setCount(int count)
Set count.
Prototype circle particle emitter plane velocity definition.
void setCount(int count)
Set count.
Prototype circle particle emitter definition.
void setCount(int count)
Set count.
Prototype particle system emitter type enum.
Prototype point particle system definition.
void setMaxPoints(int maxPoints)
Set max points.
Prototype object particle system definition.
void setMaxCount(int maxCount)
Set max count.
Prototype point particle emitter definition.
void setCount(int count)
Set count.
Prototype point particle system definition.
void setMaxPoints(int maxPoints)
Set max points.
Prototype sphere particle emitter definition.
void setCount(int count)
Set count.
Prototype particle system type enum.
Prototype particle system 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_Emitter * getEmitter()
PrototypeParticleSystem_SphereParticleEmitter * getSphereParticleEmitter()
PrototypeParticleSystem_FogParticleSystem * getFogParticleSystem()
PrototypeParticleSystem_Type * getType()
Prototype physics body type enum.
Prototype physics body definitions.
void setType(PrototypePhysics_BodyType *type)
Set type.
Prototype terrain definition.
void setWidth(float width)
Set width.
vector< unordered_map< int, vector< Transformations > > > & getFoliageMaps()
int getFoliagePrototypeIndex(Prototype *prototype)
Get or allocate a foliage prototype index.
PrototypeAudio * addSound(const string &id)
Add sound with given id.
void setLODLevel3(PrototypeLODLevel *lodLevel)
Set LOD level 3.
void setImposterLOD(PrototypeImposterLOD *imposterLOD)
Set imposter LOD.
void setContributesShadows(bool contributesShadows)
Enable/disable contributes shadows.
int getParticleSystemsCount()
PrototypeParticleSystem * addParticleSystem()
Add particle system.
void setFileName(const string &fileName)
Set up prototype file name including relative path.
void setShader(const string &id)
Set shader.
void setDistanceShaderParameters(const EntityShaderParameters ¶meters)
Set distance shader parameters.
const string & getShader()
Get shader.
const string & getDistanceShader()
Get distance shader.
bool addBoundingVolume(int idx, PrototypeBoundingVolume *prototypeBoundingVolume)
Add bounding volume at given index.
void setDistanceShaderDistance(float distance)
Set distance shader distance.
PrototypePhysics * getPhysics()
void setTerrainMesh(bool terrainMesh)
Set terrain mesh.
PrototypeParticleSystem * getParticleSystemAt(int idx)
Get particle system at given index.
void setDistanceShader(const string &id)
Set distance shader.
void setShaderParameters(EntityShaderParameters ¶meters)
Set shader parameters.
void setEnvironmentMapTimeRenderUpdateFrequency(int64_t frequency)
Set up environment map render update time frequency.
PrototypeTerrain * getTerrain()
void setRenderGroups(bool renderGroups)
Set using render groups.
void setLODLevel2(PrototypeLODLevel *lodLevel)
Set LOD level 2.
void setEnvironmentMapRenderPassMask(int renderPassMask)
Set up environment render pass mask.
void setReceivesShadows(bool receivesShadows)
Enable/disable receives shadows.
Prototype_Type * getType()
File system singleton class.
Base64 encoding/decoding class.
const string & getName() const
std::exception Exception
Exception base class.