mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-14 16:09:06 +07:00
Merge branch 'feature/remove_3d' into feature/input_event_system
This commit is contained in:
@@ -17,6 +17,18 @@ namespace e2d
|
||||
public:
|
||||
renderer() = default;
|
||||
|
||||
renderer& transform(const t3f& transform) noexcept;
|
||||
[[nodiscard]] const t3f& transform() const noexcept;
|
||||
|
||||
renderer& translation(const v3f& translation) noexcept;
|
||||
[[nodiscard]] const v3f& translation() const noexcept;
|
||||
|
||||
renderer& rotation(const q4f& rotation) noexcept;
|
||||
[[nodiscard]] const q4f& rotation() const noexcept;
|
||||
|
||||
renderer& scale(const v3f& scale) noexcept;
|
||||
[[nodiscard]] const v3f& scale() const noexcept;
|
||||
|
||||
renderer& properties(render::property_block&& value) noexcept;
|
||||
renderer& properties(const render::property_block& value);
|
||||
|
||||
@@ -29,6 +41,7 @@ namespace e2d
|
||||
[[nodiscard]] vector<material_asset::ptr>& materials() noexcept;
|
||||
[[nodiscard]] const vector<material_asset::ptr>& materials() const noexcept;
|
||||
private:
|
||||
t3f transform_ = t3f::identity();
|
||||
render::property_block properties_;
|
||||
vector<material_asset::ptr> materials_;
|
||||
};
|
||||
@@ -50,6 +63,42 @@ namespace e2d
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
inline renderer& renderer::transform(const t3f& transform) noexcept {
|
||||
transform_ = transform;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline const t3f& renderer::transform() const noexcept {
|
||||
return transform_;
|
||||
}
|
||||
|
||||
inline renderer& renderer::translation(const v3f& translation) noexcept {
|
||||
transform_.translation = translation;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline const v3f& renderer::translation() const noexcept {
|
||||
return transform_.translation;
|
||||
}
|
||||
|
||||
inline renderer& renderer::rotation(const q4f& rotation) noexcept {
|
||||
transform_.rotation = rotation;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline const q4f& renderer::rotation() const noexcept {
|
||||
return transform_.rotation;
|
||||
}
|
||||
|
||||
inline renderer& renderer::scale(const v3f& scale) noexcept {
|
||||
transform_.scale = scale;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline const v3f& renderer::scale() const noexcept {
|
||||
return transform_.scale;
|
||||
}
|
||||
|
||||
inline renderer& renderer::properties(render::property_block&& value) noexcept {
|
||||
properties_ = std::move(value);
|
||||
return *this;
|
||||
|
||||
@@ -30,31 +30,31 @@ namespace e2d
|
||||
virtual ~node() noexcept;
|
||||
|
||||
static node_iptr create();
|
||||
static node_iptr create(const t3f& transform);
|
||||
static node_iptr create(const t2f& transform);
|
||||
|
||||
static node_iptr create(const node_iptr& parent);
|
||||
static node_iptr create(const node_iptr& parent, const t3f& transform);
|
||||
static node_iptr create(const node_iptr& parent, const t2f& transform);
|
||||
|
||||
static node_iptr create(gobject owner);
|
||||
static node_iptr create(gobject owner, const t3f& transform);
|
||||
static node_iptr create(gobject owner, const t2f& transform);
|
||||
|
||||
static node_iptr create(gobject owner, const node_iptr& parent);
|
||||
static node_iptr create(gobject owner, const node_iptr& parent, const t3f& transform);
|
||||
static node_iptr create(gobject owner, const node_iptr& parent, const t2f& transform);
|
||||
|
||||
void owner(gobject owner) noexcept;
|
||||
gobject owner() const noexcept;
|
||||
|
||||
void transform(const t3f& transform) noexcept;
|
||||
const t3f& transform() const noexcept;
|
||||
void transform(const t2f& transform) noexcept;
|
||||
const t2f& transform() const noexcept;
|
||||
|
||||
void translation(const v3f& translation) noexcept;
|
||||
const v3f& translation() const noexcept;
|
||||
void translation(const v2f& translation) noexcept;
|
||||
const v2f& translation() const noexcept;
|
||||
|
||||
void rotation(const q4f& rotation) noexcept;
|
||||
const q4f& rotation() const noexcept;
|
||||
void rotation(const radf& rotation) noexcept;
|
||||
const radf& rotation() const noexcept;
|
||||
|
||||
void scale(const v3f& scale) noexcept;
|
||||
const v3f& scale() const noexcept;
|
||||
void scale(const v2f& scale) noexcept;
|
||||
const v2f& scale() const noexcept;
|
||||
|
||||
const m4f& local_matrix() const noexcept;
|
||||
const m4f& world_matrix() const noexcept;
|
||||
@@ -145,7 +145,7 @@ namespace e2d
|
||||
void update_local_matrix_() const noexcept;
|
||||
void update_world_matrix_() const noexcept;
|
||||
private:
|
||||
t3f transform_;
|
||||
t2f transform_;
|
||||
gobject owner_;
|
||||
node* parent_{nullptr};
|
||||
node_children children_;
|
||||
|
||||
@@ -28,8 +28,8 @@ namespace e2d
|
||||
gobject instantiate(const node_iptr& parent);
|
||||
gobject instantiate(const prefab& prefab, const node_iptr& parent);
|
||||
|
||||
gobject instantiate(const node_iptr& parent, const t3f& transform);
|
||||
gobject instantiate(const prefab& prefab, const node_iptr& parent, const t3f& transform);
|
||||
gobject instantiate(const node_iptr& parent, const t2f& transform);
|
||||
gobject instantiate(const prefab& prefab, const node_iptr& parent, const t2f& transform);
|
||||
|
||||
void destroy_instance(gobject& inst) noexcept;
|
||||
void finalize_instances() noexcept;
|
||||
|
||||
@@ -134,6 +134,58 @@ namespace e2d::json_utils
|
||||
try_parse_value(const rapidjson::Value& root, unit<T, Tag>& v) noexcept {
|
||||
return try_parse_value(root, v.value);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
bool try_parse_value(const rapidjson::Value& root, trs2<T>& t) noexcept {
|
||||
trs2<T> tt = trs2<T>::identity();
|
||||
|
||||
if ( root.HasMember("translation") ) {
|
||||
if ( !try_parse_value(root["translation"], tt.translation) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( root.HasMember("rotation") ) {
|
||||
if ( !try_parse_value(root["rotation"], tt.rotation) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( root.HasMember("scale") ) {
|
||||
if ( !try_parse_value(root["scale"], tt.scale) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
t = tt;
|
||||
return true;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
bool try_parse_value(const rapidjson::Value& root, trs3<T>& t) noexcept {
|
||||
trs3<T> tt = trs3<T>::identity();
|
||||
|
||||
if ( root.HasMember("translation") ) {
|
||||
if ( !try_parse_value(root["translation"], tt.translation) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( root.HasMember("rotation") ) {
|
||||
if ( !try_parse_value(root["rotation"], tt.rotation) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( root.HasMember("scale") ) {
|
||||
if ( !try_parse_value(root["scale"], tt.scale) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
t = tt;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
namespace e2d::json_utils
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"prototype" : "../prefabs/gnome_prefab.json",
|
||||
"components" : {
|
||||
"actor" : {
|
||||
"translation" : [0,0,0],
|
||||
"translation" : [0,0],
|
||||
"scale" : 20
|
||||
},
|
||||
"behaviour" : {
|
||||
@@ -28,7 +28,7 @@
|
||||
"outline_color" : [0,0,0,255]
|
||||
},
|
||||
"actor" : {
|
||||
"translation" : [-315,-235,0],
|
||||
"translation" : [-315,-235],
|
||||
"scale" : 1
|
||||
},
|
||||
"behaviour" : {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"prototype" : "../prefabs/gnome_prefab.json",
|
||||
"components" : {
|
||||
"actor" : {
|
||||
"translation" : [0,0,0],
|
||||
"translation" : [0,0],
|
||||
"scale" : 20
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@
|
||||
"blending" : "additive"
|
||||
},
|
||||
"actor" : {
|
||||
"translation" : [-50,-50,0]
|
||||
"translation" : [-50,-50]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@@ -29,7 +29,7 @@
|
||||
"tint" : [255,0,0,255]
|
||||
},
|
||||
"actor" : {
|
||||
"translation" : [50,-50,0]
|
||||
"translation" : [50,-50]
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@@ -42,7 +42,7 @@
|
||||
"outline_color" : [0,0,0,255]
|
||||
},
|
||||
"actor" : {
|
||||
"translation" : [0,180,0],
|
||||
"translation" : [0,180],
|
||||
"scale" : 3
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@
|
||||
"outline_color" : [0,0,0,255]
|
||||
},
|
||||
"actor" : {
|
||||
"translation" : [0.5,-180.5,0],
|
||||
"translation" : [0.5,-180.5],
|
||||
"scale" : 3
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"prototype" : "../prefabs/coin_prefab.json",
|
||||
"components" : {
|
||||
"actor" : {
|
||||
"translation" : [350,250,0],
|
||||
"translation" : [350,250],
|
||||
"scale" : 0.25
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
"prototype" : "../prefabs/raptor_prefab.json",
|
||||
"components" : {
|
||||
"actor" : {
|
||||
"translation" : [300,-350,0],
|
||||
"translation" : [300,-350],
|
||||
"scale" : 0.25
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@
|
||||
"prototype" : "../prefabs/dragon_prefab.json",
|
||||
"components" : {
|
||||
"actor" : {
|
||||
"translation" : [-100,0,0],
|
||||
"translation" : [-100,0],
|
||||
"scale" : 0.9
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,19 @@ local renderer = {
|
||||
enabled = true,
|
||||
|
||||
---@type boolean
|
||||
disabled = false
|
||||
disabled = false,
|
||||
|
||||
---@type t3f
|
||||
transform = t3f.identity(),
|
||||
|
||||
---@type v3f
|
||||
translation = v3f.zero(),
|
||||
|
||||
---@type q4f
|
||||
rotation = q4f.identity(),
|
||||
|
||||
---@type v3f
|
||||
scale = v3f.unit()
|
||||
}
|
||||
|
||||
---@overload fun(self: renderer)
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
---@class node
|
||||
local node = {
|
||||
---@type t3f
|
||||
transform = t3f.identity(),
|
||||
---@type gobject
|
||||
owner = nil,
|
||||
|
||||
---@type v3f
|
||||
translation = v3f.zero(),
|
||||
---@type t2f
|
||||
transform = t2f.identity(),
|
||||
|
||||
---@type q4f
|
||||
rotation = q4f.identity(),
|
||||
---@type v2f
|
||||
translation = v2f.zero(),
|
||||
|
||||
---@type v3f
|
||||
scale = v3f.unit(),
|
||||
---@type number
|
||||
rotation = 0,
|
||||
|
||||
---@type v2f
|
||||
scale = v2f.unit(),
|
||||
|
||||
---@type m4f
|
||||
local_matrix = m4f.identity(),
|
||||
|
||||
@@ -4,7 +4,7 @@ local world = {
|
||||
|
||||
---@overload fun(prefab: prefab): gobject
|
||||
---@overload fun(prefab: prefab, parent: node): gobject
|
||||
---@overload fun(prefab: prefab, parent: node, transform: t3f): gobject
|
||||
---@overload fun(prefab: prefab, parent: node, transform: t2f): gobject
|
||||
---@return gobject
|
||||
function world:instantiate(...) end
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ end
|
||||
---@param go gobject
|
||||
local function update_gnome_rotation(meta, go)
|
||||
local time = the_engine.time
|
||||
go.actor.node.rotation = q4f.make_from_euler_angles(0, time, 0)
|
||||
go.renderer.rotation = q4f.make_from_euler_angles(0, time, 0)
|
||||
end
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
|
||||
@@ -9,7 +9,10 @@ using namespace e2d;
|
||||
|
||||
namespace
|
||||
{
|
||||
struct rotator {
|
||||
struct node_rotator {
|
||||
};
|
||||
|
||||
struct renderer_rotator {
|
||||
v3f axis;
|
||||
};
|
||||
|
||||
@@ -61,14 +64,21 @@ namespace
|
||||
ecs::registry& owner,
|
||||
const systems::update_event& event) override
|
||||
{
|
||||
owner.for_joined_components<rotator, actor>(
|
||||
[&event](const ecs::const_entity&, const rotator& rot, actor& act){
|
||||
owner.for_joined_components<node_rotator, actor>(
|
||||
[&event](const ecs::const_entity&, const node_rotator&, actor& act){
|
||||
const node_iptr node = act.node();
|
||||
if ( node ) {
|
||||
const q4f q = math::make_quat_from_axis_angle(make_rad(event.time), rot.axis);
|
||||
node->rotation(q);
|
||||
node->rotation(make_rad(event.time));
|
||||
}
|
||||
});
|
||||
|
||||
owner.for_joined_components<renderer_rotator, renderer>(
|
||||
[&event](const ecs::const_entity&, const renderer_rotator& rot, renderer& r){
|
||||
const q4f q = math::make_quat_from_axis_angle(
|
||||
make_rad(event.time),
|
||||
rot.axis);
|
||||
r.rotation(q);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -97,20 +107,20 @@ namespace
|
||||
{
|
||||
prefab prefab;
|
||||
prefab.prototype()
|
||||
.component<rotator>(rotator{v3f::unit_y()})
|
||||
.component<renderer_rotator>(v3f::unit_y())
|
||||
.component<renderer>(renderer().materials({model_mat}))
|
||||
.component<model_renderer>(model_res);
|
||||
|
||||
the<world>().instantiate(
|
||||
prefab,
|
||||
scene_i.component<actor>()->node(),
|
||||
make_trs3(v3f{0,50.f,0}, q4f::identity(), v3f{20.f}));
|
||||
make_trs2(v2f{0,50.f}, radf::zero(), v2f{20.f}));
|
||||
}
|
||||
|
||||
{
|
||||
prefab prefab;
|
||||
prefab.prototype()
|
||||
.component<rotator>(rotator{v3f::unit_z()})
|
||||
.component<node_rotator>()
|
||||
.component<renderer>()
|
||||
.component<sprite_renderer>(sprite_renderer(sprite_res)
|
||||
.materials({{"normal", sprite_mat}}));
|
||||
@@ -118,13 +128,13 @@ namespace
|
||||
the<world>().instantiate(
|
||||
prefab,
|
||||
scene_i.component<actor>()->node(),
|
||||
math::make_translation_trs3(v3f{0,-50.f,0}));
|
||||
math::make_translation_trs2(v2f{0,-50.f}));
|
||||
}
|
||||
|
||||
{
|
||||
prefab prefab_a;
|
||||
prefab_a.prototype()
|
||||
.component<rotator>(rotator{v3f::unit_z()})
|
||||
.component<node_rotator>()
|
||||
.component<renderer>()
|
||||
.component<sprite_renderer>(sprite_renderer()
|
||||
.filtering(false)
|
||||
@@ -135,10 +145,10 @@ namespace
|
||||
|
||||
for ( std::size_t i = 0; i < 2; ++i )
|
||||
for ( std::size_t j = 0; j < 5; ++j ) {
|
||||
t3f trans{
|
||||
{-80.f + j * 40.f, -200.f + i * 40.f, 0},
|
||||
q4f::identity(),
|
||||
{2.f,2.f,1.f}};
|
||||
t2f trans{
|
||||
{-80.f + j * 40.f, -200.f + i * 40.f},
|
||||
radf::zero(),
|
||||
{2.f,2.f}};
|
||||
gobject inst = the<world>().instantiate(
|
||||
prefab_a,
|
||||
scene_i.component<actor>()->node(),
|
||||
@@ -146,11 +156,11 @@ namespace
|
||||
|
||||
prefab prefab_b = prefab_a;
|
||||
prefab_b.prototype()
|
||||
.component<rotator>(rotator{v3f::unit_z()})
|
||||
.component<actor>(node::create(make_trs3(
|
||||
v3f{20.f,0.f,0.f},
|
||||
q4f::identity(),
|
||||
v3f{0.3f,0.3f,3.f})));
|
||||
.component<node_rotator>()
|
||||
.component<actor>(node::create(make_trs2(
|
||||
v2f{20.f,0.f},
|
||||
radf::zero(),
|
||||
v2f{0.3f,0.3f})));
|
||||
|
||||
the<world>().instantiate(
|
||||
prefab_b,
|
||||
|
||||
@@ -48,7 +48,23 @@ namespace e2d::bindings::high
|
||||
c.owner().component<disabled<renderer>>().remove();
|
||||
}
|
||||
}
|
||||
)
|
||||
),
|
||||
|
||||
"transform", sol::property(
|
||||
[](const gcomponent<renderer>& c) -> t3f { return c->transform(); },
|
||||
[](gcomponent<renderer>& c, const t3f& v) { c->transform(v); }),
|
||||
|
||||
"translation", sol::property(
|
||||
[](const gcomponent<renderer>& c) -> v3f { return c->translation(); },
|
||||
[](gcomponent<renderer>& c, const v3f& v) { c->translation(v); }),
|
||||
|
||||
"rotation", sol::property(
|
||||
[](const gcomponent<renderer>& c) -> q4f { return c->rotation(); },
|
||||
[](gcomponent<renderer>& c, const q4f& v) { c->rotation(v); }),
|
||||
|
||||
"scale", sol::property(
|
||||
[](const gcomponent<renderer>& c) -> v3f { return c->scale(); },
|
||||
[](gcomponent<renderer>& c, const v3f& v) { c->scale(v); })
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,25 +15,23 @@ namespace e2d::bindings::high
|
||||
sol::no_constructor,
|
||||
|
||||
"owner", sol::property(
|
||||
[](const node& n) -> gobject {
|
||||
return n.owner();
|
||||
}),
|
||||
[](const node& n) -> gobject { return n.owner(); }),
|
||||
|
||||
"transform", sol::property(
|
||||
[](const node& n) -> t3f { return n.transform(); },
|
||||
sol::resolve<void(const t3f&)>(&node::transform)),
|
||||
[](const node& n) -> t2f { return n.transform(); },
|
||||
[](node& n, const t2f& v) { n.transform(v); }),
|
||||
|
||||
"translation", sol::property(
|
||||
[](const node& n) -> v3f { return n.translation(); },
|
||||
sol::resolve<void(const v3f&)>(&node::translation)),
|
||||
[](const node& n) -> v2f { return n.translation(); },
|
||||
[](node& n, const v2f& v) { n.translation(v); }),
|
||||
|
||||
"rotation", sol::property(
|
||||
[](const node& n) -> q4f { return n.rotation(); },
|
||||
sol::resolve<void(const q4f&)>(&node::rotation)),
|
||||
[](const node& n) -> f32 { return n.rotation().value; },
|
||||
[](node& n, f32 v) { n.rotation(make_rad(v)); }),
|
||||
|
||||
"scale", sol::property(
|
||||
[](const node& n) -> v3f { return n.scale(); },
|
||||
sol::resolve<void(const v3f&)>(&node::scale)),
|
||||
[](const node& n) -> v2f { return n.scale(); },
|
||||
[](node& n, const v2f& v) { n.scale(v); }),
|
||||
|
||||
"local_matrix", sol::property(
|
||||
[](const node& n) -> m4f { return n.local_matrix(); }),
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace e2d::bindings::high
|
||||
[](world& w, const prefab& prefab, const node_iptr& parent) -> gobject {
|
||||
return w.instantiate(prefab, parent);
|
||||
},
|
||||
[](world& w, const prefab& prefab, const node_iptr& parent, const t3f& transform) -> gobject {
|
||||
[](world& w, const prefab& prefab, const node_iptr& parent, const t2f& transform) -> gobject {
|
||||
return w.instantiate(prefab, parent, transform);
|
||||
}
|
||||
)
|
||||
|
||||
@@ -13,9 +13,9 @@ namespace e2d
|
||||
"required" : [],
|
||||
"additionalProperties" : false,
|
||||
"properties" : {
|
||||
"translation" : { "$ref": "#/common_definitions/v3" },
|
||||
"rotation" : { "$ref": "#/common_definitions/q4" },
|
||||
"scale" : { "$ref": "#/common_definitions/v3" }
|
||||
"translation" : { "$ref": "#/common_definitions/v2" },
|
||||
"rotation" : { "type" : "number" },
|
||||
"scale" : { "$ref": "#/common_definitions/v2" }
|
||||
}
|
||||
})json";
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace e2d
|
||||
}
|
||||
|
||||
if ( ctx.root.HasMember("translation") ) {
|
||||
auto translation = component.node()->translation();
|
||||
v2f translation = component.node()->translation();
|
||||
if ( !json_utils::try_parse_value(ctx.root["translation"], translation) ) {
|
||||
the<debug>().error("ACTOR: Incorrect formatting of 'translation' property");
|
||||
return false;
|
||||
@@ -37,7 +37,7 @@ namespace e2d
|
||||
}
|
||||
|
||||
if ( ctx.root.HasMember("rotation") ) {
|
||||
auto rotation = component.node()->rotation();
|
||||
radf rotation = component.node()->rotation();
|
||||
if ( !json_utils::try_parse_value(ctx.root["rotation"], rotation) ) {
|
||||
the<debug>().error("ACTOR: Incorrect formatting of 'rotation' property");
|
||||
return false;
|
||||
@@ -46,7 +46,7 @@ namespace e2d
|
||||
}
|
||||
|
||||
if ( ctx.root.HasMember("scale") ) {
|
||||
auto scale = component.node()->scale();
|
||||
v2f scale = component.node()->scale();
|
||||
if ( !json_utils::try_parse_value(ctx.root["scale"], scale) ) {
|
||||
the<debug>().error("ACTOR: Incorrect formatting of 'scale' property");
|
||||
return false;
|
||||
|
||||
@@ -13,6 +13,10 @@ namespace e2d
|
||||
"required" : [],
|
||||
"additionalProperties" : false,
|
||||
"properties" : {
|
||||
"transform" : { "$ref": "#/common_definitions/t3" },
|
||||
"materials" : { "$ref": "#/definitions/materials" }
|
||||
},
|
||||
"definitions" : {
|
||||
"materials" : {
|
||||
"type" : "array",
|
||||
"items" : { "$ref": "#/common_definitions/address" }
|
||||
@@ -24,6 +28,15 @@ namespace e2d
|
||||
renderer& component,
|
||||
const fill_context& ctx) const
|
||||
{
|
||||
if ( ctx.root.HasMember("transform") ) {
|
||||
t3f transform = component.transform();
|
||||
if ( !json_utils::try_parse_value(ctx.root["transform"], transform) ) {
|
||||
the<debug>().error("RENDERER: Incorrect formatting of 'transform' property");
|
||||
return false;
|
||||
}
|
||||
component.transform(transform);
|
||||
}
|
||||
|
||||
if ( ctx.root.HasMember("properties") ) {
|
||||
//TODO(BlackMat): add properties parsing
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace e2d
|
||||
"required" : [],
|
||||
"additionalProperties" : false,
|
||||
"properties" : {
|
||||
"depth" : { "type" : "number" }
|
||||
"depth" : { "type" : "integer" }
|
||||
}
|
||||
})json";
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace e2d
|
||||
const fill_context& ctx) const
|
||||
{
|
||||
if ( ctx.root.HasMember("depth") ) {
|
||||
auto depth = component.depth();
|
||||
i32 depth = component.depth();
|
||||
if ( !json_utils::try_parse_value(ctx.root["depth"], depth) ) {
|
||||
the<debug>().error("SCENE: Incorrect formatting of 'depth' property");
|
||||
return false;
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace e2d
|
||||
return node_iptr(new node());
|
||||
}
|
||||
|
||||
node_iptr node::create(const t3f& transform) {
|
||||
node_iptr node::create(const t2f& transform) {
|
||||
node_iptr n = create();
|
||||
n->transform(transform);
|
||||
return n;
|
||||
@@ -35,7 +35,7 @@ namespace e2d
|
||||
return child;
|
||||
}
|
||||
|
||||
node_iptr node::create(const node_iptr& parent, const t3f& transform) {
|
||||
node_iptr node::create(const node_iptr& parent, const t2f& transform) {
|
||||
node_iptr n = create(parent);
|
||||
n->transform(transform);
|
||||
return n;
|
||||
@@ -45,7 +45,7 @@ namespace e2d
|
||||
return node_iptr(new node(std::move(owner)));
|
||||
}
|
||||
|
||||
node_iptr node::create(gobject owner, const t3f& transform) {
|
||||
node_iptr node::create(gobject owner, const t2f& transform) {
|
||||
node_iptr n = create(owner);
|
||||
n->transform(transform);
|
||||
return n;
|
||||
@@ -59,7 +59,7 @@ namespace e2d
|
||||
return child;
|
||||
}
|
||||
|
||||
node_iptr node::create(gobject owner, const node_iptr& parent, const t3f& transform) {
|
||||
node_iptr node::create(gobject owner, const node_iptr& parent, const t2f& transform) {
|
||||
node_iptr n = create(owner, parent);
|
||||
n->transform(transform);
|
||||
return n;
|
||||
@@ -73,39 +73,39 @@ namespace e2d
|
||||
return owner_;
|
||||
}
|
||||
|
||||
void node::transform(const t3f& transform) noexcept {
|
||||
void node::transform(const t2f& transform) noexcept {
|
||||
transform_ = transform;
|
||||
mark_dirty_local_matrix_();
|
||||
}
|
||||
|
||||
const t3f& node::transform() const noexcept {
|
||||
const t2f& node::transform() const noexcept {
|
||||
return transform_;
|
||||
}
|
||||
|
||||
void node::translation(const v3f& translation) noexcept {
|
||||
void node::translation(const v2f& translation) noexcept {
|
||||
transform_.translation = translation;
|
||||
mark_dirty_local_matrix_();
|
||||
}
|
||||
|
||||
const v3f& node::translation() const noexcept {
|
||||
const v2f& node::translation() const noexcept {
|
||||
return transform_.translation;
|
||||
}
|
||||
|
||||
void node::rotation(const q4f& rotation) noexcept {
|
||||
void node::rotation(const radf& rotation) noexcept {
|
||||
transform_.rotation = rotation;
|
||||
mark_dirty_local_matrix_();
|
||||
}
|
||||
|
||||
const q4f& node::rotation() const noexcept {
|
||||
const radf& node::rotation() const noexcept {
|
||||
return transform_.rotation;
|
||||
}
|
||||
|
||||
void node::scale(const v3f& scale) noexcept {
|
||||
void node::scale(const v2f& scale) noexcept {
|
||||
transform_.scale = scale;
|
||||
mark_dirty_local_matrix_();
|
||||
}
|
||||
|
||||
const v3f& node::scale() const noexcept {
|
||||
const v2f& node::scale() const noexcept {
|
||||
return transform_.scale;
|
||||
}
|
||||
|
||||
|
||||
@@ -92,16 +92,20 @@ namespace e2d::render_system_impl
|
||||
return;
|
||||
}
|
||||
|
||||
const m4f& model_m =
|
||||
math::make_trs_matrix4(node_r->transform()) *
|
||||
node->world_matrix();
|
||||
|
||||
if ( auto mdl_r = gcomponent<model_renderer>{owner} ) {
|
||||
draw(node, *node_r, *mdl_r);
|
||||
draw(model_m, *node_r, *mdl_r);
|
||||
}
|
||||
|
||||
if ( auto spn_p = gcomponent<spine_player>{owner} ) {
|
||||
draw(node, *node_r, *spn_p);
|
||||
draw(model_m, *node_r, *spn_p);
|
||||
}
|
||||
|
||||
if ( auto spr_r = gcomponent<sprite_renderer>{owner} ) {
|
||||
draw(node, *node_r, *spr_r);
|
||||
draw(model_m, *node_r, *spr_r);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +114,7 @@ namespace e2d::render_system_impl
|
||||
}
|
||||
|
||||
void drawer::context::draw(
|
||||
const const_node_iptr& node,
|
||||
const m4f& model_m,
|
||||
const renderer& node_r,
|
||||
const model_renderer& mdl_r)
|
||||
{
|
||||
@@ -124,7 +128,7 @@ namespace e2d::render_system_impl
|
||||
try {
|
||||
property_cache_
|
||||
.merge(batcher_.flush())
|
||||
.property(matrix_m_property_hash, node->world_matrix())
|
||||
.property(matrix_m_property_hash, model_m)
|
||||
.merge(node_r.properties());
|
||||
|
||||
const std::size_t submesh_count = math::min(
|
||||
@@ -151,7 +155,7 @@ namespace e2d::render_system_impl
|
||||
}
|
||||
|
||||
void drawer::context::draw(
|
||||
const const_node_iptr& node,
|
||||
const m4f& model_m,
|
||||
const renderer& node_r,
|
||||
const spine_player& spine_r)
|
||||
{
|
||||
@@ -175,7 +179,6 @@ namespace e2d::render_system_impl
|
||||
material_asset::ptr multiply_mat_a;
|
||||
material_asset::ptr screen_mat_a;
|
||||
|
||||
const m4f& sm = node->world_matrix();
|
||||
unsigned short quad_indices[6] = { 0, 1, 2, 2, 3, 0 };
|
||||
|
||||
for ( int i = 0; i < skeleton->slotsCount; ++i ) {
|
||||
@@ -399,7 +402,7 @@ namespace e2d::render_system_impl
|
||||
|
||||
for ( std::size_t j = 0; j < batch_vertex_count; ++j ) {
|
||||
batcher_type::vertex_type& vert = batch_vertices[j];
|
||||
vert.v = v3f(v4f(vertices[j * 2], vertices[j * 2 + 1], 0.f, 1.f) * sm);
|
||||
vert.v = v3f(v4f(vertices[j * 2], vertices[j * 2 + 1], 0.f, 1.f) * model_m);
|
||||
vert.t = v2f(uvs[j * 2], uvs[j * 2 + 1]);
|
||||
vert.c = vert_color;
|
||||
}
|
||||
@@ -431,7 +434,7 @@ namespace e2d::render_system_impl
|
||||
}
|
||||
|
||||
void drawer::context::draw(
|
||||
const const_node_iptr& node,
|
||||
const m4f& model_m,
|
||||
const renderer& node_r,
|
||||
const sprite_renderer& spr_r)
|
||||
{
|
||||
@@ -467,17 +470,16 @@ namespace e2d::render_system_impl
|
||||
const f32 tw = tex_r.size.x / tex_s.x;
|
||||
const f32 th = tex_r.size.y / tex_s.y;
|
||||
|
||||
const m4f& sm = node->world_matrix();
|
||||
const color32& tc = spr_r.tint();
|
||||
|
||||
const batcher_type::index_type indices[] = {
|
||||
0u, 1u, 2u, 2u, 3u, 0u};
|
||||
|
||||
const batcher_type::vertex_type vertices[] = {
|
||||
{ v3f(p1 * sm), {tx + 0.f, ty + 0.f}, tc },
|
||||
{ v3f(p2 * sm), {tx + tw, ty + 0.f}, tc },
|
||||
{ v3f(p3 * sm), {tx + tw, ty + th }, tc },
|
||||
{ v3f(p4 * sm), {tx + 0.f, ty + th }, tc }};
|
||||
{ v3f(p1 * model_m), {tx + 0.f, ty + 0.f}, tc },
|
||||
{ v3f(p2 * model_m), {tx + tw, ty + 0.f}, tc },
|
||||
{ v3f(p3 * model_m), {tx + tw, ty + th }, tc },
|
||||
{ v3f(p4 * model_m), {tx + 0.f, ty + th }, tc }};
|
||||
|
||||
const render::sampler_min_filter tex_min_f = spr_r.filtering()
|
||||
? render::sampler_min_filter::linear
|
||||
|
||||
@@ -44,17 +44,17 @@ namespace e2d::render_system_impl
|
||||
void flush();
|
||||
private:
|
||||
void draw(
|
||||
const const_node_iptr& node,
|
||||
const m4f& model_m,
|
||||
const renderer& node_r,
|
||||
const model_renderer& mdl_r);
|
||||
|
||||
void draw(
|
||||
const const_node_iptr& node,
|
||||
const m4f& model_m,
|
||||
const renderer& node_r,
|
||||
const sprite_renderer& spr_r);
|
||||
|
||||
void draw(
|
||||
const const_node_iptr& node,
|
||||
const m4f& model_m,
|
||||
const renderer& node_r,
|
||||
const spine_player& spine_r);
|
||||
private:
|
||||
|
||||
@@ -211,11 +211,11 @@ namespace e2d
|
||||
return inst;
|
||||
}
|
||||
|
||||
gobject world::instantiate(const node_iptr& parent, const t3f& transform) {
|
||||
gobject world::instantiate(const node_iptr& parent, const t2f& transform) {
|
||||
return instantiate(prefab(), parent, transform);
|
||||
}
|
||||
|
||||
gobject world::instantiate(const prefab& prefab, const node_iptr& parent, const t3f& transform) {
|
||||
gobject world::instantiate(const prefab& prefab, const node_iptr& parent, const t2f& transform) {
|
||||
gobject inst = new_instance(*this, prefab);
|
||||
inst.component<actor>()->node()->transform(transform);
|
||||
|
||||
|
||||
@@ -192,6 +192,24 @@ namespace
|
||||
}
|
||||
}]
|
||||
},
|
||||
"t2" : {
|
||||
"type" : "object",
|
||||
"additionalProperties" : false,
|
||||
"properties" : {
|
||||
"translation" : { "$ref": "#/common_definitions/v2" },
|
||||
"rotation" : { "type" : "number" },
|
||||
"scale" : { "$ref": "#/common_definitions/v2" }
|
||||
}
|
||||
},
|
||||
"t3" : {
|
||||
"type" : "object",
|
||||
"additionalProperties" : false,
|
||||
"properties" : {
|
||||
"translation" : { "$ref": "#/common_definitions/v3" },
|
||||
"rotation" : { "$ref": "#/common_definitions/q4" },
|
||||
"scale" : { "$ref": "#/common_definitions/v3" }
|
||||
}
|
||||
},
|
||||
"color" : {
|
||||
"anyOf" : [{
|
||||
"type" : "number"
|
||||
|
||||
@@ -655,82 +655,82 @@ TEST_CASE("node") {
|
||||
SECTION("transform") {
|
||||
auto p = node::create();
|
||||
|
||||
REQUIRE(p->transform() == t3f::identity());
|
||||
REQUIRE(p->translation() == v3f::zero());
|
||||
REQUIRE(p->rotation() == q4f::identity());
|
||||
REQUIRE(p->scale() == v3f::unit());
|
||||
REQUIRE(p->transform() == t2f::identity());
|
||||
REQUIRE(p->translation() == v2f::zero());
|
||||
REQUIRE(p->rotation() == radf::zero());
|
||||
REQUIRE(p->scale() == v2f::unit());
|
||||
|
||||
p->translation(v3f(1,2,3));
|
||||
REQUIRE(p->translation() == v3f(1,2,3));
|
||||
p->translation(v2f(1,2));
|
||||
REQUIRE(p->translation() == v2f(1,2));
|
||||
|
||||
p->rotation(q4f(1,2,3,4));
|
||||
REQUIRE(p->rotation() == q4f(1,2,3,4));
|
||||
p->rotation(radf(1.f));
|
||||
REQUIRE(p->rotation() == radf(1.f));
|
||||
|
||||
p->scale(v3f(1,2,3));
|
||||
REQUIRE(p->scale() == v3f(1,2,3));
|
||||
p->scale(v2f(1,2));
|
||||
REQUIRE(p->scale() == v2f(1,2));
|
||||
}
|
||||
SECTION("local_matrix") {
|
||||
{
|
||||
auto p = node::create();
|
||||
p->transform(math::make_translation_trs3(v3f{10.f,0.f,0.f}));
|
||||
p->transform(math::make_translation_trs2(v2f{10.f,0.f}));
|
||||
|
||||
auto n = node::create(p);
|
||||
n->transform(math::make_translation_trs3(v3f{20.f,0.f,0.f}));
|
||||
REQUIRE(n->local_matrix() == math::make_translation_matrix4(20.f,0.f,0.f));
|
||||
n->transform(math::make_translation_trs2(v2f{20.f,0.f}));
|
||||
REQUIRE(n->local_matrix() == math::make_translation_matrix4(20.f,0.f));
|
||||
|
||||
auto v = v4f(5.f,0.f,0.f,1.f);
|
||||
REQUIRE(v * n->local_matrix() == v4f{25.f,0.f,0.f,1.f});
|
||||
|
||||
n->transform(math::make_scale_trs3(v3f(1.f,2.f,3.f)));
|
||||
REQUIRE(n->local_matrix() == math::make_scale_matrix4(1.f,2.f,3.f));
|
||||
n->transform(math::make_scale_trs2(v2f(1.f,2.f)));
|
||||
REQUIRE(n->local_matrix() == math::make_scale_matrix4(1.f,2.f));
|
||||
}
|
||||
}
|
||||
SECTION("world_matrix") {
|
||||
{
|
||||
auto p = node::create();
|
||||
p->translation({10.f,0.f,0.f});
|
||||
p->translation({10.f,0.f});
|
||||
|
||||
auto n = node::create(p);
|
||||
n->translation({20.f,0.f,0.f});
|
||||
n->translation({20.f,0.f});
|
||||
|
||||
auto v = v4f(5.f,0.f,0.f,1.f);
|
||||
REQUIRE(v * n->world_matrix() == v4f{35.f,0.f,0.f,1.f});
|
||||
|
||||
n->transform(math::make_scale_trs3(v3f(1.f,2.f,3.f)));
|
||||
n->transform(math::make_scale_trs2(v2f(1.f,2.f)));
|
||||
REQUIRE(n->world_matrix() ==
|
||||
math::make_scale_matrix4(1.f,2.f,3.f) *
|
||||
math::make_translation_matrix4(10.f,0.f,0.f));
|
||||
math::make_scale_matrix4(1.f,2.f) *
|
||||
math::make_translation_matrix4(10.f,0.f));
|
||||
}
|
||||
{
|
||||
auto n = node::create();
|
||||
n->translation({20.f,0.f,0.f});
|
||||
n->translation({20.f,0.f});
|
||||
REQUIRE(n->world_matrix() ==
|
||||
math::make_translation_matrix4(20.f,0.f,0.f));
|
||||
math::make_translation_matrix4(20.f,0.f));
|
||||
|
||||
auto p = node::create();
|
||||
p->transform(math::make_translation_trs3(v3f{10.f,0.f,0.f}));
|
||||
p->transform(math::make_translation_trs2(v2f{10.f,0.f}));
|
||||
|
||||
p->add_child(n);
|
||||
REQUIRE(n->world_matrix() ==
|
||||
math::make_translation_matrix4(30.f,0.f,0.f));
|
||||
math::make_translation_matrix4(30.f,0.f));
|
||||
}
|
||||
{
|
||||
auto p1 = node::create();
|
||||
p1->translation({10.f,0.f,0.f});
|
||||
p1->translation({10.f,0.f});
|
||||
|
||||
auto p2 = node::create();
|
||||
p2->transform(math::make_translation_trs3(v3f{20.f,0.f,0.f}));
|
||||
p2->transform(math::make_translation_trs2(v2f{20.f,0.f}));
|
||||
|
||||
auto n = node::create(p2);
|
||||
n->transform(math::make_translation_trs3(v3f{30.f,0.f,0.f}));
|
||||
n->transform(math::make_translation_trs2(v2f{30.f,0.f}));
|
||||
|
||||
REQUIRE(n->world_matrix() ==
|
||||
math::make_translation_matrix4(50.f,0.f,0.f));
|
||||
math::make_translation_matrix4(50.f,0.f));
|
||||
|
||||
p1->add_child(p2);
|
||||
|
||||
REQUIRE(n->world_matrix() ==
|
||||
math::make_translation_matrix4(60.f,0.f,0.f));
|
||||
math::make_translation_matrix4(60.f,0.f));
|
||||
}
|
||||
}
|
||||
SECTION("lifetime") {
|
||||
|
||||
@@ -62,6 +62,18 @@ namespace
|
||||
"b3_4" : [1,2,3,4,5,6],
|
||||
"b3_5" : [1,2,3,4,5,6,7],
|
||||
|
||||
"t2" : {
|
||||
"translation" : [1,2],
|
||||
"rotation" : 3,
|
||||
"scale" : [4,5]
|
||||
},
|
||||
|
||||
"t3" : {
|
||||
"translation" : [1,2,3],
|
||||
"rotation" : [4,5,6,7],
|
||||
"scale" : [8,9,10]
|
||||
},
|
||||
|
||||
"c0" : 0.5,
|
||||
"c1" : { "r" : 0.1, "b" : 0.2 },
|
||||
"c2" : { "r" : 0.1, "g" : 0.2, "b" : 0.3, "a" : 0.4 },
|
||||
@@ -189,6 +201,15 @@ TEST_CASE("json_utils") {
|
||||
REQUIRE_FALSE(json_utils::try_parse_value(doc["s2"], s3));
|
||||
REQUIRE_FALSE(json_utils::try_parse_value(doc["s2"], s4));
|
||||
}
|
||||
{
|
||||
t2f t2;
|
||||
REQUIRE(json_utils::try_parse_value(doc["t2"], t2));
|
||||
REQUIRE(t2 == make_trs2(v2f(1,2), radf(3), v2f(4,5)));
|
||||
|
||||
t3f t3;
|
||||
REQUIRE(json_utils::try_parse_value(doc["t3"], t3));
|
||||
REQUIRE(t3 == make_trs3(v3f(1,2,3), q4f(4,5,6,7), v3f(8,9,10)));
|
||||
}
|
||||
{
|
||||
color c0, c1, c2;
|
||||
REQUIRE(json_utils::try_parse_value(doc["c0"], c0));
|
||||
|
||||
Reference in New Issue
Block a user