Skip to content

Commit 50a21bd

Browse files
Merge pull request #56 from VirtualStarry/master
为小程序示例添加ar功能
2 parents a946755 + 88902e1 commit 50a21bd

File tree

313 files changed

+9322
-3073
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

313 files changed

+9322
-3073
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
## 使用
99

1010
```
11-
cd demo
12-
npm i
13-
cd miniprogram
14-
npm i
11+
npm run init
1512
```
1613
完成上述步骤后,使用微信开发者工具,点击【工具-构建npm】
1714

cloudfunctions/ARDemo/config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"permissions": {
3+
"openapi": [
4+
]
5+
}
6+
}

cloudfunctions/ARDemo/index.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// 云函数入口文件
2+
const cloud = require('wx-server-sdk')
3+
const wxgService = require('@tencent/wx-server-sdk-wxg-service')
4+
const svrkitUtils = require('./svrkit-utils.js')
5+
6+
cloud.registerService(wxgService)
7+
cloud.init()
8+
9+
// 云函数入口函数
10+
exports.main = async (event, context) => {
11+
const wxContext = cloud.getWXContext()
12+
const bizuin = wxContext.APPUIN
13+
console.log(bizuin)
14+
console.log(event)
15+
switch(event.type){
16+
case "GenerateARModel":
17+
return await cloud.callWXSvrkit({
18+
pbInstance: svrkitUtils.generate({
19+
serviceName: "Mmbizwxaintpar",
20+
funcName: "GenerateARModel",
21+
data:{
22+
bizuin: bizuin,
23+
name: event.name,
24+
url: event.url,
25+
algoType: event.algoType
26+
},
27+
})
28+
});
29+
case "GetARModelList":
30+
return await cloud.callWXSvrkit({
31+
pbInstance: svrkitUtils.generate({
32+
serviceName: "Mmbizwxaintpar",
33+
funcName: "GetARModelList",
34+
data:{
35+
bizuin: bizuin,
36+
modelStatus: event.modelStatus,
37+
algoType: event.algoType
38+
},
39+
})
40+
});
41+
case "GetARModel":
42+
return await cloud.callWXSvrkit({
43+
pbInstance: svrkitUtils.generate({
44+
serviceName: "Mmbizwxaintpar",
45+
funcName: "GetARModel",
46+
data:{
47+
bizuin: bizuin,
48+
cosid: event.cosid,
49+
modelType: event.modelType,
50+
needData: event.needData,
51+
useIntranet: event.useIntranet,
52+
expireTime: event.expireTime
53+
},
54+
})
55+
});
56+
}
57+
58+
}

cloudfunctions/ARDemo/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "ARDemo",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"svrkit": "svrkit-utils --config ./svrkit.config.js --output ./svrkit-utils.js"
9+
},
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"@tencent/wx-server-sdk-wxg-service": "^0.7.0",
14+
"wx-server-sdk": "^2.6.3"
15+
},
16+
"devDependencies": {
17+
"@tencent/cloud-functions-tools": "^1.5.1"
18+
}
19+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
enum enARModelStatus
2+
{
3+
ARModel_Status_Default = 0;
4+
ARModel_Status_Init = 1;
5+
ARModel_Status_Sparse_Finished = 2;
6+
ARModel_Status_3d_Finished = 3;
7+
ARModel_Status_Object_Finished = 4;
8+
ARModel_Status_Marker_Finished = 5;
9+
}
10+
11+
enum enARAlgorithmType
12+
{
13+
Algorithm_Type_3D_Object = 1;
14+
Algorithm_Type_3D_Marker = 2;
15+
}
16+
17+
enum enARModelType
18+
{
19+
ARModel_Type_Sparse = 1;
20+
ARModel_Type_3D = 2;
21+
ARModel_Type_Marker = 3;
22+
}
23+
24+
message ModelCos
25+
{
26+
message ModelCosId
27+
{
28+
optional enARModelType model_type = 1;
29+
optional string model_cosid = 2;
30+
}
31+
repeated ModelCosId model_list = 1;
32+
}
33+
34+
message ARModel
35+
{
36+
//option(mmbizintpkv.KvTableID) = 493;
37+
option(mmbizintpkv.KvTableTestID) = 916;
38+
optional string cosid = 1; // 原始文件的cosid
39+
optional uint32 bizuin = 2;
40+
optional string name = 3; // 原始文件的名称
41+
optional uint32 upload_time = 4;
42+
optional enARModelStatus model_status = 5;
43+
optional enARAlgorithmType algo_type = 6;
44+
optional ModelCos model_cos = 7;
45+
}
46+
47+
48+
message GenerateARModelReq
49+
{
50+
optional uint32 bizuin = 1;
51+
optional string name = 2;
52+
optional bytes buffer = 3;
53+
optional string url = 4;
54+
optional enARAlgorithmType algo_type = 5;
55+
}
56+
57+
message GenerateARModelResp
58+
{
59+
optional string url = 1;
60+
optional string host = 2;
61+
optional string cosid = 3;
62+
}
63+
64+
message GetARModelListReq
65+
{
66+
optional uint32 bizuin = 1;
67+
optional uint32 model_status = 2; // enARModelStatus
68+
optional uint32 start_time = 3;
69+
optional uint32 end_time = 4;
70+
optional uint32 offset = 5;
71+
optional uint32 limit = 6;
72+
optional uint32 algo_type = 7; // enARAlgorithmType
73+
}
74+
75+
message GetARModelListResp
76+
{
77+
repeated ARModel model_list = 1;
78+
}
79+
80+
81+
message ARModelData
82+
{
83+
optional bytes mesh_model = 1; // 文本(点面信息)
84+
optional bytes texture_model = 2; // 图像png
85+
}
86+
87+
message GetARModelReq
88+
{
89+
optional uint32 bizuin = 1;
90+
optional string cosid = 2;
91+
optional uint32 model_type = 3; // 1:稀疏点云 2:3d模型
92+
optional uint32 need_data = 4[default=1]; // 0:不需要数据 1:需要数据
93+
optional uint32 use_intranet = 5[default=0]; // 当need_data为0时生效 0:生成外网链接 1:内网链接
94+
optional uint32 expire_time = 6; // url过期时间,默认5分钟,单位为秒
95+
}
96+
97+
message GetARModelResp
98+
{
99+
optional ARModelData model_data = 1;
100+
optional string url = 2;
101+
optional string host = 3;
102+
}

