Skip to content

Writing out PolyfaceMesh seems to produce corrupted results. #794

@IainS1986

Description

@IainS1986

I'm trying to write out some data to a PolyfaceMesh object. I'm replacing another Cad library so I'm porting over logic that previously worked in one library, and trying to work out the equivalent properties in ACad, so this 100% could just be my logic is wrong, but I'm not sure if its that or an internal issue.

Here are two example files, one was exported in a different library and shows the PolyfaceMesh how it should look, the other is from ACad.

(Hope these AutoDesk viewer links work, let me know if you need something different - they are only live for 27 days)

Correct: https://autode.sk/47N5WGg
Incorrect: https://autode.sk/3VRJ3Kn

Part of the confusion on my side is the VertexRecord within PolyfaceMesh. It requires 4 indices, when 3 is also valid for a PolyfaceMesh. I've read conflicting documentation (imagine that!) to what the 4th index is meant to be if you only have 3 points (ive tried leaving the index to 0, or the same as the 3rd point or the same as the 1st point, all produce different messes).

Here's some rough psuedo code of how I'm making a PolyfaceMesh

            var polyFaceMesh = new PolyfaceMesh();
            polyFaceMesh.LineWeight = LineweightType.W100;
            polyFaceMesh.Color = Color.Red;
            // polyFaceMesh.BlendCrease = false;
            polyFaceMesh.Layer = layer;
            // polyFaceMesh.Vertices.AddRange(points.Select(x => Generate3D_Point(unit, x)));
            polyFaceMesh.Vertices.AddRange(points.Select(GenerateCad_Vertex3D));
            for (short p = 0; p < points.Length; p += 3)
            {
                polyFaceMesh.Faces.Add(new VertexFaceRecord()
                {
                    Index1 = p,
                    Index2 = (short)(p + 1),
                    Index3 = (short)(p + 2),
                    Index4 = 0,
                });
            }
            cadDocument.ModelSpace.Entities.Add(polyFaceMesh);

I have a list of points, where the list of points are in sequeence of 3 where each group of 3 is a triangle.

This is very similar to a previous library, except that let me add a "MeshFace" with only 3 points, so I'm not sure what it 'did' under the hood.

Some confusion as well...

  • VertexFaceRecord is itself, a Vertex - is that just weird Cad logic?
  • PolyfaceMesh clone logic seems odd -
    clone.Vertices.Add((VertexFaceRecord)v.Clone());
    • Its going through the Faces, then cloning these as VertexRecords into the Vertices
    • Is that right? Because when I add to the Faces (in the above psuedo code), i'm also adding Vertices but not the same ones as the Faces property.

Basically, anyone got an example of making a PolyfaceMesh from a list of points in groups of 3! Is it just my logic or is there a bug?


Release needed

  • Yes, using the Nuget package.
  • No, using the github repo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions