Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Masking separate attachments #41

Closed
Kaloyancho opened this issue Aug 30, 2024 · 6 comments
Closed

Masking separate attachments #41

Kaloyancho opened this issue Aug 30, 2024 · 6 comments

Comments

@Kaloyancho
Copy link

Hello, in the old plugin for spine runtimes @pixi-spine all the attachments were placed inside of a containers which gave us the chance to mask different attachments with different masks, or apply mask from Pixi Graphic. Will this be added here ?
Also when clipping mask is applied from the spine file, not only the selected attachments are clipped but all above, I couldn't manage to figure a workaround, can you give me some tips ?

Cheers, Kaloyan.

P.S.: I've managed to create mixins for loading atlases from already loaded images (it was possible in the old plugin). If it's considered to be added I may provide PR so you have look around and merge it ?

@johnnotron
Copy link

P.S.: I've managed to create mixins for loading atlases from already loaded images (it was possible in the old plugin). If it's considered to be added I may provide PR so you have look around and merge it ?

Also would like to create TextureAtlas from Pixi textures already loaded from spritesheet.

@Kaloyancho
Copy link
Author

Yea, that's what i meant. We can call empty constructor TextureAtlas new TextureAtlas() and then pass textures to it, like the version in the pixi-spine extension. I may create PR.

@johnnotron
Copy link

Yea, that's what i meant. We can call empty constructor TextureAtlas new TextureAtlas() and then pass textures to it, like the version in the pixi-spine extension. I may create PR.

Would be great to see your mixin code! I need to do the same thing

@Kaloyancho
Copy link
Author

Yea, that's what i meant. We can call empty constructor TextureAtlas new TextureAtlas() and then pass textures to it, like the version in the pixi-spine extension. I may create PR.

Would be great to see your mixin code! I need to do the same thing

I wll make PR this weekend or maybe next week.

@Kaloyancho
Copy link
Author

Kaloyancho commented Sep 12, 2024

Hi, don't know how to make PR here so...

// mixins -> Creates atlas pages from all the images that we already have in the cache.
const p = TextureAtlas.prototype;
p.addTextureHash = function(textures: Map<string, Texture>, stripExtension: boolean) {
	for (const key in textures) {
		if (textures.hasOwnProperty(key)) {
			this.addTexture(stripExtension && key.indexOf('.') !== -1 ? key.substring(0, key.lastIndexOf('.')) : key, textures[key]);
		}
	}
};
p.addTexture = function(name: string, texture: Texture) {
	let page: TextureAtlasPage = this.pages.find((page: TextureAtlasPage) => page.baseTexture === texture.baseTexture) || null;

	// Sets the atlas page
	if (!page) {
		page = new TextureAtlasPage(name);

		const baseTexture = texture.baseTexture;

		page.baseTexture = baseTexture;
		page.width = baseTexture.width;
		page.height = baseTexture.height;

		page.minFilter = filterFromString(baseTexture.minFilter);
		page.magFilter = filterFromString(baseTexture.magFilter);
		page.uWrap = page.vWrap = wrapFromString(baseTexture.repeatMode);

		this.pages.push(page);
	}

	// Sets the region for the atlas page
	const region = new TextureAtlasRegion(page, name);

	region.index = -1;
	region.width = page.width;
	region.height = page.height;
	region.u = region.v = 0;
	region.u2 = region.v2 = 1;

	if (region.originalWidth == 0 && region.originalHeight == 0) {
		region.originalWidth = region.width;
		region.originalHeight = region.height;
	}

	this.regions.push(region);

	// Attaches the texture for each region
	const spineTexture = new SpineTexture(texture.baseTexture);
	page.setTexture(spineTexture);

	return region;
};
	
async load(images) {
	const spineAtlas = new TextureAtlas('');
	spineAtlas.addTextureHash(images, true);

	const skeletonAsset = await resource; // This may be json or skel
	const attachmentLoader = new AtlasAttachmentLoader(spineAtlas);

	const parser = skeletonAsset instanceof Uint8Array ? new SkeletonBinary(attachmentLoader) : new SkeletonJson(attachmentLoader);
	const skeletonData = parser.readSkeletonData(skeletonAsset);

	return new Spine({ skeletonData });
}

@Zyie
Copy link
Member

Zyie commented Nov 20, 2024

Hi

We have now moved this project to the official Esoteric Software repo for them to maintain. As a result we will be archiving this repo and closing all issues. If you still are having this issue please feel free to open an issue over on the new repo!

As for migrating between the projects it should be as simple as swapping out the imports from @pxi/spine-pixi to @esotericsoftware/spine-pixi-v8

@Zyie Zyie closed this as completed Nov 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants