packer3d 0.5.0__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. packer3d-0.5.0.data/purelib/packer3d/__init__.py +10 -0
  2. packer3d-0.5.0.data/purelib/packer3d/bin/LICENSE +21 -0
  3. packer3d-0.5.0.data/purelib/packer3d/bin/LICENSE-cJSON +20 -0
  4. packer3d-0.5.0.data/purelib/packer3d/bin/packer.exe +0 -0
  5. packer3d-0.5.0.data/purelib/packer_adapter/__init__.py +4 -0
  6. packer3d-0.5.0.data/purelib/packer_adapter/assets/camera.js +23 -0
  7. packer3d-0.5.0.data/purelib/packer_adapter/assets/packing-scene.js +94 -0
  8. packer3d-0.5.0.data/purelib/packer_adapter/assets/pose.js +21 -0
  9. packer3d-0.5.0.data/purelib/packer_adapter/assets/render.html +63 -0
  10. packer3d-0.5.0.data/purelib/packer_adapter/assets/vendor/LICENSE-three.txt +21 -0
  11. packer3d-0.5.0.data/purelib/packer_adapter/assets/vendor/three.core.js +58773 -0
  12. packer3d-0.5.0.data/purelib/packer_adapter/assets/vendor/three.module.js +18251 -0
  13. packer3d-0.5.0.data/purelib/packer_adapter/client.py +98 -0
  14. packer3d-0.5.0.data/purelib/packer_adapter/engine.py +161 -0
  15. packer3d-0.5.0.data/purelib/packer_adapter/geometry3d_oracle.py +165 -0
  16. packer3d-0.5.0.data/purelib/packer_adapter/mcp_server.py +219 -0
  17. packer3d-0.5.0.data/purelib/packer_adapter/models.py +184 -0
  18. packer3d-0.5.0.data/purelib/packer_adapter/ordinary_geometry.py +256 -0
  19. packer3d-0.5.0.data/purelib/packer_adapter/render.py +183 -0
  20. packer3d-0.5.0.data/purelib/packer_adapter/schemas/request-v2.json +210 -0
  21. packer3d-0.5.0.data/purelib/packer_adapter/schemas/result-v2.json +369 -0
  22. packer3d-0.5.0.data/purelib/packer_adapter/validation.py +20 -0
  23. packer3d-0.5.0.data/purelib/packer_adapter/validation_3d.py +326 -0
  24. packer3d-0.5.0.data/purelib/packer_adapter/validation_ordinary.py +351 -0
  25. packer3d-0.5.0.data/purelib/packer_adapter/validation_worker.py +19 -0
  26. packer3d-0.5.0.dist-info/METADATA +65 -0
  27. packer3d-0.5.0.dist-info/RECORD +31 -0
  28. packer3d-0.5.0.dist-info/WHEEL +5 -0
  29. packer3d-0.5.0.dist-info/entry_points.txt +2 -0
  30. packer3d-0.5.0.dist-info/licenses/LICENSE +21 -0
  31. packer3d-0.5.0.dist-info/top_level.txt +2 -0
