[godot] pragma once, clean-up SpineSlotNode, add SpineBoneNode + example

This commit is contained in:
badlogic 2022-04-30 14:59:16 +02:00
parent 33ea04646a
commit 4326314fd1
39 changed files with 386 additions and 153 deletions

View File

@ -0,0 +1,5 @@
extends Node2D
func _ready():
$SpineSprite.get_animation_state().set_animation("hoverboard", true, 0)
pass

View File

@ -0,0 +1,19 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://examples/11-bone-node/bone-node.gd" type="Script" id=1]
[ext_resource path="res://assets/spineboy/spineboy-data-res.tres" type="SpineSkeletonDataResource" id=2]
[node name="Node2D" type="Node2D"]
script = ExtResource( 1 )
[node name="SpineSprite" type="SpineSprite" parent="."]
position = Vector2( 461, 491 )
scale = Vector2( 0.479082, 0.479082 )
skeleton_data_res = ExtResource( 2 )
[node name="SpineBoneNode" type="SpineBoneNode" parent="SpineSprite"]
position = Vector2( -329.751, -69.5322 )
rotation = 0.00281584
scale = Vector2( 1, 1 )
bone_name = "hoverboard-controller"
bone_mode = 1

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINEEXTENSION_H
#define GODOT_SPINEEXTENSION_H
#pragma once
#include <spine/Extension.h>
@ -44,6 +43,3 @@ protected:
virtual char *_readFile(const spine::String &path, int *length);
};
#endif//GODOT_SPINEEXTENSION_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINEANIMATION_H
#define GODOT_SPINEANIMATION_H
#pragma once
#include "SpineCommon.h"
#include "SpineConstant.h"
@ -58,5 +57,3 @@ public:
void set_duration(float duration);
};
#endif//GODOT_SPINEANIMATION_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINEANIMATIONSTATE_H
#define GODOT_SPINEANIMATIONSTATE_H
#pragma once
#include "SpineCommon.h"
#include "SpineSkeleton.h"
@ -81,5 +80,3 @@ public:
void enable_queue();
};
#endif//GODOT_SPINEANIMATIONSTATE_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINEANIMATIONTRACK_H
#define GODOT_SPINEANIMATIONTRACK_H
#pragma once
#include "SpineSprite.h"
#include "scene/animation/animation_player.h"
@ -129,5 +128,3 @@ public:
bool get_debug();
};
#endif

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINEATLASRESOURCE_H
#define GODOT_SPINEATLASRESOURCE_H
#pragma once
#include "SpineCommon.h"
#include "core/io/resource_loader.h"
@ -36,7 +35,6 @@
#include "core/io/image_loader.h"
#include <spine/Atlas.h>
class GodotSpineTextureLoader;
class SpineAtlasResource : public Resource {
@ -105,6 +103,3 @@ public:
bool recognize(const RES &resource) const override;
};
#endif//GODOT_SPINEATLASRESOURCE_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINEATTACHMENT_H
#define GODOT_SPINEATTACHMENT_H
#pragma once
#include "SpineCommon.h"
#include <spine/spine.h>
@ -48,5 +47,3 @@ public:
Ref<SpineAttachment> copy();
};
#endif//GODOT_SPINEATTACHMENT_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINEBONE_H
#define GODOT_SPINEBONE_H
#pragma once
#include "SpineCommon.h"
#include "SpineBoneData.h"
@ -172,5 +171,3 @@ public:
void set_global_transform(Transform2D trans);
};
#endif//GODOT_SPINEBONE_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINEBONEDATA_H
#define GODOT_SPINEBONEDATA_H
#pragma once
#include "SpineCommon.h"
#include "SpineConstant.h"
@ -93,5 +92,3 @@ public:
void set_color(Color color);
};
#endif//GODOT_SPINEBONEDATA_H

View File

