refactor - properties moved from engine to editor
This commit is contained in:
parent
2162eb18d9
commit
8dc6229323
16 changed files with 615 additions and 595 deletions
|
@ -8,7 +8,6 @@
|
|||
#include "core/resource_manager.h"
|
||||
#include "editor/world_editor.h"
|
||||
#include "engine.h"
|
||||
#include "engine/property_descriptor.h"
|
||||
#include "renderer/render_scene.h"
|
||||
#include "universe/universe.h"
|
||||
|
||||
|
@ -292,7 +291,6 @@ public:
|
|||
, m_engine(engine)
|
||||
, m_animation_manager(m_allocator)
|
||||
{
|
||||
registerPropertyDescriptors();
|
||||
}
|
||||
|
||||
virtual IScene* createScene(UniverseContext& ctx) override
|
||||
|
@ -311,21 +309,6 @@ public:
|
|||
virtual const char* getName() const override { return "animation"; }
|
||||
|
||||
|
||||
void registerPropertyDescriptors()
|
||||
{
|
||||
IAllocator& allocator = m_engine.getAllocator();
|
||||
m_engine.registerComponentType("animable", "Animable");
|
||||
m_engine.registerProperty(
|
||||
"animable",
|
||||
allocator.newObject<FilePropertyDescriptor<AnimationSceneImpl>>(
|
||||
"preview",
|
||||
&AnimationSceneImpl::getPreview,
|
||||
&AnimationSceneImpl::setPreview,
|
||||
"Animation (*.ani)",
|
||||
allocator));
|
||||
}
|
||||
|
||||
|
||||
virtual bool create() override
|
||||
{
|
||||
m_animation_manager.create(ResourceManager::ANIMATION,
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include "universe\universe.h"
|
||||
#include "core/blob.h"
|
||||
#include "core/crc32.h"
|
||||
#include "core/delegate.h"
|
||||
#include "core/stack_allocator.h"
|
||||
#include "core/string.h"
|
||||
#include "core/vec4.h"
|
||||
#include "universe\universe.h"
|
||||
#include <cfloat>
|
||||
|
||||
|
147
src/editor/property_register.cpp
Normal file
147
src/editor/property_register.cpp
Normal file
|
@ -0,0 +1,147 @@
|
|||
#include "property_register.h"
|
||||
#include "core/associative_array.h"
|
||||
#include "editor/property_descriptor.h"
|
||||
|
||||
|
||||
namespace Lumix
|
||||
{
|
||||
|
||||
|
||||
namespace PropertyRegister
|
||||
{
|
||||
|
||||
|
||||
struct ComponentType
|
||||
{
|
||||
ComponentType(IAllocator& allocator)
|
||||
: m_name(allocator)
|
||||
, m_id(allocator)
|
||||
{
|
||||
}
|
||||
|
||||
string m_name;
|
||||
string m_id;
|
||||
|
||||
uint32_t m_id_hash;
|
||||
uint32_t m_dependency;
|
||||
};
|
||||
|
||||
|
||||
typedef AssociativeArray<uint32_t, Array<IPropertyDescriptor*>> PropertyMap;
|
||||
|
||||
|
||||
static PropertyMap* g_properties = nullptr;
|
||||
static Array<ComponentType>* g_component_types = nullptr;
|
||||
static IAllocator* g_allocator = nullptr;
|
||||
|
||||
|
||||
void init(IAllocator& allocator)
|
||||
{
|
||||
ASSERT(!g_properties);
|
||||
g_properties = LUMIX_NEW(allocator, PropertyMap)(allocator);
|
||||
g_allocator = &allocator;
|
||||
g_component_types = LUMIX_NEW(allocator, Array<ComponentType>)(allocator);
|
||||
}
|
||||
|
||||
|
||||
void shutdown()
|
||||
{
|
||||
for (int j = 0; j < g_properties->size(); ++j)
|
||||
{
|
||||
Array<IPropertyDescriptor*>& props = g_properties->at(j);
|
||||
for (auto* prop : props)
|
||||
{
|
||||
LUMIX_DELETE(*g_allocator, prop);
|
||||
}
|
||||
}
|
||||
|
||||
LUMIX_DELETE(*g_allocator, g_properties);
|
||||
LUMIX_DELETE(*g_allocator, g_component_types);
|
||||
g_properties = nullptr;
|
||||
g_allocator = nullptr;
|
||||
g_component_types = nullptr;
|
||||
}
|
||||
|
||||
|
||||
void add(const char* component_type, IPropertyDescriptor* descriptor)
|
||||
{
|
||||
getDescriptors(crc32(component_type)).push(descriptor);
|
||||
}
|
||||
|
||||
|
||||
Array<IPropertyDescriptor*>& getDescriptors(uint32_t type)
|
||||
{
|
||||
int props_index = g_properties->find(type);
|
||||
if (props_index < 0)
|
||||
{
|
||||
g_properties->insert(type, Array<IPropertyDescriptor*>(*g_allocator));
|
||||
props_index = g_properties->find(type);
|
||||
}
|
||||
return g_properties->at(props_index);
|
||||
}
|
||||
|
||||
|
||||
const IPropertyDescriptor& getDescriptor(uint32_t type, uint32_t name_hash)
|
||||
{
|
||||
Array<IPropertyDescriptor*>& props = getDescriptors(type);
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
{
|
||||
if (props[i]->getNameHash() == name_hash)
|
||||
{
|
||||
return *props[i];
|
||||
}
|
||||
}
|
||||
ASSERT(false);
|
||||
return *props[0];
|
||||
}
|
||||
|
||||
|
||||
const IPropertyDescriptor& getDescriptor(const char* component_type, const char* property_name)
|
||||
{
|
||||
return getDescriptor(crc32(component_type), crc32(property_name));
|
||||
}
|
||||
|
||||
|
||||
void registerComponentDependency(const char* id, const char* dependency_id)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool componentDepends(uint32_t dependent, uint32_t dependency)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void registerComponentType(const char* id, const char* name)
|
||||
{
|
||||
ComponentType& type = g_component_types->emplace(*g_allocator);
|
||||
type.m_name = name;
|
||||
type.m_id = id;
|
||||
type.m_id_hash = crc32(id);
|
||||
type.m_dependency = 0;
|
||||
}
|
||||
|
||||
|
||||
int getComponentTypesCount()
|
||||
{
|
||||
return g_component_types->size();
|
||||
}
|
||||
|
||||
|
||||
const char* getComponentTypeName(int index)
|
||||
{
|
||||
return (*g_component_types)[index].m_name.c_str();
|
||||
}
|
||||
|
||||
|
||||
const char* getComponentTypeID(int index)
|
||||
{
|
||||
return (*g_component_types)[index].m_id.c_str();
|
||||
}
|
||||
|
||||
|
||||
} // namespace PropertyRegister
|
||||
|
||||
|
||||
} // namespace Lumix
|
40
src/editor/property_register.h
Normal file
40
src/editor/property_register.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
#include "lumix.h"
|
||||
#include "core/array.h"
|
||||
|
||||
|
||||
namespace Lumix
|
||||
{
|
||||
|
||||
|
||||
class IPropertyDescriptor;
|
||||
|
||||
|
||||
namespace PropertyRegister
|
||||
{
|
||||
|
||||
|
||||
LUMIX_EDITOR_API void init(IAllocator& allocator);
|
||||
LUMIX_EDITOR_API void shutdown();
|
||||
LUMIX_EDITOR_API void add(const char* component_type, IPropertyDescriptor* desc);
|
||||
LUMIX_EDITOR_API const IPropertyDescriptor& getDescriptor(uint32_t type, uint32_t name_hash);
|
||||
LUMIX_EDITOR_API const IPropertyDescriptor& getDescriptor(const char* component_type,
|
||||
const char* property_name);
|
||||
LUMIX_EDITOR_API Array<IPropertyDescriptor*>& getDescriptors(uint32_t type);
|
||||
|
||||
|
||||
LUMIX_EDITOR_API void registerComponentDependency(const char* id, const char* dependency_id);
|
||||
LUMIX_EDITOR_API bool componentDepends(uint32_t dependent, uint32_t dependency);
|
||||
LUMIX_EDITOR_API void registerComponentType(const char* name, const char* title);
|
||||
LUMIX_EDITOR_API int getComponentTypesCount();
|
||||
LUMIX_EDITOR_API const char* getComponentTypeName(int index);
|
||||
LUMIX_EDITOR_API const char* getComponentTypeID(int index);
|
||||
|
||||
|
||||
|
||||
} // namespace PropertyRegister
|
||||
|
||||
|
||||
} // namespace Lumix
|
|
@ -29,8 +29,9 @@
|
|||
#include "editor/entity_template_system.h"
|
||||
#include "editor/gizmo.h"
|
||||
#include "editor/measure_tool.h"
|
||||
#include "editor/property_register.h"
|
||||
#include "engine.h"
|
||||
#include "engine/property_descriptor.h"
|
||||
#include "editor/property_descriptor.h"
|
||||
#include "iplugin.h"
|
||||
#include "plugin_manager.h"
|
||||
#include "renderer/material.h"
|
||||
|
@ -556,8 +557,7 @@ public:
|
|||
uint32_t property_name_hash;
|
||||
serializer.deserialize("property_name_hash", property_name_hash, 0);
|
||||
m_descriptor = static_cast<const IArrayDescriptor*>(
|
||||
&m_editor.getEngine().getPropertyDescriptor(m_component.type,
|
||||
property_name_hash));
|
||||
&PropertyRegister::getDescriptor(m_component.type, property_name_hash));
|
||||
}
|
||||
|
||||
|
||||
|
@ -638,8 +638,7 @@ public:
|
|||
uint32_t property_name_hash;
|
||||
serializer.deserialize("property_name_hash", property_name_hash, 0);
|
||||
m_descriptor = static_cast<const IArrayDescriptor*>(
|
||||
&m_editor.getEngine().getPropertyDescriptor(m_component.type,
|
||||
property_name_hash));
|
||||
&PropertyRegister::getDescriptor(m_component.type, property_name_hash));
|
||||
}
|
||||
|
||||
|
||||
|
@ -759,8 +758,8 @@ public:
|
|||
serializer.deserializeArrayEnd();
|
||||
uint32_t property_name_hash;
|
||||
serializer.deserialize("property_name_hash", property_name_hash, 0);
|
||||
m_property_descriptor = &m_editor.getEngine().getPropertyDescriptor(
|
||||
m_component_type, property_name_hash);
|
||||
m_property_descriptor =
|
||||
&PropertyRegister::getDescriptor(m_component_type, property_name_hash);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1091,14 +1090,12 @@ private:
|
|||
{
|
||||
m_old_values.write(cmps[j].type);
|
||||
Array<IPropertyDescriptor*>& props =
|
||||
m_editor.getEngine().getPropertyDescriptors(
|
||||
cmps[j].type);
|
||||
PropertyRegister::getDescriptors(cmps[j].type);
|
||||
for (int k = 0; k < props.size(); ++k)
|
||||
{
|
||||
props[k]->get(cmps[j], m_old_values);
|
||||
}
|
||||
cmps[j].scene->destroyComponent(cmps[j].index,
|
||||
cmps[j].type);
|
||||
cmps[j].scene->destroyComponent(cmps[j].index, cmps[j].type);
|
||||
}
|
||||
|
||||
universe->destroyEntity(Entity(m_entities[i]));
|
||||
|
@ -1128,8 +1125,7 @@ private:
|
|||
ComponentUID new_component;
|
||||
for (int i = 0; i < scenes.size(); ++i)
|
||||
{
|
||||
new_component.index =
|
||||
scenes[i]->createComponent(cmp_type, new_entity);
|
||||
new_component.index = scenes[i]->createComponent(cmp_type, new_entity);
|
||||
new_component.entity = new_entity;
|
||||
new_component.scene = scenes[i];
|
||||
new_component.type = cmp_type;
|
||||
|
@ -1139,8 +1135,7 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
Array<IPropertyDescriptor*>& props =
|
||||
m_editor.getEngine().getPropertyDescriptors(cmp_type);
|
||||
Array<IPropertyDescriptor*>& props = PropertyRegister::getDescriptors(cmp_type);
|
||||
|
||||
for (int k = 0; k < props.size(); ++k)
|
||||
{
|
||||
|
@ -1214,16 +1209,15 @@ private:
|
|||
|
||||
void undo() override
|
||||
{
|
||||
uint32_t template_hash =
|
||||
m_editor.m_template_system->getTemplate(m_component.entity);
|
||||
uint32_t template_hash = m_editor.m_template_system->getTemplate(m_component.entity);
|
||||
const Array<IScene*>& scenes = m_editor.getScenes();
|
||||
|
||||
if (template_hash == 0)
|
||||
{
|
||||
for (int i = 0; i < scenes.size(); ++i)
|
||||
{
|
||||
ComponentIndex cmp = scenes[i]->createComponent(
|
||||
m_component.type, m_component.entity);
|
||||
ComponentIndex cmp =
|
||||
scenes[i]->createComponent(m_component.type, m_component.entity);
|
||||
if (cmp != INVALID_COMPONENT)
|
||||
{
|
||||
m_component.index = cmp;
|
||||
|
@ -1233,8 +1227,7 @@ private:
|
|||
}
|
||||
InputBlob blob(m_old_values);
|
||||
const Array<IPropertyDescriptor*>& props =
|
||||
m_editor.getEngine().getPropertyDescriptors(
|
||||
m_component.type);
|
||||
PropertyRegister::getDescriptors(m_component.type);
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
{
|
||||
props[i]->set(m_component, blob);
|
||||
|
@ -1244,15 +1237,11 @@ private:
|
|||
{
|
||||
const Array<Entity>& entities =
|
||||
m_editor.m_template_system->getInstances(template_hash);
|
||||
for (int entity_index = 0, c = entities.size();
|
||||
entity_index < c;
|
||||
++entity_index)
|
||||
for (int entity_index = 0, c = entities.size(); entity_index < c; ++entity_index)
|
||||
{
|
||||
for (int scene_index = 0; scene_index < scenes.size();
|
||||
++scene_index)
|
||||
for (int scene_index = 0; scene_index < scenes.size(); ++scene_index)
|
||||
{
|
||||
ComponentUID cmp_new(
|
||||
entities[entity_index],
|
||||
ComponentUID cmp_new(entities[entity_index],
|
||||
m_component.type,
|
||||
scenes[scene_index],
|
||||
scenes[scene_index]->createComponent(
|
||||
|
@ -1261,8 +1250,7 @@ private:
|
|||
{
|
||||
InputBlob blob(m_old_values);
|
||||
const Array<IPropertyDescriptor*>& props =
|
||||
m_editor.getEngine().getPropertyDescriptors(
|
||||
m_component.type);
|
||||
PropertyRegister::getDescriptors(m_component.type);
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
{
|
||||
props[i]->set(cmp_new, blob);
|
||||
|
@ -1286,8 +1274,7 @@ private:
|
|||
|
||||
bool execute() override
|
||||
{
|
||||
Array<IPropertyDescriptor*>& props =
|
||||
m_editor.getEngine().getPropertyDescriptors(m_component.type);
|
||||
Array<IPropertyDescriptor*>& props = PropertyRegister::getDescriptors(m_component.type);
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
{
|
||||
props[i]->get(m_component, m_old_values);
|
||||
|
@ -1719,6 +1706,7 @@ public:
|
|||
|
||||
destroyUniverse();
|
||||
EntityTemplateSystem::destroy(m_template_system);
|
||||
PropertyRegister::shutdown();
|
||||
}
|
||||
|
||||
|
||||
|
@ -2234,7 +2222,7 @@ public:
|
|||
uint32_t cmp_type = cmps[i].type;
|
||||
m_copy_buffer.write(cmp_type);
|
||||
Array<IPropertyDescriptor*>& props =
|
||||
getEngine().getPropertyDescriptors(cmps[i].type);
|
||||
PropertyRegister::getDescriptors(cmps[i].type);
|
||||
int32_t prop_count = props.size();
|
||||
for (int j = 0; j < prop_count; ++j)
|
||||
{
|
||||
|
@ -2276,7 +2264,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
const auto& properties = getEngine().getPropertyDescriptors(src.type);
|
||||
const auto& properties = PropertyRegister::getDescriptors(src.type);
|
||||
OutputBlob stream(m_allocator);
|
||||
for (int i = 0; i < properties.size(); ++i)
|
||||
{
|
||||
|
@ -2293,7 +2281,7 @@ public:
|
|||
auto& cmps = getComponents(cmp.entity);
|
||||
for (auto& possible_dependent : cmps)
|
||||
{
|
||||
if (m_engine->componentDepends(possible_dependent.type, cmp.type)) return false;
|
||||
if (PropertyRegister::componentDepends(possible_dependent.type, cmp.type)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -2594,6 +2582,7 @@ public:
|
|||
, m_gizmo_use_step(false)
|
||||
, m_is_additive_selection(false)
|
||||
{
|
||||
PropertyRegister::init(m_allocator);
|
||||
m_go_to_parameters.m_is_active = false;
|
||||
m_undo_index = -1;
|
||||
m_mouse_handling_plugin = nullptr;
|
||||
|
@ -3321,10 +3310,9 @@ bool PasteEntityCommand::execute()
|
|||
{
|
||||
uint32_t type;
|
||||
blob.read(type);
|
||||
ComponentUID cmp = static_cast<WorldEditorImpl&>(m_editor)
|
||||
.createComponent(type, new_entity);
|
||||
Array<IPropertyDescriptor*>& props =
|
||||
m_editor.getEngine().getPropertyDescriptors(type);
|
||||
ComponentUID cmp =
|
||||
static_cast<WorldEditorImpl&>(m_editor).createComponent(type, new_entity);
|
||||
Array<IPropertyDescriptor*>& props = PropertyRegister::getDescriptors(type);
|
||||
for (int j = 0; j < props.size(); ++j)
|
||||
{
|
||||
props[j]->set(cmp, blob);
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include "debug/allocator.h"
|
||||
#include "debug/debug.h"
|
||||
#include "engine/iplugin.h"
|
||||
#include "engine/property_descriptor.h"
|
||||
#include "plugin_manager.h"
|
||||
#include "universe/hierarchy.h"
|
||||
#include "universe/universe.h"
|
||||
|
@ -72,7 +71,6 @@ public:
|
|||
, m_mtjd_manager(m_allocator)
|
||||
, m_fps(0)
|
||||
, m_is_game_running(false)
|
||||
, m_component_properties(m_allocator)
|
||||
, m_component_types(m_allocator)
|
||||
{
|
||||
if (!fs)
|
||||
|
@ -121,15 +119,6 @@ public:
|
|||
|
||||
~EngineImpl()
|
||||
{
|
||||
for (int j = 0; j < m_component_properties.size(); ++j)
|
||||
{
|
||||
Array<IPropertyDescriptor*>& props = m_component_properties.at(j);
|
||||
for (int i = 0, c = props.size(); i < c; ++i)
|
||||
{
|
||||
m_allocator.deleteObject(props[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Timer::destroy(m_timer);
|
||||
Timer::destroy(m_fps_timer);
|
||||
PluginManager::destroy(m_plugin_manager);
|
||||
|
@ -148,111 +137,6 @@ public:
|
|||
IAllocator& getAllocator() override { return m_allocator; }
|
||||
|
||||
|
||||
const char* getComponentTypeName(int index) override
|
||||
{
|
||||
return m_component_types[index].m_name.c_str();
|
||||
}
|
||||
|
||||
|
||||
const char* getComponentTypeID(int index) override
|
||||
{
|
||||
return m_component_types[index].m_id.c_str();
|
||||
}
|
||||
|
||||
|
||||
int getComponentTypesCount() const override
|
||||
{
|
||||
return m_component_types.size();
|
||||
}
|
||||
|
||||
|
||||
Array<IPropertyDescriptor*>& getPropertyDescriptors(uint32_t type)
|
||||
{
|
||||
int props_index = m_component_properties.find(type);
|
||||
if (props_index < 0)
|
||||
{
|
||||
m_component_properties.insert(
|
||||
type, Array<IPropertyDescriptor*>(m_allocator));
|
||||
props_index = m_component_properties.find(type);
|
||||
}
|
||||
return m_component_properties.at(props_index);
|
||||
}
|
||||
|
||||
|
||||
const IPropertyDescriptor&
|
||||
getPropertyDescriptor(uint32_t type, uint32_t name_hash) override
|
||||
{
|
||||
Array<IPropertyDescriptor*>& props = getPropertyDescriptors(type);
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
{
|
||||
if (props[i]->getNameHash() == name_hash)
|
||||
{
|
||||
return *props[i];
|
||||
}
|
||||
}
|
||||
ASSERT(false);
|
||||
return *props[0];
|
||||
}
|
||||
|
||||
|
||||
IPropertyDescriptor* getProperty(const char* component_type,
|
||||
const char* property_name) override
|
||||
{
|
||||
auto& props = getPropertyDescriptors(crc32(component_type));
|
||||
auto name_hash = crc32(property_name);
|
||||
for (int i = 0; i < props.size(); ++i)
|
||||
{
|
||||
if (props[i]->getNameHash() == name_hash)
|
||||
{
|
||||
return props[i];
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
virtual bool componentDepends(uint32_t dependent, uint32_t dependency) const override
|
||||
{
|
||||
for (ComponentType& cmp_type : m_component_types)
|
||||
{
|
||||
if (cmp_type.m_id_hash == dependent)
|
||||
{
|
||||
return cmp_type.m_dependency == dependency;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void registerComponentDependency(const char* id, const char* dependency_id) override
|
||||
{
|
||||
for (ComponentType& cmp_type : m_component_types)
|
||||
{
|
||||
if (cmp_type.m_id == id)
|
||||
{
|
||||
cmp_type.m_dependency = crc32(dependency_id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
ASSERT(false);
|
||||
}
|
||||
|
||||
|
||||
void registerComponentType(const char* id, const char* name) override
|
||||
{
|
||||
ComponentType& type = m_component_types.emplace(m_allocator);
|
||||
type.m_name = name;
|
||||
type.m_id = id;
|
||||
type.m_id_hash = crc32(id);
|
||||
}
|
||||
|
||||
|
||||
void registerProperty(const char* component_type, IPropertyDescriptor* descriptor) override
|
||||
{
|
||||
ASSERT(descriptor);
|
||||
getPropertyDescriptors(crc32(component_type)).push(descriptor);
|
||||
}
|
||||
|
||||
|
||||
UniverseContext& createUniverse() override
|
||||
{
|
||||
UniverseContext* context =
|
||||
|
@ -481,8 +365,6 @@ private:
|
|||
|
||||
MTJD::Manager m_mtjd_manager;
|
||||
|
||||
AssociativeArray<uint32_t, Array<IPropertyDescriptor*>>
|
||||
m_component_properties;
|
||||
Array<ComponentType> m_component_types;
|
||||
PluginManager* m_plugin_manager;
|
||||
InputSystem m_input_system;
|
||||
|
|
|
@ -74,18 +74,6 @@ public:
|
|||
virtual float getFPS() const = 0;
|
||||
virtual float getLastTimeDelta() = 0;
|
||||
|
||||
virtual const IPropertyDescriptor& getPropertyDescriptor(uint32_t type, uint32_t name_hash) = 0;
|
||||
virtual Array<IPropertyDescriptor*>& getPropertyDescriptors(uint32_t type) = 0;
|
||||
virtual void registerProperty(const char* name, IPropertyDescriptor* desc) = 0;
|
||||
virtual IPropertyDescriptor* getProperty(const char* component_type,
|
||||
const char* property_name) = 0;
|
||||
virtual void registerComponentDependency(const char* id, const char* dependency_id) = 0;
|
||||
virtual bool componentDepends(uint32_t dependent, uint32_t dependency) const = 0;
|
||||
virtual void registerComponentType(const char* name, const char* title) = 0;
|
||||
virtual int getComponentTypesCount() const = 0;
|
||||
virtual const char* getComponentTypeName(int index) = 0;
|
||||
virtual const char* getComponentTypeID(int index) = 0;
|
||||
|
||||
protected:
|
||||
Engine() {}
|
||||
};
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "core/resource_manager.h"
|
||||
#include "debug/allocator.h"
|
||||
#include "engine.h"
|
||||
#include "engine/property_descriptor.h"
|
||||
#include "iplugin.h"
|
||||
#include "plugin_manager.h"
|
||||
#include "lua_script/lua_script_manager.h"
|
||||
|
@ -51,7 +50,6 @@ public:
|
|||
virtual bool create() override;
|
||||
virtual void destroy() override;
|
||||
virtual const char* getName() const override;
|
||||
void registerProperties();
|
||||
LuaScriptManager& getScriptManager() { return m_script_manager; }
|
||||
|
||||
Engine& m_engine;
|
||||
|
@ -439,7 +437,7 @@ public:
|
|||
}
|
||||
|
||||
|
||||
const char* getScriptPath(ComponentIndex cmp)
|
||||
const char* getScriptPath(ComponentIndex cmp) override
|
||||
{
|
||||
return m_scripts[cmp].m_script
|
||||
? m_scripts[cmp].m_script->getPath().c_str()
|
||||
|
@ -447,7 +445,7 @@ public:
|
|||
}
|
||||
|
||||
|
||||
void setScriptPath(ComponentIndex cmp, const char* path)
|
||||
void setScriptPath(ComponentIndex cmp, const char* path) override
|
||||
{
|
||||
if (m_scripts[cmp].m_script)
|
||||
{
|
||||
|
@ -475,7 +473,6 @@ LuaScriptSystem::LuaScriptSystem(Engine& engine)
|
|||
, m_script_manager(m_allocator)
|
||||
{
|
||||
m_script_manager.create(crc32("lua_script"), engine.getResourceManager());
|
||||
registerProperties();
|
||||
}
|
||||
|
||||
|
||||
|
@ -509,20 +506,6 @@ bool LuaScriptSystem::create()
|
|||
}
|
||||
|
||||
|
||||
void LuaScriptSystem::registerProperties()
|
||||
{
|
||||
IAllocator& allocator = m_engine.getAllocator();
|
||||
m_engine.registerComponentType("lua_script", "Lua script");
|
||||
m_engine.registerProperty("lua_script",
|
||||
LUMIX_NEW(allocator, ResourcePropertyDescriptor<LuaScriptSceneImpl>)("source",
|
||||
&LuaScriptSceneImpl::getScriptPath,
|
||||
&LuaScriptSceneImpl::setScriptPath,
|
||||
"Lua (*.lua)",
|
||||
crc32("lua_script"),
|
||||
allocator));
|
||||
}
|
||||
|
||||
|
||||
void LuaScriptSystem::destroy()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ public:
|
|||
};
|
||||
|
||||
public:
|
||||
virtual const char* getScriptPath(ComponentIndex cmp) = 0;
|
||||
virtual void setScriptPath(ComponentIndex cmp, const char* path) = 0;
|
||||
virtual int getPropertyCount(ComponentIndex cmp) const = 0;
|
||||
virtual const char* getPropertyName(ComponentIndex cmp, int index) const = 0;
|
||||
virtual const char* getPropertyValue(ComponentIndex cmp, int index) const = 0;
|
||||
|
|
|
@ -9,10 +9,10 @@
|
|||
#include "core/resource_manager.h"
|
||||
#include "editor/world_editor.h"
|
||||
#include "engine.h"
|
||||
#include "engine/property_descriptor.h"
|
||||
#include "renderer/render_scene.h"
|
||||
#include "physics/physics_geometry_manager.h"
|
||||
#include "physics/physics_scene.h"
|
||||
#include "renderer/render_scene.h"
|
||||
#include "universe/universe.h"
|
||||
|
||||
|
||||
namespace Lumix
|
||||
|
@ -34,7 +34,6 @@ struct PhysicsSystemImpl : public PhysicsSystem
|
|||
, m_manager(*this, engine.getAllocator())
|
||||
{
|
||||
m_manager.create(ResourceManager::PHYSICS, engine.getResourceManager());
|
||||
registerProperties();
|
||||
}
|
||||
|
||||
virtual bool create() override;
|
||||
|
@ -58,7 +57,6 @@ struct PhysicsSystemImpl : public PhysicsSystem
|
|||
}
|
||||
|
||||
bool connect2VisualDebugger();
|
||||
void registerProperties();
|
||||
|
||||
physx::PxPhysics* m_physics;
|
||||
physx::PxFoundation* m_foundation;
|
||||
|
@ -162,70 +160,6 @@ class AssertNullAllocator : public physx::PxAllocatorCallback
|
|||
};
|
||||
|
||||
|
||||
void PhysicsSystemImpl::registerProperties()
|
||||
{
|
||||
m_engine.registerComponentType("box_rigid_actor", "Physics Box");
|
||||
m_engine.registerComponentType("physical_controller",
|
||||
"Physics Controller");
|
||||
m_engine.registerComponentType("mesh_rigid_actor", "Physics Mesh");
|
||||
m_engine.registerComponentType("physical_heightfield",
|
||||
"Physics Heightfield");
|
||||
|
||||
IAllocator& allocator = m_engine.getAllocator();
|
||||
m_engine.registerProperty(
|
||||
"box_rigid_actor",
|
||||
LUMIX_NEW(allocator, BoolPropertyDescriptor<PhysicsScene>)(
|
||||
"dynamic",
|
||||
&PhysicsScene::isDynamic,
|
||||
&PhysicsScene::setIsDynamic,
|
||||
allocator));
|
||||
m_engine.registerProperty(
|
||||
"box_rigid_actor",
|
||||
LUMIX_NEW(allocator, Vec3PropertyDescriptor<PhysicsScene>)(
|
||||
"size",
|
||||
&PhysicsScene::getHalfExtents,
|
||||
&PhysicsScene::setHalfExtents,
|
||||
allocator));
|
||||
m_engine.registerProperty(
|
||||
"mesh_rigid_actor",
|
||||
LUMIX_NEW(allocator, FilePropertyDescriptor<PhysicsScene>)(
|
||||
"source",
|
||||
&PhysicsScene::getShapeSource,
|
||||
&PhysicsScene::setShapeSource,
|
||||
"Physics (*.pda)",
|
||||
allocator));
|
||||
m_engine.registerProperty(
|
||||
"physical_heightfield",
|
||||
LUMIX_NEW(allocator, ResourcePropertyDescriptor<PhysicsScene>)(
|
||||
"heightmap",
|
||||
&PhysicsScene::getHeightmap,
|
||||
&PhysicsScene::setHeightmap,
|
||||
"Image (*.raw)",
|
||||
Lumix::ResourceManager::TEXTURE,
|
||||
allocator));
|
||||
m_engine.registerProperty(
|
||||
"physical_heightfield",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<PhysicsScene>)(
|
||||
"xz_scale",
|
||||
&PhysicsScene::getHeightmapXZScale,
|
||||
&PhysicsScene::setHeightmapXZScale,
|
||||
0.0f,
|
||||
FLT_MAX,
|
||||
0.0f,
|
||||
allocator));
|
||||
m_engine.registerProperty(
|
||||
"physical_heightfield",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<PhysicsScene>)(
|
||||
"y_scale",
|
||||
&PhysicsScene::getHeightmapYScale,
|
||||
&PhysicsScene::setHeightmapYScale,
|
||||
0.0f,
|
||||
FLT_MAX,
|
||||
0.0f,
|
||||
allocator));
|
||||
}
|
||||
|
||||
|
||||
bool PhysicsSystemImpl::create()
|
||||
{
|
||||
m_physx_allocator = m_allocator.newObject<AssertNullAllocator>();
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "debug/debug.h"
|
||||
#include "editor/world_editor.h"
|
||||
#include "engine.h"
|
||||
#include "engine/property_descriptor.h"
|
||||
#include "renderer/material.h"
|
||||
#include "renderer/material_manager.h"
|
||||
#include "renderer/model.h"
|
||||
|
@ -216,8 +215,6 @@ struct RendererImpl : public Renderer
|
|||
|
||||
m_current_pass_hash = crc32("MAIN");
|
||||
m_view_counter = 0;
|
||||
|
||||
registerPropertyDescriptors();
|
||||
}
|
||||
|
||||
~RendererImpl()
|
||||
|
@ -248,269 +245,6 @@ struct RendererImpl : public Renderer
|
|||
}
|
||||
|
||||
|
||||
void registerPropertyDescriptors()
|
||||
{
|
||||
IAllocator& allocator = m_engine.getAllocator();
|
||||
|
||||
m_engine.registerComponentType("camera", "Camera");
|
||||
m_engine.registerComponentType("global_light", "Global light");
|
||||
m_engine.registerComponentType("renderable", "Mesh");
|
||||
m_engine.registerComponentType("particle_emitter", "Particle emitter");
|
||||
m_engine.registerComponentType("particle_emitter_fade", "Particle emitter - fade");
|
||||
m_engine.registerComponentType(
|
||||
"particle_emitter_linear_movement", "Particle emitter - linear movement");
|
||||
m_engine.registerComponentType(
|
||||
"particle_emitter_random_rotation", "Particle emitter - random rotation");
|
||||
m_engine.registerComponentType("point_light", "Point light");
|
||||
m_engine.registerComponentType("terrain", "Terrain");
|
||||
|
||||
m_engine.registerComponentDependency("particle_emitter_fade", "particle_emitter");
|
||||
m_engine.registerComponentDependency(
|
||||
"particle_emitter_linear_movement", "particle_emitter");
|
||||
m_engine.registerComponentDependency(
|
||||
"particle_emitter_random_rotation", "particle_emitter");
|
||||
|
||||
m_engine.registerProperty("particle_emitter_linear_movement",
|
||||
LUMIX_NEW(allocator, Vec2PropertyDescriptor<RenderScene>)("x",
|
||||
&RenderScene::getParticleEmitterLinearMovementX,
|
||||
&RenderScene::setParticleEmitterLinearMovementX,
|
||||
allocator));
|
||||
m_engine.registerProperty("particle_emitter_linear_movement",
|
||||
LUMIX_NEW(allocator, Vec2PropertyDescriptor<RenderScene>)("y",
|
||||
&RenderScene::getParticleEmitterLinearMovementY,
|
||||
&RenderScene::setParticleEmitterLinearMovementY,
|
||||
allocator));
|
||||
m_engine.registerProperty("particle_emitter_linear_movement",
|
||||
LUMIX_NEW(allocator, Vec2PropertyDescriptor<RenderScene>)("z",
|
||||
&RenderScene::getParticleEmitterLinearMovementZ,
|
||||
&RenderScene::setParticleEmitterLinearMovementZ,
|
||||
allocator));
|
||||
|
||||
m_engine.registerProperty("particle_emitter",
|
||||
LUMIX_NEW(allocator, Vec2PropertyDescriptor<RenderScene>)("Life",
|
||||
&RenderScene::getParticleEmitterInitialLife,
|
||||
&RenderScene::setParticleEmitterInitialLife,
|
||||
allocator));
|
||||
m_engine.registerProperty("particle_emitter",
|
||||
LUMIX_NEW(allocator, Vec2PropertyDescriptor<RenderScene>)("Initial size",
|
||||
&RenderScene::getParticleEmitterInitialSize,
|
||||
&RenderScene::setParticleEmitterInitialSize,
|
||||
allocator));
|
||||
m_engine.registerProperty("particle_emitter",
|
||||
LUMIX_NEW(allocator, Vec2PropertyDescriptor<RenderScene>)("Spawn period",
|
||||
&RenderScene::getParticleEmitterSpawnPeriod,
|
||||
&RenderScene::setParticleEmitterSpawnPeriod,
|
||||
allocator));
|
||||
m_engine.registerProperty("particle_emitter",
|
||||
LUMIX_NEW(allocator, ResourcePropertyDescriptor<RenderScene>)("Material",
|
||||
&RenderScene::getParticleEmitterMaterialPath,
|
||||
&RenderScene::setParticleEmitterMaterialPath,
|
||||
"Material (*.mat)",
|
||||
Lumix::ResourceManager::MATERIAL,
|
||||
allocator));
|
||||
|
||||
m_engine.registerProperty("camera",
|
||||
LUMIX_NEW(allocator, StringPropertyDescriptor<RenderScene>)("Slot",
|
||||
&RenderScene::getCameraSlot,
|
||||
&RenderScene::setCameraSlot,
|
||||
allocator));
|
||||
m_engine.registerProperty("camera",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("FOV",
|
||||
&RenderScene::getCameraFOV,
|
||||
&RenderScene::setCameraFOV,
|
||||
1.0f,
|
||||
179.0f,
|
||||
1.0f,
|
||||
allocator));
|
||||
m_engine.registerProperty("camera",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Near",
|
||||
&RenderScene::getCameraNearPlane,
|
||||
&RenderScene::setCameraNearPlane,
|
||||
0.0f,
|
||||
FLT_MAX,
|
||||
0.0f,
|
||||
allocator));
|
||||
m_engine.registerProperty("camera",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Far",
|
||||
&RenderScene::getCameraFarPlane,
|
||||
&RenderScene::setCameraFarPlane,
|
||||
0.0f,
|
||||
FLT_MAX,
|
||||
0.0f,
|
||||
allocator));
|
||||
|
||||
m_engine.registerProperty("renderable",
|
||||
LUMIX_NEW(allocator, ResourcePropertyDescriptor<RenderScene>)("Source",
|
||||
&RenderScene::getRenderablePath,
|
||||
&RenderScene::setRenderablePath,
|
||||
"Mesh (*.msh)",
|
||||
Lumix::ResourceManager::MODEL,
|
||||
allocator));
|
||||
|
||||
m_engine.registerProperty("global_light",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Ambient intensity",
|
||||
&RenderScene::getLightAmbientIntensity,
|
||||
&RenderScene::setLightAmbientIntensity,
|
||||
0.0f,
|
||||
1.0f,
|
||||
0.05f,
|
||||
allocator));
|
||||
m_engine.registerProperty("global_light",
|
||||
LUMIX_NEW(allocator, Vec4PropertyDescriptor<RenderScene>)("Shadow cascades",
|
||||
&RenderScene::getShadowmapCascades,
|
||||
&RenderScene::setShadowmapCascades,
|
||||
allocator));
|
||||
|
||||
m_engine.registerProperty("global_light",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Diffuse intensity",
|
||||
&RenderScene::getGlobalLightIntensity,
|
||||
&RenderScene::setGlobalLightIntensity,
|
||||
0.0f,
|
||||
1.0f,
|
||||
0.05f,
|
||||
allocator));
|
||||
m_engine.registerProperty("global_light",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Fog density",
|
||||
&RenderScene::getFogDensity,
|
||||
&RenderScene::setFogDensity,
|
||||
0.0f,
|
||||
1.0f,
|
||||
0.01f,
|
||||
allocator));
|
||||
m_engine.registerProperty("global_light",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Fog bottom",
|
||||
&RenderScene::getFogBottom,
|
||||
&RenderScene::setFogBottom,
|
||||
-FLT_MAX,
|
||||
FLT_MAX,
|
||||
1.0f,
|
||||
allocator));
|
||||
m_engine.registerProperty("global_light",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Fog height",
|
||||
&RenderScene::getFogHeight,
|
||||
&RenderScene::setFogHeight,
|
||||
0.01f,
|
||||
FLT_MAX,
|
||||
1.0f,
|
||||
allocator));
|
||||
m_engine.registerProperty("global_light",
|
||||
LUMIX_NEW(allocator, ColorPropertyDescriptor<RenderScene>)("Ambient color",
|
||||
&RenderScene::getLightAmbientColor,
|
||||
&RenderScene::setLightAmbientColor,
|
||||
allocator));
|
||||
m_engine.registerProperty("global_light",
|
||||
LUMIX_NEW(allocator, ColorPropertyDescriptor<RenderScene>)("Diffuse color",
|
||||
&RenderScene::getGlobalLightColor,
|
||||
&RenderScene::setGlobalLightColor,
|
||||
allocator));
|
||||
m_engine.registerProperty("global_light",
|
||||
LUMIX_NEW(allocator, ColorPropertyDescriptor<RenderScene>)("Fog color",
|
||||
&RenderScene::getFogColor,
|
||||
&RenderScene::setFogColor,
|
||||
allocator));
|
||||
|
||||
m_engine.registerProperty("point_light",
|
||||
LUMIX_NEW(allocator, BoolPropertyDescriptor<RenderScene>)("Cast shadows",
|
||||
&RenderScene::getLightCastShadows,
|
||||
&RenderScene::setLightCastShadows,
|
||||
allocator));
|
||||
m_engine.registerProperty("point_light",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Diffuse intensity",
|
||||
&RenderScene::getPointLightIntensity,
|
||||
&RenderScene::setPointLightIntensity,
|
||||
0.0f,
|
||||
1.0f,
|
||||
0.05f,
|
||||
allocator));
|
||||
m_engine.registerProperty("point_light",
|
||||
LUMIX_NEW(allocator, ColorPropertyDescriptor<RenderScene>)("Diffuse color",
|
||||
&RenderScene::getPointLightColor,
|
||||
&RenderScene::setPointLightColor,
|
||||
allocator));
|
||||
m_engine.registerProperty("point_light",
|
||||
LUMIX_NEW(allocator, ColorPropertyDescriptor<RenderScene>)("Specular color",
|
||||
&RenderScene::getPointLightSpecularColor,
|
||||
&RenderScene::setPointLightSpecularColor,
|
||||
allocator));
|
||||
m_engine.registerProperty("point_light",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("FOV",
|
||||
&RenderScene::getLightFOV,
|
||||
&RenderScene::setLightFOV,
|
||||
0.0f,
|
||||
360.0f,
|
||||
5.0f,
|
||||
allocator));
|
||||
m_engine.registerProperty("point_light",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Attenuation",
|
||||
&RenderScene::getLightAttenuation,
|
||||
&RenderScene::setLightAttenuation,
|
||||
0.0f,
|
||||
1000.0f,
|
||||
0.1f,
|
||||
allocator));
|
||||
m_engine.registerProperty("point_light",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Range",
|
||||
&RenderScene::getLightRange,
|
||||
&RenderScene::setLightRange,
|
||||
0.0f,
|
||||
FLT_MAX,
|
||||
1.0f,
|
||||
allocator));
|
||||
m_engine.registerProperty("terrain",
|
||||
LUMIX_NEW(allocator, ResourcePropertyDescriptor<RenderScene>)("Material",
|
||||
&RenderScene::getTerrainMaterialPath,
|
||||
&RenderScene::setTerrainMaterialPath,
|
||||
"Material (*.mat)",
|
||||
Lumix::ResourceManager::MATERIAL,
|
||||
allocator));
|
||||
m_engine.registerProperty("terrain",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("XZ scale",
|
||||
&RenderScene::getTerrainXZScale,
|
||||
&RenderScene::setTerrainXZScale,
|
||||
0.0f,
|
||||
FLT_MAX,
|
||||
0.0f,
|
||||
allocator));
|
||||
m_engine.registerProperty("terrain",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Height scale",
|
||||
&RenderScene::getTerrainYScale,
|
||||
&RenderScene::setTerrainYScale,
|
||||
0.0f,
|
||||
FLT_MAX,
|
||||
0.0f,
|
||||
allocator));
|
||||
|
||||
m_engine.registerProperty("terrain",
|
||||
LUMIX_NEW(allocator, IntPropertyDescriptor<RenderScene>)("Grass distance",
|
||||
&RenderScene::getGrassDistance,
|
||||
&RenderScene::setGrassDistance,
|
||||
allocator));
|
||||
|
||||
auto grass = LUMIX_NEW(allocator, ArrayDescriptor<RenderScene>)("Grass",
|
||||
&RenderScene::getGrassCount,
|
||||
&RenderScene::addGrass,
|
||||
&RenderScene::removeGrass,
|
||||
allocator);
|
||||
grass->addChild(LUMIX_NEW(allocator, ResourceArrayObjectDescriptor<RenderScene>)("Mesh",
|
||||
&RenderScene::getGrassPath,
|
||||
&RenderScene::setGrassPath,
|
||||
"Mesh (*.msh)",
|
||||
crc32("model"),
|
||||
allocator));
|
||||
auto ground = LUMIX_NEW(allocator, IntArrayObjectDescriptor<RenderScene>)("Ground",
|
||||
&RenderScene::getGrassGround,
|
||||
&RenderScene::setGrassGround,
|
||||
allocator);
|
||||
ground->setLimit(0, 4);
|
||||
grass->addChild(ground);
|
||||
grass->addChild(LUMIX_NEW(allocator, IntArrayObjectDescriptor<RenderScene>)("Density",
|
||||
&RenderScene::getGrassDensity,
|
||||
&RenderScene::setGrassDensity,
|
||||
allocator));
|
||||
m_engine.registerProperty("terrain", grass);
|
||||
}
|
||||
|
||||
|
||||
virtual bool create() override { return true; }
|
||||
|
||||
|
||||
|
|
|
@ -181,6 +181,8 @@ Terrain::Terrain(Renderer& renderer, Entity entity, RenderScene& scene, IAllocat
|
|||
, m_material(nullptr)
|
||||
, m_root(nullptr)
|
||||
, m_detail_texture(nullptr)
|
||||
, m_heightmap(nullptr)
|
||||
, m_splatmap(nullptr)
|
||||
, m_width(0)
|
||||
, m_height(0)
|
||||
, m_layer_mask(1)
|
||||
|
@ -682,6 +684,8 @@ float Terrain::getHeight(float x, float z)
|
|||
|
||||
float Terrain::getHeight(int x, int z)
|
||||
{
|
||||
if (!m_heightmap) return 0;
|
||||
|
||||
int texture_x = x;
|
||||
int texture_y = z;
|
||||
Texture* t = m_heightmap;
|
||||
|
|
|
@ -152,6 +152,7 @@ public:
|
|||
if (ImGui::BeginChild("right", half_size, true))
|
||||
{
|
||||
ImGui::Text("Version 0.18. - News");
|
||||
ImGui::BulletText("Basic particle system");
|
||||
ImGui::Separator();
|
||||
ImGui::Text("Version 0.17. - News");
|
||||
ImGui::BulletText("Back button in the asset browser");
|
||||
|
@ -1103,6 +1104,9 @@ public:
|
|||
loadSettings();
|
||||
|
||||
if (!m_metadata.load()) Lumix::g_log_info.log("studio") << "Could not load metadata";
|
||||
|
||||
void registerProperties(Lumix::WorldEditor&);
|
||||
registerProperties(*m_editor);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#include "property_grid.h"
|
||||
#include "asset_browser.h"
|
||||
#include "core/crc32.h"
|
||||
#include "editor/property_descriptor.h"
|
||||
#include "editor/property_register.h"
|
||||
#include "editor/world_editor.h"
|
||||
#include "engine/engine.h"
|
||||
#include "engine/property_descriptor.h"
|
||||
#include "lua_script/lua_script_manager.h"
|
||||
#include "lua_script/lua_script_system.h"
|
||||
#include "ocornut-imgui/imgui.h"
|
||||
|
@ -14,12 +15,12 @@
|
|||
const char* PropertyGrid::getComponentTypeName(Lumix::ComponentUID cmp) const
|
||||
{
|
||||
auto& engine = m_editor.getEngine();
|
||||
for (int i = 0; i < engine.getComponentTypesCount(); ++i)
|
||||
for (int i = 0; i < Lumix::PropertyRegister::getComponentTypesCount(); ++i)
|
||||
{
|
||||
if (cmp.type ==
|
||||
Lumix::crc32(engine.getComponentTypeID(i)))
|
||||
Lumix::crc32(Lumix::PropertyRegister::getComponentTypeID(i)))
|
||||
{
|
||||
return engine.getComponentTypeName(i);
|
||||
return Lumix::PropertyRegister::getComponentTypeName(i);
|
||||
}
|
||||
}
|
||||
return "Unknown";
|
||||
|
@ -241,7 +242,7 @@ void PropertyGrid::showComponentProperties(Lumix::ComponentUID cmp)
|
|||
return;
|
||||
}
|
||||
|
||||
auto& descs = m_editor.getEngine().getPropertyDescriptors(cmp.type);
|
||||
auto& descs = Lumix::PropertyRegister::getDescriptors(cmp.type);
|
||||
|
||||
for (auto* desc : descs)
|
||||
{
|
||||
|
@ -417,15 +418,12 @@ void PropertyGrid::onGUI()
|
|||
}
|
||||
if (ImGui::BeginPopup("AddComponentPopup"))
|
||||
{
|
||||
for (int i = 0;
|
||||
i < m_editor.getEngine().getComponentTypesCount();
|
||||
++i)
|
||||
for (int i = 0; i < Lumix::PropertyRegister::getComponentTypesCount(); ++i)
|
||||
{
|
||||
if (ImGui::Selectable(
|
||||
m_editor.getEngine().getComponentTypeName(i)))
|
||||
if (ImGui::Selectable(Lumix::PropertyRegister::getComponentTypeName(i)))
|
||||
{
|
||||
m_editor.addComponent(Lumix::crc32(
|
||||
m_editor.getEngine().getComponentTypeID(i)));
|
||||
m_editor.addComponent(
|
||||
Lumix::crc32(Lumix::PropertyRegister::getComponentTypeID(i)));
|
||||
}
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
|
|
344
src/studio/register_properties.cpp
Normal file
344
src/studio/register_properties.cpp
Normal file
|
@ -0,0 +1,344 @@
|
|||
#include "editor/property_register.h"
|
||||
#include "core/resource_manager.h"
|
||||
#include "editor/property_descriptor.h"
|
||||
#include "editor/world_editor.h"
|
||||
#include "lua_script/lua_script_system.h"
|
||||
#include "physics/physics_scene.h"
|
||||
#include "renderer/render_scene.h"
|
||||
|
||||
|
||||
using namespace Lumix;
|
||||
|
||||
|
||||
void registerLuaScriptProperties(Lumix::IAllocator& allocator)
|
||||
{
|
||||
PropertyRegister::registerComponentType("lua_script", "Lua script");
|
||||
|
||||
Lumix::PropertyRegister::add("lua_script",
|
||||
LUMIX_NEW(allocator, ResourcePropertyDescriptor<LuaScriptScene>)("source",
|
||||
&LuaScriptScene::getScriptPath,
|
||||
&LuaScriptScene::setScriptPath,
|
||||
"Lua (*.lua)",
|
||||
crc32("lua_script"),
|
||||
allocator));
|
||||
}
|
||||
|
||||
|
||||
void registerPhysicsProperties(Lumix::IAllocator& allocator)
|
||||
{
|
||||
PropertyRegister::registerComponentType("box_rigid_actor", "Physics Box");
|
||||
PropertyRegister::registerComponentType("physical_controller",
|
||||
"Physics Controller");
|
||||
PropertyRegister::registerComponentType("mesh_rigid_actor", "Physics Mesh");
|
||||
PropertyRegister::registerComponentType("physical_heightfield",
|
||||
"Physics Heightfield");
|
||||
|
||||
Lumix::PropertyRegister::add("box_rigid_actor",
|
||||
LUMIX_NEW(allocator, BoolPropertyDescriptor<PhysicsScene>)("dynamic",
|
||||
&PhysicsScene::isDynamic,
|
||||
&PhysicsScene::setIsDynamic,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("box_rigid_actor",
|
||||
LUMIX_NEW(allocator, Vec3PropertyDescriptor<PhysicsScene>)("size",
|
||||
&PhysicsScene::getHalfExtents,
|
||||
&PhysicsScene::setHalfExtents,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("mesh_rigid_actor",
|
||||
LUMIX_NEW(allocator, FilePropertyDescriptor<PhysicsScene>)("source",
|
||||
&PhysicsScene::getShapeSource,
|
||||
&PhysicsScene::setShapeSource,
|
||||
"Physics (*.pda)",
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("physical_heightfield",
|
||||
LUMIX_NEW(allocator, ResourcePropertyDescriptor<PhysicsScene>)("heightmap",
|
||||
&PhysicsScene::getHeightmap,
|
||||
&PhysicsScene::setHeightmap,
|
||||
"Image (*.raw)",
|
||||
Lumix::ResourceManager::TEXTURE,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("physical_heightfield",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<PhysicsScene>)("xz_scale",
|
||||
&PhysicsScene::getHeightmapXZScale,
|
||||
&PhysicsScene::setHeightmapXZScale,
|
||||
0.0f,
|
||||
FLT_MAX,
|
||||
0.0f,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("physical_heightfield",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<PhysicsScene>)("y_scale",
|
||||
&PhysicsScene::getHeightmapYScale,
|
||||
&PhysicsScene::setHeightmapYScale,
|
||||
0.0f,
|
||||
FLT_MAX,
|
||||
0.0f,
|
||||
allocator));
|
||||
}
|
||||
|
||||
|
||||
void registerRendererProperties(Lumix::IAllocator& allocator)
|
||||
{
|
||||
PropertyRegister::registerComponentType("camera", "Camera");
|
||||
PropertyRegister::registerComponentType("global_light", "Global light");
|
||||
PropertyRegister::registerComponentType("renderable", "Mesh");
|
||||
PropertyRegister::registerComponentType("particle_emitter", "Particle emitter");
|
||||
PropertyRegister::registerComponentType("particle_emitter_fade", "Particle emitter - fade");
|
||||
PropertyRegister::registerComponentType(
|
||||
"particle_emitter_linear_movement", "Particle emitter - linear movement");
|
||||
PropertyRegister::registerComponentType(
|
||||
"particle_emitter_random_rotation", "Particle emitter - random rotation");
|
||||
PropertyRegister::registerComponentType("point_light", "Point light");
|
||||
PropertyRegister::registerComponentType("terrain", "Terrain");
|
||||
|
||||
PropertyRegister::registerComponentDependency("particle_emitter_fade", "particle_emitter");
|
||||
PropertyRegister::registerComponentDependency(
|
||||
"particle_emitter_linear_movement", "particle_emitter");
|
||||
PropertyRegister::registerComponentDependency(
|
||||
"particle_emitter_random_rotation", "particle_emitter");
|
||||
|
||||
Lumix::PropertyRegister::add("particle_emitter_linear_movement",
|
||||
LUMIX_NEW(allocator, Vec2PropertyDescriptor<RenderScene>)("x",
|
||||
&RenderScene::getParticleEmitterLinearMovementX,
|
||||
&RenderScene::setParticleEmitterLinearMovementX,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("particle_emitter_linear_movement",
|
||||
LUMIX_NEW(allocator, Vec2PropertyDescriptor<RenderScene>)("y",
|
||||
&RenderScene::getParticleEmitterLinearMovementY,
|
||||
&RenderScene::setParticleEmitterLinearMovementY,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("particle_emitter_linear_movement",
|
||||
LUMIX_NEW(allocator, Vec2PropertyDescriptor<RenderScene>)("z",
|
||||
&RenderScene::getParticleEmitterLinearMovementZ,
|
||||
&RenderScene::setParticleEmitterLinearMovementZ,
|
||||
allocator));
|
||||
|
||||
Lumix::PropertyRegister::add("particle_emitter",
|
||||
LUMIX_NEW(allocator, Vec2PropertyDescriptor<RenderScene>)("Life",
|
||||
&RenderScene::getParticleEmitterInitialLife,
|
||||
&RenderScene::setParticleEmitterInitialLife,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("particle_emitter",
|
||||
LUMIX_NEW(allocator, Vec2PropertyDescriptor<RenderScene>)("Initial size",
|
||||
&RenderScene::getParticleEmitterInitialSize,
|
||||
&RenderScene::setParticleEmitterInitialSize,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("particle_emitter",
|
||||
LUMIX_NEW(allocator, Vec2PropertyDescriptor<RenderScene>)("Spawn period",
|
||||
&RenderScene::getParticleEmitterSpawnPeriod,
|
||||
&RenderScene::setParticleEmitterSpawnPeriod,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("particle_emitter",
|
||||
LUMIX_NEW(allocator, ResourcePropertyDescriptor<RenderScene>)("Material",
|
||||
&RenderScene::getParticleEmitterMaterialPath,
|
||||
&RenderScene::setParticleEmitterMaterialPath,
|
||||
"Material (*.mat)",
|
||||
Lumix::ResourceManager::MATERIAL,
|
||||
allocator));
|
||||
|
||||
Lumix::PropertyRegister::add("camera",
|
||||
LUMIX_NEW(allocator, StringPropertyDescriptor<RenderScene>)("Slot",
|
||||
&RenderScene::getCameraSlot,
|
||||
&RenderScene::setCameraSlot,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("camera",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("FOV",
|
||||
&RenderScene::getCameraFOV,
|
||||
&RenderScene::setCameraFOV,
|
||||
1.0f,
|
||||
179.0f,
|
||||
1.0f,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("camera",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Near",
|
||||
&RenderScene::getCameraNearPlane,
|
||||
&RenderScene::setCameraNearPlane,
|
||||
0.0f,
|
||||
FLT_MAX,
|
||||
0.0f,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("camera",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Far",
|
||||
&RenderScene::getCameraFarPlane,
|
||||
&RenderScene::setCameraFarPlane,
|
||||
0.0f,
|
||||
FLT_MAX,
|
||||
0.0f,
|
||||
allocator));
|
||||
|
||||
Lumix::PropertyRegister::add("renderable",
|
||||
LUMIX_NEW(allocator, ResourcePropertyDescriptor<RenderScene>)("Source",
|
||||
&RenderScene::getRenderablePath,
|
||||
&RenderScene::setRenderablePath,
|
||||
"Mesh (*.msh)",
|
||||
Lumix::ResourceManager::MODEL,
|
||||
allocator));
|
||||
|
||||
Lumix::PropertyRegister::add("global_light",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Ambient intensity",
|
||||
&RenderScene::getLightAmbientIntensity,
|
||||
&RenderScene::setLightAmbientIntensity,
|
||||
0.0f,
|
||||
1.0f,
|
||||
0.05f,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("global_light",
|
||||
LUMIX_NEW(allocator, Vec4PropertyDescriptor<RenderScene>)("Shadow cascades",
|
||||
&RenderScene::getShadowmapCascades,
|
||||
&RenderScene::setShadowmapCascades,
|
||||
allocator));
|
||||
|
||||
Lumix::PropertyRegister::add("global_light",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Diffuse intensity",
|
||||
&RenderScene::getGlobalLightIntensity,
|
||||
&RenderScene::setGlobalLightIntensity,
|
||||
0.0f,
|
||||
1.0f,
|
||||
0.05f,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("global_light",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Fog density",
|
||||
&RenderScene::getFogDensity,
|
||||
&RenderScene::setFogDensity,
|
||||
0.0f,
|
||||
1.0f,
|
||||
0.01f,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("global_light",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Fog bottom",
|
||||
&RenderScene::getFogBottom,
|
||||
&RenderScene::setFogBottom,
|
||||
-FLT_MAX,
|
||||
FLT_MAX,
|
||||
1.0f,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("global_light",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Fog height",
|
||||
&RenderScene::getFogHeight,
|
||||
&RenderScene::setFogHeight,
|
||||
0.01f,
|
||||
FLT_MAX,
|
||||
1.0f,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("global_light",
|
||||
LUMIX_NEW(allocator, ColorPropertyDescriptor<RenderScene>)("Ambient color",
|
||||
&RenderScene::getLightAmbientColor,
|
||||
&RenderScene::setLightAmbientColor,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("global_light",
|
||||
LUMIX_NEW(allocator, ColorPropertyDescriptor<RenderScene>)("Diffuse color",
|
||||
&RenderScene::getGlobalLightColor,
|
||||
&RenderScene::setGlobalLightColor,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("global_light",
|
||||
LUMIX_NEW(allocator, ColorPropertyDescriptor<RenderScene>)("Fog color",
|
||||
&RenderScene::getFogColor,
|
||||
&RenderScene::setFogColor,
|
||||
allocator));
|
||||
|
||||
Lumix::PropertyRegister::add("point_light",
|
||||
LUMIX_NEW(allocator, BoolPropertyDescriptor<RenderScene>)("Cast shadows",
|
||||
&RenderScene::getLightCastShadows,
|
||||
&RenderScene::setLightCastShadows,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("point_light",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Diffuse intensity",
|
||||
&RenderScene::getPointLightIntensity,
|
||||
&RenderScene::setPointLightIntensity,
|
||||
0.0f,
|
||||
1.0f,
|
||||
0.05f,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("point_light",
|
||||
LUMIX_NEW(allocator, ColorPropertyDescriptor<RenderScene>)("Diffuse color",
|
||||
&RenderScene::getPointLightColor,
|
||||
&RenderScene::setPointLightColor,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("point_light",
|
||||
LUMIX_NEW(allocator, ColorPropertyDescriptor<RenderScene>)("Specular color",
|
||||
&RenderScene::getPointLightSpecularColor,
|
||||
&RenderScene::setPointLightSpecularColor,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("point_light",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("FOV",
|
||||
&RenderScene::getLightFOV,
|
||||
&RenderScene::setLightFOV,
|
||||
0.0f,
|
||||
360.0f,
|
||||
5.0f,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("point_light",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Attenuation",
|
||||
&RenderScene::getLightAttenuation,
|
||||
&RenderScene::setLightAttenuation,
|
||||
0.0f,
|
||||
1000.0f,
|
||||
0.1f,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("point_light",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Range",
|
||||
&RenderScene::getLightRange,
|
||||
&RenderScene::setLightRange,
|
||||
0.0f,
|
||||
FLT_MAX,
|
||||
1.0f,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("terrain",
|
||||
LUMIX_NEW(allocator, ResourcePropertyDescriptor<RenderScene>)("Material",
|
||||
&RenderScene::getTerrainMaterialPath,
|
||||
&RenderScene::setTerrainMaterialPath,
|
||||
"Material (*.mat)",
|
||||
Lumix::ResourceManager::MATERIAL,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("terrain",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("XZ scale",
|
||||
&RenderScene::getTerrainXZScale,
|
||||
&RenderScene::setTerrainXZScale,
|
||||
0.0f,
|
||||
FLT_MAX,
|
||||
0.0f,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("terrain",
|
||||
LUMIX_NEW(allocator, DecimalPropertyDescriptor<RenderScene>)("Height scale",
|
||||
&RenderScene::getTerrainYScale,
|
||||
&RenderScene::setTerrainYScale,
|
||||
0.0f,
|
||||
FLT_MAX,
|
||||
0.0f,
|
||||
allocator));
|
||||
|
||||
Lumix::PropertyRegister::add("terrain",
|
||||
LUMIX_NEW(allocator, IntPropertyDescriptor<RenderScene>)("Grass distance",
|
||||
&RenderScene::getGrassDistance,
|
||||
&RenderScene::setGrassDistance,
|
||||
allocator));
|
||||
|
||||
auto grass = LUMIX_NEW(allocator, ArrayDescriptor<RenderScene>)("Grass",
|
||||
&RenderScene::getGrassCount,
|
||||
&RenderScene::addGrass,
|
||||
&RenderScene::removeGrass,
|
||||
allocator);
|
||||
grass->addChild(LUMIX_NEW(allocator, ResourceArrayObjectDescriptor<RenderScene>)("Mesh",
|
||||
&RenderScene::getGrassPath,
|
||||
&RenderScene::setGrassPath,
|
||||
"Mesh (*.msh)",
|
||||
crc32("model"),
|
||||
allocator));
|
||||
auto ground = LUMIX_NEW(allocator, IntArrayObjectDescriptor<RenderScene>)("Ground",
|
||||
&RenderScene::getGrassGround,
|
||||
&RenderScene::setGrassGround,
|
||||
allocator);
|
||||
ground->setLimit(0, 4);
|
||||
grass->addChild(ground);
|
||||
grass->addChild(LUMIX_NEW(allocator, IntArrayObjectDescriptor<RenderScene>)("Density",
|
||||
&RenderScene::getGrassDensity,
|
||||
&RenderScene::setGrassDensity,
|
||||
allocator));
|
||||
Lumix::PropertyRegister::add("terrain", grass);
|
||||
}
|
||||
|
||||
|
||||
void registerProperties(Lumix::WorldEditor& editor)
|
||||
{
|
||||
registerRendererProperties(editor.getAllocator());
|
||||
registerLuaScriptProperties(editor.getAllocator());
|
||||
registerPhysicsProperties(editor.getAllocator());
|
||||
}
|
|
@ -9,8 +9,9 @@
|
|||
#include "core/system.h"
|
||||
#include "editor/entity_template_system.h"
|
||||
#include "editor/ieditor_command.h"
|
||||
#include "editor/property_descriptor.h"
|
||||
#include "editor/property_register.h"
|
||||
#include "engine.h"
|
||||
#include "engine/property_descriptor.h"
|
||||
#include "ocornut-imgui/imgui.h"
|
||||
#include "renderer/material.h"
|
||||
#include "renderer/model.h"
|
||||
|
@ -390,7 +391,7 @@ struct RemoveEntitiesCommand : public Lumix::IEditorCommand
|
|||
if (new_component.isValid()) break;
|
||||
}
|
||||
|
||||
auto& props = m_editor.getEngine().getPropertyDescriptors(cmp_type);
|
||||
auto& props = Lumix::PropertyRegister::getDescriptors(cmp_type);
|
||||
for (int k = 0; k < props.size(); ++k)
|
||||
{
|
||||
props[k]->set(new_component, blob);
|
||||
|
@ -470,7 +471,7 @@ struct RemoveEntitiesCommand : public Lumix::IEditorCommand
|
|||
for (const auto& cmp : cmps)
|
||||
{
|
||||
m_removed_entities.write(cmp.type);
|
||||
auto& props = m_editor.getEngine().getPropertyDescriptors(cmp.type);
|
||||
auto& props = Lumix::PropertyRegister::getDescriptors(cmp.type);
|
||||
for (int k = 0; k < props.size(); ++k)
|
||||
{
|
||||
props[k]->get(cmp, m_removed_entities);
|
||||
|
@ -1215,8 +1216,8 @@ void TerrainEditor::decreaseBrushSize()
|
|||
|
||||
|
||||
void TerrainEditor::drawCursor(Lumix::RenderScene& scene,
|
||||
const Lumix::ComponentUID& terrain,
|
||||
const Lumix::Vec3& center)
|
||||
const Lumix::ComponentUID& terrain,
|
||||
const Lumix::Vec3& center)
|
||||
{
|
||||
static const int SLICE_COUNT = 30;
|
||||
if (m_type == TerrainEditor::FLAT_HEIGHT && ImGui::GetIO().KeyCtrl)
|
||||
|
@ -1236,16 +1237,12 @@ void TerrainEditor::drawCursor(Lumix::RenderScene& scene,
|
|||
float angle_step = Lumix::Math::PI * 2 / SLICE_COUNT;
|
||||
float angle = i * angle_step;
|
||||
float next_angle = i * angle_step + angle_step;
|
||||
Lumix::Vec3 local_from =
|
||||
local_center + Lumix::Vec3(cos(angle), 0, sin(angle)) * brush_size;
|
||||
local_from.y =
|
||||
scene.getTerrainHeightAt(terrain.index, local_from.x, local_from.z);
|
||||
Lumix::Vec3 local_from = local_center + Lumix::Vec3(cos(angle), 0, sin(angle)) * brush_size;
|
||||
local_from.y = scene.getTerrainHeightAt(terrain.index, local_from.x, local_from.z);
|
||||
local_from.y += 0.25f;
|
||||
Lumix::Vec3 local_to =
|
||||
local_center +
|
||||
Lumix::Vec3(cos(next_angle), 0, sin(next_angle)) * brush_size;
|
||||
local_to.y =
|
||||
scene.getTerrainHeightAt(terrain.index, local_to.x, local_to.z);
|
||||
local_center + Lumix::Vec3(cos(next_angle), 0, sin(next_angle)) * brush_size;
|
||||
local_to.y = scene.getTerrainHeightAt(terrain.index, local_to.x, local_to.z);
|
||||
local_to.y += 0.25f;
|
||||
|
||||
Lumix::Vec3 from = terrain_matrix.multiplyPosition(local_from);
|
||||
|
@ -1267,11 +1264,9 @@ void TerrainEditor::drawCursor(Lumix::RenderScene& scene,
|
|||
float dz = local_center.z - local_pos.z;
|
||||
if (dx * dx + dz * dz < brush_size2)
|
||||
{
|
||||
local_pos.y = scene.getTerrainHeightAt(
|
||||
terrain.index, local_pos.x, local_pos.z);
|
||||
local_pos.y = scene.getTerrainHeightAt(terrain.index, local_pos.x, local_pos.z);
|
||||
local_pos.y += 0.05f;
|
||||
Lumix::Vec3 world_pos =
|
||||
terrain_matrix.multiplyPosition(local_pos);
|
||||
Lumix::Vec3 world_pos = terrain_matrix.multiplyPosition(local_pos);
|
||||
scene.addDebugPoint(world_pos, 0xffff0000, 0);
|
||||
}
|
||||
++local_pos.z;
|
||||
|
@ -1286,38 +1281,27 @@ void TerrainEditor::drawCursor(Lumix::RenderScene& scene,
|
|||
void TerrainEditor::tick()
|
||||
{
|
||||
if (!m_component.isValid()) return;
|
||||
if (m_type == NOT_SET) return;
|
||||
|
||||
float mouse_x = m_world_editor.getMouseX();
|
||||
float mouse_y = m_world_editor.getMouseY();
|
||||
|
||||
if (m_type != NOT_SET)
|
||||
for (auto entity : m_world_editor.getSelectedEntities())
|
||||
{
|
||||
for (int i = m_world_editor.getSelectedEntities().size() - 1; i >= 0;
|
||||
--i)
|
||||
Lumix::ComponentUID terrain = m_world_editor.getComponent(entity, TERRAIN_HASH);
|
||||
if (!terrain.isValid()) continue;
|
||||
|
||||
Lumix::ComponentUID camera_cmp = m_world_editor.getEditCamera();
|
||||
Lumix::RenderScene* scene = static_cast<Lumix::RenderScene*>(camera_cmp.scene);
|
||||
Lumix::Vec3 origin, dir;
|
||||
scene->getRay(camera_cmp.index, (float)mouse_x, (float)mouse_y, origin, dir);
|
||||
Lumix::RayCastModelHit hit = scene->castRay(origin, dir, Lumix::INVALID_COMPONENT);
|
||||
|
||||
if (hit.m_is_hit)
|
||||
{
|
||||
Lumix::ComponentUID terrain = m_world_editor.getComponent(
|
||||
m_world_editor.getSelectedEntities()[i],
|
||||
Lumix::crc32("terrain"));
|
||||
if (terrain.isValid())
|
||||
{
|
||||
Lumix::ComponentUID camera_cmp = m_world_editor.getEditCamera();
|
||||
Lumix::RenderScene* scene =
|
||||
static_cast<Lumix::RenderScene*>(camera_cmp.scene);
|
||||
Lumix::Vec3 origin, dir;
|
||||
scene->getRay(camera_cmp.index,
|
||||
(float)mouse_x,
|
||||
(float)mouse_y,
|
||||
origin,
|
||||
dir);
|
||||
Lumix::RayCastModelHit hit =
|
||||
scene->castRay(origin, dir, Lumix::INVALID_COMPONENT);
|
||||
if (hit.m_is_hit)
|
||||
{
|
||||
Lumix::Vec3 center = hit.m_origin + hit.m_dir * hit.m_t;
|
||||
drawCursor(*scene, terrain, center);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Lumix::Vec3 center = hit.m_origin + hit.m_dir * hit.m_t;
|
||||
drawCursor(*scene, terrain, center);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1516,6 +1500,11 @@ void TerrainEditor::onGUI()
|
|||
auto* scene = static_cast<Lumix::RenderScene*>(m_component.scene);
|
||||
if (!ImGui::CollapsingHeader("Terrain editor", nullptr, true, true)) return;
|
||||
|
||||
if (!getMaterial())
|
||||
{
|
||||
ImGui::Text("No heightmap");
|
||||
return;
|
||||
}
|
||||
ImGui::SliderFloat("Brush size", &m_terrain_brush_size, MIN_BRUSH_SIZE, 100);
|
||||
ImGui::SliderFloat("Brush strength", &m_terrain_brush_strength, 0, 1.0f);
|
||||
|
||||
|
|
Loading…
Reference in a new issue