ClipPlaneManager.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. var ClipPlaneManager = {
  2. clipMeshInfos: [],
  3. activeMeshInfo: undefined,
  4. anyMeshIsActive: false,
  5. adjustedClipPlanesMesh: function (params) {
  6. this.clipMeshInfos.forEach((clipMeshInfo, index) => {
  7. if (clipMeshInfo.Index != undefined) return;
  8. clipMeshInfo.Object.material.uniforms.fSharpness.value = params[0];
  9. clipMeshInfo.Object.material.uniforms.fBrightness.value = params[1];
  10. clipMeshInfo.Object.material.uniforms.fContrast.value = params[2];
  11. });
  12. },
  13. //通过三点生成切面
  14. generateClipPlaneByPoints: function (points, callback) {
  15. if (points.length < 3) return false;
  16. this.resetClipInfo();
  17. //生成切面
  18. let clipPlane = new THREE.Plane();
  19. clipPlane.setFromCoplanarPoints(points[0], points[1], points[2]);
  20. //根据cube中心点判断切面的方向
  21. let zero = new THREE.Vector3(0, 0, 0);
  22. cube.localToWorld(zero);
  23. let cubeVector = points[0].clone().sub(zero);
  24. let direction = cubeVector.dot(clipPlane.normal);
  25. if (direction > 0) {
  26. clipPlane.normal.negate();
  27. clipPlane.constant = -clipPlane.constant;
  28. //cube中心点为(width/2,height/2,depth/2)
  29. //切面在中心点左侧,留cube右半部分,故相机位置在cube中心点左侧,相机距cube中心点距离 width *(2+1/2)
  30. camera.position.set(-width * 2, height / 2, depth / 2);
  31. } else {
  32. //切面在中心点右侧,留cube左半部分,故相机位置在cube中心点右侧,相机距cube中心点距离 width *(3-1/2)
  33. camera.position.set(width * 3, height / 2, depth / 2);
  34. }
  35. orbitCtl.update();
  36. //生成切面对应的mesh
  37. let mesh = new THREE.Mesh(
  38. new THREE.PlaneGeometry(),
  39. ShaderMaterialHelper(new THREE.Texture(), [])
  40. );
  41. scene.add(mesh);
  42. //添加切面信息
  43. let clipMeshInfo = ClipMeshInfo.createNew(mesh, clipPlane);
  44. this.addClipMeshInfo(clipMeshInfo);
  45. this.activeMeshInfo = ActiveMeshInfo.createNew(
  46. clipMeshInfo,
  47. zero,
  48. MeshType.additionalMesh
  49. );
  50. refreshClipMesh(clipPlane, mesh, clipMeshInfo.ImageName, function () {
  51. if (SpriteManager.clipType == ClipType.MoveClipPlane) {
  52. addRotateInfo();
  53. }
  54. if (callback != undefined) {
  55. callback();
  56. }
  57. });
  58. return true;
  59. },
  60. //通过切割线生成切面
  61. generateClipPlane: function () {
  62. if (!LinesDrawingManager.clipLine.visible) {
  63. return;
  64. }
  65. let endPoint = LinesDrawingManager.clipLine.geometry.userData;
  66. let normal = this.activeMeshInfo.getClonedNormal();
  67. let startPoint = this.activeMeshInfo.Point;
  68. if (startPoint.distanceTo(endPoint) == 0) return;
  69. let clipLine = startPoint.clone().sub(endPoint);
  70. let normalVector = new THREE.Vector3();
  71. normalVector.crossVectors(clipLine, normal).normalize();
  72. //根据cube中心点判断切面的方向
  73. let zero = new THREE.Vector3(0, 0, 0);
  74. cube.localToWorld(zero);
  75. let cubeVector = startPoint.clone().sub(zero);
  76. if (cubeVector.dot(normalVector) > 0) {
  77. normalVector.negate();
  78. }
  79. //生成切面
  80. let clipPlane = new THREE.Plane();
  81. clipPlane.setFromNormalAndCoplanarPoint(normalVector, endPoint);
  82. //移除现有切面中无用的切面
  83. this.removeUselessClipPlane(clipPlane);
  84. //生成切面对应的mesh
  85. let mesh = new THREE.Mesh(
  86. new THREE.PlaneGeometry(),
  87. ShaderMaterialHelper(new THREE.Texture(), [])
  88. );
  89. scene.add(mesh);
  90. //添加切面信息
  91. let clipMeshInfo = ClipMeshInfo.createNew(mesh, clipPlane);
  92. this.addClipMeshInfo(clipMeshInfo);
  93. refreshClipMesh(clipPlane, mesh, clipMeshInfo.ImageName);
  94. LinesDrawingManager.hideClipLine();
  95. },
  96. //通过cube表面切面
  97. generateCubeFaceClipPlane: function () {
  98. let clipMeshInfo = undefined;
  99. //计算切面信息(normal,distance)
  100. let normal = this.activeMeshInfo.getClonedNormal().negate();
  101. // zero to face's first point.
  102. let faceVector = cube.localToWorld(
  103. this.activeMeshInfo.Mesh.object.geometry.vertices[
  104. this.activeMeshInfo.Mesh.face.a
  105. ].clone()
  106. );
  107. let distance = Math.abs(faceVector.dot(normal)) + 5;
  108. //判断切面是否已存在
  109. if (this.clipMeshInfos.length > 0) {
  110. clipMeshInfo = this.clipMeshInfos.find(
  111. (m) => m.Plane.normal.equals(normal) && m.Plane.constant == distance
  112. );
  113. }
  114. if (clipMeshInfo == undefined) {
  115. //生成切面对应的mesh
  116. let material =
  117. cube.material[this.activeMeshInfo.Mesh.face.materialIndex].clone();
  118. material.clippingPlanes = [];
  119. let mesh = new THREE.Mesh(new THREE.PlaneGeometry(), material);
  120. scene.add(mesh);
  121. //生成切面
  122. let faceClipPlane = new THREE.Plane(normal, distance);
  123. //添加切面信息
  124. clipMeshInfo = ClipMeshInfo.createNew(
  125. mesh,
  126. faceClipPlane,
  127. this.activeMeshInfo.Mesh.face.materialIndex
  128. );
  129. this.addClipMeshInfo(clipMeshInfo);
  130. }
  131. this.activeMeshInfo.Mesh = clipMeshInfo;
  132. this.activeMeshInfo.MeshType = MeshType.additionalMesh;
  133. },
  134. //移除切面数组里指定位置的元素,若index未定义则移除最后一个元素
  135. removeClipPlane: function (index) {
  136. if (index == undefined) {
  137. index = this.clipMeshInfos.length - 1;
  138. this.resetActiveMeshInfo();
  139. }
  140. if (index < 0) return;
  141. if (this.clipMeshInfos.length <= 0) return;
  142. let clipPlane = this.clipMeshInfos[index].Plane;
  143. cube.material.forEach((material) => {
  144. ClipPlaneManager.removeMaterialClipPlane(
  145. material.clippingPlanes,
  146. clipPlane
  147. );
  148. });
  149. this.clipMeshInfos.forEach((m) => {
  150. if (m.Object.material.clippingPlanes.length > 0) {
  151. ClipPlaneManager.removeMaterialClipPlane(
  152. m.Object.material.clippingPlanes,
  153. clipPlane
  154. );
  155. }
  156. });
  157. scene.remove(this.clipMeshInfos[index].Object);
  158. // jsObj.DeleteClipImageData(this.clipMeshInfos[index].ImageName);
  159. Dart_deleteClipImageData(this.clipMeshInfos[index].ImageName);
  160. this.clipMeshInfos[index].dispose();
  161. this.clipMeshInfos.splice(index, 1);
  162. },
  163. //排序:将最后激活的切面移到切面列表的最后
  164. moveElementToEnd: function (clipMeshInfo) {
  165. let index = this.clipMeshInfos.findIndex(
  166. (n) => n.Object == clipMeshInfo.Object && n.Plane == clipMeshInfo.Plane
  167. );
  168. this.clipMeshInfos.splice(index, 1);
  169. this.clipMeshInfos.push(clipMeshInfo);
  170. },
  171. //获取鼠标点击时激活的面信息
  172. getActiveMeshInfo: function (raycaster) {
  173. let intersects = raycaster.intersectObject(cube);
  174. if (intersects.length <= 0) {
  175. //not intersect cube
  176. return undefined;
  177. }
  178. if (this.clipMeshInfos.length > 0) {
  179. let distance = 0;
  180. let intersectMesh = undefined;
  181. let clipMeshInfo = undefined;
  182. this.clipMeshInfos.forEach((m) => {
  183. let meshIntersectObject = raycaster.intersectObject(m.Object);
  184. //取鼠标最远拾取的mesh
  185. if (meshIntersectObject.length > 0) {
  186. if (distance < meshIntersectObject[0].distance) {
  187. intersectMesh = meshIntersectObject[0];
  188. clipMeshInfo = m;
  189. distance = meshIntersectObject[0].distance;
  190. }
  191. }
  192. });
  193. if (distance > 0) {
  194. return ActiveMeshInfo.createNew(
  195. clipMeshInfo,
  196. intersectMesh.point,
  197. MeshType.additionalMesh
  198. );
  199. }
  200. }
  201. return ActiveMeshInfo.createNew(
  202. intersects[0],
  203. intersects[0].point,
  204. MeshType.cube
  205. );
  206. },
  207. //获取激活面的边框线
  208. getActiveMeshBorders: function () {
  209. let meshBorders = [];
  210. if (this.activeMeshInfo.Vertices.length > 1) {
  211. for (
  212. let cursor = 0;
  213. cursor < this.activeMeshInfo.Vertices.length - 1;
  214. cursor++
  215. ) {
  216. meshBorders.push(
  217. new THREE.Line3(
  218. this.activeMeshInfo.Vertices[cursor],
  219. this.activeMeshInfo.Vertices[cursor + 1]
  220. )
  221. );
  222. }
  223. }
  224. return meshBorders;
  225. },
  226. //获取使用同一转轴的相邻面(非激活面)的法向量
  227. getNeighbourPlaneNormal: function (line, clipMeshInfo) {
  228. //查找包含旋转轴line的切面法向量
  229. let projectStartPoint = new THREE.Vector3();
  230. let projectEndPoint = new THREE.Vector3();
  231. let clippingPlanes = clipMeshInfo.Object.material.clippingPlanes;
  232. if (clippingPlanes != undefined && clippingPlanes.length > 0) {
  233. for (let cursor = 0; cursor < clippingPlanes.length; cursor++) {
  234. clippingPlanes[cursor].projectPoint(line.start, projectStartPoint);
  235. clippingPlanes[cursor].projectPoint(line.end, projectEndPoint);
  236. if (
  237. line.start.distanceTo(projectStartPoint) < Accuracy &&
  238. line.end.distanceTo(projectEndPoint) < Accuracy
  239. ) {
  240. return clippingPlanes[cursor].normal;
  241. }
  242. }
  243. }
  244. //查找包含旋转轴line的cube face法向量
  245. //判断旋转轴是否在cube的左/右面上且cubeFace在旋转范围内
  246. if (
  247. this.isLineInCubeFaceByFaceNormal(line, CubeFaceNormalHelper.Left) &&
  248. this.isWithinRotateRange(
  249. CubeFaceNormalHelper.Left,
  250. clipMeshInfo.Plane.normal
  251. )
  252. ) {
  253. return CubeFaceNormalHelper.Left;
  254. }
  255. //判断旋转轴是否在cube的前/后面上且cubeFace在旋转范围内
  256. if (
  257. this.isLineInCubeFaceByFaceNormal(line, CubeFaceNormalHelper.Front) &&
  258. this.isWithinRotateRange(
  259. CubeFaceNormalHelper.Front,
  260. clipMeshInfo.Plane.normal
  261. )
  262. ) {
  263. return CubeFaceNormalHelper.Front;
  264. }
  265. //判断旋转轴是否在cube的上/下面上且cubeFace在旋转范围内
  266. if (
  267. this.isLineInCubeFaceByFaceNormal(line, CubeFaceNormalHelper.Down) &&
  268. this.isWithinRotateRange(
  269. CubeFaceNormalHelper.Down,
  270. clipMeshInfo.Plane.normal
  271. )
  272. ) {
  273. return CubeFaceNormalHelper.Down;
  274. }
  275. return undefined;
  276. },
  277. //判断线line是否在法向量为normal的cube面或其对面上
  278. isLineInCubeFaceByFaceNormal: function (line, normal) {
  279. let startValue = Math.round(Math.abs(line.start.dot(normal)));
  280. let endValue = Math.round(Math.abs(line.end.dot(normal)));
  281. //(width,height,depth)与向量点乘
  282. let faceValue = Math.abs(
  283. normal.x * width + normal.y * height + normal.z * depth
  284. );
  285. if (
  286. (startValue == 0 && endValue == 0) ||
  287. (startValue == faceValue && endValue == faceValue)
  288. ) {
  289. return true;
  290. }
  291. return false;
  292. },
  293. //判断平面向量是否在切面旋转范围内
  294. isWithinRotateRange: function (planeNormal, currentClipPlaneNormal) {
  295. let angle = Math.abs(planeNormal.angleTo(currentClipPlaneNormal));
  296. if (angle > MinRotateAngle && angle < MaxRotateAngle) {
  297. return true;
  298. }
  299. return false;
  300. },
  301. //重置切面信息
  302. resetActiveMeshInfo: function () {
  303. this.activeMeshInfo = undefined;
  304. },
  305. //检查当前鼠标选中的面是否被完全切掉
  306. isActivePlaneCompleteClipped: function () {
  307. if (this.activeMeshInfo == undefined) return true;
  308. let clipPlanes = this.activeMeshInfo.Mesh.Object.material.clippingPlanes;
  309. let existedPoints = [];
  310. if (clipPlanes != null) {
  311. let projectPoint = new THREE.Vector3();
  312. this.activeMeshInfo.Vertices.forEach((point) => {
  313. if (pointIsDuplicate(existedPoints, point)) {
  314. return;
  315. }
  316. //检查当前point是否被切割掉
  317. let isClipped = clipPlanes.some((clipPlane) => {
  318. clipPlane.projectPoint(point, projectPoint);
  319. if (point.xyzFixedEq(projectPoint, 3)) {
  320. return false;
  321. }
  322. let projectDirection = point.clone().sub(projectPoint);
  323. //点到投影点的向量与平面夹角为锐角或直角则未被切掉
  324. if (projectDirection.dot(clipPlane.normal) >= 0) {
  325. return false;
  326. }
  327. return true;
  328. });
  329. if (!isClipped) {
  330. existedPoints.push(point);
  331. }
  332. });
  333. if (existedPoints.length <= 2) {
  334. return true;
  335. }
  336. return false;
  337. }
  338. return false;
  339. },
  340. //计算当前切面可向前推动的最大距离
  341. setMaxForwardDistance: function () {
  342. let farClipPoint = this.getFarClipPoint(
  343. this.activeMeshInfo.Mesh,
  344. this.activeMeshInfo.Vertices
  345. );
  346. this.activeMeshInfo.MaxForwardDistance =
  347. -farClipPoint.dot(this.activeMeshInfo.Mesh.Plane.normal) + 10; //放在正方向前面一点
  348. },
  349. //计算当前切面可向前推到的最远点
  350. getFarClipPoint: function (clipMeshInfo, activePoints) {
  351. //求cube顶点到切面的最大距离
  352. let maxDistance = clipMeshInfo.Plane.distanceToPoint(
  353. cube.localToWorld(cube.geometry.vertices[0].clone())
  354. );
  355. cube.geometry.vertices.forEach((m) => {
  356. let distance = clipMeshInfo.Plane.distanceToPoint(
  357. cube.localToWorld(m.clone())
  358. );
  359. if (distance > maxDistance) {
  360. maxDistance = distance;
  361. }
  362. });
  363. //获取切面中心点
  364. let centerPoint = PolyPointsTool.getPolyCenter(activePoints);
  365. var meshCenterToVertices = {
  366. createNew: function (line) {
  367. var node = {};
  368. node.line = line;
  369. node.intersectWithPlane = false;
  370. return node;
  371. },
  372. };
  373. //最远距离的顶点到切面可见中心点的连线集合
  374. let lineNodes = [];
  375. cube.geometry.vertices.forEach((m) => {
  376. let vector = cube.localToWorld(m.clone());
  377. let distance = clipMeshInfo.Plane.distanceToPoint(vector);
  378. if (distance == maxDistance) {
  379. lineNodes.push(
  380. meshCenterToVertices.createNew(new THREE.Line3(centerPoint, vector))
  381. );
  382. }
  383. });
  384. //取与中心点的连线相交的切面
  385. let intersectPlanes = clipMeshInfo.Object.material.clippingPlanes.filter(
  386. (m) => {
  387. let result = false;
  388. lineNodes.forEach((lineNode) => {
  389. if (m.intersectsLine(lineNode.line)) {
  390. result = true;
  391. //被切面挡住了就标记这根线跟面相交过
  392. lineNode.intersectWithPlane = true;
  393. }
  394. });
  395. return result;
  396. }
  397. );
  398. //如果存在未与切面相交的线,则最远距离即为cube顶点到切面的最大距离
  399. let lineNode = lineNodes.find((m) => m.intersectWithPlane == false);
  400. if (lineNode != undefined) {
  401. return lineNode.line.end;
  402. }
  403. let farPoints = [];
  404. //获取所有与中心点的连线相交切面的顶点
  405. intersectPlanes.forEach((m) => {
  406. let node = this.clipMeshInfos.find((n) => n.Plane == m);
  407. let points = LineIntersectionHelper.getActiveMeshPoints(
  408. node.Object.material.clippingPlanes,
  409. node.Object.geometry.vertices,
  410. node.Plane.normal
  411. );
  412. farPoints = farPoints.concat(points);
  413. });
  414. //遍历顶点求出最远距离点
  415. let farClipPoint = undefined;
  416. maxDistance = 0;
  417. farPoints.forEach((m) => {
  418. let distance = clipMeshInfo.Plane.distanceToPoint(m);
  419. if (distance > maxDistance) {
  420. farClipPoint = m;
  421. maxDistance = distance;
  422. }
  423. });
  424. return farClipPoint;
  425. },
  426. //添加切面信息
  427. addClipMeshInfo: function (clipMeshInfo) {
  428. cube.material.forEach((material) => {
  429. material.clippingPlanes.push(clipMeshInfo.Plane);
  430. });
  431. this.clipMeshInfos.forEach((m) => {
  432. m.Object.material.clippingPlanes.push(clipMeshInfo.Plane);
  433. });
  434. this.clipMeshInfos.forEach((m) => {
  435. clipMeshInfo.Object.material.clippingPlanes.push(m.Plane);
  436. });
  437. this.clipMeshInfos.push(clipMeshInfo);
  438. },
  439. //移除纹理切面列表中的指定切面
  440. removeMaterialClipPlane: function (clipPlanes, clipPlane) {
  441. let index = clipPlanes.findIndex((n) => n == clipPlane);
  442. if (index != -1) {
  443. clipPlanes.splice(index, 1);
  444. }
  445. },
  446. //移除无用的切面
  447. removeUselessClipPlane: function (newClipPlane) {
  448. let removeNodes = [];
  449. //遍历所有切面
  450. this.clipMeshInfos.forEach((clipMeshInfo) => {
  451. //获取切面顶点信息
  452. let vertices = clipMeshInfo.Object.geometry.vertices;
  453. vertices = LineIntersectionHelper.getActiveMeshPoints(
  454. clipMeshInfo.Object.material.clippingPlanes,
  455. vertices,
  456. clipMeshInfo.Plane.normal
  457. );
  458. let projectPoint = new THREE.Vector3();
  459. let tempResult = [];
  460. //遍历所有顶点,计算顶点到新切面的投影向量与新切面法向量的点乘信息
  461. vertices.forEach((m) => {
  462. newClipPlane.projectPoint(m, projectPoint);
  463. tempResult.push(m.clone().sub(projectPoint).dot(newClipPlane.normal));
  464. });
  465. let minValue = tempResult.min();
  466. let maxValue = tempResult.max();
  467. if (minValue * maxValue > 0) {
  468. //切面所有顶点都在新切面的一侧
  469. if (maxValue < 0) {
  470. //切面顶点到新切面的向量与新切面的法向量夹角的最大值为锐角,该切面需要删除
  471. removeNodes.push(clipMeshInfo);
  472. }
  473. }
  474. });
  475. //删除切面
  476. removeNodes.forEach((m) => {
  477. let index = this.clipMeshInfos.findIndex((n) => n == m);
  478. if (index != -1) {
  479. this.removeClipPlane(index);
  480. }
  481. });
  482. },
  483. //移除所有切面
  484. removeAllClipPlane: function () {
  485. this.clipMeshInfos.forEach((m) => {
  486. scene.remove(m.Object);
  487. m.dispose();
  488. });
  489. this.clipMeshInfos.splice(0, this.clipMeshInfos.length);
  490. cube.material.forEach((material) => {
  491. material.clippingPlanes.splice(0, material.clippingPlanes.length);
  492. });
  493. // jsObj.DeleteAllClipImageData();
  494. Dart_deleteAllClipImageData("useless arg");
  495. this.resetActiveMeshInfo();
  496. },
  497. //获取当前切割面的信息以供测量使用
  498. getSelectedClipInfo: function () {
  499. let activeMeshInfo = this.activeMeshInfo;
  500. if (
  501. activeMeshInfo == undefined ||
  502. activeMeshInfo.Vertices == undefined ||
  503. activeMeshInfo.Vertices.length < 3
  504. ) {
  505. return undefined;
  506. }
  507. let points = [];
  508. activeMeshInfo.Vertices.forEach((m) => {
  509. if (!pointIsDuplicate(points, m)) {
  510. points.push(m.clone());
  511. }
  512. });
  513. convertToVTKPoints(points);
  514. let mappingPoints = [];
  515. points.forEach((item) => {
  516. mappingPoints.push(new cefMappingPoint(item.x, item.y, item.z));
  517. });
  518. let faceType;
  519. let flip = false;
  520. if (activeMeshInfo.MeshType == MeshType.cube) {
  521. faceType = CubeFaceNormalHelper.getClipFaceType(
  522. activeMeshInfo.Mesh.face.normal.clone().negate()
  523. );
  524. flip =
  525. faceType === ClipFaceType.Left ||
  526. faceType === ClipFaceType.Down ||
  527. faceType === ClipFaceType.Front;
  528. } else {
  529. faceType = CubeFaceNormalHelper.getClipFaceType(
  530. activeMeshInfo.Mesh.Normal
  531. );
  532. if (activeMeshInfo.Mesh.Index != undefined) {
  533. flip =
  534. faceType === ClipFaceType.Left ||
  535. faceType === ClipFaceType.Down ||
  536. faceType === ClipFaceType.Front;
  537. } else {
  538. flip =
  539. activeMeshInfo.Mesh.Object.geometry.faces[0].b >
  540. activeMeshInfo.Mesh.Object.geometry.faces[0].c;
  541. }
  542. }
  543. let clipCategory =
  544. faceType === ClipFaceType.Up || faceType === ClipFaceType.Down
  545. ? ClipCategory.Soleplate
  546. : ClipCategory.Flank;
  547. let clipInformation = {
  548. PointsList: mappingPoints,
  549. ClipCategory: clipCategory,
  550. Flip: flip,
  551. };
  552. return clipInformation;
  553. },
  554. drawActiveMeshEdges: function () {
  555. let activeMeshInfo = this.activeMeshInfo;
  556. if (activeMeshInfo == undefined) return;
  557. let drawVertices;
  558. let clippingPlanes = activeMeshInfo.getClipPlanes();
  559. if (activeMeshInfo.MeshType === MeshType.cube) {
  560. drawVertices = getCubeFaceVertices(activeMeshInfo, clippingPlanes);
  561. drawVertices = LineIntersectionHelper.getActiveMeshPoints(
  562. clippingPlanes,
  563. drawVertices,
  564. activeMeshInfo.Mesh.face.normal
  565. );
  566. } else {
  567. drawVertices = activeMeshInfo.getClonedVertices();
  568. ClipPlaneManager.moveElementToEnd(activeMeshInfo.Mesh);
  569. drawVertices = LineIntersectionHelper.getActiveMeshPoints(
  570. clippingPlanes,
  571. drawVertices,
  572. activeMeshInfo.Mesh.Plane.normal
  573. );
  574. }
  575. LinesDrawingManager.showMeshEdgeLines(drawVertices, clippingPlanes);
  576. activeMeshInfo.Vertices = drawVertices;
  577. //获取选中cube面的顶点信息
  578. function getCubeFaceVertices(activeMeshInfo) {
  579. let vertices = activeMeshInfo.getClonedVertices();
  580. let selectedCubeFace = activeMeshInfo.Mesh.object.geometry.faces.find(
  581. (m) => m.normal == activeMeshInfo.Mesh.face.normal
  582. );
  583. let besideCubeFace = activeMeshInfo.Mesh.object.geometry.faces.find(
  584. (m) =>
  585. m != selectedCubeFace &&
  586. m.materialIndex == selectedCubeFace.materialIndex
  587. );
  588. let tempIndexArray = [
  589. besideCubeFace.a,
  590. besideCubeFace.b,
  591. besideCubeFace.c,
  592. ];
  593. let diagonalIndex = tempIndexArray.find(
  594. (m) =>
  595. m != selectedCubeFace.a &&
  596. m != selectedCubeFace.b &&
  597. m != selectedCubeFace.c
  598. );
  599. let tempPoints = [
  600. vertices[selectedCubeFace.a].clone(),
  601. vertices[selectedCubeFace.b].clone(),
  602. vertices[selectedCubeFace.c].clone(),
  603. vertices[diagonalIndex].clone(),
  604. ];
  605. tempPoints.forEach((vector) => {
  606. cube.localToWorld(vector);
  607. });
  608. //顶点排序
  609. let drawVertices = PolyPointsTool.clockwiseSortPoints(
  610. tempPoints,
  611. activeMeshInfo.Mesh.face.normal
  612. );
  613. return drawVertices;
  614. }
  615. },
  616. resetClipInfo: function () {
  617. LinesDrawingManager.hideClipLine();
  618. this.removeAllClipPlane();
  619. removeRotateInfo();
  620. LinesDrawingManager.hideAll();
  621. },
  622. meshIsActive: function () {
  623. if (!ClipPlaneManager.anyMeshIsActive) {
  624. ClipPlaneManager.anyMeshIsActive = true;
  625. // jsObj.MeshActiveStatusChanged(true);
  626. Dart_meshActiveStatusChanged(true);
  627. return;
  628. }
  629. },
  630. meshIsInactive() {
  631. if (ClipPlaneManager.anyMeshIsActive) {
  632. ClipPlaneManager.anyMeshIsActive = false;
  633. // jsObj.MeshActiveStatusChanged(false);
  634. Dart_meshActiveStatusChanged(false);
  635. return;
  636. }
  637. },
  638. };