72 lines
2.0 KiB
C#
72 lines
2.0 KiB
C#
using Autodesk.Revit.DB;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace GraphicsStudy
|
|
{
|
|
class MaterialData
|
|
{
|
|
public List<Color> InstanceColorList { get; set; }
|
|
|
|
public List<double> TransparentList { get; set; }
|
|
|
|
public MaterialData()
|
|
{
|
|
InstanceColorList = new List<Color>();
|
|
TransparentList = new List<double>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加颜色
|
|
/// </summary>
|
|
/// <param name="c"></param>
|
|
/// <param name="transparent"></param>
|
|
/// <returns>颜色的索引</returns>
|
|
public int AddColor(Color c,double transparent)
|
|
{
|
|
int index = 0;
|
|
int findIndex = InstanceColorList.FindIndex(x => x.Red==c.Red&&x.Green==c.Green&&x.Blue==c.Blue);
|
|
if(findIndex != -1&& TransparentList[findIndex]==transparent)
|
|
{
|
|
index = findIndex;
|
|
}
|
|
else
|
|
{
|
|
InstanceColorList.Add(c);
|
|
TransparentList.Add(transparent);
|
|
index = InstanceColorList.Count - 1;
|
|
}
|
|
|
|
|
|
return index;
|
|
}
|
|
|
|
public string ToJosn()
|
|
{
|
|
string result = null;
|
|
for (int i = 0; i < InstanceColorList.Count; i++)
|
|
{
|
|
if (i == InstanceColorList.Count - 1)
|
|
{
|
|
result += $"\n{{\n\"color\":\"{colorRGBtoHx16(InstanceColorList[i])}\",\n\"transparent\":{TransparentList[i]}}}";
|
|
}
|
|
else
|
|
{
|
|
result += $"\n{{\n\"color\":\"{colorRGBtoHx16(InstanceColorList[i])}\",\n\"transparent\":{TransparentList[i]}}},";
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public string colorRGBtoHx16(Color c)
|
|
{
|
|
|
|
return System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(c.Red,c.Green, c.Blue));
|
|
}
|
|
}
|
|
}
|