Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Masking separate attachments #41

Open
Kaloyancho opened this issue Aug 30, 2024 · 5 comments
Open

Masking separate attachments #41

Kaloyancho opened this issue Aug 30, 2024 · 5 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 });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants