LumixEngine/src/editor/world_editor.h

167 lines
7.5 KiB
C
Raw Normal View History

2014-06-16 21:18:15 +02:00
#pragma once
#include "engine/lumix.h"
2019-06-13 17:26:52 +02:00
#include "engine/math.h"
2014-06-16 21:18:15 +02:00
2019-11-04 18:28:18 +01:00
struct lua_State;
2014-06-16 21:18:15 +02:00
namespace Lumix
{
namespace OS { enum class MouseButton; }
2019-01-05 15:14:34 +01:00
2020-02-21 22:09:11 +01:00
template <typename T> struct DelegateList;
template <typename T> struct Array;
2016-01-16 13:47:42 +01:00
2020-01-06 17:25:22 +01:00
struct IEditorCommand
{
virtual ~IEditorCommand() {}
virtual bool isReady() { return true; }
virtual bool execute() = 0;
virtual void undo() = 0;
virtual const char* getType() = 0;
virtual bool merge(IEditorCommand& command) = 0;
};
2020-02-03 01:36:24 +01:00
struct UniverseView {
struct RayHit {
bool is_hit;
float t;
EntityPtr entity;
DVec3 pos;
};
struct Vertex {
Vec3 pos;
u32 abgr;
};
2020-02-03 01:36:24 +01:00
virtual ~UniverseView() = default;
virtual const struct Viewport& getViewport() const = 0;
2020-02-03 01:36:24 +01:00
virtual void setViewport(const Viewport& vp) = 0;
virtual void lookAtSelected() = 0;
virtual void setTopView() = 0;
virtual void setFrontView() = 0;
virtual void setSideView() = 0;
virtual bool isOrbitCamera() const = 0;
virtual void setOrbitCamera(bool enable) = 0;
virtual void moveCamera(float forward, float right, float up, float speed) = 0;
virtual void copyTransform() = 0;
2020-02-03 22:20:11 +01:00
virtual bool isMouseDown(OS::MouseButton button) const = 0;
virtual bool isMouseClick(OS::MouseButton button) const = 0;
virtual Vec2 getMousePos() const = 0;
virtual void setMouseSensitivity(float x, float y) = 0;
virtual Vec2 getMouseSensitivity() = 0;
virtual void setCustomPivot() = 0;
virtual void resetPivot() = 0;
2020-02-03 22:20:11 +01:00
virtual void setSnapMode(bool enable, bool vertex_snap) = 0;
virtual RayHit getCameraRaycastHit(int cam_x, int cam_y) = 0;
virtual Vertex* render(bool lines, u32 vertex_count) = 0;
2020-03-07 22:14:30 +01:00
virtual void addText2D(float x, float y, Color color, const char* text) = 0;
2020-02-03 01:36:24 +01:00
};
2020-01-06 17:25:22 +01:00
LUMIX_EDITOR_API void addSphere(UniverseView& view, const DVec3& center, float radius, Color color);
LUMIX_EDITOR_API void addCube(UniverseView& view, const DVec3& center, const Vec3& x, const Vec3& y, const Vec3& z, Color color);
LUMIX_EDITOR_API void addCube(UniverseView& view, const DVec3& min, const DVec3& max, Color color);
LUMIX_EDITOR_API void addLine(UniverseView& view, const DVec3& a, const DVec3& b, Color color);
LUMIX_EDITOR_API void addCone(UniverseView& view, const DVec3& vertex, const Vec3& dir, const Vec3& axis0, const Vec3& axis1, Color color);
LUMIX_EDITOR_API void addFrustum(UniverseView& view, const struct ShiftedFrustum& frustum, Color color);
LUMIX_EDITOR_API void addCapsule(UniverseView& view, const DVec3& position, float height, float radius, Color color);
2020-02-21 22:09:11 +01:00
struct LUMIX_EDITOR_API WorldEditor
{
enum class Coordinate : i32 {
X,
Y,
2017-11-28 19:37:15 +01:00
Z,
NONE
};
2019-11-04 18:28:18 +01:00
using CommandCreator = IEditorCommand* (lua_State*, WorldEditor&);
static WorldEditor* create(struct Engine& engine, struct IAllocator& allocator);
2015-09-21 21:39:28 +02:00
static void destroy(WorldEditor* editor, IAllocator& allocator);
2015-04-05 18:08:50 +02:00
2020-04-29 19:13:16 +02:00
virtual bool loadProject() = 0;
virtual void update() = 0;
virtual Engine& getEngine() = 0;
virtual struct Universe* getUniverse() = 0;
virtual IAllocator& getAllocator() = 0;
2020-02-03 01:36:24 +01:00
virtual UniverseView& getView() = 0;
virtual void setView(UniverseView* view) = 0;
2020-02-03 02:16:08 +01:00
virtual void beginCommandGroup(u32 type) = 0;
virtual void endCommandGroup() = 0;
virtual void executeCommand(IEditorCommand* command) = 0;
virtual void executeCommand(const char* name, const char* args) = 0;
virtual void registerCommand(const char* name, CommandCreator* creator) = 0;
virtual bool isUniverseChanged() const = 0;
2015-09-19 11:38:53 +02:00
virtual bool canUndo() const = 0;
virtual bool canRedo() const = 0;
virtual void undo() = 0;
virtual void redo() = 0;
2020-01-06 17:25:22 +01:00
virtual void addComponent(Span<const EntityRef> entities, ComponentType type) = 0;
virtual void destroyComponent(Span<const EntityRef> entities, ComponentType cmp_type) = 0;
2018-08-19 17:35:37 +02:00
virtual EntityRef addEntity() = 0;
virtual void destroyEntities(const EntityRef* entities, int count) = 0;
virtual void selectEntities(const EntityRef* entities, int count, bool toggle) = 0;
virtual EntityRef addEntityAt(int camera_x, int camera_y) = 0;
virtual EntityRef addEntityAt(const DVec3& pos) = 0;
2018-09-16 18:35:57 +02:00
virtual void setEntitiesPositions(const EntityRef* entities, const DVec3* positions, int count) = 0;
virtual void setEntitiesCoordinate(const EntityRef* entities, int count, double value, Coordinate coord) = 0;
virtual void setEntitiesLocalCoordinate(const EntityRef* entities, int count, double value, Coordinate coord) = 0;
2018-08-19 17:35:37 +02:00
virtual void setEntitiesScale(const EntityRef* entities, int count, float scale) = 0;
virtual void setEntitiesScales(const EntityRef* entities, const float* scales, int count) = 0;
virtual void setEntitiesRotations(const EntityRef* entity, const Quat* rotations, int count) = 0;
virtual void setEntitiesPositionsAndRotations(const EntityRef* entity,
2018-09-16 18:35:57 +02:00
const DVec3* position,
2015-09-21 00:11:12 +02:00
const Quat* rotation,
2018-02-09 17:06:35 +01:00
int count) = 0;
2018-08-19 17:35:37 +02:00
virtual void setEntityName(EntityRef entity, const char* name) = 0;
2020-04-29 19:13:16 +02:00
virtual void setProperty(ComponentType component, const char* array, int index, const char* property, Span<const EntityRef> entities, float value) = 0;
virtual void setProperty(ComponentType component, const char* array, int index, const char* property, Span<const EntityRef> entities, i32 value) = 0;
virtual void setProperty(ComponentType component, const char* array, int index, const char* property, Span<const EntityRef> entities, u32 value) = 0;
virtual void setProperty(ComponentType component, const char* array, int index, const char* property, Span<const EntityRef> entities, EntityPtr value) = 0;
virtual void setProperty(ComponentType component, const char* array, int index, const char* property, Span<const EntityRef> entities, const char* value) = 0;
virtual void setProperty(ComponentType component, const char* array, int index, const char* property, Span<const EntityRef> entities, const struct Path& value) = 0;
virtual void setProperty(ComponentType component, const char* array, int index, const char* property, Span<const EntityRef> entities, bool value) = 0;
virtual void setProperty(ComponentType component, const char* array, int index, const char* property, Span<const EntityRef> entities, const Vec2& value) = 0;
virtual void setProperty(ComponentType component, const char* array, int index, const char* property, Span<const EntityRef> entities, const Vec3& value) = 0;
virtual void setProperty(ComponentType component, const char* array, int index, const char* property, Span<const EntityRef> entities, const Vec4& value) = 0;
virtual void setProperty(ComponentType component, const char* array, int index, const char* property, Span<const EntityRef> entities, const IVec3& value) = 0;
virtual void addArrayPropertyItem(const struct ComponentUID& cmp, const char* property) = 0;
virtual void removeArrayPropertyItem(const ComponentUID& cmp, int index, const char* property) = 0;
2020-02-03 02:16:08 +01:00
virtual const Array<EntityRef>& getSelectedEntities() const = 0;
virtual bool isEntitySelected(EntityRef entity) const = 0;
virtual void makeParent(EntityPtr parent, EntityRef child) = 0;
virtual void copyEntities() = 0;
virtual bool canPasteEntities() const = 0;
virtual void pasteEntities() = 0;
virtual void duplicateEntities() = 0;
virtual void loadUniverse(const char* basename) = 0;
virtual void saveUniverse(const char* basename, bool save_path) = 0;
virtual void newUniverse() = 0;
virtual void toggleGameMode() = 0;
virtual void setToggleSelection(bool is_toggle) = 0;
virtual DelegateList<void()>& universeCreated() = 0;
virtual DelegateList<void()>& universeDestroyed() = 0;
2016-02-24 20:46:14 +01:00
virtual struct PrefabSystem& getPrefabSystem() = 0;
virtual void snapEntities(const DVec3& hit_pos, bool translate_mode) = 0;
2014-06-16 21:18:15 +02:00
virtual bool isGameMode() const = 0;
2014-06-16 21:18:15 +02:00
protected:
virtual ~WorldEditor() {}
};
}