• RuntimesUnity
  • 스파인 슬롯에서 메시어태치먼트, 텍스쳐를 따로따로 선택해서 아바타를 만들고 싶습니다.

스파인에디터에서 슬롯안에 리전 어태치먼트만 사용하고 있습니다.
베이스 캐릭터에 수백개의 슬롯이 있고, 각각의 슬롯에는 더미 리전 어태치먼트(1x1 dummy pixel texture)가 붙어있습니다.

아바타 시스템을 만들기위해 슬롯에 리전 어태치먼트를 찾아서 더미 텍스처를 교체하고 교체한 텍스처들을 런타임에서 아틀라스로 패킹하여 사용하고 있습니다. ex) 상의 슬롯 [상의1] RegionAttachment 텍스처[상의1텍스처1, 상의1텍스처2....]

제가 하고싶은건 리전 어태치먼트를 메쉬 어태치먼트로 바꾸고 텍스처는 런타임에서 선택하여 아틀라스로 패킹하여 사용하고싶습니다.

예를들어 상의 슬롯에 [상의1, 상의2, 상의3]의 메쉬 어태치먼트가 있고, 텍스처는 [상의1텍스처1, 상의1 텍스처2, 상의2텍스처1, 상의2텍스처2 .....] 들이 있어서 각각의 메쉬어태치먼트에 맞는 텍스처를 조합하여 슬롯에 런타임으로 추가하고 싶습니다.

이 시스템을 위해 스킨을 만들고, 스킨플레이스홀더에 메쉬어태치먼트를 생성하고 텍스처를 붙였습니다. 그후 유니티로 임포트하여 스킨데이터만 따로 serialize하여 런타임에서 스킨데이터를 넣는 작업을 했습니다.

혹시 더 좋은해결방법이나 접근방법이 있다면 조언부탁합니다.

Related Discussions
...

스파인에서 아바타 시스템을 구현하기 위해 메쉬 어태치먼트를 사용하고, 런타임에서 텍스처를 선택하여 아틀라스로 패킹하는 방법에 대해 설명드리겠습니다. 현재 사용하고 계신 방법은 스킨을 생성하고, 스킨 플레이스홀더에 메쉬 어태치먼트를 추가한 후, 런타임에서 스킨 데이터를 적용하는 방식입니다. 이는 매우 유효한 접근 방식입니다.

다른 접근 방법으로는 다음과 같은 방법을 고려해볼 수 있습니다:

  1. 런타임에서 메쉬 어태치먼트 생성: 스파인 런타임 API를 사용하여 런타임에서 메쉬 어태치먼트를 생성하고, 필요한 텍스처를 동적으로 할당할 수 있습니다. 이를 통해 더 유연하게 아바타의 외형을 조정할 수 있습니다.

  2. 커스텀 아틀라스 생성: 런타임에서 필요한 텍스처만을 포함하는 커스텀 아틀라스를 생성하여 메모리 사용을 최적화할 수 있습니다. 이를 위해 Spine의 TextureAtlas 클래스를 활용하여 런타임에서 아틀라스를 동적으로 생성할 수 있습니다.

  3. 스킨 교체 기능 활용: 스파인의 스킨 기능을 활용하여 다양한 조합의 메쉬와 텍스처를 미리 정의하고, 런타임에서 스킨을 교체하는 방식으로 구현할 수 있습니다. 이는 스킨 데이터를 미리 준비해두고, 필요에 따라 스킨을 교체하는 방식으로 성능을 최적화할 수 있습니다.

이러한 방법들을 통해 아바타 시스템을 더욱 효율적으로 구현할 수 있을 것입니다. 필요에 따라 각 방법을 조합하여 사용하시면 더욱 유연한 시스템을 구축할 수 있습니다.

Using template attachments that you replace at runtime is a good approach, described here:
https://esotericsoftware.com/spine-runtime-skins#Creating-attachments

However, with 1x1 template images how do you control the position of the replacement image? The location of the center of the 1x1 image and replacement image will match, but you may need to create quite a large replacement image to get it in the right place. It would be mostly blank space and texture packing can trim off the blank space, but there may be a better solution.

More commonly the template image is large enough to contain any art for the slot. All replacement images are the same size, so you more easily know the position on the skeleton the art will appear.

I think your actual question is about how to use template with meshes. Create the mesh in Spine using a template image. At runtime, duplicate the template mesh and change the texture. The replacement image should be the same size as the template image.

A common approach for an avatar system is to configure the avatar with game items (clothing, armor, weapons, etc). Find the corresponding slots and template attachment, duplicate them, and replace the images so they look like the game items. Once you have the skeleton outfitted with all the correct images, you collect only those images and pack them into an atlas at runtime.

@canghwan Please also be sure to check out the example scenes Spine Examples/Other Examples/Mix and Match and Mix and Match Equip on how to use Unity Sprites to replace an existing attachment region, if you should need that.

  • Nate оценил это.

답변 감사합니다.

Harald가 답변한 예제 코드를 확인한뒤 Nate가 답변한 큰 템플릿 이미지를 사용해서 해결했습니다.

큰 템플릿 이미지를 메쉬어태치먼트로 사용하여 다른 이미지로 바꿀경우 비슷한 사이즈의 경우 괜찮았지만 템플릿 이미지보다 작은경우 원하는 결과를 얻을수없었습니다.

템플릿 이미지를 대, 중 소,로 구분하여 메쉬 어태치먼트를 생성하고 커스텀 시리얼라이즈로 메쉬 어태치먼트 정보를 저장하여 런타임에서 메쉬 어태치먼트와 텍스쳐를 선택하여 스킨을 만든뒤 기존 스파인에 적용할수있었습니다.