今天花了一天的时间来看forge,做的过程中发现了不少问题,实现了一个简单模型的可视化
总结:
1、走了不少弯路,因为windows系统和linux系统中命令的不同(什么双引号单引号问题,还有最后加上-k的问题),还不如直接用虚拟机来获取token和上传模型
2、需要安装curl
3、一步步跟着官网上来
具体步骤:
1、创建APP

2、根据APP中的Client ID 和Client Secret来获取token

把自己的Client ID 和Client Secret替换下面的<your-Client ID>和<your-Client Secret>
curl -v 'https://developer.api.autodesk.com/authentication/v1/authenticate' -X 'POST' -H 'Content-Type: application/x-www-form-urlencoded' -d 'client_id=<your-Client ID>&client_secret=<your-Client Secret>&grant_type=client_credentials&scope=data:read data:write bucket:create bucket:read'
token时效24小时
3、创建bucket
<your-bucketKey>自己随便取
curl -v 'https://developer.api.autodesk.com/oss/v2/buckets' -X 'POST' -H 'Content-Type: application/json' -H 'Authorization: Bearer <your-token>' -d '{"bucketKey":"<your-bucketKey>","policyKey":"persistent"}'
这里的policyKey如果是persistent就表示容器是永久的,如果是transient就表示容器是暂时的(时效24小时)

4、上传模型
通过cd 命令到达模型文件所在的目录下

curl -v 'https://developer.api.autodesk.com/oss/v2/buckets/lqbucket1211/objects/<fileName>' -X 'PUT' -H 'Authorization: Bearer <your-token>' -H 'Content-Type: application/octet-stream' -H 'Content-Length: <your-fileLength>' -T '<fileName>'
通过文件属性查看Content-Length,如下<your-fileLength>则是4861728


5、Convert the source URN into a Base64-Encoded URN
对于返回的urn进行64位编码,网址:http://www.freeformatter.com/base64-encoder.html

6、Translate the Source File into SVF Format
转换成svf格式
<your-Base64-Encoded URN>是上一步通过编码获得的字符串
curl -X 'POST' -H 'Authorization: Bearer <your-token>' -H 'Content-Type: application/json' -v 'https://developer.api.autodesk.com/modelderivative/v2/designdata/job' -d '{"input":{"urn":"<your-Base64-Encoded URN>"},"output": {"formats":[{"type":"svf","views": ["2d","3d"]}]}}'
上传成功后返回格式:

7、转换格式后就可以通过.html文件查看了
创建一个后缀名为.html的文件,将代码复制进去,代码地址:https://developer.autodesk.com/en/docs/viewer/v2/tutorials/basic-viewer/

代码改好后保存,用浏览器打开就完成了。

网友评论