Merge branch '3.6' into 3.7-beta

This commit is contained in:
badlogic 2018-02-06 15:16:55 +01:00
commit 28df2f8944
20 changed files with 312 additions and 180 deletions

View File

@ -72,6 +72,7 @@
* Added support for vertex effects. See `RaptorExample.cpp`. * Added support for vertex effects. See `RaptorExample.cpp`.
* Added ETC1 alpha support, thanks @halx99! Does not work when two color tint is enabled. * Added ETC1 alpha support, thanks @halx99! Does not work when two color tint is enabled.
* Added `spAtlasPage_setCustomTextureLoader()` which let's you do texture loading manually. Thanks @jareguo. * Added `spAtlasPage_setCustomTextureLoader()` which let's you do texture loading manually. Thanks @jareguo.
* Added `SkeletonRenderer:setSlotsRange()` and `SkeletonRenderer::createWithSkeleton()`. This allows you to split rendering of a skeleton up into multiple parts, and render other nodes in between. See `SkeletonRendererSeparatorExample.cpp` for an example.
### Cocos2d-Objc ### Cocos2d-Objc
* Fixed renderer to work with 3.6 changes * Fixed renderer to work with 3.6 changes

View File

@ -36,6 +36,7 @@
#include "RaptorExample.h" #include "RaptorExample.h"
#include "BatchingExample.h" #include "BatchingExample.h"
#include "CoinExample.h" #include "CoinExample.h"
#include "SkeletonRendererSeparatorExample.h"
#include "AppMacros.h" #include "AppMacros.h"
USING_NS_CC; USING_NS_CC;
@ -99,7 +100,7 @@ bool AppDelegate::applicationDidFinishLaunching () {
// create a scene. it's an autorelease object // create a scene. it's an autorelease object
//auto scene = RaptorExample::scene(); //auto scene = RaptorExample::scene();
auto scene = BatchingExample::scene(); auto scene = SkeletonRendererSeparatorExample::scene();
// run // run
director->runWithScene(scene); director->runWithScene(scene);

View File

@ -1,102 +0,0 @@
/******************************************************************************
* Spine Runtimes Software License v2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
* the Spine Software License Agreement), you may not (a) modify, translate,
* adapt, or develop new applications using the Spine Runtimes or otherwise
* create derivative works or improvements of the Spine Runtimes or (b) remove,
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
* or other intellectual property or proprietary rights notices on or in the
* Software, including any copy thereof. Redistributions in binary or source
* form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "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 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.
*****************************************************************************/
#include "SimpleCommand.h"
USING_NS_CC;
using namespace std;
Scene* SimpleCommand::scene () {
Scene *scene = Scene::create();
scene->addChild(SimpleCommand::create());
return scene;
}
bool SimpleCommand::init () {
if (!Node::init()) return false;
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP));
_texture = _director->getTextureCache()->addImage("sprite.png");
setPosition(100, 100);
return true;
}
void SimpleCommand::draw (Renderer* renderer, const Mat4& transform, uint32_t transformFlags) {
TrianglesCommand::Triangles* triangles = new TrianglesCommand::Triangles();
float x = 0, y = 0;
float w = 80, h = 80;
triangles->vertCount = 4;
triangles->verts = new V3F_C4B_T2F[4];
triangles->verts[0].colors = Color4B::WHITE;
triangles->verts[0].texCoords.u = 0;
triangles->verts[0].texCoords.v = 1;
triangles->verts[0].vertices.x = 0;
triangles->verts[0].vertices.y = 0;
triangles->verts[0].vertices.z = 0;
triangles->verts[1].colors = Color4B::WHITE;
triangles->verts[1].texCoords.u = 0;
triangles->verts[1].texCoords.v = 0;
triangles->verts[1].vertices.x = 0;
triangles->verts[1].vertices.y = h;
triangles->verts[1].vertices.z = 0;
triangles->verts[2].colors = Color4B::WHITE;
triangles->verts[2].texCoords.u = 1;
triangles->verts[2].texCoords.v = 1;
triangles->verts[2].vertices.x = w;
triangles->verts[2].vertices.y = 0;
triangles->verts[2].vertices.z = 0;
triangles->verts[3].colors = Color4B::WHITE;
triangles->verts[3].texCoords.u = 1;
triangles->verts[3].texCoords.v = 0;
triangles->verts[3].vertices.x = w;
triangles->verts[3].vertices.y = h;
triangles->verts[3].vertices.z = 0;
triangles->indexCount = 6;
triangles->indices = new GLushort[6];
triangles->indices[0] = 0;
triangles->indices[1] = 1;
triangles->indices[2] = 2;
triangles->indices[3] = 3;
triangles->indices[4] = 2;
triangles->indices[5] = 1;
TrianglesCommand* trianglesCommand = new TrianglesCommand();
trianglesCommand->init(_globalZOrder, _texture->getName(), getGLProgramState(), BlendFunc::ALPHA_PREMULTIPLIED, *triangles, transform, transformFlags);
renderer->addCommand(trianglesCommand);
}

View File

