mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[cpp] Removed VertexEffect, see #2076
This commit is contained in:
parent
9762da09cd
commit
53f69d0f48
@ -1,120 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* Spine Runtimes License Agreement
|
|
||||||
* Last updated September 24, 2021. Replaces all prior versions.
|
|
||||||
*
|
|
||||||
* Copyright (c) 2013-2021, 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.
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef Spine_VertexEffect_h
|
|
||||||
#define Spine_VertexEffect_h
|
|
||||||
|
|
||||||
#include <spine/SpineObject.h>
|
|
||||||
#include <spine/MathUtil.h>
|
|
||||||
|
|
||||||
namespace spine {
|
|
||||||
|
|
||||||
class Skeleton;
|
|
||||||
|
|
||||||
class Color;
|
|
||||||
|
|
||||||
class SP_API VertexEffect : public SpineObject {
|
|
||||||
public:
|
|
||||||
virtual void begin(Skeleton &skeleton) = 0;
|
|
||||||
|
|
||||||
virtual void transform(float &x, float &y, float &u, float &v, Color &light, Color &dark) = 0;
|
|
||||||
|
|
||||||
virtual void end() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class SP_API JitterVertexEffect : public VertexEffect {
|
|
||||||
public:
|
|
||||||
JitterVertexEffect(float jitterX, float jitterY);
|
|
||||||
|
|
||||||
void begin(Skeleton &skeleton);
|
|
||||||
|
|
||||||
void transform(float &x, float &y, float &u, float &v, Color &light, Color &dark);
|
|
||||||
|
|
||||||
void end();
|
|
||||||
|
|
||||||
void setJitterX(float jitterX);
|
|
||||||
|
|
||||||
float getJitterX();
|
|
||||||
|
|
||||||
void setJitterY(float jitterY);
|
|
||||||
|
|
||||||
float getJitterY();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
float _jitterX;
|
|
||||||
float _jitterY;
|
|
||||||
};
|
|
||||||
|
|
||||||
class SP_API SwirlVertexEffect : public VertexEffect {
|
|
||||||
public:
|
|
||||||
SwirlVertexEffect(float radius, Interpolation &interpolation);
|
|
||||||
|
|
||||||
void begin(Skeleton &skeleton);
|
|
||||||
|
|
||||||
void transform(float &x, float &y, float &u, float &v, Color &light, Color &dark);
|
|
||||||
|
|
||||||
void end();
|
|
||||||
|
|
||||||
void setCenterX(float centerX);
|
|
||||||
|
|
||||||
float getCenterX();
|
|
||||||
|
|
||||||
void setCenterY(float centerY);
|
|
||||||
|
|
||||||
float getCenterY();
|
|
||||||
|
|
||||||
void setRadius(float radius);
|
|
||||||
|
|
||||||
float getRadius();
|
|
||||||
|
|
||||||
void setAngle(float angle);
|
|
||||||
|
|
||||||
float getAngle();
|
|
||||||
|
|
||||||
void setWorldX(float worldX);
|
|
||||||
|
|
||||||
float getWorldX();
|
|
||||||
|
|
||||||
void setWorldY(float worldY);
|
|
||||||
|
|
||||||
float getWorldY();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
float _centerX;
|
|
||||||
float _centerY;
|
|
||||||
float _radius;
|
|
||||||
float _angle;
|
|
||||||
float _worldX;
|
|
||||||
float _worldY;
|
|
||||||
|
|
||||||
Interpolation &_interpolation;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* Spine_VertexEffect_h */
|
|
||||||
@ -105,7 +105,6 @@
|
|||||||
#include <spine/Updatable.h>
|
#include <spine/Updatable.h>
|
||||||
#include <spine/Vector.h>
|
#include <spine/Vector.h>
|
||||||
#include <spine/VertexAttachment.h>
|
#include <spine/VertexAttachment.h>
|
||||||
#include <spine/VertexEffect.h>
|
|
||||||
#include <spine/Vertices.h>
|
#include <spine/Vertices.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -1,153 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* Spine Runtimes License Agreement
|
|
||||||
* Last updated September 24, 2021. Replaces all prior versions.
|
|
||||||
*
|
|
||||||
* Copyright (c) 2013-2021, Esoteric Software LLC
|
|
||||||
*
|
|
||||||
* Integration of the Spine Runtimes into software or otherwise creating
|
|
||||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
|
||||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
|
||||||
* http://esotericsoftware.com/spine-editor-license
|
|
||||||
*
|
|
||||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
|
||||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
|
||||||
* "Products"), provided that each user of the Products must obtain their own
|
|
||||||
* Spine Editor license and redistribution of the Products in any form must
|
|
||||||
* include this license and copyright notice.
|
|
||||||
*
|
|
||||||
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
|
|
||||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
|
|
||||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
|
|
||||||
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
|
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
||||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
#include <spine/VertexEffect.h>
|
|
||||||
#include <spine/MathUtil.h>
|
|
||||||
#include <spine/Skeleton.h>
|
|
||||||
|
|
||||||
using namespace spine;
|
|
||||||
|
|
||||||
JitterVertexEffect::JitterVertexEffect(float jitterX, float jitterY) : _jitterX(jitterX), _jitterY(jitterY) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void JitterVertexEffect::begin(Skeleton &skeleton) {
|
|
||||||
SP_UNUSED(skeleton);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JitterVertexEffect::transform(float &x, float &y, float &u, float &v, Color &light, Color &dark) {
|
|
||||||
SP_UNUSED(u);
|
|
||||||
SP_UNUSED(v);
|
|
||||||
SP_UNUSED(light);
|
|
||||||
SP_UNUSED(dark);
|
|
||||||
float jitterX = _jitterX;
|
|
||||||
float jitterY = _jitterY;
|
|
||||||
x += MathUtil::randomTriangular(-jitterX, jitterX);
|
|
||||||
y += MathUtil::randomTriangular(-jitterX, jitterY);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JitterVertexEffect::end() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void JitterVertexEffect::setJitterX(float jitterX) {
|
|
||||||
_jitterX = jitterX;
|
|
||||||
}
|
|
||||||
|
|
||||||
float JitterVertexEffect::getJitterX() {
|
|
||||||
return _jitterX;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JitterVertexEffect::setJitterY(float jitterY) {
|
|
||||||
_jitterY = jitterY;
|
|
||||||
}
|
|
||||||
|
|
||||||
float JitterVertexEffect::getJitterY() {
|
|
||||||
return _jitterY;
|
|
||||||
}
|
|
||||||
|
|
||||||
SwirlVertexEffect::SwirlVertexEffect(float radius, Interpolation &interpolation) : _centerX(0),
|
|
||||||
_centerY(0),
|
|
||||||
_radius(radius),
|
|
||||||
_angle(0),
|
|
||||||
_worldX(0),
|
|
||||||
_worldY(0),
|
|
||||||
_interpolation(interpolation) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void SwirlVertexEffect::begin(Skeleton &skeleton) {
|
|
||||||
_worldX = skeleton.getX() + _centerX;
|
|
||||||
_worldY = skeleton.getY() + _centerY;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SwirlVertexEffect::transform(float &positionX, float &positionY, float &u, float &v, Color &light, Color &dark) {
|
|
||||||
SP_UNUSED(u);
|
|
||||||
SP_UNUSED(v);
|
|
||||||
SP_UNUSED(light);
|
|
||||||
SP_UNUSED(dark);
|
|
||||||
|
|
||||||
float x = positionX - _worldX;
|
|
||||||
float y = positionY - _worldY;
|
|
||||||
float dist = (float) MathUtil::sqrt(x * x + y * y);
|
|
||||||
if (dist < _radius) {
|
|
||||||
float theta = _interpolation.interpolate(0, _angle, (_radius - dist) / _radius);
|
|
||||||
float cos = MathUtil::cos(theta), sin = MathUtil::sin(theta);
|
|
||||||
positionX = cos * x - sin * y + _worldX;
|
|
||||||
positionY = sin * x + cos * y + _worldY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SwirlVertexEffect::end() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void SwirlVertexEffect::setCenterX(float centerX) {
|
|
||||||
_centerX = centerX;
|
|
||||||
}
|
|
||||||
|
|
||||||
float SwirlVertexEffect::getCenterX() {
|
|
||||||
return _centerX;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SwirlVertexEffect::setCenterY(float centerY) {
|
|
||||||
_centerY = centerY;
|
|
||||||
}
|
|
||||||
|
|
||||||
float SwirlVertexEffect::getCenterY() {
|
|
||||||
return _centerY;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SwirlVertexEffect::setRadius(float radius) {
|
|
||||||
_radius = radius;
|
|
||||||
}
|
|
||||||
|
|
||||||
float SwirlVertexEffect::getRadius() {
|
|
||||||
return _radius;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SwirlVertexEffect::setAngle(float angle) {
|
|
||||||
_angle = angle * MathUtil::Deg_Rad;
|
|
||||||
}
|
|
||||||
|
|
||||||
float SwirlVertexEffect::getAngle() {
|
|
||||||
return _angle;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SwirlVertexEffect::setWorldX(float worldX) {
|
|
||||||
_worldX = worldX;
|
|
||||||
}
|
|
||||||
|
|
||||||
float SwirlVertexEffect::getWorldX() {
|
|
||||||
return _worldX;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SwirlVertexEffect::setWorldY(float worldY) {
|
|
||||||
_worldY = worldY;
|
|
||||||
}
|
|
||||||
|
|
||||||
float SwirlVertexEffect::getWorldY() {
|
|
||||||
return _worldY;
|
|
||||||
}
|
|
||||||
@ -278,9 +278,6 @@ void raptor(SkeletonData *skeletonData, Atlas *atlas) {
|
|||||||
|
|
||||||
PowInterpolation pow2(2);
|
PowInterpolation pow2(2);
|
||||||
PowOutInterpolation powOut2(2);
|
PowOutInterpolation powOut2(2);
|
||||||
SwirlVertexEffect effect(400, powOut2);
|
|
||||||
effect.setCenterY(-200);
|
|
||||||
drawable.vertexEffect = &effect;
|
|
||||||
|
|
||||||
Skeleton *skeleton = drawable.skeleton;
|
Skeleton *skeleton = drawable.skeleton;
|
||||||
skeleton->setPosition(320, 590);
|
skeleton->setPosition(320, 590);
|
||||||
@ -293,7 +290,6 @@ void raptor(SkeletonData *skeletonData, Atlas *atlas) {
|
|||||||
window.setFramerateLimit(60);
|
window.setFramerateLimit(60);
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
sf::Clock deltaClock;
|
sf::Clock deltaClock;
|
||||||
float swirlTime = 0;
|
|
||||||
while (window.isOpen()) {
|
while (window.isOpen()) {
|
||||||
while (window.pollEvent(event))
|
while (window.pollEvent(event))
|
||||||
if (event.type == sf::Event::Closed) window.close();
|
if (event.type == sf::Event::Closed) window.close();
|
||||||
@ -301,11 +297,6 @@ void raptor(SkeletonData *skeletonData, Atlas *atlas) {
|
|||||||
float delta = deltaClock.getElapsedTime().asSeconds();
|
float delta = deltaClock.getElapsedTime().asSeconds();
|
||||||
deltaClock.restart();
|
deltaClock.restart();
|
||||||
|
|
||||||
swirlTime += delta;
|
|
||||||
float percent = MathUtil::fmod(swirlTime, 2);
|
|
||||||
if (percent > 1) percent = 1 - (percent - 1);
|
|
||||||
effect.setAngle(pow2.interpolate(-60.0f, 60.0f, percent));
|
|
||||||
|
|
||||||
drawable.update(delta);
|
drawable.update(delta);
|
||||||
|
|
||||||
window.clear();
|
window.clear();
|
||||||
|
|||||||
@ -49,7 +49,7 @@ namespace spine {
|
|||||||
|
|
||||||
SkeletonDrawable::SkeletonDrawable(SkeletonData *skeletonData, AnimationStateData *stateData) : timeScale(1),
|
SkeletonDrawable::SkeletonDrawable(SkeletonData *skeletonData, AnimationStateData *stateData) : timeScale(1),
|
||||||
vertexArray(new VertexArray(Triangles, skeletonData->getBones().size() * 4)),
|
vertexArray(new VertexArray(Triangles, skeletonData->getBones().size() * 4)),
|
||||||
vertexEffect(NULL), worldVertices(), clipper() {
|
worldVertices(), clipper() {
|
||||||
Bone::setYDown(true);
|
Bone::setYDown(true);
|
||||||
worldVertices.ensureCapacity(SPINE_MESH_VERTEX_COUNT_MAX);
|
worldVertices.ensureCapacity(SPINE_MESH_VERTEX_COUNT_MAX);
|
||||||
skeleton = new (__FILE__, __LINE__) Skeleton(skeletonData);
|
skeleton = new (__FILE__, __LINE__) Skeleton(skeletonData);
|
||||||
@ -89,8 +89,6 @@ namespace spine {
|
|||||||
// Early out if skeleton is invisible
|
// Early out if skeleton is invisible
|
||||||
if (skeleton->getColor().a == 0) return;
|
if (skeleton->getColor().a == 0) return;
|
||||||
|
|
||||||
if (vertexEffect != NULL) vertexEffect->begin(*skeleton);
|
|
||||||
|
|
||||||
sf::Vertex vertex;
|
sf::Vertex vertex;
|
||||||
Texture *texture = NULL;
|
Texture *texture = NULL;
|
||||||
for (unsigned i = 0; i < skeleton->getSlots().size(); ++i) {
|
for (unsigned i = 0; i < skeleton->getSlots().size(); ++i) {
|
||||||
@ -226,55 +224,18 @@ namespace spine {
|
|||||||
|
|
||||||
Vector2u size = texture->getSize();
|
Vector2u size = texture->getSize();
|
||||||
|
|
||||||
if (vertexEffect != 0) {
|
for (int ii = 0; ii < indicesCount; ++ii) {
|
||||||
tempUvs.clear();
|
int index = (*indices)[ii] << 1;
|
||||||
tempColors.clear();
|
vertex.position.x = (*vertices)[index];
|
||||||
for (int ii = 0; ii < verticesCount; ii++) {
|
vertex.position.y = (*vertices)[index + 1];
|
||||||
Color vertexColor = light;
|
vertex.texCoords.x = (*uvs)[index] * size.x;
|
||||||
Color dark;
|
vertex.texCoords.y = (*uvs)[index + 1] * size.y;
|
||||||
dark.r = dark.g = dark.b = dark.a = 0;
|
vertexArray->append(vertex);
|
||||||
int index = ii << 1;
|
|
||||||
float x = (*vertices)[index];
|
|
||||||
float y = (*vertices)[index + 1];
|
|
||||||
float u = (*uvs)[index];
|
|
||||||
float v = (*uvs)[index + 1];
|
|
||||||
vertexEffect->transform(x, y, u, v, vertexColor, dark);
|
|
||||||
(*vertices)[index] = x;
|
|
||||||
(*vertices)[index + 1] = y;
|
|
||||||
tempUvs.add(u);
|
|
||||||
tempUvs.add(v);
|
|
||||||
tempColors.add(vertexColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int ii = 0; ii < indicesCount; ++ii) {
|
|
||||||
int index = (*indices)[ii] << 1;
|
|
||||||
vertex.position.x = (*vertices)[index];
|
|
||||||
vertex.position.y = (*vertices)[index + 1];
|
|
||||||
vertex.texCoords.x = (*uvs)[index] * size.x;
|
|
||||||
vertex.texCoords.y = (*uvs)[index + 1] * size.y;
|
|
||||||
Color vertexColor = tempColors[index >> 1];
|
|
||||||
vertex.color.r = static_cast<Uint8>(vertexColor.r * 255);
|
|
||||||
vertex.color.g = static_cast<Uint8>(vertexColor.g * 255);
|
|
||||||
vertex.color.b = static_cast<Uint8>(vertexColor.b * 255);
|
|
||||||
vertex.color.a = static_cast<Uint8>(vertexColor.a * 255);
|
|
||||||
vertexArray->append(vertex);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (int ii = 0; ii < indicesCount; ++ii) {
|
|
||||||
int index = (*indices)[ii] << 1;
|
|
||||||
vertex.position.x = (*vertices)[index];
|
|
||||||
vertex.position.y = (*vertices)[index + 1];
|
|
||||||
vertex.texCoords.x = (*uvs)[index] * size.x;
|
|
||||||
vertex.texCoords.y = (*uvs)[index + 1] * size.y;
|
|
||||||
vertexArray->append(vertex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
clipper.clipEnd(slot);
|
clipper.clipEnd(slot);
|
||||||
}
|
}
|
||||||
target.draw(*vertexArray, states);
|
target.draw(*vertexArray, states);
|
||||||
clipper.clipEnd();
|
clipper.clipEnd();
|
||||||
|
|
||||||
if (vertexEffect != 0) vertexEffect->end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SFMLTextureLoader::load(AtlasPage &page, const String &path) {
|
void SFMLTextureLoader::load(AtlasPage &page, const String &path) {
|
||||||
|
|||||||
@ -46,10 +46,10 @@ namespace spine {
|
|||||||
AnimationState *state;
|
AnimationState *state;
|
||||||
float timeScale;
|
float timeScale;
|
||||||
sf::VertexArray *vertexArray;
|
sf::VertexArray *vertexArray;
|
||||||
VertexEffect *vertexEffect;
|
|
||||||
|
|
||||||
SkeletonDrawable(SkeletonData *skeleton, AnimationStateData *stateData = 0);
|
SkeletonDrawable(SkeletonData *skeleton, AnimationStateData *stateData = 0);
|
||||||
|
|
||||||
|
|
||||||
~SkeletonDrawable();
|
~SkeletonDrawable();
|
||||||
|
|
||||||
void update(float deltaTime);
|
void update(float deltaTime);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user