test rendering

This commit is contained in:
ikpil 2023-03-19 04:36:31 +09:00
parent 6ef631457e
commit 07b13aae4d
10 changed files with 267 additions and 205 deletions

View File

@ -8,6 +8,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Serilog" Version="2.12.0" /> <PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Silk.NET" Version="2.16.0" /> <PackageReference Include="Silk.NET" Version="2.16.0" />
<PackageReference Include="Silk.NET.OpenGL.Extensions.ImGui" Version="2.16.0" /> <PackageReference Include="Silk.NET.OpenGL.Extensions.ImGui" Version="2.16.0" />
</ItemGroup> </ItemGroup>

View File

@ -27,19 +27,25 @@ namespace DotRecast.Recast.Demo.Draw;
public class DebugDraw public class DebugDraw
{ {
private readonly GLCheckerTexture g_tex = new GLCheckerTexture(); private readonly GLCheckerTexture g_tex;
private readonly OpenGLDraw openGlDraw = new ModernOpenGLDraw(); private readonly OpenGLDraw openGlDraw;
private readonly int[] boxIndices = { 7, 6, 5, 4, 0, 1, 2, 3, 1, 5, 6, 2, 3, 7, 4, 0, 2, 6, 7, 3, 0, 4, 5, 1, }; private readonly int[] boxIndices = { 7, 6, 5, 4, 0, 1, 2, 3, 1, 5, 6, 2, 3, 7, 4, 0, 2, 6, 7, 3, 0, 4, 5, 1, };
private readonly float[][] frustumPlanes = private readonly float[][] frustumPlanes = ArrayUtils.Of<float>(6, 4);
// {
// new[] { 0f, 0f, 0f, 0f },
// new[] { 0f, 0f, 0f, 0f },
// new[] { 0f, 0f, 0f, 0f },
// new[] { 0f, 0f, 0f, 0f },
// new[] { 0f, 0f, 0f, 0f },
// new[] { 0f, 0f, 0f, 0f },
// };
public DebugDraw(GL gl)
{ {
new[] { 0f, 0f, 0f, 0f }, g_tex = new GLCheckerTexture(gl);
new[] { 0f, 0f, 0f, 0f }, openGlDraw = new ModernOpenGLDraw(gl);
new[] { 0f, 0f, 0f, 0f }, }
new[] { 0f, 0f, 0f, 0f },
new[] { 0f, 0f, 0f, 0f },
new[] { 0f, 0f, 0f, 0f },
};
public void begin(DebugDrawPrimitives prim) public void begin(DebugDrawPrimitives prim)
@ -554,9 +560,9 @@ public class DebugDraw
getOpenGlDraw().texture(g_tex, state); getOpenGlDraw().texture(g_tex, state);
} }
public void init(GL gl, float fogDistance) public void init(float fogDistance)
{ {
getOpenGlDraw().init(gl); getOpenGlDraw().init();
} }
public void clear() public void clear()

View File

@ -24,42 +24,58 @@ namespace DotRecast.Recast.Demo.Draw;
public class GLCheckerTexture public class GLCheckerTexture
{ {
int m_texId; private readonly GL _gl;
private uint m_texId;
public GLCheckerTexture(GL gl)
{
_gl = gl;
}
public void release() public void release()
{ {
// if (m_texId != 0) { if (m_texId != 0)
// glDeleteTextures(m_texId); {
// } _gl.DeleteTextures(1, m_texId);
}
} }
public void bind() public void bind()
{ {
// if (m_texId == 0) { if (m_texId == 0)
// // Create checker pattern. {
// int col0 = DebugDraw.duRGBA(215, 215, 215, 255); // Create checker pattern.
// int col1 = DebugDraw.duRGBA(255, 255, 255, 255); int col0 = DebugDraw.duRGBA(215, 215, 215, 255);
// int TSIZE = 64; int col1 = DebugDraw.duRGBA(255, 255, 255, 255);
// int[] data = new int[TSIZE * TSIZE]; uint TSIZE = 64;
// int[] data = new int[TSIZE * TSIZE];
// m_texId = glGenTextures();
// glBindTexture(GL_TEXTURE_2D, m_texId); _gl.GenTextures(1, out m_texId);
// _gl.BindTexture(GLEnum.Texture2D, m_texId);
// int level = 0;
// int size = TSIZE; int level = 0;
// while (size > 0) { uint size = TSIZE;
// for (int y = 0; y < size; ++y) while (size > 0)
// for (int x = 0; x < size; ++x) {
// data[x + y * size] = (x == 0 || y == 0) ? col0 : col1; for (int y = 0; y < size; ++y)
// glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); {
// size /= 2; for (int x = 0; x < size; ++x)
// level++; {
// } data[x + y * size] = (x == 0 || y == 0) ? col0 : col1;
// }
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); }
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// } else { _gl.TexImage2D<int>(GLEnum.Texture2D, level, InternalFormat.Rgba, size, size, 0, GLEnum.Rgba, GLEnum.UnsignedByte, data);
// glBindTexture(GL_TEXTURE_2D, m_texId); size /= 2;
// } level++;
}
_gl.TexParameterI(GLEnum.Texture2D, GLEnum.TextureMinFilter, (uint)GLEnum.LinearMipmapNearest);
_gl.TexParameterI(GLEnum.Texture2D, GLEnum.TextureMagFilter, (uint)GLEnum.Linear);
}
else
{
_gl.BindTexture(GLEnum.Texture2D, m_texId);
}
} }
} }