@ -0,0 +1,151 @@
/******************************************************************************
* 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 "SpineBoneNode.h"
void SpineBoneNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_bone_mode"), &SpineBoneNode::set_bone_mode);
ClassDB::bind_method(D_METHOD("get_bone_mode"), &SpineBoneNode::get_bone_mode);
ClassDB::bind_method(D_METHOD("_before_world_transforms_change", "spine_sprite"), &SpineBoneNode::before_world_transforms_change);
ClassDB::bind_method(D_METHOD("_on_world_transforms_changed", "spine_sprite"), &SpineBoneNode::on_world_transforms_changed);
ADD_PROPERTY(PropertyInfo(Variant::INT, "bone_mode", PROPERTY_HINT_ENUM, "Follow,Drive"), "set_bone_mode", "get_bone_mode");
}
void SpineBoneNode::_notification(int what) {
switch(what) {
case NOTIFICATION_PARENTED: {
SpineSprite *sprite = cast_to<SpineSprite>(get_parent());
if (sprite) {
#if VERSION_MAJOR > 3
sprite->connect("before_world_transforms_change", callable_mp(this, &SpineBoneNode::before_world_transforms_change));
sprite->connect("world_transforms_changed", callable_mp(this, &SpineSlotNode::on_world_transforms_changed));
#else
sprite->connect("before_world_transforms_change", this, "_before_world_transforms_change");
sprite->connect("world_transforms_changed", this, "_on_world_transforms_changed");
#endif
update_transform(sprite);
#if VERSION_MAJOR == 3
_change_notify("transform/translation");
_change_notify("transform/rotation");
_change_notify("transform/scale");
_change_notify("translation");
_change_notify("rotation");
_change_notify("rotation_deg");
_change_notify("scale");
#endif
} else {
WARN_PRINT("SpineSlotNode parent is not a SpineSprite.");
}
NOTIFY_PROPERTY_LIST_CHANGED();
break;
}
case NOTIFICATION_UNPARENTED: {
SpineSprite *sprite = cast_to<SpineSprite>(get_parent());
if (sprite) {
#if VERSION_MAJOR > 3
sprite->disconnect("before_world_transforms_change", callable_mp(this, &SpineBoneNode::before_world_transforms_change));
sprite->disconnect("world_transforms_changed", callable_mp(this, &SpineSlotNode::on_world_transforms_changed));
#else
sprite->disconnect("before_world_transforms_change", this, "_before_world_transforms_change");
sprite->disconnect("world_transforms_changed", this, "_on_world_transforms_changed");
#endif
}
}
default:
break;
}
}
void SpineBoneNode::_get_property_list(List<PropertyInfo>* list) const {
Vector<String> bone_names;
SpineSprite *sprite = cast_to<SpineSprite>(get_parent());
if (sprite) sprite->get_skeleton_data_res()->get_bone_names(bone_names);
else bone_names.push_back(bone_name);
auto element = list->front();
while (element) {
auto property_info = element->get();
if (property_info.name == "SpineBoneNode") break;
element = element->next();
}
PropertyInfo slot_name_property;
slot_name_property.name = "bone_name";
slot_name_property.type = Variant::STRING;
slot_name_property.hint_string = String(",").join(bone_names);
slot_name_property.hint = PROPERTY_HINT_ENUM;
slot_name_property.usage = PROPERTY_USAGE_DEFAULT;
list->insert_after(element, slot_name_property);
}
bool SpineBoneNode::_get(const StringName& property, Variant& value) const {
if (property == "bone_name") {
value = bone_name;
return true;
}
return false;
}
bool SpineBoneNode::_set(const StringName& property, const Variant& value) {
if (property == "bone_name") {
bone_name = value;
return true;
}
return false;
}
void SpineBoneNode::before_world_transforms_change(const Variant& _sprite) {
SpineSprite* sprite = cast_to<SpineSprite>(_sprite.operator Object*());
if (bone_mode == SpineConstant::BoneMode_Drive) update_transform(sprite);
}
void SpineBoneNode::on_world_transforms_changed(const Variant& _sprite) {
SpineSprite* sprite = cast_to<SpineSprite>(_sprite.operator Object*());
if (bone_mode == SpineConstant::BoneMode_Follow) update_transform(sprite);
}
void SpineBoneNode::update_transform(SpineSprite* sprite) {
if (!sprite) return;
if (!sprite->get_skeleton().is_valid() || !sprite->get_skeleton()->get_spine_object()) return;
auto bone = sprite->get_skeleton()->find_bone(bone_name);
if (!bone.is_valid()) return;
if (bone_mode == SpineConstant::BoneMode_Drive) {
bone->set_global_transform(get_global_transform());
} else {
this->set_global_transform(bone->get_global_transform());
}
}
SpineConstant::BoneMode SpineBoneNode::get_bone_mode() {
return bone_mode;
}
void SpineBoneNode::set_bone_mode(SpineConstant::BoneMode _bone_mode) {
bone_mode = _bone_mode;
}

View File

@ -0,0 +1,62 @@
/******************************************************************************
* 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.
*****************************************************************************/
#pragma once
#include "SpineCommon.h"
#include "SpineSprite.h"
#include "scene/2d/node_2d.h"
class SpineBoneNode: public Node2D {
GDCLASS(SpineBoneNode, Node2D)
protected:
String bone_name;
SpineConstant::BoneMode bone_mode;
static void _bind_methods();
void _notification(int what);
void _get_property_list(List<PropertyInfo> *list) const;
bool _get(const StringName &property, Variant &value) const;
bool _set(const StringName &property, const Variant &value);
void before_world_transforms_change(const Variant &_sprite);
void on_world_transforms_changed(const Variant &_sprite);
void update_transform(SpineSprite *sprite);
public:
SpineBoneNode(): bone_mode(SpineConstant::BoneMode_Follow) {}
String get_bone_name();
void set_bone_name(const String &_bone_name);
SpineConstant::BoneMode get_bone_mode();
void set_bone_mode(SpineConstant::BoneMode bone_mode);
};

