completed ConvexVolumeTool

This commit is contained in:
ikpil 2023-03-26 12:24:06 +09:00
parent 877d38cd57
commit 4d19a86c11
4 changed files with 89 additions and 82 deletions

View File

@ -18,6 +18,9 @@ freely, subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution. 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; namespace DotRecast.Recast.Demo.Builder;
public class SampleAreaModifications 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_JUMP_AUTO = 0x6;
public const int SAMPLE_POLYAREA_TYPE_WALKABLE = 0x3f; public const int SAMPLE_POLYAREA_TYPE_WALKABLE = 0x3f;
public static AreaModification SAMPLE_AREAMOD_WALKABLE = new AreaModification(SAMPLE_POLYAREA_TYPE_WALKABLE); public static readonly AreaModification SAMPLE_AREAMOD_WALKABLE = new(SAMPLE_POLYAREA_TYPE_WALKABLE);
public static AreaModification SAMPLE_AREAMOD_GROUND = new AreaModification(SAMPLE_POLYAREA_TYPE_GROUND); public static readonly AreaModification SAMPLE_AREAMOD_GROUND = new(SAMPLE_POLYAREA_TYPE_GROUND);
public static AreaModification SAMPLE_AREAMOD_WATER = new AreaModification(SAMPLE_POLYAREA_TYPE_WATER); public static readonly AreaModification SAMPLE_AREAMOD_WATER = new(SAMPLE_POLYAREA_TYPE_WATER);
public static AreaModification SAMPLE_AREAMOD_ROAD = new AreaModification(SAMPLE_POLYAREA_TYPE_ROAD); public static readonly AreaModification SAMPLE_AREAMOD_ROAD = new(SAMPLE_POLYAREA_TYPE_ROAD);
public static AreaModification SAMPLE_AREAMOD_GRASS = new AreaModification(SAMPLE_POLYAREA_TYPE_GRASS); public static readonly AreaModification SAMPLE_AREAMOD_GRASS = new(SAMPLE_POLYAREA_TYPE_GRASS);
public static AreaModification SAMPLE_AREAMOD_DOOR = new AreaModification(SAMPLE_POLYAREA_TYPE_DOOR); public static readonly AreaModification SAMPLE_AREAMOD_DOOR = new(SAMPLE_POLYAREA_TYPE_DOOR);
public static AreaModification SAMPLE_AREAMOD_JUMP = new AreaModification(SAMPLE_POLYAREA_TYPE_JUMP); 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_WALK = 0x01; // Ability to walk (ground, grass, road)
public static readonly int SAMPLE_POLYFLAGS_SWIM = 0x02; // Ability to swim (water). public static readonly int SAMPLE_POLYFLAGS_SWIM = 0x02; // Ability to swim (water).

View File

