/****************************************************************************** * Spine Runtimes License Agreement * Last updated January 1, 2020. Replaces all prior versions. * * Copyright (c) 2013-2020, Esoteric Software LLC * * Integration of the Spine Runtimes into software or otherwise creating * derivative works of the Spine Runtimes is permitted under the terms and * conditions of Section 2 of the Spine Editor License Agreement: * http://esotericsoftware.com/spine-editor-license * * Otherwise, it is permitted to integrate the Spine Runtimes into software * or otherwise create derivative works of the Spine Runtimes (collectively, * "Products"), provided that each user of the Products must obtain their own * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ #include "SpineSprite.h" #include "SpineEvent.h" #include "SpineTrackEntry.h" void SpineSprite::_bind_methods() { ClassDB::bind_method(D_METHOD("set_animation_state_data_res", "animation_state_data_res"), &SpineSprite::set_animation_state_data_res); ClassDB::bind_method(D_METHOD("get_animation_state_data_res"), &SpineSprite::get_animation_state_data_res); ClassDB::bind_method(D_METHOD("_on_animation_data_created"), &SpineSprite::_on_animation_data_created); ClassDB::bind_method(D_METHOD("get_skeleton"), &SpineSprite::get_skeleton); ClassDB::bind_method(D_METHOD("get_animation_state"), &SpineSprite::get_animation_state); ClassDB::bind_method(D_METHOD("_on_animation_data_changed"), &SpineSprite::_on_animation_data_changed); ClassDB::bind_method(D_METHOD("get_bind_slot_nodes"), &SpineSprite::get_bind_slot_nodes); ClassDB::bind_method(D_METHOD("set_bind_slot_nodes", "v"), &SpineSprite::set_bind_slot_nodes); ClassDB::bind_method(D_METHOD("get_overlap"), &SpineSprite::get_overlap); ClassDB::bind_method(D_METHOD("set_overlap", "v"), &SpineSprite::set_overlap); ClassDB::bind_method(D_METHOD("bone_get_global_transform", "bone_name"), &SpineSprite::bone_get_global_transform); ClassDB::bind_method(D_METHOD("bone_set_global_transform", "bone_name", "global_transform"), &SpineSprite::bone_set_global_transform); ClassDB::bind_method(D_METHOD("set_process_mode", "v"), &SpineSprite::set_process_mode); ClassDB::bind_method(D_METHOD("get_process_mode"), &SpineSprite::get_process_mode); ClassDB::bind_method(D_METHOD("update_all", "delta"), &SpineSprite::_update_all); ADD_SIGNAL(MethodInfo("animation_state_ready", PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "skeleton", PROPERTY_HINT_TYPE_STRING, "SpineSkeleton"))); ADD_SIGNAL(MethodInfo("animation_start", PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_TYPE_STRING, "SpineEvent"))); ADD_SIGNAL(MethodInfo("animation_interrupt", PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_TYPE_STRING, "SpineEvent"))); ADD_SIGNAL(MethodInfo("animation_end", PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_TYPE_STRING, "SpineEvent"))); ADD_SIGNAL(MethodInfo("animation_complete", PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_TYPE_STRING, "SpineEvent"))); ADD_SIGNAL(MethodInfo("animation_dispose", PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_TYPE_STRING, "SpineEvent"))); ADD_SIGNAL(MethodInfo("animation_event", PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_TYPE_STRING, "SpineEvent"))); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "animation_state_data_res", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineAnimationStateDataResource"), "set_animation_state_data_res", "get_animation_state_data_res"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "overlap"), "set_overlap", "get_overlap"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "bind_slot_nodes"), "set_bind_slot_nodes", "get_bind_slot_nodes"); ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Process,Physics,Manual"), "set_process_mode", "get_process_mode"); BIND_ENUM_CONSTANT(ProcessMode::ProcessMode_Process); BIND_ENUM_CONSTANT(ProcessMode::ProcessMode_Physics); BIND_ENUM_CONSTANT(ProcessMode::ProcessMode_Manual); } SpineSprite::SpineSprite() : overlap(false), skeleton_clipper(NULL), process_mode(ProcessMode_Process) { skeleton_clipper = new spine::SkeletonClipping(); } SpineSprite::~SpineSprite() { delete skeleton_clipper; } void SpineSprite::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { set_process_internal(process_mode == ProcessMode_Process); set_physics_process_internal(process_mode == ProcessMode_Physics); remove_redundant_mesh_instances(); } break; case NOTIFICATION_INTERNAL_PROCESS: { if (process_mode == ProcessMode_Process) _update_all(get_process_delta_time()); } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { if (process_mode == ProcessMode_Physics) _update_all(get_physics_process_delta_time()); } break; } } void SpineSprite::_update_all(float delta) { if (!(skeleton.is_valid() && animation_state.is_valid()) || mesh_instances.empty()) return; animation_state->update(delta); if (!is_visible_in_tree()) return; animation_state->apply(skeleton); skeleton->update_world_transform(); update_mesh_from_skeleton(skeleton); update(); update_bind_slot_nodes(); } void SpineSprite::update_bind_slot_nodes() { if (animation_state.is_valid() && skeleton.is_valid()) { for (size_t i = 0, n = bind_slot_nodes.size(); i < n; ++i) { auto a = bind_slot_nodes[i]; if (a.get_type() == Variant::DICTIONARY) { auto d = (Dictionary) a; if (d.has("slot_name") && d.has("node_path")) { NodePath node_path = d["node_path"]; Node *node = get_node_or_null(node_path); if (node && node->is_class("Node2D")) { Node2D *node2d = (Node2D *) node; String slot_name = d["slot_name"]; auto slot = skeleton->find_slot(slot_name); if (slot.is_valid()) { auto bone = slot->get_bone(); if (bone.is_valid()) { update_bind_slot_node_transform(bone, node2d); update_bind_slot_node_draw_order(slot_name, node2d); } } } } } else if (a.get_type() == Variant::ARRAY) { auto as = (Array) a;// 0: slot_name, 1: node_path if (as.size() >= 2 && as[0].get_type() == Variant::STRING && as[1].get_type() == Variant::NODE_PATH) { NodePath node_path = as[1]; Node *node = get_node_or_null(node_path); if (node && node->is_class("Node2D")) { Node2D *node2d = (Node2D *) node; String slot_name = as[0]; auto slot = skeleton->find_slot(slot_name); if (slot.is_valid()) { auto bone = slot->get_bone(); if (bone.is_valid()) { update_bind_slot_node_transform(bone, node2d); update_bind_slot_node_draw_order(slot_name, node2d); } } } } } } } } void SpineSprite::update_bind_slot_node_transform(Ref bone, Node2D *node2d) { bone->apply_world_transform_2d(node2d); } void SpineSprite::update_bind_slot_node_draw_order(const String &slot_name, Node2D *node2d) { auto mesh_ins = find_node(slot_name); if (mesh_ins) { auto pos = mesh_ins->get_index(); // get child auto node = find_child_node_by_node(node2d); if (node && node->get_index() != pos + 1) { move_child(node, pos + 1); } } } Node *SpineSprite::find_child_node_by_node(Node *node) { if (node == NULL) return NULL; while (node && node->get_parent() != this) node = node->get_parent(); return node; } void SpineSprite::set_animation_state_data_res(const Ref &s) { animation_state_data_res = s; _on_animation_data_changed(); } Ref SpineSprite::get_animation_state_data_res() { return animation_state_data_res; } void SpineSprite::_on_animation_data_created() { skeleton = Ref(memnew(SpineSkeleton)); skeleton->load_skeleton(animation_state_data_res->get_skeleton()); skeleton->set_spine_sprite(this); animation_state = Ref(memnew(SpineAnimationState)); animation_state->load_animation_state(animation_state_data_res); animation_state->get_animation_state()->setListener(this); animation_state->update(0); animation_state->apply(skeleton); skeleton->update_world_transform(); gen_mesh_from_skeleton(skeleton); if (process_mode == ProcessMode_Process) { _notification(NOTIFICATION_INTERNAL_PROCESS); } else if (process_mode == ProcessMode_Physics) { _notification(NOTIFICATION_INTERNAL_PHYSICS_PROCESS); } emit_signal("animation_state_ready", animation_state, skeleton); } void SpineSprite::_on_animation_data_changed() { remove_mesh_instances(); skeleton.unref(); animation_state.unref(); if (!animation_state_data_res.is_null()) { if (!animation_state_data_res->is_connected("animation_state_data_created", this, "_on_animation_data_created")) animation_state_data_res->connect("animation_state_data_created", this, "_on_animation_data_created"); if (!animation_state_data_res->is_connected("skeleton_data_res_changed", this, "_on_animation_data_changed")) animation_state_data_res->connect("skeleton_data_res_changed", this, "_on_animation_data_changed"); if (!animation_state_data_res->is_connected("animation_state_data_changed", this, "_on_animation_data_changed")) animation_state_data_res->connect("animation_state_data_changed", this, "_on_animation_data_changed"); if (animation_state_data_res->is_animation_state_data_created()) { _on_animation_data_created(); } } } Ref SpineSprite::get_skeleton() { return skeleton; } Ref SpineSprite::get_animation_state() { return animation_state; } void SpineSprite::gen_mesh_from_skeleton(Ref s) { auto sk = s->get_spine_object(); for (size_t i = 0, n = sk->getSlots().size(); i < n; ++i) { auto mesh_ins = memnew(SpineSpriteMeshInstance2D); add_child(mesh_ins); mesh_ins->set_position(Vector2(0, 0)); mesh_ins->set_owner(this); mesh_instances.push_back(mesh_ins); spine::Slot *slot = sk->getDrawOrder()[i]; mesh_ins->set_name(slot->getData().getName().buffer()); Ref gd_slot(memnew(SpineSlot)); gd_slot->set_spine_object(slot); mesh_ins->set_slot(gd_slot); Ref mat(memnew(CanvasItemMaterial)); CanvasItemMaterial::BlendMode blend_mode; switch (slot->getData().getBlendMode()) { case spine::BlendMode_Normal: blend_mode = CanvasItemMaterial::BLEND_MODE_MIX; break; case spine::BlendMode_Additive: blend_mode = CanvasItemMaterial::BLEND_MODE_ADD; break; case spine::BlendMode_Multiply: blend_mode = CanvasItemMaterial::BLEND_MODE_MUL; break; case spine::BlendMode_Screen: blend_mode = CanvasItemMaterial::BLEND_MODE_MIX; break; default: blend_mode = CanvasItemMaterial::BLEND_MODE_MIX; } mat->set_blend_mode(blend_mode); mesh_ins->set_material(mat); } } void SpineSprite::remove_mesh_instances() { for (size_t i = 0; i < mesh_instances.size(); ++i) { remove_child(mesh_instances[i]); memdelete(mesh_instances[i]); } mesh_instances.clear(); } void SpineSprite::remove_redundant_mesh_instances() { Vector ms; // remove the redundant mesh instances that added by duplicating for (size_t i = 0, n = get_child_count(); i < n; ++i) { auto node = get_child(i); if (node && node->is_class("SpineSpriteMeshInstance2D")) { if (mesh_instances.find((SpineSpriteMeshInstance2D *) node) == -1) { ms.push_back(node); } } } for (size_t i = 0, n = ms.size(); i < n; ++i) { remove_child(ms[i]); memdelete(ms[i]); } ms.clear(); } #define TEMP_COPY(t, get_res) \ do { \ auto &temp_uvs = get_res; \ t.setSize(temp_uvs.size(), 0); \ for (size_t j = 0; j < t.size(); ++j) { \ t[j] = temp_uvs[j]; \ } \ } while (false); void SpineSprite::update_mesh_from_skeleton(Ref s) { static const unsigned short VERTEX_STRIDE = 2; static unsigned short quad_indices[] = {0, 1, 2, 2, 3, 0}; auto sk = s->get_spine_object(); for (size_t i = 0, n = sk->getSlots().size(); i < n; ++i) { spine::Vector vertices; spine::Vector uvs; spine::Vector indices; spine::Slot *slot = sk->getDrawOrder()[i]; spine::Attachment *attachment = slot->getAttachment(); if (!attachment) { mesh_instances[i]->set_visible(false); skeleton_clipper->clipEnd(*slot); continue; } mesh_instances[i]->set_visible(true); spine::Color skeleton_color = sk->getColor(); spine::Color slot_color = slot->getColor(); spine::Color tint(skeleton_color.r * slot_color.r, skeleton_color.g * slot_color.g, skeleton_color.b * slot_color.b, skeleton_color.a * slot_color.a); Ref tex; Ref normal_tex; size_t v_num = 0; if (attachment->getRTTI().isExactly(spine::RegionAttachment::rtti)) { spine::RegionAttachment *region_attachment = (spine::RegionAttachment *) attachment; auto p_spine_renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) region_attachment->getRendererObject())->page->getRendererObject(); tex = p_spine_renderer_object->texture; normal_tex = p_spine_renderer_object->normal_map; v_num = 4; vertices.setSize(v_num * VERTEX_STRIDE, 0); region_attachment->computeWorldVertices(*slot, vertices, 0); TEMP_COPY(uvs, region_attachment->getUVs()); indices.setSize(sizeof(quad_indices) / sizeof(unsigned short), 0); for (size_t j = 0, qn = indices.size(); j < qn; ++j) { indices[j] = quad_indices[j]; } auto attachment_color = region_attachment->getColor(); tint.r *= attachment_color.r; tint.g *= attachment_color.g; tint.b *= attachment_color.b; tint.a *= attachment_color.a; } else if (attachment->getRTTI().isExactly(spine::MeshAttachment::rtti)) { spine::MeshAttachment *mesh = (spine::MeshAttachment *) attachment; auto p_spine_renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) mesh->getRendererObject())->page->getRendererObject(); tex = p_spine_renderer_object->texture; normal_tex = p_spine_renderer_object->normal_map; v_num = mesh->getWorldVerticesLength() / VERTEX_STRIDE; vertices.setSize(mesh->getWorldVerticesLength(), 0); mesh->computeWorldVertices(*slot, vertices); TEMP_COPY(uvs, mesh->getUVs()); TEMP_COPY(indices, mesh->getTriangles()); auto attachment_color = mesh->getColor(); tint.r *= attachment_color.r; tint.g *= attachment_color.g; tint.b *= attachment_color.b; tint.a *= attachment_color.a; } else if (attachment->getRTTI().isExactly(spine::ClippingAttachment::rtti)) { auto clip = (spine::ClippingAttachment *) attachment; skeleton_clipper->clipStart(*slot, clip); continue; } else { skeleton_clipper->clipEnd(*slot); continue; } auto mesh_ins = mesh_instances[i]; VisualServer::get_singleton()->canvas_item_clear(mesh_ins->get_canvas_item()); if (skeleton_clipper->isClipping()) { skeleton_clipper->clipTriangles(vertices, indices, uvs, VERTEX_STRIDE); if (skeleton_clipper->getClippedTriangles().size() == 0) { skeleton_clipper->clipEnd(*slot); continue; } auto &clipped_vertices = skeleton_clipper->getClippedVertices(); v_num = clipped_vertices.size() / VERTEX_STRIDE; auto &clipped_uvs = skeleton_clipper->getClippedUVs(); auto &clipped_indices = skeleton_clipper->getClippedTriangles(); if (indices.size() > 0) { Vector p_points, p_uvs; Vector p_colors; Vector p_indices; p_points.resize(v_num); p_uvs.resize(v_num); p_colors.resize(v_num); for (size_t j = 0; j < v_num; j++) { p_points.set(j, Vector2(clipped_vertices[j * VERTEX_STRIDE], -clipped_vertices[j * VERTEX_STRIDE + 1])); p_uvs.set(j, Vector2(clipped_uvs[j * VERTEX_STRIDE], clipped_uvs[j * VERTEX_STRIDE + 1])); p_colors.set(j, Color(tint.r, tint.g, tint.b, tint.a)); } p_indices.resize(clipped_indices.size()); for (size_t j = 0; j < clipped_indices.size(); ++j) { p_indices.set(j, clipped_indices[j]); } VisualServer::get_singleton()->canvas_item_add_triangle_array(mesh_ins->get_canvas_item(), p_indices, p_points, p_colors, p_uvs, Vector(), Vector(), tex.is_null() ? RID() : tex->get_rid(), -1, normal_tex.is_null() ? RID() : normal_tex->get_rid()); } } else { if (indices.size() > 0) { Vector p_points, p_uvs; Vector p_colors; Vector p_indices; p_points.resize(v_num); p_uvs.resize(v_num); p_colors.resize(v_num); for (size_t j = 0; j < v_num; j++) { p_points.set(j, Vector2(vertices[j * VERTEX_STRIDE], -vertices[j * VERTEX_STRIDE + 1])); p_uvs.set(j, Vector2(uvs[j * VERTEX_STRIDE], uvs[j * VERTEX_STRIDE + 1])); p_colors.set(j, Color(tint.r, tint.g, tint.b, tint.a)); } p_indices.resize(indices.size()); for (size_t j = 0; j < indices.size(); ++j) { p_indices.set(j, indices[j]); } VisualServer::get_singleton()->canvas_item_add_triangle_array(mesh_ins->get_canvas_item(), p_indices, p_points, p_colors, p_uvs, Vector(), Vector(), tex.is_null() ? RID() : tex->get_rid(), -1, normal_tex.is_null() ? RID() : normal_tex->get_rid()); } } skeleton_clipper->clipEnd(*slot); if (mesh_ins->get_material()->is_class("CanvasItemMaterial")) { Ref mat = mesh_ins->get_material(); CanvasItemMaterial::BlendMode blend_mode; switch (slot->getData().getBlendMode()) { case spine::BlendMode_Normal: blend_mode = CanvasItemMaterial::BLEND_MODE_MIX; break; case spine::BlendMode_Additive: blend_mode = CanvasItemMaterial::BLEND_MODE_ADD; break; case spine::BlendMode_Multiply: blend_mode = CanvasItemMaterial::BLEND_MODE_MUL; break; case spine::BlendMode_Screen: blend_mode = CanvasItemMaterial::BLEND_MODE_MIX; break; default: blend_mode = CanvasItemMaterial::BLEND_MODE_MIX; } mat->set_blend_mode(blend_mode); } } skeleton_clipper->clipEnd(); } void SpineSprite::callback(spine::AnimationState *state, spine::EventType type, spine::TrackEntry *entry, spine::Event *event) { Ref gd_entry(NULL); Ref gd_event(NULL); if (entry) { gd_entry = Ref(memnew(SpineTrackEntry)); gd_entry->set_spine_object(entry); } if (event) { gd_event = Ref(memnew(SpineEvent)); gd_event->set_spine_object(event); } switch (type) { case spine::EventType_Start: { emit_signal("animation_start", animation_state, gd_entry, gd_event); } break; case spine::EventType_Interrupt: { emit_signal("animation_interrupt", animation_state, gd_entry, gd_event); } break; case spine::EventType_End: { emit_signal("animation_end", animation_state, gd_entry, gd_event); } break; case spine::EventType_Complete: { emit_signal("animation_complete", animation_state, gd_entry, gd_event); } break; case spine::EventType_Dispose: { emit_signal("animation_dispose", animation_state, gd_entry, gd_event); } break; case spine::EventType_Event: { emit_signal("animation_event", animation_state, gd_entry, gd_event); } break; } } Array SpineSprite::get_bind_slot_nodes() { return bind_slot_nodes; } void SpineSprite::set_bind_slot_nodes(Array v) { bind_slot_nodes = v; } bool SpineSprite::get_overlap() { return overlap; } void SpineSprite::set_overlap(bool v) { overlap = v; } Transform2D SpineSprite::bone_get_global_transform(const String &bone_name) { if (!animation_state.is_valid() && !skeleton.is_valid()) { return get_global_transform(); } auto bone = skeleton->find_bone(bone_name); if (!bone.is_valid()) { print_error(vformat("Bone: '%s' not found.", bone_name)); return get_global_transform(); } return bone->get_godot_global_transform(); } void SpineSprite::bone_set_global_transform(const String &bone_name, Transform2D transform) { if (!animation_state.is_valid() && !skeleton.is_valid()) { return; } auto bone = skeleton->find_bone(bone_name); if (!bone.is_valid()) { return; } bone->set_godot_global_transform(transform); } SpineSprite::ProcessMode SpineSprite::get_process_mode() { return process_mode; } void SpineSprite::set_process_mode(SpineSprite::ProcessMode v) { process_mode = v; set_process_internal(process_mode == ProcessMode_Process); set_physics_process_internal(process_mode == ProcessMode_Physics); } void SpineSprite::_get_property_list(List *p_list) const { Vector animations; Vector skins; if (animation_state_data_res.is_valid() && animation_state_data_res->get_skeleton().is_valid()) { animation_state_data_res->get_skeleton()->get_animation_names(animations); animation_state_data_res->get_skeleton()->get_skin_names(skins); } animations.insert(0, "- None -"); PropertyInfo animationListProperty; animationListProperty.name = "Preview animation"; animationListProperty.type = Variant::STRING; animationListProperty.hint_string = String(",").join(animations); animationListProperty.hint = PROPERTY_HINT_ENUM; animationListProperty.usage = PROPERTY_USAGE_EDITOR; p_list->push_back(animationListProperty); PropertyInfo skinListProperty; skinListProperty.name = "Preview skin"; skinListProperty.type = Variant::STRING; skinListProperty.hint_string = String(",").join(skins); skinListProperty.hint = PROPERTY_HINT_ENUM; skinListProperty.usage = PROPERTY_USAGE_EDITOR; p_list->push_back(skinListProperty); } bool SpineSprite::_get(const StringName &p_property, Variant &r_value) const { return false; } bool SpineSprite::_set(const StringName &p_property, const Variant &p_value) { if (p_property == "Preview animation") { if (animation_state.is_valid() && skeleton.is_valid()) { auto animName = p_value.operator String(); skeleton->set_to_setup_pose(); if (skeleton->get_data()->find_animation(animName).is_valid()) { animation_state->set_animation(animName, true, 0); } else { animation_state->clear_tracks(); } } } if (p_property == "Preview skin") { if (animation_state.is_valid() && skeleton.is_valid()) { auto skinName = p_value.operator String(); if (skeleton->get_data()->find_skin(skinName).is_valid()) { skeleton->set_skin_by_name(skinName); } else { skeleton->set_skin(NULL); } skeleton->set_to_setup_pose(); } } return false; }