//public SourceTexture texture; public FaceMesh() { relativePosition = Vector3.zero; relativeRotation = Vector3.zero; meshData = new MeshHelpers.MeshData(); textureFlag = texflags.SURF_NODRAW; }
private void ReadFaces(BSPParser bspParser, VPKParser vpkParser, CancellationToken cancelToken, Action <float, string> onProgressChanged = null) { for (int i = 0; i < Mathf.RoundToInt(bspParser.faces.Length * FaceLoadPercent); i++) { if (cancelToken.IsCancellationRequested) { return; } dface_t face = bspParser.faces[i]; texflags currentTexFlags = GetFaceTextureFlags(face, bspParser); string textureLocation = GetFaceTextureLocation(face, bspParser); if (!IsUndesiredTexture(textureLocation, currentTexFlags)) { FaceMesh currentFace = new FaceMesh(); currentFace.textureFlag = currentTexFlags; currentFace.lightmapKey = bspParser.faces[i].lightofs; currentFace.faceName = textureLocation; currentFace.material = VMTData.GrabVMT(bspParser, vpkParser, textureLocation); currentFace.meshData = MakeFace(bspParser, face); AddFaceMesh(currentFace, combineMeshesWithSameTexture); } totalItemsLoaded++; onProgressChanged?.Invoke(PercentLoaded, currentMessage); } }
private texflags GetFaceTextureFlags(dface_t face, BSPParser bspParser) { texflags currentTexFlag = texflags.SURF_SKIP; if (bspParser.texInfo != null && face.texinfo < bspParser.texInfo.Length) { currentTexFlag = (texflags)bspParser.texInfo[face.texinfo].flags; } return(currentTexFlag); }
private bool IsUndesiredTexture(string textureLocation, texflags tf) { bool undesired = false; foreach (string undesiredTexture in undesiredTextures) { if (textureLocation.Equals(undesiredTexture, StringComparison.OrdinalIgnoreCase)) { undesired = true; break; } } return(undesired || (tf & texflags.SURF_SKY2D) == texflags.SURF_SKY2D || (tf & texflags.SURF_SKY) == texflags.SURF_SKY || (tf & texflags.SURF_NODRAW) == texflags.SURF_NODRAW || (tf & texflags.SURF_SKIP) == texflags.SURF_SKIP); }
private void MakeFaceMeshes() { if (faces != null) { List <FaceMesh> desiredFaceMeshes = new List <FaceMesh>(); foreach (dface_t face in faces) { FaceMesh currentFace = new FaceMesh(); currentFace.face = face; currentFace.mesh = MakeFaceMesh(face); currentFace.s = new Vector3(texInfo[face.texinfo].textureVecs[0][0], texInfo[face.texinfo].textureVecs[0][2], texInfo[face.texinfo].textureVecs[0][1]); currentFace.t = new Vector3(texInfo[face.texinfo].textureVecs[1][0], texInfo[face.texinfo].textureVecs[1][2], texInfo[face.texinfo].textureVecs[1][1]); currentFace.xOffset = texInfo[face.texinfo].textureVecs[0][3]; currentFace.yOffset = texInfo[face.texinfo].textureVecs[1][3]; currentFace.rawTexture = textureStringData.Substring(Math.Abs(texStringTable[Math.Abs(texData[Math.Abs(texInfo[Math.Abs(face.texinfo)].texdata)].nameStringTableID)])); currentFace.rawTexture = currentFace.rawTexture.Substring(0, currentFace.rawTexture.IndexOf(BSPParser.TEXTURE_STRING_DATA_SPLITTER)); currentFace.rawTexture = RemoveMisleadingPath(currentFace.rawTexture); #region Desirabilities texflags textureFlag = texflags.SURF_NODRAW; try { textureFlag = ((texflags)texInfo[face.texinfo].flags); } catch (System.Exception) { } bool undesired = false; foreach (string undesiredTexture in undesiredTextures) { if (currentFace.rawTexture.Equals(undesiredTexture, StringComparison.InvariantCultureIgnoreCase)) { undesired = true; break; } } #endregion if (!undesired && (textureFlag & texflags.SURF_SKY2D) != texflags.SURF_SKY2D && (textureFlag & texflags.SURF_SKY) != texflags.SURF_SKY && (textureFlag & texflags.SURF_NODRAW) != texflags.SURF_NODRAW && (textureFlag & texflags.SURF_SKIP) != texflags.SURF_SKIP) { desiredFaceMeshes.Add(currentFace); } } faceMeshes = desiredFaceMeshes.ToArray(); } }
public List <string> GetDependencies(CancellationToken cancelToken) { List <string> dependencies = new List <string>(); using (VPKParser vpkParser = new VPKParser(vpkLoc)) using (BSPParser bspParser = new BSPParser(Path.Combine(mapDir, mapName + ".bsp"))) { bool validVPK = vpkParser.IsValid(); if (!validVPK) { return(null); } bspParser.ParseData(cancelToken); if (cancelToken.IsCancellationRequested) { return(null); } //Note: If there are materials that point to textures in separate archives or there are textures used by the models whose vpk archive is not already // added by other dependencies, those archives will not be added. That would require us to read the materials and models to get what textures they use. #region Map face textures dependencies if (FaceLoadPercent > 0) { foreach (dface_t face in bspParser.faces) { if (cancelToken.IsCancellationRequested) { return(null); } texflags currentTexFlags = GetFaceTextureFlags(face, bspParser); string rawTextureLocation = GetFaceTextureLocation(face, bspParser); if (!IsUndesiredTexture(rawTextureLocation, currentTexFlags)) { string fixedLocation = VMTData.FixLocation(bspParser, vpkParser, rawTextureLocation); if (!vpkParser.FileExists(fixedLocation)) { fixedLocation = SourceTexture.FixLocation(bspParser, vpkParser, rawTextureLocation); } string dependency = vpkParser.LocateInArchive(fixedLocation); if (!string.IsNullOrEmpty(dependency) && !dependencies.Contains(dependency)) { dependencies.Add(dependency); } } } } #endregion #region Model dependencies if (ModelLoadPercent > 0) { for (int i = 0; i < bspParser.staticProps.staticPropInfo.Length; i++) { if (cancelToken.IsCancellationRequested) { return(null); } var currentPropInfo = bspParser.staticProps.staticPropInfo[i]; ushort propType = currentPropInfo.PropType; string modelFullPath = bspParser.staticProps.staticPropDict.names[propType]; modelFullPath = modelFullPath.Substring(0, modelFullPath.LastIndexOf(".")); string mdlPath = modelFullPath + ".mdl"; string vvdPath = modelFullPath + ".vvd"; string vtxPath = modelFullPath + ".vtx"; if (!vpkParser.FileExists(vtxPath)) { vtxPath = modelFullPath + ".dx90.vtx"; } string dependency = vpkParser.LocateInArchive(mdlPath); if (!string.IsNullOrEmpty(dependency) && !dependencies.Contains(dependency)) { dependencies.Add(dependency); } dependency = vpkParser.LocateInArchive(vvdPath); if (!string.IsNullOrEmpty(dependency) && !dependencies.Contains(dependency)) { dependencies.Add(dependency); } dependency = vpkParser.LocateInArchive(vtxPath); if (!string.IsNullOrEmpty(dependency) && !dependencies.Contains(dependency)) { dependencies.Add(dependency); } } } #endregion } return(dependencies); }