Added spine example

This commit is contained in:
WEREMSOFT 2020-01-09 22:23:30 +01:00
commit df3ed39a25
40 changed files with 15884 additions and 1 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,150 @@
/******************************************************************************
* 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 <spine/AnimationStateData.h>
#include <spine/extension.h>
typedef struct _ToEntry _ToEntry;
struct _ToEntry {
spAnimation* animation;
float duration;
_ToEntry* next;
};
_ToEntry* _ToEntry_create (spAnimation* to, float duration) {
_ToEntry* self = NEW(_ToEntry);
self->animation = to;
self->duration = duration;
return self;
}
void _ToEntry_dispose (_ToEntry* self) {
FREE(self);
}
/**/
typedef struct _FromEntry _FromEntry;
struct _FromEntry {
spAnimation* animation;
_ToEntry* toEntries;
_FromEntry* next;
};
_FromEntry* _FromEntry_create (spAnimation* from) {
_FromEntry* self = NEW(_FromEntry);
self->animation = from;
return self;
}
void _FromEntry_dispose (_FromEntry* self) {
FREE(self);
}
/**/
spAnimationStateData* spAnimationStateData_create (spSkeletonData* skeletonData) {
spAnimationStateData* self = NEW(spAnimationStateData);
CONST_CAST(spSkeletonData*, self->skeletonData) = skeletonData;
return self;
}
void spAnimationStateData_dispose (spAnimationStateData* self) {
_ToEntry* toEntry;
_ToEntry* nextToEntry;
_FromEntry* nextFromEntry;
_FromEntry* fromEntry = (_FromEntry*)self->entries;
while (fromEntry) {
toEntry = fromEntry->toEntries;
while (toEntry) {
nextToEntry = toEntry->next;
_ToEntry_dispose(toEntry);
toEntry = nextToEntry;
}
nextFromEntry = fromEntry->next;
_FromEntry_dispose(fromEntry);
fromEntry = nextFromEntry;
}
FREE(self);
}
void spAnimationStateData_setMixByName (spAnimationStateData* self, const char* fromName, const char* toName, float duration) {
spAnimation* to;
spAnimation* from = spSkeletonData_findAnimation(self->skeletonData, fromName);
if (!from) return;
to = spSkeletonData_findAnimation(self->skeletonData, toName);
if (!to) return;
spAnimationStateData_setMix(self, from, to, duration);
}
void spAnimationStateData_setMix (spAnimationStateData* self, spAnimation* from, spAnimation* to, float duration) {
/* Find existing FromEntry. */
_ToEntry* toEntry;
_FromEntry* fromEntry = (_FromEntry*)self->entries;
while (fromEntry) {
if (fromEntry->animation == from) {
/* Find existing ToEntry. */
toEntry = fromEntry->toEntries;
while (toEntry) {
if (toEntry->animation == to) {
toEntry->duration = duration;
return;
}
toEntry = toEntry->next;
}
break; /* Add new ToEntry to the existing FromEntry. */
}
fromEntry = fromEntry->next;
}
if (!fromEntry) {
fromEntry = _FromEntry_create(from);
fromEntry->next = (_FromEntry*)self->entries;
CONST_CAST(_FromEntry*, self->entries) = fromEntry;
}
toEntry = _ToEntry_create(to, duration);
toEntry->next = fromEntry->toEntries;
fromEntry->toEntries = toEntry;
}
float spAnimationStateData_getMix (spAnimationStateData* self, spAnimation* from, spAnimation* to) {
_FromEntry* fromEntry = (_FromEntry*)self->entries;
while (fromEntry) {
if (fromEntry->animation == from) {
_ToEntry* toEntry = fromEntry->toEntries;
while (toEntry) {
if (toEntry->animation == to) return toEntry->duration;
toEntry = toEntry->next;
}
}
fromEntry = fromEntry->next;
}
return self->defaultMix;
}

View file