@ -0,0 +1,96 @@
/******************************************************************************
* Spine Runtimes Software License v2.5
*
* Copyright (c) 2013-2016, Esoteric Software
* All rights reserved.
*
* You are granted a perpetual, non-exclusive, non-sublicensable, and
* non-transferable license to use, install, execute, and perform the Spine
* Runtimes software and derivative works solely for personal or internal
* use. Without the written permission of Esoteric Software (see Section 2 of
* the Spine Software License Agreement), you may not (a) modify, translate,
* adapt, or develop new applications using the Spine Runtimes or otherwise
* create derivative works or improvements of the Spine Runtimes or (b) remove,
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
* or other intellectual property or proprietary rights notices on or in the
* Software, including any copy thereof. Redistributions in binary or source
* form must include this license and terms.
*
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "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 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.
*****************************************************************************/
#include "SkeletonRendererSeparatorExample.h"
#include "GoblinsExample.h"
USING_NS_CC;
using namespace spine;
Scene* SkeletonRendererSeparatorExample::scene () {
Scene *scene = Scene::create();
scene->addChild(SkeletonRendererSeparatorExample::create());
return scene;
}
bool SkeletonRendererSeparatorExample::init () {
if (!LayerColor::initWithColor(Color4B(128, 128, 128, 255))) return false;
// Spineboy's back, which will manage the animation and GPU resources
// will render only the front slots of Spineboy
backNode = SkeletonAnimation::createWithJsonFile("spineboy-ess.json", "spineboy.atlas", 0.6f);
backNode->setMix("walk", "jump", 0.4);
backNode->setAnimation(0, "walk", true);
backNode->setSlotsRange(backNode->findSlot("rear-upper-arm")->data->index, backNode->findSlot("rear-shin")->data->index);
backNode->setPosition(Vec2(_contentSize.width / 2, 20));
// A simple rectangle to go between the front and back slots of Spineboy
betweenNode = DrawNode::create();
Vec2 rect[4];
rect[0] = Vec2(0, 0);
rect[1] = Vec2(40, 0);
rect[2] = Vec2(40, 200);
rect[3] = Vec2(0, 200);
betweenNode->drawPolygon(rect, 4, Color4F(1, 0, 0, 1), 1, Color4F(1, 0, 0, 1));
betweenNode->setPosition(Vec2(_contentSize.width / 2 + 30, 20));
// Spineboy's front, doesn't manage any skeleton, animation or GPU resources, but simply
// renders the back slots of Spineboy. The skeleton, animatio state and GPU resources
// are shared with the front node!
frontNode = SkeletonRenderer::createWithSkeleton(backNode->getSkeleton());
frontNode->setSlotsRange(frontNode->findSlot("neck")->data->index, -1);
frontNode->setPosition(Vec2(_contentSize.width / 2, 20));
// Add the front, between and back node in the correct order to this scene
addChild(backNode);
addChild(betweenNode);
addChild(frontNode);
scheduleUpdate();
EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = [this] (Touch* touch, Event* event) -> bool {
if (!backNode->getDebugBonesEnabled())
backNode->setDebugBonesEnabled(true);
else if (backNode->getTimeScale() == 1)
backNode->setTimeScale(0.3f);
else
Director::getInstance()->replaceScene(GoblinsExample::scene());
return true;
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
return true;
}
void SkeletonRendererSeparatorExample::update (float deltaTime) {
// Test releasing memory.
// Director::getInstance()->replaceScene(SpineboyExample::scene());
}

View File

@ -28,23 +28,27 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
#ifndef _SIMPLECOMMAND_H_ #ifndef _SKELETONRENDERERSEPARATOREXAMPLE_H_
#define _SIMPLECOMMAND_H_ #define _SKELETONRENDERERSEPARATOREXAMPLE_H_
#include "cocos2d.h" #include "cocos2d.h"
#include <spine/spine-cocos2dx.h>
class SkeletonRendererSeparatorExample : public cocos2d::LayerColor {
class SimpleCommand : public cocos2d::Node {
public: public:
static cocos2d::Scene* scene (); static cocos2d::Scene* scene ();
CREATE_FUNC (SkeletonRendererSeparatorExample);
virtual bool init (); virtual bool init ();
virtual void draw (cocos2d::Renderer* renderer, const cocos2d::Mat4& transform, uint32_t transformFlags) override;
CREATE_FUNC (SimpleCommand); virtual void update (float deltaTime);
private:
spine::SkeletonAnimation* backNode;
spine::SkeletonRenderer* frontNode;
cocos2d::DrawNode* betweenNode;
protected:
cocos2d::Texture2D* _texture;
}; };
#endif // _SIMPLECOMMAND_H_ #endif // _SKELETONRENDERERSEPARATOREXAMPLE_H_

View File

@ -52,7 +52,6 @@
76AAA3C11D180F7C00C54FCB /* BatchingExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3B61D180F7C00C54FCB /* BatchingExample.cpp */; }; 76AAA3C11D180F7C00C54FCB /* BatchingExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3B61D180F7C00C54FCB /* BatchingExample.cpp */; };
76AAA3C21D180F7C00C54FCB /* GoblinsExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3B81D180F7C00C54FCB /* GoblinsExample.cpp */; }; 76AAA3C21D180F7C00C54FCB /* GoblinsExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3B81D180F7C00C54FCB /* GoblinsExample.cpp */; };
76AAA3C31D180F7C00C54FCB /* RaptorExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3BA1D180F7C00C54FCB /* RaptorExample.cpp */; }; 76AAA3C31D180F7C00C54FCB /* RaptorExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3BA1D180F7C00C54FCB /* RaptorExample.cpp */; };
76AAA3C41D180F7C00C54FCB /* SimpleCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3BC1D180F7C00C54FCB /* SimpleCommand.cpp */; };
76AAA3C51D180F7C00C54FCB /* SpineboyExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3BE1D180F7C00C54FCB /* SpineboyExample.cpp */; }; 76AAA3C51D180F7C00C54FCB /* SpineboyExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3BE1D180F7C00C54FCB /* SpineboyExample.cpp */; };
76AAA40C1D18106000C54FCB /* AttachmentVertices.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA4001D18106000C54FCB /* AttachmentVertices.cpp */; }; 76AAA40C1D18106000C54FCB /* AttachmentVertices.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA4001D18106000C54FCB /* AttachmentVertices.cpp */; };
76AAA40D1D18106000C54FCB /* Cocos2dAttachmentLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA4021D18106000C54FCB /* Cocos2dAttachmentLoader.cpp */; }; 76AAA40D1D18106000C54FCB /* Cocos2dAttachmentLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA4021D18106000C54FCB /* Cocos2dAttachmentLoader.cpp */; };
@ -81,12 +80,12 @@
76AAA4411D1811B000C54FCB /* GoblinsExample.h in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3B91D180F7C00C54FCB /* GoblinsExample.h */; }; 76AAA4411D1811B000C54FCB /* GoblinsExample.h in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3B91D180F7C00C54FCB /* GoblinsExample.h */; };
76AAA4421D1811B000C54FCB /* RaptorExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3BA1D180F7C00C54FCB /* RaptorExample.cpp */; }; 76AAA4421D1811B000C54FCB /* RaptorExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3BA1D180F7C00C54FCB /* RaptorExample.cpp */; };
76AAA4431D1811B000C54FCB /* RaptorExample.h in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3BB1D180F7C00C54FCB /* RaptorExample.h */; }; 76AAA4431D1811B000C54FCB /* RaptorExample.h in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3BB1D180F7C00C54FCB /* RaptorExample.h */; };
76AAA4441D1811B000C54FCB /* SimpleCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3BC1D180F7C00C54FCB /* SimpleCommand.cpp */; };
76AAA4451D1811B000C54FCB /* SimpleCommand.h in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3BD1D180F7C00C54FCB /* SimpleCommand.h */; };
76AAA4461D1811B000C54FCB /* SpineboyExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3BE1D180F7C00C54FCB /* SpineboyExample.cpp */; }; 76AAA4461D1811B000C54FCB /* SpineboyExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3BE1D180F7C00C54FCB /* SpineboyExample.cpp */; };
76AAA4471D1811B000C54FCB /* SpineboyExample.h in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3BF1D180F7C00C54FCB /* SpineboyExample.h */; }; 76AAA4471D1811B000C54FCB /* SpineboyExample.h in Sources */ = {isa = PBXBuildFile; fileRef = 76AAA3BF1D180F7C00C54FCB /* SpineboyExample.h */; };
76AAA4571D18132D00C54FCB /* common in Resources */ = {isa = PBXBuildFile; fileRef = 76AAA4521D18132D00C54FCB /* common */; }; 76AAA4571D18132D00C54FCB /* common in Resources */ = {isa = PBXBuildFile; fileRef = 76AAA4521D18132D00C54FCB /* common */; };
76AAA4581D18132D00C54FCB /* common in Resources */ = {isa = PBXBuildFile; fileRef = 76AAA4521D18132D00C54FCB /* common */; }; 76AAA4581D18132D00C54FCB /* common in Resources */ = {isa = PBXBuildFile; fileRef = 76AAA4521D18132D00C54FCB /* common */; };
76D1BFE02029E35200A0272D /* SkeletonRendererSeparatorExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76D1BFDF2029E35200A0272D /* SkeletonRendererSeparatorExample.cpp */; };
76D1BFE12029E37700A0272D /* SkeletonRendererSeparatorExample.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76D1BFDF2029E35200A0272D /* SkeletonRendererSeparatorExample.cpp */; };
76D520DA1EB3611300572471 /* ClippingAttachment.c in Sources */ = {isa = PBXBuildFile; fileRef = 76D520D71EB3611300572471 /* ClippingAttachment.c */; }; 76D520DA1EB3611300572471 /* ClippingAttachment.c in Sources */ = {isa = PBXBuildFile; fileRef = 76D520D71EB3611300572471 /* ClippingAttachment.c */; };
76D520DB1EB3611300572471 /* SkeletonClipping.c in Sources */ = {isa = PBXBuildFile; fileRef = 76D520D81EB3611300572471 /* SkeletonClipping.c */; }; 76D520DB1EB3611300572471 /* SkeletonClipping.c in Sources */ = {isa = PBXBuildFile; fileRef = 76D520D81EB3611300572471 /* SkeletonClipping.c */; };
76D520DC1EB3611300572471 /* Triangulator.c in Sources */ = {isa = PBXBuildFile; fileRef = 76D520D91EB3611300572471 /* Triangulator.c */; }; 76D520DC1EB3611300572471 /* Triangulator.c in Sources */ = {isa = PBXBuildFile; fileRef = 76D520D91EB3611300572471 /* Triangulator.c */; };
@ -276,8 +275,6 @@
76AAA3B91D180F7C00C54FCB /* GoblinsExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GoblinsExample.h; sourceTree = "<group>"; }; 76AAA3B91D180F7C00C54FCB /* GoblinsExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GoblinsExample.h; sourceTree = "<group>"; };
76AAA3BA1D180F7C00C54FCB /* RaptorExample.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RaptorExample.cpp; sourceTree = "<group>"; }; 76AAA3BA1D180F7C00C54FCB /* RaptorExample.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RaptorExample.cpp; sourceTree = "<group>"; };
76AAA3BB1D180F7C00C54FCB /* RaptorExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RaptorExample.h; sourceTree = "<group>"; }; 76AAA3BB1D180F7C00C54FCB /* RaptorExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RaptorExample.h; sourceTree = "<group>"; };
76AAA3BC1D180F7C00C54FCB /* SimpleCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SimpleCommand.cpp; sourceTree = "<group>"; };
76AAA3BD1D180F7C00C54FCB /* SimpleCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleCommand.h; sourceTree = "<group>"; };
76AAA3BE1D180F7C00C54FCB /* SpineboyExample.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SpineboyExample.cpp; sourceTree = "<group>"; }; 76AAA3BE1D180F7C00C54FCB /* SpineboyExample.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SpineboyExample.cpp; sourceTree = "<group>"; };
76AAA3BF1D180F7C00C54FCB /* SpineboyExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpineboyExample.h; sourceTree = "<group>"; }; 76AAA3BF1D180F7C00C54FCB /* SpineboyExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpineboyExample.h; sourceTree = "<group>"; };
76AAA4001D18106000C54FCB /* AttachmentVertices.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AttachmentVertices.cpp; path = ../../src/spine/AttachmentVertices.cpp; sourceTree = "<group>"; }; 76AAA4001D18106000C54FCB /* AttachmentVertices.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AttachmentVertices.cpp; path = ../../src/spine/AttachmentVertices.cpp; sourceTree = "<group>"; };
@ -293,6 +290,8 @@
76AAA40A1D18106000C54FCB /* spine-cocos2dx.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "spine-cocos2dx.cpp"; path = "../../src/spine/spine-cocos2dx.cpp"; sourceTree = "<group>"; }; 76AAA40A1D18106000C54FCB /* spine-cocos2dx.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "spine-cocos2dx.cpp"; path = "../../src/spine/spine-cocos2dx.cpp"; sourceTree = "<group>"; };
76AAA40B1D18106000C54FCB /* spine-cocos2dx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "spine-cocos2dx.h"; path = "../../src/spine/spine-cocos2dx.h"; sourceTree = "<group>"; }; 76AAA40B1D18106000C54FCB /* spine-cocos2dx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "spine-cocos2dx.h"; path = "../../src/spine/spine-cocos2dx.h"; sourceTree = "<group>"; };
76AAA4521D18132D00C54FCB /* common */ = {isa = PBXFileReference; lastKnownFileType = folder; path = common; sourceTree = "<group>"; }; 76AAA4521D18132D00C54FCB /* common */ = {isa = PBXFileReference; lastKnownFileType = folder; path = common; sourceTree = "<group>"; };
76D1BFDE2029E35100A0272D /* SkeletonRendererSeparatorExample.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SkeletonRendererSeparatorExample.h; sourceTree = "<group>"; };
76D1BFDF2029E35200A0272D /* SkeletonRendererSeparatorExample.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SkeletonRendererSeparatorExample.cpp; sourceTree = "<group>"; };
76D520D71EB3611300572471 /* ClippingAttachment.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ClippingAttachment.c; path = "../../../spine-c/spine-c/src/spine/ClippingAttachment.c"; sourceTree = "<group>"; }; 76D520D71EB3611300572471 /* ClippingAttachment.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ClippingAttachment.c; path = "../../../spine-c/spine-c/src/spine/ClippingAttachment.c"; sourceTree = "<group>"; };
76D520D81EB3611300572471 /* SkeletonClipping.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SkeletonClipping.c; path = "../../../spine-c/spine-c/src/spine/SkeletonClipping.c"; sourceTree = "<group>"; }; 76D520D81EB3611300572471 /* SkeletonClipping.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SkeletonClipping.c; path = "../../../spine-c/spine-c/src/spine/SkeletonClipping.c"; sourceTree = "<group>"; };
76D520D91EB3611300572471 /* Triangulator.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = Triangulator.c; path = "../../../spine-c/spine-c/src/spine/Triangulator.c"; sourceTree = "<group>"; }; 76D520D91EB3611300572471 /* Triangulator.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = Triangulator.c; path = "../../../spine-c/spine-c/src/spine/Triangulator.c"; sourceTree = "<group>"; };
@ -483,6 +482,8 @@
46880B8319C43A87006E1F66 /* Classes */ = { 46880B8319C43A87006E1F66 /* Classes */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
76D1BFDF2029E35200A0272D /* SkeletonRendererSeparatorExample.cpp */,
76D1BFDE2029E35100A0272D /* SkeletonRendererSeparatorExample.h */,
76D520E41EB362DD00572471 /* CoinExample.cpp */, 76D520E41EB362DD00572471 /* CoinExample.cpp */,
76D520E51EB362DD00572471 /* CoinExample.h */, 76D520E51EB362DD00572471 /* CoinExample.h */,
76F5BD531D2BD7D3005917E5 /* TankExample.cpp */, 76F5BD531D2BD7D3005917E5 /* TankExample.cpp */,
@ -496,8 +497,6 @@
76AAA3B91D180F7C00C54FCB /* GoblinsExample.h */, 76AAA3B91D180F7C00C54FCB /* GoblinsExample.h */,
76AAA3BA1D180F7C00C54FCB /* RaptorExample.cpp */, 76AAA3BA1D180F7C00C54FCB /* RaptorExample.cpp */,
76AAA3BB1D180F7C00C54FCB /* RaptorExample.h */, 76AAA3BB1D180F7C00C54FCB /* RaptorExample.h */,
76AAA3BC1D180F7C00C54FCB /* SimpleCommand.cpp */,
76AAA3BD1D180F7C00C54FCB /* SimpleCommand.h */,
76AAA3BE1D180F7C00C54FCB /* SpineboyExample.cpp */, 76AAA3BE1D180F7C00C54FCB /* SpineboyExample.cpp */,
76AAA3BF1D180F7C00C54FCB /* SpineboyExample.h */, 76AAA3BF1D180F7C00C54FCB /* SpineboyExample.h */,
); );
@ -763,6 +762,7 @@
files = ( files = (
76F28CCA1DEC7EBB00CDE54D /* SkeletonJson.c in Sources */, 76F28CCA1DEC7EBB00CDE54D /* SkeletonJson.c in Sources */,
76AAA40C1D18106000C54FCB /* AttachmentVertices.cpp in Sources */, 76AAA40C1D18106000C54FCB /* AttachmentVertices.cpp in Sources */,
76D1BFE02029E35200A0272D /* SkeletonRendererSeparatorExample.cpp in Sources */,
76F28CC81DEC7EBB00CDE54D /* SkeletonBounds.c in Sources */, 76F28CC81DEC7EBB00CDE54D /* SkeletonBounds.c in Sources */,
76F28CB71DEC7EBB00CDE54D /* AttachmentLoader.c in Sources */, 76F28CB71DEC7EBB00CDE54D /* AttachmentLoader.c in Sources */,
76F5BD551D2BD7D3005917E5 /* TankExample.cpp in Sources */, 76F5BD551D2BD7D3005917E5 /* TankExample.cpp in Sources */,
@ -785,7 +785,6 @@
76AAA3C01D180F7C00C54FCB /* AppDelegate.cpp in Sources */, 76AAA3C01D180F7C00C54FCB /* AppDelegate.cpp in Sources */,
76FAC18D1E3F97D2001CCC8C /* PointAttachment.c in Sources */, 76FAC18D1E3F97D2001CCC8C /* PointAttachment.c in Sources */,
76F28CC31DEC7EBB00CDE54D /* PathConstraint.c in Sources */, 76F28CC31DEC7EBB00CDE54D /* PathConstraint.c in Sources */,
76AAA3C41D180F7C00C54FCB /* SimpleCommand.cpp in Sources */,
503AE10017EB989F00D1A890 /* AppController.mm in Sources */, 503AE10017EB989F00D1A890 /* AppController.mm in Sources */,
76F28CC11DEC7EBB00CDE54D /* MeshAttachment.c in Sources */, 76F28CC11DEC7EBB00CDE54D /* MeshAttachment.c in Sources */,
76F28CC01DEC7EBB00CDE54D /* Json.c in Sources */, 76F28CC01DEC7EBB00CDE54D /* Json.c in Sources */,
@ -825,6 +824,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
76D1BFE12029E37700A0272D /* SkeletonRendererSeparatorExample.cpp in Sources */,
76FB15111F0139B400C5377F /* VertexEffect.c in Sources */, 76FB15111F0139B400C5377F /* VertexEffect.c in Sources */,
76D520E71EB3634600572471 /* CoinExample.cpp in Sources */, 76D520E71EB3634600572471 /* CoinExample.cpp in Sources */,
76D520E31EB3625B00572471 /* Array.c in Sources */, 76D520E31EB3625B00572471 /* Array.c in Sources */,
@ -878,8 +878,6 @@
76AAA4411D1811B000C54FCB /* GoblinsExample.h in Sources */, 76AAA4411D1811B000C54FCB /* GoblinsExample.h in Sources */,
76AAA4421D1811B000C54FCB /* RaptorExample.cpp in Sources */, 76AAA4421D1811B000C54FCB /* RaptorExample.cpp in Sources */,
76AAA4431D1811B000C54FCB /* RaptorExample.h in Sources */, 76AAA4431D1811B000C54FCB /* RaptorExample.h in Sources */,
76AAA4441D1811B000C54FCB /* SimpleCommand.cpp in Sources */,
76AAA4451D1811B000C54FCB /* SimpleCommand.h in Sources */,
76AAA4461D1811B000C54FCB /* SpineboyExample.cpp in Sources */, 76AAA4461D1811B000C54FCB /* SpineboyExample.cpp in Sources */,
76AAA4471D1811B000C54FCB /* SpineboyExample.h in Sources */, 76AAA4471D1811B000C54FCB /* SpineboyExample.h in Sources */,
76AAA4121D18119F00C54FCB /* AttachmentVertices.cpp in Sources */, 76AAA4121D18119F00C54FCB /* AttachmentVertices.cpp in Sources */,

View File

@ -65,6 +65,12 @@ void SkeletonRenderer::destroyScratchBuffers() {
} }
} }
SkeletonRenderer* SkeletonRenderer::createWithSkeleton(spSkeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData) {
SkeletonRenderer* node = new SkeletonRenderer(skeleton, ownsSkeleton, ownsSkeletonData);
node->autorelease();
return node;
}
SkeletonRenderer* SkeletonRenderer::createWithData (spSkeletonData* skeletonData, bool ownsSkeletonData) { SkeletonRenderer* SkeletonRenderer::createWithData (spSkeletonData* skeletonData, bool ownsSkeletonData) {
SkeletonRenderer* node = new SkeletonRenderer(skeletonData, ownsSkeletonData); SkeletonRenderer* node = new SkeletonRenderer(skeletonData, ownsSkeletonData);
node->autorelease(); node->autorelease();
@ -135,38 +141,51 @@ void SkeletonRenderer::setSkeletonData (spSkeletonData *skeletonData, bool ownsS
} }
SkeletonRenderer::SkeletonRenderer () SkeletonRenderer::SkeletonRenderer ()
: _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1), _effect(nullptr) { : _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1), _effect(nullptr), _startSlotIndex(-1), _endSlotIndex(-1) {
}
SkeletonRenderer::SkeletonRenderer(spSkeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData)
: _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1), _effect(nullptr), _startSlotIndex(-1), _endSlotIndex(-1) {
initWithSkeleton(skeleton, ownsSkeleton, ownsSkeletonData);
} }
SkeletonRenderer::SkeletonRenderer (spSkeletonData *skeletonData, bool ownsSkeletonData) SkeletonRenderer::SkeletonRenderer (spSkeletonData *skeletonData, bool ownsSkeletonData)
: _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1), _effect(nullptr) { : _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1), _effect(nullptr), _startSlotIndex(-1), _endSlotIndex(-1) {
initWithData(skeletonData, ownsSkeletonData); initWithData(skeletonData, ownsSkeletonData);
} }
SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, spAtlas* atlas, float scale) SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, spAtlas* atlas, float scale)
: _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1), _effect(nullptr) { : _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1), _effect(nullptr), _startSlotIndex(-1), _endSlotIndex(-1) {
initWithJsonFile(skeletonDataFile, atlas, scale); initWithJsonFile(skeletonDataFile, atlas, scale);
} }
SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) SkeletonRenderer::SkeletonRenderer (const std::string& skeletonDataFile, const std::string& atlasFile, float scale)
: _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1), _effect(nullptr) { : _atlas(nullptr), _attachmentLoader(nullptr), _debugSlots(false), _debugBones(false), _debugMeshes(false), _timeScale(1), _effect(nullptr), _startSlotIndex(-1), _endSlotIndex(-1) {
initWithJsonFile(skeletonDataFile, atlasFile, scale); initWithJsonFile(skeletonDataFile, atlasFile, scale);
} }
SkeletonRenderer::~SkeletonRenderer () { SkeletonRenderer::~SkeletonRenderer () {
if (_ownsSkeletonData) spSkeletonData_dispose(_skeleton->data); if (_ownsSkeletonData) spSkeletonData_dispose(_skeleton->data);
spSkeleton_dispose(_skeleton); if (_ownsSkeleton) spSkeleton_dispose(_skeleton);
if (_atlas) spAtlas_dispose(_atlas); if (_atlas) spAtlas_dispose(_atlas);
if (_attachmentLoader) spAttachmentLoader_dispose(_attachmentLoader); if (_attachmentLoader) spAttachmentLoader_dispose(_attachmentLoader);
spSkeletonClipping_dispose(_clipper); spSkeletonClipping_dispose(_clipper);
} }
void SkeletonRenderer::initWithData (spSkeletonData* skeletonData, bool ownsSkeletonData) { void SkeletonRenderer::initWithSkeleton(spSkeleton* skeleton, bool ownsSkeleton, bool ownsSkeletonData) {
setSkeletonData(skeletonData, ownsSkeletonData); _skeleton = skeleton;
_ownsSkeleton = ownsSkeleton;
_ownsSkeletonData = ownsSkeletonData;
initialize(); initialize();
} }
void SkeletonRenderer::initWithData (spSkeletonData* skeletonData, bool ownsSkeletonData) {
_ownsSkeleton = true;
setSkeletonData(skeletonData, ownsSkeletonData);
initialize();
}
void SkeletonRenderer::initWithJsonFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale) { void SkeletonRenderer::initWithJsonFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale) {
_atlas = atlas; _atlas = atlas;
_attachmentLoader = SUPER(Cocos2dAttachmentLoader_create(_atlas)); _attachmentLoader = SUPER(Cocos2dAttachmentLoader_create(_atlas));
@ -177,6 +196,7 @@ void SkeletonRenderer::initWithJsonFile (const std::string& skeletonDataFile, sp
CCASSERT(skeletonData, json->error ? json->error : "Error reading skeleton data."); CCASSERT(skeletonData, json->error ? json->error : "Error reading skeleton data.");
spSkeletonJson_dispose(json); spSkeletonJson_dispose(json);
_ownsSkeleton = true;
setSkeletonData(skeletonData, true); setSkeletonData(skeletonData, true);
initialize(); initialize();
@ -194,6 +214,7 @@ void SkeletonRenderer::initWithJsonFile (const std::string& skeletonDataFile, co
CCASSERT(skeletonData, json->error ? json->error : "Error reading skeleton data file."); CCASSERT(skeletonData, json->error ? json->error : "Error reading skeleton data file.");
spSkeletonJson_dispose(json); spSkeletonJson_dispose(json);
_ownsSkeleton = true;
setSkeletonData(skeletonData, true); setSkeletonData(skeletonData, true);
initialize(); initialize();
@ -208,7 +229,7 @@ void SkeletonRenderer::initWithBinaryFile (const std::string& skeletonDataFile,
spSkeletonData* skeletonData = spSkeletonBinary_readSkeletonDataFile(binary, skeletonDataFile.c_str()); spSkeletonData* skeletonData = spSkeletonBinary_readSkeletonDataFile(binary, skeletonDataFile.c_str());
CCASSERT(skeletonData, binary->error ? binary->error : "Error reading skeleton data file."); CCASSERT(skeletonData, binary->error ? binary->error : "Error reading skeleton data file.");
spSkeletonBinary_dispose(binary); spSkeletonBinary_dispose(binary);
_ownsSkeleton = true;
setSkeletonData(skeletonData, true); setSkeletonData(skeletonData, true);
initialize(); initialize();
@ -225,7 +246,7 @@ void SkeletonRenderer::initWithBinaryFile (const std::string& skeletonDataFile,
spSkeletonData* skeletonData = spSkeletonBinary_readSkeletonDataFile(binary, skeletonDataFile.c_str()); spSkeletonData* skeletonData = spSkeletonBinary_readSkeletonDataFile(binary, skeletonDataFile.c_str());
CCASSERT(skeletonData, binary->error ? binary->error : "Error reading skeleton data file."); CCASSERT(skeletonData, binary->error ? binary->error : "Error reading skeleton data file.");
spSkeletonBinary_dispose(binary); spSkeletonBinary_dispose(binary);
_ownsSkeleton = true;
setSkeletonData(skeletonData, true); setSkeletonData(skeletonData, true);
initialize(); initialize();
@ -234,7 +255,7 @@ void SkeletonRenderer::initWithBinaryFile (const std::string& skeletonDataFile,
void SkeletonRenderer::update (float deltaTime) { void SkeletonRenderer::update (float deltaTime) {
Node::update(deltaTime); Node::update(deltaTime);
spSkeleton_update(_skeleton, deltaTime * _timeScale); if (_ownsSkeleton) spSkeleton_update(_skeleton, deltaTime * _timeScale);
} }
void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t transformFlags) { void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t transformFlags) {
@ -255,8 +276,23 @@ void SkeletonRenderer::draw (Renderer* renderer, const Mat4& transform, uint32_t
float darkPremultipliedAlpha = _premultipliedAlpha ? 255 : 0; float darkPremultipliedAlpha = _premultipliedAlpha ? 255 : 0;
AttachmentVertices* attachmentVertices = nullptr; AttachmentVertices* attachmentVertices = nullptr;
TwoColorTrianglesCommand* lastTwoColorTrianglesCommand = nullptr; TwoColorTrianglesCommand* lastTwoColorTrianglesCommand = nullptr;
bool inRange = _startSlotIndex != -1 || _endSlotIndex != -1 ? false : true;
for (int i = 0, n = _skeleton->slotsCount; i < n; ++i) { for (int i = 0, n = _skeleton->slotsCount; i < n; ++i) {
spSlot* slot = _skeleton->drawOrder[i]; spSlot* slot = _skeleton->drawOrder[i];
if (_startSlotIndex >= 0 && _startSlotIndex == slot->data->index) {
inRange = true;
}
if (!inRange) {
spSkeletonClipping_clipEnd(_clipper, slot);
continue;
}
if (_endSlotIndex >= 0 && _endSlotIndex == slot->data->index) {
inRange = false;
}
if (!slot->attachment) { if (!slot->attachment) {
spSkeletonClipping_clipEnd(_clipper, slot); spSkeletonClipping_clipEnd(_clipper, slot);
continue; continue;
@ -781,6 +817,11 @@ void SkeletonRenderer::setVertexEffect(spVertexEffect *effect) {
this->_effect = effect; this->_effect = effect;
} }
void SkeletonRenderer::setSlotsRange(int startSlotIndex, int endSlotIndex) {
this->_startSlotIndex = startSlotIndex;
this->_endSlotIndex = endSlotIndex;
}
spSkeleton* SkeletonRenderer::getSkeleton () { spSkeleton* SkeletonRenderer::getSkeleton () {
return _skeleton; return _skeleton;
} }

View File

@ -42,6 +42,7 @@ class AttachmentVertices;
class SkeletonRenderer: public cocos2d::Node, public cocos2d::BlendProtocol { class SkeletonRenderer: public cocos2d::Node, public cocos2d::BlendProtocol {
public: public:
CREATE_FUNC(SkeletonRenderer); CREATE_FUNC(SkeletonRenderer);
static SkeletonRenderer* createWithSkeleton(spSkeleton* skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false);
static SkeletonRenderer* createWithData (spSkeletonData* skeletonData, bool ownsSkeletonData = false); static SkeletonRenderer* createWithData (spSkeletonData* skeletonData, bool ownsSkeletonData = false);
static SkeletonRenderer* createWithFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1); static SkeletonRenderer* createWithFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1);
static SkeletonRenderer* createWithFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1); static SkeletonRenderer* createWithFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1);
@ -103,6 +104,9 @@ public:
/* Sets the vertex effect to be used, set to 0 to disable vertex effects */ /* Sets the vertex effect to be used, set to 0 to disable vertex effects */
void setVertexEffect(spVertexEffect* effect); void setVertexEffect(spVertexEffect* effect);
/* Sets the range of slots that should be rendered. Use -1, -1 to clear the range */
void setSlotsRange(int startSlotIndex, int endSlotIndex);
// --- BlendProtocol // --- BlendProtocol
virtual void setBlendFunc (const cocos2d::BlendFunc& blendFunc)override; virtual void setBlendFunc (const cocos2d::BlendFunc& blendFunc)override;
virtual const cocos2d::BlendFunc& getBlendFunc () const override; virtual const cocos2d::BlendFunc& getBlendFunc () const override;
@ -114,12 +118,14 @@ public:
CC_CONSTRUCTOR_ACCESS: CC_CONSTRUCTOR_ACCESS:
SkeletonRenderer (); SkeletonRenderer ();
SkeletonRenderer(spSkeleton* skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false);
SkeletonRenderer (spSkeletonData* skeletonData, bool ownsSkeletonData = false); SkeletonRenderer (spSkeletonData* skeletonData, bool ownsSkeletonData = false);
SkeletonRenderer (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1); SkeletonRenderer (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1);
SkeletonRenderer (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1); SkeletonRenderer (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1);
virtual ~SkeletonRenderer (); virtual ~SkeletonRenderer ();
void initWithSkeleton(spSkeleton* skeleton, bool ownsSkeleton = false, bool ownsSkeletonData = false);
void initWithData (spSkeletonData* skeletonData, bool ownsSkeletonData = false); void initWithData (spSkeletonData* skeletonData, bool ownsSkeletonData = false);
void initWithJsonFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1); void initWithJsonFile (const std::string& skeletonDataFile, spAtlas* atlas, float scale = 1);
void initWithJsonFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1); void initWithJsonFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale = 1);
@ -135,6 +141,7 @@ protected:
void setupGLProgramState(bool twoColorTintEnabled); void setupGLProgramState(bool twoColorTintEnabled);
bool _ownsSkeletonData; bool _ownsSkeletonData;
bool _ownsSkeleton;
spAtlas* _atlas; spAtlas* _atlas;
spAttachmentLoader* _attachmentLoader; spAttachmentLoader* _attachmentLoader;
cocos2d::CustomCommand _debugCommand; cocos2d::CustomCommand _debugCommand;
@ -147,6 +154,9 @@ protected:
bool _debugMeshes; bool _debugMeshes;
spSkeletonClipping* _clipper; spSkeletonClipping* _clipper;
spVertexEffect* _effect; spVertexEffect* _effect;
int _startSlotIndex;
int _endSlotIndex;
}; };
} }

View File

@ -138,7 +138,7 @@ namespace Spine.Unity {
// Recommended setup: Use local transform properties if Spine GameObject is the immediate parent // Recommended setup: Use local transform properties if Spine GameObject is the immediate parent
thisTransform.localPosition = new Vector3(bone.worldX, bone.worldY, followZPosition ? 0f : thisTransform.localPosition.z); thisTransform.localPosition = new Vector3(bone.worldX, bone.worldY, followZPosition ? 0f : thisTransform.localPosition.z);
if (followBoneRotation) { if (followBoneRotation) {
var halfRotation = Mathf.Atan2(bone.c, bone.a) * 0.5f; float halfRotation = Mathf.Atan2(bone.c, bone.a) * 0.5f;
if (followLocalScale && bone.scaleX < 0) // Negate rotation from negative scaleX. Don't use negative determinant. local scaleY doesn't factor into used rotation. if (followLocalScale && bone.scaleX < 0) // Negate rotation from negative scaleX. Don't use negative determinant. local scaleY doesn't factor into used rotation.
halfRotation += Mathf.PI * 0.5f; halfRotation += Mathf.PI * 0.5f;

View File

@ -79,10 +79,10 @@ namespace Spine.Unity.Editor {
var objectReferenceValue = dataField.objectReferenceValue; var objectReferenceValue = dataField.objectReferenceValue;
if (objectReferenceValue is SkeletonDataAsset) { if (objectReferenceValue is SkeletonDataAsset) {
skeletonDataAsset = (SkeletonDataAsset)objectReferenceValue; skeletonDataAsset = (SkeletonDataAsset)objectReferenceValue;
} else if (objectReferenceValue is ISkeletonComponent) { } else if (objectReferenceValue is IHasSkeletonDataAsset) {
var skeletonComponent = (ISkeletonComponent)objectReferenceValue; var hasSkeletonDataAsset = (IHasSkeletonDataAsset)objectReferenceValue;
if (skeletonComponent != null) if (hasSkeletonDataAsset != null)
skeletonDataAsset = skeletonComponent.SkeletonDataAsset; skeletonDataAsset = hasSkeletonDataAsset.SkeletonDataAsset;
} else if (objectReferenceValue != null) { } else if (objectReferenceValue != null) {
EditorGUI.LabelField(position, "ERROR:", "Invalid reference type"); EditorGUI.LabelField(position, "ERROR:", "Invalid reference type");
return; return;
@ -90,9 +90,9 @@ namespace Spine.Unity.Editor {
} else if (property.serializedObject.targetObject is Component) { } else if (property.serializedObject.targetObject is Component) {
var component = (Component)property.serializedObject.targetObject; var component = (Component)property.serializedObject.targetObject;
var skeletonComponent = component.GetComponentInChildren(typeof(ISkeletonComponent)) as ISkeletonComponent; var hasSkeletonDataAsset = component.GetComponentInChildren(typeof(IHasSkeletonDataAsset)) as IHasSkeletonDataAsset;
if (skeletonComponent != null) if (hasSkeletonDataAsset != null)
skeletonDataAsset = skeletonComponent.SkeletonDataAsset; skeletonDataAsset = hasSkeletonDataAsset.SkeletonDataAsset;
} }
if (skeletonDataAsset == null) { if (skeletonDataAsset == null) {

View File

@ -220,9 +220,9 @@ namespace Spine.Unity.Editor {
public static bool TargetsUseSameData (SerializedObject so) { public static bool TargetsUseSameData (SerializedObject so) {
if (so.isEditingMultipleObjects) { if (so.isEditingMultipleObjects) {
int n = so.targetObjects.Length; int n = so.targetObjects.Length;
var first = so.targetObjects[0] as ISkeletonComponent; var first = so.targetObjects[0] as IHasSkeletonDataAsset;
for (int i = 1; i < n; i++) { for (int i = 1; i < n; i++) {
var sr = so.targetObjects[i] as ISkeletonComponent; var sr = so.targetObjects[i] as IHasSkeletonDataAsset;
if (sr != null && sr.SkeletonDataAsset != first.SkeletonDataAsset) if (sr != null && sr.SkeletonDataAsset != first.SkeletonDataAsset)
return false; return false;
} }

View File

@ -42,7 +42,7 @@ namespace Spine.Unity {
} }
/// <summary>Holds a reference to a SkeletonDataAsset.</summary> /// <summary>Holds a reference to a SkeletonDataAsset.</summary>
public interface ISkeletonDataAssetComponent { public interface IHasSkeletonDataAsset {
/// <summary>Gets the SkeletonDataAsset of the Spine Component.</summary> /// <summary>Gets the SkeletonDataAsset of the Spine Component.</summary>
SkeletonDataAsset SkeletonDataAsset { get; } SkeletonDataAsset SkeletonDataAsset { get; }
} }

View File

@ -9,7 +9,7 @@ Shader "Spine/Skeleton Fill" {
[NoScaleOffset]_MainTex ("MainTex", 2D) = "white" {} [NoScaleOffset]_MainTex ("MainTex", 2D) = "white" {}
} }
SubShader { SubShader {
Tags { "IgnoreProjector"="True" "Queue"="Transparent" "RenderType"="Transparent" "PreviewType"="Plane" } Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
Blend One OneMinusSrcAlpha Blend One OneMinusSrcAlpha
Cull Off Cull Off
ZWrite Off ZWrite Off

View File

@ -13,7 +13,7 @@ Shader "Spine/Skeleton Tint" {
} }
SubShader { SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
Fog { Mode Off } Fog { Mode Off }
Cull Off Cull Off

View File

@ -35,7 +35,7 @@ using Spine;
namespace Spine.Unity { namespace Spine.Unity {
[ExecuteInEditMode, RequireComponent(typeof(CanvasRenderer), typeof(RectTransform)), DisallowMultipleComponent] [ExecuteInEditMode, RequireComponent(typeof(CanvasRenderer), typeof(RectTransform)), DisallowMultipleComponent]
[AddComponentMenu("Spine/SkeletonGraphic (Unity UI Canvas)")] [AddComponentMenu("Spine/SkeletonGraphic (Unity UI Canvas)")]
public class SkeletonGraphic : MaskableGraphic, ISkeletonComponent, IAnimationStateComponent, ISkeletonAnimation, ISkeletonDataAssetComponent { public class SkeletonGraphic : MaskableGraphic, ISkeletonComponent, IAnimationStateComponent, ISkeletonAnimation, IHasSkeletonDataAsset {
#region Inspector #region Inspector
public SkeletonDataAsset skeletonDataAsset; public SkeletonDataAsset skeletonDataAsset;

View File

@ -5,7 +5,7 @@ Shader "Spine/Skeleton" {
} }
SubShader { SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane"}
Fog { Mode Off } Fog { Mode Off }
Cull Off Cull Off

View File

@ -38,7 +38,7 @@ namespace Spine.Unity {
/// <summary>Renders a skeleton.</summary> /// <summary>Renders a skeleton.</summary>
[ExecuteInEditMode, RequireComponent(typeof(MeshFilter), typeof(MeshRenderer)), DisallowMultipleComponent] [ExecuteInEditMode, RequireComponent(typeof(MeshFilter), typeof(MeshRenderer)), DisallowMultipleComponent]
[HelpURL("http://esotericsoftware.com/spine-unity-documentation#Rendering")] [HelpURL("http://esotericsoftware.com/spine-unity-documentation#Rendering")]
public class SkeletonRenderer : MonoBehaviour, ISkeletonComponent, ISkeletonDataAssetComponent { public class SkeletonRenderer : MonoBehaviour, ISkeletonComponent, IHasSkeletonDataAsset {
public delegate void SkeletonRendererDelegate (SkeletonRenderer skeletonRenderer); public delegate void SkeletonRendererDelegate (SkeletonRenderer skeletonRenderer);
public event SkeletonRendererDelegate OnRebuild; public event SkeletonRendererDelegate OnRebuild;

View File

@ -28,8 +28,10 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
//#define HINGECHAIN2D
// Contributed by: Mitch Thompson // Contributed by: Mitch Thompson
using UnityEngine; using UnityEngine;
using UnityEditor; using UnityEditor;
using System.Collections.Generic; using System.Collections.Generic;
@ -277,6 +279,54 @@ namespace Spine.Unity.Editor {
EditorGUIUtility.PingObject(go); EditorGUIUtility.PingObject(go);
} }
#if HINGECHAIN2D
bool CanCreateHingeChain () {
if (utilityBone == null) return false;
if (utilityBone.GetComponent<Rigidbody2D>() != null) return false;
if (utilityBone.bone != null && utilityBone.bone.Children.Count == 0) return false;
var rigidbodies = utilityBone.GetComponentsInChildren<Rigidbody2D>();
return rigidbodies.Length <= 0;
}
void CreateHingeChain () {
var utilBoneArr = utilityBone.GetComponentsInChildren<SkeletonUtilityBone>();
foreach (var utilBone in utilBoneArr) {
if (utilBone.GetComponent<Collider2D>() == null) {
if (utilBone.bone.Data.Length == 0) {
var sphere = utilBone.gameObject.AddComponent<CircleCollider2D>();
sphere.radius = 0.1f;
} else {
float length = utilBone.bone.Data.Length;
var box = utilBone.gameObject.AddComponent<BoxCollider2D>();
box.size = new Vector3(length, length / 3f, 0.2f);
box.offset = new Vector3(length / 2f, 0, 0);
}
}
utilBone.gameObject.AddComponent<Rigidbody2D>();
}
utilityBone.GetComponent<Rigidbody2D>().isKinematic = true;
foreach (var utilBone in utilBoneArr) {
if (utilBone == utilityBone)
continue;
utilBone.mode = SkeletonUtilityBone.Mode.Override;
var joint = utilBone.gameObject.AddComponent<HingeJoint2D>();
joint.connectedBody = utilBone.transform.parent.GetComponent<Rigidbody2D>();
joint.useLimits = true;
joint.limits = new JointAngleLimits2D {
min = -20,
max = 20
};
utilBone.GetComponent<Rigidbody2D>().mass = utilBone.transform.parent.GetComponent<Rigidbody2D>().mass * 0.75f;
}
}
#else
bool CanCreateHingeChain () { bool CanCreateHingeChain () {
if (utilityBone == null) if (utilityBone == null)
return false; return false;
@ -285,7 +335,7 @@ namespace Spine.Unity.Editor {
if (utilityBone.bone != null && utilityBone.bone.Children.Count == 0) if (utilityBone.bone != null && utilityBone.bone.Children.Count == 0)
return false; return false;
Rigidbody[] rigidbodies = utilityBone.GetComponentsInChildren<Rigidbody>(); var rigidbodies = utilityBone.GetComponentsInChildren<Rigidbody>();
return rigidbodies.Length <= 0; return rigidbodies.Length <= 0;
} }
@ -332,6 +382,7 @@ namespace Spine.Unity.Editor {
utilBone.gameObject.AddComponent<Rigidbody>(); utilBone.gameObject.AddComponent<Rigidbody>();
} }
#endif
} }
} }

View File

@ -267,27 +267,27 @@ namespace Spine.Unity {
for (int i = 0, n = utilityBones.Count; i < n; i++) for (int i = 0, n = utilityBones.Count; i < n; i++)
utilityBones[i].transformLerpComplete = false; utilityBones[i].transformLerpComplete = false;
UpdateAllBones(); UpdateAllBones(SkeletonUtilityBone.UpdatePhase.Local);
} }
void UpdateWorld (ISkeletonAnimation anim) { void UpdateWorld (ISkeletonAnimation anim) {
UpdateAllBones(); UpdateAllBones(SkeletonUtilityBone.UpdatePhase.World);
for (int i = 0, n = utilityConstraints.Count; i < n; i++) for (int i = 0, n = utilityConstraints.Count; i < n; i++)
utilityConstraints[i].DoUpdate(); utilityConstraints[i].DoUpdate();
} }
void UpdateComplete (ISkeletonAnimation anim) { void UpdateComplete (ISkeletonAnimation anim) {
UpdateAllBones(); UpdateAllBones(SkeletonUtilityBone.UpdatePhase.Complete);
} }
void UpdateAllBones () { void UpdateAllBones (SkeletonUtilityBone.UpdatePhase phase) {
if (boneRoot == null) if (boneRoot == null)
CollectBones(); CollectBones();
var utilityBones = this.utilityBones; var utilityBones = this.utilityBones;
if (utilityBones == null) return; if (utilityBones == null) return;
for (int i = 0, n = utilityBones.Count; i < n; i++) for (int i = 0, n = utilityBones.Count; i < n; i++)
utilityBones[i].DoUpdate(); utilityBones[i].DoUpdate(phase);
} }
public Transform GetBoneRoot () { public Transform GetBoneRoot () {

View File

@ -43,6 +43,12 @@ namespace Spine.Unity {
Override Override
} }
public enum UpdatePhase {
Local,
World,
Complete
}
#region Inspector #region Inspector
/// <summary>If a bone isn't set, boneName is used to find the bone.</summary> /// <summary>If a bone isn't set, boneName is used to find the bone.</summary>
public string boneName; public string boneName;
@ -71,7 +77,7 @@ namespace Spine.Unity {
skeletonTransform = skeletonUtility.transform; skeletonTransform = skeletonUtility.transform;
skeletonUtility.OnReset -= HandleOnReset; skeletonUtility.OnReset -= HandleOnReset;
skeletonUtility.OnReset += HandleOnReset; skeletonUtility.OnReset += HandleOnReset;
DoUpdate(); DoUpdate(UpdatePhase.Local);
} }
void OnEnable () { void OnEnable () {
@ -95,7 +101,7 @@ namespace Spine.Unity {
} }
} }
public void DoUpdate () { public void DoUpdate (UpdatePhase phase) {
if (!valid) { if (!valid) {
Reset(); Reset();
return; return;
@ -112,46 +118,72 @@ namespace Spine.Unity {
} }
} }
var thisTransform = cachedTransform;
float skeletonFlipRotation = (skeleton.flipX ^ skeleton.flipY) ? -1f : 1f; float skeletonFlipRotation = (skeleton.flipX ^ skeleton.flipY) ? -1f : 1f;
if (mode == Mode.Follow) { if (mode == Mode.Follow) {
if (!bone.appliedValid) switch (phase) {
bone.UpdateAppliedTransform(); case UpdatePhase.Local:
if (position)
thisTransform.localPosition = new Vector3(bone.x, bone.y, 0);
if (position) if (rotation) {
cachedTransform.localPosition = new Vector3(bone.ax, bone.ay, 0); if (bone.data.transformMode.InheritsRotation()) {
thisTransform.localRotation = Quaternion.Euler(0, 0, bone.rotation);
} else {
Vector3 euler = skeletonTransform.rotation.eulerAngles;
thisTransform.rotation = Quaternion.Euler(euler.x, euler.y, euler.z + (bone.WorldRotationX * skeletonFlipRotation));
}
}
if (rotation) { if (scale) {
if (bone.data.transformMode.InheritsRotation()) { thisTransform.localScale = new Vector3(bone.scaleX, bone.scaleY, 1f);
cachedTransform.localRotation = Quaternion.Euler(0, 0, bone.AppliedRotation); incompatibleTransformMode = BoneTransformModeIncompatible(bone);
} else { }
Vector3 euler = skeletonTransform.rotation.eulerAngles; break;
cachedTransform.rotation = Quaternion.Euler(euler.x, euler.y, euler.z + (bone.WorldRotationX * skeletonFlipRotation)); case UpdatePhase.World:
} case UpdatePhase.Complete:
// Use Applied transform values (ax, ay, AppliedRotation, ascale) if world values were modified by constraints.
if (!bone.appliedValid) {
bone.UpdateAppliedTransform();
if (position)
thisTransform.localPosition = new Vector3(bone.ax, bone.ay, 0);
if (rotation) {
if (bone.data.transformMode.InheritsRotation()) {
thisTransform.localRotation = Quaternion.Euler(0, 0, bone.AppliedRotation);
} else {
Vector3 euler = skeletonTransform.rotation.eulerAngles;
thisTransform.rotation = Quaternion.Euler(euler.x, euler.y, euler.z + (bone.WorldRotationX * skeletonFlipRotation));
}
}
if (scale) {
thisTransform.localScale = new Vector3(bone.ascaleX, bone.ascaleY, 1f);
incompatibleTransformMode = BoneTransformModeIncompatible(bone);
}
}
break;
} }
if (scale) {
cachedTransform.localScale = new Vector3(bone.ascaleX, bone.ascaleY, 1f);
incompatibleTransformMode = BoneTransformModeIncompatible(bone);
}
} else if (mode == Mode.Override) { } else if (mode == Mode.Override) {
if (transformLerpComplete) if (transformLerpComplete)
return; return;
if (parentReference == null) { if (parentReference == null) {
if (position) { if (position) {
Vector3 clp = cachedTransform.localPosition; Vector3 clp = thisTransform.localPosition;
bone.x = Mathf.Lerp(bone.x, clp.x, overrideAlpha); bone.x = Mathf.Lerp(bone.x, clp.x, overrideAlpha);
bone.y = Mathf.Lerp(bone.y, clp.y, overrideAlpha); bone.y = Mathf.Lerp(bone.y, clp.y, overrideAlpha);
} }
if (rotation) { if (rotation) {
float angle = Mathf.LerpAngle(bone.Rotation, cachedTransform.localRotation.eulerAngles.z, overrideAlpha); float angle = Mathf.LerpAngle(bone.Rotation, thisTransform.localRotation.eulerAngles.z, overrideAlpha);
bone.Rotation = angle; bone.Rotation = angle;
bone.AppliedRotation = angle; bone.AppliedRotation = angle;
} }
if (scale) { if (scale) {
Vector3 cls = cachedTransform.localScale; Vector3 cls = thisTransform.localScale;
bone.scaleX = Mathf.Lerp(bone.scaleX, cls.x, overrideAlpha); bone.scaleX = Mathf.Lerp(bone.scaleX, cls.x, overrideAlpha);
bone.scaleY = Mathf.Lerp(bone.scaleY, cls.y, overrideAlpha); bone.scaleY = Mathf.Lerp(bone.scaleY, cls.y, overrideAlpha);
} }
@ -161,19 +193,19 @@ namespace Spine.Unity {
return; return;
if (position) { if (position) {
Vector3 pos = parentReference.InverseTransformPoint(cachedTransform.position); Vector3 pos = parentReference.InverseTransformPoint(thisTransform.position);
bone.x = Mathf.Lerp(bone.x, pos.x, overrideAlpha); bone.x = Mathf.Lerp(bone.x, pos.x, overrideAlpha);
bone.y = Mathf.Lerp(bone.y, pos.y, overrideAlpha); bone.y = Mathf.Lerp(bone.y, pos.y, overrideAlpha);
} }
if (rotation) { if (rotation) {
float angle = Mathf.LerpAngle(bone.Rotation, Quaternion.LookRotation(Vector3.forward, parentReference.InverseTransformDirection(cachedTransform.up)).eulerAngles.z, overrideAlpha); float angle = Mathf.LerpAngle(bone.Rotation, Quaternion.LookRotation(Vector3.forward, parentReference.InverseTransformDirection(thisTransform.up)).eulerAngles.z, overrideAlpha);
bone.Rotation = angle; bone.Rotation = angle;
bone.AppliedRotation = angle; bone.AppliedRotation = angle;
} }
if (scale) { if (scale) {
Vector3 cls = cachedTransform.localScale; Vector3 cls = thisTransform.localScale;
bone.scaleX = Mathf.Lerp(bone.scaleX, cls.x, overrideAlpha); bone.scaleX = Mathf.Lerp(bone.scaleX, cls.x, overrideAlpha);
bone.scaleY = Mathf.Lerp(bone.scaleY, cls.y, overrideAlpha); bone.scaleY = Mathf.Lerp(bone.scaleY, cls.y, overrideAlpha);
} }