質問編集履歴
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -15,6 +15,10 @@
|
|
15
15
|
Matrix4x4[][] matrix4X4s;
|
16
16
|
Matrix4x4[] flatMatrix;
|
17
17
|
|
18
|
+
public Material material;
|
19
|
+
|
20
|
+
HashSet<Matrix4x4> matriHash = new HashSet<Matrix4x4>();
|
21
|
+
|
18
22
|
private void Start()
|
19
23
|
{
|
20
24
|
int seed = Random.Range(-999999, 999999);
|
@@ -41,15 +45,17 @@
|
|
41
45
|
if (height < 0.35f)
|
42
46
|
{
|
43
47
|
flatMatrix[index] = Matrix4x4.TRS(pos, rotation, scale);
|
48
|
+
matriHash.Add(flatMatrix[index]);
|
44
49
|
}
|
45
50
|
}
|
46
51
|
}
|
47
52
|
|
48
|
-
matrix4X4s = flatMatrix.Select((m, i) => (m, i / 1023))
|
49
|
-
.GroupBy(t => t.Item2)
|
50
|
-
.Select(g => g.Select(t => t.Item1).ToArray()).ToArray();
|
51
|
-
|
52
|
-
|
53
|
+
foreach (Matrix4x4 hash in matriHash)
|
54
|
+
{
|
55
|
+
var position = new Vector3(hash[0, 3], hash[1, 3], hash[2, 3]);
|
56
|
+
Vector2 pos = new Vector2(position.x, position.y);
|
57
|
+
posHash.Add(pos);
|
58
|
+
}
|
53
59
|
}
|
54
60
|
|
55
61
|
Vector2 getScreenDownLeft()
|
@@ -82,13 +88,48 @@
|
|
82
88
|
return hash;
|
83
89
|
}
|
84
90
|
|
91
|
+
Matrix4x4[] array = new Matrix4x4[1023];
|
92
|
+
|
93
|
+
HashSet<Matrix4x4> hashMat = new HashSet<Matrix4x4>();
|
94
|
+
|
95
|
+
HashSet<Vector2> posHash = new HashSet<Vector2>();
|
96
|
+
|
85
97
|
private void Update()
|
86
98
|
{
|
87
99
|
foreach (Vector2 item in getScreenPos())
|
88
100
|
{
|
101
|
+
GetMatrix(item);
|
102
|
+
}
|
89
103
|
|
104
|
+
foreach (var m in matrix4X4s)
|
105
|
+
{
|
106
|
+
Graphics.DrawMeshInstanced(MeshGenerator.basicMesh, 0, material, m);
|
90
107
|
}
|
91
108
|
}
|
109
|
+
|
110
|
+
Matrix4x4[][] GetMatrix(Vector2 pos)
|
111
|
+
{
|
112
|
+
if (posHash.Contains(pos))
|
113
|
+
{
|
114
|
+
foreach(Matrix4x4 item in matriHash)
|
115
|
+
{
|
116
|
+
var position = new Vector2(item[0, 3], item[1, 3]);
|
117
|
+
Vector2 matriPos = new Vector2(position.x, position.y);
|
118
|
+
if(pos == matriPos)
|
119
|
+
{
|
120
|
+
hashMat.Add(item);
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
array = hashMat.ToArray();
|
126
|
+
|
127
|
+
matrix4X4s = array.Select((m, i) => (m, i / 1023))
|
128
|
+
.GroupBy(t => t.Item2)
|
129
|
+
.Select(g => g.Select(t => t.Item1).ToArray()).ToArray();
|
130
|
+
|
131
|
+
return matrix4X4s;
|
132
|
+
}
|
92
133
|
}
|
93
134
|
|
94
135
|
```
|
@@ -173,4 +214,10 @@
|
|
173
214
|
|
174
215
|
### 試したこと
|
175
216
|
|
176
|
-
カメラに映っているメッシュだけをGraphics.DrawMeshInstancedを使って描画したかったのですが、カメラに映っているワールド座標と、変換行列に代入されている座標を一致しているか確認する方法が、分からなかったため、質問しました。
|
217
|
+
カメラに映っているメッシュだけをGraphics.DrawMeshInstancedを使って描画したかったのですが、カメラに映っているワールド座標と、変換行列に代入されている座標を一致しているか確認する方法が、分からなかったため、質問しました。
|
218
|
+
|
219
|
+
【追記】
|
220
|
+
|
221
|
+
回答者様の回答をもとに、スクリプトを変更しました。
|
222
|
+
ですが、カメラに映っているメッシュだけを描画はしているのですが、0.1~0.3FPSしか出ません。
|
223
|
+
Graphics.DrawMeshのほうが軽いくらいです……。どのように書き換えたらよいでしょうか?
|