@ -0,0 +1,38 @@
/******************************************************************************
* 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 <spine/Array.h>
#include <spine/extension.h>
_SP_ARRAY_IMPLEMENT_TYPE(spFloatArray, float)
_SP_ARRAY_IMPLEMENT_TYPE(spIntArray, int)
_SP_ARRAY_IMPLEMENT_TYPE(spShortArray, short)
_SP_ARRAY_IMPLEMENT_TYPE(spUnsignedShortArray, unsigned short)
_SP_ARRAY_IMPLEMENT_TYPE(spArrayFloatArray, spFloatArray*)
_SP_ARRAY_IMPLEMENT_TYPE(spArrayShortArray, spShortArray*)

View file

@ -0,0 +1,361 @@
/******************************************************************************
* 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 <spine/Atlas.h>
#include <ctype.h>
#include <spine/extension.h>
spAtlasPage* spAtlasPage_create(spAtlas* atlas, const char* name) {
spAtlasPage* self = NEW(spAtlasPage);
CONST_CAST(spAtlas*, self->atlas) = atlas;
MALLOC_STR(self->name, name);
return self;
}
void spAtlasPage_dispose(spAtlasPage* self) {
_spAtlasPage_disposeTexture(self);
FREE(self->name);
FREE(self);
}
/**/
spAtlasRegion* spAtlasRegion_create() {
return NEW(spAtlasRegion);
}
void spAtlasRegion_dispose(spAtlasRegion* self) {
FREE(self->name);
FREE(self->splits);
FREE(self->pads);
FREE(self);
}
/**/
typedef struct {
const char* begin;
const char* end;
} Str;
static void trim(Str* str) {
while (isspace((unsigned char)*str->begin) && str->begin < str->end)
(str->begin)++;
if (str->begin == str->end) return;
str->end--;
while (((unsigned char)*str->end == '\r') && str->end >= str->begin)
str->end--;
str->end++;
}
/* Tokenize string without modification. Returns 0 on failure. */
static int readLine(const char** begin, const char* end, Str* str) {
if (*begin == end) return 0;
str->begin = *begin;
/* Find next delimiter. */
while (*begin != end && **begin != '\n')
(*begin)++;
str->end = *begin;
trim(str);
if (*begin != end) (*begin)++;
return 1;
}
/* Moves str->begin past the first occurence of c. Returns 0 on failure. */
static int beginPast(Str* str, char c) {
const char* begin = str->begin;
while (1) {
char lastSkippedChar = *begin;
if (begin == str->end) return 0;
begin++;
if (lastSkippedChar == c) break;
}
str->begin = begin;
return 1;
}
/* Returns 0 on failure. */
static int readValue(const char** begin, const char* end, Str* str) {
readLine(begin, end, str);
if (!beginPast(str, ':')) return 0;
trim(str);
return 1;
}
/* Returns the number of tuple values read (1, 2, 4, or 0 for failure). */
static int readTuple(const char** begin, const char* end, Str tuple[]) {
int i;
Str str = { NULL, NULL };
readLine(begin, end, &str);
if (!beginPast(&str, ':')) return 0;
for (i = 0; i < 3; ++i) {
tuple[i].begin = str.begin;
if (!beginPast(&str, ',')) break;
tuple[i].end = str.begin - 2;
trim(&tuple[i]);
}
tuple[i].begin = str.begin;
tuple[i].end = str.end;
trim(&tuple[i]);
return i + 1;
}
static char* mallocString(Str* str) {
int length = (int)(str->end - str->begin);
char* string = MALLOC(char, length + 1);
memcpy(string, str->begin, length);
string[length] = '\0';
return string;
}
static int indexOf(const char** array, int count, Str* str) {
int length = (int)(str->end - str->begin);
int i;
for (i = count - 1; i >= 0; i--)
if (strncmp(array[i], str->begin, length) == 0) return i;
return 0;
}
static int equals(Str* str, const char* other) {
return strncmp(other, str->begin, str->end - str->begin) == 0;
}
static int toInt(Str* str) {
return (int)strtol(str->begin, (char**)&str->end, 10);
}
static spAtlas* abortAtlas(spAtlas* self) {
spAtlas_dispose(self);
return 0;
}
static const char* formatNames[] = { "", "Alpha", "Intensity", "LuminanceAlpha", "RGB565", "RGBA4444", "RGB888", "RGBA8888" };
static const char* textureFilterNames[] = { "", "Nearest", "Linear", "MipMap", "MipMapNearestNearest", "MipMapLinearNearest",
"MipMapNearestLinear", "MipMapLinearLinear" };
spAtlas* spAtlas_create(const char* begin, int length, const char* dir, void* rendererObject) {
spAtlas* self;
int count;
const char* end = begin + length;
int dirLength = (int)strlen(dir);
int needsSlash = dirLength > 0 && dir[dirLength - 1] != '/' && dir[dirLength - 1] != '\\';
spAtlasPage *page = 0;
spAtlasPage *lastPage = 0;
spAtlasRegion *lastRegion = 0;
Str str;
Str tuple[4];
self = NEW(spAtlas);
self->rendererObject = rendererObject;
while (readLine(&begin, end, &str)) {
if (str.end - str.begin == 0)
page = 0;
else if (!page) {
char* name = mallocString(&str);
char* path = MALLOC(char, dirLength + needsSlash + strlen(name) + 1);
memcpy(path, dir, dirLength);
if (needsSlash) path[dirLength] = '/';
strcpy(path + dirLength + needsSlash, name);
page = spAtlasPage_create(self, name);
FREE(name);
if (lastPage)
lastPage->next = page;
else
self->pages = page;
lastPage = page;
switch (readTuple(&begin, end, tuple)) {
case 0:
return abortAtlas(self);
case 2: /* size is only optional for an atlas packed with an old TexturePacker. */
page->width = toInt(tuple);
page->height = toInt(tuple + 1);
if (!readTuple(&begin, end, tuple)) return abortAtlas(self);
}
page->format = (spAtlasFormat)indexOf(formatNames, 8, tuple);
if (!readTuple(&begin, end, tuple)) return abortAtlas(self);
page->minFilter = (spAtlasFilter)indexOf(textureFilterNames, 8, tuple);
page->magFilter = (spAtlasFilter)indexOf(textureFilterNames, 8, tuple + 1);
if (!readValue(&begin, end, &str)) return abortAtlas(self);
page->uWrap = SP_ATLAS_CLAMPTOEDGE;
page->vWrap = SP_ATLAS_CLAMPTOEDGE;
if (!equals(&str, "none")) {
if (str.end - str.begin == 1) {
if (*str.begin == 'x')
page->uWrap = SP_ATLAS_REPEAT;
else if (*str.begin == 'y')
page->vWrap = SP_ATLAS_REPEAT;
}
else if (equals(&str, "xy")) {
page->uWrap = SP_ATLAS_REPEAT;
page->vWrap = SP_ATLAS_REPEAT;
}
}
_spAtlasPage_createTexture(page, path);
FREE(path);
} else {
spAtlasRegion *region = spAtlasRegion_create();
if (lastRegion)
lastRegion->next = region;
else
self->regions = region;
lastRegion = region;
region->page = page;
region->name = mallocString(&str);
if (!readValue(&begin, end, &str)) return abortAtlas(self);
if (equals(&str, "true"))
region->degrees = 90;
else if (equals(&str, "false"))
region->degrees = 0;
else
region->degrees = toInt(&str);
region->rotate = region->degrees == 90;
if (readTuple(&begin, end, tuple) != 2) return abortAtlas(self);
region->x = toInt(tuple);
region->y = toInt(tuple + 1);
if (readTuple(&begin, end, tuple) != 2) return abortAtlas(self);
region->width = toInt(tuple);
region->height = toInt(tuple + 1);
region->u = region->x / (float)page->width;
region->v = region->y / (float)page->height;
if (region->rotate) {
region->u2 = (region->x + region->height) / (float)page->width;
region->v2 = (region->y + region->width) / (float)page->height;
} else {
region->u2 = (region->x + region->width) / (float)page->width;
region->v2 = (region->y + region->height) / (float)page->height;
}
count = readTuple(&begin, end, tuple);
if (!count) return abortAtlas(self);
if (count == 4) { /* split is optional */
region->splits = MALLOC(int, 4);
region->splits[0] = toInt(tuple);
region->splits[1] = toInt(tuple + 1);
region->splits[2] = toInt(tuple + 2);
region->splits[3] = toInt(tuple + 3);
count = readTuple(&begin, end, tuple);
if (!count) return abortAtlas(self);
if (count == 4) { /* pad is optional, but only present with splits */
region->pads = MALLOC(int, 4);
region->pads[0] = toInt(tuple);
region->pads[1] = toInt(tuple + 1);
region->pads[2] = toInt(tuple + 2);
region->pads[3] = toInt(tuple + 3);
if (!readTuple(&begin, end, tuple)) return abortAtlas(self);
}
}
region->originalWidth = toInt(tuple);
region->originalHeight = toInt(tuple + 1);
readTuple(&begin, end, tuple);
region->offsetX = toInt(tuple);
region->offsetY = toInt(tuple + 1);
if (!readValue(&begin, end, &str)) return abortAtlas(self);
region->index = toInt(&str);
}
}
return self;
}
spAtlas* spAtlas_createFromFile(const char* path, void* rendererObject) {
int dirLength;
char *dir;
int length;
const char* data;
spAtlas* atlas = 0;
/* Get directory from atlas path. */
const char* lastForwardSlash = strrchr(path, '/');
const char* lastBackwardSlash = strrchr(path, '\\');
const char* lastSlash = lastForwardSlash > lastBackwardSlash ? lastForwardSlash : lastBackwardSlash;
if (lastSlash == path) lastSlash++; /* Never drop starting slash. */
dirLength = (int)(lastSlash ? lastSlash - path : 0);
dir = MALLOC(char, dirLength + 1);
memcpy(dir, path, dirLength);
dir[dirLength] = '\0';
data = _spUtil_readFile(path, &length);
if (data) atlas = spAtlas_create(data, length, dir, rendererObject);
FREE(data);
FREE(dir);
return atlas;
}
void spAtlas_dispose(spAtlas* self) {
spAtlasRegion* region, *nextRegion;
spAtlasPage* page = self->pages;
while (page) {
spAtlasPage* nextPage = page->next;
spAtlasPage_dispose(page);
page = nextPage;
}
region = self->regions;
while (region) {
nextRegion = region->next;
spAtlasRegion_dispose(region);
region = nextRegion;
}
FREE(self);
}
spAtlasRegion* spAtlas_findRegion(const spAtlas* self, const char* name) {
spAtlasRegion* region = self->regions;
while (region) {
if (strcmp(region->name, name) == 0) return region;
region = region->next;
}
return 0;
}

View file

@ -0,0 +1,100 @@
/******************************************************************************
* 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 <spine/AtlasAttachmentLoader.h>
#include <spine/extension.h>
spAttachment* _spAtlasAttachmentLoader_createAttachment (spAttachmentLoader* loader, spSkin* skin, spAttachmentType type,
const char* name, const char* path) {
spAtlasAttachmentLoader* self = SUB_CAST(spAtlasAttachmentLoader, loader);
switch (type) {
case SP_ATTACHMENT_REGION: {
spRegionAttachment* attachment;
spAtlasRegion* region = spAtlas_findRegion(self->atlas, path);
if (!region) {
_spAttachmentLoader_setError(loader, "Region not found: ", path);
return 0;
}
attachment = spRegionAttachment_create(name);
attachment->rendererObject = region;
spRegionAttachment_setUVs(attachment, region->u, region->v, region->u2, region->v2, region->rotate);
attachment->regionOffsetX = region->offsetX;
attachment->regionOffsetY = region->offsetY;
attachment->regionWidth = region->width;
attachment->regionHeight = region->height;
attachment->regionOriginalWidth = region->originalWidth;
attachment->regionOriginalHeight = region->originalHeight;
return SUPER(attachment);
}
case SP_ATTACHMENT_MESH:
case SP_ATTACHMENT_LINKED_MESH: {
spMeshAttachment* attachment;
spAtlasRegion* region = spAtlas_findRegion(self->atlas, path);
if (!region) {
_spAttachmentLoader_setError(loader, "Region not found: ", path);
return 0;
}
attachment = spMeshAttachment_create(name);
attachment->rendererObject = region;
attachment->regionU = region->u;
attachment->regionV = region->v;
attachment->regionU2 = region->u2;
attachment->regionV2 = region->v2;
attachment->regionRotate = region->rotate;
attachment->regionDegrees = region->degrees;
attachment->regionOffsetX = region->offsetX;
attachment->regionOffsetY = region->offsetY;
attachment->regionWidth = region->width;
attachment->regionHeight = region->height;
attachment->regionOriginalWidth = region->originalWidth;
attachment->regionOriginalHeight = region->originalHeight;
return SUPER(SUPER(attachment));
}
case SP_ATTACHMENT_BOUNDING_BOX:
return SUPER(SUPER(spBoundingBoxAttachment_create(name)));
case SP_ATTACHMENT_PATH:
return SUPER(SUPER(spPathAttachment_create(name)));
case SP_ATTACHMENT_POINT:
return SUPER(spPointAttachment_create(name));
case SP_ATTACHMENT_CLIPPING:
return SUPER(SUPER(spClippingAttachment_create(name)));
default:
_spAttachmentLoader_setUnknownTypeError(loader, type);
return 0;
}
UNUSED(skin);
}
spAtlasAttachmentLoader* spAtlasAttachmentLoader_create (spAtlas* atlas) {
spAtlasAttachmentLoader* self = NEW(spAtlasAttachmentLoader);
_spAttachmentLoader_init(SUPER(self), _spAttachmentLoader_deinit, _spAtlasAttachmentLoader_createAttachment, 0, 0);
self->atlas = atlas;
return self;
}

View file

@ -0,0 +1,64 @@
/******************************************************************************
* 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 <spine/Attachment.h>
#include <spine/extension.h>
#include <spine/Slot.h>
typedef struct _spAttachmentVtable {
void (*dispose) (spAttachment* self);
spAttachment* (*copy) (spAttachment* self);
} _spAttachmentVtable;
void _spAttachment_init (spAttachment* self, const char* name, spAttachmentType type, /**/
void (*dispose) (spAttachment* self), spAttachment* (*copy) (spAttachment* self)) {
CONST_CAST(_spAttachmentVtable*, self->vtable) = NEW(_spAttachmentVtable);
VTABLE(spAttachment, self)->dispose = dispose;
VTABLE(spAttachment, self)->copy = copy;
MALLOC_STR(self->name, name);
CONST_CAST(spAttachmentType, self->type) = type;
}
void _spAttachment_deinit (spAttachment* self) {
if (self->attachmentLoader) spAttachmentLoader_disposeAttachment(self->attachmentLoader, self);
FREE(self->vtable);
FREE(self->name);
}
spAttachment* spAttachment_copy (spAttachment* self) {
return VTABLE(spAttachment, self) ->copy(self);
}
void spAttachment_dispose (spAttachment* self) {
self->refCount--;
if (self->refCount <= 0)
VTABLE(spAttachment, self) ->dispose(self);
}

