@yangyongtao/gaea 1.1.25 → 1.1.26

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/GaeaMethods.js +66 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yangyongtao/gaea",
3
- "version": "1.1.25",
3
+ "version": "1.1.26",
4
4
  "description": "Gaea 3D visualization component library - Vue 3 components based on Godot WASM engine. Includes WMTS layer loading, camera view control, Vite plugin auto-injection, etc.",
5
5
  "type": "module",
6
6
  "main": "src/index.cjs",
@@ -290,7 +290,8 @@ export class GaeaApp {
290
290
  this._screenIconList = [];
291
291
  this._hiddenCategories = new Set();
292
292
  this._tilesetMap = {}; // 已加载的 3D Tiles 引用,key 为 tileset 名称
293
- this._flattenTool = null; // 压平绘制工具
293
+ this._flattenTool = null; // 压平工具
294
+ this._flattenPolygon = null; // 压平多边形元素
294
295
  this._secIsClickArr = [];
295
296
  this._secScreenIconKeyValue = {};
296
297
  this._groundPolygonElements = [];
@@ -1210,24 +1211,41 @@ export class GaeaApp {
1210
1211
  // ---- 倾斜摄影压平 ----
1211
1212
 
1212
1213
  /**
1213
- * 进入倾斜摄影压平绘制模式
1214
- * 调用后可以在 3D Tiles 上绘制多边形,多边形区域内将被压平
1215
- * @param {string} [tilesetName] - 目标 3D Tiles 名称(不传则默认使用第一个已加载的 tileset)
1214
+ * 传入多边形坐标直接对倾斜摄影执行压平
1215
+ * @param {Object} opts
1216
+ * @param {string} [opts.tilesetName] - 目标 3D Tiles 名称(不传则默认使用第一个已加载的 tileset)
1217
+ * @param {Array<{lat: number, lng: number}>} opts.polygon - 多边形顶点坐标数组,会自动闭合
1218
+ * @param {number} opts.height - 压平目标高度
1219
+ * @example
1220
+ * app.flatten3DTiles({
1221
+ * tilesetName: '沿浦海塘倾斜',
1222
+ * polygon: [
1223
+ * { lat: 27.2205, lng: 120.456 },
1224
+ * { lat: 27.2210, lng: 120.458 },
1225
+ * { lat: 27.2195, lng: 120.458 },
1226
+ * { lat: 27.2190, lng: 120.456 }
1227
+ * ],
1228
+ * height: 30
1229
+ * })
1216
1230
  */
1217
- startFlattenDraw = (tilesetName) => {
1231
+ flatten3DTiles = ({ tilesetName, polygon, height }) => {
1232
+ if (!polygon || polygon.length < 3) {
1233
+ console.warn('[GaeaApp] flatten3DTiles: polygon 至少需要3个顶点')
1234
+ return
1235
+ }
1236
+
1218
1237
  // 查找目标 tileset
1219
1238
  let tileset = null
1220
1239
  if (tilesetName) {
1221
1240
  tileset = this._tilesetMap[tilesetName]
1222
1241
  if (!tileset) {
1223
- console.warn(`[GaeaApp] startFlattenDraw: 未找到 tileset "${tilesetName}"`)
1242
+ console.warn(`[GaeaApp] flatten3DTiles: 未找到 tileset "${tilesetName}"`)
1224
1243
  return
1225
1244
  }
1226
1245
  } else {
1227
- // 取第一个有名字的 tileset
1228
1246
  const keys = Object.keys(this._tilesetMap)
1229
1247
  if (keys.length === 0) {
1230
- console.warn('[GaeaApp] startFlattenDraw: 没有已加载的 3D Tiles')
1248
+ console.warn('[GaeaApp] flatten3DTiles: 没有已加载的 3D Tiles')
1231
1249
  return
1232
1250
  }
1233
1251
  tileset = this._tilesetMap[keys[0]]
@@ -1235,38 +1253,60 @@ export class GaeaApp {
1235
1253
 
1236
1254
  tileset.EnabledFlatten = true
1237
1255
 
1256
+ // 创建/更新压平工具
1238
1257
  if (!this._flattenTool) {
1239
1258
  this._flattenTool = new Gaea.FlattenTool()
1240
1259
  this._flattenTool.NeedIntersectWithMesh = false
1241
1260
  this._flattenTool.IsMovingIntersectWithMesh = false
1242
1261
  }
1262
+ this._flattenTool.Gdtvalue = height
1243
1263
 
1244
- Gaea.World.Instance.SetCurrentTool(this._flattenTool)
1245
- Gaea.World.Instance.CurrentTool = this._flattenTool
1246
- console.log('[GaeaApp] 压平绘制模式已启动:', tileset.Name || tileset.TilesetUrl)
1247
- };
1264
+ // 构建多边形坐标(经纬度 → Vector3,闭合多边形)
1265
+ const positions = polygon.map(p => new Gaea.Vector3(p.lat, p.lng, height))
1266
+ positions.push(new Gaea.Vector3(polygon[0].lat, polygon[0].lng, height))
1248
1267
 
1249
- /**
1250
- * 设置压平高度
1251
- * @param {number} height - 压平目标高度
1252
- */
1253
- setFlattenHeight = (height) => {
1254
- if (!this._flattenTool) {
1255
- console.warn('[GaeaApp] setFlattenHeight: 尚未启用压平绘制模式,请先调用 startFlattenDraw()')
1256
- return
1268
+ // 创建几何体
1269
+ const geometry = Gaea.Geometry.Create1(Gaea.GeometryType.Polygon, positions)
1270
+ const polygonElement = new Gaea.PolygonGeometryElement()
1271
+ polygonElement.Shape = geometry
1272
+ polygonElement.EnablePick = false
1273
+ polygonElement.EnableEdit = false
1274
+ polygonElement.NeedIntersectWithMesh = true
1275
+ polygonElement.EnableVirtualPoint = true
1276
+ Gaea.SimpleFillSymbol.ConvertBy(polygonElement.Symbol).HasOutLine = true
1277
+
1278
+ // 移除旧的压平多边形
1279
+ if (this._flattenPolygon) {
1280
+ try { Gaea.World.Instance.RenderableObjectList.RemoveChild(this._flattenPolygon) } catch (e) { /* ignore */ }
1257
1281
  }
1258
- this._flattenTool.Gdtvalue = height
1259
- console.log('[GaeaApp] 压平高度已设置为:', height)
1282
+
1283
+ Gaea.World.Instance.RenderableObjectList.AddLast(polygonElement)
1284
+ this._flattenPolygon = polygonElement
1285
+ console.log('[GaeaApp] 压平已执行:', tileset.Name || tileset.TilesetUrl, `高度: ${height}`, `顶点数: ${polygon.length}`)
1260
1286
  };
1261
1287
 
1262
1288
  /**
1263
- * 结束压平绘制模式(保留已绘制的压平效果)
1289
+ * 清除倾斜摄影压平效果
1290
+ * @param {string} [tilesetName] - 目标 tileset 名称(不传则清除压平多边形并重置工具)
1264
1291
  */
1265
- stopFlattenDraw = () => {
1292
+ clearFlatten = (tilesetName) => {
1293
+ // 移除压平多边形
1294
+ if (this._flattenPolygon) {
1295
+ try { Gaea.World.Instance.RenderableObjectList.RemoveChild(this._flattenPolygon) } catch (e) { /* ignore */ }
1296
+ this._flattenPolygon = null
1297
+ }
1298
+
1299
+ // 重置压平工具状态
1300
+ this._flattenTool = null
1266
1301
  Gaea.World.Instance.SetCurrentTool(null)
1267
1302
  Gaea.World.Instance.CurrentTool = null
1268
- this._flattenTool = null
1269
- console.log('[GaeaApp] 压平绘制模式已退出')
1303
+
1304
+ // 可选:禁用特定 tileset 的压平
1305
+ if (tilesetName && this._tilesetMap[tilesetName]) {
1306
+ this._tilesetMap[tilesetName].EnabledFlatten = false
1307
+ }
1308
+
1309
+ console.log('[GaeaApp] 压平效果已清除')
1270
1310
  };
1271
1311
 
1272
1312
  /**