表題の通りですが、3Dモデルのテクスチャをスクリプトから別の名前(.png形式)で保存したいと思います。
3Dのマテリアルは renderer.material.mainTexture になります。
下記のように3Dモデル表示中にスクリーン上に表示されている画像をpngで保存してみたのですが、
単純なスクリーンキャプチャになってしまい、3Dモデルのテクスチャとして適用すると合いません。
3dモデルのテクスチャとして出力するにはどうすればよいでしょうか
c#
1 2void Update() 3{ 4 if(Input.GetMouseButtonDown(0)){ 5 StartCoroutine(TexCreate()); 6 } 7} 8 9private IEnumerator TexCreate() 10{ 11 Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.ARGB32, false); 12 yield return new WaitForEndOfFrame(); 13 14 texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); 15 texture.Apply(); 16 17 byte[] bytes = texture.EncodeToPNG(); 18 UnityEngine.Object.Destroy(texture); 19 20 string exportPath = "Assets/tex.png"; 21 File.WriteAllBytes(exportPath, bytes); 22 23} 24
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/27 23:21
2018/12/28 00:06