View file

@ -0,0 +1,96 @@
/******************************************************************************
* 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 <spine/AttachmentLoader.h>
#include <stdio.h>
#include <spine/extension.h>
typedef struct _spAttachmentLoaderVtable {
spAttachment* (*createAttachment) (spAttachmentLoader* self, spSkin* skin, spAttachmentType type, const char* name, const char* path);
void (*configureAttachment) (spAttachmentLoader* self, spAttachment*);
void (*disposeAttachment) (spAttachmentLoader* self, spAttachment*);
void (*dispose) (spAttachmentLoader* self);
} _spAttachmentLoaderVtable;
void _spAttachmentLoader_init (spAttachmentLoader* self,
void (*dispose) (spAttachmentLoader* self),
spAttachment* (*createAttachment) (spAttachmentLoader* self, spSkin* skin, spAttachmentType type, const char* name,
const char* path),
void (*configureAttachment) (spAttachmentLoader* self, spAttachment*),
void (*disposeAttachment) (spAttachmentLoader* self, spAttachment*)
) {
CONST_CAST(_spAttachmentLoaderVtable*, self->vtable) = NEW(_spAttachmentLoaderVtable);
VTABLE(spAttachmentLoader, self)->dispose = dispose;
VTABLE(spAttachmentLoader, self)->createAttachment = createAttachment;
VTABLE(spAttachmentLoader, self)->configureAttachment = configureAttachment;
VTABLE(spAttachmentLoader, self)->disposeAttachment = disposeAttachment;
}
void _spAttachmentLoader_deinit (spAttachmentLoader* self) {
FREE(self->vtable);
FREE(self->error1);
FREE(self->error2);
}
void spAttachmentLoader_dispose (spAttachmentLoader* self) {
VTABLE(spAttachmentLoader, self)->dispose(self);
FREE(self);
}
spAttachment* spAttachmentLoader_createAttachment (spAttachmentLoader* self, spSkin* skin, spAttachmentType type, const char* name,
const char* path) {
FREE(self->error1);
FREE(self->error2);
self->error1 = 0;
self->error2 = 0;
return VTABLE(spAttachmentLoader, self)->createAttachment(self, skin, type, name, path);
}
void spAttachmentLoader_configureAttachment (spAttachmentLoader* self, spAttachment* attachment) {
if (!VTABLE(spAttachmentLoader, self)->configureAttachment) return;
VTABLE(spAttachmentLoader, self)->configureAttachment(self, attachment);
}
void spAttachmentLoader_disposeAttachment (spAttachmentLoader* self, spAttachment* attachment) {
if (!VTABLE(spAttachmentLoader, self)->disposeAttachment) return;
VTABLE(spAttachmentLoader, self)->disposeAttachment(self, attachment);
}
void _spAttachmentLoader_setError (spAttachmentLoader* self, const char* error1, const char* error2) {
FREE(self->error1);
FREE(self->error2);
MALLOC_STR(self->error1, error1);
MALLOC_STR(self->error2, error2);
}
void _spAttachmentLoader_setUnknownTypeError (spAttachmentLoader* self, spAttachmentType type) {
char buffer[16];
sprintf(buffer, "%d", type);
_spAttachmentLoader_setError(self, "Unknown attachment type: ", buffer);
}

View file

@ -0,0 +1,287 @@
/******************************************************************************
* 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 <spine/Bone.h>
#include <spine/extension.h>
#include <stdio.h>
static int yDown;
void spBone_setYDown (int value) {
yDown = value;
}
int spBone_isYDown () {
return yDown;
}
spBone* spBone_create (spBoneData* data, spSkeleton* skeleton, spBone* parent) {
spBone* self = NEW(spBone);
CONST_CAST(spBoneData*, self->data) = data;
CONST_CAST(spSkeleton*, self->skeleton) = skeleton;
CONST_CAST(spBone*, self->parent) = parent;
CONST_CAST(float, self->a) = 1.0f;
CONST_CAST(float, self->d) = 1.0f;
spBone_setToSetupPose(self);
return self;
}
void spBone_dispose (spBone* self) {
FREE(self->children);
FREE(self);
}
void spBone_updateWorldTransform (spBone* self) {
spBone_updateWorldTransformWith(self, self->x, self->y, self->rotation, self->scaleX, self->scaleY, self->shearX, self->shearY);
}
void spBone_updateWorldTransformWith (spBone* self, float x, float y, float rotation, float scaleX, float scaleY, float shearX, float shearY) {
float cosine, sine;
float pa, pb, pc, pd;
spBone* parent = self->parent;
float sx = self->skeleton->scaleX;
float sy = self->skeleton->scaleY * (spBone_isYDown() ? -1 : 1);
self->ax = x;
self->ay = y;
self->arotation = rotation;
self->ascaleX = scaleX;
self->ascaleY = scaleY;
self->ashearX = shearX;
self->ashearY = shearY;
self->appliedValid = 1;
if (!parent) { /* Root bone. */
float rotationY = rotation + 90 + shearY;
CONST_CAST(float, self->a) = COS_DEG(rotation + shearX) * scaleX * sx;
CONST_CAST(float, self->b) = COS_DEG(rotationY) * scaleY * sx;
CONST_CAST(float, self->c) = SIN_DEG(rotation + shearX) * scaleX * sy;
CONST_CAST(float, self->d) = SIN_DEG(rotationY) * scaleY * sy;
CONST_CAST(float, self->worldX) = x * sx + self->skeleton->x;
CONST_CAST(float, self->worldY) = y * sy + self->skeleton->y;
return;
}
pa = parent->a;
pb = parent->b;
pc = parent->c;
pd = parent->d;
CONST_CAST(float, self->worldX) = pa * x + pb * y + parent->worldX;
CONST_CAST(float, self->worldY) = pc * x + pd * y + parent->worldY;
switch (self->data->transformMode) {
case SP_TRANSFORMMODE_NORMAL: {
float rotationY = rotation + 90 + shearY;
float la = COS_DEG(rotation + shearX) * scaleX;
float lb = COS_DEG(rotationY) * scaleY;
float lc = SIN_DEG(rotation + shearX) * scaleX;
float ld = SIN_DEG(rotationY) * scaleY;
CONST_CAST(float, self->a) = pa * la + pb * lc;
CONST_CAST(float, self->b) = pa * lb + pb * ld;
CONST_CAST(float, self->c) = pc * la + pd * lc;
CONST_CAST(float, self->d) = pc * lb + pd * ld;
return;
}
case SP_TRANSFORMMODE_ONLYTRANSLATION: {
float rotationY = rotation + 90 + shearY;
CONST_CAST(float, self->a) = COS_DEG(rotation + shearX) * scaleX;
CONST_CAST(float, self->b) = COS_DEG(rotationY) * scaleY;
CONST_CAST(float, self->c) = SIN_DEG(rotation + shearX) * scaleX;
CONST_CAST(float, self->d) = SIN_DEG(rotationY) * scaleY;
break;
}
case SP_TRANSFORMMODE_NOROTATIONORREFLECTION: {
float s = pa * pa + pc * pc;
float prx, rx, ry, la, lb, lc, ld;
if (s > 0.0001f) {
s = ABS(pa * pd - pb * pc) / s;
pb = pc * s;
pd = pa * s;
prx = ATAN2(pc, pa) * RAD_DEG;
} else {
pa = 0;
pc = 0;
prx = 90 - ATAN2(pd, pb) * RAD_DEG;
}
rx = rotation + shearX - prx;
ry = rotation + shearY - prx + 90;
la = COS_DEG(rx) * scaleX;
lb = COS_DEG(ry) * scaleY;
lc = SIN_DEG(rx) * scaleX;
ld = SIN_DEG(ry) * scaleY;
CONST_CAST(float, self->a) = pa * la - pb * lc;
CONST_CAST(float, self->b) = pa * lb - pb * ld;
CONST_CAST(float, self->c) = pc * la + pd * lc;
CONST_CAST(float, self->d) = pc * lb + pd * ld;
break;
}
case SP_TRANSFORMMODE_NOSCALE:
case SP_TRANSFORMMODE_NOSCALEORREFLECTION: {
float za, zc, s;
float r, zb, zd, la, lb, lc, ld;
cosine = COS_DEG(rotation); sine = SIN_DEG(rotation);
za = (pa * cosine + pb * sine) / sx;
zc = (pc * cosine + pd * sine) / sy;
s = SQRT(za * za + zc * zc);
if (s > 0.00001f) s = 1 / s;
za *= s;
zc *= s;
s = SQRT(za * za + zc * zc);
if (self->data->transformMode == SP_TRANSFORMMODE_NOSCALE && (pa * pd - pb * pc < 0) != (sx < 0 != sy < 0))
s = -s;
r = PI / 2 + ATAN2(zc, za);
zb = COS(r) * s;
zd = SIN(r) * s;
la = COS_DEG(shearX) * scaleX;
lb = COS_DEG(90 + shearY) * scaleY;
lc = SIN_DEG(shearX) * scaleX;
ld = SIN_DEG(90 + shearY) * scaleY;
CONST_CAST(float, self->a) = za * la + zb * lc;
CONST_CAST(float, self->b) = za * lb + zb * ld;
CONST_CAST(float, self->c) = zc * la + zd * lc;
CONST_CAST(float, self->d) = zc * lb + zd * ld;
break;
}
}
CONST_CAST(float, self->a) *= sx;
CONST_CAST(float, self->b) *= sx;
CONST_CAST(float, self->c) *= sy;
CONST_CAST(float, self->d) *= sy;
}
void spBone_setToSetupPose (spBone* self) {
self->x = self->data->x;
self->y = self->data->y;
self->rotation = self->data->rotation;
self->scaleX = self->data->scaleX;
self->scaleY = self->data->scaleY;
self->shearX = self->data->shearX;
self->shearY = self->data->shearY;
}
float spBone_getWorldRotationX (spBone* self) {
return ATAN2(self->c, self->a) * RAD_DEG;
}
float spBone_getWorldRotationY (spBone* self) {
return ATAN2(self->d, self->b) * RAD_DEG;
}
float spBone_getWorldScaleX (spBone* self) {
return SQRT(self->a * self->a + self->c * self->c);
}
float spBone_getWorldScaleY (spBone* self) {
return SQRT(self->b * self->b + self->d * self->d);
}
/** Computes the individual applied transform values from the world transform. This can be useful to perform processing using
* the applied transform after the world transform has been modified directly (eg, by a constraint).
* <p>
* Some information is ambiguous in the world transform, such as -1,-1 scale versus 180 rotation. */
void spBone_updateAppliedTransform (spBone* self) {
spBone* parent = self->parent;
self->appliedValid = 1;
if (!parent) {
self->ax = self->worldX;
self->ay = self->worldY;
self->arotation = ATAN2(self->c, self->a) * RAD_DEG;
self->ascaleX = SQRT(self->a * self->a + self->c * self->c);
self->ascaleY = SQRT(self->b * self->b + self->d * self->d);
self->ashearX = 0;
self->ashearY = ATAN2(self->a * self->b + self->c * self->d, self->a * self->d - self->b * self->c) * RAD_DEG;
} else {
float pa = parent->a, pb = parent->b, pc = parent->c, pd = parent->d;
float pid = 1 / (pa * pd - pb * pc);
float dx = self->worldX - parent->worldX, dy = self->worldY - parent->worldY;
float ia = pid * pd;
float id = pid * pa;
float ib = pid * pb;
float ic = pid * pc;
float ra = ia * self->a - ib * self->c;
float rb = ia * self->b - ib * self->d;
float rc = id * self->c - ic * self->a;
float rd = id * self->d - ic * self->b;
self->ax = (dx * pd * pid - dy * pb * pid);
self->ay = (dy * pa * pid - dx * pc * pid);
self->ashearX = 0;
self->ascaleX = SQRT(ra * ra + rc * rc);
if (self->ascaleX > 0.0001f) {
float det = ra * rd - rb * rc;
self->ascaleY = det / self->ascaleX;
self->ashearY = ATAN2(ra * rb + rc * rd, det) * RAD_DEG;
self->arotation = ATAN2(rc, ra) * RAD_DEG;
} else {
self->ascaleX = 0;
self->ascaleY = SQRT(rb * rb + rd * rd);
self->ashearY = 0;
self->arotation = 90 - ATAN2(rd, rb) * RAD_DEG;
}
}
}
void spBone_worldToLocal (spBone* self, float worldX, float worldY, float* localX, float* localY) {
float a = self->a, b = self->b, c = self->c, d = self->d;
float invDet = 1 / (a * d - b * c);
float x = worldX - self->worldX, y = worldY - self->worldY;
*localX = (x * d * invDet - y * b * invDet);
*localY = (y * a * invDet - x * c * invDet);
}
void spBone_localToWorld (spBone* self, float localX, float localY, float* worldX, float* worldY) {
float x = localX, y = localY;
*worldX = x * self->a + y * self->b + self->worldX;
*worldY = x * self->c + y * self->d + self->worldY;
}
float spBone_worldToLocalRotation (spBone* self, float worldRotation) {
float sine, cosine;
sine = SIN_DEG(worldRotation);
cosine = COS_DEG(worldRotation);
return ATAN2(self->a * sine - self->c * cosine, self->d * cosine - self->b * sine) * RAD_DEG + self->rotation - self->shearX;
}
float spBone_localToWorldRotation (spBone* self, float localRotation) {
float sine, cosine;
localRotation -= self->rotation - self->shearX;
sine = SIN_DEG(localRotation);
cosine = COS_DEG(localRotation);
return ATAN2(cosine * self->c + sine * self->d, cosine * self->a + sine * self->b) * RAD_DEG;
}
void spBone_rotateWorld (spBone* self, float degrees) {
float a = self->a, b = self->b, c = self->c, d = self->d;
float cosine = COS_DEG(degrees), sine = SIN_DEG(degrees);
CONST_CAST(float, self->a) = cosine * a - sine * c;
CONST_CAST(float, self->b) = cosine * b - sine * d;
CONST_CAST(float, self->c) = sine * a + cosine * c;
CONST_CAST(float, self->d) = sine * b + cosine * d;
CONST_CAST(int, self->appliedValid) = 0;
}

