forked from bit/DotRecastNetSim
completed ConvexVolumeTool
This commit is contained in:
parent
877d38cd57
commit
4d19a86c11
|
@ -18,6 +18,9 @@ freely, subject to the following restrictions:
|
|||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
|
||||
namespace DotRecast.Recast.Demo.Builder;
|
||||
|
||||
public class SampleAreaModifications
|
||||
|
@ -31,13 +34,28 @@ public class SampleAreaModifications
|
|||
public const int SAMPLE_POLYAREA_TYPE_JUMP_AUTO = 0x6;
|
||||
public const int SAMPLE_POLYAREA_TYPE_WALKABLE = 0x3f;
|
||||
|
||||
public static AreaModification SAMPLE_AREAMOD_WALKABLE = new AreaModification(SAMPLE_POLYAREA_TYPE_WALKABLE);
|
||||
public static AreaModification SAMPLE_AREAMOD_GROUND = new AreaModification(SAMPLE_POLYAREA_TYPE_GROUND);
|
||||
public static AreaModification SAMPLE_AREAMOD_WATER = new AreaModification(SAMPLE_POLYAREA_TYPE_WATER);
|
||||
public static AreaModification SAMPLE_AREAMOD_ROAD = new AreaModification(SAMPLE_POLYAREA_TYPE_ROAD);
|
||||
public static AreaModification SAMPLE_AREAMOD_GRASS = new AreaModification(SAMPLE_POLYAREA_TYPE_GRASS);
|
||||
public static AreaModification SAMPLE_AREAMOD_DOOR = new AreaModification(SAMPLE_POLYAREA_TYPE_DOOR);
|
||||
public static AreaModification SAMPLE_AREAMOD_JUMP = new AreaModification(SAMPLE_POLYAREA_TYPE_JUMP);
|
||||
public static readonly AreaModification SAMPLE_AREAMOD_WALKABLE = new(SAMPLE_POLYAREA_TYPE_WALKABLE);
|
||||
public static readonly AreaModification SAMPLE_AREAMOD_GROUND = new(SAMPLE_POLYAREA_TYPE_GROUND);
|
||||
public static readonly AreaModification SAMPLE_AREAMOD_WATER = new(SAMPLE_POLYAREA_TYPE_WATER);
|
||||
public static readonly AreaModification SAMPLE_AREAMOD_ROAD = new(SAMPLE_POLYAREA_TYPE_ROAD);
|
||||
public static readonly AreaModification SAMPLE_AREAMOD_GRASS = new(SAMPLE_POLYAREA_TYPE_GRASS);
|
||||
public static readonly AreaModification SAMPLE_AREAMOD_DOOR = new(SAMPLE_POLYAREA_TYPE_DOOR);
|
||||
public static readonly AreaModification SAMPLE_AREAMOD_JUMP = new(SAMPLE_POLYAREA_TYPE_JUMP);
|
||||
|
||||
public static readonly ImmutableArray<AreaModification> Values = ImmutableArray.Create(
|
||||
SAMPLE_AREAMOD_WALKABLE,
|
||||
SAMPLE_AREAMOD_GROUND,
|
||||
SAMPLE_AREAMOD_WATER,
|
||||
SAMPLE_AREAMOD_ROAD,
|
||||
SAMPLE_AREAMOD_GRASS,
|
||||
SAMPLE_AREAMOD_DOOR,
|
||||
SAMPLE_AREAMOD_JUMP
|
||||
);
|
||||
|
||||
public static AreaModification OfValue(int value)
|
||||
{
|
||||
return Values.FirstOrDefault(x => x.Value == value, SAMPLE_AREAMOD_GRASS);
|
||||
}
|
||||
|
||||
public static readonly int SAMPLE_POLYFLAGS_WALK = 0x01; // Ability to walk (ground, grass, road)
|
||||
public static readonly int SAMPLE_POLYFLAGS_SWIM = 0x02; // Ability to swim (water).
|
||||
|
|
|
@ -34,6 +34,7 @@ namespace DotRecast.Recast.Demo.Tools;
|
|||
public class ConvexVolumeTool : Tool
|
||||
{
|
||||
private Sample sample;
|
||||
private int areaTypeValue = SampleAreaModifications.SAMPLE_AREAMOD_GRASS.Value;
|
||||
private AreaModification areaType = SampleAreaModifications.SAMPLE_AREAMOD_GRASS;
|
||||
private float boxHeight = 6f;
|
||||
private float boxDescent = 1f;
|
||||
|
@ -106,8 +107,7 @@ public class ConvexVolumeTool : Tool
|
|||
if (polyOffset > 0.01f)
|
||||
{
|
||||
float[] offset = new float[verts.Length * 2];
|
||||
int noffset = PolyUtils.offsetPoly(verts, hull.Count, polyOffset, offset,
|
||||
offset.Length);
|
||||
int noffset = PolyUtils.offsetPoly(verts, hull.Count, polyOffset, offset, offset.Length);
|
||||
if (noffset > 0)
|
||||
{
|
||||
geom.addConvexVolume(ArrayUtils.CopyOf(offset, 0, noffset * 3), minh, maxh, areaType);
|
||||
|
@ -187,44 +187,44 @@ public class ConvexVolumeTool : Tool
|
|||
|
||||
public override void layout()
|
||||
{
|
||||
// nk_layout_row_dynamic(ctx, 20, 1);
|
||||
ImGui.SliderFloat("Shape Height", ref boxHeight, 0.1f, 20f, "%.1f");
|
||||
// nk_layout_row_dynamic(ctx, 20, 1);
|
||||
ImGui.SliderFloat("Shape Descent", ref boxDescent, 0.1f, 20f, "%.1f");
|
||||
// nk_layout_row_dynamic(ctx, 20, 1);
|
||||
ImGui.SliderFloat("Poly Offset", ref polyOffset, 0.1f, 10f, "%.1f");
|
||||
ImGui.NewLine();
|
||||
|
||||
ImGui.Text("Area Type");
|
||||
// nk_layout_row_dynamic(ctx, 20, 1);
|
||||
// if (nk_option_label(ctx, "Ground", areaType == SampleAreaModifications.SAMPLE_AREAMOD_GROUND)) {
|
||||
// areaType = SampleAreaModifications.SAMPLE_AREAMOD_GROUND;
|
||||
// }
|
||||
// if (nk_option_label(ctx, "Water", areaType == SampleAreaModifications.SAMPLE_AREAMOD_WATER)) {
|
||||
// areaType = SampleAreaModifications.SAMPLE_AREAMOD_WATER;
|
||||
// }
|
||||
// if (nk_option_label(ctx, "Road", areaType == SampleAreaModifications.SAMPLE_AREAMOD_ROAD)) {
|
||||
// areaType = SampleAreaModifications.SAMPLE_AREAMOD_ROAD;
|
||||
// }
|
||||
// if (nk_option_label(ctx, "Door", areaType == SampleAreaModifications.SAMPLE_AREAMOD_DOOR)) {
|
||||
// areaType = SampleAreaModifications.SAMPLE_AREAMOD_DOOR;
|
||||
// }
|
||||
// if (nk_option_label(ctx, "Grass", areaType == SampleAreaModifications.SAMPLE_AREAMOD_GRASS)) {
|
||||
// areaType = SampleAreaModifications.SAMPLE_AREAMOD_GRASS;
|
||||
// }
|
||||
// if (nk_option_label(ctx, "Jump", areaType == SampleAreaModifications.SAMPLE_AREAMOD_JUMP)) {
|
||||
// areaType = SampleAreaModifications.SAMPLE_AREAMOD_JUMP;
|
||||
// }
|
||||
// if (nk_button_text(ctx, "Clear Shape")) {
|
||||
// hull.clear();
|
||||
// pts.clear();
|
||||
// }
|
||||
// if (nk_button_text(ctx, "Remove All")) {
|
||||
// hull.clear();
|
||||
// pts.clear();
|
||||
// DemoInputGeomProvider geom = sample.getInputGeom();
|
||||
// if (geom != null) {
|
||||
// geom.clearConvexVolumes();
|
||||
// }
|
||||
// }
|
||||
ImGui.Separator();
|
||||
int prevAreaTypeValue = areaTypeValue;
|
||||
ImGui.RadioButton("Ground", ref areaTypeValue, SampleAreaModifications.SAMPLE_AREAMOD_GROUND.Value);
|
||||
ImGui.RadioButton("Water", ref areaTypeValue, SampleAreaModifications.SAMPLE_AREAMOD_WATER.Value);
|
||||
ImGui.RadioButton("Road", ref areaTypeValue, SampleAreaModifications.SAMPLE_AREAMOD_ROAD.Value);
|
||||
ImGui.RadioButton("Door", ref areaTypeValue, SampleAreaModifications.SAMPLE_AREAMOD_DOOR.Value);
|
||||
ImGui.RadioButton("Grass", ref areaTypeValue, SampleAreaModifications.SAMPLE_AREAMOD_GRASS.Value);
|
||||
ImGui.RadioButton("Jump", ref areaTypeValue, SampleAreaModifications.SAMPLE_AREAMOD_JUMP.Value);
|
||||
ImGui.NewLine();
|
||||
|
||||
if (prevAreaTypeValue != areaTypeValue)
|
||||
{
|
||||
areaType = SampleAreaModifications.OfValue(areaTypeValue);
|
||||
}
|
||||
|
||||
if (ImGui.Button("Clear Shape"))
|
||||
{
|
||||
hull.Clear();
|
||||
pts.Clear();
|
||||
}
|
||||
|
||||
if (ImGui.Button("Remove All"))
|
||||
{
|
||||
hull.Clear();
|
||||
pts.Clear();
|
||||
|
||||
DemoInputGeomProvider geom = sample.getInputGeom();
|
||||
if (geom != null)
|
||||
{
|
||||
geom.clearConvexVolumes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string getName()
|
||||
|
|
|
@ -22,50 +22,50 @@ namespace DotRecast.Recast
|
|||
{
|
||||
public class AreaModification
|
||||
{
|
||||
public readonly int RC_AREA_FLAGS_MASK = 0x3F;
|
||||
public const int RC_AREA_FLAGS_MASK = 0x3F;
|
||||
|
||||
private readonly int value;
|
||||
private readonly int mask;
|
||||
public int Value { get; }
|
||||
public int Mask { get; }
|
||||
|
||||
/**
|
||||
* Mask is set to all available bits, which means value is fully applied
|
||||
*
|
||||
* @param value
|
||||
* The area id to apply. [Limit: <= #RC_AREA_FLAGS_MASK]
|
||||
*/
|
||||
* Mask is set to all available bits, which means value is fully applied
|
||||
*
|
||||
* @param value
|
||||
* The area id to apply. [Limit: <= #RC_AREA_FLAGS_MASK]
|
||||
*/
|
||||
public AreaModification(int value)
|
||||
{
|
||||
this.value = value;
|
||||
mask = RC_AREA_FLAGS_MASK;
|
||||
this.Value = value;
|
||||
Mask = RC_AREA_FLAGS_MASK;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
* The area id to apply. [Limit: <= #RC_AREA_FLAGS_MASK]
|
||||
* @param mask
|
||||
* Bitwise mask used when applying value. [Limit: <= #RC_AREA_FLAGS_MASK]
|
||||
*/
|
||||
*
|
||||
* @param value
|
||||
* The area id to apply. [Limit: <= #RC_AREA_FLAGS_MASK]
|
||||
* @param mask
|
||||
* Bitwise mask used when applying value. [Limit: <= #RC_AREA_FLAGS_MASK]
|
||||
*/
|
||||
public AreaModification(int value, int mask)
|
||||
{
|
||||
this.value = value;
|
||||
this.mask = mask;
|
||||
this.Value = value;
|
||||
this.Mask = mask;
|
||||
}
|
||||
|
||||
public AreaModification(AreaModification other)
|
||||
{
|
||||
value = other.value;
|
||||
mask = other.mask;
|
||||
Value = other.Value;
|
||||
Mask = other.Mask;
|
||||
}
|
||||
|
||||
public int getMaskedValue()
|
||||
{
|
||||
return value & mask;
|
||||
return Value & Mask;
|
||||
}
|
||||
|
||||
public int apply(int area)
|
||||
{
|
||||
return ((value & mask) | (area & ~mask));
|
||||
return ((Value & Mask) | (area & ~Mask));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,23 +30,12 @@ public class SampleAreaModifications
|
|||
public const int SAMPLE_POLYAREA_TYPE_GRASS = 0x5;
|
||||
public const int SAMPLE_POLYAREA_TYPE_JUMP = 0x6;
|
||||
|
||||
public static AreaModification SAMPLE_AREAMOD_GROUND = new AreaModification(SAMPLE_POLYAREA_TYPE_GROUND,
|
||||
SAMPLE_POLYAREA_TYPE_MASK);
|
||||
|
||||
public static AreaModification SAMPLE_AREAMOD_WATER = new AreaModification(SAMPLE_POLYAREA_TYPE_WATER,
|
||||
SAMPLE_POLYAREA_TYPE_MASK);
|
||||
|
||||
public static AreaModification SAMPLE_AREAMOD_ROAD = new AreaModification(SAMPLE_POLYAREA_TYPE_ROAD,
|
||||
SAMPLE_POLYAREA_TYPE_MASK);
|
||||
|
||||
public static AreaModification SAMPLE_AREAMOD_GRASS = new AreaModification(SAMPLE_POLYAREA_TYPE_GRASS,
|
||||
SAMPLE_POLYAREA_TYPE_MASK);
|
||||
|
||||
public static AreaModification SAMPLE_AREAMOD_DOOR = new AreaModification(SAMPLE_POLYAREA_TYPE_DOOR,
|
||||
SAMPLE_POLYAREA_TYPE_DOOR);
|
||||
|
||||
public static AreaModification SAMPLE_AREAMOD_JUMP = new AreaModification(SAMPLE_POLYAREA_TYPE_JUMP,
|
||||
SAMPLE_POLYAREA_TYPE_JUMP);
|
||||
public static AreaModification SAMPLE_AREAMOD_GROUND = new AreaModification(SAMPLE_POLYAREA_TYPE_GROUND, SAMPLE_POLYAREA_TYPE_MASK);
|
||||
public static AreaModification SAMPLE_AREAMOD_WATER = new AreaModification(SAMPLE_POLYAREA_TYPE_WATER, SAMPLE_POLYAREA_TYPE_MASK);
|
||||
public static AreaModification SAMPLE_AREAMOD_ROAD = new AreaModification(SAMPLE_POLYAREA_TYPE_ROAD, SAMPLE_POLYAREA_TYPE_MASK);
|
||||
public static AreaModification SAMPLE_AREAMOD_GRASS = new AreaModification(SAMPLE_POLYAREA_TYPE_GRASS, SAMPLE_POLYAREA_TYPE_MASK);
|
||||
public static AreaModification SAMPLE_AREAMOD_DOOR = new AreaModification(SAMPLE_POLYAREA_TYPE_DOOR, SAMPLE_POLYAREA_TYPE_DOOR);
|
||||
public static AreaModification SAMPLE_AREAMOD_JUMP = new AreaModification(SAMPLE_POLYAREA_TYPE_JUMP, SAMPLE_POLYAREA_TYPE_JUMP);
|
||||
|
||||
public const int SAMPLE_POLYFLAGS_WALK = 0x01; // Ability to walk (ground, grass, road)
|
||||
public const int SAMPLE_POLYFLAGS_SWIM = 0x02; // Ability to swim (water).
|
||||
|
|
Loading…
Reference in New Issue