cloudfunctions/ARDemo/svrkit-utils.js

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
2+
const config = require('./svrkit.config.js')
3+
const proto = require('./svrkit-utils.static.js')
4+
const protoJSON = require('./svrkit-utils.static.json')
5+
6+
function generate(options) {
7+
if (!options) {
8+
throw new Error('options must be provided')
9+
}
10+
11+
const { serviceName, funcName, data } = options
12+
13+
const serviceConfig = config.find(c => c.serviceName === serviceName)
14+
if (!serviceConfig) {
15+
throw new Error('service not found')
16+
}
17+
18+
if (!serviceConfig.functions[funcName]) {
19+
throw new Error('function not found')
20+
}
21+
22+
const reqProtoName = serviceConfig.functions[funcName].req
23+
const reqProto = proto[reqProtoName]
24+
25+
if (!reqProto) {
26+
throw new Error('request proto not found')
27+
}
28+
29+
const resProtoName = serviceConfig.functions[funcName].res
30+
const resProto = resProtoName && proto[resProtoName]
31+
32+
const reqProtoVerifyErr = reqProto.verify(data)
33+
if (reqProtoVerifyErr) {
34+
throw new Error(`verify proto data error: ${reqProtoVerifyErr}`)
35+
}
36+
37+
const reqProtoJSON = protoJSON.nested[reqProtoName]
38+
39+
if (reqProtoJSON && reqProtoJSON.fields) {
40+
if (Object.prototype.toString.call(data).slice(8, -1) === 'Object') {
41+
for (const key in data) {
42+
if (!reqProtoJSON.fields[key]) {
43+
throw new Error(`'${key}' doesn't exist in '${reqProtoName}' proto, valid keys are ${Object.keys(reqProtoJSON.fields)}`)
44+
}
45+
}
46+
} else {
47+
throw new Error('data must be object')
48+
}
49+
}
50+
51+
return {
52+
data: {
53+
serviceName,
54+
funcName,
55+
magic: serviceConfig.magic,
56+
cmdid: serviceConfig.functions[funcName].cmdid,
57+
existResp: Boolean(resProto),
58+
reqBodyBuffer: reqProto.encode(data).finish(),
59+
},
60+
reqProto,
61+
resProto,
62+
decode: buf => resProto && resProto.decode(buf)
63+
}
64+
}
65+
66+
function generateV2(options) {
67+
if (!options) {
68+
throw new Error('options must be provided')
69+
}
70+
71+
const { apiName, data } = options
72+
73+
const apiConfig = config.find(c => c.apiName === apiName)
74+
75+
const reqProtoName = apiConfig.req
76+
const reqProto = proto[reqProtoName]
77+
78+
if (!reqProto) {
79+
throw new Error('request proto not found')
80+
}
81+
82+
const resProtoName = apiConfig.res
83+
const resProto = proto[resProtoName]
84+
85+
const reqProtoVerifyErr = reqProto.verify(data)
86+
if (reqProtoVerifyErr) {
87+
throw new Error(`verify proto data error: ${reqProtoVerifyErr}`)
88+
}
89+
90+
const reqProtoJSON = protoJSON.nested[reqProtoName]
91+
92+
if (reqProtoJSON && reqProtoJSON.fields) {
93+
if (Object.prototype.toString.call(data).slice(8, -1) === 'Object') {
94+
for (const key in data) {
95+
if (!reqProtoJSON.fields[key]) {
96+
throw new Error(`'${key}' doesn't exist in '${reqProtoName}' proto, valid keys are ${Object.keys(reqProtoJSON.fields)}`)
97+
}
98+
}
99+
} else {
100+
throw new Error('data must be object')
101+
}
102+
}
103+
104+
return {
105+
data: {
106+
apiName,
107+
reqBodyBuffer: reqProto.encode(data).finish(),
108+
},
109+
reqProto,
110+
resProto,
111+
decode: buf => resProto && resProto.decode(buf)
112+
}
113+
}
114+
115+
module.exports = {
116+
generate,
117+
generateV2,
118+
}
119+

0 commit comments

Comments
 (0)