@soonspacejs/plugin-pathfinding 2.13.16 → 2.14.0
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 +7 -2
- package/dist/index.esm.js +99 -1
- package/dist/utils.d.ts +2 -2
- package/package.json +7 -7
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
|
|
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(
|
|
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:
|
|
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.
|
|
4
|
+
"version": "2.14.0",
|
|
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": "
|
|
16
|
+
"gitHead": "4c85e8b7b8ad24ccb9b42f3a1826bca377c42a6d",
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"@recast-navigation/core": "^0.
|
|
19
|
-
"@recast-navigation/generators": "^0.
|
|
20
|
-
"@recast-navigation/three": "^0.
|
|
21
|
-
"@recast-navigation/wasm": "^0.
|
|
22
|
-
"soonspacejs": "2.
|
|
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.0"
|
|
23
23
|
}
|
|
24
24
|
}
|