-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbullet.min.js
245 lines (245 loc) · 122 KB
/
bullet.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
var Vecmath={};
(function(a){a.Vec3=function(){arguments.length==3&&this.set3(arguments[0],arguments[1],arguments[2])};a.Vec3.prototype.x=0;a.Vec3.prototype.y=0;a.Vec3.prototype.z=0;a.Vec3.prototype.set3=function(b,a,c){this.x=b;this.y=a;this.z=c};a.Vec3.prototype.set1=function(b){this.x=b.x;this.y=b.y;this.z=b.z};a.Vec3.prototype.sub1=function(b){this.x-=b.x;this.y-=b.y;this.z-=b.z};a.Vec3.prototype.sub2=function(b,a){this.x=b.x-a.x;this.y=b.y-a.y;this.z=b.z-a.z};a.Vec3.prototype.cross=function(b,a){this.set3(b.y*
a.z-b.z*a.y,b.z*a.x-b.x*a.z,b.x*a.y-b.y*a.x)};a.Vec3.prototype.normalize=function(){var b=this.length();this.x/=b;this.y/=b;this.z/=b};a.Vec3.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z};a.Vec3.prototype.length=function(){return Math.sqrt(this.lengthSquared())};a.Vec3.prototype.scale1=function(b){this.x*=b;this.y*=b;this.z*=b};a.Vec3.prototype.scale2=function(b,a){this.x=b*a.x;this.y=b*a.y;this.z=b*a.z};a.Vec3.prototype.scaleAdd=function(b,a,c){this.x=b*a.x+
c.x;this.y=b*a.y+c.y;this.z=b*a.z+c.z};a.Vec3.prototype.dot=function(b){return this.x*b.x+this.y*b.y+this.z*b.z};a.Vec3.prototype.normalize1=function(b){this.set1(b);this.normalize()};a.Vec3.prototype.add1=function(b){this.x+=b.x;this.y+=b.y;this.z+=b.z};a.Vec3.prototype.add2=function(b,a){this.x=b.x+a.x;this.y=b.y+a.y;this.z=b.z+a.z};a.Vec3.prototype.negate0=function(){this.x=-this.x;this.y=-this.y;this.z=-this.z};a.Vec3.prototype.negate1=function(b){this.x=-b.x;this.y=-b.y;this.z=-b.z};a.Vec3.prototype.toString=
function(){return"V3["+this.x+","+this.y+","+this.z+"]"};a.Vec3.prototype.equals=function(b){return b!=null&&this.x==b.x&&this.y==b.y&&this.z==b.z};a.Vec4=function(){arguments.length==1&&this.set1(arguments[0]);arguments.length==4&&this.set4(arguments[0],arguments[1],arguments[2],arguments[3])};a.Vec4.prototype.x=0;a.Vec4.prototype.y=0;a.Vec4.prototype.z=0;a.Vec4.prototype.w=0;a.Vec4.prototype.set4=function(b,a,c,e){this.x=b;this.y=a;this.z=c;this.w=e};a.Vec4.prototype.set1=function(b){this.x=b.x;
this.y=b.y;this.z=b.z;this.w=b.w};a.Vec4.prototype.absolute=function(){if(this.x<0)this.x=-this.x;if(this.y<0)this.y=-this.y;if(this.z<0)this.z=-this.z;if(this.w<0)this.w=-this.w};a.Vec4.prototype.toString=function(){return"Vec4["+this.x+","+this.y+","+this.z+","+this.w+"]"};a.Quat4=function(){arguments.length==1&&this.set1(arguments[0]);arguments.length==4&&this.set4(arguments[0],arguments[1],arguments[2],arguments[3])};a.Quat4.prototype=new a.Vec4;a.Quat4.prototype.mul=function(b,a){this.set4(b.x*
a.w+b.w*a.x+b.y*a.z-b.z*a.y,b.y*a.w+b.w*a.y+b.z*a.x-b.x*a.z,b.z*a.w+b.w*a.z+b.x*a.y-b.y*a.x,b.w*a.w-b.x*a.x-b.y*a.y-b.z*a.z)};a.Quat4.prototype.norm=function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w};a.Quat4.prototype.normalize=function(){var b=Math.sqrt(this.norm());this.x/=b;this.y/=b;this.z/=b;this.w/=b};a.Quat4.prototype.toString=function(){return"Quat4"};a.Mat3=function(){};a.Mat3.prototype.m00=0;a.Mat3.prototype.m01=0;a.Mat3.prototype.m02=0;a.Mat3.prototype.m10=0;a.Mat3.prototype.m11=
0;a.Mat3.prototype.m12=0;a.Mat3.prototype.m20=0;a.Mat3.prototype.m21=0;a.Mat3.prototype.m22=0;a.Mat3.prototype.set9=function(b,a,c,e,f,g,h,j,i){this.m00=b;this.m01=a;this.m02=c;this.m10=e;this.m11=f;this.m12=g;this.m20=h;this.m21=j;this.m22=i};a.Mat3.prototype.set1=function(b){this.m00=b.m00;this.m01=b.m01;this.m02=b.m02;this.m10=b.m10;this.m11=b.m11;this.m12=b.m12;this.m20=b.m20;this.m21=b.m21;this.m22=b.m22};a.Mat3.prototype.seta=function(b){this.m00=b[0];this.m01=b[1];this.m02=b[2];this.m10=b[3];
this.m11=b[4];this.m12=b[5];this.m20=b[6];this.m21=b[7];this.m22=b[8]};a.Mat3.prototype.transform1=function(b){this.transform2(b,b)};a.Mat3.prototype.transform2=function(b,a){a.set3(this.m00*b.x+this.m01*b.y+this.m02*b.z,this.m10*b.x+this.m11*b.y+this.m12*b.z,this.m20*b.x+this.m21*b.y+this.m22*b.z)};a.Mat3.prototype.mul1=function(b){this.mul2(this,b)};a.Mat3.prototype.mul2=function(b,a){this.set9(b.m00*a.m00+b.m01*a.m10+b.m02*a.m20,b.m00*a.m01+b.m01*a.m11+b.m02*a.m21,b.m00*a.m02+b.m01*a.m12+b.m02*
a.m22,b.m10*a.m00+b.m11*a.m10+b.m12*a.m20,b.m10*a.m01+b.m11*a.m11+b.m12*a.m21,b.m10*a.m02+b.m11*a.m12+b.m12*a.m22,b.m20*a.m00+b.m21*a.m10+b.m22*a.m20,b.m20*a.m01+b.m21*a.m11+b.m22*a.m21,b.m20*a.m02+b.m21*a.m12+b.m22*a.m22)};a.Mat3.prototype.transpose=function(){var b=this.m01;this.m01=this.m10;this.m10=b;b=this.m02;this.m02=this.m20;this.m20=b;b=this.m12;this.m12=this.m21;this.m21=b};a.Mat3.prototype.getRow=function(b,a){b==0?(a.x=this.m00,a.y=this.m01,a.z=this.m02):b==1?(a.x=this.m10,a.y=this.m11,
a.z=this.m12):b==2?(a.x=this.m20,a.y=this.m21,a.z=this.m22):alert("row must be 0 to 2 and is "+b)};a.Mat3.prototype.setRow=function(b,a,c,e){b==0?(this.m00=a,this.m01=c,this.m02=e):b==1?(this.m10=a,this.m11=c,this.m12=e):b==2?(this.m20=a,this.m21=c,this.m22=e):alert("row must be 0 to 2 and is "+b)};a.Mat3.prototype.getElement=function(b,a){if(b==0)if(a==0)return this.m00;else if(a==1)return this.m01;else if(a==2)return this.m02;else alert("column must be 0 to 2 and is "+a);else if(b==1)if(a==0)return this.m10;
else if(a==1)return this.m11;else if(a==2)return this.m12;else alert("column must be 0 to 2 and is "+a);else if(b==2)if(a==0)return this.m20;else if(a==1)return this.m21;else if(a==2)return this.m22;else alert("column must be 0 to 2 and is "+a);else alert("row must be 0 to 2 and is "+b)};a.Mat3.prototype.setIdentity=function(){this.m00=1;this.m10=this.m02=this.m01=0;this.m11=1;this.m21=this.m20=this.m12=0;this.m22=1};a.Mat3.prototype.toString=function(){return"M3("+this.m00+","+this.m01+","+this.m02+
"..)"};a.Mat4=function(){};a.Mat4.prototype.m00=0;a.Mat4.prototype.m01=0;a.Mat4.prototype.m02=0;a.Mat4.prototype.m03=0;a.Mat4.prototype.m10=0;a.Mat4.prototype.m11=0;a.Mat4.prototype.m12=0;a.Mat4.prototype.m13=0;a.Mat4.prototype.m20=0;a.Mat4.prototype.m21=0;a.Mat4.prototype.m22=0;a.Mat4.prototype.m23=0;a.Mat4.prototype.m30=0;a.Mat4.prototype.m31=0;a.Mat4.prototype.m32=0;a.Mat4.prototype.m33=0;a.Mat4.prototype.rotX=function(b){var a=Math.cos(b),b=Math.sin(b);this.m00=1;this.m10=this.m03=this.m02=this.m01=
0;this.m11=a;this.m12=-b;this.m20=this.m13=0;this.m21=b;this.m22=a;this.m32=this.m31=this.m30=this.m23=0;this.m33=1};a.Mat4.prototype.rotZ=function(b){var a=Math.cos(b),b=Math.sin(b);this.m00=a;this.m01=-b;this.m03=this.m02=0;this.m10=b;this.m11=a;this.m21=this.m20=this.m13=this.m12=0;this.m22=1;this.m32=this.m31=this.m30=this.m23=0;this.m33=1};a.Mat4.prototype.transform2=function(b,a){a.set4(this.m00*b.x+this.m01*b.y+this.m02*b.z+this.m03*b.w,this.m10*b.x+this.m11*b.y+this.m12*b.z+this.m13*b.w,this.m20*
b.x+this.m21*b.y+this.m22*b.z+this.m23*b.w,this.m30*b.x+this.m31*b.y+this.m32*b.z+this.m33*b.w)};a.Mat4.prototype.transform1=function(b){this.transform2(b,b)};a.Mat4.prototype.set16=function(b,a,c,e,f,g,h,j,i,m,k,l,o,p,n,q){this.m00=b;this.m01=a;this.m02=c;this.m03=e;this.m10=f;this.m11=g;this.m12=h;this.m13=j;this.m20=i;this.m21=m;this.m22=k;this.m23=l;this.m30=o;this.m31=p;this.m32=n;this.m33=q};a.Mat4.prototype.set1=function(b){this.m00=b.m00;this.m01=b.m01;this.m02=b.m02;this.m03=0;this.m10=b.m10;
this.m11=b.m11;this.m12=b.m12;this.m13=0;this.m20=b.m20;this.m21=b.m21;this.m22=b.m22;this.m32=this.m31=this.m30=this.m23=0;this.m33=1};a.Mat4.prototype.mul2=function(b,a){this.set16(b.m00*a.m00+b.m01*a.m10+b.m02*a.m20+b.m03*a.m30,b.m00*a.m01+b.m01*a.m11+b.m02*a.m21+b.m03*a.m31,b.m00*a.m02+b.m01*a.m12+b.m02*a.m22+b.m03*a.m32,b.m00*a.m03+b.m01*a.m13+b.m02*a.m23+b.m03*a.m33,b.m10*a.m00+b.m11*a.m10+b.m12*a.m20+b.m13*a.m30,b.m10*a.m01+b.m11*a.m11+b.m12*a.m21+b.m13*a.m31,b.m10*a.m02+b.m11*a.m12+b.m12*
a.m22+b.m13*a.m32,b.m10*a.m03+b.m11*a.m13+b.m12*a.m23+b.m13*a.m33,b.m20*a.m00+b.m21*a.m10+b.m22*a.m20+b.m23*a.m30,b.m20*a.m01+b.m21*a.m11+b.m22*a.m21+b.m23*a.m31,b.m20*a.m02+b.m21*a.m12+b.m22*a.m22+b.m23*a.m32,b.m20*a.m03+b.m21*a.m13+b.m22*a.m23+b.m23*a.m33,b.m30*a.m00+b.m31*a.m10+b.m32*a.m20+b.m33*a.m30,b.m30*a.m01+b.m31*a.m11+b.m32*a.m21+b.m33*a.m31,b.m30*a.m02+b.m31*a.m12+b.m32*a.m22+b.m33*a.m32,b.m30*a.m03+b.m31*a.m13+b.m32*a.m23+b.m33*a.m33)};a.Mat4.prototype.mul1=function(b){this.mul2(this,
b)};a.Mat4.prototype.getRotationScale=function(b){b.m00=this.m00;b.m01=this.m01;b.m02=this.m02;b.m10=this.m10;b.m11=this.m11;b.m12=this.m12;b.m20=this.m20;b.m21=this.m21;b.m22=this.m22};a.Mat4.prototype.toString=function(){return"M4("+this.m00+","+this.m01+","+this.m02+","+this.m03+"..)"}})(Vecmath);var Bullet={};
(function(a){a.dbg=!1;a.objC=0;a.log=function(){};a.out=function(b){document.getElementById("info0").innerHTML="Out: "+b};a.a2s=function(b,a){if(a>b.length)a=b.len;for(var c="",e=0;e<a;e++)c+=(e==0?"[":",")+b[e];c+="]";return c};a.arrayFill=function(b,a){for(var c=b.length-1;c>=0;c--)b[c]=a};a.arrayCreate=function(b,d,c){d==null&&(d=0);for(var e=Array(b[d]),f=e.length-1;f>=0;f--)e[f]=d<b.length-1?a.arrayCreate(b,d+1):c;return e};a.stacktrace=function(){function b(a){return!a?[]:b(a.caller).concat([a.toString().split("(")[0].substring(9)+
"("+a.arguments+")"])}return b(arguments.callee.caller)};a.ObjectStackList=function(b){this.stack=Array(512);this.list=[];this.createF=b;this.returnObj=b()};a.ObjectStackList.prototype.stackCount=0;a.ObjectStackList.prototype.pos=0;a.ObjectStackList.prototype.push=function(){this.stack[this.stackCount++]=this.pos};a.ObjectStackList.prototype.pop=function(){this.pos=this.stack[--this.stackCount]};a.ObjectStackList.prototype.get=function(){this.pos==this.list.length&&this.list.push(this.createF());
return this.list[this.pos++]};a.ObjectArrayList=function(){this.array=Array(16)};a.ObjectArrayList.prototype.size=0;a.ObjectArrayList.prototype.add=function(b){this.size==this.array.length&&this.array.push(b);this.array[this.size++]=b};a.ObjectArrayList.prototype.remove=function(b){this.array.splice(b,1);this.size--};a.ObjectArrayList.prototype.get=function(b){return this.array[b]};a.ObjectArrayList.prototype.set=function(b,a){var c=this.array[b];this.array[b]=a;return c};a.ObjectArrayList.prototype.sizef=
function(){return this.size};a.ObjectArrayList.prototype.capacity=function(){return this.array.length};a.ObjectArrayList.prototype.clear=function(){this.size=0};a.ObjectArrayList.prototype.indexOf=function(b){for(var a=0;a<size;a++)if(b==null?array[a]==null:b==array[a])return a;return-1};a.ObjectArrayList.prototype.toString=function(){return"ObjectArrayList["+a.a2s(this.array,16)+"]"};a.ObjectPool=function(b){this.list=[];this.createF=b};a.ObjectPool.prototype.get=function(){return this.list.length>
0?this.list.pop():this.createF()};a.ObjectPool.prototype.release=function(b){this.list.push(b)};a.ArrayPool=function(){};a.ArrayPool.prototype.ars={};a.ArrayPool.prototype.getFixed=function(b){var a=this.ars["a"+b];if(a!=null&&a.length>0)return a.pop();return Array(b)};a.ArrayPool.prototype.release=function(b){var a=this.ars["a"+b.length];a==null&&(a=[],this.ars["a"+b.length]=a);a.push(b)};a.BroadphaseNativeType={BOX_SHAPE_PROXYTYPE:0,TRIANGLE_SHAPE_PROXYTYPE:1,TETRAHEDRAL_SHAPE_PROXYTYPE:2,CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE:3,
CONVEX_HULL_SHAPE_PROXYTYPE:4,IMPLICIT_CONVEX_SHAPES_START_HERE:5,SPHERE_SHAPE_PROXYTYPE:6,MULTI_SPHERE_SHAPE_PROXYTYPE:7,CAPSULE_SHAPE_PROXYTYPE:8,CONE_SHAPE_PROXYTYPE:9,CONVEX_SHAPE_PROXYTYPE:10,CYLINDER_SHAPE_PROXYTYPE:11,UNIFORM_SCALING_SHAPE_PROXYTYPE:12,MINKOWSKI_SUM_SHAPE_PROXYTYPE:13,MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE:14,CONCAVE_SHAPES_START_HERE:15,TRIANGLE_MESH_SHAPE_PROXYTYPE:16,SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE:17,FAST_CONCAVE_MESH_PROXYTYPE:18,TERRAIN_SHAPE_PROXYTYPE:19,GIMPACT_SHAPE_PROXYTYPE:20,
MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE:21,EMPTY_SHAPE_PROXYTYPE:22,STATIC_PLANE_PROXYTYPE:23,CONCAVE_SHAPES_END_HERE:24,COMPOUND_SHAPE_PROXYTYPE:25,SOFTBODY_SHAPE_PROXYTYPE:26,MAX_BROADPHASE_COLLISION_TYPES:27};a.BroadphaseNativeType.isPolyhedral=function(b){return b<this.IMPLICIT_CONVEX_SHAPES_START_HERE};a.BroadphaseNativeType.isConvex=function(b){return b<this.CONCAVE_SHAPES_START_HERE};a.BroadphaseNativeType.isConcave=function(b){return b>this.CONCAVE_SHAPES_START_HERE&&b<this.CONCAVE_SHAPES_END_HERE};
a.BroadphaseNativeType.isCompound=function(b){return b==this.COMPOUND_SHAPE_PROXYTYPE};a.BroadphaseNativeType.isInfinite=function(b){return b==this.STATIC_PLANE_PROXYTYPE};a.BulletGlobals={CONVEX_DISTANCE_MARGIN:0.04,FLT_EPSILON:1.1920929E-7,SIMD_EPSILON:1.1920929E-7,SIMD_2_PI:6.283185307179586,SIMD_PI:3.141592653589793,SIMD_HALF_PI:1.5707963267948966,SIMD_RADS_PER_DEG:0.017453292519943295,SIMD_DEGS_PER_RAD:57.29577951308232,SIMD_INFINITY:Number.MAX_VALUE,contactBreakingThreshold:0.02,deactivationTime:2,
disableDeactivation:!1};a.MiscUtil={};a.MiscUtil.resizec=function(b,a,c){for(;b.sizef()<a;)b.add(c);for(;b.sizef()>a;)b.remove(b.sizef()-1)};a.MiscUtil.resizea=function(b,a,c){for(;b.length<a;)b.push(c());for(;b.length>a;)b.pop()};a.MiscUtil.GEN_clamped=function(b,a,c){return b<a?a:c<b?c:b};a.MiscUtil.downHeap=function(b,a,c,e){for(var f=b[a-1];a<=Math.floor(c/2);){var g=2*a;g<c&&e(b[g-1],b[g])<0&&g++;if(e(f,b[g-1])<0)b[a-1]=b[g-1],a=g;else break}b.set[a-1]=f};a.MiscUtil.swap=function(b,a,c){var e=
b[a];b[a]=b[c];b[c]=e};a.MiscUtil.quickSort=function(b,a){b.length>1&&this.quickSortInternal(b,a,0,b.length-1)};a.MiscUtil.quickSortInternal=function(b,a,c,e){var f=c,g=e,h=b[Math.floor((c+e)/2)];do{for(;a(b[f],h)<0;)f++;for(;a(h,b[g])<0;)g--;f<=g&&(this.swap(b,f,g),f++,g--)}while(f<=g);c<g&&this.quickSortInternal(b,a,c,g);f<e&&this.quickSortInternal(b,a,f,e)};a.MatrixUtil={};a.MatrixUtil.scale=function(b,a,c){b.m00=a.m00*c.x;b.m01=a.m01*c.y;b.m02=a.m02*c.z;b.m10=a.m10*c.x;b.m11=a.m11*c.y;b.m12=a.m12*
c.z;b.m20=a.m20*c.x;b.m21=a.m21*c.y;b.m22=a.m22*c.z};a.MatrixUtil.absolute=function(b){b.m00=Math.abs(b.m00);b.m01=Math.abs(b.m01);b.m02=Math.abs(b.m02);b.m10=Math.abs(b.m10);b.m11=Math.abs(b.m11);b.m12=Math.abs(b.m12);b.m20=Math.abs(b.m20);b.m21=Math.abs(b.m21);b.m22=Math.abs(b.m22)};a.MatrixUtil.tdotx=function(b,a){return b.m00*a.x+b.m10*a.y+b.m20*a.z};a.MatrixUtil.tdoty=function(b,a){return b.m01*a.x+b.m11*a.y+b.m21*a.z};a.MatrixUtil.tdotz=function(b,a){return b.m02*a.x+b.m12*a.y+b.m22*a.z};a.MatrixUtil.transposeTransform=
function(b,a,c){var e=this.tdotx(c,a),f=this.tdoty(c,a),a=this.tdotz(c,a);b.x=e;b.y=f;b.z=a};a.MatrixUtil.setRotation=function(b,a){var c=2/(a.x*a.x+a.y*a.y+a.z*a.z+a.w*a.w),e=a.x*c,f=a.y*c,g=a.z*c,c=a.w*e,h=a.w*f,j=a.w*g;e*=a.x;var i=a.x*f,m=a.x*g;f*=a.y;var k=a.y*g;g*=a.z;b.m00=1-(f+g);b.m01=i-j;b.m02=m+h;b.m10=i+j;b.m11=1-(e+g);b.m12=k-c;b.m20=m-h;b.m21=k+c;b.m22=1-(e+f)};a.MatrixUtil.temp=Array(4);a.MatrixUtil.getRotation=function(b,a){var c=b.m00+b.m11+b.m22;if(c>0)c=Math.sqrt(c+1),this.temp[3]=
c*0.5,c=0.5/c,this.temp[0]=(b.m21-b.m12)*c,this.temp[1]=(b.m02-b.m20)*c,this.temp[2]=(b.m10-b.m01)*c;else{var e=b.m00<b.m11?b.m11<b.m22?2:1:b.m00<b.m22?2:0,f=(e+1)%3,g=(e+2)%3,c=Math.sqrt(b.getElement(e,e)-b.getElement(f,f)-b.getElement(g,g)+1);this.temp[e]=c*0.5;c=0.5/c;this.temp[3]=(b.getElement(g,f)-b.getElement(f,g))*c;this.temp[f]=(b.getElement(f,e)+b.getElement(e,f))*c;this.temp[g]=(b.getElement(g,e)+b.getElement(e,g))*c}a.set4(this.temp[0],this.temp[1],this.temp[2],this.temp[3])};a.ScalarUtil=
{};a.ScalarUtil.fsel=function(b,a,c){return b>=0?a:c};a.ScalarUtil.fuzzyZero=function(b){return Math.abs(b)<a.BulletGlobals.FLT_EPSILON};a.VectorUtil={};a.VectorUtil.maxAxis4=function(b){var a=-1,c=-1.0E30;if(b.x>c)a=0,c=b.x;if(b.y>c)a=1,c=b.y;if(b.z>c)a=2,c=b.z;b.w>c&&(a=3);return a};a.VectorUtil.closestAxis4=function(b){b=new Vecmath.Vec4(b);b.absolute();return this.maxAxis4(b)};a.VectorUtil.add=function(b,a,c,e){b.x=a.x+c.x+e.x;b.y=a.y+c.y+e.y;b.z=a.z+c.z+e.z};a.VectorUtil.add5=function(b,a,c,
e,f){b.x=a.x+c.x+e.x+f.x;b.y=a.y+c.y+e.y+f.y;b.z=a.z+c.z+e.z+f.z};a.VectorUtil.mul=function(b,a,c){b.x=a.x*c.x;b.y=a.y*c.y;b.z=a.z*c.z};a.VectorUtil.setMin=function(b,a){b.x=Math.min(b.x,a.x);b.y=Math.min(b.y,a.y);b.z=Math.min(b.z,a.z)};a.VectorUtil.setMax=function(b,a){b.x=Math.max(b.x,a.x);b.y=Math.max(b.y,a.y);b.z=Math.max(b.z,a.z)};a.Transform=function(){this.basis=new Vecmath.Mat3;this.origin=new Vecmath.Vec3;this.vec=new Vecmath.Vec3;this.mat=new Vecmath.Mat3};a.Transform.createM3=function(b){var d=
new a.Transform;d.basis.set1(b);return d};a.Transform.createM4=function(b){var d=new a.Transform;d.setM4(b);return d};a.Transform.createT=function(b){var d=new a.Transform;d.setT(b);return d};a.Transform.prototype.setT=function(b){this.basis.set1(b.basis);this.origin.set1(b.origin)};a.Transform.prototype.setM3=function(b){this.basis.set1(b);this.origin.set(0,0,0)};a.Transform.prototype.setM4=function(b){b.getRotationScale(this.basis);this.origin.set(b.m03,b.m13,b.m23)};a.Transform.prototype.transform=
function(b){this.basis.transform1(b);b.add1(this.origin)};a.Transform.prototype.setIdentity=function(){this.basis.setIdentity();this.origin.set3(0,0,0)};a.Transform.prototype.inverse=function(){this.basis.transpose();this.origin.scale(-1);this.basis.transform1(this.origin)};a.Transform.prototype.inverseT=function(b){this.set(b);this.inverse()};a.Transform.prototype.mul=function(b){this.vec.set1(b.origin);this.transform(this.vec);this.basis.mul1(b.basis);this.origin.set1(this.vec)};a.Transform.prototype.invXform=
function(b,a){a.sub2(b,this.origin);this.mat.set1(this.basis);this.mat.transpose();this.mat.transform1(a)};a.Transform.prototype.getRotation=function(b){a.MatrixUtil.getRotation(this.basis,b);return b};a.Transform.prototype.setRotation=function(b){a.MatrixUtil.setRotation(this.basis,b)};a.Transform.prototype.getMatrix=function(b){b.set1(this.basis);b.m03=this.origin.x;b.m13=this.origin.y;b.m23=this.origin.z;return b};a.Transform.prototype.toString=function(){return"T("+this.basis+" "+this.origin+
")"};a.TransformUtil={};a.TransformUtil.SIMDSQRT12=0.7071067811865476;a.TransformUtil.ANGULAR_MOTION_THRESHOLD=0.7853981633974483;a.TransformUtil.recipSqrt=function(b){return 1/Math.sqrt(b)};a.TransformUtil.planeSpace1=function(b,a,c){if(Math.abs(b.z)>this.SIMDSQRT12){var e=b.y*b.y+b.z*b.z,f=this.recipSqrt(e);a.set3(0,-b.z*f,b.y*f);c.set3(e*f,-b.x*a.z,b.x*a.y)}else e=b.x*b.x+b.y*b.y,f=this.recipSqrt(e),a.set3(-b.y*f,b.x*f,0),c.set3(-b.z*a.y,b.z*a.x,e*f)};a.TransformUtil.axis=new Vecmath.Vec3;a.TransformUtil.dorn=
new Vecmath.Quat4;a.TransformUtil.orn0=new Vecmath.Quat4;a.TransformUtil.predictedOrn=new Vecmath.Quat4;a.TransformUtil.integrateTransform=function(b,d,c,e,f){f.origin.scaleAdd(e,d,b.origin);this.axis.set3(0,0,0);d=c.length();d*e>a.TransformUtil.ANGULAR_MOTION_THRESHOLD&&(d=a.TransformUtil.ANGULAR_MOTION_THRESHOLD/e);d<0.001?this.axis.scale2(0.5*e-e*e*e*0.020833333333*d*d,c):this.axis.scale2(Math.sin(0.5*d*e)/d,c);this.dorn.set4(0,0,0,0);this.dorn.set4(this.axis.x,this.axis.y,this.axis.z,Math.cos(d*
e*0.5));this.orn0.set4(0,0,0,0);this.orn0=b.getRotation(this.orn0);this.predictedOrn.set4(0,0,0,0);this.predictedOrn.mul(this.dorn,this.orn0);this.predictedOrn.normalize();f.setRotation(this.predictedOrn)};a.MotionState=function(b){this.graphicsWorldTrans=new a.Transform;this.centerOfMassOffset=new a.Transform;this.startWorldTrans=new a.Transform;this.graphicsWorldTrans.setT(b);this.centerOfMassOffset.setIdentity();this.startWorldTrans.setT(b)};a.MotionState.prototype.getWorldTransform=function(b){b.inverse(this.centerOfMassOffset);
b.mul(this.graphicsWorldTrans);return b};a.MotionState.prototype.setWorldTransform=function(b){this.graphicsWorldTrans.set(b);this.graphicsWorldTrans.mul(centerOfMassOffset)};a.ManifoldPoint=function(){this.localPointA=new Vecmath.Vec3;this.localPointB=new Vecmath.Vec3;this.positionWorldOnB=new Vecmath.Vec3;this.positionWorldOnA=new Vecmath.Vec3;this.normalWorldOnB=new Vecmath.Vec3;this.lateralFrictionDir1=new Vecmath.Vec3;this.lateralFrictionDir2=new Vecmath.Vec3;this.userPersistentData=null;this.appliedImpulse=
0;this.lateralFrictionInitialized=!1;this.lifeTime=0};a.ManifoldPoint.prototype.distance1=0;a.ManifoldPoint.prototype.combinedFriction=0;a.ManifoldPoint.prototype.combinedRestitution=0;a.ManifoldPoint.prototype.partId0=0;a.ManifoldPoint.prototype.partId1=0;a.ManifoldPoint.prototype.index0=0;a.ManifoldPoint.prototype.index1=0;a.ManifoldPoint.prototype.appliedImpulse=0;a.ManifoldPoint.prototype.lateralFrictionInitialized=!1;a.ManifoldPoint.prototype.appliedImpulseLateral1=0;a.ManifoldPoint.prototype.appliedImpulseLateral2=
0;a.ManifoldPoint.prototype.lifeTime=0;a.ManifoldPoint.prototype.init=function(b,a,c,e){this.localPointA.set1(b);this.localPointB.set1(a);this.normalWorldOnB.set1(c);this.distance1=e;this.combinedRestitution=this.combinedFriction=0;this.userPersistentData=null;this.appliedImpulse=0;this.lateralFrictionInitialized=!1;this.lifeTime=this.appliedImpulseLateral2=this.appliedImpulseLateral1=0};a.ManifoldPoint.prototype.set=function(b){this.localPointA.set1(b.localPointA);this.localPointB.set1(b.localPointB);
this.positionWorldOnA.set1(b.positionWorldOnA);this.positionWorldOnB.set1(b.positionWorldOnB);this.normalWorldOnB.set1(b.normalWorldOnB);this.distance1=b.distance1;this.combinedFriction=b.combinedFriction;this.combinedRestitution=b.combinedRestitution;this.partId0=b.partId0;this.partId1=b.partId1;this.index0=b.index0;this.index1=b.index1;this.userPersistentData=b.userPersistentData;this.appliedImpulse=b.appliedImpulse;this.lateralFrictionInitialized=b.lateralFrictionInitialized;this.appliedImpulseLateral1=
b.appliedImpulseLateral1;this.appliedImpulseLateral2=b.appliedImpulseLateral2;this.lifeTime=b.lifeTime;this.lateralFrictionDir1.set1(b.lateralFrictionDir1);this.lateralFrictionDir2.set1(b.lateralFrictionDir2)};a.ManifoldPoint.prototype.getPositionWorldOnA=function(b){b.set1(this.positionWorldOnA);return b};a.ManifoldPoint.prototype.getPositionWorldOnB=function(b){b.set1(this.positionWorldOnB);return b};a.ManifoldPoint.prototype.toString=function(){return"ManifoldPoint("+this.localPointA+","+this.localPointB+
")"};a.PersistentManifold=function(){this.pointCache=Array(a.PersistentManifold.prototype.MANIFOLD_CACHE_SIZE);this.cross=new Vecmath.Vec3;this.a0=new Vecmath.Vec3;this.b0=new Vecmath.Vec3;this.a1=new Vecmath.Vec3;this.b1=new Vecmath.Vec3;this.a2=new Vecmath.Vec3;this.b2=new Vecmath.Vec3;this.a3=new Vecmath.Vec3;this.b3=new Vecmath.Vec3;this.maxvec=new Vecmath.Vec4;this.diffA=new Vecmath.Vec3;this.tmp=new Vecmath.Vec3;this.projectedDifference=new Vecmath.Vec3;this.projectedPoint=new Vecmath.Vec3;
for(var b=0;b<this.pointCache.length;b++)this.pointCache[b]=new a.ManifoldPoint};a.PersistentManifold.prototype.MANIFOLD_CACHE_SIZE=4;a.PersistentManifold.prototype.cachedPoints=0;a.PersistentManifold.prototype.index1a=0;a.PersistentManifold.prototype.init=function(b,a){this.body0=b;this.body1=a;this.index1a=this.cachedPoints=0};a.PersistentManifold.prototype.sortCachedPoints=function(b){for(var d=-1,c=b.distance1,e=0;e<4;e++)if(this.pointCache[e].distance1<c)d=e,c=this.pointCache[e].distance1;var f=
e=c=0,g=0;d!=0&&(this.a0.set1(b.localPointA),this.a0.sub1(this.pointCache[1].localPointA),this.b0.set1(this.pointCache[3].localPointA),this.b0.sub1(this.pointCache[2].localPointA),this.cross.cross(this.a0,this.b0),c=this.cross.lengthSquared());d!=1&&(this.a1.set1(b.localPointA),this.a1.sub1(this.pointCache[0].localPointA),this.b1.set1(this.pointCache[3].localPointA),this.b1.sub1(this.pointCache[2].localPointA),this.cross.cross(this.a1,this.b1),e=this.cross.lengthSquared());d!=2&&(this.a2.set1(b.localPointA),
this.a2.sub1(this.pointCache[0].localPointA),this.b2.set1(this.pointCache[3].localPointA),this.b2.sub1(this.pointCache[1].localPointA),this.cross.cross(this.a2,this.b2),f=this.cross.lengthSquared());d!=3&&(this.a3.set1(b.localPointA),this.a3.sub1(this.pointCache[0].localPointA),this.b3.set1(this.pointCache[2].localPointA),this.b3.sub1(this.pointCache[1].localPointA),this.cross.cross(this.a3,this.b3),g=this.cross.lengthSquared());this.maxvec.set4(c,e,f,g);return a.VectorUtil.closestAxis4(this.maxvec)};
a.PersistentManifold.prototype.getCacheEntry=function(b){var d=a.BulletGlobals.contactBreakingThreshold*a.BulletGlobals.contactBreakingThreshold,c=this.cachedPoints,e=-1;this.diffA.set3(0,0,0);for(var f=0;f<c;f++){this.diffA.sub2(this.pointCache[f].localPointA,b.localPointA);var g=this.diffA.dot(this.diffA);g<d&&(d=g,e=f)}return e};a.PersistentManifold.prototype.addManifoldPoint=function(b){var a=this.cachedPoints;a==this.MANIFOLD_CACHE_SIZE?a=this.MANIFOLD_CACHE_SIZE>=4?this.sortCachedPoints(b):
0:this.cachedPoints++;this.pointCache[a].set(b);return a};a.PersistentManifold.prototype.removeContactPoint=function(b){var a=this.cachedPoints-1;if(b!=a)this.pointCache[b].set(this.pointCache[a]),this.pointCache[a].userPersistentData=null,this.pointCache[a].appliedImpulse=0,this.pointCache[a].lateralFrictionInitialized=!1,this.pointCache[a].appliedImpulseLateral1=0,this.pointCache[a].appliedImpulseLateral2=0,this.pointCache[a].lifeTime=0;this.cachedPoints--};a.PersistentManifold.prototype.replaceContactPoint=
function(b,a){var c=this.pointCache[a].lifeTime,e=this.pointCache[a].appliedImpulse,f=this.pointCache[a].appliedImpulseLateral1,g=this.pointCache[a].appliedImpulseLateral2,h=this.pointCache[a].userPersistentData;this.pointCache[a].set(b);this.pointCache[a].userPersistentData=h;this.pointCache[a].appliedImpulse=e;this.pointCache[a].appliedImpulseLateral1=f;this.pointCache[a].appliedImpulseLateral2=g;this.pointCache[a].lifeTime=c};a.PersistentManifold.prototype.validContactDistance=function(b){return b.distance1<=
a.BulletGlobals.contactBreakingThreshold};a.PersistentManifold.prototype.refreshContactPoints=function(b,d){this.tmp.set3(0,0,0);var c;for(c=this.cachedPoints-1;c>=0;c--){var e=this.pointCache[c];e.positionWorldOnA.set1(e.localPointA);b.transform(e.positionWorldOnA);e.positionWorldOnB.set1(e.localPointB);d.transform(e.positionWorldOnB);this.tmp.set1(e.positionWorldOnA);this.tmp.sub1(e.positionWorldOnB);e.distance1=this.tmp.dot(e.normalWorldOnB);e.lifeTime++}this.projectedDifference.set3(0,0,0);this.projectedPoint.set3(0,
0,0);for(c=this.cachedPoints-1;c>=0;c--)e=this.pointCache[c],this.validContactDistance(e)?(this.tmp.scale2(e.distance1,e.normalWorldOnB),this.projectedPoint.sub2(e.positionWorldOnA,this.tmp),this.projectedDifference.sub2(e.positionWorldOnB,this.projectedPoint),e=this.projectedDifference.dot(this.projectedDifference),e>a.BulletGlobals.contactBreakingThreshold*a.BulletGlobals.contactBreakingThreshold&&this.removeContactPoint(c)):this.removeContactPoint(c)};a.PersistentManifold.prototype.clearManifold=
function(){this.cachedPoints=0};a.PersistentManifold.prototype.toString=function(){return"PersistentManifold("+this.cachedPoints+","+this.pointCache[0]+"..)"};a.ClosestPointInput=function(){this.transformA=new a.Transform;this.transformB=new a.Transform;this.init()};a.ClosestPointInput.prototype.maximumDistanceSquared=0;a.ClosestPointInput.prototype.init=function(){this.maximumDistanceSquared=Number.MAX_VALUE};a.ClosestPointInput.prototype.toString=function(){return"ClosestPointInput("+this.maximumDistanceSquared+
","+this.transformA+","+this.transformB+")"};a.UsageBitfield=function(){};a.UsageBitfield.prototype.usedVertexA=!1;a.UsageBitfield.prototype.usedVertexB=!1;a.UsageBitfield.prototype.usedVertexC=!1;a.UsageBitfield.prototype.usedVertexD=!1;a.UsageBitfield.prototype.reset=function(){this.usedVertexD=this.usedVertexC=this.usedVertexB=this.usedVertexA=!1};a.SubSimplexClosestResult=function(){this.closestPointOnSimplex=new Vecmath.Vec3;this.usedVertices=new a.UsageBitfield;this.barycentricCoords=Array(4)};
a.SubSimplexClosestResult.prototype.degenerate=!1;a.SubSimplexClosestResult.prototype.reset=function(){this.degenerate=!1;this.setBarycentricCoordinates(0,0,0,0);this.usedVertices.reset()};a.SubSimplexClosestResult.prototype.isValid=function(){return this.barycentricCoords[0]>=0&&this.barycentricCoords[1]>=0&&this.barycentricCoords[2]>=0&&this.barycentricCoords[3]>=0};a.SubSimplexClosestResult.prototype.setBarycentricCoordinates=function(b,a,c,e){this.barycentricCoords[0]=b;this.barycentricCoords[1]=
a;this.barycentricCoords[2]=c;this.barycentricCoords[3]=e};a.poolSubSimplexClosestResult=new a.ObjectPool(function(){return new a.SubSimplexClosestResult});a.SimplexSolver=function(){this.simplexVectorW=Array(a.SimplexSolver.prototype.VORONOI_SIMPLEX_MAX_VERTS);this.simplexPointsP=Array(a.SimplexSolver.prototype.VORONOI_SIMPLEX_MAX_VERTS);this.simplexPointsQ=Array(a.SimplexSolver.prototype.VORONOI_SIMPLEX_MAX_VERTS);this.cachedP1=new Vecmath.Vec3;this.cachedP2=new Vecmath.Vec3;this.cachedV=new Vecmath.Vec3;
this.lastW=new Vecmath.Vec3;this.cachedBC=new a.SubSimplexClosestResult;this.tmp=new Vecmath.Vec3;this.nearest=new Vecmath.Vec3;this.p=new Vecmath.Vec3;this.diff=new Vecmath.Vec3;this.v=new Vecmath.Vec3;this.tmp1=new Vecmath.Vec3;this.tmp2=new Vecmath.Vec3;this.tmp3=new Vecmath.Vec3;this.tmp4=new Vecmath.Vec3;this.ab=new Vecmath.Vec3;this.ac=new Vecmath.Vec3;this.ap=new Vecmath.Vec3;this.bp=new Vecmath.Vec3;this.cp=new Vecmath.Vec3;this.tmp_=new Vecmath.Vec3;this.normal=new Vecmath.Vec3;this.q=new Vecmath.Vec3;
for(var b=0;b<this.VORONOI_SIMPLEX_MAX_VERTS;b++)this.simplexVectorW[b]=new Vecmath.Vec3,this.simplexPointsP[b]=new Vecmath.Vec3,this.simplexPointsQ[b]=new Vecmath.Vec3};a.SimplexSolver.prototype.subsimplexResultsPool=a.poolSubSimplexClosestResult;a.SimplexSolver.prototype.VORONOI_SIMPLEX_MAX_VERTS=5;a.SimplexSolver.VERTA=0;a.SimplexSolver.VERTB=1;a.SimplexSolver.VERTC=2;a.SimplexSolver.VERTD=3;a.SimplexSolver.prototype.numVertices=0;a.SimplexSolver.prototype.cachedValidClosest=!1;a.SimplexSolver.prototype.needsUpdate=
!1;a.SimplexSolver.prototype.removeVertex=function(b){this.numVertices--;this.simplexVectorW[b].set1(this.simplexVectorW[this.numVertices]);this.simplexPointsP[b].set1(this.simplexPointsP[this.numVertices]);this.simplexPointsQ[b].set1(this.simplexPointsQ[this.numVertices])};a.SimplexSolver.prototype.reduceVertices=function(b){this.numVertices>=4&&!b.usedVertexD&&this.removeVertex(3);this.numVertices>=3&&!b.usedVertexC&&this.removeVertex(2);this.numVertices>=2&&!b.usedVertexB&&this.removeVertex(1);
this.numVertices>=1&&!b.usedVertexA&&this.removeVertex(0)};a.SimplexSolver.prototype.updateClosestVectorAndPoints=function(){if(this.needsUpdate)switch(this.cachedBC.reset(),this.needsUpdate=!1,this.numVertices){case 0:this.cachedValidClosest=!1;break;case 1:this.cachedP1.set1(this.simplexPointsP[0]);this.cachedP2.set1(this.simplexPointsQ[0]);this.cachedV.sub2(this.cachedP1,this.cachedP2);this.cachedBC.reset();this.cachedBC.setBarycentricCoordinates(1,0,0,0);this.cachedValidClosest=this.cachedBC.isValid();
break;case 2:this.tmp.set3(0,0,0);var b=this.simplexVectorW[0],d=this.simplexVectorW[1];this.nearest.set3(0,0,0);this.p.set3(0,0,0);this.diff.set3(0,0,0);this.diff.sub2(this.p,b);this.v.set3(0,0,0);this.v.sub2(d,b);d=this.v.dot(this.diff);if(d>0){var c=this.v.dot(this.v);d<c?(d/=c,this.tmp.scale2(d,this.v),this.diff.sub1(this.tmp),this.cachedBC.usedVertices.usedVertexA=!0):(d=1,this.diff.sub1(this.v));this.cachedBC.usedVertices.usedVertexB=!0}else d=0,this.cachedBC.usedVertices.usedVertexA=!0;this.cachedBC.setBarycentricCoordinates(1-
d,d,0,0);this.tmp.scale2(d,this.v);this.nearest.add2(b,this.tmp);this.tmp.sub2(this.simplexPointsP[1],this.simplexPointsP[0]);this.tmp.scale1(d);this.cachedP1.add2(this.simplexPointsP[0],this.tmp);this.tmp.sub2(this.simplexPointsQ[1],this.simplexPointsQ[0]);this.tmp.scale1(d);this.cachedP2.add2(this.simplexPointsQ[0],this.tmp);this.cachedV.sub2(this.cachedP1,this.cachedP2);this.reduceVertices(this.cachedBC.usedVertices);this.cachedValidClosest=this.cachedBC.isValid();break;case 3:this.tmp1.set3(0,
0,0);this.tmp2.set3(0,0,0);this.tmp3.set3(0,0,0);this.p.set3(0,0,0);b=this.simplexVectorW[0];d=this.simplexVectorW[1];c=this.simplexVectorW[2];this.closestPtPointTriangle(this.p,b,d,c,this.cachedBC);this.tmp1.scale2(this.cachedBC.barycentricCoords[0],this.simplexPointsP[0]);this.tmp2.scale2(this.cachedBC.barycentricCoords[1],this.simplexPointsP[1]);this.tmp3.scale2(this.cachedBC.barycentricCoords[2],this.simplexPointsP[2]);a.VectorUtil.add(this.cachedP1,this.tmp1,this.tmp2,this.tmp3);this.tmp1.scale2(this.cachedBC.barycentricCoords[0],
this.simplexPointsQ[0]);this.tmp2.scale2(this.cachedBC.barycentricCoords[1],this.simplexPointsQ[1]);this.tmp3.scale2(this.cachedBC.barycentricCoords[2],this.simplexPointsQ[2]);a.VectorUtil.add(this.cachedP2,this.tmp1,this.tmp2,this.tmp3);this.cachedV.sub2(this.cachedP1,this.cachedP2);this.reduceVertices(this.cachedBC.usedVertices);this.cachedValidClosest=this.cachedBC.isValid();break;case 4:this.tmp1.set3(0,0,0);this.tmp2.set3(0,0,0);this.tmp3.set3(0,0,0);this.tmp4.set3(0,0,0);this.p.set3(0,0,0);
b=this.simplexVectorW[0];d=this.simplexVectorW[1];c=this.simplexVectorW[2];if(this.closestPtPointTetrahedron(this.p,b,d,c,this.simplexVectorW[3],this.cachedBC))this.tmp1.scale2(this.cachedBC.barycentricCoords[0],this.simplexPointsP[0]),this.tmp2.scale2(this.cachedBC.barycentricCoords[1],this.simplexPointsP[1]),this.tmp3.scale2(this.cachedBC.barycentricCoords[2],this.simplexPointsP[2]),this.tmp4.scale2(this.cachedBC.barycentricCoords[3],this.simplexPointsP[3]),a.VectorUtil.add(this.cachedP1,this.tmp1,
this.tmp2,this.tmp3,this.tmp4),this.tmp1.scale2(this.cachedBC.barycentricCoords[0],this.simplexPointsQ[0]),this.tmp2.scale2(this.cachedBC.barycentricCoords[1],this.simplexPointsQ[1]),this.tmp3.scale2(this.cachedBC.barycentricCoords[2],this.simplexPointsQ[2]),this.tmp4.scale2(this.cachedBC.barycentricCoords[3],this.simplexPointsQ[3]),a.VectorUtil.add(this.cachedP2,this.tmp1,this.tmp2,this.tmp3,this.tmp4),this.cachedV.sub2(this.cachedP1,this.cachedP2),this.reduceVertices(this.cachedBC.usedVertices);
else{this.cachedBC.degenerate?this.cachedValidClosest=!1:(this.cachedValidClosest=!0,this.cachedV.set3(0,0,0));break}this.cachedValidClosest=this.cachedBC.isValid();break;default:this.cachedValidClosest=!1}return this.cachedValidClosest};a.SimplexSolver.prototype.closestPtPointTriangle=function(b,d,c,e,f){f.usedVertices.reset();this.ab.set3(0,0,0);this.ab.sub2(c,d);this.ac.set3(0,0,0);this.ac.sub2(e,d);this.ap.set3(0,0,0);this.ap.sub2(b,d);var g=this.ab.dot(this.ap),h=this.ac.dot(this.ap);if(g<=0&&
h<=0)return f.closestPointOnSimplex.set1(d),f.usedVertices.usedVertexA=!0,f.setBarycentricCoordinates(1,0,0,0),!0;this.bp.set3(0,0,0);this.bp.sub2(b,c);var j=this.ab.dot(this.bp),i=this.ac.dot(this.bp);if(j>=0&&i<=j)return f.closestPointOnSimplex.set1(c),f.usedVertices.usedVertexB=!0,f.setBarycentricCoordinates(0,1,0,0),!0;var m=g*i-j*h;if(m<=0&&g>=0&&j<=0)return c=g/(g-j),f.closestPointOnSimplex.scaleAdd(c,this.ab,d),f.usedVertices.usedVertexA=!0,f.usedVertices.usedVertexB=!0,f.setBarycentricCoordinates(1-
c,c,0,0),!0;this.cp.set3(0,0,0);this.cp.sub2(b,e);var b=this.ab.dot(this.cp),k=this.ac.dot(this.cp);if(k>=0&&b<=k)return f.closestPointOnSimplex.set1(e),f.usedVertices.usedVertexC=!0,f.setBarycentricCoordinates(0,0,1,0),!0;g=b*h-g*k;if(g<=0&&h>=0&&k<=0)return m=h/(h-k),f.closestPointOnSimplex.scaleAdd(m,this.ac,d),f.usedVertices.usedVertexA=!0,f.usedVertices.usedVertexC=!0,f.setBarycentricCoordinates(1-m,0,m,0),!0;h=j*k-b*i;if(h<=0&&i-j>=0&&b-k>=0)return m=(i-j)/(i-j+(b-k)),this.tmp.set3(0,0,0),this.tmp.sub2(e,
c),f.closestPointOnSimplex.scaleAdd(m,this.tmp,c),f.usedVertices.usedVertexB=!0,f.usedVertices.usedVertexC=!0,f.setBarycentricCoordinates(0,1-m,m,0),!0;e=1/(h+g+m);c=g*e;m*=e;this.tmp1.set3(0,0,0);this.tmp2.set3(0,0,0);this.tmp1.scale2(c,this.ab);this.tmp2.scale2(m,this.ac);a.VectorUtil.add(f.closestPointOnSimplex,d,this.tmp1,this.tmp2);f.usedVertices.usedVertexA=!0;f.usedVertices.usedVertexB=!0;f.usedVertices.usedVertexC=!0;f.setBarycentricCoordinates(1-c-m,c,m,0);return!0};a.SimplexSolver.prototype.pointOutsideOfPlane=
function(b,a,c,e,f){var g=this.tmp_;g.set3(0,0,0);this.normal.set3(0,0,0);this.normal.sub2(c,a);g.sub2(e,a);this.normal.cross(this.normal,g);g.sub2(b,a);b=g.dot(this.normal);g.sub2(f,a);a=g.dot(this.normal);if(a*a<1.0E-8)return-1;return b*a<0?1:0};a.SimplexSolver.prototype.closestPtPointTetrahedron=function(b,d,c,e,f,g){var h=this.subsimplexResultsPool.get();h.reset();try{this.tmp.set3(0,0,0);this.q.set3(0,0,0);g.closestPointOnSimplex.set1(b);g.usedVertices.reset();g.usedVertices.usedVertexA=!0;g.usedVertices.usedVertexB=
!0;g.usedVertices.usedVertexC=!0;g.usedVertices.usedVertexD=!0;var j=this.pointOutsideOfPlane(b,d,c,e,f),i=this.pointOutsideOfPlane(b,d,e,f,c),m=this.pointOutsideOfPlane(b,d,f,c,e),k=this.pointOutsideOfPlane(b,c,f,e,d);if(j<0||i<0||m<0||k<0)return g.degenerate=!0,!1;if(j==0&&i==0&&m==0&&k==0)return!1;var l=Number.MAX_VALUE;if(j!=0){this.closestPtPointTriangle(b,d,c,e,h);this.q.set1(h.closestPointOnSimplex);this.tmp.sub2(this.q,b);var o=this.tmp.dot(this.tmp);if(o<l)l=o,g.closestPointOnSimplex.set1(this.q),
g.usedVertices.reset(),g.usedVertices.usedVertexA=h.usedVertices.usedVertexA,g.usedVertices.usedVertexB=h.usedVertices.usedVertexB,g.usedVertices.usedVertexC=h.usedVertices.usedVertexC,g.setBarycentricCoordinates(h.barycentricCoords[a.SimplexSolver.VERTA],h.barycentricCoords[a.SimplexSolver.VERTB],h.barycentricCoords[a.SimplexSolver.VERTC],0)}if(i!=0&&(this.closestPtPointTriangle(b,d,e,f,h),this.q.set1(h.closestPointOnSimplex),this.tmp.sub2(this.q,b),o=this.tmp.dot(this.tmp),o<l))l=o,g.closestPointOnSimplex.set1(this.q),
g.usedVertices.reset(),g.usedVertices.usedVertexA=h.usedVertices.usedVertexA,g.usedVertices.usedVertexC=h.usedVertices.usedVertexB,g.usedVertices.usedVertexD=h.usedVertices.usedVertexC,g.setBarycentricCoordinates(h.barycentricCoords[a.SimplexSolver.VERTA],0,h.barycentricCoords[a.SimplexSolver.VERTB],h.barycentricCoords[a.SimplexSolver.VERTC]);if(m!=0&&(this.closestPtPointTriangle(b,d,f,c,h),this.q.set1(h.closestPointOnSimplex),this.tmp.sub2(this.q,b),o=this.tmp.dot(this.tmp),o<l))l=o,g.closestPointOnSimplex.set1(this.q),
g.usedVertices.reset(),g.usedVertices.usedVertexA=h.usedVertices.usedVertexA,g.usedVertices.usedVertexB=h.usedVertices.usedVertexC,g.usedVertices.usedVertexD=h.usedVertices.usedVertexB,g.setBarycentricCoordinates(h.barycentricCoords[a.SimplexSolver.VERTA],h.barycentricCoords[a.SimplexSolver.VERTC],0,h.barycentricCoords[a.SimplexSolver.VERTB]);if(k!=0&&(this.closestPtPointTriangle(b,c,f,e,h),this.q.set1(h.closestPointOnSimplex),this.tmp.sub2(this.q,b),o=this.tmp.dot(this.tmp),o<l))g.closestPointOnSimplex.set1(this.q),
g.usedVertices.reset(),g.usedVertices.usedVertexB=h.usedVertices.usedVertexA,g.usedVertices.usedVertexC=h.usedVertices.usedVertexC,g.usedVertices.usedVertexD=h.usedVertices.usedVertexB,g.setBarycentricCoordinates(0,h.barycentricCoords[a.SimplexSolver.VERTA],h.barycentricCoords[a.SimplexSolver.VERTC],h.barycentricCoords[a.SimplexSolver.VERTB]);return!0}finally{this.subsimplexResultsPool.release(h)}};a.SimplexSolver.prototype.reset=function(){this.cachedValidClosest=!1;this.numVertices=0;this.needsUpdate=
!0;this.lastW.set3(1.0E30,1.0E30,1.0E30);this.cachedBC.reset()};a.SimplexSolver.prototype.addVertex=function(b,a,c){this.lastW.set1(b);this.needsUpdate=!0;this.simplexVectorW[this.numVertices].set1(b);this.simplexPointsP[this.numVertices].set1(a);this.simplexPointsQ[this.numVertices].set1(c);this.numVertices++};a.SimplexSolver.prototype.closest=function(b){var a=this.updateClosestVectorAndPoints();b.set1(this.cachedV);return a};a.SimplexSolver.prototype.fullSimplex=function(){return this.numVertices==
4};a.SimplexSolver.prototype.inSimplex=function(b){var a=!1,c,e=this.numVertices;for(c=0;c<e;c++)this.simplexVectorW[c].equals(b)&&(a=!0);if(b.equals(this.lastW))return!0;return a};a.SimplexSolver.prototype.backup_closest=function(b){b.set1(this.cachedV)};a.SimplexSolver.prototype.compute_points=function(b,a){this.updateClosestVectorAndPoints();b.set1(this.cachedP1);a.set1(this.cachedP2)};a.ResultsStatus={Separated:0,Penetrating:1,GJK_Failed:2,EPA_Failed:3};a.Results=function(){this.witnesses=[new Vecmath.Vec3,
new Vecmath.Vec3];this.normal=new Vecmath.Vec3};a.Results.prototype.depth=0;a.Results.prototype.epa_iterations=0;a.Results.prototype.gjk_iterations=0;a.Mkv=function(){this.w=new Vecmath.Vec3;this.r=new Vecmath.Vec3};a.Mkv.prototype.set=function(b){this.w.set1(b.w);this.r.set1(b.r)};a.He=function(){this.v=new Vecmath.Vec3};a.GJK=function(b){this.table=Array(a.GJK.GJK_hashsize);this.wrotations=[new Vecmath.Mat3,new Vecmath.Mat3];this.positions=[new Vecmath.Vec3,new Vecmath.Vec3];this.shapes=Array(2);
this.simplex=Array(5);this.ray=new Vecmath.Vec3;this.tmp=new Vecmath.Vec3;this.tmp1=new Vecmath.Vec3;this.tmp2=new Vecmath.Vec3;this.tmp_=new Vecmath.Vec3;this.cabo=new Vecmath.Vec3;this.tmps=new Vecmath.Vec3;this.tmp2s=new Vecmath.Vec3;this.crs=new Vecmath.Vec3;this.tmp3=new Vecmath.Vec3;this.tso=new Vecmath.Vec3;this.tso1=new Vecmath.Vec3;this.tso2=new Vecmath.Vec3;this.tso3=new Vecmath.Vec3;this.tso4=new Vecmath.Vec3;this.eo=new Vecmath.Vec3;this.eo1=new Vecmath.Vec3;this.eo2=new Vecmath.Vec3;
this.ab=new Vecmath.Vec3;this.w=new Vecmath.Vec3;this.n=new Vecmath.Vec3;this.b=[new Vecmath.Vec3,new Vecmath.Vec3,new Vecmath.Vec3];this.tmpQuat=new Vecmath.Quat4;this.r=new Vecmath.Mat3;this.slvr=b;for(b=0;b<this.simplex.length;b++)this.simplex[b]=new a.Mkv};a.GJK.GJK_hashsize=64;a.GJK.prototype.order=0;a.GJK.prototype.iterations=0;a.GJK.prototype.margin=0;a.GJK.prototype.failed=!1;a.GJK.prototype.init=function(b,a,c,e,f,g,h){this.slvr.pushStack();this.wrotations[0].set1(b);this.positions[0].set1(a);
this.shapes[0]=c;this.wrotations[1].set1(e);this.positions[1].set1(f);this.shapes[1]=g;this.margin=h;this.failed=!1};a.GJK.prototype.destroy=function(){this.slvr.popStack()};a.GJK.prototype.Hash=function(b){return(Math.floor(b.x*15461)^Math.floor(b.y*83003)^Math.floor(b.z*15473))*169639&a.GjkEpaSolver.GJK_hashmask};a.GJK.prototype.LocalSupport=function(b,d,c){this.tmp.set3(0,0,0);a.MatrixUtil.transposeTransform(this.tmp,b,this.wrotations[d]);this.shapes[d].localGetSupportingVertex(this.tmp,c);this.wrotations[d].transform1(c);
c.add1(this.positions[d]);return c};a.GJK.prototype.Support=function(b,a){a.r.set1(b);this.tmp1.set3(0,0,0);this.tmp1=this.LocalSupport(b,0,this.tmp1);var c=this.tmp_;c.set1(b);c.negate0();this.tmp2.set3(0,0,0);this.tmp2=this.LocalSupport(c,1,this.tmp2);a.w.sub2(this.tmp1,this.tmp2);a.w.scaleAdd(this.margin,b,a.w)};a.GJK.prototype.FetchSupport=function(){for(var b=this.Hash(this.ray),a=this.table[b];a!=null;)if(a.v.equals(this.ray))return--this.order,!1;else a=a.n;a=this.slvr.stackHe.get();a.v.set1(this.ray);
a.n=this.table[b];this.table[b]=a;this.Support(this.ray,this.simplex[++this.order]);return this.ray.dot(this.simplex[this.order].w)>0};a.GJK.prototype.SolveSimplex2=function(b,d){if(d.dot(b)>=0)if(this.cabo.set3(0,0,0),this.cabo.cross(d,b),this.cabo.lengthSquared()>a.GjkEpaSolver.GJK_sqinsimplex_eps)this.ray.cross(this.cabo,d);else return!0;else this.order=0,this.simplex[0].set(this.simplex[1]),this.ray.set1(b);return!1};a.GJK.prototype.SolveSimplex3=function(a,d,c){this.tmp.set3(0,0,0);this.tmp.cross(d,
c);return this.SolveSimplex3a(a,d,c,this.tmp)};a.GJK.prototype.SolveSimplex3a=function(b,d,c,e){var f=this.tmps;f.set3(0,0,0);f.cross(e,d);var g=this.tmp2s;g.set3(0,0,0);g.cross(e,c);return f.dot(b)<-a.GjkEpaSolver.GJK_insimplex_eps?(this.order=1,this.simplex[0].set(this.simplex[1]),this.simplex[1].set(this.simplex[2]),this.SolveSimplex2(b,d)):g.dot(b)>+a.GjkEpaSolver.GJK_insimplex_eps?(this.order=1,this.simplex[1].set(this.simplex[2]),this.SolveSimplex2(b,c)):(b=e.dot(b),Math.abs(b)>a.GjkEpaSolver.GJK_insimplex_eps?
(b>0?this.ray.set1(e):(this.ray.negate1(e),e=new a.Mkv,e.set(this.simplex[0]),this.simplex[0].set(this.simplex[1]),this.simplex[1].set(e)),!1):!0)};a.GJK.prototype.SolveSimplex4=function(b,d,c,e){this.crs.set3(0,0,0);this.tmp.set3(0,0,0);this.tmp.cross(d,c);this.tmp2.set3(0,0,0);this.tmp2.cross(c,e);this.tmp3.set3(0,0,0);this.tmp3.cross(e,d);return this.tmp.dot(b)>a.GjkEpaSolver.GJK_insimplex_eps?(this.crs.set1(this.tmp),this.order=2,this.simplex[0].set(this.simplex[1]),this.simplex[1].set(this.simplex[2]),
this.simplex[2].set(this.simplex[3]),this.SolveSimplex3a(b,d,c,this.crs)):this.tmp2.dot(b)>a.GjkEpaSolver.GJK_insimplex_eps?(this.crs.set1(this.tmp2),this.order=2,this.simplex[2].set(this.simplex[3]),this.SolveSimplex3a(b,c,e,this.crs)):this.tmp3.dot(b)>a.GjkEpaSolver.GJK_insimplex_eps?(this.crs.set1(this.tmp3),this.order=2,this.simplex[1].set(this.simplex[0]),this.simplex[0].set(this.simplex[2]),this.simplex[2].set(this.simplex[3]),this.SolveSimplex3a(b,e,d,this.crs)):!0};a.GJK.prototype.SearchOrigin=
function(){var a=this.tso;a.set3(1,0,0);return this.SearchOrigin1(a)};a.GJK.prototype.SearchOrigin1=function(b){var d=this.tso1;d.set3(0,0,0);var c=this.tso2;c.set3(0,0,0);var e=this.tso3;e.set3(0,0,0);var f=this.tso4;f.set3(0,0,0);this.iterations=0;this.order=-1;this.failed=!1;this.ray.set1(b);this.ray.normalize();a.arrayFill(this.table,null);this.FetchSupport();for(this.ray.negate1(this.simplex[0].w);this.iterations<a.GjkEpaSolver.GJK_maxiterations;++this.iterations)if(b=this.ray.length(),this.ray.scale1(1/
(b>0?b:1)),this.FetchSupport()){b=!1;switch(this.order){case 1:d.negate1(this.simplex[1].w);c.sub2(this.simplex[0].w,this.simplex[1].w);b=this.SolveSimplex2(d,c);break;case 2:d.negate1(this.simplex[2].w);c.sub2(this.simplex[1].w,this.simplex[2].w);e.sub2(this.simplex[0].w,this.simplex[2].w);b=this.SolveSimplex3(d,c,e);break;case 3:d.negate1(this.simplex[3].w),c.sub2(this.simplex[2].w,this.simplex[3].w),e.sub2(this.simplex[1].w,this.simplex[3].w),f.sub2(this.simplex[0].w,this.simplex[3].w),b=this.SolveSimplex4(d,
c,e,f)}if(b)return!0}else return!1;this.failed=!0;return!1};a.GJK.prototype.EncloseOrigin=function(){var a=this.eo;a.set3(0,0,0);var d=this.eo1;d.set3(0,0,0);var c=this.eo2;c.set3(0,0,0);switch(this.order){case 2:return d.sub2(this.simplex[1].w,this.simplex[0].w),c.sub2(this.simplex[2].w,this.simplex[0].w),this.n.set3(0,0,0),this.n.cross(d,c),this.n.normalize(),this.Support(this.n,this.simplex[3]),a.negate1(this.n),this.Support(a,this.simplex[4]),this.order=4,!0;case 3:return!0;case 4:return!0}return!1};
a.Face=function(){this.v=Array(3);this.f=Array(3);this.e=Array(3);this.n=new Vecmath.Vec3};a.Face.prototype.d=0;a.Face.prototype.mark=0;a.EPA=function(a,d){this.features=[[new Vecmath.Vec3,new Vecmath.Vec3,new Vecmath.Vec3],[new Vecmath.Vec3,new Vecmath.Vec3,new Vecmath.Vec3]];this.nearest=[new Vecmath.Vec3,new Vecmath.Vec3];this.normal=new Vecmath.Vec3;this.tmp=new Vecmath.Vec3;this.tmp1=new Vecmath.Vec3;this.tmp2=new Vecmath.Vec3;this.o=new Vecmath.Vec3;this.tmp3=new Vecmath.Vec3;this.nrm=new Vecmath.Vec3;
this.b=new Vecmath.Vec3;this.gjk=a;this.slvr=d};a.EPA.prototype.nfaces=0;a.EPA.prototype.iterations=0;a.EPA.prototype.depth=0;a.EPA.prototype.failed=!1;a.EPA.prototype.GetCoordinates=function(a,d){this.tmp.set3(0,0,0);this.tmp1.set3(0,0,0);this.tmp2.set3(0,0,0);this.o.set3(0,0,0);this.o.scale2(-a.d,a.n);var c=this.slvr.floatArrays.getFixed(3);this.tmp1.sub2(a.v[0].w,this.o);this.tmp2.sub2(a.v[1].w,this.o);this.tmp.cross(this.tmp1,this.tmp2);c[0]=this.tmp.length();this.tmp1.sub2(a.v[1].w,this.o);this.tmp2.sub2(a.v[2].w,
this.o);this.tmp.cross(this.tmp1,this.tmp2);c[1]=this.tmp.length();this.tmp1.sub2(a.v[2].w,this.o);this.tmp2.sub2(a.v[0].w,this.o);this.tmp.cross(this.tmp1,this.tmp2);c[2]=this.tmp.length();var e=c[0]+c[1]+c[2];d.set3(c[1],c[2],c[0]);d.scale1(1/(e>0?e:1));this.slvr.floatArrays.release(c);return d};a.EPA.prototype.FindBest=function(){var b=null;if(this.root!=null){var d=this.root,c=a.GjkEpaSolver.cstInf;do if(d.d<c)c=d.d,b=d;while(null!=(d=d.next))}return b};a.EPA.prototype.Set=function(b,d,c,e){this.tmp1.set3(0,
0,0);this.tmp2.set3(0,0,0);this.tmp3.set3(0,0,0);this.nrm.set3(0,0,0);this.tmp1.sub2(c.w,d.w);this.tmp2.sub2(e.w,d.w);this.nrm.cross(this.tmp1,this.tmp2);var f=this.nrm.length();this.tmp1.cross(d.w,c.w);this.tmp2.cross(c.w,e.w);this.tmp3.cross(e.w,d.w);var g=this.tmp1.dot(this.nrm)>=-a.GjkEpaSolver.EPA_inface_eps&&this.tmp2.dot(this.nrm)>=-a.GjkEpaSolver.EPA_inface_eps&&this.tmp3.dot(this.nrm)>=-a.GjkEpaSolver.EPA_inface_eps;b.v[0]=d;b.v[1]=c;b.v[2]=e;b.mark=0;b.n.scale2(1/(f>0?f:a.GjkEpaSolver.cstInf),
this.nrm);b.d=Math.max(0,-b.n.dot(d.w));return g};a.EPA.prototype.NewFace=function(a,d,c){var e=this.slvr.stackFace.get();if(this.Set(e,a,d,c)){if(this.root!=null)this.root.prev=e;e.prev=null;e.next=this.root;this.root=e;++this.nfaces}else e.prev=e.next=null;return e};a.EPA.prototype.Detach=function(a){if(a.prev!=null||a.next!=null)--this.nfaces,a==this.root?(this.root=a.next,this.root.prev=null):a.next==null?a.prev.next=null:(a.prev.next=a.next,a.next.prev=a.prev),a.prev=a.next=null};a.EPA.prototype.Link=
function(a,d,c,e){a.f[d]=c;c.e[e]=d;c.f[e]=a;a.e[d]=e};a.EPA.prototype.Support=function(a){var d=this.slvr.stackMkv.get();this.gjk.Support(a,d);return d};a.EPA.prototype.BuildHorizon=function(b,d,c,e,f,g){var h=0;if(c.mark!=b){var j=a.GjkEpaSolver.mod3[e+1];c.n.dot(d.w)+c.d>0?(b=this.NewFace(c.v[j],c.v[e],d),this.Link(b,0,c,e),f[0]!=null?this.Link(f[0],1,b,2):g[0]=b,f[0]=b,h=1):(e=a.GjkEpaSolver.mod3[e+2],this.Detach(c),c.mark=b,h+=this.BuildHorizon(b,d,c.f[j],c.e[j],f,g),h+=this.BuildHorizon(b,d,
c.f[e],c.e[e],f,g))}return h};a.EPA.prototype.EvaluatePD0=function(){return this.EvaluatePD1(a.GjkEpaSolver.EPA_accuracy)};a.EPA.prototype.EvaluatePD1=function(b){this.slvr.pushStack();try{this.tmp.set3(0,0,0);var d=null,c=1;this.depth=-a.GjkEpaSolver.cstInf;this.normal.set3(0,0,0);this.root=null;this.iterations=this.nfaces=0;this.failed=!1;if(this.gjk.EncloseOrigin()){var e=null,f=0,g=0,h=null,j=0,i=0,m=Array(5),k=Array(6);switch(this.gjk.order){case 3:e=a.GjkEpaSolver.tetrahedron_fidx;f=0;g=4;h=
a.GjkEpaSolver.tetrahedron_eidx;j=0;i=6;break;case 4:e=a.GjkEpaSolver.hexahedron_fidx,f=0,g=6,h=a.GjkEpaSolver.hexahedron_eidx,j=0,i=9}var l;for(l=0;l<=this.gjk.order;++l)m[l]=new a.Mkv,m[l].set(this.gjk.simplex[l]);for(l=0;l<g;++l,f++)k[l]=this.NewFace(m[e[f][0]],m[e[f][1]],m[e[f][2]]);for(l=0;l<i;++l,j++)this.Link(k[h[j][0]],h[j][1],k[h[j][2]],h[j][3])}if(0==this.nfaces)return this.depth;for(;this.iterations<a.GjkEpaSolver.EPA_maxiterations;++this.iterations){var o=this.FindBest();if(o!=null){this.tmp.negate1(o.n);
var p=this.Support(this.tmp),n=o.n.dot(p.w)+o.d,d=o;if(n<-b){e=[null];f=[null];g=0;this.Detach(o);o.mark=++c;for(l=0;l<3;++l)g+=this.BuildHorizon(c,p,o.f[l],o.e[l],e,f);if(g<=2)break;this.Link(e[0],1,f[0],2)}else break}else break}if(d!=null){this.b.set3(0,0,0);this.b=this.GetCoordinates(d,this.b);this.normal.set1(d.n);this.depth=Math.max(0,d.d);for(l=0;l<2;++l){b=l!=0?-1:1;for(c=0;c<3;++c)this.tmp.scale2(b,d.v[c].r),this.gjk.LocalSupport(this.tmp,l,this.features[l][c])}this.tmp1.set3(0,0,0);this.tmp2.set3(0,
0,0);this.tmp3.set3(0,0,0);this.tmp1.scale2(this.b.x,this.features[0][0]);this.tmp2.scale2(this.b.y,this.features[0][1]);this.tmp3.scale2(this.b.z,this.features[0][2]);a.VectorUtil.add(this.nearest[0],this.tmp1,this.tmp2,this.tmp3);this.tmp1.scale2(this.b.x,this.features[1][0]);this.tmp2.scale2(this.b.y,this.features[1][1]);this.tmp3.scale2(this.b.z,this.features[1][2]);a.VectorUtil.add(this.nearest[1],this.tmp1,this.tmp2,this.tmp3)}else this.failed=!0;return this.depth}finally{this.slvr.popStack()}};
a.floatArrayPool=new a.ArrayPool;a.GjkEpaSolver=function(){this.gjk=new a.GJK(this)};a.GjkEpaSolver.GJK_hashsize=4;a.GjkEpaSolver.prototype.floatArrays=a.floatArrayPool;a.GjkEpaSolver.prototype.stackMkv=new a.ObjectStackList(function(){return new a.Mkv});a.GjkEpaSolver.prototype.stackHe=new a.ObjectStackList(function(){return new a.He});a.GjkEpaSolver.prototype.stackFace=new a.ObjectStackList(function(){return new a.Face});a.GjkEpaSolver.prototype.pushStack=function(){this.stackMkv.push();this.stackHe.push();
this.stackFace.push()};a.GjkEpaSolver.prototype.popStack=function(){this.stackMkv.pop();this.stackHe.pop();this.stackFace.pop()};a.GjkEpaSolver.cstInf=a.BulletGlobals.SIMD_INFINITY;a.GjkEpaSolver.cstPi=a.BulletGlobals.SIMD_PI;a.GjkEpaSolver.cst2Pi=a.BulletGlobals.SIMD_2_PI;a.GjkEpaSolver.GJK_maxiterations=128;a.GjkEpaSolver.GJK_hashsize=64;a.GjkEpaSolver.GJK_hashmask=a.GjkEpaSolver.GJK_hashsize-1;a.GjkEpaSolver.GJK_insimplex_eps=1.0E-4;a.GjkEpaSolver.GJK_sqinsimplex_eps=a.GjkEpaSolver.GJK_insimplex_eps*
a.GjkEpaSolver.GJK_insimplex_eps;a.GjkEpaSolver.EPA_maxiterations=256;a.GjkEpaSolver.EPA_inface_eps=0.01;a.GjkEpaSolver.EPA_accuracy=0.001;a.GjkEpaSolver.mod3=[0,1,2,0,1];a.GjkEpaSolver.tetrahedron_fidx=[[2,1,0],[3,0,1],[3,1,2],[3,2,0]];a.GjkEpaSolver.tetrahedron_eidx=[[0,0,2,1],[0,1,1,1],[0,2,3,1],[1,0,3,2],[2,0,1,2],[3,0,2,2]];a.GjkEpaSolver.hexahedron_fidx=[[2,0,4],[4,1,2],[1,4,0],[0,3,1],[0,2,3],[1,3,2]];a.GjkEpaSolver.hexahedron_eidx=[[0,0,4,0],[0,1,2,1],[0,2,1,2],[1,1,5,2],[1,0,2,0],[2,2,3,
2],[3,1,5,0],[3,0,4,2],[5,1,4,1]];a.GjkEpaSolver.prototype.collide=function(b,d,c,e,f,g){g.witnesses[0].set3(0,0,0);g.witnesses[1].set3(0,0,0);g.normal.set3(0,0,0);g.depth=0;g.status=a.ResultsStatus.Separated;g.epa_iterations=0;g.gjk_iterations=0;this.gjk.init(d.basis,d.origin,b,e.basis,e.origin,c,f+a.GjkEpaSolver.EPA_accuracy);try{var h=this.gjk.SearchOrigin();g.gjk_iterations=this.gjk.iterations+1;if(h){var j=new a.EPA(this.gjk,this),i=j.EvaluatePD0();g.epa_iterations=j.iterations+1;if(i>0)return g.status=
a.ResultsStatus.Penetrating,g.normal.set1(j.normal),g.depth=i,g.witnesses[0].set1(j.nearest[0]),g.witnesses[1].set1(j.nearest[1]),!0;else if(j.failed)g.status=a.ResultsStatus.EPA_Failed}else if(this.gjk.failed)g.status=a.ResultsStatus.GJK_Failed;return!1}finally{this.gjk.destroy()}};a.GjkEpaPenetrationDepthSolver=function(){this.gjkEpaSolver=new a.GjkEpaSolver};a.GjkEpaPenetrationDepthSolver.prototype.calcPenDepth=function(b,d,c,e,f,g,h,j){b=new a.Results;if(this.gjkEpaSolver.collide(d,e,c,f,0,b))return h.set1(b.witnesses[0]),
j.set1(b.witnesses[1]),!0;return!1};a.GjkPairDetector=function(){this.cachedSeparatingAxis=new Vecmath.Vec3;this.tmp=new Vecmath.Vec3;this.normalInB=new Vecmath.Vec3;this.pointOnA=new Vecmath.Vec3;this.pointOnB=new Vecmath.Vec3;this.positionOffset=new Vecmath.Vec3;this.seperatingAxisInA=new Vecmath.Vec3;this.seperatingAxisInB=new Vecmath.Vec3;this.pInA=new Vecmath.Vec3;this.qInB=new Vecmath.Vec3;this.pWorld=new Vecmath.Vec3;this.qWorld=new Vecmath.Vec3;this.w=new Vecmath.Vec3;this.tmpPointOnA=new Vecmath.Vec3;
this.tmpPointOnB=new Vecmath.Vec3;this.tmpNormalInB=new Vecmath.Vec3;this.localTransA=new a.Transform;this.localTransB=new a.Transform};a.GjkPairDetector.REL_ERROR2=1.0E-6;a.GjkPairDetector.prototype.ignoreMargin=!1;a.GjkPairDetector.prototype.lastUsedMethod=0;a.GjkPairDetector.prototype.curIter=0;a.GjkPairDetector.prototype.degenerateSimplex=0;a.GjkPairDetector.prototype.catchDegeneracies=0;a.GjkPairDetector.prototype.init=function(a,d,c,e){this.cachedSeparatingAxis.set3(0,0,1);this.ignoreMargin=
!1;this.lastUsedMethod=-1;this.catchDegeneracies=1;this.penetrationDepthSolver=e;this.simplexSolver=c;this.minkowskiA=a;this.minkowskiB=d};a.GjkPairDetector.prototype.getClosestPoints2=function(a,d){this.getClosestPoints(a,d,!1)};a.GjkPairDetector.prototype.getClosestPoints=function(b,d){this.tmp.set3(0,0,0);var c=0;this.normalInB.set3(0,0,0);this.pointOnA.set3(0,0,0);this.pointOnB.set3(0,0,0);this.localTransA.setT(b.transformA);this.localTransB.setT(b.transformB);this.positionOffset.set3(0,0,0);
this.positionOffset.add2(this.localTransA.origin,this.localTransB.origin);this.positionOffset.scale1(0.5);this.localTransA.origin.sub1(this.positionOffset);this.localTransB.origin.sub1(this.positionOffset);var e=this.minkowskiA.getMargin(),f=this.minkowskiB.getMargin();this.ignoreMargin&&(f=e=0);this.curIter=0;this.cachedSeparatingAxis.set3(0,1,0);var g=!1,h=!1,j=!0;this.degenerateSimplex=0;this.lastUsedMethod=-1;var i=a.BulletGlobals.SIMD_INFINITY,m=0,k=e+f;this.simplexSolver.reset();this.seperatingAxisInA.set3(0,
0,0);this.seperatingAxisInB.set3(0,0,0);this.pInA.set3(0,0,0);this.qInB.set3(0,0,0);this.pWorld.set3(0,0,0);this.qWorld.set3(0,0,0);this.w.set3(0,0,0);this.tmpPointOnA.set3(0,0,0);this.tmpPointOnB.set3(0,0,0);for(this.tmpNormalInB.set3(0,0,0);;){this.seperatingAxisInA.negate1(this.cachedSeparatingAxis);a.MatrixUtil.transposeTransform(this.seperatingAxisInA,this.seperatingAxisInA,b.transformA.basis);this.seperatingAxisInB.set1(this.cachedSeparatingAxis);a.MatrixUtil.transposeTransform(this.seperatingAxisInB,
this.seperatingAxisInB,b.transformB.basis);this.minkowskiA.localGetSupportingVertexWithoutMargin(this.seperatingAxisInA,this.pInA);this.minkowskiB.localGetSupportingVertexWithoutMargin(this.seperatingAxisInB,this.qInB);this.pWorld.set1(this.pInA);this.localTransA.transform(this.pWorld);this.qWorld.set1(this.qInB);this.localTransB.transform(this.qWorld);this.w.sub2(this.pWorld,this.qWorld);m=this.cachedSeparatingAxis.dot(this.w);if(m>0&&m*m>i*b.maximumDistanceSquared){j=!1;break}if(this.simplexSolver.inSimplex(this.w)){this.degenerateSimplex=
1;h=!0;break}m=i-m;if(m<=i*a.GjkPairDetector.REL_ERROR2){if(m<=0)this.degenerateSimplex=2;h=!0;break}this.simplexSolver.addVertex(this.w,this.pWorld,this.qWorld);if(!this.simplexSolver.closest(this.cachedSeparatingAxis)){this.degenerateSimplex=3;h=!0;break}if(this.cachedSeparatingAxis.lengthSquared()<a.GjkPairDetector.REL_ERROR2){this.degenerateSimplex=6;h=!0;break}m=i;i=this.cachedSeparatingAxis.lengthSquared();if(m-i<=a.BulletGlobals.FLT_EPSILON*m){this.simplexSolver.backup_closest(this.cachedSeparatingAxis);
h=!0;break}if(this.curIter++>1E3)break;if(this.simplexSolver.fullSimplex()){this.simplexSolver.backup_closest(this.cachedSeparatingAxis);break}}if(h){this.simplexSolver.compute_points(this.pointOnA,this.pointOnB);this.normalInB.sub2(this.pointOnA,this.pointOnB);h=this.cachedSeparatingAxis.lengthSquared();if(h<1.0E-4)this.degenerateSimplex=5;h>a.BulletGlobals.FLT_EPSILON*a.BulletGlobals.FLT_EPSILON?(c=1/Math.sqrt(h),this.normalInB.scale1(c),g=Math.sqrt(i),this.tmp.scale2(e/g,this.cachedSeparatingAxis),
this.pointOnA.sub1(this.tmp),this.tmp.scale2(f/g,this.cachedSeparatingAxis),this.pointOnB.add1(this.tmp),c=1/c-k,g=!0,this.lastUsedMethod=1):this.lastUsedMethod=2}e=this.catchDegeneracies!=0&&this.penetrationDepthSolver!=null&&this.degenerateSimplex!=0&&c+k<0.01;if(j&&(!g||e)&&this.penetrationDepthSolver!=null)if(this.penetrationDepthSolver.calcPenDepth(this.simplexSolver,this.minkowskiA,this.minkowskiB,this.localTransA,this.localTransB,this.cachedSeparatingAxis,this.tmpPointOnA,this.tmpPointOnB))if(this.tmpNormalInB.sub2(this.tmpPointOnB,
this.tmpPointOnA),h=this.tmpNormalInB.lengthSquared(),h>a.BulletGlobals.FLT_EPSILON*a.BulletGlobals.FLT_EPSILON){if(this.tmpNormalInB.scale1(1/Math.sqrt(h)),this.tmp.sub2(this.tmpPointOnA,this.tmpPointOnB),j=-this.tmp.length(),!g||j<c)c=j,this.pointOnA.set1(this.tmpPointOnA),this.pointOnB.set1(this.tmpPointOnB),this.normalInB.set1(this.tmpNormalInB),g=!0,this.lastUsedMethod=3}else this.lastUsedMethod=4;else this.lastUsedMethod=5;g&&(this.tmp.add2(this.pointOnB,this.positionOffset),d.addContactPoint(this.normalInB,
this.tmp,c))};a.CollisionShape=function(){};a.CollisionShape.prototype.userPointer=null;a.CollisionShape.prototype.toString=function(){return"CollisionShape"};a.ConvexShape=function(){};a.ConvexShape.prototype=new a.CollisionShape;a.ConvexShape.MAX_PREFERRED_PENETRATION_DIRECTIONS=10;a.ConvexShape.prototype.toString=function(){return"ConvexShape"};a.ConvexInternalShape=function(){};a.ConvexInternalShape.prototype=new a.ConvexShape;a.ConvexInternalShape.prototype.collisionMargin=a.BulletGlobals.CONVEX_DISTANCE_MARGIN;
a.ConvexInternalShape.prototype.getMargin=function(){return this.collisionMargin};a.ConvexInternalShape.prototype.toString=function(){return"ConvexInternalShape"};a.BoxShape=function(a){this.margin=new Vecmath.Vec3;this.halfExtents=new Vecmath.Vec3;this.abs_b=new Vecmath.Mat3;this.tmp=new Vecmath.Vec3;this.center=new Vecmath.Vec3;this.extent=new Vecmath.Vec3;this.implicitShapeDimensions=new Vecmath.Vec3;var d=new Vecmath.Vec3(this.getMargin(),this.getMargin(),this.getMargin());this.implicitShapeDimensions.set1(a);
this.implicitShapeDimensions.sub1(d)};a.BoxShape.prototype=new a.ConvexInternalShape;a.BoxShape.prototype.getHalfExtentsWithMargin=function(a){var d=this.getHalfExtentsWithoutMargin(a);this.margin.set3(0,0,0);this.margin.set3(this.getMargin(),this.getMargin(),this.getMargin());d.add1(this.margin);return a};a.BoxShape.prototype.getHalfExtentsWithoutMargin=function(a){a.set1(this.implicitShapeDimensions);return a};a.BoxShape.prototype.getShapeType=function(){return a.BroadphaseNativeType.BOX_SHAPE_PROXYTYPE};
a.BoxShape.prototype.localGetSupportingVertex=function(b,d){var c=this.getHalfExtentsWithoutMargin(d),e=this.getMargin();c.x+=e;c.y+=e;c.z+=e;d.set3(a.ScalarUtil.fsel(b.x,c.x,-c.x),a.ScalarUtil.fsel(b.y,c.y,-c.y),a.ScalarUtil.fsel(b.z,c.z,-c.z));return d};a.BoxShape.prototype.localGetSupportingVertexWithoutMargin=function(b,d){var c=this.getHalfExtentsWithoutMargin(d);d.set3(a.ScalarUtil.fsel(b.x,c.x,-c.x),a.ScalarUtil.fsel(b.y,c.y,-c.y),a.ScalarUtil.fsel(b.z,c.z,-c.z));return d};a.BoxShape.prototype.getAabb=
function(b,d,c){this.halfExtents.set3(0,0,0);this.halfExtents=this.getHalfExtentsWithoutMargin(this.halfExtents);this.abs_b.set1(b.basis);a.MatrixUtil.absolute(this.abs_b);this.tmp.set3(0,0,0);this.center.set1(b.origin);this.extent.set3(0,0,0);this.abs_b.getRow(0,this.tmp);this.extent.x=this.tmp.dot(this.halfExtents);this.abs_b.getRow(1,this.tmp);this.extent.y=this.tmp.dot(this.halfExtents);this.abs_b.getRow(2,this.tmp);this.extent.z=this.tmp.dot(this.halfExtents);this.margin.set3(0,0,0);this.margin.set3(this.getMargin(),
this.getMargin(),this.getMargin());this.extent.add1(this.margin);d.sub2(this.center,this.extent);c.add2(this.center,this.extent)};a.BoxShape.prototype.calculateLocalInertia=function(a,d){this.halfExtents.set3(0,0,0);this.halfExtents=this.getHalfExtentsWithMargin(this.halfExtents);var c=2*this.halfExtents.x,e=2*this.halfExtents.y,f=2*this.halfExtents.z;d.set3(a/12*(e*e+f*f),a/12*(c*c+f*f),a/12*(c*c+e*e))};a.BoxShape.prototype.toString=function(){return"BoxShape"};a.DispatchFunc=function(){};a.DispatchFunc.DISPATCH_DISCRETE=
1;a.DispatchFunc.DISPATCH_CONTINUOUS=2;a.DispatcherInfo=function(){this.dispatchFunc=a.DispatchFunc.DISPATCH_DISCRETE;this.timeOfImpact=1};a.DispatcherInfo.prototype.timeStep=0;a.DispatcherInfo.prototype.stepCount=0;a.DispatcherInfo.prototype.dispatchFunc=0;a.DispatcherInfo.prototype.timeOfImpact=0;a.DispatcherInfo.prototype.useContinuous=!1;a.DispatcherInfo.prototype.enableSatConvex=!1;a.DispatcherInfo.prototype.enableSPU=!0;a.DispatcherInfo.prototype.useEpa=!0;a.DispatcherInfo.prototype.allowedCcdPenetration=
0.04;a.CollisionFilterGroups={DEFAULT_FILTER:1,STATIC_FILTER:2,KINEMATIC_FILTER:4,DEBRIS_FILTER:8,SENSOR_TRIGGER:16,ALL_FILTER:-1};a.Element=function(){};a.Element.prototype.id=0;a.Element.prototype.sz=0;a.UnionFind=function(){this.elements=[]};a.UnionFind.prototype.sortIslands=function(){for(var b=this.elements.length,d=0;d<b;d++)this.elements[d].id=this.find(d),this.elements[d].sz=d;a.MiscUtil.quickSort(this.elements,a.UnionFind.elementComparator)};a.UnionFind.prototype.reset=function(a){this.allocate(a);
for(var d=0;d<a;d++)this.elements[d].id=d,this.elements[d].sz=1};a.UnionFind.prototype.getNumElements=function(){return this.elements.length};a.UnionFind.prototype.getElement=function(a){return this.elements[a]};a.UnionFind.prototype.allocate=function(b){a.MiscUtil.resizea(this.elements,b,function(){return new a.Element})};a.UnionFind.prototype.unite=function(a,d){var c=this.find(a),e=this.find(d);if(c!=e)this.elements[c].id=e,this.elements[e].sz+=this.elements[c].sz};a.UnionFind.prototype.find=function(a){for(;a!=
this.elements[a].id;)this.elements[a].id=this.elements[this.elements[a].id].id,a=this.elements[a].id;return a};a.UnionFind.elementComparator=function(a,d){return a.id<d.id?-1:1};a.CollisionObjectType={COLLISION_OBJECT:1,RIGID_BODY:2,SOFT_BODY:3};a.CollisionFlags={STATIC_OBJECT:1,KINEMATIC_OBJECT:2,NO_CONTACT_RESPONSE:4,CUSTOM_MATERIAL_CALLBACK:8};a.poolManifoldPoint=new a.ObjectPool(function(){return new a.ManifoldPoint});a.ManifoldResult=function(){this.rootTransA=new a.Transform;this.rootTransB=
new a.Transform};a.ManifoldResult.prototype.pointsPool=a.poolManifoldPoint;a.ManifoldResult.prototype.partId0=0;a.ManifoldResult.prototype.partId1=0;a.ManifoldResult.prototype.index0=0;a.ManifoldResult.prototype.index1=0;a.ManifoldResult.prototype.init=function(a,d){this.body0=a;this.body1=d;a.getWorldTransform(this.rootTransA);d.getWorldTransform(this.rootTransB)};a.ManifoldResult.prototype.setPersistentManifold=function(a){this.manifoldPtr=a};a.ManifoldResult.prototype.pointA=new Vecmath.Vec3;a.ManifoldResult.prototype.localA=
new Vecmath.Vec3;a.ManifoldResult.prototype.localB=new Vecmath.Vec3;a.ManifoldResult.prototype.addContactPoint=function(b,d,c){if(!(c>a.BulletGlobals.contactBreakingThreshold)){var e=this.manifoldPtr.body0!=this.body0;this.pointA.set3(0,0,0);this.pointA.scaleAdd(c,b,d);this.localA.set3(0,0,0);this.localB.set3(0,0,0);e?(this.rootTransB.invXform(this.pointA,this.localA),this.rootTransA.invXform(this.pointInWorld,this.localB)):(this.rootTransA.invXform(this.pointA,this.localA),this.rootTransB.invXform(d,
this.localB));e=this.pointsPool.get();e.init(this.localA,this.localB,b,c);e.positionWorldOnA.set1(this.pointA);e.positionWorldOnB.set1(d);b=this.manifoldPtr.getCacheEntry(e);e.combinedFriction=a.ManifoldResult.calculateCombinedFriction(this.body0,this.body1);e.combinedRestitution=a.ManifoldResult.calculateCombinedRestitution(this.body0,this.body1);e.partId0=this.partId0;e.partId1=this.partId1;e.index0=this.index0;e.index1=this.index1;b>=0?this.manifoldPtr.replaceContactPoint(e,b):this.manifoldPtr.addManifoldPoint(e);
this.pointsPool.release(e)}};a.ManifoldResult.calculateCombinedFriction=function(a,d){var c=a.friction*d.friction;c<-10&&(c=-10);c>10&&(c=10);return c};a.ManifoldResult.calculateCombinedRestitution=function(a,d){return a.restitution*d.restitution};a.ManifoldResult.prototype.refreshContactPoints=function(){this.manifoldPtr.cachedPoints!=0&&(this.manifoldPtr.body0!=this.body0?this.manifoldPtr.refreshContactPoints(this.rootTransB,this.rootTransA):this.manifoldPtr.refreshContactPoints(this.rootTransA,
this.rootTransB))};a.ManifoldResult.prototype.toString=function(){return"ManifoldResult("+this.manifoldPtr+")"};a.CollisionObject=function(){this.worldTransform=new a.Transform;this.interpolationWorldTransform=new a.Transform;this.interpolationLinearVelocity=new Vecmath.Vec3;this.interpolationAngularVelocity=new Vecmath.Vec3;this.collisionFlags=a.CollisionFlags.STATIC_OBJECT;this.companionId=this.islandTag1=-1;this.activationState1=1;this.friction=0.5;this.hitFraction=1};a.CollisionObject.ACTIVE_TAG=
1;a.CollisionObject.ISLAND_SLEEPING=2;a.CollisionObject.WANTS_DEACTIVATION=3;a.CollisionObject.DISABLE_DEACTIVATION=4;a.CollisionObject.DISABLE_SIMULATION=5;a.CollisionObject.prototype.collisionFlags=0;a.CollisionObject.prototype.islandTag1=0;a.CollisionObject.prototype.companionId=0;a.CollisionObject.prototype.activationState1=0;a.CollisionObject.prototype.deactivationTime=0;a.CollisionObject.prototype.friction=0;a.CollisionObject.prototype.restitution=0;a.CollisionObject.prototype.internalType=
a.CollisionObjectType.COLLISION_OBJECT;a.CollisionObject.prototype.hitFraction=0;a.CollisionObject.prototype.ccdSquareMotionThreshold=0;a.CollisionObject.prototype.checkCollideWith=!1;a.CollisionObject.prototype.mergesSimulationIslands=function(){return(this.collisionFlags&(a.CollisionFlags.STATIC_OBJECT|a.CollisionFlags.KINEMATIC_OBJECT|a.CollisionFlags.NO_CONTACT_RESPONSE))==0};a.CollisionObject.prototype.isStaticObject=function(){return(this.collisionFlags&a.CollisionFlags.STATIC_OBJECT)!=0};a.CollisionObject.prototype.isKinematicObject=
function(){return(this.collisionFlags&a.CollisionFlags.KINEMATIC_OBJECT)!=0};a.CollisionObject.prototype.isStaticOrKinematicObject=function(){return(this.collisionFlags&(a.CollisionFlags.KINEMATIC_OBJECT|a.CollisionFlags.STATIC_OBJECT))!=0};a.CollisionObject.prototype.hasContactResponse=function(){return(this.collisionFlags&a.CollisionFlags.NO_CONTACT_RESPONSE)==0};a.CollisionObject.prototype.setCollisionShape=function(a){this.rootCollisionShape=this.collisionShape=a};a.CollisionObject.prototype.setActivationState=
function(b){if(this.activationState1!=a.CollisionObject.DISABLE_DEACTIVATION&&this.activationState1!=a.CollisionObject.DISABLE_SIMULATION)this.activationState1=b};a.CollisionObject.prototype.activate=function(){this.activate1(!1)};a.CollisionObject.prototype.activate1=function(b){if(b||(this.collisionFlags&(a.CollisionFlags.STATIC_OBJECT|a.CollisionFlags.KINEMATIC_OBJECT))==0)this.setActivationState(a.CollisionObject.ACTIVE_TAG),this.deactivationTime=0};a.CollisionObject.prototype.isActive=function(){return this.activationState1!=
a.CollisionObject.ISLAND_SLEEPING&&this.activationState1!=a.CollisionObject.DISABLE_SIMULATION};a.CollisionObject.prototype.getWorldTransform=function(a){a.setT(this.worldTransform);return a};a.CollisionObject.prototype.setWorldTransform=function(a){this.worldTransform.setT(a)};a.CollisionObject.prototype.getInterpolationWorldTransform=function(a){a.setT(this.interpolationWorldTransform);return a};a.CollisionObject.prototype.getInterpolationLinearVelocity=function(a){a.set1(this.interpolationLinearVelocity);
return a};a.CollisionObject.prototype.getInterpolationAngularVelocity=function(a){a.set1(this.interpolationAngularVelocity);return a};a.poolBroadphasePair=new a.ObjectPool(function(){return new a.BroadphasePair(null,null)});a.OverlappingPairCache=function(){this.overlappingPairArray=new a.ObjectArrayList;this.hashTable=new a.ObjectArrayList;this.next=new a.ObjectArrayList;this.hashTable.array=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.growTables()};a.OverlappingPairCache.prototype.pairsPool=a.poolBroadphasePair;
a.OverlappingPairCache.NULL_PAIR=-1;a.OverlappingPairCache.prototype.blockedForChanges=!1;a.OverlappingPairCache.prototype.addOverlappingPair=function(a,d){if(!this.needsBroadphaseCollision(a,d))return null;return this.internalAddPair(a,d)};a.OverlappingPairCache.prototype.removeOverlappingPair=function(b,d,c){if(b.uniqueId>d.uniqueId)var e=b,b=d,d=e;e=this.getHash(b.uniqueId,d.uniqueId)&this.overlappingPairArray.capacity()-1;b=this.internalFindPair(b,d,e);if(b==null)return null;this.cleanOverlappingPair(b,
c);for(var c=b.userInfo,b=this.overlappingPairArray.indexOf(b),d=this.hashTable.get(e),f=a.OverlappingPairCache.NULL_PAIR;d!=b;)f=d,d=this.next.get(d);f!=NULL_PAIR?this.next.set(f,this.next.get(b)):this.hashTable.set(e,this.next.get(b));e=this.overlappingPairArray.size()-1;if(e==b)return this.overlappingPairArray.remove(this.overlappingPairArray.size()-1),c;for(var d=this.overlappingPairArray.get(e),g=this.getHash(d.pProxy0.uniqueId,d.pProxy1.uniqueId)&this.overlappingPairArray.capacity()-1,d=this.hashTable.get(g),
f=a.OverlappingPairCache.NULL_PAIR;d!=e;)f=d,d=next.get(d);f!=a.OverlappingPairCache.NULL_PAIR?this.next.set(f,this.next.get(e)):this.hashTable.set(g,next.get(e));this.overlappingPairArray.get(b).set(this.overlappingPairArray.get(e));this.next.set(b,this.hashTable.get(g));this.hashTable.set(g,b);this.overlappingPairArray.remove(this.overlappingPairArray.size()-1);return c};a.OverlappingPairCache.prototype.needsBroadphaseCollision=function(a,d){var c=(a.collisionFilterGroup&d.collisionFilterMask)!=
0;return c=c&&(d.collisionFilterGroup&a.collisionFilterMask)!=0};a.OverlappingPairCache.prototype.processAllOverlappingPairs=function(a,d){for(var c=0;c<this.overlappingPairArray.sizef();){var e=this.overlappingPairArray.get(c);a.processOverlap(e)?this.removeOverlappingPair(e.pProxy0,e.pProxy1,d):c++}};a.OverlappingPairCache.prototype.cleanOverlappingPair=function(a){if(a.algorithm!=null)a.algorithm=null};a.OverlappingPairCache.prototype.findPair=function(b,d){b.uniqueId>d.uniqueId&&(d=b=d);var c=
b.uniqueId,e=d.uniqueId,f=this.getHash(c,e)&this.overlappingPairArray.capacity()-1;if(f>=this.hashTable.size())return null;for(f=this.hashTable.get(f);f!=a.OverlappingPairCache.NULL_PAIR&&equalsPair(this.overlappingPairArray.get(f),c,e)==!1;)f=this.next.get(f);if(f==a.OverlappingPairCache.NULL_PAIR)return null;return this.overlappingPairArray.get(f)};a.OverlappingPairCache.prototype.getCount=function(){return this.overlappingPairArray.size()};a.OverlappingPairCache.prototype.getNumOverlappingPairs=
function(){return this.overlappingPairArray.size()};a.OverlappingPairCache.prototype.hasDeferredRemoval=function(){return!1};a.OverlappingPairCache.prototype.internalAddPair=function(b,d){if(b.uniqueId>d.uniqueId)var c=b,b=d,d=c;var c=b.uniqueId,e=d.uniqueId,f=this.getHash(c,e)&this.overlappingPairArray.capacity()-1,g=this.internalFindPair(b,d,f);if(g!=null)return g;var h=this.overlappingPairArray.sizef(),g=this.overlappingPairArray.capacity();this.overlappingPairArray.add(null);var j=this.overlappingPairArray.capacity();
g<j&&(this.growTables(),f=this.getHash(c,e)&this.overlappingPairArray.capacity()-1);g=new a.BroadphasePair(b,d);g.algorithm=null;g.userInfo=null;this.overlappingPairArray.set(this.overlappingPairArray.sizef()-1,g);this.next.set(h,this.hashTable.get(f));this.hashTable.set(f,h);return g};a.OverlappingPairCache.prototype.growTables=function(){var b=this.overlappingPairArray.capacity();if(this.hashTable.sizef()<b){var d=this.hashTable.sizef();a.MiscUtil.resizec(this.hashTable,b,0);a.MiscUtil.resizec(this.next,
b,0);for(var c=0;c<b;++c)this.hashTable.set(c,a.OverlappingPairCache.NULL_PAIR);for(c=0;c<b;++c)this.next.set(c,a.OverlappingPairCache.NULL_PAIR);for(c=0;c<d;c++)b=this.overlappingPairArray.get(c),b=this.getHash(b.pProxy0.uniqueId,b.pProxy1.uniqueId)&this.overlappingPairArray.capacity()-1,this.next.set(c,this.hashTable.get(b)),this.hashTable.set(b,c)}};a.OverlappingPairCache.prototype.equalsPair=function(a,d,c){if(a==null)throw arguments.callee.caller;return a.pProxy0.uniqueId==d&&a.pProxy1.uniqueId==
c};a.OverlappingPairCache.prototype.getHash=function(a,d){var c=a|d<<16;c+=~(c<<15);c^=c>>>10;c+=c<<3;c^=c>>>6;c+=~(c<<11);c^=c>>>16;return c};a.OverlappingPairCache.prototype.internalFindPair=function(b,d,c){b=b.uniqueId;d=d.uniqueId;for(c=this.hashTable.get(c);c!=a.OverlappingPairCache.NULL_PAIR&&this.equalsPair(this.overlappingPairArray.get(c),b,d)==!1;)c=this.next.get(c);if(c==a.OverlappingPairCache.NULL_PAIR)return null;return this.overlappingPairArray.get(c)};a.OverlappingPairCache.prototype.toString=
function(){return"OverlappingPairCache"};a.EdgeArray=function(a){this.pos=Array(a);this.handle=Array(a)};a.EdgeArray.prototype.swap=function(a,d){var c=this.pos[a],e=this.handle[a];this.pos[a]=this.pos[d];this.handle[a]=this.handle[d];this.pos[d]=c;this.handle[d]=e};a.EdgeArray.prototype.set=function(a,d){this.pos[a]=this.pos[d];this.handle[a]=this.handle[d]};a.EdgeArray.prototype.getPos=function(a){return this.pos[a]&65535};a.EdgeArray.prototype.setPos=function(a,d){this.pos[a]=d};a.EdgeArray.prototype.getHandle=
function(a){for(var d="",c=0;c<10;c++)d+=this.handle[c]+",";return this.handle[a]&65535};a.EdgeArray.prototype.setHandle=function(a,d){this.handle[a]=d};a.EdgeArray.prototype.isMax=function(a){return this.getPos(a)&1};a.EdgeArray.prototype.toString=function(){return"EdgeArray["+this.pos.length+"/"+this.handle.length+"]"};a.BroadphaseInterface=function(b,d,c,e,f,g){this.worldAabbMin=new Vecmath.Vec3;this.worldAabbMax=new Vecmath.Vec3;this.quantize=new Vecmath.Vec3;this.pEdges=Array(3);this.aabbSize=
new Vecmath.Vec3;this.clampedPoint=new Vecmath.Vec3;this.v=new Vecmath.Vec3;this.bpHandleMask=c;this.handleSentinel=e;this.pairCache=g;c=f+1;if(this.pairCache==null)this.pairCache=new a.OverlappingPairCache,this.ownsPairCache=!0;this.worldAabbMin.set1(b);this.worldAabbMax.set1(d);this.aabbSize.set3(0,0,0);this.aabbSize.sub2(this.worldAabbMax,this.worldAabbMin);b=this.handleSentinel;this.quantize.set3(b/this.aabbSize.x,b/this.aabbSize.y,b/this.aabbSize.z);this.pHandles=Array(c);for(b=0;b<c;b++)this.pHandles[b]=
this.createHandle();this.maxHandles=c;this.numHandles=0;for(b=this.firstFreeHandle=1;b<c;b++)this.pHandles[b].setNextFree(b+1);this.pHandles[c-1].setNextFree(0);for(b=0;b<3;b++)this.pEdges[b]=this.createEdgeArray(c*2);this.pHandles[0].clientObject=null;for(b=0;b<3;b++)this.pHandles[0].setMinEdges(b,0),this.pHandles[0].setMaxEdges(b,1),this.pEdges[b].setPos(0,0),this.pEdges[b].setHandle(0,0),this.pEdges[b].setPos(1,e),this.pEdges[b].setHandle(1,0);this.mask=65535};a.BroadphaseInterface.prototype.bpHandleMask=
0;a.BroadphaseInterface.prototype.handleSentinel=0;a.BroadphaseInterface.prototype.numHandles=0;a.BroadphaseInterface.prototype.maxHandles=0;a.BroadphaseInterface.prototype.firstFreeHandle=0;a.BroadphaseInterface.prototype.ownsPairCache=!1;a.BroadphaseInterface.prototype.invalidPair=0;a.BroadphaseInterface.prototype.mask=0;a.BroadphaseInterface.prototype.allocHandle=function(){var a=this.firstFreeHandle;this.firstFreeHandle=this.getHandle(a).getNextFree();this.numHandles++;return a};a.BroadphaseInterface.prototype.testOverlap=
function(a,d,c){for(var e=0;e<3;e++)if(e!=a&&(d.getMaxEdges(e)<c.getMinEdges(e)||c.getMaxEdges(e)<d.getMinEdges(e)))return!1;return!0};a.BroadphaseInterface.prototype.quantize3=function(b,d,c){this.clampedPoint.set3(0,0,0);a.VectorUtil.setMax(this.clampedPoint,this.worldAabbMin);a.VectorUtil.setMin(this.clampedPoint,this.worldAabbMax);this.v.set3(0,0,0);this.v.sub2(this.clampedPoint,this.worldAabbMin);a.VectorUtil.mul(this.v,this.v,this.quantize);b[0]=(Math.floor(this.v.x)&this.bpHandleMask|c)&this.mask;
b[1]=(Math.floor(this.v.y)&this.bpHandleMask|c)&this.mask;b[2]=(Math.floor(this.v.z)&this.bpHandleMask|c)&this.mask};a.BroadphaseInterface.prototype.sortMinDown=function(a,d,c,e){for(var c=this.pEdges[a],f=d-1,g=this.getHandle(c.getHandle(d));c.getPos(d)<c.getPos(f);){var h=this.getHandle(c.getHandle(f));c.isMax(f)!=0?(e&&this.testOverlap(a,g,h)&&(this.pairCache.addOverlappingPair(g,h),this.userPairCallback!=null&&this.userPairCallback.addOverlappingPair(g,h)),h.incMaxEdges(a)):h.incMinEdges(a);g.decMinEdges(a);
c.swap(d,f);d--;f--}};a.BroadphaseInterface.prototype.sortMaxDown=function(a,d,c,e){for(var f=this.pEdges[a],g=d-1,h=this.getHandle(f.getHandle(d));f.getPos(d)<f.getPos(g);){var j=this.getHandle(f.getHandle(g));if(f.isMax(g)==0){if(e){var i=this.getHandle(f.getHandle(d)),m=this.getHandle(f.getHandle(g));this.pairCache.removeOverlappingPair(i,m,c);this.userPairCallback!=null&&this.userPairCallback.removeOverlappingPair(i,m,c)}j.incMinEdges(a)}else j.incMaxEdges(a);h.decMaxEdges(a);f.swap(d,g);d--;
g--}};a.BroadphaseInterface.prototype.calculateOverlappingPairs=function(b){if(this.pairCache.hasDeferredRemoval()){var d=this.pairCache.overlappingPairArray;a.MiscUtil.quickSort(d,a.BroadphasePair.broadphasePairSortPredicate);a.MiscUtil.resizea(d,d.size()-this.invalidPair,a.BroadphasePair.createF);var c=this.invalidPair=0,e=new a.BroadphasePair(null,null);e.pProxy0=null;e.pProxy1=null;e.algorithm=null;for(c=0;c<d.size();c++){var f=d.get(c),g=f.equals(e);e.set(f);var h=!1;g&&(h=!0);if(h)this.pairCache.cleanOverlappingPair(f,
b),f.pProxy0=null,f.pProxy1=null,this.invalidPair++}a.MiscUtil.quickSort(d,a.BroadphasePair.broadphasePairSortPredicate);a.MiscUtil.resizea(d,d.size()-this.invalidPair,a.BroadphasePair.createF);this.invalidPair=0}};a.BroadphaseInterface.prototype.addHandle=function(a,d,c,e,f,g,h){var j=Array(3),i=Array(3);this.quantize3(j,a,0);this.quantize3(i,d,1);a=this.allocHandle();d=this.getHandle(a);d.uniqueId=a;d.clientObject=c;d.collisionFilterGroup=e;d.collisionFilterMask=f;d.multiSapParentProxy=h;c=this.numHandles*
2;for(e=0;e<3;e++)this.pHandles[0].setMaxEdges(e,this.pHandles[0].getMaxEdges(e)+2),this.pEdges[e].set(c+1,c-1),this.pEdges[e].setPos(c-1,j[e]),this.pEdges[e].setHandle(c-1,a),this.pEdges[e].setPos(c,i[e]),this.pEdges[e].setHandle(c,a),d.setMinEdges(e,c-1),d.setMaxEdges(e,c);this.sortMinDown(0,d.getMinEdges(0),g,!1);this.sortMaxDown(0,d.getMaxEdges(0),g,!1);this.sortMinDown(1,d.getMinEdges(1),g,!1);this.sortMaxDown(1,d.getMaxEdges(1),g,!1);this.sortMinDown(2,d.getMinEdges(2),g,!0);this.sortMaxDown(2,
d.getMaxEdges(2),g,!0);return a};a.BroadphaseInterface.prototype.updateHandle=function(a,d,c,e){var a=this.getHandle(a),f=Array(3),g=Array(3);this.quantize3(f,d,0);this.quantize3(g,c,1);for(d=0;d<3;d++){var c=a.getMinEdges(d),h=a.getMaxEdges(d),j=Math.floor(f[d])-Math.floor(this.pEdges[d].getPos(c)),i=Math.floor(g[d])-Math.floor(this.pEdges[d].getPos(h));this.pEdges[d].setPos(c,f[d]);this.pEdges[d].setPos(h,g[d]);j<0&&this.sortMinDown(d,c,e,!0);i<0&&this.sortMaxDown(d,h,e,!0)}};a.BroadphaseInterface.prototype.getHandle=
function(a){return this.pHandles[a]};a.BroadphaseInterface.prototype.createProxy=function(a,d,c,e,f,g,h,j){return this.getHandle(this.addHandle(a,d,e,f,g,h,j))};a.BroadphaseInterface.prototype.setAabb=function(a,d,c,e){this.updateHandle(a.uniqueId,d,c,e)};a.BroadphaseInterface.prototype.createEdgeArray=function(b){return new a.EdgeArray(b)};a.BroadphaseInterface.prototype.createHandle=function(){return new a.BroadphaseProxy};a.BroadphaseProxy=function(){};a.BroadphaseProxy.prototype.collisionFilterGroup=
0;a.BroadphaseProxy.prototype.collisionFilterMask=0;a.BroadphaseProxy.prototype.uniqueId=0;a.BroadphaseProxy.prototype.minEdges0=0;a.BroadphaseProxy.prototype.minEdges1=0;a.BroadphaseProxy.prototype.minEdges2=0;a.BroadphaseProxy.prototype.maxEdges0=0;a.BroadphaseProxy.prototype.maxEdges1=0;a.BroadphaseProxy.prototype.maxEdges2=0;a.BroadphaseProxy.prototype.getMinEdges=function(a){switch(a){default:case 0:return this.minEdges0&65535;case 1:return this.minEdges1&65535;case 2:return this.minEdges2&65535}};
a.BroadphaseProxy.prototype.setMinEdges=function(a,d){switch(a){case 0:this.minEdges0=d;break;case 1:this.minEdges1=d;break;case 2:this.minEdges2=d}};a.BroadphaseProxy.prototype.getMaxEdges=function(a){switch(a){default:case 0:return this.maxEdges0&65535;case 1:return this.maxEdges1&65535;case 2:return this.maxEdges2&65535}};a.BroadphaseProxy.prototype.setMaxEdges=function(a,d){switch(a){case 0:this.maxEdges0=d;break;case 1:this.maxEdges1=d;break;case 2:this.maxEdges2=d}};a.BroadphaseProxy.prototype.incMinEdges=
function(a){this.setMinEdges(a,this.getMinEdges(a)+1)};a.BroadphaseProxy.prototype.incMaxEdges=function(a){this.setMaxEdges(a,this.getMaxEdges(a)+1)};a.BroadphaseProxy.prototype.decMinEdges=function(a){this.setMinEdges(a,this.getMinEdges(a)-1)};a.BroadphaseProxy.prototype.decMaxEdges=function(a){this.setMaxEdges(a,this.getMaxEdges(a)-1)};a.BroadphaseProxy.prototype.setNextFree=function(a){this.setMinEdges(0,a)};a.BroadphaseProxy.prototype.getNextFree=function(){return this.getMinEdges(0)};a.BroadphaseProxy.prototype.toString=
function(){return"BroadPhaseProxy["+this.uniqueId+";minEdges:"+this.minEdges0+","+this.minEdges1+","+this.minEdges2+"]"};a.CollisionAlgorithmConstructionInfo=function(){};a.BroadphasePair=function(a,d){this.pProxy0=a;this.pProxy1=d;this.userInfo=this.algorithm=null};a.BroadphasePair.prototype.set=function(a){this.pProxy0=a.pProxy0;this.pProxy1=a.pProxy1;this.algorithm=a.algorithm;this.userInfo=a.userInfo};a.BroadphasePair.broadphasePairSortPredicate=function(a,d){return a.pProxy0.uniqueId>d.pProxy0.uniqueId||
a.pProxy0.uniqueId==d.pProxy0.uniqueId&&a.pProxy1.uniqueId>d.pProxy1.uniqueId||a.pProxy0.uniqueId==d.pProxy0.uniqueId&&a.pProxy1.uniqueId==d.pProxy1.uniqueId?-1:1};a.poolCollisionAlgorithm=new a.ObjectPool(function(){return new a.CollisionAlgorithm});a.CollisionAlgorithmCreateFunc=function(a,d){this.simplexSolver=a;this.pdSolver=d};a.CollisionAlgorithmCreateFunc.prototype.swapped=!1;a.CollisionAlgorithmCreateFunc.prototype.pool=a.poolCollisionAlgorithm;a.CollisionAlgorithmCreateFunc.prototype.createCollisionAlgorithm=
function(a,d,c){var e=this.pool.get();e.init6(a.manifold,a,d,c,this.simplexSolver,this.pdSolver);return e};a.CollisionAlgorithmCreateFunc.prototype.releaseCollisionAlgorithm=function(a){pool.release(a)};a.poolClosestPointInput=new a.ObjectPool(function(){return new a.ClosestPointInput});a.CollisionAlgorithm=function(){};a.CollisionAlgorithm.prototype.init1=function(a){this.dispatcher=a.dispatcher1};a.CollisionAlgorithm.prototype.pointInputsPool=a.poolClosestPointInput;a.CollisionAlgorithm.prototype.gjkPairDetector=
new a.GjkPairDetector;a.CollisionAlgorithm.prototype.ownManifold=!1;a.CollisionAlgorithm.prototype.init6=function(a,d,c,e,f,g){this.init1(d);this.gjkPairDetector.init(null,null,f,g);this.manifoldPtr=a;this.lowLevelOfDetail=this.ownManifold=!1};a.CollisionAlgorithm.prototype.processCollision=function(b,d,c,e){if(this.manifoldPtr==null)this.manifoldPtr=this.dispatcher.getNewManifold(b,d),this.ownManifold=!0;e.setPersistentManifold(this.manifoldPtr);var c=b.collisionShape,f=d.collisionShape,g=this.pointInputsPool.get();
g.init();this.gjkPairDetector.minkowskiA=c;this.gjkPairDetector.minkowskiB=f;g.maximumDistanceSquared=c.getMargin()+f.getMargin()+a.BulletGlobals.contactBreakingThreshold;g.maximumDistanceSquared*=g.maximumDistanceSquared;b.getWorldTransform(g.transformA);d.getWorldTransform(g.transformB);this.gjkPairDetector.getClosestPoints(g,e);this.pointInputsPool.release(g);this.ownManifold&&e.refreshContactPoints()};a.CollisionAlgorithm.prototype.disableCcd=!1;a.CollisionConfiguration=function(){this.simplexSolver=
new a.SimplexSolver;this.pdSolver=new a.GjkEpaPenetrationDepthSolver;this.convexConvexCreateFunc=new a.CollisionAlgorithmCreateFunc(this.simplexSolver,this.pdSolver)};a.CollisionConfiguration.prototype.getCollisionAlgorithmCreateFunc=function(b,d){if(b==a.BroadphaseNativeType.SPHERE_SHAPE_PROXYTYPE&&d==a.BroadphaseNativeType.SPHERE_SHAPE_PROXYTYPE)return this.sphereSphereCF;if(a.BroadphaseNativeType.isConvex(b)&&d==a.BroadphaseNativeType.STATIC_PLANE_PROXYTYPE)return this.convexPlaneCF;if(a.BroadphaseNativeType.isConvex(d)&&
b==a.BroadphaseNativeType.STATIC_PLANE_PROXYTYPE)return this.planeConvexCF;if(a.BroadphaseNativeType.isConvex(b)&&a.BroadphaseNativeType.isConvex(d))return this.convexConvexCreateFunc;if(a.BroadphaseNativeType.isConvex(b)&&a.BroadphaseNativeType.isConcave(d))return this.convexConcaveCreateFunc;if(a.BroadphaseNativeType.isConvex(d)&&a.BroadphaseNativeType.isConcave(b))return this.swappedConvexConcaveCreateFunc;if(a.BroadphaseNativeType.isCompound(b))return this.compoundCreateFunc;else if(a.BroadphaseNativeType.isCompound(d))return this.swappedCompoundCreateFunc;
return this.emptyCreateFunc};a.NearCallback=function(){this.contactPointResult=new a.ManifoldResult};a.NearCallback.prototype.handleCollision=function(b,d,c){var e=b.pProxy0.clientObject,f=b.pProxy1.clientObject;if(d.needsCollision(e,f)){if(b.algorithm==null)b.algorithm=d.findAlgorithm2(e,f);b.algorithm!=null&&(this.contactPointResult.init(e,f),c.dispatchFunc==a.DispatchFunc.DISPATCH_DISCRETE&&b.algorithm.processCollision(e,f,c,this.contactPointResult))}};a.CollisionPairCallback=function(){};a.CollisionPairCallback.prototype.init=
function(a,d){this.dispatchInfo=a;this.dispatcher=d};a.CollisionPairCallback.prototype.processOverlap=function(a){this.dispatcher.nearCallback.handleCollision(a,this.dispatcher,this.dispatchInfo);return!1};a.poolPersistentManifold=new a.ObjectPool(function(){return new a.PersistentManifold});a.Dispatcher=function(b){this.manifoldsPtr=[];this.doubleDispatch=a.arrayCreate([a.Dispatcher.MAX_BROADPHASE_COLLISION_TYPES,a.Dispatcher.MAX_BROADPHASE_COLLISION_TYPES]);this.tmpCI=new a.CollisionAlgorithmConstructionInfo;
this.collisionPairCallback=new a.CollisionPairCallback;this.collisionConfiguration=b;this.nearCallback=new a.NearCallback;for(var d=0;d<a.Dispatcher.MAX_BROADPHASE_COLLISION_TYPES;d++)for(var c=0;c<a.Dispatcher.MAX_BROADPHASE_COLLISION_TYPES;c++)this.doubleDispatch[d][c]=b.getCollisionAlgorithmCreateFunc(d,c)};a.Dispatcher.prototype.manifoldsPool=a.poolPersistentManifold;a.Dispatcher.MAX_BROADPHASE_COLLISION_TYPES=a.BroadphaseNativeType.MAX_BROADPHASE_COLLISION_TYPES;a.Dispatcher.prototype.count=
0;a.Dispatcher.prototype.useIslands=!0;a.Dispatcher.prototype.staticWarningReported=!1;a.Dispatcher.prototype.findAlgorithm2=function(a,d){return this.findAlgorithm3(a,d,null)};a.Dispatcher.prototype.findAlgorithm3=function(a,d,c){var e=this.tmpCI;e.dispatcher1=this;e.manifold=c;c=this.doubleDispatch[a.collisionShape.getShapeType()][d.collisionShape.getShapeType()];a=c.createCollisionAlgorithm(e,a,d);a.createFunc=c;return a};a.Dispatcher.prototype.getNewManifold=function(a,d){var c=this.manifoldsPool.get();
c.init(a,d,0);c.index1a=this.manifoldsPtr.length;this.manifoldsPtr.push(c);return c};a.Dispatcher.prototype.needsCollision=function(a,d){var c=!0;if(!this.staticWarningReported&&(a.isStaticObject()||a.isKinematicObject())&&(d.isStaticObject()||d.isKinematicObject()))this.staticWarningReported=!0,alert("warning Dispatcher.needsCollision: static-static collision!");!a.isActive()&&!d.isActive()&&(c=!1);return c};a.Dispatcher.prototype.needsResponse=function(a,d){var c=a.hasContactResponse()&&d.hasContactResponse();
return c=c&&(!a.isStaticOrKinematicObject()||!d.isStaticOrKinematicObject())};a.Dispatcher.prototype.dispatchAllCollisionPairs=function(a,d,c){this.collisionPairCallback.init(d,this);a.processAllOverlappingPairs(this.collisionPairCallback,c)};a.Dispatcher.prototype.getNumManifolds=function(){return this.manifoldsPtr.length};a.Dispatcher.prototype.getManifoldByIndexInternal=function(a){return this.manifoldsPtr[a]};a.SimulationIslandManager=function(){this.unionFind=new a.UnionFind;this.islandmanifold=
[];this.islandBodies=[]};a.SimulationIslandManager.prototype.initUnionFind=function(a){this.unionFind.reset(a)};a.SimulationIslandManager.prototype.findUnions=function(a,d){for(var c=d.getPairCache().overlappingPairArray,e=0;e<c.sizef();e++){var f=c.get(e),g=f.pProxy0.clientObject,f=f.pProxy1.clientObject;g!=null&&g.mergesSimulationIslands()&&f!=null&&f.mergesSimulationIslands()&&this.unionFind.unite(g.islandTag1,f.islandTag1)}};a.SimulationIslandManager.prototype.updateActivationState=function(a,
d){this.initUnionFind(a.collisionObjects.length);var c=0,e;for(e=0;e<a.collisionObjects.length;e++){var f=a.collisionObjects[e];f.islandTag1=c;f.companionId=-1;f.hitFraction=1;c++}this.findUnions(d,a)};a.SimulationIslandManager.prototype.storeIslandActivationState=function(a){var d=0,c;for(c=0;c<a.collisionObjects.length;c++){var e=a.collisionObjects[c];e.mergesSimulationIslands()?(e.islandTag1=this.unionFind.find(d),e.companionId=-1):(e.islandTag1=-1,e.companionId=-2);d++}};a.SimulationIslandManager.getIslandId=
function(a){var d=a.body0,a=a.body1;return d.islandTag1>=0?d.islandTag1:a.islandTag1};a.SimulationIslandManager.prototype.buildAndProcessIslands=function(b,d,c){this.unionFind.sortIslands();var e=this.unionFind.getNumElements(),f=1,g;for(g=0;g<e;g=f){for(var h=this.unionFind.getElement(g).id,f=g+1;f<e&&this.unionFind.getElement(f).id==h;f++)var j=!0;var i;for(i=g;i<f;i++){var m=this.unionFind.getElement(i).sz,k=d[m];k.islandTag1==h&&(k.activationState1==a.CollisionObject.ACTIVE_TAG&&(j=!1),k.activationState1==
a.CollisionObject.DISABLE_DEACTIVATION&&(j=!1))}if(j)for(i=g;i<f;i++)m=this.unionFind.getElement(i).sz,k=d[m],k.islandTag1==h&&k.setActivationState(a.CollisionObject.ISLAND_SLEEPING);else for(i=g;i<f;i++)m=this.unionFind.getElement(i).sz,k=d[m],k.islandTag1==h&&k.activationState1==a.CollisionObject.ISLAND_SLEEPING&&k.setActivationState(a.CollisionObject.WANTS_DEACTIVATION)}f=b.getNumManifolds();for(m=0;m<f;m++)if(h=b.getManifoldByIndexInternal(m),k=h.body0,g=h.body1,k!=null&&k.activationState1!=a.CollisionObject.ISLAND_SLEEPING||
g!=null&&g.activationState1!=a.CollisionObject.ISLAND_SLEEPING)k.isKinematicObject()&&k.activationState1!=a.CollisionObject.ISLAND_SLEEPING&&g.activate(),g.isKinematicObject()&&g.activationState1!=a.CollisionObject.ISLAND_SLEEPING&&k.activate(),b.needsResponse(k,g)&&this.islandmanifold.push(h);b=this.islandmanifold.length;a.MiscUtil.quickSort(this.islandmanifold,a.SimulationIslandManager.persistentManifoldComparator);j=0;i=1;for(g=0;g<e;g=f){for(var h=this.unionFind.getElement(g).id,l=!1,f=g;f<e&&
this.unionFind.getElement(f).id==h;f++)m=this.unionFind.getElement(f).sz,k=d[m],this.islandBodies.push(k),k.isActive()||(l=!0);m=0;k=-1;if(j<b&&a.SimulationIslandManager.getIslandId(this.islandmanifold[j])==h){k=j;for(i=j+1;i<b&&h==a.SimulationIslandManager.getIslandId(this.islandmanifold[i]);i++);m=i-j}l||c.processIsland(this.islandBodies,this.islandBodies.length,this.islandmanifold,k,m,h);m!=0&&(j=i);this.islandBodies.splice(0,this.islandBodies.length)}this.islandmanifold.splice(0,this.islandmanifold.length)};
a.SimulationIslandManager.persistentManifoldComparator=function(b,d){return a.SimulationIslandManager.getIslandId(b)<a.SimulationIslandManager.getIslandId(d)?-1:1};a.SolverMode={SOLVER_RANDMIZE_ORDER:1,SOLVER_FRICTION_SEPARATE:2,SOLVER_USE_WARMSTARTING:4,SOLVER_CACHE_FRIENDLY:8};a.ContactSolverInfo=function(){};a.ContactSolverInfo.prototype.tau=0.6;a.ContactSolverInfo.prototype.damping=1;a.ContactSolverInfo.prototype.friction=0.3;a.ContactSolverInfo.prototype.restitution=0;a.ContactSolverInfo.prototype.numIterations=
10;a.ContactSolverInfo.prototype.maxErrorReduction=20;a.ContactSolverInfo.prototype.sor=1.3;a.ContactSolverInfo.prototype.erp=0.2;a.ContactSolverInfo.prototype.erp2=0.1;a.ContactSolverInfo.prototype.splitImpulse=!1;a.ContactSolverInfo.prototype.splitImpulsePenetrationThreshold=-0.02;a.ContactSolverInfo.prototype.linearSlop=0;a.ContactSolverInfo.prototype.warmstartingFactor=0.85;a.ContactSolverInfo.prototype.solverMode=a.SolverMode.SOLVER_RANDMIZE_ORDER|a.SolverMode.SOLVER_CACHE_FRIENDLY|a.SolverMode.SOLVER_USE_WARMSTARTING;
a.ConstraintPersistentData=function(){this.frictionWorldTangential0=new Vecmath.Vec3;this.frictionWorldTangential1=new Vecmath.Vec3;this.frictionAngularComponent0A=new Vecmath.Vec3;this.frictionAngularComponent0B=new Vecmath.Vec3;this.frictionAngularComponent1A=new Vecmath.Vec3;this.frictionAngularComponent1B=new Vecmath.Vec3;this.angularComponentA=new Vecmath.Vec3;this.angularComponentB=new Vecmath.Vec3};a.ConstraintPersistentData.prototype.appliedImpulse=0;a.ConstraintPersistentData.prototype.prevAppliedImpulse=
0;a.ConstraintPersistentData.prototype.accumulatedTangentImpulse0=0;a.ConstraintPersistentData.prototype.accumulatedTangentImpulse1=0;a.ConstraintPersistentData.prototype.jacDiagABInv=0;a.ConstraintPersistentData.prototype.persistentLifeTime=0;a.ConstraintPersistentData.prototype.restitution=0;a.ConstraintPersistentData.prototype.friction=0;a.ConstraintPersistentData.prototype.penetration=0;a.SolverBody=function(){this.angularVelocity=new Vecmath.Vec3;this.linearVelocity=new Vecmath.Vec3;this.centerOfMassPosition=
new Vecmath.Vec3;this.pushVelocity=new Vecmath.Vec3;this.turnVelocity=new Vecmath.Vec3};a.SolverBody.prototype.internalApplyImpulse=function(a,d,c){this.invMass!=0&&(this.linearVelocity.scaleAdd(c,a,this.linearVelocity),this.angularVelocity.scaleAdd(c*this.angularFactor,d,this.angularVelocity))};a.SolverBody.prototype.writebackVelocity=function(){this.invMass!=0&&(this.originalBody.setLinearVelocity(this.linearVelocity),this.originalBody.setAngularVelocity(this.angularVelocity))};a.SolverBody.prototype.readVelocity=
function(){invMass!=0&&(this.originalBody.getLinearVelocity(this.linearVelocity),this.originalBody.getAngularVelocity(this.angularVelocity))};a.RigidBodyConstructionInfo=function(b,d,c,e){this.startWorldTransform=new a.Transform;this.localInertia=new Vecmath.Vec3;this.mass=b;this.motionState=d;this.collisionShape=c;this.localInertia.set1(e);this.startWorldTransform.setIdentity()};a.RigidBodyConstructionInfo.prototype.linearDamping=0;a.RigidBodyConstructionInfo.prototype.angularDamping=0;a.RigidBodyConstructionInfo.prototype.friction=
0.5;a.RigidBodyConstructionInfo.prototype.restitution=0;a.RigidBodyConstructionInfo.prototype.linearSleepingThreshold=0.8;a.RigidBodyConstructionInfo.prototype.angularSleepingThreshold=1;a.RigidBodyConstructionInfo.prototype.additionalDamping=!1;a.RigidBodyConstructionInfo.prototype.additionalDampingFactor=0.005;a.RigidBodyConstructionInfo.prototype.additionalLinearDampingThresholdSqr=0.01;a.RigidBodyConstructionInfo.prototype.additionalAngularDampingThresholdSqr=0.01;a.RigidBodyConstructionInfo.prototype.additionalAngularDampingFactor=
0.01;a.RigidBody=function(b){this.worldTransform=new a.Transform;this.interpolationWorldTransform=new a.Transform;this.interpolationLinearVelocity=new Vecmath.Vec3;this.interpolationAngularVelocity=new Vecmath.Vec3;this.collisionFlags=a.CollisionFlags.STATIC_OBJECT;this.companionId=this.islandTag1=-1;this.activationState1=1;this.friction=0.5;this.hitFraction=1;this.invInertiaTensorWorld=new Vecmath.Mat3;this.linearVelocity=new Vecmath.Vec3;this.angularVelocity=new Vecmath.Vec3;this.gravity=new Vecmath.Vec3;
this.invInertiaLocal=new Vecmath.Vec3;this.totalForce=new Vecmath.Vec3;this.totalTorque=new Vecmath.Vec3;this.constraintRefs=[];this.dir=new Vecmath.Vec3;this.tmp=new Vecmath.Vec3;this.t0=new Vecmath.Vec3;this.t1=new Vecmath.Vec3;this.mat1=new Vecmath.Mat3;this.mat2=new Vecmath.Mat3;this.setupRigidBody(b)};a.RigidBody.prototype=new a.CollisionObject;a.RigidBody.MAX_ANGVEL=a.BulletGlobals.SIMD_HALF_PI;a.RigidBody.uniqueId=0;a.RigidBody.prototype.setupRigidBody=function(b){this.internalType=a.CollisionObjectType.RIGID_BODY;
this.linearVelocity.set3(0,0,0);this.angularVelocity.set3(0,0,0);this.angularFactor=1;this.gravity.set3(0,0,0);this.totalForce.set3(0,0,0);this.totalTorque.set3(0,0,0);this.linearDamping=0;this.angularDamping=0.5;this.linearSleepingThreshold=b.linearSleepingThreshold;this.angularSleepingThreshold=b.angularSleepingThreshold;this.optionalMotionState=b.motionState;this.frictionSolverType=this.contactSolverType=0;this.additionalDamping=b.additionalDamping;this.additionalDampingFactor=b.additionalDampingFactor;
this.additionalLinearDampingThresholdSqr=b.additionalLinearDampingThresholdSqr;this.additionalAngularDampingThresholdSqr=b.additionalAngularDampingThresholdSqr;this.additionalAngularDampingFactor=b.additionalAngularDampingFactor;this.optionalMotionState!=null?this.optionalMotionState.getWorldTransform(this.worldTransform):this.worldTransform.setT(b.startWorldTransform);this.interpolationWorldTransform.setT(this.worldTransform);this.interpolationLinearVelocity.set3(0,0,0);this.interpolationAngularVelocity.set3(0,
0,0);this.friction=b.friction;this.restitution=b.restitution;this.setCollisionShape(b.collisionShape);this.debugBodyId=a.RigidBody.uniqueId++;this.setMassProps(b.mass,b.localInertia);this.setDamping(b.linearDamping,b.angularDamping);this.updateInertiaTensor()};a.RigidBody.prototype.proceedToTransform=function(a){this.setCenterOfMassTransform(a)};a.RigidBody.upcast=function(b){if(b.internalType==a.CollisionObjectType.RIGID_BODY)return b;return null};a.RigidBody.prototype.predictIntegratedTransform=
function(b,d){a.TransformUtil.integrateTransform(this.worldTransform,this.linearVelocity,this.angularVelocity,b,d)};a.RigidBody.prototype.applyGravity=function(){this.isStaticOrKinematicObject()||this.applyCentralForce(this.gravity)};a.RigidBody.prototype.setGravity=function(a){this.inverseMass!=0&&this.gravity.scale2(1/this.inverseMass,a)};a.RigidBody.prototype.setDamping=function(b,d){this.linearDamping=a.MiscUtil.GEN_clamped(b,0,1);this.angularDamping=a.MiscUtil.GEN_clamped(d,0,1)};a.RigidBody.prototype.applyDamping=
function(b){this.linearVelocity.scale1(a.MiscUtil.GEN_clamped(1-b*this.linearDamping,0,1));this.angularVelocity.scale1(a.MiscUtil.GEN_clamped(1-b*this.angularDamping,0,1));this.additionalDamping&&(this.angularVelocity.lengthSquared()<this.additionalAngularDampingThresholdSqr&&this.linearVelocity.lengthSquared()<this.additionalLinearDampingThresholdSqr&&(this.angularVelocity.scale(this.additionalDampingFactor),this.linearVelocity.scale(this.additionalDampingFactor)),b=this.linearVelocity.length(),
b<this.linearDamping&&(b>0.005?(this.dir.set1(this.linearVelocity),this.dir.normalize(),this.dir.scale(0.005),this.linearVelocity.sub(this.dir)):this.linearVelocity.set(0,0,0)),b=this.angularVelocity.length(),b<this.angularDamping&&(b>0.005?(this.dir.set1(this.angularVelocity),this.dir.normalize(),this.dir.scale(0.005),this.angularVelocity.sub(dir)):this.angularVelocity.set(0,0,0)))};a.RigidBody.prototype.setMassProps=function(b,d){b==0?(this.collisionFlags|=a.CollisionFlags.STATIC_OBJECT,this.inverseMass=
0):(this.collisionFlags&=~a.CollisionFlags.STATIC_OBJECT,this.inverseMass=1/b);this.invInertiaLocal.set3(d.x!=0?1/d.x:0,d.y!=0?1/d.y:0,d.z!=0?1/d.z:0)};a.RigidBody.prototype.getInvInertiaTensorWorld=function(a){a.set1(this.invInertiaTensorWorld);return a};a.RigidBody.prototype.integrateVelocities=function(b){if(!this.isStaticOrKinematicObject()){this.linearVelocity.scaleAdd(this.inverseMass*b,this.totalForce,this.linearVelocity);this.tmp.set1(this.totalTorque);this.invInertiaTensorWorld.transform1(this.tmp);
this.angularVelocity.scaleAdd(b,this.tmp,this.angularVelocity);var d=this.angularVelocity.length();d*b>a.RigidBody.MAX_ANGVEL&&this.angularVelocity.scale(a.RigidBody.MAX_ANGVEL/b/d)}};a.RigidBody.prototype.setCenterOfMassTransform=function(a){this.isStaticOrKinematicObject()?this.interpolationWorldTransform.set(this.worldTransform):this.interpolationWorldTransform.setT(a);this.getLinearVelocity(this.interpolationLinearVelocity);this.getAngularVelocity(this.interpolationAngularVelocity);this.worldTransform.setT(a);
this.updateInertiaTensor()};a.RigidBody.prototype.applyCentralForce=function(a){this.totalForce.add1(a)};a.RigidBody.prototype.clearForces=function(){this.totalForce.set3(0,0,0);this.totalTorque.set3(0,0,0)};a.RigidBody.prototype.updateInertiaTensor=function(){a.MatrixUtil.scale(this.mat1,this.worldTransform.basis,this.invInertiaLocal);this.mat2.set1(this.worldTransform.basis);this.mat2.transpose();this.invInertiaTensorWorld.mul2(this.mat1,this.mat2)};a.RigidBody.prototype.getLinearVelocity=function(a){a.set1(this.linearVelocity);
return a};a.RigidBody.prototype.getAngularVelocity=function(a){a.set1(this.angularVelocity);return a};a.RigidBody.prototype.setLinearVelocity=function(a){this.linearVelocity.set1(a)};a.RigidBody.prototype.setAngularVelocity=function(a){this.angularVelocity.set1(a)};a.RigidBody.prototype.getVelocityInLocalPoint=function(a,d){d.cross(this.angularVelocity,a);d.add1(this.linearVelocity);return d};a.RigidBody.prototype.updateDeactivation=function(b){if(!(this.activationState1==a.CollisionObject.ISLAND_SLEEPING||
this.activationState1==a.CollisionObject.DISABLE_DEACTIVATION))this.getLinearVelocity(this.t0).lengthSquared()<this.linearSleepingThreshold*this.linearSleepingThreshold&&this.getAngularVelocity(this.t1).lengthSquared()<this.angularSleepingThreshold*this.angularSleepingThreshold?this.deactivationTime+=b:(this.deactivationTime=0,this.setActivationState(0))};a.RigidBody.prototype.wantsSleeping=function(){if(this.activationState1==a.CollisionObject.DISABLE_DEACTIVATION)return!1;if(a.BulletGlobals.disableDeactivation||
a.BulletGlobals.deactivationTime==0)return!1;if(this.activationState1==a.CollisionObject.ISLAND_SLEEPING||this.activationState1==a.CollisionObject.WANTS_DEACTIVATION)return!0;if(this.deactivationTime>a.BulletGlobals.deactivationTime)return!0;return!1};a.SolverConstraintType={SOLVER_CONTACT_1D:0,SOLVER_FRICTION_1D:1};a.SolverConstraint=function(){this.relpos1CrossNormal=new Vecmath.Vec3;this.contactNormal=new Vecmath.Vec3;this.relpos2CrossNormal=new Vecmath.Vec3;this.angularComponentA=new Vecmath.Vec3;
this.angularComponentB=new Vecmath.Vec3};a.ContactConstraintEnum={DEFAULT_CONTACT_SOLVER_TYPE:0,CONTACT_SOLVER_TYPE1:1,CONTACT_SOLVER_TYPE2:2,USER_CONTACT_SOLVER_TYPE1:3,MAX_CONTACT_SOLVER_TYPES:4};a.OrderIndex=function(){};a.OrderIndex.prototype.manifoldIndex=0;a.OrderIndex.prototype.pointIndex=0;a.poolSolverBody=new a.ObjectPool(function(){return new a.SolverBody});a.poolSolverConstraint=new a.ObjectPool(function(){return new a.SolverConstraint});a.ConstraintSolver=function(){this.gOrder=Array(a.ConstraintSolver.SEQUENTIAL_IMPULSE_MAX_SOLVER_POINTS);
this.bodiesPool=a.poolSolverBody;this.constraintsPool=a.poolSolverConstraint;this.tmpSolverBodyPool=[];this.tmpSolverConstraintPool=[];this.tmpSolverFrictionConstraintPool=[];this.orderTmpConstraintPool=new a.ObjectArrayList;this.orderFrictionConstraintPool=new a.ObjectArrayList;this.tr0=new a.Transform;this.tmp=new Vecmath.Vec3;this.ftorqueAxis1=new Vecmath.Vec3;this.vec=new Vecmath.Vec3;this.tmpMat=new Vecmath.Mat3;this.tmpTrans=new a.Transform;this.rel_pos1=new Vecmath.Vec3;this.rel_pos2=new Vecmath.Vec3;
this.pos1=new Vecmath.Vec3;this.pos2=new Vecmath.Vec3;this.vel=new Vecmath.Vec3;this.torqueAxis0=new Vecmath.Vec3;this.torqueAxis1=new Vecmath.Vec3;this.vel1=new Vecmath.Vec3;this.vel2=new Vecmath.Vec3;this.frictionDir1=new Vecmath.Vec3;this.frictionDir2=new Vecmath.Vec3;for(var b=0;b<this.gOrder.length;b++)this.gOrder[b]=new a.OrderIndex};a.ConstraintSolver.MAX_CONTACT_SOLVER_TYPES=a.ContactConstraintEnum.MAX_CONTACT_SOLVER_TYPES;a.ConstraintSolver.SEQUENTIAL_IMPULSE_MAX_SOLVER_POINTS=16384;a.ConstraintSolver.prototype.totalCpd=
0;a.ConstraintSolver.prototype.bodiesPool=a.poolSolverBody;a.ConstraintSolver.prototype.constraintsPool=a.poolSolverConstraint;a.ConstraintSolver.prototype.btSeed2=0;a.ConstraintSolver.prototype.prepareSolve=function(){};a.ConstraintSolver.prototype.allSolved=function(){};a.ConstraintSolver.prototype.rand2=function(){return this.btSeed2=1664525*this.btSeed2+1013904223&4294967295};a.ConstraintSolver.prototype.randInt2=function(a){var d=this.rand2();a<=65536&&(d^=d>>>16,a<=256&&(d^=d>>>8,a<=16&&(d^=
d>>>4,a<=4&&(d^=d>>>2,a<=2&&(d^=d>>>1)))));return Math.abs(d%a)};a.ConstraintSolver.prototype.initSolverBody=function(b,d){var c=a.RigidBody.upcast(d);c!=null?(c.getAngularVelocity(b.angularVelocity),b.centerOfMassPosition.set1(d.getWorldTransform(this.tr0).origin),b.friction=d.friction,b.invMass=c.inverseMass,c.getLinearVelocity(b.linearVelocity),b.originalBody=c,b.angularFactor=c.angularFactor):(b.angularVelocity.set3(0,0,0),b.centerOfMassPosition.set1(d.getWorldTransform(this.tr0).origin),b.friction=
d.friction,b.invMass=0,b.linearVelocity.set3(0,0,0),b.originalBody=null,b.angularFactor=1);b.pushVelocity.set3(0,0,0);b.turnVelocity.set3(0,0,0)};a.ConstraintSolver.prototype.restitutionCurve=function(a,d){return d*-a};a.ConstraintSolver.prototype.resolveSingleCollisionCombinedCacheFriendly=function(a,d,c,e){var f;f=c.contactNormal.dot(a.linearVelocity)+c.relpos1CrossNormal.dot(a.angularVelocity);var g=c.contactNormal.dot(d.linearVelocity)+c.relpos2CrossNormal.dot(d.angularVelocity),h=0;if(!e.splitImpulse||
c.penetration>e.splitImpulsePenetrationThreshold)h=-c.penetration*e.erp/e.timeStep;f=h*c.jacDiagABInv+(c.restitution-(f-g))*c.jacDiagABInv;e=c.appliedImpulse;f=e+f;c.appliedImpulse=0>f?0:f;f=c.appliedImpulse-e;this.tmp.scale2(a.invMass,c.contactNormal);a.internalApplyImpulse(this.tmp,c.angularComponentA,f);this.tmp.scale2(d.invMass,c.contactNormal);d.internalApplyImpulse(this.tmp,c.angularComponentB,-f);return f};a.ConstraintSolver.prototype.resolveSingleFrictionCacheFriendly=function(a,d,c,e,f){e=
f*c.friction;if(f>0){var f=c.contactNormal.dot(a.linearVelocity)+c.relpos1CrossNormal.dot(a.angularVelocity),g=c.contactNormal.dot(d.linearVelocity)+c.relpos2CrossNormal.dot(d.angularVelocity),f=-(f-g)*c.jacDiagABInv,g=c.appliedImpulse;c.appliedImpulse=g+f;if(e<c.appliedImpulse)c.appliedImpulse=e;else if(c.appliedImpulse<-e)c.appliedImpulse=-e;f=c.appliedImpulse-g;this.tmp.scale2(a.invMass,c.contactNormal);a.internalApplyImpulse(this.tmp,c.angularComponentA,f);this.tmp.scale2(d.invMass,c.contactNormal);
d.internalApplyImpulse(this.tmp,c.angularComponentB,-f)}return 0};a.ConstraintSolver.prototype.addFrictionConstraint=function(b,d,c,e,f,g,h,j,i,m){var j=a.RigidBody.upcast(j),i=a.RigidBody.upcast(i),k=this.constraintsPool.get();this.tmpSolverFrictionConstraintPool.push(k);k.contactNormal.set1(b);k.solverBodyIdA=d;k.solverBodyIdB=c;k.constraintType=a.SolverConstraintType.SOLVER_FRICTION_1D;k.frictionIndex=e;k.friction=f.combinedFriction;k.originalContactPoint=null;k.appliedImpulse=0;k.appliedPushImpulse=
0;k.penetration=0;this.ftorqueAxis1.cross(g,k.contactNormal);k.relpos1CrossNormal.set1(this.ftorqueAxis1);j!=null?(k.angularComponentA.set1(this.ftorqueAxis1),j.getInvInertiaTensorWorld(this.tmpMat).transform1(k.angularComponentA)):k.angularComponentA.set3(0,0,0);this.ftorqueAxis1.cross(h,k.contactNormal);k.relpos2CrossNormal.set1(this.ftorqueAxis1);i!=null?(k.angularComponentB.set1(this.ftorqueAxis1),i.getInvInertiaTensorWorld(this.tmpMat).transform1(k.angularComponentB)):k.angularComponentB.set3(0,
0,0);c=d=0;j!=null&&(this.vec.cross(k.angularComponentA,g),d=j.inverseMass+b.dot(this.vec));i!=null&&(this.vec.cross(k.angularComponentB,h),c=i.inverseMass+b.dot(this.vec));k.jacDiagABInv=m/(d+c)};a.ConstraintSolver.prototype.solveGroupCacheFriendlySetup=function(b,d,c,e,f,g,h,j,i){if(j+f==0)return 0;h=g=d=null;this.rel_pos1.set3(0,0,0);this.rel_pos2.set3(0,0,0);this.pos1.set3(0,0,0);this.pos2.set3(0,0,0);this.vel.set3(0,0,0);this.torqueAxis0.set3(0,0,0);this.torqueAxis1.set3(0,0,0);this.vel1.set3(0,
0,0);this.vel2.set3(0,0,0);this.frictionDir1.set3(0,0,0);this.frictionDir2.set3(0,0,0);this.vec.set3(0,0,0);for(b=0;b<f;b++){var d=c[e+b],g=d.body0,h=d.body1,m=j=-1;if(d.cachedPoints!=0){if(g.islandTag1>=0)if(g.companionId>=0)j=g.companionId;else{var j=this.tmpSolverBodyPool.length,k=this.bodiesPool.get();this.tmpSolverBodyPool.push(k);this.initSolverBody(k,g);g.companionId=j}else j=this.tmpSolverBodyPool.length,k=this.bodiesPool.get(),this.tmpSolverBodyPool.push(k),this.initSolverBody(k,g);h.islandTag1>=
0?h.companionId>=0?m=h.companionId:(m=this.tmpSolverBodyPool.length,k=this.bodiesPool.get(),this.tmpSolverBodyPool.push(k),this.initSolverBody(k,h),h.companionId=m):(m=this.tmpSolverBodyPool.size(),k=this.bodiesPool.get(),this.tmpSolverBodyPool.add(k),this.initSolverBody(k,h))}for(k=0;k<d.cachedPoints;k++){var l=d.pointCache[k];if(l.distance1<=0){l.getPositionWorldOnA(this.pos1);l.getPositionWorldOnB(this.pos2);this.rel_pos1.sub2(this.pos1,g.getWorldTransform(this.tmpTrans).origin);this.rel_pos2.sub2(this.pos2,
h.getWorldTransform(this.tmpTrans).origin);var o,p=this.tmpSolverConstraintPool.length,n=this.constraintsPool.get();this.tmpSolverConstraintPool.push(n);var q=a.RigidBody.upcast(g),r=a.RigidBody.upcast(h);n.solverBodyIdA=j;n.solverBodyIdB=m;n.constraintType=a.SolverConstraintType.SOLVER_CONTACT_1D;n.originalContactPoint=l;this.torqueAxis0.cross(this.rel_pos1,l.normalWorldOnB);q!=null?(n.angularComponentA.set1(this.torqueAxis0),q.getInvInertiaTensorWorld(this.tmpMat).transform1(n.angularComponentA)):
n.angularComponentA.set3(0,0,0);this.torqueAxis1.cross(this.rel_pos2,l.normalWorldOnB);r!=null?(n.angularComponentB.set1(this.torqueAxis1),r.getInvInertiaTensorWorld(this.tmpMat).transform1(n.angularComponentB)):n.angularComponentB.set3(0,0,0);var s=o=0;q!=null&&(this.vec.cross(n.angularComponentA,this.rel_pos1),o=q.inverseMass+l.normalWorldOnB.dot(this.vec));r!=null&&(this.vec.cross(n.angularComponentB,this.rel_pos2),s=r.inverseMass+l.normalWorldOnB.dot(this.vec));n.jacDiagABInv=1/(o+s);n.contactNormal.set1(l.normalWorldOnB);
n.relpos1CrossNormal.cross(this.rel_pos1,l.normalWorldOnB);n.relpos2CrossNormal.cross(this.rel_pos2,l.normalWorldOnB);q!=null?q.getVelocityInLocalPoint(this.rel_pos1,this.vel1):this.vel1.set3(0,0,0);r!=null?r.getVelocityInLocalPoint(this.rel_pos2,this.vel2):vel2.set3(0,0,0);this.vel.sub2(this.vel1,this.vel2);o=l.normalWorldOnB.dot(this.vel);n.penetration=Math.min(l.distance1+i.linearSlop,0);n.friction=l.combinedFriction;n.restitution=this.restitutionCurve(o,l.combinedRestitution);if(n.restitution<=
0)n.restitution=0;if(n.restitution>-n.penetration/i.timeStep)n.penetration=0;this.tmp.set3(0,0,0);(i.solverMode&a.SolverMode.SOLVER_USE_WARMSTARTING)!=0?(n.appliedImpulse=l.appliedImpulse*i.warmstartingFactor,q!=null&&(this.tmp.scale2(q.inverseMass,n.contactNormal),this.tmpSolverBodyPool[n.solverBodyIdA].internalApplyImpulse(this.tmp,n.angularComponentA,n.appliedImpulse)),r!=null&&(this.tmp.scale2(r.inverseMass,n.contactNormal),this.tmpSolverBodyPool[n.solverBodyIdB].internalApplyImpulse(this.tmp,
n.angularComponentB,-n.appliedImpulse))):n.appliedImpulse=0;n.appliedPushImpulse=0;n.frictionIndex=this.tmpSolverFrictionConstraintPool.length;l.lateralFrictionInitialized?(this.addFrictionConstraint(l.lateralFrictionDir1,j,m,p,l,this.rel_pos1,this.rel_pos2,g,h,1),this.addFrictionConstraint(l.lateralFrictionDir2,j,m,p,l,this.rel_pos1,this.rel_pos2,g,h,1)):(l.lateralFrictionDir1.scale2(this.rel_vel,l.normalWorldOnB),l.lateralFrictionDir1.sub2(this.vel,l.lateralFrictionDir1),o=l.lateralFrictionDir1.lengthSquared(),
o>a.BulletGlobals.FLT_EPSILON?(l.lateralFrictionDir1.scale(1/Math.sqrt(o)),this.addFrictionConstraint(l.lateralFrictionDir1,j,m,p,l,rel_pos1,rel_pos2,g,h,1),l.lateralFrictionDir2.cross(l.lateralFrictionDir1,l.normalWorldOnB),l.lateralFrictionDir2.normalize(),this.addFrictionConstraint(l.lateralFrictionDir2,j,m,p,l,rel_pos1,rel_pos2,g,h,1)):(a.TransformUtil.planeSpace1(l.normalWorldOnB,l.lateralFrictionDir1,l.lateralFrictionDir2),this.addFrictionConstraint(l.lateralFrictionDir1,j,m,p,l,this.rel_pos1,
this.rel_pos2,g,h,1),this.addFrictionConstraint(l.lateralFrictionDir2,j,m,p,l,this.rel_pos1,this.rel_pos2,g,h,1)),l.lateralFrictionInitialized=!0);p=this.tmpSolverFrictionConstraintPool[n.frictionIndex];(i.solverMode&a.SolverMode.SOLVER_USE_WARMSTARTING)!=0?(p.appliedImpulse=l.appliedImpulseLateral1*i.warmstartingFactor,q!=null&&(this.tmp.scale2(q.inverseMass,p.contactNormal),this.tmpSolverBodyPool[n.solverBodyIdA].internalApplyImpulse(this.tmp,p.angularComponentA,p.appliedImpulse)),r!=null&&(this.tmp.scale2(r.inverseMass,
p.contactNormal),this.tmpSolverBodyPool[n.solverBodyIdB].internalApplyImpulse(this.tmp,p.angularComponentB,-p.appliedImpulse))):p.appliedImpulse=0;p=this.tmpSolverFrictionConstraintPool[n.frictionIndex+1];(i.solverMode&a.SolverMode.SOLVER_USE_WARMSTARTING)!=0?(p.appliedImpulse=l.appliedImpulseLateral2*i.warmstartingFactor,q!=null&&(this.tmp.scale2(q.inverseMass,p.contactNormal),this.tmpSolverBodyPool[n.solverBodyIdA].internalApplyImpulse(this.tmp,p.angularComponentA,p.appliedImpulse)),r!=null&&(this.tmp.scale2(r.inverseMass,
p.contactNormal),this.tmpSolverBodyPool[n.solverBodyIdB].internalApplyImpulse(this.tmp,p.angularComponentB,-p.appliedImpulse))):p.appliedImpulse=0}}}c=this.tmpSolverConstraintPool.length;e=this.tmpSolverFrictionConstraintPool.length;a.MiscUtil.resizec(this.orderTmpConstraintPool,c,0);a.MiscUtil.resizec(this.orderFrictionConstraintPool,e,0);for(b=0;b<c;b++)this.orderTmpConstraintPool.set(b,b);for(b=0;b<e;b++)this.orderFrictionConstraintPool.set(b,b);return 0};a.ConstraintSolver.prototype.solveGroupCacheFriendlyIterations=
function(b,d,c,e,f,g,h,j,i){b=this.tmpSolverConstraintPool.length;d=this.tmpSolverFrictionConstraintPool.length;for(c=0;c<i.numIterations;c++){if((i.solverMode&a.SolverMode.SOLVER_RANDMIZE_ORDER)!=0&&(c&7)==0){for(e=0;e<b;++e)f=this.orderTmpConstraintPool.get(e),g=this.randInt2(e+1),this.orderTmpConstraintPool.set(e,this.orderTmpConstraintPool.get(g)),this.orderTmpConstraintPool.set(g,f);for(e=0;e<d;++e)f=this.orderFrictionConstraintPool.get(e),g=this.randInt2(e+1),this.orderFrictionConstraintPool.set(e,
this.orderFrictionConstraintPool.get(g)),this.orderFrictionConstraintPool.set(g,f)}g=this.tmpSolverConstraintPool.length;for(e=0;e<g;e++)f=this.tmpSolverConstraintPool[this.orderTmpConstraintPool.get(e)],this.resolveSingleCollisionCombinedCacheFriendly(this.tmpSolverBodyPool[f.solverBodyIdA],this.tmpSolverBodyPool[f.solverBodyIdB],f,i);g=this.tmpSolverFrictionConstraintPool.length;for(e=0;e<g;e++)f=this.tmpSolverFrictionConstraintPool[this.orderFrictionConstraintPool.get(e)],this.resolveSingleFrictionCacheFriendly(this.tmpSolverBodyPool[f.solverBodyIdA],
this.tmpSolverBodyPool[f.solverBodyIdB],f,i,this.tmpSolverConstraintPool[f.frictionIndex].appliedImpulse+this.tmpSolverConstraintPool[f.frictionIndex].appliedPushImpulse)}if(i.splitImpulse)for(c=0;c<i.numIterations;c++){g=this.tmpSolverConstraintPool.size();for(e=0;e<g;)throw this.tmpSolverConstraintPool.get(orderTmpConstraintPool.get(e)),Error("n/i");}return 0};a.ConstraintSolver.prototype.solveGroupCacheFriendly=function(a,d,c,e,f,g,h,j,i){this.solveGroupCacheFriendlySetup(a,d,c,e,f,g,h,j,i);this.solveGroupCacheFriendlyIterations(a,
d,c,e,f,g,h,j,i);a=this.tmpSolverConstraintPool.length;for(d=0;d<a;d++)c=this.tmpSolverConstraintPool[d],e=c.originalContactPoint,e.appliedImpulse=c.appliedImpulse,e.appliedImpulseLateral1=this.tmpSolverFrictionConstraintPool[c.frictionIndex].appliedImpulse,e.appliedImpulseLateral1=this.tmpSolverFrictionConstraintPool[c.frictionIndex+1].appliedImpulse;if(i.splitImpulse)for(i=0;i<this.tmpSolverBodyPool.size();)throw Error("n/i");else for(i=0;i<this.tmpSolverBodyPool.length;i++)this.tmpSolverBodyPool[i].writebackVelocity(),
this.bodiesPool.release(this.tmpSolverBodyPool[i]);this.tmpSolverBodyPool.splice(0,this.tmpSolverBodyPool.length);for(i=0;i<this.tmpSolverConstraintPool.length;i++)this.constraintsPool.release(this.tmpSolverConstraintPool[i]);this.tmpSolverConstraintPool.splice(0,this.tmpSolverConstraintPool.length);for(i=0;i<this.tmpSolverFrictionConstraintPool.length;i++)this.constraintsPool.release(this.tmpSolverFrictionConstraintPool[i]);this.tmpSolverFrictionConstraintPool.splice(0,this.tmpSolverFrictionConstraintPool.length);
return 0};a.ConstraintSolver.prototype.solveGroup=function(b,d,c,e,f,g,h,j,i){if((i.solverMode&a.SolverMode.SOLVER_CACHE_FRIENDLY)!=0)return this.solveGroupCacheFriendly(b,d,c,e,f,g,h,j,i);throw Error("\u20ac");};a.IslandCallback=function(){};a.IslandCallback.prototype.numConstraints=0;a.IslandCallback.prototype.init=function(a,d,c,e,f){this.solverInfo=a;this.solver=d;this.sortedConstraints=c;this.numConstraints=e;this.dispatcher=f};a.IslandCallback.prototype.processIsland=function(a,d,c,e,f,g){g<
0||f+0>0&&this.solver.solveGroup(a,d,c,e,f,this.sortedConstraints,-1,0,this.solverInfo,this.dispatcher)};a.CollisionWorld=function(b,d,c){this.collisionObjects=[];this.dispatchInfo=new a.DispatcherInfo;this.trans=new a.Transform;this.tmpTrans=new a.Transform;this.minAabb=new Vecmath.Vec3;this.maxAabb=new Vecmath.Vec3;this.tmp=new Vecmath.Vec3;this.solverInfo=new a.ContactSolverInfo;this.constraints=[];this.gravity=new Vecmath.Vec3(0,-10,0);this.interpolatedTransform=new a.Transform;this.tmpLinVel=
new Vecmath.Vec3;this.tmpAngVel=new Vecmath.Vec3;this.sortedConstraints=[];this.solverCallback=new a.IslandCallback;this.predictedTrans=new a.Transform;this.dispatcher1=b;this.broadphasePairCache=d;this.constraintSolver=c;this.constraintSolver==null?(this.constraintSolver=new a.ConstraintSolver,this.ownsConstraintSolver=!0):this.ownsConstraintSolver=!1;this.islandManager=new a.SimulationIslandManager;this.ownsIslandManager=!0};a.CollisionWorld.prototype.addCollisionObject=function(a,d,c){this.collisionObjects.push(a);
this.trans=a.getWorldTransform(this.trans);this.minAabb.set3(0,0,0);this.maxAabb.set3(0,0,0);a.collisionShape.getAabb(this.trans,this.minAabb,this.maxAabb);var e=a.collisionShape.getShapeType();a.broadphaseHandle=this.broadphasePairCache.createProxy(this.minAabb,this.maxAabb,e,a,d,c,this.dispatcher1,null)};a.CollisionWorld.prototype.performDiscreteCollisionDetection=function(){this.updateAabbs();this.broadphasePairCache.calculateOverlappingPairs(this.dispatcher1);var a=this.dispatcher1;a!=null&&a.dispatchAllCollisionPairs(this.broadphasePairCache.pairCache,
this.dispatchInfo,this.dispatcher1)};a.CollisionWorld.prototype.getPairCache=function(){return this.broadphasePairCache.pairCache};a.CollisionWorld.prototype.updateSingleAabb=function(b){this.minAabb.set3(0,0,0);this.maxAabb.set3(0,0,0);this.tmp.set3(0,0,0);b.collisionShape.getAabb(b.getWorldTransform(this.tmpTrans),this.minAabb,this.maxAabb);var d=this.broadphasePairCache;this.tmp.sub2(this.maxAabb,this.minAabb);b.isStaticObject()||this.tmp.lengthSquared()<1E12?d.setAabb(b.broadphaseHandle,this.minAabb,
this.maxAabb,this.dispatcher1):b.setActivationState(a.CollisionObject.DISABLE_SIMULATION)};a.CollisionWorld.prototype.updateAabbs=function(){for(var a=0;a<this.collisionObjects.length;a++){var d=this.collisionObjects[a];d.isActive()&&this.updateSingleAabb(d)}};a.CollisionWorld.prototype.getNumCollisionObjects=function(){return this.collisionObjects.length};a.CollisionWorld.prototype.stepSimulation1=function(a){return this.stepSimulation3(a,1,1/60)};a.CollisionWorld.prototype.localTime=1/60;a.CollisionWorld.prototype.ownsConstraintSolver=
!1;a.CollisionWorld.prototype.profileTimings=0;a.CollisionWorld.prototype.saveKinematicState=function(){for(var b=0;b<this.collisionObjects.length;b++){var d=a.RigidBody.upcast(this.collisionObjects[b]);d!=null&&d.activationState1!=a.CollisionObject.ISLAND_SLEEPING&&d.isKinematicObject()}};a.CollisionWorld.prototype.clearForces=function(){for(var b=0;b<this.collisionObjects.length;b++){var d=a.RigidBody.upcast(this.collisionObjects[b]);d!=null&&d.clearForces()}};a.CollisionWorld.prototype.applyGravity=
function(){for(var b=0;b<this.collisionObjects.length;b++){var d=a.RigidBody.upcast(this.collisionObjects[b]);d!=null&&d.isActive()&&d.applyGravity()}};a.CollisionWorld.prototype.synchronizeMotionStates=function(){for(var b=0;b<this.collisionObjects.length;b++){var d=a.RigidBody.upcast(this.collisionObjects[b]);d!=null&&d.optionalMotionState!=null&&!d.isStaticOrKinematicObject()&&(a.TransformUtil.integrateTransform(d.getInterpolationWorldTransform(this.tmpTrans),d.getInterpolationLinearVelocity(this.tmpLinVel),
d.getInterpolationAngularVelocity(this.tmpAngVel),this.localTime,this.interpolatedTransform),d.optionalMotionState.setWorldTransform(this.interpolatedTransform))}};a.CollisionWorld.prototype.stepSimulation3=function(b,d,c){(new Date).getTime();var e=0;d!=0?(this.localTime+=b,this.localTime>=c&&(e=Math.floor(this.localTime/c),this.localTime-=e*c)):(localTime=c=b,d=a.ScalarUtil.fuzzyZero(b)?e=0:e=1);if(e!=0){this.saveKinematicState(c);this.applyGravity();b=e>d?d:e;for(d=0;d<b;d++)this.internalSingleStepSimulation(c),
this.synchronizeMotionStates()}this.synchronizeMotionStates();this.clearForces();return e};a.CollisionWorld.prototype.internalSingleStepSimulation=function(a){this.predictUnconstraintMotion(a);var d=this.dispatchInfo;d.timeStep=a;d.stepCount=0;this.performDiscreteCollisionDetection();this.calculateSimulationIslands();this.solverInfo.timeStep=a;this.solveConstraints(this.solverInfo);this.integrateTransforms(a);this.updateActivationState(a)};a.CollisionWorld.prototype.setGravity=function(b){this.gravity.set1(b);
for(var d=0;d<this.collisionObjects.length;d++){var c=this.collisionObjects.get(d),c=a.RigidBody.upcast(c);c!=null&&c.setGravity(b)}};a.CollisionWorld.prototype.addRigidBody=function(b){b.isStaticOrKinematicObject()||b.setGravity(this.gravity);if(b.collisionShape!=null){var d=!(b.isStaticObject()||b.isKinematicObject());this.addCollisionObject(b,d?a.CollisionFilterGroups.DEFAULT_FILTER:a.CollisionFilterGroups.STATIC_FILTER,d?a.CollisionFilterGroups.ALL_FILTER:a.CollisionFilterGroups.ALL_FILTER^a.CollisionFilterGroups.STATIC_FILTER)}};
a.CollisionWorld.prototype.updateActivationState=function(b){for(var d=0;d<this.collisionObjects.length;d++){var c=a.RigidBody.upcast(this.collisionObjects[d]);c!=null&&(c.updateDeactivation(b),c.wantsSleeping()?c.isStaticOrKinematicObject()?c.setActivationState(a.CollisionObject.ISLAND_SLEEPING):c.activationState1==a.CollisionObject.ACTIVE_TAG&&c.setActivationState(a.CollisionObject.WANTS_DEACTIVATION):c.activationState1!=a.CollisionObject.DISABLE_DEACTIVATION&&c.setActivationState(a.CollisionObject.ACTIVE_TAG))}};
a.CollisionWorld.prototype.solveConstraints=function(a){this.sortedConstraints.splice(0,this.sortedConstraints.length);for(var d=0;d<this.constraints.length;d++)this.sortedConstraints.add(this.constraints[d]);this.getNumConstraints();this.solverCallback.init(a,this.constraintSolver,this.constraintsPtr,this.sortedConstraints.length,this.dispatcher1);this.constraintSolver.prepareSolve(this.getNumCollisionObjects(),this.dispatcher1.getNumManifolds());this.islandManager.buildAndProcessIslands(this.dispatcher1,
this.collisionObjects,this.solverCallback);this.constraintSolver.allSolved(a)};a.CollisionWorld.prototype.calculateSimulationIslands=function(){this.islandManager.updateActivationState(this,this.dispatcher1);this.islandManager.storeIslandActivationState(this)};a.CollisionWorld.prototype.integrateTransforms=function(b){for(var d=0;d<this.collisionObjects.length;d++){var c=a.RigidBody.upcast(this.collisionObjects[d]);c!=null&&c.isActive()&&!c.isStaticOrKinematicObject()&&(c.predictIntegratedTransform(b,
this.predictedTrans),c.proceedToTransform(this.predictedTrans))}};a.CollisionWorld.prototype.predictUnconstraintMotion=function(b){for(var d=0;d<this.collisionObjects.length;d++){var c=a.RigidBody.upcast(this.collisionObjects[d]);c!=null&&!c.isStaticOrKinematicObject()&&c.isActive()&&(c.integrateVelocities(b),c.applyDamping(b),c.predictIntegratedTransform(b,c.getInterpolationWorldTransform(this.tmpTrans)))}};a.CollisionWorld.prototype.debugDrawSphere=function(){};a.CollisionWorld.prototype.debugDrawObject=
function(){};a.CollisionWorld.prototype.getNumConstraints=function(){return this.constraints.length}})(Bullet);