From 3533260884af69cd2f2ca0ae92aad61491738c26 Mon Sep 17 00:00:00 2001 From: dexy Date: Sat, 15 Dec 2018 04:09:02 +1100 Subject: [PATCH] Rendering OccludeModels when in Occlusion mode --- .../GameFiles/FileTypes/YmapFile.cs | 59 +++++++++++++++---- .../GameFiles/MetaTypes/MetaTypes.cs | 15 +++++ Rendering/Renderer.cs | 9 +++ WorldForm.cs | 8 ++- 4 files changed, 78 insertions(+), 13 deletions(-) diff --git a/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs b/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs index 0150d17..7bf9c31 100644 --- a/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs +++ b/CodeWalker.Core/GameFiles/FileTypes/YmapFile.cs @@ -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(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; diff --git a/CodeWalker.Core/GameFiles/MetaTypes/MetaTypes.cs b/CodeWalker.Core/GameFiles/MetaTypes/MetaTypes.cs index 13b5a0a..c0000b1 100644 --- a/CodeWalker.Core/GameFiles/MetaTypes/MetaTypes.cs +++ b/CodeWalker.Core/GameFiles/MetaTypes/MetaTypes.cs @@ -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(Meta meta, MetaName name) where T : struct diff --git a/Rendering/Renderer.cs b/Rendering/Renderer.cs index 3d67492..f37cf18 100644 --- a/Rendering/Renderer.cs +++ b/Rendering/Renderer.cs @@ -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 ymts) { foreach (var scenario in ymts) diff --git a/WorldForm.cs b/WorldForm.cs index e29e193..0ceb125 100644 --- a/WorldForm.cs +++ b/WorldForm.cs @@ -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); + + } } }