View file

@ -0,0 +1,47 @@
/******************************************************************************
* 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 <spine/BoneData.h>
#include <spine/extension.h>
spBoneData* spBoneData_create (int index, const char* name, spBoneData* parent) {
spBoneData* self = NEW(spBoneData);
CONST_CAST(int, self->index) = index;
MALLOC_STR(self->name, name);
CONST_CAST(spBoneData*, self->parent) = parent;
self->scaleX = 1;
self->scaleY = 1;
self->transformMode = SP_TRANSFORMMODE_NORMAL;
return self;
}
void spBoneData_dispose (spBoneData* self) {
FREE(self->name);
FREE(self);
}

View file

@ -0,0 +1,53 @@
/******************************************************************************
* 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 <spine/BoundingBoxAttachment.h>
#include <spine/extension.h>
void _spBoundingBoxAttachment_dispose (spAttachment* attachment) {
spBoundingBoxAttachment* self = SUB_CAST(spBoundingBoxAttachment, attachment);
_spVertexAttachment_deinit(SUPER(self));
FREE(self);
}
spAttachment* _spBoundingBoxAttachment_copy (spAttachment* attachment) {
spBoundingBoxAttachment* copy = spBoundingBoxAttachment_create(attachment->name);
spBoundingBoxAttachment* self = SUB_CAST(spBoundingBoxAttachment, attachment);
spVertexAttachment_copyTo(SUPER(self), SUPER(copy));
return SUPER(SUPER(copy));
}
spBoundingBoxAttachment* spBoundingBoxAttachment_create (const char* name) {
spBoundingBoxAttachment* self = NEW(spBoundingBoxAttachment);
_spVertexAttachment_init(SUPER(self));
_spAttachment_init(SUPER(SUPER(self)), name, SP_ATTACHMENT_BOUNDING_BOX, _spBoundingBoxAttachment_dispose, _spBoundingBoxAttachment_copy);
return self;
}

View file

@ -0,0 +1,55 @@
/******************************************************************************
* 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 <spine/ClippingAttachment.h>
#include <spine/extension.h>
void _spClippingAttachment_dispose (spAttachment* attachment) {
spClippingAttachment* self = SUB_CAST(spClippingAttachment, attachment);
_spVertexAttachment_deinit(SUPER(self));
FREE(self);
}
spAttachment* _spClippingAttachment_copy (spAttachment* attachment) {
spClippingAttachment* copy = spClippingAttachment_create(attachment->name);
spClippingAttachment* self = SUB_CAST(spClippingAttachment, attachment);
spVertexAttachment_copyTo(SUPER(self), SUPER(copy));
copy->endSlot = self->endSlot;
return SUPER(SUPER(copy));
}
spClippingAttachment* spClippingAttachment_create (const char* name) {
spClippingAttachment* self = NEW(spClippingAttachment);
_spVertexAttachment_init(SUPER(self));
_spAttachment_init(SUPER(SUPER(self)), name, SP_ATTACHMENT_CLIPPING, _spClippingAttachment_dispose, _spClippingAttachment_copy);
self->endSlot = 0;
return self;
}

View file

@ -0,0 +1,84 @@
/******************************************************************************
* 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 <spine/Color.h>
#include <spine/extension.h>
spColor* spColor_create() {
return MALLOC(spColor, 1);
}
void spColor_dispose(spColor* self) {
if (self) FREE(self);
}
void spColor_setFromFloats(spColor* self, float r, float g, float b, float a) {
self->r = r;
self->g = g;
self->b = b;
self->a = a;
spColor_clamp(self);
}
void spColor_setFromColor(spColor* self, spColor* otherColor) {
self->r = otherColor->r;
self->g = otherColor->g;
self->b = otherColor->b;
self->a = otherColor->a;
}
void spColor_addColor(spColor* self, spColor* otherColor) {
self->r += otherColor->r;
self->g += otherColor->g;
self->b += otherColor->b;
self->a += otherColor->a;
spColor_clamp(self);
}
void spColor_addFloats(spColor* self, float r, float g, float b, float a) {
self->r += r;
self->g += g;
self->b += b;
self->a += a;
spColor_clamp(self);
}
void spColor_clamp(spColor* self) {
if (self->r < 0) self->r = 0;
else if (self->r > 1) self->r = 1;
if (self->g < 0) self->g = 0;
else if (self->g > 1) self->g = 1;
if (self->b < 0) self->b = 0;
else if (self->b > 1) self->b = 1;
if (self->a < 0) self->a = 0;
else if (self->a > 1) self->a = 1;
}

View file

@ -0,0 +1,43 @@
/******************************************************************************
* 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 <spine/Event.h>
#include <spine/extension.h>
spEvent* spEvent_create (float time, spEventData* data) {
spEvent* self = NEW(spEvent);
CONST_CAST(spEventData*, self->data) = data;
CONST_CAST(float, self->time) = time;
return self;
}
void spEvent_dispose (spEvent* self) {
FREE(self->stringValue);
FREE(self);
}

View file

@ -0,0 +1,44 @@
/******************************************************************************
* 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 <spine/EventData.h>
#include <spine/extension.h>
spEventData* spEventData_create (const char* name) {
spEventData* self = NEW(spEventData);
MALLOC_STR(self->name, name);
return self;
}
void spEventData_dispose (spEventData* self) {
FREE(self->audioPath);
FREE(self->stringValue);
FREE(self->name);
FREE(self);
}

View file

@ -0,0 +1,275 @@
/******************************************************************************
* 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 <spine/IkConstraint.h>
#include <spine/Skeleton.h>
#include <spine/extension.h>
#include <float.h>
spIkConstraint *spIkConstraint_create(spIkConstraintData *data, const spSkeleton *skeleton) {
int i;
spIkConstraint *self = NEW(spIkConstraint);
CONST_CAST(spIkConstraintData*, self->data) = data;
self->bendDirection = data->bendDirection;
self->compress = data->compress;
self->stretch = data->stretch;
self->mix = data->mix;
self->softness = data->softness;
self->bonesCount = self->data->bonesCount;
self->bones = MALLOC(spBone*, self->bonesCount);
for (i = 0; i < self->bonesCount; ++i)
self->bones[i] = spSkeleton_findBone(skeleton, self->data->bones[i]->name);
self->target = spSkeleton_findBone(skeleton, self->data->target->name);
return self;
}
void spIkConstraint_dispose(spIkConstraint *self) {
FREE(self->bones);
FREE(self);
}
void spIkConstraint_apply(spIkConstraint *self) {
switch (self->bonesCount) {
case 1:
spIkConstraint_apply1(self->bones[0], self->target->worldX, self->target->worldY, self->compress, self->stretch, self->data->uniform, self->mix);
break;
case 2:
spIkConstraint_apply2(self->bones[0], self->bones[1], self->target->worldX, self->target->worldY, self->bendDirection, self->stretch, self->softness, self->mix);
break;
}
}
void spIkConstraint_apply1 (spBone* bone, float targetX, float targetY, int /*boolean*/ compress, int /*boolean*/ stretch, int /*boolean*/ uniform, float alpha) {
spBone* p = bone->parent;
float pa = p->a, pb = p->b, pc = p->c, pd = p->d;
float rotationIK = -bone->ashearX - bone->arotation;
float tx = 0, ty = 0, sx = 0, sy = 0, s = 0;
if (!bone->appliedValid) spBone_updateAppliedTransform(bone);
switch(bone->data->transformMode) {
case SP_TRANSFORMMODE_ONLYTRANSLATION:
tx = targetX - bone->worldX;
ty = targetY - bone->worldY;
break;
case SP_TRANSFORMMODE_NOROTATIONORREFLECTION: {
float ps;
rotationIK += ATAN2(pc, pa) * RAD_DEG;
ps = ABS(pa * pd - pb * pc) / (pa * pa + pc * pc);
pb = -pc * ps;
pd = pa * ps;
}
default: {
float x = targetX - p->worldX, y = targetY - p->worldY;
float d = pa * pd - pb * pc;
tx = (x * pd - y * pb) / d - bone->ax;
ty = (y * pa - x * pc) / d - bone->ay;
}
}
rotationIK += ATAN2(ty, tx) * RAD_DEG;
if (bone->ascaleX < 0) rotationIK += 180;
if (rotationIK > 180) rotationIK -= 360;
else if (rotationIK < -180) rotationIK += 360;
sx = bone->ascaleX;
sy = bone->ascaleY;
if (compress || stretch) {
float b, dd;
switch(bone->data->transformMode) {
case SP_TRANSFORMMODE_NOSCALE:
case SP_TRANSFORMMODE_NOSCALEORREFLECTION:
tx = targetX - bone->worldX;
ty = targetY - bone->worldY;
default: ;
}
b = bone->data->length * sx, dd = SQRT(tx * tx + ty * ty);
if ((compress && dd < b) || ((stretch && dd > b) && (b > 0.0001f))) {
s = (dd / b - 1) * alpha + 1;
sx *= s;
if (uniform) sy *= s;
}
}
spBone_updateWorldTransformWith(bone, bone->ax, bone->ay, bone->arotation + rotationIK * alpha, sx,
sy, bone->ashearX, bone->ashearY);
}
void spIkConstraint_apply2 (spBone* parent, spBone* child, float targetX, float targetY, int bendDir, int /*boolean*/ stretch, float softness, float alpha) {
float a, b, c, d;
float px, py, psx, sx, psy;
float cx, cy, csx, cwx, cwy;
int o1, o2, s2, u;
spBone* pp = parent->parent;
float tx, ty, dd, dx, dy, l1, l2, a1, a2, r, td, sd, p;
float id, x, y;
float aa, bb, ll, ta, c0, c1, c2;
if (alpha == 0) {
spBone_updateWorldTransform(child);
return;
}
if (!parent->appliedValid) spBone_updateAppliedTransform(parent);
if (!child->appliedValid) spBone_updateAppliedTransform(child);
px = parent->ax; py = parent->ay; psx = parent->ascaleX; sx = psx; psy = parent->ascaleY; csx = child->ascaleX;
if (psx < 0) {
psx = -psx;
o1 = 180;
s2 = -1;
} else {
o1 = 0;
s2 = 1;
}
if (psy < 0) {
psy = -psy;
s2 = -s2;
}
if (csx < 0) {
csx = -csx;
o2 = 180;
} else
o2 = 0;
r = psx - psy;
cx = child->ax;
u = (r < 0 ? -r : r) <= 0.0001f;
if (!u) {
cy = 0;
cwx = parent->a * cx + parent->worldX;
cwy = parent->c * cx + parent->worldY;
} else {
cy = child->ay;
cwx = parent->a * cx + parent->b * cy + parent->worldX;
cwy = parent->c * cx + parent->d * cy + parent->worldY;
}
a = pp->a;
b = pp->b;
c = pp->c;
d = pp->d;
id = 1 / (a * d - b * c);
x = cwx - pp->worldX;
y = cwy - pp->worldY;
dx = (x * d - y * b) * id - px;
dy = (y * a - x * c) * id - py;
l1 = SQRT(dx * dx + dy * dy);
l2 = child->data->length * csx;
if (l1 < 0.0001) {
spIkConstraint_apply1(parent, targetX, targetY, 0, stretch, 0, alpha);
spBone_updateWorldTransformWith(child, cx, cy, 0, child->ascaleX, child->ascaleY, child->ashearX, child->ashearY);
return;
}
x = targetX - pp->worldX;
y = targetY - pp->worldY;
tx = (x * d - y * b) * id - px;
ty = (y * a - x * c) * id - py;
dd = tx * tx + ty * ty;
if (softness != 0) {
softness *= psx * (csx + 1) / 2;
td = SQRT(dd);
sd = td - l1 - l2 * psx + softness;
if (sd > 0) {
p = MIN(1, sd / (softness * 2)) - 1;
p = (sd - softness * (1 - p * p)) / td;
tx -= p * tx;
ty -= p * ty;
dd = tx * tx + ty * ty;
}
}
if (u) {
float cosine;
l2 *= psx;
cosine = (dd - l1 * l1 - l2 * l2) / (2 * l1 * l2);
if (cosine < -1) cosine = -1;
else if (cosine > 1) {
cosine = 1;
if (stretch) sx *= (SQRT(dd) / (l1 + l2) - 1) * alpha + 1;
}
a2 = ACOS(cosine) * bendDir;
a = l1 + l2 * cosine;
b = l2 * SIN(a2);
a1 = ATAN2(ty * a - tx * b, tx * a + ty * b);
} else {
a = psx * l2; b = psy * l2;
aa = a * a, bb = b * b, ll = l1 * l1, ta = ATAN2(ty, tx);
c0 = bb * ll + aa * dd - aa * bb, c1 = -2 * bb * l1, c2 = bb - aa;
d = c1 * c1 - 4 * c2 * c0;
if (d >= 0) {
float q = SQRT(d), r0, r1;
if (c1 < 0) q = -q;
q = -(c1 + q) / 2;
r0 = q / c2; r1 = c0 / q;
r = ABS(r0) < ABS(r1) ? r0 : r1;
if (r * r <= dd) {
y = SQRT(dd - r * r) * bendDir;
a1 = ta - ATAN2(y, r);
a2 = ATAN2(y / psy, (r - l1) / psx);
goto break_outer;
}
}
{
float minAngle = PI, minX = l1 - a, minDist = minX * minX, minY = 0;
float maxAngle = 0, maxX = l1 + a, maxDist = maxX * maxX, maxY = 0;
c0 = -a * l1 / (aa - bb);
if (c0 >= -1 && c0 <= 1) {
c0 = ACOS(c0);
x = a * COS(c0) + l1;
y = b * SIN(c0);
d = x * x + y * y;
if (d < minDist) {
minAngle = c0;
minDist = d;
minX = x;
minY = y;
}
if (d > maxDist) {
maxAngle = c0;
maxDist = d;
maxX = x;
maxY = y;
}
}
if (dd <= (minDist + maxDist) / 2) {
a1 = ta - ATAN2(minY * bendDir, minX);
a2 = minAngle * bendDir;
} else {
a1 = ta - ATAN2(maxY * bendDir, maxX);
a2 = maxAngle * bendDir;
}
}
}
break_outer: {
float os = ATAN2(cy, cx) * s2;
a1 = (a1 - os) * RAD_DEG + o1 - parent->arotation;
if (a1 > 180) a1 -= 360;
else if (a1 < -180) a1 += 360;
spBone_updateWorldTransformWith(parent, px, py, parent->rotation + a1 * alpha, sx, parent->ascaleY, 0, 0);
a2 = ((a2 + os) * RAD_DEG - child->ashearX) * s2 + o2 - child->arotation;
if (a2 > 180) a2 -= 360;
else if (a2 < -180) a2 += 360;
spBone_updateWorldTransformWith(child, cx, cy, child->arotation + a2 * alpha, child->ascaleX, child->ascaleY, child->ashearX, child->ashearY);
}
}

