public XmlMeshFormula(MeshVolumeFormula meshVolumeFormula) { m_id = meshVolumeFormula.meshID; m_relativeVolume = meshVolumeFormula.relativeVolume; Polynome2D formula = meshVolumeFormula.formula; m_k = formula.k; m_xTerms = new List <XMLTerm1D>(formula.xTerms.Count); foreach (Term1D term in formula.xTerms) { m_xTerms.Add(new XMLTerm1D(term)); } m_yTerms = new List <XMLTerm1D>(formula.yTerms.Count); foreach (Term1D term in formula.yTerms) { m_yTerms.Add(new XMLTerm1D(term)); } m_xyTerms = new List <XMLTerm2D>(formula.xyTerms.Count); foreach (Term2D term in formula.xyTerms) { m_xyTerms.Add(new XMLTerm2D(term)); } }
public MeshVolumeFormula FormulaCopy() { List <Term1D> xTerms = new List <Term1D>(m_xTerms.Count); foreach (XMLTerm1D term in m_xTerms) { xTerms.Add(term.ToTerm1D()); } List <Term1D> yTerms = new List <Term1D>(m_yTerms.Count); foreach (XMLTerm1D term in m_yTerms) { yTerms.Add(term.ToTerm1D()); } List <Term2D> xyTerms = new List <Term2D>(m_xyTerms.Count); foreach (XMLTerm2D term in m_xyTerms) { xyTerms.Add(term.ToTerm2D()); } MeshVolumeFormula formula = new MeshVolumeFormula(xTerms, yTerms, xyTerms, m_k, m_id, m_relativeVolume); return(formula); }
// Precal #region Precalculated Volume-Rotation-Height Datas protected void LoadMeshFormula() { MeshVolumeFormula xmlMeshFormula = XmlMeshFormula.FormulaForMesh(m_meshID); if (xmlMeshFormula == null) { this.enabled = false; return; } m_heightFormula = xmlMeshFormula.formula; m_scaleFactor = transform.lossyScale.x * transform.lossyScale.y * transform.lossyScale.z; m_fullVolume = xmlMeshFormula.relativeVolume * m_scaleFactor; m_currentVolume = m_fullVolume * m_volumePercentage; }
static public void SaveFormula(MeshVolumeFormula formula, bool forceUpdate = false) { // Reload List <MeshVolumeFormula> existingData = LoadData(); if (!forceUpdate) { for (int i = 0; i < existingData.Count; i++) { MeshVolumeFormula existingFormula = existingData[i]; if (existingFormula.meshID == formula.meshID) { return; } } } else { for (int i = 0; i < existingData.Count; i++) { MeshVolumeFormula existingFormula = existingData[i]; if (existingFormula.meshID == formula.meshID) { existingData.RemoveAt(i); break; } } } List <XmlMeshFormula> xmlFormulas = new List <XmlMeshFormula>(existingData.Count + 1); foreach (MeshVolumeFormula existingFormula in existingData) { xmlFormulas.Add(new XmlMeshFormula(existingFormula)); } // Add xmlFormulas.Add(new XmlMeshFormula(formula)); // Save XmlSerializer xmlSerializer = new XmlSerializer(typeof(List <XmlMeshFormula>)); using (StreamWriter streamWriter = new StreamWriter(s_dataFilePath)) { xmlSerializer.Serialize(streamWriter, xmlFormulas); } }