diff --git a/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs b/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs index d7677b7..2fee53c 100644 --- a/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs @@ -78,7 +78,9 @@ public class ConvexVolumeTool : IRcTool // If clicked on that last pt, create the shape. if (pts.Count > 0 && RcVec3f.DistSqr(p, pts[pts.Count - 1]) < 0.2f * 0.2f) { - _impl.Add(pts, hull, areaType, boxDescent, boxHeight, polyOffset); + var vol = ConvexVolumeToolImpl.CreateConvexVolume(pts, hull, areaType, boxDescent, boxHeight, polyOffset); + if (null != vol) + _impl.Add(vol); pts.Clear(); hull.Clear(); diff --git a/src/DotRecast.Recast.DemoTool/Geom/DemoInputGeomProvider.cs b/src/DotRecast.Recast.DemoTool/Geom/DemoInputGeomProvider.cs index 1c57cfc..96a5229 100644 --- a/src/DotRecast.Recast.DemoTool/Geom/DemoInputGeomProvider.cs +++ b/src/DotRecast.Recast.DemoTool/Geom/DemoInputGeomProvider.cs @@ -217,6 +217,11 @@ namespace DotRecast.Recast.DemoTool.Geom volume.hmin = minh; volume.hmax = maxh; volume.areaMod = areaMod; + AddConvexVolume(volume); + } + + public void AddConvexVolume(RcConvexVolume volume) + { _convexVolumes.Add(volume); } diff --git a/src/DotRecast.Recast.DemoTool/Tools/ConvexVolumeToolImpl.cs b/src/DotRecast.Recast.DemoTool/Tools/ConvexVolumeToolImpl.cs index 926596f..01d6507 100644 --- a/src/DotRecast.Recast.DemoTool/Tools/ConvexVolumeToolImpl.cs +++ b/src/DotRecast.Recast.DemoTool/Tools/ConvexVolumeToolImpl.cs @@ -48,11 +48,17 @@ namespace DotRecast.Recast.DemoTool.Tools return removal; } - public void Add(List pts, List hull, RcAreaModification areaType, float boxDescent, float boxHeight, float polyOffset) + public void Add(RcConvexVolume volume) + { + var geom = _sample.GetInputGeom(); + geom.AddConvexVolume(volume); + } + + public static RcConvexVolume CreateConvexVolume(List pts, List hull, RcAreaModification areaType, float boxDescent, float boxHeight, float polyOffset) { // if (hull.Count <= 2) - return; + return null; // Create shape. float[] verts = new float[hull.Count * 3]; @@ -72,20 +78,23 @@ namespace DotRecast.Recast.DemoTool.Tools minh -= boxDescent; maxh = minh + boxHeight; - var geom = _sample.GetInputGeom(); if (polyOffset > 0.01f) { float[] offset = new float[verts.Length * 2]; int noffset = PolyUtils.OffsetPoly(verts, hull.Count, polyOffset, offset, offset.Length); if (noffset > 0) { - geom.AddConvexVolume(RcArrayUtils.CopyOf(offset, 0, noffset * 3), minh, maxh, areaType); + verts = RcArrayUtils.CopyOf(offset, 0, noffset * 3); } } - else + + return new RcConvexVolume() { - geom.AddConvexVolume(verts, minh, maxh, areaType); - } + verts = verts, + hmin = minh, + hmax = maxh, + areaMod = areaType, + }; } } } \ No newline at end of file