View file

@ -0,0 +1,48 @@
/******************************************************************************
* 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 <spine/IkConstraintData.h>
#include <spine/extension.h>
spIkConstraintData* spIkConstraintData_create (const char* name) {
spIkConstraintData* self = NEW(spIkConstraintData);
MALLOC_STR(self->name, name);
self->bendDirection = 1;
self->compress = 0;
self->stretch = 0;
self->uniform = 0;
self->mix = 1;
return self;
}
void spIkConstraintData_dispose (spIkConstraintData* self) {
FREE(self->name);
FREE(self->bones);
FREE(self);
}

View file

@ -0,0 +1,461 @@
/*
Copyright (c) 2009, Dave Gamble
Copyright (c) 2013, Esoteric Software
Permission is hereby granted, dispose of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* Json */
/* JSON parser in C. */
#ifndef _DEFAULT_SOURCE
/* Bring strings.h definitions into string.h, where appropriate */
#define _DEFAULT_SOURCE
#endif
#ifndef _BSD_SOURCE
/* Bring strings.h definitions into string.h, where appropriate */
#define _BSD_SOURCE
#endif
#include "Json.h"
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h> /* strtod (C89), strtof (C99) */
#include <string.h> /* strcasecmp (4.4BSD - compatibility), _stricmp (_WIN32) */
#include <spine/extension.h>
#ifndef SPINE_JSON_DEBUG
/* Define this to do extra NULL and expected-character checking */
#define SPINE_JSON_DEBUG 0
#endif
static const char* ep;
const char* Json_getError (void) {
return ep;
}
static int Json_strcasecmp (const char* s1, const char* s2) {
/* TODO we may be able to elide these NULL checks if we can prove
the graph and input (only callsite is Json_getItem) should not have NULLs */
if (s1 && s2) {
#if defined(_WIN32)
return _stricmp(s1, s2);
#else
return strcasecmp( s1, s2 );
#endif
} else {
if (s1 < s2)
return -1; /* s1 is null, s2 is not */
else if (s1 == s2)
return 0; /* both are null */
else
return 1; /* s2 is nul s1 is not */
}
}
/* Internal constructor. */
static Json *Json_new (void) {
return (Json*)CALLOC(Json, 1);
}
/* Delete a Json structure. */
void Json_dispose (Json *c) {
Json *next;
while (c) {
next = c->next;
if (c->child) Json_dispose(c->child);
if (c->valueString) FREE(c->valueString);
if (c->name) FREE(c->name);
FREE(c);
c = next;
}
}
/* Parse the input text to generate a number, and populate the result into item. */
static const char* parse_number (Json *item, const char* num) {
double result = 0.0;
int negative = 0;
char* ptr = (char*)num;
if (*ptr == '-') {
negative = -1;
++ptr;
}
while (*ptr >= '0' && *ptr <= '9') {
result = result * 10.0 + (*ptr - '0');
++ptr;
}
if (*ptr == '.') {
double fraction = 0.0;
int n = 0;
++ptr;
while (*ptr >= '0' && *ptr <= '9') {
fraction = (fraction * 10.0) + (*ptr - '0');
++ptr;
++n;
}
result += fraction / POW(10.0, n);
}
if (negative) result = -result;
if (*ptr == 'e' || *ptr == 'E') {
double exponent = 0;
int expNegative = 0;
int n = 0;
++ptr;
if (*ptr == '-') {
expNegative = -1;
++ptr;
} else if (*ptr == '+') {
++ptr;
}
while (*ptr >= '0' && *ptr <= '9') {
exponent = (exponent * 10.0) + (*ptr - '0');
++ptr;
++n;
}
if (expNegative)
result = result / POW(10, exponent);
else
result = result * POW(10, exponent);
}
if (ptr != num) {
/* Parse success, number found. */
item->valueFloat = (float)result;
item->valueInt = (int)result;
item->type = Json_Number;
return ptr;
} else {
/* Parse failure, ep is set. */
ep = num;
return 0;
}
}
/* Parse the input text into an unescaped cstring, and populate item. */
static const unsigned char firstByteMark[7] = {0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC};
static const char* parse_string (Json *item, const char* str) {
const char* ptr = str + 1;
char* ptr2;
char* out;
int len = 0;
unsigned uc, uc2;
if (*str != '\"') { /* TODO: don't need this check when called from parse_value, but do need from parse_object */
ep = str;
return 0;
} /* not a string! */
while (*ptr != '\"' && *ptr && ++len)
if (*ptr++ == '\\') ptr++; /* Skip escaped quotes. */
out = MALLOC(char, len + 1); /* The length needed for the string, roughly. */
if (!out) return 0;
ptr = str + 1;
ptr2 = out;
while (*ptr != '\"' && *ptr) {
if (*ptr != '\\')
*ptr2++ = *ptr++;
else {
ptr++;
switch (*ptr) {
case 'b':
*ptr2++ = '\b';
break;
case 'f':
*ptr2++ = '\f';
break;
case 'n':
*ptr2++ = '\n';
break;
case 'r':
*ptr2++ = '\r';
break;
case 't':
*ptr2++ = '\t';
break;
case 'u': /* transcode utf16 to utf8. */
sscanf(ptr + 1, "%4x", &uc);
ptr += 4; /* get the unicode char. */
if ((uc >= 0xDC00 && uc <= 0xDFFF) || uc == 0) break; /* check for invalid. */
/* TODO provide an option to ignore surrogates, use unicode replacement character? */
if (uc >= 0xD800 && uc <= 0xDBFF) /* UTF16 surrogate pairs. */
{
if (ptr[1] != '\\' || ptr[2] != 'u') break; /* missing second-half of surrogate. */
sscanf(ptr + 3, "%4x", &uc2);
ptr += 6;
if (uc2 < 0xDC00 || uc2 > 0xDFFF) break; /* invalid second-half of surrogate. */
uc = 0x10000 + (((uc & 0x3FF) << 10) | (uc2 & 0x3FF));
}
len = 4;
if (uc < 0x80)
len = 1;
else if (uc < 0x800)
len = 2;
else if (uc < 0x10000) len = 3;
ptr2 += len;
switch (len) {
case 4:
*--ptr2 = ((uc | 0x80) & 0xBF);
uc >>= 6;
/* fallthrough */
case 3:
*--ptr2 = ((uc | 0x80) & 0xBF);
uc >>= 6;
/* fallthrough */
case 2:
*--ptr2 = ((uc | 0x80) & 0xBF);
uc >>= 6;
/* fallthrough */
case 1:
*--ptr2 = (uc | firstByteMark[len]);
}
ptr2 += len;
break;
default:
*ptr2++ = *ptr;
break;
}
ptr++;
}
}
*ptr2 = 0;
if (*ptr == '\"') ptr++; /* TODO error handling if not \" or \0 ? */
item->valueString = out;
item->type = Json_String;
return ptr;
}
/* Predeclare these prototypes. */
static const char* parse_value (Json *item, const char* value);
static const char* parse_array (Json *item, const char* value);
static const char* parse_object (Json *item, const char* value);
/* Utility to jump whitespace and cr/lf */
static const char* skip (const char* in) {
if (!in) return 0; /* must propagate NULL since it's often called in skip(f(...)) form */
while (*in && (unsigned char)*in <= 32)
in++;
return in;
}
/* Parse an object - create a new root, and populate. */
Json *Json_create (const char* value) {
Json *c;
ep = 0;
if (!value) return 0; /* only place we check for NULL other than skip() */
c = Json_new();
if (!c) return 0; /* memory fail */
value = parse_value(c, skip(value));
if (!value) {
Json_dispose(c);
return 0;
} /* parse failure. ep is set. */
return c;
}
/* Parser core - when encountering text, process appropriately. */
static const char* parse_value (Json *item, const char* value) {
/* Referenced by Json_create(), parse_array(), and parse_object(). */
/* Always called with the result of skip(). */
#if SPINE_JSON_DEBUG /* Checked at entry to graph, Json_create, and after every parse_ call. */
if (!value) return 0; /* Fail on null. */
#endif
switch (*value) {
case 'n': {
if (!strncmp(value + 1, "ull", 3)) {
item->type = Json_NULL;
return value + 4;
}
break;
}
case 'f': {
if (!strncmp(value + 1, "alse", 4)) {
item->type = Json_False;
/* calloc prevents us needing item->type = Json_False or valueInt = 0 here */
return value + 5;
}
break;
}
case 't': {
if (!strncmp(value + 1, "rue", 3)) {
item->type = Json_True;
item->valueInt = 1;
return value + 4;
}
break;
}
case '\"':
return parse_string(item, value);
case '[':
return parse_array(item, value);
case '{':
return parse_object(item, value);
case '-': /* fallthrough */
case '0': /* fallthrough */
case '1': /* fallthrough */
case '2': /* fallthrough */
case '3': /* fallthrough */
case '4': /* fallthrough */
case '5': /* fallthrough */
case '6': /* fallthrough */
case '7': /* fallthrough */
case '8': /* fallthrough */
case '9':
return parse_number(item, value);
default:
break;
}
ep = value;
return 0; /* failure. */
}
/* Build an array from input text. */
static const char* parse_array (Json *item, const char* value) {
Json *child;
#if SPINE_JSON_DEBUG /* unnecessary, only callsite (parse_value) verifies this */
if (*value != '[') {
ep = value;
return 0;
} /* not an array! */
#endif
item->type = Json_Array;
value = skip(value + 1);
if (*value == ']') return value + 1; /* empty array. */
item->child = child = Json_new();
if (!item->child) return 0; /* memory fail */
value = skip(parse_value(child, skip(value))); /* skip any spacing, get the value. */
if (!value) return 0;
item->size = 1;
while (*value == ',') {
Json *new_item = Json_new();
if (!new_item) return 0; /* memory fail */
child->next = new_item;
#if SPINE_JSON_HAVE_PREV
new_item->prev = child;
#endif
child = new_item;
value = skip(parse_value(child, skip(value + 1)));
if (!value) return 0; /* parse fail */
item->size++;
}
if (*value == ']') return value + 1; /* end of array */
ep = value;
return 0; /* malformed. */
}
/* Build an object from the text. */
static const char* parse_object (Json *item, const char* value) {
Json *child;
#if SPINE_JSON_DEBUG /* unnecessary, only callsite (parse_value) verifies this */
if (*value != '{') {
ep = value;
return 0;
} /* not an object! */
#endif
item->type = Json_Object;
value = skip(value + 1);
if (*value == '}') return value + 1; /* empty array. */
item->child = child = Json_new();
if (!item->child) return 0;
value = skip(parse_string(child, skip(value)));
if (!value) return 0;
child->name = child->valueString;
child->valueString = 0;
if (*value != ':') {
ep = value;
return 0;
} /* fail! */
value = skip(parse_value(child, skip(value + 1))); /* skip any spacing, get the value. */
if (!value) return 0;
item->size = 1;
while (*value == ',') {
Json *new_item = Json_new();
if (!new_item) return 0; /* memory fail */
child->next = new_item;
#if SPINE_JSON_HAVE_PREV
new_item->prev = child;
#endif
child = new_item;
value = skip(parse_string(child, skip(value + 1)));
if (!value) return 0;
child->name = child->valueString;
child->valueString = 0;
if (*value != ':') {
ep = value;
return 0;
} /* fail! */
value = skip(parse_value(child, skip(value + 1))); /* skip any spacing, get the value. */
if (!value) return 0;
item->size++;
}
if (*value == '}') return value + 1; /* end of array */
ep = value;
return 0; /* malformed. */
}
Json *Json_getItem (Json *object, const char* string) {
Json *c = object->child;
while (c && Json_strcasecmp(c->name, string))
c = c->next;
return c;
}
const char* Json_getString (Json* object, const char* name, const char* defaultValue) {
object = Json_getItem(object, name);
if (object) return object->valueString;
return defaultValue;
}
float Json_getFloat (Json* value, const char* name, float defaultValue) {
value = Json_getItem(value, name);
return value ? value->valueFloat : defaultValue;
}
int Json_getInt (Json* value, const char* name, int defaultValue) {
value = Json_getItem(value, name);
return value ? value->valueInt : defaultValue;
}

