Rendering OccludeModels when in Occlusion mode

This commit is contained in:
dexy 2018-12-15 04:09:02 +11:00
parent ca7f270c5c
commit 3533260884
4 changed files with 78 additions and 13 deletions

View File

@ -455,6 +455,9 @@ namespace CodeWalker.GameFiles
for (int i = 0; i < COccludeModels.Length; i++)
{
OccludeModels[i] = new YmapOccludeModel(this, COccludeModels[i]);
OccludeModels[i].Load(Meta);
}
}
}
@ -2212,19 +2215,60 @@ namespace CodeWalker.GameFiles
[TypeConverter(typeof(ExpandableObjectConverter))]
public class YmapOccludeModel
public class YmapOccludeModel : BasePathData
{
public OccludeModel _OccludeModel;
public OccludeModel OccludeModel { get { return _OccludeModel; } set { _OccludeModel = value; } }
public YmapFile Ymap { get; set; }
public byte[] Data { get; set; }
public Vector3[] Vertices { get; set; }
public byte[] Indices { get; set; }
public YmapOccludeModel(YmapFile ymap, OccludeModel model)
{
Ymap = ymap;
_OccludeModel = model;
}
public void Load(Meta meta)
{
var vptr = _OccludeModel.verts;
var dataSize = _OccludeModel.dataSize;
var indicesOffset = _OccludeModel.Unk_853977995;
var vertexCount = indicesOffset / 12;
var indexCount = (int)(dataSize - indicesOffset);// / 4;
Data = MetaTypes.GetByteArray(meta, vptr, dataSize);
Vertices = MetaTypes.ConvertDataArray<Vector3>(Data, 0, vertexCount);
Indices = new byte[indexCount];
Buffer.BlockCopy(Data, indicesOffset, Indices, 0, indexCount);
}
public EditorVertex[] GetTriangleVertices()
{
if ((Vertices == null) || (Indices == null)) return null;
EditorVertex[] res = new EditorVertex[Indices.Length];//changing from indexed to nonindexed triangle list
var colour = new Color4(1.0f, 1.0f, 1.0f, 0.2f); //todo: colours for occlude models? currently transparent white
var colourval = (uint)colour.ToRgba();
for (int i = 0; i < Indices.Length; i++)
{
res[i].Position = Vertices[Indices[i]];
res[i].Colour = colourval;
}
return res;
}
public EditorVertex[] GetPathVertices()
{
return null;
}
public Vector4[] GetNodePositions()
{
return null;
}
}
[TypeConverter(typeof(ExpandableObjectConverter))]
@ -2248,17 +2292,8 @@ namespace CodeWalker.GameFiles
Ymap = ymap;
_Box = box;
Vector3 ymapbbmin = ymap._CMapData.entitiesExtentsMin;
Vector3 ymapbbmax = ymap._CMapData.entitiesExtentsMax;
Vector3 ymapbbrng = ymapbbmax - ymapbbmin;
Vector3 boxcenter = new Vector3(box.iCenterX, box.iCenterY, box.iCenterZ) / 4.0f;// / 32767.0f;
Vector3 boxsize = new Vector3(box.iLength, box.iWidth, box.iHeight) / 4.0f;// / 32767.0f;
Position = boxcenter;// * ymapbbrng;
Size = boxsize;// * ymapbbrng;
Position = new Vector3(box.iCenterX, box.iCenterY, box.iCenterZ) / 4.0f;
Size = new Vector3(box.iLength, box.iWidth, box.iHeight) / 4.0f;
BBMin = Size * -0.5f;
BBMax = Size * 0.5f;

View File

@ -1728,6 +1728,21 @@ namespace CodeWalker.GameFiles
Buffer.BlockCopy(ptrblock.Data, (int)ptroffset, data, 0, count);
return data;
}
public static byte[] GetByteArray(Meta meta, DataBlockPointer ptr, uint count)
{
//var pointer = array.Pointer;
uint ptrindex = ptr.PointerDataIndex;// (pointer & 0xFFF) - 1;
uint ptroffset = ptr.PointerDataOffset;// ((pointer >> 12) & 0xFFFFF);
var ptrblock = (ptrindex < meta.DataBlocks.Count) ? meta.DataBlocks[(int)ptrindex] : null;
if ((ptrblock == null) || (ptrblock.Data == null))// || (ptrblock.StructureNameHash != name))
{ return null; } //no block or wrong block? shouldn't happen!
//var count = array.Count1;
if ((ptroffset + count) > ptrblock.Data.Length)
{ return null; }
byte[] data = new byte[count];
Buffer.BlockCopy(ptrblock.Data, (int)ptroffset, data, 0, (int)count);
return data;
}
public static T[] GetTypedDataArray<T>(Meta meta, MetaName name) where T : struct

View File

@ -1433,6 +1433,15 @@ namespace CodeWalker.Rendering
}
}
public void RenderBasePath(BasePathData basepath)
{
RenderablePathBatch rnd = renderableCache.GetRenderablePathBatch(basepath);
if ((rnd != null) && (rnd.IsLoaded))
{
shaders.Enqueue(rnd);
}
}
public void RenderScenarios(List<YmtFile> ymts)
{
foreach (var scenario in ymts)

View File

@ -2736,7 +2736,13 @@ namespace CodeWalker
}
if ((SelectionMode == MapSelectionMode.Occlusion) && (ymap.OccludeModels != null))
{
//TODO
for (int i = 0; i < ymap.OccludeModels.Length; i++)
{
var om = ymap.OccludeModels[i];
Renderer.RenderBasePath(om);
}
}
}