Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spine iOS #2504

Draft
wants to merge 23 commits into
base: 4.2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
554 changes: 554 additions & 0 deletions spine-cpp/spine-cpp-lite/spine-cpp-lite-codegen.py

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions spine-cpp/spine-cpp-lite/spine-cpp-lite.cpp
Expand Up @@ -1907,7 +1907,7 @@ void spine_slot_data_set_dark_color(spine_slot_data slot, float r, float g, floa
_slot->getDarkColor().set(r, g, b, a);
}

spine_bool spine_slot_data_has_dark_color(spine_slot_data slot) {
spine_bool spine_slot_data_get_has_dark_color(spine_slot_data slot) {
if (slot == nullptr) return 0;
SlotData *_slot = (SlotData *) slot;
return _slot->hasDarkColor() ? -1 : 0;
Expand Down Expand Up @@ -2161,7 +2161,7 @@ void spine_bone_data_set_inherit(spine_bone_data data, spine_inherit inherit) {
_data->setInherit((Inherit) inherit);
}

spine_bool spine_bone_data_is_skin_required(spine_bone_data data) {
spine_bool spine_bone_data_get_is_skin_required(spine_bone_data data) {
if (data == nullptr) return 0;
BoneData *_data = (BoneData *) data;
return _data->isSkinRequired() ? -1 : 0;
Expand Down Expand Up @@ -2491,7 +2491,7 @@ float spine_bone_get_a_shear_y(spine_bone bone) {
return _bone->getAShearY();
}

void spine_bone_set_shear_a_y(spine_bone bone, float shearY) {
void spine_bone_set_a_shear_y(spine_bone bone, float shearY) {
if (bone == nullptr) return;
Bone *_bone = (Bone *) bone;
_bone->setAShearY(shearY);
Expand Down Expand Up @@ -3377,6 +3377,12 @@ spine_bool spine_ik_constraint_data_get_uniform(spine_ik_constraint_data data) {
return _data->getUniform() ? -1 : 0;
}

void spine_ik_constraint_data_set_uniform(spine_ik_constraint_data data, spine_bool uniform) {
if (data == nullptr) return;
IkConstraintData *_data = (IkConstraintData *) data;
_data->setUniform(uniform);
}

float spine_ik_constraint_data_get_mix(spine_ik_constraint_data data) {
if (data == nullptr) return 0;
IkConstraintData *_data = (IkConstraintData *) data;
Expand Down Expand Up @@ -4662,7 +4668,7 @@ float spine_physics_constraint_get_last_time(spine_physics_constraint constraint
return _constraint->getLastTime();
}

void spine_physics_constraint_reset(spine_physics_constraint constraint) {
void spine_physics_constraint_reset_fully(spine_physics_constraint constraint) {
if (constraint == nullptr) return;
PhysicsConstraint *_constraint = (PhysicsConstraint *) constraint;
_constraint->reset();
Expand Down
35 changes: 31 additions & 4 deletions spine-cpp/spine-cpp-lite/spine-cpp-lite.h
Expand Up @@ -59,6 +59,8 @@
} name##_wrapper; \
typedef name##_wrapper *name;

// @start: opaque_types

SPINE_OPAQUE_TYPE(spine_skeleton)
SPINE_OPAQUE_TYPE(spine_skeleton_data)
SPINE_OPAQUE_TYPE(spine_bone)
Expand Down Expand Up @@ -103,8 +105,12 @@ SPINE_OPAQUE_TYPE(spine_skeleton_drawable)
SPINE_OPAQUE_TYPE(spine_skin_entry)
SPINE_OPAQUE_TYPE(spine_skin_entries)

// @end: opaque_types

typedef char utf8;

// @start: enums

typedef enum spine_blend_mode {
SPINE_BLEND_MODE_NORMAL = 0,
SPINE_BLEND_MODE_ADDITIVE,
Expand Down Expand Up @@ -177,8 +183,12 @@ typedef enum spine_physics {

} spine_physics;

// @end: enums

typedef int32_t spine_bool;

// @start: function_declarations

SPINE_CPP_LITE_EXPORT int32_t spine_major_version();
SPINE_CPP_LITE_EXPORT int32_t spine_minor_version();
SPINE_CPP_LITE_EXPORT void spine_enable_debug_extension(spine_bool enable);
Expand All @@ -203,7 +213,9 @@ SPINE_CPP_LITE_EXPORT utf8 *spine_atlas_get_image_path(spine_atlas atlas, int32_
SPINE_CPP_LITE_EXPORT utf8 *spine_atlas_get_error(spine_atlas atlas);
SPINE_CPP_LITE_EXPORT void spine_atlas_dispose(spine_atlas atlas);

// @ignore
SPINE_CPP_LITE_EXPORT spine_skeleton_data_result spine_skeleton_data_load_json(spine_atlas atlas, const utf8 *skeletonData);
// @ignore
SPINE_CPP_LITE_EXPORT spine_skeleton_data_result spine_skeleton_data_load_binary(spine_atlas atlas, const uint8_t *skeletonData, int32_t length);
SPINE_CPP_LITE_EXPORT utf8 *spine_skeleton_data_result_get_error(spine_skeleton_data_result result);
SPINE_CPP_LITE_EXPORT spine_skeleton_data spine_skeleton_data_result_get_data(spine_skeleton_data_result result);
Expand Down Expand Up @@ -248,7 +260,8 @@ SPINE_CPP_LITE_EXPORT void spine_skeleton_data_set_width(spine_skeleton_data dat
SPINE_CPP_LITE_EXPORT float spine_skeleton_data_get_height(spine_skeleton_data data);
SPINE_CPP_LITE_EXPORT void spine_skeleton_data_set_height(spine_skeleton_data data, float height);
SPINE_CPP_LITE_EXPORT const utf8 *spine_skeleton_data_get_version(spine_skeleton_data data);
// OMITTED setVersion()
// OMITTED setVersion()
// @ignore
SPINE_CPP_LITE_EXPORT const utf8 *spine_skeleton_data_get_hash(spine_skeleton_data data);
// OMITTED setHash()
SPINE_CPP_LITE_EXPORT const utf8 *spine_skeleton_data_get_images_path(spine_skeleton_data data);
Expand All @@ -260,16 +273,21 @@ SPINE_CPP_LITE_EXPORT float spine_skeleton_data_get_fps(spine_skeleton_data data
SPINE_CPP_LITE_EXPORT float spine_skeleton_data_get_reference_scale(spine_skeleton_data data);
SPINE_CPP_LITE_EXPORT void spine_skeleton_data_dispose(spine_skeleton_data data);

// @ignore
SPINE_CPP_LITE_EXPORT spine_skeleton_drawable spine_skeleton_drawable_create(spine_skeleton_data skeletonData);
// @ignore
SPINE_CPP_LITE_EXPORT spine_render_command spine_skeleton_drawable_render(spine_skeleton_drawable drawable);
SPINE_CPP_LITE_EXPORT void spine_skeleton_drawable_dispose(spine_skeleton_drawable drawable);
SPINE_CPP_LITE_EXPORT spine_skeleton spine_skeleton_drawable_get_skeleton(spine_skeleton_drawable drawable);
SPINE_CPP_LITE_EXPORT spine_animation_state spine_skeleton_drawable_get_animation_state(spine_skeleton_drawable drawable);
SPINE_CPP_LITE_EXPORT spine_animation_state_data spine_skeleton_drawable_get_animation_state_data(spine_skeleton_drawable drawable);
SPINE_CPP_LITE_EXPORT spine_animation_state_events spine_skeleton_drawable_get_animation_state_events(spine_skeleton_drawable drawable);

// @ignore
SPINE_CPP_LITE_EXPORT float *spine_render_command_get_positions(spine_render_command command);
// @ignore
SPINE_CPP_LITE_EXPORT float *spine_render_command_get_uvs(spine_render_command command);
// @ignore
SPINE_CPP_LITE_EXPORT int32_t *spine_render_command_get_colors(spine_render_command command);
SPINE_CPP_LITE_EXPORT int32_t spine_render_command_get_num_vertices(spine_render_command command);
SPINE_CPP_LITE_EXPORT uint16_t *spine_render_command_get_indices(spine_render_command command);
Expand Down Expand Up @@ -315,11 +333,13 @@ SPINE_CPP_LITE_EXPORT void spine_animation_state_set_time_scale(spine_animation_
// OMITTED enableQueue()
// OMITTED setManualTrackEntryDisposal()
// OMITTED getManualTrackEntryDisposal()
// @ignore
SPINE_CPP_LITE_EXPORT void spine_animation_state_dispose_track_entry(spine_animation_state state, spine_track_entry entry);

SPINE_CPP_LITE_EXPORT int32_t spine_animation_state_events_get_num_events(spine_animation_state_events events);
SPINE_CPP_LITE_EXPORT spine_event_type spine_animation_state_events_get_event_type(spine_animation_state_events events, int32_t index);
SPINE_CPP_LITE_EXPORT spine_track_entry spine_animation_state_events_get_track_entry(spine_animation_state_events events, int32_t index);
// @optional
SPINE_CPP_LITE_EXPORT spine_event spine_animation_state_events_get_event(spine_animation_state_events events, int32_t index);
SPINE_CPP_LITE_EXPORT void spine_animation_state_events_reset(spine_animation_state_events events);

Expand Down Expand Up @@ -410,6 +430,7 @@ SPINE_CPP_LITE_EXPORT int32_t spine_skeleton_get_num_path_constraints(spine_skel
SPINE_CPP_LITE_EXPORT spine_path_constraint *spine_skeleton_get_path_constraints(spine_skeleton skeleton);
SPINE_CPP_LITE_EXPORT int32_t spine_skeleton_get_num_physics_constraints(spine_skeleton skeleton);
SPINE_CPP_LITE_EXPORT spine_physics_constraint *spine_skeleton_get_physics_constraints(spine_skeleton skeleton);
// @optional
SPINE_CPP_LITE_EXPORT spine_skin spine_skeleton_get_skin(spine_skeleton skeleton);
SPINE_CPP_LITE_EXPORT spine_color spine_skeleton_get_color(spine_skeleton skeleton);
SPINE_CPP_LITE_EXPORT void spine_skeleton_set_color(spine_skeleton skeleton, float r, float g, float b, float a);
Expand Down Expand Up @@ -460,7 +481,7 @@ SPINE_CPP_LITE_EXPORT spine_color spine_slot_data_get_color(spine_slot_data slot
SPINE_CPP_LITE_EXPORT void spine_slot_data_set_color(spine_slot_data slot, float r, float g, float b, float a);
SPINE_CPP_LITE_EXPORT spine_color spine_slot_data_get_dark_color(spine_slot_data slot);
SPINE_CPP_LITE_EXPORT void spine_slot_data_set_dark_color(spine_slot_data slot, float r, float g, float b, float a);
SPINE_CPP_LITE_EXPORT spine_bool spine_slot_data_has_dark_color(spine_slot_data slot);
SPINE_CPP_LITE_EXPORT spine_bool spine_slot_data_get_has_dark_color(spine_slot_data slot);
SPINE_CPP_LITE_EXPORT void spine_slot_data_set_has_dark_color(spine_slot_data slot, spine_bool hasDarkColor);
SPINE_CPP_LITE_EXPORT const utf8 *spine_slot_data_get_attachment_name(spine_slot_data slot);
SPINE_CPP_LITE_EXPORT void spine_slot_data_set_attachment_name(spine_slot_data slot, const utf8 *attachmentName);
Expand Down Expand Up @@ -506,7 +527,7 @@ SPINE_CPP_LITE_EXPORT float spine_bone_data_get_shear_y(spine_bone_data data);
SPINE_CPP_LITE_EXPORT void spine_bone_data_set_shear_y(spine_bone_data data, float shearY);
SPINE_CPP_LITE_EXPORT spine_inherit spine_bone_data_get_inherit(spine_bone_data data);
SPINE_CPP_LITE_EXPORT void spine_bone_data_set_inherit(spine_bone_data data, spine_inherit inherit);
SPINE_CPP_LITE_EXPORT spine_bool spine_bone_data_is_skin_required(spine_bone_data data);
SPINE_CPP_LITE_EXPORT spine_bool spine_bone_data_get_is_skin_required(spine_bone_data data);
SPINE_CPP_LITE_EXPORT void spine_bone_data_set_is_skin_required(spine_bone_data data, spine_bool isSkinRequired);
SPINE_CPP_LITE_EXPORT spine_color spine_bone_data_get_color(spine_bone_data data);
SPINE_CPP_LITE_EXPORT void spine_bone_data_set_color(spine_bone_data data, float r, float g, float b, float a);
Expand Down Expand Up @@ -601,6 +622,7 @@ SPINE_CPP_LITE_EXPORT spine_color spine_point_attachment_get_color(spine_point_a
SPINE_CPP_LITE_EXPORT void spine_point_attachment_set_color(spine_point_attachment attachment, float r, float g, float b, float a);

SPINE_CPP_LITE_EXPORT void spine_region_attachment_update_region(spine_region_attachment attachment);
// @ignore
SPINE_CPP_LITE_EXPORT void spine_region_attachment_compute_world_vertices(spine_region_attachment attachment, spine_slot slot, float *worldVertices);
SPINE_CPP_LITE_EXPORT float spine_region_attachment_get_x(spine_region_attachment attachment);
SPINE_CPP_LITE_EXPORT void spine_region_attachment_set_x(spine_region_attachment attachment, float x);
Expand Down Expand Up @@ -630,6 +652,7 @@ SPINE_CPP_LITE_EXPORT int32_t spine_region_attachment_get_num_uvs(spine_region_a
SPINE_CPP_LITE_EXPORT float *spine_region_attachment_get_uvs(spine_region_attachment attachment);

SPINE_CPP_LITE_EXPORT int32_t spine_vertex_attachment_get_world_vertices_length(spine_vertex_attachment attachment);
// @ignore
SPINE_CPP_LITE_EXPORT void spine_vertex_attachment_compute_world_vertices(spine_vertex_attachment attachment, spine_slot slot, float *worldVertices);
// OMITTED getId()
SPINE_CPP_LITE_EXPORT int32_t spine_vertex_attachment_get_num_bones(spine_vertex_attachment attachment);
Expand Down Expand Up @@ -704,6 +727,7 @@ SPINE_CPP_LITE_EXPORT int32_t spine_skin_get_num_bones(spine_skin skin);
SPINE_CPP_LITE_EXPORT spine_bone_data *spine_skin_get_bones(spine_skin skin);
SPINE_CPP_LITE_EXPORT int32_t spine_skin_get_num_constraints(spine_skin skin);
SPINE_CPP_LITE_EXPORT spine_constraint_data *spine_skin_get_constraints(spine_skin skin);
// @ignore
SPINE_CPP_LITE_EXPORT spine_skin spine_skin_create(const utf8 *name);
SPINE_CPP_LITE_EXPORT void spine_skin_dispose(spine_skin skin);

Expand Down Expand Up @@ -806,6 +830,7 @@ SPINE_CPP_LITE_EXPORT float spine_transform_constraint_get_mix_shear_y(spine_tra
SPINE_CPP_LITE_EXPORT void spine_transform_constraint_set_mix_shear_y(spine_transform_constraint constraint, float mixShearY);
SPINE_CPP_LITE_EXPORT spine_bool spine_transform_constraint_get_is_active(spine_transform_constraint constraint);
SPINE_CPP_LITE_EXPORT void spine_transform_constraint_set_is_active(spine_transform_constraint constraint, spine_bool isActive);

// OMITTED setToSetupPose()

SPINE_CPP_LITE_EXPORT int32_t spine_path_constraint_data_get_num_bones(spine_path_constraint_data data);
Expand Down Expand Up @@ -949,7 +974,7 @@ SPINE_CPP_LITE_EXPORT void spine_physics_constraint_set_remaining(spine_physics_
SPINE_CPP_LITE_EXPORT float spine_physics_constraint_get_remaining(spine_physics_constraint constraint);
SPINE_CPP_LITE_EXPORT void spine_physics_constraint_set_last_time(spine_physics_constraint constraint, float value);
SPINE_CPP_LITE_EXPORT float spine_physics_constraint_get_last_time(spine_physics_constraint constraint);
SPINE_CPP_LITE_EXPORT void spine_physics_constraint_reset(spine_physics_constraint constraint);
SPINE_CPP_LITE_EXPORT void spine_physics_constraint_reset_fully(spine_physics_constraint constraint);
// Omitted setToSetupPose()
SPINE_CPP_LITE_EXPORT void spine_physics_constraint_update(spine_physics_constraint data, spine_physics physics);
SPINE_CPP_LITE_EXPORT void spine_physics_constraint_translate(spine_physics_constraint data, float x, float y);
Expand Down Expand Up @@ -995,4 +1020,6 @@ SPINE_CPP_LITE_EXPORT void spine_texture_region_set_original_width(spine_texture
SPINE_CPP_LITE_EXPORT int32_t spine_texture_region_get_original_height(spine_texture_region textureRegion);
SPINE_CPP_LITE_EXPORT void spine_texture_region_set_original_height(spine_texture_region textureRegion, int32_t originalHeight);

// @end: function_declarations

#endif
4 changes: 2 additions & 2 deletions spine-flutter/example/lib/animation_state_events.dart
Expand Up @@ -23,14 +23,14 @@ class AnimationStateEvents extends StatelessWidget {
controller.animationState.setListener((type, trackEntry, event) {
if (type == EventType.event) {
print(
"User event: { name: ${event?.getData().getName()}, intValue: ${event?.getIntValue()}, floatValue: intValue: ${event?.getFloatValue()}, stringValue: ${event?.getStringValue()} }");
"User event: { name: ${event?.getData().getName()}, intValue: ${event?.getIntValue()}, floatValue: ${event?.getFloatValue()}, stringValue: ${event?.getStringValue()} }");
}
});
print("Current: ${controller.animationState.getCurrent(0)?.getAnimation().getName()}");
});

return Scaffold(
appBar: AppBar(title: const Text('Spineboy')),
appBar: AppBar(title: const Text('Animation State Listener')),
body: Column(children: [
const Text("See output in console!"),
Expanded(child: SpineWidget.fromAsset("assets/spineboy.atlas", "assets/spineboy-pro.skel", controller))
Expand Down
1 change: 0 additions & 1 deletion spine-flutter/example/lib/physics.dart
Expand Up @@ -41,7 +41,6 @@ class PhysicsState extends State<PhysicsTest> {
late SpineWidgetController controller;
Offset? mousePosition;
Offset? lastMousePosition;
Offset? delta;

@override
void initState() {
Expand Down
2 changes: 1 addition & 1 deletion spine-flutter/lib/spine_widget.dart
Expand Up @@ -657,7 +657,7 @@ class _SpineRenderObject extends RenderBox {
..translate(offsetX, offsetY)
..scale(scaleX, scaleY)
..translate(x, y);
_controller._setCoordinateTransform(x + offsetX / scaleY, y + offsetY / scaleY, scaleX, scaleY);
_controller._setCoordinateTransform(x + offsetX / scaleX, y + offsetY / scaleY, scaleX, scaleY);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion spine-flutter/pubspec.yaml
Expand Up @@ -45,4 +45,4 @@ flutter:
- lib/assets/libspine_flutter.js
- lib/assets/libspine_flutter.wasm
- src/spine-cpp-lite/spine-cpp-lite.cpp
- src/spine-cpp-lite/spine-cpp-lite.h
- ../spine-cpp/spine-cpp-lite/spine-cpp-lite.h
8 changes: 8 additions & 0 deletions spine-ios/.gitignore
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
16 changes: 16 additions & 0 deletions spine-ios/CHANGELOG.md
@@ -0,0 +1,16 @@
# Changelog

# Unreleased

- Add `spine-iOS` SPM package & example app (#1)
- Basic Mesh Rendering (#2)
- Spine C++ Swift Wrapper (#3)
- Load `Atlas` & `SkeletonData` (#4)
- Generate Swift classes from `spine-cpp-lite.h` (#5)
- Draw `SkeletonData` render commands (#6)
- Add `BoundsProvider` (#7)
- Support `SpineController` & `Event` callbacks (#8)
- Support `DressUp` sample (#9)
- Add `Physics` sample (#10)
- Add `DebugRendering` sample (#11)
- Move remaining files to SPM package (#12)
91 changes: 91 additions & 0 deletions spine-ios/Example/.gitignore
@@ -0,0 +1,91 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

## Obj-C/Swift specific
*.hmap

## App packaging
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
# *.xcodeproj
#
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
# .swiftpm

.build/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
#
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build/

# Accio dependency management
Dependencies/
.accio/

# fastlane
#
# It is recommended to not store the screenshots in the git repo.
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

# Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/
.DS_store