Browse Source

Recast.js To Ref Updates

Recast.js plugin and crowd to ref performance optimizations
Mackey Kinard 5 năm trước cách đây
mục cha
commit
71707d2cb0

+ 1 - 0
dist/preview release/what's new.md

@@ -5,6 +5,7 @@
 ## Updates
 
 ### General
+- Recast.js plugin nav mesh and crowd agent to ref performance optimizations. ([MackeyK24](https://github.com/MackeyK24))
 
 ### Engine
 

+ 49 - 0
src/Navigation/INavigationEngine.ts

@@ -34,6 +34,13 @@ export interface INavigationEnginePlugin {
     getClosestPoint(position: Vector3): Vector3;
 
     /**
+     * Get a navigation mesh constrained position, closest to the parameter position
+     * @param position world position
+     * @param result output the closest point to position constrained by the navigation mesh
+     */
+    getClosestPointToRef(position: Vector3, result: Vector3): void;
+
+    /**
      * Get a navigation mesh constrained position, within a particular radius
      * @param position world position
      * @param maxRadius the maximum distance to the constrained world position
@@ -42,6 +49,14 @@ export interface INavigationEnginePlugin {
     getRandomPointAround(position: Vector3, maxRadius: number): Vector3;
 
     /**
+     * Get a navigation mesh constrained position, within a particular radius
+     * @param position world position
+     * @param maxRadius the maximum distance to the constrained world position
+     * @param result output the closest point to position constrained by the navigation mesh
+     */
+    getRandomPointAroundToRef(position: Vector3, maxRadius: number, result: Vector3): void;
+
+    /**
      * Compute the final position from a segment made of destination-position
      * @param position world position
      * @param destination world position
@@ -50,6 +65,14 @@ export interface INavigationEnginePlugin {
     moveAlong(position: Vector3, destination: Vector3): Vector3;
 
     /**
+     * Compute the final position from a segment made of destination-position
+     * @param position world position
+     * @param destination world position
+     * @param result output the resulting point along the navmesh
+     */
+    moveAlongToRef(position: Vector3, destination: Vector3, result: Vector3): void;
+
+    /**
      * Compute a navigation path from start to end. Returns an empty array if no path can be computed
      * @param start world position
      * @param end world position
@@ -87,6 +110,12 @@ export interface INavigationEnginePlugin {
     getDefaultQueryExtent(): Vector3;
 
     /**
+     * Get the Bounding box extent result specified by setDefaultQueryExtent
+     * @param result output the box extent values
+     */
+    getDefaultQueryExtentToRef(result: Vector3): void;
+
+    /**
      * Release all resources
      */
     dispose(): void;
@@ -114,6 +143,13 @@ export interface ICrowd {
     getAgentPosition(index: number): Vector3;
 
     /**
+     * Gets the agent position result in world space
+     * @param index agent index returned by addAgent
+     * @param result output world space position
+     */
+    getAgentPositionToRef(index: number, result: Vector3): void;
+
+    /**
      * Gets the agent velocity in world space
      * @param index agent index returned by addAgent
      * @returns world space velocity
@@ -121,6 +157,13 @@ export interface ICrowd {
     getAgentVelocity(index: number): Vector3;
 
     /**
+     * Gets the agent velocity result in world space
+     * @param index agent index returned by addAgent
+     * @param result output world space velocity
+     */
+    getAgentVelocityToRef(index: number, result: Vector3): void;
+
+    /**
      * remove a particular agent previously created
      * @param index agent index returned by addAgent
      */
@@ -174,6 +217,12 @@ export interface ICrowd {
     getDefaultQueryExtent(): Vector3;
 
     /**
+     * Get the Bounding box extent result specified by setDefaultQueryExtent
+     * @param result output the box extent values
+     */
+    getDefaultQueryExtentToRef(result: Vector3): void;
+
+    /**
      * Release all resources
      */
     dispose() : void;

+ 76 - 0
src/Navigation/Plugins/recastJSPlugin.ts

@@ -162,6 +162,17 @@ export class RecastJSPlugin implements INavigationEnginePlugin {
     }
 
     /**
+     * Get a navigation mesh constrained position, closest to the parameter position
+     * @param position world position
+     * @param result output the closest point to position constrained by the navigation mesh
+     */
+    getClosestPointToRef(position: Vector3, result: Vector3) : void {
+        var p = new this.bjsRECAST.Vec3(position.x, position.y, position.z);
+        var ret = this.navMesh.getClosestPoint(p);
+        result.set(ret.x, ret.y, ret.z);
+    }
+
+    /**
      * Get a navigation mesh constrained position, within a particular radius
      * @param position world position
      * @param maxRadius the maximum distance to the constrained world position
@@ -175,6 +186,18 @@ export class RecastJSPlugin implements INavigationEnginePlugin {
     }
 
     /**
+     * Get a navigation mesh constrained position, within a particular radius
+     * @param position world position
+     * @param maxRadius the maximum distance to the constrained world position
+     * @param result output the closest point to position constrained by the navigation mesh
+     */
+    getRandomPointAroundToRef(position: Vector3, maxRadius: number, result: Vector3): void {
+        var p = new this.bjsRECAST.Vec3(position.x, position.y, position.z);
+        var ret = this.navMesh.getRandomPointAround(p, maxRadius);
+        result.set(ret.x, ret.y, ret.z);
+    }
+
+    /**
      * Compute the final position from a segment made of destination-position
      * @param position world position
      * @param destination world position
@@ -189,6 +212,19 @@ export class RecastJSPlugin implements INavigationEnginePlugin {
     }
 
     /**
+     * Compute the final position from a segment made of destination-position
+     * @param position world position
+     * @param destination world position
+     * @param result output the resulting point along the navmesh
+     */
+    moveAlongToRef(position: Vector3, destination: Vector3, result: Vector3): void {
+        var p = new this.bjsRECAST.Vec3(position.x, position.y, position.z);
+        var d = new this.bjsRECAST.Vec3(destination.x, destination.y, destination.z);
+        var ret = this.navMesh.moveAlong(p, d);
+        result.set(ret.x, ret.y, ret.z);
+    }
+
+    /**
      * Compute a navigation path from start to end. Returns an empty array if no path can be computed
      * @param start world position
      * @param end world position
@@ -246,6 +282,16 @@ export class RecastJSPlugin implements INavigationEnginePlugin {
     }
 
     /**
+     * Get the Bounding box extent result specified by setDefaultQueryExtent
+     * @param result output the box extent values
+     */
+    getDefaultQueryExtentToRef(result: Vector3): void
+    {
+        let p = this.navMesh.getDefaultQueryExtent();
+        result.set(p.x, p.y, p.z);
+    }
+
+    /**
      * Disposes
      */
     public dispose() {
@@ -349,6 +395,16 @@ export class RecastJSCrowd implements ICrowd {
     }
 
     /**
+     * Returns the agent position result in world space
+     * @param index agent index returned by addAgent
+     * @param result output world space position
+     */
+    getAgentPositionToRef(index: number, result: Vector3): void {
+        var agentPos = this.recastCrowd.getAgentPosition(index);
+        result.set(agentPos.x, agentPos.y, agentPos.z);
+    }
+
+    /**
      * Returns the agent velocity in world space
      * @param index agent index returned by addAgent
      * @returns world space velocity
@@ -359,6 +415,16 @@ export class RecastJSCrowd implements ICrowd {
     }
 
     /**
+     * Returns the agent velocity result in world space
+     * @param index agent index returned by addAgent
+     * @param result output world space velocity
+     */
+    getAgentVelocityToRef(index: number, result: Vector3): void {
+        var agentVel = this.recastCrowd.getAgentVelocity(index);
+        result.set(agentVel.x, agentVel.y, agentVel.z);
+    }
+    
+    /**
      * Asks a particular agent to go to a destination. That destination is constrained by the navigation mesh
      * @param index agent index returned by addAgent
      * @param destination targeted world position
@@ -469,6 +535,16 @@ export class RecastJSCrowd implements ICrowd {
     }
 
     /**
+     * Get the Bounding box extent result specified by setDefaultQueryExtent
+     * @param result output the box extent values
+     */
+    getDefaultQueryExtentToRef(result: Vector3): void
+    {
+        let p = this.recastCrowd.getDefaultQueryExtent();
+        result.set(p.x, p.y, p.z);
+    }
+
+    /**
      * Release all resources
      */
     dispose() : void