unsafe private void ProcessMaterial(IFlverMaterial mat, FlverMaterial dest, GameType type) { dest.MaterialName = Path.GetFileNameWithoutExtension(mat.MTD); dest.MaterialBuffer = Scene.Renderer.MaterialBufferAllocator.Allocate((uint)sizeof(Scene.Material), sizeof(Scene.Material)); dest.MaterialData = new Scene.Material(); if (!CFG.Current.EnableTexturing) { dest.ShaderName = @"SimpleFlver"; dest.LayoutType = MeshLayoutType.LayoutSky; dest.VertexLayout = MeshLayoutUtils.GetLayoutDescription(dest.LayoutType); dest.VertexSize = MeshLayoutUtils.GetLayoutVertexSize(dest.LayoutType); dest.SpecializationConstants = new SpecializationConstant[0]; return; } bool blend = false; bool blendMask = false; bool hasNormal2 = false; bool hasSpec2 = false; bool hasShininess2 = false; foreach (var matparam in mat.Textures) { string paramNameCheck; if (matparam.Type == null) { paramNameCheck = "G_DIFFUSE"; } else { paramNameCheck = matparam.Type.ToUpper(); } if (paramNameCheck == "G_DIFFUSETEXTURE2" || paramNameCheck == "G_DIFFUSE2" || paramNameCheck.Contains("ALBEDO_2")) { LookupTexture(ref dest.AlbedoTextureResource2, dest, matparam, mat.MTD); blend = true; } else if (paramNameCheck == "G_DIFFUSETEXTURE" || paramNameCheck == "G_DIFFUSE" || paramNameCheck.Contains("ALBEDO")) { LookupTexture(ref dest.AlbedoTextureResource, dest, matparam, mat.MTD); } else if (paramNameCheck == "G_BUMPMAPTEXTURE2" || paramNameCheck == "G_BUMPMAP2" || paramNameCheck.Contains("NORMAL_2")) { LookupTexture(ref dest.NormalTextureResource2, dest, matparam, mat.MTD); blend = true; hasNormal2 = true; } else if (paramNameCheck == "G_BUMPMAPTEXTURE" || paramNameCheck == "G_BUMPMAP" || paramNameCheck.Contains("NORMAL")) { LookupTexture(ref dest.NormalTextureResource, dest, matparam, mat.MTD); } else if (paramNameCheck == "G_SPECULARTEXTURE2" || paramNameCheck == "G_SPECULAR2" || paramNameCheck.Contains("SPECULAR_2")) { LookupTexture(ref dest.SpecularTextureResource2, dest, matparam, mat.MTD); blend = true; hasSpec2 = true; } else if (paramNameCheck == "G_SPECULARTEXTURE" || paramNameCheck == "G_SPECULAR" || paramNameCheck.Contains("SPECULAR")) { LookupTexture(ref dest.SpecularTextureResource, dest, matparam, mat.MTD); } else if (paramNameCheck == "G_SHININESSTEXTURE2" || paramNameCheck == "G_SHININESS2" || paramNameCheck.Contains("SHININESS2")) { LookupTexture(ref dest.ShininessTextureResource2, dest, matparam, mat.MTD); blend = true; hasShininess2 = true; } else if (paramNameCheck == "G_SHININESSTEXTURE" || paramNameCheck == "G_SHININESS" || paramNameCheck.Contains("SHININESS")) { LookupTexture(ref dest.ShininessTextureResource, dest, matparam, mat.MTD); } else if (paramNameCheck.Contains("BLENDMASK")) { LookupTexture(ref dest.BlendmaskTextureResource, dest, matparam, mat.MTD); blendMask = true; } } if (blendMask) { dest.ShaderName = @"FlverShader\FlverShader_blendmask"; dest.LayoutType = MeshLayoutType.LayoutUV2; } else if (blend) { dest.ShaderName = @"FlverShader\FlverShader_blend"; dest.LayoutType = MeshLayoutType.LayoutUV2; } else { dest.ShaderName = @"FlverShader\FlverShader"; dest.LayoutType = MeshLayoutType.LayoutStandard; } List <SpecializationConstant> specConstants = new List <SpecializationConstant>(); specConstants.Add(new SpecializationConstant(0, (uint)type)); if (blend || blendMask) { specConstants.Add(new SpecializationConstant(1, hasNormal2)); specConstants.Add(new SpecializationConstant(2, hasSpec2)); specConstants.Add(new SpecializationConstant(3, hasShininess2)); } dest.SpecializationConstants = specConstants.ToArray(); dest.VertexLayout = MeshLayoutUtils.GetLayoutDescription(dest.LayoutType); dest.VertexSize = MeshLayoutUtils.GetLayoutVertexSize(dest.LayoutType); dest.UpdateMaterial(); }
unsafe private void ProcessGraph(hkaiDirectedGraphExplicitCost graph) { var verts = graph.m_positions; int indexCount = 0; foreach (var g in graph.m_nodes) { // Simple formula for indices count for a triangulation of a poly indexCount += g.m_numEdges; } var MeshIndices = new int[indexCount * 2]; var MeshVertices = new PositionColor[indexCount * 2]; var vertPos = new Vector3[indexCount * 2]; var factory = Scene.Renderer.Factory; int idx = 0; for (int id = 0; id < graph.m_nodes.Count; id++) { var sedge = graph.m_nodes[id].m_startEdgeIndex; var ecount = graph.m_nodes[id].m_numEdges; for (int e = 0; e < ecount; e++) { var vert1 = graph.m_positions[id]; var vert2 = graph.m_positions[(int)graph.m_edges[graph.m_nodes[id].m_startEdgeIndex + e].m_target]; MeshVertices[idx] = new PositionColor(); MeshVertices[idx + 1] = new PositionColor(); MeshVertices[idx].Position = new Vector3(vert1.X, vert1.Y, vert1.Z); MeshVertices[idx + 1].Position = new Vector3(vert2.X, vert2.Y, vert2.Z); vertPos[idx] = new Vector3(vert1.X, vert1.Y, vert1.Z); vertPos[idx + 1] = new Vector3(vert2.X, vert2.Y, vert2.Z); MeshVertices[idx].Color[0] = (byte)(235); MeshVertices[idx].Color[1] = (byte)(200); MeshVertices[idx].Color[2] = (byte)(255); MeshVertices[idx].Color[3] = (byte)(255); MeshVertices[idx + 1].Color[0] = (byte)(235); MeshVertices[idx + 1].Color[1] = (byte)(200); MeshVertices[idx + 1].Color[2] = (byte)(255); MeshVertices[idx + 1].Color[3] = (byte)(255); MeshIndices[idx] = idx; MeshIndices[idx + 1] = idx + 1; idx += 2; } } GraphVertexCount = MeshVertices.Length; GraphIndexCount = MeshIndices.Length; uint buffersize = (uint)GraphIndexCount * 4u; if (GraphVertexCount > 0) { fixed(void *ptr = vertPos) { Bounds = BoundingBox.CreateFromPoints((Vector3 *)ptr, vertPos.Count(), 12, Quaternion.Identity, Vector3.Zero, Vector3.One); } } else { Bounds = new BoundingBox(); } var lsize = MeshLayoutUtils.GetLayoutVertexSize(MeshLayoutType.LayoutPositionColor); uint vbuffersize = (uint)MeshVertices.Length * lsize; CostGraphGeomBuffer = Scene.Renderer.GeometryBufferAllocator.Allocate(vbuffersize, buffersize, (int)lsize, 4, (h) => { h.FillIBuffer(MeshIndices, () => { MeshIndices = null; }); h.FillVBuffer(MeshVertices, () => { MeshVertices = null; }); }); }