Merge branch '4.1' into 4.2-beta

This commit is contained in:
Mario Zechner 2022-07-25 15:21:49 +02:00
commit 5eb9667d38
6 changed files with 187 additions and 156 deletions

View File

@ -21,6 +21,10 @@ else()
endif()
if((${SPINE_SFML}) OR (${CMAKE_CURRENT_BINARY_DIR} MATCHES "spine-sfml"))
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_OSX_ARCHITECTURES x86_64)
set(ONLY_ACTIVE_ARCH NO)
endif()
add_subdirectory(spine-c)
add_subdirectory(spine-sfml/c)
add_subdirectory(spine-cpp)

View File

@ -549,161 +549,161 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) {
}
switch (type) {
case AttachmentType_Region: {
Sequence *sequence = readSequence(Json::getItem(attachmentMap, "sequence"));
attachment = _attachmentLoader->newRegionAttachment(*skin, attachmentName, attachmentPath, sequence);
if (!attachment) {
delete skeletonData;
setError(root, "Error reading attachment: ", skinAttachmentName);
return NULL;
}
RegionAttachment *region = static_cast<RegionAttachment *>(attachment);
region->_path = attachmentPath;
region->_x = Json::getFloat(attachmentMap, "x", 0) * _scale;
region->_y = Json::getFloat(attachmentMap, "y", 0) * _scale;
region->_scaleX = Json::getFloat(attachmentMap, "scaleX", 1);
region->_scaleY = Json::getFloat(attachmentMap, "scaleY", 1);
region->_rotation = Json::getFloat(attachmentMap, "rotation", 0);
region->_width = Json::getFloat(attachmentMap, "width", 32) * _scale;
region->_height = Json::getFloat(attachmentMap, "height", 32) * _scale;
region->_sequence = sequence;
color = Json::getString(attachmentMap, "color", 0);
if (color) toColor(region->getColor(), color, true);
if (region->_region != NULL) region->updateRegion();
_attachmentLoader->configureAttachment(region);
break;
}
case AttachmentType_Mesh:
case AttachmentType_Linkedmesh: {
Sequence *sequence = readSequence(Json::getItem(attachmentMap, "sequence"));
attachment = _attachmentLoader->newMeshAttachment(*skin, attachmentName, attachmentPath, sequence);
if (!attachment) {
delete skeletonData;
setError(root, "Error reading attachment: ", skinAttachmentName);
return NULL;
}
MeshAttachment *mesh = static_cast<MeshAttachment *>(attachment);
mesh->_path = attachmentPath;
color = Json::getString(attachmentMap, "color", 0);
if (color) toColor(mesh->getColor(), color, true);
mesh->_width = Json::getFloat(attachmentMap, "width", 32) * _scale;
mesh->_height = Json::getFloat(attachmentMap, "height", 32) * _scale;
mesh->_sequence = sequence;
entry = Json::getItem(attachmentMap, "parent");
if (!entry) {
int verticesLength;
entry = Json::getItem(attachmentMap, "triangles");
mesh->_triangles.ensureCapacity(entry->_size);
mesh->_triangles.setSize(entry->_size, 0);
for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii)
mesh->_triangles[ii] = (unsigned short) entry->_valueInt;
entry = Json::getItem(attachmentMap, "uvs");
verticesLength = entry->_size;
mesh->_regionUVs.ensureCapacity(verticesLength);
mesh->_regionUVs.setSize(verticesLength, 0);
for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii)
mesh->_regionUVs[ii] = entry->_valueFloat;
readVertices(attachmentMap, mesh, verticesLength);
if (mesh->_region != NULL) mesh->updateRegion();
mesh->_hullLength = Json::getInt(attachmentMap, "hull", 0);
entry = Json::getItem(attachmentMap, "edges");
if (entry) {
mesh->_edges.ensureCapacity(entry->_size);
mesh->_edges.setSize(entry->_size, 0);
for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii)
mesh->_edges[ii] = entry->_valueInt;
case AttachmentType_Region: {
Sequence *sequence = readSequence(Json::getItem(attachmentMap, "sequence"));
attachment = _attachmentLoader->newRegionAttachment(*skin, attachmentName, attachmentPath, sequence);
if (!attachment) {
delete skeletonData;
setError(root, "Error reading attachment: ", skinAttachmentName);
return NULL;
}
_attachmentLoader->configureAttachment(mesh);
} else {
bool inheritTimelines = Json::getInt(attachmentMap, "timelines", 1) ? true : false;
LinkedMesh *linkedMesh = new (__FILE__, __LINE__) LinkedMesh(mesh,
String(Json::getString(
attachmentMap,
"skin", 0)),
slot->getIndex(),
String(entry->_valueString),
inheritTimelines);
_linkedMeshes.add(linkedMesh);
RegionAttachment *region = static_cast<RegionAttachment *>(attachment);
region->_path = attachmentPath;
region->_x = Json::getFloat(attachmentMap, "x", 0) * _scale;
region->_y = Json::getFloat(attachmentMap, "y", 0) * _scale;
region->_scaleX = Json::getFloat(attachmentMap, "scaleX", 1);
region->_scaleY = Json::getFloat(attachmentMap, "scaleY", 1);
region->_rotation = Json::getFloat(attachmentMap, "rotation", 0);
region->_width = Json::getFloat(attachmentMap, "width", 32) * _scale;
region->_height = Json::getFloat(attachmentMap, "height", 32) * _scale;
region->_sequence = sequence;
color = Json::getString(attachmentMap, "color", 0);
if (color) toColor(region->getColor(), color, true);
if (region->_region != NULL) region->updateRegion();
_attachmentLoader->configureAttachment(region);
break;
}
break;
}
case AttachmentType_Boundingbox: {
attachment = _attachmentLoader->newBoundingBoxAttachment(*skin, attachmentName);
case AttachmentType_Mesh:
case AttachmentType_Linkedmesh: {
Sequence *sequence = readSequence(Json::getItem(attachmentMap, "sequence"));
attachment = _attachmentLoader->newMeshAttachment(*skin, attachmentName, attachmentPath, sequence);
BoundingBoxAttachment *box = static_cast<BoundingBoxAttachment *>(attachment);
if (!attachment) {
delete skeletonData;
setError(root, "Error reading attachment: ", skinAttachmentName);
return NULL;
}
int vertexCount = Json::getInt(attachmentMap, "vertexCount", 0) << 1;
readVertices(attachmentMap, box, vertexCount);
color = Json::getString(attachmentMap, "color", NULL);
if (color) toColor(box->getColor(), color, true);
_attachmentLoader->configureAttachment(attachment);
break;
}
case AttachmentType_Path: {
attachment = _attachmentLoader->newPathAttachment(*skin, attachmentName);
MeshAttachment *mesh = static_cast<MeshAttachment *>(attachment);
mesh->_path = attachmentPath;
PathAttachment *pathAttatchment = static_cast<PathAttachment *>(attachment);
color = Json::getString(attachmentMap, "color", 0);
if (color) toColor(mesh->getColor(), color, true);
int vertexCount = 0;
pathAttatchment->_closed = Json::getInt(attachmentMap, "closed", 0) ? true : false;
pathAttatchment->_constantSpeed = Json::getInt(attachmentMap, "constantSpeed", 1) ? true
: false;
vertexCount = Json::getInt(attachmentMap, "vertexCount", 0);
readVertices(attachmentMap, pathAttatchment, vertexCount << 1);
mesh->_width = Json::getFloat(attachmentMap, "width", 32) * _scale;
mesh->_height = Json::getFloat(attachmentMap, "height", 32) * _scale;
mesh->_sequence = sequence;
pathAttatchment->_lengths.ensureCapacity(vertexCount / 3);
pathAttatchment->_lengths.setSize(vertexCount / 3, 0);
entry = Json::getItem(attachmentMap, "parent");
if (!entry) {
int verticesLength;
entry = Json::getItem(attachmentMap, "triangles");
mesh->_triangles.ensureCapacity(entry->_size);
mesh->_triangles.setSize(entry->_size, 0);
for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii)
mesh->_triangles[ii] = (unsigned short) entry->_valueInt;
curves = Json::getItem(attachmentMap, "lengths");
for (curves = curves->_child, ii = 0; curves; curves = curves->_next, ++ii)
pathAttatchment->_lengths[ii] = curves->_valueFloat * _scale;
color = Json::getString(attachmentMap, "color", NULL);
if (color) toColor(pathAttatchment->getColor(), color, true);
_attachmentLoader->configureAttachment(attachment);
break;
}
case AttachmentType_Point: {
attachment = _attachmentLoader->newPointAttachment(*skin, attachmentName);
entry = Json::getItem(attachmentMap, "uvs");
verticesLength = entry->_size;
mesh->_regionUVs.ensureCapacity(verticesLength);
mesh->_regionUVs.setSize(verticesLength, 0);
for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii)
mesh->_regionUVs[ii] = entry->_valueFloat;
PointAttachment *point = static_cast<PointAttachment *>(attachment);
readVertices(attachmentMap, mesh, verticesLength);
point->_x = Json::getFloat(attachmentMap, "x", 0) * _scale;
point->_y = Json::getFloat(attachmentMap, "y", 0) * _scale;
point->_rotation = Json::getFloat(attachmentMap, "rotation", 0);
color = Json::getString(attachmentMap, "color", NULL);
if (color) toColor(point->getColor(), color, true);
_attachmentLoader->configureAttachment(attachment);
break;
}
case AttachmentType_Clipping: {
attachment = _attachmentLoader->newClippingAttachment(*skin, attachmentName);
if (mesh->_region != NULL) mesh->updateRegion();
ClippingAttachment *clip = static_cast<ClippingAttachment *>(attachment);
mesh->_hullLength = Json::getInt(attachmentMap, "hull", 0);
int vertexCount = 0;
const char *end = Json::getString(attachmentMap, "end", 0);
if (end) clip->_endSlot = skeletonData->findSlot(end);
vertexCount = Json::getInt(attachmentMap, "vertexCount", 0) << 1;
readVertices(attachmentMap, clip, vertexCount);
color = Json::getString(attachmentMap, "color", NULL);
if (color) toColor(clip->getColor(), color, true);
_attachmentLoader->configureAttachment(attachment);
break;
}
entry = Json::getItem(attachmentMap, "edges");
if (entry) {
mesh->_edges.ensureCapacity(entry->_size);
mesh->_edges.setSize(entry->_size, 0);
for (entry = entry->_child, ii = 0; entry; entry = entry->_next, ++ii)
mesh->_edges[ii] = entry->_valueInt;
}
_attachmentLoader->configureAttachment(mesh);
} else {
bool inheritTimelines = Json::getInt(attachmentMap, "timelines", 1) ? true : false;
LinkedMesh *linkedMesh = new (__FILE__, __LINE__) LinkedMesh(mesh,
String(Json::getString(
attachmentMap,
"skin", 0)),
slot->getIndex(),
String(entry->_valueString),
inheritTimelines);
_linkedMeshes.add(linkedMesh);
}
break;
}
case AttachmentType_Boundingbox: {
attachment = _attachmentLoader->newBoundingBoxAttachment(*skin, attachmentName);
BoundingBoxAttachment *box = static_cast<BoundingBoxAttachment *>(attachment);
int vertexCount = Json::getInt(attachmentMap, "vertexCount", 0) << 1;
readVertices(attachmentMap, box, vertexCount);
color = Json::getString(attachmentMap, "color", NULL);
if (color) toColor(box->getColor(), color, true);
_attachmentLoader->configureAttachment(attachment);
break;
}
case AttachmentType_Path: {
attachment = _attachmentLoader->newPathAttachment(*skin, attachmentName);
PathAttachment *pathAttatchment = static_cast<PathAttachment *>(attachment);
int vertexCount = 0;
pathAttatchment->_closed = Json::getInt(attachmentMap, "closed", 0) ? true : false;
pathAttatchment->_constantSpeed = Json::getInt(attachmentMap, "constantSpeed", 1) ? true
: false;
vertexCount = Json::getInt(attachmentMap, "vertexCount", 0);
readVertices(attachmentMap, pathAttatchment, vertexCount << 1);
pathAttatchment->_lengths.ensureCapacity(vertexCount / 3);
pathAttatchment->_lengths.setSize(vertexCount / 3, 0);
curves = Json::getItem(attachmentMap, "lengths");
for (curves = curves->_child, ii = 0; curves; curves = curves->_next, ++ii)
pathAttatchment->_lengths[ii] = curves->_valueFloat * _scale;
color = Json::getString(attachmentMap, "color", NULL);
if (color) toColor(pathAttatchment->getColor(), color, true);
_attachmentLoader->configureAttachment(attachment);
break;
}
case AttachmentType_Point: {
attachment = _attachmentLoader->newPointAttachment(*skin, attachmentName);
PointAttachment *point = static_cast<PointAttachment *>(attachment);
point->_x = Json::getFloat(attachmentMap, "x", 0) * _scale;
point->_y = Json::getFloat(attachmentMap, "y", 0) * _scale;
point->_rotation = Json::getFloat(attachmentMap, "rotation", 0);
color = Json::getString(attachmentMap, "color", NULL);
if (color) toColor(point->getColor(), color, true);
_attachmentLoader->configureAttachment(attachment);
break;
}
case AttachmentType_Clipping: {
attachment = _attachmentLoader->newClippingAttachment(*skin, attachmentName);
ClippingAttachment *clip = static_cast<ClippingAttachment *>(attachment);
int vertexCount = 0;
const char *end = Json::getString(attachmentMap, "end", 0);
if (end) clip->_endSlot = skeletonData->findSlot(end);
vertexCount = Json::getInt(attachmentMap, "vertexCount", 0) << 1;
readVertices(attachmentMap, clip, vertexCount);
color = Json::getString(attachmentMap, "color", NULL);
if (color) toColor(clip->getColor(), color, true);
_attachmentLoader->configureAttachment(attachment);
break;
}
}
skin->setAttachment(slot->getIndex(), skinAttachmentName, attachment);