View File

@ -80,4 +80,11 @@ void SpineConstant::_bind_methods() {
BIND_ENUM_CONSTANT(BlendMode_Additive)
BIND_ENUM_CONSTANT(BlendMode_Multiply)
BIND_ENUM_CONSTANT(BlendMode_Screen)
BIND_ENUM_CONSTANT(UpdateMode_Process)
BIND_ENUM_CONSTANT(UpdateMode_Physics)
BIND_ENUM_CONSTANT(UpdateMode_Manual)
BIND_ENUM_CONSTANT(BoneMode_Follow)
BIND_ENUM_CONSTANT(BoneMode_Drive)
}

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINECONSTANT_H
#define GODOT_SPINECONSTANT_H
#pragma once
#include "SpineCommon.h"
@ -105,6 +104,17 @@ public:
BlendMode_Multiply,
BlendMode_Screen
};
enum UpdateMode {
UpdateMode_Process,
UpdateMode_Physics,
UpdateMode_Manual
};
enum BoneMode {
BoneMode_Follow,
BoneMode_Drive
};
};
VARIANT_ENUM_CAST(SpineConstant::MixBlend)
@ -115,5 +125,5 @@ VARIANT_ENUM_CAST(SpineConstant::PositionMode)
VARIANT_ENUM_CAST(SpineConstant::SpacingMode)
VARIANT_ENUM_CAST(SpineConstant::RotateMode)
VARIANT_ENUM_CAST(SpineConstant::BlendMode)
#endif//GODOT_SPINECONSTANT_H
VARIANT_ENUM_CAST(SpineConstant::UpdateMode)
VARIANT_ENUM_CAST(SpineConstant::BoneMode)

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINECONSTRAINTDATA_H
#define GODOT_SPINECONSTRAINTDATA_H
#pragma once
#include "SpineCommon.h"
#include <spine/ConstraintData.h>
@ -52,5 +51,3 @@ public:
void set_skin_required(bool v);
};
#endif//GODOT_SPINECONSTRAINTDATA_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINEEDITORPLUGIN_H
#define GODOT_SPINEEDITORPLUGIN_H
#pragma once
#ifdef TOOLS_ENABLED
#include "SpineCommon.h"
@ -206,5 +205,3 @@ public:
};
#endif
#endif//GODOT_SPINEEDITORPLUGIN_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINEEVENT_H
#define GODOT_SPINEEVENT_H
#pragma once
#include "SpineCommon.h"
#include "SpineEventData.h"
@ -67,5 +66,3 @@ public:
void set_balance(float v);
};
#endif//GODOT_SPINEEVENT_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINEEVENTDATA_H
#define GODOT_SPINEEVENTDATA_H
#pragma once
#include "SpineCommon.h"
#include <spine/EventData.h>
@ -64,5 +63,3 @@ public:
void set_balance(float v);
};
#endif//GODOT_SPINEEVENTDATA_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINEIKCONSTRAINT_H
#define GODOT_SPINEIKCONSTRAINT_H
#pragma once
#include "SpineIkConstraintData.h"
#include <spine/IkConstraint.h>
@ -79,5 +78,3 @@ public:
void set_active(bool v);
};
#endif//GODOT_SPINEIKCONSTRAINT_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINEIKCONSTRAINTDATA_H
#define GODOT_SPINEIKCONSTRAINTDATA_H
#pragma once
#include "SpineConstraintData.h"
#include "SpineBoneData.h"
@ -73,5 +72,3 @@ public:
void set_softness(float v);
};
#endif//GODOT_SPINEIKCONSTRAINTDATA_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINEPATHCONSTRAINT_H
#define GODOT_SPINEPATHCONSTRAINT_H
#pragma once
#include "SpinePathConstraintData.h"
#include "SpineSlot.h"
@ -77,5 +76,3 @@ public:
void set_active(bool v);
};
#endif//GODOT_SPINEPATHCONSTRAINT_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINEPATHCONSTRAINTDATA_H
#define GODOT_SPINEPATHCONSTRAINTDATA_H
#pragma once
#include "SpineConstraintData.h"
#include "SpineConstant.h"
@ -87,4 +86,3 @@ public:
void set_mix_y(float v);
};
#endif//GODOT_SPINEPATHCONSTRAINTDATA_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINESKELETON_H
#define GODOT_SPINESKELETON_H
#pragma once
#include "SpineCommon.h"
#include "SpineSkeletonDataResource.h"
@ -51,6 +50,8 @@ class SpineSkeleton : public REFCOUNTED {
friend class SpineAnimationState;
friend class SpineCollisionShapeProxy;
friend class SpineAnimationTrack;
friend class SpineBoneNode;
friend class SpineSlotNode;
protected:
static void _bind_methods();
@ -137,5 +138,3 @@ public:
void set_scale_y(float v);
};
#endif//GODOT_SPINESKELETON_H

