math.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. import * as THREE from "../../libs/three.js/build/three.module.js";
  2. import searchRings from "./searchRings.js";
  3. var math = {
  4. getBaseLog(x, y) {//返回以 x 为底 y 的对数(即 logx y) . Math.log 返回一个数的自然对数
  5. return Math.log(y) / Math.log(x);
  6. }
  7. ,
  8. convertVector : {
  9. ZupToYup: function(e){//navvis -> 4dkk
  10. return new THREE.Vector3(e.x,e.z,-e.y)
  11. },
  12. YupToZup: function(e){//4dkk -> navvis
  13. return new THREE.Vector3(e.x,-e.z,e.y)
  14. },
  15. },
  16. convertQuaternion: {
  17. ZupToYup: function(e){//navvis -> 4dkk //不同于convertVisionQuaternion
  18. let rotation = new THREE.Euler(-Math.PI/2,0,0)
  19. let quaternion = new THREE.Quaternion().setFromEuler(rotation)
  20. return e.clone().premultiply(quaternion)
  21. //return new THREE.Quaternion(e.x,e.z,-e.y,e.w).multiply((new THREE.Quaternion).setFromAxisAngle(new THREE.Vector3(1,0,0), THREE.Math.degToRad(90)))
  22. },
  23. YupToZup: function(e){//4dkk -> navvis
  24. let rotation = new THREE.Euler(Math.PI/2,0,0)
  25. let quaternion = new THREE.Quaternion().setFromEuler(rotation)
  26. return e.clone().premultiply(quaternion)
  27. },
  28. },
  29. convertVisionQuaternion: function(e) {
  30. return new THREE.Quaternion(e.x,e.z,-e.y,e.w).multiply((new THREE.Quaternion).setFromAxisAngle(new THREE.Vector3(0,1,0), THREE.Math.degToRad(90)))
  31. },
  32. invertVisionQuaternion : function(e) {//反转给算法部
  33. var a = e.clone().multiply((new THREE.Quaternion).setFromAxisAngle(new THREE.Vector3(0,1,0), THREE.Math.degToRad(-90)))
  34. return new THREE.Quaternion(a.x,-a.z,a.y,a.w)
  35. },
  36. //------------
  37. getVec2Angle : function(dir1,dir2){
  38. return Math.acos( THREE.Math.clamp(this.getVec2Cos(dir1,dir2), -1,1) )
  39. },
  40. getVec2Cos : function(dir1,dir2){
  41. return dir1.dot(dir2) / dir1.length() / dir2.length()
  42. },
  43. getAngle:function(vec1, vec2, axis){//带方向的角度 vector3
  44. var angle = vec1.angleTo(vec2)
  45. var axis_ = vec1.clone().cross(vec2);
  46. if(axis_[axis] < 0){
  47. angle *= -1
  48. }
  49. return angle
  50. },
  51. closeTo : function(a,b, precision=1e-6){
  52. let f = (a,b)=>{
  53. return Math.abs(a-b) < precision;
  54. }
  55. if(typeof (a) == 'number'){
  56. return f(a, b);
  57. }else{
  58. let judge = (name)=>{
  59. if(a[name] == void 0)return true //有值就判断,没值就不判断
  60. else return f(a[name],b[name])
  61. }
  62. return judge('x') && judge('y') && judge('z') && judge('w')
  63. }
  64. },
  65. toPrecision: function (e, t) {//xzw change 保留小数
  66. var f = function (e, t) {
  67. var i = Math.pow(10, t);
  68. return Math.round(e * i) / i
  69. }
  70. if (e instanceof Array) {
  71. for (var s = 0; s < e.length; s++) {
  72. e[s] = f(e[s], t);
  73. }
  74. return e;
  75. } else if (e instanceof Object) {
  76. for (var s in e) {
  77. e[s] = f(e[s], t);
  78. }
  79. return e;
  80. } else return f(e, t)
  81. },
  82. isEmptyQuaternion: function(e) {
  83. return 0 === Math.abs(e.x) && 0 === Math.abs(e.y) && 0 === Math.abs(e.z) && 0 === Math.abs(e.w)
  84. },
  85. projectPositionToCanvas: function(e, t, i) {
  86. i = i || new THREE.Vector3,
  87. i.copy(e);
  88. var r = .5 * $('#player').width()
  89. , o = .5 * $('#player').height();
  90. return i.project(t),
  91. i.x = i.x * r + r,
  92. i.y = -(i.y * o) + o,
  93. i
  94. },
  95. handelPadResize:false,
  96. /* handelPadding : function () { //去除player左边和上面的宽高,因为pc的player左上有其他element 许钟文
  97. var pads = [];//记录下来避免反复计算
  98. var index = [];
  99. var resetPad = function(){
  100. pads = [];
  101. index = [];
  102. math.handelPadResize = false; //switchview时resized为true
  103. }
  104. if(config.isEdit && !config.isMobile){
  105. window.addEventListener('resize',resetPad);
  106. }
  107. return function(x, y, domE){
  108. if(!config.isEdit || config.isMobile) {
  109. return {
  110. x: x,
  111. y: y
  112. }
  113. }
  114. if(this.handelPadResize)resetPad();
  115. domE = domE || $('#player')[0];
  116. var pad;
  117. var i = index.indexOf(domE);
  118. if (i == -1){
  119. index.push(domE);
  120. pad = {
  121. x: this.getOffset("left", domE),
  122. y: this.getOffset("top", domE)
  123. }
  124. pads.push(pad)
  125. }
  126. else pad = pads[i];
  127. return {
  128. x: x - pad.x,
  129. y: y - pad.y
  130. }
  131. }
  132. }(), */
  133. getOffset: function (type, element, parent) {//获取元素的边距 许钟文
  134. var offset = (type == "left") ? element.offsetLeft : element.offsetTop;
  135. if (!parent) parent = $("body")[0];
  136. while (element = element.offsetParent) {
  137. if (element == parent) break;
  138. offset += (type == "left") ? element.offsetLeft : element.offsetTop;
  139. }
  140. return offset;
  141. }
  142. ,
  143. constrainedTurn: function(e) {
  144. var t = e % (2 * Math.PI);
  145. return t = t > Math.PI ? t -= 2 * Math.PI : t < -Math.PI ? t += 2 * Math.PI : t
  146. },
  147. getFOVDotThreshold: function(e) {
  148. return Math.cos(THREE.Math.degToRad(e / 2))
  149. },
  150. transform2DForwardVectorByCubeFace: function(e, t, i, n) {
  151. switch (e) {
  152. case GLCubeFaces.GL_TEXTURE_CUBE_MAP_POSITIVE_X:
  153. i.set(1, t.y, t.x);
  154. break;
  155. case GLCubeFaces.GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
  156. i.set(-1, t.y, -t.x);
  157. break;
  158. case GLCubeFaces.GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
  159. i.set(-t.x, 1, -t.y);
  160. break;
  161. case GLCubeFaces.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
  162. i.set(-t.x, -1, t.y);
  163. break;
  164. case GLCubeFaces.GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
  165. i.set(-t.x, t.y, 1);
  166. break;
  167. case GLCubeFaces.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
  168. i.set(t.x, t.y, -1)
  169. }
  170. n && i.normalize()
  171. },
  172. getFootPoint : function(oldPos, p1, p2, restricInline){ //找oldPos在线段p1, p2上的垂足
  173. /* if(isWorld){//输出全局坐标 需要考虑meshGroup.position
  174. p1 = p1.clone();
  175. p2 = p2.clone();
  176. p1.y += mainDesign.meshGroup.position.y;
  177. p2.y += mainDesign.meshGroup.position.y;
  178. } */
  179. if(p1.equals(p2))return p1.clone()
  180. var op1 = oldPos.clone().sub(p1);
  181. var p1p2 = p1.clone().sub(p2)
  182. var p1p2Len = p1p2.length()
  183. var leftLen = op1.dot(p1p2) / p1p2Len;
  184. var pos = p1.clone().add(p1p2.multiplyScalar( leftLen/p1p2Len ));
  185. if(restricInline && pos.clone().sub(p1).dot( pos.clone().sub(p2) ) > 0){//foot不在线段上
  186. if(pos.distanceTo(p1) < pos.distanceTo(p2)) pos = p1.clone();
  187. else pos = p2.clone();
  188. }
  189. return pos;
  190. },
  191. /**
  192. * 计算多边形的重心
  193. * @param {*} points
  194. */
  195. getCenterOfGravityPoint : function(mPoints){
  196. var area = 0.0;//多边形面积
  197. var Gx = 0.0, Gy = 0.0;// 重心的x、y
  198. for (var i = 1; i <= mPoints.length; i++) {
  199. var ix = mPoints[i % mPoints.length].x;
  200. var iy = mPoints[i % mPoints.length].y;
  201. var nx = mPoints[i - 1].x;
  202. var ny = mPoints[i - 1].y;
  203. var temp = (ix * ny - iy * nx) / 2.0;
  204. area += temp;
  205. Gx += temp * (ix + nx) / 3.0;
  206. Gy += temp * (iy + ny) / 3.0;
  207. }
  208. Gx = Gx / area;
  209. Gy = Gy / area;
  210. return { x: Gx, y: Gy };
  211. },
  212. getBound : function(ring){
  213. var bound = new THREE.Box2();
  214. for(var j=0,len = ring.length; j<len; j++){
  215. bound.expandByPoint(ring[j])
  216. }
  217. return bound;
  218. },
  219. isPointInArea : function(ring, holes, point, ifAtLine){//判断点是否在某个环内, 若传递了holes代表还要不能在内环内
  220. var bound = this.getBound(ring);
  221. if(point.x < bound.min.x || point.x > bound.max.x || point.y < bound.min.y || point.y > bound.max.y)return false;
  222. var inside = false;
  223. var x = point.x,
  224. y = point.y;
  225. for (var i = 0, j = ring.length - 1; i < ring.length; j = i++) {
  226. var xi = ring[i].x,
  227. yi = ring[i].y;
  228. var xj = ring[j].x,
  229. yj = ring[j].y;
  230. if((xi - x)*(yj - y) == (xi - x)*(yi - y) && x>=Math.min(xi,xj) && x<=Math.max(xi,xj)//xzw add
  231. && y>=Math.min(yi,yj) && y<=Math.max(yi,yj)
  232. ){
  233. //return !!ifAtLine;//在线段上,则判断为…… (默认在外)
  234. return {atLine:true}
  235. }
  236. if (((yi > y) != (yj > y)) &&
  237. (x < (xj - xi) * (y - yi) / (yj - yi) + xi)
  238. ) {
  239. inside = !inside;
  240. }
  241. }
  242. if(inside && holes){
  243. return !holes.some(ring=>this.isPointInArea(ring, null, point, ifAtLine) ) //不能存在于任何一个二级内环内
  244. }else{
  245. return inside;
  246. }
  247. },
  248. getArea : function (ring) { //求面积 顺时针为正 来自three shape
  249. for (var t = ring.length, i = 0, n = t - 1, r = 0; r < t; n = r++)
  250. i += ring[n].x * ring[r].y - ring[r].x * ring[n].y;
  251. return -.5 * i
  252. },
  253. isInBetween : function(a, b, c, precision) {
  254. // 如果b几乎等于a或c,返回false.为了避免浮点运行时两值几乎相等,但存在相差0.00000...0001的这种情况出现使用下面方式进行避免
  255. /* if (Math.abs(a - b) < 0.000001 || Math.abs(b - c) < 0.000001) {
  256. return false;
  257. }
  258. return (a <= b && b <= c) || (c <= b && b <= a);*/
  259. //更改:如果b和a或c中一个接近 就算在a和c之间
  260. return (a <= b && b <= c) || (c <= b && b <= a) || this.closeTo(a,b,precision) || this.closeTo(b,c,precision);
  261. },
  262. ifPointAtLineBound:function(point, linePoints, precision){
  263. //待验证 横线和竖线比较特殊
  264. return math.isInBetween(linePoints[0].x, point.x, linePoints[1].x, precision) && math.isInBetween(linePoints[0].y, point.y, linePoints[1].y, precision)
  265. }
  266. ,
  267. isLineIntersect: function (line1, line2, notSegment, precision) {//线段和线段是否有交点. notSegment代表是直线而不是线段
  268. var a1 = line1[1].y - line1[0].y;
  269. var b1 = line1[0].x - line1[1].x;
  270. var c1 = a1 * line1[0].x + b1 * line1[0].y;
  271. //转换成一般式: Ax+By = C
  272. var a2 = line2[1].y - line2[0].y;
  273. var b2 = line2[0].x - line2[1].x;
  274. var c2 = a2 * line2[0].x + b2 * line2[0].y;
  275. // 计算交点
  276. var d = a1 * b2 - a2 * b1;
  277. // 当d==0时,两线平行
  278. if (d == 0) {
  279. return false;
  280. } else {
  281. var x = (b2 * c1 - b1 * c2) / d;
  282. var y = (a1 * c2 - a2 * c1) / d;
  283. // 检测交点是否在两条线段上
  284. /* if (notSegment || (isInBetween(line1[0].x, x, line1[1].x) || isInBetween(line1[0].y, y, line1[1].y)) &&
  285. (isInBetween(line2[0].x, x, line2[1].x) || isInBetween(line2[0].y, y, line2[1].y))) {
  286. return {x,y};
  287. } */
  288. if (notSegment || math.ifPointAtLineBound({x,y}, line1, precision) && math.ifPointAtLineBound({x,y}, line2, precision)){
  289. return {x,y};
  290. }
  291. }
  292. },
  293. getNormal2d : function(o={} ){//获取二维法向量 方向向内
  294. var x,y, x1,y1;
  295. //line2d的向量
  296. if(o.vec){
  297. x1 = o.vec.x; y1 = o.vec.y
  298. }else{
  299. x1 = o.p1.x - o.p2.x;
  300. y1 = o.p1.y - o.p2.y;
  301. }
  302. //假设法向量的x或y固定为1或-1
  303. if(y1 != 0){
  304. x = 1;
  305. y = - (x1 * x) / y1;
  306. }else if(x1 != 0){//y如果为0,正常情况x不会是0
  307. y = 1;
  308. x = - (y1 * y) / x1;
  309. }else{
  310. console.log("两个点一样");
  311. return null;
  312. }
  313. //判断方向里或者外:
  314. var vNormal = new THREE.Vector3(x, 0, y);
  315. var vLine = new THREE.Vector3(x1, 0, y1);
  316. var vDir = vNormal.cross(vLine);
  317. if(vDir.y>0){
  318. x *= -1;
  319. y *= -1;
  320. }
  321. return new THREE.Vector2(x, y).normalize();
  322. },
  323. getQuaBetween2Vector:function(oriVec, newVec, upVec){ //获取从oriVec旋转到newVec可以应用的quaternion
  324. var angle = oriVec.angleTo(newVec);
  325. var axis = oriVec.clone().cross( newVec).normalize();//两个up之间
  326. if(axis.length() == 0){//当夹角为180 或 0 度时,得到的axis为(0,0,0),故使用备用的指定upVec
  327. return new THREE.Quaternion().setFromAxisAngle( upVec, angle );
  328. }
  329. return new THREE.Quaternion().setFromAxisAngle( axis, angle );
  330. }
  331. /* ,
  332. getQuaBetween2Vector2 : function(oriVec, newVec ){//not camera
  333. var _ = (new THREE.Matrix4).lookAt( oriVec, new THREE.Vector3, new THREE.Vector3(0,1,0))
  334. var aimQua = (new THREE.Quaternion).setFromRotationMatrix(_)
  335. var _2 = (new THREE.Matrix4).lookAt( newVec, new THREE.Vector3, new THREE.Vector3(0,1,0))
  336. var aimQua2 = (new THREE.Quaternion).setFromRotationMatrix(_2)
  337. return aimQua2.multiply(aimQua.clone().inverse())
  338. } */
  339. ,
  340. getScaleForConstantSize : function(){ //获得规定二维大小的mesh的scale值。可以避免因camera的projection造成的mesh视觉大小改变。 来源:tag.updateDisc
  341. var w;
  342. var i = new THREE.Vector3, o = new THREE.Vector3, l = new THREE.Vector3, c = new THREE.Vector3, h = new THREE.Vector3
  343. return function(op={}){
  344. if(op.width2d) w = op.width2d //如果恒定二维宽度
  345. else{//否则考虑上距离,加一丢丢近大远小的效果
  346. var currentDis, nearBound, farBound
  347. if(op.camera.type == "OrthographicCamera"){
  348. currentDis = 200 / op.camera.zoom //(op.camera.right - op.camera.left) / op.camera.zoom
  349. }else{
  350. currentDis = op.position.distanceTo(op.camera.position);
  351. }
  352. w = op.maxSize - ( op.maxSize - op.minSize) * THREE.Math.smoothstep(currentDis, op.nearBound, op.farBound);
  353. //maxSize : mesh要表现的最大像素宽度; nearBound: 最近距离,若比nearBound近,则使用maxSize
  354. }
  355. i.copy(op.position).project(op.camera), //tag中心在屏幕上的二维坐标
  356. o.set(op.resolution.x / 2, op.resolution.y / 2, 1).multiply(i), //转化成px -w/2 到 w/2的范围
  357. l.set(w / 2, 0, 0).add(o), //加上tag宽度的一半
  358. c.set(2 / op.resolution.x, 2 / op.resolution.y, 1).multiply(l), //再转回 -1 到 1的范围
  359. h.copy(c).unproject(op.camera);//再转成三维坐标,求得tag边缘的位置
  360. var g = h.distanceTo(op.position)//就能得到tag的三维半径
  361. //这里使用的都是resolution2, 好处是手机端不会太小, 坏处是pc更改网页显示百分比时显示的大小会变(或许可以自己算出设备真实的deviceRatio, 因window.screen是不会改变的),但考虑到用户可以自行调节字大小也许是好的
  362. return g //可能NAN 当相机和position重叠时
  363. }
  364. }()
  365. ,
  366. //W , H, left, top分别是rect的宽、高、左、上
  367. getCrossPointAtRect : function(p1, aim, W , H, left, top){//求射线p1-aim在rect边界上的交点,其中aim在rect范围内,p1则不一定(交点在aim这边的延长线上)
  368. var x,y, borderX;
  369. var r = (aim.x - p1.x) / (aim.y - p1.y);//根据相似三角形原理先求出这个比值
  370. var getX = function(y){
  371. return r * (y-p1.y) + p1.x;
  372. }
  373. var getY = function(x){
  374. return 1/r * (x-p1.x) + p1.y;
  375. }
  376. if(aim.x >= p1.x){
  377. borderX = W+left;
  378. }else{
  379. borderX = left;
  380. }
  381. x = borderX;
  382. y = getY(x);
  383. if(y < top || y > top+H){
  384. if(y < top){
  385. y = top;
  386. }else{
  387. y = top+H;
  388. }
  389. x = getX(y)
  390. }
  391. return new THREE.Vector2(x, y);
  392. },
  393. getDirFromUV : function(uv){ //获取dir 反向计算 - - 二维转三维比较麻烦
  394. var dirB; //所求 单位向量
  395. var y = Math.cos(uv.y * Math.PI); //uv中纵向可以直接确定y, 根据上面getUVfromDir的反向计算
  396. // 故 uv.y * Math.PI 就是到垂直线(向上)的夹角
  397. var angle = 2 * Math.PI * uv.x - Math.PI //x/z代表的是角度
  398. var axisX, axisZ; //axis为1代表是正,-1是负数
  399. if (-Math.PI <= angle && angle < 0) {
  400. axisX = -1 //下半圆
  401. } else {
  402. axisX = 1 //上半圆
  403. }
  404. if (-Math.PI / 2 <= angle && angle < Math.PI / 2) {
  405. axisZ = 1 //右半圆
  406. } else {
  407. axisZ = -1 //左半圆
  408. }
  409. var XDivideZ = Math.tan(angle);
  410. var z = Math.sqrt((1 - y * y) / (1 + XDivideZ * XDivideZ));
  411. var x = XDivideZ * z
  412. if (z * axisZ < 0) { //异号
  413. z *= -1;
  414. x *= -1;
  415. if (x * axisX < 0) {
  416. // console.log("wrong!!!!!??????????")
  417. }
  418. }
  419. x *= -1 //计算完成后这里不能漏掉 *= -1
  420. dirB = this.convertVector.YupToZup(new THREE.Vector3(x, y, z))
  421. //理想状态下x和z和anotherDir相同
  422. return dirB
  423. },
  424. getUVfromDir : function(dir) { //获取UV 同shader里的计算
  425. var dir = this.convertVector.ZupToYup(dir)
  426. dir.x *= -1; //计算前这里不能漏掉 *= -1 见shader
  427. var tx = Math.atan2(dir.x, dir.z) / (Math.PI * 2.0) + 0.5; //atan2(y,x) 返回从 X 轴正向逆时针旋转到点 (x,y) 时经过的角度。区间是-PI 到 PI 之间的值
  428. var ty = Math.acos(dir.y) / Math.PI;
  429. return new THREE.Vector2(tx, ty)
  430. //理想状态下tx相同
  431. },
  432. getDirByLonLat : function(lon,lat){
  433. var dir = new THREE.Vector3
  434. var phi = THREE.Math.degToRad(90 - lat);
  435. var theta = THREE.Math.degToRad(lon);
  436. dir.x = Math.sin(phi) * Math.cos(theta);
  437. dir.y = Math.cos(phi);
  438. dir.z = Math.sin(phi) * Math.sin(theta);
  439. return dir
  440. } //0,0 => (1,0,0) 270=>(0,0,-1)
  441. ,
  442. projectPointAtPlane:function(o={}){//获取一个点在一个面上的投影 {facePoints:[a,b,c], point:}
  443. var plane = new THREE.Plane().setFromCoplanarPoints(...o.facePoints)
  444. return plane.projectPoint(o.point, new THREE.Vector3() )
  445. }
  446. ,
  447. getPolygonsMixedRings:function( polygons, onlyGetOutRing){//{points:[vector2,...],holes:[[],[]]}
  448. let points = []
  449. let lines = []
  450. let i = 0
  451. polygons.forEach(e=> points.push(...e.map(a=>new THREE.Vector2().copy(a) )) )
  452. polygons.forEach((ps,j)=>{
  453. let length = ps.length;
  454. let index = 0;
  455. while(index<length){
  456. lines.push({p1:index+i,p2:(index+1)%length+i});
  457. index ++;
  458. }
  459. i+=length
  460. })
  461. points.forEach((p,j)=>{p.id = j})
  462. let rings = searchRings({
  463. points,
  464. lines,
  465. onlyGetOutRing
  466. })
  467. //console.log(rings)
  468. rings = rings.filter(e=>e.closetParent == void 0)// 子环不加,被外环包含了
  469. return rings
  470. },
  471. getQuaFromPosAim( position, target ){
  472. let matrix = (new THREE.Matrix4).lookAt(position, target, new THREE.Vector3(0,0,1))
  473. return (new THREE.Quaternion).setFromRotationMatrix(matrix)
  474. },
  475. getBoundByPoints(points, minSize){
  476. var bound = new THREE.Box3
  477. points.forEach(point=>{
  478. bound.expandByPoint(point)
  479. })
  480. let center = bound.getCenter(new THREE.Vector3)
  481. if(minSize){
  482. let minBound = (new THREE.Box3()).setFromCenterAndSize(center, minSize)
  483. bound.union(minBound)
  484. }
  485. return {
  486. bounding:bound,
  487. size: bound.getSize(new THREE.Vector3),
  488. center,
  489. }
  490. },
  491. };
  492. Potree.math = math
  493. export default math