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

Visualisation #239

Open
shakethatweight-simon opened this issue May 13, 2021 · 3 comments
Open

Visualisation #239

shakethatweight-simon opened this issue May 13, 2021 · 3 comments

Comments

@shakethatweight-simon
Copy link

Is it possible to know which rotation has been used when an item is packed?

Although we've started with a basic cuboid representation of the objects in the box (we've used Three.js before I noticed you already had a visualisation). We want to upgrade this to use simplified GLTF models of the items. At the moment the only thing I can think of is comparing the original dimensions to the final dimensions to determine it.

image

@dvdoug
Copy link
Owner

dvdoug commented May 13, 2021

Hi @shakethatweight-simon

You want to draw the actual items, not just an encapsulating cuboid? (where those things are different).

I think your identified solution is probably the only feasible one, there is nothing in BoxPacker itself that stores that kind of information and I can't see an easy way of adding it. The data structures are arrays, but the keys are already used for deduplication and then assumed not to matter.

Happy to take a look at PR in theory though if you think it could be done without regressing performance. The starting point would be here: https://github.com/dvdoug/BoxPacker/blob/3.x/src/OrientatedItemFactory.php#L226.

@shakethatweight-simon
Copy link
Author

@dvdoug at first glance it seems like rekeying the array to provide orientation information might be the starting point.

        //simple 2D rotation
        $permutations['O'] = [$w, $l, $d];
        $permutations['Y'] = [$l, $w, $d];

        //add 3D rotation if we're allowed
        if (!$item->getKeepFlat()) {
            $permutations['Z'] = [$w, $d, $l];
            $permutations['YX'] = [$l, $d, $w];
            $permutations['YZ'] = [$d, $w, $l];
            $permutations['X'] = [$d, $l, $w];
        }

This assumes:

  • X axis is the Length
  • Y axis is the Width
  • Z axis is the Height ?

Just wanted to check this with you first before taking it further, I can see other sections of code that would need to be updated too.

If I mange to make some changes, do you want me to use 3.x as the starting point for the changes or master?


Notes to self

(none of this has been tested)

https://github.com/dvdoug/BoxPacker/blob/3.x/src/OrientatedItemFactory.php#L92 - uasort

https://github.com/dvdoug/BoxPacker/blob/3.x/src/OrientatedItemFactory.php#L121 - add key to $orientations

https://github.com/dvdoug/BoxPacker/blob/3.x/src/OrientatedItemFactory.php#L177 - add key to $stableOrientations $unstableOrientations

https://github.com/dvdoug/BoxPacker/blob/3.x/src/OrientatedItemFactory.php#L96

$this->appliedRotation = key($orientations);
return $orientations[$this->appliedRotation];

@dvdoug
Copy link
Owner

dvdoug commented May 16, 2021

Yes, 3.x please as it's easier to merge up than backport. X axis is width, Y is length, Z is depth.

Thinking about it a bit now, the dimension comparison calculations you were looking as a fallback for your own application - maybe adding a new getter into PackedItem to basically do that would be easier than generating meaningful keys deep in the core and then propagating them outwards?

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

No branches or pull requests

2 participants