Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions engine/includes/components/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ class ENGINE_EXPORT Actor : public Object {
World *world() const;

Component *component(const std::string type);

template<typename T>
T *getComponent() {
return static_cast<T *>(component(T::metaClass()->name()));
}

Component *componentInChild(const std::string type);

std::list<Component *> componentsInChild(const std::string type);
Expand Down
36 changes: 1 addition & 35 deletions engine/includes/editor/editortool.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,11 @@
#include <engine.h>

#include <cstdint>
#include <QMap>
#include <QCursor>

class Actor;
class Renderable;

class ENGINE_EXPORT EditorTool {
public:
struct ENGINE_EXPORT Select {
Select();

bool operator==(const Select &left) {
return (uuid == left.uuid);
}

uint32_t uuid;
Actor *object;
Renderable *renderable;
Vector3 position;
Vector3 scale;
Vector3 euler;
Vector3 pivot;
Quaternion quat;
AABBox box;
};

typedef QList<Select> SelectList;

public:
explicit EditorTool(EditorTool::SelectList &selection);
EditorTool();

virtual void update(bool center, bool local, bool snap);

Expand All @@ -51,16 +26,7 @@ class ENGINE_EXPORT EditorTool {

Qt::CursorShape cursor() const;

Vector3 objectPosition();
AABBox objectBound();

const VariantList &cache() const;

protected:
SelectList &m_selected;

VariantList m_propertiesCache;

Qt::CursorShape m_cursor;

float m_snap;
Expand Down
92 changes: 4 additions & 88 deletions engine/src/editor/editortool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@

#include "editor/viewport/handletools.h"

EditorTool::Select::Select() :
uuid(0),
object(nullptr),
renderable(nullptr) {
#include <QString>

}

EditorTool::EditorTool(EditorTool::SelectList &selection) :
m_selected(selection),
EditorTool::EditorTool() :
m_cursor(Qt::ArrowCursor),
m_snap(0.0f) {

Expand Down Expand Up @@ -44,95 +38,17 @@ void EditorTool::update(bool center, bool local, bool snap) {
}

void EditorTool::beginControl() {
m_propertiesCache.clear();

for(auto &it : m_selected) {
Transform *t = it.object->transform();
it.position = t->position();
it.scale = t->scale();
it.euler = t->rotation();
it.quat = t->quaternion();

VariantMap components;
for(auto &child : it.object->getChildren()) {
Component *component = dynamic_cast<Component *>(child);
if(component) {
VariantMap properies;
const MetaObject *meta = component->metaObject();
for(int i = 0; i < meta->propertyCount(); i++) {
MetaProperty property = meta->property(i);
properies[property.name()] = property.read(component);
}
components[std::to_string(component->uuid())] = properies;
}
}
m_propertiesCache.push_back(components);
}

}

void EditorTool::endControl() {

}

void EditorTool::cancelControl() {
auto cache = m_propertiesCache.begin();
for(auto &it : m_selected) {
VariantMap components = (*cache).toMap();
for(auto &child : it.object->getChildren()) {
Component *component = dynamic_cast<Component *>(child);
if(component) {
VariantMap properties = components[std::to_string(component->uuid())].toMap();
const MetaObject *meta = component->metaObject();
for(int i = 0; i < meta->propertyCount(); i++) {
MetaProperty property = meta->property(i);
property.write(component, properties[property.name()]);
}
}
}

++cache;
}

}

Qt::CursorShape EditorTool::cursor() const {
return m_cursor;
}

Vector3 EditorTool::objectPosition() {
if(m_selected.size() == 1) {
return m_selected.front().object->transform()->worldPosition();
}
return objectBound().center;
}

AABBox EditorTool::objectBound() {
AABBox result;
result.extent = Vector3(-1.0f);
if(!m_selected.empty()) {
bool first = true;
for(auto &it : m_selected) {
if(it.renderable == nullptr) {
it.renderable = dynamic_cast<Renderable *>(it.object->component("Renderable"));
}
if(it.renderable) {
if(first) {
result = it.renderable->bound();
first = false;
} else {
result.encapsulate(it.renderable->bound());
}
} else {
if(first) {
result.center = it.object->transform()->worldPosition();
} else {
result.encapsulate(it.object->transform()->worldPosition());
}
}
}
}
return result;
}

const VariantList &EditorTool::cache() const {
return m_propertiesCache;
}
2 changes: 1 addition & 1 deletion modules/editor/texturetools/converter/textureconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ std::string TextureImportSettings::findFreeElementName(const std::string &name)
return "Element";
}

const TextureImportSettings::ElementMap &TextureImportSettings::elements() const {
TextureImportSettings::ElementMap &TextureImportSettings::elements() {
return m_elements;
}

Expand Down
8 changes: 7 additions & 1 deletion modules/editor/texturetools/converter/textureconverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,15 @@ class TextureImportSettings : public AssetConverterSettings {
Vector2 m_min;
Vector2 m_max;

Vector2 m_saveMin;
Vector2 m_saveMax;

Vector2 m_borderMin;
Vector2 m_borderMax;

Vector2 m_saveBorderMin;
Vector2 m_saveBorderMax;

Vector2 m_pivot = Vector2(0.5f);
};
typedef std::map<std::string, Element> ElementMap;
Expand All @@ -65,7 +71,7 @@ class TextureImportSettings : public AssetConverterSettings {
bool lod() const;
void setLod(bool lod);

const ElementMap &elements() const;
ElementMap &elements();
std::string setElement(const Element &element, const std::string &key = std::string());
void removeElement(const std::string &key);

Expand Down
Loading