메뉴 건너뛰기

게임
2020.09.11 00:58

수동 밉맵(mipmap)

조회 수 471 추천 수 0 댓글 3


Honeycam 2020-09-11 00-48-14.gif5.7 MB

 

유니티가 기본 지원하는 밉맵 자동 생성은 영 시원찮아서

주워다 쓰는 중인 수동 밉맵 생성

 

포-토샵으로 줄여서 미리 이미지를 이름 맞춰서 넣으면 적당히 적당히 밉맵을 세팅해준다.

문제는 버그가 좀 있어서 파일을 함부로 넣었다만 무한 로딩 iteration에 빠지게 된다는 것.

오늘도 까먹어서 삽질 좀 했으므로 기록하여둔다.

 

유니티 에셋 폴더에 크키 조절한 이미지 파일을 밉맵이 적용되지 않게 이름을 적당히 바꿔서 먼저 집어 넣고

로드가 다 되고 나면 .mip1 .mip2 이런식으로 제대로 이름을 수정하면 무한 로딩에 빠지지 않는다. (유니티 에디터 프로젝트 창 안에서 하나씩)

 

 

 

https://www.programmersought.com/article/62534451752/

 

 

 

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Text.RegularExpressions;

public class TestTextureIporter : AssetPostprocessor {
    bool m_isReadable;
    bool m_importing;

    bool ShouldImportAsset(string path)
    {
        string pattern = GetMipmapFilenamePattern(path);
        string mip1Path = string.Format(pattern, 1);
        return File.Exists(mip1Path);
    }
    
    string GetMipmapFilenamePattern(string path)
    {
        var filename = Path.GetFileName(path);
        var filenameWithoutExtention = Path.GetFileNameWithoutExtension(path);
        var extension = Path.GetExtension(path);
        var directoryName = Path.GetDirectoryName(path);

        return Path.Combine(directoryName, filenameWithoutExtention + ".mip{0}" + extension);
    }

    void OnPreprocessTexture()
    {
        string extension = Path.GetExtension(assetPath);
        string filenameWithoutExtention = Path.GetFileNameWithoutExtension(assetPath);
        var match = Regex.Match(filenameWithoutExtention, @".mip(\d)+$");

        if(match.Success)
        {
            string filenameWithoutMip = filenameWithoutExtention.Substring(0, match.Index);
            string directoryName = Path.GetDirectoryName(assetPath);
            string mip0Path = Path.Combine(directoryName, filenameWithoutMip + extension);

            TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(mip0Path);
            if(importer != null)
                importer.SaveAndReimport();
        }

        if (ShouldImportAsset(assetPath))
        {
            m_importing = true;

            string pattern = GetMipmapFilenamePattern(assetPath);
            int m = 1;

            bool reimport = false;

            while(true)
            {
                string mipPath = string.Format(pattern, m);
                m++;

                TextureImporter importer = (TextureImporter)TextureImporter.GetAtPath(mipPath);
                if(importer != null)
                {

                    if(!importer.mipmapEnabled || !importer.isReadable)
                    {
                        importer.mipmapEnabled = true;
                        importer.isReadable = true;
                        importer.SaveAndReimport();

                        reimport = true;
                    }
                    continue;
                }
                else
                {
                    break;
                }
            }

            if(reimport)
            {
                m_importing = false;
                return;
            }
            TextureImporter textureImporter  = (TextureImporter)assetImporter;
            m_isReadable = textureImporter.isReadable;
            textureImporter.isReadable = true;
        }
    }

    void OnPostprocessTexture(Texture2D texture)
    {
        if (m_importing)
        {
            string pattern = GetMipmapFilenamePattern(assetPath);

            for (int m = 0; m < texture.mipmapCount; m++)
            {
                var mipmapTexture = AssetDatabase.LoadAssetAtPath<Texture2D>(string.Format(pattern, m));

                if(mipmapTexture != null)
                {
                    Color[] c = mipmapTexture.GetPixels(0);
                    texture.SetPixels(c, m);
                }
            }
            
            texture.Apply(false, !m_isReadable);
            TextureImporter textureImporter  = (TextureImporter)assetImporter;
            textureImporter.isReadable = m_isReadable;
        }
    }
}
 

 

 


  • 유사당 2020.09.20 12:40

    이런식의 그래픽 셋팅은 3D모델링에 2D텍스쳐를 입힌건가요?

  • 조루나 2020.09.20 18:27
    아니요.
    98% 다 2D 스프라이트 이펙트입니다.
  • 유사당 2020.09.21 14:20
    아하 3D 카툰렌더링처럼 보이는게 매우 신기합니다
사진 및 파일 첨부

여기에 파일을 끌어 놓거나 왼쪽의 버튼을 클릭하세요.

파일 용량 제한 : 0MB (허용 확장자 : *.*)

0개 첨부 됨 ( / )

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
26 게임 유니티 스파인 슬롯에 HSL 색상 변경(=포토샵 Colorize) 3 file 조루나 2022.05.13 409
25 게임 배경 하늘 경계선이 마음에 안 들어서 그래디언트 추가 file 조루나 2022.03.31 251
24 게임 Shader를 적용 시킨 UI에 ZWrite가 On 되어 있으면 안되나? file 조루나 2022.03.29 231
23 게임 유니티 Spine 셰이더 고쳐서 부위별 Hue-Shift 적용시키기 file 조루나 2022.03.10 283
22 게임 유니티 URP에 쓸 투명 원 쇼크 웨이브 file 조루나 2021.12.27 298
21 게임 한붓 그리기 경우의 수 계산 file 조루나 2021.10.20 329
20 게임 터렛 관절 무-빙- file 조루나 2021.07.23 344
19 게임 게임에 한 붓 그리기 퍼즐을 넣고 싶다길래... file 조루나 2021.07.15 311
18 게임 2D 쿼터뷰 타일 게임을 3D처럼 해달라잖아! file 조루나 2021.05.27 390
17 게임 2D 쿼터뷰 게임의 스프라이트 Sorting Order 정렬 방법 file 조루나 2021.04.30 418
16 게임 스크롤러 에셋과 VerticalLayoutGroup의 저주 file 조루나 2021.03.10 368
15 게임 스프라이트 하프 밉맵 file 조루나 2020.11.20 347
14 게임 3D 입문2. Mixamo 애니메이션으로 날로 먹기 1 file 조루나 2020.11.10 388
13 게임 3D 입문. Vroid Studio로 날먹 해보기. file 조루나 2020.11.09 469
12 게임 총알 방패막 + 회전회오리슛 1 file 조루나 2020.10.27 406
11 게임 엔터 더 건전 따라서 UI에 현재 무기 그림이 나오게 해달라기에. 1 file 조루나 2020.10.16 434
10 게임 버프버프 2 file 조루나 2020.09.22 373
» 게임 수동 밉맵(mipmap) 유니티가 기본 지원하는 밉맵 자동 생성은 영 시원찮아서 주워다 쓰는 중인 수동 밉맵 생성 포-토샵으로 줄여서 미리 이미지를 이름 맞춰서 넣으면 적당히 적당히... 3 file 조루나 2020.09.11 471
8 게임 2D 게임이라도 팝콘이 튀기고 싶어 file 조루나 2020.09.09 384
7 게임 뭐! 지도에 캐릭터 위치를 보여달라고! 1 file 조루나 2020.08.20 461
Board Pagination Prev 1 2 3 Next
/ 3