/// <summary> /// Determines whether the specified <see cref="MaterialPalette"/> is equal to the current <see cref="UFLT.Records.MaterialPalette"/>. /// </summary> /// <param name='other'> /// The <see cref="MaterialPalette"/> to compare with the current <see cref="UFLT.Records.MaterialPalette"/>. /// </param> /// <returns> /// <c>true</c> if the specified <see cref="MaterialPalette"/> is equal to the current /// <see cref="UFLT.Records.MaterialPalette"/>; otherwise, <c>false</c>. /// </returns> public bool Equals(MaterialPalette other) { // Check color fields if (!Ambient.Equals(other.Ambient)) { return(false); } if (!Diffuse.Equals(other.Diffuse)) { return(false); } if (!Specular.Equals(other.Specular)) { return(false); } if (!Emissive.Equals(other.Emissive)) { return(false); } if (Mathf.Approximately(Shininess, other.Shininess)) { return(false); } if (Mathf.Approximately(Alpha, other.Alpha)) { return(false); } return(true); }
/// <summary> /// Handle a material palete, adds it to our collection. /// </summary> /// <returns></returns> private bool HandleMaterialPalette() { MaterialPalette m = new MaterialPalette(); m.Parse(Header); MaterialPalettes[m.Index] = m; return(true); }
/// <summary> /// Returns the submesh for this face based on material info. /// </summary> /// <param name='f'>The face to find a submesh for.</param> public KeyValuePair <IntermediateMaterial, List <int> > FindOrCreateSubMesh(Face f) { ExternalReference externalRef = null; if (Header.Parent != null) { externalRef = Header.Parent as ExternalReference; } // Fetch palettes MaterialPalette mp = null; if (f.MaterialIndex != -1) { if (externalRef != null) { externalRef.Header.MaterialPalettes.TryGetValue(f.MaterialIndex, out mp); } if (mp == null) { Header.MaterialPalettes.TryGetValue(f.MaterialIndex, out mp); } if (mp == null) { Log.WriteError("Could not find material palette: " + f.MaterialIndex); } } TexturePalette mainTex = null; if (f.TexturePattern != -1) { if (externalRef != null) { externalRef.Header.TexturePalettes.TryGetValue(f.TexturePattern, out mainTex); } if (mainTex == null) { Header.TexturePalettes.TryGetValue(f.TexturePattern, out mainTex); } if (mainTex == null) { Log.WriteError("Could not find texture pattern: " + f.TexturePattern); } } TexturePalette detailTex = null; if (f.DetailTexturePattern != -1) { if (externalRef != null) { externalRef.Header.TexturePalettes.TryGetValue(f.DetailTexturePattern, out detailTex); } if (mainTex == null) { Header.TexturePalettes.TryGetValue(f.DetailTexturePattern, out detailTex); } if (mainTex == null) { Log.WriteError("Could not find detail texture pattern: " + f.DetailTexturePattern); } } // Check locally foreach (KeyValuePair <IntermediateMaterial, List <int> > mesh in SubMeshes) { if (mesh.Key.Equals(mp, mainTex, detailTex, f.Transparency, f.LightMode)) { return(mesh); } } // Create a new submesh IntermediateMaterial im = Header.MaterialBank.FindOrCreateMaterial(f); KeyValuePair <IntermediateMaterial, List <int> > newMesh = new KeyValuePair <IntermediateMaterial, List <int> >(im, new List <int>()); SubMeshes.Add(newMesh); return(newMesh); }