teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

6

追加の質問

2019/10/10 18:37

投稿

ocelot
ocelot

スコア18

title CHANGED
File without changes
body CHANGED
@@ -39,4 +39,51 @@
39
39
  ![イメージ説明](541e24da6bdb9b744dfa94db1ed89d25.png)
40
40
 
41
41
 
42
- 本当に度々申し訳ありません。わかりにくい文章で恐縮ですが時間があるときでよいので回答よろしくお願いします。
42
+ 本当に度々申し訳ありません。わかりにくい文章で恐縮ですが時間があるときでよいので回答よろしくお願いします。
43
+
44
+ 追記
45
+ ```C#
46
+ void Update()
47
+ {
48
+ Texture2D tex;
49
+ private Color[] CubeMapColors;
50
+ string path = @"C:\Users\Username\Desktop\unity\Captures\";
51
+ CubemapFace[] cubemapFaces =
52
+ {
53
+ CubemapFace.PositiveX, CubemapFace.NegativeX,
54
+ CubemapFace.PositiveY, CubemapFace.NegativeY,
55
+ CubemapFace.PositiveZ, CubemapFace.NegativeZ
56
+ };
57
+ foreach (CubemapFace face in cubemapFaces)
58
+ {
59
+ name = path + @"Right\" + "frame" + framecount.ToString("0") + face.ToString() + ".png";
60
+ tex = ReadTexture(name, 1024, 1024);
61
+ CubeMapColors = tex.GetPixels();
62
+ cubemapRight.SetPixels(CubeMapColors, face);
63
+ cubemapRight.Apply();
64
+ }
65
+ }
66
+ byte[] ReadPngFile(string path)
67
+ {
68
+ FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
69
+ BinaryReader bin = new BinaryReader(fileStream);
70
+ byte[] values = bin.ReadBytes((int)bin.BaseStream.Length);
71
+
72
+ bin.Close();
73
+
74
+ return values;
75
+ }
76
+
77
+ Texture2D ReadTexture(string path, int width, int height)
78
+ {
79
+ byte[] readBinary = ReadPngFile(path);
80
+
81
+ Texture2D texture = new Texture2D(width, height,TextureFormat.RGB24, false);
82
+ texture.LoadImage(readBinary);
83
+
84
+ return texture;
85
+ }
86
+ ```
87
+ すみませんが最後にもう一つだけ質問してよろしいでしょうか。
88
+ Cubemap.SetPixelsを使って6枚の画像をRenderTextureにセットするスクリプトを書いてみたのですが、RenderTextureにうまくセットできていないようです。ファイルから画像を読み込むことはできているようです。Cubemap.SetPixelsの使い方かヒントを教えていだだけないでしょうか。
89
+ 質問ばかりで申し訳ありませんが時間のあるときでいいのでよろしくお願いします。

5

修正

2019/10/10 18:37

投稿

ocelot
ocelot

スコア18

title CHANGED
File without changes
body CHANGED
@@ -16,27 +16,6 @@
16
16
  それで質問なのですが、StereoCubemapUpdaterでつくったCubemapLeft,CubemapRightをStereoEquirectangularTextureUpdaterで再度利用するためにはどんな形式で出力して保存すればいいのでしょうか?
17
17
 
18
18
  ```C#
19
- public class CreateCubemapTest : MonoBehaviour
20
- {
21
- int cubemapsize = 1024;
22
- int framecount = 0;
23
- public RenderTexture cubemap;
24
- private new Camera camera;
25
- void Start()
26
- {
27
- cubemap = new RenderTexture(this.cubemapsize, this.cubemapsize, 24)
28
- {
29
- dimension = TextureDimension.Cube
30
- };
31
- }
32
-
33
- void Update()
34
- {
35
- this.camera = GetComponent<Camera>();
36
- this.camera.RenderToCubemap(this.cubemap);
37
- savePng("frame",framecount,cubemap);
38
- framecount++;
39
- }
40
19
  void savePng(String filename, int count, RenderTexture saveRT)
41
20
  {
42
21
 
@@ -54,7 +33,7 @@
54
33
  File.WriteAllBytes(name, bytes);
55
34
 
56
35
  }
57
- }
36
+
58
37
  ```
59
38
  とりあえず上記の関数でCubemapLeftをpngにしてみたのですが、下のような画像になってしまってキューブマップではないと思います。
60
39
  ![イメージ説明](541e24da6bdb9b744dfa94db1ed89d25.png)

4

コードの修正

2019/10/09 17:14

投稿

ocelot
ocelot

スコア18

title CHANGED
File without changes
body CHANGED
@@ -16,6 +16,27 @@
16
16
  それで質問なのですが、StereoCubemapUpdaterでつくったCubemapLeft,CubemapRightをStereoEquirectangularTextureUpdaterで再度利用するためにはどんな形式で出力して保存すればいいのでしょうか?
17
17
 