View File

@ -236,6 +236,16 @@ void SpineSkeletonDataResource::get_slot_names(Vector<String>& slot_names) {
}
}
void SpineSkeletonDataResource::get_bone_names(Vector<String>& bone_names) {
bone_names.clear();
if (!is_skeleton_data_loaded()) return;
auto bones = skeleton_data->getBones();
for (size_t i = 0; i < bones.size(); ++i) {
auto bone = bones[i];
bone_names.push_back(bone->getName().buffer());
}
}
void SpineSkeletonDataResource::set_default_mix(float _default_mix) {
this->default_mix = _default_mix;
update_mixes();

View File

@ -1,5 +1,4 @@
#ifndef GODOT_SPINESKELETONDATARESOURCE_H
#define GODOT_SPINESKELETONDATARESOURCE_H
#pragma once
#include "SpineAtlasResource.h"
#include "SpineSkeletonFileResource.h"
@ -78,6 +77,8 @@ public:
void get_slot_names(Vector<String> &slot_names);
void get_bone_names(Vector<String> &bone_names);
void set_default_mix(float default_mix);
float get_default_mix();
@ -146,6 +147,3 @@ public:
float get_fps() const;
};
#endif //GODOT_SPINESKELETONDATARESOURCE_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINESKELETONFILERESOURCE_H
#define GODOT_SPINESKELETONFILERESOURCE_H
#pragma once
#include "SpineCommon.h"
#include "core/io/resource_loader.h"
@ -82,5 +81,3 @@ public:
bool recognize(const RES &p_resource) const override;
};
#endif//GODOT_SPINESKELETONFILERESOURCE_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINESKIN_H
#define GODOT_SPINESKIN_H
#pragma once
#include "SpineCommon.h"
#include "SpineAttachment.h"
@ -101,5 +100,3 @@ public:
Ref<SpineAttachment> get_attachment();
};
#endif//GODOT_SPINESKIN_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINESLOT_H
#define GODOT_SPINESLOT_H
#pragma once
#include "SpineCommon.h"
#include "SpineSlotData.h"
@ -77,5 +76,3 @@ public:
void set_sequence_index(int v);
};
#endif//GODOT_SPINESLOT_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINESLOTDATA_H
#define GODOT_SPINESLOTDATA_H
#pragma once
#include "SpineCommon.h"
#include "SpineBoneData.h"
@ -69,5 +68,3 @@ public:
void set_blend_mode(SpineConstant::BlendMode v);
};
#endif//GODOT_SPINESLOTDATA_H

