public static void Postfix(ref MeshDescriptionCollection __instance) { System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew(); string myResourcesPath = Path.Combine(Utils.GetGamePath(), "Mods", MyModFolder, "Resources"); string myBundlePath = Path.Combine(myResourcesPath, MyUnityBundle); MeshDescription newBlockTexMD = new MeshDescription(__instance.meshes[0]); newBlockTexMD.Name = MyTextureArrayMeshName; newBlockTexMD.ShaderName = __instance.meshes[0].ShaderName; newBlockTexMD.SecondaryShader = __instance.meshes[0].SecondaryShader; newBlockTexMD.bTextureArray = true; newBlockTexMD.MetaData = new TextAsset(File.ReadAllText(Path.Combine(myResourcesPath, MyUVMappingXml))); AssetBundleManager.Instance.LoadAssetBundle(myBundlePath, false); newBlockTexMD.TexDiffuse = AssetBundleManager.Instance.Get <Texture2DArray>(myBundlePath, MyTextureArrayDiffuse); newBlockTexMD.TexNormal = AssetBundleManager.Instance.Get <Texture2DArray>(myBundlePath, MyTextureArrayNormal); newBlockTexMD.TexSpecular = AssetBundleManager.Instance.Get <Texture2DArray>(myBundlePath, MyTextureArraySpecular); Array.Resize(ref __instance.meshes, 11); __instance.meshes[10] = newBlockTexMD; MeshDescription.MESH_LENGTH = 11; sw.Stop(); Log.Out("Load new texture arrays complete. Elapsed time: {0}", sw.Elapsed); }
public static bool Prefix(ref MeshDescription __instance, MeshDescriptionCollection _meshDescriptionCollection, int _index, int _quality, bool _isReload = false) { if (_index > MeshDescription.MESH_OPAQUE2) { Log.Out("_index > MESH_OPAQUE2(9) so let's not load/reload. Skipping LoadTextureArraysForQuality for index {0}", _index); return(false); } return(true); }
public override int GetHashCode() { return(GetType().GetHashCode() ^ (Layout != null ? Layout.GetHashCode() : 1) ^ (MeshDescription != null ? MeshDescription.GetHashCode() : 1) ^ (MetaMesh != null ? MetaMesh.GetHashCode() : 1) ^ (Mesh != null ? Mesh.GetHashCode() : 1) ^ (XMesh != null ? XMesh.GetHashCode() : 1) ^ (MetaXMesh != null ? MetaXMesh.GetHashCode() : 1) ^ XMeshFlags.GetHashCode() ^ Pool.GetHashCode()); }
public BCMMesh([NotNull] MeshDescription meshDesc, [NotNull] List <BCMMeshData> metaData) { Name = meshDesc.Name; AtlasClass = meshDesc.TextureAtlasClass; MeshType = meshDesc.meshType.ToString(); Shadows = meshDesc.bCastShadows; BlendMode = meshDesc.BlendMode.ToString(); Tag = meshDesc.Tag; Collider = meshDesc.ColliderLayerName; SecShader = meshDesc.SecondaryShader; ShaderName = meshDesc.ShaderName; ShaderDistant = meshDesc.ShaderNameDistant; MetaName = meshDesc.MetaData?.name; MetaText = meshDesc.MetaData?.text; MetaData = metaData; }
private MeshDescription TriangulateVoronoi() { Dictionary<Vertex, HashSet<Vertex>> internalEdges = new Dictionary<Vertex, HashSet<Vertex>>(); Dictionary<Vertex, HashSet<Vertex>> voronoiEdges = new Dictionary<Vertex, HashSet<Vertex>>(); Dictionary<Vertex, HashSet<Vertex>> voronoiToInternalEdges = new Dictionary<Vertex, HashSet<Vertex>>(); foreach (HalfEdge halfEdge in m_Delaunay.HalfEdges) { ProcessHalfEdge(halfEdge, voronoiEdges, internalEdges, voronoiToInternalEdges); } List<Vertex> verticesToRemove = new List<Vertex>(); List<InvalidEdge> invalidEdges = FindClippingVoronoiEdges(voronoiEdges, verticesToRemove, m_ClippingEdges); FixInvalidVoronoiEdges(invalidEdges, verticesToRemove, voronoiEdges, internalEdges, voronoiToInternalEdges); List<Vector3> vertices = new List<Vector3>(); List<int>[] triangleLists = new List<int>[2]; triangleLists[0] = new List<int>(); triangleLists[1] = new List<int>(); foreach (Vertex inputNode in internalEdges.Keys) { bool unowned = inputNode.Ownership == Vertex.EOwnership.UNOWNED; int playerIndex = inputNode.Ownership == Vertex.EOwnership.PLAYER1 ? 0 : -1; playerIndex = inputNode.Ownership == Vertex.EOwnership.PLAYER2 ? 1 : playerIndex; HashSet<Vertex> voronoiNodes = internalEdges[inputNode]; foreach (Vertex voronoiNode in voronoiNodes) { HashSet<Vertex> adjacentVoronoiNodes = voronoiEdges[voronoiNode]; HashSet<Vertex> intersection = new HashSet<Vertex>(adjacentVoronoiNodes, adjacentVoronoiNodes.Comparer); intersection.IntersectWith(voronoiNodes); foreach (Vertex adjacent in intersection) { int curCount = vertices.Count; vertices.Add(new Vector3(inputNode.X, 0, inputNode.Y)); vertices.Add(new Vector3(voronoiNode.X, 0, voronoiNode.Y)); vertices.Add(new Vector3(adjacent.X, 0, adjacent.Y)); if (unowned) { triangleLists [0].Add (curCount); triangleLists [0].Add (curCount + 1); triangleLists [0].Add (curCount + 2); triangleLists [1].Add (curCount); triangleLists [1].Add (curCount + 1); triangleLists [1].Add (curCount + 2); } else { triangleLists [playerIndex].Add (curCount); triangleLists [playerIndex].Add (curCount + 1); triangleLists [playerIndex].Add (curCount + 2); } } } } MeshDescription description = new MeshDescription(); description.triangles = new int[2][]; description.triangles[0] = triangleLists[0].ToArray(); description.triangles[1] = triangleLists[1].ToArray(); description.vertices = vertices.ToArray(); return description; /**GL.Begin(GL.LINES); foreach (Vertex key in internalEdges.Keys) { HashSet<Vertex> vertices = internalEdges[key]; foreach (Vertex item in vertices) { GL.Vertex3(key.X, 0, key.Y); GL.Vertex3(item.X, 0, item.Y); } } foreach (Vertex key in voronoiEdges.Keys) { HashSet<Vertex> vertices = voronoiEdges[key]; foreach (Vertex item in vertices) { GL.Vertex3(key.X, 0, key.Y); GL.Vertex3(item.X, 0, item.Y); } } GL.End();**/ }
public BCMMeshShort([NotNull] MeshDescription meshDesc, [NotNull] List <BCMMeshDataShort> metaData) { Name = meshDesc.Name; MetaData = metaData; }
private void ReadBWM(Stream stream) { using (var reader = new BinaryReader(stream)) { if (new string(reader.ReadChars(13)) != MagicFileIdentifier) { throw new ArgumentException("This file is not a Lionhead Model file. (Magic String mismatch)"); } reader.BaseStream.Position += 27; // this should be equal to stream.Length - 44. It tells us how much of the file is left in bytes. var size = reader.ReadInt32(); if (reader.ReadUInt32() != MagicNumberIdentifier) { throw new ArgumentException("This file is not a Lionhead Model file. (Magic Header mismatch)"); } var fileFormatVersion = reader.ReadUInt32(); if (fileFormatVersion != 5 && fileFormatVersion != 6) { throw new ArgumentException("This file format version is not supported."); } FileFormatVersion = (BWMVersion)fileFormatVersion; NotHeaderSize = reader.ReadUInt32(); // <ModelHeader> reader.ReadBytes(68); // uint32 0, 0, 0 12 // 7 floats 28 MaterialDefinitions = new MaterialDefinition[reader.ReadUInt32()]; // 68 MeshDescriptions = new MeshDescription[reader.ReadUInt32()]; // 72 Bones = new Bone[reader.ReadUInt32()]; // 76 Entities = new Entity[reader.ReadUInt32()]; // 80 var numSomething4 = reader.ReadUInt32(); // 84 var numSomething5 = reader.ReadUInt32(); // 88 reader.ReadBytes(20); // 92 var numVerticies = reader.ReadUInt32(); // 112 var numStrides = reader.ReadUInt32(); // 116 reader.ReadUInt32(); // 120 (*((_DWORD *)v75[66] + 30) = 2;) Indices = new UInt16[reader.ReadUInt32()]; // </ModelHeader> for (int i = 0; i < MaterialDefinitions.Length; i++) { MaterialDefinitions[i] = ReadMaterialDefinition(reader); } for (int i = 0; i < MeshDescriptions.Length; i++) { MeshDescriptions[i] = ReadMeshDescription(reader); } for (int i = 0; i < MeshDescriptions.Length; i++) { for (int j = 0; j < MeshDescriptions[i].MaterialRefs.Length; j++) { MeshDescriptions[i].MaterialRefs[j] = ReadMeshMaterialReference(reader); } } for (int i = 0; i < Bones.Length; i++) { reader.BaseStream.Position += 48; // todo } for (int i = 0; i < Entities.Length; i++) { Entities[i] = ReadEntity(reader); } for (int i = 0; i < numSomething4; i++) { reader.BaseStream.Position += 12; // todo (unknown) CircleFootprint } for (int i = 0; i < numSomething5; i++) { reader.BaseStream.Position += 12; // todo (unknown) } var strides = new byte[numStrides][]; for (int i = 0; i < numStrides; i++) { var stride = reader.ReadBytes(136); strides[i] = stride; } Verticies = new Vertex[numVerticies]; for (int i = 0; i < numStrides; i++) { if (i == 1) { throw new ArgumentException("Stride count of more then 1 not supported yet."); } var stride = Engine.StrideInBytesFromStreamDef(new MemoryStream(strides[i])); var totalSize = numVerticies * stride; //if (stride != 32) // Console.WriteLine("unknown stride uhoh {0}", stride); for (int j = 0; j < numVerticies; j++) { Verticies[j] = new Vertex { Position = new LHPoint(reader), Normal = new LHPoint(reader), U = reader.ReadSingle(), V = reader.ReadSingle(), }; if (stride > 32) { reader.BaseStream.Position += (stride - 32); } } } for (int i = 0; i < Indices.Length; i++) { Indices[i] = reader.ReadUInt16(); } if (FileFormatVersion != BWMVersion.BWM6) { return; } ModelCleaves = new LHPoint[reader.ReadUInt32()]; for (int i = 0; i < ModelCleaves.Length; i++) { ModelCleaves[i] = new LHPoint(reader); } } }