mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 23:34:53 +08:00
[as3][starling] Added default constructors to base classes. Changed project settings to use Air 22. Updated Starling runtime to Starling 2.0, removing PolygonBatch etc. Smoothing and pre-multiplied alpha support currently missing.
This commit is contained in:
parent
413bda2de6
commit
3de5fe4ea3
@ -13,7 +13,7 @@
|
||||
<booleanAttribute key="FORCE_FRESH_COMPILATION" value="false"/>
|
||||
<booleanAttribute key="KILL_PREVIOUS_VIEWER" value="true"/>
|
||||
<stringAttribute key="LAUNCHER_DEPENDENCIES" value="[Self]"/>
|
||||
<stringAttribute key="MAIN_CLASS" value="src/spine/Main.as"/>
|
||||
<stringAttribute key="MAIN_CLASS" value="src/spine/examples/Main.as"/>
|
||||
<stringAttribute key="MOBILE_PRESET" value=""/>
|
||||
<booleanAttribute key="NEW_WINDOW_EACH_LAUNCH" value="false"/>
|
||||
<stringAttribute key="OUTPUT" value="bin/spine-as3-example.swf"/>
|
||||
|
||||
Binary file not shown.
@ -29,10 +29,11 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
package spine {
|
||||
package spine.examples {
|
||||
|
||||
import flash.display.Sprite;
|
||||
|
||||
import spine.*;
|
||||
import spine.animation.AnimationStateData;
|
||||
import spine.atlas.Atlas;
|
||||
import spine.attachments.AtlasAttachmentLoader;
|
||||
@ -1,5 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="true" type="lib" useAsSharedCode="false">frameworks/libs/player/{playerVersion}/playerglobal.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="false" type="source" useAsSharedCode="false">src</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="true" type="lib" useAsSharedCode="false">frameworks/libs/player/{playerVersion}/playerglobal.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="true" type="lib" useAsSharedCode="false">frameworks/libs/textLayout.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="true" type="lib" useAsSharedCode="false">frameworks/libs/osmf.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="true" type="lib" useAsSharedCode="false">frameworks/libs/authoringsupport.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="true" type="lib" useAsSharedCode="false">frameworks/libs/core.swc</AS3Classpath>
|
||||
</AS3Classpath>
|
||||
|
||||
13
spine-as3/spine-as3/.settings/com.powerflasher.fdt.exclude
Normal file
13
spine-as3/spine-as3/.settings/com.powerflasher.fdt.exclude
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<exclude>
|
||||
<resource>frameworks/libs/air/aircore.swc</resource>
|
||||
<resource>frameworks/libs/air/airglobal.swc</resource>
|
||||
<resource>frameworks/libs/air/applicationupdater.swc</resource>
|
||||
<resource>frameworks/libs/air/applicationupdater_ui.swc</resource>
|
||||
<resource>frameworks/libs/air/servicemonitor.swc</resource>
|
||||
<resource>frameworks/libs/authoringsupport.swc</resource>
|
||||
<resource>frameworks/libs/core.swc</resource>
|
||||
<resource>frameworks/libs/osmf.swc</resource>
|
||||
<resource>frameworks/libs/textLayout.swc</resource>
|
||||
</exclude>
|
||||
|
||||
@ -34,6 +34,9 @@ package spine {
|
||||
public class Polygon {
|
||||
public var vertices:Vector.<Number> = new Vector.<Number>();
|
||||
|
||||
public function Polygon () {
|
||||
}
|
||||
|
||||
/** Returns true if the polygon contains the point. */
|
||||
public function containsPoint (x:Number, y:Number) : Boolean {
|
||||
var nn:int = vertices.length;
|
||||
|
||||
@ -38,6 +38,9 @@ public class SkeletonBounds {
|
||||
public var boundingBoxes:Vector.<BoundingBoxAttachment> = new Vector.<BoundingBoxAttachment>();
|
||||
public var polygons:Vector.<Polygon> = new Vector.<Polygon>();
|
||||
public var minX:Number, minY:Number, maxX:Number, maxY:Number;
|
||||
|
||||
public function SkeletonBounds () {
|
||||
}
|
||||
|
||||
public function update (skeleton:Skeleton, updateAabb:Boolean) : void {
|
||||
var slots:Vector.<Slot> = skeleton.slots;
|
||||
|
||||
@ -45,6 +45,9 @@ public class SkeletonData {
|
||||
public var transformConstraints:Vector.<TransformConstraintData> = new Vector.<TransformConstraintData>();
|
||||
public var width:Number, height:Number;
|
||||
public var version:String, hash:String;
|
||||
|
||||
public function SkeletonData () {
|
||||
}
|
||||
|
||||
// --- Bones.
|
||||
|
||||
|
||||
@ -33,6 +33,9 @@ package spine.animation {
|
||||
public class Listeners {
|
||||
private var _listeners:Vector.<Function> = new Vector.<Function>();
|
||||
|
||||
public function Listeners () {
|
||||
}
|
||||
|
||||
public function get listeners () : Vector.<Function> {
|
||||
return _listeners;
|
||||
}
|
||||
|
||||
@ -40,6 +40,9 @@ public class TrackEntry {
|
||||
internal var mixTime:Number, mixDuration:Number, mix:Number = 1;
|
||||
public var onStart:Function, onEnd:Function, onComplete:Function, onEvent:Function;
|
||||
|
||||
public function TrackEntry () {
|
||||
}
|
||||
|
||||
public function toString () : String {
|
||||
return animation == null ? "<none>" : animation.name;
|
||||
}
|
||||
|
||||
@ -41,6 +41,9 @@ public class AtlasPage {
|
||||
public var rendererObject:Object;
|
||||
public var width:int;
|
||||
public var height:int;
|
||||
|
||||
public function AtlasPage () {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -51,6 +51,9 @@ public class AtlasRegion {
|
||||
public var splits:Vector.<int>;
|
||||
public var pads:Vector.<int>;
|
||||
public var rendererObject:Object;
|
||||
|
||||
public function AtlasRegion () {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
<AS3LibraryFolder>lib</AS3LibraryFolder>
|
||||
<AS3Classpath generateProblems="true" sdkBased="true" type="lib" useAsSharedCode="false">frameworks/libs/player/{playerVersion}/playerglobal.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="false" type="source" useAsSharedCode="false">src</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="false" type="lib" useAsSharedCode="false">lib/spine-starling.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="false" type="lib" useAsSharedCode="false">lib/starling-2.0.1.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="false" type="lib" useAsSharedCode="false">lib/spine-as3.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="false" type="lib" useAsSharedCode="false">lib/starling-1.7.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="false" type="lib" useAsSharedCode="false">lib/spine-starling.swc</AS3Classpath>
|
||||
</AS3Classpath>
|
||||
|
||||
@ -0,0 +1,2 @@
|
||||
//lib/starling-2.0.1.swc=/Applications/flash/starling/src
|
||||
eclipse.preferences.version=1
|
||||
@ -8,12 +8,15 @@
|
||||
<stringAttribute key="APP_ARGUMENTS" value=""/>
|
||||
<stringAttribute key="ARGUMENTS" value="-static-link-runtime-shared-libraries=true -target-player={playerVersion} -library-path+="{flexSDK}/frameworks/locale/en_US" -default-size=550,400"/>
|
||||
<listAttribute key="COMPILER_CONSTANTS"/>
|
||||
<stringAttribute key="COMPILER_TECHNOLOGY" value="Flex SDK"/>
|
||||
<stringAttribute key="COMPILER_TECHNOLOGY" value="ASC"/>
|
||||
<booleanAttribute key="DISABLE_COMPILE_PROCESS" value="false"/>
|
||||
<booleanAttribute key="FORCE_FRESH_COMPILATION" value="false"/>
|
||||
<booleanAttribute key="FORCE_INCLUDE_TEST_RESOURCES" value="false"/>
|
||||
<booleanAttribute key="IGNORE_SWF_LOCATION_PROBLEM" value="false"/>
|
||||
<booleanAttribute key="INCLUDE_TEST_RESOURCES" value="false"/>
|
||||
<booleanAttribute key="KILL_PREVIOUS_VIEWER" value="true"/>
|
||||
<stringAttribute key="LAUNCHER_DEPENDENCIES" value="[Self]"/>
|
||||
<stringAttribute key="MAIN_CLASS" value="src/spine/Main.as"/>
|
||||
<stringAttribute key="MAIN_CLASS" value="src/spine/examples/Main.as"/>
|
||||
<stringAttribute key="MOBILE_PRESET" value=""/>
|
||||
<booleanAttribute key="NEW_WINDOW_EACH_LAUNCH" value="false"/>
|
||||
<stringAttribute key="OUTPUT" value="bin/spine-starling-example.swf"/>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
spine-starling/spine-starling-example/lib/starling-2.0.1.swc
Normal file
BIN
spine-starling/spine-starling-example/lib/starling-2.0.1.swc
Normal file
Binary file not shown.
@ -29,8 +29,8 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
package spine {
|
||||
|
||||
package spine.examples {
|
||||
import spine.*;
|
||||
import spine.atlas.Atlas;
|
||||
import spine.attachments.AtlasAttachmentLoader;
|
||||
import spine.attachments.AttachmentLoader;
|
||||
@ -81,7 +81,7 @@ public class GoblinsExample extends Sprite {
|
||||
var json:SkeletonJson = new SkeletonJson(attachmentLoader);
|
||||
var skeletonData:SkeletonData = json.readSkeletonData(new GoblinsJson());
|
||||
|
||||
skeleton = new SkeletonAnimation(skeletonData, true);
|
||||
skeleton = new SkeletonAnimation(skeletonData);
|
||||
skeleton.x = 320;
|
||||
skeleton.y = 420;
|
||||
skeleton.skeleton.skinName = "goblin";
|
||||
@ -29,7 +29,7 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
package spine {
|
||||
package spine.examples {
|
||||
|
||||
import flash.display.Sprite;
|
||||
|
||||
@ -41,13 +41,14 @@ public class Main extends Sprite {
|
||||
|
||||
public function Main () {
|
||||
var example:Class;
|
||||
//example = SpineboyExample;
|
||||
//example = GoblinsExample;
|
||||
// example = SpineboyExample;
|
||||
// example = GoblinsExample;
|
||||
example = RaptorExample;
|
||||
|
||||
_starling = new Starling(example, stage);
|
||||
_starling.enableErrorChecking = true;
|
||||
_starling.showStats = true;
|
||||
_starling.skipUnchangedFrames = false;
|
||||
_starling.start();
|
||||
}
|
||||
}
|
||||
@ -29,8 +29,9 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
package spine {
|
||||
package spine.examples {
|
||||
import spine.atlas.Atlas;
|
||||
import spine.*;
|
||||
import spine.attachments.AtlasAttachmentLoader;
|
||||
import spine.attachments.AttachmentLoader;
|
||||
import spine.starling.SkeletonAnimation;
|
||||
@ -64,7 +65,7 @@ public class RaptorExample extends Sprite {
|
||||
json.scale = 0.5;
|
||||
var skeletonData:SkeletonData = json.readSkeletonData(new RaptorJson());
|
||||
|
||||
skeleton = new SkeletonAnimation(skeletonData, true);
|
||||
skeleton = new SkeletonAnimation(skeletonData);
|
||||
skeleton.x = 400;
|
||||
skeleton.y = 560;
|
||||
skeleton.state.setAnimationByName(0, "walk", true);
|
||||
@ -29,8 +29,9 @@
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
package spine {
|
||||
package spine.examples {
|
||||
import spine.animation.AnimationStateData;
|
||||
import spine.*;
|
||||
import spine.atlas.Atlas;
|
||||
import spine.attachments.AtlasAttachmentLoader;
|
||||
import spine.attachments.AttachmentLoader;
|
||||
@ -67,7 +68,7 @@ public class SpineboyExample extends Sprite {
|
||||
stateData.setMixByName("jump", "run", 0.4);
|
||||
stateData.setMixByName("jump", "jump", 0.2);
|
||||
|
||||
skeleton = new SkeletonAnimation(skeletonData, false, stateData);
|
||||
skeleton = new SkeletonAnimation(skeletonData, stateData);
|
||||
skeleton.x = 400;
|
||||
skeleton.y = 560;
|
||||
|
||||
@ -1,8 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<AS3Classpath>
|
||||
<AS3LibraryFolder>lib</AS3LibraryFolder>
|
||||
<AS3Classpath generateProblems="true" sdkBased="true" type="lib" useAsSharedCode="false">frameworks/libs/player/{playerVersion}/playerglobal.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="false" type="source" useAsSharedCode="false">src</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="false" type="lib" useAsSharedCode="false">lib/spine-as3.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="false" type="lib" useAsSharedCode="false">lib/starling-1.7.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="false" type="lib" useAsSharedCode="false">lib/starling-2.0.1.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="true" type="lib" useAsSharedCode="false">frameworks/libs/air/airglobal.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="true" type="lib" useAsSharedCode="false">frameworks/libs/textLayout.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="true" type="lib" useAsSharedCode="false">frameworks/libs/osmf.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="true" type="lib" useAsSharedCode="false">frameworks/libs/authoringsupport.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="true" type="lib" useAsSharedCode="false">frameworks/libs/core.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="true" type="lib" useAsSharedCode="false">frameworks/libs/air/aircore.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="true" type="lib" useAsSharedCode="false">frameworks/libs/air/applicationupdater.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="true" type="lib" useAsSharedCode="false">frameworks/libs/air/applicationupdater_ui.swc</AS3Classpath>
|
||||
<AS3Classpath generateProblems="true" sdkBased="true" type="lib" useAsSharedCode="false">frameworks/libs/air/servicemonitor.swc</AS3Classpath>
|
||||
</AS3Classpath>
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
com.powerflasher.fdt.core.CompatiblePlayers=External_SWF_Viewer\:Browser\:Standalone_Flash_Player
|
||||
com.powerflasher.fdt.core.CompatiblePlayers=AIR_Debug_Launcher
|
||||
com.powerflasher.fdt.core.CompilerArguments=-static-link-runtime-shared-libraries\=true\n-target-player\={playerVersion}\n-library-path+\="{flexSDK}/frameworks/locale/en_US"\n-default-size\=550,400
|
||||
com.powerflasher.fdt.core.CompilerConstants=CONFIG\:\:AUTHOR\!"{user.name}"\nCONFIG\:\:DEBUG\!{debug}
|
||||
com.powerflasher.fdt.core.DefaultOutputFolder=bin
|
||||
com.powerflasher.fdt.core.DefaultPlayer=External_SWF_Viewer
|
||||
com.powerflasher.fdt.core.DefaultPlayer=AIR_Debug_Launcher
|
||||
com.powerflasher.fdt.core.IncludeTestResources=false
|
||||
com.powerflasher.fdt.core.Language=AS3
|
||||
com.powerflasher.fdt.core.Manifests=
|
||||
@ -13,9 +13,9 @@ com.powerflasher.fdt.core.PassMainclass=true
|
||||
com.powerflasher.fdt.core.PassManifests=true
|
||||
com.powerflasher.fdt.core.PassRsls=false
|
||||
com.powerflasher.fdt.core.PassSwcs=true
|
||||
com.powerflasher.fdt.core.PlatformType=WEB
|
||||
com.powerflasher.fdt.core.PlatformType=AIR
|
||||
com.powerflasher.fdt.core.PlayerVersion=22.0
|
||||
com.powerflasher.fdt.core.ProjectTypeHint=Web
|
||||
com.powerflasher.fdt.core.Runtime=Flash_Player
|
||||
com.powerflasher.fdt.core.ProjectTypeHint=Library AIR
|
||||
com.powerflasher.fdt.core.Runtime=AIR
|
||||
com.powerflasher.fdt.core.SdkName=Flex 4.6.0
|
||||
eclipse.preferences.version=1
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<exclude>
|
||||
<resource>SDK:frameworks/libs/air/aircore.swc</resource>
|
||||
<resource>SDK:frameworks/libs/air/airglobal.swc</resource>
|
||||
<resource>SDK:frameworks/libs/air/applicationupdater.swc</resource>
|
||||
<resource>SDK:frameworks/libs/air/applicationupdater_ui.swc</resource>
|
||||
<resource>SDK:frameworks/libs/air/servicemonitor.swc</resource>
|
||||
<resource>SDK:frameworks/libs/authoringsupport.swc</resource>
|
||||
<resource>SDK:frameworks/libs/core.swc</resource>
|
||||
<resource>SDK:frameworks/libs/osmf.swc</resource>
|
||||
<resource>SDK:frameworks/libs/textLayout.swc</resource>
|
||||
<resource>frameworks/libs/air/aircore.swc</resource>
|
||||
<resource>frameworks/libs/air/airglobal.swc</resource>
|
||||
<resource>frameworks/libs/air/applicationupdater.swc</resource>
|
||||
<resource>frameworks/libs/air/applicationupdater_ui.swc</resource>
|
||||
<resource>frameworks/libs/air/servicemonitor.swc</resource>
|
||||
<resource>frameworks/libs/authoringsupport.swc</resource>
|
||||
<resource>frameworks/libs/core.swc</resource>
|
||||
<resource>frameworks/libs/osmf.swc</resource>
|
||||
<resource>frameworks/libs/textLayout.swc</resource>
|
||||
</exclude>
|
||||
|
||||
@ -1,2 +1,7 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/spine/starling/SkeletonAnimation.as=UTF-8
|
||||
encoding//src/spine/starling/SkeletonMesh.as=UTF-8
|
||||
encoding//src/spine/starling/SkeletonSprite.as=UTF-8
|
||||
encoding//src/spine/starling/StarlingAtlasAttachmentLoader.as=UTF-8
|
||||
encoding//src/spine/starling/StarlingTextureLoader.as=UTF-8
|
||||
encoding/<project>=UTF-8
|
||||
|
||||
Binary file not shown.
Binary file not shown.
BIN
spine-starling/spine-starling/lib/starling-2.0.1.swc
Normal file
BIN
spine-starling/spine-starling/lib/starling-2.0.1.swc
Normal file
Binary file not shown.
@ -1,289 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes Software License
|
||||
* Version 2.3
|
||||
*
|
||||
* Copyright (c) 2013-2015, 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 (the "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 otherwise create derivative works, improvements of the
|
||||
* Software or develop new applications using the Software 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; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) 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 spine.BlendMode;
|
||||
|
||||
import starling.core.RenderSupport;
|
||||
import starling.core.Starling;
|
||||
import starling.textures.Texture;
|
||||
import starling.textures.TextureSmoothing;
|
||||
import starling.utils.MatrixUtil;
|
||||
import starling.utils.VertexData;
|
||||
|
||||
import flash.display3D.Context3D;
|
||||
import flash.display3D.Context3DProgramType;
|
||||
import flash.display3D.Context3DTextureFormat;
|
||||
import flash.display3D.Context3DVertexBufferFormat;
|
||||
import flash.display3D.IndexBuffer3D;
|
||||
import flash.display3D.Program3D;
|
||||
import flash.display3D.VertexBuffer3D;
|
||||
import flash.events.Event;
|
||||
import flash.geom.Matrix;
|
||||
import flash.geom.Point;
|
||||
import flash.utils.Dictionary;
|
||||
|
||||
internal class PolygonBatch {
|
||||
static private var _tempPoint:Point = new Point();
|
||||
static private var _renderAlpha:Vector.<Number> = new <Number>[1.0, 1.0, 1.0, 1.0];
|
||||
static private var _programNameCache:Dictionary = new Dictionary();
|
||||
|
||||
private var _capacity:int;
|
||||
public var maxCapacity:int = 2000;
|
||||
public var smoothing:String = TextureSmoothing.BILINEAR;
|
||||
|
||||
private var _texture:Texture;
|
||||
private var _support:RenderSupport;
|
||||
private var _programBits:uint;
|
||||
private var _blendModeNormal:String;
|
||||
private var _blendMode:spine.BlendMode;
|
||||
private var _alpha:Number;
|
||||
|
||||
private var _verticesCount:int;
|
||||
private var _vertices:Vector.<Number> = new <Number>[];
|
||||
private var _verticesBuffer:VertexBuffer3D;
|
||||
|
||||
private var _trianglesCount:int;
|
||||
private var _triangles:Vector.<uint> = new <uint>[];
|
||||
private var _trianglesBuffer:IndexBuffer3D;
|
||||
|
||||
public function PolygonBatch () {
|
||||
Starling.current.stage3D.addEventListener(Event.CONTEXT3D_CREATE, onContextCreated, false, 0, true);
|
||||
}
|
||||
|
||||
public function dispose () : void {
|
||||
Starling.current.stage3D.removeEventListener(Event.CONTEXT3D_CREATE, onContextCreated);
|
||||
if (_verticesBuffer) _verticesBuffer.dispose();
|
||||
if (_trianglesBuffer) _trianglesBuffer.dispose();
|
||||
}
|
||||
|
||||
public function begin (support:RenderSupport, alpha:Number, blendMode:String) : void {
|
||||
_support = support;
|
||||
_alpha = alpha;
|
||||
_programBits = 0xffffffff;
|
||||
_blendMode = null;
|
||||
|
||||
support.finishQuadBatch();
|
||||
support.blendMode = blendMode;
|
||||
_blendModeNormal = support.blendMode;
|
||||
|
||||
var context:Context3D = Starling.context;
|
||||
context.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 1, support.mvpMatrix3D, true);
|
||||
|
||||
var verticesBuffer:VertexBuffer3D = _verticesBuffer;
|
||||
if (verticesBuffer) {
|
||||
context.setVertexBufferAt(0, verticesBuffer, VertexData.POSITION_OFFSET, Context3DVertexBufferFormat.FLOAT_2);
|
||||
context.setVertexBufferAt(1, verticesBuffer, VertexData.COLOR_OFFSET, Context3DVertexBufferFormat.FLOAT_4);
|
||||
context.setVertexBufferAt(2, verticesBuffer, VertexData.TEXCOORD_OFFSET, Context3DVertexBufferFormat.FLOAT_2);
|
||||
}
|
||||
}
|
||||
|
||||
public function end () : void {
|
||||
flush();
|
||||
var context:Context3D = Starling.context;
|
||||
context.setTextureAt(0, null);
|
||||
context.setVertexBufferAt(2, null);
|
||||
context.setVertexBufferAt(1, null);
|
||||
context.setVertexBufferAt(0, null);
|
||||
}
|
||||
|
||||
public function add (texture:Texture, vertices:Vector.<Number>, vl:int, uvs:Vector.<Number>, triangles:Vector.<uint>,
|
||||
r:Number, g:Number, b:Number, a:Number, blendMode:spine.BlendMode, matrix:Matrix) : void {
|
||||
if (blendMode != _blendMode) {
|
||||
_blendMode = blendMode;
|
||||
flush();
|
||||
if (blendMode == spine.BlendMode.normal)
|
||||
_support.blendMode = _blendModeNormal;
|
||||
else
|
||||
_support.blendMode = spine.starling.SkeletonSprite.blendModes[blendMode.ordinal];
|
||||
_support.applyBlendMode(true);
|
||||
}
|
||||
|
||||
if (!_texture || texture.base != _texture.base) {
|
||||
flush();
|
||||
_texture = texture;
|
||||
}
|
||||
|
||||
var vc:int = _verticesCount, firstVertex:int = vc >> 3;
|
||||
if (firstVertex + (vl >> 1) > _capacity) {
|
||||
resize(firstVertex + (vl >> 1) - _capacity);
|
||||
vc = _verticesCount;
|
||||
firstVertex = vc >> 3;
|
||||
}
|
||||
var tl:int = triangles.length, tc:int = _trianglesCount;
|
||||
if (tc + tl > _triangles.length) {
|
||||
resize((tc + tl - _triangles.length) / 3);
|
||||
vc = _verticesCount;
|
||||
firstVertex = vc >> 3;
|
||||
tc = _trianglesCount;
|
||||
}
|
||||
|
||||
var i:int, t:Vector.<uint> = _triangles;
|
||||
for (i = 0; i < tl; i += 3, tc += 3) {
|
||||
t[tc] = firstVertex + triangles[i];
|
||||
t[int(tc + 1)] = firstVertex + triangles[int(i + 1)];
|
||||
t[int(tc + 2)] = firstVertex + triangles[int(i + 2)];
|
||||
}
|
||||
_trianglesCount = tc;
|
||||
|
||||
var v:Vector.<Number> = _vertices;
|
||||
if (matrix) {
|
||||
var point:Point = _tempPoint;
|
||||
for (i = 0; i < vl; i += 2, vc += 8) {
|
||||
MatrixUtil.transformCoords(matrix, vertices[i], vertices[int(i + 1)], point);
|
||||
v[vc] = point.x;
|
||||
v[int(vc + 1)] = point.y;
|
||||
v[int(vc + 2)] = r;
|
||||
v[int(vc + 3)] = g;
|
||||
v[int(vc + 4)] = b;
|
||||
v[int(vc + 5)] = a;
|
||||
v[int(vc + 6)] = uvs[i];
|
||||
v[int(vc + 7)] = uvs[int(i + 1)];
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < vl; i += 2, vc += 8) {
|
||||
v[vc] = vertices[i];
|
||||
v[int(vc + 1)] = vertices[int(i + 1)];
|
||||
v[int(vc + 2)] = r;
|
||||
v[int(vc + 3)] = g;
|
||||
v[int(vc + 4)] = b;
|
||||
v[int(vc + 5)] = a;
|
||||
v[int(vc + 6)] = uvs[i];
|
||||
v[int(vc + 7)] = uvs[int(i + 1)];
|
||||
}
|
||||
}
|
||||
_verticesCount = vc;
|
||||
}
|
||||
|
||||
private function resize (additional:int) : void {
|
||||
var newCapacity:int = Math.min(maxCapacity, Math.max(_capacity + additional, _capacity * 2));
|
||||
if (newCapacity == maxCapacity) {
|
||||
flush();
|
||||
newCapacity = additional;
|
||||
if (newCapacity < _capacity) return;
|
||||
if (newCapacity > maxCapacity) throw new ArgumentError("Too many vertices: " + newCapacity + " > " + maxCapacity);
|
||||
}
|
||||
_capacity = newCapacity;
|
||||
_vertices.length = newCapacity << 3;
|
||||
_triangles.length = newCapacity * 3;
|
||||
_verticesBuffer = null;
|
||||
_trianglesBuffer = null;
|
||||
}
|
||||
|
||||
public function flush () : void {
|
||||
if (!_verticesCount) return;
|
||||
|
||||
var context:Context3D = Starling.context;
|
||||
|
||||
if (!_verticesBuffer) {
|
||||
_verticesBuffer = context.createVertexBuffer(_capacity, 8);
|
||||
var count:int = _verticesCount >> 3;
|
||||
_verticesBuffer.uploadFromVector(_vertices, 0, count);
|
||||
var verticesTemp:Vector.<Number> = new <Number>[]; // Buffer must be filled completely once.
|
||||
verticesTemp.length = (_capacity << 3) - _verticesCount;
|
||||
_verticesBuffer.uploadFromVector(verticesTemp, count, _capacity - count);
|
||||
verticesTemp = null;
|
||||
|
||||
_trianglesBuffer = context.createIndexBuffer(_capacity * 3);
|
||||
_trianglesBuffer.uploadFromVector(_triangles, 0, _trianglesCount);
|
||||
var trianglesTemp:Vector.<uint> = new <uint>[]; // Buffer must be filled completely once.
|
||||
trianglesTemp.length = _capacity * 3 - _trianglesCount;
|
||||
_trianglesBuffer.uploadFromVector(trianglesTemp, _trianglesCount, trianglesTemp.length);
|
||||
trianglesTemp = null;
|
||||
|
||||
context.setVertexBufferAt(0, _verticesBuffer, VertexData.POSITION_OFFSET, Context3DVertexBufferFormat.FLOAT_2);
|
||||
context.setVertexBufferAt(1, _verticesBuffer, VertexData.COLOR_OFFSET, Context3DVertexBufferFormat.FLOAT_4);
|
||||
context.setVertexBufferAt(2, _verticesBuffer, VertexData.TEXCOORD_OFFSET, Context3DVertexBufferFormat.FLOAT_2);
|
||||
} else {
|
||||
_verticesBuffer.uploadFromVector(_vertices, 0, _verticesCount >> 3);
|
||||
_trianglesBuffer.uploadFromVector(_triangles, 0, _trianglesCount);
|
||||
}
|
||||
|
||||
var pma:Boolean = _texture ? _texture.premultipliedAlpha : true;
|
||||
_renderAlpha[0] = _renderAlpha[1] = _renderAlpha[2] = pma ? _alpha : 1.0;
|
||||
_renderAlpha[3] = _alpha;
|
||||
|
||||
_support.applyBlendMode(pma);
|
||||
context.setProgramConstantsFromVector(Context3DProgramType.VERTEX, 0, _renderAlpha, 1);
|
||||
|
||||
setProgram(context);
|
||||
context.setTextureAt(0, _texture.base);
|
||||
context.drawTriangles(_trianglesBuffer, 0, _trianglesCount / 3);
|
||||
|
||||
_verticesCount = 0;
|
||||
_trianglesCount = 0;
|
||||
|
||||
_support.raiseDrawCount();
|
||||
}
|
||||
|
||||
private function onContextCreated (event:Event) : void {
|
||||
_verticesBuffer = null;
|
||||
_trianglesBuffer = null;
|
||||
}
|
||||
|
||||
private function setProgram (context:Context3D) : void {
|
||||
var bits:uint = 0;
|
||||
var texture:Texture = _texture;
|
||||
if (texture.mipMapping) bits |= 1 << 1;
|
||||
if (texture.repeat) bits |= 1 << 2;
|
||||
if (smoothing != TextureSmoothing.BILINEAR) bits |= 1 << (smoothing == TextureSmoothing.TRILINEAR ? 3 : 4);
|
||||
if (texture.format != Context3DTextureFormat.BGRA) bits |= 1 << (texture.format == "compressedAlpha" ? 5 : 6);
|
||||
if (bits == _programBits) return;
|
||||
_programBits = bits;
|
||||
|
||||
var name:String = _programNameCache[bits];
|
||||
if (name == null) {
|
||||
name = "PB_i." + bits.toString(16);
|
||||
_programNameCache[bits] = name;
|
||||
}
|
||||
|
||||
var program:Program3D = Starling.current.getProgram(name);
|
||||
if (!program) {
|
||||
// va0 -> position
|
||||
// va1 -> color
|
||||
// va2 -> texCoords
|
||||
// vc0 -> alpha
|
||||
// vc1 -> mvpMatrix
|
||||
// fs0 -> texture
|
||||
var vertexShader:String =
|
||||
"m44 op, va0, vc1 \n" + // 4x4 matrix transform to output clipspace
|
||||
"mul v0, va1, vc0 \n" + // multiply alpha (vc0) with color (va1)
|
||||
"mov v1, va2 \n"; // pass texture coordinates to fragment program
|
||||
var flags:String = RenderSupport.getTextureLookupFlags(texture.format, texture.mipMapping, texture.repeat, smoothing);
|
||||
var fragmentShader:String =
|
||||
"tex ft1, v1, fs0 " + flags + " \n" + // sample texture 0
|
||||
"mul oc, ft1, v0 \n"; // multiply color with texel color
|
||||
program = Starling.current.registerProgramFromSource(name, vertexShader, fragmentShader);
|
||||
}
|
||||
context.setProgram(program);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -39,10 +39,9 @@ import starling.animation.IAnimatable;
|
||||
public class SkeletonAnimation extends SkeletonSprite implements IAnimatable {
|
||||
public var state:AnimationState;
|
||||
public var timeScale:Number = 1;
|
||||
|
||||
/** @param renderMeshes If false, meshes won't be rendered. This may improve batching with non-Spine display objects. */
|
||||
public function SkeletonAnimation (skeletonData:SkeletonData, renderMeshes:Boolean = true, stateData:AnimationStateData = null) {
|
||||
super(skeletonData, renderMeshes);
|
||||
|
||||
public function SkeletonAnimation (skeletonData:SkeletonData, stateData:AnimationStateData = null) {
|
||||
super(skeletonData);
|
||||
state = new AnimationState(stateData ? stateData : new AnimationStateData(skeletonData));
|
||||
}
|
||||
|
||||
@ -52,6 +51,7 @@ public class SkeletonAnimation extends SkeletonSprite implements IAnimatable {
|
||||
state.update(time);
|
||||
state.apply(skeleton);
|
||||
skeleton.updateWorldTransform();
|
||||
this.setRequiresRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -30,27 +30,26 @@
|
||||
*****************************************************************************/
|
||||
|
||||
package spine.starling {
|
||||
|
||||
import starling.display.Image;
|
||||
import starling.textures.Texture;
|
||||
import starling.utils.VertexData;
|
||||
import starling.styles.MeshStyle;
|
||||
import starling.rendering.IndexData;
|
||||
import starling.rendering.VertexData;
|
||||
import starling.display.Mesh;
|
||||
|
||||
public class SkeletonImage extends Image {
|
||||
public function SkeletonImage (texture:Texture) {
|
||||
super(texture);
|
||||
public class SkeletonMesh extends Mesh {
|
||||
|
||||
public function SkeletonMesh(texture:Texture, vertexData:VertexData = null, indexData:IndexData = null, style:MeshStyle=null) {
|
||||
super(vertexData == null? new VertexData(): vertexData, indexData == null? new IndexData(): indexData, style);
|
||||
this.texture = texture;
|
||||
}
|
||||
|
||||
public function getVertexData(): VertexData {
|
||||
return this.vertexData;
|
||||
}
|
||||
|
||||
public function get vertexData () : VertexData {
|
||||
return mVertexData;
|
||||
}
|
||||
|
||||
public function updateVertices () : void {
|
||||
onVertexDataChanged();
|
||||
}
|
||||
|
||||
override public function get tinted () : Boolean {
|
||||
return true;
|
||||
|
||||
public function getIndexData(): IndexData {
|
||||
return this.indexData;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -40,12 +40,14 @@ import spine.attachments.MeshAttachment;
|
||||
import spine.attachments.RegionAttachment;
|
||||
import spine.attachments.WeightedMeshAttachment;
|
||||
|
||||
import starling.core.RenderSupport;
|
||||
import starling.display.BlendMode;
|
||||
import starling.display.DisplayObject;
|
||||
import starling.display.Image;
|
||||
import starling.rendering.IndexData;
|
||||
import starling.rendering.Painter;
|
||||
import starling.rendering.VertexData;
|
||||
import starling.utils.Color;
|
||||
import starling.utils.MatrixUtil;
|
||||
import starling.utils.VertexData;
|
||||
|
||||
import flash.geom.Matrix;
|
||||
import flash.geom.Point;
|
||||
@ -54,129 +56,23 @@ import flash.geom.Rectangle;
|
||||
public class SkeletonSprite extends DisplayObject {
|
||||
static private var _tempPoint:Point = new Point();
|
||||
static private var _tempMatrix:Matrix = new Matrix();
|
||||
static private var _tempVertices:Vector.<Number> = new Vector.<Number>(8);
|
||||
static private var _quadTriangles:Vector.<uint> = new <uint>[0, 1, 2, 2, 3, 0];
|
||||
static private var _tempVertices:Vector.<Number> = new Vector.<Number>(8);
|
||||
static internal var blendModes:Vector.<String> = new <String>[
|
||||
BlendMode.NORMAL, BlendMode.ADD, BlendMode.MULTIPLY, BlendMode.SCREEN];
|
||||
|
||||
private var _skeleton:Skeleton;
|
||||
private var _polygonBatch:PolygonBatch;
|
||||
public var batchable:Boolean = true;
|
||||
private var _batched:Boolean;
|
||||
private var _skeleton:Skeleton;
|
||||
public var batchable:Boolean = true;
|
||||
private var _smoothing:String = "bilinear";
|
||||
|
||||
/** @param renderMeshes If false, meshes won't be rendered. This may improve batching with non-Spine display objects. */
|
||||
public function SkeletonSprite (skeletonData:SkeletonData, renderMeshes:Boolean = true) {
|
||||
|
||||
public function SkeletonSprite (skeletonData:SkeletonData) {
|
||||
Bone.yDown = true;
|
||||
|
||||
if (renderMeshes) _polygonBatch = new PolygonBatch();
|
||||
|
||||
_skeleton = new Skeleton(skeletonData);
|
||||
_skeleton.updateWorldTransform();
|
||||
}
|
||||
|
||||
override public function render (support:RenderSupport, alpha:Number) : void {
|
||||
alpha *= this.alpha * skeleton.a;
|
||||
var originalBlendMode:String = support.blendMode;
|
||||
if (_polygonBatch)
|
||||
renderMeshes(support, alpha);
|
||||
else
|
||||
renderRegions(support, alpha);
|
||||
support.blendMode = originalBlendMode;
|
||||
}
|
||||
|
||||
private function renderMeshes (support:RenderSupport, alpha:Number) : void {
|
||||
if (!batchable) {
|
||||
_polygonBatch.begin(support, alpha, blendMode);
|
||||
addToBatch(_polygonBatch, alpha, null);
|
||||
_polygonBatch.end();
|
||||
} else if (!_batched) {
|
||||
support.popMatrix();
|
||||
_polygonBatch.begin(support, alpha, blendMode);
|
||||
addToBatch(_polygonBatch, alpha, transformationMatrix);
|
||||
for(var i:int = parent.getChildIndex(this) + 1, n:int = parent.numChildren; i < n; ++i) {
|
||||
var sibling:SkeletonSprite = parent.getChildAt(i) as SkeletonSprite;
|
||||
if (!sibling || !sibling.batchable || sibling.blendMode != blendMode || !sibling.visible) break;
|
||||
sibling._batched = true;
|
||||
sibling.addToBatch(_polygonBatch, alpha, sibling.transformationMatrix);
|
||||
}
|
||||
_polygonBatch.end();
|
||||
support.pushMatrix();
|
||||
support.transformMatrix(this);
|
||||
} else
|
||||
_batched = false;
|
||||
}
|
||||
|
||||
private function addToBatch (polygonBatch:PolygonBatch, skeletonA:Number, matrix:Matrix) : void {
|
||||
var skeletonR:Number = skeleton.r;
|
||||
var skeletonG:Number = skeleton.g;
|
||||
var skeletonB:Number = skeleton.b;
|
||||
var x:Number = skeleton.x;
|
||||
var y:Number = skeleton.y;
|
||||
var worldVertices:Vector.<Number> = _tempVertices;
|
||||
var drawOrder:Vector.<Slot> = skeleton.drawOrder;
|
||||
for (var i:int = 0, n:int = drawOrder.length; i < n; ++i) {
|
||||
var slot:Slot = drawOrder[i];
|
||||
var attachment:Attachment = slot.attachment;
|
||||
if (!attachment) continue;
|
||||
var image:SkeletonImage, verticesLength:int, uvs:Vector.<Number>, triangles:Vector.<uint>;
|
||||
var r:Number, g:Number, b:Number, a:Number;
|
||||
if (attachment is RegionAttachment) {
|
||||
var region:RegionAttachment = RegionAttachment(slot.attachment);
|
||||
verticesLength = 8;
|
||||
region.computeWorldVertices(x, y, slot.bone, worldVertices);
|
||||
uvs = region.uvs;
|
||||
triangles = _quadTriangles;
|
||||
r = region.r;
|
||||
g = region.g;
|
||||
b = region.b;
|
||||
a = region.a;
|
||||
image = region.rendererObject as SkeletonImage;
|
||||
if (image == null) region.rendererObject = image = SkeletonImage(AtlasRegion(region.rendererObject).rendererObject);
|
||||
} else if (attachment is MeshAttachment) {
|
||||
var mesh:MeshAttachment = MeshAttachment(attachment);
|
||||
verticesLength = mesh.vertices.length;
|
||||
if (worldVertices.length < verticesLength) worldVertices.length = verticesLength;
|
||||
mesh.computeWorldVertices(x, y, slot, worldVertices);
|
||||
uvs = mesh.uvs;
|
||||
triangles = mesh.triangles;
|
||||
r = mesh.r;
|
||||
g = mesh.g;
|
||||
b = mesh.b;
|
||||
a = mesh.a;
|
||||
image = mesh.rendererObject as SkeletonImage;
|
||||
if (image == null) mesh.rendererObject = image = SkeletonImage(AtlasRegion(mesh.rendererObject).rendererObject);
|
||||
} else if (attachment is WeightedMeshAttachment) {
|
||||
var weightedMesh:WeightedMeshAttachment = WeightedMeshAttachment(attachment);
|
||||
verticesLength = weightedMesh.uvs.length;
|
||||
if (worldVertices.length < verticesLength) worldVertices.length = verticesLength;
|
||||
weightedMesh.computeWorldVertices(x, y, slot, worldVertices);
|
||||
uvs = weightedMesh.uvs;
|
||||
triangles = weightedMesh.triangles;
|
||||
r = weightedMesh.r;
|
||||
g = weightedMesh.g;
|
||||
b = weightedMesh.b;
|
||||
a = weightedMesh.a;
|
||||
image = weightedMesh.rendererObject as SkeletonImage;
|
||||
if (image == null) weightedMesh.rendererObject = image = SkeletonImage(AtlasRegion(weightedMesh.rendererObject).rendererObject);
|
||||
}
|
||||
if (image) {
|
||||
a *= skeletonA * slot.a;
|
||||
if (image.texture.premultipliedAlpha) {
|
||||
r *= skeletonR * slot.r * a;
|
||||
g *= skeletonG * slot.g * a;
|
||||
b *= skeletonB * slot.b * a;
|
||||
} else {
|
||||
r *= skeletonR * slot.r;
|
||||
g *= skeletonG * slot.g;
|
||||
b *= skeletonB * slot.b;
|
||||
}
|
||||
polygonBatch.add(image.texture, worldVertices, verticesLength, uvs, triangles, r, g, b, a, slot.data.blendMode, matrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function renderRegions (support:RenderSupport, alpha:Number) : void {
|
||||
override public function render (painter:Painter) : void {
|
||||
alpha *= this.alpha * skeleton.a;
|
||||
var originalBlendMode:String = painter.state.blendMode;
|
||||
var r:Number = skeleton.r * 255;
|
||||
var g:Number = skeleton.g * 255;
|
||||
var b:Number = skeleton.b * 255;
|
||||
@ -184,43 +80,144 @@ public class SkeletonSprite extends DisplayObject {
|
||||
var y:Number = skeleton.y;
|
||||
var drawOrder:Vector.<Slot> = skeleton.drawOrder;
|
||||
var worldVertices:Vector.<Number> = _tempVertices;
|
||||
var ii:int, iii:int;
|
||||
var rgb:uint, a:Number;
|
||||
var mesh:SkeletonMesh;
|
||||
var verticesLength:int, verticesCount:int, indicesLength:int;
|
||||
var indexData:IndexData, indices:Vector.<uint>, vertexData:VertexData;
|
||||
var uvs: Vector.<Number>;
|
||||
|
||||
for (var i:int = 0, n:int = drawOrder.length; i < n; ++i) {
|
||||
var slot:Slot = drawOrder[i];
|
||||
var region:RegionAttachment = slot.attachment as RegionAttachment;
|
||||
if (region != null) {
|
||||
var slot:Slot = drawOrder[i];
|
||||
if (slot.attachment is RegionAttachment) {
|
||||
var region:RegionAttachment = slot.attachment as RegionAttachment;
|
||||
region.computeWorldVertices(x, y, slot.bone, worldVertices);
|
||||
var a:Number = slot.a * region.a;
|
||||
var rgb:uint = Color.rgb(
|
||||
// FIXME pre-multiplied alpha?
|
||||
a = slot.a * region.a;
|
||||
rgb = Color.rgb(
|
||||
r * slot.r * region.r,
|
||||
g * slot.g * region.g,
|
||||
b * slot.b * region.b);
|
||||
|
||||
var image:SkeletonImage = region.rendererObject as SkeletonImage;
|
||||
if (image == null) region.rendererObject = image = SkeletonImage(AtlasRegion(region.rendererObject).rendererObject);
|
||||
|
||||
var vertexData:VertexData = image.vertexData;
|
||||
vertexData.setPosition(0, worldVertices[2], worldVertices[3]);
|
||||
vertexData.setColorAndAlpha(0, rgb, a);
|
||||
var image:Image = region.rendererObject as Image;
|
||||
if (image == null) region.rendererObject = image = Image(AtlasRegion(region.rendererObject).rendererObject);
|
||||
|
||||
vertexData.setPosition(1, worldVertices[4], worldVertices[5]);
|
||||
vertexData.setColorAndAlpha(1, rgb, a);
|
||||
image.setVertexPosition(0, worldVertices[2], worldVertices[3]);
|
||||
image.setVertexColor(0, rgb);
|
||||
image.setVertexAlpha(0, a);
|
||||
|
||||
vertexData.setPosition(2, worldVertices[0], worldVertices[1]);
|
||||
vertexData.setColorAndAlpha(2, rgb, a);
|
||||
image.setVertexPosition(1, worldVertices[4], worldVertices[5]);
|
||||
image.setVertexColor(1, rgb);
|
||||
image.setVertexAlpha(1, a);
|
||||
|
||||
vertexData.setPosition(3, worldVertices[6], worldVertices[7]);
|
||||
vertexData.setColorAndAlpha(3, rgb, a);
|
||||
image.setVertexPosition(2, worldVertices[0], worldVertices[1]);
|
||||
image.setVertexColor(2, rgb);
|
||||
image.setVertexAlpha(2, a);
|
||||
|
||||
image.updateVertices();
|
||||
support.blendMode = blendModes[slot.data.blendMode.ordinal];
|
||||
support.batchQuad(image, alpha, image.texture, _smoothing);
|
||||
image.setVertexPosition(3, worldVertices[6], worldVertices[7]);
|
||||
image.setVertexColor(3, rgb);
|
||||
image.setVertexAlpha(3, a);
|
||||
|
||||
image.setRequiresRedraw();
|
||||
painter.state.blendMode = blendModes[slot.data.blendMode.ordinal];
|
||||
// FIXME set smoothing/filter
|
||||
painter.batchMesh(image);
|
||||
} else if (slot.attachment is MeshAttachment) {
|
||||
var meshAttachment:MeshAttachment = MeshAttachment(slot.attachment);
|
||||
verticesLength = meshAttachment.vertices.length;
|
||||
verticesCount = verticesLength >> 1;
|
||||
if (worldVertices.length < verticesLength) worldVertices.length = verticesLength;
|
||||
meshAttachment.computeWorldVertices(x, y, slot, worldVertices);
|
||||
mesh = meshAttachment.rendererObject as SkeletonMesh;
|
||||
if (mesh == null) {
|
||||
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);
|
||||
}
|
||||
|
||||
if (mesh.numIndices != meshAttachment.triangles.length) {
|
||||
indexData = mesh.getIndexData();
|
||||
indices = meshAttachment.triangles;
|
||||
indicesLength = meshAttachment.triangles.length;
|
||||
for (ii = 0; ii < indicesLength; ii++) {
|
||||
indexData.setIndex(ii, indices[ii]);
|
||||
}
|
||||
indexData.numIndices = indicesLength;
|
||||
indexData.trim();
|
||||
}
|
||||
|
||||
// FIXME pre-multiplied alpha?
|
||||
a = slot.a * meshAttachment.a;
|
||||
rgb = Color.rgb(
|
||||
r * slot.r * meshAttachment.r,
|
||||
g * slot.g * meshAttachment.g,
|
||||
b * slot.b * meshAttachment.b);
|
||||
|
||||
vertexData = mesh.getVertexData();
|
||||
uvs = meshAttachment.uvs;
|
||||
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.setVertexColor(ii, rgb);
|
||||
mesh.setVertexAlpha(ii, alpha);
|
||||
}
|
||||
vertexData.numVertices = verticesCount;
|
||||
// FIXME set smoothing/filter
|
||||
painter.batchMesh(mesh);
|
||||
} else if (slot.attachment is WeightedMeshAttachment) {
|
||||
var weightedMeshAttachment:WeightedMeshAttachment = WeightedMeshAttachment(slot.attachment);
|
||||
verticesLength = weightedMeshAttachment.uvs.length;
|
||||
verticesCount = verticesLength >> 1;
|
||||
if (worldVertices.length < verticesLength) worldVertices.length = verticesLength;
|
||||
weightedMeshAttachment.computeWorldVertices(x, y, slot, worldVertices);
|
||||
mesh = weightedMeshAttachment.rendererObject as SkeletonMesh;
|
||||
if (mesh == null) {
|
||||
if (weightedMeshAttachment.rendererObject is Image)
|
||||
weightedMeshAttachment.rendererObject = mesh = new SkeletonMesh(Image(weightedMeshAttachment.rendererObject).texture);
|
||||
else if (weightedMeshAttachment.rendererObject is AtlasRegion)
|
||||
weightedMeshAttachment.rendererObject = mesh = new SkeletonMesh(Image(AtlasRegion(weightedMeshAttachment.rendererObject).rendererObject).texture);
|
||||
else throw new Error("Unknown rendererObject");
|
||||
}
|
||||
|
||||
if (mesh.numIndices != weightedMeshAttachment.triangles.length) {
|
||||
indexData = mesh.getIndexData();
|
||||
indices = weightedMeshAttachment.triangles;
|
||||
indicesLength = weightedMeshAttachment.triangles.length;
|
||||
for (ii = 0; ii < indicesLength; ii++) {
|
||||
indexData.setIndex(ii, indices[ii]);
|
||||
}
|
||||
indexData.numIndices = indicesLength;
|
||||
indexData.trim();
|
||||
}
|
||||
|
||||
// FIXME pre-multiplied alpha?
|
||||
a = slot.a * weightedMeshAttachment.a;
|
||||
rgb = Color.rgb(
|
||||
r * slot.r * weightedMeshAttachment.r,
|
||||
g * slot.g * weightedMeshAttachment.g,
|
||||
b * slot.b * weightedMeshAttachment.b);
|
||||
|
||||
vertexData = mesh.getVertexData();
|
||||
uvs = weightedMeshAttachment.uvs;
|
||||
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.setVertexColor(ii, rgb);
|
||||
mesh.setVertexAlpha(ii, alpha);
|
||||
}
|
||||
vertexData.numVertices = verticesCount;
|
||||
// FIXME set smoothing/filter
|
||||
painter.batchMesh(mesh);
|
||||
}
|
||||
}
|
||||
painter.state.blendMode = originalBlendMode;
|
||||
}
|
||||
|
||||
override public function hitTest (localPoint:Point, forTouch:Boolean = false) : DisplayObject {
|
||||
if (forTouch && (!visible || !touchable))
|
||||
return null;
|
||||
override public function hitTest (localPoint:Point) : DisplayObject {
|
||||
// FIXME what to do here?
|
||||
// if (forTouch && (!visible || !touchable))
|
||||
// return null;
|
||||
|
||||
var minX:Number = Number.MAX_VALUE, minY:Number = Number.MAX_VALUE;
|
||||
var maxX:Number = -Number.MAX_VALUE, maxY:Number = -Number.MAX_VALUE;
|
||||
@ -298,8 +295,7 @@ public class SkeletonSprite extends DisplayObject {
|
||||
}
|
||||
|
||||
public function set smoothing (smoothing:String) : void {
|
||||
_smoothing = smoothing;
|
||||
if (_polygonBatch) _polygonBatch.smoothing = _smoothing;
|
||||
_smoothing = smoothing;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
*****************************************************************************/
|
||||
|
||||
package spine.starling {
|
||||
import starling.display.Image;
|
||||
import spine.Bone;
|
||||
import spine.Skin;
|
||||
import spine.attachments.AttachmentLoader;
|
||||
@ -58,7 +59,7 @@ public class StarlingAtlasAttachmentLoader implements AttachmentLoader {
|
||||
if (texture == null)
|
||||
throw new Error("Region not found in Starling atlas: " + path + " (region attachment: " + name + ")");
|
||||
var attachment:RegionAttachment = new RegionAttachment(name);
|
||||
attachment.rendererObject = new SkeletonImage(Texture.fromTexture(texture)); // Discard frame.
|
||||
attachment.rendererObject = new Image(Texture.fromTexture(texture)); // Discard frame.
|
||||
var frame:Rectangle = texture.frame;
|
||||
attachment.regionOffsetX = frame ? -frame.x : 0;
|
||||
attachment.regionOffsetY = frame ? -frame.y : 0;
|
||||
@ -90,7 +91,7 @@ public class StarlingAtlasAttachmentLoader implements AttachmentLoader {
|
||||
if (texture == null)
|
||||
throw new Error("Region not found in Starling atlas: " + path + " (mesh attachment: " + name + ")");
|
||||
var attachment:MeshAttachment = new MeshAttachment(name);
|
||||
attachment.rendererObject = new SkeletonImage(Texture.fromTexture(texture)); // Discard frame.
|
||||
attachment.rendererObject = new Image(Texture.fromTexture(texture)); // Discard frame.
|
||||
var subTexture:SubTexture = texture as SubTexture;
|
||||
if (subTexture) {
|
||||
var root:Texture = subTexture.root;
|
||||
@ -99,6 +100,7 @@ public class StarlingAtlasAttachmentLoader implements AttachmentLoader {
|
||||
attachment.regionV = rectRegion.y / root.height;
|
||||
attachment.regionU2 = (rectRegion.x + subTexture.width) / root.width;
|
||||
attachment.regionV2 = (rectRegion.y + subTexture.height) / root.height;
|
||||
attachment.rendererObject = new Image(root);
|
||||
} else {
|
||||
attachment.regionU = 0;
|
||||
attachment.regionV = 1;
|
||||
@ -120,7 +122,7 @@ public class StarlingAtlasAttachmentLoader implements AttachmentLoader {
|
||||
if (texture == null)
|
||||
throw new Error("Region not found in Starling atlas: " + path + " (weighted mesh attachment: " + name + ")");
|
||||
var attachment:WeightedMeshAttachment = new WeightedMeshAttachment(name);
|
||||
attachment.rendererObject = new SkeletonImage(Texture.fromTexture(texture)); // Discard frame.
|
||||
attachment.rendererObject = new Image(Texture.fromTexture(texture)); // Discard frame.
|
||||
var subTexture:SubTexture = texture as SubTexture;
|
||||
if (subTexture) {
|
||||
var root:Texture = subTexture.root;
|
||||
@ -129,6 +131,7 @@ public class StarlingAtlasAttachmentLoader implements AttachmentLoader {
|
||||
attachment.regionV = rectRegion.y / root.height;
|
||||
attachment.regionU2 = (rectRegion.x + subTexture.width) / root.width;
|
||||
attachment.regionV2 = (rectRegion.y + subTexture.height) / root.height;
|
||||
attachment.rendererObject = new Image(root);
|
||||
} else {
|
||||
attachment.regionU = 0;
|
||||
attachment.regionV = 1;
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
*****************************************************************************/
|
||||
|
||||
package spine.starling {
|
||||
import starling.display.Image;
|
||||
import spine.atlas.AtlasPage;
|
||||
import spine.atlas.AtlasRegion;
|
||||
import spine.atlas.TextureLoader;
|
||||
@ -78,17 +79,17 @@ public class StarlingTextureLoader implements TextureLoader {
|
||||
}
|
||||
|
||||
public function loadRegion (region:AtlasRegion) : void {
|
||||
var image:SkeletonImage = new SkeletonImage(Texture(region.page.rendererObject));
|
||||
if (region.rotate) {
|
||||
image.setTexCoordsTo(0, region.u, region.v2);
|
||||
image.setTexCoordsTo(1, region.u, region.v);
|
||||
image.setTexCoordsTo(2, region.u2, region.v2);
|
||||
image.setTexCoordsTo(3, region.u2, region.v);
|
||||
var image:Image = new Image(Texture(region.page.rendererObject));
|
||||
if (region.rotate) {
|
||||
image.setTexCoords(0, region.u, region.v2);
|
||||
image.setTexCoords(1, region.u, region.v);
|
||||
image.setTexCoords(2, region.u2, region.v2);
|
||||
image.setTexCoords(3, region.u2, region.v);
|
||||
} else {
|
||||
image.setTexCoordsTo(0, region.u, region.v);
|
||||
image.setTexCoordsTo(1, region.u2, region.v);
|
||||
image.setTexCoordsTo(2, region.u, region.v2);
|
||||
image.setTexCoordsTo(3, region.u2, region.v2);
|
||||
image.setTexCoords(0, region.u, region.v);
|
||||
image.setTexCoords(1, region.u2, region.v);
|
||||
image.setTexCoords(2, region.u, region.v2);
|
||||
image.setTexCoords(3, region.u2, region.v2);
|
||||
}
|
||||
region.rendererObject = image;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user