73TerrainEditorTabView::TerrainEditorTabView(
EditorView* editorView,
const string& tabId,
Prototype* prototype)
79 engine = Engine::createOffScreenInstance(512, 512,
true,
true,
true);
85 light0->setDiffuse(
Color4(0.3f, 0.3f, 0.3f, 1.0f));
86 light0->setSpecular(
Color4(1.0f, 1.0f, 1.0f, 1.0f));
87 light0->setPosition(
Vector4(0.0f, 20000.0f, 0.0f, 0.0f));
88 light0->setSpotDirection(
Vector3(0.0f, 0.0f, 0.0f).sub(
Vector3(light0->getPosition().getX(), light0->getPosition().getY(), light0->getPosition().getZ())).
normalize());
89 light0->setConstantAttenuation(0.5f);
90 light0->setLinearAttenuation(0.0f);
91 light0->setQuadraticAttenuation(0.0f);
92 light0->setSpotExponent(0.0f);
93 light0->setSpotCutOff(180.0f);
94 light0->setEnabled(
true);
110 for (
auto i = 0; i <
engine->
getGUI()->getMouseEvents().size(); i++) {
112 if (event.isProcessed() ==
true)
continue;
114 if (event.getType() == GUIMouseEvent::MOUSEEVENT_WHEEL_MOVED) {
115 if (event.isShiftDown() ==
true) {
117 event.setProcessed(
true);
119 if (event.isControlDown() ==
true) {
121 event.setProcessed(
true);
124 if (event.getType() == GUIMouseEvent::MOUSEEVENT_MOVED) {
133 if (brushEnabled ==
true) {
147 if (event.getType() == GUIMouseEvent::MOUSEEVENT_RELEASED) {
154 event.setProcessed(
true);
158 if (event.getType() == GUIMouseEvent::MOUSEEVENT_RELEASED) {
193 event.setProcessed(
true);
195 if (event.getType() == GUIMouseEvent::MOUSEEVENT_PRESSED ||
196 event.getType() == GUIMouseEvent::MOUSEEVENT_DRAGGED) {
206 vector<Model*> waterModels;
207 Vector3 waterReflectionEnvironmentMappingPosition;
212 for (
auto waterModel: waterModels) {
213 auto waterObject3D =
new Object3D(waterModel->getId(), waterModel);
214 waterObject3D->setRenderPass(Entity::RENDERPASS_WATER);
215 waterObject3D->setShader(
"water");
216 waterObject3D->setDistanceShader(
"water");
217 waterObject3D->setContributesShadows(
false);
218 waterObject3D->setReceivesShadows(
false);
219 waterObject3D->setReflectionEnvironmentMappingId(
"sky_environment_mapping");
220 waterObject3D->setReflectionEnvironmentMappingPosition(waterReflectionEnvironmentMappingPosition);
221 waterObject3D->setPickable(
true);
228 if (selectedEntity !=
nullptr && StringTools::startsWith(selectedEntity->getId(),
"water.") ==
true) {
229 auto waterBeginIdx = selectedEntity->
getId().find(
'.', selectedEntity->getId().find(
'.') + 1) + 1;
230 auto waterEndIdx = selectedEntity->getId().find(
'.', waterBeginIdx + 1);
231 auto waterPositionMapIdx = Integer::parse(StringTools::substring(selectedEntity->getId(), waterBeginIdx, waterEndIdx));
239 event.setProcessed(
true);
243 for (
auto i = 0; i <
engine->
getGUI()->getKeyboardEvents().size(); i++) {
245 if (event.isProcessed() ==
true)
continue;
246 if (event.getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_TYPED)
continue;
247 auto isKeyDown =
event.getType() == GUIKeyboardEvent::KEYBOARDEVENT_KEY_PRESSED;
248 if (event.getKeyCode() == GUIKeyboardEvent::KEYCODE_ESCAPE) {
249 if (isKeyDown ==
true) {
257 event.setProcessed(
true);
295 skySpherePrototype = PrototypeReader::read(
"resources/engine/models",
"sky_sphere.tmodel");
296 skyDomePrototype = PrototypeReader::read(
"resources/engine/models",
"sky_dome.tmodel");
299 Console::print(
string(
"TerrainEditorTabView::initialize(): An error occurred: "));
300 Console::println(
string(exception.what()));
338 PrototypeWriter::write(pathName, fileName,
prototype);
344 skySphere->setRenderPass(Entity::RENDERPASS_NOFRUSTUMCULLING);
345 skySphere->setShader(
"sky");
346 skySphere->setFrustumCulling(
false);
347 skySphere->setTranslation(
Vector3(0.0f, 0.0f, 0.0f));
348 skySphere->setScale(
Vector3(300.0f/200.0f, 300.0f/200.0f, 300.0f/200.0f));
350 skySphere->setContributesShadows(
false);
351 skySphere->setReceivesShadows(
false);
352 skySphere->setExcludeEffectPass(Engine::EFFECTPASS_LIGHTSCATTERING);
357 skyDome->setRenderPass(Entity::RENDERPASS_NOFRUSTUMCULLING);
358 skyDome->setShader(
"sky");
359 skyDome->setFrustumCulling(
false);
360 skyDome->setTranslation(
Vector3(0.0f, 0.0f, 0.0f));
361 skyDome->setScale(
Vector3(295.0f/190.0f, 295.0f/190.0f, 295.0f/190.0f));
362 skyDome->getModel()->getMaterials().begin()->second->getSpecularMaterialProperties()->setDiffuseTextureMaskedTransparency(
true);
364 skyDome->setContributesShadows(
false);
365 skyDome->setReceivesShadows(
false);
366 skyDome->setEffectColorMul(
Color4(1.0f, 1.0f, 1.0f, 0.7f));
367 skyDome->setExcludeEffectPass(Engine::EFFECTPASS_LIGHTSCATTERING);
372 skyPanorama->setRenderPass(Entity::RENDERPASS_NOFRUSTUMCULLING);
373 skyPanorama->setShader(
"sky");
374 skyPanorama->setFrustumCulling(
false);
375 skyPanorama->setTranslation(
Vector3(0.0f, 0.0f, 0.0f));
376 skyPanorama->setScale(
Vector3(280.0f/190.0f, 280.0f/180.0f, 280.0f/180.0f));
377 skyPanorama->addRotation(
Vector3(0.0f, 1.0f, 0.0f), 0.0f);
378 skyPanorama->update();
379 skyPanorama->setContributesShadows(
false);
380 skyPanorama->setReceivesShadows(
false);
381 skyPanorama->setExcludeEffectPass(Engine::EFFECTPASS_LIGHTSCATTERING);
384 auto environmentMapping =
new EnvironmentMapping(
"sky_environment_mapping", Engine::getEnvironmentMappingWidth(), Engine::getEnvironmentMappingHeight(),
BoundingBox(
Vector3(-30.0f, 0.0f, -30.0f),
Vector3(30.0f, 60.0f, -30.0f)));
385 environmentMapping->setFrustumCulling(
false);
386 environmentMapping->setRenderPassMask(Entity::RENDERPASS_NOFRUSTUMCULLING);
387 environmentMapping->setTimeRenderUpdateFrequency(33LL);
388 environmentMapping->update();
405 skyPanorama->update();
407 auto environmentMapping =
engine->
getEntity(
"sky_environment_mapping");
409 environmentMapping->update();
437 auto terrainObject3D =
new Object3D(
"terrain." + to_string(idx), terrainModel);
438 terrainObject3D->setNeedsPreRender(
true);
439 terrainObject3D->setRenderPass(Entity::RENDERPASS_TERRAIN);
440 terrainObject3D->setShader(
"terraineditor");
441 terrainObject3D->setDistanceShader(
"terraineditor");
442 terrainObject3D->setContributesShadows(
true);
443 terrainObject3D->setReceivesShadows(
true);
444 terrainObject3D->setPickable(
true);
455 if (
waters.empty() ==
false) {
457 auto& water = it.second;
458 for (
auto waterModel: water.waterModels) {
459 auto waterObject3D =
new Object3D(waterModel->getId(), waterModel);
460 waterObject3D->setRenderPass(Entity::RENDERPASS_WATER);
461 waterObject3D->setShader(
"water");
462 waterObject3D->setDistanceShader(
"water");
463 waterObject3D->setContributesShadows(
false);
464 waterObject3D->setReceivesShadows(
false);
465 waterObject3D->setReflectionEnvironmentMappingId(
"sky_environment_mapping");
466 waterObject3D->setReflectionEnvironmentMappingPosition(water.waterReflectionEnvironmentMappingPosition);
467 waterObject3D->setPickable(
true);
482 for (
auto waterModel: it.second.waterModels) {
487 this->waters.clear();
497 auto partitionIdx = 0;
498 for (
auto& foliageMapPartition: foliageMaps) {
500 auto shaderParameterIdx = 0;
501 while (
engine->
removeEntity(
"foliage.object3drendergroup." + to_string(partitionIdx) +
"." + to_string(shaderParameterIdx)) ==
true) shaderParameterIdx++;
502 auto partitionPrototypeInstanceCount = 0;
503 for (
auto& foliageMapPartitionIt: foliageMapPartition) {
504 partitionPrototypeInstanceCount+= foliageMapPartitionIt.second.size();
506 if (partitionPrototypeInstanceCount > 0) {
507 unordered_map<string, Object3DRenderGroup*> object3DRenderGroupByShaderParameters;
508 for (
auto& foliageMapPartitionIt: foliageMapPartition) {
509 auto prototypeIdx = foliageMapPartitionIt.first;
510 auto& transformationsVector = foliageMapPartitionIt.second;
511 if (transformationsVector.empty() ==
false) {
514 auto foliagePartitionObject3DRenderGroupIt = object3DRenderGroupByShaderParameters.find(foliagePrototype->getShaderParameters().getShaderParametersHash());
515 if (foliagePartitionObject3DRenderGroupIt != object3DRenderGroupByShaderParameters.end()) {
516 foliagePartitionObject3DRenderGroup = foliagePartitionObject3DRenderGroupIt->second;
518 if (foliagePartitionObject3DRenderGroup ==
nullptr) {
520 "foliage.object3drendergroup." + to_string(partitionIdx) +
"." + to_string(object3DRenderGroupByShaderParameters.size()),
530 foliagePartitionObject3DRenderGroup->
setShader(foliagePrototype->getShader());
531 auto shaderParametersDefault = Engine::getShaderParameterDefaults(foliagePrototype->getShader());
532 for (
auto& parameterIt: shaderParametersDefault) {
533 auto& parameterName = parameterIt.first;
534 auto parameterValue = foliagePrototype->getShaderParameters().getShaderParameter(parameterName);
535 foliagePartitionObject3DRenderGroup->
setShaderParameter(parameterName, parameterValue);
538 object3DRenderGroupByShaderParameters[foliagePrototype->getShaderParameters().getShaderParametersHash()] = foliagePartitionObject3DRenderGroup;
540 for (
auto& transformations: transformationsVector) {
541 foliagePartitionObject3DRenderGroup->
addObject(foliagePrototype->getModel(), transformations);
545 for (
auto& object3DRenderGroupByShaderParametersIt: object3DRenderGroupByShaderParameters) {
546 object3DRenderGroupByShaderParametersIt.second->updateRenderGroup();
560 auto partitionIdx = 0;
561 for (
auto& foliageMapPartition: newFoliageMaps) {
562 auto partitionPrototypeInstanceCount = 0;
563 for (
auto& foliageMapPartitionIt: foliageMapPartition) {
564 partitionPrototypeInstanceCount+= foliageMapPartitionIt.second.size();
566 if (partitionPrototypeInstanceCount > 0) {
571 auto foliagePartitionObject3DRenderGroup =
engine->
getEntity(
"foliage.object3drendergroup." + to_string(partitionIdx) +
".0");
572 if (foliagePartitionObject3DRenderGroup !=
nullptr) {
573 auto shaderParameterIdx = 0;
574 while (
engine->
removeEntity(
"foliage.object3drendergroup." + to_string(partitionIdx) +
"." + to_string(shaderParameterIdx)) ==
true) shaderParameterIdx++;
578 if (foliagePartitionEntityHierarchy ==
nullptr) {
579 foliagePartitionEntityHierarchy =
new EntityHierarchy(
"foliage.entityhierarchy." + to_string(partitionIdx));
580 foliagePartitionEntityHierarchy->setContributesShadows(
true);
581 foliagePartitionEntityHierarchy->setReceivesShadows(
true);
584 for (
auto& foliageMapPartitionIt: foliageMapPartition) {
585 auto prototypeIdx = foliageMapPartitionIt.first;
586 auto& transformationsVector = foliageMapPartitionIt.second;
587 if (transformationsVector.empty() ==
false) {
590 for (
auto& transformations: transformationsVector) {
591 auto foliageEntity = SceneConnector::createEntity(foliagePrototype, foliagePartitionEntityHierarchy->getId() +
"." + to_string(prototypeIdx) +
"." + to_string(foliageIdx), transformations, 1, foliagePartitionEntityHierarchy);
592 foliagePartitionEntityHierarchy->addEntity(foliageEntity);
597 foliagePartitionEntityHierarchy->update();
610 auto partitionIdx = 0;
611 for (
auto partitionIdx: partitionIdxSet) {
612 auto& foliageMapPartition = foliageMaps[partitionIdx];
613 auto partitionPrototypeInstanceCount = 0;
614 for (
auto& foliageMapPartitionIt: foliageMapPartition) {
615 partitionPrototypeInstanceCount+= foliageMapPartitionIt.second.size();
617 if (partitionPrototypeInstanceCount > 0) {
622 auto foliagePartitionObject3DRenderGroup =
engine->
getEntity(
"foliage.object3drendergroup." + to_string(partitionIdx) +
".0");
624 if (foliagePartitionObject3DRenderGroup !=
nullptr || foliagePartitionEntityHierarchy ==
nullptr) {
625 auto shaderParameterIdx = 0;
626 while (
engine->
removeEntity(
"foliage.object3drendergroup." + to_string(partitionIdx) +
"." + to_string(shaderParameterIdx)) ==
true) shaderParameterIdx++;
629 if (foliagePartitionEntityHierarchy ==
nullptr) foliagePartitionEntityHierarchy =
dynamic_cast<EntityHierarchy*
>(
engine->
getEntity(
"foliage.entityhierarchy." + to_string(partitionIdx)));
631 for (
auto& foliageMapPartitionIt: foliageMapPartition) {
632 auto& transformationsVector = foliageMapPartitionIt.second;
633 for (
auto i = 0; i < transformationsVector.size(); i++) {
634 foliagePartitionEntityHierarchy->
getEntities()[foliageIdx]->fromTransformations(transformationsVector[i]);
638 foliagePartitionEntityHierarchy->update();
654 auto& foliageMapPartition = foliageMaps[partitionIdx];
656 auto shaderParameterIdx = 0;
657 while (
engine->
removeEntity(
"foliage.object3drendergroup." + to_string(partitionIdx) +
"." + to_string(shaderParameterIdx)) ==
true) shaderParameterIdx++;
658 auto partitionPrototypeInstanceCount = 0;
659 for (
auto& foliageMapPartitionIt: foliageMapPartition) {
660 partitionPrototypeInstanceCount+= foliageMapPartitionIt.second.size();
662 if (partitionPrototypeInstanceCount > 0) {
663 auto foliagePartitionEntityHierarchy =
new EntityHierarchy(
"foliage.entityhierarchy." + to_string(partitionIdx));
664 foliagePartitionEntityHierarchy->setContributesShadows(
true);
665 foliagePartitionEntityHierarchy->setReceivesShadows(
true);
667 for (
auto& foliageMapPartitionIt: foliageMapPartition) {
668 auto prototypeIdx = foliageMapPartitionIt.first;
670 auto& transformationsVector = foliageMapPartitionIt.second;
672 for (
auto& transformations: transformationsVector) {
673 auto foliageEntity = SceneConnector::createEntity(foliagePrototype, foliagePartitionEntityHierarchy->getId() +
"." + to_string(prototypeIdx) +
"." + to_string(foliageIdx), transformations, 1, foliagePartitionEntityHierarchy);
674 foliagePartitionEntityHierarchy->addEntity(foliageEntity);
678 foliagePartitionEntityHierarchy->update();
689 for (
auto partitionIdx: partitionIdxSet) {
690 auto& foliageMapPartition = foliageMaps[partitionIdx];
692 auto shaderParameterIdx = 0;
693 while (
engine->
removeEntity(
"foliage.object3drendergroup." + to_string(partitionIdx) +
"." + to_string(shaderParameterIdx)) ==
true) shaderParameterIdx++;
694 auto partitionPrototypeInstanceCount = 0;
695 for (
auto& foliageMapPartitionIt: foliageMapPartition) {
696 partitionPrototypeInstanceCount+= foliageMapPartitionIt.second.size();
698 if (partitionPrototypeInstanceCount > 0) {
699 unordered_map<string, Object3DRenderGroup*> object3DRenderGroupByShaderParameters;
700 for (
auto& foliageMapPartitionIt: foliageMapPartition) {
701 auto prototypeIdx = foliageMapPartitionIt.first;
702 auto& transformationsVector = foliageMapPartitionIt.second;
703 if (transformationsVector.empty() ==
false) {
706 auto foliagePartitionObject3DRenderGroupIt = object3DRenderGroupByShaderParameters.find(foliagePrototype->getShaderParameters().getShaderParametersHash());
707 if (foliagePartitionObject3DRenderGroupIt != object3DRenderGroupByShaderParameters.end()) {
708 foliagePartitionObject3DRenderGroup = foliagePartitionObject3DRenderGroupIt->second;
710 if (foliagePartitionObject3DRenderGroup ==
nullptr) {
712 "foliage.object3drendergroup." + to_string(partitionIdx) +
"." + to_string(object3DRenderGroupByShaderParameters.size()),
722 foliagePartitionObject3DRenderGroup->
setShader(foliagePrototype->getShader());
723 auto shaderParametersDefault = Engine::getShaderParameterDefaults(foliagePrototype->getShader());
724 for (
auto& parameterIt: shaderParametersDefault) {
725 auto& parameterName = parameterIt.first;
726 auto parameterValue = foliagePrototype->getShaderParameters().getShaderParameter(parameterName);
727 foliagePartitionObject3DRenderGroup->
setShaderParameter(parameterName, parameterValue);
730 object3DRenderGroupByShaderParameters[foliagePrototype->getShaderParameters().getShaderParametersHash()] = foliagePartitionObject3DRenderGroup;
732 for (
auto& transformations: transformationsVector) {
733 foliagePartitionObject3DRenderGroup->
addObject(foliagePrototype->getModel(), transformations);
737 for (
auto& object3DRenderGroupByShaderParametersIt: object3DRenderGroupByShaderParameters) {
738 object3DRenderGroupByShaderParametersIt.second->updateRenderGroup();
745 auto& water =
waters[waterIdx];
746 for (
auto waterModel: water.waterModels) {
754 auto& water =
waters[waterIdx];
755 for (
auto waterModel: water.waterModels) {
759 water.waterModels = waterModels;
760 water.waterReflectionEnvironmentMappingPosition = waterReflectionEnvironmentMappingPosition;
764 for (
auto terrainModel: this->
terrainModels)
delete terrainModel;
766 this->terrainModels.clear();
const Vector3 & getLookFrom() const
bool removeEntity(const string &id)
Removes an entity.
void display()
Renders the scene.
Light * getLightAt(int32_t idx)
Returns light at idx (0 <= idx < 8)
void setShaderParameter(const string &shaderId, const string ¶meterName, const ShaderParameter ¶meterValue)
Set shader parameter for given shader id and parameter name.
Entity * getEntityByMousePosition(int32_t mouseX, int32_t mouseY, EntityPickingFilter *filter=nullptr, Node **object3DNode=nullptr, ParticleSystemEntity **particleSystemEntity=nullptr)
Retrieves entity by mouse position.
static TextureManager * getTextureManager()
void addEntity(Entity *entity)
Adds an entity by id.
const ShaderParameter getShaderParameter(const string &shaderId, const string ¶meterName)
Returns shader parameter for given shader id and parameter name, if the value does not exist,...
void dispose()
Shutdown the engine.
Entity * getEntity(const string &id)
Returns a entity by given id.
void reset()
Removes all entities and caches.
void setSceneColor(const Color4 &sceneColor)
Set scene color.
Entity hierarchy to be used with engine class.
const vector< Entity * > & getEntities()
virtual const string & getId()=0
virtual void setTranslation(const Vector3 &translation)=0
Set translation.
Environment mapping entity.
void setEnabled(bool enabled)
Set enabled.
void setAmbient(const Color4 &ambient)
Set ambient light component.
Object 3D render group for static objects that might be animated by shaders.
void setShader(const string &id)
Set shader id.
void setReceivesShadows(bool receivesShadows) override
Enable/disable receives shadows.
void addObject(Model *model, const Transformations &transformations)
Adds a instance to this render group.
void setShaderParameter(const string ¶meterName, const ShaderParameter ¶meterValue)
Set shader parameter for given parameter name.
void setContributesShadows(bool contributesShadows) override
Enable/disable contributes shadows.
Object 3D to be used with engine class.
void setTranslation(const Vector3 &translation) override
Set translation.
Scene engine/physics connector.
float getFloatValue() const
const Vector2 getVector2Value() const
int64_t getDeltaTime()
Gets the time passed between last and current frame.
const string & getId() const
int32_t getTextureHeight() const
int32_t getTextureWidth() const
Represents specular material properties.
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
const Vector3 & getCenter() const
Prototype terrain definition.
vector< unordered_map< int, vector< Transformations > > > & getFoliageMaps()
Prototype * getFoliagePrototype(int prototypeIdx)
Get foliage prototype by given index.
PrototypeTerrain * getTerrain()
void removeTexture(const string &textureId)
Removes a texture from manager / open gl stack.
TextureManager_TextureManaged * addTexture(const string &id, bool &created)
Adds a texture to manager.
vector< GUIMouseEvent > & getMouseEvents()
vector< GUIKeyboardEvent > & getKeyboardEvents()
GUI screen node that represents a screen that can be rendered via GUI system.
Vector3 & normalize()
Normalize the vector.
Vector3 & set(float x, float y, float z)
Set up vector.
MutableString & append(char c)
Append character.
void releaseReference()
releases a reference, thus decrementing the counter and delete it if reference counter is zero
void acquireReference()
acquires a reference, incrementing the counter
std::exception Exception
Exception base class.