mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-15 00:11:55 +07:00
added ability to use atlas with premultiplied alpha
This commit is contained in:
@@ -42,7 +42,7 @@ namespace e2d
|
||||
spine_model& assign(spine_model&& other) noexcept;
|
||||
spine_model& assign(const spine_model& other);
|
||||
|
||||
spine_model& set_atlas(atlas_ptr atlas);
|
||||
spine_model& set_atlas(atlas_ptr atlas, bool premultiplied_alpha);
|
||||
spine_model& set_skeleton(skeleton_data_ptr skeleton);
|
||||
|
||||
spine_model& set_default_mix(secf duration);
|
||||
@@ -54,10 +54,12 @@ namespace e2d
|
||||
const atlas_ptr& atlas() const noexcept;
|
||||
const skeleton_data_ptr& skeleton() const noexcept;
|
||||
const animation_data_ptr& animation() const noexcept;
|
||||
bool premultiplied_alpha() const noexcept;
|
||||
private:
|
||||
atlas_ptr atlas_;
|
||||
skeleton_data_ptr skeleton_;
|
||||
animation_data_ptr animation_;
|
||||
bool premultiplied_alpha_ = false;
|
||||
};
|
||||
|
||||
void swap(spine_model& l, spine_model& r) noexcept;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"atlas" : "coin/coin-pma.atlas",
|
||||
"premultiplied_alpha" : true,
|
||||
"skeleton" : "coin/coin-pro.skel",
|
||||
"skeleton_scale" : 1.0
|
||||
}
|
||||
|
||||
@@ -107,7 +107,6 @@ namespace
|
||||
.component<actor>(node::create(coin_i, scene_r))
|
||||
.component<renderer>(renderer()
|
||||
.materials({spine_mat}))
|
||||
.component<spine_renderer>(spine_renderer(spine_coin))
|
||||
.component<spine_player>(spine_player(spine_coin)
|
||||
.set_animation(0, "animation", true));
|
||||
|
||||
@@ -120,7 +119,6 @@ namespace
|
||||
.component<actor>(node::create(raptor_gobj_, scene_r))
|
||||
.component<renderer>(renderer()
|
||||
.materials({spine_mat}))
|
||||
.component<spine_renderer>(spine_renderer(spine_raptor))
|
||||
.component<spine_player>(spine_player(spine_raptor)
|
||||
.set_animation(0, "walk", true));
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace
|
||||
"additionalProperties" : false,
|
||||
"properties" : {
|
||||
"atlas" : { "$ref" : "#/common_definitions/address" },
|
||||
"premultiplied_alpha" : { "type" : "boolean" },
|
||||
"skeleton" : { "$ref" : "#/common_definitions/address" },
|
||||
"skeleton_scale" : { "type" : "number" },
|
||||
"default_animation_mix" : { "type" : "number" },
|
||||
@@ -279,6 +280,13 @@ namespace
|
||||
parse_animation_mix(mixes_json[i]));
|
||||
}
|
||||
}
|
||||
|
||||
bool pma = false;
|
||||
if ( root.HasMember("premultiplied_alpha") ) {
|
||||
if ( !json_utils::try_parse_value(root["premultiplied_alpha"], pma) ) {
|
||||
the<debug>().error("SPINE: Incorrect formating of 'premultiplied_alpha' property");
|
||||
}
|
||||
}
|
||||
|
||||
E2D_ASSERT(root.HasMember("atlas") && root["atlas"].IsString());
|
||||
const str atlas_address = root["atlas"].GetString();
|
||||
@@ -308,13 +316,14 @@ namespace
|
||||
})
|
||||
.then([
|
||||
default_animation_mix,
|
||||
animation_mixes = std::move(animation_mixes)
|
||||
animation_mixes = std::move(animation_mixes),
|
||||
pma
|
||||
](const std::tuple<
|
||||
spine_model::atlas_ptr,
|
||||
spine_model::skeleton_data_ptr
|
||||
>& results){
|
||||
spine_model content;
|
||||
content.set_atlas(std::get<0>(results));
|
||||
content.set_atlas(std::get<0>(results), pma);
|
||||
content.set_skeleton(std::get<1>(results));
|
||||
content.set_default_mix(default_animation_mix);
|
||||
for ( const animation_mix& mix : animation_mixes ) {
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace e2d
|
||||
void spine_model::swap(spine_model& other) noexcept {
|
||||
using std::swap;
|
||||
swap(atlas_, other.atlas_);
|
||||
swap(premultiplied_alpha_, other.premultiplied_alpha_);
|
||||
swap(skeleton_, other.skeleton_);
|
||||
swap(animation_, other.animation_);
|
||||
}
|
||||
@@ -51,6 +52,7 @@ namespace e2d
|
||||
if ( this != &other ) {
|
||||
spine_model m;
|
||||
m.atlas_ = other.atlas_;
|
||||
m.premultiplied_alpha_ = other.premultiplied_alpha_;
|
||||
m.skeleton_ = other.skeleton_;
|
||||
m.animation_ = other.animation_;
|
||||
swap(m);
|
||||
@@ -58,8 +60,9 @@ namespace e2d
|
||||
return *this;
|
||||
}
|
||||
|
||||
spine_model& spine_model::set_atlas(atlas_ptr atlas) {
|
||||
spine_model& spine_model::set_atlas(atlas_ptr atlas, bool premultiplied_alpha) {
|
||||
atlas_ = std::move(atlas);
|
||||
premultiplied_alpha_ = premultiplied_alpha;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -118,6 +121,10 @@ namespace e2d
|
||||
const spine_model::animation_data_ptr& spine_model::animation() const noexcept {
|
||||
return animation_;
|
||||
}
|
||||
|
||||
bool spine_model::premultiplied_alpha() const noexcept {
|
||||
return premultiplied_alpha_;
|
||||
}
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
|
||||
@@ -268,8 +268,7 @@ namespace e2d::render_system_impl
|
||||
spSkeletonClipping* clipper = spine_r.clipper().operator->();
|
||||
spVertexEffect* effect = spine_r.effect().operator->();
|
||||
const material_asset::ptr& src_mat = node_r.materials().front();
|
||||
//const bool use_premultiplied_alpha = spine_r.model()->content().premultiplied_alpha();
|
||||
const bool use_premultiplied_alpha = false; // TODO: pma is not supported
|
||||
const bool use_premultiplied_alpha = spine_r.model()->content().premultiplied_alpha();
|
||||
|
||||
if ( !skeleton || !clipper || !src_mat ) {
|
||||
return;
|
||||
@@ -351,10 +350,17 @@ namespace e2d::render_system_impl
|
||||
continue;
|
||||
}
|
||||
|
||||
const color32 vert_color(
|
||||
color vert_colorf =
|
||||
color(skeleton->color.r, skeleton->color.g, skeleton->color.b, skeleton->color.a) *
|
||||
color(slot->color.r, slot->color.g, slot->color.b, slot->color.a) *
|
||||
color(attachment_color->r, attachment_color->g, attachment_color->b, attachment_color->a));
|
||||
color(attachment_color->r, attachment_color->g, attachment_color->b, attachment_color->a);
|
||||
|
||||
if ( use_premultiplied_alpha ) {
|
||||
vert_colorf.r *= vert_colorf.a;
|
||||
vert_colorf.g *= vert_colorf.a;
|
||||
vert_colorf.b *= vert_colorf.a;
|
||||
}
|
||||
const color32 vert_color(vert_colorf);
|
||||
|
||||
render::blending_state blend_mode;
|
||||
switch ( slot->data->blendMode ) {
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <enduro2d/high/systems/spine_system.hpp>
|
||||
|
||||
#include <enduro2d/high/components/spine_player.hpp>
|
||||
#include <enduro2d/high/components/spine_renderer.hpp>
|
||||
|
||||
#include <spine/AnimationState.h>
|
||||
#include <spine/Skeleton.h>
|
||||
|
||||
Reference in New Issue
Block a user