Skip to content

Commit

Permalink
Merge pull request cocos#21 from sunnylanwanjun/v211
Browse files Browse the repository at this point in the history
V211 spine and dragonbones
  • Loading branch information
pandamicro authored Jan 16, 2019
2 parents 45bae93 + 6ca0729 commit 880bea1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion extensions/dragonbones/ArmatureDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ let ArmatureDisplay = cc.Class({

// override
_updateMaterial (material) {
this._super(material);
this.setMaterial(0, material);
this._materialCache = {};
},

Expand Down
2 changes: 1 addition & 1 deletion extensions/dragonbones/webgl-assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

const Armature = require('./ArmatureDisplay');
const RenderFlow = require('../../cocos2d/core/renderer/render-flow');
const gfx = require('../../cocos2d/renderer/gfx');
const Material = require('../../cocos2d/core/assets/material/CCMaterial');
const gfx = cc.gfx;

let _boneColor = cc.color(255, 0, 0, 255);
let _slotColor = cc.color(0, 0, 255, 255);
Expand Down
10 changes: 7 additions & 3 deletions extensions/spine/Skeleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,21 +376,25 @@ sp.Skeleton = cc.Class({
this._rootBone = null;
this._listener = null;
this._boundingBox = cc.rect();
this._material = Material.getInstantiatedBuiltinMaterial('spine', this);
this._materialCache = {};
this._debugRenderer = null;
this._startSlotIndex = -1;
this._endSlotIndex = -1;
},

onLoad() {
var material = Material.getInstantiatedBuiltinMaterial('spine', this);
this.setMaterial(0, material);
},

// override
_updateMaterial (material) {
this._super(material);
this.setMaterial(0, material);
this._materialCache = {};
},

_updateUseTint () {
var cache = this._materialCache
var cache = this._materialCache;
for (var mKey in cache) {
var material = cache[mKey];
if (material) {
Expand Down
23 changes: 7 additions & 16 deletions extensions/spine/spine-assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@
const Skeleton = require('./Skeleton');
const spine = require('./lib/spine');
const RenderFlow = require('../../cocos2d/core/renderer/render-flow');
const Material = require('../../cocos2d/core/assets/material/CCMaterial');
const VertexFormat = require('../../cocos2d/core/renderer/webgl/vertex-format')
const VFOneColor = VertexFormat.vfmtPosUvColor;
const VFTwoColor = VertexFormat.vfmtPosUvTwoColor;
import gfx from '../../cocos2d/renderer/gfx';
const gfx = cc.gfx;

let _quadTriangles = [0, 1, 2, 2, 3, 0];
let _slotColor = cc.color(0, 0, 255, 255);
Expand Down Expand Up @@ -87,21 +86,16 @@ function _getSlotMaterial (comp, slot, tex) {
}

let key = tex.url + src + dst;
comp._material = comp._material || Material.getInstantiatedBuiltinMaterial('spine', comp);
let baseMaterial = comp._material;
let baseMaterial = comp.sharedMaterials[0];
if (!baseMaterial) return null;

let materialCache = comp._materialCache;
let material = materialCache[key];
if (!material) {
var baseKey = baseMaterial.getHash();
if (!materialCache[baseKey]) {
material = baseMaterial;
} else {
material = new Material();
material.copy(baseMaterial);
}

material = new cc.Material();
material.copy(baseMaterial);
material.define('_USE_MODEL', true);
material.define('USE_TEXTURE', true);
material.define('USE_TINT', _useTint);
// update texture
material.setProperty('texture', tex);

Expand All @@ -118,9 +112,6 @@ function _getSlotMaterial (comp, slot, tex) {
materialCache[key] = material;
}
else if (material.getProperty('texture') !== tex) {
if (materialCache[material._hash]) {
delete materialCache[material._hash];
}
material.setProperty('texture', tex);
material.updateHash(key);
materialCache[key] = material;
Expand Down

0 comments on commit 880bea1

Please sign in to comment.