@@ -2952,22 +2952,31 @@ CANNON.ConvexPolyhedron.prototype.transformAllPoints = function(offset,quat){
29522952// The point lies outside of the convex hull of the other points
29532953// if and only if the direction of all the vectors from it to those
29542954// other points are on less than one half of a sphere around it.
2955+ var ConvexPolyhedron_pointIsInside = new CANNON . Vec3 ( ) ;
2956+ var ConvexPolyhedron_vToP = new CANNON . Vec3 ( ) ;
2957+ var ConvexPolyhedron_vToPointInside = new CANNON . Vec3 ( ) ;
29552958CANNON . ConvexPolyhedron . prototype . pointIsInside = function ( p ) {
29562959 var n = this . vertices . length ,
29572960 verts = this . vertices ,
29582961 faces = this . faces ,
29592962 normals = this . faceNormals ;
29602963 var positiveResult = null ;
29612964 var N = this . faces . length ;
2962- var pointInside = this . getAveragePointLocal ( ) ;
2965+ var pointInside = ConvexPolyhedron_pointIsInside ;
2966+ this . getAveragePointLocal ( pointInside ) ;
29632967 for ( var i = 0 ; i < N ; i ++ ) {
29642968 var numVertices = this . faces [ i ] . length ;
29652969 var n = normals [ i ] ;
29662970 var v = verts [ faces [ i ] [ 0 ] ] ; // We only need one point in the face
29672971
29682972 // This dot product determines which side of the edge the point is
2969- var r1 = n . dot ( p . vsub ( v ) ) ;
2970- var r2 = n . dot ( pointInside . vsub ( v ) ) ;
2973+ var vToP = ConvexPolyhedron_vToP ;
2974+ p . vsub ( v , vToP ) ;
2975+ var r1 = n . dot ( vToP ) ;
2976+
2977+ var vToPointInside = ConvexPolyhedron_vToPointInside ;
2978+ pointInside . vsub ( v , vToPointInside ) ;
2979+ var r2 = n . dot ( vToPointInside ) ;
29712980
29722981 if ( ( r1 < 0 && r2 > 0 ) || ( r1 > 0 && r2 < 0 ) ) {
29732982 return false ; // Encountered some other sign. Exit.
@@ -4714,7 +4723,7 @@ CANNON.ContactGenerator = function(){
47144723 sj . faceNormals [ i ] . copy ( normal ) ;
47154724 normal . normalize ( ) ;
47164725 qj . vmult ( normal , normal ) ;
4717-
4726+
47184727 // Check how much the particle penetrates the polygon plane.
47194728 var penetration = - normal . dot ( xi . vsub ( verts [ 0 ] ) ) ;
47204729 if ( minPenetration === null || Math . abs ( penetration ) < Math . abs ( minPenetration ) ) {
0 commit comments