forked from bit/DotRecastNetSim
test rendering
This commit is contained in:
parent
6ef631457e
commit
07b13aae4d
|
@ -8,6 +8,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<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.OpenGL.Extensions.ImGui" Version="2.16.0" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -27,19 +27,25 @@ namespace DotRecast.Recast.Demo.Draw;
|
|||
|
||||
public class DebugDraw
|
||||
{
|
||||
private readonly GLCheckerTexture g_tex = new GLCheckerTexture();
|
||||
private readonly OpenGLDraw openGlDraw = new ModernOpenGLDraw();
|
||||
private readonly GLCheckerTexture g_tex;
|
||||
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 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 },
|
||||
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 },
|
||||
};
|
||||
g_tex = new GLCheckerTexture(gl);
|
||||
openGlDraw = new ModernOpenGLDraw(gl);
|
||||
}
|
||||
|
||||
|
||||
public void begin(DebugDrawPrimitives prim)
|
||||
|
@ -554,9 +560,9 @@ public class DebugDraw
|
|||
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()
|
||||
|
|
|
@ -24,42 +24,58 @@ namespace DotRecast.Recast.Demo.Draw;
|
|||
|
||||
public class GLCheckerTexture
|
||||
{
|
||||
int m_texId;
|
||||
private readonly GL _gl;
|
||||
private uint m_texId;
|
||||
|
||||
public GLCheckerTexture(GL gl)
|
||||
{
|
||||
_gl = gl;
|
||||
}
|
||||
|
||||
public void release()
|
||||
{
|
||||
// if (m_texId != 0) {
|
||||
// glDeleteTextures(m_texId);
|
||||
// }
|
||||
if (m_texId != 0)
|
||||
{
|
||||
_gl.DeleteTextures(1, m_texId);
|
||||
}
|
||||
}
|
||||
|
||||
public void bind()
|
||||
{
|
||||
// if (m_texId == 0) {
|
||||
// // Create checker pattern.
|
||||
// int col0 = DebugDraw.duRGBA(215, 215, 215, 255);
|
||||
// int col1 = DebugDraw.duRGBA(255, 255, 255, 255);
|
||||
// int TSIZE = 64;
|
||||
// int[] data = new int[TSIZE * TSIZE];
|
||||
//
|
||||
// m_texId = glGenTextures();
|
||||
// glBindTexture(GL_TEXTURE_2D, m_texId);
|
||||
//
|
||||
// int level = 0;
|
||||
// int size = TSIZE;
|
||||
// while (size > 0) {
|
||||
// for (int y = 0; y < size; ++y)
|
||||
// for (int x = 0; x < size; ++x)
|
||||
// data[x + y * size] = (x == 0 || y == 0) ? col0 : col1;
|
||||
// glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
||||
// size /= 2;
|
||||
// level++;
|
||||
// }
|
||||
//
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
||||
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
// } else {
|
||||
// glBindTexture(GL_TEXTURE_2D, m_texId);
|
||||
// }
|
||||
if (m_texId == 0)
|
||||
{
|
||||
// Create checker pattern.
|
||||
int col0 = DebugDraw.duRGBA(215, 215, 215, 255);
|
||||
int col1 = DebugDraw.duRGBA(255, 255, 255, 255);
|
||||
uint TSIZE = 64;
|
||||
int[] data = new int[TSIZE * TSIZE];
|
||||
|
||||
_gl.GenTextures(1, out m_texId);
|
||||
_gl.BindTexture(GLEnum.Texture2D, m_texId);
|
||||
|
||||
int level = 0;
|
||||
uint size = TSIZE;
|
||||
while (size > 0)
|
||||
{
|
||||
for (int y = 0; y < size; ++y)
|
||||
{
|
||||
for (int x = 0; x < size; ++x)
|
||||
{
|
||||
data[x + y * size] = (x == 0 || y == 0) ? col0 : col1;
|
||||
}
|
||||
}
|
||||
|
||||
_gl.TexImage2D<int>(GLEnum.Texture2D, level, InternalFormat.Rgba, size, size, 0, GLEnum.Rgba, GLEnum.UnsignedByte, data);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,9 @@ namespace DotRecast.Recast.Demo.Draw;
|
|||
|
||||
public class LegacyOpenGLDraw : OpenGLDraw
|
||||
{
|
||||
private GL _gl;
|
||||
public LegacyOpenGLDraw(GL gl)
|
||||
{
|
||||
}
|
||||
|
||||
public void fog(bool state)
|
||||
{
|
||||
|
@ -15,10 +17,8 @@ public class LegacyOpenGLDraw : OpenGLDraw
|
|||
// }
|
||||
}
|
||||
|
||||
public void init(GL gl)
|
||||
public void init()
|
||||
{
|
||||
_gl = gl;
|
||||
|
||||
// // Fog.
|
||||
// float fogDistance = 1000f;
|
||||
// float fogColor[] = { 0.32f, 0.31f, 0.30f, 1.0f };
|
||||
|
|
|
@ -36,9 +36,13 @@ public class ModernOpenGLDraw : OpenGLDraw
|
|||
private int uniformFogStart;
|
||||
private int uniformFogEnd;
|
||||
|
||||
public unsafe void init(GL gl)
|
||||
public ModernOpenGLDraw(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 vertex_shader = NK_SHADER_VERSION + "uniform mat4 ProjMtx;\n" //
|
||||
+ "uniform mat4 ViewMtx;\n" //
|
||||
|
@ -77,13 +81,13 @@ public class ModernOpenGLDraw : OpenGLDraw
|
|||
_gl.ShaderSource(frag_shdr, fragment_shader);
|
||||
_gl.CompileShader(vert_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)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
gl.GetShader(frag_shdr, GLEnum.CompileStatus, out status);
|
||||
_gl.GetShader(frag_shdr, GLEnum.CompileStatus, out status);
|
||||
if (status != (int)GLEnum.True)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
|
@ -128,14 +132,19 @@ public class ModernOpenGLDraw : OpenGLDraw
|
|||
IntPtr pointer1 = 0;
|
||||
IntPtr pointer2 = 12;
|
||||
IntPtr pointer3 = 20;
|
||||
_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_col, 4, GLEnum.UnsignedByte, true, 24, pointer3.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_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.VertexAttribP2(attrib_uv, GLEnum.Float, false, 12);
|
||||
// _gl.VertexAttribP4(attrib_col, GLEnum.UnsignedByte, true, 20);
|
||||
|
||||
|
||||
_gl.BindTexture(GLEnum.Texture2D, 0);
|
||||
_gl.BindBuffer(GLEnum.ArrayBuffer, 0);
|
||||
_gl.BindBuffer(GLEnum.ElementArrayBuffer, 0);
|
||||
|
@ -180,42 +189,54 @@ public class ModernOpenGLDraw : OpenGLDraw
|
|||
_gl.BindBuffer(GLEnum.ElementArrayBuffer, ebo);
|
||||
// glBufferData(GL_ARRAY_BUFFER, MAX_VERTEX_BUFFER, GL_STREAM_DRAW);
|
||||
// glBufferData(GL_ELEMENT_ARRAY_BUFFER, MAX_ELEMENT_BUFFER, GL_STREAM_DRAW);
|
||||
|
||||
|
||||
int vboSize = vertices.Count * 24;
|
||||
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.ElementArrayBuffer, (nuint)eboSize, IntPtr.Zero, GLEnum.StreamDraw);
|
||||
// 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);
|
||||
using var elems = new UnmanagedMemoryStream(pElems, eboSize, eboSize, FileAccess.Write);
|
||||
byte* pVerts = (byte*)_gl.MapBuffer(GLEnum.ArrayBuffer, GLEnum.WriteOnly);
|
||||
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));
|
||||
if (currentPrim == DebugDrawPrimitives.QUADS)
|
||||
{
|
||||
for (int i = 0; i < vertices.Count; i += 4)
|
||||
{
|
||||
elems.Write(BitConverter.GetBytes(i));
|
||||
elems.Write(BitConverter.GetBytes(i + 1));
|
||||
elems.Write(BitConverter.GetBytes(i + 2));
|
||||
elems.Write(BitConverter.GetBytes(i));
|
||||
elems.Write(BitConverter.GetBytes(i + 2));
|
||||
elems.Write(BitConverter.GetBytes(i + 3));
|
||||
// elems.Write(BitConverter.GetBytes(i));
|
||||
// elems.Write(BitConverter.GetBytes(i + 1));
|
||||
// elems.Write(BitConverter.GetBytes(i + 2));
|
||||
// elems.Write(BitConverter.GetBytes(i));
|
||||
// elems.Write(BitConverter.GetBytes(i + 2));
|
||||
// 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
|
||||
{
|
||||
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.ArrayBuffer);
|
||||
|
@ -229,24 +250,25 @@ public class ModernOpenGLDraw : OpenGLDraw
|
|||
{
|
||||
_gl.Uniform1(uniformUseTexture, 0.0f);
|
||||
}
|
||||
//
|
||||
// switch (currentPrim) {
|
||||
// case POINTS:
|
||||
// glDrawElements(GL_POINTS, vertices.size(), GL_UNSIGNED_INT, 0);
|
||||
// break;
|
||||
// case LINES:
|
||||
// glDrawElements(GL_LINES, vertices.size(), GL_UNSIGNED_INT, 0);
|
||||
// break;
|
||||
// case TRIS:
|
||||
// glDrawElements(GL_TRIANGLES, vertices.size(), GL_UNSIGNED_INT, 0);
|
||||
// break;
|
||||
// case QUADS:
|
||||
// glDrawElements(GL_TRIANGLES, vertices.size() * 6 / 4, GL_UNSIGNED_INT, 0);
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
|
||||
|
||||
switch (currentPrim)
|
||||
{
|
||||
case DebugDrawPrimitives.POINTS:
|
||||
_gl.DrawElements(GLEnum.Points, (uint)vertices.Count, GLEnum.UnsignedInt, 0);
|
||||
break;
|
||||
case DebugDrawPrimitives.LINES:
|
||||
_gl.DrawElements(GLEnum.Lines, (uint)vertices.Count, GLEnum.UnsignedInt, 0);
|
||||
break;
|
||||
case DebugDrawPrimitives.TRIS:
|
||||
_gl.DrawElements(GLEnum.Triangles, (uint)vertices.Count, GLEnum.UnsignedInt, 0);
|
||||
break;
|
||||
case DebugDrawPrimitives.QUADS:
|
||||
_gl.DrawElements(GLEnum.Triangles, (uint)(vertices.Count * 6 / 4), GLEnum.UnsignedInt, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
_gl.UseProgram(0);
|
||||
_gl.BindBuffer(GLEnum.ArrayBuffer, 0);
|
||||
_gl.BindBuffer(GLEnum.ElementArrayBuffer, 0);
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace DotRecast.Recast.Demo.Draw;
|
|||
|
||||
public interface OpenGLDraw
|
||||
{
|
||||
void init(GL gl);
|
||||
void init();
|
||||
|
||||
void clear();
|
||||
|
||||
|
|
|
@ -38,13 +38,21 @@ public class OpenGLVertex
|
|||
this.color = color;
|
||||
}
|
||||
|
||||
public void store(Stream writer)
|
||||
public void store(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(BitConverter.GetBytes(x));
|
||||
writer.Write(BitConverter.GetBytes(y));
|
||||
writer.Write(BitConverter.GetBytes(z));
|
||||
writer.Write(BitConverter.GetBytes(u));
|
||||
writer.Write(BitConverter.GetBytes(v));
|
||||
writer.Write(BitConverter.GetBytes(color));
|
||||
// writer.Write(BitConverter.GetBytes(x));
|
||||
// writer.Write(BitConverter.GetBytes(y));
|
||||
// writer.Write(BitConverter.GetBytes(z));
|
||||
// writer.Write(BitConverter.GetBytes(u));
|
||||
// writer.Write(BitConverter.GetBytes(v));
|
||||
// writer.Write(BitConverter.GetBytes(color));
|
||||
|
||||
writer.Write(x);
|
||||
writer.Write(y);
|
||||
writer.Write(z);
|
||||
writer.Write(u);
|
||||
writer.Write(v);
|
||||
writer.Write(color);
|
||||
|
||||
}
|
||||
}
|
|
@ -22,6 +22,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using DotRecast.Detour;
|
||||
using DotRecast.Recast.Demo.Builder;
|
||||
using Silk.NET.OpenGL;
|
||||
|
||||
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_COLOR_TILES = 0x04;
|
||||
|
||||
public RecastDebugDraw(GL gl) : base(gl)
|
||||
{
|
||||
}
|
||||
|
||||
public void debugDrawTriMeshSlope(float[] verts, int[] tris, float[] normals, float walkableSlopeAngle,
|
||||
float texScale)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System.IO;
|
||||
using DotRecast.Core;
|
||||
using Serilog;
|
||||
|
||||
namespace DotRecast.Recast.Demo;
|
||||
|
||||
|
@ -7,6 +8,11 @@ public static class Program
|
|||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.WriteTo.Console()
|
||||
.MinimumLevel.Verbose()
|
||||
.CreateLogger();
|
||||
|
||||
var path = Loader.ToRPath("dungeon.obj");
|
||||
path = Path.GetDirectoryName(path);
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
|
|
|
@ -25,7 +25,6 @@ using System.Diagnostics;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using Serilog;
|
||||
using Silk.NET.Input;
|
||||
using Silk.NET.Maths;
|
||||
|
@ -53,7 +52,8 @@ namespace DotRecast.Recast.Demo;
|
|||
|
||||
public class RecastDemo : MouseListener
|
||||
{
|
||||
private readonly ILogger logger = Log.ForContext<RecastDemo>();
|
||||
private static readonly ILogger Logger = Log.ForContext<RecastDemo>();
|
||||
|
||||
private RcViewSystem _viewSys;
|
||||
private IWindow window;
|
||||
private IInputContext _input;
|
||||
|
@ -66,7 +66,7 @@ public class RecastDemo : MouseListener
|
|||
private readonly string title = "DotRecast Demo";
|
||||
|
||||
//private readonly RecastDebugDraw dd;
|
||||
private readonly NavMeshRenderer renderer;
|
||||
private NavMeshRenderer renderer;
|
||||
private bool building = false;
|
||||
private float timeAcc = 0;
|
||||
private float camr = 1000;
|
||||
|
@ -107,8 +107,6 @@ public class RecastDemo : MouseListener
|
|||
|
||||
public RecastDemo()
|
||||
{
|
||||
dd = new RecastDebugDraw();
|
||||
renderer = new NavMeshRenderer(dd);
|
||||
}
|
||||
|
||||
public void start()
|
||||
|
@ -294,7 +292,6 @@ public class RecastDemo : MouseListener
|
|||
// glfwWindowHint(GLFW_BLUE_BITS, mode.blueBits());
|
||||
// glfwWindowHint(GLFW_REFRESH_RATE, mode.refreshRate());
|
||||
|
||||
|
||||
var options = WindowOptions.Default;
|
||||
options.Title = title;
|
||||
options.Size = new Vector2D<int>(width, height);
|
||||
|
@ -385,7 +382,11 @@ public class RecastDemo : MouseListener
|
|||
|
||||
_input = window.CreateInput();
|
||||
_gl = window.CreateOpenGL();
|
||||
dd.init(_gl, camr);
|
||||
|
||||
dd = new RecastDebugDraw(_gl);
|
||||
renderer = new NavMeshRenderer(dd);
|
||||
|
||||
dd.init(camr);
|
||||
|
||||
_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);
|
||||
// // }
|
||||
var vendor = _gl.GetStringS(GLEnum.Vendor);
|
||||
logger.Debug(vendor);
|
||||
Logger.Debug(vendor);
|
||||
|
||||
var version = _gl.GetStringS(GLEnum.Version);
|
||||
logger.Debug(version);
|
||||
Logger.Debug(version);
|
||||
|
||||
var renderGl = _gl.GetStringS(GLEnum.Renderer);
|
||||
logger.Debug(renderGl);
|
||||
Logger.Debug(renderGl);
|
||||
|
||||
var glslString = _gl.GetStringS(GLEnum.ShadingLanguageVersion);
|
||||
logger.Debug(glslString);
|
||||
|
||||
window.CreateInput();
|
||||
|
||||
Logger.Debug(glslString);
|
||||
|
||||
settingsUI = new RcSettingsView();
|
||||
toolsUI = new ToolsView(
|
||||
|
@ -435,43 +433,43 @@ public class RecastDemo : MouseListener
|
|||
* try (MemoryStack stack = stackPush()) { int[] w = stack.mallocInt(1); int[] h =
|
||||
* stack.mallocInt(1); glfwGetWindowSize(win, w, h); width = w[0]; height = h[0]; }
|
||||
*/
|
||||
if (sample.getInputGeom() != null)
|
||||
{
|
||||
float[] bmin = sample.getInputGeom().getMeshBoundsMin();
|
||||
float[] bmax = sample.getInputGeom().getMeshBoundsMax();
|
||||
int[] voxels = Recast.calcGridSize(bmin, bmax, settingsUI.getCellSize());
|
||||
settingsUI.setVoxels(voxels);
|
||||
settingsUI.setTiles(tileNavMeshBuilder.getTiles(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()));
|
||||
}
|
||||
// if (sample.getInputGeom() != null)
|
||||
// {
|
||||
// float[] bmin = sample.getInputGeom().getMeshBoundsMin();
|
||||
// float[] bmax = sample.getInputGeom().getMeshBoundsMax();
|
||||
// int[] voxels = Recast.calcGridSize(bmin, bmax, settingsUI.getCellSize());
|
||||
// settingsUI.setVoxels(voxels);
|
||||
// settingsUI.setTiles(tileNavMeshBuilder.getTiles(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()));
|
||||
// }
|
||||
|
||||
_viewSys.inputBegin();
|
||||
window.DoEvents();
|
||||
_viewSys.inputEnd(window);
|
||||
//_viewSys.inputBegin();
|
||||
// window.DoEvents();
|
||||
// _viewSys.inputEnd(window);
|
||||
|
||||
long time = Stopwatch.GetTimestamp() / 1000;
|
||||
//float dt = (time - prevFrameTime) / 1000000.0f;
|
||||
prevFrameTime = time;
|
||||
// long time = Stopwatch.GetTimestamp() / 1000;
|
||||
// //float dt = (time - prevFrameTime) / 1000000.0f;
|
||||
// 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.
|
||||
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())
|
||||
{
|
||||
// if (settingsUI.isMeshInputTrigerred())
|
||||
// {
|
||||
// aFilterPatterns.put(stack.UTF8("*.obj"));
|
||||
// aFilterPatterns.flip();
|
||||
// string filename = TinyFileDialogs.tinyfd_openFileDialog("Open Mesh File", "", aFilterPatterns,
|
||||
|
@ -483,9 +481,9 @@ public class RecastDemo : MouseListener
|
|||
// Console.WriteLine(e).printStackTrace();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
else if (settingsUI.isNavMeshInputTrigerred())
|
||||
{
|
||||
// }
|
||||
// else if (settingsUI.isNavMeshInputTrigerred())
|
||||
// {
|
||||
// try (MemoryStack stack = stackPush()) {
|
||||
// PointerBuffer aFilterPatterns = stack.mallocPointer(4);
|
||||
// aFilterPatterns.put(stack.UTF8("*.bin"));
|
||||
|
@ -507,58 +505,58 @@ public class RecastDemo : MouseListener
|
|||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
else if (settingsUI.isBuildTriggered() && sample.getInputGeom() != null)
|
||||
{
|
||||
if (!building)
|
||||
{
|
||||
float m_cellSize = settingsUI.getCellSize();
|
||||
float m_cellHeight = settingsUI.getCellHeight();
|
||||
float m_agentHeight = settingsUI.getAgentHeight();
|
||||
float m_agentRadius = settingsUI.getAgentRadius();
|
||||
float m_agentMaxClimb = settingsUI.getAgentMaxClimb();
|
||||
float m_agentMaxSlope = settingsUI.getAgentMaxSlope();
|
||||
int m_regionMinSize = settingsUI.getMinRegionSize();
|
||||
int m_regionMergeSize = settingsUI.getMergedRegionSize();
|
||||
float m_edgeMaxLen = settingsUI.getEdgeMaxLen();
|
||||
float m_edgeMaxError = settingsUI.getEdgeMaxError();
|
||||
int m_vertsPerPoly = settingsUI.getVertsPerPoly();
|
||||
float m_detailSampleDist = settingsUI.getDetailSampleDist();
|
||||
float m_detailSampleMaxError = settingsUI.getDetailSampleMaxError();
|
||||
int m_tileSize = settingsUI.getTileSize();
|
||||
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;
|
||||
}
|
||||
// }
|
||||
// else if (settingsUI.isBuildTriggered() && sample.getInputGeom() != null)
|
||||
// {
|
||||
// if (!building)
|
||||
// {
|
||||
// float m_cellSize = settingsUI.getCellSize();
|
||||
// float m_cellHeight = settingsUI.getCellHeight();
|
||||
// float m_agentHeight = settingsUI.getAgentHeight();
|
||||
// float m_agentRadius = settingsUI.getAgentRadius();
|
||||
// float m_agentMaxClimb = settingsUI.getAgentMaxClimb();
|
||||
// float m_agentMaxSlope = settingsUI.getAgentMaxSlope();
|
||||
// int m_regionMinSize = settingsUI.getMinRegionSize();
|
||||
// int m_regionMergeSize = settingsUI.getMergedRegionSize();
|
||||
// float m_edgeMaxLen = settingsUI.getEdgeMaxLen();
|
||||
// float m_edgeMaxError = settingsUI.getEdgeMaxError();
|
||||
// int m_vertsPerPoly = settingsUI.getVertsPerPoly();
|
||||
// float m_detailSampleDist = settingsUI.getDetailSampleDist();
|
||||
// float m_detailSampleMaxError = settingsUI.getDetailSampleMaxError();
|
||||
// int m_tileSize = settingsUI.getTileSize();
|
||||
// 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;
|
||||
// }
|
||||
|
||||
if (!mouseOverMenu)
|
||||
{
|
||||
// if (!mouseOverMenu)
|
||||
// {
|
||||
// GLU.glhUnProjectf(mousePos[0], viewport[3] - 1 - mousePos[1], 0.0f, modelviewMatrix, projectionMatrix, viewport,
|
||||
// rayStart);
|
||||
// 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())
|
||||
{
|
||||
|
@ -693,7 +691,7 @@ public class RecastDemo : MouseListener
|
|||
// Set the viewport.
|
||||
// glViewport(0, 0, width, 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);
|
||||
|
||||
// Clear the screen
|
||||
|
@ -703,17 +701,17 @@ public class RecastDemo : MouseListener
|
|||
|
||||
dd.fog(camr * 0.1f, camr * 1.25f);
|
||||
renderer.render(sample);
|
||||
Tool tool = toolsUI.getTool();
|
||||
if (tool != null)
|
||||
{
|
||||
tool.handleRender(renderer);
|
||||
}
|
||||
// Tool tool = toolsUI.getTool();
|
||||
// if (tool != null)
|
||||
// {
|
||||
// tool.handleRender(renderer);
|
||||
// }
|
||||
|
||||
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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue