TDME2  1.9.200
Tools.cpp
Go to the documentation of this file.
2 
3 #include <array>
4 #include <memory>
5 #include <string>
6 
7 #include <tdme/tdme.h>
10 #include <tdme/engine/Texture.h>
12 #include <tdme/engine/Color4.h>
13 #include <tdme/engine/model/Face.h>
17 #include <tdme/engine/model/Node.h>
29 #include <tdme/engine/Camera.h>
30 #include <tdme/engine/Engine.h>
31 #include <tdme/engine/Entity.h>
34 #include <tdme/engine/Light.h>
35 #include <tdme/engine/Object.h>
38 #include <tdme/engine/Transform.h>
39 #include <tdme/math/Math.h>
40 #include <tdme/math/Matrix4x4.h>
41 #include <tdme/math/Quaternion.h>
42 #include <tdme/math/Vector2.h>
43 #include <tdme/math/Vector3.h>
44 #include <tdme/math/Vector4.h>
48 #include <tdme/utilities/Console.h>
50 #include <tdme/utilities/Float.h>
51 #include <tdme/utilities/Integer.h>
57 
58 using std::array;
59 using std::make_unique;
60 using std::string;
61 using std::to_string;
62 using std::unique_ptr;
63 
65 
97 using tdme::math::Math;
100 using tdme::math::Vector2;
101 using tdme::math::Vector3;
102 using tdme::math::Vector4;
115 
116 Engine* Tools::osEngine = nullptr;
117 Model* Tools::gizmoAll = nullptr;
118 Model* Tools::gizmoTranslationScale = nullptr;
119 Model* Tools::gizmoTranslation = nullptr;
120 Model* Tools::gizmoScale = nullptr;
121 Model* Tools::gizmoRotations = nullptr;
122 Model* Tools::defaultOBB = nullptr;
123 Tools::ToolsShutdown Tools::toolsShutdown;
124 
125 string Tools::formatFloat(float value)
126 {
127 
128  string floatString = to_string(value);
129  return floatString.substr(0, floatString.length() - 3);
130 }
131 
133 {
134  light->setAmbient(Color4(1.0f, 1.0f, 1.0f, 1.0f));
135  light->setDiffuse(Color4(0.5f, 0.5f, 0.5f, 1.0f));
136  light->setSpecular(Color4(1.0f, 1.0f, 1.0f, 1.0f));
137  light->setPosition(Vector4(0.0f, 20000.0f, 0.0f, 0.0f));
138  light->setSpotDirection(Vector3(0.0f, 0.0f, 0.0f).sub(Vector3(light->getPosition().getX(), light->getPosition().getY(), light->getPosition().getZ())));
139  light->setConstantAttenuation(0.5f);
140  light->setLinearAttenuation(0.0f);
141  light->setQuadraticAttenuation(0.0f);
142  light->setSpotExponent(0.0f);
143  light->setSpotCutOff(180.0f);
144  light->setEnabled(true);
145 }
146 
148 {
149  if (osEngine != nullptr) return;
150  osEngine = Engine::createOffScreenInstance(128, 128, false, true, false);
153 }
154 
156 {
157  if (osEngine == nullptr) return;
158  osEngine->dispose();
159  delete osEngine;
160 }
161 
162 void Tools::oseThumbnail(Prototype* prototype, vector<uint8_t>& pngData)
163 {
164  oseInit();
165  Vector3 objectScale;
166  Transform oseLookFromRotations;
167  oseLookFromRotations.addRotation(Vector3(0.0f, 1.0f, 0.0f), -45.0f);
168  oseLookFromRotations.addRotation(Vector3(1.0f, 0.0f, 0.0f), -45.0f);
169  oseLookFromRotations.addRotation(Vector3(0.0f, 0.0f, 1.0f), 0.0f);
170  oseLookFromRotations.update();
171  Tools::setupPrototype(prototype, osEngine, oseLookFromRotations, 1, objectScale, nullptr, 1.0f);
172  osEngine->setSceneColor(Color4(0.5f, 0.5f, 0.5f, 1.0f));
173  osEngine->display();
174  osEngine->makeScreenshot(pngData);
175  /*
176  osEngine->setSceneColor(Color4(0.8f, 0.0f, 0.0f, 1.0f));
177  osEngine->display();
178  osEngine->makeScreenshot(pngData);
179  */
180  osEngine->reset();
181 }
182 
184 {
185  auto maxAxisDimension = 0.0f;
186  Vector3 dimension = boundingBox->getMax().clone().sub(boundingBox->getMin());
187  if (dimension.getX() > maxAxisDimension) maxAxisDimension = dimension.getX();
188  if (dimension.getY() > maxAxisDimension) maxAxisDimension = dimension.getY();
189  if (dimension.getZ() > maxAxisDimension) maxAxisDimension = dimension.getZ();
190  return maxAxisDimension;
191 }
192 
193 Model* Tools::createGroundModel(float width, float depth, float y)
194 {
195  auto modelId = "tdme.ground" + to_string(static_cast<int>(width * 100)) + "x" + to_string(static_cast<int>(depth * 100)) + "@" + to_string(static_cast<int>(y * 100));
196  auto ground = make_unique<Model>(modelId, modelId, UpVector::Y_UP, RotationOrder::ZYX, nullptr);
197  //
198  auto groundMaterial = make_unique<Material>("ground");
199  groundMaterial->setSpecularMaterialProperties(make_unique<SpecularMaterialProperties>().release());
200  groundMaterial->getSpecularMaterialProperties()->setSpecularColor(Color4(0.0f, 0.0f, 0.0f, 1.0f));
201  groundMaterial->getSpecularMaterialProperties()->setDiffuseTexture("resources/engine/textures", "groundplate.png");
202  //
203  auto groundNode = make_unique<Node>(ground.get(), nullptr, "ground", "ground");
204  vector<Vector3> groundVertices;
205  groundVertices.emplace_back(-width/2, y, -depth/2);
206  groundVertices.emplace_back(-width/2, y, +depth/2);
207  groundVertices.emplace_back(+width/2, y, +depth/2);
208  groundVertices.emplace_back(+width/2, y, -depth/2);
209  vector<Vector3> groundNormals;
210  groundNormals.emplace_back(0.0f, 1.0f, 0.0f);
211  vector<Vector2> groundTextureCoordinates;
212  groundTextureCoordinates.emplace_back(0.0f, 0.0f);
213  groundTextureCoordinates.emplace_back(0.0f, depth);
214  groundTextureCoordinates.emplace_back(width, depth);
215  groundTextureCoordinates.emplace_back(width, 0.0f);
216  vector<Face> groundFacesGround;
217  groundFacesGround.emplace_back(groundNode.get(), 0, 1, 2, 0, 0, 0, 0, 1, 2);
218  groundFacesGround.emplace_back(groundNode.get(), 2, 3, 0, 0, 0, 0, 2, 3, 0);
219  FacesEntity nodeFacesEntityGround(groundNode.get(), "ground.facesentity");
220  nodeFacesEntityGround.setMaterial(groundMaterial.get());
221  vector<FacesEntity> nodeFacesEntities;
222  nodeFacesEntityGround.setFaces(groundFacesGround);
223  nodeFacesEntities.push_back(nodeFacesEntityGround);
224  groundNode->setVertices(groundVertices);
225  groundNode->setNormals(groundNormals);
226  groundNode->setTextureCoordinates(groundTextureCoordinates);
227  groundNode->setFacesEntities(nodeFacesEntities);
228  ground->getNodes()["ground"] = groundNode.get();
229  ground->getSubNodes()["ground"] = groundNode.get();
230  groundNode.release();
231  //
232  ground->getMaterials()["ground"] = groundMaterial.get();
233  groundMaterial.release();
234  //
235  ModelTools::prepareForIndexedRendering(ground.get());
236  //
237  return ground.release();
238 }
239 
241 {
242  //
243  auto groundPlate = make_unique<Model>("tdme.grid", "tdme.grid", UpVector::Y_UP, RotationOrder::XYZ, make_unique<BoundingBox>(Vector3(0.0f, -0.01f, 0.0f), Vector3(10000.0f, +0.01f, 10000.0f)).release());
244  //
245  auto groundPlateMaterial = make_unique<Material>("ground");
246  groundPlateMaterial->setSpecularMaterialProperties(make_unique<SpecularMaterialProperties>().release());
247  groundPlateMaterial->getSpecularMaterialProperties()->setDiffuseColor(
248  Color4(
249  groundPlateMaterial->getSpecularMaterialProperties()->getDiffuseColor().getRed(),
250  groundPlateMaterial->getSpecularMaterialProperties()->getDiffuseColor().getGreen(),
251  groundPlateMaterial->getSpecularMaterialProperties()->getDiffuseColor().getBlue(),
252  0.75f
253  )
254  );
255  groundPlateMaterial->getSpecularMaterialProperties()->setDiffuseTexture("resources/engine/textures", "groundplate.png");
256  groundPlateMaterial->getSpecularMaterialProperties()->setSpecularColor(Color4(0.0f, 0.0f, 0.0f, 1.0f));
257  //
258  auto groundNode = make_unique<Node>(groundPlate.get(), nullptr, "grid", "grid");
259  vector<Vector3> groundVertices;
260  groundVertices.emplace_back(0.0f, 0.0f, 0.0f);
261  groundVertices.emplace_back(0.0f, 0.0f, 10000.0f);
262  groundVertices.emplace_back(10000.0f, 0.0f, 10000.0f);
263  groundVertices.emplace_back(10000.0f, 0.0f, 0.0f);
264  vector<Vector3> groundNormals;
265  groundNormals.emplace_back(0.0f, 1.0f, 0.0f);
266  vector<Vector2> groundTextureCoordinates;
267  groundTextureCoordinates.emplace_back(0.0f, 0.0f);
268  groundTextureCoordinates.emplace_back(0.0f, 10000.0f);
269  groundTextureCoordinates.emplace_back(10000.0f, 10000.0f);
270  groundTextureCoordinates.emplace_back(10000.0f, 0.0f);
271  vector<Face> groundFacesGround;
272  groundFacesGround.emplace_back(groundNode.get(), 0, 1, 2, 0, 0, 0, 0, 1, 2);
273  groundFacesGround.emplace_back(groundNode.get(), 2, 3, 0, 0, 0, 0, 2, 3, 0);
274  FacesEntity nodeFacesEntityGround(groundNode.get(), "tdme.sceneeditor.grid.facesentity");
275  nodeFacesEntityGround.setMaterial(groundPlateMaterial.get());
276  nodeFacesEntityGround.setFaces(groundFacesGround);
277  vector<FacesEntity> nodeFacesEntities;
278  nodeFacesEntities.push_back(nodeFacesEntityGround);
279  groundNode->setVertices(groundVertices);
280  groundNode->setNormals(groundNormals);
281  groundNode->setTextureCoordinates(groundTextureCoordinates);
282  groundNode->setFacesEntities(nodeFacesEntities);
283  groundPlate->getNodes()[groundNode->getId()] = groundNode.get();
284  groundPlate->getSubNodes()[groundNode->getId()] = groundNode.get();
285  groundNode.release();
286  //
287  groundPlate->getMaterials()["grid"] = groundPlateMaterial.get();
288  groundPlateMaterial.release();
289  //
290  ModelTools::prepareForIndexedRendering(groundPlate.get());
291  //
292  return groundPlate.release();
293 }
294 
295 void Tools::setupPrototype(Prototype* prototype, Engine* engine, const Transform& lookFromRotations, int lodLevel, Vector3& objectScale, CameraRotationInputHandler* cameraRotationInputHandler, float scale, bool resetup)
296 {
297  if (prototype == nullptr) return;
298 
299  // create engine entity
300  auto entityBoundingBoxFallback = make_unique<BoundingBox>(Vector3(-2.5f, 0.0f, -2.5f), Vector3(2.5f, 2.0f, 2.5f));
301  BoundingBox* entityBoundingBox = nullptr;
302  Entity* modelEntity = nullptr;
303  objectScale.set(1.0f, 1.0f, 1.0f);
304  Color4 colorMul(1.0f, 1.0f, 1.0f, 1.0f);
305  Color4 colorAdd(0.0f, 0.0f, 0.0f, 0.0f);
306 
307  // bounding volumes
308  auto entityBoundingVolumesHierarchy = new EntityHierarchy("tdme.prototype.bvs");
309  {
310  auto i = 0;
311  for (auto prototypeBoundingVolume: prototype->getBoundingVolumes()) {
312  if (prototypeBoundingVolume->getModel() != nullptr) {
313  auto bvObject = new Object("tdme.prototype.bv." + to_string(i), prototypeBoundingVolume->getModel());
314  bvObject->setEnabled(false);
315  entityBoundingVolumesHierarchy->addEntity(bvObject);
316  }
317  i++;
318  }
319  }
320  entityBoundingVolumesHierarchy->update();
321  engine->addEntity(entityBoundingVolumesHierarchy);
322 
323  //
324  if (prototype->getType() == Prototype_Type::TRIGGER ||
325  prototype->getType() == Prototype_Type::ENVIRONMENTMAPPING ||
326  prototype->getType() == Prototype_Type::DECAL) {
327  entityBoundingBox = entityBoundingVolumesHierarchy->getBoundingBox();
328  } else
329  if (prototype->getType() == Prototype_Type::PARTICLESYSTEM) {
330  modelEntity = SceneConnector::createEntity(prototype, "model", Transform());
331  if (modelEntity != nullptr) engine->addEntity(modelEntity);
332  } else
333  if (prototype->getModel() != nullptr) {
334  // model
335  Model* model = nullptr;
336  switch (lodLevel) {
337  case 1:
338  model = prototype->getModel();
339  break;
340  case 2:
341  {
342  auto lodLevelEntity = prototype->getLODLevel2();
343  if (lodLevelEntity != nullptr) {
344  model = lodLevelEntity->getModel();
345  colorMul.set(lodLevelEntity->getColorMul());
346  colorAdd.set(lodLevelEntity->getColorAdd());
347  }
348  break;
349  }
350  case 3:
351  {
352  auto lodLevelEntity = prototype->getLODLevel3();
353  if (lodLevelEntity != nullptr) {
354  model = lodLevelEntity->getModel();
355  colorMul.set(lodLevelEntity->getColorMul());
356  colorAdd.set(lodLevelEntity->getColorAdd());
357  }
358  break;
359  }
360  case 4:
361  {
362  auto imposterLOD = prototype->getImposterLOD();
363  if (imposterLOD != nullptr) {
364  modelEntity = new ImposterObject(
365  "model",
366  imposterLOD->getModels()
367  );
368  // TODO: remove this duplicated code, see :368
369  modelEntity->setContributesShadows(true);
370  modelEntity->setReceivesShadows(true);
371  modelEntity->setEffectColorMul(colorMul);
372  modelEntity->setEffectColorAdd(colorAdd);
373  auto object = dynamic_cast<ImposterObject*>(modelEntity);
374  object->setShader(prototype->getShader());
375  for (const auto& parameterName: Engine::getShaderParameterNames(prototype->getShader())) {
376  auto parameterValue = prototype->getShaderParameters().getShaderParameter(parameterName);
377  object->setShaderParameter(parameterName, parameterValue);
378  }
379  engine->addEntity(modelEntity);
380  }
381  }
382  }
383  entityBoundingBox = prototype->getModel()->getBoundingBox();
384  if (model != nullptr) {
385  modelEntity = new Object("model", model);
386  modelEntity->setContributesShadows(true);
387  modelEntity->setReceivesShadows(true);
388  modelEntity->setEffectColorMul(colorMul);
389  modelEntity->setEffectColorAdd(colorAdd);
390  auto object = dynamic_cast<Object*>(modelEntity);
391  object->setShader(prototype->getShader());
392  for (const auto& parameterName: Engine::getShaderParameterNames(prototype->getShader())) {
393  auto parameterValue = prototype->getShaderParameters().getShaderParameter(parameterName);
394  object->setShaderParameter(parameterName, parameterValue);
395  }
396  engine->addEntity(modelEntity);
397  }
398  }
399 
400  //
401  auto entityBoundingBoxToUse = entityBoundingBox != nullptr?entityBoundingBox:entityBoundingBoxFallback.get();
402 
403  // do a feasible scale
404  float maxAxisDimension = Tools::computeMaxAxisDimension(entityBoundingBoxToUse);
405  if (maxAxisDimension < Math::EPSILON) maxAxisDimension = 1.0f;
406 
407  if (modelEntity != nullptr) {
408  modelEntity->setPickable(true);
409  modelEntity->setScale(objectScale);
410  modelEntity->update();
411  }
412 
413  // generate ground
414  auto ground = createGroundModel(
415  50.0f,
416  50.0f,
417  0.0f
418  );
419  auto groundObject = new Object("ground", ground);
420  groundObject->setEnabled(false);
421  groundObject->setScale(objectScale);
422  groundObject->setShader("solid");
423  groundObject->update();
424  engine->addEntity(groundObject);
425 
426  //
427  dynamic_cast<EntityHierarchy*>(engine->getEntity("tdme.prototype.bvs"))->setScale(objectScale);
428  dynamic_cast<EntityHierarchy*>(engine->getEntity("tdme.prototype.bvs"))->update();
429 
430  // if re setting up we do leave camera and lighting as it is
431  if (resetup == false) {
432  // lights
433  for (auto i = 1; i < engine->getLightCount(); i++) engine->getLightAt(i)->setEnabled(false);
434  auto light0 = engine->getLightAt(0);
435  light0->setAmbient(Color4(0.7f, 0.7f, 0.7f, 1.0f));
436  light0->setDiffuse(Color4(0.3f, 0.3f, 0.3f, 1.0f));
437  light0->setSpecular(Color4(1.0f, 1.0f, 1.0f, 1.0f));
438  light0->setPosition(
439  Vector4(
440  0.0f,
441  20.0f * maxAxisDimension,
442  20.0f * maxAxisDimension,
443  1.0f
444  )
445  );
446  light0->setSpotDirection(Vector3(0.0f, 0.0f, 0.0f).sub(Vector3(light0->getPosition().getX(), light0->getPosition().getY(), light0->getPosition().getZ())).normalize());
447  light0->setConstantAttenuation(0.5f);
448  light0->setLinearAttenuation(0.0f);
449  light0->setQuadraticAttenuation(0.0f);
450  light0->setSpotExponent(0.0f);
451  light0->setSpotCutOff(180.0f);
452  light0->setEnabled(true);
453 
454  // cam
455  auto cam = engine->getCamera();
456  auto lookAt = cam->getLookAt();
457  lookAt.set(entityBoundingBoxToUse->getCenter().clone().scale(objectScale));
458  Vector3 forwardVector(0.0f, 0.0f, 1.0f);
459  // TODO: a.drewke
460  Transform _lookFromRotations;
461  _lookFromRotations.setTransform(lookFromRotations);
462  if (cameraRotationInputHandler != nullptr) {
463  cameraRotationInputHandler->setDefaultScale(maxAxisDimension * scale);
464  cameraRotationInputHandler->setScale(maxAxisDimension * scale);
465  }
466  auto forwardVectorTransformed = _lookFromRotations.getTransformMatrix().multiply(forwardVector).scale(cameraRotationInputHandler != nullptr?cameraRotationInputHandler->getScale():maxAxisDimension * scale);
467  auto upVector = _lookFromRotations.getRotation(2).getQuaternion().multiply(Vector3(0.0f, 1.0f, 0.0f)).normalize();
468  auto lookFrom = lookAt.clone().add(forwardVectorTransformed);
469  cam->setLookFrom(lookFrom);
470  cam->setLookAt(lookAt);
471  cam->setUpVector(upVector);
472  } else {
473  if (cameraRotationInputHandler != nullptr) {
474  cameraRotationInputHandler->setDefaultScale(maxAxisDimension * scale);
475  }
476  }
477 }
478 
479 const string Tools::getRelativeResourcesFileName(const string& applicationRoot, const string& fileName)
480 {
481  auto newFileName = StringTools::replace(fileName, '\\', '/');
482  auto cutFileNameIdx = string::npos;
483  if (cutFileNameIdx == string::npos) {
484  cutFileNameIdx = fileName.rfind("/resources/");
485  if (cutFileNameIdx != string::npos) {
486  newFileName = StringTools::substring(fileName, cutFileNameIdx + 1);
487  }
488  }
489  if (cutFileNameIdx == string::npos) {
490  cutFileNameIdx = fileName.rfind("resources/");
491  if (cutFileNameIdx != string::npos) {
492  newFileName = StringTools::substring(fileName, cutFileNameIdx);
493  }
494  }
495  return newFileName;
496 }
497 
498 const string Tools::getApplicationRootPathName(const string& fileName)
499 {
500  auto newFileName = StringTools::replace(fileName, '\\', '/');
501  auto applicationRootPathNameIdx = string::npos;
502  if (applicationRootPathNameIdx == string::npos) {
503  applicationRootPathNameIdx = fileName.rfind("/resources/");
504  if (applicationRootPathNameIdx != string::npos) return StringTools::substring(fileName, 0, applicationRootPathNameIdx);
505  }
506  if (StringTools::startsWith(fileName, "resources/") == true) {
507  return "";
508  }
509  if (StringTools::endsWith(fileName, "/resources") == true) {
510  return StringTools::substring(fileName, 0, fileName.size() - string("/resources").size());
511  }
512  return "";
513 }
514 
515 const string Tools::getApplicationSubPathName(const string& fileName)
516 {
517  auto newFileName = StringTools::replace(fileName, '\\', '/');
518  auto applicationSubPathNameIdx = -1;
519  if (applicationSubPathNameIdx == -1) {
520  applicationSubPathNameIdx = fileName.rfind("/resources/");
521  if (applicationSubPathNameIdx != -1) {
522  applicationSubPathNameIdx+= string("/resources/").size();
523  auto applicationSubPathName = StringTools::substring(fileName, applicationSubPathNameIdx, fileName.find("/", applicationSubPathNameIdx));
524  if (applicationSubPathName == "engine") return applicationSubPathName; else
525  if (applicationSubPathName == "project") return applicationSubPathName; else
526  if (applicationSubPathName == "installer") return applicationSubPathName; else
527  return "engine";
528  }
529  }
530  if (applicationSubPathNameIdx == -1) {
531  applicationSubPathNameIdx = fileName.rfind("resources/");
532  if (applicationSubPathNameIdx != -1) {
533  applicationSubPathNameIdx+= string("resources/").size();
534  auto applicationSubPathName = StringTools::substring(fileName, applicationSubPathNameIdx, fileName.find("/", applicationSubPathNameIdx));
535  if (applicationSubPathName == "engine") return applicationSubPathName; else
536  if (applicationSubPathName == "project") return applicationSubPathName; else
537  if (applicationSubPathName == "installer") return applicationSubPathName; else
538  return "engine";
539  }
540  }
541  return "engine";
542 }
543 
544 const string Tools::getPathName(const string& fileName)
545 {
546  return FileSystem::getInstance()->getPathName(fileName);
547 }
548 
549 const string Tools::getFileName(const string& fileName)
550 {
551  return FileSystem::getInstance()->getFileName(fileName);
552 }
553 
554 const string Tools::removeFileExtension(const string& fileName)
555 {
556  auto idx = fileName.rfind('.');
557  if (idx == string::npos) {
558  return fileName;
559  } else {
560  return fileName.substr(0, idx);
561  }
562 }
563 
564 const string Tools::ensureFileExtension(const string& fileName, const string& extension)
565 {
566  if (StringTools::endsWith(StringTools::toLowerCase(fileName), "." + extension) == true) {
567  return fileName;
568  } else {
569  return removeFileExtension(fileName) + "." + extension;
570  }
571 }
572 
573 const string Tools::getFileExtension(const string& fileName)
574 {
575  auto idx = fileName.rfind('.');
576  if (idx == string::npos) {
577  return string();
578  } else {
579  return fileName.substr(idx + 1);
580  }
581 }
582 
583 void Tools::loadSettings(Application* application) {
584  Properties settings;
585 
586  // settings
587  try {
588  settings.load("settings", "settings.properties");
589  } catch (FileSystemException &exception) {
590  Console::println("Tools::loadSettings(): An error occurred: " + string(exception.what()));
591  }
592 
593  // 4k
594  if (settings.get("4k", "false") == "true") {
595  Engine::set4K(true);
596  }
597 
598  // Window
599  application->setWindowWidth(Integer::parse(settings.get("window_width", "1024")));
600  application->setWindowHeight(Integer::parse(settings.get("window_height", "768")));
601  application->setWindowXPosition(Integer::parse(settings.get("window_x", "-1")));
602  application->setWindowYPosition(Integer::parse(settings.get("window_y", "-1")));
603  application->setFullScreen(settings.get("fullscreen", "false") == "true");
604 }
605 
607  if (gizmoAll == nullptr) {
608  gizmoAll = ModelReader::read("resources/engine/models", "gizmo_all.tm");
609  ModelTools::prepareForShader(gizmoAll);
610  ModelTools::changeFrontFace(gizmoAll); // TODO: why is this needed currently
611  gizmoAll->setShaderModel(ShaderModel::SPECULAR);
612  }
613  return gizmoAll;
614 }
615 
617  if (gizmoTranslationScale == nullptr) {
618  gizmoTranslationScale = ModelReader::read("resources/engine/models", "gizmo_transscale.tm");
619  ModelTools::prepareForShader(gizmoTranslationScale);
620  ModelTools::changeFrontFace(gizmoTranslationScale); // TODO: why is this needed currently
621  gizmoTranslationScale->setShaderModel(ShaderModel::SPECULAR);
622  }
623  return gizmoTranslationScale;
624 }
625 
627  if (gizmoTranslation == nullptr) {
628  gizmoTranslation = ModelReader::read("resources/engine/models", "gizmo_translate.tm");
629  ModelTools::prepareForShader(gizmoTranslation);
630  ModelTools::changeFrontFace(gizmoTranslation); // TODO: why is this needed currently
631  gizmoTranslation->setShaderModel(ShaderModel::SPECULAR);
632  }
633  return gizmoTranslation;
634 }
635 
637  if (gizmoScale == nullptr) {
638  gizmoScale = ModelReader::read("resources/engine/models", "gizmo_scale.tm");
639  ModelTools::prepareForShader(gizmoScale);
640  ModelTools::changeFrontFace(gizmoScale); // TODO: why is this needed currently
641  gizmoScale->setShaderModel(ShaderModel::SPECULAR);
642  }
643  return gizmoScale;
644 }
645 
647  if (gizmoRotations == nullptr) {
648  gizmoRotations = ModelReader::read("resources/engine/models", "gizmo_rotate.tm");
649  ModelTools::prepareForShader(gizmoRotations);
650  ModelTools::changeFrontFace(gizmoRotations); // TODO: why is this needed currently
651  gizmoRotations->setShaderModel(ShaderModel::SPECULAR);
652  }
653  return gizmoRotations;
654 }
655 
657  if (defaultOBB == nullptr) {
659  Vector3(),
660  OrientedBoundingBox::AABB_AXIS_X,
661  OrientedBoundingBox::AABB_AXIS_Y,
662  OrientedBoundingBox::AABB_AXIS_Z,
663  Vector3(0.5f, 0.5f, 0.5f)
664  );
665  defaultOBB = Primitives::createModel(&obb, "tdme.obb.default");
666  }
667  return defaultOBB;
668 
669 }
670 
672  if (Application::hasApplication() == true) Tools::oseDispose();
673 };
674 
675 bool Tools::hasFileExtension(const string& fileName, const vector<string>& extensions) {
676  auto fileNameLowerCase = StringTools::toLowerCase(fileName);
677  for (const auto& extension: extensions) {
678  if (StringTools::endsWith(fileNameLowerCase, "." + extension) == true) return true;
679  }
680  return false;
681 }
Application base class, please make sure to allocate application on heap to have correct application ...
Definition: Application.h:41
void setWindowXPosition(int windowXPosition)
Set window X position when initializing.
void setWindowYPosition(int windowYPosition)
Set window Y position when initializing.
void setWindowWidth(int windowWidth)
Set window width.
void setFullScreen(bool fullScreen)
Set full screen mode.
void setWindowHeight(int windowHeight)
Set window height.
const Vector3 & getLookAt() const
Definition: Camera.h:234
Color 4 definition class.
Definition: Color4.h:18
void set(float r, float g, float b, float a)
Sets this color by its components.
Definition: Color4.h:66
Engine main class.
Definition: Engine.h:131
Light * getLightAt(int32_t idx)
Returns light at idx (0 <= idx < 8)
Definition: Engine.h:1143
int32_t getLightCount()
Definition: Engine.h:1134
void display()
Renders the scene.
Definition: Engine.cpp:1361
bool makeScreenshot(const string &pathName, const string &fileName, bool removeAlphaChannel=true)
Creates a PNG file from current screen( This does not seem to work with GLES2 and offscreen engines.
Definition: Engine.cpp:2151
Camera * getCamera()
Definition: Engine.h:1071
void setPartition(Partition *partition)
Set partition.
Definition: Engine.cpp:352
void addEntity(Entity *entity)
Adds an entity by id.
Definition: Engine.cpp:357
void dispose()
Shutdown the engine.
Definition: Engine.cpp:2071
Entity * getEntity(const string &id)
Returns a entity by given id.
Definition: Engine.h:1175
void reset()
Removes all entities and caches.
Definition: Engine.cpp:716
void setSceneColor(const Color4 &sceneColor)
Set scene color.
Definition: Engine.h:1159
Entity hierarchy to be used with engine class.
const ShaderParameter getShaderParameter(const string &parameterName) const
Returns shader parameter for given parameter name, if the value does not exist, the default will be r...
Engine entity.
Definition: Entity.h:30
virtual void setScale(const Vector3 &scale)=0
Set scale.
virtual void setEffectColorMul(const Color4 &effectColorMul)=0
Set effect color that will be multiplied with fragment color.
virtual void update()=0
Update transform.
virtual void setContributesShadows(bool contributesShadows)=0
Enable/disable contributes shadows.
virtual void setPickable(bool pickable)=0
Set this entity pickable.
virtual void setReceivesShadows(bool receivesShadows)=0
Enable/disable receives shadows.
virtual void setEffectColorAdd(const Color4 &effectColorAdd)=0
Set effect color that will be added to fragment color.
Imposter object to be used with engine class.
void setShader(const string &id)
Set shader id.
Light representation.
Definition: Light.h:33
void setEnabled(bool enabled)
Set enabled.
Definition: Light.h:87
void setSpecular(const Color4 &specular)
Set specular light component.
Definition: Light.h:132
void setConstantAttenuation(float constantAttenuation)
Set up constant attenuation.
Definition: Light.h:207
void setSpotDirection(const Vector3 &spotDirection)
Set spot direction.
Definition: Light.h:162
void setAmbient(const Color4 &ambient)
Set ambient light component.
Definition: Light.h:102
void setQuadraticAttenuation(float quadraticAttenuation)
Set up quadratic attenuation.
Definition: Light.h:237
void setSpotCutOff(float spotCutOff)
Set spot cut off.
Definition: Light.h:192
void setPosition(const Vector4 &position)
Set light position.
Definition: Light.h:147
const Vector4 & getPosition() const
Definition: Light.h:139
void setDiffuse(const Color4 &diffuse)
Set diffuse light component.
Definition: Light.h:117
void setLinearAttenuation(float linearAttenuation)
Set up linear attenuation.
Definition: Light.h:222
void setSpotExponent(float spotExponent)
Set up spot exponent.
Definition: Light.h:177
Object to be used with engine class.
Definition: Object.h:60
void setShader(const string &id)
Set shader.
Definition: Object.cpp:116
const Quaternion & getQuaternion() const
Definition: Rotation.h:124
Scene engine/physics connector.
Bogus/Simple partition implementation.
Texture entity.
Definition: Texture.h:24
Transform which contain scale, rotations and translation.
Definition: Transform.h:29
virtual void setTransform(const Transform &transform)
Set transform.
Definition: Transform.h:177
Rotation & getRotation(const int idx)
Get rotation at given index.
Definition: Transform.h:95
virtual void update()
Computes transform matrix.
Definition: Transform.cpp:33
void addRotation(const Vector3 &axis, const float angle)
Add rotation.
Definition: Transform.h:113
const Matrix4x4 & getTransformMatrix() const
Definition: Transform.h:169
Represents a model face, consisting of vertex, normal, tangent and bitangent vectors,...
Definition: Face.h:18
Node faces entity A node can have multiple entities containing faces and a applied material.
Definition: FacesEntity.h:23
void setMaterial(Material *material)
Set up the entity's material.
Definition: FacesEntity.h:67
void setFaces(const vector< Face > &faces)
Set up entity's faces.
Definition: FacesEntity.cpp:43
Represents a material.
Definition: Material.h:23
Representation of a 3D model.
Definition: Model.h:35
void setShaderModel(ShaderModel *shaderModel)
Set preferred shader model.
Definition: Model.h:172
BoundingBox * getBoundingBox()
Definition: Model.cpp:150
Model node.
Definition: Node.h:32
Represents rotation orders of a model.
Definition: RotationOrder.h:23
Represents specular material properties.
Model up vector.
Definition: UpVector.h:20
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
Definition: BoundingBox.h:26
Oriented bounding box physics primitive.
Prototype LOD level definition.
Prototype definition.
Definition: Prototype.h:55
PrototypeLODLevel * getLODLevel3()
Definition: Prototype.h:341
PrototypeImposterLOD * getImposterLOD()
Definition: Prototype.h:360
const string & getShader()
Get shader.
Definition: Prototype.h:480
UniquePtrSequenceIterator< PrototypeBoundingVolume > getBoundingVolumes()
Definition: Prototype.h:272
PrototypeLODLevel * getLODLevel2()
Definition: Prototype.h:328
const EntityShaderParameters & getShaderParameters()
Get shader parameters.
Definition: Prototype.h:497
Standard math functions.
Definition: Math.h:19
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Definition: Matrix4x4.h:23
Vector3 multiply(const Vector3 &vector3) const
Multiplies this matrix with vector3.
Definition: Matrix4x4.h:225
Quaternion class representing quaternion mathematical structure and operations with x,...
Definition: Quaternion.h:24
Quaternion & add(const Quaternion &quaternion)
Adds quaternion.
Definition: Quaternion.h:239
Quaternion & multiply(const Quaternion quaternion)
Multiplies this quaternion with given quaternion.
Definition: Quaternion.h:278
Quaternion clone() const
Clones this quaternion.
Definition: Quaternion.h:427
Quaternion & normalize()
Normalizes this quaternion.
Definition: Quaternion.h:346
Vector2 class representing vector2 mathematical structure and operations with x, y components.
Definition: Vector2.h:20
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
float getY() const
Definition: Vector3.h:117
float getX() const
Definition: Vector3.h:100
float getZ() const
Definition: Vector3.h:134
Vector3 clone() const
Clones this vector3.
Definition: Vector3.h:374
Vector3 & sub(float scalar)
Subtracts a scalar.
Definition: Vector3.h:177
Vector3 & scale(float scalar)
Scales by scalar.
Definition: Vector3.h:201
Vector3 & set(float x, float y, float z)
Sets this vector3 by its components.
Definition: Vector3.h:70
Vector4 class representing vector4 mathematical structure and operations with x, y,...
Definition: Vector4.h:22
float getY() const
Definition: Vector4.h:159
float getX() const
Definition: Vector4.h:142
float getZ() const
Definition: Vector4.h:176
File system singleton class.
Definition: FileSystem.h:17
void setDefaultScale(float defaultScale)
Set default scale.
static const string getApplicationRootPathName(const string &fileName)
Get application root path name.
Definition: Tools.cpp:498
static STATIC_DLL_IMPEXT Model * gizmoTranslation
Definition: Tools.h:42
static STATIC_DLL_IMPEXT Model * defaultOBB
Definition: Tools.h:45
static bool hasFileExtension(const string &fileName, const vector< string > &extensions)
Returns if file extension of given file name does match a extension in given extensions.
Definition: Tools.cpp:675
static const string removeFileExtension(const string &fileName)
Remove file extension, e.g.
Definition: Tools.cpp:554
static STATIC_DLL_IMPEXT Model * gizmoRotations
Definition: Tools.h:44
static STATIC_DLL_IMPEXT Model * gizmoTranslationScale
Definition: Tools.h:41
static Model * getGizmoTranslation()
Definition: Tools.cpp:626
static void oseInit()
Init off screen engine for making thumbails.
Definition: Tools.cpp:147
static void setDefaultLight(Light *light)
Set up given engine light with default light.
Definition: Tools.cpp:132
static Model * getGizmoTranslationScale()
Definition: Tools.cpp:616
static Model * getGizmoScale()
Definition: Tools.cpp:636
static STATIC_DLL_IMPEXT Model * gizmoScale
Definition: Tools.h:43
static Model * createGroundModel(float width, float depth, float y)
Creates ground plate with 1m x 1m texture.
Definition: Tools.cpp:193
static void loadSettings(Application *application)
Load settings.
Definition: Tools.cpp:583
static STATIC_DLL_IMPEXT Model * gizmoAll
Definition: Tools.h:40
static const string getFileExtension(const string &fileName)
Get file extension.
Definition: Tools.cpp:573
static STATIC_DLL_IMPEXT Engine * osEngine
Definition: Tools.h:39
static const string getFileName(const string &fileName)
Get file name of given file name.
Definition: Tools.cpp:549
static void setupPrototype(Prototype *prototype, Engine *engine, const Transform &lookFromRotations, int lodLevel, Vector3 &objectScale, CameraRotationInputHandler *cameraRotationInputHandler=nullptr, float scale=1.5f, bool resetup=false)
Set up entity in given engine with look from rotations and scale.
Definition: Tools.cpp:295
static const string getRelativeResourcesFileName(const string &applicationRoot, const string &fileName)
Get relative resources file name.
Definition: Tools.cpp:479
static float computeMaxAxisDimension(BoundingBox *boundingBox)
Compute max axis dimension for given bounding box.
Definition: Tools.cpp:183
static Model * createGridModel()
Creates grid plate with 1m x 1m texture.
Definition: Tools.cpp:240
static void oseThumbnail(Prototype *prototype, vector< uint8_t > &pngData)
Make a thumbnail of given prototype with off screen engine.
Definition: Tools.cpp:162
static void oseDispose()
Dispose off screen engine.
Definition: Tools.cpp:155
static Model * getGizmoRotations()
Definition: Tools.cpp:646
static const string ensureFileExtension(const string &fileName, const string &extension)
Ensure file extension.
Definition: Tools.cpp:564
static const string getPathName(const string &fileName)
Get path of given file name.
Definition: Tools.cpp:544
static Model * getGizmoAll()
Definition: Tools.cpp:606
static Model * getDefaultObb()
Definition: Tools.cpp:656
static const string getApplicationSubPathName(const string &fileName)
Get application sub path name.
Definition: Tools.cpp:515
Console class.
Definition: Console.h:29
Float class.
Definition: Float.h:27
Integer class.
Definition: Integer.h:25
Model tools functions class.
Definition: ModelTools.h:42
Helper class to create models from physics primitive bounding volumes.
Definition: Primitives.h:33
Properties class, which helps out with storeing or loading key value pairs from/to property files.
Definition: Properties.h:23
const string & get(const string &key, const string &defaultValue) const
Get property value by key.
Definition: Properties.h:46
void load(const string &pathName, const string &fileName, FileSystemInterface *fileSystem=nullptr)
Load property file.
Definition: Properties.cpp:24
String tokenizer class.
String tools class.
Definition: StringTools.h:22
std::exception Exception
Exception base class.
Definition: Exception.h:18