View File

@ -4,7 +4,9 @@ namespace DotRecast.Recast.Demo.Draw;
public class LegacyOpenGLDraw : OpenGLDraw public class LegacyOpenGLDraw : OpenGLDraw
{ {
private GL _gl; public LegacyOpenGLDraw(GL gl)
{
}
public void fog(bool state) public void fog(bool state)
{ {
@ -15,10 +17,8 @@ public class LegacyOpenGLDraw : OpenGLDraw
// } // }
} }
public void init(GL gl) public void init()
{ {
_gl = gl;
// // Fog. // // Fog.
// float fogDistance = 1000f; // float fogDistance = 1000f;
// float fogColor[] = { 0.32f, 0.31f, 0.30f, 1.0f }; // float fogColor[] = { 0.32f, 0.31f, 0.30f, 1.0f };

View File

@ -36,9 +36,13 @@ public class ModernOpenGLDraw : OpenGLDraw
private int uniformFogStart; private int uniformFogStart;
private int uniformFogEnd; private int uniformFogEnd;
public unsafe void init(GL gl) public ModernOpenGLDraw(GL gl)
{ {
_gl = gl; _gl = gl;
}
public unsafe void init()
{
string NK_SHADER_VERSION = PlatformID.MacOSX == Environment.OSVersion.Platform ? "#version 150\n" : "#version 300 es\n"; string NK_SHADER_VERSION = PlatformID.MacOSX == Environment.OSVersion.Platform ? "#version 150\n" : "#version 300 es\n";
string vertex_shader = NK_SHADER_VERSION + "uniform mat4 ProjMtx;\n" // string vertex_shader = NK_SHADER_VERSION + "uniform mat4 ProjMtx;\n" //
+ "uniform mat4 ViewMtx;\n" // + "uniform mat4 ViewMtx;\n" //
@ -77,13 +81,13 @@ public class ModernOpenGLDraw : OpenGLDraw
_gl.ShaderSource(frag_shdr, fragment_shader); _gl.ShaderSource(frag_shdr, fragment_shader);
_gl.CompileShader(vert_shdr); _gl.CompileShader(vert_shdr);
_gl.CompileShader(frag_shdr); _gl.CompileShader(frag_shdr);
gl.GetShader(vert_shdr, GLEnum.CompileStatus, out var status); _gl.GetShader(vert_shdr, GLEnum.CompileStatus, out var status);
if (status != (int)GLEnum.True) if (status != (int)GLEnum.True)
{ {
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
gl.GetShader(frag_shdr, GLEnum.CompileStatus, out status); _gl.GetShader(frag_shdr, GLEnum.CompileStatus, out status);
if (status != (int)GLEnum.True) if (status != (int)GLEnum.True)
{ {
throw new InvalidOperationException(); throw new InvalidOperationException();
@ -128,14 +132,19 @@ public class ModernOpenGLDraw : OpenGLDraw
IntPtr pointer1 = 0; IntPtr pointer1 = 0;
IntPtr pointer2 = 12; IntPtr pointer2 = 12;
IntPtr pointer3 = 20; IntPtr pointer3 = 20;
_gl.VertexAttribPointer(attrib_pos, 3, GLEnum.Float, false, 24, pointer1.ToPointer()); // _gl.VertexAttribPointer(attrib_pos, 3, GLEnum.Float, false, 24, pointer1.ToPointer());
_gl.VertexAttribPointer(attrib_uv, 2, GLEnum.Float, false, 24, pointer2.ToPointer()); // _gl.VertexAttribPointer(attrib_uv, 2, GLEnum.Float, false, 24, pointer2.ToPointer());
_gl.VertexAttribPointer(attrib_col, 4, GLEnum.UnsignedByte, true, 24, pointer3.ToPointer()); // _gl.VertexAttribPointer(attrib_col, 4, GLEnum.UnsignedByte, true, 24, pointer3.ToPointer());
_gl.VertexAttribPointer(attrib_pos, 3, GLEnum.Float, false, 24, (void*)0);
_gl.VertexAttribPointer(attrib_uv, 2, GLEnum.Float, false, 24, (void*)12);
_gl.VertexAttribPointer(attrib_col, 4, GLEnum.UnsignedByte, true, 24, (void*)20);
// _gl.VertexAttribP3(attrib_pos, GLEnum.Float, false, 0); // _gl.VertexAttribP3(attrib_pos, GLEnum.Float, false, 0);
// _gl.VertexAttribP2(attrib_uv, GLEnum.Float, false, 12); // _gl.VertexAttribP2(attrib_uv, GLEnum.Float, false, 12);
// _gl.VertexAttribP4(attrib_col, GLEnum.UnsignedByte, true, 20); // _gl.VertexAttribP4(attrib_col, GLEnum.UnsignedByte, true, 20);
_gl.BindTexture(GLEnum.Texture2D, 0); _gl.BindTexture(GLEnum.Texture2D, 0);
_gl.BindBuffer(GLEnum.ArrayBuffer, 0); _gl.BindBuffer(GLEnum.ArrayBuffer, 0);
_gl.BindBuffer(GLEnum.ElementArrayBuffer, 0); _gl.BindBuffer(GLEnum.ElementArrayBuffer, 0);
@ -183,39 +192,51 @@ public class ModernOpenGLDraw : OpenGLDraw
int vboSize = vertices.Count * 24; int vboSize = vertices.Count * 24;
int eboSize = currentPrim == DebugDrawPrimitives.QUADS ? vertices.Count * 6 : vertices.Count * 4; int eboSize = currentPrim == DebugDrawPrimitives.QUADS ? vertices.Count * 6 : vertices.Count * 4;
// var ssss = new byte[vboSize];
// var ssss2 = new byte[eboSize];
_gl.BufferData(GLEnum.ArrayBuffer, (nuint)vboSize, IntPtr.Zero, GLEnum.StreamDraw); _gl.BufferData(GLEnum.ArrayBuffer, (nuint)vboSize, IntPtr.Zero, GLEnum.StreamDraw);
_gl.BufferData(GLEnum.ElementArrayBuffer, (nuint)eboSize, IntPtr.Zero, GLEnum.StreamDraw); _gl.BufferData(GLEnum.ElementArrayBuffer, (nuint)eboSize, IntPtr.Zero, GLEnum.StreamDraw);
// load draw vertices & elements directly into vertex + element buffer // load draw vertices & elements directly into vertex + element buffer
byte* pVerts = (byte*)_gl.MapBuffer(GLEnum.ArrayBuffer, GLEnum.WriteOnly);
byte* pElems = (byte*)_gl.MapBuffer(GLEnum.ElementArrayBuffer, GLEnum.WriteOnly);
{ {
using var verts = new UnmanagedMemoryStream(pVerts, vboSize, vboSize, FileAccess.Write); byte* pVerts = (byte*)_gl.MapBuffer(GLEnum.ArrayBuffer, GLEnum.WriteOnly);
using var elems = new UnmanagedMemoryStream(pElems, eboSize, eboSize, FileAccess.Write); byte* pElems = (byte*)_gl.MapBuffer(GLEnum.ElementArrayBuffer, GLEnum.WriteOnly);
using var unmanagedVerts = new UnmanagedMemoryStream(pVerts, vboSize, vboSize, FileAccess.Write);
using var unmanagedElems = new UnmanagedMemoryStream(pElems, eboSize, eboSize, FileAccess.Write);
using var verts = new BinaryWriter(unmanagedVerts);
using var elems = new BinaryWriter(unmanagedElems);
vertices.forEach(v => v.store(verts)); vertices.forEach(v => v.store(verts));
if (currentPrim == DebugDrawPrimitives.QUADS) if (currentPrim == DebugDrawPrimitives.QUADS)
{ {
for (int i = 0; i < vertices.Count; i += 4) for (int i = 0; i < vertices.Count; i += 4)
{ {
elems.Write(BitConverter.GetBytes(i)); // elems.Write(BitConverter.GetBytes(i));
elems.Write(BitConverter.GetBytes(i + 1)); // elems.Write(BitConverter.GetBytes(i + 1));
elems.Write(BitConverter.GetBytes(i + 2)); // elems.Write(BitConverter.GetBytes(i + 2));
elems.Write(BitConverter.GetBytes(i)); // elems.Write(BitConverter.GetBytes(i));
elems.Write(BitConverter.GetBytes(i + 2)); // elems.Write(BitConverter.GetBytes(i + 2));
elems.Write(BitConverter.GetBytes(i + 3)); // elems.Write(BitConverter.GetBytes(i + 3));
elems.Write(i);
elems.Write(i + 1);
elems.Write(i + 2);
elems.Write(i);
elems.Write(i + 2);
elems.Write(i + 3);
} }
} }
else else
{ {
for (int i = 0; i < vertices.Count; i++) for (int i = 0; i < vertices.Count; i++)
{ {
elems.Write(BitConverter.GetBytes(i)); //elems.Write(BitConverter.GetBytes(i));
elems.Write(i);
} }
} }
verts.Flush();
elems.Flush();
_gl.UnmapBuffer(GLEnum.ElementArrayBuffer); _gl.UnmapBuffer(GLEnum.ElementArrayBuffer);
_gl.UnmapBuffer(GLEnum.ArrayBuffer); _gl.UnmapBuffer(GLEnum.ArrayBuffer);
@ -229,23 +250,24 @@ public class ModernOpenGLDraw : OpenGLDraw
{ {
_gl.Uniform1(uniformUseTexture, 0.0f); _gl.Uniform1(uniformUseTexture, 0.0f);
} }
//
// switch (currentPrim) { switch (currentPrim)
// case POINTS: {
// glDrawElements(GL_POINTS, vertices.size(), GL_UNSIGNED_INT, 0); case DebugDrawPrimitives.POINTS:
// break; _gl.DrawElements(GLEnum.Points, (uint)vertices.Count, GLEnum.UnsignedInt, 0);
// case LINES: break;
// glDrawElements(GL_LINES, vertices.size(), GL_UNSIGNED_INT, 0); case DebugDrawPrimitives.LINES:
// break; _gl.DrawElements(GLEnum.Lines, (uint)vertices.Count, GLEnum.UnsignedInt, 0);
// case TRIS: break;
// glDrawElements(GL_TRIANGLES, vertices.size(), GL_UNSIGNED_INT, 0); case DebugDrawPrimitives.TRIS:
// break; _gl.DrawElements(GLEnum.Triangles, (uint)vertices.Count, GLEnum.UnsignedInt, 0);
// case QUADS: break;
// glDrawElements(GL_TRIANGLES, vertices.size() * 6 / 4, GL_UNSIGNED_INT, 0); case DebugDrawPrimitives.QUADS:
// break; _gl.DrawElements(GLEnum.Triangles, (uint)(vertices.Count * 6 / 4), GLEnum.UnsignedInt, 0);
// default: break;
// break; default:
// } break;
}
_gl.UseProgram(0); _gl.UseProgram(0);
_gl.BindBuffer(GLEnum.ArrayBuffer, 0); _gl.BindBuffer(GLEnum.ArrayBuffer, 0);

View File

@ -4,7 +4,7 @@ namespace DotRecast.Recast.Demo.Draw;
public interface OpenGLDraw public interface OpenGLDraw
{ {
void init(GL gl); void init();
void clear(); void clear();

View File

@ -38,13 +38,21 @@ public class OpenGLVertex
this.color = color; this.color = color;
} }
public void store(Stream writer) public void store(BinaryWriter writer)
{ {
writer.Write(BitConverter.GetBytes(x)); // writer.Write(BitConverter.GetBytes(x));
writer.Write(BitConverter.GetBytes(y)); // writer.Write(BitConverter.GetBytes(y));
writer.Write(BitConverter.GetBytes(z)); // writer.Write(BitConverter.GetBytes(z));
writer.Write(BitConverter.GetBytes(u)); // writer.Write(BitConverter.GetBytes(u));
writer.Write(BitConverter.GetBytes(v)); // writer.Write(BitConverter.GetBytes(v));
writer.Write(BitConverter.GetBytes(color)); // writer.Write(BitConverter.GetBytes(color));
writer.Write(x);
writer.Write(y);
writer.Write(z);
writer.Write(u);
writer.Write(v);
writer.Write(color);
} }
} }

View File

@ -22,6 +22,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using DotRecast.Detour; using DotRecast.Detour;
using DotRecast.Recast.Demo.Builder; using DotRecast.Recast.Demo.Builder;
using Silk.NET.OpenGL;
namespace DotRecast.Recast.Demo.Draw; namespace DotRecast.Recast.Demo.Draw;
@ -31,6 +32,10 @@ public class RecastDebugDraw : DebugDraw
public static readonly int DRAWNAVMESH_CLOSEDLIST = 0x02; public static readonly int DRAWNAVMESH_CLOSEDLIST = 0x02;
public static readonly int DRAWNAVMESH_COLOR_TILES = 0x04; public static readonly int DRAWNAVMESH_COLOR_TILES = 0x04;
public RecastDebugDraw(GL gl) : base(gl)
{
}
public void debugDrawTriMeshSlope(float[] verts, int[] tris, float[] normals, float walkableSlopeAngle, public void debugDrawTriMeshSlope(float[] verts, int[] tris, float[] normals, float walkableSlopeAngle,
float texScale) float texScale)
{ {

View File

@ -1,5 +1,6 @@
using System.IO; using System.IO;
using DotRecast.Core; using DotRecast.Core;
using Serilog;
namespace DotRecast.Recast.Demo; namespace DotRecast.Recast.Demo;
@ -7,6 +8,11 @@ public static class Program
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.MinimumLevel.Verbose()
.CreateLogger();
var path = Loader.ToRPath("dungeon.obj"); var path = Loader.ToRPath("dungeon.obj");
path = Path.GetDirectoryName(path); path = Path.GetDirectoryName(path);
if (!string.IsNullOrEmpty(path)) if (!string.IsNullOrEmpty(path))

View File

@ -25,7 +25,6 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using System.Runtime.InteropServices;
using Serilog; using Serilog;
using Silk.NET.Input; using Silk.NET.Input;
using Silk.NET.Maths; using Silk.NET.Maths;
@ -53,7 +52,8 @@ namespace DotRecast.Recast.Demo;
public class RecastDemo : MouseListener public class RecastDemo : MouseListener
{ {
private readonly ILogger logger = Log.ForContext<RecastDemo>(); private static readonly ILogger Logger = Log.ForContext<RecastDemo>();
private RcViewSystem _viewSys; private RcViewSystem _viewSys;
private IWindow window; private IWindow window;
private IInputContext _input; private IInputContext _input;
@ -66,7 +66,7 @@ public class RecastDemo : MouseListener
private readonly string title = "DotRecast Demo"; private readonly string title = "DotRecast Demo";
//private readonly RecastDebugDraw dd; //private readonly RecastDebugDraw dd;
private readonly NavMeshRenderer renderer; private NavMeshRenderer renderer;
private bool building = false; private bool building = false;
private float timeAcc = 0; private float timeAcc = 0;
private float camr = 1000; private float camr = 1000;
@ -107,8 +107,6 @@ public class RecastDemo : MouseListener
public RecastDemo() public RecastDemo()
{ {
dd = new RecastDebugDraw();
renderer = new NavMeshRenderer(dd);
} }
public void start() public void start()
@ -294,7 +292,6 @@ public class RecastDemo : MouseListener
// glfwWindowHint(GLFW_BLUE_BITS, mode.blueBits()); // glfwWindowHint(GLFW_BLUE_BITS, mode.blueBits());
// glfwWindowHint(GLFW_REFRESH_RATE, mode.refreshRate()); // glfwWindowHint(GLFW_REFRESH_RATE, mode.refreshRate());
var options = WindowOptions.Default; var options = WindowOptions.Default;
options.Title = title; options.Title = title;
options.Size = new Vector2D<int>(width, height); options.Size = new Vector2D<int>(width, height);
@ -385,7 +382,11 @@ public class RecastDemo : MouseListener
_input = window.CreateInput(); _input = window.CreateInput();
_gl = window.CreateOpenGL(); _gl = window.CreateOpenGL();
dd.init(_gl, camr);
dd = new RecastDebugDraw(_gl);
renderer = new NavMeshRenderer(dd);
dd.init(camr);
_imgui = new ImGuiController(_gl, window, _input); _imgui = new ImGuiController(_gl, window, _input);
@ -399,19 +400,16 @@ public class RecastDemo : MouseListener
// // ARBDebugOutput.GL_DEBUG_TYPE_OTHER_ARB, ARBDebugOutput.GL_DEBUG_SEVERITY_LOW_ARB, (int[]) null, false); // // ARBDebugOutput.GL_DEBUG_TYPE_OTHER_ARB, ARBDebugOutput.GL_DEBUG_SEVERITY_LOW_ARB, (int[]) null, false);
// // } // // }
var vendor = _gl.GetStringS(GLEnum.Vendor); var vendor = _gl.GetStringS(GLEnum.Vendor);
logger.Debug(vendor); Logger.Debug(vendor);
var version = _gl.GetStringS(GLEnum.Version); var version = _gl.GetStringS(GLEnum.Version);
logger.Debug(version); Logger.Debug(version);
var renderGl = _gl.GetStringS(GLEnum.Renderer); var renderGl = _gl.GetStringS(GLEnum.Renderer);
logger.Debug(renderGl); Logger.Debug(renderGl);
var glslString = _gl.GetStringS(GLEnum.ShadingLanguageVersion); var glslString = _gl.GetStringS(GLEnum.ShadingLanguageVersion);
logger.Debug(glslString); Logger.Debug(glslString);
window.CreateInput();
settingsUI = new RcSettingsView(); settingsUI = new RcSettingsView();
toolsUI = new ToolsView( toolsUI = new ToolsView(
@ -435,43 +433,43 @@ public class RecastDemo : MouseListener
* try (MemoryStack stack = stackPush()) { int[] w = stack.mallocInt(1); int[] h = * try (MemoryStack stack = stackPush()) { int[] w = stack.mallocInt(1); int[] h =
* stack.mallocInt(1); glfwGetWindowSize(win, w, h); width = w[0]; height = h[0]; } * stack.mallocInt(1); glfwGetWindowSize(win, w, h); width = w[0]; height = h[0]; }
*/ */
if (sample.getInputGeom() != null) // if (sample.getInputGeom() != null)
{ // {
float[] bmin = sample.getInputGeom().getMeshBoundsMin(); // float[] bmin = sample.getInputGeom().getMeshBoundsMin();
float[] bmax = sample.getInputGeom().getMeshBoundsMax(); // float[] bmax = sample.getInputGeom().getMeshBoundsMax();
int[] voxels = Recast.calcGridSize(bmin, bmax, settingsUI.getCellSize()); // int[] voxels = Recast.calcGridSize(bmin, bmax, settingsUI.getCellSize());
settingsUI.setVoxels(voxels); // settingsUI.setVoxels(voxels);
settingsUI.setTiles(tileNavMeshBuilder.getTiles(sample.getInputGeom(), settingsUI.getCellSize(), settingsUI.getTileSize())); // settingsUI.setTiles(tileNavMeshBuilder.getTiles(sample.getInputGeom(), settingsUI.getCellSize(), settingsUI.getTileSize()));
settingsUI.setMaxTiles(tileNavMeshBuilder.getMaxTiles(sample.getInputGeom(), settingsUI.getCellSize(), settingsUI.getTileSize())); // settingsUI.setMaxTiles(tileNavMeshBuilder.getMaxTiles(sample.getInputGeom(), settingsUI.getCellSize(), settingsUI.getTileSize()));
settingsUI.setMaxPolys(tileNavMeshBuilder.getMaxPolysPerTile(sample.getInputGeom(), settingsUI.getCellSize(), settingsUI.getTileSize())); // settingsUI.setMaxPolys(tileNavMeshBuilder.getMaxPolysPerTile(sample.getInputGeom(), settingsUI.getCellSize(), settingsUI.getTileSize()));
} // }
_viewSys.inputBegin(); //_viewSys.inputBegin();
window.DoEvents(); // window.DoEvents();
_viewSys.inputEnd(window); // _viewSys.inputEnd(window);
long time = Stopwatch.GetTimestamp() / 1000; // long time = Stopwatch.GetTimestamp() / 1000;
//float dt = (time - prevFrameTime) / 1000000.0f; // //float dt = (time - prevFrameTime) / 1000000.0f;
prevFrameTime = time; // prevFrameTime = time;
//
// // Update sample simulation.
// float SIM_RATE = 20;
// float DELTA_TIME = 1.0f / SIM_RATE;
// timeAcc = clamp((float)(timeAcc + dt), -1.0f, 1.0f);
// int simIter = 0;
// while (timeAcc > DELTA_TIME)
// {
// timeAcc -= DELTA_TIME;
// if (simIter < 5 && sample != null)
// {
// toolsUI.handleUpdate((float)dt);
// }
//
// simIter++;
// }
// Update sample simulation. // if (settingsUI.isMeshInputTrigerred())
float SIM_RATE = 20; // {
float DELTA_TIME = 1.0f / SIM_RATE;
timeAcc = clamp((float)(timeAcc + dt), -1.0f, 1.0f);
int simIter = 0;
while (timeAcc > DELTA_TIME)
{
timeAcc -= DELTA_TIME;
if (simIter < 5 && sample != null)
{
toolsUI.handleUpdate((float)dt);
}
simIter++;
}
if (settingsUI.isMeshInputTrigerred())
{
// aFilterPatterns.put(stack.UTF8("*.obj")); // aFilterPatterns.put(stack.UTF8("*.obj"));
// aFilterPatterns.flip(); // aFilterPatterns.flip();
// string filename = TinyFileDialogs.tinyfd_openFileDialog("Open Mesh File", "", aFilterPatterns, // string filename = TinyFileDialogs.tinyfd_openFileDialog("Open Mesh File", "", aFilterPatterns,
@ -483,9 +481,9 @@ public class RecastDemo : MouseListener
// Console.WriteLine(e).printStackTrace(); // Console.WriteLine(e).printStackTrace();
// } // }
// } // }
} // }
else if (settingsUI.isNavMeshInputTrigerred()) // else if (settingsUI.isNavMeshInputTrigerred())
{ // {
// try (MemoryStack stack = stackPush()) { // try (MemoryStack stack = stackPush()) {
// PointerBuffer aFilterPatterns = stack.mallocPointer(4); // PointerBuffer aFilterPatterns = stack.mallocPointer(4);
// aFilterPatterns.put(stack.UTF8("*.bin")); // aFilterPatterns.put(stack.UTF8("*.bin"));
@ -507,58 +505,58 @@ public class RecastDemo : MouseListener
// } // }
// } // }
// } // }
} // }
else if (settingsUI.isBuildTriggered() && sample.getInputGeom() != null) // else if (settingsUI.isBuildTriggered() && sample.getInputGeom() != null)
{ // {
if (!building) // if (!building)
{ // {
float m_cellSize = settingsUI.getCellSize(); // float m_cellSize = settingsUI.getCellSize();
float m_cellHeight = settingsUI.getCellHeight(); // float m_cellHeight = settingsUI.getCellHeight();
float m_agentHeight = settingsUI.getAgentHeight(); // float m_agentHeight = settingsUI.getAgentHeight();
float m_agentRadius = settingsUI.getAgentRadius(); // float m_agentRadius = settingsUI.getAgentRadius();
float m_agentMaxClimb = settingsUI.getAgentMaxClimb(); // float m_agentMaxClimb = settingsUI.getAgentMaxClimb();
float m_agentMaxSlope = settingsUI.getAgentMaxSlope(); // float m_agentMaxSlope = settingsUI.getAgentMaxSlope();
int m_regionMinSize = settingsUI.getMinRegionSize(); // int m_regionMinSize = settingsUI.getMinRegionSize();
int m_regionMergeSize = settingsUI.getMergedRegionSize(); // int m_regionMergeSize = settingsUI.getMergedRegionSize();
float m_edgeMaxLen = settingsUI.getEdgeMaxLen(); // float m_edgeMaxLen = settingsUI.getEdgeMaxLen();
float m_edgeMaxError = settingsUI.getEdgeMaxError(); // float m_edgeMaxError = settingsUI.getEdgeMaxError();
int m_vertsPerPoly = settingsUI.getVertsPerPoly(); // int m_vertsPerPoly = settingsUI.getVertsPerPoly();
float m_detailSampleDist = settingsUI.getDetailSampleDist(); // float m_detailSampleDist = settingsUI.getDetailSampleDist();
float m_detailSampleMaxError = settingsUI.getDetailSampleMaxError(); // float m_detailSampleMaxError = settingsUI.getDetailSampleMaxError();
int m_tileSize = settingsUI.getTileSize(); // int m_tileSize = settingsUI.getTileSize();
long t = Stopwatch.GetTimestamp(); // long t = Stopwatch.GetTimestamp();
//
// Tuple<IList<RecastBuilderResult>, NavMesh> buildResult;
// if (settingsUI.isTiled())
// {
// buildResult = tileNavMeshBuilder.build(sample.getInputGeom(), settingsUI.getPartitioning(), m_cellSize,
// m_cellHeight, m_agentHeight, m_agentRadius, m_agentMaxClimb, m_agentMaxSlope, m_regionMinSize,
// m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError, m_vertsPerPoly, m_detailSampleDist,
// m_detailSampleMaxError, settingsUI.isFilterLowHangingObstacles(), settingsUI.isFilterLedgeSpans(),
// settingsUI.isFilterWalkableLowHeightSpans(), m_tileSize);
// }
// else
// {
// buildResult = soloNavMeshBuilder.build(sample.getInputGeom(), settingsUI.getPartitioning(), m_cellSize,
// m_cellHeight, m_agentHeight, m_agentRadius, m_agentMaxClimb, m_agentMaxSlope, m_regionMinSize,
// m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError, m_vertsPerPoly, m_detailSampleDist,
// m_detailSampleMaxError, settingsUI.isFilterLowHangingObstacles(), settingsUI.isFilterLedgeSpans(),
// settingsUI.isFilterWalkableLowHeightSpans());
// }
//
// sample.update(sample.getInputGeom(), buildResult.Item1, buildResult.Item2);
// sample.setChanged(false);
// settingsUI.setBuildTime((Stopwatch.GetTimestamp() - t) / 1_000_000);
// toolsUI.setSample(sample);
// }
// }
// else
// {
// building = false;
// }
Tuple<IList<RecastBuilderResult>, NavMesh> buildResult; // if (!mouseOverMenu)
if (settingsUI.isTiled()) // {
{
buildResult = tileNavMeshBuilder.build(sample.getInputGeom(), settingsUI.getPartitioning(), m_cellSize,
m_cellHeight, m_agentHeight, m_agentRadius, m_agentMaxClimb, m_agentMaxSlope, m_regionMinSize,
m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError, m_vertsPerPoly, m_detailSampleDist,
m_detailSampleMaxError, settingsUI.isFilterLowHangingObstacles(), settingsUI.isFilterLedgeSpans(),
settingsUI.isFilterWalkableLowHeightSpans(), m_tileSize);
}
else
{
buildResult = soloNavMeshBuilder.build(sample.getInputGeom(), settingsUI.getPartitioning(), m_cellSize,
m_cellHeight, m_agentHeight, m_agentRadius, m_agentMaxClimb, m_agentMaxSlope, m_regionMinSize,
m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError, m_vertsPerPoly, m_detailSampleDist,
m_detailSampleMaxError, settingsUI.isFilterLowHangingObstacles(), settingsUI.isFilterLedgeSpans(),
settingsUI.isFilterWalkableLowHeightSpans());
}
sample.update(sample.getInputGeom(), buildResult.Item1, buildResult.Item2);
sample.setChanged(false);
settingsUI.setBuildTime((Stopwatch.GetTimestamp() - t) / 1_000_000);
toolsUI.setSample(sample);
}
}
else
{
building = false;
}
if (!mouseOverMenu)
{
// GLU.glhUnProjectf(mousePos[0], viewport[3] - 1 - mousePos[1], 0.0f, modelviewMatrix, projectionMatrix, viewport, // GLU.glhUnProjectf(mousePos[0], viewport[3] - 1 - mousePos[1], 0.0f, modelviewMatrix, projectionMatrix, viewport,
// rayStart); // rayStart);
// GLU.glhUnProjectf(mousePos[0], viewport[3] - 1 - mousePos[1], 1.0f, modelviewMatrix, projectionMatrix, viewport, // GLU.glhUnProjectf(mousePos[0], viewport[3] - 1 - mousePos[1], 1.0f, modelviewMatrix, projectionMatrix, viewport,
@ -617,8 +615,8 @@ public class RecastDemo : MouseListener
// // } // // }
// } // }
processHitTest = false; // processHitTest = false;
} // }
if (sample.isChanged()) if (sample.isChanged())
{ {
@ -693,7 +691,7 @@ public class RecastDemo : MouseListener
// Set the viewport. // Set the viewport.
// glViewport(0, 0, width, height); // glViewport(0, 0, width, height);
//_gl.Viewport(0, 0, (uint)width, (uint)height); //_gl.Viewport(0, 0, (uint)width, (uint)height);
//int[] viewport = new int[] { 0, 0, width, height }; int[] viewport = new int[] { 0, 0, width, height };
// glGetIntegerv(GL_VIEWPORT, viewport); // glGetIntegerv(GL_VIEWPORT, viewport);
// Clear the screen // Clear the screen
@ -703,17 +701,17 @@ public class RecastDemo : MouseListener
dd.fog(camr * 0.1f, camr * 1.25f); dd.fog(camr * 0.1f, camr * 1.25f);
renderer.render(sample); renderer.render(sample);
Tool tool = toolsUI.getTool(); // Tool tool = toolsUI.getTool();
if (tool != null) // if (tool != null)
{ // {
tool.handleRender(renderer); // tool.handleRender(renderer);
} // }
dd.fog(false); dd.fog(false);
mouseOverMenu = _viewSys.render(window, 0, 0, width, height, (int)mousePos[0], (int)mousePos[1]); //mouseOverMenu = _viewSys.render(window, 0, 0, width, height, (int)mousePos[0], (int)mousePos[1]);
_imgui.Render(); //_imgui.Render();
window.SwapBuffers(); window.SwapBuffers();
} }