- 수정됨
Mix and Match with Skins
I've studying about the project mix and match, but the way is done is not exactly what I was expecting.
What the project does is just get an image from unity and swap with one of the images inside the skeleton.
What I expeted is that when I change the skins and combine it, they see what images I'm using from the atlas and create a new atlas from this images, not from unity, but directly from the spine atlas.
Because what I need today is not just swap images, but each skin there is your own mesh, animations and sprites.
In fact for me the best way was Spine didn't create an atlas at all, import the folder with separated images into Unity, than when combine a skin, like golden helmet with silver chest, they get the image from this folder and generate an atlas in runtime.
Is it possible?
We are sorry for the confusion, thanks for the feedback. We will add a new example scene that shows combining skins for more clarity.
MichelVictor wroteWhat I expeted is that when I change the skins and combine it, they see what images I'm using from the atlas and create a new atlas from this images, not from unity, but directly from the spine atlas.
This is what happens actually, it will use the used items and create a new atlas from it, regardless where they come from.
Use e.g. the following code to combine multiple skins to a new skin, packed to a single atlas texture from one or more Spine atlas source textures:
private void Start () {
var skeleton = skeletonAnimation.Skeleton;
var skeletonData = skeleton.data;
var mixAndMatchSkin = new Skin("custom-girl");
mixAndMatchSkin.AddSkin(skeletonData.FindSkin("skin-base"));
mixAndMatchSkin.AddSkin(skeletonData.FindSkin("nose/short"));
mixAndMatchSkin.AddSkin(skeletonData.FindSkin("eyelids/girly"));
mixAndMatchSkin.AddSkin(skeletonData.FindSkin("eyes/violet"));
mixAndMatchSkin.AddSkin(skeletonData.FindSkin("hair/brown"));
mixAndMatchSkin.AddSkin(skeletonData.FindSkin("clothes/hoodie-orange"));
mixAndMatchSkin.AddSkin(skeletonData.FindSkin("legs/pants-jeans"));
mixAndMatchSkin.AddSkin(skeletonData.FindSkin("accessories/bag"));
mixAndMatchSkin.AddSkin(skeletonData.FindSkin("accessories/hat-red-yellow"));
bool repack = true;
if (repack) {
Material runtimeMaterial;
Texture2D runtimeAtlas;
Skin repackedSkin = mixAndMatchSkin.GetRepackedSkin("Repacked skin", skeletonAnimation.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial, out runtimeMaterial, out runtimeAtlas);
mixAndMatchSkin.Clear();
// Use the repacked skin.
skeletonAnimation.Skeleton.Skin = repackedSkin;
skeletonAnimation.Skeleton.SetSlotsToSetupPose();
skeletonAnimation.AnimationState.Apply(skeletonAnimation.Skeleton);
}
else {
skeleton.SetSkin(mixAndMatchSkin);
skeleton.SetSlotsToSetupPose();
}
}
You can also find a list of references regarding the new Skin API and the Mix and Match
Spine project here posted by Nate: Combining Skins
Note that this does not include the repacking step (which is added in the code above), which is spine-unity specific.
Coool! I was already giving up about repack, glad to know that it can be done!
I'll try it later and see if I can make it work!
All my sprites have a normalmap, there is a way to repack a normalmap atlas too?
MichelVictor wroteAll my sprites have a normalmap, there is a way to repack a normalmap atlas too?
There you have hit a current weak spot unfortunately, currently repacking skins only re-assembles the main atlas textures.
I have created an issue ticket here, it should not take too long to come up with a solution for this:
[unity] GetRepackedSkin does not include normal maps · #1519
If you are in a hurry, what should work as a quick workaround in the meantime is to exchange textures at the input materials, to assign the normal maps as primary textures and then run repacking.
Thank you! I'll wait for that!
I have added additional optional parameters to the existing GetRepackedSkin()
methods, so that you can now specity additional texture properties that shall be copied as well:
Material runtimeMaterial;
Texture2D runtimeAtlas;
Texture2D[] additionalOutputTextures = null;
int[] additionalTexturePropertyIDsToCopy = new int[] { Shader.PropertyToID("_BumpMap") };
Skin repackedSkin = prevSkin.GetRepackedSkin("Repacked skin", skeletonAnimation.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial, out runtimeMaterial, out runtimeAtlas,
additionalTexturePropertyIDsToCopy : additionalTexturePropertyIDsToCopy, additionalOutputTextures : additionalOutputTextures);
// Use the repacked skin.
skeletonAnimation.Skeleton.Skin = repackedSkin;
skeletonAnimation.Skeleton.SetSlotsToSetupPose();
skeletonAnimation.AnimationState.Apply(skeletonAnimation.Skeleton);
Passing int[] additionalTexturePropertyIDsToCopy = new int[] { Shader.PropertyToID("_BumpMap") };
as parameter will therefore repack the main texture and the normal map, with the normal map property typically named "_BumpMap". Note that this name is the property name in the shader, not the pretty "Normal Map" label string shown in the inspector.
You can download the updated unitypackages here as usual:
Spine Unity Download
Please let us know if this now provides everything that you need for repacking for your normal-map based shader.