質問編集履歴
6
追加の質問
test
CHANGED
File without changes
|
test
CHANGED
@@ -81,3 +81,97 @@
|
|
81
81
|
|
82
82
|
|
83
83
|
本当に度々申し訳ありません。わかりにくい文章で恐縮ですが時間があるときでよいので回答よろしくお願いします。
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
追記
|
88
|
+
|
89
|
+
```C#
|
90
|
+
|
91
|
+
void Update()
|
92
|
+
|
93
|
+
{
|
94
|
+
|
95
|
+
Texture2D tex;
|
96
|
+
|
97
|
+
private Color[] CubeMapColors;
|
98
|
+
|
99
|
+
string path = @"C:\Users\Username\Desktop\unity\Captures\";
|
100
|
+
|
101
|
+
CubemapFace[] cubemapFaces =
|
102
|
+
|
103
|
+
{
|
104
|
+
|
105
|
+
CubemapFace.PositiveX, CubemapFace.NegativeX,
|
106
|
+
|
107
|
+
CubemapFace.PositiveY, CubemapFace.NegativeY,
|
108
|
+
|
109
|
+
CubemapFace.PositiveZ, CubemapFace.NegativeZ
|
110
|
+
|
111
|
+
};
|
112
|
+
|
113
|
+
foreach (CubemapFace face in cubemapFaces)
|
114
|
+
|
115
|
+
{
|
116
|
+
|
117
|
+
name = path + @"Right\" + "frame" + framecount.ToString("0") + face.ToString() + ".png";
|
118
|
+
|
119
|
+
tex = ReadTexture(name, 1024, 1024);
|
120
|
+
|
121
|
+
CubeMapColors = tex.GetPixels();
|
122
|
+
|
123
|
+
cubemapRight.SetPixels(CubeMapColors, face);
|
124
|
+
|
125
|
+
cubemapRight.Apply();
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
byte[] ReadPngFile(string path)
|
132
|
+
|
133
|
+
{
|
134
|
+
|
135
|
+
FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
136
|
+
|
137
|
+
BinaryReader bin = new BinaryReader(fileStream);
|
138
|
+
|
139
|
+
byte[] values = bin.ReadBytes((int)bin.BaseStream.Length);
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
bin.Close();
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
return values;
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
Texture2D ReadTexture(string path, int width, int height)
|
154
|
+
|
155
|
+
{
|
156
|
+
|
157
|
+
byte[] readBinary = ReadPngFile(path);
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
Texture2D texture = new Texture2D(width, height,TextureFormat.RGB24, false);
|
162
|
+
|
163
|
+
texture.LoadImage(readBinary);
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
return texture;
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
```
|
172
|
+
|
173
|
+
すみませんが最後にもう一つだけ質問してよろしいでしょうか。
|
174
|
+
|
175
|
+
Cubemap.SetPixelsを使って6枚の画像をRenderTextureにセットするスクリプトを書いてみたのですが、RenderTextureにうまくセットできていないようです。ファイルから画像を読み込むことはできているようです。Cubemap.SetPixelsの使い方かヒントを教えていだだけないでしょうか。
|
176
|
+
|
177
|
+
質問ばかりで申し訳ありませんが時間のあるときでいいのでよろしくお願いします。
|
5
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,48 +34,6 @@
|
|
34
34
|
|
35
35
|
```C#
|
36
36
|
|
37
|
-
public class CreateCubemapTest : MonoBehaviour
|
38
|
-
|
39
|
-
{
|
40
|
-
|
41
|
-
int cubemapsize = 1024;
|
42
|
-
|
43
|
-
int framecount = 0;
|
44
|
-
|
45
|
-
public RenderTexture cubemap;
|
46
|
-
|
47
|
-
private new Camera camera;
|
48
|
-
|
49
|
-
void Start()
|
50
|
-
|
51
|
-
{
|
52
|
-
|
53
|
-
cubemap = new RenderTexture(this.cubemapsize, this.cubemapsize, 24)
|
54
|
-
|
55
|
-
{
|
56
|
-
|
57
|
-
dimension = TextureDimension.Cube
|
58
|
-
|
59
|
-
};
|
60
|
-
|
61
|
-
}
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
void Update()
|
66
|
-
|
67
|
-
{
|
68
|
-
|
69
|
-
this.camera = GetComponent<Camera>();
|
70
|
-
|
71
|
-
this.camera.RenderToCubemap(this.cubemap);
|
72
|
-
|
73
|
-
savePng("frame",framecount,cubemap);
|
74
|
-
|
75
|
-
framecount++;
|
76
|
-
|
77
|
-
}
|
78
|
-
|
79
37
|
void savePng(String filename, int count, RenderTexture saveRT)
|
80
38
|
|
81
39
|
{
|
@@ -110,7 +68,7 @@
|
|
110
68
|
|
111
69
|
}
|
112
70
|
|
113
|
-
|
71
|
+
|
114
72
|
|
115
73
|
```
|
116
74
|
|
4
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,6 +34,48 @@
|
|
34
34
|
|
35
35
|
```C#
|
36
36
|
|
37
|
+
public class CreateCubemapTest : MonoBehaviour
|
38
|
+
|
39
|
+
{
|
40
|
+
|
41
|
+
int cubemapsize = 1024;
|
42
|
+
|
43
|
+
int framecount = 0;
|
44
|
+
|
45
|
+
public RenderTexture cubemap;
|
46
|
+
|
47
|
+
private new Camera camera;
|
48
|
+
|
49
|
+
void Start()
|
50
|
+
|
51
|
+
{
|
52
|
+
|
53
|
+
cubemap = new RenderTexture(this.cubemapsize, this.cubemapsize, 24)
|
54
|
+
|
55
|
+
{
|
56
|
+
|
57
|
+
dimension = TextureDimension.Cube
|
58
|
+
|
59
|
+
};
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
void Update()
|
66
|
+
|
67
|
+
{
|
68
|
+
|
69
|
+
this.camera = GetComponent<Camera>();
|
70
|
+
|
71
|
+
this.camera.RenderToCubemap(this.cubemap);
|
72
|
+
|
73
|
+
savePng("frame",framecount,cubemap);
|
74
|
+
|
75
|
+
framecount++;
|
76
|
+
|
77
|
+
}
|
78
|
+
|
37
79
|
void savePng(String filename, int count, RenderTexture saveRT)
|
38
80
|
|
39
81
|
{
|
@@ -68,6 +110,8 @@
|
|
68
110
|
|
69
111
|
}
|
70
112
|
|
113
|
+
}
|
114
|
+
|
71
115
|
```
|
72
116
|
|
73
117
|
とりあえず上記の関数でCubemapLeftをpngにしてみたのですが、下のような画像になってしまってキューブマップではないと思います。
|
3
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -76,4 +76,6 @@
|
|
76
76
|
|
77
77
|
|
78
78
|
|
79
|
+
|
80
|
+
|
79
|
-
本当に度々申し訳ありません。時間があるときでよいので回答よろしくお願いします。
|
81
|
+
本当に度々申し訳ありません。わかりにくい文章で恐縮ですが時間があるときでよいので回答よろしくお願いします。
|
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -15,3 +15,65 @@
|
|
15
15
|
|
16
16
|
|
17
17
|
Unity5.6.2f1です。よろしくお願いします。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
追記
|
28
|
+
|
29
|
+
処理が差し込めないのはStereoEquirectangularTextureUpdaterだけなので、StereoCubemapUpdaterで作ったCubemapLeft,CubemapRightをファイルかなにかに出力して、後でそのファイルをシェーダーファイルを読み込める環境で処理すればできないでしょうか。
|
30
|
+
|
31
|
+
それで質問なのですが、StereoCubemapUpdaterでつくったCubemapLeft,CubemapRightをStereoEquirectangularTextureUpdaterで再度利用するためにはどんな形式で出力して保存すればいいのでしょうか?
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
```C#
|
36
|
+
|
37
|
+
void savePng(String filename, int count, RenderTexture saveRT)
|
38
|
+
|
39
|
+
{
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
Texture2D tex = new Texture2D(saveRT.width, saveRT.height, TextureFormat.RGB24, false);
|
44
|
+
|
45
|
+
RenderTexture.active = saveRT;
|
46
|
+
|
47
|
+
tex.ReadPixels(new Rect(0, 0, saveRT.width, saveRT.height), 0, 0);
|
48
|
+
|
49
|
+
tex.Apply();
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
// Encode texture into PNG
|
54
|
+
|
55
|
+
byte[] bytes = tex.EncodeToPNG();
|
56
|
+
|
57
|
+
UnityEngine.Object.Destroy(tex);
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
var name = @"C:\Users\Username\Desktop\unity\Captures\" + filename + count.ToString("0") + ".png";
|
62
|
+
|
63
|
+
//Write to a file in the project folder
|
64
|
+
|
65
|
+
File.WriteAllBytes(name, bytes);
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
とりあえず上記の関数でCubemapLeftをpngにしてみたのですが、下のような画像になってしまってキューブマップではないと思います。
|
74
|
+
|
75
|
+

|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
本当に度々申し訳ありません。時間があるときでよいので回答よろしくお願いします。
|
1
文章の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,4 +14,4 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
-
Unity5.6.2f1です。
|
17
|
+
Unity5.6.2f1です。よろしくお願いします。
|