Skip to content

Commit

Permalink
#149 Update spawn CPrimitive object (Ctrl + D)
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Jun 7, 2022
1 parent f686de4 commit 6fe82fd
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 8 deletions.
3 changes: 1 addition & 2 deletions Assets/BuiltIn/Shader/SSR/GLSL/LibSSR.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ vec3 SSR(const vec3 baseColor, const vec4 position, const vec3 reflection, const
float mipLevel = roughness * 5.0;
vec2 ssrUV;

// ray test
// RayMarch test
for (int i = 32; i > 0; --i)
{
rayPosition += dir;
Expand Down Expand Up @@ -69,5 +69,4 @@ vec3 SSR(const vec3 baseColor, const vec4 position, const vec3 reflection, const
float screenEdgefactor = clamp(1.0 - (dCoords.x + dCoords.y), 0.0, 1.0);

return mix(baseColor * 0.8, color, screenEdgefactor * z);
// return vec3(screenEdgefactor * z, screenEdgefactor * z, screenEdgefactor * z);
}
48 changes: 46 additions & 2 deletions Projects/Editor/Source/Editor/SpaceController/CSceneController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,12 +509,12 @@ namespace Skylicht
}
else if (objectType == L"Cube")
{
std::vector<std::string> components = { "CCube", "CIndirectLighting" };
std::vector<std::string> components = { "CCube" };
createComponentObject("Cube", components, NULL);
}
else if (objectType == L"Sphere")
{
std::vector<std::string> components = { "CSphere", "CIndirectLighting" };
std::vector<std::string> components = { "CSphere" };
createComponentObject("Sphere", components, NULL);
}

Expand Down Expand Up @@ -1122,6 +1122,50 @@ namespace Skylicht

void CSceneController::onDuplicate()
{
// Check duplicate entity
CSelection* selection = CSelection::getInstance();
std::vector<CSelectObject*>& selected = selection->getAllSelected();
if (selected.size() == 1)
{
CSelectObject* selectObject = selected[0];
CSelectObject::ESelectType type = selectObject->getType();
if (type == CSelectObject::Entity)
{
CEntity* entity = m_scene->getEntityManager()->getEntityByID(selectObject->getID().c_str());
if (entity != NULL)
{
CEntityHandleData* data = (CEntityHandleData*)entity->getDataByIndex(CEntityHandleData::DataTypeIndex);
CWorldTransformData* transform = (CWorldTransformData*)entity->getDataByIndex(CWorldTransformData::DataTypeIndex);

if (data != NULL)
{
CEntityHandler* handler = data->Handler;

// spawn new entity
CEntity* spawnNewEntity = handler->spawn();
if (spawnNewEntity != NULL)
{
CWorldTransformData* spawnTransform = (CWorldTransformData*)spawnNewEntity->getDataByIndex(CWorldTransformData::DataTypeIndex);
spawnTransform->Relative = transform->Relative;

// change selection
selection->clear();
selection->addSelect(spawnNewEntity);

// remove gui hierachy
if (m_spaceHierarchy != NULL)
m_spaceHierarchy->getController()->updateTreeNode(handler->getGameObject());

// select on GUI
selectOnHierachy(spawnNewEntity);
}
}
}
return;
}
}

// Duplicate game object
onCopy();
onPaste();
}
Expand Down
16 changes: 16 additions & 0 deletions Projects/Skylicht/Components/Source/Primitive/CPrimitive.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
/*
!@
MIT License
Expand Down Expand Up @@ -31,6 +32,7 @@ This file is part of the "Skylicht Engine".
#include "Transform/CWorldInverseTransformData.h"
#include "Culling/CCullingData.h"
#include "Culling/CCullingBBoxData.h"
#include "IndirectLighting/CIndirectLightingData.h"


namespace Skylicht
Expand Down Expand Up @@ -61,6 +63,11 @@ namespace Skylicht
}
}

CEntity* CPrimitive::spawn()
{
return addPrimitive(core::vector3df(), core::vector3df(), core::vector3df(1.0f, 1.0f, 1.0f));
}

CEntity* CPrimitive::addPrimitive(const core::vector3df& pos, const core::vector3df& rotDeg, const core::vector3df& scale)
{
CEntity* entity = createEntity();
Expand All @@ -71,6 +78,7 @@ namespace Skylicht
// Culling
entity->addData<CWorldInverseTransformData>();
entity->addData<CCullingData>();
entity->addData<CIndirectLightingData>();

CCullingBBoxData* cullingBBox = entity->addData<CCullingBBoxData>();
cullingBBox->BBox.MinEdge.set(-1.0f, -1.0f, -1.0f);
Expand All @@ -82,6 +90,14 @@ namespace Skylicht
transform->Relative.setRotationDegrees(rotDeg);
transform->Relative.setScale(scale);

// Indirect lighting
CIndirectLightingData* indirect = (CIndirectLightingData*)entity->getDataByIndex(CIndirectLightingData::DataTypeIndex);
indirect->Type = CIndirectLightingData::SH9;
indirect->AutoSH = new bool();
indirect->SH = new core::vector3df[9];
indirect->ReleaseSH = true;

*indirect->AutoSH = true;
return entity;
}
}
2 changes: 2 additions & 0 deletions Projects/Skylicht/Components/Source/Primitive/CPrimitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace Skylicht

virtual void initComponent();

virtual CEntity* spawn();

CEntity* addPrimitive(const core::vector3df& pos, const core::vector3df& rotDeg, const core::vector3df& scale);

inline CPrimiviteData::EPrimitive getType()
Expand Down
5 changes: 5 additions & 0 deletions Projects/Skylicht/Engine/Source/Entity/CEntityHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ namespace Skylicht

CEntity* createEntity(CEntity* parent);

virtual CEntity* spawn()
{
return NULL;
}

void removeEntity(CEntity* entity);

void removeAllEntities();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ namespace Skylicht
ReflectionTexture(NULL),
SH(NULL),
AutoSH(NULL),
Init(true)
Init(true),
ReleaseSH(false)
{

}

CIndirectLightingData::~CIndirectLightingData()
{

if (ReleaseSH)
{
delete[]SH;
delete AutoSH;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ namespace Skylicht

bool Init;

bool ReleaseSH;

DECLARE_DATA_TYPE_INDEX;

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace Skylicht

CIndirectLightingData* lightData = (CIndirectLightingData*)entity->getDataByIndex(CIndirectLightingData::DataTypeIndex);
if (lightData != NULL &&
lightData->AutoSH &&
*lightData->AutoSH &&
lightData->Type == CIndirectLightingData::SH9)
{
Expand Down
5 changes: 5 additions & 0 deletions Projects/Skylicht/Engine/Source/LightProbes/CLightProbes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ namespace Skylicht
}
}

CEntity* CLightProbes::spawn()
{
return addLightProbe(core::vector3df());
}

CEntity* CLightProbes::addLightProbe(const core::vector3df& position)
{
CEntity* entity = createEntity();
Expand Down
2 changes: 2 additions & 0 deletions Projects/Skylicht/Engine/Source/LightProbes/CLightProbes.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ namespace Skylicht

virtual void loadSerializable(CObjectSerializable* object);

virtual CEntity* spawn();

CEntity* addLightProbe(const core::vector3df& position);

int getPositions(std::vector<core::vector3df>& positions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,11 @@ namespace Skylicht
{

}

CObjectSerializable* CProbeSerializable::clone()
{
CProbeSerializable* object = new CProbeSerializable();
copyTo(object);
return object;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace Skylicht

virtual ~CProbeSerializable();

virtual CObjectSerializable* clone();

DECLARE_GETTYPENAME(CProbeSerializable);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ namespace Skylicht
driver->drawMeshBuffer(mb);
}
}
else if (indirectData->Type == CIndirectLightingData::SH9)
else if (indirectData->Type == CIndirectLightingData::SH9 && indirectData->SH)
{
CShaderSH::setSH9(indirectData->SH);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ namespace Skylicht
for (CValueProperty* value : m_value)
{
CValueProperty* newValue = value->clone();
newValue->setOwner(this);
newValue->setOwner(object);
newValue->setUIHeader(value->getUIHeader().c_str());
newValue->setUISpace(value->getUISpace());

Expand All @@ -282,7 +282,24 @@ namespace Skylicht
return object;
}

void CObjectSerializable::copyTo(CObjectSerializable* object)
{
object->m_savePath = m_savePath;

io::IAttributes* io = getIrrlichtDevice()->getFileSystem()->createEmptyAttributes();

for (CValueProperty* value : m_value)
{
io->clear();
value->serialize(io);

CValueProperty* dst = object->getProperty(value->Name.c_str());
if (dst)
dst->deserialize(io);
}

io->drop();
}


bool CSerializableActivator::registerType(const char* type, SerializableCreateInstance func)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ namespace Skylicht
virtual void parseSerializable(io::IXMLReader* reader);

virtual CObjectSerializable* clone();

virtual void copyTo(CObjectSerializable* object);
};


Expand Down

0 comments on commit 6fe82fd

Please sign in to comment.