forked from bit/DotRecastNetSim
fix modernOpenGLDraw
This commit is contained in:
parent
768d813a1f
commit
6ef631457e
|
@ -122,6 +122,15 @@ namespace DotRecast.Core
|
||||||
|
|
||||||
public void putFloat(float v)
|
public void putFloat(float v)
|
||||||
{
|
{
|
||||||
|
// if (_order == ByteOrder.BIG_ENDIAN)
|
||||||
|
// {
|
||||||
|
// BinaryPrimitives.WriteInt32BigEndian(_bytes[_position]);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// BinaryPrimitives.ReadInt64LittleEndian(span);
|
||||||
|
// }
|
||||||
|
|
||||||
// ?
|
// ?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace DotRecast.Core
|
||||||
filePath = Path.Combine("..", filePath);
|
filePath = Path.Combine("..", filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
return filename;
|
return Path.GetFullPath(filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -18,6 +18,7 @@ freely, subject to the following restrictions:
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
|
using Silk.NET.OpenGL;
|
||||||
|
|
||||||
namespace DotRecast.Recast.Demo.Draw;
|
namespace DotRecast.Recast.Demo.Draw;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Buffers;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using DotRecast.Core;
|
||||||
|
using ImGuiNET;
|
||||||
using Microsoft.DotNet.PlatformAbstractions;
|
using Microsoft.DotNet.PlatformAbstractions;
|
||||||
using Silk.NET.OpenGL;
|
using Silk.NET.OpenGL;
|
||||||
using Silk.NET.Windowing;
|
using Silk.NET.Windowing;
|
||||||
|
using Buffer = Silk.NET.OpenGL.Buffer;
|
||||||
|
|
||||||
namespace DotRecast.Recast.Demo.Draw;
|
namespace DotRecast.Recast.Demo.Draw;
|
||||||
|
|
||||||
|
@ -30,7 +36,7 @@ public class ModernOpenGLDraw : OpenGLDraw
|
||||||
private int uniformFogStart;
|
private int uniformFogStart;
|
||||||
private int uniformFogEnd;
|
private int uniformFogEnd;
|
||||||
|
|
||||||
public void init(GL gl)
|
public unsafe void init(GL gl)
|
||||||
{
|
{
|
||||||
_gl = gl;
|
_gl = gl;
|
||||||
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";
|
||||||
|
@ -116,13 +122,19 @@ public class ModernOpenGLDraw : OpenGLDraw
|
||||||
_gl.EnableVertexAttribArray(attrib_uv);
|
_gl.EnableVertexAttribArray(attrib_uv);
|
||||||
_gl.EnableVertexAttribArray(attrib_col);
|
_gl.EnableVertexAttribArray(attrib_col);
|
||||||
|
|
||||||
// _gl.VertexAttribPointer(attrib_pos, 3, GLEnum.Float, false, 24, 0);
|
// _gl.VertexAttribP3(attrib_pos, GLEnum.Float, false, 24);
|
||||||
// _gl.VertexAttribPointer(attrib_uv, 2, GLEnum.Float, false, 24, 12);
|
// _gl.VertexAttribP2(attrib_pos, GLEnum.Float, false, 24);
|
||||||
// _gl.VertexAttribPointer(attrib_col, 4, GLEnum.UnsignedByte, true, 24, 20);
|
// _gl.VertexAttribP4(attrib_pos, GLEnum.UnsignedByte, true, 24);
|
||||||
|
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.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);
|
||||||
|
@ -149,57 +161,74 @@ public class ModernOpenGLDraw : OpenGLDraw
|
||||||
_gl.PointSize(size);
|
_gl.PointSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void end()
|
public unsafe void end()
|
||||||
{
|
{
|
||||||
// if (vertices.isEmpty()) {
|
if (0 >= vertices.Count)
|
||||||
// return;
|
{
|
||||||
// }
|
return;
|
||||||
// glUseProgram(program);
|
}
|
||||||
// glUniform1i(uniformTexture, 0);
|
|
||||||
// glUniformMatrix4fv(uniformViewMatrix, false, viewMatrix);
|
_gl.UseProgram(program);
|
||||||
// glUniformMatrix4fv(uniformProjectionMatrix, false, projectionMatrix);
|
_gl.Uniform1(uniformTexture, 0);
|
||||||
// glUniform1f(uniformFogStart, fogStart);
|
_gl.UniformMatrix4(uniformViewMatrix, false, _viewMatrix);
|
||||||
// glUniform1f(uniformFogEnd, fogEnd);
|
_gl.UniformMatrix4(uniformProjectionMatrix, false, _projectionMatrix);
|
||||||
// glUniform1f(uniformFog, fogEnabled ? 1.0f : 0.0f);
|
_gl.Uniform1(uniformFogStart, fogStart);
|
||||||
// glBindVertexArray(vao);
|
_gl.Uniform1(uniformFogEnd, fogEnd);
|
||||||
// glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
_gl.Uniform1(uniformFog, fogEnabled ? 1.0f : 0.0f);
|
||||||
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
|
_gl.BindVertexArray(vao);
|
||||||
// // glBufferData(GL_ARRAY_BUFFER, MAX_VERTEX_BUFFER, GL_STREAM_DRAW);
|
_gl.BindBuffer(GLEnum.ArrayBuffer, vbo);
|
||||||
// // glBufferData(GL_ELEMENT_ARRAY_BUFFER, MAX_ELEMENT_BUFFER, GL_STREAM_DRAW);
|
_gl.BindBuffer(GLEnum.ElementArrayBuffer, ebo);
|
||||||
//
|
// glBufferData(GL_ARRAY_BUFFER, MAX_VERTEX_BUFFER, GL_STREAM_DRAW);
|
||||||
// int vboSize = vertices.size() * 24;
|
// glBufferData(GL_ELEMENT_ARRAY_BUFFER, MAX_ELEMENT_BUFFER, GL_STREAM_DRAW);
|
||||||
// int eboSize = currentPrim == DebugDrawPrimitives.QUADS ? vertices.size() * 6 : vertices.size() * 4;
|
|
||||||
//
|
int vboSize = vertices.Count * 24;
|
||||||
// glBufferData(GL_ARRAY_BUFFER, vboSize, GL_STREAM_DRAW);
|
int eboSize = currentPrim == DebugDrawPrimitives.QUADS ? vertices.Count * 6 : vertices.Count * 4;
|
||||||
// glBufferData(GL_ELEMENT_ARRAY_BUFFER, eboSize, GL_STREAM_DRAW);
|
// var ssss = new byte[vboSize];
|
||||||
// // load draw vertices & elements directly into vertex + element buffer
|
// var ssss2 = new byte[eboSize];
|
||||||
// ByteBuffer verts = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY, vboSize, null);
|
|
||||||
// ByteBuffer elems = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY, eboSize, null);
|
_gl.BufferData(GLEnum.ArrayBuffer, (nuint)vboSize, IntPtr.Zero, GLEnum.StreamDraw);
|
||||||
// vertices.forEach(v => v.store(verts));
|
_gl.BufferData(GLEnum.ElementArrayBuffer, (nuint)eboSize, IntPtr.Zero, GLEnum.StreamDraw);
|
||||||
// if (currentPrim == DebugDrawPrimitives.QUADS) {
|
// load draw vertices & elements directly into vertex + element buffer
|
||||||
// for (int i = 0; i < vertices.size(); i += 4) {
|
byte* pVerts = (byte*)_gl.MapBuffer(GLEnum.ArrayBuffer, GLEnum.WriteOnly);
|
||||||
// elems.putInt(i);
|
byte* pElems = (byte*)_gl.MapBuffer(GLEnum.ElementArrayBuffer, GLEnum.WriteOnly);
|
||||||
// elems.putInt(i + 1);
|
|
||||||
// elems.putInt(i + 2);
|
{
|
||||||
// elems.putInt(i);
|
using var verts = new UnmanagedMemoryStream(pVerts, vboSize, vboSize, FileAccess.Write);
|
||||||
// elems.putInt(i + 2);
|
using var elems = new UnmanagedMemoryStream(pElems, eboSize, eboSize, FileAccess.Write);
|
||||||
// elems.putInt(i + 3);
|
|
||||||
// }
|
vertices.forEach(v => v.store(verts));
|
||||||
//
|
if (currentPrim == DebugDrawPrimitives.QUADS)
|
||||||
// } else {
|
{
|
||||||
// for (int i = 0; i < vertices.size(); i++) {
|
for (int i = 0; i < vertices.Count; i += 4)
|
||||||
// elems.putInt(i);
|
{
|
||||||
// }
|
elems.Write(BitConverter.GetBytes(i));
|
||||||
// }
|
elems.Write(BitConverter.GetBytes(i + 1));
|
||||||
//
|
elems.Write(BitConverter.GetBytes(i + 2));
|
||||||
// glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
|
elems.Write(BitConverter.GetBytes(i));
|
||||||
// glUnmapBuffer(GL_ARRAY_BUFFER);
|
elems.Write(BitConverter.GetBytes(i + 2));
|
||||||
// if (texture != null) {
|
elems.Write(BitConverter.GetBytes(i + 3));
|
||||||
// texture.bind();
|
}
|
||||||
// glUniform1f(uniformUseTexture, 1.0f);
|
}
|
||||||
// } else {
|
else
|
||||||
// glUniform1f(uniformUseTexture, 0.0f);
|
{
|
||||||
// }
|
for (int i = 0; i < vertices.Count; i++)
|
||||||
|
{
|
||||||
|
elems.Write(BitConverter.GetBytes(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_gl.UnmapBuffer(GLEnum.ElementArrayBuffer);
|
||||||
|
_gl.UnmapBuffer(GLEnum.ArrayBuffer);
|
||||||
|
}
|
||||||
|
if (_texture != null)
|
||||||
|
{
|
||||||
|
_texture.bind();
|
||||||
|
_gl.Uniform1(uniformUseTexture, 1.0f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_gl.Uniform1(uniformUseTexture, 0.0f);
|
||||||
|
}
|
||||||
//
|
//
|
||||||
// switch (currentPrim) {
|
// switch (currentPrim) {
|
||||||
// case POINTS:
|
// case POINTS:
|
||||||
|
@ -217,14 +246,14 @@ public class ModernOpenGLDraw : OpenGLDraw
|
||||||
// default:
|
// default:
|
||||||
// break;
|
// break;
|
||||||
// }
|
// }
|
||||||
//
|
|
||||||
// glUseProgram(0);
|
_gl.UseProgram(0);
|
||||||
// glBindBuffer(GL_ARRAY_BUFFER, 0);
|
_gl.BindBuffer(GLEnum.ArrayBuffer, 0);
|
||||||
// glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
_gl.BindBuffer(GLEnum.ElementArrayBuffer, 0);
|
||||||
// glBindVertexArray(0);
|
_gl.BindVertexArray(0);
|
||||||
// vertices.clear();
|
vertices.Clear();
|
||||||
// glLineWidth(1.0f);
|
_gl.LineWidth(1.0f);
|
||||||
// glPointSize(1.0f);
|
_gl.PointSize(1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void vertex(float x, float y, float z, int color)
|
public void vertex(float x, float y, float z, int color)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
|
|
||||||
namespace DotRecast.Recast.Demo.Draw;
|
namespace DotRecast.Recast.Demo.Draw;
|
||||||
|
@ -36,13 +38,13 @@ public class OpenGLVertex
|
||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void store(ByteBuffer buffer)
|
public void store(Stream writer)
|
||||||
{
|
{
|
||||||
buffer.putFloat(x);
|
writer.Write(BitConverter.GetBytes(x));
|
||||||
buffer.putFloat(y);
|
writer.Write(BitConverter.GetBytes(y));
|
||||||
buffer.putFloat(z);
|
writer.Write(BitConverter.GetBytes(z));
|
||||||
buffer.putFloat(u);
|
writer.Write(BitConverter.GetBytes(u));
|
||||||
buffer.putFloat(v);
|
writer.Write(BitConverter.GetBytes(v));
|
||||||
buffer.putInt(color);
|
writer.Write(BitConverter.GetBytes(color));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,9 +1,21 @@
|
||||||
namespace DotRecast.Recast.Demo;
|
using System.IO;
|
||||||
|
using DotRecast.Core;
|
||||||
|
|
||||||
|
namespace DotRecast.Recast.Demo;
|
||||||
|
|
||||||
public static class Program
|
public static class Program
|
||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
var path = Loader.ToRPath("dungeon.obj");
|
||||||
|
path = Path.GetDirectoryName(path);
|
||||||
|
if (!string.IsNullOrEmpty(path))
|
||||||
|
{
|
||||||
|
var workingDirectory = Path.Combine(path, "..");
|
||||||
|
workingDirectory = Path.GetFullPath(workingDirectory);
|
||||||
|
Directory.SetCurrentDirectory(workingDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
var demo = new RecastDemo();
|
var demo = new RecastDemo();
|
||||||
demo.start();
|
demo.start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,13 @@ freely, subject to the following restrictions:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Immutable;
|
||||||
using System.Diagnostics;
|
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;
|
||||||
|
@ -40,6 +43,7 @@ using DotRecast.Recast.Demo.Geom;
|
||||||
using DotRecast.Recast.Demo.Settings;
|
using DotRecast.Recast.Demo.Settings;
|
||||||
using DotRecast.Recast.Demo.Tools;
|
using DotRecast.Recast.Demo.Tools;
|
||||||
using DotRecast.Recast.Demo.UI;
|
using DotRecast.Recast.Demo.UI;
|
||||||
|
using Silk.NET.SDL;
|
||||||
using Silk.NET.Windowing.Sdl;
|
using Silk.NET.Windowing.Sdl;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Detour.DetourCommon;
|
||||||
using Color = System.Drawing.Color;
|
using Color = System.Drawing.Color;
|
||||||
|
@ -55,6 +59,7 @@ public class RecastDemo : MouseListener
|
||||||
private IInputContext _input;
|
private IInputContext _input;
|
||||||
private ImGuiController _imgui;
|
private ImGuiController _imgui;
|
||||||
private GL _gl;
|
private GL _gl;
|
||||||
|
private Sdl _sdl;
|
||||||
private int width = 1000;
|
private int width = 1000;
|
||||||
private int height = 900;
|
private int height = 900;
|
||||||
|
|
||||||
|
@ -69,7 +74,7 @@ public class RecastDemo : MouseListener
|
||||||
private readonly SoloNavMeshBuilder soloNavMeshBuilder = new SoloNavMeshBuilder();
|
private readonly SoloNavMeshBuilder soloNavMeshBuilder = new SoloNavMeshBuilder();
|
||||||
private readonly TileNavMeshBuilder tileNavMeshBuilder = new TileNavMeshBuilder();
|
private readonly TileNavMeshBuilder tileNavMeshBuilder = new TileNavMeshBuilder();
|
||||||
|
|
||||||
//private Sample sample;
|
private Sample sample;
|
||||||
|
|
||||||
private bool processHitTest = false;
|
private bool processHitTest = false;
|
||||||
private bool processHitTestShift;
|
private bool processHitTestShift;
|
||||||
|
@ -95,15 +100,15 @@ public class RecastDemo : MouseListener
|
||||||
|
|
||||||
private bool markerPositionSet;
|
private bool markerPositionSet;
|
||||||
private readonly float[] markerPosition = new float[3];
|
private readonly float[] markerPosition = new float[3];
|
||||||
private ToolsView _toolsView;
|
private ToolsView toolsUI;
|
||||||
private RcSettingsView _rcSettingsView;
|
private RcSettingsView settingsUI;
|
||||||
private long prevFrameTime;
|
private long prevFrameTime;
|
||||||
private RecastDebugDraw dd;
|
private RecastDebugDraw dd;
|
||||||
|
|
||||||
public RecastDemo()
|
public RecastDemo()
|
||||||
{
|
{
|
||||||
//dd = new RecastDebugDraw();
|
dd = new RecastDebugDraw();
|
||||||
// renderer = new NavMeshRenderer(dd);
|
renderer = new NavMeshRenderer(dd);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start()
|
public void start()
|
||||||
|
@ -326,8 +331,8 @@ public class RecastDemo : MouseListener
|
||||||
private DemoInputGeomProvider loadInputMesh(byte[] stream)
|
private DemoInputGeomProvider loadInputMesh(byte[] stream)
|
||||||
{
|
{
|
||||||
DemoInputGeomProvider geom = DemoObjImporter.load(stream);
|
DemoInputGeomProvider geom = DemoObjImporter.load(stream);
|
||||||
//sample = new Sample(geom, ImmutableArray<RecastBuilderResult>.Empty, null, settingsUI, dd);
|
sample = new Sample(geom, ImmutableArray<RecastBuilderResult>.Empty, null, settingsUI, dd);
|
||||||
_toolsView.setEnabled(true);
|
toolsUI.setEnabled(true);
|
||||||
return geom;
|
return geom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,7 +356,7 @@ public class RecastDemo : MouseListener
|
||||||
if (mesh != null)
|
if (mesh != null)
|
||||||
{
|
{
|
||||||
//sample = new Sample(null, ImmutableArray<RecastBuilderResult>.Empty, mesh, settingsUI, dd);
|
//sample = new Sample(null, ImmutableArray<RecastBuilderResult>.Empty, mesh, settingsUI, dd);
|
||||||
_toolsView.setEnabled(true);
|
toolsUI.setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,11 +381,11 @@ public class RecastDemo : MouseListener
|
||||||
|
|
||||||
private void OnWindowOnLoad()
|
private void OnWindowOnLoad()
|
||||||
{
|
{
|
||||||
var s = SdlWindowing.GetExistingApi(window);
|
_sdl = SdlWindowing.GetExistingApi(window);
|
||||||
|
|
||||||
_input = window.CreateInput();
|
_input = window.CreateInput();
|
||||||
_gl = window.CreateOpenGL();
|
_gl = window.CreateOpenGL();
|
||||||
//dd.init(_gl, camr);
|
dd.init(_gl, camr);
|
||||||
|
|
||||||
_imgui = new ImGuiController(_gl, window, _input);
|
_imgui = new ImGuiController(_gl, window, _input);
|
||||||
|
|
||||||
|
@ -408,8 +413,8 @@ public class RecastDemo : MouseListener
|
||||||
window.CreateInput();
|
window.CreateInput();
|
||||||
|
|
||||||
|
|
||||||
_rcSettingsView = new RcSettingsView();
|
settingsUI = new RcSettingsView();
|
||||||
_toolsView = new ToolsView(
|
toolsUI = new ToolsView(
|
||||||
new TestNavmeshTool(),
|
new TestNavmeshTool(),
|
||||||
new OffMeshConnectionTool(),
|
new OffMeshConnectionTool(),
|
||||||
new ConvexVolumeTool(),
|
new ConvexVolumeTool(),
|
||||||
|
@ -418,10 +423,10 @@ public class RecastDemo : MouseListener
|
||||||
new DynamicUpdateTool()
|
new DynamicUpdateTool()
|
||||||
);
|
);
|
||||||
|
|
||||||
_viewSys = new RcViewSystem(window, _input, _rcSettingsView, _toolsView);
|
_viewSys = new RcViewSystem(window, _input, settingsUI, toolsUI);
|
||||||
|
|
||||||
DemoInputGeomProvider geom = loadInputMesh(Loader.ToBytes("nav_test.obj"));
|
DemoInputGeomProvider geom = loadInputMesh(Loader.ToBytes("nav_test.obj"));
|
||||||
//sample = new Sample(geom, ImmutableArray<RecastBuilderResult>.Empty, null, settingsUI, dd);
|
sample = new Sample(geom, ImmutableArray<RecastBuilderResult>.Empty, null, settingsUI, dd);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnWindowOnUpdate(double dt)
|
private void OnWindowOnUpdate(double dt)
|
||||||
|
@ -430,16 +435,16 @@ 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();
|
||||||
|
@ -454,30 +459,18 @@ public class RecastDemo : MouseListener
|
||||||
float DELTA_TIME = 1.0f / SIM_RATE;
|
float DELTA_TIME = 1.0f / SIM_RATE;
|
||||||
timeAcc = clamp((float)(timeAcc + dt), -1.0f, 1.0f);
|
timeAcc = clamp((float)(timeAcc + dt), -1.0f, 1.0f);
|
||||||
int simIter = 0;
|
int simIter = 0;
|
||||||
// while (timeAcc > DELTA_TIME)
|
while (timeAcc > DELTA_TIME)
|
||||||
// {
|
{
|
||||||
// timeAcc -= DELTA_TIME;
|
timeAcc -= DELTA_TIME;
|
||||||
// if (simIter < 5 && sample != null)
|
if (simIter < 5 && sample != null)
|
||||||
// {
|
{
|
||||||
// toolsUI.handleUpdate(DELTA_TIME);
|
toolsUI.handleUpdate((float)dt);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// simIter++;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Set the viewport.
|
simIter++;
|
||||||
// glViewport(0, 0, width, height);
|
}
|
||||||
int[] viewport = new int[] { 0, 0, width, height };
|
|
||||||
// glGetIntegerv(GL_VIEWPORT, viewport);
|
|
||||||
|
|
||||||
// Clear the screen
|
if (settingsUI.isMeshInputTrigerred())
|
||||||
// dd.clear();
|
|
||||||
// float[] projectionMatrix = dd.projectionMatrix(50f, (float)width / (float)height, 1.0f, camr);
|
|
||||||
// float[] modelviewMatrix = dd.viewMatrix(cameraPos, cameraEulers);
|
|
||||||
|
|
||||||
//mouseOverMenu = nuklearUI.layout(window, 0, 0, width, height, (int)mousePos[0], (int)mousePos[1]);
|
|
||||||
|
|
||||||
if (_rcSettingsView.isMeshInputTrigerred())
|
|
||||||
{
|
{
|
||||||
// aFilterPatterns.put(stack.UTF8("*.obj"));
|
// aFilterPatterns.put(stack.UTF8("*.obj"));
|
||||||
// aFilterPatterns.flip();
|
// aFilterPatterns.flip();
|
||||||
|
@ -491,7 +484,7 @@ public class RecastDemo : MouseListener
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
else if (_rcSettingsView.isNavMeshInputTrigerred())
|
else if (settingsUI.isNavMeshInputTrigerred())
|
||||||
{
|
{
|
||||||
// try (MemoryStack stack = stackPush()) {
|
// try (MemoryStack stack = stackPush()) {
|
||||||
// PointerBuffer aFilterPatterns = stack.mallocPointer(4);
|
// PointerBuffer aFilterPatterns = stack.mallocPointer(4);
|
||||||
|
@ -515,50 +508,50 @@ 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;
|
Tuple<IList<RecastBuilderResult>, NavMesh> buildResult;
|
||||||
// if (settingsUI.isTiled())
|
if (settingsUI.isTiled())
|
||||||
// {
|
{
|
||||||
// buildResult = tileNavMeshBuilder.build(sample.getInputGeom(), settingsUI.getPartitioning(), m_cellSize,
|
buildResult = tileNavMeshBuilder.build(sample.getInputGeom(), settingsUI.getPartitioning(), m_cellSize,
|
||||||
// m_cellHeight, m_agentHeight, m_agentRadius, m_agentMaxClimb, m_agentMaxSlope, m_regionMinSize,
|
m_cellHeight, m_agentHeight, m_agentRadius, m_agentMaxClimb, m_agentMaxSlope, m_regionMinSize,
|
||||||
// m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError, m_vertsPerPoly, m_detailSampleDist,
|
m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError, m_vertsPerPoly, m_detailSampleDist,
|
||||||
// m_detailSampleMaxError, settingsUI.isFilterLowHangingObstacles(), settingsUI.isFilterLedgeSpans(),
|
m_detailSampleMaxError, settingsUI.isFilterLowHangingObstacles(), settingsUI.isFilterLedgeSpans(),
|
||||||
// settingsUI.isFilterWalkableLowHeightSpans(), m_tileSize);
|
settingsUI.isFilterWalkableLowHeightSpans(), m_tileSize);
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
// {
|
{
|
||||||
// buildResult = soloNavMeshBuilder.build(sample.getInputGeom(), settingsUI.getPartitioning(), m_cellSize,
|
buildResult = soloNavMeshBuilder.build(sample.getInputGeom(), settingsUI.getPartitioning(), m_cellSize,
|
||||||
// m_cellHeight, m_agentHeight, m_agentRadius, m_agentMaxClimb, m_agentMaxSlope, m_regionMinSize,
|
m_cellHeight, m_agentHeight, m_agentRadius, m_agentMaxClimb, m_agentMaxSlope, m_regionMinSize,
|
||||||
// m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError, m_vertsPerPoly, m_detailSampleDist,
|
m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError, m_vertsPerPoly, m_detailSampleDist,
|
||||||
// m_detailSampleMaxError, settingsUI.isFilterLowHangingObstacles(), settingsUI.isFilterLedgeSpans(),
|
m_detailSampleMaxError, settingsUI.isFilterLowHangingObstacles(), settingsUI.isFilterLedgeSpans(),
|
||||||
// settingsUI.isFilterWalkableLowHeightSpans());
|
settingsUI.isFilterWalkableLowHeightSpans());
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// sample.update(sample.getInputGeom(), buildResult.Item1, buildResult.Item2);
|
sample.update(sample.getInputGeom(), buildResult.Item1, buildResult.Item2);
|
||||||
// sample.setChanged(false);
|
sample.setChanged(false);
|
||||||
// settingsUI.setBuildTime((Stopwatch.GetTimestamp() - t) / 1_000_000);
|
settingsUI.setBuildTime((Stopwatch.GetTimestamp() - t) / 1_000_000);
|
||||||
// toolsUI.setSample(sample);
|
toolsUI.setSample(sample);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
building = false;
|
building = false;
|
||||||
|
@ -627,68 +620,60 @@ public class RecastDemo : MouseListener
|
||||||
processHitTest = false;
|
processHitTest = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (sample.isChanged())
|
if (sample.isChanged())
|
||||||
// {
|
{
|
||||||
// float[] bmin = null;
|
float[] bmin = null;
|
||||||
// float[] bmax = null;
|
float[] bmax = null;
|
||||||
// if (sample.getInputGeom() != null)
|
if (sample.getInputGeom() != null)
|
||||||
// {
|
{
|
||||||
// bmin = sample.getInputGeom().getMeshBoundsMin();
|
bmin = sample.getInputGeom().getMeshBoundsMin();
|
||||||
// bmax = sample.getInputGeom().getMeshBoundsMax();
|
bmax = sample.getInputGeom().getMeshBoundsMax();
|
||||||
// }
|
}
|
||||||
// else if (sample.getNavMesh() != null)
|
else if (sample.getNavMesh() != null)
|
||||||
// {
|
{
|
||||||
// float[][] bounds = NavMeshUtils.getNavMeshBounds(sample.getNavMesh());
|
float[][] bounds = NavMeshUtils.getNavMeshBounds(sample.getNavMesh());
|
||||||
// bmin = bounds[0];
|
bmin = bounds[0];
|
||||||
// bmax = bounds[1];
|
bmax = bounds[1];
|
||||||
// }
|
}
|
||||||
// else if (0 < sample.getRecastResults().Count)
|
else if (0 < sample.getRecastResults().Count)
|
||||||
// {
|
{
|
||||||
// foreach (RecastBuilderResult result in sample.getRecastResults())
|
foreach (RecastBuilderResult result in sample.getRecastResults())
|
||||||
// {
|
{
|
||||||
// if (result.getSolidHeightfield() != null)
|
if (result.getSolidHeightfield() != null)
|
||||||
// {
|
{
|
||||||
// if (bmin == null)
|
if (bmin == null)
|
||||||
// {
|
{
|
||||||
// bmin = new float[] { float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity };
|
bmin = new float[] { float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity };
|
||||||
// bmax = new float[] { float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity };
|
bmax = new float[] { float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity };
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
// {
|
{
|
||||||
// bmin[i] = Math.Min(bmin[i], result.getSolidHeightfield().bmin[i]);
|
bmin[i] = Math.Min(bmin[i], result.getSolidHeightfield().bmin[i]);
|
||||||
// bmax[i] = Math.Max(bmax[i], result.getSolidHeightfield().bmax[i]);
|
bmax[i] = Math.Max(bmax[i], result.getSolidHeightfield().bmax[i]);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if (bmin != null && bmax != null)
|
if (bmin != null && bmax != null)
|
||||||
// {
|
{
|
||||||
// camr = (float)(Math.Sqrt(
|
camr = (float)(Math.Sqrt(
|
||||||
// DemoMath.sqr(bmax[0] - bmin[0]) + DemoMath.sqr(bmax[1] - bmin[1]) + DemoMath.sqr(bmax[2] - bmin[2]))
|
DemoMath.sqr(bmax[0] - bmin[0]) + DemoMath.sqr(bmax[1] - bmin[1]) + DemoMath.sqr(bmax[2] - bmin[2]))
|
||||||
// / 2);
|
/ 2);
|
||||||
// cameraPos[0] = (bmax[0] + bmin[0]) / 2 + camr;
|
cameraPos[0] = (bmax[0] + bmin[0]) / 2 + camr;
|
||||||
// cameraPos[1] = (bmax[1] + bmin[1]) / 2 + camr;
|
cameraPos[1] = (bmax[1] + bmin[1]) / 2 + camr;
|
||||||
// cameraPos[2] = (bmax[2] + bmin[2]) / 2 + camr;
|
cameraPos[2] = (bmax[2] + bmin[2]) / 2 + camr;
|
||||||
// camr *= 3;
|
camr *= 3;
|
||||||
// cameraEulers[0] = 45;
|
cameraEulers[0] = 45;
|
||||||
// cameraEulers[1] = -45;
|
cameraEulers[1] = -45;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// sample.setChanged(false);
|
sample.setChanged(false);
|
||||||
// toolsUI.setSample(sample);
|
toolsUI.setSample(sample);
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
|
||||||
// dd.fog(camr * 0.1f, camr * 1.25f);
|
|
||||||
// renderer.render(sample);
|
|
||||||
// Tool tool = toolsUI.getTool();
|
|
||||||
// if (tool != null)
|
|
||||||
// {
|
|
||||||
// tool.handleRender(renderer);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// dd.fog(false);
|
|
||||||
|
|
||||||
var io = ImGui.GetIO();
|
var io = ImGui.GetIO();
|
||||||
|
|
||||||
|
@ -702,8 +687,29 @@ public class RecastDemo : MouseListener
|
||||||
|
|
||||||
private unsafe void OnWindowOnRender(double dt)
|
private unsafe void OnWindowOnRender(double dt)
|
||||||
{
|
{
|
||||||
_gl.ClearColor(Color.CadetBlue);
|
// _gl.ClearColor(Color.CadetBlue);
|
||||||
_gl.Clear(ClearBufferMask.ColorBufferBit);
|
// _gl.Clear(ClearBufferMask.ColorBufferBit);
|
||||||
|
|
||||||
|
// Set the viewport.
|
||||||
|
// glViewport(0, 0, width, height);
|
||||||
|
//_gl.Viewport(0, 0, (uint)width, (uint)height);
|
||||||
|
//int[] viewport = new int[] { 0, 0, width, height };
|
||||||
|
// glGetIntegerv(GL_VIEWPORT, viewport);
|
||||||
|
|
||||||
|
// Clear the screen
|
||||||
|
dd.clear();
|
||||||
|
float[] projectionMatrix = dd.projectionMatrix(50f, (float)width / (float)height, 1.0f, camr);
|
||||||
|
float[] modelviewMatrix = dd.viewMatrix(cameraPos, cameraEulers);
|
||||||
|
|
||||||
|
dd.fog(camr * 0.1f, camr * 1.25f);
|
||||||
|
renderer.render(sample);
|
||||||
|
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]);
|
||||||
|
|
||||||
|
|
|
@ -31,17 +31,17 @@ public class Sample
|
||||||
private DemoInputGeomProvider inputGeom;
|
private DemoInputGeomProvider inputGeom;
|
||||||
private NavMesh navMesh;
|
private NavMesh navMesh;
|
||||||
private NavMeshQuery navMeshQuery;
|
private NavMeshQuery navMeshQuery;
|
||||||
private readonly RcSettingsView _rcSettingsView;
|
private readonly RcSettingsView _settingsView;
|
||||||
private IList<RecastBuilderResult> recastResults;
|
private IList<RecastBuilderResult> recastResults;
|
||||||
private bool changed;
|
private bool changed;
|
||||||
|
|
||||||
public Sample(DemoInputGeomProvider inputGeom, IList<RecastBuilderResult> recastResults, NavMesh navMesh,
|
public Sample(DemoInputGeomProvider inputGeom, IList<RecastBuilderResult> recastResults, NavMesh navMesh,
|
||||||
RcSettingsView rcSettingsView, RecastDebugDraw debugDraw)
|
RcSettingsView settingsView, RecastDebugDraw debugDraw)
|
||||||
{
|
{
|
||||||
this.inputGeom = inputGeom;
|
this.inputGeom = inputGeom;
|
||||||
this.recastResults = recastResults;
|
this.recastResults = recastResults;
|
||||||
this.navMesh = navMesh;
|
this.navMesh = navMesh;
|
||||||
this._rcSettingsView = rcSettingsView;
|
_settingsView = settingsView;
|
||||||
setQuery(navMesh);
|
setQuery(navMesh);
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public class Sample
|
||||||
|
|
||||||
public RcSettingsView getSettingsUI()
|
public RcSettingsView getSettingsUI()
|
||||||
{
|
{
|
||||||
return _rcSettingsView;
|
return _settingsView;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NavMeshQuery getNavMeshQuery()
|
public NavMeshQuery getNavMeshQuery()
|
||||||
|
|
Loading…
Reference in New Issue