public static Elements.Material MaterialDefault = new Elements.Material("Default",
new Elements.Geometry.Color(System.Drawing.Color.FromArgb(128, 128, 0)), 0, 0, null, false, true, true, null, true, null, 0, false);
static void Main(string[] args)
{
Console.Title = "Convert IFC/IfcZip to glTF...";
var continues = true;
do
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Drop file IFC/IfcZip and Enter convert...");
var path2 = Console.ReadLine();
if (path2.Length > 0)
{
var pathaa = path2.Replace("\"", "");
if (File.Exists(pathaa))
{
var stopwatch = new Stopwatch();
stopwatch.Start();
Console.WriteLine("Start converting...");
FileInfo ifc = new FileInfo(pathaa);
var x = 0.0;
var y = 0.0;
var z = 0.0;
var specularFactor = 0.0;
var glossinessFactor = 0.0;
var textData = new List<(Vector3, Vector3, Vector3, string, Color?)>();
var sphere = Mesh.Sphere(0.5, 20);
#region Box
// Tạo một danh sách các điểm để tạo các đỉnh của hộp
var points = new List<Vector3>
{
new Vector3(0, 0, 0), // Điểm 0
new Vector3(1, 0, 0), // Điểm 1
new Vector3(1, 1, 0), // Điểm 2
new Vector3(0, 1, 0), // Điểm 3
new Vector3(0, 0, 1), // Điểm 4
new Vector3(1, 0, 1), // Điểm 5
new Vector3(1, 1, 1), // Điểm 6
new Vector3(0, 1, 1) // Điểm 7
};
// Tạo lưới tam giác
var mesh = new Mesh();
// Thêm các đỉnh vào lưới và lưu lại để sử dụng sau
var vertices = new List<Elements.Geometry.Vertex>();
foreach (var point in points)
{
var vertex = new Elements.Geometry.Vertex(point);
mesh.AddVertex(vertex);
mesh.AddVertex(vertex);
vertices.Add(vertex);
}
// Thêm các tam giác vào lưới
mesh.AddTriangle(vertices[0], vertices[1], vertices[5]); // Mặt trước
mesh.AddTriangle(vertices[0], vertices[5], vertices[4]);
mesh.AddTriangle(vertices[1], vertices[2], vertices[6]); // Mặt phải
mesh.AddTriangle(vertices[1], vertices[6], vertices[5]);
mesh.AddTriangle(vertices[2], vertices[3], vertices[7]); // Mặt sau
mesh.AddTriangle(vertices[2], vertices[7], vertices[6]);
mesh.AddTriangle(vertices[3], vertices[0], vertices[4]); // Mặt trái
mesh.AddTriangle(vertices[3], vertices[4], vertices[7]);
mesh.AddTriangle(vertices[4], vertices[5], vertices[6]); // Mặt trên
mesh.AddTriangle(vertices[4], vertices[6], vertices[7]);
mesh.AddTriangle(vertices[0], vertices[3], vertices[2]); // Mặt dưới
mesh.AddTriangle(vertices[0], vertices[2], vertices[1]);
mesh.ComputeNormals();
#endregion
#region box extrude
// Tạo một hình hộp kích thước 1x1x1
var profile = Polygon.Rectangle(0.5, 0.5);
var extrude = new Extrude(profile, 0.5, Vector3.ZAxis, false);
#endregion
#region lamina
var lu1 = new Lamina(new Polygon(new List<Vector3>() { vertices[0].Position, vertices[1].Position, vertices[5].Position }));
var lu2 = new Lamina(new Polygon(new List<Vector3>() { vertices[0].Position, vertices[5].Position, vertices[4].Position }));
var lu3 = new Lamina(new Polygon(new List<Vector3>() { vertices[1].Position, vertices[2].Position, vertices[6].Position }));
var lu4 = new Lamina(new Polygon(new List<Vector3>() { vertices[1].Position, vertices[6].Position, vertices[5].Position }));
var lu5 = new Lamina(new Polygon(new List<Vector3>() { vertices[2].Position, vertices[3].Position, vertices[7].Position }));
var lu6 = new Lamina(new Polygon(new List<Vector3>() { vertices[2].Position, vertices[7].Position, vertices[6].Position }));
var lu7 = new Lamina(new Polygon(new List<Vector3>() { vertices[3].Position, vertices[0].Position, vertices[4].Position }));
var lu8 = new Lamina(new Polygon(new List<Vector3>() { vertices[3].Position, vertices[4].Position, vertices[7].Position }));
var lu9 = new Lamina(new Polygon(new List<Vector3>() { vertices[4].Position, vertices[5].Position, vertices[6].Position }));
var lu10 = new Lamina(new Polygon(new List<Vector3>() { vertices[4].Position, vertices[6].Position, vertices[7].Position }));
var lu11 = new Lamina(new Polygon(new List<Vector3>() { vertices[0].Position, vertices[3].Position, vertices[2].Position }));
var lu12 = new Lamina(new Polygon(new List<Vector3>() { vertices[0].Position, vertices[2].Position, vertices[1].Position }));
var representation = new Representation(new List<SolidOperation>() { lu1, lu2, lu3, lu4, lu5, lu6, lu7, lu8, lu9, lu10, lu11, lu12 });
#endregion
var model = new Model();
var index1 = 0;
for (var r = 0.0; r <= 1.0; r += 0.2)
{
if (index1 == 0) { }
for (var g = 0.0; g <= 1.0; g += 0.2)
{
if (r == 0)
{
textData.Add((new Vector3(-1.5, y), Vector3.ZAxis, Vector3.XAxis, $"roughness: {1 - glossinessFactor:f2}", Colors.Black));
}
if (g == 0)
{
textData.Add((new Vector3(x, -1), Vector3.ZAxis, Vector3.XAxis, $"specular: {specularFactor:f2}", Colors.Black));
}
for (var b = 0.0; b <= 1.0; b += 0.2)
{
var color = new Color(r, g, b, 1 - b);
if (r == 1.0 && g == 0.0)
{
textData.Add((new Vector3(x + 1.5, y, z), Vector3.YAxis.Negate(), Vector3.XAxis, $"alpha: {color.Alpha:f2}", Colors.Black));
}
index1++;
var material = new Material($"{r}_{g}_{b}", color, specularFactor, glossinessFactor, null, false, false, false, null, true, null, 0, false);
var box = new GeometricElement(new Transform(new Vector3(x, y, z)), material, representation, false);
//model.AddElement(box);
//model.AddElement(new GeometricElement(new Transform(new Vector3(x, y, z)), material, new Representation(new List<SolidOperation>() { extrude} ), false));
//model.AddElement(new MeshElement(sphere, new Transform(new Vector3(x, y, z)), material));
model.AddElement(new MeshElement(mesh, new Transform(new Vector3(x, y, z)), material));
z += 2.0;
}
z = 0;
y += 2.0;
glossinessFactor += 0.2;
}
glossinessFactor = 0.0;
y = 0;
x += 2.0;
specularFactor += 0.2;
}
// Lưu mô hình dưới dạng GLTF
var gltfPath = Path.ChangeExtension(ifc.FullName, ".glb");
model.UpdateRepresentations();
model.UpdateBoundsAndComputedSolids();
model.ToGlTF(gltfPath, true, false);
stopwatch.Stop();
Console.WriteLine("Converting finished.");
Console.WriteLine("Elapsed: " + stopwatch.Elapsed);
}
}
}
while (continues);
}
Describe the bug
When I try create Mesh & Box (have same material) , Material in View is not same.
To Reproduce
Use package [Elements] => Create Mesh & Box (have same material)
Expected behavior
When I try create Mesh & Box (have same material) , Material in View is not same.
I need show material of Mesh same material of Box
Screenshots
var material = new Elements.Geometry.Color(System.Drawing.Color.FromArgb(128, 128, 0)),0, 0, null, false, true, true, null, true, null,0, false);
Desktop (please complete the following information):
Additional context
None
Please reply
My Code