Skip to content

Commit

Permalink
NavMesh: Remove obsolete code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed Jan 29, 2019
1 parent 3a27d4a commit 5534c79
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 363 deletions.
90 changes: 14 additions & 76 deletions build/yuka.js
Original file line number Diff line number Diff line change
Expand Up @@ -12891,12 +12891,6 @@
*/
this.polygon = null;

/**
* The unique index of the vertex.
* @type number
*/
this.nodeIndex = - 1;

}

/**
Expand Down Expand Up @@ -13109,10 +13103,6 @@

this._buildRegions( sortedEdgeList );

// ensure unique node indices for all twin edges

this._buildNodeIndices();

// now build the navigation graph

this._buildGraph();
Expand Down Expand Up @@ -13532,73 +13522,12 @@

}

_buildNodeIndices() {

const regions = this.regions;

const indicesMap = new Map();
let nextNodeIndex = 0;

for ( let i = 0, l = regions.length; i < l; i ++ ) {

const region = regions[ i ];

let edge = region.edge;

do {

// only edges with a twin reference needs to be considered

if ( edge.twin !== null && edge.nodeIndex === null ) {

let nodeIndex = - 1;
const position = edge.from();

// check all existing entries

for ( const [ index, pos ] of indicesMap.entries() ) {

if ( position.equals( pos ) === true ) {

// found, use the existing index

nodeIndex = index;
break;

}

}

// if no suitable index was found, create a new one

if ( nodeIndex === - 1 ) {

nodeIndex = nextNodeIndex ++;
indicesMap.set( nodeIndex, position );

}

// assign unique node index to edge

edge.nodeIndex = nodeIndex;
edge.twin.next.nodeIndex = nodeIndex;

}

edge = edge.next;

} while ( edge !== region.edge );

}

}

_buildGraph() {

const graph = this.graph;
const regions = this.regions;

// for each region, the code creates an array of directly accessible node indices
// for each region, the code creates an array of directly accessible regions

const regionNeighbourhood = new Array();

Expand All @@ -13610,17 +13539,26 @@
regionNeighbourhood.push( regionIndices );

let edge = region.edge;

// iterate through all egdes of the region (in other words: along its contour)

do {

// check for a portal edge

if ( edge.twin !== null ) {

regionIndices.push( this.regions.indexOf( edge.twin.polygon ) );
const regionIndex = this.regions.indexOf( edge.twin.polygon );

regionIndices.push( regionIndex ); // the index of the adjacent region

// add node to graph if necessary
// add node for this region to the graph if necessary

if ( graph.hasNode( this.regions.indexOf( edge.polygon ) ) === false ) {

graph.addNode( new NavNode( this.regions.indexOf( edge.polygon ), edge.polygon.centroid ) );
const node = new NavNode( this.regions.indexOf( edge.polygon ), edge.polygon.centroid );

graph.addNode( node );

}

Expand Down Expand Up @@ -13697,7 +13635,7 @@

/**
* A reference to the first half-edge of this polygon.
* @type Vector3
* @type HalfEdge
*/
this.edge = null;

Expand Down
267 changes: 133 additions & 134 deletions build/yuka.min.js

Large diffs are not rendered by default.

90 changes: 14 additions & 76 deletions build/yuka.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -12885,12 +12885,6 @@ class HalfEdge {
*/
this.polygon = null;

/**
* The unique index of the vertex.
* @type number
*/
this.nodeIndex = - 1;

}

/**
Expand Down Expand Up @@ -13103,10 +13097,6 @@ class NavMesh {

this._buildRegions( sortedEdgeList );

// ensure unique node indices for all twin edges

this._buildNodeIndices();

// now build the navigation graph

this._buildGraph();
Expand Down Expand Up @@ -13526,73 +13516,12 @@ class NavMesh {

}

_buildNodeIndices() {

const regions = this.regions;

const indicesMap = new Map();
let nextNodeIndex = 0;

for ( let i = 0, l = regions.length; i < l; i ++ ) {

const region = regions[ i ];

let edge = region.edge;

do {

// only edges with a twin reference needs to be considered

if ( edge.twin !== null && edge.nodeIndex === null ) {

let nodeIndex = - 1;
const position = edge.from();

// check all existing entries

for ( const [ index, pos ] of indicesMap.entries() ) {

if ( position.equals( pos ) === true ) {

// found, use the existing index

nodeIndex = index;
break;

}

}

// if no suitable index was found, create a new one

if ( nodeIndex === - 1 ) {

nodeIndex = nextNodeIndex ++;
indicesMap.set( nodeIndex, position );

}

// assign unique node index to edge

edge.nodeIndex = nodeIndex;
edge.twin.next.nodeIndex = nodeIndex;

}

edge = edge.next;

} while ( edge !== region.edge );

}

}

_buildGraph() {

const graph = this.graph;
const regions = this.regions;

// for each region, the code creates an array of directly accessible node indices
// for each region, the code creates an array of directly accessible regions

const regionNeighbourhood = new Array();

Expand All @@ -13604,17 +13533,26 @@ class NavMesh {
regionNeighbourhood.push( regionIndices );

let edge = region.edge;

// iterate through all egdes of the region (in other words: along its contour)

do {

// check for a portal edge

if ( edge.twin !== null ) {

regionIndices.push( this.regions.indexOf( edge.twin.polygon ) );
const regionIndex = this.regions.indexOf( edge.twin.polygon );

regionIndices.push( regionIndex ); // the index of the adjacent region

// add node to graph if necessary
// add node for this region to the graph if necessary

if ( graph.hasNode( this.regions.indexOf( edge.polygon ) ) === false ) {

graph.addNode( new NavNode( this.regions.indexOf( edge.polygon ), edge.polygon.centroid ) );
const node = new NavNode( this.regions.indexOf( edge.polygon ), edge.polygon.centroid );

graph.addNode( node );

}

Expand Down Expand Up @@ -13691,7 +13629,7 @@ class Polygon {

/**
* A reference to the first half-edge of this polygon.
* @type Vector3
* @type HalfEdge
*/
this.edge = null;

Expand Down
6 changes: 0 additions & 6 deletions src/navigation/navmesh/HalfEdge.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ class HalfEdge {
*/
this.polygon = null;

/**
* The unique index of the vertex.
* @type number
*/
this.nodeIndex = - 1;

}

/**
Expand Down

0 comments on commit 5534c79

Please sign in to comment.