New to Spine. New to using Unity for 2d. Competent in Unity for 3d. Just doing simple tests in Unity to learn how to use the Spine API.
Trying to wrap my head around how to apply a skin serving as a normal map onto my skeleton. I clearly have some holes in my knowledge, but am willing to learn. I have read a lot of forum posts on here concerning this topic, and the closest I have come so far in finding what I need is the Mix and Match with Skins thread...
http://esotericsoftware.com/forum/Mix-and-Match-with-Skins-12850?p=57147&hilit=normal+map#p57147
Currently I am just playing around with a very simple skeleton that consists of a single square with some color on it as a diffuse/albedo map. I have a separate skin that holds the normal map. Both images are the same size and at the same position in Spine.
Spine setup:
I used export to get into Unity. Both skins are in the same atlas.
In the example I linked to, the code says:
Skin repackedSkin = prevSkin.GetRepackedSkin("Repacked skin", ...
I can only assume that prevSkin is referring to a previously defined skin to use as a normal map, but is never mentioned in the "mixAndMatchSkin" example or any other that I have found.
That said, here is the code I am using which is based off all the examples I have found so far and the error I am receiving. There is a little extraneous code in there, but that is just leftovers from me playing around to learn the API.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Spine.Unity;
using Spine.Unity.AttachmentTools;
public class NormalMappingTest : MonoBehaviour
{
SkeletonAnimation skeletonAnimation;
Spine.AnimationState animationState;
Spine.Skeleton skeleton;
Material runtimeMaterial;
Texture2D runtimeAtlas;
Texture2D[] additionalOutputTextures = null;
void Start()
{
skeletonAnimation = GetComponent<SkeletonAnimation>();
animationState = skeletonAnimation.AnimationState;
skeleton = skeletonAnimation.Skeleton;
var skeletonData = skeleton.Data;
Spine.Skin diffuseSkin = new Spine.Skin("diffuseSkin");
diffuseSkin.AddSkin(skeletonData.FindSkin("diffuse"));
Spine.Skin normalSkin = new Spine.Skin("normalSkin");
normalSkin.AddSkin(skeletonData.FindSkin("normal"));
int[] additionalTexturePropertyIDsToCopy = new int[] { Shader.PropertyToID("_BumpMap") };
Spine.Skin finishedSkin = normalSkin.GetRepackedSkin("finishedSkin", skeletonAnimation.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial, out runtimeMaterial, out runtimeAtlas, additionalTexturePropertyIDsToCopy: additionalTexturePropertyIDsToCopy, additionalOutputTextures: additionalOutputTextures);
skeleton.SetSkin(finishedSkin);
skeleton.SetSlotsToSetupPose();
animationState.Apply(skeleton);
}
}
And the null reference error from the GetRepackedSkin() method...
Help is appreciated. Also, seeing a simple, non-convoluted example that goes from start to finish would also be really helpful.
Thanks!