View file

@ -0,0 +1,83 @@
/*
Copyright (c) 2009 Dave Gamble
Permission is hereby granted, dispose of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/* Esoteric Software: Removed everything except parsing, shorter method names, more get methods, double to float, formatted. */
#ifndef SPINE_JSON_H_
#define SPINE_JSON_H_
#ifdef __cplusplus
extern "C" {
#endif
/* Json Types: */
#define Json_False 0
#define Json_True 1
#define Json_NULL 2
#define Json_Number 3
#define Json_String 4
#define Json_Array 5
#define Json_Object 6
#ifndef SPINE_JSON_HAVE_PREV
/* Spine doesn't use the "prev" link in the Json sibling lists. */
#define SPINE_JSON_HAVE_PREV 0
#endif
/* The Json structure: */
typedef struct Json {
struct Json* next;
#if SPINE_JSON_HAVE_PREV
struct Json* prev; /* next/prev allow you to walk array/object chains. Alternatively, use getSize/getItem */
#endif
struct Json* child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
int type; /* The type of the item, as above. */
int size; /* The number of children. */
const char* valueString; /* The item's string, if type==Json_String */
int valueInt; /* The item's number, if type==Json_Number */
float valueFloat; /* The item's number, if type==Json_Number */
const char* name; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
} Json;
/* Supply a block of JSON, and this returns a Json object you can interrogate. Call Json_dispose when finished. */
Json* Json_create (const char* value);
/* Delete a Json entity and all subentities. */
void Json_dispose (Json* json);
/* Get item "string" from object. Case insensitive. */
Json* Json_getItem (Json* json, const char* string);
const char* Json_getString (Json* json, const char* name, const char* defaultValue);
float Json_getFloat (Json* json, const char* name, float defaultValue);
int Json_getInt (Json* json, const char* name, int defaultValue);
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when Json_create() returns 0. 0 when Json_create() succeeds. */
const char* Json_getError (void);
#ifdef __cplusplus
}
#endif
#endif /* SPINE_JSON_H_ */

