changed ConvexVolumeToolImpl for unity3d

This commit is contained in:
ikpil 2023-07-10 19:17:38 +09:00
parent e923e8262a
commit c604ff1ac5
3 changed files with 24 additions and 8 deletions

View File

@ -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();

View File

@ -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);
}

View File

@ -48,11 +48,17 @@ namespace DotRecast.Recast.DemoTool.Tools
return removal;
}
public void Add(List<RcVec3f> pts, List<int> 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<RcVec3f> pts, List<int> 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,
};
}
}
}