18
18
  ```C#
19
+ public class CreateCubemapTest : MonoBehaviour
20
+ {
21
+ int cubemapsize = 1024;
22
+ int framecount = 0;
23
+ public RenderTexture cubemap;
24
+ private new Camera camera;
25
+ void Start()
26
+ {
27
+ cubemap = new RenderTexture(this.cubemapsize, this.cubemapsize, 24)
28
+ {
29
+ dimension = TextureDimension.Cube
30
+ };
31
+ }
32
+
33
+ void Update()
34
+ {
35
+ this.camera = GetComponent<Camera>();
36
+ this.camera.RenderToCubemap(this.cubemap);
37
+ savePng("frame",framecount,cubemap);
38
+ framecount++;
39
+ }
19
40
  void savePng(String filename, int count, RenderTexture saveRT)
20
41
  {
21
42
 
@@ -33,6 +54,7 @@
33
54
  File.WriteAllBytes(name, bytes);
34
55
 
35
56
  }
57
+ }
36
58
  ```
37
59
  とりあえず上記の関数でCubemapLeftをpngにしてみたのですが、下のような画像になってしまってキューブマップではないと思います。
38
60
  ![イメージ説明](541e24da6bdb9b744dfa94db1ed89d25.png)

3

修正

2019/10/09 17:09

投稿

ocelot
ocelot

スコア18

title CHANGED
File without changes
body CHANGED
@@ -37,4 +37,5 @@
37
37
  とりあえず上記の関数でCubemapLeftをpngにしてみたのですが、下のような画像になってしまってキューブマップではないと思います。
38
38
  ![イメージ説明](541e24da6bdb9b744dfa94db1ed89d25.png)
39
39
 
40
+
40
- 本当に度々申し訳ありません。時間があるときでよいので回答よろしくお願いします。
41
+ 本当に度々申し訳ありません。わかりにくい文章で恐縮ですが時間があるときでよいので回答よろしくお願いします。

2

追記

2019/10/09 17:06

投稿

ocelot
ocelot

スコア18

title CHANGED
File without changes
body CHANGED
@@ -6,4 +6,35 @@
6
6
  Shader.Findという関数を使ってシェーダーファイルを読み込もうとしています。ビルド前は上記のように書いてうまくいっているのですがビルド後に実行するとNullReferenceExceptionになり実行できません。
7
7
  調べてみるとShader.Findはビルド後はこういう動作をするので、Inspecterでhttps://qiita.com/shirai/items/3d2e3ff9e0d9a55a2e23のようにすると解決するらしいのですが、なんとかスクリプト上でビルド後もシェーダーファイルを読み込むことはできないのでしょうか?ビルドされたものに処理を差し込みたいのでスクリプト上で解決したいのです。
8
8
 
9
- Unity5.6.2f1です。よろしくお願いします。
9
+ Unity5.6.2f1です。よろしくお願いします。
10
+
11
+
12
+
13
+
14
+ 追記
15
+ 処理が差し込めないのはStereoEquirectangularTextureUpdaterだけなので、StereoCubemapUpdaterで作ったCubemapLeft,CubemapRightをファイルかなにかに出力して、後でそのファイルをシェーダーファイルを読み込める環境で処理すればできないでしょうか。
16
+ それで質問なのですが、StereoCubemapUpdaterでつくったCubemapLeft,CubemapRightをStereoEquirectangularTextureUpdaterで再度利用するためにはどんな形式で出力して保存すればいいのでしょうか?
17
+
18
+ ```C#
19
+ void savePng(String filename, int count, RenderTexture saveRT)
20
+ {
21
+
22
+ Texture2D tex = new Texture2D(saveRT.width, saveRT.height, TextureFormat.RGB24, false);
23
+ RenderTexture.active = saveRT;
24
+ tex.ReadPixels(new Rect(0, 0, saveRT.width, saveRT.height), 0, 0);
25
+ tex.Apply();
26
+
27
+ // Encode texture into PNG
28
+ byte[] bytes = tex.EncodeToPNG();
29
+ UnityEngine.Object.Destroy(tex);
30
+
31
+ var name = @"C:\Users\Username\Desktop\unity\Captures\" + filename + count.ToString("0") + ".png";
32
+ //Write to a file in the project folder
33
+ File.WriteAllBytes(name, bytes);
34
+
35
+ }
36
+ ```
37
+ とりあえず上記の関数でCubemapLeftをpngにしてみたのですが、下のような画像になってしまってキューブマップではないと思います。
38
+ ![イメージ説明](541e24da6bdb9b744dfa94db1ed89d25.png)
39
+
40
+ 本当に度々申し訳ありません。時間があるときでよいので回答よろしくお願いします。

1

文章の追記

2019/10/09 17:06

投稿

ocelot
ocelot

スコア18

title CHANGED
File without changes
body CHANGED
@@ -6,4 +6,4 @@
6
6
  Shader.Findという関数を使ってシェーダーファイルを読み込もうとしています。ビルド前は上記のように書いてうまくいっているのですがビルド後に実行するとNullReferenceExceptionになり実行できません。
7
7
  調べてみるとShader.Findはビルド後はこういう動作をするので、Inspecterでhttps://qiita.com/shirai/items/3d2e3ff9e0d9a55a2e23のようにすると解決するらしいのですが、なんとかスクリプト上でビルド後もシェーダーファイルを読み込むことはできないのでしょうか?ビルドされたものに処理を差し込みたいのでスクリプト上で解決したいのです。
8
8
 
9
- Unity5.6.2f1です。
9
+ Unity5.6.2f1です。よろしくお願いします。