View file

@ -0,0 +1,211 @@
/******************************************************************************
* 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 <spine/MeshAttachment.h>
#include <spine/extension.h>
#include <stdio.h>
void _spMeshAttachment_dispose (spAttachment* attachment) {
spMeshAttachment* self = SUB_CAST(spMeshAttachment, attachment);
FREE(self->path);
FREE(self->uvs);
if (!self->parentMesh) {
_spVertexAttachment_deinit(SUPER(self));
FREE(self->regionUVs);
FREE(self->triangles);
FREE(self->edges);
} else
_spAttachment_deinit(attachment);
FREE(self);
}
spAttachment* _spMeshAttachment_copy (spAttachment* attachment) {
spMeshAttachment* copy;
spMeshAttachment* self = SUB_CAST(spMeshAttachment, attachment);
if (self->parentMesh)
return SUPER(SUPER(spMeshAttachment_newLinkedMesh(self)));
copy = spMeshAttachment_create(attachment->name);
copy->rendererObject = self->rendererObject;
copy->regionU = self->regionU;
copy->regionV = self->regionV;
copy->regionU2 = self->regionU2;
copy->regionV2 = self->regionV2;
copy->regionRotate = self->regionRotate;
copy->regionDegrees = self->regionDegrees;
copy->regionOffsetX = self->regionOffsetX;
copy->regionOffsetY = self->regionOffsetY;
copy->regionWidth = self->regionWidth;
copy->regionHeight = self->regionHeight;
copy->regionOriginalWidth = self->regionOriginalWidth;
copy->regionOriginalHeight = self->regionOriginalHeight;
MALLOC_STR(copy->path, self->path);
spColor_setFromColor(&copy->color, &self->color);
spVertexAttachment_copyTo(SUPER(self), SUPER(copy));
copy->regionUVs = MALLOC(float, SUPER(self)->worldVerticesLength);
memcpy(copy->regionUVs, self->regionUVs, SUPER(self)->worldVerticesLength * sizeof(float));
copy->uvs = MALLOC(float, SUPER(self)->worldVerticesLength);
memcpy(copy->uvs, self->uvs, SUPER(self)->worldVerticesLength * sizeof(float));
copy->trianglesCount = self->trianglesCount;
copy->triangles = MALLOC(unsigned short, self->trianglesCount);
memcpy(copy->triangles, self->triangles, self->trianglesCount * sizeof(short));
copy->hullLength = self->hullLength;
if (self->edgesCount > 0) {
copy->edgesCount = self->edgesCount;
copy->edges = MALLOC(int, self->edgesCount);
memcpy(copy->edges, self->edges, self->edgesCount * sizeof(int));
}
copy->width = self->width;
copy->height = self->height;
return SUPER(SUPER(copy));
}
spMeshAttachment* spMeshAttachment_newLinkedMesh (spMeshAttachment* self) {
spMeshAttachment* copy = spMeshAttachment_create(self->super.super.name);
copy->rendererObject = self->rendererObject;
copy->regionU = self->regionU;
copy->regionV = self->regionV;
copy->regionU2 = self->regionU2;
copy->regionV2 = self->regionV2;
copy->regionRotate = self->regionRotate;
copy->regionDegrees = self->regionDegrees;
copy->regionOffsetX = self->regionOffsetX;
copy->regionOffsetY = self->regionOffsetY;
copy->regionWidth = self->regionWidth;
copy->regionHeight = self->regionHeight;
copy->regionOriginalWidth = self->regionOriginalWidth;
copy->regionOriginalHeight = self->regionOriginalHeight;
MALLOC_STR(copy->path, self->path);
spColor_setFromColor(&copy->color, &self->color);
copy->super.deformAttachment = self->super.deformAttachment;
spMeshAttachment_setParentMesh(copy, self->parentMesh ? self->parentMesh : self);
spMeshAttachment_updateUVs(copy);
return copy;
}
spMeshAttachment* spMeshAttachment_create (const char* name) {
spMeshAttachment* self = NEW(spMeshAttachment);
_spVertexAttachment_init(SUPER(self));
spColor_setFromFloats(&self->color, 1, 1, 1, 1);
_spAttachment_init(SUPER(SUPER(self)), name, SP_ATTACHMENT_MESH, _spMeshAttachment_dispose, _spMeshAttachment_copy);
return self;
}
void spMeshAttachment_updateUVs (spMeshAttachment* self) {
int i, n;
float* uvs;
float u, v, width, height;
int verticesLength = SUPER(self)->worldVerticesLength;
FREE(self->uvs);
uvs = self->uvs = MALLOC(float, verticesLength);
n = verticesLength;
u = self->regionU; v = self->regionV;
switch (self->regionDegrees) {
case 90: {
float textureWidth = self->regionHeight / (self->regionU2 - self->regionU);
float textureHeight = self->regionWidth / (self->regionV2 - self->regionV);
u -= (self->regionOriginalHeight - self->regionOffsetY - self->regionHeight) / textureWidth;
v -= (self->regionOriginalWidth - self->regionOffsetX - self->regionWidth) / textureHeight;
width = self->regionOriginalHeight / textureWidth;
height = self->regionOriginalWidth / textureHeight;
for (i = 0; i < n; i += 2) {
uvs[i] = u + self->regionUVs[i + 1] * width;
uvs[i + 1] = v + (1 - self->regionUVs[i]) * height;
}
return;
}
case 180: {
float textureWidth = self->regionWidth / (self->regionU2 - self->regionU);
float textureHeight = self->regionHeight / (self->regionV2 - self->regionV);
u -= (self->regionOriginalWidth - self->regionOffsetX - self->regionWidth) / textureWidth;
v -= self->regionOffsetY / textureHeight;
width = self->regionOriginalWidth / textureWidth;
height = self->regionOriginalHeight / textureHeight;
for (i = 0; i < n; i += 2) {
uvs[i] = u + (1 - self->regionUVs[i]) * width;
uvs[i + 1] = v + (1 - self->regionUVs[i + 1]) * height;
}
return;
}
case 270: {
float textureHeight = self->regionHeight / (self->regionV2 - self->regionV);
float textureWidth = self->regionWidth / (self->regionU2 - self->regionU);
u -= self->regionOffsetY / textureWidth;
v -= self->regionOffsetX / textureHeight;
width = self->regionOriginalHeight / textureWidth;
height = self->regionOriginalWidth / textureHeight;
for (i = 0; i < n; i += 2) {
uvs[i] = u + (1 - self->regionUVs[i + 1]) * width;
uvs[i + 1] = v + self->regionUVs[i] * height;
}
return;
}
default: {
float textureWidth = self->regionWidth / (self->regionU2 - self->regionU);
float textureHeight = self->regionHeight / (self->regionV2 - self->regionV);
u -= self->regionOffsetX / textureWidth;
v -= (self->regionOriginalHeight - self->regionOffsetY - self->regionHeight) / textureHeight;
width = self->regionOriginalWidth / textureWidth;
height = self->regionOriginalHeight / textureHeight;
for (i = 0; i < n; i += 2) {
uvs[i] = u + self->regionUVs[i] * width;
uvs[i + 1] = v + self->regionUVs[i + 1] * height;
}
}
}
}
void spMeshAttachment_setParentMesh (spMeshAttachment* self, spMeshAttachment* parentMesh) {
CONST_CAST(spMeshAttachment*, self->parentMesh) = parentMesh;
if (parentMesh) {
self->super.bones = parentMesh->super.bones;
self->super.bonesCount = parentMesh->super.bonesCount;
self->super.vertices = parentMesh->super.vertices;
self->super.verticesCount = parentMesh->super.verticesCount;
self->regionUVs = parentMesh->regionUVs;
self->triangles = parentMesh->triangles;
self->trianglesCount = parentMesh->trianglesCount;
self->hullLength = parentMesh->hullLength;
self->super.worldVerticesLength = parentMesh->super.worldVerticesLength;
self->edges = parentMesh->edges;
self->edgesCount = parentMesh->edgesCount;
self->width = parentMesh->width;
self->height = parentMesh->height;
}
}

Some files were not shown because too many files have changed in this diff Show more