Add dragonbones support.

This commit is contained in:
zhangbin
2016-09-02 14:57:34 +08:00
parent a68b4203e2
commit 3f94336b8c
12 changed files with 8968 additions and 1 deletions
+2
View File
@@ -47,6 +47,8 @@ if (!(CC_EDITOR && Editor.isMainProcess)) {
require('./extensions/spine');
require('./extensions/dragonbones');
if (!(CC_EDITOR && Editor.isMainProcess)) {
if (!CC_JSB) {
require('./cocos2d/actions');
@@ -0,0 +1,96 @@
/****************************************************************************
Copyright (c) 2016 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
var EventTarget = require('../../cocos2d/core/event/event-target');
dragonBones.CCArmatureDisplay = cc.Class({
name: 'dragonBones.CCArmatureDisplay',
extends: _ccsg.Node,
mixins: [EventTarget],
_armature : null,
_onClear : function () {
this._armature = null;
},
_dispatchEvent : function (eventObject) {
this.emit(eventObject.type, eventObject);
},
_debugDraw : function () {
if (!this._armature) {
return;
}
var bones = this._armature.getBones();
var drawingUtil = cc._drawingUtil;
for (var i = 0, l = bones.length; i < l; ++i) {
var bone = bones[i];
var boneLength = Math.max(bone.length, 5);
var startX = bone.globalTransformMatrix.tx;
var startY = bone.globalTransformMatrix.ty;
var endX = startX + bone.globalTransformMatrix.a * boneLength;
var endY = startY + bone.globalTransformMatrix.b * boneLength;
drawingUtil.setDrawColor(0, 0, 255, 255);
drawingUtil.setLineWidth(1);
drawingUtil.drawLine({x: startX, y:startY}, {x:endX, y:endY});
}
},
update : function (passedTime) {
if (this._armature) {
this._armature.advanceTime(passedTime);
}
},
advanceTimeBySelf : function (on) {
if (on) {
this.scheduleUpdate();
} else {
this.unscheduleUpdate();
}
},
hasEvent : function(type) {
return this.hasEventListener(type, false);
},
addEvent : function(type, listener, target) {
this.on(type, listener, target);
},
removeEvent : function(type, listener, target) {
this.off(type, listener, target);
},
armature : function() {
return this._armature;
},
animation : function () {
return this._armature.animation;
}
});
+134
View File
@@ -0,0 +1,134 @@
/****************************************************************************
Copyright (c) 2016 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
const BaseObject = dragonBones.BaseObject;
dragonBones.CCFactory = cc.Class({
name: 'dragonBones.CCFactory',
extends: dragonBones.BaseFactory,
buildArmatureDisplay : function (armatureName, dragonBonesName, skinName) {
var armature = this.buildArmature(armatureName, dragonBonesName, skinName);
var armatureDisplay = armature ? armature._display : null;
if (armatureDisplay) {
armatureDisplay.advanceTimeBySelf(true);
}
return armatureDisplay;
},
_generateTextureAtlasData : function (textureAtlasData, texture) {
if (! textureAtlasData) {
textureAtlasData = BaseObject.borrowObject(dragonBones.CCTextureAtlasData);
}
textureAtlasData.texture = texture;
return textureAtlasData;
},
_generateArmature : function (dataPackage) {
var armature = BaseObject.borrowObject(dragonBones.Armature);
var armatureDisplayContainer = new dragonBones.CCArmatureDisplay();
armature._armatureData = dataPackage.armature;
armature._skinData = dataPackage.skin;
armature._animation = BaseObject.borrowObject(dragonBones.Animation);
armature._display = armatureDisplayContainer;
armatureDisplayContainer._armature = armature;
armature._animation._armature = armature;
armature.animation.animations = dataPackage.armature.animations;
return armature;
},
_generateSlot : function (dataPackage, slotDisplayDataSet) {
var slot = BaseObject.borrowObject(dragonBones.CCSlot);
var slotData = slotDisplayDataSet.slot;
var displayList = [];
slot.name = slotData.name;
slot._rawDisplay = new _ccsg.Sprite();
slot._meshDisplay = slot._rawDisplay;
for (var i = 0, l = slotDisplayDataSet.displays.length; i < l; ++i) {
var displayData = slotDisplayDataSet.displays[i];
switch (displayData.type) {
case dragonBones.DisplayType.Image:
if (!displayData.texture) {
displayData.texture = this._getTextureData(dataPackage.dataName, displayData.name);
}
displayList.push(slot._rawDisplay);
break;
case dragonBones.DisplayType.Mesh:
if (!displayData.texture) {
displayData.texture = this._getTextureData(dataPackage.dataName, displayData.name);
}
if (cc._renderType === cc.game.RENDER_TYPE_WEBGL) {
// TODO mesh support
//if (!slot._meshDisplay) {
// slot._meshDisplay = new egret.Mesh();
//}
//
displayList.push(slot._meshDisplay);
} else {
displayList.push(slot._rawDisplay);
}
break;
case dragonBones.DisplayType.Armature:
var childArmature = this.buildArmature(displayData.name, dataPackage.dataName);
if (childArmature) {
if (!slot.inheritAnimation) {
var actions = slotData.actions.length > 0 ? slotData.actions : childArmature.armatureData.actions;
if (actions.length > 0) {
for (var j = 0, n = actions.length; j < n; ++j) {
childArmature._bufferAction(actions[j]);
}
} else {
childArmature.animation.play();
}
}
displayData.armature = childArmature.armatureData; //
}
displayList.push(childArmature);
break;
default:
displayList.push(null);
break;
}
}
slot._setDisplayList(displayList);
return slot;
}
});
+208
View File
@@ -0,0 +1,208 @@
/****************************************************************************
Copyright (c) 2016 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
dragonBones.CCSlot = cc.Class({
name: 'dragonBones.CCSlot',
extends: dragonBones.Slot,
_renderDisplay : null,
statics : {
toString: function () {
return "[class dragonBones.CCSlot]";
}
},
_onClear : function () {
dragonBones.Slot.prototype._onClear.call(this);
this._renderDisplay = null;
},
_onUpdateDisplay : function () {
if (!this._rawDisplay) {
this._rawDisplay = new _ccsg.Sprite;
}
this._renderDisplay = this._display || this._rawDisplay;
},
_initDisplay : function (value) {
},
_addDisplay : function () {
var container = this._armature._display;
container.addChild(this._renderDisplay);
},
_replaceDisplay : function (value) {
var container = this._armature._display;
var prevDisplay = value;
container.addChild(this._renderDisplay, prevDisplay.getLocalZOrder());
container.removeChild(prevDisplay);
},
_removeDisplay : function () {
this._renderDisplay.removeFromParent();
},
_disposeDisplay : function () {
},
_updateVisible : function () {
this._renderDisplay.setVisible(this._parent.visible);
},
_updateBlendMode : function () {
if (this._renderDisplay instanceof _ccsg.Sprite) {
switch (this._blendMode) {
case 0: // BlendMode Normal
break;
case 1: // BlendMode Add
var texture = this._renderDisplay.getTexture();
if (texture && texture.hasPremultipliedAlpha()) {
this._renderDisplay.setBlendFunc(BlendFactor.ONE, BlendFactor.ONE);
}
else {
this._renderDisplay.setBlendFunc(BlendFactor.SRC_ALPHA, BlendFactor.ONE);
}
break;
default:
break;
}
}
else if (this._childArmature) {
var childSlots = this._childArmature.getSlots();
for (var i = 0, l = childSlots.length; i < l; i++) {
var slot = childSlots[i];
slot._blendMode = this._blendMode;
slot._updateBlendMode();
}
}
},
_updateColor : function() {
this._renderDisplay.setOpacity(this._colorTransform.alphaMultiplier * 255);
var r = this._colorTransform.redMultiplier * 255;
var g = this._colorTransform.greenMultiplier * 255;
var b = this._colorTransform.blueMultiplier * 255;
this._renderDisplay.setColor(cc.color(r, g, b));
},
_updateFilters : function () {
},
_updateFrame : function () {
// update the frame
if (this._display && this._displayIndex >= 0) {
var rawDisplayData = this._displayIndex < this._displayDataSet.displays.length ? this._displayDataSet.displays[this._displayIndex] : null;
var replacedDisplayData = this._displayIndex < this._replacedDisplayDataSet.length ? this._replacedDisplayDataSet[this._displayIndex] : null;
var currentDisplayData = replacedDisplayData || rawDisplayData;
var currentTextureData = currentDisplayData.texture;
if (currentTextureData) {
var textureAtlasTexture = currentTextureData.parent.texture;
if (!currentTextureData.texture && textureAtlasTexture) {
// Create and cache texture
var rect = cc.rect(currentTextureData.region.x, currentTextureData.region.y,
currentTextureData.region.width, currentTextureData.region.height);
var offset = cc.p(0, 0);
var size = cc.size(currentTextureData.region.width, currentTextureData.region.height);
currentTextureData.texture = new cc.SpriteFrame();
currentTextureData.texture.setTexture(textureAtlasTexture, rect, false, offset, size);
}
var currentTexture = this._armature._replacedTexture || (currentTextureData.texture ? currentTextureData.texture.getTexture() : null);
if (currentTexture) {
if (this._meshData && this._display === this._meshDisplay) {
// TODO update the frame for mesh type
//var region = currentTextureData.region;
//var textureAtlasSize = currentTextureData.texture.getTexture().getContentSize();
//var displayVertices = new cc.V3F_C4B_T2F()
}
else {
var pivot = cc.p(currentDisplayData.pivot.x, currentDisplayData.pivot.y);
var rectData = currentTextureData.frame || currentTextureData.region;
var width = rectData.width;
var height = rectData.height;
if (!currentTextureData.frame && currentTextureData.rotated) {
width = rectData.height;
height = rectData.width;
}
if (currentDisplayData.isRelativePivot) {
pivot.x *= width;
pivot.y *= height;
}
if (currentTextureData.frame) {
pivot.x += currentTextureData.frame.x;
pivot.y += currentTextureData.frame.y;
}
if (rawDisplayData && rawDisplayData !== currentDisplayData) {
pivot.x += rawDisplayData.transform.x - currentDisplayData.transform.x;
pivot.y += rawDisplayData.transform.y - currentDisplayData.transform.y;
}
pivot.x = pivot.x / currentTextureData.region.width;
pivot.y = 1 - pivot.y / currentTextureData.region.height;
this._rawDisplay.setSpriteFrame(currentTextureData.texture);
if (currentTexture !== currentTextureData.texture.getTexture()) {
this._rawDisplay.setTexture(currentTexture);
}
this._rawDisplay.setAnchorPoint(pivot);
}
this._updateVisible();
return;
}
}
}
this._rawDisplay.setTexture(null);
this._rawDisplay.setTextureRect(cc.rect(0, 0, 0, 0));
this._rawDisplay.setAnchorPoint(cc.p(0, 0));
this._rawDisplay.setVisible(false);
},
_updateMesh : function() {
// TODO update the mesh
},
_updateTransform : function () {
// update the transform
if (this._renderDisplay) {
this.global.fromMatrix(this.globalTransformMatrix);
this._renderDisplay.setScale(this.global.scaleX, this.global.scaleY);
// TODO support skew
//this._renderDisplay.setRotationSkewX(this.global.skewX * dragonBones.DragonBones.RADIAN_TO_ANGLE);
//this._renderDisplay.setRotationSkewY(this.global.skewY * dragonBones.DragonBones.RADIAN_TO_ANGLE);
this._renderDisplay.setPosition(this.global.x, -this.global.y);
}
}
});
+64
View File
@@ -0,0 +1,64 @@
/****************************************************************************
Copyright (c) 2016 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
dragonBones.CCTextureAtlasData = cc.Class({
name: 'dragonBones.CCTextureAtlasData',
extends: dragonBones.TextureAtlasData,
texture : null,
statics : {
toString : function() {
return "[class dragonBones.CCTextureAtlasData]";
}
},
_onClear : function() {
dragonBones.TextureAtlasData.prototype._onClear.call(this);
this.texture = null;
},
generateTextureData : function() {
return dragonBones.BaseObject.borrowObject(dragonBones.CCTextureData);
}
});
dragonBones.CCTextureData = cc.Class({
name: 'dragonBones.CCTextureData',
extends: dragonBones.TextureData,
texture: null,
statics : {
toString : function() {
return "[class dragonBones.CCTextureData]";
}
},
_onClear : function() {
dragonBones.TextureData.prototype._onClear.call(this);
if (this.texture) {
this.texture.dispose();
this.texture = null;
}
}
});
+113
View File
@@ -0,0 +1,113 @@
/****************************************************************************
Copyright (c) 2016 Chukong Technologies Inc.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Chukong Aipu reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
var DragonBonesAsset = cc.Class({
name: 'dragonBones.DragonBonesAsset',
extends: cc.Asset,
ctor: function () {
},
properties: {
_dragonBonesJson : '',
dragonBonesJson : {
get: function () {
return this._dragonBonesJson;
},
set: function (value) {
this._dragonBonesJson = value;
this.reset();
}
}
},
createNode: function (callback) {
// TODO create node with dragonbones asset
return callback(new Error('it is not supported now'));
//var node = new cc.Node(this.name);
//var skeleton = node.addComponent(sp.Skeleton);
//skeleton.skeletonData = this;
//
//return callback(null, node);
},
reset : function() {
if (CC_EDITOR) {
this._dragonBonesDataCache = null;
this._armaturesEnum = null;
}
},
// EDITOR
getRuntimeData: CC_EDITOR && function () {
if (!this._dragonBonesDataCache) {
var factory = new dragonBones.CCFactory();
this._dragonBonesDataCache = factory.parseDragonBonesData(this._dragonBonesJson);
}
return this._dragonBonesDataCache;
},
getArmatureEnum: CC_EDITOR && function () {
if (this._armaturesEnum) {
return this._armaturesEnum;
}
var data = this.getRuntimeData();
if (data) {
var armatureNames = data._armatureNames;
var enumDef = {};
for (var i = 0; i < armatureNames.length; i++) {
var name = armatureNames[i];
enumDef[name] = i;
}
return this._armaturesEnum = cc.Enum(enumDef);
}
return null;
},
getAnimsEnum: CC_EDITOR && function (armatureName) {
var data = this.getRuntimeData(true);
if (data) {
var armature = data.getArmature(armatureName);
if (!armature) {
return null;
}
var enumDef = { '<None>': 0 };
var anims = armature.animations;
var i = 0;
for (var animName in anims) {
if (anims.hasOwnProperty(animName)) {
enumDef[animName] = i + 1;
}
}
return cc.Enum(enumDef);
}
return null;
},
});
dragonBones.DragonBonesAsset = module.exports = DragonBonesAsset;
@@ -0,0 +1,68 @@
/****************************************************************************
Copyright (c) 2016 Chukong Technologies Inc.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Chukong Aipu reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
var DragonBonesAtlasAsset = cc.Class({
name: 'dragonBones.DragonBonesAtlasAsset',
extends: cc.Asset,
properties: {
_atlasJson : '',
/**
* @property {string} atlasJson
*/
atlasJson: {
get: function () {
return this._atlasJson;
},
set: function (value) {
this._atlasJson = value;
}
},
/**
* @property {cc.Texture2D} texture
*/
texture: {
default: '',
url: cc.Texture2D
},
},
ctor: function () {
},
createNode: function (callback) {
// TODO create node with dragonbones atlas asset
return callback(new Error('it is not supported now'));
//var node = new cc.Node(this.name);
//var skeleton = node.addComponent(sp.Skeleton);
//skeleton.skeletonData = this;
//
//return callback(null, node);
},
});
dragonBones.DragonBonesAtlasAsset = module.exports = DragonBonesAtlasAsset;
@@ -0,0 +1,98 @@
/****************************************************************************
Copyright (c) 2016 Chukong Technologies Inc.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Chukong Aipu reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
const Fs = require('fire-fs');
const Path = require('fire-path');
const DRAGONBONES_ENCODING = { encoding: 'utf-8' };
const CustomAssetMeta = Editor.metas['custom-asset'];
class DragonBonesAtlasMeta extends CustomAssetMeta {
constructor (assetdb) {
super(assetdb);
this.atlasJson = '';
this.texture = '';
}
static version () { return '1.0.0'; }
static defaultType () {
return 'dragonbones-atlas';
}
static validate (assetpath) {
var json;
var text = Fs.readFileSync(assetpath, 'utf8');
try {
json = JSON.parse(text);
}
catch (e) {
return false;
}
return typeof json.imagePath === 'string' && Array.isArray(json.SubTexture);
}
postImport (fspath, cb) {
Fs.readFile(fspath, DRAGONBONES_ENCODING, (err, data) => {
if (err) {
return cb(err);
}
var json;
try {
json = JSON.parse(data);
}
catch (e) {
return cb(e);
}
// record the raw file data
this.atlasJson = data;
// parse the depended texture
var imgPath = Path.resolve(Path.dirname(fspath), json.imagePath);
var uuid = this._assetdb.fspathToUuid(imgPath);
if (uuid) {
console.log('UUID is initialized for "%s".', imgPath);
this.texture = uuid;
}
else if (!Fs.existsSync(imgPath)) {
Editor.error('Can not find texture "%s" for atlas "%s"', json.imagePath, fspath);
}
else {
// AssetDB may call postImport more than once, we can get uuid in the next time.
console.warn('WARN: UUID not yet initialized for "%s".', json.imagePath);
}
var asset = new dragonBones.DragonBonesAtlasAsset();
asset.name = Path.basenameNoExt(fspath);
asset.atlasJson = this.atlasJson;
asset.texture = Editor.assetdb.uuidToUrl(this.texture);
this._assetdb.saveAssetToLibrary(this.uuid, asset);
cb();
});
}
}
module.exports = DragonBonesAtlasMeta;
@@ -0,0 +1,72 @@
/****************************************************************************
Copyright (c) 2016 Chukong Technologies Inc.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Chukong Aipu reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
const Fs = require('fire-fs');
const Path = require('fire-path');
const DRAGONBONES_ENCODING = { encoding: 'utf-8' };
const CustomAssetMeta = Editor.metas['custom-asset'];
class DragonBonesMeta extends CustomAssetMeta {
constructor (assetdb) {
super(assetdb);
this.dragonBonesJson = '';
}
static version () { return '1.0.0'; }
static defaultType () {
return 'dragonbones';
}
static validate (assetpath) {
var json;
var text = Fs.readFileSync(assetpath, 'utf8');
try {
json = JSON.parse(text);
}
catch (e) {
return false;
}
return Array.isArray(json.armature);
}
import (fspath, cb) {
Fs.readFile(fspath, DRAGONBONES_ENCODING, (err, data) => {
if (err) {
return cb(err);
}
this.dragonBonesJson = data;
var asset = new dragonBones.DragonBonesAsset();
asset.name = Path.basenameNoExt(fspath);
asset.dragonBonesJson = this.dragonBonesJson;
this._assetdb.saveAssetToLibrary(this.uuid, asset);
cb();
});
}
}
module.exports = DragonBonesMeta;
+62
View File
@@ -0,0 +1,62 @@
/****************************************************************************
Copyright (c) 2016 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
/**
* !#en
* The global main namespace of DragonBones, all classes, functions,
* properties and constants of DragonBones are defined in this namespace
* !#zh
* DragonBones 的全局的命名空间,
* 与 DragonBones 相关的所有的类,函数,属性,常量都在这个命名空间中定义。
* @module db
* @main db
*/
/*
* Reference:
* http://dragonbones.com/cn/index.html
*/
dragonBones = CC_JSB ? dragonBones : require('./lib/dragonBones');
dragonBones.DisplayType = {
Image : 0,
Armature : 1,
Mesh : 2
};
if (!CC_EDITOR || !Editor.isMainProcess) {
if (!CC_JSB) {
require('./CCFactory');
require('./CCSlot');
require('./CCTextureData');
require('./CCArmatureDisplay');
}
// TODO require the component for dragonbones
}
require('./DragonBonesAsset');
require('./DragonBonesAtlasAsset');
File diff suppressed because it is too large Load Diff
+6 -1
View File
@@ -83,7 +83,12 @@ var jsbSkipModules = [
'../../extensions/spine/SGSkeletonAnimation',
'../../extensions/spine/SGSkeletonCanvasRenderCmd',
'../../extensions/spine/SGSkeletonWebGLRenderCmd',
'../../extensions/spine/lib/spine'
'../../extensions/spine/lib/spine',
'../../extensions/dragonbones/lib/dragonBones',
'../../extensions/dragonbones/CCFactory',
'../../extensions/dragonbones/CCArmatureDisplay',
'../../extensions/dragonbones/CCSlot',
'../../extensions/dragonbones/CCTextureData'
];
gulp.task('build-jsb-extends-dev', function (done) {