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.
Files changed (194) hide show
  1. package/README.md +50 -59
  2. package/dev-dist/animation.esm.js +152 -0
  3. package/dev-dist/animation.esm.js.map +1 -0
  4. package/dev-dist/animation.js +154 -0
  5. package/dev-dist/animation.js.map +1 -0
  6. package/dev-dist/building.esm.js +85 -0
  7. package/dev-dist/building.esm.js.map +1 -0
  8. package/dev-dist/building.js +87 -0
  9. package/dev-dist/building.js.map +1 -0
  10. package/dev-dist/common.esm.js +16159 -0
  11. package/dev-dist/common.esm.js.map +1 -0
  12. package/dev-dist/common.js +16163 -0
  13. package/dev-dist/common.js.map +1 -0
  14. package/dev-dist/fence.esm.js +100 -0
  15. package/dev-dist/fence.esm.js.map +1 -0
  16. package/dev-dist/fence.js +102 -0
  17. package/dev-dist/fence.js.map +1 -0
  18. package/dev-dist/ghost.esm.js +53 -0
  19. package/dev-dist/ghost.esm.js.map +1 -0
  20. package/dev-dist/ghost.js +55 -0
  21. package/dev-dist/ghost.js.map +1 -0
  22. package/dev-dist/heatmap.esm.js +103 -0
  23. package/dev-dist/heatmap.esm.js.map +1 -0
  24. package/dev-dist/heatmap.js +105 -0
  25. package/dev-dist/heatmap.js.map +1 -0
  26. package/dev-dist/index.esm.js +21 -0
  27. package/dev-dist/index.esm.js.map +1 -0
  28. package/dev-dist/index.esm2.js +4272 -0
  29. package/dev-dist/index.esm2.js.map +1 -0
  30. package/dev-dist/index.js +26 -0
  31. package/dev-dist/index.js.map +1 -0
  32. package/dev-dist/index2.js +4280 -0
  33. package/dev-dist/index2.js.map +1 -0
  34. package/dev-dist/keyframe.esm.js +95 -0
  35. package/dev-dist/keyframe.esm.js.map +1 -0
  36. package/dev-dist/keyframe.js +97 -0
  37. package/dev-dist/keyframe.js.map +1 -0
  38. package/dev-dist/measurement.esm.js +57 -0
  39. package/dev-dist/measurement.esm.js.map +1 -0
  40. package/dev-dist/measurement.js +59 -0
  41. package/dev-dist/measurement.js.map +1 -0
  42. package/dev-dist/scatter.esm.js +85 -0
  43. package/dev-dist/scatter.esm.js.map +1 -0
  44. package/dev-dist/scatter.js +87 -0
  45. package/dev-dist/scatter.js.map +1 -0
  46. package/dev-dist/src.esm.js +289 -0
  47. package/dev-dist/src.esm.js.map +1 -0
  48. package/dev-dist/src.js +291 -0
  49. package/dev-dist/src.js.map +1 -0
  50. package/dev-dist/types/hj-gis-sdk/addons/animation/animate-clip.d.ts +39 -0
  51. package/dev-dist/types/hj-gis-sdk/addons/animation/animate-clip.d.ts.map +1 -0
  52. package/dev-dist/types/hj-gis-sdk/addons/animation/animation-action.d.ts +31 -0
  53. package/dev-dist/types/hj-gis-sdk/addons/animation/animation-action.d.ts.map +1 -0
  54. package/dev-dist/types/hj-gis-sdk/addons/animation/animation-mixer.d.ts +18 -0
  55. package/dev-dist/types/hj-gis-sdk/addons/animation/animation-mixer.d.ts.map +1 -0
  56. package/dev-dist/types/hj-gis-sdk/addons/animation/index.d.ts +5 -0
  57. package/dev-dist/types/hj-gis-sdk/addons/animation/index.d.ts.map +1 -0
  58. package/dev-dist/types/hj-gis-sdk/addons/camera.d.ts +59 -0
  59. package/dev-dist/types/hj-gis-sdk/addons/camera.d.ts.map +1 -0
  60. package/dev-dist/types/hj-gis-sdk/addons/clock.d.ts +40 -0
  61. package/dev-dist/types/hj-gis-sdk/addons/clock.d.ts.map +1 -0
  62. package/dev-dist/types/hj-gis-sdk/addons/commander/context.d.ts +24 -0
  63. package/dev-dist/types/hj-gis-sdk/addons/commander/context.d.ts.map +1 -0
  64. package/dev-dist/types/hj-gis-sdk/addons/commander/dispatcher.d.ts +43 -0
  65. package/dev-dist/types/hj-gis-sdk/addons/commander/dispatcher.d.ts.map +1 -0
  66. package/dev-dist/types/hj-gis-sdk/addons/commander/excutor/base.d.ts +22 -0
  67. package/dev-dist/types/hj-gis-sdk/addons/commander/excutor/base.d.ts.map +1 -0
  68. package/dev-dist/types/hj-gis-sdk/addons/loader/index.d.ts +6 -0
  69. package/dev-dist/types/hj-gis-sdk/addons/loader/index.d.ts.map +1 -0
  70. package/dev-dist/types/hj-gis-sdk/addons/loader/loader.d.ts +4 -0
  71. package/dev-dist/types/hj-gis-sdk/addons/loader/loader.d.ts.map +1 -0
  72. package/dev-dist/types/hj-gis-sdk/addons/node/base.d.ts +63 -0
  73. package/dev-dist/types/hj-gis-sdk/addons/node/base.d.ts.map +1 -0
  74. package/dev-dist/types/hj-gis-sdk/addons/node/ue-node.d.ts +82 -0
  75. package/dev-dist/types/hj-gis-sdk/addons/node/ue-node.d.ts.map +1 -0
  76. package/dev-dist/types/hj-gis-sdk/addons/proxy.d.ts +83 -0
  77. package/dev-dist/types/hj-gis-sdk/addons/proxy.d.ts.map +1 -0
  78. package/dev-dist/types/hj-gis-sdk/addons/tools/base.d.ts +7 -0
  79. package/dev-dist/types/hj-gis-sdk/addons/tools/base.d.ts.map +1 -0
  80. package/dev-dist/types/hj-gis-sdk/addons/tools/building.d.ts +36 -0
  81. package/dev-dist/types/hj-gis-sdk/addons/tools/building.d.ts.map +1 -0
  82. package/dev-dist/types/hj-gis-sdk/addons/tools/daytime.d.ts +7 -0
  83. package/dev-dist/types/hj-gis-sdk/addons/tools/daytime.d.ts.map +1 -0
  84. package/dev-dist/types/hj-gis-sdk/addons/tools/fence.d.ts +61 -0
  85. package/dev-dist/types/hj-gis-sdk/addons/tools/fence.d.ts.map +1 -0
  86. package/dev-dist/types/hj-gis-sdk/addons/tools/ghost.d.ts +14 -0
  87. package/dev-dist/types/hj-gis-sdk/addons/tools/ghost.d.ts.map +1 -0
  88. package/dev-dist/types/hj-gis-sdk/addons/tools/heat-map.d.ts +65 -0
  89. package/dev-dist/types/hj-gis-sdk/addons/tools/heat-map.d.ts.map +1 -0
  90. package/dev-dist/types/hj-gis-sdk/addons/tools/index.d.ts +26 -0
  91. package/dev-dist/types/hj-gis-sdk/addons/tools/index.d.ts.map +1 -0
  92. package/dev-dist/types/hj-gis-sdk/addons/tools/match-view.d.ts +7 -0
  93. package/dev-dist/types/hj-gis-sdk/addons/tools/match-view.d.ts.map +1 -0
  94. package/dev-dist/types/hj-gis-sdk/addons/tools/measurement.d.ts +13 -0
  95. package/dev-dist/types/hj-gis-sdk/addons/tools/measurement.d.ts.map +1 -0
  96. package/dev-dist/types/hj-gis-sdk/addons/tools/pick-cast.d.ts +26 -0
  97. package/dev-dist/types/hj-gis-sdk/addons/tools/pick-cast.d.ts.map +1 -0
  98. package/dev-dist/types/hj-gis-sdk/addons/tools/scatter.d.ts +57 -0
  99. package/dev-dist/types/hj-gis-sdk/addons/tools/scatter.d.ts.map +1 -0
  100. package/dev-dist/types/hj-gis-sdk/addons/tools/weather.d.ts +31 -0
  101. package/dev-dist/types/hj-gis-sdk/addons/tools/weather.d.ts.map +1 -0
  102. package/dev-dist/types/hj-gis-sdk/addons/transform.d.ts +91 -0
  103. package/dev-dist/types/hj-gis-sdk/addons/transform.d.ts.map +1 -0
  104. package/dev-dist/types/hj-gis-sdk/addons/world.d.ts +76 -0
  105. package/dev-dist/types/hj-gis-sdk/addons/world.d.ts.map +1 -0
  106. package/dev-dist/types/hj-gis-sdk/core/ue-rpc.d.ts +54 -0
  107. package/dev-dist/types/hj-gis-sdk/core/ue-rpc.d.ts.map +1 -0
  108. package/dev-dist/types/hj-gis-sdk/index.d.ts +27 -0
  109. package/dev-dist/types/hj-gis-sdk/index.d.ts.map +1 -0
  110. package/dev-dist/types/hj-gis-sdk/utils.d.ts +16 -0
  111. package/dev-dist/types/hj-gis-sdk/utils.d.ts.map +1 -0
  112. package/dev-dist/types/src/animation.d.ts +2 -0
  113. package/dev-dist/types/src/animation.d.ts.map +1 -0
  114. package/dev-dist/types/src/building.d.ts +2 -0
  115. package/dev-dist/types/src/building.d.ts.map +1 -0
  116. package/dev-dist/types/src/common.d.ts +5 -0
  117. package/dev-dist/types/src/common.d.ts.map +1 -0
  118. package/dev-dist/types/src/fence.d.ts +2 -0
  119. package/dev-dist/types/src/fence.d.ts.map +1 -0
  120. package/dev-dist/types/src/ghost.d.ts +2 -0
  121. package/dev-dist/types/src/ghost.d.ts.map +1 -0
  122. package/dev-dist/types/src/heatmap.d.ts +2 -0
  123. package/dev-dist/types/src/heatmap.d.ts.map +1 -0
  124. package/dev-dist/types/src/index.d.ts +2 -0
  125. package/dev-dist/types/src/index.d.ts.map +1 -0
  126. package/dev-dist/types/src/keyframe.d.ts +2 -0
  127. package/dev-dist/types/src/keyframe.d.ts.map +1 -0
  128. package/dev-dist/types/src/measurement.d.ts +2 -0
  129. package/dev-dist/types/src/measurement.d.ts.map +1 -0
  130. package/dev-dist/types/src/scatter.d.ts +2 -0
  131. package/dev-dist/types/src/scatter.d.ts.map +1 -0
  132. package/dev-dist/types/src/weather.d.ts +2 -0
  133. package/dev-dist/types/src/weather.d.ts.map +1 -0
  134. package/dev-dist/weather.esm.js +68 -0
  135. package/dev-dist/weather.esm.js.map +1 -0
  136. package/dev-dist/weather.js +70 -0
  137. package/dev-dist/weather.js.map +1 -0
  138. package/dist/sdk.esm.js +19 -6
  139. package/dist/sdk.esm.js.map +1 -1
  140. package/dist/sdk.js +19 -6
  141. package/dist/sdk.js.map +1 -1
  142. package/dist/sdk.umd.js +1 -1
  143. package/dist/sdk.umd.js.map +1 -1
  144. package/dist/types/hj-gis-sdk/addons/tools/scatter.d.ts.map +1 -1
  145. package/dist/types/src/common.d.ts.map +1 -1
  146. package/hj-gis-sdk/addons/animation/animate-clip.ts +93 -0
  147. package/hj-gis-sdk/addons/animation/animation-action.ts +93 -0
  148. package/hj-gis-sdk/addons/animation/animation-mixer.ts +51 -0
  149. package/hj-gis-sdk/addons/animation/index.ts +17 -0
  150. package/hj-gis-sdk/addons/camera.ts +173 -0
  151. package/hj-gis-sdk/addons/clock.ts +85 -0
  152. package/hj-gis-sdk/addons/commander/context.ts +70 -0
  153. package/hj-gis-sdk/addons/commander/dispatcher.ts +68 -0
  154. package/hj-gis-sdk/addons/commander/excutor/base.ts +26 -0
  155. package/hj-gis-sdk/addons/loader/index.ts +7 -0
  156. package/hj-gis-sdk/addons/loader/loader.ts +3 -0
  157. package/hj-gis-sdk/addons/node/base.ts +131 -0
  158. package/hj-gis-sdk/addons/node/ue-node.ts +147 -0
  159. package/hj-gis-sdk/addons/proxy.ts +200 -0
  160. package/hj-gis-sdk/addons/tools/base.ts +11 -0
  161. package/hj-gis-sdk/addons/tools/building.ts +84 -0
  162. package/hj-gis-sdk/addons/tools/daytime.ts +14 -0
  163. package/hj-gis-sdk/addons/tools/fence.ts +105 -0
  164. package/hj-gis-sdk/addons/tools/ghost.ts +31 -0
  165. package/hj-gis-sdk/addons/tools/heat-map.ts +95 -0
  166. package/hj-gis-sdk/addons/tools/index.ts +25 -0
  167. package/hj-gis-sdk/addons/tools/match-view.ts +35 -0
  168. package/hj-gis-sdk/addons/tools/measurement.ts +25 -0
  169. package/hj-gis-sdk/addons/tools/pick-cast.ts +67 -0
  170. package/hj-gis-sdk/addons/tools/scatter.ts +230 -0
  171. package/hj-gis-sdk/addons/tools/weather.ts +40 -0
  172. package/hj-gis-sdk/addons/transform.ts +126 -0
  173. package/hj-gis-sdk/addons/world.ts +173 -0
  174. package/hj-gis-sdk/core/ue-rpc.ts +234 -0
  175. package/hj-gis-sdk/index.ts +26 -0
  176. package/hj-gis-sdk/utils.ts +52 -0
  177. package/index.html +48 -0
  178. package/package-lock.json +7368 -0
  179. package/package.json +17 -4
  180. package/rollup.config.dev.js +107 -0
  181. package/rollup.config.js +52 -0
  182. package/src/animation.ts +175 -0
  183. package/src/building.ts +114 -0
  184. package/src/common.ts +47 -0
  185. package/src/fence.ts +131 -0
  186. package/src/ghost.ts +70 -0
  187. package/src/heatmap.ts +125 -0
  188. package/src/index.ts +350 -0
  189. package/src/keyframe.ts +113 -0
  190. package/src/measurement.ts +80 -0
  191. package/src/scatter.ts +105 -0
  192. package/src/weather.ts +86 -0
  193. package/tsconfig.json +30 -0
  194. 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>