mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
@@ -36,3 +36,4 @@ require('../textures/CCTexture2D');
|
||||
require('./CCTTFFont');
|
||||
require('./CCSpriteAnimation');
|
||||
require('./CCSpriteAtlas');
|
||||
//require('./CCTextAsset');
|
||||
|
||||
@@ -287,15 +287,29 @@ sp.Skeleton = cc.Class({
|
||||
this._refresh();
|
||||
},
|
||||
|
||||
//onEnable: function () {
|
||||
// this._super();
|
||||
//},
|
||||
|
||||
_createSgNode: function () {
|
||||
if (this.skeletonData/* && self.atlasFile*/) {
|
||||
var data = this.skeletonData.getRuntimeData();
|
||||
if (data) {
|
||||
return new sp._SGSkeletonAnimation(data, null, this.skeletonData.scale);
|
||||
if (CC_JSB) {
|
||||
var uuid = this.skeletonData._uuid;
|
||||
if ( !uuid ) {
|
||||
cc.error('Can not render dynamic created SkeletonData');
|
||||
return null;
|
||||
}
|
||||
var jsonFile = cc.AssetLibrary.getImportedDir(uuid) + '/' + uuid + '.raw.json';
|
||||
var atlasFile = this.skeletonData.atlasUrl;
|
||||
if (atlasFile) {
|
||||
if (typeof atlasFile !== 'string') {
|
||||
cc.error('Invalid type of atlasFile, atlas should be registered as raw asset.');
|
||||
return null;
|
||||
}
|
||||
return new sp._SGSkeletonAnimation(jsonFile, atlasFile, this.skeletonData.scale);
|
||||
}
|
||||
}
|
||||
else {
|
||||
var data = this.skeletonData.getRuntimeData();
|
||||
if (data) {
|
||||
return new sp._SGSkeletonAnimation(data, null, this.skeletonData.scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -119,6 +119,13 @@ var SkeletonData = cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
// Fallback to raw asset for JSB -------------------
|
||||
atlasUrl: {
|
||||
default: '',
|
||||
url: cc.RawAsset
|
||||
},
|
||||
// -------------------------------------------------
|
||||
|
||||
/**
|
||||
* @property {cc.Texture2D} textures
|
||||
*/
|
||||
@@ -179,7 +186,7 @@ var SkeletonData = cc.Class({
|
||||
* @param {boolean} [quiet=false]
|
||||
* @return {spine.SkeletonData}
|
||||
*/
|
||||
getRuntimeData: function (quiet) {
|
||||
getRuntimeData: !CC_JSB && function (quiet) {
|
||||
if (this._skeletonCache) {
|
||||
return this._skeletonCache;
|
||||
}
|
||||
@@ -251,7 +258,7 @@ var SkeletonData = cc.Class({
|
||||
* @return {spine.Atlas}
|
||||
* @private
|
||||
*/
|
||||
_getAtlas: function (quiet) {
|
||||
_getAtlas: !CC_JSB && function (quiet) {
|
||||
if (this._atlasCache) {
|
||||
return this._atlasCache;
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ class SpineMeta extends CustomAssetMeta {
|
||||
constructor (assetdb) {
|
||||
super(assetdb);
|
||||
this.textures = [];
|
||||
this.atlas = '';
|
||||
this.scale = 1;
|
||||
}
|
||||
|
||||
@@ -93,7 +94,7 @@ class SpineMeta extends CustomAssetMeta {
|
||||
//this.textures[0] = value;
|
||||
}
|
||||
|
||||
static version () { return '1.0.0'; }
|
||||
static version () { return '1.0.1'; }
|
||||
static defaultType () {
|
||||
return 'spine';
|
||||
}
|
||||
@@ -123,9 +124,17 @@ class SpineMeta extends CustomAssetMeta {
|
||||
return false;
|
||||
}
|
||||
|
||||
dests () {
|
||||
var res = super.dests();
|
||||
// for JSB
|
||||
res.push(this._assetdb._uuidToImportPathNoExt(this.uuid) + '.raw.json');
|
||||
if (this.atlas) {
|
||||
res.push(this._assetdb._uuidToImportPathNoExt(this.atlas) + '.atlas');
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
import (fspath, cb) {
|
||||
var self = this;
|
||||
|
||||
Fs.readFile(fspath, SPINE_ENCODING, (err, data) => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
@@ -149,6 +158,8 @@ class SpineMeta extends CustomAssetMeta {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
var db = this._assetdb;
|
||||
|
||||
// parse atlas textures
|
||||
var textureParser = new TextureParser(res.atlasPath);
|
||||
try {
|
||||
@@ -167,10 +178,21 @@ class SpineMeta extends CustomAssetMeta {
|
||||
|
||||
//
|
||||
asset.atlasText = res.data;
|
||||
|
||||
|
||||
// save raw assets for JSB..
|
||||
|
||||
var atlasUuid = db.fspathToUuid(res.atlasPath);
|
||||
asset.atlasUrl = db.uuidToUrl(atlasUuid);
|
||||
|
||||
var rawJsonPath = db._uuidToImportPathNoExt(this.uuid) + '.raw.json';
|
||||
db.mkdirForAsset(rawJsonPath);
|
||||
Fs.copySync(fspath, rawJsonPath);
|
||||
|
||||
this.atlas = atlasUuid; // save for dest()
|
||||
|
||||
//
|
||||
self._assetdb.saveAssetToLibrary(self.uuid, asset);
|
||||
|
||||
|
||||
db.saveAssetToLibrary(this.uuid, asset);
|
||||
cb();
|
||||
});
|
||||
});
|
||||
|
||||
+17
-15
@@ -35,7 +35,7 @@
|
||||
* http://en.esotericsoftware.com/spine-using-runtimes
|
||||
*/
|
||||
|
||||
sp = {};
|
||||
sp = CC_JSB ? sp : {};
|
||||
|
||||
// The vertex index of spine.
|
||||
sp.VERTEX_INDEX = {
|
||||
@@ -84,20 +84,22 @@ sp.AnimationEventType = cc.Enum({
|
||||
* @module sp
|
||||
*/
|
||||
|
||||
if (!CC_JSB && (!CC_EDITOR || !Editor.isCoreLevel)) {
|
||||
|
||||
/**
|
||||
* The official spine runtime.
|
||||
* See http://en.esotericsoftware.com/spine-using-runtimes
|
||||
* @property {object} spine
|
||||
*/
|
||||
sp.spine = require('./lib/spine');
|
||||
|
||||
require('./SGSkeleton');
|
||||
require('./SGSkeletonCanvasRenderCmd');
|
||||
require('./SGSkeletonWebGLRenderCmd');
|
||||
require('./SGSkeletonAnimation');
|
||||
|
||||
if (!CC_EDITOR || !Editor.isCoreLevel) {
|
||||
|
||||
if (!CC_JSB) {
|
||||
/**
|
||||
* The official spine runtime.
|
||||
* See http://en.esotericsoftware.com/spine-using-runtimes
|
||||
* @property {object} spine
|
||||
*/
|
||||
sp.spine = require('./lib/spine');
|
||||
|
||||
require('./SGSkeleton');
|
||||
require('./SGSkeletonCanvasRenderCmd');
|
||||
require('./SGSkeletonWebGLRenderCmd');
|
||||
require('./SGSkeletonAnimation');
|
||||
}
|
||||
|
||||
require('./SkeletonData');
|
||||
require('./Skeleton');
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ require('./jsb-scale9sprite');
|
||||
require('./jsb-label');
|
||||
require('./jsb-editbox');
|
||||
require('./jsb-particle');
|
||||
require('./jsb-spine');
|
||||
require('./jsb-enums');
|
||||
require('./jsb-event');
|
||||
require('./jsb-action');
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
sp._SGSkeleton = sp.Skeleton;
|
||||
sp._SGSkeletonAnimation = sp.SkeletonAnimation;
|
||||
sp.ANIMATION_EVENT_TYPE = null;
|
||||
Reference in New Issue
Block a user