Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restricted #1

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Restricted #1

wants to merge 16 commits into from

Conversation

Megidd
Copy link
Owner

@Megidd Megidd commented Jan 28, 2023

Play around to come up with a restricted pack rather than a 3D one.

What's restricted?

Assume there is a 3D print floor. The Z axis is upward. The only transformations allowed are moving along X and Y and rotating around Z axis. That's what we mean by 2D pack.

@Megidd
Copy link
Owner Author

Megidd commented Jan 28, 2023

3D example

With this file as input for VS Code debugger, the 3D packing result is as follows.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch Package",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${fileDirname}",
            "args": ["4", "3DBenchy.stl", "2", "Pharaoh.stl", "10", "Utah_teapot_solid.stl"],
        }
    ]
}

1st iteration of Simulated Annealing

Screenshot_20230128_121822

2nd iteration of Simulated Annealing

Screenshot_20230128_121841

3rd iteration of Simulated Annealing

Screenshot_20230128_121900

@Megidd
Copy link
Owner Author

Megidd commented Jan 28, 2023

There is a Rotations variable:

https://github.com/fogleman/pack3d/blob/4c6f72b19a7688cfc90e933fd7d4a5c3ed30a5a0/pack3d/model.go#L10

Looks like it determines the available options for orienting 3D models. Maybe we can reduce 3D behavior to 2D behavior by limiting the options of Rotations variable.

Screenshot_20230128_110205

Limiting rotations

After limiting rotations, now the Simulated Annealing results are like these:

Screenshot_20230128_123420

@Megidd
Copy link
Owner Author

Megidd commented Jan 28, 2023

Z axis translation

After limiting the Rotations variable, the Simulated Annealing algorithm is still moving the objects along the Z axis. Such a movement is not allowed for our 2D case.

It's needed to find a way to prevent translation along Z axis.

@Megidd
Copy link
Owner Author

Megidd commented Jan 28, 2023

Prevent move along Z

After preventing the translation along the Z axis, the Simulated Annealing results look like these:

Screenshot_20230128_145840

Screenshot_20230128_150429
Screenshot_20230128_150400
Screenshot_20230128_150331

@Megidd
Copy link
Owner Author

Megidd commented Jan 29, 2023

Test

After introducing a restricted mode, the test is still as before:

Screenshot_20230129_102134

@Megidd
Copy link
Owner Author

Megidd commented Jan 29, 2023

Mesh origin: bottom-center

After setting mesh local origin to bottom-center of bounding box, rather than center of b-box, the results look generally fine. But there are collisions between objects:

Screenshot_20230129_110343

Screenshot_20230129_110915-1

Screenshot_20230129_111645-1

@Megidd
Copy link
Owner Author

Megidd commented Jan 29, 2023

Mesh origin: center

When mesh local origin is at the center of bounding-box, no collision is observed between objects. Apparently, the logic has specific assumptions about mesh local coordinate system origin.

Screenshot_20230129_112959

Screenshot_20230129_114158

@Megidd Megidd changed the title 2D Restricted Jan 29, 2023
@Megidd
Copy link
Owner Author

Megidd commented Jan 29, 2023

Reasonable assumption

It looks reasonable to assume the mesh origin to be located at center of b-box. Makes sense. It's apparently a sensible general requirement. Let's go with it? 🙄

@Megidd
Copy link
Owner Author

Megidd commented Feb 2, 2023

Collision bug 🐞

For 3D print on a floor, it's desired to align the bottom of all the 3D models with each other. So, let's try to see if this collision bug can be fixed:

#1 (comment)

@Megidd
Copy link
Owner Author

Megidd commented Feb 7, 2023

Maybe the collision bug is due to the fact that while building BVH, the mesh.Center() is called again:

https://github.com/fogleman/pack3d/blob/4c6f72b19a7688cfc90e933fd7d4a5c3ed30a5a0/pack3d/bvh.go#L9

Would the bug be fixed if mesh.Center() is commented out?

When local origin is moved to bottom-center of b-box.
@Megidd
Copy link
Owner Author

Megidd commented Feb 7, 2023

Fix collision bug 🔧

Collision bug is fixed.

Before

Screenshot_20230207_125151

After

No collision is observed ✔️

Screenshot_20230207_125528

Screenshot_20230207_130346

1. Single responsibility
2. Remove `init()`
3. Remove global variables
4. Remove extra computations
5. Efficient design
6. ...
@Megidd
Copy link
Owner Author

Megidd commented Feb 8, 2023

Optimize

Many suggested optimizations are applied.

Test

3D mode

Screenshot_20230208_131027

Restricted mode

Screenshot_20230208_131608

@Megidd Megidd mentioned this pull request Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant