@recast-navigation/playcanvas 0.38.0 → 0.40.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright © 2022 Isaac Mason
3
+ Copyright © 2025 Isaac Mason
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -92,18 +92,6 @@ this.entity.add(navMeshHelper);
92
92
  navMeshHelper.update();
93
93
  ```
94
94
 
95
- #### `OffMeshConnectionsHelper`
96
-
97
- ```ts
98
- import { OffMeshConnectionsHelper } from '@recast-navigation/playcanvas';
99
-
100
- const offMeshConnectionsHelper = new OffMeshConnectionsHelper(
101
- offMeshConnections
102
- );
103
-
104
- this.entity.add(offMeshConnectionsHelper);
105
- ```
106
-
107
95
  #### `TileCacheHelper`
108
96
 
109
97
  Visualises obstacles in a `TileCache`.
@@ -1,4 +1,3 @@
1
1
  export * from './crowd-helper';
2
2
  export * from './nav-mesh-helper';
3
- export * from './off-mesh-connections-helper';
4
3
  export * from './tile-cache-helper';
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { DebugDrawerUtils } from '@recast-navigation/core';
2
- import { Entity, StandardMaterial, Color, BLEND_NORMAL, MeshInstance, VertexFormat, SEMANTIC_POSITION, TYPE_FLOAT32, SEMANTIC_COLOR, VertexBuffer, BUFFER_STATIC, Mesh, PRIMITIVE_POINTS, PRIMITIVE_LINES, PRIMITIVE_TRIANGLES, Vec3, GraphNode, CylinderGeometry, calculateNormals, createMesh, RENDERSTYLE_WIREFRAME, VertexIterator, INDEXFORMAT_UINT32 } from 'playcanvas';
1
+ import { DebugDrawerUtils, getNavMeshPositionsAndIndices } from '@recast-navigation/core';
2
+ import { Entity, StandardMaterial, Color, BLEND_NORMAL, MeshInstance, VertexFormat, SEMANTIC_POSITION, TYPE_FLOAT32, SEMANTIC_COLOR, VertexBuffer, BUFFER_STATIC, Mesh, PRIMITIVE_POINTS, PRIMITIVE_LINES, PRIMITIVE_TRIANGLES, Vec3, GraphNode, CylinderGeometry, calculateNormals, RENDERSTYLE_WIREFRAME, VertexIterator, INDEXFORMAT_UINT32 } from 'playcanvas';
3
3
  import { mergePositionsAndIndices, generateSoloNavMesh, generateTiledNavMesh, generateTileCache } from '@recast-navigation/generators';
4
4
 
5
5
  /**
@@ -179,7 +179,7 @@ class DebugDrawer extends Entity {
179
179
  positions.push(x, y, z);
180
180
  colors.push(r, g, b, a);
181
181
  }
182
- const mesh = createLineMesh$1(graphicsDevice, positions, colors);
182
+ const mesh = createLineMesh(graphicsDevice, positions, colors);
183
183
  const meshInstance = new MeshInstance(mesh, this.lineMaterial);
184
184
  const entity = new Entity();
185
185
  entity.addComponent('render', {
@@ -269,7 +269,7 @@ function createPointMesh(graphicsDevice, positions, colors) {
269
269
  /**
270
270
  * Creates a line mesh.
271
271
  */
272
- function createLineMesh$1(graphicsDevice, positions, colors) {
272
+ function createLineMesh(graphicsDevice, positions, colors) {
273
273
  const vertexFormat = new VertexFormat(graphicsDevice, [{
274
274
  semantic: SEMANTIC_POSITION,
275
275
  components: 3,
@@ -452,7 +452,7 @@ class NavMeshHelper extends Entity {
452
452
  * @private
453
453
  */
454
454
  updateMesh(graphicsDevice) {
455
- const [positions, indices] = this.navMesh.getDebugNavMesh();
455
+ const [positions, indices] = getNavMeshPositionsAndIndices(this.navMesh);
456
456
  const normals = calculateNormals(positions, indices);
457
457
  // Create the mesh
458
458
  this.mesh = new Mesh(graphicsDevice);
@@ -475,163 +475,6 @@ class NavMeshHelper extends Entity {
475
475
  }
476
476
  }
477
477
 
478
- class OffMeshConnectionsHelper extends Entity {
479
- constructor(offMeshConnections, params) {
480
- super();
481
- this.offMeshConnections = offMeshConnections;
482
- // Initialize materials
483
- if (params?.entryCircleMaterial) {
484
- this.entryCircleMaterial = params.entryCircleMaterial;
485
- } else {
486
- const material = new StandardMaterial();
487
- material.diffuse = new Color(0, 1, 0); // Green
488
- material.useLighting = false;
489
- material.update();
490
- this.entryCircleMaterial = material;
491
- }
492
- if (params?.exitCircleMaterial) {
493
- this.exitCircleMaterial = params.exitCircleMaterial;
494
- } else {
495
- const material = new StandardMaterial();
496
- material.diffuse = new Color(0, 0, 1); // Blue
497
- material.useLighting = false;
498
- material.update();
499
- this.exitCircleMaterial = material;
500
- }
501
- if (params?.lineMaterial) {
502
- this.lineMaterial = params.lineMaterial;
503
- } else {
504
- const material = new StandardMaterial();
505
- material.diffuse = new Color(1, 0, 0); // Red
506
- material.useLighting = false;
507
- material.update();
508
- this.lineMaterial = material;
509
- }
510
- this.updateHelper();
511
- }
512
- /**
513
- * Updates the visual representation of the off-mesh connections.
514
- */
515
- updateHelper() {
516
- // Remove all child entities
517
- while (this.children.length > 0) {
518
- this.children[0].destroy();
519
- }
520
- const graphicsDevice = this.app.graphicsDevice;
521
- for (const offMeshConnection of this.offMeshConnections) {
522
- // Create circle mesh at start position
523
- const circleMesh = createCircleMesh(graphicsDevice, offMeshConnection.radius, 16);
524
- const circleEntity = new Entity();
525
- circleEntity.addComponent('render', {
526
- meshInstances: [new MeshInstance(circleMesh, this.entryCircleMaterial)]
527
- });
528
- circleEntity.setPosition(offMeshConnection.startPosition);
529
- circleEntity.setLocalEulerAngles(-90, 0, 0); // Rotate to lie flat on XZ plane
530
- this.addChild(circleEntity);
531
- // Create circle mesh at end position
532
- const endCircleEntity = new Entity();
533
- endCircleEntity.addComponent('render', {
534
- meshInstances: [new MeshInstance(circleMesh, offMeshConnection.bidirectional ? this.entryCircleMaterial : this.exitCircleMaterial)]
535
- });
536
- endCircleEntity.setPosition(offMeshConnection.endPosition);
537
- endCircleEntity.setLocalEulerAngles(-90, 0, 0); // Rotate to lie flat on XZ plane
538
- this.addChild(endCircleEntity);
539
- // Create curve between points
540
- const start = offMeshConnection.startPosition.clone();
541
- const end = offMeshConnection.endPosition.clone();
542
- const middle = new Vec3().add2(start, end).mulScalar(0.5);
543
- middle.y *= 1.2; // Elevate the middle point for a curve effect
544
- // Generate points along a quadratic Bezier curve
545
- const curvePoints = generateBezierCurve([start, middle, end], 50);
546
- // Create line mesh
547
- const lineMesh = createLineMesh(graphicsDevice, curvePoints);
548
- const lineEntity = new Entity();
549
- lineEntity.addComponent('render', {
550
- meshInstances: [new MeshInstance(lineMesh, this.lineMaterial)]
551
- });
552
- this.addChild(lineEntity);
553
- }
554
- }
555
- }
556
- /**
557
- * Creates a circle mesh.
558
- * @param {GraphicsDevice} graphicsDevice - The graphics device.
559
- * @param {number} radius - Radius of the circle.
560
- * @param {number} segments - Number of segments.
561
- * @returns {Mesh} - The circle mesh.
562
- */
563
- function createCircleMesh(graphicsDevice, radius, segments) {
564
- const positions = [];
565
- const indices = [];
566
- // Create circle vertices
567
- for (let i = 0; i <= segments; i++) {
568
- const theta = i / segments * Math.PI * 2;
569
- const x = radius * Math.cos(theta);
570
- const z = radius * Math.sin(theta);
571
- positions.push(x, 0, z);
572
- }
573
- // Center point
574
- positions.push(0, 0, 0);
575
- const centerIndex = positions.length / 3 - 1;
576
- // Create indices
577
- for (let i = 0; i < segments; i++) {
578
- indices.push(i, (i + 1) % segments, centerIndex);
579
- }
580
- return createMesh(graphicsDevice, positions, {
581
- indices: indices
582
- });
583
- }
584
- /**
585
- * Generates points along a quadratic Bezier curve.
586
- * @param {Vec3[]} points - Control points.
587
- * @param {number} numPoints - Number of points to generate.
588
- * @returns {Vec3[]} - Points along the curve.
589
- */
590
- function generateBezierCurve(points, numPoints) {
591
- const curvePoints = [];
592
- for (let i = 0; i <= numPoints; i++) {
593
- const t = i / numPoints;
594
- const point = bezierQuadratic(points[0], points[1], points[2], t);
595
- curvePoints.push(point);
596
- }
597
- return curvePoints;
598
- }
599
- /**
600
- * Computes a point on a quadratic Bezier curve.
601
- * @param {Vec3} p0 - Start point.
602
- * @param {Vec3} p1 - Control point.
603
- * @param {Vec3} p2 - End point.
604
- * @param {number} t - Parameter between 0 and 1.
605
- * @returns {Vec3} - Point on the curve.
606
- */
607
- function bezierQuadratic(p0, p1, p2, t) {
608
- const oneMinusT = 1 - t;
609
- const x = oneMinusT * oneMinusT * p0.x + 2 * oneMinusT * t * p1.x + t * t * p2.x;
610
- const y = oneMinusT * oneMinusT * p0.y + 2 * oneMinusT * t * p1.y + t * t * p2.y;
611
- const z = oneMinusT * oneMinusT * p0.z + 2 * oneMinusT * t * p1.z + t * t * p2.z;
612
- return new Vec3(x, y, z);
613
- }
614
- /**
615
- * Creates a line mesh from an array of points.
616
- * @param {GraphicsDevice} graphicsDevice - The graphics device.
617
- * @param {Vec3[]} points - Points of the line.
618
- * @returns {Mesh} - The line mesh.
619
- */
620
- function createLineMesh(graphicsDevice, points) {
621
- const positions = [];
622
- const indices = [];
623
- for (let i = 0; i < points.length; i++) {
624
- positions.push(points[i].x, points[i].y, points[i].z);
625
- }
626
- for (let i = 0; i < points.length - 1; i++) {
627
- indices.push(i, i + 1);
628
- }
629
- return createMesh(graphicsDevice, positions, {
630
- indices: indices,
631
- primitiveType: PRIMITIVE_LINES
632
- });
633
- }
634
-
635
478
  /**
636
479
  * Represents a helper class to visualize tile cache obstacles in PlayCanvas.
637
480
  */
@@ -774,4 +617,4 @@ const threeToTileCache = (meshes, navMeshGeneratorConfig = {}, keepIntermediates
774
617
  return generateTileCache(positions, indices, navMeshGeneratorConfig, keepIntermediates);
775
618
  };
776
619
 
777
- export { CrowdHelper, DebugDrawer, NavMeshHelper, OffMeshConnectionsHelper, TileCacheHelper, getPositionsAndIndices, pcToSoloNavMesh, pcToTiledNavMesh, threeToTileCache };
620
+ export { CrowdHelper, DebugDrawer, NavMeshHelper, TileCacheHelper, getPositionsAndIndices, pcToSoloNavMesh, pcToTiledNavMesh, threeToTileCache };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@recast-navigation/playcanvas",
3
3
  "description": "Utilities for using recast-navigation with PlayCanvas",
4
- "version": "0.38.0",
4
+ "version": "0.40.0",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/isaac-mason/recast-navigation-js",
7
7
  "bugs": {
@@ -22,8 +22,8 @@
22
22
  "lint": "eslint src"
23
23
  },
24
24
  "dependencies": {
25
- "@recast-navigation/core": "0.38.0",
26
- "@recast-navigation/generators": "0.38.0"
25
+ "@recast-navigation/core": "0.40.0",
26
+ "@recast-navigation/generators": "0.40.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@babel/core": "^7.24.5",
@@ -1,29 +0,0 @@
1
- import { Entity, Material, Vec3 } from 'playcanvas';
2
- /**
3
- * Parameters for creating OffMeshConnectionsHelper.
4
- */
5
- export type OffMeshConnectionsHelperParams = {
6
- entryCircleMaterial?: Material;
7
- exitCircleMaterial?: Material;
8
- lineMaterial?: Material;
9
- };
10
- /**
11
- * Represents an off-mesh connection between two points.
12
- */
13
- export type OffMeshConnectionParams = {
14
- startPosition: Vec3;
15
- endPosition: Vec3;
16
- radius: number;
17
- bidirectional: boolean;
18
- };
19
- export declare class OffMeshConnectionsHelper extends Entity {
20
- offMeshConnections: OffMeshConnectionParams[];
21
- entryCircleMaterial: Material;
22
- exitCircleMaterial: Material;
23
- lineMaterial: Material;
24
- constructor(offMeshConnections: OffMeshConnectionParams[], params?: OffMeshConnectionsHelperParams);
25
- /**
26
- * Updates the visual representation of the off-mesh connections.
27
- */
28
- updateHelper(): void;
29
- }