drawGeometry.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. // let scene, camera, renderer, controls;
  2. // let stats = initStats();
  3. // let key = 'points', id = 'id';
  4. // let verticalLineAry = [];
  5. // let geoKeys = ['3d_point1', '3d_point2'];
  6. // // n_panorama_line_3d = rx1
  7. // /* 初始加载 */
  8. // (function () {
  9. // console.log("three start...");
  10. // init();
  11. // animate();
  12. // console.log("three end...");
  13. // })();
  14. // /**
  15. // * 初始化函数
  16. // */
  17. // function init() {
  18. // initRenderer();
  19. // initScene();
  20. // initCamera();
  21. // initLight();
  22. // initControls();
  23. // drawGeometry(rx1);
  24. // findIntersectLine();
  25. // }
  26. // // function drawGeometry() {
  27. // // findIntersectLine();
  28. // // if (!panorama_line_3d) {
  29. // // let geometry = new THREE.geometry
  30. // // console.log('panorama_line_3d未定义, 请检查');
  31. // // return;
  32. // // }
  33. // // let material = new THREE.LineBasicMaterial({
  34. // // color: 'red'
  35. // // })
  36. // // let geometry = new THREE.Geometry();
  37. // // // 第一层的面循环
  38. // // for (let i = 0; i < panorama_line_3d.length; i++) {
  39. // // let face = panorama_line_3d[i]['faceLine'];
  40. // // let index = panorama_line_3d[i]['index'];
  41. // // let curVerticalLine = []
  42. // // // if (face.length < 4) {
  43. // // // console.log('构成面的线段数小于4, 请检查');
  44. // // // return;
  45. // // // }
  46. // // let sta = false; // 用于控制寻找相同点还是不同点
  47. // // // 第二层面中的线循环
  48. // // for (let j = 0; j < face.length; j++) {
  49. // // if (!face[j][key] || face[j][key].length < 2) {
  50. // // console.log('线段' + face[j][id] + '的点数据有误, 请检查');
  51. // // return;
  52. // // }
  53. // // // 绘制第一条线段
  54. // // if (j === 0) {
  55. // // // 第一条线段, 先寻找不同点
  56. // // let firstPoint = findPoint(face[j][key], face[j + 1][key], false);
  57. // // findverticalLine(firstPoint).forEach((item) => {
  58. // // index.indexOf(item) < 0 && curVerticalLine.indexOf(item) < 0 && curVerticalLine.push(item);
  59. // // })
  60. // // firstPoint && geometry.vertices.push(new THREE.Vector3(firstPoint[0], firstPoint[1], firstPoint[2]));
  61. // // // 再寻找相同点
  62. // // let secondPoint = findPoint(face[j][key], face[j + 1][key], true);
  63. // // findverticalLine(secondPoint).forEach((item) => {
  64. // // index.indexOf(item) < 0 && curVerticalLine.indexOf(item) < 0 && curVerticalLine.push(item);
  65. // // })
  66. // // secondPoint && geometry.vertices.push(new THREE.Vector3(secondPoint[0], secondPoint[1], secondPoint[2]));
  67. // // } else if (j === face.length - 1) { // 最后一条线段, 寻找与第一条线段相交的点
  68. // // let lastPoint = findPoint(face[j][key], face[0][key], true);
  69. // // findverticalLine(lastPoint).forEach((item) => {
  70. // // index.indexOf(item) < 0 && curVerticalLine.indexOf(item) < 0 && curVerticalLine.push(item);
  71. // // })
  72. // // lastPoint && geometry.vertices.push(new THREE.Vector3(lastPoint[0], lastPoint[1], lastPoint[2]));
  73. // // } else { // 寻找与上一条线段相交的点
  74. // // let point = findPoint(face[j][key], face[j + 1][key], true);
  75. // // findverticalLine(point).forEach((item) => {
  76. // // index.indexOf(item) < 0 && curVerticalLine.indexOf(item) < 0 && curVerticalLine.push(item);
  77. // // })
  78. // // point && geometry.vertices.push(new THREE.Vector3(point[0], point[1], point[2]));
  79. // // }
  80. // // }
  81. // // panorama_line_3d[i].verticalLine.push(curVerticalLine);
  82. // // }
  83. // // let line = new THREE.Line(geometry, material);
  84. // // scene.add(line);
  85. // // }
  86. // function drawGeometry(n_panorama_line_3d) {
  87. // // if (!panorama_line_3d) {
  88. // // console.log('panorama_line_3d未定义, 请检查');
  89. // // return;
  90. // // }
  91. // if (scene.getObjectByName("3d_line")) {
  92. // scene.remove(scene.getObjectByName("3d_line"));
  93. // }
  94. // let material = new THREE.LineBasicMaterial({
  95. // color: 'red'
  96. // })
  97. // let line_model = new THREE.Object3D();
  98. // // 第一层的面循环
  99. // for (let i = 0; i < n_panorama_line_3d.length; i++) {
  100. // let threeDLine = n_panorama_line_3d[i];
  101. // let geometry = new THREE.Geometry();
  102. // for (let j = 0; j < geoKeys.length; j++) {
  103. // geometry.vertices.push(new THREE.Vector3(threeDLine[geoKeys[j]][0], threeDLine[geoKeys[j]][1], threeDLine[geoKeys[j]][2]))
  104. // }
  105. // let line = new THREE.Line(geometry, material);
  106. // line_model.add(line);
  107. // }
  108. // line_model.name = '3d_line';
  109. // scene.add(line_model);
  110. // }
  111. // /**
  112. // *
  113. // * @param {*} point
  114. // */
  115. // // function findverticalLine(point) {
  116. // // let lineAry = [];
  117. // // for (let i = 0; i < panorama_line_3d.length; i++) {
  118. // // for (let j = 0; j < panorama_line_3d[i].length; j++) {
  119. // // for (let k = 0; k < panorama_line_3d[i][j]['points'].length; k++) {
  120. // // let o_point = panorama_line_3d[i][j]['points'][k];
  121. // // if (arrayEquals(o_point, point)) {
  122. // // lineAry.push(panorama_line_3d[i][j]['id']);
  123. // // }
  124. // // }
  125. // // }
  126. // // }
  127. // // // console.log(lineAry);
  128. // // return lineAry;
  129. // // }
  130. // /**
  131. // * 初始化渲染器
  132. // */
  133. // function initRenderer() {
  134. // renderer = new THREE.WebGLRenderer({
  135. // antialias: true
  136. // });
  137. // renderer.setSize(window.innerWidth / 2, window.innerHeight);
  138. // renderer.setClearColor("#ccc");
  139. // renderer.shadowMap.enabled = true;
  140. // let rightCav = document.getElementById('geo-cav');
  141. // rightCav.appendChild(renderer.domElement);
  142. // // canvas = renderer.domElement;
  143. // }
  144. // /**
  145. // * 初始化场景
  146. // */
  147. // function initScene() {
  148. // scene = new THREE.Scene();
  149. // // initContents();
  150. // }
  151. // /**
  152. // * 初始化相机
  153. // */
  154. // function initCamera() {
  155. // camera = new THREE.PerspectiveCamera(
  156. // 45,
  157. // 0.5 * window.innerWidth / window.innerHeight,
  158. // 1,
  159. // 100
  160. // );
  161. // // camera = new THREE.OrthographicCamera(3 / - 2, 3 / 2, 3 / 2, 3 / - 2, 1, 1000);
  162. // camera.position.set(15, -15, 8);
  163. // camera.up.x = 0;
  164. // camera.up.y = 0;
  165. // camera.up.z = 1;
  166. // camera.lookAt(new THREE.Vector3(0, 0, 0));
  167. // }
  168. // /**
  169. // * 初始化灯光
  170. // */
  171. // function initLight() {
  172. // let ambientLight = new THREE.AmbientLight(0x333333);
  173. // let directionalLight = new THREE.DirectionalLight("#FFFAFA", 1);
  174. // directionalLight.position.set(100, -200, 200);
  175. // directionalLight.castShadow = true;
  176. // scene.add(ambientLight);
  177. // scene.add(directionalLight);
  178. // }
  179. // /**
  180. // * 初始化控制器
  181. // */
  182. // function initControls() {
  183. // // TODO: 3D状态下启动控制器
  184. // controls = new THREE.OrbitControls(camera, renderer.domElement);
  185. // }
  186. // /**
  187. // * 初始化性能插件
  188. // */
  189. // function initStats() {
  190. // let stats = new Stats();
  191. // stats.setMode(0);
  192. // stats.domElement.style.position = "absolute";
  193. // stats.domElement.style.left = "0";
  194. // stats.domElement.style.top = "0";
  195. // document.body.appendChild(stats.domElement);
  196. // return stats;
  197. // }
  198. // /* 循环调用 */
  199. // function animate() {
  200. // requestAnimationFrame(animate);
  201. // renderer.render(scene, camera);
  202. // update();
  203. // }
  204. // /* 更新数据 */
  205. // function update() {
  206. // stats.update();
  207. // controls.update();
  208. // }