feat: container packing simulator + Android shell
- web/packing: scan-sweep planner (bottom-up X/Y sweep, all items per cell), multi-direction candidates, gap fill, stack/capacity/rigid-body checks, theoretical fill bound with red warning, occupancy voxel metrics - per-item params via right-click menu (upright, stack count, capacity, box/voxel fit, mass); simplified left panel - 3D: pan/zoom/rotate mouse mapping, touch gestures, draggable XYZ compass - android: offline WebView APK build pipeline (aapt2/javac/d8/apksigner) - docs: packing preview and mobile screenshots
@@ -5,3 +5,14 @@ __pycache__/
|
||||
out/*.npz
|
||||
data/*.parts/
|
||||
.DS_Store
|
||||
|
||||
# Android APK(壳工程)构建产物
|
||||
android/build/
|
||||
android/**/build/
|
||||
android/.gradle/
|
||||
android/local.properties
|
||||
android/keystore/
|
||||
android/icon-preview.png
|
||||
.idea/
|
||||
*.iml
|
||||
dist/
|
||||
|
||||
@@ -233,6 +233,72 @@ surface/material occupancy,而不是完整的“车辆实体障碍物”语义
|
||||
页面数据全部内嵌在 `web/data.js`,不依赖后端或网络;OCP 只在离线推理阶段使用。
|
||||
three.js 和 OrbitControls 已放在 `web/vendor/`,可离线打开。
|
||||
|
||||
## 装箱模拟(新页签)
|
||||
|
||||
顶部页签切到「装箱模拟」(`web/packing.html`),是一套可以玩的装箱推演:
|
||||
|
||||

