Make MeshSurfaceData more generic
This commit is contained in:
parent
2db83a827e
commit
30db43eac8
|
@ -12,19 +12,19 @@ public class MeshSurfaceData
|
||||||
private readonly List<Vector3> _vertices = new();
|
private readonly List<Vector3> _vertices = new();
|
||||||
private readonly List<Vector3> _normals = new();
|
private readonly List<Vector3> _normals = new();
|
||||||
private readonly List<int> _indices = new();
|
private readonly List<int> _indices = new();
|
||||||
private readonly List<Vector2> _textureUvs = new();
|
private readonly List<Vector2> _uv1s = new();
|
||||||
private readonly List<Vector2> _lightmapUvs = new();
|
private readonly List<Vector2> _uv2s = new();
|
||||||
|
|
||||||
public MeshSurfaceData()
|
public MeshSurfaceData()
|
||||||
{
|
{
|
||||||
Empty = true;
|
Empty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TransformLightmapUvs(int start, int end, Func<Vector2, Vector2> f)
|
public void TransformUv2s(int start, int end, Func<Vector2, Vector2> f)
|
||||||
{
|
{
|
||||||
for (var i = start; i < end; i++)
|
for (var i = start; i < end; i++)
|
||||||
{
|
{
|
||||||
_lightmapUvs[i] = f(_lightmapUvs[i]);
|
_uv2s[i] = f(_uv2s[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ public class MeshSurfaceData
|
||||||
public (int, int) AddPolygon(
|
public (int, int) AddPolygon(
|
||||||
List<Vector3> vertices,
|
List<Vector3> vertices,
|
||||||
Vector3 normal,
|
Vector3 normal,
|
||||||
List<Vector2> textureUvs,
|
List<Vector2> uv1s,
|
||||||
List<Vector2> lightmapUvs)
|
List<Vector2> uv2s)
|
||||||
{
|
{
|
||||||
Empty = false;
|
Empty = false;
|
||||||
|
|
||||||
|
@ -54,11 +54,11 @@ public class MeshSurfaceData
|
||||||
_indices.Add(indexOffset + j + 1);
|
_indices.Add(indexOffset + j + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
_textureUvs.AddRange(textureUvs);
|
_uv1s.AddRange(uv1s);
|
||||||
_lightmapUvs.AddRange(lightmapUvs);
|
_uv2s.AddRange(uv2s);
|
||||||
|
|
||||||
var end = _lightmapUvs.Count;
|
var end = _uv2s.Count;
|
||||||
var start = end - lightmapUvs.Count;
|
var start = end - uv2s.Count;
|
||||||
return (start, end);
|
return (start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,8 +69,8 @@ public class MeshSurfaceData
|
||||||
array[(int)Mesh.ArrayType.Vertex] = _vertices.ToArray();
|
array[(int)Mesh.ArrayType.Vertex] = _vertices.ToArray();
|
||||||
array[(int)Mesh.ArrayType.Normal] = _normals.ToArray();
|
array[(int)Mesh.ArrayType.Normal] = _normals.ToArray();
|
||||||
array[(int)Mesh.ArrayType.Index] = _indices.ToArray();
|
array[(int)Mesh.ArrayType.Index] = _indices.ToArray();
|
||||||
array[(int)Mesh.ArrayType.TexUV] = _textureUvs.ToArray();
|
array[(int)Mesh.ArrayType.TexUV] = _uv1s.ToArray();
|
||||||
array[(int)Mesh.ArrayType.TexUV2] = _lightmapUvs.ToArray();
|
array[(int)Mesh.ArrayType.TexUV2] = _uv2s.ToArray();
|
||||||
|
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,7 +229,7 @@ public partial class Mission : Node3D
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!surfaceDataMap.ContainsKey(info.textureId)) GD.Print("Invalid SurfaceDataMap key");
|
if (!surfaceDataMap.ContainsKey(info.textureId)) GD.Print("Invalid SurfaceDataMap key");
|
||||||
surfaceDataMap[info.textureId].TransformLightmapUvs(info.uvStart, info.uvEnd, (uv) =>
|
surfaceDataMap[info.textureId].TransformUv2s(info.uvStart, info.uvEnd, (uv) =>
|
||||||
{
|
{
|
||||||
var u = uv.X;
|
var u = uv.X;
|
||||||
var v = uv.Y;
|
var v = uv.Y;
|
||||||
|
|
Loading…
Reference in New Issue