View File

@ -1,11 +1,38 @@
#include "SpineSlotNode.h"
/******************************************************************************
* 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 "SpineSlotNode.h"
#include "editor/editor_node.h"
#include "scene/main/viewport.h"
void SpineSlotNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_slot_name"), &SpineSlotNode::set_slot_name);
ClassDB::bind_method(D_METHOD("get_slot_name"), &SpineSlotNode::get_slot_name);
ClassDB::bind_method(D_METHOD("_on_world_transforms_changed", "spine_sprite"), &SpineSlotNode::on_world_transforms_changed);
ClassDB::bind_method(D_METHOD("set_normal_material", "material"), &SpineSlotNode::set_normal_material);
@ -24,13 +51,13 @@ void SpineSlotNode::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "screen_material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_screen_material", "get_screen_material");
}
SpineSlotNode::SpineSlotNode(): slot_index(-1), sprite(nullptr) {
SpineSlotNode::SpineSlotNode(): slot_index(-1) {
}
void SpineSlotNode::_notification(int what) {
switch(what) {
case NOTIFICATION_PARENTED: {
sprite = Object::cast_to<SpineSprite>(get_parent());
SpineSprite *sprite = cast_to<SpineSprite>(get_parent());
if (sprite) {
#if VERSION_MAJOR > 3
sprite->connect("world_transforms_changed", callable_mp(this, &SpineSlotNode::on_world_transforms_changed));
@ -54,13 +81,15 @@ void SpineSlotNode::_notification(int what) {
break;
}
case NOTIFICATION_UNPARENTED: {
SpineSprite *sprite = cast_to<SpineSprite>(get_parent());
if (sprite) {
#if VERSION_MAJOR > 3
sprite->disconnect("world_transforms_changed", callable_mp(this, &SpineSlotNode::on_world_transforms_changed));
#else
sprite->disconnect("world_transforms_changed", this, "_on_world_transforms_changed");
#endif
}
}
break;
}
default:
break;
@ -69,6 +98,7 @@ void SpineSlotNode::_notification(int what) {
void SpineSlotNode::_get_property_list(List<PropertyInfo>* list) const {
Vector<String> slot_names;
SpineSprite *sprite = cast_to<SpineSprite>(get_parent());
if (sprite) sprite->get_skeleton_data_res()->get_slot_names(slot_names);
else slot_names.push_back(slot_name);
auto element = list->front();
@ -97,6 +127,7 @@ bool SpineSlotNode::_get(const StringName& property, Variant& value) const {
bool SpineSlotNode::_set(const StringName& property, const Variant& value) {
if (property == "slot_name") {
slot_name = value;
SpineSprite *sprite = cast_to<SpineSprite>(get_parent());
update_transform(sprite);
#if VERSION_MAJOR == 3
_change_notify("transform/translation");
@ -113,12 +144,13 @@ bool SpineSlotNode::_set(const StringName& property, const Variant& value) {
}
void SpineSlotNode::on_world_transforms_changed(const Variant& _sprite) {
SpineSprite* sprite = Object::cast_to<SpineSprite>(_sprite.operator Object*());
SpineSprite* sprite = cast_to<SpineSprite>(_sprite.operator Object*());
update_transform(sprite);
}
void SpineSlotNode::update_transform(SpineSprite *sprite) {
if (!sprite) return;
if (!sprite->get_skeleton().is_valid() || !sprite->get_skeleton()->get_spine_object()) return;
auto slot = sprite->get_skeleton()->find_slot(slot_name);
if (!slot.is_valid()) {
slot_index = -1;

View File

@ -1,5 +1,33 @@
#ifndef GODOT_SPINESLOTNODE_H
#define GODOT_SPINESLOTNODE_H
/******************************************************************************
* 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.
*****************************************************************************/
#pragma once
#include "SpineCommon.h"
#include "SpineSprite.h"
@ -15,7 +43,6 @@ protected:
Ref<Material> additive_material;
Ref<Material> multiply_material;
Ref<Material> screen_material;
SpineSprite *sprite;
static void _bind_methods();
void _notification(int what);
@ -49,5 +76,3 @@ public:
void set_screen_material(Ref<Material> material);
};
#endif

