Skip to content

Commit

Permalink
Add RenderMode TS support (#3879)
Browse files Browse the repository at this point in the history
Add spine assembler var define
  • Loading branch information
sunnylanwanjun authored and pandamicro committed Feb 20, 2019
1 parent 62bc2c7 commit 201e4e0
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 36 deletions.
61 changes: 43 additions & 18 deletions extensions/dragonbones/ArmatureDisplay.js
Expand Up @@ -41,8 +41,33 @@ let ArmatureCache = require('./ArmatureCache');

let DefaultArmaturesEnum = cc.Enum({ 'default': -1 });
let DefaultAnimsEnum = cc.Enum({ '<None>': 0 });
let DefaultRenderModeEnum = cc.Enum({ 'REALTIME': 0 });
let RenderModeEnum = cc.Enum({ 'REALTIME': 0, 'SHARED_CACHE': 1, "PRIVATE_CACHE": 2 });
let DefaultRenderMode = cc.Enum({ 'REALTIME': 0 });

/**
* !#en Enum for render mode type.
* !#zh Dragonbones渲染类型
* @enum ArmatureDisplay.RenderMode
*/
let RenderMode = cc.Enum({
/**
* !#en The realtime mode.
* !#zh 实时计算模式。
* @property {Number} REALTIME
*/
REALTIME: 0,
/**
* !#en The shared cache mode.
* !#zh 共享缓存模式。
* @property {Number} SHARED_CACHE
*/
SHARED_CACHE: 1,
/**
* !#en The private cache mode.
* !#zh 私有缓存模式。
* @property {Number} PRIVATE_CACHE
*/
PRIVATE_CACHE: 2
});

function setEnumAttr (obj, propName, enumDef) {
cc.Class.attr(obj, propName, {
Expand Down Expand Up @@ -79,7 +104,7 @@ let ArmatureDisplay = cc.Class({
},

statics: {
RenderMode: RenderModeEnum,
RenderMode: RenderMode,
},

properties: {
Expand Down Expand Up @@ -294,10 +319,10 @@ let ArmatureDisplay = cc.Class({

// Record pre render mode.
_preRenderMode: -1,
_renderMode: RenderModeEnum.REALTIME,
_renderMode: RenderMode.REALTIME,
_defaultRenderMode: {
default: 0,
type: RenderModeEnum,
type: RenderMode,
notify () {
this.setRenderMode(this._defaultRenderMode);
},
Expand Down Expand Up @@ -448,7 +473,7 @@ let ArmatureDisplay = cc.Class({
this._inited = true;

if (CC_JSB) {
this._renderMode = RenderModeEnum.REALTIME;
this._renderMode = RenderMode.REALTIME;
}

this._parseDragonAsset();
Expand Down Expand Up @@ -493,7 +518,7 @@ let ArmatureDisplay = cc.Class({
*/
isCachedMode () {
if (CC_EDITOR) return false;
return this._renderMode !== RenderModeEnum.REALTIME;
return this._renderMode !== RenderMode.REALTIME;
},

onEnable () {
Expand Down Expand Up @@ -557,11 +582,11 @@ let ArmatureDisplay = cc.Class({
this._inited = false;

if (!CC_EDITOR) {
if (this._renderMode === RenderModeEnum.PRIVATE_CACHE) {
if (this._renderMode === RenderMode.PRIVATE_CACHE) {
this._armatureCache.dispose();
this._armatureCache = null;
this._armature = null;
} else if (this._renderMode === RenderModeEnum.SHARED_CACHE) {
} else if (this._renderMode === RenderMode.SHARED_CACHE) {
this._armatureCache = null;
this._armature = null;
} else if (this._armature) {
Expand Down Expand Up @@ -601,9 +626,9 @@ let ArmatureDisplay = cc.Class({
if (this._armature) {
// dispose pre build armature
if (!CC_EDITOR) {
if (this._preRenderMode === RenderModeEnum.PRIVATE_CACHE) {
if (this._preRenderMode === RenderMode.PRIVATE_CACHE) {
this._armatureCache.dispose();
} else if (this._preRenderMode === RenderModeEnum.REALTIME) {
} else if (this._preRenderMode === RenderMode.REALTIME) {
this._armature.dispose();
}
} else {
Expand All @@ -620,9 +645,9 @@ let ArmatureDisplay = cc.Class({
}

if (!CC_EDITOR) {
if (this._renderMode === RenderModeEnum.SHARED_CACHE) {
if (this._renderMode === RenderMode.SHARED_CACHE) {
this._armatureCache = ArmatureCache.sharedCache;
} else if (this._renderMode === RenderModeEnum.PRIVATE_CACHE) {
} else if (this._renderMode === RenderMode.PRIVATE_CACHE) {
this._armatureCache = new ArmatureCache;
}
}
Expand All @@ -634,20 +659,20 @@ let ArmatureDisplay = cc.Class({
this._armature = this._armatureCache.getArmatureCache(this.armatureName, dragonbonesName, atlasName);
if (!this._armature) {
// Cache fail,swith to REALTIME render mode.
this._renderMode = RenderModeEnum.REALTIME;
this._renderMode = RenderMode.REALTIME;
}
}

this._preRenderMode = this._renderMode;
if (CC_EDITOR || this._renderMode === RenderModeEnum.REALTIME) {
if (CC_EDITOR || this._renderMode === RenderMode.REALTIME) {
this._displayProxy = this._factory.buildArmatureDisplay(this.armatureName, dragonbonesName, "", atlasName);
if (!this._displayProxy) return;
this._displayProxy._ccNode = this.node;
this._armature = this._displayProxy._armature;
this._armature.animation.timeScale = this.timeScale;
}

if (this._renderMode !== RenderModeEnum.REALTIME && this.debugBones) {
if (this._renderMode !== RenderMode.REALTIME && this.debugBones) {
cc.warn("Debug bones is invalid in cached mode");
}

Expand Down Expand Up @@ -683,9 +708,9 @@ let ArmatureDisplay = cc.Class({

_updateRenderModeEnum: CC_EDITOR && function () {
if (this._armature && ArmatureCache.canCache(this._armature)) {
setEnumAttr(this, 'renderMode', RenderModeEnum);
setEnumAttr(this, 'renderMode', RenderMode);
} else {
setEnumAttr(this, 'renderMode', DefaultRenderModeEnum);
setEnumAttr(this, 'renderMode', DefaultRenderMode);
}
},

Expand Down
43 changes: 34 additions & 9 deletions extensions/spine/Skeleton.js
Expand Up @@ -38,7 +38,32 @@ let SkeletonCache = require('./skeleton-cache');
*/
let DefaultSkinsEnum = cc.Enum({ 'default': -1 });
let DefaultAnimsEnum = cc.Enum({ '<None>': 0 });
let RenderModeEnum = cc.Enum({ 'REALTIME': 0, 'SHARED_CACHE': 1, "PRIVATE_CACHE": 2 });

/**
* !#en Enum for render mode type.
* !#zh Spine渲染类型
* @enum Skeleton.RenderMode
*/
let RenderMode = cc.Enum({
/**
* !#en The realtime mode.
* !#zh 实时计算模式。
* @property {Number} REALTIME
*/
REALTIME: 0,
/**
* !#en The shared cache mode.
* !#zh 共享缓存模式。
* @property {Number} SHARED_CACHE
*/
SHARED_CACHE: 1,
/**
* !#en The private cache mode.
* !#zh 私有缓存模式。
* @property {Number} PRIVATE_CACHE
*/
PRIVATE_CACHE: 2
});

function setEnumAttr (obj, propName, enumDef) {
cc.Class.attr(obj, propName, {
Expand Down Expand Up @@ -74,7 +99,7 @@ sp.Skeleton = cc.Class({
},

statics: {
RenderMode: RenderModeEnum,
RenderMode: RenderMode,
},

properties: {
Expand Down Expand Up @@ -288,10 +313,10 @@ sp.Skeleton = cc.Class({

// Record pre render mode.
_preRenderMode: -1,
_renderMode: RenderModeEnum.REALTIME,
_renderMode: RenderMode.REALTIME,
_defaultRenderMode: {
default: 0,
type: RenderModeEnum,
type: RenderMode,
notify () {
this.setRenderMode(this._defaultRenderMode);
},
Expand Down Expand Up @@ -545,7 +570,7 @@ sp.Skeleton = cc.Class({
}

if (CC_JSB) {
this._renderMode = RenderModeEnum.REALTIME;
this._renderMode = RenderMode.REALTIME;
}

this._updateSkeletonData();
Expand Down Expand Up @@ -582,7 +607,7 @@ sp.Skeleton = cc.Class({
*/
isCachedMode () {
if (CC_EDITOR) return false;
return this._renderMode !== RenderModeEnum.REALTIME;
return this._renderMode !== RenderMode.REALTIME;
},

update (dt) {
Expand Down Expand Up @@ -1218,9 +1243,9 @@ sp.Skeleton = cc.Class({
if (!data) return;

if (!CC_EDITOR) {
if (this._renderMode === RenderModeEnum.SHARED_CACHE) {
if (this._renderMode === RenderMode.SHARED_CACHE) {
this._skeletonCache = SkeletonCache.sharedCache;
} else if (this._renderMode === RenderModeEnum.PRIVATE_CACHE) {
} else if (this._renderMode === RenderMode.PRIVATE_CACHE) {
this._skeletonCache = new SkeletonCache;
}
}
Expand Down Expand Up @@ -1253,7 +1278,7 @@ sp.Skeleton = cc.Class({
},

_updateRenderModeEnum: CC_EDITOR && function () {
setEnumAttr(this, 'renderMode', RenderModeEnum);
setEnumAttr(this, 'renderMode', RenderMode);
},

_updateDebugDraw: function () {
Expand Down
5 changes: 3 additions & 2 deletions extensions/spine/skeleton-cache.js
Expand Up @@ -199,7 +199,7 @@ let AnimationCache = cc.Class({
frame.indices = indices;
},

fillVertices (skeletonColor, attachmentColor, slotColor, clipper) {
fillVertices (skeletonColor, attachmentColor, slotColor, clipper, slot) {

_tempa = slotColor.a * attachmentColor.a * skeletonColor.a * 255;
_tempr = attachmentColor.r * skeletonColor.r * 255;
Expand Down Expand Up @@ -285,6 +285,7 @@ let AnimationCache = cc.Class({
let texture;
let preSegOffset, preSegInfo;
let blendMode;
let slot;

for (let slotIdx = 0, slotCount = skeleton.drawOrder.length; slotIdx < slotCount; slotIdx++) {
slot = skeleton.drawOrder[slotIdx];
Expand Down Expand Up @@ -383,7 +384,7 @@ let AnimationCache = cc.Class({
attachmentColor = attachment.color;
slotColor = slot.color;

this.fillVertices(skeletonColor, attachmentColor, slotColor, clipper);
this.fillVertices(skeletonColor, attachmentColor, slotColor, clipper, slot);

if (_indexCount > 0) {
for (let ii = _indexOffset, nn = _indexOffset + _indexCount; ii < nn; ii++) {
Expand Down
14 changes: 7 additions & 7 deletions extensions/spine/spine-assembler.js
Expand Up @@ -68,13 +68,14 @@ let _finalColor32, _darkColor32;
let _vertexFormat;
let _perVertexSize;
let _perClipVertexSize;
let _vertexFloatCount = 0, _vertexFloatOffset = 0, _vertexOffset = 0,
_indexCount = 0, _indexOffset = 0;
let _vertexFloatCount = 0, _vertexCount = 0, _vertexFloatOffset = 0, _vertexOffset = 0,
_indexCount = 0, _indexOffset = 0, _vfOffset = 0;
let _tempr, _tempg, _tempb, _tempa;
let _inRange;
let _mustFlush;
let _x, _y, _m00, _m04, _m12, _m01, _m05, _m13;
let _r, _g, _b, _a, _fr, _fg, _fb, _fa, _dr, _dg, _db, _da;
let _r, _g, _b, _fr, _fg, _fb, _fa, _dr, _dg, _db, _da;
let _comp, _buffer, _renderer, _node, _needColor;

function _getSlotMaterial (tex, blendMode) {
let src, dst;
Expand Down Expand Up @@ -167,7 +168,7 @@ var spineAssembler = {
}
},

fillVertices (skeletonColor, attachmentColor, slotColor, clipper) {
fillVertices (skeletonColor, attachmentColor, slotColor, clipper, slot) {

let vbuf = _buffer._vData,
ibuf = _buffer._iData,
Expand Down Expand Up @@ -271,6 +272,7 @@ var spineAssembler = {
let attachment, attachmentColor, slotColor, uvs, triangles;
let isRegion, isMesh, isClip;
let offsetInfo;
let slot;

_slotRangeStart = _comp._startSlotIndex;
_slotRangeEnd = _comp._endSlotIndex;
Expand Down Expand Up @@ -353,7 +355,6 @@ var spineAssembler = {
_vertexFloatOffset = offsetInfo.byteOffset >> 2;
vbuf = _buffer._vData,
ibuf = _buffer._iData;
uintVData = _buffer._uintVData;

// compute vertex and fill x y
attachment.computeWorldVertices(slot.bone, vbuf, _vertexFloatOffset, _perVertexSize);
Expand Down Expand Up @@ -382,7 +383,6 @@ var spineAssembler = {
_vertexFloatOffset = offsetInfo.byteOffset >> 2;
vbuf = _buffer._vData,
ibuf = _buffer._iData;
uintVData = _buffer._uintVData;

// compute vertex and fill x y
attachment.computeWorldVertices(slot, 0, attachment.worldVerticesLength, vbuf, _vertexFloatOffset, _perVertexSize);
Expand All @@ -405,7 +405,7 @@ var spineAssembler = {
attachmentColor = attachment.color,
slotColor = slot.color;

this.fillVertices(skeletonColor, attachmentColor, slotColor, clipper);
this.fillVertices(skeletonColor, attachmentColor, slotColor, clipper, slot);

if (_indexCount > 0) {
for (let ii = _indexOffset, nn = _indexOffset + _indexCount; ii < nn; ii++) {
Expand Down

0 comments on commit 201e4e0

Please sign in to comment.