diff --git a/Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp b/Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp index 916678585..ade16d71c 100644 --- a/Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp +++ b/Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp @@ -236,6 +236,7 @@ namespace Skylicht // add handle renderer CEntityManager* entityMgr = m_scene->getEntityManager(); + entityMgr->addSystem(); m_handlesRenderer = entityMgr->addRenderSystem(); m_gizmosRenderer = entityMgr->addRenderSystem(); @@ -277,7 +278,7 @@ namespace Skylicht CDirectionalLight* directionalLight = lightObj->addComponent(); SColor c(255, 255, 244, 214); - directionalLight->setColor(SColorf(c)); + directionalLight->setColor(SColorf(c)); // update search index m_scene->updateAddRemoveObject(); diff --git a/Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.h b/Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.h index 9e3d06181..8d1d91cbe 100644 --- a/Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.h +++ b/Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.h @@ -29,6 +29,8 @@ This file is part of the "Skylicht Engine". #include "Editor/History/CSceneHistory.h" #include "EditorComponents/Handles/CHandlesRenderer.h" #include "EditorComponents/Gizmos/CGizmosRenderer.h" +#include "EditorComponents/PickCollision/CPickCollisionSystem.h" + #include "CViewpointController.h" #include "Reactive/ISubject.h" diff --git a/Projects/Editor/Source/Editor/SpaceController/CCollisionController.h b/Projects/Editor/Source/Editor/SpaceController/CCollisionController.h index 8840e810d..5e0d19246 100644 --- a/Projects/Editor/Source/Editor/SpaceController/CCollisionController.h +++ b/Projects/Editor/Source/Editor/SpaceController/CCollisionController.h @@ -27,6 +27,7 @@ This file is part of the "Skylicht Engine". #include "Utils/CGameSingleton.h" #include "Collision/CBBCollisionManager.h" +#include "EditorComponents/PickCollision/CPickCollisionData.h" namespace Skylicht { diff --git a/Projects/Editor/Source/EditorComponents/DirectionLight/CGDirectionLight.cpp b/Projects/Editor/Source/EditorComponents/DirectionLight/CGDirectionLight.cpp index da3d4548e..95a0b5241 100644 --- a/Projects/Editor/Source/EditorComponents/DirectionLight/CGDirectionLight.cpp +++ b/Projects/Editor/Source/EditorComponents/DirectionLight/CGDirectionLight.cpp @@ -69,6 +69,10 @@ namespace Skylicht CBBCollisionManager* bbCollision = CCollisionController::getInstance()->getBBCollision(); m_collisionNode = bbCollision->addBBCollision(m_gameObject, core::aabbox3df(core::vector3df(-1.0f, -1.0f, -1.0f), core::vector3df(1.0f, 1.0f, 1.0f))); + + CPickCollisionData* pickData = m_gameObject->getEntity()->addData(); + pickData->CollisionNode = m_collisionNode; + pickData->IsBBoxCollision = true; } void CGDirectionLight::updateComponent() diff --git a/Projects/Editor/Source/EditorComponents/PickCollision/CPickCollisionData.cpp b/Projects/Editor/Source/EditorComponents/PickCollision/CPickCollisionData.cpp new file mode 100644 index 000000000..4d60ef980 --- /dev/null +++ b/Projects/Editor/Source/EditorComponents/PickCollision/CPickCollisionData.cpp @@ -0,0 +1,44 @@ +/* +!@ +MIT License + +Copyright (c) 2021 Skylicht Technology CO., LTD + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files +(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +This file is part of the "Skylicht Engine". +https://github.com/skylicht-lab/skylicht-engine +!# +*/ + +#include "pch.h" +#include "CPickCollisionData.h" + +namespace Skylicht +{ + namespace Editor + { + CPickCollisionData::CPickCollisionData() : + CollisionNode(NULL), + IsBBoxCollision(false), + IsChanged(true) + { + + } + + CPickCollisionData::~CPickCollisionData() + { + } + } +} \ No newline at end of file diff --git a/Projects/Editor/Source/EditorComponents/PickCollision/CPickCollisionData.h b/Projects/Editor/Source/EditorComponents/PickCollision/CPickCollisionData.h new file mode 100644 index 000000000..f43716c93 --- /dev/null +++ b/Projects/Editor/Source/EditorComponents/PickCollision/CPickCollisionData.h @@ -0,0 +1,47 @@ +/* +!@ +MIT License + +Copyright (c) 2021 Skylicht Technology CO., LTD + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files +(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +This file is part of the "Skylicht Engine". +https://github.com/skylicht-lab/skylicht-engine +!# +*/ + +#pragma once + +#include "Entity/IEntityData.h" +#include "Collision/CCollisionNode.h" + +namespace Skylicht +{ + namespace Editor + { + class CPickCollisionData : public IEntityData + { + public: + CCollisionNode* CollisionNode; + bool IsBBoxCollision; + bool IsChanged; + + public: + CPickCollisionData(); + + virtual ~CPickCollisionData(); + }; + } +} \ No newline at end of file diff --git a/Projects/Editor/Source/EditorComponents/PickCollision/CPickCollisionSystem.cpp b/Projects/Editor/Source/EditorComponents/PickCollision/CPickCollisionSystem.cpp new file mode 100644 index 000000000..f3d911d83 --- /dev/null +++ b/Projects/Editor/Source/EditorComponents/PickCollision/CPickCollisionSystem.cpp @@ -0,0 +1,86 @@ +/* +!@ +MIT License + +Copyright (c) 2021 Skylicht Technology CO., LTD + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files +(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +This file is part of the "Skylicht Engine". +https://github.com/skylicht-lab/skylicht-engine +!# +*/ + +#include "pch.h" +#include "CPickCollisionSystem.h" +#include "Editor/SpaceController/CCollisionController.h" + +namespace Skylicht +{ + namespace Editor + { + CPickCollisionSystem::CPickCollisionSystem() + { + + + } + + CPickCollisionSystem::~CPickCollisionSystem() + { + + } + + void CPickCollisionSystem::beginQuery() + { + m_pickCollisions.set_used(0); + } + + void CPickCollisionSystem::onQuery(CEntityManager* entityManager, CEntity* entity) + { + // if transform is changed + CPickCollisionData* collisionData = entity->getData(); + if (collisionData != NULL && + collisionData->CollisionNode != NULL && + collisionData->IsChanged) + { + m_pickCollisions.push_back(collisionData); + } + } + + void CPickCollisionSystem::init(CEntityManager* entityManager) + { + + } + + void CPickCollisionSystem::update(CEntityManager* entityManager) + { + CPickCollisionData** listCollision = m_pickCollisions.pointer(); + u32 numCollision = m_pickCollisions.size(); + + CBBCollisionManager* bbCollision = CCollisionController::getInstance()->getBBCollision(); + + for (u32 i = 0; i < numCollision; i++) + { + CPickCollisionData* collision = listCollision[i]; + + if (collision->IsBBoxCollision) + { + bbCollision->updateNode(collision->CollisionNode); + } + + collision->IsChanged = false; + } + } + } +} \ No newline at end of file diff --git a/Projects/Editor/Source/EditorComponents/PickCollision/CPickCollisionSystem.h b/Projects/Editor/Source/EditorComponents/PickCollision/CPickCollisionSystem.h new file mode 100644 index 000000000..ec03bbb94 --- /dev/null +++ b/Projects/Editor/Source/EditorComponents/PickCollision/CPickCollisionSystem.h @@ -0,0 +1,56 @@ +/* +!@ +MIT License + +Copyright (c) 2021 Skylicht Technology CO., LTD + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files +(the "Software"), to deal in the Software without restriction, including without limitation the Rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +This file is part of the "Skylicht Engine". +https://github.com/skylicht-lab/skylicht-engine +!# +*/ + +#pragma once + +#include "Entity/IEntityData.h" +#include "Entity/IEntitySystem.h" + +#include "CPickCollisionData.h" +#include "Transform/CWorldTransformData.h" + +namespace Skylicht +{ + namespace Editor + { + class CPickCollisionSystem : public IEntitySystem + { + protected: + core::array m_pickCollisions; + + public: + CPickCollisionSystem(); + + virtual ~CPickCollisionSystem(); + + virtual void beginQuery(); + + virtual void onQuery(CEntityManager* entityManager, CEntity* entity); + + virtual void init(CEntityManager* entityManager); + + virtual void update(CEntityManager* entityManager); + }; + } +} \ No newline at end of file diff --git a/Projects/Skylicht/Collision/Source/Collision/CBBoxPatchBuilder.cpp b/Projects/Skylicht/Collision/Source/Collision/CBBoxPatchBuilder.cpp index 5f7488e7c..8edfb1d51 100644 --- a/Projects/Skylicht/Collision/Source/Collision/CBBoxPatchBuilder.cpp +++ b/Projects/Skylicht/Collision/Source/Collision/CBBoxPatchBuilder.cpp @@ -83,6 +83,8 @@ namespace Skylicht core::vector3df patchSize(m_patchSize, m_patchSize, m_patchSize); + m_global.VolumeBox.MinEdge = m_size.MinEdge; + m_global.VolumeBox.MaxEdge = m_size.MinEdge + core::vector3df(m_numX * m_patchSize, m_numY * m_patchSize, m_numZ * m_patchSize); m_global.BBox = m_size; for (int x = 0; x < m_numX; x++) @@ -98,8 +100,8 @@ namespace Skylicht p.Y = y; p.Z = z; - p.BBox.MinEdge = m_size.MinEdge + core::vector3df(x * m_patchSize, y * m_patchSize, z * m_patchSize); - p.BBox.MaxEdge = p.BBox.MinEdge + patchSize; + p.VolumeBox.MinEdge = m_size.MinEdge + core::vector3df(x * m_patchSize, y * m_patchSize, z * m_patchSize); + p.VolumeBox.MaxEdge = p.VolumeBox.MinEdge + patchSize; } } } @@ -113,9 +115,12 @@ namespace Skylicht // step4: collect the patch have collisions for (u32 i = 0, n = m_patchs.size(); i < n; i++) { - if (m_patchs[i]->Collisions.size() > 0) + SPatch* patch = m_patchs[i]; + + if (patch->Collisions.size() > 0) { - m_collisionPatchs.push_back(m_patchs[i]); + patch->calculateBBox(); + m_collisionPatchs.push_back(patch); } } @@ -173,7 +178,7 @@ namespace Skylicht SPatch* patch = getPatch(x, y, z); if (patch) { - if (bbox.isFullInside(patch->BBox)) + if (bbox.isFullInside(patch->VolumeBox)) { patch->Collisions.push_back(collision); } @@ -226,6 +231,7 @@ namespace Skylicht if (patch->Collisions[i] == collision) { patch->Collisions.erase(i); + patch->calculateBBox(); return; } } @@ -262,7 +268,6 @@ namespace Skylicht void CBBoxPatchBuilder::drawDebug() { - /* CSceneDebug* debug = CSceneDebug::getInstance(); debug->addBoudingBox(m_global.BBox, SColor(255, 255, 0, 255)); @@ -278,7 +283,6 @@ namespace Skylicht debug->addBoudingBox(node->getTransformBBox(), SColor(255, 255, 255, 0)); } } - */ } bool CBBoxPatchBuilder::getCollisionPoint( diff --git a/Projects/Skylicht/Collision/Source/Collision/CBBoxPatchBuilder.h b/Projects/Skylicht/Collision/Source/Collision/CBBoxPatchBuilder.h index 0708d0552..f5a479104 100644 --- a/Projects/Skylicht/Collision/Source/Collision/CBBoxPatchBuilder.h +++ b/Projects/Skylicht/Collision/Source/Collision/CBBoxPatchBuilder.h @@ -33,6 +33,7 @@ namespace Skylicht protected: struct SPatch { + core::aabbox3df VolumeBox; core::aabbox3df BBox; int X; int Y; @@ -45,6 +46,19 @@ namespace Skylicht Y = 0; Z = 0; } + + void calculateBBox() + { + BBox.reset(core::vector3df()); + + for (u32 i = 0, n = Collisions.size(); i < n; i++) + { + if (i == 0) + BBox = Collisions[0]->getTransformBBox(); + else + BBox.addInternalBox(Collisions[i]->getTransformBBox()); + } + } }; SPatch m_global; diff --git a/Projects/Skylicht/Components/Source/SpriteDraw/CSpriteDrawData.cpp b/Projects/Skylicht/Components/Source/SpriteDraw/CSpriteDrawData.cpp index 821d2fc6a..97034c8c4 100644 --- a/Projects/Skylicht/Components/Source/SpriteDraw/CSpriteDrawData.cpp +++ b/Projects/Skylicht/Components/Source/SpriteDraw/CSpriteDrawData.cpp @@ -30,6 +30,7 @@ namespace Skylicht CSpriteDrawData::CSpriteDrawData() : Frame(NULL), Scale(1.0f), + ViewScale(1.0f), Color(255, 255, 255, 255), Center(false), Billboard(false), diff --git a/Projects/Skylicht/Engine/Source/Transform/CWorldTransformData.h b/Projects/Skylicht/Engine/Source/Transform/CWorldTransformData.h index 78766b0b7..acc6056c0 100644 --- a/Projects/Skylicht/Engine/Source/Transform/CWorldTransformData.h +++ b/Projects/Skylicht/Engine/Source/Transform/CWorldTransformData.h @@ -32,6 +32,7 @@ namespace Skylicht { public: bool HasChanged; + bool NeedValidate; core::matrix4 World; core::matrix4 Relative; int Depth; @@ -43,9 +44,9 @@ namespace Skylicht virtual ~CWorldTransformData(); - virtual bool serializable(CMemoryStream *stream, IMeshExporter *exporter); + virtual bool serializable(CMemoryStream* stream, IMeshExporter* exporter); - virtual bool deserializable(CMemoryStream *stream, IMeshImporter *importer); + virtual bool deserializable(CMemoryStream* stream, IMeshImporter* importer); DECLARE_GETTYPENAME(CWorldTransformData); }; diff --git a/Projects/Skylicht/Engine/Source/Transform/CWorldTransformSystem.cpp b/Projects/Skylicht/Engine/Source/Transform/CWorldTransformSystem.cpp index 03cb67abf..2e250cf61 100644 --- a/Projects/Skylicht/Engine/Source/Transform/CWorldTransformSystem.cpp +++ b/Projects/Skylicht/Engine/Source/Transform/CWorldTransformSystem.cpp @@ -60,8 +60,12 @@ namespace Skylicht if (t->Depth > m_maxDepth) m_maxDepth = t->Depth; + t->NeedValidate = false; + if (t->HasChanged == true) { + t->NeedValidate = true; + // my transform changed m_entities[t->Depth].push_back(t); @@ -77,6 +81,7 @@ namespace Skylicht { // this transform changed because parent is changed t->HasChanged = true; + t->NeedValidate = true; // notify recalc inverse matrix if (tInverse != NULL)