@@ -0,0 +1,10 @@
1
+ """paCker cuboid packing for Python: the native engine ships inside the wheel.
2
+
3
+ from packer3d import Packer
4
+ result = (Packer().add_box(id='carton', width=180, length=180, height=30)
5
+ .add_item(id='bar', width=220, length=30, height=20, quantity=3).pack())
6
+ """
7
+ from packer_adapter.client import Packer, PackerError, default_binary
8
+
9
+ __version__ = '0.5.0'
10
+ __all__ = ['Packer', 'PackerError', 'default_binary', '__version__']
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 paCker contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
20
+
@@ -0,0 +1,4 @@
1
+ """paCker Python facade, independent result validation and image rendering."""
2
+ from .client import Packer, PackerError
3
+
4
+ __all__ = ["Packer", "PackerError"]
@@ -0,0 +1,23 @@
1
+ // Fit world bounds in the camera's projected horizontal and vertical extents.
2
+ export function fitPackingCamera(THREE, camera, bounds, direction, margin=.9) {
3
+ const center=bounds.getCenter(new THREE.Vector3());
4
+ const size=bounds.getSize(new THREE.Vector3());
5
+ const extent=Math.max(size.x,size.y,size.z,1e-6);
6
+ const eye=direction.lengthSq() ? direction.clone().normalize() : new THREE.Vector3(.8,-1,.78).normalize();
7
+ const right=new THREE.Vector3().crossVectors(camera.up,eye).normalize();
8
+ const up=new THREE.Vector3().crossVectors(eye,right).normalize();
9
+ const tanY=Math.tan(THREE.MathUtils.degToRad(camera.fov/2))*margin;
10
+ const tanX=tanY*camera.aspect;
11
+ let distance=extent*.01;
12
+ for (const x of [bounds.min.x,bounds.max.x]) for (const y of [bounds.min.y,bounds.max.y]) for (const z of [bounds.min.z,bounds.max.z]) {
13
+ const p=new THREE.Vector3(x,y,z).sub(center);
14
+ distance=Math.max(distance,p.dot(eye)+Math.abs(p.dot(right))/tanX,p.dot(eye)+Math.abs(p.dot(up))/tanY);
15
+ }
16
+ camera.position.copy(center).addScaledVector(eye,distance);
17
+ camera.near=Math.max(1e-10,distance/10000);
18
+ camera.far=distance+extent*10;
19
+ camera.lookAt(center);
20
+ camera.updateProjectionMatrix();
21
+ camera.updateMatrixWorld(true);
22
+ return {center,extent,distance};
23
+ }
@@ -0,0 +1,94 @@
1
+ import {itemPose, normalizedQuaternion} from './pose.js';
2
+
3
+ export const COLORS = [0x36a58a, 0xe4ad58, 0x709dcc, 0xa591cf, 0xdc887f, 0x84ad65];
4
+
5
+ // Inspection only: expand centers uniformly, leaving every solid's shape intact.
6
+ // Uniform expansion preserves a separating plane between disjoint convex solids.
7
+ export function inspectionCenter(center, bin, amount) {
8
+ if (!amount) return [...center];
9
+ return center.map((value,axis) => {
10
+ const origin=[bin.width,bin.length,bin.height][axis]/2;
11
+ return origin+(value-origin)*(1+2.5*amount);
12
+ });
13
+ }
14
+
15
+ function numberLabel(THREE, number, size) {
16
+ const canvas=document.createElement('canvas');canvas.width=128;canvas.height=128;
17
+ const context=canvas.getContext('2d');
18
+ context.fillStyle='#ffffff';context.beginPath();context.arc(64,64,53,0,Math.PI*2);context.fill();
19
+ context.strokeStyle='#184c41';context.lineWidth=8;context.stroke();
20
+ context.fillStyle='#173b34';context.font='bold 60px system-ui, sans-serif';
21
+ context.textAlign='center';context.textBaseline='middle';context.fillText(String(number),64,68);
22
+ const texture=new THREE.CanvasTexture(canvas);
23
+ const sprite=new THREE.Sprite(new THREE.SpriteMaterial({map:texture,transparent:true,depthTest:false}));
24
+ sprite.scale.set(size,size,1);sprite.renderOrder=10;sprite.userData.number=number;
25
+ return sprite;
26
+ }
27
+
28
+ export function createItemMesh(THREE, pose, color) {
29
+ const mesh = new THREE.Mesh(
30
+ new THREE.BoxGeometry(pose.width, pose.length, pose.height),
31
+ new THREE.MeshStandardMaterial({color, roughness: .55, metalness: .02})
32
+ );
33
+ mesh.position.fromArray(pose.center);
34
+ mesh.quaternion.fromArray(normalizedQuaternion(pose.orientation));
35
+ const edge = new THREE.LineSegments(
36
+ new THREE.EdgesGeometry(mesh.geometry),
37
+ new THREE.LineBasicMaterial({color: 0x173a34, transparent: true, opacity: .42})
38
+ );
39
+ mesh.add(edge);
40
+ return mesh;
41
+ }
42
+
43
+ export function buildPackingScene(THREE, result) {
44
+ const root = new THREE.Group();
45
+ const boxes = [];
46
+ const items = [];
47
+ const schema = result.schema_version || 1;
48
+ const widest = Math.max(1, ...result.bins.map(b => Math.max(b.width, b.length, b.height)));
49
+ const maxWidth = Math.max(1, ...result.bins.map(b => b.width));
50
+ const maxLength = Math.max(1, ...result.bins.map(b => b.length));
51
+ const columns = Math.max(1,Math.ceil(Math.sqrt(result.bins.length * 1.6)));
52
+ result.bins.forEach((bin, boxIndex) => {
53
+ const group = new THREE.Group();
54
+ // Container origin is its lower, left, near corner. Keep every item pose intact.
55
+ const offset=[(boxIndex%columns)*(maxWidth+widest*.35),Math.floor(boxIndex/columns)*(maxLength+widest*.35)];
56
+ group.position.set(offset[0],offset[1],0);
57
+ const geometry = new THREE.BoxGeometry(bin.width, bin.length, bin.height);
58
+ const shell = new THREE.Mesh(geometry, new THREE.MeshPhysicalMaterial({
59
+ color: 0xb4cad4, transparent: true, opacity: .085, depthWrite: false,
60
+ side: THREE.DoubleSide, roughness: .85
61
+ }));
62
+ shell.position.set(bin.width / 2, bin.length / 2, bin.height / 2);
63
+ group.add(shell);
64
+ const edges = new THREE.LineSegments(new THREE.EdgesGeometry(geometry),
65
+ new THREE.LineBasicMaterial({color: 0x5c7883, transparent: true, opacity: .7}));
66
+ edges.position.copy(shell.position);
67
+ group.add(edges);
68
+ const floor = new THREE.Mesh(new THREE.PlaneGeometry(bin.width, bin.length),
69
+ new THREE.MeshStandardMaterial({color: 0xe0e8ec, side: THREE.DoubleSide, roughness: 1}));
70
+ floor.position.set(bin.width / 2, bin.length / 2, -.001 * widest);
71
+ group.add(floor);
72
+ bin.items.forEach((item, itemIndex) => {
73
+ const pose = itemPose(item, schema);
74
+ const mesh = createItemMesh(THREE, pose, COLORS[items.length % COLORS.length]);
75
+ mesh.userData = {boxIndex, itemIndex, base: mesh.position.clone(), pose};
76
+ group.add(mesh);
77
+ const label=numberLabel(THREE, items.length+1, Math.max(2.5,Math.min(14,widest*.13)));
78
+ label.position.copy(mesh.position);label.position.z+=Math.max(item.height*.15,widest*.025);
79
+ group.add(label);
80
+ items.push({mesh, label, pose, item, boxIndex, itemIndex, color: COLORS[items.length % COLORS.length]});
81
+ });
82
+ root.add(group);
83
+ boxes.push({group, bin, offset});
84
+ });
85
+ return {root, boxes, items};
86
+ }
87
+
88
+ export function disposePackingScene(scene) {
89
+ scene?.root.traverse(object => {
90
+ object.geometry?.dispose();
91
+ if (Array.isArray(object.material)) object.material.forEach(material => material.dispose());
92
+ else {object.material?.map?.dispose();object.material?.dispose();}
93
+ });
94
+ }
@@ -0,0 +1,21 @@
1
+ // Solver coordinates are right-handed, Z up. All mesh positions are centers.
2
+ export function itemPose(item, schemaVersion = 1) {
3
+ if (schemaVersion === 2) {
4
+ return {
5
+ width: item.width, length: item.length, height: item.height,
6
+ center: [...item.center], orientation: [...item.orientation]
7
+ };
8
+ }
9
+ const half = item.angle * Math.PI / 360;
10
+ return {
11
+ width: item.width, length: item.length, height: item.height,
12
+ center: [item.x, item.y, item.z + item.height / 2],
13
+ orientation: [0, 0, Math.sin(half), Math.cos(half)]
14
+ };
15
+ }
16
+
17
+ export function normalizedQuaternion(q) {
18
+ const norm = Math.hypot(...q);
19
+ if (!Number.isFinite(norm) || norm === 0) throw new Error('Invalid product orientation.');
20
+ return q.map(component => component / norm);
21
+ }
@@ -0,0 +1,63 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=1024,height=768,initial-scale=1">
6
+ <title>paCker final packing image</title>
7
+ <script type="importmap">{"imports":{"three":"./vendor/three.module.js"}}</script>
8
+ <style>
9
+ html,body{margin:0;width:1024px;height:768px;overflow:hidden;background:#f3f7f6;color:#173b34;font:16px system-ui,sans-serif}
10
+ #scene{position:absolute;inset:0}
11
+ #caption{position:absolute;left:28px;top:24px;padding:12px 16px;background:#ffffffed;border:1px solid #b9c9c3;border-radius:8px;max-width:900px}
12
+ #caption strong{display:block;font-size:20px}
13
+ #caption span{font-size:13px;color:#49645c}
14
+ </style>
15
+ </head>
16
+ <body>
17
+ <div id="scene"></div><div id="caption"></div>
18
+ <script type="module">
19
+ import * as THREE from 'three';
20
+ import {buildPackingScene,disposePackingScene} from './packing-scene.js';
21
+ import {fitPackingCamera} from './camera.js';
22
+ const scene=new THREE.Scene();scene.background=new THREE.Color(0xf3f7f6);
23
+ scene.add(new THREE.HemisphereLight(0xffffff,0x7b8c98,2.5));
24
+ const light=new THREE.DirectionalLight(0xffffff,3);light.position.set(150,-250,450);scene.add(light);
25
+ const camera=new THREE.PerspectiveCamera(38,1024/768,.01,1e9);camera.up.set(0,0,1);
26
+ const renderer=new THREE.WebGLRenderer({antialias:true,preserveDrawingBuffer:true});
27
+ renderer.setPixelRatio(1);renderer.setSize(1024,768,false);renderer.outputColorSpace=THREE.SRGBColorSpace;
28
+ document.querySelector('#scene').appendChild(renderer.domElement);
29
+ let packing=null;
30
+ window.sceneReady=false;
31
+ window.renderScene=async ({result,boxIndex,view}) => {
32
+ window.sceneReady=false;
33
+ if (!['isometric','top'].includes(view) || !Number.isInteger(boxIndex) || boxIndex<0 || boxIndex>=result.bins.length)
34
+ throw Error('Invalid box or view');
35
+ if (packing){scene.remove(packing.root);disposePackingScene(packing);}
36
+ packing=buildPackingScene(THREE,result);
37
+ scene.add(packing.root);
38
+ packing.boxes.forEach(({group},i)=>group.visible=i===boxIndex);
39
+ const target=packing.boxes[boxIndex].group;
40
+ const bounds=new THREE.Box3().setFromObject(target);
41
+ fitPackingCamera(THREE,camera,bounds,view==='top' ? new THREE.Vector3(0,-.001,1) : new THREE.Vector3(.8,-1,.78),.78);
42
+ const bin=result.bins[boxIndex];
43
+ const caption=document.querySelector('#caption');caption.replaceChildren();
44
+ const title=document.createElement('strong');title.textContent=`Box ${boxIndex+1} · ${bin.type_id}`;
45
+ const detail=document.createElement('span');detail.textContent=`${bin.width} × ${bin.length} × ${bin.height} · ${bin.items.length} product${bin.items.length===1?'':'s'} · ${view==='top'?'Top':'Isometric'} view`;
46
+ caption.append(title,detail);
47
+ renderer.render(scene,camera);
48
+ await new Promise(resolve=>requestAnimationFrame(()=>{renderer.render(scene,camera);resolve();}));
49
+ window.sceneReady=true;
50
+ return {boxIndex,view,camera:camera.position.toArray(),items:packing.items.filter(x=>x.boxIndex===boxIndex).map(x=>({
51
+ id:x.item.id,instance:x.item.instance,center:x.pose.center,meshCenter:x.mesh.position.toArray(),
52
+ orientation:x.pose.orientation,
53
+ width:x.pose.width,length:x.pose.length,height:x.pose.height
54
+ }))};
55
+ };
56
+ window.capturePng=()=>{
57
+ if (!window.sceneReady) throw Error('Scene is not ready');
58
+ return renderer.domElement.toDataURL('image/png');
59
+ };
60
+ window.renderPageReady=true;
61
+ </script>
62
+ </body>
63
+ </html>
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright © 2010-2025 three.js authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.