private MeshData GetOrCreateMeshData(ValveBspFile bsp, GeometryPage page, string matPath, bool cacheVertices = true) { MaterialGroup matGroup; var matDictIndex = MaterialDictionary.GetResourceIndex(bsp, matPath); if (!page.MaterialIndices.TryGetValue(matDictIndex, out int matIndex)) { var vmt = ValveMaterialFile.FromProvider(MaterialDictionary.GetResourcePath(bsp, matDictIndex), bsp.PakFile, Program.Resources); matGroup = new MaterialGroup(matIndex = page.Materials.Count, cacheVertices) { Material = matDictIndex }; page.MaterialIndices.Add(matDictIndex, matIndex); page.Materials.Add(matGroup); FindMaterialAttributes(vmt, matGroup.MeshData.Attributes); } else { matGroup = page.Materials[matIndex]; } return(matGroup.MeshData); }
private static KeyframeRope InitKeyframeRope(KeyframeRope ent, ValveBsp.Entities.Entity value, MapParams mapParams) { var min = (SourceUtils.Vector3)value["origin"]; var max = min; ent.NextKey = value["NextKey"]; if (!string.IsNullOrEmpty(ent.NextKey)) { var next = mapParams.Bsp.Entities.FirstOrDefault(x => ent.NextKey.Equals(x["targetname"])); if (next != null) { var nextOrigin = (SourceUtils.Vector3)next["origin"]; min = SourceUtils.Vector3.Min(min, nextOrigin); max = SourceUtils.Vector3.Max(max, nextOrigin); } } var clusters = GetIntersectingClusters(mapParams.Tree, min, max); if (InitPvsEntity(ent, value, clusters) == null) { return(null); } ent.Width = value["Width"]; ent.TextureScale = value["TextureScale"]; ent.SubDivisions = value["Subdiv"]; ent.Slack = value["Slack"]; ent.RopeMaterial = MaterialDictionary.GetResourceIndex(mapParams.Bsp, value["RopeMaterial"]); ent.MoveSpeed = value["MoveSpeed"]; return(ent); }