Skip to content

Commit

Permalink
Search for textures in page property
Browse files Browse the repository at this point in the history
To support 4.0, textures are stored under the page property.
  • Loading branch information
epreston committed Sep 15, 2023
1 parent d0ce5a4 commit d603386
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions src/component/Spine.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,29 +254,38 @@ class Spine {
slot._active.type = ATTACHMENT_TYPE.MESH;
}

let texture = null;

// search for texture property if it exists
if (attachment.region) {
if (attachment.region.texture) {
texture = attachment.region.texture.pcTexture;
}
if (attachment.region.page && attachment.region.page.texture) {
texture = attachment.region.page.texture.pcTexture;
}
}

// create / assign material
if (attachment.region && attachment.region.texture) {
const texture = attachment.region.texture.pcTexture;
if (texture) {
if (texture instanceof pc.StandardMaterial) {
this._materials[texture.name] = texture;
slot.material = texture.name;
} else {
// get a unique key for the texture
let key = null;
if (texture.name) {
key = texture.name; // texture name might not be unique - should be resolved with content
} else if (texture.getSource() instanceof Image) {
key = texture.getSource().getAttribute('src');
}
if (key) {
// create a new material if required
if (this._materials[key] === undefined) {
const material = this.createMaterial(texture);
this._materials[key] = material;
}
slot.material = key;
if (texture) {
if (texture instanceof pc.StandardMaterial) {
this._materials[texture.name] = texture;
slot.material = texture.name;
} else {
// get a unique key for the texture
let key = null;
if (texture.name) {
key = texture.name; // texture name might not be unique - should be resolved with content
} else if (texture.getSource() instanceof Image) {
key = texture.getSource().getAttribute('src');
}
if (key) {
// create a new material if required
if (this._materials[key] === undefined) {
const material = this.createMaterial(texture);
this._materials[key] = material;
}
slot.material = key;
}
}
}
Expand Down

0 comments on commit d603386

Please sign in to comment.