5 #include <unordered_set>
49 using std::make_unique;
52 using std::unique_ptr;
53 using std::unordered_set;
97 SceneEditorTabView::SceneEditorTabView(
EditorView* editorView,
const string& tabId,
Scene* scene):
Gizmo(nullptr,
"le")
102 engine = unique_ptr<Engine>(Engine::createOffScreenInstance(512, 512,
true,
true,
true));
103 engine->setSceneColor(
Color4(39.0f / 255.0f, 39.0f / 255.0f, 39.0f / 255.0f, 1.0f));
104 engine->setSkyShaderEnabled(
true);
105 this->scene = unique_ptr<Scene>(
scene);
123 this->
gridModel = unique_ptr<Model>(Tools::createGridModel());
144 bool filterEntity(
Entity* entity)
override {
145 return entity->
getId() !=
"tdme.sceneeditor.grid";
152 PrototypePickingFilterNoGrid(
SceneEditorTabView* sceneEditorTabView): sceneEditorTabView(sceneEditorTabView) {
168 bool filterEntity(
Entity* entity)
override {
170 entity->
getId() !=
"tdme.sceneeditor.placeentity" &&
171 StringTools::startsWith(entity->
getId(),
"tdme.sceneeditor.paste.") ==
false &&
172 StringTools::startsWith(entity->
getId(),
"le.tdme.gizmo.") ==
false;
179 PrototypePickingFilterPlacing(
SceneEditorTabView* sceneEditorTabView): sceneEditorTabView(sceneEditorTabView) {
200 auto gui =
engine->getGUI();
202 gui->handleEvents(
false);
204 applicationClient->handleHIDEvents(gui->getMouseEvents(), gui->getKeyboardEvents());
206 gui->getMouseEvents().clear();
207 gui->getKeyboardEvents().clear();
213 auto keyControlX =
false;
214 auto keyControlC =
false;
215 auto keyControlV =
false;
216 auto keyDelete =
false;
217 for (
auto& event:
engine->getGUI()->getKeyboardEvents()) {
218 if (event.isProcessed() ==
true)
continue;
219 if (event.getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_TYPED)
continue;
220 auto isKeyDown =
event.getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED;
223 event.setProcessed(
true);
227 event.setProcessed(
true);
229 if (event.getKeyCode() == GUIKeyboardEvent::KEYCODE_ESCAPE) {
231 event.setProcessed(
true);
233 if (event.getKeyCode() == GUIKeyboardEvent::KEYCODE_BACKSPACE ||
234 event.getKeyCode() == GUIKeyboardEvent::KEYCODE_DELETE) {
235 keyDelete = isKeyDown;
236 event.setProcessed(
true);
239 if (Character::toLowerCase(event.getKeyChar()) ==
'x' &&
keyControl ==
true) {
240 keyControlX = isKeyDown;
241 event.setProcessed(
true);
243 if (Character::toLowerCase(event.getKeyChar()) ==
'c' &&
keyControl ==
true) {
244 keyControlC = isKeyDown;
245 event.setProcessed(
true);
247 if (Character::toLowerCase(event.getKeyChar()) ==
'v' &&
keyControl ==
true) {
248 keyControlV = isKeyDown;
249 event.setProcessed(
true);
252 if (Character::toLowerCase(event.getKeyChar()) ==
'.' && !isKeyDown ==
false) {
254 event.setProcessed(
true);
256 if (Character::toLowerCase(event.getKeyChar()) ==
',' && !isKeyDown ==
false) {
258 event.setProcessed(
true);
260 if (Character::toLowerCase(event.getKeyChar()) ==
'1' && isKeyDown ==
true) {
263 event.setProcessed(
true);
265 if (Character::toLowerCase(event.getKeyChar()) ==
'2' && isKeyDown ==
true) {
268 event.setProcessed(
true);
270 if (Character::toLowerCase(event.getKeyChar()) ==
'3' && isKeyDown ==
true) {
273 event.setProcessed(
true);
275 if (Character::toLowerCase(event.getKeyChar()) ==
'4' && isKeyDown ==
true) {
278 event.setProcessed(
true);
281 for (
auto& event:
engine->getGUI()->getMouseEvents()) {
282 if ((event.getType() == GUIMouseEvent::MOUSEEVENT_MOVED ||
283 event.getType() == GUIMouseEvent::MOUSEEVENT_DRAGGED) &&
284 event.getXUnscaled() >= 0 &&
285 event.getYUnscaled() >= 0) {
290 if (event.isProcessed() ==
true)
continue;
293 if (event.getType() == GUIMouseEvent::MOUSEEVENT_DRAGGED) {
297 event.setProcessed(
true);
303 event.setProcessed(
true);
308 if (event.getType() == GUIMouseEvent::MOUSEEVENT_RELEASED) {
319 auto _selectedEntity =
engine->getEntity(selectedEntityId);
320 if (_selectedEntity ==
nullptr)
continue;
321 auto sceneEntity =
scene->getEntity(_selectedEntity->getId());
322 if (sceneEntity ==
nullptr)
continue;
323 auto rotationEuler = _selectedEntity->getRotationsQuaternion().computeMatrix().computeEulerAngles();
324 _selectedEntity->setRotationAngle(
scene->getRotationOrder()->getAxisXIndex(), rotationEuler[0]);
325 _selectedEntity->setRotationAngle(
scene->getRotationOrder()->getAxisYIndex(), rotationEuler[1]);
326 _selectedEntity->setRotationAngle(
scene->getRotationOrder()->getAxisZIndex(), rotationEuler[2]);
327 while (_selectedEntity->getRotationCount() > 3) _selectedEntity->removeRotation(_selectedEntity->getRotationCount() - 1);
328 _selectedEntity->update();
329 sceneEntity->getTransform().setTransform(_selectedEntity->getTransform());
334 event.setProcessed(
true);
337 Node* selectedEntityNode =
nullptr;
338 Entity* selectedEntity =
nullptr;
346 if (gizmoEntity !=
nullptr) {
348 auto _selectedEntity =
engine->getEntity(selectedEntityId);
349 if (_selectedEntity !=
nullptr && StringTools::startsWith(_selectedEntity->getId(),
"tdme.sceneeditor.") ==
false) {
350 auto sceneEntity =
scene->getEntity(_selectedEntity->getId());
351 if (sceneEntity ==
nullptr)
continue;
352 _selectedEntity->setTranslation(_selectedEntity->getTransform().getTranslation().clone().add(deltaTranslation));
353 auto scale = _selectedEntity->getScale().clone().scale(absoluteScale);
354 if (Math::abs(scale.getX()) < 0.01f) scale.setX(Math::sign(scale.getX()) * 0.01f);
355 if (Math::abs(scale.getY()) < 0.01f) scale.setY(Math::sign(scale.getY()) * 0.01f);
356 if (Math::abs(scale.getZ()) < 0.01f) scale.setZ(Math::sign(scale.getZ()) * 0.01f);
357 if (Math::abs(scale.getX()) > 100.0f) scale.setX(Math::sign(scale.getX()) * 100.0f);
358 if (Math::abs(scale.getY()) > 100.0f) scale.setY(Math::sign(scale.getY()) * 100.0f);
359 if (Math::abs(scale.getZ()) > 100.0f) scale.setZ(Math::sign(scale.getZ()) * 100.0f);
360 _selectedEntity->setScale(scale);
361 if ((sceneEntity->getPrototype()->getType()->getGizmoTypeMask() & Gizmo::GIZMOTYPE_ROTATE) == Gizmo::GIZMOTYPE_ROTATE &&
363 if (_selectedEntity->getRotationCount() == 3) {
364 _selectedEntity->addRotation(
scene->getRotationOrder()->getAxis0(), 0.0f);
365 _selectedEntity->addRotation(
scene->getRotationOrder()->getAxis1(), 0.0f);
366 _selectedEntity->addRotation(
scene->getRotationOrder()->getAxis2(), 0.0f);
368 _selectedEntity->setRotationAngle(3 +
scene->getRotationOrder()->getAxisXIndex(), _selectedEntity->getRotationAngle(3 +
scene->getRotationOrder()->getAxisXIndex()) + deltaRotation[0]);
369 _selectedEntity->setRotationAngle(3 +
scene->getRotationOrder()->getAxisYIndex(), _selectedEntity->getRotationAngle(3 +
scene->getRotationOrder()->getAxisYIndex()) + deltaRotation[1]);
370 _selectedEntity->setRotationAngle(3 +
scene->getRotationOrder()->getAxisZIndex(), _selectedEntity->getRotationAngle(3 +
scene->getRotationOrder()->getAxisZIndex()) + deltaRotation[2]);
372 _selectedEntity->update();
377 if (_selectedEntity !=
nullptr) {
388 if (Math::abs(deltaTranslation.
getX()) > Math::EPSILON ||
389 Math::abs(deltaTranslation.
getY()) > Math::EPSILON ||
390 Math::abs(deltaTranslation.
getZ()) > Math::EPSILON) {
398 if (selectedEntity !=
nullptr &&
scene->getEntity(selectedEntity->
getId()) ==
nullptr) selectedEntity =
nullptr;
400 vector<Entity*> entitiesToRemove;
402 auto selectedEntity =
engine->getEntity(selectedEntityId);
406 if (selectedEntity !=
nullptr) entitiesToRemove.push_back(selectedEntity);
409 for (
const auto& entityToRemove: entitiesToRemove) {
419 if (selectedEntity !=
nullptr) {
435 auto sceneEntity =
scene->getEntity(selectedEntity->
getId());
436 if (sceneEntity !=
nullptr && sceneEntity->getPrototype()->getType()->hasNonEditScaleDownMode() ==
true) {
437 selectedEntity->
setTransform(sceneEntity->getTransform());
453 event.setProcessed(
true);
457 if (keyDelete ==
true) {
461 if (keyControlX ==
true) {
466 if (keyControlC ==
true) {
469 if (keyControlV ==
true) {
487 engine->getGUI()->render();
500 auto selectedEngineEntity =
engine->getEntity(
"tdme.sceneeditor.placeentity");
514 if (selectedEngineEntity !=
nullptr)
engine->addEntity(selectedEngineEntity);
516 if (selectedEngineEntity !=
nullptr) {
520 Vector3 snappedWorldCoordinate;
522 worldCoordinate = snappedWorldCoordinate;
528 selectedEngineEntity->setTransform(transform);
537 Vector3 snappedWorldCoordinate;
539 worldCoordinate = snappedWorldCoordinate;
571 Console::println(
"SceneEditorTabView::initialize(): An error occurred: " +
string(exception.what()));
574 SceneConnector::setLights(
engine.get(),
scene.get());
575 SceneConnector::addScene(
engine.get(),
scene.get(),
true,
true,
true,
true,
true);
610 const auto& skyShaderParameters =
scene->getSkyShaderParameters();
611 for (
const auto& parameterName: Engine::getShaderParameterNames(
"sky")) {
612 engine->setShaderParameter(
"sky", parameterName, skyShaderParameters.getShaderParameter(parameterName));
618 engine->resetPostProcessingPrograms();
620 for (
const auto& shaderId: Engine::getRegisteredShader(Engine::SHADERTYPE_POSTPROCESSING,
false)) {
622 if (
scene->isPostProcessingShaderEnabled(shaderId) ==
true) {
623 engine->addPostProcessingProgram(shaderId);
626 for (
const auto& parameterName: Engine::getShaderParameterNames(shaderId)) {
628 auto parameterDefaults = Engine::getDefaultShaderParameter(shaderId, parameterName);
629 if (parameterDefaults ==
nullptr) {
633 auto shaderParameters =
scene->getPostProcessingShaderParameters(shaderId);
634 if (shaderParameters ==
nullptr) {
638 engine->setShaderParameter(shaderId, parameterName, shaderParameters->getShaderParameter(parameterName));
645 SceneConnector::resetEngine(
engine.get(),
scene.get());
667 SceneConnector::addScene(
engine.get(),
scene.get(),
true,
true,
true,
true,
true);
694 SceneConnector::setLights(
engine.get(),
scene.get());
699 auto sceneEntity =
scene->getEntity(entity->
getId());
700 if (sceneEntity !=
nullptr && sceneEntity->getPrototype()->getType() == Prototype_Type::DECAL) {
702 auto decalObbEntity = decalEntityHierarchy !=
nullptr?decalEntityHierarchy->
getEntity(
"tdme.prototype.bv.0"):
nullptr;
703 if (decalObbEntity !=
nullptr) decalObbEntity->
setEnabled(
true);
715 auto sceneEntity =
scene->getEntity(entity->
getId());
716 if (sceneEntity ==
nullptr)
return;
717 auto colorProperty = sceneEntity->getProperty(
"object.color");
718 if (colorProperty ==
nullptr) colorProperty = sceneEntity->getPrototype()->getProperty(
"object.color");
719 if (colorProperty !=
nullptr) {
720 auto entityColorIt =
entityColors.find(colorProperty->getValue());
722 const auto& entityColor = entityColorIt->second;
727 if (sceneEntity !=
nullptr && sceneEntity->getPrototype()->getType() == Prototype_Type::DECAL) {
729 auto decalObbEntity = decalEntityHierarchy !=
nullptr?decalEntityHierarchy->
getEntity(
"tdme.prototype.bv.0"):
nullptr;
730 if (decalObbEntity !=
nullptr) decalObbEntity->
setEnabled(
false);
735 if (entity ==
nullptr)
return;
737 auto sceneEntity =
scene->getEntity(entity->
getId());
738 if (sceneEntity ==
nullptr)
return;
739 if (sceneEntity->getPrototype()->getType()->hasNonEditScaleDownMode() ==
false)
return;
742 sceneEntity->getPrototype()->getType()->getNonEditScaleDownModeDimension().
759 auto entityToRemove =
engine->getEntity(entityIdToRemove);
764 for (
const auto& entityId: entityIds) {
765 auto selectedEntity =
engine->getEntity(entityId);
766 if (selectedEntity ==
nullptr)
continue;
772 if (entityIds.size() == 1) {
773 auto selectedEntity =
engine->getEntity(entityIds[0]);
774 if (selectedEntity !=
nullptr) {
779 if (entityIds.size() > 1) {
791 auto entityToUnselect =
engine->getEntity(entityIdToUnselect);
792 if (entityToUnselect ==
nullptr)
continue;
803 auto selectedEntity =
engine->getEntity(selectedEntityId);
804 if (selectedEntity !=
nullptr && StringTools::startsWith(selectedEntity->getId(),
"tdme.sceneeditor.") ==
false) {
805 auto sceneEntity =
scene->getEntity(selectedEntity->getId());
806 if (sceneEntity ==
nullptr)
continue;
823 engine->removeEntity(
"tdme.sceneeditor.placeentity");
843 sceneEntityTransform.
addRotation(
scene->getRotationOrder()->getAxis0(), 0.0f);
844 sceneEntityTransform.
addRotation(
scene->getRotationOrder()->getAxis1(), 0.0f);
845 sceneEntityTransform.
addRotation(
scene->getRotationOrder()->getAxis2(), 0.0f);
847 sceneEntityTransform.
update();
848 for (
auto i = 0; i <
scene->getEntityCount(); i++) {
849 auto sceneEntity =
scene->getEntityAt(i);
857 sceneEntityTransform,
860 scene->addEntity(sceneEntity);
863 if (entity !=
nullptr) {
865 entity->setPickable(
true);
866 engine->addEntity(entity);
885 vector<Entity*> entitiesToRemove;
887 Entity* selectedEntity =
engine->getEntity(selectedEntityId);
888 if (selectedEntity !=
nullptr && StringTools::startsWith(selectedEntity->
getId(),
"tdme.sceneeditor.") ==
false) {
891 entitiesToRemove.push_back(selectedEntity);
894 for (
const auto& entityToRemove: entitiesToRemove) {
916 auto pasteEntityIdx = 0;
918 auto pastePrototype = pasteEntity->getPrototype();
919 auto entityId =
"tdme.sceneeditor.paste." + pastePrototype->getName() +
"." + to_string(pasteEntityIdx);
920 engine->removeEntity(entityId);
929 auto pasteEntitiesMinX = Float::MAX_VALUE;
930 auto pasteEntitiesMinZ = Float::MAX_VALUE;
931 auto pasteEntitiesMinY = Float::MAX_VALUE;
932 auto pasteEntitiesMaxX = Float::MIN_VALUE;
933 auto pasteEntitiesMaxZ = Float::MIN_VALUE;
934 auto pasteEntitiesMaxY = Float::MIN_VALUE;
936 auto entity =
engine->getEntity(copiedEntity->getId());
937 if (entity ==
nullptr)
continue;
940 const auto& entityBBMin = cbv.
getMin();
941 if (entityBBMin[0] < pasteEntitiesMinX) pasteEntitiesMinX = entityBBMin[0];
942 if (entityBBMin[1] < pasteEntitiesMinY) pasteEntitiesMinY = entityBBMin[1];
943 if (entityBBMin[2] < pasteEntitiesMinZ) pasteEntitiesMinZ = entityBBMin[2];
944 const auto& entityBBMax = cbv.
getMax();
945 if (entityBBMax[0] > pasteEntitiesMaxX) pasteEntitiesMaxX = entityBBMax[0];
946 if (entityBBMax[1] > pasteEntitiesMaxY) pasteEntitiesMaxY = entityBBMax[1];
947 if (entityBBMax[2] > pasteEntitiesMaxZ) pasteEntitiesMaxZ = entityBBMax[2];
949 auto centerX = (pasteEntitiesMaxX - pasteEntitiesMinX) / 2.0f;
950 auto centerZ = (pasteEntitiesMaxZ - pasteEntitiesMinZ) / 2.0f;
951 auto pasteEntitiesIdx = 0;
952 vector<string> entitiesToSelect;
954 auto pastePrototype = copiedEntity->getPrototype();
956 sceneEntityTransform.
setTransform(copiedEntity->getTransform());
957 auto entityDiffX = copiedEntity->getTransform().getTranslation().getX() - pasteEntitiesMinX;
958 auto entityDiffY = copiedEntity->getTransform().getTranslation().getY() - pasteEntitiesMinY;
959 auto entityDiffZ = copiedEntity->getTransform().getTranslation().getZ() - pasteEntitiesMinZ;
967 sceneEntityTransform.
update();
968 if (displayOnly ==
false) {
970 auto sceneEntityId = pastePrototype->getName() +
"_" + to_string(
scene->allocateEntityId());
974 sceneEntityTransform,
979 sceneEntity->
addProperty(property->getName(), property->getValue());
981 scene->addEntity(sceneEntity);
982 auto entity =
createEntity(pastePrototype, sceneEntityId, sceneEntityTransform);
983 if (entity !=
nullptr) {
985 entity->setPickable(
true);
986 engine->addEntity(entity);
988 entitiesToSelect.push_back(sceneEntityId);
990 auto entityId =
"tdme.sceneeditor.paste." + pastePrototype->getName() +
"." + to_string(pasteEntitiesIdx);
991 auto entity =
engine->getEntity(entityId);
992 if (entity !=
nullptr) {
993 entity->setTransform(sceneEntityTransform);
995 entity =
createEntity(pastePrototype, entityId, sceneEntityTransform);
996 if (entity !=
nullptr) {
998 entity->setPickable(
true);
999 engine->addEntity(entity);
1007 if (displayOnly ==
false) {
1011 for (
const auto& entityId: entitiesToSelect) {
1020 auto entityCount = 0;
1022 auto selectedEntity =
engine->getEntity(selectedEntityId);
1023 if (selectedEntity !=
nullptr && StringTools::startsWith(selectedEntity->getId(),
"tdme.sceneeditor.") ==
false) {
1024 auto sceneEntity =
scene->getEntity(selectedEntity->getId());
1025 if (sceneEntity ==
nullptr)
continue;
1026 pivot.
add(sceneEntity->getTransform().getTranslation());
1030 if (entityCount > 1) pivot.
scale(1.0f / entityCount);
1035 string selectedEnvironmentMappingId;
1037 auto selectedEntity =
engine->getEntity(selectedEntityId);
1038 if (selectedEntity !=
nullptr && StringTools::startsWith(selectedEntity->getId(),
"tdme.sceneeditor.") ==
false) {
1039 auto sceneEntity =
scene->getEntity(selectedEntity->getId());
1040 if (sceneEntity ==
nullptr)
continue;
1041 if (selectedEnvironmentMappingId.empty() ==
true) {
1042 selectedEnvironmentMappingId = sceneEntity->getReflectionEnvironmentMappingId();
1044 if (selectedEnvironmentMappingId != sceneEntity->getReflectionEnvironmentMappingId()) {
1045 selectedEnvironmentMappingId.clear();
1046 return selectedEnvironmentMappingId;
1050 return selectedEnvironmentMappingId;
1060 auto selectedEntity =
engine->getEntity(selectedEntityId);
1061 if (selectedEntity ==
nullptr)
continue;
1062 center.
add(selectedEntity->getWorldBoundingBox()->getMin().clone().add(selectedEntity->getWorldBoundingBox()->getMax()).scale(0.5f));
1075 auto prototype = sceneEntity !=
nullptr?sceneEntity->getPrototype():
nullptr;
1076 vector<string> entitiesToSelect;
1077 for (
auto _sceneEntity:
scene->getEntities()) {
1078 if (_sceneEntity->getPrototype() != prototype)
continue;
1080 entitiesToSelect.push_back(_sceneEntity->getId());
1093 auto prototype = sceneEntity !=
nullptr?sceneEntity->getPrototype():
nullptr;
1094 if (prototype ==
nullptr || prototype->getFileName().empty() ==
true) {
1112 auto entityCount = 0;
1114 auto selectedEntity =
engine->getEntity(selectedEntityId);
1115 if (selectedEntity !=
nullptr && StringTools::startsWith(selectedEntity->getId(),
"tdme.sceneeditor.") ==
false) {
1116 auto sceneEntity =
scene->getEntity(selectedEntity->getId());
1117 if (sceneEntity ==
nullptr)
continue;
1118 gizmoCenter.
add(selectedEntity->getTransform().getTranslation());
1122 if (entityCount == 0) {
1126 if (entityCount == 1) {
1128 auto selectedPrototype = selectedSceneEntity !=
nullptr?selectedSceneEntity->getPrototype():
nullptr;
1129 if (selectedSceneEntity !=
nullptr) transform.
setTransform(selectedSceneEntity->getTransform());
1135 gizmoCenter.
scale(1.0f / entityCount);
1139 Gizmo::updateGizmo(gizmoCenter, transform);
1146 if (selectedEntity ==
nullptr || StringTools::startsWith(selectedEntity->getId(),
"tdme.sceneeditor."))
return false;
1148 auto sceneEntity =
scene->getEntity(selectedEntity->getId());
1149 if (sceneEntity ==
nullptr)
return false;
1151 sceneEntity->setDescription(description);
1152 auto oldName = sceneEntity->getId();
1153 if (oldName == name)
return true;
1155 if (
engine->getEntity(name) !=
nullptr)
return false;
1156 if (
scene->renameEntity(sceneEntity->getId(), name) ==
true) {
1157 engine->removeEntity(oldName);
1161 if (entity ==
nullptr) {
1167 entity->setPickable(
true);
1168 engine->addEntity(entity);
1184 if (selectedEntity ==
nullptr)
return;
1185 auto sceneEntity =
scene->getEntity(selectedEntity->getId());
1186 if (sceneEntity ==
nullptr)
return;
1188 sceneEntity->getTransform().setTranslation(translation);
1189 sceneEntity->getTransform().update();
1190 selectedEntity->setTransform(sceneEntity->getTransform());
1194 auto selectedEntity =
engine->getEntity(selectedEntityId);
1195 if (selectedEntity ==
nullptr)
continue;
1196 auto sceneEntity =
scene->getEntity(selectedEntity->getId());
1197 if (sceneEntity ==
nullptr)
continue;
1199 sceneEntity->getTransform().setTranslation(
1202 sceneEntity->getTransform().update();
1203 selectedEntity->setTransform(sceneEntity->getTransform());
1218 if (selectedEntity ==
nullptr)
return;
1219 auto sceneEntity =
scene->getEntity(selectedEntity->getId());
1220 if (sceneEntity ==
nullptr)
return;
1221 sceneEntity->getTransform().getRotation(
scene->getRotationOrder()->getAxisXIndex()).setAngle(rotation.
getX());
1222 sceneEntity->getTransform().getRotation(
scene->getRotationOrder()->getAxisYIndex()).setAngle(rotation.
getY());
1223 sceneEntity->getTransform().getRotation(
scene->getRotationOrder()->getAxisZIndex()).setAngle(rotation.
getZ());
1224 sceneEntity->getTransform().update();
1225 selectedEntity->setTransform(sceneEntity->getTransform());
1229 auto selectedEntity =
engine->getEntity(selectedEntityId);
1230 if (selectedEntity ==
nullptr)
continue;
1231 auto sceneEntity =
scene->getEntity(selectedEntity->getId());
1232 if (sceneEntity ==
nullptr)
continue;
1233 if ((sceneEntity->getPrototype()->getType()->getGizmoTypeMask() & Gizmo::GIZMOTYPE_ROTATE) == Gizmo::GIZMOTYPE_ROTATE) {
1234 sceneEntity->getTransform().getRotation(
scene->getRotationOrder()->getAxisXIndex()).setAngle(sceneEntity->getTransform().getRotation(
scene->getRotationOrder()->getAxisXIndex()).getAngle() + (rotation.
getX() -
multipleSelectionRotation.
getX()));
1235 sceneEntity->getTransform().getRotation(
scene->getRotationOrder()->getAxisYIndex()).setAngle(sceneEntity->getTransform().getRotation(
scene->getRotationOrder()->getAxisYIndex()).getAngle() + (rotation.
getY() -
multipleSelectionRotation.
getY()));
1236 sceneEntity->getTransform().getRotation(
scene->getRotationOrder()->getAxisZIndex()).setAngle(sceneEntity->getTransform().getRotation(
scene->getRotationOrder()->getAxisZIndex()).getAngle() + (rotation.
getZ() -
multipleSelectionRotation.
getZ()));
1238 sceneEntity->getTransform().update();
1239 selectedEntity->setTransform(sceneEntity->getTransform());
1254 if (selectedEntity ==
nullptr)
return;
1255 auto sceneEntity =
scene->getEntity(selectedEntity->getId());
1256 if (sceneEntity ==
nullptr)
return;
1258 sceneEntity->getTransform().setScale(
Vector3(scale));
1259 sceneEntity->getTransform().update();
1260 selectedEntity->setTransform(sceneEntity->getTransform());
1264 auto selectedEntity =
engine->getEntity(selectedEntityId);
1265 if (selectedEntity ==
nullptr)
continue;
1266 auto sceneEntity =
scene->getEntity(selectedEntity->getId());
1267 if (sceneEntity ==
nullptr)
continue;
1269 sceneEntity->getTransform().setScale(sceneEntity->getTransform().getScale().clone().scale(scale /
multipleSelectionScale));
1270 sceneEntity->getTransform().update();
1271 selectedEntity->setTransform(sceneEntity->getTransform());
1285 auto selectedEntity =
engine->getEntity(selectedEntityId);
1286 if (selectedEntity ==
nullptr)
continue;
1287 auto sceneEntity =
scene->getEntity(selectedEntity->getId());
1288 if (sceneEntity ==
nullptr)
continue;
1290 auto object =
dynamic_cast<Object*
>(selectedEntity);
1292 sceneEntity->setReflectionEnvironmentMappingId(reflectionEnvironmentMappingId);
1319 this->gridY =
gridY;
1328 string entityId =
"tdme.sceneeditor.grid";
1329 auto entity =
engine->getEntity(entityId);
1330 if (entity ==
nullptr) {
1332 entity->setFrustumCulling(
false);
1333 entity->addRotation(
scene->getRotationOrder()->getAxis0(), 0.0f);
1334 entity->addRotation(
scene->getRotationOrder()->getAxis1(), 0.0f);
1335 entity->addRotation(
scene->getRotationOrder()->getAxis2(), 0.0f);
1336 entity->setTranslation(
1343 entity->setEnabled(
true);
1344 entity->setPickable(
true);
1352 engine->addEntity(entity);
1358 engine->removeEntity(
"tdme.sceneeditor.grid");
1376 auto sceneLibrary =
scene->getLibrary();
1377 if (prototype->
getType() == Prototype_Type::TERRAIN) {
1378 while (sceneLibrary->getTerrainPrototype() !=
nullptr) {
1379 for (
auto prototype: sceneLibrary->getPrototypes()) {
1380 if (prototype->
getType() == Prototype_Type::TERRAIN) {
1381 sceneLibrary->removePrototype(prototype->
getId());
1386 sceneLibrary->addPrototype(prototype);
1387 SceneConnector::resetEngine(
engine.get(),
scene.get());
1388 SceneConnector::setLights(
engine.get(),
scene.get());
1389 SceneConnector::addScene(
engine.get(),
scene.get(),
true,
true,
true,
true,
true);
1394 sceneLibrary->addPrototype(prototype);
1397 Console::println(
"SceneEditorTabView::addPrototype(): An error occurred: " +
string(exception.what()));
1404 if (prototype->
getType() == Prototype_Type::DECAL) {
1405 return SceneConnector::createEditorDecalEntity(prototype,
id, transform, instances);
1407 return SceneConnector::createEntity(prototype,
id, transform, instances);
1413 return SceneConnector::createEditorDecalEntity(sceneEntity, translation, instances);
1415 return SceneConnector::createEntity(sceneEntity, translation, instances);
1428 auto world = make_unique<World>(
"applicationclient-world");
1429 SceneConnector::addScene(world.get(),
scene.get(),
true);
1430 auto applicationContext = make_unique<Context>(
false);
1432 applicationContext->setScene(
scene.get());
1433 applicationContext->setEngine(
engine.get());
1434 applicationContext->setAudio(Audio::getInstance());
1435 applicationContext->setWorld(world.release());
1436 applicationContext->setSoundPoolSize(1);
1437 applicationClient = make_unique<ApplicationClient>(applicationContext.release());
1442 if (
scene->getGUIFileName().empty() ==
false) {
1444 auto screenNode = GUIParser::parse(
1445 Tools::getPathName(
scene->getGUIFileName()),
1446 Tools::getFileName(
scene->getGUIFileName()),
1448 MiniScript::ScriptVariable(),
1451 engine->getGUI()->addScreen(screenNode->getId(), screenNode);
1452 engine->getGUI()->addRenderScreen(screenNode->getId());
1454 Console::println(
"SceneEditorTabView::runScene(): an error occurred: " +
string(exception.what()));
1461 string invalidScripts;
1462 for (
auto entity:
scene->getEntities()) {
1463 if (entity->getPrototype()->hasScript() ==
true) {
1464 auto miniScript = make_unique<LogicMiniScript>();
1465 miniScript->parseScript(
1466 Tools::getPathName(entity->getPrototype()->getScript()),
1467 Tools::getFileName(entity->getPrototype()->getScript())
1469 if (miniScript->isValid() ==
false) {
1472 Tools::getRelativeResourcesFileName(
1476 if (miniScript->getParseErrors().empty() ==
true) {
1477 invalidScripts+=
"\n";
1480 invalidScripts+=
":\n";
1482 for (
const auto& parseError: miniScript->getParseErrors())
1483 invalidScripts+=
"\t" + parseError +
"\n";
1485 invalidScripts+=
"\n";
1493 make_unique<MiniScriptLogic>(
1496 entity->getPrototype()->isScriptHandlingHID(),
1497 miniScript.release(),
1498 entity->getPrototype(),
1506 if (valid ==
false) {
1516 engine->getGUI()->reset();
1517 SceneConnector::resetEngine(
engine.get(),
scene.get());
1518 SceneConnector::setLights(
engine.get(),
scene.get());
1519 SceneConnector::addScene(
engine.get(),
scene.get(),
true,
true,
true,
true,
true);
1542 engine->getGUI()->reset();
1543 SceneConnector::setLights(
engine.get(),
scene.get());
1544 SceneConnector::addScene(
engine.get(),
scene.get(),
true,
true,
true,
true,
true);
1557 SceneConnector::resetEngine(
engine.get(),
scene.get());
Interface to audio module.
Color 4 definition class.
Entity hierarchy to be used with engine class.
Entity * getEntity(const string &id)
virtual void setScale(const Vector3 &scale)=0
Set scale.
virtual BoundingBox * getBoundingBox()=0
virtual const string & getId()=0
virtual const Color4 & getEffectColorAdd() const =0
The effect color will be added to fragment color.
virtual void setEffectColorMul(const Color4 &effectColorMul)=0
Set effect color that will be multiplied with fragment color.
virtual const Transform & getTransform() const =0
virtual void update()=0
Update transform.
virtual void setTransform(const Transform &transform)=0
Set transform.
virtual const Color4 & getEffectColorMul() const =0
The effect color will be multiplied with fragment color.
virtual void setEffectColorAdd(const Color4 &effectColorAdd)=0
Set effect color that will be added to fragment color.
virtual void setEnabled(bool enabled)=0
Enable/disable rendering.
Object to be used with engine class.
void setReflectionEnvironmentMappingId(const string &reflectionEnvironmentMappingId)
Scene engine/physics connector.
Dynamic physics world class.
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
void fromBoundingVolumeWithTransform(BoundingBox *original, const Transform &transform)
Create bounding volume from given original(of same type) with applied transform.
const Vector3 & getDimensions() const
ConstUniquePtrSequenceIterator< BaseProperty > getProperties() const
bool addProperty(const string &name, const string &value)
Add a property.
Base property model class.
int32_t getGizmoTypeMask()
Prototype_Type * getType()
void setEmbedded(bool embedded)
Set embedded.
Prototype * getPrototype()
Scene prototype library definition.
GUI screen node that represents a screen that can be rendered via GUI system.
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Vector3 & setX(float x)
Sets x component.
Vector3 & add(float scalar)
Adds a scalar.
Vector3 & setY(float y)
Sets y component.
float computeLengthSquared() const
Vector3 clone() const
Clones this vector3.
Vector3 & sub(float scalar)
Subtracts a scalar.
Vector3 & scale(float scalar)
Scales by scalar.
Vector3 & set(float x, float y, float z)
Sets this vector3 by its components.
Vector3 & setZ(float z)
Sets z component.
Mutable utf8 aware string class.
MutableString & append(char c)
Append character.
std::exception Exception
Exception base class.