mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 14:24:53 +08:00
[starling] two color tint baby steps
This commit is contained in:
parent
aeff32bf58
commit
8eba84856e
@ -60,12 +60,16 @@ public class SkeletonSprite extends DisplayObject {
|
||||
|
||||
private var _skeleton:Skeleton;
|
||||
public var batchable:Boolean = true;
|
||||
private var _smoothing:String = "bilinear";
|
||||
private var _smoothing:String = "bilinear";
|
||||
private static var _twoColorStyle:TwoColorMeshStyle;
|
||||
|
||||
public function SkeletonSprite (skeletonData:SkeletonData) {
|
||||
Bone.yDown = true;
|
||||
_skeleton = new Skeleton(skeletonData);
|
||||
_skeleton.updateWorldTransform();
|
||||
if (_twoColorStyle == null) {
|
||||
_twoColorStyle = new TwoColorMeshStyle();
|
||||
}
|
||||
}
|
||||
|
||||
override public function render (painter:Painter) : void {
|
||||
@ -78,10 +82,11 @@ public class SkeletonSprite extends DisplayObject {
|
||||
var worldVertices:Vector.<Number> = _tempVertices;
|
||||
var ii:int, iii:int;
|
||||
var rgb:uint, a:Number;
|
||||
var dark:uint;
|
||||
var mesh:SkeletonMesh;
|
||||
var verticesLength:int, verticesCount:int, indicesLength:int;
|
||||
var indexData:IndexData, indices:Vector.<uint>, vertexData:VertexData;
|
||||
var uvs: Vector.<Number>;
|
||||
var uvs: Vector.<Number>;
|
||||
|
||||
for (var i:int = 0, n:int = drawOrder.length; i < n; ++i) {
|
||||
var slot:Slot = drawOrder[i];
|
||||
@ -94,19 +99,23 @@ public class SkeletonSprite extends DisplayObject {
|
||||
g * slot.color.g * region.color.g,
|
||||
b * slot.color.b * region.color.b);
|
||||
|
||||
var image:Image = region.rendererObject as Image;
|
||||
var image:Image = region.rendererObject as Image;
|
||||
if (image == null) {
|
||||
var origImage:Image = Image(AtlasRegion(region.rendererObject).rendererObject);
|
||||
var origImage:Image = Image(AtlasRegion(region.rendererObject).rendererObject);
|
||||
region.rendererObject = image = new Image(origImage.texture);
|
||||
image.style = _twoColorStyle;
|
||||
for (var j:int = 0; j < 4; j++) {
|
||||
var p: Point = origImage.getTexCoords(j);
|
||||
image.setTexCoords(j, p.x, p.y);
|
||||
}
|
||||
}
|
||||
|
||||
if (slot.darkColor == null) dark = Color.rgb(0, 0, 0);
|
||||
else dark = Color.rgb(slot.darkColor.r * 255, slot.darkColor.g * 255, slot.darkColor.b * 255);
|
||||
|
||||
image.setVertexPosition(0, worldVertices[2], worldVertices[3]);
|
||||
image.setVertexColor(0, rgb);
|
||||
image.setVertexAlpha(0, a);
|
||||
image.setVertexAlpha(0, a);
|
||||
|
||||
image.setVertexPosition(1, worldVertices[4], worldVertices[5]);
|
||||
image.setVertexColor(1, rgb);
|
||||
@ -135,7 +144,7 @@ public class SkeletonSprite extends DisplayObject {
|
||||
if (meshAttachment.rendererObject is Image)
|
||||
meshAttachment.rendererObject = mesh = new SkeletonMesh(Image(meshAttachment.rendererObject).texture);
|
||||
if (meshAttachment.rendererObject is AtlasRegion)
|
||||
meshAttachment.rendererObject = mesh = new SkeletonMesh(Image(AtlasRegion(meshAttachment.rendererObject).rendererObject).texture);
|
||||
meshAttachment.rendererObject = mesh = new SkeletonMesh(Image(AtlasRegion(meshAttachment.rendererObject).rendererObject).texture);
|
||||
}
|
||||
|
||||
if (mesh.numIndices != meshAttachment.triangles.length) {
|
||||
@ -155,13 +164,19 @@ public class SkeletonSprite extends DisplayObject {
|
||||
r * slot.color.r * meshAttachment.color.r,
|
||||
g * slot.color.g * meshAttachment.color.g,
|
||||
b * slot.color.b * meshAttachment.color.b);
|
||||
|
||||
if (slot.darkColor == null) dark = Color.rgb(0, 0, 0);
|
||||
else dark = Color.rgb(slot.darkColor.r * 255, slot.darkColor.g * 255, slot.darkColor.b * 255);
|
||||
|
||||
if (mesh.style.vertexFormat != _twoColorStyle.vertexFormat)
|
||||
mesh.style = _twoColorStyle;
|
||||
vertexData = mesh.getVertexData();
|
||||
uvs = meshAttachment.uvs;
|
||||
vertexData.colorize("color", rgb, a);
|
||||
uvs = meshAttachment.uvs;
|
||||
vertexData.colorize("color", rgb, a);
|
||||
vertexData.colorize("color2", dark);
|
||||
for (ii = 0, iii = 0; ii < verticesCount; ii++, iii+=2) {
|
||||
mesh.setVertexPosition(ii, worldVertices[iii], worldVertices[iii+1]);
|
||||
mesh.setTexCoords(ii, uvs[iii], uvs[iii+1]);
|
||||
mesh.setTexCoords(ii, uvs[iii], uvs[iii+1]);
|
||||
}
|
||||
vertexData.numVertices = verticesCount;
|
||||
painter.state.blendMode = blendModes[slot.data.blendMode.ordinal];
|
||||
|
||||
@ -0,0 +1,73 @@
|
||||
/******************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
package spine.starling {
|
||||
import starling.rendering.Program;
|
||||
import flash.display3D.Context3D;
|
||||
import starling.rendering.VertexDataFormat;
|
||||
import starling.rendering.MeshEffect;
|
||||
|
||||
public class TwoColorEffect extends MeshEffect {
|
||||
public static const VERTEX_FORMAT:VertexDataFormat = TwoColorMeshStyle.VERTEX_FORMAT;
|
||||
|
||||
override protected function createProgram():Program {
|
||||
var vertexShader:String = [
|
||||
"m44 op, va0, vc0", // 4x4 matrix transform to output clip-space
|
||||
"mov v0, va1 ", // pass texture coordinates to fragment program
|
||||
"mul v1, va2, vc4", // multiply alpha (vc4) with color (va2), pass to fp
|
||||
"mov v2, va3 " // pass offset to fp
|
||||
].join("\n");
|
||||
|
||||
var fragmentShader:String = [
|
||||
tex("ft0", "v0", 0, texture) + // get color from texture
|
||||
"mul ft0, ft0, v1", // multiply color with texel color
|
||||
"mov ft1, v2", // copy complete offset to ft1
|
||||
"mul ft1.xyz, v2.xyz, ft0.www", // multiply offset.rgb with alpha (pma!)
|
||||
"add oc, ft0, ft1" // add offset, copy to output
|
||||
].join("\n");
|
||||
|
||||
return Program.fromSource(vertexShader, fragmentShader);
|
||||
}
|
||||
|
||||
override public function get vertexFormat():VertexDataFormat {
|
||||
return VERTEX_FORMAT;
|
||||
}
|
||||
|
||||
override protected function beforeDraw(context:Context3D):void {
|
||||
super.beforeDraw(context);
|
||||
vertexFormat.setVertexBufferAt(3, vertexBuffer, "color2");
|
||||
}
|
||||
|
||||
override protected function afterDraw(context:Context3D):void {
|
||||
context.setVertexBufferAt(3, null);
|
||||
super.afterDraw(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
/******************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
package spine.starling {
|
||||
import starling.rendering.MeshEffect;
|
||||
import starling.rendering.VertexDataFormat;
|
||||
import starling.styles.MeshStyle;
|
||||
|
||||
public class TwoColorMeshStyle extends MeshStyle {
|
||||
public static const VERTEX_FORMAT:VertexDataFormat = MeshStyle.VERTEX_FORMAT.extend("color2:bytes4");
|
||||
|
||||
override public function get vertexFormat():VertexDataFormat {
|
||||
return VERTEX_FORMAT;
|
||||
}
|
||||
|
||||
override public function createEffect():MeshEffect {
|
||||
return new TwoColorEffect();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user