@soonspacejs/plugin-pathfinding 2.13.17 → 2.14.1

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/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Object3D } from 'three';
2
2
  import { NavMesh, Crowd, CrowdParams } from '@recast-navigation/core';
3
- import { SoloNavMeshGeneratorConfig } from '@recast-navigation/generators';
3
+ import { SoloNavMeshGeneratorConfig, TiledNavMeshGeneratorConfig } from '@recast-navigation/generators';
4
4
  import { DebugDrawer, CrowdHelper, CrowdHelperParams } from '@recast-navigation/three';
5
- import SoonSpace from 'soonspacejs';
5
+ import { default as SoonSpace } from 'soonspacejs';
6
6
  declare class PathfindingPlugin {
7
7
  readonly ssp: SoonSpace;
8
8
  navMesh: NavMesh | null;
@@ -11,7 +11,12 @@ declare class PathfindingPlugin {
11
11
  crowdHelper: CrowdHelper | null;
12
12
  constructor(ssp: SoonSpace);
13
13
  createSoloNavMesh(objects: Object3D[], config?: Partial<SoloNavMeshGeneratorConfig>): NavMesh | null;
14
+ createTiledNavMesh(objects: Object3D[], config?: Partial<TiledNavMeshGeneratorConfig>): NavMesh | null;
15
+ /**
16
+ * @deprecated use disposeNavMesh() instead
17
+ */
14
18
  disposeSoloNavMesh(): void;
19
+ disposeNavMesh(): void;
15
20
  _crowdUpdate: () => void;
16
21
  createCrowd(params: CrowdParams): Crowd | null;
17
22
  disposeCrowd(): void;
package/dist/index.esm.js CHANGED
@@ -1 +1,99 @@
1
- import{Matrix4 as e,Mesh as s,InstancedMesh as r,MeshStandardMaterial as t}from"three";import{Crowd as o}from"@recast-navigation/core";import{generateSoloNavMesh as i}from"@recast-navigation/generators";import{DebugDrawer as a,CrowdHelper as d}from"@recast-navigation/three";import h from"soonspacejs";import{StaticGeometryGenerator as n}from"three-mesh-bvh";function c(r){const t=r.name,o=r.geometry,i=r.material,a=r.count,d=[];for(let h=0;h<a;h++){const a=new e;r.getMatrixAt(h,a);const n=new s(o,i);n.name=`${t}_${h}`,d.push(n),a.premultiply(r.matrixWorld),n.matrix.copy(a),n.matrixWorld.copy(a),a.decompose(n.position,n.quaternion,n.scale)}return d}function p(e){var s;const t=[];e.forEach(e=>{e.traverse(e=>{"Mesh"===e.type&&(e instanceof r?t.push(...c(e)):t.push(e))})});const o=new n(t);o.applyWorldTransforms=!0,o.attributes=["position","index"];const i=o.generate();return{positions:i.attributes.position.array,indices:null===(s=i.index)||void 0===s?void 0:s.array}}const{warn:l}=h.utils;class w{constructor(e){this.ssp=e,this.navMesh=null,this.crowd=null,this.debugDrawer=null,this.crowdHelper=null,this._crowdUpdate=()=>{var e;this.crowd&&(this.crowd.update(this.ssp.viewport.state.delta),null===(e=this.crowdHelper)||void 0===e||e.update(),this.crowd.getActiveAgentCount()>0&&this.ssp.render())}}createSoloNavMesh(e,s={}){if(this.navMesh)return l("navmesh 已经存在,请先调用 disposeNavMesh()"),this.navMesh;const{positions:r,indices:t}=p(e),o=i(r,t,s);return o.success?(this.navMesh=o.navMesh,this.navMesh):null}disposeSoloNavMesh(){var e;null===(e=this.navMesh)||void 0===e||e.destroy(),this.navMesh=null}createCrowd(e){return this.crowd?(l("crowd 已经存在,请先调用 disposeCrowd()"),this.crowd):this.navMesh?(this.crowd=new o(this.navMesh,e),this.ssp.signals.beforeRender.add(this._crowdUpdate),this.crowd):(l("navmesh 不存在,请先调用 createSoloNavMesh()"),null)}disposeCrowd(){var e;null===(e=this.crowd)||void 0===e||e.destroy(),this.crowd=null,this.ssp.signals.beforeRender.remove(this._crowdUpdate)}createDebugDrawer(){return this.debugDrawer?(l("debug drawer 已经存在,请先调用 disposeDebugDrawer()"),this.debugDrawer):this.navMesh?(this.debugDrawer=new a,this.debugDrawer.drawNavMesh(this.navMesh,0),this.ssp.addObject(this.debugDrawer),this.debugDrawer):(l("navmesh 不存在,请先调用 createSoloNavMesh()"),null)}disposeDebugDrawer(){this.debugDrawer&&(this.debugDrawer.dispose(),this.ssp.removeObject(this.debugDrawer),this.debugDrawer=null)}createCrowdHelper(e={agentMaterial:new t({color:65280})}){return this.crowdHelper?(l("crowd helper 已经存在,请先调用 disposeCrowdHelper()"),this.crowdHelper):this.crowd?(this.crowdHelper=new d(this.crowd,e),this.ssp.addObject(this.crowdHelper),this.crowdHelper):(l("crowd 不存在,请先调用 createCrowd()"),null)}disposeCrowdHelper(){this.crowdHelper&&(this.crowdHelper.agentMeshes.forEach(e=>{e.geometry.dispose(),e.material.dispose()}),this.ssp.removeObject(this.crowdHelper))}dispose(){this.disposeSoloNavMesh(),this.disposeCrowd(),this.disposeDebugDrawer(),this.disposeCrowdHelper()}}export{c as deInstancingMesh,w as default,p as getVertices};
1
+ import { Matrix4 as u, Mesh as p, InstancedMesh as l, MeshStandardMaterial as w } from "three";
2
+ import { Crowd as m } from "@recast-navigation/core";
3
+ import { generateSoloNavMesh as v, generateTiledNavMesh as f } from "@recast-navigation/generators";
4
+ import { DebugDrawer as g, CrowdHelper as M } from "@recast-navigation/three";
5
+ import b from "soonspacejs";
6
+ import { StaticGeometryGenerator as D } from "three-mesh-bvh";
7
+ function H(o) {
8
+ const e = o.name, i = o.geometry, n = o.material, a = o.count, r = [];
9
+ for (let h = 0; h < a; h++) {
10
+ const s = new u();
11
+ o.getMatrixAt(h, s);
12
+ const d = new p(i, n);
13
+ d.name = `${e}_${h}`, r.push(d), s.premultiply(o.matrixWorld), d.matrix.copy(s), d.matrixWorld.copy(s), s.decompose(d.position, d.quaternion, d.scale);
14
+ }
15
+ return r;
16
+ }
17
+ function c(o) {
18
+ const e = [];
19
+ o.forEach((h) => {
20
+ h.traverse((s) => {
21
+ s instanceof p && s.geometry.index && (s instanceof l ? e.push(...H(s)) : e.push(s));
22
+ });
23
+ });
24
+ const i = new D(e);
25
+ i.applyWorldTransforms = !0, i.attributes = ["position", "index"];
26
+ const n = i.generate(), a = n.attributes.position.array, r = n.index && n.index.array;
27
+ return { positions: a, indices: r };
28
+ }
29
+ const { warn: t } = b.utils;
30
+ class G {
31
+ constructor(e) {
32
+ this.ssp = e;
33
+ }
34
+ navMesh = null;
35
+ crowd = null;
36
+ debugDrawer = null;
37
+ crowdHelper = null;
38
+ // solo navmesh
39
+ createSoloNavMesh(e, i = {}) {
40
+ if (this.navMesh)
41
+ return t("navmesh 已经存在,请先调用 disposeNavMesh()"), this.navMesh;
42
+ const { positions: n, indices: a } = c(e);
43
+ if (!a)
44
+ return t("生成 navmesh 失败,几何体不包含索引信息"), null;
45
+ const r = v(n, a, i);
46
+ return r.success ? (this.navMesh = r.navMesh, this.navMesh) : null;
47
+ }
48
+ // create tiled navmesh
49
+ createTiledNavMesh(e, i = {}) {
50
+ if (this.navMesh)
51
+ return t("navmesh 已经存在,请先调用 disposeNavMesh()"), this.navMesh;
52
+ const { positions: n, indices: a } = c(e);
53
+ if (!a)
54
+ return t("生成 navmesh 失败,几何体不包含索引信息"), null;
55
+ const r = f(n, a, i);
56
+ return r.success ? (this.navMesh = r.navMesh, this.navMesh) : null;
57
+ }
58
+ /**
59
+ * @deprecated use disposeNavMesh() instead
60
+ */
61
+ disposeSoloNavMesh() {
62
+ this.disposeNavMesh();
63
+ }
64
+ disposeNavMesh() {
65
+ this.navMesh?.destroy(), this.navMesh = null;
66
+ }
67
+ // crowd
68
+ _crowdUpdate = () => {
69
+ this.crowd && (this.crowd.update(this.ssp.viewport.state.delta), this.crowdHelper?.update(), this.crowd.getActiveAgentCount() > 0 && this.ssp.render());
70
+ };
71
+ createCrowd(e) {
72
+ return this.crowd ? (t("crowd 已经存在,请先调用 disposeCrowd()"), this.crowd) : this.navMesh ? (this.crowd = new m(this.navMesh, e), this.ssp.signals.beforeRender.add(this._crowdUpdate), this.crowd) : (t("navmesh 不存在,请先调用 createSoloNavMesh()"), null);
73
+ }
74
+ disposeCrowd() {
75
+ this.crowd?.destroy(), this.crowd = null, this.ssp.signals.beforeRender.remove(this._crowdUpdate);
76
+ }
77
+ createDebugDrawer() {
78
+ return this.debugDrawer ? (t("debug drawer 已经存在,请先调用 disposeDebugDrawer()"), this.debugDrawer) : this.navMesh ? (this.debugDrawer = new g(), this.debugDrawer.drawNavMesh(this.navMesh, 0), this.ssp.addObject(this.debugDrawer), this.debugDrawer) : (t("navmesh 不存在,请先调用 createSoloNavMesh()"), null);
79
+ }
80
+ disposeDebugDrawer() {
81
+ this.debugDrawer && (this.debugDrawer.dispose(), this.ssp.removeObject(this.debugDrawer), this.debugDrawer = null);
82
+ }
83
+ createCrowdHelper(e = { agentMaterial: new w({ color: 65280 }) }) {
84
+ return this.crowdHelper ? (t("crowd helper 已经存在,请先调用 disposeCrowdHelper()"), this.crowdHelper) : this.crowd ? (this.crowdHelper = new M(this.crowd, e), this.ssp.addObject(this.crowdHelper), this.crowdHelper) : (t("crowd 不存在,请先调用 createCrowd()"), null);
85
+ }
86
+ disposeCrowdHelper() {
87
+ this.crowdHelper && (this.crowdHelper.agentMeshes.forEach((e) => {
88
+ e.geometry.dispose(), e.material.dispose();
89
+ }), this.ssp.removeObject(this.crowdHelper));
90
+ }
91
+ dispose() {
92
+ this.disposeNavMesh(), this.disposeCrowd(), this.disposeDebugDrawer(), this.disposeCrowdHelper();
93
+ }
94
+ }
95
+ export {
96
+ H as deInstancingMesh,
97
+ G as default,
98
+ c as getVertices
99
+ };
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { InstancedMesh, Mesh, Object3D } from 'three';
2
- export declare function deInstancingMesh(insMesh: InstancedMesh): Mesh<import("three").BufferGeometry<import("three").NormalBufferAttributes, import("three").BufferGeometryEventMap>, import("three").Material | import("three").Material[], import("three").Object3DEventMap>[];
2
+ export declare function deInstancingMesh(insMesh: InstancedMesh): Mesh<import('three').BufferGeometry<import('three').NormalBufferAttributes, import('three').BufferGeometryEventMap>, import('three').Material | import('three').Material[], import('three').Object3DEventMap>[];
3
3
  export declare function getVertices(objects: Object3D[]): {
4
4
  positions: Float32Array<ArrayBufferLike>;
5
- indices: Uint32Array<ArrayBufferLike>;
5
+ indices: import('three').TypedArray | null;
6
6
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@soonspacejs/plugin-pathfinding",
3
3
  "pluginName": "PathfindingPlugin",
4
- "version": "2.13.17",
4
+ "version": "2.14.1",
5
5
  "description": "Pathfinding plugin for SoonSpace.js",
6
6
  "main": "dist/index.esm.js",
7
7
  "module": "dist/index.esm.js",
@@ -13,12 +13,12 @@
13
13
  ],
14
14
  "author": "xuek,jiangqi",
15
15
  "license": "UNLICENSED",
16
- "gitHead": "8afa5fda9a0ef2c080060e7d8e71a8bf168fd4d2",
16
+ "gitHead": "27d5e0bcd79ff71c8e2943a8420c39624ae6f8e6",
17
17
  "peerDependencies": {
18
- "@recast-navigation/core": "^0.38.0",
19
- "@recast-navigation/generators": "^0.38.0",
20
- "@recast-navigation/three": "^0.38.0",
21
- "@recast-navigation/wasm": "^0.38.0",
22
- "soonspacejs": "2.13.17"
18
+ "@recast-navigation/core": "^0.42.0",
19
+ "@recast-navigation/generators": "^0.42.0",
20
+ "@recast-navigation/three": "^0.42.0",
21
+ "@recast-navigation/wasm": "^0.42.0",
22
+ "soonspacejs": "2.14.1"
23
23
  }
24
24
  }