Open HoNgocQuocSang2721 opened 4 weeks ago
Các vật liệu là giống nhau, nhưng hình học giữa các ví dụ của bạn có sự khác biệt tinh tế.
Khi bạn sử dụng Extrude
, bạn nhận được kết quả hợp lý cho các hộp của mình:
Khi bạn sử dụng Lamina
, bạn đang tạo ra một hình dạng với hình học không hợp lệ. Representation
cố gắng thực hiện một phép hợp boolean của tất cả các SolidOperation
mà bạn cung cấp, và Lamina
là rất mỏng, vì vậy chúng không hoạt động tốt trong boolean. Điều này dẫn đến kết quả hiển thị kỳ lạ mà bạn thấy:
Bạn có thể làm cho Representation
ngừng cố gắng thực hiện hợp boolean bằng cách sử dụng cờ SkipCSGUnion
:
new Representation(solidOperations)
{
SkipCSGUnion = true
}
Điều này giúp cải thiện tình trạng trong ví dụ của bạn, nhưng vẫn có sự khác biệt với các hộp trong suốt:
Tôi nghĩ điều này là do Lamina
có hai mặt, vì vậy bạn đang nhận được nhiều mặt bên trong hộp hơn.
Để tạo ra một SolidOperation
tùy chỉnh, như bạn đang cố gắng làm ở đây, tôi khuyên bạn nên sử dụng kiểu ConstructedSolid
:
var solid = new Solid();
solid.AddFace(new Polygon(vertices[4].Position, vertices[5].Position, vertices[6].Position, vertices[7].Position));
solid.AddFace(new Polygon(vertices[0].Position, vertices[1].Position, vertices[5].Position, vertices[4].Position));
solid.AddFace(new Polygon(vertices[1].Position, vertices[2].Position, vertices[6].Position, vertices[5].Position));
solid.AddFace(new Polygon(vertices[2].Position, vertices[3].Position, vertices[7].Position, vertices[6].Position));
solid.AddFace(new Polygon(vertices[3].Position, vertices[0].Position, vertices[4].Position, vertices[7].Position));
solid.AddFace(new Polygon(vertices[0].Position, vertices[3].Position, vertices[2].Position, vertices[1].Position));
var customRepresentation = new Representation(new ConstructedSolid(solid));
Điều này tạo ra kết quả giống hệt với Extrude
:
Cuối cùng, lý do Mesh
của bạn trông như thế này:
Là do các vector pháp tuyến của chúng không đúng. Bạn đã xây dựng một lưới được gọi là “welded” mesh, được dùng để biểu diễn các bề mặt mịn liên tục, trong đó các vector pháp tuyến của điểm là trung bình của các vector pháp tuyến của mặt, như thế này:
Để khắc phục điều này, hãy tạo ra các đỉnh riêng biệt cho từng mặt, như sau:
// Tạo lưới tam giác
var mesh = new Mesh();
var boxTriangles = new List<int>{
0, 1, 5, // Mặt trước
0, 5, 4,
1, 2, 6, // Mặt phải
1, 6, 5,
2, 3, 7, // Mặt sau
2, 7, 6,
3, 0, 4, // Mặt trái
3, 4, 7,
4, 5, 6, // Mặt trên
4, 6, 7,
0, 3, 2, // Mặt dưới
0, 2, 1
};
for (var i = 0; i < boxTriangles.Count; i += 3)
{
var a = mesh.AddVertex(points[boxTriangles[i]]);
var b = mesh.AddVertex(points[boxTriangles[i + 1]]);
var c = mesh.AddVertex(points[boxTriangles[i + 2]]);
mesh.AddTriangle(a, b, c);
}
mesh.ComputeNormals();
Điều này sẽ tạo ra các lưới trông giống hệt với hai ví dụ khác ở trên.
(English version:)
The materials are identical, but the geometry across your various examples is subtly different.
When you use Extrude
s, you get sensible results for your boxes:
When you use Lamina
s, you are constructing a representation with invalid geometry. The Representation
attempts to perform a boolean union of all the SolidOperation
s you provide, and Lamina
s are infinitely thin, so they do not work well in the boolean. This results in the strange appearance you see:
You can cause the representation to stop trying to perform a boolean union by passing the SkipCSGUnion
flag:
new Representation(solidOperations)
{
SkipCSGUnion = true
}
And this helps a bit in your example, but it still looks different for the transparent boxes:
I think this is because Laminas are two-sided, so you're getting a bunch of extra faces on the inside of the box.
To construct a custom SolidOperation
, as you are trying to do here, I would recommend using the ConstructedSolid
type:
var solid = new Solid();
solid.AddFace(new Polygon(vertices[4].Position, vertices[5].Position, vertices[6].Position, vertices[7].Position));
solid.AddFace(new Polygon(vertices[0].Position, vertices[1].Position, vertices[5].Position, vertices[4].Position));
solid.AddFace(new Polygon(vertices[1].Position, vertices[2].Position, vertices[6].Position, vertices[5].Position));
solid.AddFace(new Polygon(vertices[2].Position, vertices[3].Position, vertices[7].Position, vertices[6].Position));
solid.AddFace(new Polygon(vertices[3].Position, vertices[0].Position, vertices[4].Position, vertices[7].Position));
solid.AddFace(new Polygon(vertices[0].Position, vertices[3].Position, vertices[2].Position, vertices[1].Position));
var customRepresentation = new Representation(new ConstructedSolid(solid));
This produces identical results to the Extrude
:
Finally, the reason your Mesh
es look like this:
Is because their normals are incorrect. You have built what is referred to as a "welded" mesh, meant for representing continuous smooth surfaces, where the vertex normals are the average of the face normals like this:
To correct this, add separate vertices for each face, like so:
// Tạo lưới tam giác
var mesh = new Mesh();
var boxTriangles = new List<int>{
0, 1, 5, // Mặt trước
0, 5, 4,
1, 2, 6, // Mặt phải
1, 6, 5,
2, 3, 7, // Mặt sau
2, 7, 6,
3, 0, 4, // Mặt trái
3, 4, 7,
4, 5, 6, // Mặt trên
4, 6, 7,
0, 3, 2, // Mặt dưới
0, 2, 1
};
for (var i = 0; i < boxTriangles.Count; i += 3)
{
var a = mesh.AddVertex(points[boxTriangles[i]]);
var b = mesh.AddVertex(points[boxTriangles[i + 1]]);
var c = mesh.AddVertex(points[boxTriangles[i + 2]]);
mesh.AddTriangle(a, b, c);
}
mesh.ComputeNormals();
This will result in meshes that look identical to the other two examples above.
If i use old method => File small size file .glb, but i use new method => File x3 size file .glb. File .IFC has large size file => File .glb very large size file. Because new method has each triangle include 3 vertices. => File has very large triangle => very large size file .glb. Is there a way to reduce the file size while still ensuring the geometry material?
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