I am too sorry for the late reply.
Currently I combine everything inside my CharacterVisual script.
So this is my CharacterVisuals script Im using.
using System;
using Anisoft.Character;
using Anisoft.Game.Entity.Skin;
using Spine;
using Spine.Unity;
using Spine.Unity.AttachmentTools;
using UnityEngine;
namespace Anisoft.Behaviors.Character {
[RequireComponent(typeof(CharacterB))]
public class CharacterVisualsB: MonoBehaviour {
private SkeletonAnimation _skeletonAnimation;
private CharacterB CharacterRef { get; set; } = null;
public GameObject visuals;
public Material sourceMaterial;
public Material blankMaterial;
public Skin[] skinParts;
public Skin customSkin;
[Header("Do not assign")] public Texture2D runtimeAtlas;
public Material runtimeMaterial;
public Texture2D[] additionalOutputTextures = null;
public int[] additionalTexturePropertyIDsToCopy = new int[] { Shader.PropertyToID("_BumpMap") };
private bool _refreshTexture = true;
public void Setup(CharacterB character) {
skinParts = new Skin[Enum.GetValues(typeof(SkinType)).Length];
CharacterRef = character;
CharacterRef.UpdateVisuals += RefreshVisuals;
_skeletonAnimation = visuals.GetComponent<SkeletonAnimation>();
}
private void RefreshVisuals() {
RefreshSkin();
RefreshSkinTexture();
}
private void RefreshSkin() {
var skinPartsSlots= CharacterRef.DataActor.dataSkinPartSlots;
var skeleton = _skeletonAnimation.Skeleton;
var templateSkin = skeleton.Data.FindSkin("base").GetClone();
customSkin = customSkin ?? new Skin("Custom Skin");
customSkin.AddAttachments(templateSkin);
for (var index = 0; index < skinPartsSlots.Length; index++) {
var skinPart = skinPartsSlots[index];
if (skinPart == null || skinPart.Name == (skinParts[index]?.Name)) continue;
var skin = new Skin(skinPart.Name);
foreach (var subParts in skinPart.subParts) {
var attachKey = subParts.attachKey;
var attachSlot = subParts.attachSlot;
var slotIndex = skeleton.FindSlotIndex(attachSlot);
var attachSprite = subParts.attachSprite;
var templateAttachment = templateSkin.GetAttachment(slotIndex, attachKey);
var newAttachment = templateAttachment.GetRemappedClone(attachSprite, blankMaterial,
false, false, true);
skin.SetAttachment(slotIndex, attachKey, newAttachment);
}
customSkin.AddAttachments(skin);
skinParts[index] = skin;
_refreshTexture = true;
}
}
private void RefreshSkinTexture() {
if (!_refreshTexture) return;
var skeleton = _skeletonAnimation.Skeleton;
customSkin = customSkin.GetRepackedSkin("custom skin", sourceMaterial,
out runtimeMaterial, out runtimeAtlas,2048,
additionalTexturePropertyIDsToCopy : additionalTexturePropertyIDsToCopy, additionalOutputTextures : additionalOutputTextures);
skeleton.SetSkin(customSkin);
_refreshTexture = false;
}
}
}
Which looks like the following in the inspector
What I'm trying to do is build a custom skin + normals from a base skin (using a texture atlas and normal texture atlas)
and then on top apply separate attachments that each have their own texture/normals
One issue I found is that if I assign a material that doesn't have a normal, I get an error about missing textures.
//inspector
//base texture settings
//error
So i tested out just using the same material with the same normals for each (for testing)
And it... sorta worked but resulted in an incorrect normalmap.
I will note that it wouldn't allow me to combine the textures unless they matched formats. So I changed it to the only uncompressed format I could RGBA 32 bit
And it seems like when I check the channels... the GBA have texture but the R doesn't... so it seems like it copied the colors to the wrong channels based on what i did?
So its pretty evident I don't know what I'm doing just yet lol. I'm try to get some sleep and tackle it more later tmw. I hope I've provided some info as to what I'm trying to pull off here.
I tested not combining the skin and it appears the seperate attachment with a placeholder normal worked fine.|
Separate attachments
Combined skin attachments
The combined skin doesn't apply the normal correctly
Looking at the combined texture it seems the rgba aren't correct for me. Its placing the channels of the normal texture in gba instead of rgb.
The added normal is the little square of noise in the middle right.