moethu / SketchUpNET

SketchUp C# API - A C++/CLI API Wrapper for the Trimble(R) SketchUp(R) C API
MIT License
108 stars 34 forks source link

Having trouble creating a surface with a hole in it. #40

Closed RonLight closed 2 years ago

RonLight commented 2 years ago

I am getting weird results when trying to create a surface with a hole in it. In order to test my code, I created a square with a square hole in Sketchup. I opened the file and created code from all the values in the opened file (second part of code.txt). Finally I just tried opening the file and saving it and I get the same results. The shape is merged together.

Any suggestions? Thank you

Input

SketchUpNET.SketchUp skp = new SketchUpNET.SketchUp();
if (skp.LoadModel("Input.skp"))
{
    skp.WriteNewModel("new.skp", SKPVersion.V2017);
}

Output Sketchup.zip

moethu commented 2 years ago

thanks, I will have a look at this later today.

moethu commented 2 years ago

Thanks @RonLight for reporting this. Writing inner loops actually has never been implemented in this library, therefore I started implementing this feature in this branch: https://github.com/moethu/SketchUpNET/tree/feature/innersurfaceloops - the test worked out fine already. please assure that your loops are closed and contain ordered edges without any duplicates on their start points. CW or CCW doesn't matter but for now they need to be ordered like this:

                OuterEdges.Edges.Add(new SketchUpNET.Edge(new Vertex(0, 0, 0), new Vertex(500, 0, 0), "Layer0"));
                OuterEdges.Edges.Add(new SketchUpNET.Edge(new Vertex(500, 0, 0), new Vertex(500, 500, 0), "Layer0"));
                OuterEdges.Edges.Add(new SketchUpNET.Edge(new Vertex(500, 500, 0), new Vertex(0, 500, 0), "Layer0"));
                OuterEdges.Edges.Add(new SketchUpNET.Edge(new Vertex(0, 500, 0), new Vertex(0, 0, 0), "Layer0"));
moethu commented 2 years ago

@RonLight did you find time testing this?

RonLight commented 2 years ago

Thanks for checking back. It did fix it for the example I gave. However, if I have something more complex, it fails. At this point, I am simply opening the file and saving it.

TestCubeInput TestCubeOutput TestCube.zip .

moethu commented 2 years ago

Thanks for testing this. Most users use this lib for either reading or writing but rarely both. Looks like the point order gets messed up either on read or on write. my suspicion is I created the issue by relying on ordered and directed edges in loops. I'm only adding the start point of each edge: https://github.com/moethu/SketchUpNET/blob/master/SketchUpNET/Surface.cpp#L191 I'll change that to make sure the direction doesn't matter.

RonLight commented 2 years ago

I plan on using it to write, but I am using the read to help figure out what I need to do. Have components been implemented? I notice I can read components, but have not been able to write them.

Thanks Ron

On Sun, Jan 30, 2022 at 7:57 AM moethu @.***> wrote:

Thanks for testing this. Most users use this lib for either reading or writing but rarely both. Looks like the point order gets messed up either on read or on write. my suspicion is I created the issue by relying on ordered and directed edges in loops. I'm only adding the start point of each edge:

https://github.com/moethu/SketchUpNET/blob/master/SketchUpNET/Surface.cpp#L191 I'll change that to make sure the direction doesn't matter.

— Reply to this email directly, view it on GitHub https://github.com/moethu/SketchUpNET/issues/40#issuecomment-1025149319, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPBBLXFUJIM7MOLOJ5ZUVDUYU7VNANCNFSM5JIK6LEQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

moethu commented 2 years ago

currently you cannot write them, that's right. but that shouldn't be too hard to add. what would you need? surfaces and edges? about the reading and writing back issue: I gave it a go (https://github.com/moethu/SketchUpNET/commit/48be53985a9f180dff32b10a01c2a674f8caf5f0) and tried your file. it looks like this is becoming a rounding / tolerance issue. changing tolerances I can almost get the correct result. currently the library is converting from inches to metric on the fly, maybe I'll have to remove this in order to make re-writing work correctly.