color properties in lua
This commit is contained in:
parent
f7b83ee2ca
commit
e277bc38ac
6 changed files with 71 additions and 6 deletions
|
@ -3,12 +3,12 @@ height_distribution_rayleigh = 8000
|
|||
height_distribution_mie = 1200
|
||||
ground_r = 6378
|
||||
atmo_r = 6478
|
||||
local scatter_rayleigh = { 5.802 / 33.1, 13.558 / 33.1, 33.1 / 33.1 }
|
||||
local scatter_mie = { 1, 1, 1 }
|
||||
local absorb_mie = {1, 1, 1 }
|
||||
--Editor.setPropertyType(this, "scatter_rayleigh", Editor.COLOR_PROPERTY)
|
||||
--Editor.setPropertyType(this, "scatter_mie", Editor.COLOR_PROPERTY)
|
||||
--Editor.setPropertyType(this, "absorb_mie", Editor.COLOR_PROPERTY)
|
||||
scatter_rayleigh = { 5.802 / 33.1, 13.558 / 33.1, 33.1 / 33.1 }
|
||||
scatter_mie = { 1, 1, 1 }
|
||||
absorb_mie = {1, 1, 1 }
|
||||
Editor.setPropertyType(this, "scatter_rayleigh", Editor.COLOR_PROPERTY)
|
||||
Editor.setPropertyType(this, "scatter_mie", Editor.COLOR_PROPERTY)
|
||||
Editor.setPropertyType(this, "absorb_mie", Editor.COLOR_PROPERTY)
|
||||
|
||||
function postprocess(env, transparent_phase, hdr_buffer, gbuffer0, gbuffer1, gbuffer_depth, shadowmap)
|
||||
if not enabled then return hdr_buffer end
|
||||
|
|
|
@ -137,6 +137,32 @@ struct GridUIVisitor final : Reflection::IPropertyVisitor
|
|||
case Reflection::IDynamicProperties::ENTITY: dynamicProperty<EntityPtr>(cmp, prop, i); break;
|
||||
case Reflection::IDynamicProperties::I32: dynamicProperty<i32>(cmp, prop, i); break;
|
||||
case Reflection::IDynamicProperties::STRING: dynamicProperty<const char*>(cmp, prop, i); break;
|
||||
case Reflection::IDynamicProperties::COLOR: {
|
||||
struct : Reflection::Property<Vec3> {
|
||||
Span<const Reflection::IAttribute* const> getAttributes() const override {
|
||||
return Span((const Reflection::IAttribute*const*)attrs, 1);
|
||||
}
|
||||
|
||||
Vec3 get(ComponentUID cmp, int array_index) const override {
|
||||
return Reflection::get<Vec3>(prop->getValue(cmp, array_index, index));
|
||||
}
|
||||
void set(ComponentUID cmp, int array_index, Vec3 value) const override {
|
||||
Reflection::IDynamicProperties::Value v;
|
||||
Reflection::set(v, value);
|
||||
prop->set(cmp, array_index, index, v);
|
||||
}
|
||||
const Reflection::IDynamicProperties* prop;
|
||||
ComponentUID cmp;
|
||||
int index;
|
||||
Reflection::ColorAttribute attr;
|
||||
Reflection::IAttribute* attrs[1] = { &attr };
|
||||
} p;
|
||||
p.name = prop.getName(cmp, m_index, i);
|
||||
p.prop = ∝
|
||||
p.index = i;
|
||||
visit(p);
|
||||
break;
|
||||
}
|
||||
case Reflection::IDynamicProperties::RESOURCE: {
|
||||
struct : Reflection::Property<Path> {
|
||||
Span<const Reflection::IAttribute* const> getAttributes() const override {
|
||||
|
|
|
@ -1105,6 +1105,7 @@ public:
|
|||
static void set(Ref<Reflection::IDynamicProperties::Value> v, const char* val) { Reflection::set(v.value, val); }
|
||||
static void set(Ref<Reflection::IDynamicProperties::Value> v, EntityPtr val) { Reflection::set(v.value, val); }
|
||||
static void set(Ref<Reflection::IDynamicProperties::Value> v, bool val) { Reflection::set(v.value, val); }
|
||||
static void set(Ref<Reflection::IDynamicProperties::Value> v, Vec3 val) { Reflection::set(v.value, val); }
|
||||
static void set(Ref<Reflection::IDynamicProperties::Value> v, const String& val) { Reflection::set(v.value, val.c_str()); }
|
||||
|
||||
|
||||
|
|
|
@ -150,6 +150,7 @@ struct IDynamicProperties {
|
|||
ENTITY,
|
||||
RESOURCE,
|
||||
BOOLEAN,
|
||||
COLOR,
|
||||
|
||||
NONE
|
||||
};
|
||||
|
@ -160,6 +161,7 @@ struct IDynamicProperties {
|
|||
float f;
|
||||
const char* s;
|
||||
bool b;
|
||||
Vec3 v3;
|
||||
};
|
||||
virtual u32 getCount(ComponentUID cmp, int array_idx) const = 0;
|
||||
virtual Type getType(ComponentUID cmp, int array_idx, u32 idx) const = 0;
|
||||
|
@ -178,6 +180,7 @@ template <> inline i32 get(IDynamicProperties::Value v) { return v.i; }
|
|||
template <> inline const char* get(IDynamicProperties::Value v) { return v.s; }
|
||||
template <> inline EntityPtr get(IDynamicProperties::Value v) { return v.e; }
|
||||
template <> inline bool get(IDynamicProperties::Value v) { return v.b; }
|
||||
template <> inline Vec3 get(IDynamicProperties::Value v) { return v.v3; }
|
||||
|
||||
template <typename T> inline void set(IDynamicProperties::Value& v, T);
|
||||
template <> inline void set(IDynamicProperties::Value& v, float val) { v.f = val; }
|
||||
|
@ -185,6 +188,7 @@ template <> inline void set(IDynamicProperties::Value& v, i32 val) { v.i = val;
|
|||
template <> inline void set(IDynamicProperties::Value& v, const char* val) { v.s = val; }
|
||||
template <> inline void set(IDynamicProperties::Value& v, EntityPtr val) { v.e = val; }
|
||||
template <> inline void set(IDynamicProperties::Value& v, bool val) { v.b = val; }
|
||||
template <> inline void set(IDynamicProperties::Value& v, Vec3 val) { v.v3 = val; }
|
||||
|
||||
struct IArrayProperty
|
||||
{
|
||||
|
|
|
@ -42,6 +42,15 @@ namespace Lumix
|
|||
template <> const char* fromString(const char* val) { return val; }
|
||||
template <> float fromString(const char* val) { return (float)atof(val); }
|
||||
template <> bool fromString(const char* val) { return equalIStrings(val, "true"); }
|
||||
template <> Vec3 fromString(const char* val) {
|
||||
Vec3 r;
|
||||
r.x = (float)atof(val + 1);
|
||||
const char* c = strstr(val + 1, ",");
|
||||
r.y = (float)atof(c + 1);
|
||||
c = strstr(val + 1, ",");
|
||||
r.z = (float)atof(c + 1);
|
||||
return r;
|
||||
}
|
||||
|
||||
template <typename T> static void toString(T val, Ref<String> out) {
|
||||
char tmp[128];
|
||||
|
@ -55,6 +64,11 @@ namespace Lumix
|
|||
out = tmp;
|
||||
}
|
||||
|
||||
template <> void toString(Vec3 val, Ref<String> out) {
|
||||
StaticString<512> tmp("{", val.x, ", ", val.y, ", ", val.z, "}");
|
||||
out = tmp;
|
||||
}
|
||||
|
||||
struct LuaScriptManager final : ResourceManager
|
||||
{
|
||||
LuaScriptManager(IAllocator& allocator)
|
||||
|
@ -532,6 +546,7 @@ namespace Lumix
|
|||
LuaWrapper::createSystemVariable(L, "Editor", "INT_PROPERTY", Property::INT);
|
||||
LuaWrapper::createSystemVariable(L, "Editor", "ENTITY_PROPERTY", Property::ENTITY);
|
||||
LuaWrapper::createSystemVariable(L, "Editor", "RESOURCE_PROPERTY", Property::RESOURCE);
|
||||
LuaWrapper::createSystemVariable(L, "Editor", "COLOR_PROPERTY", Property::COLOR);
|
||||
}
|
||||
|
||||
static int rescan(lua_State* L) {
|
||||
|
@ -1098,6 +1113,11 @@ namespace Lumix
|
|||
applyProperty(script, prop, tmp);
|
||||
}
|
||||
|
||||
void applyProperty(ScriptInstance& script, Property& prop, Vec3 value) {
|
||||
const StaticString<512> tmp("{", value.x, ",", value.y, ",", value.z, "}");
|
||||
applyProperty(script, prop, tmp.data);
|
||||
}
|
||||
|
||||
void applyProperty(ScriptInstance& script, Property& prop, char* value) {
|
||||
applyProperty(script, prop, (const char*)value);
|
||||
}
|
||||
|
@ -1118,6 +1138,8 @@ namespace Lumix
|
|||
return;
|
||||
}
|
||||
|
||||
if (prop.type != Property::STRING && prop.type != Property::RESOURCE && value[0] == '\0') return;
|
||||
|
||||
if (prop.type == Property::ENTITY)
|
||||
{
|
||||
applyEntityProperty(script, name, prop, value);
|
||||
|
@ -1477,6 +1499,13 @@ namespace Lumix
|
|||
toCString(val, out, 8);
|
||||
}
|
||||
break;
|
||||
case Property::COLOR:
|
||||
{
|
||||
const Vec3 val = LuaWrapper::toType<Vec3>(scr.m_state, -1);
|
||||
const StaticString<512> tmp("{", val.x, ",", val.y, ",", val.z, "}");
|
||||
copyString(out, tmp.data);
|
||||
}
|
||||
break;
|
||||
case Property::INT:
|
||||
{
|
||||
int val = (int )lua_tointeger(scr.m_state, -1);
|
||||
|
@ -2082,6 +2111,7 @@ namespace Lumix
|
|||
case LuaScriptScene::Property::Type::STRING: return STRING;
|
||||
case LuaScriptScene::Property::Type::ENTITY: return ENTITY;
|
||||
case LuaScriptScene::Property::Type::RESOURCE: return RESOURCE;
|
||||
case LuaScriptScene::Property::Type::COLOR: return COLOR;
|
||||
default: ASSERT(false); return NONE;
|
||||
}
|
||||
}
|
||||
|
@ -2111,6 +2141,7 @@ namespace Lumix
|
|||
const char* name = scene.getPropertyName(e, array_idx, idx);
|
||||
Value v = {};
|
||||
switch(type) {
|
||||
case LuaScriptScene::Property::Type::COLOR: Reflection::set(v, scene.getPropertyValue<Vec3>(e, array_idx, name)); break;
|
||||
case LuaScriptScene::Property::Type::BOOLEAN: Reflection::set(v, scene.getPropertyValue<bool>(e, array_idx, name)); break;
|
||||
case LuaScriptScene::Property::Type::INT: Reflection::set(v, scene.getPropertyValue<i32>(e, array_idx, name)); break;
|
||||
case LuaScriptScene::Property::Type::FLOAT: Reflection::set(v, scene.getPropertyValue<float>(e, array_idx, name)); break;
|
||||
|
@ -2142,6 +2173,7 @@ namespace Lumix
|
|||
case STRING: scene.setPropertyValue(e, array_idx, name, v.s); break;
|
||||
case ENTITY: scene.setPropertyValue(e, array_idx, name, v.e); break;
|
||||
case RESOURCE: scene.setPropertyValue(e, array_idx, name, v.s); break;
|
||||
case COLOR: scene.setPropertyValue(e, array_idx, name, v.v3); break;
|
||||
default: ASSERT(false); break;
|
||||
}
|
||||
}
|
||||
|
@ -2158,6 +2190,7 @@ namespace Lumix
|
|||
case LuaScriptScene::Property::Type::STRING: scene.setPropertyValue(e, array_idx, name, v.s); break;
|
||||
case LuaScriptScene::Property::Type::ENTITY: scene.setPropertyValue(e, array_idx, name, v.e); break;
|
||||
case LuaScriptScene::Property::Type::RESOURCE: scene.setPropertyValue(e, array_idx, name, v.s); break;
|
||||
case LuaScriptScene::Property::Type::COLOR: scene.setPropertyValue(e, array_idx, name, v.v3); break;
|
||||
default: ASSERT(false); break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ struct LuaScriptScene : IScene
|
|||
ENTITY,
|
||||
RESOURCE,
|
||||
STRING,
|
||||
COLOR,
|
||||
ANY
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue