BoxPacker icon indicating copy to clipboard operation
BoxPacker copied to clipboard

Visualisation

Open shakethatweight-simon opened this issue 3 years ago • 3 comments

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

shakethatweight-simon avatar May 13 '21 10:05 shakethatweight-simon

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.

dvdoug avatar May 13 '21 20:05 dvdoug

@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];

shakethatweight-simon avatar May 14 '21 10:05 shakethatweight-simon

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?

dvdoug avatar May 16 '21 20:05 dvdoug