mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2024-11-26 00:43:00 +08:00
Improved rendering for nav poly selection, path shader now batches selection lines and tris
This commit is contained in:
parent
a56e87d64a
commit
4c46a850f4
@ -757,7 +757,7 @@ namespace CodeWalker.Rendering
|
||||
public void RenderSelectionNavPoly(YnvPoly poly)
|
||||
{
|
||||
////draw poly triangles
|
||||
var pcolour = new Color4(0.6f, 0.95f, 0.6f, 1.0f);
|
||||
var pcolour = new Color4(1.0f, 1.0f, 1.0f, 0.2f);
|
||||
var colourval = (uint)pcolour.ToRgba();
|
||||
var ynv = poly.Ynv;
|
||||
var ic = poly._RawData.IndexCount;
|
||||
@ -792,6 +792,71 @@ namespace CodeWalker.Rendering
|
||||
}
|
||||
}
|
||||
|
||||
public void RenderSelectionNavPolyOutline(YnvPoly poly, uint colourval)
|
||||
{
|
||||
//var colourval = (uint)colour.ToRgba();
|
||||
var ynv = poly.Ynv;
|
||||
var ic = poly._RawData.IndexCount;
|
||||
var startid = poly._RawData.IndexID;
|
||||
var endid = startid + ic;
|
||||
var lastid = endid - 1;
|
||||
var vc = ynv.Vertices.Count;
|
||||
var startind = ynv.Indices[startid];
|
||||
|
||||
////draw poly outline
|
||||
VertexTypePC v = new VertexTypePC();
|
||||
v.Colour = colourval;
|
||||
VertexTypePC v0 = new VertexTypePC();
|
||||
for (int id = startid; id < endid; id++)
|
||||
{
|
||||
var ind = ynv.Indices[id];
|
||||
if (ind >= vc)
|
||||
{ continue; }
|
||||
|
||||
v.Position = ynv.Vertices[ind];
|
||||
SelectionLineVerts.Add(v);
|
||||
if (id == startid)
|
||||
{
|
||||
v0 = v;
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectionLineVerts.Add(v);
|
||||
}
|
||||
if (id == lastid)
|
||||
{
|
||||
SelectionLineVerts.Add(v0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////draw poly triangles
|
||||
//VertexTypePC v0 = new VertexTypePC();
|
||||
//VertexTypePC v1 = new VertexTypePC();
|
||||
//VertexTypePC v2 = new VertexTypePC();
|
||||
//v0.Position = ynv.Vertices[startind];
|
||||
//v0.Colour = colourval;
|
||||
//v1.Colour = colourval;
|
||||
//v2.Colour = colourval;
|
||||
//int tricount = ic - 2;
|
||||
//for (int t = 0; t < tricount; t++)
|
||||
//{
|
||||
// int tid = startid + t;
|
||||
// int ind1 = ynv.Indices[tid + 1];
|
||||
// int ind2 = ynv.Indices[tid + 2];
|
||||
// if ((ind1 >= vc) || (ind2 >= vc))
|
||||
// { continue; }
|
||||
// v1.Position = ynv.Vertices[ind1];
|
||||
// v2.Position = ynv.Vertices[ind2];
|
||||
// Renderer.SelectionTriVerts.Add(v0);
|
||||
// Renderer.SelectionTriVerts.Add(v1);
|
||||
// Renderer.SelectionTriVerts.Add(v2);
|
||||
// Renderer.SelectionTriVerts.Add(v0);
|
||||
// Renderer.SelectionTriVerts.Add(v2);
|
||||
// Renderer.SelectionTriVerts.Add(v1);
|
||||
//}
|
||||
}
|
||||
|
||||
public void RenderSelectionGeometry(MapSelectionMode mode)
|
||||
{
|
||||
|
||||
|
@ -178,16 +178,31 @@ namespace CodeWalker.Rendering
|
||||
SetInputLayout(context, VertexType.PC);
|
||||
SetSceneVars(context, camera, null, lights);
|
||||
|
||||
vertices.Clear();
|
||||
foreach (var vert in verts)
|
||||
int drawn = 0;
|
||||
int tricount = verts.Count / 3;
|
||||
int maxcount = vertices.StructCount / 3;
|
||||
while (drawn < tricount)
|
||||
{
|
||||
vertices.Add(vert);
|
||||
}
|
||||
vertices.Update(context);
|
||||
vertices.SetVSResource(context, 0);
|
||||
vertices.Clear();
|
||||
|
||||
int offset = drawn*3;
|
||||
int bcount = Math.Min(tricount - drawn, maxcount);
|
||||
for (int i = 0; i < bcount; i++)
|
||||
{
|
||||
int t = offset + (i * 3);
|
||||
vertices.Add(verts[t + 0]);
|
||||
vertices.Add(verts[t + 1]);
|
||||
vertices.Add(verts[t + 2]);
|
||||
}
|
||||
drawn += bcount;
|
||||
|
||||
vertices.Update(context);
|
||||
vertices.SetVSResource(context, 0);
|
||||
|
||||
context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
|
||||
context.Draw(vertices.CurrentCount, 0);
|
||||
}
|
||||
|
||||
context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
|
||||
context.Draw(vertices.CurrentCount, 0);
|
||||
}
|
||||
|
||||
public void RenderLines(DeviceContext context, List<VertexTypePC> verts, Camera camera, ShaderGlobalLights lights)
|
||||
@ -197,16 +212,29 @@ namespace CodeWalker.Rendering
|
||||
SetInputLayout(context, VertexType.PC);
|
||||
SetSceneVars(context, camera, null, lights);
|
||||
|
||||
vertices.Clear();
|
||||
foreach (var vert in verts)
|
||||
int drawn = 0;
|
||||
int linecount = verts.Count / 2;
|
||||
int maxcount = vertices.StructCount / 2;
|
||||
while (drawn < linecount)
|
||||
{
|
||||
vertices.Add(vert);
|
||||
}
|
||||
vertices.Update(context);
|
||||
vertices.SetVSResource(context, 0);
|
||||
vertices.Clear();
|
||||
|
||||
context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.LineList;
|
||||
context.Draw(vertices.CurrentCount, 0);
|
||||
int offset = drawn * 2;
|
||||
int bcount = Math.Min(linecount - drawn, maxcount);
|
||||
for (int i = 0; i < bcount; i++)
|
||||
{
|
||||
int t = offset + (i * 2);
|
||||
vertices.Add(verts[t + 0]);
|
||||
vertices.Add(verts[t + 1]);
|
||||
}
|
||||
drawn += bcount;
|
||||
|
||||
vertices.Update(context);
|
||||
vertices.SetVSResource(context, 0);
|
||||
|
||||
context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.LineList;
|
||||
context.Draw(vertices.CurrentCount, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
68
WorldForm.cs
68
WorldForm.cs
@ -1435,7 +1435,8 @@ namespace CodeWalker
|
||||
if (selectionItem.NavPoly != null)
|
||||
{
|
||||
Renderer.RenderSelectionNavPoly(selectionItem.NavPoly);
|
||||
//return;//don't render a selection box for nav mesh?
|
||||
Renderer.RenderSelectionNavPolyOutline(selectionItem.NavPoly, cgrn);
|
||||
return;//don't render a selection box for nav poly
|
||||
}
|
||||
if (selectionItem.NavPoint != null)
|
||||
{
|
||||
@ -2717,70 +2718,7 @@ namespace CodeWalker
|
||||
|
||||
if ((CurMouseHit.NavPoly != null) && MouseSelectEnabled)
|
||||
{
|
||||
var colour = Color4.White;
|
||||
var colourval = (uint)colour.ToRgba();
|
||||
var poly = CurMouseHit.NavPoly;
|
||||
var ynv = poly.Ynv;
|
||||
var ic = poly._RawData.IndexCount;
|
||||
var startid = poly._RawData.IndexID;
|
||||
var endid = startid + ic;
|
||||
var lastid = endid - 1;
|
||||
var vc = ynv.Vertices.Count;
|
||||
var startind = ynv.Indices[startid];
|
||||
|
||||
////draw poly outline
|
||||
VertexTypePC v = new VertexTypePC();
|
||||
v.Colour = colourval;
|
||||
VertexTypePC v0 = new VertexTypePC();
|
||||
for (int id = startid; id < endid; id++)
|
||||
{
|
||||
var ind = ynv.Indices[id];
|
||||
if (ind >= vc)
|
||||
{ continue; }
|
||||
|
||||
v.Position = ynv.Vertices[ind];
|
||||
Renderer.SelectionLineVerts.Add(v);
|
||||
if (id == startid)
|
||||
{
|
||||
v0 = v;
|
||||
}
|
||||
else
|
||||
{
|
||||
Renderer.SelectionLineVerts.Add(v);
|
||||
}
|
||||
if (id == lastid)
|
||||
{
|
||||
Renderer.SelectionLineVerts.Add(v0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////draw poly triangles
|
||||
//VertexTypePC v0 = new VertexTypePC();
|
||||
//VertexTypePC v1 = new VertexTypePC();
|
||||
//VertexTypePC v2 = new VertexTypePC();
|
||||
//v0.Position = ynv.Vertices[startind];
|
||||
//v0.Colour = colourval;
|
||||
//v1.Colour = colourval;
|
||||
//v2.Colour = colourval;
|
||||
//int tricount = ic - 2;
|
||||
//for (int t = 0; t < tricount; t++)
|
||||
//{
|
||||
// int tid = startid + t;
|
||||
// int ind1 = ynv.Indices[tid + 1];
|
||||
// int ind2 = ynv.Indices[tid + 2];
|
||||
// if ((ind1 >= vc) || (ind2 >= vc))
|
||||
// { continue; }
|
||||
// v1.Position = ynv.Vertices[ind1];
|
||||
// v2.Position = ynv.Vertices[ind2];
|
||||
// Renderer.SelectionTriVerts.Add(v0);
|
||||
// Renderer.SelectionTriVerts.Add(v1);
|
||||
// Renderer.SelectionTriVerts.Add(v2);
|
||||
// Renderer.SelectionTriVerts.Add(v0);
|
||||
// Renderer.SelectionTriVerts.Add(v2);
|
||||
// Renderer.SelectionTriVerts.Add(v1);
|
||||
//}
|
||||
|
||||
Renderer.RenderSelectionNavPolyOutline(CurMouseHit.NavPoly, 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user