hj-gis-sdk 1.0.0 → 1.0.2
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.
- package/README.md +50 -59
- package/dev-dist/animation.esm.js +152 -0
- package/dev-dist/animation.esm.js.map +1 -0
- package/dev-dist/animation.js +154 -0
- package/dev-dist/animation.js.map +1 -0
- package/dev-dist/building.esm.js +85 -0
- package/dev-dist/building.esm.js.map +1 -0
- package/dev-dist/building.js +87 -0
- package/dev-dist/building.js.map +1 -0
- package/dev-dist/common.esm.js +16159 -0
- package/dev-dist/common.esm.js.map +1 -0
- package/dev-dist/common.js +16163 -0
- package/dev-dist/common.js.map +1 -0
- package/dev-dist/fence.esm.js +100 -0
- package/dev-dist/fence.esm.js.map +1 -0
- package/dev-dist/fence.js +102 -0
- package/dev-dist/fence.js.map +1 -0
- package/dev-dist/ghost.esm.js +53 -0
- package/dev-dist/ghost.esm.js.map +1 -0
- package/dev-dist/ghost.js +55 -0
- package/dev-dist/ghost.js.map +1 -0
- package/dev-dist/heatmap.esm.js +103 -0
- package/dev-dist/heatmap.esm.js.map +1 -0
- package/dev-dist/heatmap.js +105 -0
- package/dev-dist/heatmap.js.map +1 -0
- package/dev-dist/index.esm.js +21 -0
- package/dev-dist/index.esm.js.map +1 -0
- package/dev-dist/index.esm2.js +4272 -0
- package/dev-dist/index.esm2.js.map +1 -0
- package/dev-dist/index.js +26 -0
- package/dev-dist/index.js.map +1 -0
- package/dev-dist/index2.js +4280 -0
- package/dev-dist/index2.js.map +1 -0
- package/dev-dist/keyframe.esm.js +95 -0
- package/dev-dist/keyframe.esm.js.map +1 -0
- package/dev-dist/keyframe.js +97 -0
- package/dev-dist/keyframe.js.map +1 -0
- package/dev-dist/measurement.esm.js +57 -0
- package/dev-dist/measurement.esm.js.map +1 -0
- package/dev-dist/measurement.js +59 -0
- package/dev-dist/measurement.js.map +1 -0
- package/dev-dist/scatter.esm.js +85 -0
- package/dev-dist/scatter.esm.js.map +1 -0
- package/dev-dist/scatter.js +87 -0
- package/dev-dist/scatter.js.map +1 -0
- package/dev-dist/src.esm.js +289 -0
- package/dev-dist/src.esm.js.map +1 -0
- package/dev-dist/src.js +291 -0
- package/dev-dist/src.js.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/animation/animate-clip.d.ts +39 -0
- package/dev-dist/types/hj-gis-sdk/addons/animation/animate-clip.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/animation/animation-action.d.ts +31 -0
- package/dev-dist/types/hj-gis-sdk/addons/animation/animation-action.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/animation/animation-mixer.d.ts +18 -0
- package/dev-dist/types/hj-gis-sdk/addons/animation/animation-mixer.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/animation/index.d.ts +5 -0
- package/dev-dist/types/hj-gis-sdk/addons/animation/index.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/camera.d.ts +59 -0
- package/dev-dist/types/hj-gis-sdk/addons/camera.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/clock.d.ts +40 -0
- package/dev-dist/types/hj-gis-sdk/addons/clock.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/commander/context.d.ts +24 -0
- package/dev-dist/types/hj-gis-sdk/addons/commander/context.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/commander/dispatcher.d.ts +43 -0
- package/dev-dist/types/hj-gis-sdk/addons/commander/dispatcher.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/commander/excutor/base.d.ts +22 -0
- package/dev-dist/types/hj-gis-sdk/addons/commander/excutor/base.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/loader/index.d.ts +6 -0
- package/dev-dist/types/hj-gis-sdk/addons/loader/index.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/loader/loader.d.ts +4 -0
- package/dev-dist/types/hj-gis-sdk/addons/loader/loader.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/node/base.d.ts +63 -0
- package/dev-dist/types/hj-gis-sdk/addons/node/base.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/node/ue-node.d.ts +82 -0
- package/dev-dist/types/hj-gis-sdk/addons/node/ue-node.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/proxy.d.ts +83 -0
- package/dev-dist/types/hj-gis-sdk/addons/proxy.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/base.d.ts +7 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/base.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/building.d.ts +36 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/building.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/daytime.d.ts +7 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/daytime.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/fence.d.ts +61 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/fence.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/ghost.d.ts +14 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/ghost.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/heat-map.d.ts +65 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/heat-map.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/index.d.ts +26 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/index.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/match-view.d.ts +7 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/match-view.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/measurement.d.ts +13 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/measurement.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/pick-cast.d.ts +26 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/pick-cast.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/scatter.d.ts +57 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/scatter.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/weather.d.ts +31 -0
- package/dev-dist/types/hj-gis-sdk/addons/tools/weather.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/transform.d.ts +91 -0
- package/dev-dist/types/hj-gis-sdk/addons/transform.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/addons/world.d.ts +76 -0
- package/dev-dist/types/hj-gis-sdk/addons/world.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/core/ue-rpc.d.ts +54 -0
- package/dev-dist/types/hj-gis-sdk/core/ue-rpc.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/index.d.ts +27 -0
- package/dev-dist/types/hj-gis-sdk/index.d.ts.map +1 -0
- package/dev-dist/types/hj-gis-sdk/utils.d.ts +16 -0
- package/dev-dist/types/hj-gis-sdk/utils.d.ts.map +1 -0
- package/dev-dist/types/src/animation.d.ts +2 -0
- package/dev-dist/types/src/animation.d.ts.map +1 -0
- package/dev-dist/types/src/building.d.ts +2 -0
- package/dev-dist/types/src/building.d.ts.map +1 -0
- package/dev-dist/types/src/common.d.ts +5 -0
- package/dev-dist/types/src/common.d.ts.map +1 -0
- package/dev-dist/types/src/fence.d.ts +2 -0
- package/dev-dist/types/src/fence.d.ts.map +1 -0
- package/dev-dist/types/src/ghost.d.ts +2 -0
- package/dev-dist/types/src/ghost.d.ts.map +1 -0
- package/dev-dist/types/src/heatmap.d.ts +2 -0
- package/dev-dist/types/src/heatmap.d.ts.map +1 -0
- package/dev-dist/types/src/index.d.ts +2 -0
- package/dev-dist/types/src/index.d.ts.map +1 -0
- package/dev-dist/types/src/keyframe.d.ts +2 -0
- package/dev-dist/types/src/keyframe.d.ts.map +1 -0
- package/dev-dist/types/src/measurement.d.ts +2 -0
- package/dev-dist/types/src/measurement.d.ts.map +1 -0
- package/dev-dist/types/src/scatter.d.ts +2 -0
- package/dev-dist/types/src/scatter.d.ts.map +1 -0
- package/dev-dist/types/src/weather.d.ts +2 -0
- package/dev-dist/types/src/weather.d.ts.map +1 -0
- package/dev-dist/weather.esm.js +68 -0
- package/dev-dist/weather.esm.js.map +1 -0
- package/dev-dist/weather.js +70 -0
- package/dev-dist/weather.js.map +1 -0
- package/dist/sdk.esm.js +19 -6
- package/dist/sdk.esm.js.map +1 -1
- package/dist/sdk.js +19 -6
- package/dist/sdk.js.map +1 -1
- package/dist/sdk.umd.js +1 -1
- package/dist/sdk.umd.js.map +1 -1
- package/dist/types/hj-gis-sdk/addons/tools/scatter.d.ts.map +1 -1
- package/dist/types/src/common.d.ts.map +1 -1
- package/hj-gis-sdk/addons/animation/animate-clip.ts +93 -0
- package/hj-gis-sdk/addons/animation/animation-action.ts +93 -0
- package/hj-gis-sdk/addons/animation/animation-mixer.ts +51 -0
- package/hj-gis-sdk/addons/animation/index.ts +17 -0
- package/hj-gis-sdk/addons/camera.ts +173 -0
- package/hj-gis-sdk/addons/clock.ts +85 -0
- package/hj-gis-sdk/addons/commander/context.ts +70 -0
- package/hj-gis-sdk/addons/commander/dispatcher.ts +68 -0
- package/hj-gis-sdk/addons/commander/excutor/base.ts +26 -0
- package/hj-gis-sdk/addons/loader/index.ts +7 -0
- package/hj-gis-sdk/addons/loader/loader.ts +3 -0
- package/hj-gis-sdk/addons/node/base.ts +131 -0
- package/hj-gis-sdk/addons/node/ue-node.ts +147 -0
- package/hj-gis-sdk/addons/proxy.ts +200 -0
- package/hj-gis-sdk/addons/tools/base.ts +11 -0
- package/hj-gis-sdk/addons/tools/building.ts +84 -0
- package/hj-gis-sdk/addons/tools/daytime.ts +14 -0
- package/hj-gis-sdk/addons/tools/fence.ts +105 -0
- package/hj-gis-sdk/addons/tools/ghost.ts +31 -0
- package/hj-gis-sdk/addons/tools/heat-map.ts +95 -0
- package/hj-gis-sdk/addons/tools/index.ts +25 -0
- package/hj-gis-sdk/addons/tools/match-view.ts +35 -0
- package/hj-gis-sdk/addons/tools/measurement.ts +25 -0
- package/hj-gis-sdk/addons/tools/pick-cast.ts +67 -0
- package/hj-gis-sdk/addons/tools/scatter.ts +230 -0
- package/hj-gis-sdk/addons/tools/weather.ts +40 -0
- package/hj-gis-sdk/addons/transform.ts +126 -0
- package/hj-gis-sdk/addons/world.ts +173 -0
- package/hj-gis-sdk/core/ue-rpc.ts +234 -0
- package/hj-gis-sdk/index.ts +26 -0
- package/hj-gis-sdk/utils.ts +52 -0
- package/index.html +48 -0
- package/package-lock.json +7368 -0
- package/package.json +17 -4
- package/rollup.config.dev.js +107 -0
- package/rollup.config.js +52 -0
- package/src/animation.ts +175 -0
- package/src/building.ts +114 -0
- package/src/common.ts +47 -0
- package/src/fence.ts +131 -0
- package/src/ghost.ts +70 -0
- package/src/heatmap.ts +125 -0
- package/src/index.ts +350 -0
- package/src/keyframe.ts +113 -0
- package/src/measurement.ts +80 -0
- package/src/scatter.ts +105 -0
- package/src/weather.ts +86 -0
- package/tsconfig.json +30 -0
- package/yarn.lock +3108 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 世界模块,提供世界场景的核心类
|
|
3
|
+
* 用于管理场景中的所有对象、天气和RPC通信
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import UERPCNode, { AssetType } from './node/ue-node'
|
|
7
|
+
import UERPC from '../core/ue-rpc'
|
|
8
|
+
import { PixelStreaming } from '@epicgames-ps/lib-pixelstreamingfrontend-ue5.5'
|
|
9
|
+
import { Transform } from './transform'
|
|
10
|
+
import Tools from './tools'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 世界类,整个场景的根容器
|
|
14
|
+
* 管理场景中的所有对象、天气系统和RPC通信
|
|
15
|
+
*/
|
|
16
|
+
class World {
|
|
17
|
+
/** 场景根节点 */
|
|
18
|
+
root: UERPCNode
|
|
19
|
+
/** RPC通信实例 */
|
|
20
|
+
private _rpc: UERPC
|
|
21
|
+
tools: {
|
|
22
|
+
ghost: InstanceType<typeof Tools.GhostTool>
|
|
23
|
+
weather: InstanceType<typeof Tools.WeatherTool>
|
|
24
|
+
matchView: InstanceType<typeof Tools.MatchViewTool>
|
|
25
|
+
pickCast: InstanceType<typeof Tools.PickCastTool>
|
|
26
|
+
scatter: InstanceType<typeof Tools.ScatterTool>
|
|
27
|
+
heatMap: InstanceType<typeof Tools.HeatMapTool>
|
|
28
|
+
fence: InstanceType<typeof Tools.FenceTool>
|
|
29
|
+
building: InstanceType<typeof Tools.BuildingTool>
|
|
30
|
+
measurement: InstanceType<typeof Tools.MeasurementTool>
|
|
31
|
+
daytime: InstanceType<typeof Tools.DaytimeTool>
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 构造函数
|
|
35
|
+
* @param pixelStream PixelStream实例,用于与远程渲染引擎通信
|
|
36
|
+
*/
|
|
37
|
+
constructor(pixelStream: PixelStreaming) {
|
|
38
|
+
this._rpc = new UERPC(pixelStream)
|
|
39
|
+
this.root = new UERPCNode(this._rpc)
|
|
40
|
+
this.root.world = this
|
|
41
|
+
this.tools = {
|
|
42
|
+
ghost: new Tools.GhostTool(this._rpc),
|
|
43
|
+
weather: new Tools.WeatherTool(this._rpc),
|
|
44
|
+
matchView: new Tools.MatchViewTool(this._rpc),
|
|
45
|
+
pickCast: new Tools.PickCastTool(this._rpc),
|
|
46
|
+
scatter: new Tools.ScatterTool(this._rpc),
|
|
47
|
+
heatMap: new Tools.HeatMapTool(this._rpc, this),
|
|
48
|
+
fence: new Tools.FenceTool(this._rpc),
|
|
49
|
+
building: new Tools.BuildingTool(this._rpc),
|
|
50
|
+
measurement: new Tools.MeasurementTool(this._rpc),
|
|
51
|
+
daytime: new Tools.DaytimeTool(this._rpc)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 获取RPC通信实例
|
|
57
|
+
*/
|
|
58
|
+
get rpc() {
|
|
59
|
+
return this._rpc
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 加载关卡
|
|
64
|
+
* @param params 加载关卡的参数
|
|
65
|
+
* @returns 加载成功后返回关卡节点
|
|
66
|
+
*/
|
|
67
|
+
async loadLevelByName(assetPath: string) {
|
|
68
|
+
let response = await this._rpc.loadLevelByName(assetPath)
|
|
69
|
+
// let response = await this._rpc.callModule('Mesh', 'Spawn', {
|
|
70
|
+
// AssetPath: assetPath,
|
|
71
|
+
// Transform: Transform.default().toRPCJSON()
|
|
72
|
+
// })
|
|
73
|
+
let handle = response.Handle || 'map'
|
|
74
|
+
let node = new UERPCNode(this._rpc, handle, { assetType: AssetType.Map })
|
|
75
|
+
node.data = { assetType: AssetType.Map }
|
|
76
|
+
this.root.add(node)
|
|
77
|
+
return node
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 生成含有骨骼动画的Mesh
|
|
82
|
+
*/
|
|
83
|
+
async spawnSkeletalMesh(params: {
|
|
84
|
+
assetPath: string
|
|
85
|
+
transform?: Transform
|
|
86
|
+
tag?: string | undefined
|
|
87
|
+
}) {
|
|
88
|
+
let _transform = params.transform || Transform.default()
|
|
89
|
+
let response = await this._rpc.callModule('Mesh', 'Spawn', {
|
|
90
|
+
Type: 'SkeletalMesh',
|
|
91
|
+
AssetPath: params.assetPath,
|
|
92
|
+
Transform: _transform.toRPCJSON(),
|
|
93
|
+
Tag: params.tag
|
|
94
|
+
})
|
|
95
|
+
let handle = response.Handle
|
|
96
|
+
let node = new UERPCNode(
|
|
97
|
+
this._rpc,
|
|
98
|
+
handle,
|
|
99
|
+
{
|
|
100
|
+
assetType: AssetType.SkeletalMesh
|
|
101
|
+
},
|
|
102
|
+
_transform
|
|
103
|
+
)
|
|
104
|
+
this.root.add(node)
|
|
105
|
+
return node
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 生成静态网格体演员
|
|
110
|
+
* @param params 生成静态网格体的参数
|
|
111
|
+
* @returns 生成成功后返回演员节点
|
|
112
|
+
*/
|
|
113
|
+
async spawnStaticMeshActor(params: {
|
|
114
|
+
assetPath: string
|
|
115
|
+
transform?: Transform
|
|
116
|
+
tag?: string | undefined
|
|
117
|
+
}) {
|
|
118
|
+
let _transform = params.transform || Transform.default()
|
|
119
|
+
let response = await this._rpc.callModule('Mesh', 'Spawn', {
|
|
120
|
+
Type: 'StaticMesh',
|
|
121
|
+
AssetPath: params.assetPath,
|
|
122
|
+
Transform: _transform.toRPCJSON(),
|
|
123
|
+
Tag: params.tag
|
|
124
|
+
})
|
|
125
|
+
let handle = response.Handle
|
|
126
|
+
let node = new UERPCNode(
|
|
127
|
+
this._rpc,
|
|
128
|
+
handle,
|
|
129
|
+
{
|
|
130
|
+
assetType: AssetType.StaticMesh
|
|
131
|
+
},
|
|
132
|
+
_transform
|
|
133
|
+
)
|
|
134
|
+
this.root.add(node)
|
|
135
|
+
return node
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 生成本地蓝图演员
|
|
140
|
+
* @param params 生成本地蓝图的参数
|
|
141
|
+
* @returns 生成成功后返回演员节点
|
|
142
|
+
*/
|
|
143
|
+
async spawnLocalBlueprintActor(params: {
|
|
144
|
+
assetPath: string
|
|
145
|
+
transform?: Transform
|
|
146
|
+
tag?: string | undefined
|
|
147
|
+
}) {
|
|
148
|
+
let _transform = params.transform || Transform.default()
|
|
149
|
+
let response = await this._rpc.callModule('Mesh', 'Spawn', {
|
|
150
|
+
Type: 'Blueprint',
|
|
151
|
+
AssetPath: params.assetPath,
|
|
152
|
+
Transform: _transform.toRPCJSON(),
|
|
153
|
+
Tag: params.tag
|
|
154
|
+
})
|
|
155
|
+
// let response = await this._rpc.spawnLocalBlueprintActor({
|
|
156
|
+
// AssetPath: params.assetPath,
|
|
157
|
+
// Transform: _transform.toRPCJSON(),
|
|
158
|
+
// Tag: params.tag
|
|
159
|
+
// })
|
|
160
|
+
let handle = response.Handle
|
|
161
|
+
let node = new UERPCNode(
|
|
162
|
+
this._rpc,
|
|
163
|
+
handle,
|
|
164
|
+
{
|
|
165
|
+
assetType: AssetType.Blueprint
|
|
166
|
+
},
|
|
167
|
+
_transform
|
|
168
|
+
)
|
|
169
|
+
this.root.add(node)
|
|
170
|
+
return node
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
export default World
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Logger,
|
|
3
|
+
PixelStreaming
|
|
4
|
+
} from '@epicgames-ps/lib-pixelstreamingfrontend-ue5.5'
|
|
5
|
+
|
|
6
|
+
export type RpcPayload = Record<string, any>
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* UERPC wraps RPC-style interactions over Pixel Streaming's DataChannel.
|
|
10
|
+
* It mirrors the Web/script.js behavior: sends {Type:'RPC_CALL', Command, ReqId, ...payload}
|
|
11
|
+
* and expects UE to reply with {Type:'RPC_RESPONSE', ReqId, Status, Data|Message} via EmitJSEvent.
|
|
12
|
+
*/
|
|
13
|
+
export class UERPC {
|
|
14
|
+
private stream: PixelStreaming
|
|
15
|
+
private responseEventName: string
|
|
16
|
+
private pendingRequests: Map<
|
|
17
|
+
string,
|
|
18
|
+
{ resolve: (data: any) => void; reject: (err: any) => void; timer: number }
|
|
19
|
+
>
|
|
20
|
+
timeoutMs: number
|
|
21
|
+
constructor(stream: PixelStreaming, responseEventName = 'handle_responses') {
|
|
22
|
+
this.stream = stream
|
|
23
|
+
this.responseEventName = responseEventName
|
|
24
|
+
this.pendingRequests = new Map()
|
|
25
|
+
this.timeoutMs = 30000
|
|
26
|
+
try {
|
|
27
|
+
this.stream.addResponseEventListener(
|
|
28
|
+
this.responseEventName,
|
|
29
|
+
this.handleResponse.bind(this)
|
|
30
|
+
)
|
|
31
|
+
} catch (e) {
|
|
32
|
+
// If the stream is not ready yet, user can call bind later.
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getStream() {
|
|
37
|
+
return this.stream
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Bind the response listener explicitly if constructor binding failed or the stream changed.
|
|
41
|
+
*/
|
|
42
|
+
bind(stream: PixelStreaming, responseEventName = this.responseEventName) {
|
|
43
|
+
this.stream = stream
|
|
44
|
+
this.responseEventName = responseEventName
|
|
45
|
+
this.stream.addResponseEventListener(
|
|
46
|
+
this.responseEventName,
|
|
47
|
+
this.handleResponse.bind(this)
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
emitCommand(playload: { Command: string; [key: string]: any }) {
|
|
52
|
+
this.stream.emitCommand(playload)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Generic RPC call. Resolves when UE replies with matching ReqId.
|
|
57
|
+
*/
|
|
58
|
+
call(
|
|
59
|
+
command: string,
|
|
60
|
+
payload: RpcPayload = {},
|
|
61
|
+
timeoutMs?: number
|
|
62
|
+
): Promise<any> {
|
|
63
|
+
const reqId = this.generateUUID()
|
|
64
|
+
const message = {
|
|
65
|
+
Type: 'RPC_CALL',
|
|
66
|
+
Command: command,
|
|
67
|
+
ReqId: reqId,
|
|
68
|
+
...payload
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
const timer = window.setTimeout(() => {
|
|
73
|
+
if (this.pendingRequests.has(reqId)) {
|
|
74
|
+
this.pendingRequests.delete(reqId)
|
|
75
|
+
reject(new Error(`UE RPC Timeout: ${command}`))
|
|
76
|
+
}
|
|
77
|
+
}, timeoutMs || this.timeoutMs)
|
|
78
|
+
|
|
79
|
+
this.pendingRequests.set(reqId, { resolve, reject, timer })
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
this.stream.emitUIInteraction(message)
|
|
83
|
+
} catch (e) {
|
|
84
|
+
window.clearTimeout(timer)
|
|
85
|
+
this.pendingRequests.delete(reqId)
|
|
86
|
+
reject(e)
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Handle UE responses. Accepts stringified or object payloads.
|
|
93
|
+
*/
|
|
94
|
+
handleResponse(raw: any) {
|
|
95
|
+
let json = raw
|
|
96
|
+
try {
|
|
97
|
+
if (typeof raw === 'string') {
|
|
98
|
+
json = JSON.parse(raw)
|
|
99
|
+
}
|
|
100
|
+
} catch {
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (!json || json.Type !== 'RPC_RESPONSE') return
|
|
105
|
+
const reqId = json.ReqId
|
|
106
|
+
if (!reqId) return
|
|
107
|
+
|
|
108
|
+
const pending = this.pendingRequests.get(reqId)
|
|
109
|
+
if (!pending) return
|
|
110
|
+
|
|
111
|
+
window.clearTimeout(pending.timer)
|
|
112
|
+
this.pendingRequests.delete(reqId)
|
|
113
|
+
|
|
114
|
+
const status = json.Status
|
|
115
|
+
if (status === 'success') {
|
|
116
|
+
pending.resolve(json.Data)
|
|
117
|
+
} else {
|
|
118
|
+
const msg = json.Message || 'Unknown UE Error'
|
|
119
|
+
pending.reject(new Error(msg))
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
callModule(
|
|
124
|
+
moduleName: string,
|
|
125
|
+
actionName: string,
|
|
126
|
+
params: RpcPayload = {},
|
|
127
|
+
timeoutMs = 30000
|
|
128
|
+
): Promise<any> {
|
|
129
|
+
const reqId = this.generateUUID()
|
|
130
|
+
const message = {
|
|
131
|
+
Type: 'RPC_CALL',
|
|
132
|
+
ReqId: reqId,
|
|
133
|
+
ModuleName: moduleName,
|
|
134
|
+
ActionName: actionName,
|
|
135
|
+
Params: params
|
|
136
|
+
}
|
|
137
|
+
Logger.Info(JSON.stringify(message))
|
|
138
|
+
return new Promise((resolve, reject) => {
|
|
139
|
+
const timer = window.setTimeout(() => {
|
|
140
|
+
if (this.pendingRequests.has(reqId)) {
|
|
141
|
+
this.pendingRequests.delete(reqId)
|
|
142
|
+
reject(new Error(`UE Call Timeout: ${moduleName}/${actionName}`))
|
|
143
|
+
}
|
|
144
|
+
}, timeoutMs || this.timeoutMs)
|
|
145
|
+
|
|
146
|
+
this.pendingRequests.set(reqId, { resolve, reject, timer })
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
this.stream.emitUIInteraction(message)
|
|
150
|
+
} catch (e) {
|
|
151
|
+
window.clearTimeout(timer)
|
|
152
|
+
this.pendingRequests.delete(reqId)
|
|
153
|
+
reject(e)
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// ---- Convenience helpers for Web-supported commands ----
|
|
159
|
+
|
|
160
|
+
// Level management
|
|
161
|
+
loadLevelByName(levelName: string) {
|
|
162
|
+
return this.call('LoadLevelByName', { LevelName: levelName })
|
|
163
|
+
}
|
|
164
|
+
unLoadMap(levelName: string) {
|
|
165
|
+
return this.call('UnLoadMap', { LevelName: levelName })
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Actor management
|
|
169
|
+
spawnStaticMeshActor(params: {
|
|
170
|
+
AssetPath: string
|
|
171
|
+
Transform?: any
|
|
172
|
+
Tag?: string
|
|
173
|
+
}) {
|
|
174
|
+
return this.call('SpawnStaticMeshActor', params)
|
|
175
|
+
}
|
|
176
|
+
// Blueprint management
|
|
177
|
+
spawnLocalBlueprintActor(params: {
|
|
178
|
+
AssetPath: string
|
|
179
|
+
Transform?: any
|
|
180
|
+
Tag?: string
|
|
181
|
+
}) {
|
|
182
|
+
return this.call('SpawnLocalBlueprintActor', params)
|
|
183
|
+
}
|
|
184
|
+
setActorTransformByHandle(handle: string, transform: any) {
|
|
185
|
+
return this.call('SetActorTransformByHandle', {
|
|
186
|
+
Handle: handle,
|
|
187
|
+
Transform: transform
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
destroyActorByHandle(handle: string) {
|
|
191
|
+
return this.call('DestroyActorByHandle', { Handle: handle })
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Picking
|
|
195
|
+
pickPointByScreen(
|
|
196
|
+
x: number,
|
|
197
|
+
y: number,
|
|
198
|
+
maxDistance = 10000000,
|
|
199
|
+
highlight = false
|
|
200
|
+
) {
|
|
201
|
+
return this.call('PickPointByScreen', {
|
|
202
|
+
Screen: {
|
|
203
|
+
X: x,
|
|
204
|
+
Y: y
|
|
205
|
+
},
|
|
206
|
+
MaxDistance: maxDistance,
|
|
207
|
+
Highlight: highlight
|
|
208
|
+
})
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Camera lens and transform
|
|
212
|
+
getCameraTransform() {
|
|
213
|
+
return this.call('GetCameraTransform', {})
|
|
214
|
+
}
|
|
215
|
+
setCameraTransform(transform: any) {
|
|
216
|
+
return this.call('SetCameraTransform', { Transform: transform })
|
|
217
|
+
}
|
|
218
|
+
setCameraResetTransform(transform: any) {
|
|
219
|
+
return this.call('SetCameraResetTransform', { Transform: transform })
|
|
220
|
+
}
|
|
221
|
+
resetCameraToSavedTransform() {
|
|
222
|
+
return this.call('ResetCameraToSavedTransform', {})
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
private generateUUID(): string {
|
|
226
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
227
|
+
const r = (Math.random() * 16) | 0
|
|
228
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8
|
|
229
|
+
return v.toString(16)
|
|
230
|
+
})
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export default UERPC
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { UERPC } from './core/ue-rpc'
|
|
2
|
+
import World from './addons/world'
|
|
3
|
+
import { Transform } from './addons/transform'
|
|
4
|
+
import { PerspectiveCamera } from './addons/camera'
|
|
5
|
+
import UERPCNode from './addons/node/ue-node'
|
|
6
|
+
import { Clock } from './addons/clock'
|
|
7
|
+
import { WeatherType } from './addons/tools/weather'
|
|
8
|
+
import { MeasurementType } from './addons/tools/measurement'
|
|
9
|
+
import * as Animation from './addons/animation'
|
|
10
|
+
const Core = {
|
|
11
|
+
UERPC
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const Addons = {
|
|
15
|
+
World,
|
|
16
|
+
Transform,
|
|
17
|
+
PerspectiveCamera,
|
|
18
|
+
UERPCNode,
|
|
19
|
+
WeatherType,
|
|
20
|
+
MeasurementType,
|
|
21
|
+
Animation: {
|
|
22
|
+
...Animation
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { Core, Addons }
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 防抖函数 - 延迟执行函数,直到停止调用一段时间后才执行
|
|
3
|
+
* @param func 要执行的函数
|
|
4
|
+
* @param wait 等待时间(毫秒)
|
|
5
|
+
* @param immediate 是否立即执行
|
|
6
|
+
* @returns 防抖处理后的函数
|
|
7
|
+
*/
|
|
8
|
+
export function debounce<T extends (...args: any[]) => any>(
|
|
9
|
+
func: T,
|
|
10
|
+
wait: number,
|
|
11
|
+
immediate: boolean = false
|
|
12
|
+
): (...args: Parameters<T>) => void {
|
|
13
|
+
let timeout: NodeJS.Timeout | null = null
|
|
14
|
+
|
|
15
|
+
return function (this: any, ...args: Parameters<T>) {
|
|
16
|
+
const context = this
|
|
17
|
+
|
|
18
|
+
const later = () => {
|
|
19
|
+
timeout = null
|
|
20
|
+
if (!immediate) func.apply(context, args)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const callNow = immediate && !timeout
|
|
24
|
+
if (timeout) clearTimeout(timeout)
|
|
25
|
+
timeout = setTimeout(later, wait)
|
|
26
|
+
|
|
27
|
+
if (callNow) func.apply(context, args)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 节流函数 - 限制函数在一定时间内只能执行一次
|
|
33
|
+
* @param func 要执行的函数
|
|
34
|
+
* @param limit 时间限制(毫秒)
|
|
35
|
+
* @returns 节流处理后的函数
|
|
36
|
+
*/
|
|
37
|
+
export function throttle<T extends (...args: any[]) => any>(
|
|
38
|
+
func: T,
|
|
39
|
+
limit: number
|
|
40
|
+
): (...args: Parameters<T>) => void {
|
|
41
|
+
let inThrottle: boolean = false
|
|
42
|
+
|
|
43
|
+
return function (this: any, ...args: Parameters<T>) {
|
|
44
|
+
const context = this
|
|
45
|
+
|
|
46
|
+
if (!inThrottle) {
|
|
47
|
+
func.apply(context, args)
|
|
48
|
+
inThrottle = true
|
|
49
|
+
setTimeout(() => (inThrottle = false), limit)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
package/index.html
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>GIS SDK 示例目录</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
font-family: Arial, sans-serif;
|
|
10
|
+
max-width: 800px;
|
|
11
|
+
margin: 0 auto;
|
|
12
|
+
padding: 20px;
|
|
13
|
+
}
|
|
14
|
+
h1 {
|
|
15
|
+
color: #333;
|
|
16
|
+
}
|
|
17
|
+
ul {
|
|
18
|
+
list-style-type: none;
|
|
19
|
+
padding: 0;
|
|
20
|
+
}
|
|
21
|
+
li {
|
|
22
|
+
margin: 10px 0;
|
|
23
|
+
}
|
|
24
|
+
a {
|
|
25
|
+
color: #0000ee;
|
|
26
|
+
text-decoration: underline;
|
|
27
|
+
}
|
|
28
|
+
a:hover {
|
|
29
|
+
color: #0000aa;
|
|
30
|
+
}
|
|
31
|
+
</style>
|
|
32
|
+
</head>
|
|
33
|
+
<body>
|
|
34
|
+
<h1>GIS SDK 示例目录</h1>
|
|
35
|
+
<ul>
|
|
36
|
+
<li><a href="./example/index.html">基础示例</a></li>
|
|
37
|
+
<li><a href="./example/fence.html">围栏示例</a></li>
|
|
38
|
+
<li><a href="./example/heatmap.html">热力图示例</a></li>
|
|
39
|
+
<li><a href="./example/scatter.html">散点图示例</a></li>
|
|
40
|
+
<li><a href="./example/building.html">建筑示例</a></li>
|
|
41
|
+
<li><a href="./example/weather.html">天气与时间示例</a></li>
|
|
42
|
+
<li><a href="./example/measurement.html">测量示例</a></li>
|
|
43
|
+
<li><a href="./example/ghost.html">虚化示例</a></li>
|
|
44
|
+
<li><a href="./example/animation.html">动画示例</a></li>
|
|
45
|
+
<li><a href="./example/keyframe-animation.html">关键帧动画示例</a></li>
|
|
46
|
+
</ul>
|
|
47
|
+
</body>
|
|
48
|
+
</html>
|