@ -34,6 +34,7 @@ namespace DotRecast.Recast.Demo.Tools;
public class ConvexVolumeTool : Tool public class ConvexVolumeTool : Tool
{ {
private Sample sample; private Sample sample;
private int areaTypeValue = SampleAreaModifications.SAMPLE_AREAMOD_GRASS.Value;
private AreaModification areaType = SampleAreaModifications.SAMPLE_AREAMOD_GRASS; private AreaModification areaType = SampleAreaModifications.SAMPLE_AREAMOD_GRASS;
private float boxHeight = 6f; private float boxHeight = 6f;
private float boxDescent = 1f; private float boxDescent = 1f;
@ -106,8 +107,7 @@ public class ConvexVolumeTool : Tool
if (polyOffset > 0.01f) if (polyOffset > 0.01f)
{ {
float[] offset = new float[verts.Length * 2]; float[] offset = new float[verts.Length * 2];
int noffset = PolyUtils.offsetPoly(verts, hull.Count, polyOffset, offset, int noffset = PolyUtils.offsetPoly(verts, hull.Count, polyOffset, offset, offset.Length);
offset.Length);
if (noffset > 0) if (noffset > 0)
{ {
geom.addConvexVolume(ArrayUtils.CopyOf(offset, 0, noffset * 3), minh, maxh, areaType); geom.addConvexVolume(ArrayUtils.CopyOf(offset, 0, noffset * 3), minh, maxh, areaType);
@ -187,44 +187,44 @@ public class ConvexVolumeTool : Tool
public override void layout() public override void layout()
{ {
// nk_layout_row_dynamic(ctx, 20, 1);
ImGui.SliderFloat("Shape Height", ref boxHeight, 0.1f, 20f, "%.1f"); 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"); 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.SliderFloat("Poly Offset", ref polyOffset, 0.1f, 10f, "%.1f");
ImGui.NewLine();
ImGui.Text("Area Type"); ImGui.Text("Area Type");
// nk_layout_row_dynamic(ctx, 20, 1); ImGui.Separator();
// if (nk_option_label(ctx, "Ground", areaType == SampleAreaModifications.SAMPLE_AREAMOD_GROUND)) { int prevAreaTypeValue = areaTypeValue;
// areaType = SampleAreaModifications.SAMPLE_AREAMOD_GROUND; ImGui.RadioButton("Ground", ref areaTypeValue, SampleAreaModifications.SAMPLE_AREAMOD_GROUND.Value);
// } ImGui.RadioButton("Water", ref areaTypeValue, SampleAreaModifications.SAMPLE_AREAMOD_WATER.Value);
// if (nk_option_label(ctx, "Water", areaType == SampleAreaModifications.SAMPLE_AREAMOD_WATER)) { ImGui.RadioButton("Road", ref areaTypeValue, SampleAreaModifications.SAMPLE_AREAMOD_ROAD.Value);
// areaType = SampleAreaModifications.SAMPLE_AREAMOD_WATER; ImGui.RadioButton("Door", ref areaTypeValue, SampleAreaModifications.SAMPLE_AREAMOD_DOOR.Value);
// } ImGui.RadioButton("Grass", ref areaTypeValue, SampleAreaModifications.SAMPLE_AREAMOD_GRASS.Value);
// if (nk_option_label(ctx, "Road", areaType == SampleAreaModifications.SAMPLE_AREAMOD_ROAD)) { ImGui.RadioButton("Jump", ref areaTypeValue, SampleAreaModifications.SAMPLE_AREAMOD_JUMP.Value);
// areaType = SampleAreaModifications.SAMPLE_AREAMOD_ROAD; ImGui.NewLine();
// }
// if (nk_option_label(ctx, "Door", areaType == SampleAreaModifications.SAMPLE_AREAMOD_DOOR)) { if (prevAreaTypeValue != areaTypeValue)
// areaType = SampleAreaModifications.SAMPLE_AREAMOD_DOOR; {
// } areaType = SampleAreaModifications.OfValue(areaTypeValue);
// if (nk_option_label(ctx, "Grass", areaType == SampleAreaModifications.SAMPLE_AREAMOD_GRASS)) { }
// areaType = SampleAreaModifications.SAMPLE_AREAMOD_GRASS;
// } if (ImGui.Button("Clear Shape"))
// if (nk_option_label(ctx, "Jump", areaType == SampleAreaModifications.SAMPLE_AREAMOD_JUMP)) { {
// areaType = SampleAreaModifications.SAMPLE_AREAMOD_JUMP; hull.Clear();
// } pts.Clear();
// if (nk_button_text(ctx, "Clear Shape")) { }
// hull.clear();
// pts.clear(); if (ImGui.Button("Remove All"))
// } {
// if (nk_button_text(ctx, "Remove All")) { hull.Clear();
// hull.clear(); pts.Clear();
// pts.clear();
// DemoInputGeomProvider geom = sample.getInputGeom(); DemoInputGeomProvider geom = sample.getInputGeom();
// if (geom != null) { if (geom != null)
// geom.clearConvexVolumes(); {
// } geom.clearConvexVolumes();
// } }
}
} }
public override string getName() public override string getName()

View File

@ -22,50 +22,50 @@ namespace DotRecast.Recast
{ {
public class AreaModification public class AreaModification
{ {
public readonly int RC_AREA_FLAGS_MASK = 0x3F; public const int RC_AREA_FLAGS_MASK = 0x3F;
private readonly int value; public int Value { get; }
private readonly int mask; public int Mask { get; }
/** /**
* Mask is set to all available bits, which means value is fully applied * Mask is set to all available bits, which means value is fully applied
* *
* @param value * @param value
* The area id to apply. [Limit: &lt;= #RC_AREA_FLAGS_MASK] * The area id to apply. [Limit: &lt;= #RC_AREA_FLAGS_MASK]
*/ */
public AreaModification(int value) public AreaModification(int value)
{ {
this.value = value; this.Value = value;
mask = RC_AREA_FLAGS_MASK; Mask = RC_AREA_FLAGS_MASK;
} }
/** /**
* *
* @param value * @param value
* The area id to apply. [Limit: &lt;= #RC_AREA_FLAGS_MASK] * The area id to apply. [Limit: &lt;= #RC_AREA_FLAGS_MASK]
* @param mask * @param mask
* Bitwise mask used when applying value. [Limit: &lt;= #RC_AREA_FLAGS_MASK] * Bitwise mask used when applying value. [Limit: &lt;= #RC_AREA_FLAGS_MASK]
*/ */
public AreaModification(int value, int mask) public AreaModification(int value, int mask)
{ {
this.value = value; this.Value = value;
this.mask = mask; this.Mask = mask;
} }
public AreaModification(AreaModification other) public AreaModification(AreaModification other)
{ {
value = other.value; Value = other.Value;
mask = other.mask; Mask = other.Mask;
} }
public int getMaskedValue() public int getMaskedValue()
{ {
return value & mask; return Value & Mask;
} }
public int apply(int area) public int apply(int area)
{ {
return ((value & mask) | (area & ~mask)); return ((Value & Mask) | (area & ~Mask));
} }
} }
} }

View File

@ -30,23 +30,12 @@ public class SampleAreaModifications
public const int SAMPLE_POLYAREA_TYPE_GRASS = 0x5; public const int SAMPLE_POLYAREA_TYPE_GRASS = 0x5;
public const int SAMPLE_POLYAREA_TYPE_JUMP = 0x6; public const int SAMPLE_POLYAREA_TYPE_JUMP = 0x6;
public static AreaModification SAMPLE_AREAMOD_GROUND = new AreaModification(SAMPLE_POLYAREA_TYPE_GROUND, public static AreaModification SAMPLE_AREAMOD_GROUND = new AreaModification(SAMPLE_POLYAREA_TYPE_GROUND, SAMPLE_POLYAREA_TYPE_MASK);
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_WATER = new AreaModification(SAMPLE_POLYAREA_TYPE_WATER, public static AreaModification SAMPLE_AREAMOD_GRASS = new AreaModification(SAMPLE_POLYAREA_TYPE_GRASS, SAMPLE_POLYAREA_TYPE_MASK);
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_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_WALK = 0x01; // Ability to walk (ground, grass, road)
public const int SAMPLE_POLYFLAGS_SWIM = 0x02; // Ability to swim (water). public const int SAMPLE_POLYFLAGS_SWIM = 0x02; // Ability to swim (water).