View File

@ -40,8 +40,8 @@ void SpineAnimationTrack::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_draw_order_threshold"), &SpineAnimationTrack::get_draw_order_threshold);
ClassDB::bind_method(D_METHOD("set_mix_blend", "mix_blend"), &SpineAnimationTrack::set_mix_blend);
ClassDB::bind_method(D_METHOD("get_mix_blend"), &SpineAnimationTrack::get_mix_blend);
ClassDB::bind_method(D_METHOD("set_blend_tree_mode", "blend_tree_mode_enabled"), &SpineAnimationTrack::set_blend_tree_mode);
ClassDB::bind_method(D_METHOD("get_blend_tree_mode"), &SpineAnimationTrack::get_blend_tree_mode);
ClassDB::bind_method(D_METHOD("set_blend_tree_mode", "blend_tree_mode_enabled"), &SpineAnimationTrack::set_blend_tree_mode);
ClassDB::bind_method(D_METHOD("get_blend_tree_mode"), &SpineAnimationTrack::get_blend_tree_mode);
ClassDB::bind_method(D_METHOD("set_debug", "debug"), &SpineAnimationTrack::set_debug);
ClassDB::bind_method(D_METHOD("get_debug"), &SpineAnimationTrack::get_debug);
@ -60,7 +60,7 @@ void SpineAnimationTrack::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::VARIANT_FLOAT, "attachment_threshold"), "set_attachment_threshold", "get_attachment_threshold");
ADD_PROPERTY(PropertyInfo(Variant::VARIANT_FLOAT, "draw_order_threshold"), "set_draw_order_threshold", "get_draw_order_threshold");
ADD_PROPERTY(PropertyInfo(Variant::INT, "mix_blend", PROPERTY_HINT_ENUM, "Setup,First,Replace,Add"), "set_mix_blend", "get_mix_blend");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "blend_tree_mode"), "set_blend_tree_mode", "get_blend_tree_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "blend_tree_mode"), "set_blend_tree_mode", "get_blend_tree_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "debug"), "set_debug", "get_debug");
}
@ -251,7 +251,7 @@ void SpineAnimationTrack::update_animation_state(const Variant &variant_sprite)
if (Engine::get_singleton()->is_editor_hint()) {
#ifdef TOOLS_ENABLED
if (blend_tree_mode) {
AnimationTreeEditor* tree_editor = AnimationTreeEditor::get_singleton();
AnimationTreeEditor *tree_editor = AnimationTreeEditor::get_singleton();
// When the animation tree dock is no longer visible, bail.
if (!tree_editor->is_visible_in_tree()) {
skeleton->setToSetupPose();
@ -512,11 +512,11 @@ SpineConstant::MixBlend SpineAnimationTrack::get_mix_blend() {
}
void SpineAnimationTrack::set_blend_tree_mode(bool _blend_tree_mode) {
blend_tree_mode = _blend_tree_mode;
blend_tree_mode = _blend_tree_mode;
}
bool SpineAnimationTrack::get_blend_tree_mode() {
return blend_tree_mode;
return blend_tree_mode;
}
void SpineAnimationTrack::set_debug(bool _debug) {

View File

@ -148,7 +148,7 @@ void SpineSprite::_bind_methods() {
// Filled in in _get_property_list()
}
SpineSprite::SpineSprite() : update_mode(SpineConstant::UpdateMode_Process), preview_animation("-- Empty --"), preview_frame(false), preview_time(0), skeleton_clipper(nullptr), modified_bones(false) {
SpineSprite::SpineSprite() : update_mode(SpineConstant::UpdateMode_Process), preview_skin("Default"), preview_animation("-- Empty --"), preview_frame(false), preview_time(0), skeleton_clipper(nullptr), modified_bones(false) {
skeleton_clipper = new spine::SkeletonClipping();
// One material per blend mode, shared across all sprites.
@ -346,9 +346,19 @@ void SpineSprite::_notification(int what) {
void SpineSprite::_get_property_list(List<PropertyInfo> *list) const {
if (!skeleton_data_res.is_valid() || !skeleton_data_res->is_skeleton_data_loaded()) return;
Vector<String> animation_names;
Vector<String> skin_names;
skeleton_data_res->get_animation_names(animation_names);
skeleton_data_res->get_skin_names(skin_names);
animation_names.insert(0, "-- Empty --");
PropertyInfo preview_skin_property;
preview_skin_property.name = "preview_skin";
preview_skin_property.type = Variant::STRING;
preview_skin_property.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
preview_skin_property.hint_string = String(",").join(skin_names);
preview_skin_property.hint = PROPERTY_HINT_ENUM;
list->push_back(preview_skin_property);
PropertyInfo preview_anim_property;
preview_anim_property.name = "preview_animation";
preview_anim_property.type = Variant::STRING;
@ -378,6 +388,11 @@ void SpineSprite::_get_property_list(List<PropertyInfo> *list) const {
}
bool SpineSprite::_get(const StringName &property, Variant &value) const {
if (property == "preview_skin") {
value = preview_skin;
return true;
}
if (property == "preview_animation") {
value = preview_animation;
return true;
@ -395,8 +410,14 @@ bool SpineSprite::_get(const StringName &property, Variant &value) const {
return false;
}
static void update_preview_animation(SpineSprite *sprite, const String &animation, bool frame, float time) {
static void update_preview_animation(SpineSprite *sprite, const String &skin, const String &animation, bool frame, float time) {
if (!sprite->get_skeleton().is_valid()) return;
if (EMPTY(skin) || skin == "Default") {
sprite->get_skeleton()->set_skin(nullptr);
} else {
sprite->get_skeleton()->set_skin_by_name(skin);
}
sprite->get_skeleton()->set_to_setup_pose();
if (EMPTY(animation) || animation == "-- Empty --") {
sprite->get_animation_state()->set_empty_animation(0, 0);
@ -412,22 +433,29 @@ static void update_preview_animation(SpineSprite *sprite, const String &animatio
}
bool SpineSprite::_set(const StringName &property, const Variant &value) {
if (property == "preview_skin") {
preview_skin = value;
update_preview_animation(this, preview_skin, preview_animation, preview_frame, preview_time);
NOTIFY_PROPERTY_LIST_CHANGED();
return true;
}
if (property == "preview_animation") {
preview_animation = value;
update_preview_animation(this, preview_animation, preview_frame, preview_time);
update_preview_animation(this, preview_skin, preview_animation, preview_frame, preview_time);
NOTIFY_PROPERTY_LIST_CHANGED();
return true;
}
if (property == "preview_frame") {
preview_frame = value;
update_preview_animation(this, preview_animation, preview_frame, preview_time);
update_preview_animation(this, preview_skin, preview_animation, preview_frame, preview_time);
return true;
}
if (property == "preview_time") {
preview_time = value;
update_preview_animation(this, preview_animation, preview_frame, preview_time);
update_preview_animation(this, preview_skin, preview_animation, preview_frame, preview_time);
return true;
}

View File

@ -47,6 +47,7 @@ protected:
Ref<SpineAnimationState> animation_state;
SpineConstant::UpdateMode update_mode;
String preview_skin;
String preview_animation;
bool preview_frame;
float preview_time;

View File

@ -3,8 +3,6 @@
#
set(DEPS_DIR "${CMAKE_CURRENT_LIST_DIR}/dependencies/")
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_OSX_ARCHITECTURES x86_64)
set(ONLY_ACTIVE_ARCH NO)
set(SFML_URL "https://www.sfml-dev.org/files/SFML-2.5.1-macOS-clang.tar.gz")
set(SFML_DIR ${DEPS_DIR}/SFML-2.5.1-macos-clang)
if (NOT EXISTS "${SFML_DIR}")