aardio 文档

下载、校验与取消

先检查下载计划

import web.rest.polyHaven;
var ph=web.rest.polyHaven("My3DTool/1.0");
var plan,err=ph.planDownload("ceramic_vase_03",{
    kind="blend";resolution="1k";format="blend"
});
if(!plan) { ph.close();return null,err; }
print(plan.mainRelativePath,plan.totalSize,plan.files);

var report,err,partial=ph.download(plan,"/assets/ceramic_vase_03/1k",{
    maxBytes=16*1024*1024;
    onProgress=function(event){
        print(event.relativePath,event.fileBytes,event.fileSize);
        // return false; // 只有全等于 false 才取消
    }
});
ph.close();
if(!report) return null,err,partial;
return report.mainFile;

planDownload 只请求清单,不下载资产。需要离线重建时:

import web.rest.polyHaven;
import JSON;
var files=JSON.load("/cached-files.json");
var plan,err=web.rest.polyHaven.buildPlan("ceramic_vase_03",files,{resolution="1k"});
return plan,err;

files 应为该资产完整 /files/{id} 响应,而不是下载报告。

选择规则

下载选项

选项 默认 行为
maxBytes 536870912(512 MiB) 整个计划的字节上限,含缓存文件,0 会拒绝非空计划;可显式提高
overwrite false 现有文件不匹配时拒绝;true 允许用校验通过的新文件替换
onProgress 无 function(event);返回 false 取消,返回 null/0 不取消

每个进度事件包含 phase(begin 或 download)、relativePath、path、fileBytes(当前文件已接收累计值)、fileSize、completedBytes(此前已完成文件字节数)、totalSize、index、count。缓存文件只有 begin 事件;最终结果以返回 report 为准,没有伪造的网络进度或独立 done 事件。

begin 在网络前触发。下载开始通知可能还有一次 fileBytes=0。分块回调返回 false 会中断读取,库自行记录取消,防止底层仍返回 true 时误报下载完成。取消是协作式的,不能取消正在阻塞的 DNS/连接;不要在回调里重入同一个客户端。

完整性与文件布局

成功报告有 complete=true、mainFile(绝对路径)、directory、files、downloaded、cached、totalSize、source、assetUrl。仅在返回成功后把 mainFile 交给 Blender。

失败返回 null,err,detail;网络/文件处理中 detail 通常为 complete=false 的 partialReport,预算失败则为 {totalSize,maxBytes},输入错误可能无 detail。不把失败 detail 当成完整资产报告。

库不主动写清单文件,避免覆盖用户文件;需要留档可以显式 JSON.save 保存 plan/report。跨机器搬移后 report 中的绝对路径失效,应按新根目录和 relativePath 重建;复制整个资产目录以保留贴图相对布局。

Markdown 格式