View File

@ -87,13 +87,9 @@ void SpineSprite::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "additive_material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_additive_material", "get_additive_material");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "multiply_material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_multiply_material", "get_multiply_material");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "screen_material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_screen_material", "get_screen_material");
BIND_ENUM_CONSTANT(UpdateMode::UpdateMode_Process)
BIND_ENUM_CONSTANT(UpdateMode::UpdateMode_Physics)
BIND_ENUM_CONSTANT(UpdateMode::UpdateMode_Manual)
}
SpineSprite::SpineSprite() : update_mode(UpdateMode_Process), skeleton_clipper(nullptr) {
SpineSprite::SpineSprite() : update_mode(SpineConstant::UpdateMode_Process), skeleton_clipper(nullptr) {
skeleton_clipper = new spine::SkeletonClipping();
// One material per blend mode, shared across all sprites.
@ -176,9 +172,9 @@ void SpineSprite::on_skeleton_data_changed() {
skeleton->update_world_transform();
generate_meshes_for_slots(skeleton);
if (update_mode == UpdateMode_Process) {
if (update_mode == SpineConstant::UpdateMode_Process) {
_notification(NOTIFICATION_INTERNAL_PROCESS);
} else if (update_mode == UpdateMode_Physics) {
} else if (update_mode == SpineConstant::UpdateMode_Physics) {
_notification(NOTIFICATION_INTERNAL_PHYSICS_PROCESS);
}
}
@ -244,17 +240,17 @@ Ref<SpineAnimationState> SpineSprite::get_animation_state() {
void SpineSprite::_notification(int what) {
switch (what) {
case NOTIFICATION_READY: {
set_process_internal(update_mode == UpdateMode_Process);
set_physics_process_internal(update_mode == UpdateMode_Physics);
set_process_internal(update_mode == SpineConstant::UpdateMode_Process);
set_physics_process_internal(update_mode == SpineConstant::UpdateMode_Physics);
break;
}
case NOTIFICATION_INTERNAL_PROCESS: {
if (update_mode == UpdateMode_Process)
if (update_mode == SpineConstant::UpdateMode_Process)
update_skeleton(get_process_delta_time());
break;
}
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (update_mode == UpdateMode_Physics)
if (update_mode == SpineConstant::UpdateMode_Physics)
update_skeleton(get_physics_process_delta_time());
break;
}
@ -502,14 +498,14 @@ void SpineSprite::set_global_bone_transform(const String &bone_name, Transform2D
bone->set_global_transform(transform);
}
SpineSprite::UpdateMode SpineSprite::get_update_mode() {
SpineConstant::UpdateMode SpineSprite::get_update_mode() {
return update_mode;
}
void SpineSprite::set_update_mode(SpineSprite::UpdateMode v) {
void SpineSprite::set_update_mode(SpineConstant::UpdateMode v) {
update_mode = v;
set_process_internal(update_mode == UpdateMode_Process);
set_physics_process_internal(update_mode == UpdateMode_Physics);
set_process_internal(update_mode == SpineConstant::UpdateMode_Process);
set_physics_process_internal(update_mode == SpineConstant::UpdateMode_Physics);
}
Ref<SpineSkin> SpineSprite::new_skin(const String& name) {

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINESPRITE_H
#define GODOT_SPINESPRITE_H
#pragma once
#include "SpineSkeleton.h"
#include "SpineAnimationState.h"
@ -40,19 +39,12 @@ class SpineSlotNode;
class SpineSprite : public Node2D, public spine::AnimationStateListenerObject {
GDCLASS(SpineSprite, Node2D)
public:
enum UpdateMode {
UpdateMode_Process,
UpdateMode_Physics,
UpdateMode_Manual
};
protected:
Ref<SpineSkeletonDataResource> skeleton_data_res;
Ref<SpineSkeleton> skeleton;
Ref<SpineAnimationState> animation_state;
UpdateMode update_mode;
SpineConstant::UpdateMode update_mode;
spine::Vector<spine::Vector<SpineSlotNode*> > slot_nodes;
Vector<MeshInstance2D *> mesh_instances;
@ -93,9 +85,9 @@ public:
void set_global_bone_transform(const String &bone_name, Transform2D transform);
UpdateMode get_update_mode();
SpineConstant::UpdateMode get_update_mode();
void set_update_mode(UpdateMode v);
void set_update_mode(SpineConstant::UpdateMode v);
Ref<SpineSkin> new_skin(const String &name);
@ -120,6 +112,3 @@ public:
virtual bool _edit_use_rect() const;
#endif
};
VARIANT_ENUM_CAST(SpineSprite::UpdateMode);
#endif//GODOT_SPINESPRITE_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINETIMELINE_H
#define GODOT_SPINETIMELINE_H
#pragma once
#include "SpineCommon.h"
#include "SpineConstant.h"
@ -60,5 +59,3 @@ public:
String get_type();
};
#endif//GODOT_SPINETIMELINE_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINETRACKENTRY_H
#define GODOT_SPINETRACKENTRY_H
#pragma once
#include "SpineCommon.h"
#include "SpineAnimation.h"
@ -136,5 +135,3 @@ public:
float get_track_complete();
};
#endif//GODOT_SPINETRACKENTRY_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINETRANSFORMCONSTRAINT_H
#define GODOT_SPINETRANSFORMCONSTRAINT_H
#pragma once
#include "SpineCommon.h"
#include "SpineTransformConstraintData.h"
@ -82,5 +81,3 @@ public:
void set_active(bool v);
};
#endif//GODOT_SPINETRANSFORMCONSTRAINT_H

View File

@ -27,8 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINETRANSFORMCONSTRAINTDATA_H
#define GODOT_SPINETRANSFORMCONSTRAINTDATA_H
#pragma once
#include "SpineConstraintData.h"
#include "SpineBoneData.h"
@ -75,5 +74,3 @@ public:
bool is_local();
};
#endif//GODOT_SPINETRANSFORMCONSTRAINTDATA_H

View File

@ -50,6 +50,7 @@
#include "SpineTimeline.h"
#include "SpineConstant.h"
#include "SpineSlotNode.h"
#include "SpineBoneNode.h"
static Ref<SpineAtlasResourceFormatLoader> atlas_loader;
static Ref<SpineAtlasResourceFormatSaver> atlas_saver;
@ -100,6 +101,7 @@ void register_spine_godot_types() {
ClassDB::register_class<SpineConstant>();
ClassDB::register_class<SpineSlotNode>();
ClassDB::register_class<SpineBoneNode>();
ClassDB::register_class<SpineAnimationTrack>();
#if VERSION_MAJOR > 3

View File

@ -27,5 +27,7 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#pragma once
void register_spine_godot_types();
void unregister_spine_godot_types();