|
||||
|
||||
- **待选零件**:30 件货物(车 + 29 件异形件),每件可单独设置拟合方式 / 正向 / 堆码个数;
|
||||
- **全部装箱**:一键把待选件依次放进 40 尺箱(40' GP / 40' HC 可切换);
|
||||
- **装满提示**:某件找不到合法位置时弹出「集装箱已满」,该件留在待选并标「装不下」,
|
||||
不会硬塞;
|
||||
- **重新推理**:从箱底逐层沿 X/Y 扫描,每个空位把所有剩余件按体积从大到小试放,
|
||||
第一个满足「堆码 + 承重 + 支撑 + 间隙」的就放下,像冒泡一样一路铺到箱尾;
|
||||
多组扫描方向(X↑/X↓/Y↑/Y↓ 等)并行评估,取填充率最高的一组,并显示各方向对比曲线;
|
||||
- **逐件加入 / 移除**:点待选行的「+ 装箱」单独试放,点清单里的「移除」退回待选;
|
||||
- **右键菜单**:在左侧任意器件上右键,直接改正向锁定、堆码个数、承重上限、拟合方式、自身重量,
|
||||
应用后自动重新扫描铺装;左侧只保留浏览,不再重复放编辑控件;
|
||||
- **3D 查看**:右侧视口略收窄,右上角有 **XYZ 罗盘**——**拖动罗盘即可旋转**(触屏/鼠标通用),
|
||||
轻点回到整体视角;鼠标 **左键平移、中键拖动旋转、滚轮缩放**;触屏 **单指平移、双指缩放**;
|
||||
整体 / 俯视 / 侧视 / 门端 / 翻转 / 居中 / 自转;实体 / 虚影 / X 光三种显示;
|
||||
- **装箱清单**:面板里的清单就是最终装载顺序,可「导出清单」下载 CSV;
|
||||
- **理论极限与红警**:先算 Σ货物占用体积 / 箱内容积 = 理论上限;铺装后若明显低于上限
|
||||
(差距 >1% 标红、1% 内标琥珀、≤0.5% 标绿),并自动补扫 8 组随机顺序 + 缝隙补装去逼近。
|
||||
|
||||
**每件货的三个参数**(在「零件参数」里改,改完自动重推):
|
||||
|
||||
| 参数 | 含义 |
|
||||
| --- | --- |
|
||||
| 拟合方式 | 默认 **长方体**(最小外接盒);显式切成 **小立方体** 才按 100 mm 体素占位,可与长方体混装 |
|
||||
| 正向锁定 | 锁定只允许绕竖轴 0/90/180/270°;不锁定允许球面任意角度(长方体倾斜只会变大,所以只枚举轴向;小立方体件才采样空间角度) |
|
||||
| 堆码个数 | 整数 **1–9**:1 = 不可再压,2 = 上面还能再堆 1 个……同一竖列按「最小堆码个数」为准 |
|
||||
| 承重上限 | 顶部能承受的总载荷(kg,0 = 不可压),落位时逐层传播校验 |
|
||||
| 自身重量 | 参与载荷传播与整箱重心计算,可在右键菜单里改 |
|
||||
|
||||
体素件的中空 / 内凹 / 半开放腔体不占堆码深度位,所以即使堆码个数是 1,孔洞、框架内部、
|
||||
凹腔里仍然可以继续塞货。间隙按 1 个体素(100 mm)预留,叠放要求底面 ≥60% 支撑。
|
||||
|
||||
**重力与稳定性**:大底面积(≥1.5 m²)的件按“稳”字顺序优先垫底;这类件放到高层时要求
|
||||
支撑率 ≥85%(普通件 ≥60%),警告区会提示“还有 N 件大底面积货物位于高位,建议下沉”。
|
||||
|
||||
**刚体力学校验**:每个体素件的质心由体素质量分布算出来;落位时要求质心落在接触区内,
|
||||
偏心率会放大等效载荷(`1 + 1.5·e/half`,上限 2.5),再逐层向下传播校验承重——用体素模型
|
||||
而不是外接盒来传递受力,就是为了少受“包围盒虚胖”的力矩干扰。
|
||||
|
||||
所有计算都在浏览器里完成(`web/packing.js`:重力下落 + 极值点候选 + 打分 + 多轮迭代),
|
||||
不需要后端,也不读取 STEP 文件。车体体素来自 `src/gen_car_voxels.py` 生成的
|
||||
`web/car-voxels.js`(4 cm 栅格降采样到 10 cm)。
|
||||
|
||||
## Android APK(手机离线体验版)
|
||||
|
||||
`android/` 是一个零依赖的 WebView 壳(单 Activity),把 `web/` 直接当作 assets 打包,
|
||||
手机上打开就是同一套页面,**不需要 INTERNET 权限**,也不依赖服务器。
|
||||
|
||||
```powershell
|
||||
# 需要 JDK 17 + Android SDK(platform 35 / build-tools 35)
|
||||
$env:JAVA_HOME = 'E:\toolchain\jdk\jdk-17.0.21.1+2'
|
||||
$env:ANDROID_SDK_ROOT = 'E:\toolchain\android-sdk'
|
||||
.\android\build-apk.ps1 # → dist/occupancy-fitting-1.0.apk
|
||||
```
|
||||
|
||||
安装:`adb install -r dist\occupancy-fitting-1.0.apk`,或把 APK 传到手机点击安装
|
||||
(允许「未知来源」)。包名 `com.occupancyfit.app`,应用名「占用拟合」,
|
||||
minSdk 24 / targetSdk 34,约 3.5 MB。
|
||||
|
||||
`android/` 同时是标准 AGP 工程,可用 Android Studio 打开;构建细节、签名和
|
||||
Windows 打包坑见 [android/README.md](android/README.md)。
|
||||
|
||||
## 文件结构
|
||||
|
||||
```text
|
||||
@@ -250,7 +316,11 @@ occupancy-fitting/
|
||||
│ ├── app.js
|
||||
│ ├── style.css
|
||||
│ ├── data.js # inference.py 生成(含网格和体素)
|
||||
│ ├── packing.html # 装箱模拟页签
|
||||
│ ├── packing.js # 浏览器内的装箱引擎 + 3D 场景
|
||||
│ ├── packing.css
|
||||
│ └── vendor/ # three.js r128 + OrbitControls(MIT)
|
||||
├── android/ # WebView 壳工程,打包成 APK(见 android/README.md)
|
||||
├── out/
|
||||
│ ├── report.json # 完整结果与每种边长的指标
|
||||
│ └── metrics.csv # 可做表格/画图的扁平指标
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
# Android APK 壳工程
|
||||
|
||||
把 `web/`(three.js + `data.js`)装进一个单 Activity 的 WebView,做成可安装的 APK。
|
||||
页面本身完全离线,因此**不需要 INTERNET 权限**。
|
||||
|
||||
## 目录
|
||||
|
||||
```text
|
||||
android/
|
||||
├── app/
|
||||
│ ├── build.gradle # 标准 AGP 工程(Android Studio 可直接打开)
|
||||
│ └── src/main/
|
||||
│ ├── AndroidManifest.xml
|
||||
│ ├── java/com/occupancyfit/app/MainActivity.java
|
||||
│ └── res/ # 主题、字符串、图标(图标由脚本生成)
|
||||
├── build-apk.ps1 # 无 Gradle 的离线构建脚本(推荐)
|
||||
├── tools/make-icons.ps1 # 生成 adaptive icon 与各密度 PNG
|
||||
├── keystore/occupancy.jks # 本机调试签名(被 .gitignore 忽略)
|
||||
└── build/ # 中间产物(被忽略)
|
||||
```
|
||||
|
||||
`app/build.gradle` 里 `assets.srcDirs` 直接指向仓库的 `../web`,不复制文件;
|
||||
改完网页重新打包即可生效。
|
||||
|
||||
## 构建
|
||||
|
||||
需要 JDK 17、Android SDK(`platforms/android-35` + `build-tools/35.0.0`)。
|
||||
默认路径是本机的 `E:\toolchain`,可通过 `JAVA_HOME` / `ANDROID_SDK_ROOT` 覆盖:
|
||||
|
||||
```powershell
|
||||
Set-ExecutionPolicy -Scope Process Bypass -Force
|
||||
$env:JAVA_HOME = 'E:\toolchain\jdk\jdk-17.0.21.1+2'
|
||||
$env:ANDROID_SDK_ROOT = 'E:\toolchain\android-sdk'
|
||||
.\android\build-apk.ps1
|
||||
```
|
||||
|
||||
产物:`dist/occupancy-fitting-1.0.apk`(约 3.5 MB,minSdk 24 / targetSdk 34)。
|
||||
|
||||
也可以走 Gradle(`android/` 是标准 AGP 8.7.3 工程,首次构建需要联网解析依赖):
|
||||
|
||||
```powershell
|
||||
cd android; .\gradlew.bat assembleRelease
|
||||
```
|
||||
|
||||
## 脚本做了哪 6 步
|
||||
|
||||
1. 复制 manifest 并注入 `package`(Gradle 用的源 manifest 保持无 `package`,两边都能用);
|
||||
2. `aapt2 compile` + `aapt2 link`:资源、图标、`assets/web` 一起打包;
|
||||
3. `javac -encoding UTF-8 -source 8 -target 8` 编译 `MainActivity`;
|
||||
4. `d8` 生成 `classes.dex`;
|
||||
5. `jar -cf0M` 重新归档(正斜杠路径 + Store 条目),`zipalign -p 4` 对齐;
|
||||
6. `apksigner` 用 `keystore/occupancy.jks` 签名,并做结构与签名自检。
|
||||
|
||||
## Windows 上踩过的四个坑
|
||||
|
||||
- **aapt2 写反斜杠**:`-A web` 会把 `vendor\three.min.js` 写进 zip,Android 只认
|
||||
`/`,运行时会 404。所以最后用 `jar` 重新归档。
|
||||
- **`resources.arsc` 必须是 Store**:Android 11+ 安装时强校验(targetSdk ≥ 30),
|
||||
但 .NET 的 `ZipArchive` 传 `NoCompression` 仍写 deflate 存储块,只能用 `jar -cf0M`
|
||||
(全部 Store)才能满足。
|
||||
- **`d8` 不接受目录**:这个版本只吃 `.class` 文件列表,所以脚本显式枚举。
|
||||
- **`javac` 默认 GBK**:源码含中文注释时必须加 `-encoding UTF-8`;`-Xlint:-options`
|
||||
这种带冒号的参数经 PowerShell 传给原生程序会被拆坏,改用 argfile 传参。
|
||||
|
||||
## 签名
|
||||
|
||||
`keystore/occupancy.jks`,别名与密码都是 `occupancy`(仅本机演示用,别拿来发布)。
|
||||
该文件被 `.gitignore` 忽略;换机器重新生成会导致签名不同,**覆盖安装前需先卸载旧版**。
|
||||
|
||||
## 安装
|
||||
|
||||
```powershell
|
||||
adb install -r dist\occupancy-fitting-1.0.apk
|
||||
```
|
||||
|
||||
或把 APK 传到手机,点击安装并允许「未知来源」。应用名「占用拟合」,
|
||||
`com.occupancyfit.app`。
|
||||
|
||||
## 图标
|
||||
|
||||
```powershell
|
||||
Set-ExecutionPolicy -Scope Process Bypass -Force
|
||||
.\android\tools\make-icons.ps1 # 输出各密度 PNG + adaptive icon 前景 + icon-preview.png
|
||||
```
|
||||
|
||||
风格:等轴测线框立方体 + 中截面细分(呼应体素网格),一条橙色棱表示“被占据的立方体”。
|
||||
@@ -0,0 +1,47 @@
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
}
|
||||
|
||||
android {
|
||||
namespace 'com.occupancyfit.app'
|
||||
compileSdk 35
|
||||
|
||||
defaultConfig {
|
||||
applicationId 'com.occupancyfit.app'
|
||||
minSdk 24
|
||||
// keep targetSdk at 34: Android 15 forces edge-to-edge for targetSdk 35,
|
||||
// which would draw the WebView under the status bar
|
||||
targetSdk 34
|
||||
versionCode 10
|
||||
versionName '1.9'
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
release {
|
||||
storeFile rootProject.file('keystore/occupancy.jks')
|
||||
storePassword 'occupancy'
|
||||
keyAlias 'occupancy'
|
||||
keyPassword 'occupancy'
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
shrinkResources false
|
||||
signingConfig signingConfigs.release
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
// package the repo's web/ folder directly instead of copying 3 MB of data.js
|
||||
assets.srcDirs = [rootProject.file('../web').absolutePath]
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_17
|
||||
targetCompatibility JavaVersion.VERSION_17
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<!-- 页面完全离线:three.js / data.js 都在 assets 里,因此不需要 INTERNET 权限 -->
|
||||
<application
|
||||
android:allowBackup="false"
|
||||
android:hardwareAccelerated="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|keyboardHidden|uiMode|density"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,129 @@
|
||||
package com.occupancyfit.app;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebResourceRequest;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
/**
|
||||
* 单 Activity 的 WebView 外壳:加载 assets 里的 web/index.html(离线三维体素拟合页面)。
|
||||
*/
|
||||
public class MainActivity extends Activity {
|
||||
|
||||
private static final String APP_BG = "#0A0E17";
|
||||
private static final String START_URL = "file:///android_asset/index.html";
|
||||
|
||||
private WebView webView;
|
||||
|
||||
@SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"})
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
int bg = Color.parseColor(APP_BG);
|
||||
getWindow().setStatusBarColor(bg);
|
||||
getWindow().setNavigationBarColor(bg);
|
||||
getWindow().setBackgroundDrawable(new android.graphics.drawable.ColorDrawable(bg));
|
||||
|
||||
webView = new WebView(this);
|
||||
webView.setBackgroundColor(bg);
|
||||
webView.setLayoutParams(new ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
|
||||
WebSettings settings = webView.getSettings();
|
||||
settings.setJavaScriptEnabled(true);
|
||||
settings.setDomStorageEnabled(true);
|
||||
settings.setAllowFileAccess(true);
|
||||
settings.setAllowContentAccess(false);
|
||||
settings.setSupportZoom(false);
|
||||
settings.setBuiltInZoomControls(false);
|
||||
settings.setDisplayZoomControls(false);
|
||||
settings.setUseWideViewPort(false);
|
||||
settings.setLoadWithOverviewMode(false);
|
||||
settings.setTextZoom(100);
|
||||
settings.setMediaPlaybackRequiresUserGesture(false);
|
||||
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
|
||||
|
||||
webView.setWebViewClient(new WebViewClient() {
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
||||
return openExternally(request.getUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
view.setBackgroundColor(Color.TRANSPARENT);
|
||||
}
|
||||
});
|
||||
|
||||
// 让 WebGL 优先跑在硬件上,并允许 canvas 全屏(页面里没有,但留着不会出问题)
|
||||
webView.setWebChromeClient(new WebChromeClient());
|
||||
|
||||
setContentView(webView);
|
||||
webView.loadUrl(START_URL);
|
||||
}
|
||||
|
||||
/** file:// 留在 WebView 内,其余 scheme 交给系统浏览器。 */
|
||||
private boolean openExternally(Uri uri) {
|
||||
String scheme = uri.getScheme();
|
||||
if (scheme == null || "file".equals(scheme) || "about".equals(scheme)
|
||||
|| "data".equals(scheme) || "blob".equals(scheme) || "javascript".equals(scheme)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, uri));
|
||||
} catch (Exception ignored) {
|
||||
// 没有浏览器可处理时静默忽略,保持在当前页面
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (webView != null) {
|
||||
webView.onResume();
|
||||
webView.resumeTimers();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
if (webView != null) {
|
||||
webView.onPause();
|
||||
webView.pauseTimers();
|
||||
}
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (webView != null && webView.canGoBack()) {
|
||||
webView.goBack();
|
||||
return;
|
||||
}
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (webView != null) {
|
||||
ViewGroup parent = (ViewGroup) webView.getParent();
|
||||
if (parent != null) {
|
||||
parent.removeView(webView);
|
||||
}
|
||||
webView.destroy();
|
||||
webView = null;
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 5.8 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 8.6 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 26 KiB |
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 8.8 KiB |
|
After Width: | Height: | Size: 13 KiB |
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="ic_launcher_background">#0B1018</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">占用拟合</string>
|
||||
<color name="app_bg">#0A0E17</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="AppTheme" parent="android:Theme.Material.NoActionBar">
|
||||
<item name="android:windowBackground">@color/app_bg</item>
|
||||
<item name="android:colorBackground">@color/app_bg</item>
|
||||
<item name="android:statusBarColor">@color/app_bg</item>
|
||||
<item name="android:navigationBarColor">@color/app_bg</item>
|
||||
<item name="android:windowLightStatusBar">false</item>
|
||||
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -0,0 +1,169 @@
|
||||
# Builds a signed release APK without Gradle:
|
||||
# aapt2 (resources + manifest + assets) -> javac -> d8 -> zipalign -> apksigner
|
||||
# Usage: Set-ExecutionPolicy -Scope Process Bypass; .\android\build-apk.ps1
|
||||
$ErrorActionPreference = 'Continue' # native tools write hints to stderr; exit codes are checked explicitly
|
||||
|
||||
$androidRoot = $PSScriptRoot
|
||||
$repoRoot = (Resolve-Path "$androidRoot\..").Path
|
||||
|
||||
$sdk = if ($env:ANDROID_SDK_ROOT) { $env:ANDROID_SDK_ROOT } else { 'E:\toolchain\android-sdk' }
|
||||
$javaHome = if ($env:JAVA_HOME) { $env:JAVA_HOME } else { 'E:\toolchain\jdk\jdk-17.0.21.1+2' }
|
||||
$buildTools = Join-Path $sdk 'build-tools\35.0.0'
|
||||
$androidJar = Join-Path $sdk 'platforms\android-35\android.jar'
|
||||
|
||||
$env:JAVA_HOME = $javaHome
|
||||
$env:PATH = "$javaHome\bin;$buildTools;$env:PATH"
|
||||
|
||||
foreach ($p in @($buildTools, $androidJar, (Join-Path $javaHome 'bin\javac.exe'))) {
|
||||
if (-not (Test-Path $p)) { throw "missing toolchain path: $p" }
|
||||
}
|
||||
|
||||
$build = Join-Path $androidRoot 'build'
|
||||
$classes = Join-Path $build 'classes'
|
||||
$dexDir = Join-Path $build 'dex'
|
||||
$res = Join-Path $androidRoot 'app\src\main\res'
|
||||
$srcJava = Join-Path $androidRoot 'app\src\main\java'
|
||||
$keystore = Join-Path $androidRoot 'keystore\occupancy.jks'
|
||||
$apkOut = Join-Path $repoRoot 'dist\occupancy-fitting-1.9.apk'
|
||||
|
||||
if (Test-Path $build) { Remove-Item -Recurse -Force $build }
|
||||
New-Item -ItemType Directory -Force -Path $build, $classes, $dexDir, (Join-Path $repoRoot 'dist') | Out-Null
|
||||
|
||||
function Invoke-Tool {
|
||||
param([string]$Exe, [string[]]$Arguments, [string]$What)
|
||||
$out = & $Exe @Arguments 2>&1
|
||||
$code = $LASTEXITCODE
|
||||
if ($out) { $out | ForEach-Object { Write-Host " $_" } }
|
||||
if ($code -ne 0) { throw "$What failed (exit $code)" }
|
||||
}
|
||||
|
||||
# ---- 1. manifest: inject package name (AGP-compatible source stays package-free) ----
|
||||
$manifestSrc = Join-Path $androidRoot 'app\src\main\AndroidManifest.xml'
|
||||
$manifest = Get-Content -Raw $manifestSrc
|
||||
$manifest = $manifest -replace '<manifest xmlns:android="http://schemas.android.com/apk/res/android">',
|
||||
'<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.occupancyfit.app" android:versionCode="10" android:versionName="1.9">'
|
||||
if ($manifest -notmatch 'package="com\.occupancyfit\.app"') { throw 'manifest package injection failed' }
|
||||
$manifestBuilt = Join-Path $build 'AndroidManifest.xml'
|
||||
[System.IO.File]::WriteAllText($manifestBuilt, $manifest, [System.Text.UTF8Encoding]::new($false))
|
||||
|
||||
$aapt2 = Join-Path $buildTools 'aapt2.exe'
|
||||
|
||||
# ---- 2. resources + assets ----
|
||||
Write-Host '[1/6] aapt2 compile resources'
|
||||
$resZip = Join-Path $build 'res.zip'
|
||||
Invoke-Tool $aapt2 @('compile', '--dir', $res, '-o', $resZip) 'aapt2 compile'
|
||||
|
||||
Write-Host '[2/6] aapt2 link (manifest + resources + assets/web)'
|
||||
$unsigned = Join-Path $build 'unsigned.apk'
|
||||
Invoke-Tool $aapt2 @(
|
||||
'link',
|
||||
'-o', $unsigned,
|
||||
'-I', $androidJar,
|
||||
'--manifest', $manifestBuilt,
|
||||
'-A', (Join-Path $repoRoot 'web'),
|
||||
'-R', $resZip,
|
||||
'--auto-add-overlay',
|
||||
'--min-sdk-version', '24',
|
||||
'--target-sdk-version', '34',
|
||||
'--version-code', '10',
|
||||
'--version-name', '1.9'
|
||||
) 'aapt2 link'
|
||||
|
||||
# ---- 3. java -> classes (argfile avoids PowerShell/backslash quoting problems) ----
|
||||
Write-Host '[3/6] javac'
|
||||
$javaFiles = Get-ChildItem -Path $srcJava -Recurse -Filter *.java | ForEach-Object { $_.FullName }
|
||||
$argFile = Join-Path $build 'javac.args'
|
||||
$cp = $androidJar -replace '\\', '/'
|
||||
$dst = $classes -replace '\\', '/'
|
||||
$argLines = @(
|
||||
'-encoding', 'UTF-8',
|
||||
'-source', '8',
|
||||
'-target', '8',
|
||||
'-nowarn',
|
||||
'-classpath', "`"$cp`"",
|
||||
'-d', "`"$dst`""
|
||||
)
|
||||
foreach ($f in $javaFiles) {
|
||||
$fp = $f -replace '\\', '/'
|
||||
$argLines += "`"$fp`""
|
||||
}
|
||||
[System.IO.File]::WriteAllLines($argFile, $argLines, [System.Text.UTF8Encoding]::new($false))
|
||||
Invoke-Tool (Join-Path $javaHome 'bin\javac.exe') @("@$argFile") 'javac'
|
||||
|
||||
# ---- 4. classes -> classes.dex ----
|
||||
Write-Host '[4/6] d8'
|
||||
$d8 = Join-Path $buildTools 'd8.bat'
|
||||
$classFiles = Get-ChildItem -Path $classes -Recurse -Filter *.class | ForEach-Object { $_.FullName }
|
||||
if (-not $classFiles) { throw 'no .class files produced by javac' }
|
||||
Invoke-Tool $d8 (@('--release', '--min-api', '24', '--lib', $androidJar, '--output', $dexDir) + $classFiles) 'd8'
|
||||
$dex = Join-Path $dexDir 'classes.dex'
|
||||
if (-not (Test-Path $dex)) { throw 'classes.dex not produced' }
|
||||
|
||||
# ---- 5. assemble final archive: forward-slash paths + resources.arsc stored ----
|
||||
# aapt2 on Windows stores nested assets as "assets/vendor\file.js" (Android looks them up
|
||||
# with '/' only), and .NET's ZipArchive cannot emit a true Store entry (NoCompression still
|
||||
# writes deflate stored-blocks). Android 11+ refuses to install an APK whose
|
||||
# resources.arsc is not stored, so the archive is rebuilt with `jar -cf0M`.
|
||||
Write-Host '[5/6] repack (forward slashes, Store entries) + zipalign'
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
$staging = Join-Path $build 'apk-contents'
|
||||
[System.IO.Compression.ZipFile]::ExtractToDirectory($unsigned, $staging)
|
||||
if (-not (Test-Path (Join-Path $staging 'AndroidManifest.xml'))) { throw 'staging extraction failed' }
|
||||
Copy-Item -Force $dex (Join-Path $staging 'classes.dex')
|
||||
|
||||
$repacked = Join-Path $build 'repacked.apk'
|
||||
Invoke-Tool (Join-Path $javaHome 'bin\jar.exe') @('-cf0M', $repacked, '-C', $staging, '.') 'jar'
|
||||
|
||||
$aligned = Join-Path $build 'aligned.apk'
|
||||
Invoke-Tool (Join-Path $buildTools 'zipalign.exe') @('-p', '-f', '4', $repacked, $aligned) 'zipalign'
|
||||
|
||||
# ---- 6. sign ----
|
||||
Write-Host '[6/6] apksigner'
|
||||
if (-not (Test-Path $keystore)) {
|
||||
Write-Host ' keystore missing, generating a local demo key'
|
||||
New-Item -ItemType Directory -Force -Path (Split-Path $keystore) | Out-Null
|
||||
Invoke-Tool (Join-Path $javaHome 'bin\keytool.exe') @(
|
||||
'-genkeypair', '-keystore', $keystore, '-alias', 'occupancy',
|
||||
'-keyalg', 'RSA', '-keysize', '2048', '-validity', '10000',
|
||||
'-storepass', 'occupancy', '-keypass', 'occupancy',
|
||||
'-dname', 'CN=Occupancy Fitting, OU=Demo, O=Local Build, L=Local, ST=Local, C=CN'
|
||||
) 'keytool'
|
||||
}
|
||||
$apksigner = Join-Path $buildTools 'apksigner.bat'
|
||||
Invoke-Tool $apksigner @(
|
||||
'sign',
|
||||
'--ks', $keystore,
|
||||
'--ks-key-alias', 'occupancy',
|
||||
'--ks-pass', 'pass:occupancy',
|
||||
'--key-pass', 'pass:occupancy',
|
||||
'--min-sdk-version', '24',
|
||||
'--out', $apkOut,
|
||||
$aligned
|
||||
) 'apksigner sign'
|
||||
|
||||
Write-Host ''
|
||||
# ---- sanity checks ----
|
||||
$chk = [System.IO.Compression.ZipFile]::OpenRead($apkOut)
|
||||
$entries = @($chk.Entries | ForEach-Object { $_.FullName })
|
||||
$arscEntry = $chk.Entries | Where-Object { $_.FullName -eq 'resources.arsc' }
|
||||
$arscStored = ($arscEntry.Length -eq $arscEntry.CompressedLength)
|
||||
$chk.Dispose()
|
||||
$backslash = $entries | Where-Object { $_ -like '*\*' }
|
||||
if ($backslash) { throw "backslash entry names remain: $($backslash -join ', ')" }
|
||||
foreach ($need in @(
|
||||
'assets/index.html', 'assets/app.js', 'assets/data.js', 'assets/style.css',
|
||||
'assets/vendor/three.min.js', 'assets/vendor/OrbitControls.js',
|
||||
'classes.dex', 'resources.arsc')) {
|
||||
if ($entries -notcontains $need) { throw "missing APK entry: $need" }
|
||||
}
|
||||
if (-not $arscStored) { throw 'resources.arsc must be Stored (uncompressed) for Android 11+' }
|
||||
Write-Host 'entry check: ok (forward slashes, all assets present, resources.arsc stored)'
|
||||
|
||||
Write-Host ''
|
||||
Invoke-Tool $apksigner @('verify', '--verbose', '--print-certs', $apkOut) 'apksigner verify'
|
||||
|
||||
Write-Host ''
|
||||
$badging = & $aapt2 dump badging $apkOut 2>&1
|
||||
$badging | Select-String 'package:|application-label:|launchable-activity:|sdkVersion|targetSdkVersion|uses-permission' |
|
||||
ForEach-Object { $_.Line }
|
||||
Get-Item $apkOut | ForEach-Object { "APK: {0} ({1:N1} MB)" -f $_.FullName, ($_.Length / 1MB) }
|
||||
@@ -0,0 +1,3 @@
|
||||
plugins {
|
||||
id 'com.android.application' version '8.7.3' apply false
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
|
||||
org.gradle.parallel=true
|
||||
org.gradle.caching=true
|
||||
android.useAndroidX=true
|
||||
android.nonTransitiveRClass=true
|
||||
@@ -0,0 +1,17 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = 'occupancy-fitting'
|
||||
include ':app'
|
||||
@@ -0,0 +1,169 @@
|
||||
# Generates Android launcher icons: isometric wireframe cube + voxel mid-planes.
|
||||
# Usage: Set-ExecutionPolicy -Scope Process Bypass; .\android\tools\make-icons.ps1
|
||||
$ErrorActionPreference = 'Stop'
|
||||
Add-Type -AssemblyName System.Drawing
|
||||
|
||||
$root = (Resolve-Path "$PSScriptRoot\..").Path
|
||||
$res = Join-Path $root 'app\src\main\res'
|
||||
$k = [Math]::Cos([Math]::PI / 6.0)
|
||||
$tmp = Join-Path $env:TEMP 'occupancy-icon'
|
||||
|
||||
function New-Glyph {
|
||||
param([int]$Size, [double]$S)
|
||||
|
||||
$bmp = [System.Drawing.Bitmap]::new($Size, $Size)
|
||||
$g = [System.Drawing.Graphics]::FromImage($bmp)
|
||||
$g.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
|
||||
$g.Clear([System.Drawing.Color]::Transparent)
|
||||
|
||||
$cx = $Size / 2.0
|
||||
$cy = $Size / 2.0
|
||||
|
||||
$project = {
|
||||
param($x, $y, $z)
|
||||
[System.Drawing.PointF]::new(
|
||||
[float]($cx + ($x - $y) * $k * $S),
|
||||
[float]($cy + (($x + $y) * 0.5 - $z) * $S))
|
||||
}
|
||||
|
||||
$verts = @()
|
||||
foreach ($x in @(-1.0, 1.0)) {
|
||||
foreach ($y in @(-1.0, 1.0)) {
|
||||
foreach ($z in @(-1.0, 1.0)) {
|
||||
$verts += [pscustomobject]@{ X = $x; Y = $y; Z = $z }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$edges = @()
|
||||
for ($i = 0; $i -lt $verts.Count; $i++) {
|
||||
for ($j = $i + 1; $j -lt $verts.Count; $j++) {
|
||||
$a = $verts[$i]
|
||||
$b = $verts[$j]
|
||||
$diff = 0
|
||||
if ($a.X -ne $b.X) { $diff++ }
|
||||
if ($a.Y -ne $b.Y) { $diff++ }
|
||||
if ($a.Z -ne $b.Z) { $diff++ }
|
||||
if ($diff -eq 1) { $edges += , @($a, $b) }
|
||||
}
|
||||
}
|
||||
|
||||
$cyan = [System.Drawing.Color]::FromArgb(255, 0x5F, 0xE8, 0xFF)
|
||||
$glow = [System.Drawing.Pen]::new([System.Drawing.Color]::FromArgb(34, 0x5F, 0xE8, 0xFF), [float]($S * 0.20))
|
||||
$main = [System.Drawing.Pen]::new($cyan, [float]($S * 0.062))
|
||||
$inner = [System.Drawing.Pen]::new([System.Drawing.Color]::FromArgb(70, 0x5F, 0xE8, 0xFF), [float]($S * 0.022))
|
||||
$accent = [System.Drawing.Pen]::new([System.Drawing.Color]::FromArgb(220, 0xFF, 0x8A, 0x3D), [float]($S * 0.045))
|
||||
$main.LineJoin = [System.Drawing.Drawing2D.LineJoin]::Round
|
||||
$inner.LineJoin = [System.Drawing.Drawing2D.LineJoin]::Round
|
||||
$glow.LineJoin = [System.Drawing.Drawing2D.LineJoin]::Round
|
||||
|
||||
foreach ($e in $edges) {
|
||||
$g.DrawLine($glow, (& $project $e[0].X $e[0].Y $e[0].Z), (& $project $e[1].X $e[1].Y $e[1].Z))
|
||||
}
|
||||
|
||||
$rings = @(
|
||||
, @(@(0.0, -1.0, -1.0), @(0.0, 1.0, -1.0), @(0.0, 1.0, 1.0), @(0.0, -1.0, 1.0))
|
||||
, @(@(-1.0, 0.0, -1.0), @(1.0, 0.0, -1.0), @(1.0, 0.0, 1.0), @(-1.0, 0.0, 1.0))
|
||||
, @(@(-1.0, -1.0, 0.0), @(1.0, -1.0, 0.0), @(1.0, 1.0, 0.0), @(-1.0, 1.0, 0.0))
|
||||
)
|
||||
foreach ($ring in $rings) {
|
||||
for ($i = 0; $i -lt 4; $i++) {
|
||||
$p1 = $ring[$i]
|
||||
$p2 = $ring[($i + 1) % 4]
|
||||
$g.DrawLine($inner, (& $project $p1[0] $p1[1] $p1[2]), (& $project $p2[0] $p2[1] $p2[2]))
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($e in $edges) {
|
||||
$g.DrawLine($main, (& $project $e[0].X $e[0].Y $e[0].Z), (& $project $e[1].X $e[1].Y $e[1].Z))
|
||||
}
|
||||
|
||||
# one "occupied" voxel edge, highlighted in orange
|
||||
$g.DrawLine($accent, (& $project 1.0 -1.0 1.0), (& $project 1.0 -1.0 -1.0))
|
||||
|
||||
$g.Dispose()
|
||||
return $bmp
|
||||
}
|
||||
|
||||
if (-not (Test-Path $tmp)) { New-Item -ItemType Directory -Path $tmp | Out-Null }
|
||||
|
||||
$glyph = New-Glyph -Size 1024 -S 190
|
||||
$glyph.Save((Join-Path $tmp 'glyph.png'), [System.Drawing.Imaging.ImageFormat]::Png)
|
||||
|
||||
function New-RoundedPath {
|
||||
param([int]$Size, [double]$Radius)
|
||||
$p = [System.Drawing.Drawing2D.GraphicsPath]::new()
|
||||
$d = $Radius * 2
|
||||
$p.AddArc(0, 0, [float]$d, [float]$d, 180, 90)
|
||||
$p.AddArc([float]($Size - $d), 0, [float]$d, [float]$d, 270, 90)
|
||||
$p.AddArc([float]($Size - $d), [float]($Size - $d), [float]$d, [float]$d, 0, 90)
|
||||
$p.AddArc(0, [float]($Size - $d), [float]$d, [float]$d, 90, 90)
|
||||
$p.CloseFigure()
|
||||
return $p
|
||||
}
|
||||
|
||||
$bg = [System.Drawing.Color]::FromArgb(255, 0x0B, 0x10, 0x18)
|
||||
$bgInner = [System.Drawing.Color]::FromArgb(255, 0x10, 0x1A, 0x28)
|
||||
$bgEdge = [System.Drawing.Color]::FromArgb(90, 0x2A, 0x53, 0x6B)
|
||||
|
||||
foreach ($d in @(@('mdpi', 48), @('hdpi', 72), @('xhdpi', 96), @('xxhdpi', 144), @('xxxhdpi', 192))) {
|
||||
$name = $d[0]
|
||||
$size = [int]$d[1]
|
||||
$bmp = [System.Drawing.Bitmap]::new($size, $size)
|
||||
$g = [System.Drawing.Graphics]::FromImage($bmp)
|
||||
$g.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
|
||||
$g.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
|
||||
$g.Clear([System.Drawing.Color]::Transparent)
|
||||
|
||||
$path = New-RoundedPath -Size $size -Radius ([double]($size * 0.23))
|
||||
$rect = [System.Drawing.Rectangle]::new(0, 0, $size, $size)
|
||||
$brush = [System.Drawing.Drawing2D.LinearGradientBrush]::new(
|
||||
$rect, $bgInner, $bg, [System.Drawing.Drawing2D.LinearGradientMode]::Vertical)
|
||||
$g.FillPath($brush, $path)
|
||||
$pen = [System.Drawing.Pen]::new($bgEdge, [float][Math]::Max(1.0, $size * 0.012))
|
||||
$g.DrawPath($pen, $path)
|
||||
|
||||
$side = [double]($size * 0.74)
|
||||
$ox = ($size - $side) / 2.0
|
||||
$g.DrawImage($glyph, [System.Drawing.RectangleF]::new([float]$ox, [float]$ox, [float]$side, [float]$side))
|
||||
|
||||
$dir = Join-Path $res "mipmap-$name"
|
||||
New-Item -ItemType Directory -Force -Path $dir | Out-Null
|
||||
$bmp.Save((Join-Path $dir 'ic_launcher.png'), [System.Drawing.Imaging.ImageFormat]::Png)
|
||||
$g.Dispose(); $bmp.Dispose(); $path.Dispose(); $brush.Dispose(); $pen.Dispose()
|
||||
}
|
||||
|
||||
foreach ($d in @(@('mdpi', 108), @('hdpi', 162), @('xhdpi', 216), @('xxhdpi', 324), @('xxxhdpi', 432))) {
|
||||
$name = $d[0]
|
||||
$size = [int]$d[1]
|
||||
$bmp = [System.Drawing.Bitmap]::new($size, $size)
|
||||
$g = [System.Drawing.Graphics]::FromImage($bmp)
|
||||
$g.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
|
||||
$g.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
|
||||
$g.Clear([System.Drawing.Color]::Transparent)
|
||||
|
||||
$side = [double]($size * 0.62)
|
||||
$ox = ($size - $side) / 2.0
|
||||
$g.DrawImage($glyph, [System.Drawing.RectangleF]::new([float]$ox, [float]$ox, [float]$side, [float]$side))
|
||||
|
||||
$dir = Join-Path $res "drawable-$name"
|
||||
New-Item -ItemType Directory -Force -Path $dir | Out-Null
|
||||
$bmp.Save((Join-Path $dir 'ic_launcher_foreground.png'), [System.Drawing.Imaging.ImageFormat]::Png)
|
||||
$g.Dispose(); $bmp.Dispose()
|
||||
}
|
||||
|
||||
# 1024px preview with background, for eyeballing
|
||||
$preview = [System.Drawing.Bitmap]::new(1024, 1024)
|
||||
$pg = [System.Drawing.Graphics]::FromImage($preview)
|
||||
$pg.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::AntiAlias
|
||||
$pg.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
|
||||
$pg.Clear($bg)
|
||||
$path = New-RoundedPath -Size 1024 -Radius 235
|
||||
$brush = [System.Drawing.Drawing2D.LinearGradientBrush]::new(
|
||||
[System.Drawing.Rectangle]::new(0, 0, 1024, 1024), $bgInner, $bg, [System.Drawing.Drawing2D.LinearGradientMode]::Vertical)
|
||||
$pg.FillPath($brush, $path)
|
||||
$pg.DrawImage($glyph, [System.Drawing.RectangleF]::new(128, 128, 768, 768))
|
||||
$preview.Save((Join-Path $root 'icon-preview.png'), [System.Drawing.Imaging.ImageFormat]::Png)
|
||||
$pg.Dispose(); $preview.Dispose(); $glyph.Dispose()
|
||||
|
||||
Write-Output "icons written to $res"
|
||||
|
After Width: | Height: | Size: 103 KiB |
|
After Width: | Height: | Size: 180 KiB |
@@ -0,0 +1,110 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Regenerate the 10 cm car occupancy grid embedded in web/packing.js.
|
||||
|
||||
The fitting page stores the car as 4 cm occupancy cubes (`web/data.js`).
|
||||
The packing page needs a coarser, compact grid, so we downsample to 10 cm by
|
||||
majority vote and print a bit-packed base64 blob plus the dims.
|
||||
|
||||
Run: python src/gen_car_voxels.py
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import json
|
||||
import math
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
PITCH_MM = 100.0
|
||||
FINE_MM = 40.0
|
||||
|
||||
|
||||
def main() -> None:
|
||||
raw = (ROOT / "web" / "data.js").read_text(encoding="utf-8")
|
||||
data = json.loads(raw[raw.index("{"):].rstrip().rstrip(";"))
|
||||
sd = data["sizes"][0] # 4 cm cubes
|
||||
nx, ny, nz = sd["dims"]
|
||||
idx = np.frombuffer(base64.b64decode(sd["indicesB64"]), dtype="<u4")
|
||||
frac = np.frombuffer(base64.b64decode(sd["fractionsB64"]), dtype="<u2").astype(np.float32) / 1000.0
|
||||
|
||||
k = idx % nz
|
||||
t = idx // nz
|
||||
j = t % ny
|
||||
i = t // ny
|
||||
fine = np.zeros((nx, ny, nz), dtype=bool)
|
||||
fine[i[frac >= 0.5], j[frac >= 0.5], k[frac >= 0.5]] = True
|
||||
|
||||
ratio = PITCH_MM / FINE_MM # 2.5
|
||||
ox, oy, oz = (int(math.ceil(n / ratio)) for n in (nx, ny, nz))
|
||||
coarse = np.zeros((ox, oy, oz), dtype=bool)
|
||||
for cx in range(ox):
|
||||
for cy in range(oy):
|
||||
for cz in range(oz):
|
||||
x0, x1 = int(cx * ratio), min(nx, int((cx + 1) * ratio) + 1)
|
||||
y0, y1 = int(cy * ratio), min(ny, int((cy + 1) * ratio) + 1)
|
||||
z0, z1 = int(cz * ratio), min(nz, int((cz + 1) * ratio) + 1)
|
||||
block = fine[x0:x1, y0:y1, z0:z1]
|
||||
# "any" keeps thin structures (wings, wheels) at the coarse pitch;
|
||||
# majority would make the car ~0.7 m shorter than its real bbox.
|
||||
if block.size and block.any():
|
||||
coarse[cx, cy, cz] = True
|
||||
|
||||
# fill enclosed voids (cockpit, engine bay): flood the outside, then invert.
|
||||
# open space under the wings stays empty, so parts can still tuck under them.
|
||||
free = ~coarse
|
||||
reach = np.zeros_like(coarse)
|
||||
stack = []
|
||||
sx, sy, sz = free.shape
|
||||
for x in range(sx):
|
||||
for y in range(sy):
|
||||
for z in (0, sz - 1):
|
||||
if free[x, y, z]:
|
||||
stack.append((x, y, z))
|
||||
for x in range(sx):
|
||||
for z in range(sz):
|
||||
for y in (0, sy - 1):
|
||||
if free[x, y, z]:
|
||||
stack.append((x, y, z))
|
||||
for y in range(sy):
|
||||
for z in range(sz):
|
||||
for x in (0, sx - 1):
|
||||
if free[x, y, z]:
|
||||
stack.append((x, y, z))
|
||||
while stack:
|
||||
x, y, z = stack.pop()
|
||||
if reach[x, y, z] or not free[x, y, z]:
|
||||
continue
|
||||
reach[x, y, z] = True
|
||||
for dx, dy, dz in ((1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0), (0, 0, 1), (0, 0, -1)):
|
||||
nx_, ny_, nz_ = x + dx, y + dy, z + dz
|
||||
if 0 <= nx_ < sx and 0 <= ny_ < sy and 0 <= nz_ < sz and free[nx_, ny_, nz_] and not reach[nx_, ny_, nz_]:
|
||||
stack.append((nx_, ny_, nz_))
|
||||
coarse = coarse | (~reach)
|
||||
|
||||
|
||||
packed = np.packbits(coarse.ravel())
|
||||
blob = base64.b64encode(packed.tobytes()).decode("ascii")
|
||||
|
||||
out = ROOT / "web" / "car-voxels.js"
|
||||
out.write_text(
|
||||
"/* generated by src/gen_car_voxels.py - 10 cm occupancy of AURORA A1 */\n"
|
||||
"window.CAR_VOXELS = "
|
||||
+ json.dumps({
|
||||
"dims": [int(v) for v in coarse.shape],
|
||||
"cells": int(coarse.sum()),
|
||||
"pitchMm": PITCH_MM,
|
||||
"b64": blob,
|
||||
}, ensure_ascii=False, separators=(",", ":"))
|
||||
+ ";\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
print("fine dims :", (nx, ny, nz))
|
||||
print("coarse dims :", coarse.shape)
|
||||
print("occupied cells:", int(coarse.sum()), "of", coarse.size)
|
||||
print("wrote", out, f"({out.stat().st_size} bytes)")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,2 @@
|
||||
/* generated by src/gen_car_voxels.py - 10 cm occupancy of AURORA A1 */
|
||||
window.CAR_VOXELS = {"dims":[57,21,10],"cells":3247,"pitchMm":100.0,"b64":"wDAMAwAAAAgCAIA4DgIAgCAAAADAMAwDAAAwDAMAwAAAAgCAIA4DgIAgCAAAwDAMAwDAAAwAAAAAAAAAAAAAAYBgAAAAAAAAAAAAABAAAQAAAAAAAAAAAAAAcBwAAAAAAAAAAAAABAAAAAAAAAAAAAAAAGAcBwGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAcBwHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAcBwHAAAAAAAAAAAAAAAAeB4HgeAAAAAAAHgeB4HgAAAAAAB4HgeB4AA/D8Pw/AAAAAAAHgeB4DgAAAAAAD8Pw/D8AA/j+P4/gAAAAAYDwfB8DwAAAAAAD+P4/j+AA1jGP4/gAAAAAYDwPA8DwAAAAAAD+P4xjWAA1jGP4/gAAAAA8DwPA8DwAAAAAAD+P4xj2AAzjOP4/gAAAAA8DwfB8DwAAAAAAD+P4zjOAA/D8Pw/AAAAAB8HwfB8HwPAAAAAD8Pw/D8AAeB4HgeAAAAAB8HwfB8HwfAAAAAB4HgeB4AAAAAAAAAAAAAB8HwfB8HwfAAAAAAAAAAAAAAAAAAAAAAAAAB8Hwfh+HwfAAAAAAAAAAAAAAAAAAAAAAAAOB8H4fx/H4fB8AAAAAAAAAAAAAAAAAAAAAAfB+P4/z/P4fB8AAAAAAAAAAAAAAAAAAADAMfz+P+/7/v+/B/AMAwAAAAAAAAAAADwPA3D8fz9v28DwP2/Z/D8Nw8DwAAAAAAAADwfB8HwfD9vw/D8P2/Z8HwfB8DwAAAAAAAAHwfB8HwfD9PA8DwPg/R8HwfB8HwAAAAAAAAHwfB8HwfD9PA8zzPA/R8HwfB8HwAAAAAAAAHwfB8HwfD/PM9z3Ps/x8HwfB8HwAAAAAAAAHwfB8HwfD/P89z3P8/x8HwfB8HwAAAAAAAAHwfB8HwfD+P+////+/B8HwfB8HwAAAAAAAAHwfB8HwfD/P///////B8HwfB8HwAAAAAAAAHwfB8HwfD/P///////B8HwfB8HwAAAAAAAAHgfB8HwfD/v///////B8HwfB8HgAAAAAAAAHgeB8HwfD/v///////h8HwfB4HgAAAAAAAAAAeB4HgeD/P+/7/v+fh4HgeB4AAAAAAAAAAAAeB4HgeB/H+f5/n+fh4HgeB4AAAAAAAAAAAAeB4HgeB/H+f5/n+fh4HgeBwAAAAAAAAAAAAcB4HgeB/H8fx/H8fh4HgeAAAAAAAAAAAAAAcBwHAcB+H8fx/H8fBwHAcAAAAAAAAAAAAAAABwHAcB+H8fx/H8cBwHAcAAAAAAAAAAAAAAABwHAcB8H4fx/H4cBwHAcAAAAAAAAAAAAAAAAAHAcB8H4fh+H4cBwHAAAAAAAAAAAAAAAAAAAHAcB8Hwfh+HwcBwHAAAAAAAAAAAAAAAAAAAHAcBwHwfB8HwcBwGAAAAAAAAAAAAAAAAAAAGAcBwHwfB8HwcBwAAAAAAAAAAAAAAAAAAAAAAYBgHwfB8HwYBgAAAAAAAAAAAAeB4HgeCAIA4DgPg/D8Pg4DgIAuB4HgeB4AA/D8Pw/CAIAgCALg+D4LggCAIA/D8Pw/D8AA/j+P4/jAMAwDAPA+D4PAwDAMA/j+P4/j+AA1jGMY/hQFAUBQHAeB4HAUBQFA/j+MYxjWAA9jGMY/hQFAUBQHAeB4HAUBQFA/j+MYxjWAAzjOM4zhgGAYBgGAeB4GAYBgGA7jOM4zjOAA/D8Pw/BgGAYBgGAeB4GAYBgGA/D8Pw/D8AAeB4HgeAgCAIAgCAOA4CAIAgCAeB4HgeB4AAAAAAAAAwDAMAwDAOA4DAMAwDAMAAAAAAAAAAAAAAAARBEEAQBAEQRBEEAQBEEQAAAAAAAAAAAAAAABAEAQBAEEQRAEAQBAEAQAAAAAAAAAAAAAAABgGAQBAEAQBAEAQBAGAYAAAAAAAAAAAAAAAAgCAAAAAAAAAAAAAACAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"};
|
||||
@@ -9,6 +9,11 @@
|
||||
<body>
|
||||
<div id="app">
|
||||
<aside id="panel">
|
||||
<nav class="page-tabs">
|
||||
<a class="active" href="index.html">占用拟合</a>
|
||||
<a href="packing.html">装箱模拟</a>
|
||||
</nav>
|
||||
|
||||
<header class="brand">
|
||||
<div class="eyebrow"><span class="dot"></span> OCP · STEP → VOXEL</div>
|
||||
<h1>OCCUPANCY<br /><span>FITTING</span></h1>
|
||||
|
||||
@@ -0,0 +1,515 @@
|
||||
/* ------------------------------------------------------------- view toolbar */
|
||||
#app { grid-template-columns: 430px minmax(0, 1fr); }
|
||||
|
||||
@media (max-width: 920px) {
|
||||
#app { grid-template-columns: 1fr; }
|
||||
}
|
||||
|
||||
.toolbar-groups {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- context menu */
|
||||
.ctx-menu {
|
||||
position: fixed;
|
||||
z-index: 90;
|
||||
width: 258px;
|
||||
padding: 10px 12px 12px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
background: rgba(9, 17, 29, 0.98);
|
||||
box-shadow: 0 16px 44px rgba(0, 0, 0, 0.55);
|
||||
font-size: 11px;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.ctx-menu h4 {
|
||||
margin: 0 0 8px;
|
||||
font-size: 11px;
|
||||
color: var(--cyan);
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
|
||||
.ctx-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
margin: 7px 0;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.ctx-row input[type="number"] {
|
||||
width: 78px;
|
||||
padding: 3px 6px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--line);
|
||||
background: rgba(8, 15, 26, 0.9);
|
||||
color: var(--text);
|
||||
font-family: var(--mono);
|
||||
font-size: 11px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.ctx-row select {
|
||||
width: 78px;
|
||||
padding: 3px 6px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--line);
|
||||
background: rgba(8, 15, 26, 0.9);
|
||||
color: var(--text);
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.ctx-actions {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.ctx-actions button {
|
||||
flex: 1;
|
||||
padding: 6px 8px;
|
||||
border-radius: 5px;
|
||||
border: 1px solid var(--line);
|
||||
background: rgba(12, 24, 38, 0.9);
|
||||
color: var(--text);
|
||||
font-size: 11px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.ctx-actions button.primary {
|
||||
border-color: transparent;
|
||||
background: linear-gradient(180deg, #8beaff, #4fd3f2);
|
||||
color: #04121a;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------- capacity bar */
|
||||
.cap-bar {
|
||||
height: 6px;
|
||||
margin: 10px 0 6px;
|
||||
border-radius: 3px;
|
||||
background: #16283c;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.cap-bar span {
|
||||
display: block;
|
||||
width: 0;
|
||||
height: 100%;
|
||||
border-radius: 3px;
|
||||
background: linear-gradient(90deg, #3fa8c9, #56e1ff 55%, #6df5b1);
|
||||
transition: width 0.25s ease;
|
||||
}
|
||||
|
||||
.cap-bar.full span {
|
||||
background: linear-gradient(90deg, #ff8a3d, #ffb45a);
|
||||
}
|
||||
|
||||
.cap-text {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
font-family: var(--mono);
|
||||
font-size: 9px;
|
||||
color: var(--faint);
|
||||
}
|
||||
|
||||
.cap-text b {
|
||||
font-size: 13px;
|
||||
color: var(--cyan);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.cap-bar.full + .cap-text b {
|
||||
color: var(--amber);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------- convergence plot */
|
||||
.conv-chart {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 92px;
|
||||
margin: 8px 0 2px;
|
||||
border: 1px solid var(--line-soft);
|
||||
border-radius: 5px;
|
||||
background: rgba(7, 14, 24, 0.8);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ pool list */
|
||||
.pool-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
margin-top: 8px;
|
||||
max-height: 340px;
|
||||
overflow-y: auto;
|
||||
padding-right: 2px;
|
||||
}
|
||||
|
||||
.pool-row {
|
||||
display: grid;
|
||||
grid-template-columns: 8px 1fr auto;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
padding: 6px 8px;
|
||||
border: 1px solid var(--line-soft);
|
||||
border-radius: 5px;
|
||||
background: rgba(9, 17, 29, 0.65);
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
transition: border-color 0.15s, background 0.15s;
|
||||
}
|
||||
|
||||
.pool-row:hover {
|
||||
border-color: var(--cyan-dim);
|
||||
background: rgba(14, 28, 44, 0.9);
|
||||
}
|
||||
|
||||
.pool-row.blocked {
|
||||
border-color: rgba(255, 138, 61, 0.35);
|
||||
}
|
||||
|
||||
.pool-row.blocked .pool-name {
|
||||
color: #ffcf9a;
|
||||
}
|
||||
|
||||
.pool-swatch {
|
||||
width: 8px;
|
||||
height: 24px;
|
||||
border-radius: 2px;
|
||||
background: var(--swatch, #567);
|
||||
}
|
||||
|
||||
.pool-main {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.pool-name {
|
||||
display: block;
|
||||
font-size: 11px;
|
||||
color: var(--text);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.pool-meta {
|
||||
display: block;
|
||||
margin-top: 2px;
|
||||
font-family: var(--mono);
|
||||
font-size: 9px;
|
||||
color: var(--faint);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.pool-add {
|
||||
font-family: var(--mono);
|
||||
font-size: 9px;
|
||||
padding: 3px 7px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--line);
|
||||
color: var(--cyan);
|
||||
background: rgba(12, 26, 40, 0.9);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.pool-row:hover .pool-add {
|
||||
border-color: var(--cyan);
|
||||
}
|
||||
|
||||
.pool-empty {
|
||||
padding: 9px;
|
||||
border: 1px dashed var(--line);
|
||||
border-radius: 5px;
|
||||
font-size: 10px;
|
||||
color: var(--faint);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- param block */
|
||||
.param-name {
|
||||
margin: 8px 0 6px;
|
||||
font-size: 12px;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.param-name.empty {
|
||||
color: var(--faint);
|
||||
}
|
||||
|
||||
.param-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
margin: 6px 0;
|
||||
font-size: 10.5px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.param-row .switch {
|
||||
margin: 0;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
|
||||
.param-row input[type="number"] {
|
||||
width: 64px;
|
||||
padding: 3px 6px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--line);
|
||||
background: rgba(8, 15, 26, 0.9);
|
||||
color: var(--text);
|
||||
font-family: var(--mono);
|
||||
font-size: 11px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.param-row input[type="number"]:focus {
|
||||
outline: none;
|
||||
border-color: var(--cyan);
|
||||
}
|
||||
|
||||
.param-row .unit {
|
||||
font-family: var(--mono);
|
||||
font-size: 9px;
|
||||
color: var(--faint);
|
||||
width: 12px;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- placed list */
|
||||
.pack-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
margin-top: 8px;
|
||||
max-height: 460px;
|
||||
overflow-y: auto;
|
||||
padding-right: 2px;
|
||||
}
|
||||
|
||||
.pack-row {
|
||||
display: grid;
|
||||
grid-template-columns: 30px 8px 1fr auto;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
padding: 6px 8px;
|
||||
border: 1px solid var(--line-soft);
|
||||
border-radius: 5px;
|
||||
background: rgba(9, 17, 29, 0.65);
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
transition: border-color 0.15s, background 0.15s;
|
||||
}
|
||||
|
||||
.pack-row:hover {
|
||||
border-color: var(--cyan-dim);
|
||||
background: rgba(14, 28, 44, 0.9);
|
||||
}
|
||||
|
||||
.pack-row.active {
|
||||
border-color: var(--cyan);
|
||||
background: rgba(19, 45, 66, 0.9);
|
||||
}
|
||||
|
||||
.pack-order {
|
||||
font-family: var(--mono);
|
||||
font-size: 10px;
|
||||
color: var(--cyan);
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.pack-swatch {
|
||||
width: 8px;
|
||||
height: 24px;
|
||||
border-radius: 2px;
|
||||
background: var(--swatch, #567);
|
||||
}
|
||||
|
||||
.pack-main {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.pack-name {
|
||||
display: block;
|
||||
font-size: 11px;
|
||||
color: var(--text);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.pack-meta {
|
||||
display: block;
|
||||
margin-top: 2px;
|
||||
font-family: var(--mono);
|
||||
font-size: 9px;
|
||||
color: var(--faint);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.pack-badges {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
.badge {
|
||||
font-family: var(--mono);
|
||||
font-size: 8.5px;
|
||||
padding: 1px 4px;
|
||||
border-radius: 3px;
|
||||
border: 1px solid var(--line);
|
||||
color: var(--faint);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.badge.remove {
|
||||
color: var(--faint);
|
||||
border-color: transparent;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.badge.remove:hover {
|
||||
color: var(--red);
|
||||
border-color: rgba(255, 122, 122, 0.4);
|
||||
}
|
||||
|
||||
.pack-empty {
|
||||
padding: 10px;
|
||||
border: 1px dashed var(--line);
|
||||
border-radius: 5px;
|
||||
font-size: 10px;
|
||||
color: var(--faint);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- toast */
|
||||
.toast {
|
||||
position: fixed;
|
||||
left: 50%;
|
||||
bottom: 34px;
|
||||
z-index: 50;
|
||||
transform: translate(-50%, 12px);
|
||||
max-width: min(560px, 88vw);
|
||||
padding: 10px 16px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid rgba(255, 180, 90, 0.35);
|
||||
background: rgba(18, 14, 9, 0.94);
|
||||
color: #ffd9b0;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
|
||||
opacity: 0;
|
||||
transition: opacity 0.22s ease, transform 0.22s ease;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.toast.show {
|
||||
opacity: 1;
|
||||
transform: translate(-50%, 0);
|
||||
}
|
||||
|
||||
.toast.ok {
|
||||
border-color: rgba(109, 245, 177, 0.4);
|
||||
background: rgba(9, 20, 15, 0.94);
|
||||
color: #c8ffe4;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- 3D overlay */
|
||||
.pack-legend {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
right: 16px;
|
||||
z-index: 6;
|
||||
padding: 5px 9px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--line-soft);
|
||||
background: rgba(6, 12, 21, 0.72);
|
||||
backdrop-filter: blur(6px);
|
||||
font-family: var(--mono);
|
||||
font-size: 9px;
|
||||
color: var(--faint);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.cam-buttons button.spinning {
|
||||
color: #04121a;
|
||||
background: linear-gradient(180deg, #8beaff, #4fd3f2);
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
@media (max-width: 920px) {
|
||||
.pack-legend { display: none; }
|
||||
#viewport { min-height: 66vh; }
|
||||
#viewport canvas { touch-action: none; }
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ limit warning */
|
||||
.limit-warn {
|
||||
margin-top: 8px;
|
||||
padding: 7px 9px;
|
||||
border-radius: 5px;
|
||||
font-size: 10px;
|
||||
line-height: 1.5;
|
||||
border: 1px solid rgba(255, 122, 122, 0.45);
|
||||
background: rgba(60, 12, 16, 0.55);
|
||||
color: #ffb3b3;
|
||||
}
|
||||
|
||||
.limit-warn.mid {
|
||||
border-color: rgba(255, 180, 90, 0.4);
|
||||
background: rgba(46, 30, 8, 0.55);
|
||||
color: #ffd9a8;
|
||||
}
|
||||
|
||||
.limit-warn.ok {
|
||||
border-color: rgba(109, 245, 177, 0.4);
|
||||
background: rgba(8, 40, 26, 0.5);
|
||||
color: #b8ffe0;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------ compass */
|
||||
.compass {
|
||||
position: absolute;
|
||||
top: 56px;
|
||||
right: 16px;
|
||||
z-index: 6;
|
||||
width: 108px;
|
||||
height: 108px;
|
||||
border-radius: 50%;
|
||||
border: 1px solid var(--line-soft);
|
||||
background: radial-gradient(circle at 50% 45%, rgba(22, 44, 66, 0.55), rgba(6, 12, 20, 0.25));
|
||||
cursor: pointer;
|
||||
overflow: hidden;
|
||||
touch-action: none;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
#viewport canvas { touch-action: none; }
|
||||
|
||||
.compass canvas {
|
||||
display: block;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
@media (max-width: 920px) {
|
||||
.compass { width: 84px; height: 84px; top: 52px; right: 10px; }
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>Container Filling · 体素装箱模拟</title>
|
||||
<link rel="stylesheet" href="style.css?v=20261128a" />
|
||||
<link rel="stylesheet" href="packing.css?v=20261128a" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
<aside id="panel">
|
||||
<nav class="page-tabs">
|
||||
<a href="index.html?v=20261126a">占用拟合</a>
|
||||
<a class="active" href="packing.html">装箱模拟</a>
|
||||
</nav>
|
||||
|
||||
<header class="brand">
|
||||
<div class="eyebrow"><span class="dot"></span> MIXED BOX / VOXEL · FREE ROTATION</div>
|
||||
<h1>CONTAINER<br /><span>FILLING</span></h1>
|
||||
<p class="sub">长方体与小立方体混装 · 逐件正向/堆码/承重<br />从箱底扫描铺装,多方向并行比填充率</p>
|
||||
</header>
|
||||
|
||||
<section class="block controls">
|
||||
<div class="label-row"><label>箱型</label><output id="containerOut">—</output></div>
|
||||
<div class="segmented" id="containerSeg" role="group" aria-label="箱型"></div>
|
||||
|
||||
<div class="label-row second"><label>并行扫描</label><output id="roundsOut">标准</output></div>
|
||||
<div class="segmented" id="roundsSeg" role="group" aria-label="并行扫描">
|
||||
<button type="button" data-rounds="8">快</button>
|
||||
<button type="button" data-rounds="16" class="active">标准</button>
|
||||
<button type="button" data-rounds="24">深</button>
|
||||
</div>
|
||||
|
||||
<div class="button-row">
|
||||
<button id="packAll" class="primary">全部装箱</button>
|
||||
<button id="optimize" class="ghost">重新推理</button>
|
||||
</div>
|
||||
<div class="button-row">
|
||||
<button id="clearAll" class="ghost">清空</button>
|
||||
<button id="exportCsv" class="ghost">导出清单</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="block">
|
||||
<div class="block-title"><span>推理过程</span><span class="live" id="loadState">IDLE</span></div>
|
||||
<div class="cap-bar"><span id="convFill"></span></div>
|
||||
<div class="cap-text">
|
||||
<b id="convBest">0.0%</b>
|
||||
<span id="convRound">尚未开始</span>
|
||||
</div>
|
||||
<canvas id="convChart" class="conv-chart" width="300" height="92"></canvas>
|
||||
<div class="hint" id="convHint">每操作一次都从箱底重新扫描铺装;多种扫描方向并行比较,保留填充率最高的一组</div>
|
||||
<div class="limit-warn" id="limitWarn" hidden>—</div>
|
||||
</section>
|
||||
|
||||
<section class="block stats">
|
||||
<div class="block-title"><span>装载指标</span><span class="live">PLAN</span></div>
|
||||
<div class="metric big">
|
||||
<span class="k">填充率</span>
|
||||
<span class="v" id="mFill">0.0</span><span class="u">%</span>
|
||||
</div>
|
||||
<div class="grid2">
|
||||
<div class="mini"><span class="k">已装 / 总数</span><b id="mCount">0 / 0</b></div>
|
||||
<div class="mini"><span class="k">总重</span><b id="mMass">0 kg</b></div>
|
||||
<div class="mini"><span class="k">地板覆盖</span><b id="mFloor">0%</b></div>
|
||||
<div class="mini"><span class="k">最高堆码</span><b id="mTop">0 m</b></div>
|
||||
<div class="mini"><span class="k">重心高度</span><b id="mCog">0 m</b></div>
|
||||
<div class="mini"><span class="k">载重利用率</span><b id="mPayload">0%</b></div>
|
||||
</div>
|
||||
<div class="ref-row"><span>箱内体积</span><b id="mBox">—</b><span>m³</span></div>
|
||||
<div class="ref-row"><span>理论上限</span><b id="mLimit">—</b><span>%</span></div>
|
||||
<div class="ref-row"><span>占用体素</span><b id="mVox">—</b></div>
|
||||
<div class="ref-row"><span>货物装载率</span><b id="mCargoRate">—</b><span>%</span></div>
|
||||
<div class="ref-row"><span>斜放 / 翻转 / 正向</span><b id="mRot">—</b></div>
|
||||
<div class="ref-note" id="stateNote">等待第一次推理</div>
|
||||
</section>
|
||||
|
||||
<section class="block">
|
||||
<div class="block-title"><span>待选零件</span><span class="sub2" id="poolCount">—</span></div>
|
||||
<div class="pool-list" id="poolList"></div>
|
||||
<div class="hint">右键任意零件可编辑:正向锁定 / 堆码个数 / 承重上限 / 拟合方式 / 自身重量</div>
|
||||
</section>
|
||||
|
||||
<section class="block">
|
||||
<div class="block-title"><span>装箱清单</span><span class="sub2">点击定位 · 可移除</span></div>
|
||||
<div class="pack-list" id="placedList"></div>
|
||||
</section>
|
||||
|
||||
<details class="method">
|
||||
<summary>规则与算法</summary>
|
||||
<p>
|
||||
<b>拟合方式</b>:每件默认按<b>最小长方体</b>装;想用真实轮廓时,把该件切成
|
||||
「小立方体」即可与其他长方体混装。小立方体件按 100 mm 体素占位(车体来自拟合页
|
||||
4 cm 栅格降采样),其中空、内凹、半开放的腔体不占堆码深度,仍然可以继续塞东西,
|
||||
即使该件堆码个数是 1。
|
||||
</p>
|
||||
<p>
|
||||
<b>正向锁定</b>:锁定的件只允许绕竖轴 0/90/180/270°;不锁定的件允许球面任意角度。
|
||||
长方体自身倾斜只会让外接盒变大,所以长方体只枚举 6 个轴向;小立方体件才会在推理中
|
||||
按轮次采样不同的空间角度。
|
||||
</p>
|
||||
<p>
|
||||
<b>堆码个数</b>:整数 1–9。1 = 不可再压;2 = 上面还能再堆 1 个;依此类推。
|
||||
同一竖列上按「最小堆码个数」为准:底层设 2、中间件设 4,则该列总共只能放 2 个。
|
||||
</p>
|
||||
<p>
|
||||
<b>承重</b>:每件还有承重上限(kg,0 = 不可压)。落位时按体素接触面把重量逐层向下传,
|
||||
检查每一层结构件是否超载;中空、内凹区域不接触、不传力。堆码个数管层数,承重管会不会
|
||||
压坏,两者同时校验。
|
||||
</p>
|
||||
<p>
|
||||
<b>间隙与支撑</b>:件与件保持 1 个体素(100 mm)间隙;叠放要求底面 ≥60% 落在同一
|
||||
高度的支撑面上。改动任何参数都会自动重新推理。
|
||||
</p>
|
||||
</details>
|
||||
|
||||
<footer class="foot">
|
||||
<div id="genAt">mixed box / voxel · 40' GP</div>
|
||||
<div>间隙 100 mm · 支撑 60% · 奖赏 = 填充率</div>
|
||||
</footer>
|
||||
</aside>
|
||||
|
||||
<main id="viewport">
|
||||
<div class="viewport-toolbar">
|
||||
<div class="toolbar-groups">
|
||||
<div class="cam-buttons">
|
||||
<button data-view="overview" class="active">整体</button>
|
||||
<button data-view="top">俯视</button>
|
||||
<button data-view="side">侧视</button>
|
||||
<button data-view="door">门端</button>
|
||||
<button data-view="flip">翻转</button>
|
||||
<button id="recenter" type="button">居中</button>
|
||||
<button id="spin" type="button">自转</button>
|
||||
</div>
|
||||
<div class="cam-buttons" id="displaySeg">
|
||||
<button data-display="solid">实体</button>
|
||||
<button data-display="ghost" class="active">虚影</button>
|
||||
<button data-display="xray">X 光</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="compass" class="compass" title="拖动旋转 · 点击回整体视角"></div>
|
||||
<div class="pack-legend">
|
||||
<span class="legend-label">长方体 = 外廓 · 小立方体 = 真实占位</span>
|
||||
</div>
|
||||
<div class="viewport-hint">左键平移 · 滚轮缩放 · 中键或 Shift+左键拖动旋转 · 触屏:单指平移 / 双指缩放 / 罗盘拖动旋转</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<div id="toast" class="toast" hidden></div>
|
||||
<div id="ctxMenu" class="ctx-menu" hidden></div>
|
||||
|
||||
<script src="vendor/three.min.js?v=20261125b"></script>
|
||||
<script src="vendor/OrbitControls.js?v=20261125b"></script>
|
||||
<script src="car-voxels.js?v=20261127a"></script>
|
||||
<script src="packing.js?v=20261128a"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -587,3 +587,36 @@ button.ghost { flex: 1; color: var(--muted); }
|
||||
.env-compare div.on span,
|
||||
.env-compare div.on b,
|
||||
.env-compare div.on em { color: var(--green); }
|
||||
|
||||
/* ------------------------------------------------------------------ page tabs */
|
||||
.page-tabs {
|
||||
display: flex;
|
||||
gap: 5px;
|
||||
margin: 0 0 16px;
|
||||
}
|
||||
|
||||
.page-tabs a {
|
||||
flex: 1;
|
||||
padding: 7px 8px;
|
||||
text-align: center;
|
||||
font-size: 10.5px;
|
||||
letter-spacing: 0.08em;
|
||||
color: var(--muted);
|
||||
text-decoration: none;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 6px;
|
||||
background: rgba(8, 15, 26, 0.6);
|
||||
transition: color 0.15s, border-color 0.15s;
|
||||
}
|
||||
|
||||
.page-tabs a:hover {
|
||||
color: var(--text);
|
||||
border-color: var(--cyan-dim);
|
||||
}
|
||||
|
||||
.page-tabs a.active {
|
||||
color: #04121a;
|
||||
font-weight: 700;
|
||||
border-color: transparent;
|
||||
background: linear-gradient(180deg, #8beaff, #4fd3f2);
|
||||
}
|
||||