diff --git a/CHANGELOG.md b/CHANGELOG.md index ab39df551..8785fbe17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -362,6 +362,9 @@ * Added `SkeletonGraphicCustomMaterials` component, providing functionality to override materials and textures of a `SkeletonGraphic`, similar to `SkeletonRendererCustomMaterials`. Note: overriding materials or textures per slot is not provided due to structural limitations. * Added **Root Motion support** for `SkeletonAnimation`, `SkeletonMecanim` and `SkeletonGraphic` via new components `SkeletonRootMotion` and `SkeletonMecanimRootMotion`. The `SkeletonAnimation` and `SkeletonGraphic` component Inspector now provides a line `Root Motion` with `Add Component` and `Remove Component` buttons to add/remove the new `SkeletonRootMotion` component to your GameObject. The `SkeletonMecanim` Inspector detects whether root motion is enabled at the `Animator` component and adds a `SkeletonMecanimRootMotion` component automatically. * `SkeletonMecanim` now provides an additional `Custom MixMode` parameter under `Mecanim Translator`. It is enabled by default in version 3.8 to maintain current behaviour, using the set `Mix Mode` for each Mecanim layer. When disabled, `SkeletonMecanim` will use the recommended `MixMode` according to the layer blend mode. Additional information can be found in the [Mecanim Translator section](http://esotericsoftware.com/spine-unity#Parameters-for-animation-blending-control) on the spine-unity documentation pages. + * Added **SkeletonGraphic Timeline support**. Added supprot for multi-track Timeline preview in the Editor outside of play mode (multi-track scrubbing). See the [Timeline-Extension-UPM-Package](http://esotericsoftware.com/spine-unity#Timeline-Extension-UPM-Package) section of the spine-unity documentation for more information. + * Added support for double-sided lighting at all `SkeletonLit` shaders (including URP and LWRP packages). + * Added frustum culling update mode parameters `Update When Invisible` (Inspector parameter) and `UpdateMode` (available via code) to all Skeleton components. This provides a simple way to disable certain updates when the `Renderer` is no longer visible (outside all cameras, culled in frustum culling). The new `UpdateMode` property allows disabling updates at a finer granularity level than disabling the whole component. Available modes are: `Nothing`, `OnlyAnimationStatus`, `EverythingExceptMesh` and `FullUpdate`. * **Changes of default values** * `SkeletonMecanim`'s `Layer Mix Mode` now defaults to `MixMode.MixNext` instead of `MixMode.MixAlways`. diff --git a/spine-cocos2dx/src/spine/SkeletonRenderer.cpp b/spine-cocos2dx/src/spine/SkeletonRenderer.cpp index d7331158f..07471159f 100644 --- a/spine-cocos2dx/src/spine/SkeletonRenderer.cpp +++ b/spine-cocos2dx/src/spine/SkeletonRenderer.cpp @@ -34,1049 +34,1041 @@ USING_NS_CC; - namespace spine { - namespace { - Cocos2dTextureLoader textureLoader; +namespace { + Cocos2dTextureLoader textureLoader; - int computeTotalCoordCount(Skeleton& skeleton, int startSlotIndex, int endSlotIndex); - cocos2d::Rect computeBoundingRect(const float* coords, int vertexCount); - void interleaveCoordinates(float* dst, const float* src, int vertexCount, int dstStride); - BlendFunc makeBlendFunc(BlendMode blendMode, bool premultipliedAlpha); - void transformWorldVertices(float* dstCoord, int coordCount, Skeleton& skeleton, int startSlotIndex, int endSlotIndex); - bool cullRectangle(Renderer* renderer, const Mat4& transform, const cocos2d::Rect& rect); - Color4B ColorToColor4B(const Color& color); - bool slotIsOutRange(Slot& slot, int startSlotIndex, int endSlotIndex); - bool nothingToDraw(Slot& slot, int startSlotIndex, int endSlotIndex); - } + int computeTotalCoordCount(Skeleton& skeleton, int startSlotIndex, int endSlotIndex); + cocos2d::Rect computeBoundingRect(const float* coords, int vertexCount); + void interleaveCoordinates(float* dst, const float* src, int vertexCount, int dstStride); + BlendFunc makeBlendFunc(BlendMode blendMode, bool premultipliedAlpha); + void transformWorldVertices(float* dstCoord, int coordCount, Skeleton& skeleton, int startSlotIndex, int endSlotIndex); + bool cullRectangle(Renderer* renderer, const Mat4& transform, const cocos2d::Rect& rect); + Color4B ColorToColor4B(const Color& color); + bool slotIsOutRange(Slot& slot, int startSlotIndex, int endSlotIndex); + bool nothingToDraw(Slot& slot, int startSlotIndex, int endSlotIndex); +} // C Variable length array #ifdef _MSC_VER - // VLA not supported, use _malloca - #define VLA(type, arr, count) \ - type* arr = static_cast( _malloca(sizeof(type) * count) ) - #define VLA_FREE(arr) do { _freea(arr); } while(false) +// VLA not supported, use _malloca +#define VLA(type, arr, count) \ + type* arr = static_cast( _malloca(sizeof(type) * count) ) +#define VLA_FREE(arr) do { _freea(arr); } while(false) #else - #define VLA(type, arr, count) \ - type arr[count] - #define VLA_FREE(arr) +#define VLA(type, arr, count) \ + type arr[count] +#define VLA_FREE(arr) #endif +SkeletonRenderer* SkeletonRenderer::createWithSkeleton(Skeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData) { + SkeletonRenderer* node = new SkeletonRenderer(skeleton, ownsSkeleton, ownsSkeletonData); + node->autorelease(); + return node; +} - SkeletonRenderer* SkeletonRenderer::createWithSkeleton(Skeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData) { - SkeletonRenderer* node = new SkeletonRenderer(skeleton, ownsSkeleton, ownsSkeletonData); - node->autorelease(); - return node; - } +SkeletonRenderer* SkeletonRenderer::createWithData (SkeletonData* skeletonData, bool ownsSkeletonData) { + SkeletonRenderer* node = new SkeletonRenderer(skeletonData, ownsSkeletonData); + node->autorelease(); + return node; +} - SkeletonRenderer* SkeletonRenderer::createWithData (SkeletonData* skeletonData, bool ownsSkeletonData) { - SkeletonRenderer* node = new SkeletonRenderer(skeletonData, ownsSkeletonData); - node->autorelease(); - return node; - } +SkeletonRenderer* SkeletonRenderer::createWithFile (const std::string& skeletonDataFile, Atlas* atlas, float scale) { + SkeletonRenderer* node = new SkeletonRenderer(skeletonDataFile, atlas, scale); + node->autorelease(); + return node; +} - SkeletonRenderer* SkeletonRenderer::createWithFile (const std::string& skeletonDataFile, Atlas* atlas, float scale) { - SkeletonRenderer* node = new SkeletonRenderer(skeletonDataFile, atlas, scale); - node->autorelease(); - return node; - } +SkeletonRenderer* SkeletonRenderer::createWithFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) { + SkeletonRenderer* node = new SkeletonRenderer(skeletonDataFile, atlasFile, scale); + node->autorelease(); + return node; +} - SkeletonRenderer* SkeletonRenderer::createWithFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) { - SkeletonRenderer* node = new SkeletonRenderer(skeletonDataFile, atlasFile, scale); - node->autorelease(); - return node; - } +void SkeletonRenderer::initialize () { + _clipper = new (__FILE__, __LINE__) SkeletonClipping(); - void SkeletonRenderer::initialize () { - _clipper = new (__FILE__, __LINE__) SkeletonClipping(); + _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; + setOpacityModifyRGB(true); - _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; - setOpacityModifyRGB(true); + setTwoColorTint(false); - setTwoColorTint(false); + _skeleton->setToSetupPose(); + _skeleton->updateWorldTransform(); +} - _skeleton->setToSetupPose(); - _skeleton->updateWorldTransform(); - } - - void SkeletonRenderer::setupGLProgramState (bool twoColorTintEnabled) { - if (twoColorTintEnabled) { +void SkeletonRenderer::setupGLProgramState (bool twoColorTintEnabled) { + if (twoColorTintEnabled) { #if COCOS2D_VERSION < 0x00040000 - setGLProgramState(SkeletonTwoColorBatch::getInstance()->getTwoColorTintProgramState()); + setGLProgramState(SkeletonTwoColorBatch::getInstance()->getTwoColorTintProgramState()); #endif - return; + return; + } + + Texture2D *texture = nullptr; + for (int i = 0, n = _skeleton->getSlots().size(); i < n; i++) { + Slot* slot = _skeleton->getDrawOrder()[i]; + Attachment* const attachment = slot->getAttachment(); + if (!attachment) continue; + if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) { + RegionAttachment* regionAttachment = static_cast(attachment); + texture = static_cast(regionAttachment->getRendererObject())->_texture; + } else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { + MeshAttachment* meshAttachment = static_cast(attachment); + texture = static_cast(meshAttachment->getRendererObject())->_texture; + } else { + continue; } - Texture2D *texture = nullptr; - for (int i = 0, n = _skeleton->getSlots().size(); i < n; i++) { - Slot* slot = _skeleton->getDrawOrder()[i]; - Attachment* const attachment = slot->getAttachment(); - if (!attachment) continue; - if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) { - RegionAttachment* regionAttachment = static_cast(attachment); - texture = static_cast(regionAttachment->getRendererObject())->_texture; - } else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { - MeshAttachment* meshAttachment = static_cast(attachment); - texture = static_cast(meshAttachment->getRendererObject())->_texture; - } - else { - continue; - } - - if (texture != nullptr) { - break; - } + if (texture != nullptr) { + break; } + } #if COCOS2D_VERSION < 0x00040000 - setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP, texture)); + setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP, texture)); #endif +} + +void SkeletonRenderer::setSkeletonData (SkeletonData *skeletonData, bool ownsSkeletonData) { + _skeleton = new (__FILE__, __LINE__) Skeleton(skeletonData); + _ownsSkeletonData = ownsSkeletonData; +} + +SkeletonRenderer::SkeletonRenderer () + : _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits::max()) { +} + +SkeletonRenderer::SkeletonRenderer(Skeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData, bool ownsAtlas) + : _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits::max()) { + initWithSkeleton(skeleton, ownsSkeleton, ownsSkeletonData, ownsAtlas); +} + +SkeletonRenderer::SkeletonRenderer (SkeletonData *skeletonData, bool ownsSkeletonData) + : _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits::max()) { + initWithData(skeletonData, ownsSkeletonData); +} + +SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, Atlas* atlas, float scale) + : _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits::max()) { + initWithJsonFile(skeletonDataFile, atlas, scale); +} + +SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) + : _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits::max()) { + initWithJsonFile(skeletonDataFile, atlasFile, scale); +} + +SkeletonRenderer::~SkeletonRenderer () { + if (_ownsSkeletonData) delete _skeleton->getData(); + if (_ownsSkeleton) delete _skeleton; + if (_ownsAtlas && _atlas) delete _atlas; + if (_attachmentLoader) delete _attachmentLoader; + delete _clipper; +} + +void SkeletonRenderer::initWithSkeleton(Skeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData, bool ownsAtlas) { + _skeleton = skeleton; + _ownsSkeleton = ownsSkeleton; + _ownsSkeletonData = ownsSkeletonData; + _ownsAtlas = ownsAtlas; + initialize(); +} + +void SkeletonRenderer::initWithData (SkeletonData* skeletonData, bool ownsSkeletonData) { + _ownsSkeleton = true; + setSkeletonData(skeletonData, ownsSkeletonData); + initialize(); +} + +void SkeletonRenderer::initWithJsonFile (const std::string& skeletonDataFile, Atlas* atlas, float scale) { + _atlas = atlas; + _attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas); + + SkeletonJson json(_attachmentLoader); + json.setScale(scale); + SkeletonData* skeletonData = json.readSkeletonDataFile(skeletonDataFile.c_str()); + CCASSERT(skeletonData, !json.getError().isEmpty() ? json.getError().buffer() : "Error reading skeleton data."); + + _ownsSkeleton = true; + setSkeletonData(skeletonData, true); + + initialize(); +} + +void SkeletonRenderer::initWithJsonFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) { + _atlas = new (__FILE__, __LINE__) Atlas(atlasFile.c_str(), &textureLoader, true); + CCASSERT(_atlas, "Error reading atlas file."); + + _attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas); + + SkeletonJson json(_attachmentLoader); + json.setScale(scale); + SkeletonData* skeletonData = json.readSkeletonDataFile(skeletonDataFile.c_str()); + CCASSERT(skeletonData, !json.getError().isEmpty() ? json.getError().buffer() : "Error reading skeleton data."); + + _ownsSkeleton = true; + _ownsAtlas = true; + setSkeletonData(skeletonData, true); + + initialize(); +} + +void SkeletonRenderer::initWithBinaryFile (const std::string& skeletonDataFile, Atlas* atlas, float scale) { + _atlas = atlas; + _attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas); + + SkeletonBinary binary(_attachmentLoader); + binary.setScale(scale); + SkeletonData* skeletonData = binary.readSkeletonDataFile(skeletonDataFile.c_str()); + CCASSERT(skeletonData, !binary.getError().isEmpty() ? binary.getError().buffer() : "Error reading skeleton data."); + _ownsSkeleton = true; + setSkeletonData(skeletonData, true); + + initialize(); +} + +void SkeletonRenderer::initWithBinaryFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) { + _atlas = new (__FILE__, __LINE__) Atlas(atlasFile.c_str(), &textureLoader, true); + CCASSERT(_atlas, "Error reading atlas file."); + + _attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas); + + SkeletonBinary binary(_attachmentLoader); + binary.setScale(scale); + SkeletonData* skeletonData = binary.readSkeletonDataFile(skeletonDataFile.c_str()); + CCASSERT(skeletonData, !binary.getError().isEmpty() ? binary.getError().buffer() : "Error reading skeleton data."); + _ownsSkeleton = true; + _ownsAtlas = true; + setSkeletonData(skeletonData, true); + + initialize(); +} + + +void SkeletonRenderer::update (float deltaTime) { + Node::update(deltaTime); + if (_ownsSkeleton) _skeleton->update(deltaTime * _timeScale); +} + +void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t transformFlags) { + // Early exit if the skeleton is invisible. + if (getDisplayedOpacity() == 0 || _skeleton->getColor().a == 0) { + return; } - void SkeletonRenderer::setSkeletonData (SkeletonData *skeletonData, bool ownsSkeletonData) { - _skeleton = new (__FILE__, __LINE__) Skeleton(skeletonData); - _ownsSkeletonData = ownsSkeletonData; + const int coordCount = computeTotalCoordCount(*_skeleton, _startSlotIndex, _endSlotIndex); + if (coordCount == 0) { + return; + } + assert(coordCount % 2 == 0); + + VLA(float, worldCoords, coordCount); + transformWorldVertices(worldCoords, coordCount, *_skeleton, _startSlotIndex, _endSlotIndex); + +#if CC_USE_CULLING + const cocos2d::Rect bb = computeBoundingRect(worldCoords, coordCount / 2); + + if (cullRectangle(renderer, transform, bb)) { + VLA_FREE(worldCoords); + return; + } +#endif + + const float* worldCoordPtr = worldCoords; + SkeletonBatch* batch = SkeletonBatch::getInstance(); + SkeletonTwoColorBatch* twoColorBatch = SkeletonTwoColorBatch::getInstance(); + const bool hasSingleTint = (isTwoColorTint() == false); + + if (_effect) { + _effect->begin(*_skeleton); } - SkeletonRenderer::SkeletonRenderer () - : _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits::max()) { - } + const Color3B displayedColor = getDisplayedColor(); + Color nodeColor; + nodeColor.r = displayedColor.r / 255.f; + nodeColor.g = displayedColor.g / 255.f; + nodeColor.b = displayedColor.b / 255.f; + nodeColor.a = getDisplayedOpacity() / 255.f; - SkeletonRenderer::SkeletonRenderer(Skeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData, bool ownsAtlas) - : _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits::max()) { - initWithSkeleton(skeleton, ownsSkeleton, ownsSkeletonData, ownsAtlas); - } + Color color; + Color darkColor; + const float darkPremultipliedAlpha = _premultipliedAlpha ? 1.f : 0; + AttachmentVertices* attachmentVertices = nullptr; + TwoColorTrianglesCommand* lastTwoColorTrianglesCommand = nullptr; + for (int i = 0, n = _skeleton->getSlots().size(); i < n; ++i) { + Slot* slot = _skeleton->getDrawOrder()[i];; - SkeletonRenderer::SkeletonRenderer (SkeletonData *skeletonData, bool ownsSkeletonData) - : _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits::max()) { - initWithData(skeletonData, ownsSkeletonData); - } - - SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, Atlas* atlas, float scale) - : _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits::max()) { - initWithJsonFile(skeletonDataFile, atlas, scale); - } - - SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) - : _atlas(nullptr), _attachmentLoader(nullptr), _timeScale(1), _debugSlots(false), _debugBones(false), _debugMeshes(false), _debugBoundingRect(false), _effect(nullptr), _startSlotIndex(0), _endSlotIndex(std::numeric_limits::max()) { - initWithJsonFile(skeletonDataFile, atlasFile, scale); - } - - SkeletonRenderer::~SkeletonRenderer () { - if (_ownsSkeletonData) delete _skeleton->getData(); - if (_ownsSkeleton) delete _skeleton; - if (_ownsAtlas && _atlas) delete _atlas; - if (_attachmentLoader) delete _attachmentLoader; - delete _clipper; - } - - void SkeletonRenderer::initWithSkeleton(Skeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData, bool ownsAtlas) { - _skeleton = skeleton; - _ownsSkeleton = ownsSkeleton; - _ownsSkeletonData = ownsSkeletonData; - _ownsAtlas = ownsAtlas; - initialize(); - } - - void SkeletonRenderer::initWithData (SkeletonData* skeletonData, bool ownsSkeletonData) { - _ownsSkeleton = true; - setSkeletonData(skeletonData, ownsSkeletonData); - initialize(); - } - - void SkeletonRenderer::initWithJsonFile (const std::string& skeletonDataFile, Atlas* atlas, float scale) { - _atlas = atlas; - _attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas); - - SkeletonJson json(_attachmentLoader); - json.setScale(scale); - SkeletonData* skeletonData = json.readSkeletonDataFile(skeletonDataFile.c_str()); - CCASSERT(skeletonData, !json.getError().isEmpty() ? json.getError().buffer() : "Error reading skeleton data."); - - _ownsSkeleton = true; - setSkeletonData(skeletonData, true); - - initialize(); - } - - void SkeletonRenderer::initWithJsonFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) { - _atlas = new (__FILE__, __LINE__) Atlas(atlasFile.c_str(), &textureLoader, true); - CCASSERT(_atlas, "Error reading atlas file."); - - _attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas); - - SkeletonJson json(_attachmentLoader); - json.setScale(scale); - SkeletonData* skeletonData = json.readSkeletonDataFile(skeletonDataFile.c_str()); - CCASSERT(skeletonData, !json.getError().isEmpty() ? json.getError().buffer() : "Error reading skeleton data."); - - _ownsSkeleton = true; - _ownsAtlas = true; - setSkeletonData(skeletonData, true); - - initialize(); - } - - void SkeletonRenderer::initWithBinaryFile (const std::string& skeletonDataFile, Atlas* atlas, float scale) { - _atlas = atlas; - _attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas); - - SkeletonBinary binary(_attachmentLoader); - binary.setScale(scale); - SkeletonData* skeletonData = binary.readSkeletonDataFile(skeletonDataFile.c_str()); - CCASSERT(skeletonData, !binary.getError().isEmpty() ? binary.getError().buffer() : "Error reading skeleton data."); - _ownsSkeleton = true; - setSkeletonData(skeletonData, true); - - initialize(); - } - - void SkeletonRenderer::initWithBinaryFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) { - _atlas = new (__FILE__, __LINE__) Atlas(atlasFile.c_str(), &textureLoader, true); - CCASSERT(_atlas, "Error reading atlas file."); - - _attachmentLoader = new (__FILE__, __LINE__) Cocos2dAtlasAttachmentLoader(_atlas); - - SkeletonBinary binary(_attachmentLoader); - binary.setScale(scale); - SkeletonData* skeletonData = binary.readSkeletonDataFile(skeletonDataFile.c_str()); - CCASSERT(skeletonData, !binary.getError().isEmpty() ? binary.getError().buffer() : "Error reading skeleton data."); - _ownsSkeleton = true; - _ownsAtlas = true; - setSkeletonData(skeletonData, true); - - initialize(); - } - - - void SkeletonRenderer::update (float deltaTime) { - Node::update(deltaTime); - if (_ownsSkeleton) _skeleton->update(deltaTime * _timeScale); - } - - void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t transformFlags) { - // Early exit if the skeleton is invisible - if (getDisplayedOpacity() == 0 || _skeleton->getColor().a == 0) { - return; - } - - const int coordCount = computeTotalCoordCount(*_skeleton, _startSlotIndex, _endSlotIndex); - if (coordCount == 0) { - return; - } - assert(coordCount % 2 == 0); - - VLA(float, worldCoords, coordCount); - transformWorldVertices(worldCoords, coordCount, *_skeleton, _startSlotIndex, _endSlotIndex); - - #if CC_USE_CULLING - const cocos2d::Rect bb = computeBoundingRect(worldCoords, coordCount / 2); - - if (cullRectangle(renderer, transform, bb)) { - VLA_FREE(worldCoords); - return; - } - #endif - - const float* worldCoordPtr = worldCoords; - SkeletonBatch* batch = SkeletonBatch::getInstance(); - SkeletonTwoColorBatch* twoColorBatch = SkeletonTwoColorBatch::getInstance(); - const bool hasSingleTint = (isTwoColorTint() == false); - - if (_effect) { - _effect->begin(*_skeleton); - } - - const Color3B displayedColor = getDisplayedColor(); - Color nodeColor; - nodeColor.r = displayedColor.r / 255.f; - nodeColor.g = displayedColor.g / 255.f; - nodeColor.b = displayedColor.b / 255.f; - nodeColor.a = getDisplayedOpacity() / 255.f; - - Color color; - Color darkColor; - const float darkPremultipliedAlpha = _premultipliedAlpha ? 1.f : 0; - AttachmentVertices* attachmentVertices = nullptr; - TwoColorTrianglesCommand* lastTwoColorTrianglesCommand = nullptr; - for (int i = 0, n = _skeleton->getSlots().size(); i < n; ++i) { - Slot* slot = _skeleton->getDrawOrder()[i];; - - if (nothingToDraw(*slot, _startSlotIndex, _endSlotIndex)) { - _clipper->clipEnd(*slot); - continue; - } - - cocos2d::TrianglesCommand::Triangles triangles; - TwoColorTriangles trianglesTwoColor; - - if (slot->getAttachment()->getRTTI().isExactly(RegionAttachment::rtti)) { - RegionAttachment* attachment = static_cast(slot->getAttachment()); - attachmentVertices = static_cast(attachment->getRendererObject()); - - float* dstTriangleVertices = nullptr; - int dstStride = 0; // in floats - if (hasSingleTint) { - triangles.indices = attachmentVertices->_triangles->indices; - triangles.indexCount = attachmentVertices->_triangles->indexCount; - triangles.verts = batch->allocateVertices(attachmentVertices->_triangles->vertCount); - triangles.vertCount = attachmentVertices->_triangles->vertCount; - assert(triangles.vertCount == 4); - memcpy(triangles.verts, attachmentVertices->_triangles->verts, sizeof(cocos2d::V3F_C4B_T2F) * attachmentVertices->_triangles->vertCount); - dstStride = sizeof(V3F_C4B_T2F) / sizeof(float); - dstTriangleVertices = reinterpret_cast(triangles.verts); - } else { - trianglesTwoColor.indices = attachmentVertices->_triangles->indices; - trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount; - trianglesTwoColor.verts = twoColorBatch->allocateVertices(attachmentVertices->_triangles->vertCount); - trianglesTwoColor.vertCount = attachmentVertices->_triangles->vertCount; - assert(trianglesTwoColor.vertCount == 4); - for (int v = 0; v < trianglesTwoColor.vertCount; v++) { - trianglesTwoColor.verts[v].texCoords = attachmentVertices->_triangles->verts[v].texCoords; - } - dstTriangleVertices = reinterpret_cast(trianglesTwoColor.verts); - dstStride = sizeof(V3F_C4B_C4B_T2F) / sizeof(float); - } - // Copy world vertices to triangle vertices - interleaveCoordinates(dstTriangleVertices, worldCoordPtr, 4, dstStride); - worldCoordPtr += 8; - - color = attachment->getColor(); - } - else if (slot->getAttachment()->getRTTI().isExactly(MeshAttachment::rtti)) { - MeshAttachment* attachment = (MeshAttachment*)slot->getAttachment(); - attachmentVertices = (AttachmentVertices*)attachment->getRendererObject(); - - float* dstTriangleVertices = nullptr; - int dstStride = 0; // in floats - int dstVertexCount = 0; - if (hasSingleTint) { - triangles.indices = attachmentVertices->_triangles->indices; - triangles.indexCount = attachmentVertices->_triangles->indexCount; - triangles.verts = batch->allocateVertices(attachmentVertices->_triangles->vertCount); - triangles.vertCount = attachmentVertices->_triangles->vertCount; - memcpy(triangles.verts, attachmentVertices->_triangles->verts, sizeof(cocos2d::V3F_C4B_T2F) * attachmentVertices->_triangles->vertCount); - dstTriangleVertices = (float*)triangles.verts; - dstStride = sizeof(V3F_C4B_T2F) / sizeof(float); - dstVertexCount = triangles.vertCount; - } else { - trianglesTwoColor.indices = attachmentVertices->_triangles->indices; - trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount; - trianglesTwoColor.verts = twoColorBatch->allocateVertices(attachmentVertices->_triangles->vertCount); - trianglesTwoColor.vertCount = attachmentVertices->_triangles->vertCount; - for (int v = 0; v < trianglesTwoColor.vertCount; v++) { - trianglesTwoColor.verts[v].texCoords = attachmentVertices->_triangles->verts[v].texCoords; - } - dstTriangleVertices = (float*)trianglesTwoColor.verts; - dstStride = sizeof(V3F_C4B_C4B_T2F) / sizeof(float); - dstVertexCount = trianglesTwoColor.vertCount; - } - - // Copy world vertices to triangle vertices - //assert(dstVertexCount * 2 == attachment->super.worldVerticesLength); - interleaveCoordinates(dstTriangleVertices, worldCoordPtr, dstVertexCount, dstStride); - worldCoordPtr += dstVertexCount * 2; - - color = attachment->getColor(); - } - else if (slot->getAttachment()->getRTTI().isExactly(ClippingAttachment::rtti)) { - ClippingAttachment* clip = (ClippingAttachment*)slot->getAttachment(); - _clipper->clipStart(*slot, clip); - continue; - } else { - _clipper->clipEnd(*slot); - continue; - } - - if (slot->hasDarkColor()) { - darkColor = slot->getDarkColor(); - } else { - darkColor.r = 0; - darkColor.g = 0; - darkColor.b = 0; - } - darkColor.a = darkPremultipliedAlpha; - - color.a *= nodeColor.a * _skeleton->getColor().a * slot->getColor().a; - // skip rendering if the color of this attachment is 0 - if (color.a == 0){ + if (nothingToDraw(*slot, _startSlotIndex, _endSlotIndex)) { _clipper->clipEnd(*slot); - continue; - } - color.r *= nodeColor.r * _skeleton->getColor().r * slot->getColor().r; - color.g *= nodeColor.g * _skeleton->getColor().g * slot->getColor().g; - color.b *= nodeColor.b * _skeleton->getColor().b * slot->getColor().b; - if (_premultipliedAlpha) - { - color.r *= color.a; - color.g *= color.a; - color.b *= color.a; - } + continue; + } - const cocos2d::Color4B color4B = ColorToColor4B(color); - const cocos2d::Color4B darkColor4B = ColorToColor4B(darkColor); - const BlendFunc blendFunc = makeBlendFunc(slot->getData().getBlendMode(), attachmentVertices->_texture->hasPremultipliedAlpha()); - _blendFunc = blendFunc; + cocos2d::TrianglesCommand::Triangles triangles; + TwoColorTriangles trianglesTwoColor; + if (slot->getAttachment()->getRTTI().isExactly(RegionAttachment::rtti)) { + RegionAttachment* attachment = static_cast(slot->getAttachment()); + attachmentVertices = static_cast(attachment->getRendererObject()); + + float* dstTriangleVertices = nullptr; + int dstStride = 0; // in floats if (hasSingleTint) { - if (_clipper->isClipping()) { - _clipper->clipTriangles((float*)&triangles.verts[0].vertices, triangles.indices, triangles.indexCount, (float*)&triangles.verts[0].texCoords, sizeof(cocos2d::V3F_C4B_T2F) / 4); - batch->deallocateVertices(triangles.vertCount); + triangles.indices = attachmentVertices->_triangles->indices; + triangles.indexCount = attachmentVertices->_triangles->indexCount; + triangles.verts = batch->allocateVertices(attachmentVertices->_triangles->vertCount); + triangles.vertCount = attachmentVertices->_triangles->vertCount; + assert(triangles.vertCount == 4); + memcpy(triangles.verts, attachmentVertices->_triangles->verts, sizeof(cocos2d::V3F_C4B_T2F) * attachmentVertices->_triangles->vertCount); + dstStride = sizeof(V3F_C4B_T2F) / sizeof(float); + dstTriangleVertices = reinterpret_cast(triangles.verts); + } else { + trianglesTwoColor.indices = attachmentVertices->_triangles->indices; + trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount; + trianglesTwoColor.verts = twoColorBatch->allocateVertices(attachmentVertices->_triangles->vertCount); + trianglesTwoColor.vertCount = attachmentVertices->_triangles->vertCount; + assert(trianglesTwoColor.vertCount == 4); + for (int v = 0; v < trianglesTwoColor.vertCount; v++) { + trianglesTwoColor.verts[v].texCoords = attachmentVertices->_triangles->verts[v].texCoords; + } + dstTriangleVertices = reinterpret_cast(trianglesTwoColor.verts); + dstStride = sizeof(V3F_C4B_C4B_T2F) / sizeof(float); + } + // Copy world vertices to triangle vertices. + interleaveCoordinates(dstTriangleVertices, worldCoordPtr, 4, dstStride); + worldCoordPtr += 8; - if (_clipper->getClippedTriangles().size() == 0){ - _clipper->clipEnd(*slot); - continue; - } + color = attachment->getColor(); + } + else if (slot->getAttachment()->getRTTI().isExactly(MeshAttachment::rtti)) { + MeshAttachment* attachment = (MeshAttachment*)slot->getAttachment(); + attachmentVertices = (AttachmentVertices*)attachment->getRendererObject(); - triangles.vertCount = _clipper->getClippedVertices().size() / 2; - triangles.verts = batch->allocateVertices(triangles.vertCount); - triangles.indexCount = _clipper->getClippedTriangles().size(); - triangles.indices = - batch->allocateIndices(triangles.indexCount); - memcpy(triangles.indices, _clipper->getClippedTriangles().buffer(), sizeof(unsigned short) * _clipper->getClippedTriangles().size()); + float* dstTriangleVertices = nullptr; + int dstStride = 0; // in floats + int dstVertexCount = 0; + if (hasSingleTint) { + triangles.indices = attachmentVertices->_triangles->indices; + triangles.indexCount = attachmentVertices->_triangles->indexCount; + triangles.verts = batch->allocateVertices(attachmentVertices->_triangles->vertCount); + triangles.vertCount = attachmentVertices->_triangles->vertCount; + memcpy(triangles.verts, attachmentVertices->_triangles->verts, sizeof(cocos2d::V3F_C4B_T2F) * attachmentVertices->_triangles->vertCount); + dstTriangleVertices = (float*)triangles.verts; + dstStride = sizeof(V3F_C4B_T2F) / sizeof(float); + dstVertexCount = triangles.vertCount; + } else { + trianglesTwoColor.indices = attachmentVertices->_triangles->indices; + trianglesTwoColor.indexCount = attachmentVertices->_triangles->indexCount; + trianglesTwoColor.verts = twoColorBatch->allocateVertices(attachmentVertices->_triangles->vertCount); + trianglesTwoColor.vertCount = attachmentVertices->_triangles->vertCount; + for (int v = 0; v < trianglesTwoColor.vertCount; v++) { + trianglesTwoColor.verts[v].texCoords = attachmentVertices->_triangles->verts[v].texCoords; + } + dstTriangleVertices = (float*)trianglesTwoColor.verts; + dstStride = sizeof(V3F_C4B_C4B_T2F) / sizeof(float); + dstVertexCount = trianglesTwoColor.vertCount; + } + + // Copy world vertices to triangle vertices. + //assert(dstVertexCount * 2 == attachment->super.worldVerticesLength); + interleaveCoordinates(dstTriangleVertices, worldCoordPtr, dstVertexCount, dstStride); + worldCoordPtr += dstVertexCount * 2; + + color = attachment->getColor(); + } + else if (slot->getAttachment()->getRTTI().isExactly(ClippingAttachment::rtti)) { + ClippingAttachment* clip = (ClippingAttachment*)slot->getAttachment(); + _clipper->clipStart(*slot, clip); + continue; + } else { + _clipper->clipEnd(*slot); + continue; + } + + if (slot->hasDarkColor()) { + darkColor = slot->getDarkColor(); + } else { + darkColor.r = 0; + darkColor.g = 0; + darkColor.b = 0; + } + darkColor.a = darkPremultipliedAlpha; + + color.a *= nodeColor.a * _skeleton->getColor().a * slot->getColor().a; + if (color.a == 0) { + _clipper->clipEnd(*slot); + continue; + } + color.r *= nodeColor.r * _skeleton->getColor().r * slot->getColor().r; + color.g *= nodeColor.g * _skeleton->getColor().g * slot->getColor().g; + color.b *= nodeColor.b * _skeleton->getColor().b * slot->getColor().b; + if (_premultipliedAlpha) { + color.r *= color.a; + color.g *= color.a; + color.b *= color.a; + } + + const cocos2d::Color4B color4B = ColorToColor4B(color); + const cocos2d::Color4B darkColor4B = ColorToColor4B(darkColor); + const BlendFunc blendFunc = makeBlendFunc(slot->getData().getBlendMode(), attachmentVertices->_texture->hasPremultipliedAlpha()); + _blendFunc = blendFunc; + + if (hasSingleTint) { + if (_clipper->isClipping()) { + _clipper->clipTriangles((float*)&triangles.verts[0].vertices, triangles.indices, triangles.indexCount, (float*)&triangles.verts[0].texCoords, sizeof(cocos2d::V3F_C4B_T2F) / 4); + batch->deallocateVertices(triangles.vertCount); + + if (_clipper->getClippedTriangles().size() == 0) { + _clipper->clipEnd(*slot); + continue; + } + + triangles.vertCount = _clipper->getClippedVertices().size() / 2; + triangles.verts = batch->allocateVertices(triangles.vertCount); + triangles.indexCount = _clipper->getClippedTriangles().size(); + triangles.indices = + batch->allocateIndices(triangles.indexCount); + memcpy(triangles.indices, _clipper->getClippedTriangles().buffer(), sizeof(unsigned short) * _clipper->getClippedTriangles().size()); #if COCOS2D_VERSION < 0x00040000 - cocos2d::TrianglesCommand* batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _glProgramState, blendFunc, triangles, transform, transformFlags); + cocos2d::TrianglesCommand* batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _glProgramState, blendFunc, triangles, transform, transformFlags); #else - cocos2d::TrianglesCommand* batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, blendFunc, triangles, transform, transformFlags); + cocos2d::TrianglesCommand* batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, blendFunc, triangles, transform, transformFlags); #endif - const float* verts = _clipper->getClippedVertices().buffer(); - const float* uvs = _clipper->getClippedUVs().buffer(); - if (_effect) { - V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts; - Color darkTmp; - for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv+=2, ++vertex) { - Color lightCopy = color; - vertex->vertices.x = verts[vv]; - vertex->vertices.y = verts[vv + 1]; - vertex->texCoords.u = uvs[vv]; - vertex->texCoords.v = uvs[vv + 1]; - _effect->transform(vertex->vertices.x, vertex->vertices.y, vertex->texCoords.u, vertex->texCoords.v, lightCopy, darkTmp); - vertex->colors = ColorToColor4B(lightCopy); - } - } else { - V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts; - for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv+=2, ++vertex) { - vertex->vertices.x = verts[vv]; - vertex->vertices.y = verts[vv + 1]; - vertex->texCoords.u = uvs[vv]; - vertex->texCoords.v = uvs[vv + 1]; - vertex->colors = color4B; - } + const float* verts = _clipper->getClippedVertices().buffer(); + const float* uvs = _clipper->getClippedUVs().buffer(); + if (_effect) { + V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts; + Color darkTmp; + for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv+=2, ++vertex) { + Color lightCopy = color; + vertex->vertices.x = verts[vv]; + vertex->vertices.y = verts[vv + 1]; + vertex->texCoords.u = uvs[vv]; + vertex->texCoords.v = uvs[vv + 1]; + _effect->transform(vertex->vertices.x, vertex->vertices.y, vertex->texCoords.u, vertex->texCoords.v, lightCopy, darkTmp); + vertex->colors = ColorToColor4B(lightCopy); } } else { - // Not clipping -#if COCOS2D_VERSION < 0x00040000 - cocos2d::TrianglesCommand* batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _glProgramState, blendFunc, triangles, transform, transformFlags); -#else - cocos2d::TrianglesCommand* batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, blendFunc, triangles, transform, transformFlags); -#endif - - if (_effect) { - V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts; - Color darkTmp; - for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v, ++vertex) { - Color lightCopy = color; - _effect->transform(vertex->vertices.x, vertex->vertices.y, vertex->texCoords.u, vertex->texCoords.v, lightCopy, darkTmp); - vertex->colors = ColorToColor4B(lightCopy); - } - } else { - V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts; - for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v, ++vertex) { - vertex->colors = color4B; - } + V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts; + for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv+=2, ++vertex) { + vertex->vertices.x = verts[vv]; + vertex->vertices.y = verts[vv + 1]; + vertex->texCoords.u = uvs[vv]; + vertex->texCoords.v = uvs[vv + 1]; + vertex->colors = color4B; } } } else { - // Two tints - - if (_clipper->isClipping()) { - _clipper->clipTriangles((float*)&trianglesTwoColor.verts[0].position, trianglesTwoColor.indices, trianglesTwoColor.indexCount, (float*)&trianglesTwoColor.verts[0].texCoords, sizeof(V3F_C4B_C4B_T2F) / 4); - twoColorBatch->deallocateVertices(trianglesTwoColor.vertCount); - - if (_clipper->getClippedTriangles().size() == 0){ - _clipper->clipEnd(*slot); - continue; - } - - trianglesTwoColor.vertCount = _clipper->getClippedVertices().size() / 2; - trianglesTwoColor.verts = twoColorBatch->allocateVertices(trianglesTwoColor.vertCount); - trianglesTwoColor.indexCount = _clipper->getClippedTriangles().size(); - trianglesTwoColor.indices = twoColorBatch->allocateIndices(trianglesTwoColor.indexCount); - memcpy(trianglesTwoColor.indices, _clipper->getClippedTriangles().buffer(), sizeof(unsigned short) * _clipper->getClippedTriangles().size()); - + // Not clipping. #if COCOS2D_VERSION < 0x00040000 - TwoColorTrianglesCommand* batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture->getName(), _glProgramState, blendFunc, trianglesTwoColor, transform, transformFlags); + cocos2d::TrianglesCommand* batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, _glProgramState, blendFunc, triangles, transform, transformFlags); #else - TwoColorTrianglesCommand* batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, blendFunc, trianglesTwoColor, transform, transformFlags); + cocos2d::TrianglesCommand* batchedTriangles = batch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, blendFunc, triangles, transform, transformFlags); #endif - const float* verts = _clipper->getClippedVertices().buffer(); - const float* uvs = _clipper->getClippedUVs().buffer(); - - if (_effect) { - V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts; - for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv += 2, ++vertex) { - Color lightCopy = color; - Color darkCopy = darkColor; - vertex->position.x = verts[vv]; - vertex->position.y = verts[vv + 1]; - vertex->texCoords.u = uvs[vv]; - vertex->texCoords.v = uvs[vv + 1]; - _effect->transform(vertex->position.x, vertex->position.y, vertex->texCoords.u, vertex->texCoords.v, lightCopy, darkCopy); - vertex->color = ColorToColor4B(lightCopy); - vertex->color2 = ColorToColor4B(darkCopy); - } - } else { - V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts; - for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv += 2, ++vertex) { - vertex->position.x = verts[vv]; - vertex->position.y = verts[vv + 1]; - vertex->texCoords.u = uvs[vv]; - vertex->texCoords.v = uvs[vv + 1]; - vertex->color = color4B; - vertex->color2 = darkColor4B; - } + if (_effect) { + V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts; + Color darkTmp; + for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v, ++vertex) { + Color lightCopy = color; + _effect->transform(vertex->vertices.x, vertex->vertices.y, vertex->texCoords.u, vertex->texCoords.v, lightCopy, darkTmp); + vertex->colors = ColorToColor4B(lightCopy); } } else { - -#if COCOS2D_VERSION < 0x00040000 - TwoColorTrianglesCommand* batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture->getName(), _glProgramState, blendFunc, trianglesTwoColor, transform, transformFlags); -#else - TwoColorTrianglesCommand* batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, blendFunc, trianglesTwoColor, transform, transformFlags); -#endif - - if (_effect) { - V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts; - for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v, ++vertex) { - Color lightCopy = color; - Color darkCopy = darkColor; - _effect->transform(vertex->position.x, vertex->position.y, vertex->texCoords.u, vertex->texCoords.v, lightCopy, darkCopy); - vertex->color = ColorToColor4B(lightCopy); - vertex->color2 = ColorToColor4B(darkCopy); - } - } else { - V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts; - for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v, ++vertex) { - vertex->color = color4B; - vertex->color2 = darkColor4B; - } + V3F_C4B_T2F* vertex = batchedTriangles->getTriangles().verts; + for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v, ++vertex) { + vertex->colors = color4B; + } + } + } + } else { + // Two color tinting. + + if (_clipper->isClipping()) { + _clipper->clipTriangles((float*)&trianglesTwoColor.verts[0].position, trianglesTwoColor.indices, trianglesTwoColor.indexCount, (float*)&trianglesTwoColor.verts[0].texCoords, sizeof(V3F_C4B_C4B_T2F) / 4); + twoColorBatch->deallocateVertices(trianglesTwoColor.vertCount); + + if (_clipper->getClippedTriangles().size() == 0) { + _clipper->clipEnd(*slot); + continue; + } + + trianglesTwoColor.vertCount = _clipper->getClippedVertices().size() / 2; + trianglesTwoColor.verts = twoColorBatch->allocateVertices(trianglesTwoColor.vertCount); + trianglesTwoColor.indexCount = _clipper->getClippedTriangles().size(); + trianglesTwoColor.indices = twoColorBatch->allocateIndices(trianglesTwoColor.indexCount); + memcpy(trianglesTwoColor.indices, _clipper->getClippedTriangles().buffer(), sizeof(unsigned short) * _clipper->getClippedTriangles().size()); + +#if COCOS2D_VERSION < 0x00040000 + TwoColorTrianglesCommand* batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture->getName(), _glProgramState, blendFunc, trianglesTwoColor, transform, transformFlags); +#else + TwoColorTrianglesCommand* batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, blendFunc, trianglesTwoColor, transform, transformFlags); +#endif + + const float* verts = _clipper->getClippedVertices().buffer(); + const float* uvs = _clipper->getClippedUVs().buffer(); + + if (_effect) { + V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts; + for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv += 2, ++vertex) { + Color lightCopy = color; + Color darkCopy = darkColor; + vertex->position.x = verts[vv]; + vertex->position.y = verts[vv + 1]; + vertex->texCoords.u = uvs[vv]; + vertex->texCoords.v = uvs[vv + 1]; + _effect->transform(vertex->position.x, vertex->position.y, vertex->texCoords.u, vertex->texCoords.v, lightCopy, darkCopy); + vertex->color = ColorToColor4B(lightCopy); + vertex->color2 = ColorToColor4B(darkCopy); + } + } else { + V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts; + for (int v = 0, vn = batchedTriangles->getTriangles().vertCount, vv = 0; v < vn; ++v, vv += 2, ++vertex) { + vertex->position.x = verts[vv]; + vertex->position.y = verts[vv + 1]; + vertex->texCoords.u = uvs[vv]; + vertex->texCoords.v = uvs[vv + 1]; + vertex->color = color4B; + vertex->color2 = darkColor4B; + } + } + } else { + +#if COCOS2D_VERSION < 0x00040000 + TwoColorTrianglesCommand* batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture->getName(), _glProgramState, blendFunc, trianglesTwoColor, transform, transformFlags); +#else + TwoColorTrianglesCommand* batchedTriangles = lastTwoColorTrianglesCommand = twoColorBatch->addCommand(renderer, _globalZOrder, attachmentVertices->_texture, blendFunc, trianglesTwoColor, transform, transformFlags); +#endif + + if (_effect) { + V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts; + for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v, ++vertex) { + Color lightCopy = color; + Color darkCopy = darkColor; + _effect->transform(vertex->position.x, vertex->position.y, vertex->texCoords.u, vertex->texCoords.v, lightCopy, darkCopy); + vertex->color = ColorToColor4B(lightCopy); + vertex->color2 = ColorToColor4B(darkCopy); + } + } else { + V3F_C4B_C4B_T2F* vertex = batchedTriangles->getTriangles().verts; + for (int v = 0, vn = batchedTriangles->getTriangles().vertCount; v < vn; ++v, ++vertex) { + vertex->color = color4B; + vertex->color2 = darkColor4B; } } } - _clipper->clipEnd(*slot); } - _clipper->clipEnd(); + _clipper->clipEnd(*slot); + } + _clipper->clipEnd(); - if (lastTwoColorTrianglesCommand) { - Node* parent = this->getParent(); + if (lastTwoColorTrianglesCommand) { + Node* parent = this->getParent(); - // We need to decide if we can postpone flushing the current - // batch. We can postpone if the next sibling node is a - // two color tinted skeleton with the same global-z. - // The parent->getChildrenCount() > 100 check is a hack - // as checking for a sibling is an O(n) operation, and if - // all children of this nodes parent are skeletons, we - // are in O(n2) territory. - if (!parent || parent->getChildrenCount() > 100 || getChildrenCount() != 0) { + // We need to decide if we can postpone flushing the current batch. We can postpone if the next sibling node is a two color + // tinted skeleton with the same global-z. + // The parent->getChildrenCount() > 100 check is a hack as checking for a sibling is an O(n) operation, and if all children + // of this nodes parent are skeletons, we are in O(n2) territory. + if (!parent || parent->getChildrenCount() > 100 || getChildrenCount() != 0) { + lastTwoColorTrianglesCommand->setForceFlush(true); + } else { + const cocos2d::Vector& children = parent->getChildren(); + Node* sibling = nullptr; + for (ssize_t i = 0; i < children.size(); i++) { + if (children.at(i) == this) { + if (i < children.size() - 1) { + sibling = children.at(i+1); + break; + } + } + } + if (!sibling) { lastTwoColorTrianglesCommand->setForceFlush(true); } else { - const cocos2d::Vector& children = parent->getChildren(); - Node* sibling = nullptr; - for (ssize_t i = 0; i < children.size(); i++) { - if (children.at(i) == this) { - if (i < children.size() - 1) { - sibling = children.at(i+1); - break; - } - } - } - if (!sibling) { + SkeletonRenderer* siblingSkeleton = dynamic_cast(sibling); + if (!siblingSkeleton || // flush is next sibling isn't a SkeletonRenderer + !siblingSkeleton->isTwoColorTint() || // flush if next sibling isn't two color tinted + !siblingSkeleton->isVisible() || // flush if next sibling is two color tinted but not visible + (siblingSkeleton->getGlobalZOrder() != this->getGlobalZOrder())) { // flush if next sibling is two color tinted but z-order differs lastTwoColorTrianglesCommand->setForceFlush(true); - } else { - SkeletonRenderer* siblingSkeleton = dynamic_cast(sibling); - if (!siblingSkeleton || // flush is next sibling isn't a SkeletonRenderer - !siblingSkeleton->isTwoColorTint() || // flush if next sibling isn't two color tinted - !siblingSkeleton->isVisible() || // flush if next sibling is two color tinted but not visible - (siblingSkeleton->getGlobalZOrder() != this->getGlobalZOrder())) { // flush if next sibling is two color tinted but z-order differs - lastTwoColorTrianglesCommand->setForceFlush(true); - } } } } - - if (_effect) _effect->end(); - - if (_debugBoundingRect || _debugSlots || _debugBones || _debugMeshes) { - drawDebug(renderer, transform, transformFlags); - } - - VLA_FREE(worldCoords); } + if (_effect) _effect->end(); - void SkeletonRenderer::drawDebug (Renderer* renderer, const Mat4 &transform, uint32_t transformFlags) { + if (_debugBoundingRect || _debugSlots || _debugBones || _debugMeshes) { + drawDebug(renderer, transform, transformFlags); + } + + VLA_FREE(worldCoords); +} + + +void SkeletonRenderer::drawDebug (Renderer* renderer, const Mat4 &transform, uint32_t transformFlags) { #if !defined(USE_MATRIX_STACK_PROJECTION_ONLY) - Director* director = Director::getInstance(); - director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); - director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); + Director* director = Director::getInstance(); + director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); #endif - DrawNode* drawNode = DrawNode::create(); - drawNode->setGlobalZOrder(getGlobalZOrder()); + DrawNode* drawNode = DrawNode::create(); + drawNode->setGlobalZOrder(getGlobalZOrder()); - // Draw bounding rectangle - if (_debugBoundingRect) { + // Draw bounding rectangle + if (_debugBoundingRect) { #if COCOS2D_VERSION < 0x00040000 - glLineWidth(2); + glLineWidth(2); #else - drawNode->setLineWidth(2.0f); + drawNode->setLineWidth(2.0f); #endif - const cocos2d::Rect brect = getBoundingBox(); + const cocos2d::Rect brect = getBoundingBox(); + const Vec2 points[4] = + { + brect.origin, + { brect.origin.x + brect.size.width, brect.origin.y }, + { brect.origin.x + brect.size.width, brect.origin.y + brect.size.height }, + { brect.origin.x, brect.origin.y + brect.size.height } + }; + drawNode->drawPoly(points, 4, true, Color4F::GREEN); + } + + if (_debugSlots) { + // Slots. + // DrawPrimitives::setDrawColor4B(0, 0, 255, 255); +#if COCOS2D_VERSION < 0x00040000 + glLineWidth(2); +#else + drawNode->setLineWidth(2.0f); +#endif + V3F_C4B_T2F_Quad quad; + for (int i = 0, n = _skeleton->getSlots().size(); i < n; i++) { + Slot* slot = _skeleton->getDrawOrder()[i]; + + if (!slot->getBone().isActive()) continue; + if (!slot->getAttachment() || !slot->getAttachment()->getRTTI().isExactly(RegionAttachment::rtti)) continue; + + if (slotIsOutRange(*slot, _startSlotIndex, _endSlotIndex)) { + continue; + } + + RegionAttachment* attachment = (RegionAttachment*)slot->getAttachment(); + float worldVertices[8]; + attachment->computeWorldVertices(slot->getBone(), worldVertices, 0, 2); const Vec2 points[4] = { - brect.origin, - { brect.origin.x + brect.size.width, brect.origin.y }, - { brect.origin.x + brect.size.width, brect.origin.y + brect.size.height }, - { brect.origin.x, brect.origin.y + brect.size.height } + { worldVertices[0], worldVertices[1] }, + { worldVertices[2], worldVertices[3] }, + { worldVertices[4], worldVertices[5] }, + { worldVertices[6], worldVertices[7] } }; - drawNode->drawPoly(points, 4, true, Color4F::GREEN); + drawNode->drawPoly(points, 4, true, Color4F::BLUE); } + } - if (_debugSlots) { - // Slots. - // DrawPrimitives::setDrawColor4B(0, 0, 255, 255); + if (_debugBones) { + // Bone lengths. #if COCOS2D_VERSION < 0x00040000 - glLineWidth(2); + glLineWidth(2); #else - drawNode->setLineWidth(2.0f); + drawNode->setLineWidth(2.0f); #endif - V3F_C4B_T2F_Quad quad; - for (int i = 0, n = _skeleton->getSlots().size(); i < n; i++) { - Slot* slot = _skeleton->getDrawOrder()[i]; + for (int i = 0, n = _skeleton->getBones().size(); i < n; i++) { + Bone *bone = _skeleton->getBones()[i]; + if (!bone->isActive()) continue; + float x = bone->getData().getLength() * bone->getA() + bone->getWorldX(); + float y = bone->getData().getLength() * bone->getC() + bone->getWorldY(); + drawNode->drawLine(Vec2(bone->getWorldX(), bone->getWorldY()), Vec2(x, y), Color4F::RED); + } + // Bone origins. + auto color = Color4F::BLUE; // Root bone is blue. + for (int i = 0, n = _skeleton->getBones().size(); i < n; i++) { + Bone *bone = _skeleton->getBones()[i]; + if (!bone->isActive()) continue; + drawNode->drawPoint(Vec2(bone->getWorldX(), bone->getWorldY()), 4, color); + if (i == 0) color = Color4F::GREEN; + } + } - if (!slot->getBone().isActive()) continue; - if (!slot->getAttachment() || !slot->getAttachment()->getRTTI().isExactly(RegionAttachment::rtti)) continue; - - if (slotIsOutRange(*slot, _startSlotIndex, _endSlotIndex)) { - continue; - } - - RegionAttachment* attachment = (RegionAttachment*)slot->getAttachment(); - float worldVertices[8]; - attachment->computeWorldVertices(slot->getBone(), worldVertices, 0, 2); - const Vec2 points[4] = + if (_debugMeshes) { + // Meshes. +#if COCOS2D_VERSION < 0x00040000 + glLineWidth(2); +#else + drawNode->setLineWidth(2.0f); +#endif + for (int i = 0, n = _skeleton->getSlots().size(); i < n; ++i) { + Slot* slot = _skeleton->getDrawOrder()[i]; + if (!slot->getBone().isActive()) continue; + if (!slot->getAttachment() || !slot->getAttachment()->getRTTI().isExactly(MeshAttachment::rtti)) continue; + MeshAttachment* const mesh = static_cast(slot->getAttachment()); + VLA(float, worldCoord, mesh->getWorldVerticesLength()); + mesh->computeWorldVertices(*slot, 0, mesh->getWorldVerticesLength(), worldCoord, 0, 2); + for (size_t t = 0; t < mesh->getTriangles().size(); t += 3) { + // Fetch triangle indices + const int idx0 = mesh->getTriangles()[t + 0]; + const int idx1 = mesh->getTriangles()[t + 1]; + const int idx2 = mesh->getTriangles()[t + 2]; + const Vec2 v[3] = { - { worldVertices[0], worldVertices[1] }, - { worldVertices[2], worldVertices[3] }, - { worldVertices[4], worldVertices[5] }, - { worldVertices[6], worldVertices[7] } + worldCoord + (idx0 * 2), + worldCoord + (idx1 * 2), + worldCoord + (idx2 * 2) }; - drawNode->drawPoly(points, 4, true, Color4F::BLUE); + drawNode->drawPoly(v, 3, true, Color4F::YELLOW); } + VLA_FREE(worldCoord); } + } - if (_debugBones) { - // Bone lengths. -#if COCOS2D_VERSION < 0x00040000 - glLineWidth(2); -#else - drawNode->setLineWidth(2.0f); -#endif - for (int i = 0, n = _skeleton->getBones().size(); i < n; i++) { - Bone *bone = _skeleton->getBones()[i]; - if (!bone->isActive()) continue; - float x = bone->getData().getLength() * bone->getA() + bone->getWorldX(); - float y = bone->getData().getLength() * bone->getC() + bone->getWorldY(); - drawNode->drawLine(Vec2(bone->getWorldX(), bone->getWorldY()), Vec2(x, y), Color4F::RED); - } - // Bone origins. - auto color = Color4F::BLUE; // Root bone is blue. - for (int i = 0, n = _skeleton->getBones().size(); i < n; i++) { - Bone *bone = _skeleton->getBones()[i]; - if (!bone->isActive()) continue; - drawNode->drawPoint(Vec2(bone->getWorldX(), bone->getWorldY()), 4, color); - if (i == 0) color = Color4F::GREEN; - } - } - - if (_debugMeshes) { - // Meshes. -#if COCOS2D_VERSION < 0x00040000 - glLineWidth(2); -#else - drawNode->setLineWidth(2.0f); -#endif - for (int i = 0, n = _skeleton->getSlots().size(); i < n; ++i) { - Slot* slot = _skeleton->getDrawOrder()[i]; - if (!slot->getBone().isActive()) continue; - if (!slot->getAttachment() || !slot->getAttachment()->getRTTI().isExactly(MeshAttachment::rtti)) continue; - MeshAttachment* const mesh = static_cast(slot->getAttachment()); - VLA(float, worldCoord, mesh->getWorldVerticesLength()); - mesh->computeWorldVertices(*slot, 0, mesh->getWorldVerticesLength(), worldCoord, 0, 2); - for (size_t t = 0; t < mesh->getTriangles().size(); t += 3) { - // Fetch triangle indices - const int idx0 = mesh->getTriangles()[t + 0]; - const int idx1 = mesh->getTriangles()[t + 1]; - const int idx2 = mesh->getTriangles()[t + 2]; - const Vec2 v[3] = - { - worldCoord + (idx0 * 2), - worldCoord + (idx1 * 2), - worldCoord + (idx2 * 2) - }; - drawNode->drawPoly(v, 3, true, Color4F::YELLOW); - } - VLA_FREE(worldCoord); - } - } - - drawNode->draw(renderer, transform, transformFlags); + drawNode->draw(renderer, transform, transformFlags); #if !defined(USE_MATRIX_STACK_PROJECTION_ONLY) - director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); #endif - } +} - cocos2d::Rect SkeletonRenderer::getBoundingBox () const { - const int coordCount = computeTotalCoordCount(*_skeleton, _startSlotIndex, _endSlotIndex); - if (coordCount == 0) return { 0, 0, 0, 0 }; - VLA(float, worldCoords, coordCount); - transformWorldVertices(worldCoords, coordCount, *_skeleton, _startSlotIndex, _endSlotIndex); - const cocos2d::Rect bb = computeBoundingRect(worldCoords, coordCount / 2); - VLA_FREE(worldCoords); - return bb; - } +cocos2d::Rect SkeletonRenderer::getBoundingBox () const { + const int coordCount = computeTotalCoordCount(*_skeleton, _startSlotIndex, _endSlotIndex); + if (coordCount == 0) return { 0, 0, 0, 0 }; + VLA(float, worldCoords, coordCount); + transformWorldVertices(worldCoords, coordCount, *_skeleton, _startSlotIndex, _endSlotIndex); + const cocos2d::Rect bb = computeBoundingRect(worldCoords, coordCount / 2); + VLA_FREE(worldCoords); + return bb; +} - // --- Convenience methods for Skeleton_* functions. +// --- Convenience methods for Skeleton_* functions. - void SkeletonRenderer::updateWorldTransform() { - _skeleton->updateWorldTransform(); - } +void SkeletonRenderer::updateWorldTransform() { + _skeleton->updateWorldTransform(); +} - void SkeletonRenderer::setToSetupPose () { - _skeleton->setToSetupPose(); - } - void SkeletonRenderer::setBonesToSetupPose () { - _skeleton->setBonesToSetupPose(); - } - void SkeletonRenderer::setSlotsToSetupPose () { - _skeleton->setSlotsToSetupPose(); - } +void SkeletonRenderer::setToSetupPose () { + _skeleton->setToSetupPose(); +} +void SkeletonRenderer::setBonesToSetupPose () { + _skeleton->setBonesToSetupPose(); +} +void SkeletonRenderer::setSlotsToSetupPose () { + _skeleton->setSlotsToSetupPose(); +} - Bone* SkeletonRenderer::findBone (const std::string& boneName) const { - return _skeleton->findBone(boneName.c_str()); - } +Bone* SkeletonRenderer::findBone (const std::string& boneName) const { + return _skeleton->findBone(boneName.c_str()); +} - Slot* SkeletonRenderer::findSlot (const std::string& slotName) const { - return _skeleton->findSlot( slotName.c_str()); - } +Slot* SkeletonRenderer::findSlot (const std::string& slotName) const { + return _skeleton->findSlot( slotName.c_str()); +} - void SkeletonRenderer::setSkin (const std::string& skinName) { - _skeleton->setSkin(skinName.empty() ? 0 : skinName.c_str()); - } - void SkeletonRenderer::setSkin (const char* skinName) { - _skeleton->setSkin(skinName); - } +void SkeletonRenderer::setSkin (const std::string& skinName) { + _skeleton->setSkin(skinName.empty() ? 0 : skinName.c_str()); +} +void SkeletonRenderer::setSkin (const char* skinName) { + _skeleton->setSkin(skinName); +} - Attachment* SkeletonRenderer::getAttachment (const std::string& slotName, const std::string& attachmentName) const { - return _skeleton->getAttachment(slotName.c_str(), attachmentName.c_str()); - } - bool SkeletonRenderer::setAttachment (const std::string& slotName, const std::string& attachmentName) { - bool result = _skeleton->getAttachment(slotName.c_str(), attachmentName.empty() ? 0 : attachmentName.c_str()) ? true : false; - _skeleton->setAttachment(slotName.c_str(), attachmentName.empty() ? 0 : attachmentName.c_str()); - return result; - } - bool SkeletonRenderer::setAttachment (const std::string& slotName, const char* attachmentName) { - bool result = _skeleton->getAttachment(slotName.c_str(), attachmentName) ? true : false; - _skeleton->setAttachment(slotName.c_str(), attachmentName); - return result; - } +Attachment* SkeletonRenderer::getAttachment (const std::string& slotName, const std::string& attachmentName) const { + return _skeleton->getAttachment(slotName.c_str(), attachmentName.c_str()); +} +bool SkeletonRenderer::setAttachment (const std::string& slotName, const std::string& attachmentName) { + bool result = _skeleton->getAttachment(slotName.c_str(), attachmentName.empty() ? 0 : attachmentName.c_str()) ? true : false; + _skeleton->setAttachment(slotName.c_str(), attachmentName.empty() ? 0 : attachmentName.c_str()); + return result; +} +bool SkeletonRenderer::setAttachment (const std::string& slotName, const char* attachmentName) { + bool result = _skeleton->getAttachment(slotName.c_str(), attachmentName) ? true : false; + _skeleton->setAttachment(slotName.c_str(), attachmentName); + return result; +} - void SkeletonRenderer::setTwoColorTint(bool enabled) { +void SkeletonRenderer::setTwoColorTint(bool enabled) { #if COCOS2D_VERSION >= 0x00040000 - _twoColorTint = enabled; + _twoColorTint = enabled; #endif - setupGLProgramState(enabled); - } + setupGLProgramState(enabled); +} - bool SkeletonRenderer::isTwoColorTint() { +bool SkeletonRenderer::isTwoColorTint() { #if COCOS2D_VERSION < 0x00040000 - return getGLProgramState() == SkeletonTwoColorBatch::getInstance()->getTwoColorTintProgramState(); + return getGLProgramState() == SkeletonTwoColorBatch::getInstance()->getTwoColorTintProgramState(); #else - return _twoColorTint; + return _twoColorTint; #endif - } +} - void SkeletonRenderer::setVertexEffect(VertexEffect *effect) { - this->_effect = effect; - } +void SkeletonRenderer::setVertexEffect(VertexEffect *effect) { + this->_effect = effect; +} - void SkeletonRenderer::setSlotsRange(int startSlotIndex, int endSlotIndex) { - _startSlotIndex = startSlotIndex == -1 ? 0 : startSlotIndex; - _endSlotIndex = endSlotIndex == -1 ? std::numeric_limits::max() : endSlotIndex; - } +void SkeletonRenderer::setSlotsRange(int startSlotIndex, int endSlotIndex) { + _startSlotIndex = startSlotIndex == -1 ? 0 : startSlotIndex; + _endSlotIndex = endSlotIndex == -1 ? std::numeric_limits::max() : endSlotIndex; +} - Skeleton* SkeletonRenderer::getSkeleton () const { - return _skeleton; - } +Skeleton* SkeletonRenderer::getSkeleton () const { + return _skeleton; +} - void SkeletonRenderer::setTimeScale (float scale) { - _timeScale = scale; - } - float SkeletonRenderer::getTimeScale () const { - return _timeScale; - } +void SkeletonRenderer::setTimeScale (float scale) { + _timeScale = scale; +} +float SkeletonRenderer::getTimeScale () const { + return _timeScale; +} - void SkeletonRenderer::setDebugSlotsEnabled (bool enabled) { - _debugSlots = enabled; - } - bool SkeletonRenderer::getDebugSlotsEnabled () const { - return _debugSlots; - } +void SkeletonRenderer::setDebugSlotsEnabled (bool enabled) { + _debugSlots = enabled; +} +bool SkeletonRenderer::getDebugSlotsEnabled () const { + return _debugSlots; +} - void SkeletonRenderer::setDebugBonesEnabled (bool enabled) { - _debugBones = enabled; - } - bool SkeletonRenderer::getDebugBonesEnabled () const { - return _debugBones; - } +void SkeletonRenderer::setDebugBonesEnabled (bool enabled) { + _debugBones = enabled; +} +bool SkeletonRenderer::getDebugBonesEnabled () const { + return _debugBones; +} - void SkeletonRenderer::setDebugMeshesEnabled (bool enabled) { - _debugMeshes = enabled; - } - bool SkeletonRenderer::getDebugMeshesEnabled () const { - return _debugMeshes; - } +void SkeletonRenderer::setDebugMeshesEnabled (bool enabled) { + _debugMeshes = enabled; +} +bool SkeletonRenderer::getDebugMeshesEnabled () const { + return _debugMeshes; +} - void SkeletonRenderer::setDebugBoundingRectEnabled(bool enabled) { - _debugBoundingRect = enabled; - } +void SkeletonRenderer::setDebugBoundingRectEnabled(bool enabled) { + _debugBoundingRect = enabled; +} - bool SkeletonRenderer::getDebugBoundingRectEnabled() const { - return _debugBoundingRect; - } +bool SkeletonRenderer::getDebugBoundingRectEnabled() const { + return _debugBoundingRect; +} - void SkeletonRenderer::onEnter () { +void SkeletonRenderer::onEnter () { #if CC_ENABLE_SCRIPT_BINDING - if (_scriptType == kScriptTypeJavascript && ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter)) return; + if (_scriptType == kScriptTypeJavascript && ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnEnter)) return; #endif - Node::onEnter(); - scheduleUpdate(); - } + Node::onEnter(); + scheduleUpdate(); +} - void SkeletonRenderer::onExit () { +void SkeletonRenderer::onExit () { #if CC_ENABLE_SCRIPT_BINDING - if (_scriptType == kScriptTypeJavascript && ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnExit)) return; + if (_scriptType == kScriptTypeJavascript && ScriptEngineManager::sendNodeEventToJSExtended(this, kNodeOnExit)) return; #endif - Node::onExit(); - unscheduleUpdate(); - } + Node::onExit(); + unscheduleUpdate(); +} - // --- CCBlendProtocol +// --- CCBlendProtocol - const BlendFunc& SkeletonRenderer::getBlendFunc () const { - return _blendFunc; - } +const BlendFunc& SkeletonRenderer::getBlendFunc () const { + return _blendFunc; +} - void SkeletonRenderer::setBlendFunc (const BlendFunc &blendFunc) { - _blendFunc = blendFunc; - } +void SkeletonRenderer::setBlendFunc (const BlendFunc &blendFunc) { + _blendFunc = blendFunc; +} - void SkeletonRenderer::setOpacityModifyRGB (bool value) { - _premultipliedAlpha = value; - } +void SkeletonRenderer::setOpacityModifyRGB (bool value) { + _premultipliedAlpha = value; +} - bool SkeletonRenderer::isOpacityModifyRGB () const { - return _premultipliedAlpha; - } +bool SkeletonRenderer::isOpacityModifyRGB () const { + return _premultipliedAlpha; +} - namespace { - cocos2d::Rect computeBoundingRect(const float* coords, int vertexCount) { - assert(coords); - assert(vertexCount > 0); +namespace { + cocos2d::Rect computeBoundingRect(const float* coords, int vertexCount) { + assert(coords); + assert(vertexCount > 0); - const float* v = coords; - float minX = v[0]; - float minY = v[1]; - float maxX = minX; - float maxY = minY; - for (int i = 1; i < vertexCount; ++i) { - v += 2; - float x = v[0]; - float y = v[1]; - minX = std::min(minX, x); - minY = std::min(minY, y); - maxX = std::max(maxX, x); - maxY = std::max(maxY, y); - } - return { minX, minY, maxX - minX, maxY - minY }; + const float* v = coords; + float minX = v[0]; + float minY = v[1]; + float maxX = minX; + float maxY = minY; + for (int i = 1; i < vertexCount; ++i) { + v += 2; + float x = v[0]; + float y = v[1]; + minX = std::min(minX, x); + minY = std::min(minY, y); + maxX = std::max(maxX, x); + maxY = std::max(maxY, y); } + return { minX, minY, maxX - minX, maxY - minY }; + } - bool slotIsOutRange(Slot& slot, int startSlotIndex, int endSlotIndex) { - const int index = slot.getData().getIndex(); - return startSlotIndex > index || endSlotIndex < index; - } + bool slotIsOutRange(Slot& slot, int startSlotIndex, int endSlotIndex) { + const int index = slot.getData().getIndex(); + return startSlotIndex > index || endSlotIndex < index; + } - bool nothingToDraw(Slot& slot, int startSlotIndex, int endSlotIndex) { - Attachment *attachment = slot.getAttachment(); - if (!attachment || - slotIsOutRange(slot, startSlotIndex, endSlotIndex) || - !slot.getBone().isActive() || - slot.getColor().a == 0) + bool nothingToDraw(Slot& slot, int startSlotIndex, int endSlotIndex) { + Attachment *attachment = slot.getAttachment(); + if (!attachment || + slotIsOutRange(slot, startSlotIndex, endSlotIndex) || + !slot.getBone().isActive() || + slot.getColor().a == 0) + return true; + if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) { + if (static_cast(attachment)->getColor().a == 0) return true; + } + else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { + if (static_cast(attachment)->getColor().a == 0) + return true; + } + return false; + } + + int computeTotalCoordCount(Skeleton& skeleton, int startSlotIndex, int endSlotIndex) { + int coordCount = 0; + for (size_t i = 0; i < skeleton.getSlots().size(); ++i) { + Slot& slot = *skeleton.getSlots()[i]; + if (nothingToDraw(slot, startSlotIndex, endSlotIndex)) { + continue; + } + Attachment* const attachment = slot.getAttachment(); if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) { - if (static_cast(attachment)->getColor().a == 0) - return true; + coordCount += 8; } else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { - if (static_cast(attachment)->getColor().a == 0) - return true; + MeshAttachment* const mesh = static_cast(attachment); + coordCount += mesh->getWorldVerticesLength(); } - return false; - } - - int computeTotalCoordCount(Skeleton& skeleton, int startSlotIndex, int endSlotIndex) { - int coordCount = 0; - for (size_t i = 0; i < skeleton.getSlots().size(); ++i) { - Slot& slot = *skeleton.getSlots()[i]; - if (nothingToDraw(slot, startSlotIndex, endSlotIndex)) { - continue; - } - Attachment* const attachment = slot.getAttachment(); - if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) { - coordCount += 8; - } - else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { - MeshAttachment* const mesh = static_cast(attachment); - coordCount += mesh->getWorldVerticesLength(); - } - } - return coordCount; - } - - - void transformWorldVertices(float* dstCoord, int coordCount, Skeleton& skeleton, int startSlotIndex, int endSlotIndex) { - float* dstPtr = dstCoord; -#ifndef NDEBUG - float* const dstEnd = dstCoord + coordCount; -#endif - for (size_t i = 0; i < skeleton.getSlots().size(); ++i) { - /*const*/ Slot& slot = *skeleton.getDrawOrder()[i]; // match the draw order of SkeletonRenderer::Draw - if (nothingToDraw(slot, startSlotIndex, endSlotIndex)) { - continue; - } - Attachment* const attachment = slot.getAttachment(); - if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) { - RegionAttachment* const regionAttachment = static_cast(attachment); - assert(dstPtr + 8 <= dstEnd); - regionAttachment->computeWorldVertices(slot.getBone(), dstPtr, 0, 2); - dstPtr += 8; - } else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { - MeshAttachment* const mesh = static_cast(attachment); - assert(dstPtr + mesh->getWorldVerticesLength() <= dstEnd); - mesh->computeWorldVertices(slot, 0, mesh->getWorldVerticesLength(), dstPtr, 0, 2); - dstPtr += mesh->getWorldVerticesLength(); - } - } - assert(dstPtr == dstEnd); - } - - void interleaveCoordinates(float* dst, const float* src, int count, int dstStride) { - if (dstStride == 2) { - memcpy(dst, src, sizeof(float) * count * 2); - } else { - for (int i = 0; i < count; ++i) { - dst[0] = src[0]; - dst[1] = src[1]; - dst += dstStride; - src += 2; - } - } - - } - - BlendFunc makeBlendFunc(BlendMode blendMode, bool premultipliedAlpha) { - BlendFunc blendFunc; - -#if COCOS2D_VERSION < 0x00040000 - switch (blendMode) { - case BlendMode_Additive: - blendFunc.src = premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; - blendFunc.dst = GL_ONE; - break; - case BlendMode_Multiply: - blendFunc.src = GL_DST_COLOR; - blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA; - break; - case BlendMode_Screen: - blendFunc.src = GL_ONE; - blendFunc.dst = GL_ONE_MINUS_SRC_COLOR; - break; - default: - blendFunc.src = premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; - blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA; - break; - } -#else - switch (blendMode) { - case BlendMode_Additive: - blendFunc.src = premultipliedAlpha ? backend::BlendFactor::ONE : backend::BlendFactor::SRC_ALPHA; - blendFunc.dst = backend::BlendFactor::ONE; - break; - case BlendMode_Multiply: - blendFunc.src = backend::BlendFactor::DST_COLOR; - blendFunc.dst = backend::BlendFactor::ONE_MINUS_SRC_ALPHA; - break; - case BlendMode_Screen: - blendFunc.src = backend::BlendFactor::ONE; - blendFunc.dst = backend::BlendFactor::ONE_MINUS_SRC_COLOR; - break; - default: - blendFunc.src = premultipliedAlpha ? backend::BlendFactor::ONE : backend::BlendFactor::SRC_ALPHA; - blendFunc.dst = backend::BlendFactor::ONE_MINUS_SRC_ALPHA; - } -#endif - return blendFunc; - } - - - bool cullRectangle(Renderer* renderer, const Mat4& transform, const cocos2d::Rect& rect) { - if (Camera::getVisitingCamera() == nullptr) - return false; - - auto director = Director::getInstance(); - auto scene = director->getRunningScene(); - - if (!scene || (scene && Camera::getDefaultCamera() != Camera::getVisitingCamera())) - return false; - - Rect visibleRect(director->getVisibleOrigin(), director->getVisibleSize()); - - // transform center point to screen space - float hSizeX = rect.size.width/2; - float hSizeY = rect.size.height/2; - Vec3 v3p(rect.origin.x + hSizeX, rect.origin.y + hSizeY, 0); - transform.transformPoint(&v3p); - Vec2 v2p = Camera::getVisitingCamera()->projectGL(v3p); - - // convert content size to world coordinates - float wshw = std::max(fabsf(hSizeX * transform.m[0] + hSizeY * transform.m[4]), fabsf(hSizeX * transform.m[0] - hSizeY * transform.m[4])); - float wshh = std::max(fabsf(hSizeX * transform.m[1] + hSizeY * transform.m[5]), fabsf(hSizeX * transform.m[1] - hSizeY * transform.m[5])); - - // enlarge visible rect half size in screen coord - visibleRect.origin.x -= wshw; - visibleRect.origin.y -= wshh; - visibleRect.size.width += wshw * 2; - visibleRect.size.height += wshh * 2; - return !visibleRect.containsPoint(v2p); - } - - - Color4B ColorToColor4B(const Color& color) { - return { (uint8_t)(color.r * 255.f), (uint8_t)(color.g * 255.f), (uint8_t)(color.b * 255.f), (uint8_t)(color.a * 255.f) }; } + return coordCount; } + + void transformWorldVertices(float* dstCoord, int coordCount, Skeleton& skeleton, int startSlotIndex, int endSlotIndex) { + float* dstPtr = dstCoord; +#ifndef NDEBUG + float* const dstEnd = dstCoord + coordCount; +#endif + for (size_t i = 0; i < skeleton.getSlots().size(); ++i) { + /*const*/ Slot& slot = *skeleton.getDrawOrder()[i]; // match the draw order of SkeletonRenderer::Draw + if (nothingToDraw(slot, startSlotIndex, endSlotIndex)) { + continue; + } + Attachment* const attachment = slot.getAttachment(); + if (attachment->getRTTI().isExactly(RegionAttachment::rtti)) { + RegionAttachment* const regionAttachment = static_cast(attachment); + assert(dstPtr + 8 <= dstEnd); + regionAttachment->computeWorldVertices(slot.getBone(), dstPtr, 0, 2); + dstPtr += 8; + } else if (attachment->getRTTI().isExactly(MeshAttachment::rtti)) { + MeshAttachment* const mesh = static_cast(attachment); + assert(dstPtr + mesh->getWorldVerticesLength() <= dstEnd); + mesh->computeWorldVertices(slot, 0, mesh->getWorldVerticesLength(), dstPtr, 0, 2); + dstPtr += mesh->getWorldVerticesLength(); + } + } + assert(dstPtr == dstEnd); + } + + void interleaveCoordinates(float* dst, const float* src, int count, int dstStride) { + if (dstStride == 2) { + memcpy(dst, src, sizeof(float) * count * 2); + } else { + for (int i = 0; i < count; ++i) { + dst[0] = src[0]; + dst[1] = src[1]; + dst += dstStride; + src += 2; + } + } + + } + + BlendFunc makeBlendFunc(BlendMode blendMode, bool premultipliedAlpha) { + BlendFunc blendFunc; + +#if COCOS2D_VERSION < 0x00040000 + switch (blendMode) { + case BlendMode_Additive: + blendFunc.src = premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; + blendFunc.dst = GL_ONE; + break; + case BlendMode_Multiply: + blendFunc.src = GL_DST_COLOR; + blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA; + break; + case BlendMode_Screen: + blendFunc.src = GL_ONE; + blendFunc.dst = GL_ONE_MINUS_SRC_COLOR; + break; + default: + blendFunc.src = premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA; + blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA; + break; + } +#else + switch (blendMode) { + case BlendMode_Additive: + blendFunc.src = premultipliedAlpha ? backend::BlendFactor::ONE : backend::BlendFactor::SRC_ALPHA; + blendFunc.dst = backend::BlendFactor::ONE; + break; + case BlendMode_Multiply: + blendFunc.src = backend::BlendFactor::DST_COLOR; + blendFunc.dst = backend::BlendFactor::ONE_MINUS_SRC_ALPHA; + break; + case BlendMode_Screen: + blendFunc.src = backend::BlendFactor::ONE; + blendFunc.dst = backend::BlendFactor::ONE_MINUS_SRC_COLOR; + break; + default: + blendFunc.src = premultipliedAlpha ? backend::BlendFactor::ONE : backend::BlendFactor::SRC_ALPHA; + blendFunc.dst = backend::BlendFactor::ONE_MINUS_SRC_ALPHA; + } +#endif + return blendFunc; + } + + + bool cullRectangle(Renderer* renderer, const Mat4& transform, const cocos2d::Rect& rect) { + if (Camera::getVisitingCamera() == nullptr) + return false; + + auto director = Director::getInstance(); + auto scene = director->getRunningScene(); + + if (!scene || (scene && Camera::getDefaultCamera() != Camera::getVisitingCamera())) + return false; + + Rect visibleRect(director->getVisibleOrigin(), director->getVisibleSize()); + + // transform center point to screen space + float hSizeX = rect.size.width/2; + float hSizeY = rect.size.height/2; + Vec3 v3p(rect.origin.x + hSizeX, rect.origin.y + hSizeY, 0); + transform.transformPoint(&v3p); + Vec2 v2p = Camera::getVisitingCamera()->projectGL(v3p); + + // convert content size to world coordinates + float wshw = std::max(fabsf(hSizeX * transform.m[0] + hSizeY * transform.m[4]), fabsf(hSizeX * transform.m[0] - hSizeY * transform.m[4])); + float wshh = std::max(fabsf(hSizeX * transform.m[1] + hSizeY * transform.m[5]), fabsf(hSizeX * transform.m[1] - hSizeY * transform.m[5])); + + // enlarge visible rect half size in screen coord + visibleRect.origin.x -= wshw; + visibleRect.origin.y -= wshh; + visibleRect.size.width += wshw * 2; + visibleRect.size.height += wshh * 2; + return !visibleRect.containsPoint(v2p); + } + + + Color4B ColorToColor4B(const Color& color) { + return { (uint8_t)(color.r * 255.f), (uint8_t)(color.g * 255.f), (uint8_t)(color.b * 255.f), (uint8_t)(color.a * 255.f) }; + } +} + } diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java index b37d33fc9..80f8fb5f9 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonRenderer.java @@ -91,7 +91,10 @@ public class SkeletonRenderer { Object[] drawOrder = skeleton.drawOrder.items; for (int i = 0, n = skeleton.drawOrder.size; i < n; i++) { Slot slot = (Slot)drawOrder[i]; - if (!slot.bone.active) continue; + if (!slot.bone.active) { + clipper.clipEnd(slot); + continue; + } Attachment attachment = slot.attachment; if (attachment instanceof RegionAttachment) { RegionAttachment region = (RegionAttachment)attachment; @@ -169,7 +172,10 @@ public class SkeletonRenderer { Object[] drawOrder = skeleton.drawOrder.items; for (int i = 0, n = skeleton.drawOrder.size; i < n; i++) { Slot slot = (Slot)drawOrder[i]; - if (!slot.bone.active) continue; + if (!slot.bone.active) { + clipper.clipEnd(slot); + continue; + } Texture texture = null; int vertexSize = clipper.isClipping() ? 2 : 5; Attachment attachment = slot.attachment; @@ -292,7 +298,10 @@ public class SkeletonRenderer { Object[] drawOrder = skeleton.drawOrder.items; for (int i = 0, n = skeleton.drawOrder.size; i < n; i++) { Slot slot = (Slot)drawOrder[i]; - if (!slot.bone.active) continue; + if (!slot.bone.active) { + clipper.clipEnd(slot); + continue; + } Texture texture = null; int vertexSize = clipper.isClipping() ? 2 : 6; Attachment attachment = slot.attachment; diff --git a/spine-ts/README.md b/spine-ts/README.md index 4ace35ba0..981c8286a 100644 --- a/spine-ts/README.md +++ b/spine-ts/README.md @@ -1,17 +1,18 @@ - # spine-ts +# spine-ts The spine-ts runtime provides functionality to load and manipulate [Spine](http://esotericsoftware.com) skeletal animation data using TypeScript and JavaScript. spine-ts is split up into multiple modules: -1. **Core**: `core/`, the core classes to load and process Spine models -1. **WebGL**: `webgl/`, a self-contained WebGL backend, build on the core classes -1. **Canvas**: `canvas/`, a self-contained Canvas backend, build on the core classes -1. **THREE.JS**: `threejs/`, a self-contained THREE.JS backend, build on the core classes -1. **Player**: `player/`, a self-contained player to easily display Spine animations on your website, build on core classes & WebGL backend. +1. **Core**: `core/`, the core classes to load and process Spine skeletons. +1. **WebGL**: `webgl/`, a self-contained WebGL backend, built on the core classes. +1. **Canvas**: `canvas/`, a self-contained Canvas backend, built on the core classes. +1. **THREE.JS**: `threejs/`, a self-contained THREE.JS backend, built on the core classes. +1. **Player**: `player/`, a self-contained player to easily display Spine animations on your website, built on core the classes and WebGL backend. -While the source code for the core library and backends is written in TypeScript, all code is compiled to easily consumable JavaScript. +While the source code for the core library and backends is written in TypeScript, all code is compiled to JavaScript. ## Licensing + You are welcome to evaluate the Spine Runtimes and the examples we provide in this repository free of charge. You can integrate the Spine Runtimes into your software free of charge, but users of your software must have their own [Spine license](https://esotericsoftware.com/spine-purchase). Please make your users aware of this requirement! This option is often chosen by those making development tools, such as an SDK, game toolkit, or software library. @@ -22,17 +23,16 @@ For the official legal terms governing the Spine Runtimes, please read the [Spin ## Spine version -spine-ts works with data exported from Spine 3.9.xx. +spine-ts works with data exported from Spine 3.8.xx. -spine-ts WebGL & players backends supports all Spine features. +The spine-ts WebGL and Player backends support all Spine features. -spine-ts Canvas does not support white space stripped texture atlases, color tinting, mesh attachments and clipping. Only the alpha channel from tint colors is applied. Experimental support for mesh attachments can be enabled by setting `spine.canvas.SkeletonRenderer.useTriangleRendering` to true. Note that this method is slow and may lead to artifacts on some browsers. +spine-ts Canvas does not support white space stripped texture atlases, color tinting, mesh attachments, or clipping. Only the alpha channel from tint colors is applied. Experimental support for mesh attachments can be enabled by setting `spine.canvas.SkeletonRenderer.useTriangleRendering` to true. Note that this experimental mesh rendering is slow and may lead to artifacts on some browsers. -spine-ts THREE.JS does not support two color tinting & blend modes. The THREE.JS backend provides `SkeletonMesh.zOffset` to avoid z-fighting. Adjust to your near/far plane settings. - -spine-ts does not yet support loading the binary format. +spine-ts THREE.JS does not support two color tinting or blend modes. The THREE.JS backend provides `SkeletonMesh.zOffset` to avoid z-fighting. Adjust to your near/far plane settings. ## Usage + 1. Download the Spine Runtimes source using [git](https://help.github.com/articles/set-up-git) or by downloading it as a zip via the download button above. 2. To use only the core library without rendering support, include the `build/spine-core.js` file in your project. 3. To use the WebGL backend, include the `build/spine-webgl.js` file in your project. @@ -42,89 +42,102 @@ spine-ts does not yet support loading the binary format. All `*.js` files are self-contained and include both the core and respective backend classes. -If you write your app with TypeScript, additionally copy the corresponding `build/spine-*.d.ts` file to your project. +If you write your app with TypeScript, additionally copy the corresponding `build/spine-*.d.ts` file into your project. -**Note:** If you are using the compiled `.js` files with ES6 or other module systems, you have to add +**Note:** If you are using the compiled `.js` files with ES6 or other module systems, you need to add: ``` export { spine }; ``` -At the bottom of the `.js` file you are using. You can then import the module as usual, e.g.: +At the bottom of the `.js` file you are using. You can then import the module as usual, for example: ``` import { spine } from './spine-webgl.js'; ``` ## Examples -To run the examples, the image, atlas, and JSON files must be served by a webserver, they can't be loaded from your local disk. Spawn a light-weight web server in the root of spine-ts, then navigate to the `index.html` file for the example you want to view. E.g.: + +To run the various examples found in each of the spine-ts backend folders, the image, atlas, and JSON files must be served by a webserver. For security reasons browsers will not load these files from your local disk. To work around this, you can spawn a lightweight web server in the spine-ts folder, then navigate to the `index.html` file for the example you want to view. For example: ``` cd spine-ts -python -m SimpleHTTPServer +python -m SimpleHTTPServer // for Python 2 +python -m http.server // for Python 3 ``` -Then open `http://localhost:8000/webgl/example`, `http://localhost:8000/canvas/example`, `https://localhost:8000/threejs/example` or `http://localhost:8000/player/example` in your browser. +Then open `http://localhost:8000/webgl/example`, `http://localhost:8000/canvas/example`, `https://localhost:8000/threejs/example`, or `http://localhost:8000/player/example` in your browser. -## WebGL Demos -The spine-ts WebGL demos load their image, atlas, and JSON files from our webserver and so can be run directly, without needing a webserver. The demos can be viewed [all on one page](http://esotericsoftware.com/spine-demos/) or in individual, standalone pages which are easy for you to explore and edit. See the [standalone demos source code](webgl/demos) and view the pages here: +### WebGL demos -- [Spine vs sprite sheets](http://rawgit.com/EsotericSoftware/spine-runtimes/3.6/spine-ts/webgl/demos/spritesheets.html) -- [Image changes](http://rawgit.com/EsotericSoftware/spine-runtimes/3.6/spine-ts/webgl/demos/imagechanges.html) -- [Transitions](http://rawgit.com/EsotericSoftware/spine-runtimes/3.6/spine-ts/webgl/demos/transitions.html) -- [Meshes](http://rawgit.com/EsotericSoftware/spine-runtimes/3.6/spine-ts/webgl/demos/meshes.html) -- [Skins](http://rawgit.com/EsotericSoftware/spine-runtimes/3.6/spine-ts/webgl/demos/skins.html) -- [Hoverboard](http://rawgit.com/EsotericSoftware/spine-runtimes/3.6/spine-ts/webgl/demos/hoverboard.html) -- [Vine](http://rawgit.com/EsotericSoftware/spine-runtimes/3.6/spine-ts/webgl/demos/vine.html) -- [Clipping](http://rawgit.com/EsotericSoftware/spine-runtimes/3.6/spine-ts/webgl/demos/clipping.html) -- [Stretchyman](http://rawgit.com/EsotericSoftware/spine-runtimes/3.6/spine-ts/webgl/demos/stretchyman.html) -- [Tank](http://rawgit.com/EsotericSoftware/spine-runtimes/3.6/spine-ts/webgl/demos/tank.html) -- [Transform constraints](http://rawgit.com/EsotericSoftware/spine-runtimes/3.6/spine-ts/webgl/demos/transforms.html) +The spine-ts WebGL demos can be viewed [all on one page](http://esotericsoftware.com/spine-demos/) or in individual, standalone pages which are easy for you to explore and edit. See the [standalone demos source code](webgl/demos) and view the pages here: + +- [Spine vs sprite sheets](http://rawgit.com/EsotericSoftware/spine-runtimes/3.8/spine-ts/webgl/demos/spritesheets.html) +- [Image changes](http://rawgit.com/EsotericSoftware/spine-runtimes/3.8/spine-ts/webgl/demos/imagechanges.html) +- [Transitions](http://rawgit.com/EsotericSoftware/spine-runtimes/3.8/spine-ts/webgl/demos/transitions.html) +- [Meshes](http://rawgit.com/EsotericSoftware/spine-runtimes/3.8/spine-ts/webgl/demos/meshes.html) +- [Skins](http://rawgit.com/EsotericSoftware/spine-runtimes/3.8/spine-ts/webgl/demos/skins.html) +- [Hoverboard](http://rawgit.com/EsotericSoftware/spine-runtimes/3.8/spine-ts/webgl/demos/hoverboard.html) +- [Vine](http://rawgit.com/EsotericSoftware/spine-runtimes/3.8/spine-ts/webgl/demos/vine.html) +- [Clipping](http://rawgit.com/EsotericSoftware/spine-runtimes/3.8/spine-ts/webgl/demos/clipping.html) +- [Stretchyman](http://rawgit.com/EsotericSoftware/spine-runtimes/3.8/spine-ts/webgl/demos/stretchyman.html) +- [Tank](http://rawgit.com/EsotericSoftware/spine-runtimes/3.8/spine-ts/webgl/demos/tank.html) +- [Transform constraints](http://rawgit.com/EsotericSoftware/spine-runtimes/3.8/spine-ts/webgl/demos/transforms.html) Please note that Chrome and possibly other browsers do not use the original CORS headers when loading cached resources. After the initial page load for a demo, you may need to forcefully refresh (hold `shift` and click refresh) or clear your browser cache. -## Development Setup -The spine-ts runtime and the various backends are implemented in TypeScript for greater maintainability and better tooling support. To -setup a development environment, follow these steps. +### WebGL examples -1. Install [NPM](https://nodejs.org/en/download/) and make sure it's available on the command line -2. On the command line, Install the TypeScript compiler via `npm install -g typescript` -3. Install [Visual Studio Code](https://code.visualstudio.com/) -4. On the command line, change into the `spine-ts` directory +The WebGL demos serve well as examples, showing various ways to use the APIs. We also provide a simple, self-contained example with UI to control the skeletons: + +- [WebGL example](http://rawgit.com/EsotericSoftware/spine-runtimes/3.8/spine-ts/webgl/example/index.html) + +A barebones example is also available. It doesn't use JQuery and shows the minimal code necessary to use spine-ts with WebGL to load and render a skeleton: + +- [WebGL barebones](http://rawgit.com/EsotericSoftware/spine-runtimes/3.8/spine-ts/webgl/example/barebones.html) + +## Development setup + +The spine-ts runtime and the various backends are implemented in TypeScript for greater maintainability and better tooling support. To setup a development environment, follow these steps: + +1. Install [NPM](https://nodejs.org/en/download/) and make sure it's available on the command line. +2. On the command line, Install the TypeScript compiler via `npm install -g typescript`. +3. Install [Visual Studio Code](https://code.visualstudio.com/). +4. On the command line, change into the `spine-ts` directory. 5. Start the TypeScript compiler in watcher mode for the backend you want to work on: - * **Core**: `tsc -w -p tsconfig.core.json`, builds `core/src`, outputs `build/spine-core.js|d.ts|js.map` - * **WebGL**: `tsc -w -p tsconfig.webgl.json`, builds `core/src` and `webgl/src`, outputs `build/spine-webgl.js|d.ts|js.map` - * **Canvas**: `tsc -w -p tsconfig.canvas.json`, builds `core/src` and `canvas/src`, outputs `build/spine-canvas.js|d.ts|js.map` - * **THREE.JS**: `tsc -w -p tsconfig.threejs.json`, builds `core/src` and `threejs/src`, outputs `build/spine-threejs.js|d.ts|js.map` - * **Player**: `tsc -w -p tsconfig.player.json`, builds `core/src` and `player/src`, outputs `build/spine-player.js|d.ts|js.map` -6. Open the `spine-ts` folder in Visual Studio Code. VS Code will use the `tsconfig.json` file all source files from core and all -backends for your development pleasure. The actual JavaScript output is still created by the command line TypeScript compiler process from the previous step. + * **Core**: `tsc -w -p tsconfig.core.json`, builds `core/src`, outputs `build/spine-core.js|d.ts|js.map`. + * **WebGL**: `tsc -w -p tsconfig.webgl.json`, builds `core/src` and `webgl/src`, outputs `build/spine-webgl.js|d.ts|js.map`. + * **Canvas**: `tsc -w -p tsconfig.canvas.json`, builds `core/src` and `canvas/src`, outputs `build/spine-canvas.js|d.ts|js.map`. + * **THREE.JS**: `tsc -w -p tsconfig.threejs.json`, builds `core/src` and `threejs/src`, outputs `build/spine-threejs.js|d.ts|js.map`. + * **Player**: `tsc -w -p tsconfig.player.json`, builds `core/src` and `player/src`, outputs `build/spine-player.js|d.ts|js.map`. +6. Open the `spine-ts` folder in Visual Studio Code. VS Code will use the `tsconfig.json` file to find all source files for your development pleasure. The actual JavaScript output is still created by the command line TypeScript compiler process from the previous step. -Each backend contains an `example/` folder with an `index.html` file that demonstrates the respective backend. For development, we -suggest to run a HTTP server in the root of `spine-ts`, e.g. +Each backend contains an `example/` folder with an `index.html` file that demonstrates the respective backend. For development, we suggest to run a HTTP server in the root of `spine-ts`, for example: ``` cd spine-ts -python -m SimpleHTTPServer +python -m SimpleHTTPServer // for Python 2 +python -m http.server // for Python 3 ``` -Then navigate to `http://localhost:8000/webgl/example`, `http://localhost:8000/canvas/example`, `http://localhost:8000/threejs/example` or `http://localhost:8000/player/example` +Then navigate to `http://localhost:8000/webgl/example`, `http://localhost:8000/canvas/example`, `http://localhost:8000/threejs/example`, or `http://localhost:8000/player/example`. + +### WebGL backend -### Spine-ts WebGL backend By default, the spine-ts WebGL backend supports two-color tinting. This requires more per vertex data to be submitted to the GPU and the fragment shader has to do a few more arithmetic operations. It has a neglible effect on performance, but you can disable two-color tinting like this: ```javascript -// If you use SceneRenderer, disable two-color tinting via the last constructor argument +// If you use SceneRenderer, disable two-color tinting via the last constructor argument. var sceneRenderer = new spine.SceneRenderer(canvas, gl, false); -// If you use SkeletonRenderer and PolygonBatcher directly, -// disable two-color tinting in the respective constructor -// and use the shader returned by Shader.newColoredTextured() -// instead of Shader.newTwoColoredTextured() +// If you use SkeletonRenderer and PolygonBatcher directly, disable two-color +// tinting in the respective constructor and use the shader returned by +// Shader.newColoredTextured() instead of Shader.newTwoColoredTextured(). var batcher = new spine.PolygonBatcher(gl, false); var skeletonRenderer = new spine.SkeletonRenderer(gl, false); var shader = Shader.newColoredTextured(); ``` ### Using the Player -Please see the documentation for the [Spine Web Player](https://esotericsoftware.com/spine-player) + +Please see the documentation for the [Spine Web Player](https://esotericsoftware.com/spine-player). diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonGraphicInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonGraphicInspector.cs index 5f9c5942a..6af4c6901 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonGraphicInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonGraphicInspector.cs @@ -37,7 +37,6 @@ using UnityEditor; namespace Spine.Unity.Editor { using Icons = SpineEditorUtilities.Icons; - [InitializeOnLoad] [CustomEditor(typeof(SkeletonGraphic))] [CanEditMultipleObjects] public class SkeletonGraphicInspector : UnityEditor.Editor { @@ -51,7 +50,7 @@ namespace Spine.Unity.Editor { SerializedProperty material, color; SerializedProperty skeletonDataAsset, initialSkinName; - SerializedProperty startingAnimation, startingLoop, timeScale, freeze, unscaledTime, tintBlack; + SerializedProperty startingAnimation, startingLoop, timeScale, freeze, updateWhenInvisible, unscaledTime, tintBlack; SerializedProperty initialFlipX, initialFlipY; SerializedProperty meshGeneratorSettings; SerializedProperty allowMultipleCanvasRenderers, separatorSlotNames, enableSeparatorSlots, updateSeparatorPartLocation; @@ -111,6 +110,7 @@ namespace Spine.Unity.Editor { timeScale = so.FindProperty("timeScale"); unscaledTime = so.FindProperty("unscaledTime"); freeze = so.FindProperty("freeze"); + updateWhenInvisible = so.FindProperty("updateWhenInvisible"); meshGeneratorSettings = so.FindProperty("meshGenerator").FindPropertyRelative("settings"); meshGeneratorSettings.isExpanded = SkeletonRendererInspector.advancedFoldout; @@ -172,6 +172,7 @@ namespace Spine.Unity.Editor { meshGeneratorSettings.isExpanded = true; using (new SpineInspectorUtility.BoxScope()) { + EditorGUILayout.PropertyField(meshGeneratorSettings, SpineInspectorUtility.TempContent("Advanced..."), includeChildren: true); SkeletonRendererInspector.advancedFoldout = meshGeneratorSettings.isExpanded; @@ -190,6 +191,8 @@ namespace Spine.Unity.Editor { } EditorGUILayout.EndHorizontal(); + EditorGUILayout.PropertyField(updateWhenInvisible); + // warning box if (isSeparationEnabledButNotMultipleRenderers) { using (new SpineInspectorUtility.BoxScope()) { diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonRendererInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonRendererInspector.cs index 62f50ed22..1e8a3e50b 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonRendererInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonRendererInspector.cs @@ -59,7 +59,7 @@ namespace Spine.Unity.Editor { protected SerializedProperty skeletonDataAsset, initialSkinName; protected SerializedProperty initialFlipX, initialFlipY; - protected SerializedProperty singleSubmesh, separatorSlotNames, clearStateOnDisable, immutableTriangles, fixDrawOrder; + protected SerializedProperty updateWhenInvisible, singleSubmesh, separatorSlotNames, clearStateOnDisable, immutableTriangles, fixDrawOrder; protected SerializedProperty normals, tangents, zSpacing, pmaVertexColors, tintBlack; // MeshGenerator settings protected SerializedProperty maskInteraction; protected SerializedProperty maskMaterialsNone, maskMaterialsInside, maskMaterialsOutside; @@ -74,7 +74,7 @@ namespace Spine.Unity.Editor { protected bool deleteOutsideMaskMaterialsQueued = false; protected GUIContent SkeletonDataAssetLabel, SkeletonUtilityButtonContent; - protected GUIContent PMAVertexColorsLabel, ClearStateOnDisableLabel, ZSpacingLabel, ImmubleTrianglesLabel, TintBlackLabel, SingleSubmeshLabel, FixDrawOrderLabel; + protected GUIContent PMAVertexColorsLabel, ClearStateOnDisableLabel, ZSpacingLabel, ImmubleTrianglesLabel, TintBlackLabel, UpdateWhenInvisibleLabel, SingleSubmeshLabel, FixDrawOrderLabel; protected GUIContent NormalsLabel, TangentsLabel, MaskInteractionLabel; protected GUIContent MaskMaterialsHeadingLabel, MaskMaterialsNoneLabel, MaskMaterialsInsideLabel, MaskMaterialsOutsideLabel; protected GUIContent SetMaterialButtonLabel, ClearMaterialButtonLabel, DeleteMaterialButtonLabel; @@ -119,6 +119,7 @@ namespace Spine.Unity.Editor { TangentsLabel = new GUIContent("Solve Tangents", "Calculates the tangents per frame. Use this if you are using lit shaders (usually with normal maps) that require vertex tangents."); TintBlackLabel = new GUIContent("Tint Black (!)", "Adds black tint vertex data to the mesh as UV2 and UV3. Black tinting requires that the shader interpret UV2 and UV3 as black tint colors for this effect to work. You may also use the default [Spine/Skeleton Tint Black] shader.\n\nIf you only need to tint the whole skeleton and not individual parts, the [Spine/Skeleton Tint] shader is recommended for better efficiency and changing/animating the _Black material property via MaterialPropertyBlock."); SingleSubmeshLabel = new GUIContent("Use Single Submesh", "Simplifies submesh generation by assuming you are only using one Material and need only one submesh. This is will disable multiple materials, render separation, and custom slot materials."); + UpdateWhenInvisibleLabel = new GUIContent("Update When Invisible", "Update mode used when the MeshRenderer becomes invisible. Update mode is automatically reset to UpdateMode.FullUpdate when the mesh becomes visible again."); FixDrawOrderLabel = new GUIContent("Fix Draw Order", "Applies only when 3+ submeshes are used (2+ materials with alternating order, e.g. \"A B A\"). If true, GPU instancing will be disabled at all materials and MaterialPropertyBlocks are assigned at each material to prevent aggressive batching of submeshes by e.g. the LWRP renderer, leading to incorrect draw order (e.g. \"A1 B A2\" changed to \"A1A2 B\"). You can disable this parameter when everything is drawn correctly to save the additional performance cost. Note: the GPU instancing setting will remain disabled at affected material assets after exiting play mode, you have to enable it manually if you accidentally enabled this parameter."); MaskInteractionLabel = new GUIContent("Mask Interaction", "SkeletonRenderer's interaction with a Sprite Mask."); MaskMaterialsHeadingLabel = new GUIContent("Mask Interaction Materials", "Materials used for different interaction with sprite masks."); @@ -140,6 +141,7 @@ namespace Spine.Unity.Editor { pmaVertexColors = so.FindProperty("pmaVertexColors"); clearStateOnDisable = so.FindProperty("clearStateOnDisable"); tintBlack = so.FindProperty("tintBlack"); + updateWhenInvisible = so.FindProperty("updateWhenInvisible"); singleSubmesh = so.FindProperty("singleSubmesh"); fixDrawOrder = so.FindProperty("fixDrawOrder"); maskInteraction = so.FindProperty("maskInteraction"); @@ -319,6 +321,8 @@ namespace Spine.Unity.Editor { EditorGUILayout.LabelField("Renderer Settings", EditorStyles.boldLabel); using (new SpineInspectorUtility.LabelWidthScope()) { // Optimization options + if (updateWhenInvisible != null) EditorGUILayout.PropertyField(updateWhenInvisible, UpdateWhenInvisibleLabel); + if (singleSubmesh != null) EditorGUILayout.PropertyField(singleSubmesh, SingleSubmeshLabel); #if PER_MATERIAL_PROPERTY_BLOCKS if (fixDrawOrder != null) EditorGUILayout.PropertyField(fixDrawOrder, FixDrawOrderLabel); diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAttributeDrawers.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAttributeDrawers.cs index c5b38557b..33a928352 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAttributeDrawers.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAttributeDrawers.cs @@ -35,6 +35,7 @@ using System; using System.Collections.Generic; using System.Reflection; using Spine; +using System.Linq; namespace Spine.Unity.Editor { public struct SpineDrawerValuePair { @@ -177,8 +178,10 @@ namespace Spine.Unity.Editor { if (TargetAttribute.includeNone) menu.AddItem(new GUIContent(NoneString), !property.hasMultipleDifferentValues && string.IsNullOrEmpty(property.stringValue), HandleSelect, new SpineDrawerValuePair(string.Empty, property)); - for (int slotIndex = 0; slotIndex < data.Slots.Count; slotIndex++) { - string name = data.Slots.Items[slotIndex].Name; + IEnumerable orderedSlots = data.Slots.Items.OrderBy(slotData => slotData.Name); + foreach (SlotData slotData in orderedSlots) { + int slotIndex = slotData.Index; + string name = slotData.Name; if (name.StartsWith(targetAttribute.startsWith, StringComparison.Ordinal)) { if (targetAttribute.containsBoundingBoxes) { @@ -521,9 +524,17 @@ namespace Spine.Unity.Editor { menu.AddItem(new GUIContent(NoneString), !property.hasMultipleDifferentValues && string.IsNullOrEmpty(property.stringValue), HandleSelect, new SpineDrawerValuePair(string.Empty, property)); for (int i = 0; i < data.Bones.Count; i++) { - string name = data.Bones.Items[i].Name; - if (name.StartsWith(targetAttribute.startsWith, StringComparison.Ordinal)) - menu.AddItem(new GUIContent(name), !property.hasMultipleDifferentValues && name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property)); + var bone = data.Bones.Items[i]; + string name = bone.Name; + if (name.StartsWith(targetAttribute.startsWith, StringComparison.Ordinal)) { + // jointName = "root/hip/bone" to show a hierarchial tree. + string jointName = name; + var iterator = bone; + while ((iterator = iterator.Parent) != null) + jointName = string.Format("{0}/{1}", iterator.Name, jointName); + + menu.AddItem(new GUIContent(jointName), !property.hasMultipleDifferentValues && name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property)); + } } } diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs index d95dfb0f2..54988fdc1 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs @@ -256,7 +256,6 @@ namespace Spine.Unity.Editor { bool reimport = false) { var atlasPaths = new List(); - var spriteAtlasPaths = new List(); var imagePaths = new List(); var skeletonPaths = new List(); CompatibilityProblemInfo compatibilityProblemInfo = null; @@ -273,9 +272,6 @@ namespace Spine.Unity.Editor { if (str.EndsWith(".atlas.txt", System.StringComparison.Ordinal)) atlasPaths.Add(str); break; - case ".spriteatlas": - spriteAtlasPaths.Add(str); - break; case ".png": case ".jpg": imagePaths.Add(str); @@ -295,13 +291,13 @@ namespace Spine.Unity.Editor { } // Import atlases first. - var atlases = new List(); + var newAtlases = new List(); foreach (string ap in atlasPaths) { if (ap.StartsWith("Packages")) continue; TextAsset atlasText = AssetDatabase.LoadAssetAtPath(ap); AtlasAssetBase atlas = IngestSpineAtlas(atlasText, texturesWithoutMetaFile); - atlases.Add(atlas); + newAtlases.Add(atlas); } AddDependentSkeletonIfAtlasChanged(skeletonPaths, atlasPaths); @@ -328,13 +324,14 @@ namespace Spine.Unity.Editor { #if SPINE_TK2D IngestSpineProject(loadedAsset, null); #else - var localAtlases = FindAtlasesAtPath(dir); + var atlasesForSkeleton = FindAtlasesAtPath(dir); + atlasesForSkeleton.AddRange(newAtlases); var requiredPaths = GetRequiredAtlasRegions(skeletonPath); - var atlasMatch = GetMatchingAtlas(requiredPaths, localAtlases); + var atlasMatch = GetMatchingAtlas(requiredPaths, atlasesForSkeleton); if (atlasMatch != null || requiredPaths.Count == 0) { IngestSpineProject(loadedAsset, atlasMatch); } else { - SkeletonImportDialog(skeletonPath, localAtlases, requiredPaths, ref abortSkeletonImport); + SkeletonImportDialog(skeletonPath, atlasesForSkeleton, requiredPaths, ref abortSkeletonImport); } if (abortSkeletonImport) @@ -580,7 +577,10 @@ namespace Spine.Unity.Editor { } protectFromStackGarbageCollection.Remove(atlasAsset); - return (AtlasAssetBase)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(AtlasAssetBase)); + // note: at Asset Pipeline V2 this LoadAssetAtPath of the just created + // asset returns null, regardless of refresh calls. + var loadedAtlas = (AtlasAssetBase)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(AtlasAssetBase)); + return loadedAtlas != null ? loadedAtlas : atlasAsset; } public static bool SpriteAtlasSettingsNeedAdjustment (UnityEngine.U2D.SpriteAtlas spriteAtlas) { diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoundingBoxFollower.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoundingBoxFollower.cs index 570a2cc78..0ef19dd3a 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoundingBoxFollower.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoundingBoxFollower.cs @@ -177,6 +177,9 @@ namespace Spine.Unity { void OnDisable () { if (clearStateOnDisable) ClearState(); + + if (skeletonRenderer != null) + skeletonRenderer.OnRebuild -= HandleRebuild; } public void ClearState () { diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/PointFollower.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/PointFollower.cs index 699e42823..413b9306c 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/PointFollower.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/PointFollower.cs @@ -100,6 +100,11 @@ namespace Spine.Unity { } } + void OnDestroy () { + if (skeletonRenderer != null) + skeletonRenderer.OnRebuild -= HandleRebuildRenderer; + } + public void LateUpdate () { #if UNITY_EDITOR if (!Application.isPlaying) skeletonTransformIsParent = Transform.ReferenceEquals(skeletonTransform, transform.parent); diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs index 69679ff9b..112f231d5 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs @@ -185,9 +185,23 @@ namespace Spine.Unity { if (!valid || state == null) return; + wasUpdatedAfterInit = true; + if (updateMode < UpdateMode.OnlyAnimationStatus) + return; + UpdateAnimationStatus(deltaTime); + + if (updateMode == UpdateMode.OnlyAnimationStatus) + return; + ApplyAnimation(); + } + + protected void UpdateAnimationStatus (float deltaTime) { deltaTime *= timeScale; skeleton.Update(deltaTime); state.Update(deltaTime); + } + + protected void ApplyAnimation () { state.Apply(skeleton); if (_UpdateLocal != null) @@ -203,7 +217,6 @@ namespace Spine.Unity { if (_UpdateComplete != null) { _UpdateComplete(this); } - wasUpdatedAfterInit = true; } public override void LateUpdate () { diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs index 3ea70fbea..fd6a6f7f6 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs @@ -58,6 +58,16 @@ namespace Spine.Unity { public bool startingLoop; public float timeScale = 1f; public bool freeze; + + /// Update mode to optionally limit updates to e.g. only apply animations but not update the mesh. + public UpdateMode UpdateMode { get { return updateMode; } set { updateMode = value; } } + [SerializeField] protected UpdateMode updateMode = UpdateMode.FullUpdate; + + /// Update mode used when the MeshRenderer becomes invisible + /// (when OnBecameInvisible() is called). Update mode is automatically + /// reset to UpdateMode.FullUpdate when the mesh becomes visible again. + public UpdateMode updateWhenInvisible = UpdateMode.FullUpdate; + public bool unscaledTime; public bool allowMultipleCanvasRenderers = false; public List canvasRenderers = new List(); @@ -232,12 +242,27 @@ namespace Spine.Unity { public virtual void Update (float deltaTime) { if (!this.IsValid) return; + wasUpdatedAfterInit = true; + if (updateMode < UpdateMode.OnlyAnimationStatus) + return; + UpdateAnimationStatus(deltaTime); + + if (updateMode == UpdateMode.OnlyAnimationStatus) + return; + ApplyAnimation(); + } + + protected void UpdateAnimationStatus (float deltaTime) { deltaTime *= timeScale; skeleton.Update(deltaTime); state.Update(deltaTime); + } + + protected void ApplyAnimation () { state.Apply(skeleton); - if (UpdateLocal != null) UpdateLocal(this); + if (UpdateLocal != null) + UpdateLocal(this); skeleton.UpdateWorldTransform(); @@ -246,18 +271,27 @@ namespace Spine.Unity { skeleton.UpdateWorldTransform(); } - if (UpdateComplete != null) UpdateComplete(this); - wasUpdatedAfterInit = true; + if (UpdateComplete != null) + UpdateComplete(this); } public void LateUpdate () { // instantiation can happen from Update() after this component, leading to a missing Update() call. if (!wasUpdatedAfterInit) Update(0); if (freeze) return; - //this.SetVerticesDirty(); // Which is better? + if (updateMode <= UpdateMode.EverythingExceptMesh) return; + UpdateMesh(); } + public void OnBecameVisible () { + updateMode = UpdateMode.FullUpdate; + } + + public void OnBecameInvisible () { + updateMode = updateWhenInvisible; + } + public void ReapplySeparatorSlotNames () { if (!IsValid) return; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs index 6f72be6cc..f3291c538 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs @@ -78,14 +78,23 @@ namespace Spine.Unity { public void Update () { if (!valid) return; - #if UNITY_EDITOR + wasUpdatedAfterInit = true; + // animation status is kept by Mecanim Animator component + if (updateMode <= UpdateMode.OnlyAnimationStatus) + return; + ApplyAnimation(); + } + + protected void ApplyAnimation () { + #if UNITY_EDITOR var translatorAnimator = translator.Animator; if (translatorAnimator != null && !translatorAnimator.isInitialized) translatorAnimator.Rebind(); if (Application.isPlaying) { translator.Apply(skeleton); - } else { + } + else { if (translatorAnimator != null && translatorAnimator.isInitialized && translatorAnimator.isActiveAndEnabled && translatorAnimator.runtimeAnimatorController != null) { // Note: Rebind is required to prevent warning "Animator is not playing an AnimatorController" with prefabs @@ -93,9 +102,9 @@ namespace Spine.Unity { translator.Apply(skeleton); } } - #else + #else translator.Apply(skeleton); - #endif + #endif // UpdateWorldTransform and Bone Callbacks { @@ -112,7 +121,6 @@ namespace Spine.Unity { if (_UpdateComplete != null) _UpdateComplete(this); } - wasUpdatedAfterInit = true; } public override void LateUpdate () { diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs index e75c00682..2e7e9b88a 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs @@ -55,11 +55,11 @@ namespace Spine.Unity { [RequireComponent(typeof(MeshFilter), typeof(MeshRenderer)), DisallowMultipleComponent] [HelpURL("http://esotericsoftware.com/spine-unity-rendering")] public class SkeletonRenderer : MonoBehaviour, ISkeletonComponent, IHasSkeletonDataAsset { - [SerializeField] public SkeletonDataAsset skeletonDataAsset; + public SkeletonDataAsset skeletonDataAsset; #region Initialization settings /// Skin name to use when the Skeleton is initialized. - [SerializeField] [SpineSkin(defaultAsEmptyString:true)] public string initialSkinName; + [SpineSkin(defaultAsEmptyString:true)] public string initialSkinName; /// Enable this parameter when overwriting the Skeleton's skin from an editor script. /// Otherwise any changes will be overwritten by the next inspector update. @@ -71,10 +71,20 @@ namespace Spine.Unity { protected bool editorSkipSkinSync = false; #endif /// Flip X and Y to use when the Skeleton is initialized. - [SerializeField] public bool initialFlipX, initialFlipY; + public bool initialFlipX, initialFlipY; #endregion #region Advanced Render Settings + + /// Update mode to optionally limit updates to e.g. only apply animations but not update the mesh. + public UpdateMode UpdateMode { get { return updateMode; } set { updateMode = value; } } + [SerializeField] protected UpdateMode updateMode = UpdateMode.FullUpdate; + + /// Update mode used when the MeshRenderer becomes invisible + /// (when OnBecameInvisible() is called). Update mode is automatically + /// reset to UpdateMode.FullUpdate when the mesh becomes visible again. + public UpdateMode updateWhenInvisible = UpdateMode.FullUpdate; + // Submesh Separation /// Slot names used to populate separatorSlots list when the Skeleton is initialized. Changing this after initialization does nothing. [UnityEngine.Serialization.FormerlySerializedAs("submeshSeparators")][SerializeField][SpineSlot] protected string[] separatorSlotNames = new string[0]; @@ -361,6 +371,8 @@ namespace Spine.Unity { } #endif + if (updateMode <= UpdateMode.EverythingExceptMesh) return; + #if SPINE_OPTIONAL_RENDEROVERRIDE bool doMeshOverride = generateMeshOverride != null; if ((!meshRenderer.enabled) && !doMeshOverride) return; @@ -477,6 +489,14 @@ namespace Spine.Unity { OnMeshAndMaterialsUpdated(this); } + public void OnBecameVisible () { + updateMode = UpdateMode.FullUpdate; + } + + public void OnBecameInvisible () { + updateMode = updateWhenInvisible; + } + public void FindAndApplySeparatorSlots (string startsWith, bool clearExistingSeparators = true, bool updateStringArray = false) { if (string.IsNullOrEmpty(startsWith)) return; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/ISkeletonAnimation.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/ISkeletonAnimation.cs index 496957574..36e300ec9 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/ISkeletonAnimation.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/ISkeletonAnimation.cs @@ -28,6 +28,13 @@ *****************************************************************************/ namespace Spine.Unity { + public enum UpdateMode { + Nothing = 0, + OnlyAnimationStatus, + EverythingExceptMesh, + FullUpdate + }; + public delegate void UpdateBonesDelegate (ISkeletonAnimation animated); /// A Spine-Unity Component that animates a Skeleton but not necessarily with a Spine.AnimationState. diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common.cginc b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common.cginc index 9dc1709d4..73a6e1875 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common.cginc +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/CGIncludes/Spine-Skeleton-Lit-Common.cginc @@ -83,7 +83,13 @@ VertexOutput vert (appdata v) { float3 eyePos = UnityObjectToViewPos(float4(v.pos, 1)).xyz; //mul(UNITY_MATRIX_MV, float4(v.pos,1)).xyz; half3 fixedNormal = half3(0,0,-1); half3 eyeNormal = normalize(mul((float3x3)UNITY_MATRIX_IT_MV, fixedNormal)); - //half3 eyeNormal = half3(0,0,1); + +#ifdef _DOUBLE_SIDED_LIGHTING + // unfortunately we have to compute the sign here in the vertex shader + // instead of using VFACE in fragment shader stage. + half faceSign = sign(eyeNormal.z); + eyeNormal *= faceSign; +#endif // Lights half3 lcolor = half4(0,0,0,1).rgb + color.rgb * glstate_lightmodel_ambient.rgb; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Outline/Spine-Skeleton-Lit-Outline.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Outline/Spine-Skeleton-Lit-Outline.shader index 411036fee..75c0a9f5a 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Outline/Spine-Skeleton-Lit-Outline.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Outline/Spine-Skeleton-Lit-Outline.shader @@ -5,6 +5,7 @@ Shader "Spine/Outline/Skeleton Lit" { _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 + [Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0 [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0 [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Outline/Spine-Skeleton-Lit-ZWrite-Outline.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Outline/Spine-Skeleton-Lit-ZWrite-Outline.shader index 4cdf0e7c7..044308562 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Outline/Spine-Skeleton-Lit-ZWrite-Outline.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Outline/Spine-Skeleton-Lit-ZWrite-Outline.shader @@ -6,6 +6,7 @@ Shader "Spine/Outline/Skeleton Lit ZWrite" { _ShadowAlphaCutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 + [Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0 [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0 [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit-ZWrite.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit-ZWrite.shader index c8f43fd3d..95f77b77f 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit-ZWrite.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit-ZWrite.shader @@ -8,6 +8,7 @@ Shader "Spine/Skeleton Lit ZWrite" { _ShadowAlphaCutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 + [Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0 [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0 [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default @@ -42,6 +43,7 @@ Shader "Spine/Skeleton Lit ZWrite" { CGPROGRAM #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT + #pragma shader_feature _ _DOUBLE_SIDED_LIGHTING #pragma vertex vert #pragma fragment frag #pragma target 2.0 diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit.shader b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit.shader index b2e90b031..f10c478fa 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit.shader +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Shaders/Spine-Skeleton-Lit.shader @@ -7,6 +7,7 @@ Shader "Spine/Skeleton Lit" { _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 + [Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0 [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0 [HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default @@ -41,6 +42,7 @@ Shader "Spine/Skeleton Lit" { CGPROGRAM #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT + #pragma shader_feature _ _DOUBLE_SIDED_LIGHTING #pragma vertex vert #pragma fragment frag #pragma target 2.0 diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/MaterialChecks.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/MaterialChecks.cs index ce905ea55..0e1174a75 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/MaterialChecks.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/MaterialChecks.cs @@ -53,15 +53,23 @@ namespace Spine.Unity { "Warning: Z Spacing recommended on selected shader configuration!\n\nPlease\n" + "1) make sure at least minimal 'Z Spacing' is set at the SkeletonRenderer/SkeletonAnimation component under 'Advanced' and\n" + "2) ensure that the skeleton has overlapping parts on different Z depth. You can adjust this in Spine via draw order.\n"; + public static readonly string kAddNormalsRequiredMessage = + "Warning: 'Add Normals' required on URP shader to receive shadows!\n\nPlease\n" + + "a) enable 'Add Normals' at the SkeletonRenderer/SkeletonAnimation component under 'Advanced' or\n" + + "b) disable 'Receive Shadows' at the Material."; public static bool IsMaterialSetupProblematic (SkeletonRenderer renderer, ref string errorMessage) { var materials = renderer.GetComponent().sharedMaterials; bool isProblematic = false; - foreach (var mat in materials) { - if (mat == null) continue; - isProblematic |= IsMaterialSetupProblematic(mat, ref errorMessage); + foreach (var material in materials) { + if (material == null) continue; + isProblematic |= IsMaterialSetupProblematic(material, ref errorMessage); if (renderer.zSpacing == 0) { - isProblematic |= IsZSpacingRequired(mat, ref errorMessage); + isProblematic |= IsZSpacingRequired(material, ref errorMessage); + } + if (IsURPMaterial(material) && !AreShadowsDisabled(material) && renderer.addNormals == false) { + isProblematic = true; + errorMessage += kAddNormalsRequiredMessage; } } return isProblematic; @@ -101,9 +109,10 @@ namespace Spine.Unity { } public static bool IsTextureSetupProblematic (Material material, ColorSpace colorSpace, - bool sRGBTexture, bool mipmapEnabled, bool alphaIsTransparency, - string texturePath, string materialPath, - ref string errorMessage) { + bool sRGBTexture, bool mipmapEnabled, bool alphaIsTransparency, + string texturePath, string materialPath, + ref string errorMessage) { + if (material == null || !UsesSpineShader(material)) { return false; } @@ -113,19 +122,34 @@ namespace Spine.Unity { // 'sRGBTexture = true' generates incorrectly weighted mipmaps at PMA textures, // causing white borders due to undesired custom weighting. if (sRGBTexture && mipmapEnabled && colorSpace == ColorSpace.Gamma) { - errorMessage += string.Format("`{0}` : Problematic Texture Settings found: When enabling `Generate Mip Maps` in Gamma color space, it is recommended to disable `sRGB (Color Texture)` on `Premultiply alpha` textures. Otherwise you will receive white border artifacts on an atlas exported with default `Premultiply alpha` settings.\n(You can disable this warning in `Edit - Preferences - Spine`)\n", texturePath); + errorMessage += string.Format("`{0}` : Problematic Texture Settings found: " + + "When enabling `Generate Mip Maps` in Gamma color space, it is recommended " + + "to disable `sRGB (Color Texture)` on `Premultiply alpha` textures. Otherwise " + + "you will receive white border artifacts on an atlas exported with default " + + "`Premultiply alpha` settings.\n" + + "(You can disable this warning in `Edit - Preferences - Spine`)\n", texturePath); isProblematic = true; } if (alphaIsTransparency) { string materialName = System.IO.Path.GetFileName(materialPath); - errorMessage += string.Format("`{0}` and material `{1}` : Problematic Texture / Material Settings found: It is recommended to disable `Alpha Is Transparency` on `Premultiply alpha` textures.\nAssuming `Premultiply alpha` texture because `Straight Alpha Texture` is disabled at material). (You can disable this warning in `Edit - Preferences - Spine`)\n", texturePath, materialName); + errorMessage += string.Format("`{0}` and material `{1}` : Problematic " + + "Texture / Material Settings found: It is recommended to disable " + + "`Alpha Is Transparency` on `Premultiply alpha` textures.\n" + + "Assuming `Premultiply alpha` texture because `Straight Alpha Texture` " + + "is disabled at material). " + + "(You can disable this warning in `Edit - Preferences - Spine`)\n", texturePath, materialName); isProblematic = true; } } else { // straight alpha texture if (!alphaIsTransparency) { string materialName = System.IO.Path.GetFileName(materialPath); - errorMessage += string.Format("`{0}` and material `{1}` : Incorrect Texture / Material Settings found: It is strongly recommended to enable `Alpha Is Transparency` on `Straight alpha` textures.\nAssuming `Straight alpha` texture because `Straight Alpha Texture` is enabled at material). (You can disable this warning in `Edit - Preferences - Spine`)\n", texturePath, materialName); + errorMessage += string.Format("`{0}` and material `{1}` : Incorrect" + + "Texture / Material Settings found: It is strongly recommended " + + "to enable `Alpha Is Transparency` on `Straight alpha` textures.\n" + + "Assuming `Straight alpha` texture because `Straight Alpha Texture` " + + "is enabled at material). " + + "(You can disable this warning in `Edit - Preferences - Spine`)\n", texturePath, materialName); isProblematic = true; } } @@ -152,6 +176,14 @@ namespace Spine.Unity { return (material.HasProperty(STRAIGHT_ALPHA_PARAM_ID) && material.GetInt(STRAIGHT_ALPHA_PARAM_ID) == 0) || material.IsKeywordEnabled(ALPHAPREMULTIPLY_ON_KEYWORD); } + + static bool IsURPMaterial (Material material) { + return material.shader.name.Contains("Universal Render Pipeline"); + } + + static bool AreShadowsDisabled (Material material) { + return material.IsKeywordEnabled("_RECEIVE_SHADOWS_OFF"); + } } } diff --git a/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-SkeletonLit-ForwardPass-LW.hlsl b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-SkeletonLit-ForwardPass-LW.hlsl index 53e958fd9..b6b54affb 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-SkeletonLit-ForwardPass-LW.hlsl +++ b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-SkeletonLit-ForwardPass-LW.hlsl @@ -6,7 +6,7 @@ struct appdata { float3 normal : NORMAL; half4 color : COLOR; float2 uv0 : TEXCOORD0; - + UNITY_VERTEX_INPUT_INSTANCE_ID }; @@ -44,6 +44,15 @@ VertexOutput vert(appdata v) { float3 positionWS = TransformObjectToWorld(v.pos); half3 fixedNormal = half3(0, 0, -1); half3 normalWS = normalize(mul((float3x3)unity_ObjectToWorld, fixedNormal)); + +#ifdef _DOUBLE_SIDED_LIGHTING + // unfortunately we have to compute the sign here in the vertex shader + // instead of using VFACE in fragment shader stage. + half3 viewDirWS = UNITY_MATRIX_V[2].xyz; + half faceSign = sign(dot(viewDirWS, normalWS)); + normalWS *= faceSign; +#endif + color.rgb = LightweightLightVertexSimplified(positionWS, normalWS); // Note: ambient light is also handled via SH. diff --git a/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-Sprite-ForwardPass-LW.hlsl b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-Sprite-ForwardPass-LW.hlsl index 4c1e890a5..0736f78b2 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-Sprite-ForwardPass-LW.hlsl +++ b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/CGIncludes/Spine-Sprite-ForwardPass-LW.hlsl @@ -75,7 +75,7 @@ half4 LightweightFragmentPBRSimplified(InputData inputData, half4 texAlbedoAlpha half4 albedo = texAlbedoAlpha * vertexColor; BRDFData brdfData; - half ignoredAlpha = 1; // ignore alpha, otherwise + half ignoredAlpha = 1; // ignore alpha, otherwise InitializeBRDFData(albedo.rgb, metallic, specular, smoothness, ignoredAlpha, brdfData); brdfData.specular *= albedo.a; @@ -105,7 +105,7 @@ half4 LightweightFragmentPBRSimplified(InputData inputData, half4 texAlbedoAlpha finalColor += inputData.vertexLighting * brdfData.diffuse; #endif finalColor += emission; - return prepareLitPixelForOutput(half4(finalColor, texAlbedoAlpha.a), vertexColor); + return prepareLitPixelForOutput(half4(finalColor, albedo.a), vertexColor); } #else // !SPECULAR @@ -148,7 +148,7 @@ half4 LightweightFragmentBlinnPhongSimplified(InputData inputData, half4 texDiff diffuseLighting += emission; //half3 finalColor = diffuseLighting * diffuse + emission; half3 finalColor = diffuseLighting * diffuse.rgb; - return prepareLitPixelForOutput(half4(finalColor, texDiffuseAlpha.a), vertexColor); + return prepareLitPixelForOutput(half4(finalColor, diffuse.a), vertexColor); } #endif // SPECULAR @@ -168,7 +168,7 @@ VertexOutputLWRP ForwardPassVertexSprite(VertexInput input) float backFaceSign = 1; #if defined(FIXED_NORMALS_BACKFACE_RENDERING) backFaceSign = calculateBackfacingSign(positionWS.xyz); -#endif +#endif output.viewDirectionWS = GetCameraPositionWS() - positionWS; #if defined(PER_PIXEL_LIGHTING) @@ -219,7 +219,7 @@ half4 ForwardPassFragmentSprite(VertexOutputLWRP input) : SV_Target #if defined(_MAIN_LIGHT_SHADOWS) && !defined(_RECEIVE_SHADOWS_OFF) inputData.shadowCoord = input.shadowCoord; #endif - + inputData.viewDirectionWS = input.viewDirectionWS; inputData.vertexLighting = input.fogFactorAndVertexLight.yzw; @@ -239,7 +239,7 @@ half4 ForwardPassFragmentSprite(VertexOutputLWRP input) : SV_Target #if defined(_RIM_LIGHTING) || defined(_ADDITIONAL_LIGHTS) inputData.positionWS = input.positionWS.rgb; #endif - + #if defined(SPECULAR) half2 metallicGloss = getMetallicGloss(input.texcoord.xy); half metallic = metallicGloss.x; diff --git a/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-SkeletonLit-LW.shader b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-SkeletonLit-LW.shader index 14ab34d7b..f03856a19 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-SkeletonLit-LW.shader +++ b/spine-unity/Modules/com.esotericsoftware.spine.lwrp-shaders/Shaders/Spine-SkeletonLit-LW.shader @@ -7,6 +7,7 @@ Shader "Lightweight Render Pipeline/Spine/Skeleton Lit" { _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 + [Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0 [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0 [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Compare", Float) = 0.0 // Disabled stencil test by default } @@ -19,7 +20,7 @@ Shader "Lightweight Render Pipeline/Spine/Skeleton Lit" { Cull Off ZWrite Off Blend One OneMinusSrcAlpha - + Stencil { Ref[_StencilRef] Comp[_StencilComp] @@ -48,7 +49,7 @@ Shader "Lightweight Render Pipeline/Spine/Skeleton Lit" { #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS #pragma multi_compile _ _SHADOWS_SOFT #pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE - + // ------------------------------------- // Unity defined keywords #pragma multi_compile_fog @@ -60,6 +61,7 @@ Shader "Lightweight Render Pipeline/Spine/Skeleton Lit" { //-------------------------------------- // Spine related keywords #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT + #pragma shader_feature _ _DOUBLE_SIDED_LIGHTING #pragma vertex vert #pragma fragment frag #pragma target 2.0 diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/README.md b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/README.md index ab1c21bf1..5fd9eebc4 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/README.md +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/README.md @@ -4,19 +4,36 @@ The latest version of this documentation can also be found at the [spine-unity R ![](timeline.png) -Timeline support is provided as a separate UPM (Unity Package Manager) package. See section [Optional - Installing Extension UPM Packages](http://esotericsoftware.com/spine-unity#Optional---Installing-Extension-UPM-Packages) on how to download and install this package and section [Updating an Extension UPM Package](http://esotericsoftware.com/spine-unity#Updating-an-Extension-UPM-Package) on how to update it. +Timeline support is provided as a separate UPM (Unity Package Manager) package. See section [Optional Extension UPM Packages](http://esotericsoftware.com/spine-unity#Optional-Extension-UPM-Packages) on how to download and install this package and section [Updating an Extension UPM Package](http://esotericsoftware.com/spine-unity#Updating-an-Extension-UPM-Package) on how to update it. ## Spine-Unity Timeline Playables ![](add-menu.png) -Spine Timeline currently provides two types of Timeline Playables: `Spine AnimationState Track` and `Spine Skeleton Flip Track`, described below. +Spine Timeline currently provides three types of Timeline Playables: +- `Spine AnimationState Track` *(for `SkeletonAnimation`)*, +- `Spine AnimationState Graphic Track` *(for `SkeletonGraphic`)*, +- `Spine Skeleton Flip Track` *(for both `SkeletonAnimation` and `SkeletonGraphic`)*. -**Limitations:** currently only [SkeletonAnimation](http://esotericsoftware.com/spine-unity#SkeletonAnimation-Component) is supported. You can find an implementation for [SkeletonGraphic](http://esotericsoftware.com/spine-unity#SkeletonGraphic-Component) kindly provided by a forum user on [this forum thread](http://zh.esotericsoftware.com/forum/Spine-timeline-plugin-for-2019-1-12000). +**Limitations:** currently only [SkeletonAnimation](http://esotericsoftware.com/spine-unity#SkeletonAnimation-Component) and [SkeletonGraphic](http://esotericsoftware.com/spine-unity#SkeletonGraphic-Component) are supported. There is currently no Timeline support for [SkeletonMecanim](http://esotericsoftware.com/spine-unity#SkeletonMecanim-Component). ### Spine AnimationState Track + +![](animationstate-track.png) + +This track type can be used to set animations at the AnimationState of the target `SkeletonAnimation` or `SkeletonGraphic`. Track type `Spine AnimationState Track` is used for `SkeletonAnimation`, `Spine AnimationState Graphic Track` for `SkeletonGraphic`. + +![](animationstate-track-inspector.png) + +**Parameters** +- *Track Index.* The target AnimationState track index to set animations at. Do not forget to set this value accordingly when using multiple timeline tracks. +> **Important Note:** Currently it is required to order the timeline tracks with base track at the top and overlay tracks below, otherwise the Editor Preview will display incorrect results. + +#### Spine Animation State Clip + +You can add a `Spine Animation State Clip` to a `Spine AnimationState Track` (or `Spine AnimationState Graphic Track`) by dragging an `AnimationReferenceAsset` onto a Timeline track. See the [SkeletonData - Preview](http://esotericsoftware.com/spine-unity#Preview) section on how to generate `AnimationReferenceAssets` for a `SkeletonDataAsset`. + ![](animationstate-clip-inspector.png) -This track type can be used to set animations on the target SkeletonAnimation's AnimationState. **Parameters** - *Clip In.* An initial local start time offset applied when playing this animation. Can also be adjusted by dragging the left edge of the clip. @@ -33,34 +50,42 @@ This track type can be used to set animations on the target SkeletonAnimation's - *Ease Out Duration, Blend Curves*. These parameters are ignored and have no effect. **Usage** -1. Add `SkeletonAnimationPlayableHandle` component to your SkeletonAnimation GameObject. +1. Add `SkeletonAnimationPlayableHandle` component to your SkeletonAnimation GameObject, or the `SkeletonGraphicPlayableHandle` in case of `SkeletonGraphic`. 2. With an existing Unity Playable Director, and in the Unity Timeline window, right-click on an empty space on the left and choose `Spine.Unity.Playables` - `Spine Animation State Track`. -3. Drag the SkeletonAnimation GameObject onto the empty reference property of the new Spine AnimationState Track. -4. Right-click on the row in an empty space in the Timeline dopesheet and choose `Add Spine Animation State Clip Clip`. -5. Adjust the start and end times of the new clip, name it appropriately at the top of the Inspector. -6. Click on the clip inspector's SkeletonDataAsset field and choose your target skeleton's SkeletonDataAsset. This will enable the animation name dropdown to appear. -7. Choose the appropriate animation name, loop, and mix settings. -8. For easier readability, rename your clip to the animation name or something descriptive. +3. Drag the SkeletonAnimation or SkeletonGraphic GameObject onto the empty reference property of the new Spine AnimationState Track. +4. To add an animation at a track, drag the respective [`AnimationReferenceAsset`](http://esotericsoftware.com/spine-unity#Preview) into the clips view (the right part of the Timeline panel) as you would with normal animation clips. -> **Note:** To avoid having to do steps 4-6 repeatedly, use the Duplicate function (`CTRL`/`CMD` + `D`) +See spine-unity Runtime Documentation, [section Preview](http://esotericsoftware.com/spine-unity#Preview) on how to create an `AnimationReferenceAsset` for each of your animations. + +> **Note:** You can use the Duplicate function (`CTRL`/`CMD` + `D`) to duplicate selected clips in the clips view. **Track Behavior** -- `AnimationState.SetAnimation` will be called at the beginning of every clip based on the animationName. +- `AnimationState.SetAnimation` will be called at the beginning of every clip based on the `AnimationReferenceAsset`. - Clip durations don't matter. Animations won't be cleared where there is no active clip at certain slices of time. -- Empty animation: If a clip has no name specified, it will call SetEmptyAnimation instead. -- Error handling: If the animation with the provided animationName is not found, it will do nothing (the previous animation will continue playing normally). +- Empty animation: If a clip has no `AnimationReferenceAsset` assigned, it will call `SetEmptyAnimation` instead. +- Error handling: If the animation with the provided `AnimationReferenceAsset` is not found, it will do nothing (the previous animation will continue playing normally). - Animations playing before the timeline starts playing will not be interrupted until the first clip starts playing. -- At the end of the last clip and at the end of the timeline, nothing happens. This means the effect of the last clip's SetAnimation call will persist until you give other commands to that AnimationState. -- Edit mode preview mixing may look different from Play Mode mixing. Please check in actual Play Mode to see the real results. +- At the end of the last clip and at the end of the timeline, nothing happens. This means the effect of the last clip's `SetAnimation` call will persist until you issue other calls at the AnimationState. +- Edit mode preview mixing may look different from Play Mode mixing. Please check in actual Play Mode to see the actual results. Please see the remark in the [Spine AnimationState Track](#Spine-AnimationState-Track) section on correct track ordering when previewing multiple overlaid tracks. ### Spine Skeleton Flip Track + +![](skeleton-flip-track.png) + +This track type can be used to flip the skeleton of the target `SkeletonAnimation` or `SkeletonGraphic`. + +#### Spine Skeleton Flip Clip + ![](skeleton-flip-clip-inspector.png) -This track type can be used to flip the skeleton of the target SkeletonAnimation. + +**Parameters** +- *Flip X.* Flips the skeleton along the X axis during the extents of the clip. +- *Flip Y.* Flips the skeleton along the Y axis during the extents of the clip. **Usage** -1. Add `SkeletonAnimationPlayableHandle` component to your SkeletonAnimation GameObject. +1. Add `SkeletonAnimationPlayableHandle` component to your SkeletonAnimation GameObject, or the `SkeletonGraphicPlayableHandle` in case of `SkeletonGraphic`. 2. With an existing Unity Playable Director, and in the Unity Timeline window, right-click on an empty space on the left and choose `Spine.Unity.Playables` - `Spine Skeleton Flip Track`. -3. Drag the SkeletonAnimation GameObject onto the empty reference property of the new Spine Skeleton Flip Track. +3. Drag the SkeletonAnimation or SkeletonGraphic GameObject onto the empty reference property of the new Spine Skeleton Flip Track. 4. Right-click on the row in an empty space in the Timeline dopesheet and choose `Add Spine Skeleton Flip Clip Clip`. 5. Adjust the start and end times of the new clip, name it appropriately at the top of the Inspector, and choose the desired FlipX and FlipY values. @@ -69,7 +94,7 @@ This track type can be used to flip the skeleton of the target SkeletonAnimation - At the end of the timeline, the track will revert the skeleton flip to the flip values it captures when it starts playing that timeline. ### Known Issues -- The Console potentially logs an incorrect/harmless error `DrivenPropertyManager has failed to register property "m_Script" of object "Spine GameObject (spineboy-pro)" with driver "" because the property doesn't exist.`. This is a known issue on Unity's end. See more here: https://forum.unity.com/threads/default-playables-text-switcher-track-error.502903/ +- The Console potentially logs an incorrect and harmless error `DrivenPropertyManager has failed to register property "m_Script" of object "Spine GameObject (spineboy-pro)" with driver "" because the property doesn't exist.`. This is a known issue on Unity's end. See more here: https://forum.unity.com/threads/default-playables-text-switcher-track-error.502903/ - These Spine Tracks (like other custom Unity Timeline Playable types) do not have labels on them. Unity currently doesn't have API to specify their labels yet. - Each track clip currently requires you to specify a reference to SkeletonData so its inspector can show you a convenient list of animation names. This is because track clips are agnostic of its track and target component/track binding, and provides no way of automatically finding it while in the editor. The clips will still function correctly without the SkeletonDataAsset references; you just won't get the dropdown of animation names in the editor. - Each track clip cannot be automatically named based on the chosen animationName. The Timeline object editors currently doesn't provide access to the clip names to do this automatically. diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/add-menu.png b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/add-menu.png index f2277f2fb..92ad84b7c 100644 Binary files a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/add-menu.png and b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/add-menu.png differ diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/animationstate-clip-inspector.png b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/animationstate-clip-inspector.png index 3b38e79d0..98a530852 100644 Binary files a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/animationstate-clip-inspector.png and b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/animationstate-clip-inspector.png differ diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/animationstate-track-inspector.png b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/animationstate-track-inspector.png new file mode 100644 index 000000000..42b411b6d Binary files /dev/null and b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/animationstate-track-inspector.png differ diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/animationstate-track-inspector.png.meta b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/animationstate-track-inspector.png.meta new file mode 100644 index 000000000..3fa5d3077 --- /dev/null +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/animationstate-track-inspector.png.meta @@ -0,0 +1,94 @@ +fileFormatVersion: 2 +guid: 04051f71b9b3db740a8d236ff80672e7 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 11 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 5e97eb03825dee720800000000000000 + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/animationstate-track.png b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/animationstate-track.png new file mode 100644 index 000000000..14d0e0194 Binary files /dev/null and b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/animationstate-track.png differ diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/animationstate-track.png.meta b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/animationstate-track.png.meta new file mode 100644 index 000000000..f00145968 --- /dev/null +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/animationstate-track.png.meta @@ -0,0 +1,74 @@ +fileFormatVersion: 2 +guid: d698a92ba07201b4eb9f99a6275f2b3b +timeCreated: 1595514078 +licenseType: Pro +TextureImporter: + fileIDToRecycleName: {} + serializedVersion: 4 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -1 + wrapU: -1 + wrapV: -1 + wrapW: -1 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spritePixelsToUnits: 100 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/skeleton-flip-clip-inspector.png b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/skeleton-flip-clip-inspector.png index c2b8acf9c..352c167db 100644 Binary files a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/skeleton-flip-clip-inspector.png and b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/skeleton-flip-clip-inspector.png differ diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/skeleton-flip-track.png b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/skeleton-flip-track.png new file mode 100644 index 000000000..fb72274a9 Binary files /dev/null and b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/skeleton-flip-track.png differ diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/skeleton-flip-track.png.meta b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/skeleton-flip-track.png.meta new file mode 100644 index 000000000..5bbe58d1c --- /dev/null +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/skeleton-flip-track.png.meta @@ -0,0 +1,74 @@ +fileFormatVersion: 2 +guid: e56f159fca97b5d4ab93f104e1cce135 +timeCreated: 1595514078 +licenseType: Pro +TextureImporter: + fileIDToRecycleName: {} + serializedVersion: 4 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -1 + wrapU: -1 + wrapV: -1 + wrapW: -1 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spritePixelsToUnits: 100 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/timeline.png b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/timeline.png index 341a9b214..246d8d7d6 100644 Binary files a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/timeline.png and b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/timeline.png differ diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/timeline.png.meta b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/timeline.png.meta new file mode 100644 index 000000000..e9a6dd0e9 --- /dev/null +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Documentation/timeline.png.meta @@ -0,0 +1,74 @@ +fileFormatVersion: 2 +guid: 73e3829cc431d4f438368d3b284c3d03 +timeCreated: 1570476238 +licenseType: Free +TextureImporter: + fileIDToRecycleName: {} + serializedVersion: 4 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -1 + wrapU: -1 + wrapV: -1 + wrapW: -1 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spritePixelsToUnits: 100 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineAnimationStateClipInspector.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineAnimationStateClipInspector.cs index 3146633c7..80c8eda7b 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineAnimationStateClipInspector.cs +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineAnimationStateClipInspector.cs @@ -1,8 +1,8 @@ /****************************************************************************** * Spine Runtimes License Agreement - * Last updated May 1, 2019. Replaces all prior versions. + * Last updated January 1, 2020. Replaces all prior versions. * - * Copyright (c) 2013-2019, Esoteric Software LLC + * 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 @@ -15,16 +15,16 @@ * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * - * THIS SOFTWARE IS 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 THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * 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. *****************************************************************************/ using UnityEditor; @@ -46,7 +46,7 @@ namespace Spine.Unity.Editor { } protected ClipInfo[] clipInfo = null; - + public void OnEnable () { templateProp = serializedObject.FindProperty("template"); System.Array.Resize(ref clipInfo, targets.Length); @@ -66,7 +66,7 @@ namespace Spine.Unity.Editor { if (targetClip.template.useBlendDuration) AdjustMixDuration(targetClip, clipInfo[i]); } - + serializedObject.ApplyModifiedProperties(); } diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineAnimationStateDrawer.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineAnimationStateDrawer.cs index dcd472ea7..2a78226dd 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineAnimationStateDrawer.cs +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineAnimationStateDrawer.cs @@ -1,8 +1,8 @@ /****************************************************************************** * Spine Runtimes License Agreement - * Last updated May 1, 2019. Replaces all prior versions. + * Last updated January 1, 2020. Replaces all prior versions. * - * Copyright (c) 2013-2019, Esoteric Software LLC + * 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 @@ -15,16 +15,16 @@ * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * - * THIS SOFTWARE IS 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 THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * 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. *****************************************************************************/ using UnityEditor; @@ -36,9 +36,9 @@ using Spine.Unity.Editor; [CustomPropertyDrawer(typeof(SpineAnimationStateBehaviour))] public class SpineAnimationStateDrawer : PropertyDrawer { - + public override float GetPropertyHeight (SerializedProperty property, GUIContent label) { - const int fieldCount = 8; + const int fieldCount = 10; return fieldCount * EditorGUIUtility.singleLineHeight; } @@ -59,7 +59,7 @@ public class SpineAnimationStateDrawer : PropertyDrawer { useBlendDurationProp.boolValue = SpineEditorUtilities.Preferences.timelineUseBlendDuration; isInitializedProp.boolValue = true; } - + Rect singleFieldRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight); float lineHeightWithSpacing = EditorGUIUtility.singleLineHeight + 2f; diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineAnimationStateGraphicTrackInspector.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineAnimationStateGraphicTrackInspector.cs new file mode 100644 index 000000000..af9abd0c6 --- /dev/null +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineAnimationStateGraphicTrackInspector.cs @@ -0,0 +1,52 @@ +/****************************************************************************** + * 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. + *****************************************************************************/ + +using UnityEditor; +using Spine.Unity.Playables; +using UnityEngine.Timeline; + +namespace Spine.Unity.Editor { + + [CustomEditor(typeof(SpineAnimationStateGraphicTrack))] + [CanEditMultipleObjects] + public class SpineAnimationStateGraphicTrackInspector : UnityEditor.Editor { + + protected SerializedProperty trackIndexProperty = null; + + public void OnEnable () { + trackIndexProperty = serializedObject.FindProperty("trackIndex"); + } + + public override void OnInspectorGUI () { + serializedObject.Update(); + EditorGUILayout.PropertyField(trackIndexProperty); + serializedObject.ApplyModifiedProperties(); + } + } +} diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineAnimationStateGraphicTrackInspector.cs.meta b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineAnimationStateGraphicTrackInspector.cs.meta new file mode 100644 index 000000000..29205b436 --- /dev/null +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineAnimationStateGraphicTrackInspector.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 1bd1fca227e65ae4fb9a54086eb5cfce +timeCreated: 1595441224 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineAnimationStateTrackInspector.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineAnimationStateTrackInspector.cs index 3d5771186..79b915eac 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineAnimationStateTrackInspector.cs +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineAnimationStateTrackInspector.cs @@ -1,8 +1,8 @@ /****************************************************************************** * Spine Runtimes License Agreement - * Last updated May 1, 2019. Replaces all prior versions. + * Last updated January 1, 2020. Replaces all prior versions. * - * Copyright (c) 2013-2019, Esoteric Software LLC + * 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 @@ -15,16 +15,16 @@ * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * - * THIS SOFTWARE IS 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 THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * 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. *****************************************************************************/ using UnityEditor; diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineSkeletonFlipClipInspector.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineSkeletonFlipClipInspector.cs index d309d2af5..1deec447d 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineSkeletonFlipClipInspector.cs +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineSkeletonFlipClipInspector.cs @@ -1,8 +1,8 @@ /****************************************************************************** * Spine Runtimes License Agreement - * Last updated May 1, 2019. Replaces all prior versions. + * Last updated January 1, 2020. Replaces all prior versions. * - * Copyright (c) 2013-2019, Esoteric Software LLC + * 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 @@ -15,16 +15,16 @@ * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * - * THIS SOFTWARE IS 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 THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * 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. *****************************************************************************/ using UnityEditor; diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineSkeletonFlipDrawer.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineSkeletonFlipDrawer.cs index c17db3e23..e50891676 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineSkeletonFlipDrawer.cs +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Editor/SpineSkeletonFlipDrawer.cs @@ -1,8 +1,8 @@ /****************************************************************************** * Spine Runtimes License Agreement - * Last updated May 1, 2019. Replaces all prior versions. + * Last updated January 1, 2020. Replaces all prior versions. * - * Copyright (c) 2013-2019, Esoteric Software LLC + * 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 @@ -15,16 +15,16 @@ * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * - * THIS SOFTWARE IS 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 THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * 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. *****************************************************************************/ using UnityEditor; @@ -35,7 +35,7 @@ using UnityEngine.Playables; public class SpineSkeletonFlipDrawer : PropertyDrawer { public override float GetPropertyHeight (SerializedProperty property, GUIContent label) { - int fieldCount = 1; + int fieldCount = 2; return fieldCount * EditorGUIUtility.singleLineHeight; } diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/PlayableHandle Component/SkeletonAnimationPlayableHandle.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/PlayableHandle Component/SkeletonAnimationPlayableHandle.cs index 013b778cd..166c587c3 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/PlayableHandle Component/SkeletonAnimationPlayableHandle.cs +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/PlayableHandle Component/SkeletonAnimationPlayableHandle.cs @@ -1,8 +1,8 @@ /****************************************************************************** * Spine Runtimes License Agreement - * Last updated May 1, 2019. Replaces all prior versions. + * Last updated January 1, 2020. Replaces all prior versions. * - * Copyright (c) 2013-2019, Esoteric Software LLC + * 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 @@ -15,16 +15,16 @@ * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * - * THIS SOFTWARE IS 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 THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * 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. *****************************************************************************/ using System.Collections; @@ -44,9 +44,12 @@ namespace Spine.Unity.Playables { public SkeletonAnimation skeletonAnimation; #if UNITY_EDITOR + void Reset () { + InitializeReference(); + } + void OnValidate () { - if (this.skeletonAnimation == null) - skeletonAnimation = GetComponent(); + InitializeReference(); } #endif @@ -56,6 +59,10 @@ namespace Spine.Unity.Playables { public override SkeletonData SkeletonData { get { return skeletonAnimation.Skeleton.Data; } } void Awake () { + InitializeReference(); + } + + void InitializeReference () { if (skeletonAnimation == null) skeletonAnimation = GetComponent(); } diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/PlayableHandle Component/SkeletonGraphicPlayableHandle.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/PlayableHandle Component/SkeletonGraphicPlayableHandle.cs new file mode 100644 index 000000000..16a62cdf5 --- /dev/null +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/PlayableHandle Component/SkeletonGraphicPlayableHandle.cs @@ -0,0 +1,70 @@ +/****************************************************************************** + * 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. + *****************************************************************************/ + +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +//using UnityEngine.Playables; + +using Spine; +using Spine.Unity; +using Spine.Unity.Playables; + +namespace Spine.Unity.Playables { + + [AddComponentMenu("Spine/Playables/SkeletonGraphic Playable Handle (Playables)")] + public class SkeletonGraphicPlayableHandle : SpinePlayableHandleBase { + #region Inspector + public SkeletonGraphic skeletonGraphic; + + #if UNITY_EDITOR + void Reset () { + InitializeReference(); + } + + void OnValidate () { + InitializeReference(); + } + #endif + + #endregion + + public override Skeleton Skeleton { get { return skeletonGraphic.Skeleton; } } + public override SkeletonData SkeletonData { get { return skeletonGraphic.Skeleton.Data; } } + + void Awake () { + InitializeReference(); + } + + void InitializeReference () { + if (skeletonGraphic == null) + skeletonGraphic = GetComponent(); + } + } +} diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/PlayableHandle Component/SkeletonGraphicPlayableHandle.cs.meta b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/PlayableHandle Component/SkeletonGraphicPlayableHandle.cs.meta new file mode 100644 index 000000000..ad8ea1e25 --- /dev/null +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/PlayableHandle Component/SkeletonGraphicPlayableHandle.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 51a0223d4dee020468302946c8ccd329 +timeCreated: 1595439279 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/PlayableHandle Component/SpinePlayableHandleBase.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/PlayableHandle Component/SpinePlayableHandleBase.cs index f8b8fca31..de4bf450f 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/PlayableHandle Component/SpinePlayableHandleBase.cs +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/PlayableHandle Component/SpinePlayableHandleBase.cs @@ -1,8 +1,8 @@ /****************************************************************************** * Spine Runtimes License Agreement - * Last updated May 1, 2019. Replaces all prior versions. + * Last updated January 1, 2020. Replaces all prior versions. * - * Copyright (c) 2013-2019, Esoteric Software LLC + * 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 @@ -15,16 +15,16 @@ * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * - * THIS SOFTWARE IS 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 THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * 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. *****************************************************************************/ using System.Collections; diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateBehaviour.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateBehaviour.cs index 1a1d028de..685a1c2e7 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateBehaviour.cs +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateBehaviour.cs @@ -1,8 +1,8 @@ /****************************************************************************** * Spine Runtimes License Agreement - * Last updated May 1, 2019. Replaces all prior versions. + * Last updated January 1, 2020. Replaces all prior versions. * - * Copyright (c) 2013-2019, Esoteric Software LLC + * 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 @@ -15,16 +15,16 @@ * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * - * THIS SOFTWARE IS 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 THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * 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. *****************************************************************************/ using System; diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateClip.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateClip.cs index 21a0a9034..efa194f09 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateClip.cs +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateClip.cs @@ -1,8 +1,8 @@ /****************************************************************************** * Spine Runtimes License Agreement - * Last updated May 1, 2019. Replaces all prior versions. + * Last updated January 1, 2020. Replaces all prior versions. * - * Copyright (c) 2013-2019, Esoteric Software LLC + * 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 @@ -15,16 +15,16 @@ * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * - * THIS SOFTWARE IS 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 THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * 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. *****************************************************************************/ using System; diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateGraphicTrack.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateGraphicTrack.cs new file mode 100644 index 000000000..a2307591e --- /dev/null +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateGraphicTrack.cs @@ -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. + *****************************************************************************/ + +using UnityEngine; +using UnityEngine.Playables; +using UnityEngine.Timeline; + +namespace Spine.Unity.Playables { + [TrackColor(0.9960785f, 0.2509804f, 0.003921569f)] + [TrackClipType(typeof(SpineAnimationStateClip))] + [TrackBindingType(typeof(SkeletonGraphic))] + public class SpineAnimationStateGraphicTrack : TrackAsset { + public int trackIndex = 0; + + public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount) { + var scriptPlayable = ScriptPlayable.Create(graph, inputCount); + var mixerBehaviour = scriptPlayable.GetBehaviour(); + mixerBehaviour.trackIndex = this.trackIndex; + return scriptPlayable; + } + } +} diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateGraphicTrack.cs.meta b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateGraphicTrack.cs.meta new file mode 100644 index 000000000..396626a5b --- /dev/null +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateGraphicTrack.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 72a1f4f2e8b6c194bbdabda6998a77e1 +timeCreated: 1595440391 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateMixerBehaviour.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateMixerBehaviour.cs index 3d03d275c..619e9c18b 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateMixerBehaviour.cs +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateMixerBehaviour.cs @@ -1,8 +1,8 @@ /****************************************************************************** * Spine Runtimes License Agreement - * Last updated May 1, 2019. Replaces all prior versions. + * Last updated January 1, 2020. Replaces all prior versions. * - * Copyright (c) 2013-2019, Esoteric Software LLC + * 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 @@ -15,16 +15,16 @@ * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * - * THIS SOFTWARE IS 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 THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * 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. *****************************************************************************/ #define SPINE_EDITMODEPOSE @@ -42,15 +42,20 @@ namespace Spine.Unity.Playables { // NOTE: This function is called at runtime and edit time. Keep that in mind when setting the values of properties. public override void ProcessFrame (Playable playable, FrameData info, object playerData) { - var spineComponent = playerData as SkeletonAnimation; - if (spineComponent == null) return; - var skeleton = spineComponent.Skeleton; - var state = spineComponent.AnimationState; + var skeletonAnimation = playerData as SkeletonAnimation; + var skeletonGraphic = playerData as SkeletonGraphic; + var animationStateComponent = playerData as IAnimationStateComponent; + var skeletonComponent = playerData as ISkeletonComponent; + if (animationStateComponent == null || skeletonComponent == null) return; + + var skeleton = skeletonComponent.Skeleton; + var state = animationStateComponent.AnimationState; if (!Application.isPlaying) { #if SPINE_EDITMODEPOSE - PreviewEditModePose(playable, spineComponent); + PreviewEditModePose(playable, skeletonComponent, animationStateComponent, + skeletonAnimation, skeletonGraphic); #endif return; } @@ -97,8 +102,14 @@ namespace Spine.Unity.Playables { } // Ensure that the first frame ends with an updated mesh. - spineComponent.Update(0); - spineComponent.LateUpdate(); + if (skeletonAnimation) { + skeletonAnimation.Update(0); + skeletonAnimation.LateUpdate(); + } + else if (skeletonGraphic) { + skeletonGraphic.Update(0); + skeletonGraphic.LateUpdate(); + } } } } @@ -107,9 +118,12 @@ namespace Spine.Unity.Playables { AnimationState dummyAnimationState; - public void PreviewEditModePose (Playable playable, SkeletonAnimation spineComponent) { + public void PreviewEditModePose (Playable playable, + ISkeletonComponent skeletonComponent, IAnimationStateComponent animationStateComponent, + SkeletonAnimation skeletonAnimation, SkeletonGraphic skeletonGraphic) { + if (Application.isPlaying) return; - if (spineComponent == null) return; + if (skeletonComponent == null || animationStateComponent == null) return; int inputCount = playable.GetInputCount(); int lastNonZeroWeightTrack = -1; @@ -120,14 +134,17 @@ namespace Spine.Unity.Playables { } if (lastNonZeroWeightTrack != -1) { - ScriptPlayable inputPlayableClip = (ScriptPlayable)playable.GetInput(lastNonZeroWeightTrack); + ScriptPlayable inputPlayableClip = + (ScriptPlayable)playable.GetInput(lastNonZeroWeightTrack); SpineAnimationStateBehaviour clipData = inputPlayableClip.GetBehaviour(); - var skeleton = spineComponent.Skeleton; + var skeleton = skeletonComponent.Skeleton; - bool skeletonDataMismatch = clipData.animationReference != null && spineComponent.SkeletonDataAsset.GetSkeletonData(true) != clipData.animationReference.SkeletonDataAsset.GetSkeletonData(true); + bool skeletonDataMismatch = clipData.animationReference != null && + skeletonComponent.SkeletonDataAsset.GetSkeletonData(true) != clipData.animationReference.SkeletonDataAsset.GetSkeletonData(true); if (skeletonDataMismatch) { - Debug.LogWarningFormat("SpineAnimationStateMixerBehaviour tried to apply an animation for the wrong skeleton. Expected {0}. Was {1}", spineComponent.SkeletonDataAsset, clipData.animationReference.SkeletonDataAsset); + Debug.LogWarningFormat("SpineAnimationStateMixerBehaviour tried to apply an animation for the wrong skeleton. Expected {0}. Was {1}", + skeletonComponent.SkeletonDataAsset, clipData.animationReference.SkeletonDataAsset); } // Getting the from-animation here because it's required to get the mix information from AnimationStateData. @@ -147,12 +164,15 @@ namespace Spine.Unity.Playables { float mixDuration = clipData.mixDuration; if (!clipData.customDuration && fromAnimation != null && toAnimation != null) { - mixDuration = spineComponent.AnimationState.Data.GetMix(fromAnimation, toAnimation); + mixDuration = animationStateComponent.AnimationState.Data.GetMix(fromAnimation, toAnimation); } + if (trackIndex == 0) + skeleton.SetToSetupPose(); + // Approximate what AnimationState might do at runtime. if (fromAnimation != null && mixDuration > 0 && toClipTime < mixDuration) { - dummyAnimationState = dummyAnimationState ?? new AnimationState(spineComponent.skeletonDataAsset.GetAnimationStateData()); + dummyAnimationState = dummyAnimationState ?? new AnimationState(skeletonComponent.SkeletonDataAsset.GetAnimationStateData()); var toTrack = dummyAnimationState.GetCurrent(0); var fromTrack = toTrack != null ? toTrack.MixingFrom : null; @@ -174,15 +194,18 @@ namespace Spine.Unity.Playables { } // Apply Pose - skeleton.SetToSetupPose(); dummyAnimationState.Update(0); dummyAnimationState.Apply(skeleton); } else { - skeleton.SetToSetupPose(); if (toAnimation != null) toAnimation.Apply(skeleton, 0, toClipTime, clipData.loop, null, 1f, MixBlend.Setup, MixDirection.In); } + skeleton.UpdateWorldTransform(); + if (skeletonAnimation) + skeletonAnimation.LateUpdate(); + else if (skeletonGraphic) + skeletonGraphic.LateUpdate(); } // Do nothing outside of the first clip and the last clip. diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateTrack.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateTrack.cs index bb9d2e06b..0f8fb99e6 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateTrack.cs +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateTrack.cs @@ -1,8 +1,8 @@ /****************************************************************************** * Spine Runtimes License Agreement - * Last updated May 1, 2019. Replaces all prior versions. + * Last updated January 1, 2020. Replaces all prior versions. * - * Copyright (c) 2013-2019, Esoteric Software LLC + * 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 @@ -15,16 +15,16 @@ * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * - * THIS SOFTWARE IS 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 THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * 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. *****************************************************************************/ using UnityEngine; diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineSkeletonFlip/SpineSkeletonFlipBehaviour.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineSkeletonFlip/SpineSkeletonFlipBehaviour.cs index e3a3ba05f..7c744e17c 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineSkeletonFlip/SpineSkeletonFlipBehaviour.cs +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineSkeletonFlip/SpineSkeletonFlipBehaviour.cs @@ -1,8 +1,8 @@ /****************************************************************************** * Spine Runtimes License Agreement - * Last updated May 1, 2019. Replaces all prior versions. + * Last updated January 1, 2020. Replaces all prior versions. * - * Copyright (c) 2013-2019, Esoteric Software LLC + * 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 @@ -15,16 +15,16 @@ * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * - * THIS SOFTWARE IS 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 THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * 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. *****************************************************************************/ using System; diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineSkeletonFlip/SpineSkeletonFlipClip.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineSkeletonFlip/SpineSkeletonFlipClip.cs index ba7ca0160..c3c3ec80c 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineSkeletonFlip/SpineSkeletonFlipClip.cs +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineSkeletonFlip/SpineSkeletonFlipClip.cs @@ -1,8 +1,8 @@ /****************************************************************************** * Spine Runtimes License Agreement - * Last updated May 1, 2019. Replaces all prior versions. + * Last updated January 1, 2020. Replaces all prior versions. * - * Copyright (c) 2013-2019, Esoteric Software LLC + * 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 @@ -15,16 +15,16 @@ * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * - * THIS SOFTWARE IS 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 THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * 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. *****************************************************************************/ using System; diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineSkeletonFlip/SpineSkeletonFlipMixerBehaviour.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineSkeletonFlip/SpineSkeletonFlipMixerBehaviour.cs index 5f64367e7..a37b76fd1 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineSkeletonFlip/SpineSkeletonFlipMixerBehaviour.cs +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineSkeletonFlip/SpineSkeletonFlipMixerBehaviour.cs @@ -1,8 +1,8 @@ /****************************************************************************** * Spine Runtimes License Agreement - * Last updated May 1, 2019. Replaces all prior versions. + * Last updated January 1, 2020. Replaces all prior versions. * - * Copyright (c) 2013-2019, Esoteric Software LLC + * 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 @@ -15,16 +15,16 @@ * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * - * THIS SOFTWARE IS 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 THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * 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. *****************************************************************************/ using System; diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineSkeletonFlip/SpineSkeletonFlipTrack.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineSkeletonFlip/SpineSkeletonFlipTrack.cs index 6b9e036c7..089a16362 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineSkeletonFlip/SpineSkeletonFlipTrack.cs +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineSkeletonFlip/SpineSkeletonFlipTrack.cs @@ -1,8 +1,8 @@ /****************************************************************************** * Spine Runtimes License Agreement - * Last updated May 1, 2019. Replaces all prior versions. + * Last updated January 1, 2020. Replaces all prior versions. * - * Copyright (c) 2013-2019, Esoteric Software LLC + * 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 @@ -15,16 +15,16 @@ * Spine Editor license and redistribution of the Products in any form must * include this license and copyright notice. * - * THIS SOFTWARE IS 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 THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * 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. *****************************************************************************/ using UnityEngine; diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/package.json b/spine-unity/Modules/com.esotericsoftware.spine.timeline/package.json index 9089f61d6..d4ebe02cc 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/package.json +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/package.json @@ -2,7 +2,7 @@ "name": "com.esotericsoftware.spine.timeline", "displayName": "Spine Timeline Extensions", "description": "This plugin provides integration of spine-unity for the Unity Timeline.\n\nPrerequisites:\nIt requires a working installation of the spine-unity runtime, version 3.8 from 2019-10-03 or newer.\n(See http://esotericsoftware.com/git/spine-runtimes/spine-unity)", - "version": "3.8.1", + "version": "3.8.2", "unity": "2018.3", "author": { "name": "Esoteric Software", diff --git a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-SkeletonLit-ForwardPass-URP.hlsl b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-SkeletonLit-ForwardPass-URP.hlsl index f0fa20e1b..0fd0c788c 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-SkeletonLit-ForwardPass-URP.hlsl +++ b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-SkeletonLit-ForwardPass-URP.hlsl @@ -44,6 +44,15 @@ VertexOutput vert(appdata v) { float3 positionWS = TransformObjectToWorld(v.pos); half3 fixedNormal = half3(0, 0, -1); half3 normalWS = normalize(mul((float3x3)unity_ObjectToWorld, fixedNormal)); + +#ifdef _DOUBLE_SIDED_LIGHTING + // unfortunately we have to compute the sign here in the vertex shader + // instead of using VFACE in fragment shader stage. + half3 viewDirWS = UNITY_MATRIX_V[2].xyz; + half faceSign = sign(dot(viewDirWS, normalWS)); + normalWS *= faceSign; +#endif + color.rgb = LightweightLightVertexSimplified(positionWS, normalWS); // Note: ambient light is also handled via SH. diff --git a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl index 1be33a8d1..d4f7ccd7a 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl +++ b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Sprite-ForwardPass-URP.hlsl @@ -75,7 +75,7 @@ half4 LightweightFragmentPBRSimplified(InputData inputData, half4 texAlbedoAlpha half4 albedo = texAlbedoAlpha * vertexColor; BRDFData brdfData; - half ignoredAlpha = 1; // ignore alpha, otherwise + half ignoredAlpha = 1; // ignore alpha, otherwise InitializeBRDFData(albedo.rgb, metallic, specular, smoothness, ignoredAlpha, brdfData); brdfData.specular *= albedo.a; @@ -105,7 +105,7 @@ half4 LightweightFragmentPBRSimplified(InputData inputData, half4 texAlbedoAlpha finalColor += inputData.vertexLighting * brdfData.diffuse; #endif finalColor += emission; - return prepareLitPixelForOutput(half4(finalColor, texAlbedoAlpha.a), vertexColor); + return prepareLitPixelForOutput(half4(finalColor, albedo.a), vertexColor); } #else // !SPECULAR @@ -148,7 +148,7 @@ half4 LightweightFragmentBlinnPhongSimplified(InputData inputData, half4 texDiff diffuseLighting += emission; //half3 finalColor = diffuseLighting * diffuse + emission; half3 finalColor = diffuseLighting * diffuse.rgb; - return prepareLitPixelForOutput(half4(finalColor, texDiffuseAlpha.a), vertexColor); + return prepareLitPixelForOutput(half4(finalColor, diffuse.a), vertexColor); } #endif // SPECULAR @@ -168,7 +168,7 @@ VertexOutputLWRP ForwardPassVertexSprite(VertexInput input) float backFaceSign = 1; #if defined(FIXED_NORMALS_BACKFACE_RENDERING) backFaceSign = calculateBackfacingSign(positionWS.xyz); -#endif +#endif output.viewDirectionWS = GetCameraPositionWS() - positionWS; #if defined(PER_PIXEL_LIGHTING) @@ -219,7 +219,7 @@ half4 ForwardPassFragmentSprite(VertexOutputLWRP input) : SV_Target #if defined(_MAIN_LIGHT_SHADOWS) && !defined(_RECEIVE_SHADOWS_OFF) inputData.shadowCoord = input.shadowCoord; #endif - + inputData.viewDirectionWS = input.viewDirectionWS; inputData.vertexLighting = input.fogFactorAndVertexLight.yzw; @@ -239,7 +239,7 @@ half4 ForwardPassFragmentSprite(VertexOutputLWRP input) : SV_Target #if defined(_RIM_LIGHTING) || defined(_ADDITIONAL_LIGHTS) inputData.positionWS = input.positionWS.rgb; #endif - + #if defined(SPECULAR) half2 metallicGloss = getMetallicGloss(input.texcoord.xy); half metallic = metallicGloss.x; @@ -261,6 +261,7 @@ half4 ForwardPassFragmentSprite(VertexOutputLWRP input) : SV_Target COLORISE(pixel) APPLY_FOG_LWRP(pixel, input.fogFactorAndVertexLight.x) + return pixel; } diff --git a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Spine-SkeletonLit-URP.shader b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Spine-SkeletonLit-URP.shader index 166c8d2b5..f8328d65d 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Spine-SkeletonLit-URP.shader +++ b/spine-unity/Modules/com.esotericsoftware.spine.urp-shaders/Shaders/Spine-SkeletonLit-URP.shader @@ -3,6 +3,7 @@ _Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1 [NoScaleOffset] _MainTex ("Main Texture", 2D) = "black" {} [Toggle(_STRAIGHT_ALPHA_INPUT)] _StraightAlphaInput("Straight Alpha Texture", Int) = 0 + [Toggle(_DOUBLE_SIDED_LIGHTING)] _DoubleSidedLighting("Double-Sided Lighting", Int) = 0 [HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0 [Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Compare", Float) = 0.0 // Disabled stencil test by default } @@ -55,6 +56,7 @@ //-------------------------------------- // Spine related keywords #pragma shader_feature _ _STRAIGHT_ALPHA_INPUT + #pragma shader_feature _ _DOUBLE_SIDED_LIGHTING #pragma vertex vert #pragma fragment frag