remove meaningless TriMesh creation

This commit is contained in:
ikpil 2023-04-06 17:46:43 +09:00
parent 2cd93e8099
commit 6a31bfee32
4 changed files with 13 additions and 10 deletions

View File

@ -36,7 +36,7 @@ public class DemoInputGeomProvider : InputGeomProvider
private readonly Vector3f bmax; private readonly Vector3f bmax;
private readonly List<ConvexVolume> _convexVolumes = new(); private readonly List<ConvexVolume> _convexVolumes = new();
private readonly List<DemoOffMeshConnection> offMeshConnections = new(); private readonly List<DemoOffMeshConnection> offMeshConnections = new();
private readonly ChunkyTriMesh chunkyTriMesh; private readonly TriMesh _mesh;
public DemoInputGeomProvider(List<float> vertexPositions, List<int> meshFaces) : public DemoInputGeomProvider(List<float> vertexPositions, List<int> meshFaces) :
this(mapVertices(vertexPositions), mapFaces(meshFaces)) this(mapVertices(vertexPositions), mapFaces(meshFaces))
@ -81,7 +81,7 @@ public class DemoInputGeomProvider : InputGeomProvider
RecastVectors.max(ref bmax, vertices, i * 3); RecastVectors.max(ref bmax, vertices, i * 3);
} }
chunkyTriMesh = new ChunkyTriMesh(vertices, faces, faces.Length / 3, 256); _mesh = new TriMesh(vertices, faces);
} }
public Vector3f getMeshBoundsMin() public Vector3f getMeshBoundsMin()
@ -130,7 +130,7 @@ public class DemoInputGeomProvider : InputGeomProvider
public IEnumerable<TriMesh> meshes() public IEnumerable<TriMesh> meshes()
{ {
return ImmutableArray.Create(new TriMesh(vertices, faces)); return ImmutableArray.Create(_mesh);
} }
public List<DemoOffMeshConnection> getOffMeshConnections() public List<DemoOffMeshConnection> getOffMeshConnections()
@ -166,7 +166,7 @@ public class DemoInputGeomProvider : InputGeomProvider
q[0] = src[0] + (dst[0] - src[0]) * btmax; q[0] = src[0] + (dst[0] - src[0]) * btmax;
q[1] = src[2] + (dst[2] - src[2]) * btmax; q[1] = src[2] + (dst[2] - src[2]) * btmax;
List<ChunkyTriMeshNode> chunks = chunkyTriMesh.getChunksOverlappingSegment(p, q); List<ChunkyTriMeshNode> chunks = _mesh.chunkyTriMesh.getChunksOverlappingSegment(p, q);
if (0 == chunks.Count) if (0 == chunks.Count)
{ {
return null; return null;

View File

@ -32,7 +32,8 @@ namespace DotRecast.Recast.Geom
public readonly float[] normals; public readonly float[] normals;
private Vector3f bmin; private Vector3f bmin;
private Vector3f bmax; private Vector3f bmax;
readonly List<ConvexVolume> volumes = new List<ConvexVolume>(); private readonly List<ConvexVolume> volumes = new List<ConvexVolume>();
private readonly TriMesh _mesh;
public SimpleInputGeomProvider(List<float> vertexPositions, List<int> meshFaces) public SimpleInputGeomProvider(List<float> vertexPositions, List<int> meshFaces)
: this(mapVertices(vertexPositions), mapFaces(meshFaces)) : this(mapVertices(vertexPositions), mapFaces(meshFaces))
@ -76,6 +77,8 @@ namespace DotRecast.Recast.Geom
RecastVectors.min(ref bmin, vertices, i * 3); RecastVectors.min(ref bmin, vertices, i * 3);
RecastVectors.max(ref bmax, vertices, i * 3); RecastVectors.max(ref bmax, vertices, i * 3);
} }
_mesh = new TriMesh(vertices, faces);
} }
public Vector3f getMeshBoundsMin() public Vector3f getMeshBoundsMin()
@ -105,7 +108,7 @@ namespace DotRecast.Recast.Geom
public IEnumerable<TriMesh> meshes() public IEnumerable<TriMesh> meshes()
{ {
return ImmutableArray.Create(new TriMesh(vertices, faces)); return ImmutableArray.Create(_mesh);
} }
public void calculateNormals() public void calculateNormals()

View File

@ -27,7 +27,7 @@ namespace DotRecast.Recast.Geom
{ {
private readonly Vector3f bmin; private readonly Vector3f bmin;
private readonly Vector3f bmax; private readonly Vector3f bmax;
private readonly TriMesh[] _meshes; private readonly TriMesh _mesh;
public SingleTrimeshInputGeomProvider(float[] vertices, int[] faces) public SingleTrimeshInputGeomProvider(float[] vertices, int[] faces)
{ {
@ -41,7 +41,7 @@ namespace DotRecast.Recast.Geom
RecastVectors.max(ref bmax, vertices, i * 3); RecastVectors.max(ref bmax, vertices, i * 3);
} }
_meshes = new[] { new TriMesh(vertices, faces) }; _mesh = new TriMesh(vertices, faces);
} }
public Vector3f getMeshBoundsMin() public Vector3f getMeshBoundsMin()
@ -56,7 +56,7 @@ namespace DotRecast.Recast.Geom
public IEnumerable<TriMesh> meshes() public IEnumerable<TriMesh> meshes()
{ {
return _meshes; return ImmutableArray.Create(_mesh);
} }
public IList<ConvexVolume> convexVolumes() public IList<ConvexVolume> convexVolumes()

View File

@ -26,7 +26,7 @@ namespace DotRecast.Recast.Geom
{ {
private readonly float[] vertices; private readonly float[] vertices;
private readonly int[] faces; private readonly int[] faces;
private readonly ChunkyTriMesh chunkyTriMesh; public readonly ChunkyTriMesh chunkyTriMesh;
public TriMesh(float[] vertices, int[] faces) public TriMesh(float[] vertices, int[] faces)
{ {