online.vue 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420
  1. <template>
  2. <div>
  3. <div id="container"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import * as THREE from "three";
  8. import { TransformControls } from "three/examples/jsm/controls/TransformControls.js";
  9. import { DragControls } from "three/examples/jsm/controls/DragControls.js";
  10. import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
  11. import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader.js";
  12. import { MTLLoader } from "three/examples/jsm/loaders/MTLLoader.js";
  13. // import { FBXLoader } from "three/examples/jsm/loaders/FBXLoader.js";
  14. // import { DDSLoader } from "three/examples/jsm/loaders/DDSLoader.js";
  15. import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
  16. import { ConvexGeometry } from "three/examples/jsm/geometries/ConvexGeometry.js";
  17. import {
  18. showFullScreenLoading,
  19. tryHideFullScreenLoading,
  20. } from "../../../axios/filter";
  21. import { mapState } from "vuex";
  22. export default {
  23. name: "threeVehicleConfiguration", // 车辆配置详情中的threeJS
  24. components: {},
  25. data() {
  26. return {
  27. publicPath: process.env.BASE_URL,
  28. scene: null,
  29. camera: null,
  30. renderer: null,
  31. light: null,
  32. transformControls: null,
  33. geometryName: null,
  34. controls: null,
  35. mesh: null,
  36. cube: null,
  37. cacheList: [],
  38. xAngle: 0,
  39. yAngle: 0,
  40. zAngle: 0,
  41. container: null,
  42. car: null,
  43. cubeTexture: null,
  44. raf: null,
  45. canDrag: true, // 是否可移动
  46. dragControls: null,
  47. sensor: null, // 当前操作的传感器配置
  48. ogt: null,
  49. // scale: 2, // 物体加载换算倍数
  50. // rate: 20, // 坐标换算倍数
  51. };
  52. },
  53. computed: {
  54. ...mapState(["scale"]),
  55. // 坐标换算倍数
  56. rate() {
  57. return 40 / this.scale;
  58. },
  59. },
  60. props: {
  61. xValue: {
  62. type: Number,
  63. default: 0,
  64. },
  65. yValue: {
  66. type: Number,
  67. default: 0,
  68. },
  69. zValue: {
  70. type: Number,
  71. default: 0,
  72. },
  73. hValue: {
  74. type: Number,
  75. default: 0,
  76. },
  77. pValue: {
  78. type: Number,
  79. default: 0,
  80. },
  81. rValue: {
  82. type: Number,
  83. default: 0,
  84. },
  85. carModel: {
  86. type: String,
  87. default: "",
  88. },
  89. isAdd: {
  90. type: Boolean,
  91. default: false,
  92. },
  93. configList: {
  94. default: {},
  95. type: Object,
  96. },
  97. },
  98. watch: {
  99. xValue(newVal, oldVal) {
  100. if (newVal === oldVal) return;
  101. const obj = this.scene.getObjectByName("cube");
  102. if (obj) obj.position.x = newVal || 0;
  103. if (this.sensor) this.sensor.position.x = newVal || 0;
  104. },
  105. yValue(newVal, oldVal) {
  106. if (newVal === oldVal) return;
  107. const obj = this.scene.getObjectByName("cube");
  108. if (obj) obj.position.y = newVal || 0;
  109. if (this.sensor) this.sensor.position.y = newVal || 0;
  110. },
  111. zValue(newVal, oldVal) {
  112. if (newVal === oldVal) return;
  113. const obj = this.scene.getObjectByName("cube");
  114. if (obj) obj.position.z = newVal || 0;
  115. if (this.sensor) this.sensor.position.z = newVal || 0;
  116. },
  117. hValue(newVal, oldVal) {
  118. if (newVal === oldVal) return;
  119. let value = (newVal || 0) - 90;
  120. value = (value * Math.PI) / 180;
  121. this.xAngle = value;
  122. const obj = this.scene.getObjectByName("cube");
  123. if (obj) {
  124. obj.rotation.set(this.xAngle, this.yAngle, this.zAngle);
  125. }
  126. // obj.rotateX(this.xAngle * -1);
  127. // obj.rotateX(value);
  128. // obj.rotation.x += value;
  129. // var axis = new THREE.Vector3(0, 1, 0); //向量axis
  130. // obj.rotateOnAxis(axis, value); //绕axis轴旋转π/8
  131. },
  132. pValue(newVal, oldVal) {
  133. if (newVal === oldVal) return;
  134. let value = newVal || 0;
  135. value = (value * Math.PI) / 180;
  136. this.yAngle = value;
  137. const obj = this.scene.getObjectByName("cube");
  138. if (obj) {
  139. obj.rotation.set(this.xAngle, this.yAngle, this.zAngle);
  140. }
  141. },
  142. rValue(newVal, oldVal) {
  143. if (newVal === oldVal) return;
  144. let value = newVal || 0;
  145. value = (value * Math.PI) / 180;
  146. this.zAngle = value;
  147. const obj = this.scene.getObjectByName("cube");
  148. if (obj) {
  149. obj.rotation.set(this.xAngle, this.yAngle, this.zAngle);
  150. }
  151. },
  152. carModel(newVal, oldVal) {
  153. if (newVal && newVal != oldVal) {
  154. this.initCar(newVal);
  155. }
  156. },
  157. },
  158. methods: {
  159. // 场景
  160. initScene() {
  161. this.scene = new THREE.Scene();
  162. let axes = new THREE.AxesHelper(1500);
  163. this.scene.add(axes);
  164. const gridHelper = new THREE.GridHelper(1000, 100);
  165. gridHelper.material.opacity = 0.25;
  166. gridHelper.material.transparent = true;
  167. this.scene.add(gridHelper);
  168. // const geometry = new THREE.BoxGeometry(100, 100, 100);
  169. // const material = new THREE.MeshBasicMaterial({
  170. // color: 0xffffff,
  171. // opacity: 0.3,
  172. // transparent: true,
  173. // });
  174. // geometry.translate(100, 100, 100);
  175. // const cube = new THREE.Mesh(geometry, material);
  176. // this.scene.add(cube);
  177. // let geometry = new THREE.BoxGeometry(10, 10, 10, 2, 2, 2);
  178. // let material = new THREE.MeshBasicMaterial({ color: 0xff0000 });
  179. // let object = new THREE.Mesh(geometry, material);
  180. // let edges = new THREE.VertexNormalsHelper(object, 2, 0x00ff00, 1);
  181. // this.scene.add(object);
  182. // this.scene.add(edges);
  183. const genCubeUrls = function (prefix, postfix) {
  184. return [
  185. prefix + "px" + postfix,
  186. prefix + "nx" + postfix,
  187. prefix + "py" + postfix,
  188. prefix + "ny" + postfix,
  189. prefix + "pz" + postfix,
  190. prefix + "nz" + postfix,
  191. ];
  192. };
  193. const urls = genCubeUrls(`${this.publicPath}Park3Med/`, ".jpg");
  194. // const urls = genCubeUrls(`${this.publicPath}6/`, ".png");
  195. const cubeTextureLoader = new THREE.CubeTextureLoader();
  196. const environmentMapTexture = cubeTextureLoader.load(urls);
  197. // this.scene.background = environmentMapTexture;
  198. },
  199. // 相机
  200. initCamera() {
  201. /* this.camera = new THREE.OrthographicCamera(
  202. this.container.clientWidth / -2,
  203. this.container.clientWidth / 2,
  204. this.container.clientHeight / 2,
  205. this.container.clientHeight / -2,
  206. 1,
  207. // 0.1,
  208. 1000
  209. ); */
  210. this.camera = new THREE.PerspectiveCamera(
  211. 75,
  212. this.container.clientWidth / this.container.clientHeight,
  213. 0.1,
  214. 1000
  215. );
  216. // this.camera.layers.set(1);
  217. // this.camera = new THREE.PerspectiveCamera(45, 1.5, 1, 1000);
  218. // this.camera.position.set(600, 600, 600);
  219. this.camera.position.set(200, 200, 200);
  220. // this.camera.lookAt(this.scene.position);
  221. this.scene.add(this.camera);
  222. },
  223. // 渲染器
  224. initRenderer() {
  225. this.renderer = new THREE.WebGLRenderer({
  226. antialias: true,
  227. alpha: true,
  228. });
  229. this.renderer.setSize(
  230. this.container.clientWidth,
  231. this.container.clientHeight
  232. );
  233. this.renderer.setClearColor("#272727");
  234. this.container.appendChild(this.renderer.domElement);
  235. },
  236. // 初始化灯光
  237. initLight() {
  238. var hemiLight = new THREE.HemisphereLight(0xffffff, 0x444444);
  239. hemiLight.position.set(0, 20, 0);
  240. this.scene.add(hemiLight);
  241. // 环境光会均匀的照亮场景中的所有物体
  242. const light = new THREE.AmbientLight(0x5c5c5c, 0.4); // soft white light
  243. this.scene.add(light);
  244. // 点光源
  245. // const light1 = new THREE.PointLight(0xffffff, 2, 100);
  246. // light1.position.set(0, 0, -100);
  247. // this.scene.add(light1);
  248. // 平行光是沿着特定方向发射的光
  249. const dirLight = new THREE.DirectionalLight(0xffffff, 0.5);
  250. // const dirLight = new THREE.DirectionalLight(0xffffff);
  251. // dirLight.position.set(0, 200, 100);
  252. // dirLight.castShadow = true;
  253. // dirLight.shadow.camera.top = 180;
  254. // dirLight.shadow.camera.bottom = -100;
  255. // dirLight.shadow.camera.left = -120;
  256. // dirLight.shadow.camera.right = 120;
  257. // dirLight.shadow.camera.near = 0.01;
  258. // dirLight.shadow.camera.far = 60;
  259. // dirLight.shadow.camera.top = 22;
  260. // dirLight.shadow.camera.bottom = -22;
  261. // dirLight.shadow.camera.left = -35;
  262. // dirLight.shadow.camera.right = 35;
  263. // // //设置阴影分辨率
  264. // dirLight.shadow.mapSize.width = 2048; // default
  265. // dirLight.shadow.mapSize.height = 2048; // default
  266. // //阴影限制
  267. // dirLight.shadow.radius = 1;
  268. // this.scene.add(dirLight);
  269. // const spotLight = new THREE.SpotLight(0xffffff);
  270. // spotLight.position.set(100, 1000, 100);
  271. // spotLight.castShadow = true;
  272. // spotLight.shadow.mapSize.width = 1024;
  273. // spotLight.shadow.mapSize.height = 1024;
  274. // spotLight.shadow.camera.near = 500;
  275. // spotLight.shadow.camera.far = 4000;
  276. // spotLight.shadow.camera.fov = 30;
  277. // this.scene.add(spotLight);
  278. },
  279. initTransform() {
  280. // 添加平移控件
  281. this.transformControls = new TransformControls(
  282. this.camera,
  283. this.renderer.domElement
  284. );
  285. this.transformControls.setMode("translate");
  286. // 可能的值有"world" 和 "local"
  287. this.transformControls.setSpace("world");
  288. this.transformControls.addEventListener("objectChange", (e) => {
  289. // console.log(e.target.object);
  290. // this.$emit(
  291. // "posChange",
  292. // ((e.target.object.rotation.x * 360) / Math.PI) >> 0,
  293. // "h"
  294. // );
  295. if (!this.canDrag) return;
  296. this.$emit(
  297. "posChange",
  298. (e.target.object.position.x + 0.5) >> 0,
  299. "x"
  300. );
  301. this.$emit(
  302. "posChange",
  303. (e.target.object.position.y + 0.5) >> 0,
  304. "y"
  305. );
  306. this.$emit(
  307. "posChange",
  308. (e.target.object.position.z + 0.5) >> 0,
  309. "z"
  310. );
  311. });
  312. this.transformControls.addEventListener("mouseDown", (e) => {
  313. this.controls.enabled = false;
  314. });
  315. this.transformControls.addEventListener("mouseUp", (e) => {
  316. this.controls.enabled = true;
  317. });
  318. this.scene.add(this.transformControls);
  319. },
  320. // 初始化模型
  321. initContent(r, position, rotation, type) {
  322. var cubeGeometry = new THREE.ConeGeometry(
  323. r || 45 * this.scale,
  324. 150 * this.scale,
  325. 4,
  326. 1,
  327. false
  328. );
  329. cubeGeometry.translate(0, -75 * this.scale, 0);
  330. let obj = {
  331. color: 0x4c4c4c,
  332. // wireframe: true,
  333. transparent: true,
  334. opacity: 0.3,
  335. // ambient: 0x00ff00,
  336. // emissive: 0xfaff72,
  337. lightMapIntensity: 0.1,
  338. // emissiveIntensity: 0.1,
  339. // envMap: this.cubeTexture,
  340. // side: THREE.DoubleSide,
  341. // side: 2,
  342. };
  343. if (type === "camera") {
  344. obj.emissive = 0x0000ff;
  345. // obj.emissive = 0x000080;
  346. } else if (type === "ogt") {
  347. // obj.emissive = 0x228B22;
  348. // obj.emissive = 0x006400;
  349. obj.emissive = 0x008000;
  350. } else if (type === "lidar") {
  351. // obj.emissive = 0xff0000;
  352. // obj.emissive = 0xE6A23C;
  353. obj.emissive = 0xff4500;
  354. } else if (type === "gps") {
  355. // obj.emissive = 0xfaff72;
  356. // obj.emissive = 0x9400D3;
  357. obj.emissive = 0x8a2be2;
  358. }
  359. // var cubeMaterial = new THREE.MeshBasicMaterial(obj);
  360. var cubeMaterial = new THREE.MeshLambertMaterial(obj);
  361. this.cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
  362. this.cube.name = this.geometryName || "cube";
  363. if (position) {
  364. this.cube.position.x = position.x;
  365. this.cube.position.y = position.y;
  366. this.cube.position.z = position.z;
  367. }
  368. if (rotation) {
  369. this.cube.rotateX(rotation.x);
  370. this.cube.rotateY(rotation.y);
  371. this.cube.rotateZ(rotation.z);
  372. }
  373. this.scene.add(this.cube);
  374. if (this.transformControls) {
  375. this.transformControls.attach(this.cube);
  376. }
  377. },
  378. // 添加拖拽控件
  379. initDragControls() {
  380. // 过滤不是 Mesh 的物体,例如辅助网格
  381. var objects = [];
  382. for (let i = 0; i < this.scene.children.length; i++) {
  383. if (this.scene.children[i].isMesh) {
  384. objects.push(this.scene.children[i]);
  385. }
  386. }
  387. if (this.dragControls) {
  388. this.dragControls.deactivate();
  389. this.dragControls.dispose();
  390. this.dragControls = null;
  391. }
  392. // 初始化拖拽控件
  393. this.dragControls = new DragControls(
  394. objects,
  395. this.camera,
  396. this.renderer.domElement
  397. );
  398. // 鼠标略过事件
  399. // this.dragControls.addEventListener("hoveron", (event) => {
  400. // // 让变换控件对象和选中的对象绑定
  401. // this.transformControls.attach(event.object);
  402. // });
  403. this.dragControls.addEventListener("drag", (e) => {
  404. if (!this.canDrag) return;
  405. // this.$emit("posChange", (e.object.position.x + 0.5) >> 0, "x");
  406. // this.$emit("posChange", (e.object.position.y + 0.5) >> 0, "y");
  407. // this.$emit("posChange", (e.object.position.z + 0.5) >> 0, "z");
  408. });
  409. this.dragControls.addEventListener("dragstart", (e) => {
  410. this.controls.enabled = false;
  411. });
  412. this.dragControls.addEventListener("dragend", (e) => {
  413. this.controls.enabled = true;
  414. });
  415. },
  416. initCar0(model) {
  417. if (this.car) {
  418. // console.log(this.car);
  419. this.scene.remove(this.car);
  420. this.removeObj(this.car);
  421. this.car = null;
  422. }
  423. // const loading = this.$loading({
  424. // lock: true,
  425. // text: "模型加载中,请稍等...",
  426. // // spinner: "el-icon-loading",
  427. // background: "rgba(0, 0, 0, 0.2)",
  428. // });
  429. showFullScreenLoading();
  430. var that = this;
  431. var loader = new GLTFLoader(); //创建一个FBX加载器
  432. // loader.load(
  433. // `${this.publicPath}glb/AudiA6_10.glb`,
  434. // function (obj) {
  435. loader.load(
  436. model,
  437. function (obj) {
  438. // loading.close();
  439. tryHideFullScreenLoading();
  440. // console.log(obj);
  441. /* for (let i = 0; i < obj.children.length; i++) {
  442. // obj.children[i].position.set(0, -135, 0);
  443. // obj.children[i].position.set(18, 36, 0);
  444. // obj.children[i].scale.set(30, 30, 30);
  445. // obj.children[i].scale.set(0.45, 0.45, 0.45);
  446. obj.children[i].rotation.set(
  447. (-90 * Math.PI) / 180,
  448. 0,
  449. (-180 * Math.PI) / 180
  450. );
  451. // obj.children[i].transparent.set(0.5);
  452. // that.transformControls.attach(obj.children[i]);
  453. } */
  454. obj.scene.rotation.set(
  455. (-90 * Math.PI) / 180,
  456. 0,
  457. (-180 * Math.PI) / 180
  458. );
  459. let scale = 30 * that.scale;
  460. obj.scene.scale.set(scale, scale, scale);
  461. // obj.scene.scale.set(30, 30, 30);
  462. // 查看动画数据 2个剪辑对象AnimationClip,一个有关键帧动画,一个没有
  463. // console.log(obj.animations);
  464. // that.scene.add(obj);
  465. that.scene.add(obj.scene);
  466. that.car = obj.scene;
  467. },
  468. (xhr) => {
  469. // console.log((xhr.loaded / xhr.total) * 100 + "% loaded");
  470. },
  471. (error) => {
  472. // loading.close();
  473. tryHideFullScreenLoading();
  474. console.error(error);
  475. }
  476. );
  477. },
  478. initCar1() {
  479. // const loader2 = new DDSLoader();
  480. // const map1 = loader2.load(
  481. // `${this.publicPath}q5/AudiQ5_Texture.dds`
  482. // );
  483. // const map2 = loader2.load(`${this.publicPath}q5/env3.dds`);
  484. // const map3 = loader2.load(
  485. // `${this.publicPath}q5/Tx_Blur_AudiQ5.dds`
  486. // );
  487. // const map4 = loader2.load(`${this.publicPath}q5/Tx_Driver.dds`);
  488. // const map6 = loader2.load(
  489. // `${this.publicPath}q5/Tx_ln_AudiQ5_09.dds`
  490. // );
  491. // var that = this;
  492. // var loader = new FBXLoader(); //创建一个FBX加载器
  493. // // var loader = new GLTFLoader(); //创建一个FBX加载器
  494. // // loader.load(`${this.publicPath}6/a8/audia8.fbx`, function (obj) {
  495. // // loader.load(`${this.publicPath}6/q5/audiq5.fbx`, function (obj) {
  496. // // loader.load(`${this.publicPath}6/a8/audia8.fbx`, function (obj) {
  497. // // loader.load(`${this.publicPath}a8/audia8.fbx`, function (obj) {
  498. // // loader.load(`${this.publicPath}q5/audiq5.fbx`, function (obj) {
  499. // // loader.load(`${this.publicPath}lb/audiq5.fbx`, function (obj) {
  500. // loader.load(
  501. // `${this.publicPath}lb/1/fbx/untitled.fbx`,
  502. // function (obj) {
  503. // // loader.load(`${this.publicPath}q6/audiq5.fbx`, function (obj) {
  504. // // loader.load(`${this.publicPath}untitled.fbx`, function (obj) {
  505. // // loader.load(`${this.publicPath}untitled.glb`, function (obj) {
  506. // // loader.load(`${this.publicPath}fbx/Samba Dancing.fbx`, function (obj) {
  507. // // 可以在控制台打印obj对象,找到animations属性
  508. // console.log(obj);
  509. // obj.name = "car";
  510. // // obj.map = map1;
  511. // function _ChangeMaterialEmissive(parent) {
  512. // parent.traverse(function (child) {
  513. // // if (child instanceof THREE.Mesh) {
  514. // if (child.isMesh) {
  515. // // child.material.emissive = new THREE.Color(1, 1, 1);
  516. // // child.material.emissive = child.material.color;
  517. // // child.material.emissiveIntensity = 1;
  518. // // child.material.emissiveMap = child.material.map;
  519. // // child.material.envMap = child.material.map;
  520. // // child.material.alphaMap = child.material.map;
  521. // // child.material.aoMap = child.material.map;
  522. // // child.material.bumpMap = child.material.map;
  523. // // child.material.lightMap = child.material.map;
  524. // // child.material.normalMap = child.material.map;
  525. // // child.material.specularMap = child.material.map;
  526. // // child.material.transparent = true;
  527. // child.castShadow = true;
  528. // child.receiveShadow = true;
  529. // }
  530. // });
  531. // }
  532. // _ChangeMaterialEmissive(obj);
  533. // // obj.traverse(function (child) {
  534. // // if (child.isMesh) {
  535. // // // child.material.emissive = new THREE.Color(1, 1, 1);
  536. // // child.material.emissive = child.material.color;
  537. // // child.material.emissiveIntensity = 1;
  538. // // child.material.emissiveMap = child.material.map;
  539. // // child.castShadow = true;
  540. // // child.receiveShadow = true;
  541. // // }
  542. // // });
  543. // /* for (let i = 0; i < obj.children.length; i++) {
  544. // // obj.children[i].position.set(0, -135, 0);
  545. // // obj.children[i].position.set(18, 36, 0);
  546. // // obj.children[i].scale.set(30, 30, 30);
  547. // // obj.children[i].scale.set(0.45, 0.45, 0.45);
  548. // obj.children[i].rotation.set(
  549. // (-90 * Math.PI) / 180,
  550. // 0,
  551. // (-180 * Math.PI) / 180
  552. // );
  553. // // obj.children[i].transparent.set(0.5);
  554. // // that.transformControls.attach(obj.children[i]);
  555. // } */
  556. // obj.rotation.set(
  557. // (-90 * Math.PI) / 180,
  558. // 0,
  559. // (-180 * Math.PI) / 180
  560. // );
  561. // // obj.scale.set(30, 30, 30);
  562. // // 查看动画数据 2个剪辑对象AnimationClip,一个有关键帧动画,一个没有
  563. // // console.log(obj.animations);
  564. // that.scene.add(obj);
  565. // // that.scene.add(obj.scene);
  566. // }
  567. // );
  568. },
  569. initCar2() {
  570. var that = this;
  571. var loader2 = new THREE.ObjectLoader();
  572. // var loader2 = new THREE.MeshLambertMaterial();
  573. // loader2.load(`${that.publicPath}4.js`, function (obj) {
  574. loader2.load(`${that.publicPath}car.json`, function (obj) {
  575. // loader2.load(`${that.publicPath}Lidar.json`, function (obj) {
  576. // console.log(obj);
  577. obj.name = "car";
  578. // console.log(obj.type);
  579. // obj.position.set(0, 0, 0);
  580. obj.scale.set(30, 30, 30);
  581. obj.rotation.set(
  582. (-90 * Math.PI) / 180,
  583. 0,
  584. (-90 * Math.PI) / 180
  585. );
  586. // obj.layers.set(1);
  587. // that.transformControls.attach(obj);
  588. that.scene.add(obj);
  589. });
  590. },
  591. initCar3() {
  592. var Loader = new MTLLoader(); //材质文件加载器
  593. var loader = new OBJLoader(); //obj加载器
  594. var that = this;
  595. Loader.load(
  596. // "../../../assets/common/image/female02/female02.mtl",
  597. // "../../../../public/female02/female02.mtl",
  598. // `${that.publicPath}male02/male02.mtl`,
  599. // `${that.publicPath}GTR.mtl`,
  600. // `${that.publicPath}lidar.mtl`,
  601. // `${that.publicPath}female02/female02.mtl`,
  602. // `${that.publicPath}new/audiq5.mtl`,
  603. // `${that.publicPath}lb/obj/audiq5.mtl`,
  604. // `${that.publicPath}lb/00obj/00.mtl`,
  605. `${that.publicPath}lb/1/obj/untitled.mtl`,
  606. function (materials) {
  607. // 返回一个包含材质的对象MaterialCreator
  608. // console.log(materials);
  609. // materials.transparent = true;
  610. // materials.opacity = 0.15;
  611. // materials.side = THREE.DoubleSide;
  612. // materials.depthWrite = false;
  613. //obj的模型会和MaterialCreator包含的材质对应起来
  614. loader.setMaterials(materials);
  615. loader.load(
  616. // "../../../../public/female02/female02.obj",
  617. // `${that.publicPath}female02/female02.obj`,
  618. // `${that.publicPath}new/audiq5.obj`,
  619. // `${that.publicPath}lb/00obj/00.obj`,
  620. `${that.publicPath}lb/1/obj/untitled.obj`,
  621. // `${that.publicPath}male02/male02.obj`,
  622. // `${that.publicPath}GTR.obj`,
  623. // `${that.publicPath}lidar.obj`,
  624. // `${that.publicPath}oddysey_2021.obj`,
  625. function (obj) {
  626. // console.log(obj);
  627. obj.name = "car";
  628. // console.log(obj.toJSON());
  629. // console.log(JSON.stringify(obj.toJSON()));
  630. // if (that.car) {
  631. // that.scene.remove(that.car);
  632. // }
  633. for (let i = 0; i < obj.children.length; i++) {
  634. // obj.children[i].position.set(0, -135, 0);
  635. // obj.children[i].position.set(0, -30, 0);
  636. obj.children[i].position.set(0, 0, 0);
  637. // obj.children[i].scale.set(30, 30, 30);
  638. obj.children[i].rotation.set(
  639. (-90 * Math.PI) / 180,
  640. 0,
  641. (-180 * Math.PI) / 180
  642. );
  643. // obj.children[i].transparent.set(0.5);
  644. // that.transformControls.attach(obj.children[i]);
  645. }
  646. // that.transformControls.attach(that.cube);
  647. // console.log(obj.children[0].transparent);
  648. // that.transformControls.attach(obj);
  649. // that.car = obj;
  650. that.scene.add(obj); //返回的组对象插入场景中
  651. // this.camera.lookAt(obj);
  652. // loading.close();
  653. // that.camera.lookAt(obj.position);
  654. // 加载后操作
  655. // obj.children[0].scale.set(200, 200, 200); //缩放球体网格模型
  656. // 通过调节参数,地球表面的凹凸感更强
  657. // obj.children[0].material.normalScale.set(3, 3);
  658. // obj.children[0].position.set(100, 0, 0);
  659. }
  660. );
  661. }
  662. );
  663. },
  664. // 初始化车模型
  665. initCar(model) {
  666. // const loading = this.$loading({
  667. // lock: true,
  668. // text: "模型加载中,请稍等...",
  669. // // spinner: "el-icon-loading",
  670. // background: "rgba(0, 0, 0, 0.2)",
  671. // });
  672. // const car = this.scene.getObjectByName("car");
  673. // console.log(car);
  674. // console.log(this.scene);
  675. // if (car) {
  676. // this.scene.remove(car);
  677. // }
  678. // console.log(type);
  679. // if (type === "2") {
  680. // this.initCar1();
  681. // } else if (type === "f") {
  682. // this.initCar2();
  683. // } else if (type === "7") {
  684. // this.initCar3();
  685. // } else {
  686. // this.initCar1();
  687. // }
  688. // console.log(model);
  689. if (!model) return;
  690. if (!model.includes(".glb")) return;
  691. this.initCar0(model);
  692. // console.log(this.scene);
  693. // var Loader = new MTLLoader(); //材质文件加载器
  694. // var loader = new OBJLoader(); //obj加载器
  695. // var that = this;
  696. /* var loader1 = new THREE.BufferGeometryLoader();
  697. loader1.load(`${that.publicPath}car.json`, function (geometry) {
  698. // loader1.load(`${that.publicPath}Lidar.json`, function (geometry) {
  699. // 控制台查看加载放回的threejs对象结构
  700. console.log(geometry);
  701. var material = new THREE.MeshLambertMaterial({
  702. color: 0x0000ff,
  703. }); //材质对象Material
  704. var mesh = new THREE.Mesh(geometry, material); //网格模型对象Mesh
  705. that.scene.add(mesh); //网格模型添加到场景中
  706. }); */
  707. // 没有材质文件,系统自动设置Phong网格材质
  708. // loader.load("../../../assets/common/image/oddysey_2021.obj", function (obj) {
  709. // loader.load("../../../assets/common/image/tree.obj", function (obj) {
  710. // loader.load(`${that.publicPath}oddysey_2021.obj`, function (obj) {
  711. // loader.load(`${that.publicPath}GTR.obj`, function (obj) {
  712. /* loader.load(`${that.publicPath}Lidar.obj`, function (obj) {
  713. if (that.car) {
  714. that.scene.remove(that.car);
  715. }
  716. console.log(666);
  717. // console.log(JSON.stringify(obj.toJSON()));
  718. that.car = obj;
  719. // 控制台查看返回结构:包含一个网格模型Mesh的组Group
  720. console.log(obj);
  721. // loading.close();
  722. // 查看加载器生成的材质对象:MeshPhongMaterial
  723. // console.log(obj.children[0].material);
  724. that.scene.add(obj);
  725. for (let i = 0; i < obj.children.length; i++) {
  726. obj.children[i].position.set(0, 100, 0);
  727. obj.children[i].scale.set(20, 20, 20);
  728. // obj.children[i].layers.set(1);
  729. }
  730. }); */
  731. },
  732. // 初始化
  733. init() {
  734. this.initScene();
  735. this.initCamera();
  736. this.initRenderer();
  737. this.initTransform();
  738. this.initLight();
  739. // this.initDragControls();
  740. this.controls = new OrbitControls(
  741. this.camera,
  742. this.renderer.domElement
  743. ); //创建控件对象
  744. this.controls.update();
  745. // this.controls.target = this.cube.position
  746. },
  747. animate() {
  748. this.raf = requestAnimationFrame(this.animate);
  749. this.renderer.render(this.scene, this.camera);
  750. if (this.transformControls) {
  751. this.transformControls.update();
  752. }
  753. this.controls.update();
  754. },
  755. onWindowResize() {
  756. this.camera.aspect =
  757. this.container.clientWidth / this.container.clientHeight;
  758. this.camera.updateProjectionMatrix();
  759. this.renderer.setSize(
  760. this.container.clientWidth,
  761. this.container.clientHeight
  762. );
  763. },
  764. go() {
  765. this.container = document.getElementById("container");
  766. this.init();
  767. this.animate();
  768. window.addEventListener("resize", this.onWindowResize);
  769. },
  770. // 每编辑一个传感器则重新生成对应的物体
  771. reset(type) {
  772. this.canDrag = true;
  773. if (this.cacheList.length > 0) {
  774. this.scene.remove(...this.cacheList);
  775. this.cacheList.forEach((i) => {
  776. this.clearCache(i);
  777. });
  778. this.cacheList = [];
  779. }
  780. this.sensor = null;
  781. const obj1 = this.scene.getObjectByName("cube");
  782. if (obj1) {
  783. this.scene.remove(obj1);
  784. }
  785. this.xAngle = 0;
  786. this.yAngle = 0;
  787. this.zAngle = 0;
  788. let z = +this.$parent.formA.sensorX || 0;
  789. let x = +this.$parent.formA.sensorY || 0;
  790. let y = +this.$parent.formA.sensorZ || 0;
  791. let h = +this.$parent.formA.sensorP || 0;
  792. let p = +this.$parent.formA.sensorR || 0;
  793. let r = +this.$parent.formA.sensorH || 0;
  794. x = Math.floor(x / this.rate);
  795. y = Math.floor(y / this.rate);
  796. z = Math.floor(z / this.rate);
  797. this.initContent(
  798. null,
  799. { x, y, z },
  800. {
  801. x: (-90 * Math.PI) / 180,
  802. y: 0,
  803. z: 0,
  804. },
  805. type
  806. );
  807. setTimeout(() => {
  808. this.initSensor({ x, y, z }, type, true);
  809. const obj = this.scene.getObjectByName("cube");
  810. obj.position.x = x;
  811. obj.position.y = y;
  812. obj.position.z = z;
  813. // obj.rotateX(0 * -1);
  814. // obj.rotateX((h * Math.PI) / 180);
  815. this.xAngle = ((h - 90) * Math.PI) / 180;
  816. // obj.rotateY(0 * -1);
  817. // obj.rotateY((p * Math.PI) / 180);
  818. this.yAngle = (p * Math.PI) / 180;
  819. // obj.rotateZ(0 * -1);
  820. // obj.rotateZ((r * Math.PI) / 180);
  821. this.zAngle = (r * Math.PI) / 180;
  822. obj.rotation.set(this.xAngle, this.yAngle, this.zAngle);
  823. }, 0);
  824. },
  825. // 初始化传感器
  826. initSensor(
  827. pos = { x: 0, y: 0, z: 0 },
  828. type = "camera",
  829. canMove = false
  830. ) {
  831. let Loader = new MTLLoader(); //材质文件加载器
  832. let loader = new OBJLoader(); //obj加载器
  833. let that = this;
  834. let mtlUrl = "";
  835. let objUrl = "";
  836. if (type === "ogt1") {
  837. var loader2 = new THREE.ObjectLoader();
  838. loader2.load(
  839. `${that.publicPath}sensor/ogt/ogt.json`,
  840. function (obj) {
  841. // console.log(obj);
  842. that.cacheList.push(obj);
  843. for (let i = 0; i < obj.children.length; i++) {
  844. obj.children[i].scale.set(0.2, 0.2, 0.2);
  845. }
  846. obj.position.set(pos.x, pos.y, pos.z);
  847. obj.name = "ogt";
  848. if (canMove) {
  849. that.sensor = obj;
  850. }
  851. that.scene.add(obj);
  852. }
  853. );
  854. return;
  855. }
  856. if (type === "ogt1" && this.ogt) {
  857. setTimeout(() => {
  858. let obj1 = this.ogt;
  859. // for (let i = 0; i < obj1.children.length; i++) {
  860. // obj1.children[i].scale.set(0.2, 0.2, 0.2);
  861. // }
  862. obj1.position.set(pos.x, pos.y, pos.z);
  863. if (canMove) {
  864. that.sensor = obj1;
  865. }
  866. obj1.name = "ogt";
  867. // console.log(that.scene);
  868. that.scene.add(obj1); //返回的组对象插入场景中
  869. }, 600);
  870. return;
  871. }
  872. if (type === "camera") {
  873. mtlUrl = `${that.publicPath}sensor/camera/camera.mtl`;
  874. objUrl = `${that.publicPath}sensor/camera/camera.obj`;
  875. } else if (type === "ogt") {
  876. mtlUrl = `${that.publicPath}sensor/ogt/millimeter_wave_radar.mtl`;
  877. objUrl = `${that.publicPath}sensor/ogt/millimeter_wave_radar.obj`;
  878. } else if (type === "lidar") {
  879. mtlUrl = `${that.publicPath}sensor/lidar/LIDAR.mtl`;
  880. objUrl = `${that.publicPath}sensor/lidar/LIDAR.obj`;
  881. } else if (type === "gps") {
  882. mtlUrl = `${that.publicPath}sensor/gps/lidar.mtl`;
  883. objUrl = `${that.publicPath}sensor/gps/lidar.obj`;
  884. }
  885. let loading = null;
  886. if (type === "ogt") {
  887. // loading = this.$loading({
  888. // lock: true,
  889. // text: "模型加载中,请稍等...",
  890. // // spinner: "el-icon-loading",
  891. // background: "rgba(0, 0, 0, 0.2)",
  892. // });
  893. showFullScreenLoading();
  894. }
  895. Loader.load(
  896. mtlUrl,
  897. function (materials) {
  898. // console.log(materials);
  899. loader.setMaterials(materials);
  900. loader.load(objUrl, function (obj) {
  901. // console.log(obj);
  902. // console.log(obj.clone());
  903. // console.log(JSON.stringify(obj.toJSON()));
  904. // if (type === "ogt" && !that.ogt) {
  905. // that.ogt = obj.clone();
  906. // }
  907. if (type === "ogt") {
  908. // loading.close();
  909. tryHideFullScreenLoading();
  910. }
  911. that.cacheList.push(obj);
  912. for (let i = 0; i < obj.children.length; i++) {
  913. if (type === "camera") {
  914. // let scale = 0.8 * that.scale;
  915. obj.children[i].scale.set(0.8, 0.8, 0.8);
  916. } else if (type === "ogt") {
  917. obj.children[i].scale.set(0.2, 0.2, 0.2);
  918. } else if (type === "lidar") {
  919. obj.children[i].scale.set(0.1, 0.1, 0.1);
  920. } else if (type === "gps") {
  921. obj.children[i].scale.set(40, 40, 40);
  922. }
  923. // obj.children[i].position.set(0, 0, 0);
  924. // obj.children[i].geometry.translate(pos.x, pos.y, pos.z);
  925. // obj.children[i].position.set(pos.x, pos.y, pos.z);
  926. // obj.children[i].geometry.translate(-pos.x, -pos.y, -pos.z);
  927. // obj.children[i].scale.set(30, 30, 30);
  928. }
  929. obj.position.set(pos.x, pos.y, pos.z);
  930. // obj.geometry.translate.set(pos.x, pos.y, pos.z);
  931. if (canMove) {
  932. that.sensor = obj;
  933. }
  934. that.scene.add(obj); //返回的组对象插入场景中
  935. });
  936. },
  937. (xhr) => {
  938. // console.log((xhr.loaded / xhr.total) * 100 + "% loaded");
  939. },
  940. (error) => {
  941. if (type === "ogt") {
  942. // loading.close();
  943. tryHideFullScreenLoading();
  944. }
  945. console.error(error);
  946. }
  947. );
  948. },
  949. // 初始化已保存过的传感器
  950. initContentToShow(r, position, rotation, type) {
  951. var cubeGeometry = new THREE.ConeGeometry(
  952. r || 45 * this.scale,
  953. 150 * this.scale,
  954. 4,
  955. 1,
  956. false
  957. );
  958. cubeGeometry.translate(0, -75 * this.scale, 0);
  959. let obj = {
  960. transparent: true,
  961. opacity: 0.3,
  962. // emissive: 0xfaff72,
  963. lightMapIntensity: 0.1,
  964. color: 0x4c4c4c,
  965. };
  966. if (type === "camera") {
  967. obj.emissive = 0x000080;
  968. // obj.color = 0xfaff72;
  969. } else if (type === "ogt") {
  970. obj.emissive = 0x008000;
  971. // obj.color = 0x33cc66;
  972. } else if (type === "lidar") {
  973. // obj.emissive = 0xff0000;
  974. // obj.color = 0xcc3366;
  975. obj.emissive = 0xff4500;
  976. } else if (type === "gps") {
  977. // obj.emissive = 0xfaff72;
  978. // obj.color = 0x3366cc;
  979. obj.emissive = 0x8a2be2;
  980. }
  981. var cubeMaterial = new THREE.MeshLambertMaterial(obj);
  982. // var cubeMaterial = new THREE.MeshBasicMaterial(obj);
  983. var cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
  984. cube.name = this.geometryName || "cubeA";
  985. cube.rotateX((-90 * Math.PI) / 180);
  986. if (position) {
  987. cube.position.x = position.x;
  988. cube.position.y = position.y;
  989. cube.position.z = position.z;
  990. }
  991. if (rotation) {
  992. // cube.rotateX(0 * -1);
  993. // cube.rotateX((rotation.x * Math.PI) / 180);
  994. // cube.rotateY(0 * -1);
  995. // cube.rotateY((rotation.y * Math.PI) / 180);
  996. // cube.rotateZ(0 * -1);
  997. // cube.rotateZ((rotation.z * Math.PI) / 180);
  998. cube.rotation.set(
  999. ((rotation.x - 90) * Math.PI) / 180,
  1000. (rotation.y * Math.PI) / 180,
  1001. (rotation.z * Math.PI) / 180
  1002. );
  1003. }
  1004. this.cacheList.push(cube);
  1005. this.scene.add(cube);
  1006. },
  1007. // 生成一种类型的全部显示器
  1008. showSensor(sensor, type) {
  1009. if (sensor && Array.isArray(sensor) && sensor.length > 0) {
  1010. sensor.forEach((item) => {
  1011. this.initContentToShow(
  1012. null,
  1013. {
  1014. z: Math.floor(item.sensorX / this.rate || 0),
  1015. x: Math.floor(item.sensorY / this.rate || 0),
  1016. y: Math.floor(item.sensorZ / this.rate || 0),
  1017. },
  1018. {
  1019. x: +item.sensorP,
  1020. y: +item.sensorR,
  1021. z: +item.sensorH,
  1022. },
  1023. type
  1024. );
  1025. this.initSensor(
  1026. {
  1027. z: Math.floor(item.sensorX / this.rate || 0),
  1028. x: Math.floor(item.sensorY / this.rate || 0),
  1029. y: Math.floor(item.sensorZ / this.rate || 0),
  1030. },
  1031. type,
  1032. false
  1033. );
  1034. });
  1035. }
  1036. },
  1037. // 显示全部
  1038. showAll() {
  1039. // 避免重复加载所有传感器
  1040. if (!this.canDrag) return;
  1041. this.canDrag = false;
  1042. if (this.cacheList.length > 0) {
  1043. this.scene.remove(...this.cacheList);
  1044. this.cacheList = [];
  1045. }
  1046. const obj = this.scene.getObjectByName("cube");
  1047. if (obj) {
  1048. this.scene.remove(obj);
  1049. }
  1050. if (this.dragControls) {
  1051. this.dragControls.deactivate();
  1052. this.dragControls.dispose();
  1053. this.dragControls = null;
  1054. }
  1055. if (this.transformControls) {
  1056. this.transformControls.detach();
  1057. }
  1058. // console.log(this.configList);
  1059. this.showSensor(this.configList.camera, "camera");
  1060. this.showSensor(this.configList.ogt, "ogt");
  1061. this.showSensor(this.configList.lidar, "lidar");
  1062. this.showSensor(this.configList.gps, "gps");
  1063. },
  1064. removeScene() {
  1065. this.clearScene();
  1066. },
  1067. clearCache(item) {
  1068. if (item.geometry && item.geometry.dispose) item.geometry.dispose();
  1069. if (item.material && item.material.dispose) item.material.dispose();
  1070. },
  1071. clearScene() {
  1072. this.removeObj(this.scene);
  1073. },
  1074. removeObj(obj) {
  1075. let arr = obj.children.filter((x) => x);
  1076. arr.forEach((item) => {
  1077. if (item.children.length) {
  1078. this.removeObj(item);
  1079. } else {
  1080. this.clearCache(item);
  1081. item.clear();
  1082. }
  1083. }),
  1084. obj.clear();
  1085. arr = null;
  1086. },
  1087. showTX() {
  1088. var pointsArr1 = [
  1089. // [5, -1, 33],
  1090. // [5, 11, 33],
  1091. // [-5, -1, 33],
  1092. // [-5, 11, 33],
  1093. [0, 0, 0],
  1094. [10, -11, 66],
  1095. [30, 31, 66],
  1096. [-20, -21, 66],
  1097. [-30, 21, 66],
  1098. ];
  1099. let x = 0,
  1100. y = 0,
  1101. z = 0;
  1102. let r = 60;
  1103. z = r;
  1104. let a = 120,
  1105. b = 40;
  1106. x = Math.tan(THREE.MathUtils.degToRad(a / 2)) * r;
  1107. y = Math.tan(THREE.MathUtils.degToRad(b / 2)) * r;
  1108. let x1 = 0,
  1109. y1 = 0,
  1110. z1 = 0;
  1111. let r1 = 20;
  1112. z1 = r1;
  1113. x1 = Math.tan(THREE.MathUtils.degToRad(a / 2)) * r1;
  1114. y1 = Math.tan(THREE.MathUtils.degToRad(b / 2)) * r1;
  1115. let pointsArr2 = [
  1116. [0, 0, 0],
  1117. // [-x1, y1, z1],
  1118. // [-x1, -y1, z1],
  1119. // [x1, y1, z1],
  1120. // [x1, -y1, z1],
  1121. [-x, y, z],
  1122. [-x, -y, z],
  1123. [x, y, z],
  1124. [x, -y, z],
  1125. ];
  1126. let x2 = 0,
  1127. y2 = 0,
  1128. z2 = 0,
  1129. x3 = 0,
  1130. y3 = 0,
  1131. z3 = 0,
  1132. x4 = 0,
  1133. y4 = 0,
  1134. z4 = 0,
  1135. x6 = 0,
  1136. y6 = 0,
  1137. z6 = 0,
  1138. r2 = 90,
  1139. a2 = 30,
  1140. b2 = 60,
  1141. c2 = 90,
  1142. d2 = 60;
  1143. x2 = Math.tan(THREE.MathUtils.degToRad(a2 / 2)) * r2;
  1144. y2 = Math.tan(THREE.MathUtils.degToRad(b2 / 2)) * r2;
  1145. x3 = Math.tan(THREE.MathUtils.degToRad(c2 / 2)) * r2;
  1146. y3 = Math.tan(THREE.MathUtils.degToRad(d2 / 2)) * r2;
  1147. let pointsArr3 = [
  1148. [0, 0, 0],
  1149. [-x2, y3, r2],
  1150. [-x3, -y3, r2],
  1151. [x2, y2, r2],
  1152. [x3, -y2, r2],
  1153. ];
  1154. // console.log(pointsArr3);
  1155. let points = pointsArr3.map(
  1156. (d) => new THREE.Vector3(d[0], d[1], d[2])
  1157. );
  1158. let material = new THREE.MeshPhongMaterial({
  1159. color: 0x2c85e1,
  1160. shininess: 60,
  1161. specular: 0x2c85e1,
  1162. // opacity: 0.5,
  1163. // transparent: true,
  1164. });
  1165. let tixing = new ConvexGeometry(points);
  1166. //通过ConvexGeometry凸包绘制一个梯台,当然也可以使用ExtrudeGeometry挤压几何体,
  1167. let tixingMesh = new THREE.Mesh(tixing, material);
  1168. this.scene.add(tixingMesh);
  1169. // console.log(tixingMesh);
  1170. /* let vertices = [];
  1171. vertices.push(-155, 24, 90);
  1172. vertices.push(-63, -24, 90);
  1173. vertices.push(155, 91, 90);
  1174. vertices.push(63, -90, 90);
  1175. const geometry1 = new THREE.BufferGeometry();
  1176. geometry1.setAttribute(
  1177. "position",
  1178. new THREE.Float32BufferAttribute(vertices, 3)
  1179. );
  1180. const material1 = new THREE.PointsMaterial({
  1181. color: 0xff0000,
  1182. size: 10,
  1183. fog: false,
  1184. });
  1185. const points1 = new THREE.Points(geometry1, material1);
  1186. this.scene.add(points1); */
  1187. // if (this.transformControls) {
  1188. // this.transformControls.attach(tixingMesh);
  1189. // }
  1190. // const a = new THREE.Vector3(1, 1, 0);
  1191. // const b = new THREE.Vector3(0, 0, 0);
  1192. // const d = a.distanceTo(b);
  1193. // const e = a.angleTo(b);
  1194. // console.log(d, e, (e * 180) / Math.PI, THREE.MathUtils.radToDeg(e));
  1195. // (value * Math.PI) / 180;
  1196. },
  1197. },
  1198. mounted() {
  1199. this.go();
  1200. // this.showTX();
  1201. // console.log(THREE.Loader.Handlers.add);
  1202. // THREE.Loader.Handlers.add( /\.dds$/i, new DDSLoader() );
  1203. // console.log(new THREE.LoadingManager()); RGBELoader
  1204. // let dds = new THREE.LoadingManager();
  1205. // dds.addHandler(/\.dds$/i, new DDSLoader());
  1206. // dds.addHandler(/\.rgb$/i, new RGBELoader());
  1207. // console.log(dds);
  1208. // THREE.DefaultLoadingManager.addHandler(/\.dds$/i, new DDSLoader());
  1209. // THREE.DefaultLoadingManager.addHandler(/\.rgb$/i, new RGBELoader());
  1210. // console.log(THREE.DefaultLoadingManager);
  1211. // console.log(THREE.LoadingManager.addHandler);
  1212. // THREE.Loader.Handlers.add( /\.dds$/i, new DDSLoader());
  1213. // THREE.Loader.addHandler(/\.dds$/i, new DDSLoader());
  1214. // THREE.Loader.Handlers.add( /\.dds$/i, new THREE.DDSLoader() );
  1215. // THREE.Loader.Handlers.add( /\.dds$/i, new THREE.DDSLoader() );
  1216. // if (!this.isAdd) {
  1217. // setTimeout(() => {
  1218. // this.initCar();
  1219. // }, 270);
  1220. // }
  1221. },
  1222. destroyed() {
  1223. window.removeEventListener("resize", this.onWindowResize);
  1224. cancelAnimationFrame(this.raf);
  1225. if (this.renderer) {
  1226. this.renderer.renderLists.dispose();
  1227. this.renderer.dispose();
  1228. this.renderer.forceContextLoss();
  1229. this.renderer.domElement = null;
  1230. this.renderer.content = null;
  1231. this.renderer = null;
  1232. }
  1233. if (this.dragControls) {
  1234. this.dragControls.deactivate();
  1235. this.dragControls.dispose();
  1236. this.dragControls = null;
  1237. }
  1238. if (this.controls) {
  1239. this.controls.dispose();
  1240. this.controls = null;
  1241. }
  1242. if (this.transformControls) {
  1243. this.transformControls.detach();
  1244. this.transformControls.dispose();
  1245. this.transformControls = null;
  1246. }
  1247. if (this.cacheList.length > 0) {
  1248. // this.scene.remove(...this.cacheList);
  1249. this.cacheList = [];
  1250. }
  1251. this.clearScene();
  1252. this.scene = null;
  1253. this.camera = null;
  1254. this.light = null;
  1255. this.geometryName = null;
  1256. this.mesh = null;
  1257. this.cube = null;
  1258. this.container = null;
  1259. this.car = null;
  1260. this.cubeTexture = null;
  1261. this.raf = null;
  1262. THREE.Cache.clear();
  1263. },
  1264. };
  1265. </script>
  1266. <style lang="less" scoped>
  1267. #container {
  1268. width: 100%;
  1269. height: calc(100vh - 125px);
  1270. }
  1271. </style>