Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed Feb 21, 2019
1 parent 3a4f3e8 commit b0cf828
Show file tree
Hide file tree
Showing 12 changed files with 220 additions and 242 deletions.
25 changes: 12 additions & 13 deletions build/yuka.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* @license
* The MIT License
*
*
* Copyright © 2018 Yuka authors
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -2927,7 +2927,8 @@
/**
* Holds the implementation for the line of sight test of this game entity.
* This method is used by {@link Vision#visible} in order to determine whether
* this game entity blocks the given line of sight or not.
* this game entity blocks the given line of sight or not. Implement this method
* when your game entity acts as an obstacle.
*
* @param {Ray} ray - The ray that represents the line of sight.
* @param {Vector3} intersectionPoint - The intersection point.
Expand Down Expand Up @@ -7936,11 +7937,9 @@
*/
intersectRay( ray, worldMatrix, intersectionPoint, normal = null ) {

const geometry = this;

// check bounding sphere first in world space

boundingSphere$1.copy( geometry.boundingSphere ).applyMatrix4( worldMatrix );
boundingSphere$1.copy( this.boundingSphere ).applyMatrix4( worldMatrix );

if ( ray.intersectsBoundingSphere( boundingSphere$1 ) ) {

Expand All @@ -7951,12 +7950,12 @@

// check AABB in local space since its more expensive to convert an AABB to world space than a bounding sphere

if ( rayLocal.intersectsAABB( geometry.aabb ) ) {
if ( rayLocal.intersectsAABB( this.aabb ) ) {

// now perform more expensive test with all triangles of the geometry

const vertices = geometry.vertices;
const indices = geometry.indices;
const vertices = this.vertices;
const indices = this.indices;

if ( indices === null ) {

Expand All @@ -7968,7 +7967,7 @@
triangle.b.set( vertices[ i + 3 ], vertices[ i + 4 ], vertices[ i + 5 ] );
triangle.c.set( vertices[ i + 6 ], vertices[ i + 7 ], vertices[ i + 8 ] );

if ( rayLocal.intersectTriangle( triangle, geometry.backfaceCulling, intersectionPoint ) !== null ) {
if ( rayLocal.intersectTriangle( triangle, this.backfaceCulling, intersectionPoint ) !== null ) {

// transform intersection point back to world space

Expand Down Expand Up @@ -8006,7 +8005,7 @@
triangle.b.set( vertices[ ( b * stride ) ], vertices[ ( b * stride ) + 1 ], vertices[ ( b * stride ) + 2 ] );
triangle.c.set( vertices[ ( c * stride ) ], vertices[ ( c * stride ) + 1 ], vertices[ ( c * stride ) + 2 ] );

if ( rayLocal.intersectTriangle( triangle, geometry.backfaceCulling, intersectionPoint ) !== null ) {
if ( rayLocal.intersectTriangle( triangle, this.backfaceCulling, intersectionPoint ) !== null ) {

// transform intersection point back to world space

Expand Down
352 changes: 175 additions & 177 deletions build/yuka.min.js

Large diffs are not rendered by default.

25 changes: 12 additions & 13 deletions build/yuka.module.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* @license
* The MIT License
*
*
* Copyright © 2018 Yuka authors
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -2921,7 +2921,8 @@ class GameEntity {
/**
* Holds the implementation for the line of sight test of this game entity.
* This method is used by {@link Vision#visible} in order to determine whether
* this game entity blocks the given line of sight or not.
* this game entity blocks the given line of sight or not. Implement this method
* when your game entity acts as an obstacle.
*
* @param {Ray} ray - The ray that represents the line of sight.
* @param {Vector3} intersectionPoint - The intersection point.
Expand Down Expand Up @@ -7930,11 +7931,9 @@ class MeshGeometry {
*/
intersectRay( ray, worldMatrix, intersectionPoint, normal = null ) {

const geometry = this;

// check bounding sphere first in world space

boundingSphere$1.copy( geometry.boundingSphere ).applyMatrix4( worldMatrix );
boundingSphere$1.copy( this.boundingSphere ).applyMatrix4( worldMatrix );

if ( ray.intersectsBoundingSphere( boundingSphere$1 ) ) {

Expand All @@ -7945,12 +7944,12 @@ class MeshGeometry {

// check AABB in local space since its more expensive to convert an AABB to world space than a bounding sphere

if ( rayLocal.intersectsAABB( geometry.aabb ) ) {
if ( rayLocal.intersectsAABB( this.aabb ) ) {

// now perform more expensive test with all triangles of the geometry

const vertices = geometry.vertices;
const indices = geometry.indices;
const vertices = this.vertices;
const indices = this.indices;

if ( indices === null ) {

Expand All @@ -7962,7 +7961,7 @@ class MeshGeometry {
triangle.b.set( vertices[ i + 3 ], vertices[ i + 4 ], vertices[ i + 5 ] );
triangle.c.set( vertices[ i + 6 ], vertices[ i + 7 ], vertices[ i + 8 ] );

if ( rayLocal.intersectTriangle( triangle, geometry.backfaceCulling, intersectionPoint ) !== null ) {
if ( rayLocal.intersectTriangle( triangle, this.backfaceCulling, intersectionPoint ) !== null ) {

// transform intersection point back to world space

Expand Down Expand Up @@ -8000,7 +7999,7 @@ class MeshGeometry {
triangle.b.set( vertices[ ( b * stride ) ], vertices[ ( b * stride ) + 1 ], vertices[ ( b * stride ) + 2 ] );
triangle.c.set( vertices[ ( c * stride ) ], vertices[ ( c * stride ) + 1 ], vertices[ ( c * stride ) + 2 ] );

if ( rayLocal.intersectTriangle( triangle, geometry.backfaceCulling, intersectionPoint ) !== null ) {
if ( rayLocal.intersectTriangle( triangle, this.backfaceCulling, intersectionPoint ) !== null ) {

// transform intersection point back to world space

Expand Down
1 change: 1 addition & 0 deletions examples/entity/shooter/src/Ground.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @author Mugen87 / https://github.com/Mugen87
*/
import { GameEntity } from '../../../../build/yuka.module.js';

class Ground extends GameEntity {

constructor( geometry ) {
Expand Down
2 changes: 1 addition & 1 deletion examples/perception/common/Obstacle.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class Obstacle extends GameEntity {

super();


this.geometry = geometry;

}
Expand All @@ -22,4 +21,5 @@ class Obstacle extends GameEntity {
}

}

export { Obstacle };
7 changes: 1 addition & 6 deletions examples/playground/hideAndSeek/src/CustomObstacle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class CustomObstacle extends GameEntity {
constructor( geometry ) {

super();

this.geometry = geometry;

}
Expand All @@ -21,12 +22,6 @@ class CustomObstacle extends GameEntity {

}

intersectRay( ray, intersectionPoint, normal = null ) {

return this.geometry.intersectRay( ray, this.worldMatrix, intersectionPoint, normal );

}

}

export { CustomObstacle };
10 changes: 2 additions & 8 deletions examples/playground/hideAndSeek/src/Enemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import world from './World.js';

class Enemy extends Vehicle {

constructor() {
constructor( geometry ) {

super();

this.geometry = null;
this.geometry = geometry;
this.maxSpeed = 5;
this.deathAnimDuration = 0.5;
this.currentTime = 0;
Expand Down Expand Up @@ -75,12 +75,6 @@ class Enemy extends Vehicle {

}

intersectRay( ray, intersectionPoint, normal = null ) {

return this.geometry.intersectRay( ray, this.worldMatrix, intersectionPoint, normal );

}

handleMessage() {

this.dead = true;
Expand Down
7 changes: 1 addition & 6 deletions examples/playground/hideAndSeek/src/Ground.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Ground extends GameEntity {
constructor( geometry ) {

super();

this.geometry = geometry;

}
Expand All @@ -21,12 +22,6 @@ class Ground extends GameEntity {

}

intersectRay( ray, intersectionPoint, normal = null ) {

return this.geometry.intersectRay( ray, this.worldMatrix, intersectionPoint, normal );

}

}

export { Ground };
10 changes: 5 additions & 5 deletions examples/playground/hideAndSeek/src/World.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,13 @@ class World {

renderComponent.material = enemyMaterial;

const enemy = new Enemy();
const vertices = renderComponent.geometry.attributes.position.array;
const geometry = new YUKA.MeshGeometry( vertices );

const enemy = new Enemy( geometry );
enemy.boundingRadius = renderComponent.geometry.boundingSphere.radius;
enemy.setRenderComponent( renderComponent, sync );

const vertices = renderComponent.geometry.attributes.position.array;
enemy.geometry = new YUKA.MeshGeometry( vertices );

// compute spawning point

let spawningPoint = null;
Expand Down Expand Up @@ -298,7 +298,7 @@ class World {

const obstalce = obstacles[ i ];

if ( obstalce.intersectRay( ray, intersection.point, intersection.normal ) !== null ) {
if ( obstalce.geometry.intersectRay( ray, obstalce.worldMatrix, intersection.point, intersection.normal ) !== null ) {

const squaredDistance = intersection.point.squaredDistanceTo( ray.origin );
obstalce.squaredDistance = squaredDistance;
Expand Down
3 changes: 2 additions & 1 deletion src/core/GameEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ class GameEntity {
/**
* Holds the implementation for the line of sight test of this game entity.
* This method is used by {@link Vision#visible} in order to determine whether
* this game entity blocks the given line of sight or not.
* this game entity blocks the given line of sight or not. Implement this method
* when your game entity acts as an obstacle.
*
* @param {Ray} ray - The ray that represents the line of sight.
* @param {Vector3} intersectionPoint - The intersection point.
Expand Down
15 changes: 6 additions & 9 deletions src/core/MeshGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Ray } from "../math/Ray";
import { Plane } from "../math/Plane";
import { Matrix4 } from "../math/Matrix4";


const boundingSphere = new BoundingSphere();
const triangle = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
const rayLocal = new Ray();
Expand Down Expand Up @@ -89,11 +88,9 @@ class MeshGeometry {
*/
intersectRay( ray, worldMatrix, intersectionPoint, normal = null ) {

const geometry = this;

// check bounding sphere first in world space

boundingSphere.copy( geometry.boundingSphere ).applyMatrix4( worldMatrix );
boundingSphere.copy( this.boundingSphere ).applyMatrix4( worldMatrix );

if ( ray.intersectsBoundingSphere( boundingSphere ) ) {

Expand All @@ -104,12 +101,12 @@ class MeshGeometry {

// check AABB in local space since its more expensive to convert an AABB to world space than a bounding sphere

if ( rayLocal.intersectsAABB( geometry.aabb ) ) {
if ( rayLocal.intersectsAABB( this.aabb ) ) {

// now perform more expensive test with all triangles of the geometry

const vertices = geometry.vertices;
const indices = geometry.indices;
const vertices = this.vertices;
const indices = this.indices;

if ( indices === null ) {

Expand All @@ -121,7 +118,7 @@ class MeshGeometry {
triangle.b.set( vertices[ i + 3 ], vertices[ i + 4 ], vertices[ i + 5 ] );
triangle.c.set( vertices[ i + 6 ], vertices[ i + 7 ], vertices[ i + 8 ] );

if ( rayLocal.intersectTriangle( triangle, geometry.backfaceCulling, intersectionPoint ) !== null ) {
if ( rayLocal.intersectTriangle( triangle, this.backfaceCulling, intersectionPoint ) !== null ) {

// transform intersection point back to world space

Expand Down Expand Up @@ -159,7 +156,7 @@ class MeshGeometry {
triangle.b.set( vertices[ ( b * stride ) ], vertices[ ( b * stride ) + 1 ], vertices[ ( b * stride ) + 2 ] );
triangle.c.set( vertices[ ( c * stride ) ], vertices[ ( c * stride ) + 1 ], vertices[ ( c * stride ) + 2 ] );

if ( rayLocal.intersectTriangle( triangle, geometry.backfaceCulling, intersectionPoint ) !== null ) {
if ( rayLocal.intersectTriangle( triangle, this.backfaceCulling, intersectionPoint ) !== null ) {

// transform intersection point back to world space

Expand Down
5 changes: 2 additions & 3 deletions test/unit_test/core/MeshGeometry.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,12 @@ describe( 'MeshGeometry', function () {
const ray = new Ray( new Vector3( 0.5, 5, 0.5 ), new Vector3( 0, - 1, 0 ) );

const matrix = new Matrix4();
matrix.setPosition( new Vector3( 0, 0, - 0.1 ) );
matrix.setPosition( new Vector3( 10, 0, 0 ) );
const intersectionPoint = new Vector3();

const result = geometry.intersectRay( ray, matrix, intersectionPoint );

expect( result ).not.to.be.null;
expect( intersectionPoint ).to.deep.equal( { x: 0.5, y: 0, z: 0.5 } );
expect( result ).to.be.null;

} );

Expand Down

0 comments on commit b0cf828

Please sign in to comment.