123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160 |
- <template>
- <div>
- <div id="container"></div>
- </div>
- </template>
- <script>
- import * as THREE from "three";
- import { TransformControls } from "three/examples/jsm/controls/TransformControls.js";
- import { DragControls } from "three/examples/jsm/controls/DragControls.js";
- import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
- import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader.js";
- import { MTLLoader } from "three/examples/jsm/loaders/MTLLoader.js";
- import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
- import { ConvexGeometry } from "three/examples/jsm/geometries/ConvexGeometry.js";
- import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
- import {
- showFullScreenLoading,
- tryHideFullScreenLoading,
- } from "../../../axios/filter";
- import { mapState } from "vuex";
- import CoordinateAxes from "../common/coordinateAxes";
- export default {
- name: "threeVehicleConfiguration",
- components: {},
- data() {
- return {
- publicPath: process.env.BASE_URL,
- scene: null,
- scene2: null,
- camera: null,
- camera2: null,
- renderer: null,
- light: null,
- transformControls: null,
- geometryName: null,
- controls: null,
- mesh: null,
- cube: null,
- cacheList: [],
- xAngle: 0,
- yAngle: 0,
- zAngle: 0,
- container: null,
- car: null,
- cubeTexture: null,
- raf: null,
- canDrag: true,
- dragControls: null,
- sensor: null,
- ogt: null,
-
-
- };
- },
- computed: {
- ...mapState(["scale", "scaleRate"]),
-
- rate() {
- return 40 / this.scale;
- },
- },
- props: {
- xValue: {
- type: Number,
- default: 0,
- },
- yValue: {
- type: Number,
- default: 0,
- },
- zValue: {
- type: Number,
- default: 0,
- },
- hValue: {
- type: Number,
- default: 0,
- },
- pValue: {
- type: Number,
- default: 0,
- },
- rValue: {
- type: Number,
- default: 0,
- },
- carModel: {
- type: String,
- default: "",
- },
- isAdd: {
- type: Boolean,
- default: false,
- },
- configList: {
-
-
- default: function () {
- return {};
- },
- type: Object,
- },
- allSensor: {
- default: function () {
- return {};
- },
- type: Object,
- },
- },
- watch: {
- xValue(newVal, oldVal) {
- if (newVal === oldVal) return;
- const obj = this.scene.getObjectByName("cube");
- if (obj) obj.position.x = newVal || 0;
- if (this.sensor) this.sensor.position.x = newVal || 0;
- },
- yValue(newVal, oldVal) {
- if (newVal === oldVal) return;
- const obj = this.scene.getObjectByName("cube");
- if (obj) obj.position.y = newVal || 0;
- if (this.sensor) this.sensor.position.y = newVal || 0;
- },
- zValue(newVal, oldVal) {
- if (newVal === oldVal) return;
- const obj = this.scene.getObjectByName("cube");
- if (obj) obj.position.z = newVal || 0;
- if (this.sensor) this.sensor.position.z = newVal || 0;
- },
- hValue(newVal, oldVal) {
- if (newVal === oldVal) return;
-
- let value = newVal || 0;
- value = (value * Math.PI) / 180;
- this.xAngle = value;
- const obj = this.scene.getObjectByName("cube");
- if (obj) {
- obj.rotation.set(this.xAngle, this.yAngle, this.zAngle);
- }
-
-
-
-
-
- },
- pValue(newVal, oldVal) {
- if (newVal === oldVal) return;
- let value = newVal || 0;
- value = (value * Math.PI) / 180;
- this.yAngle = value;
- const obj = this.scene.getObjectByName("cube");
- if (obj) {
- obj.rotation.set(this.xAngle, this.yAngle, this.zAngle);
- }
- },
- rValue(newVal, oldVal) {
- if (newVal === oldVal) return;
- let value = newVal || 0;
- value = (value * Math.PI) / 180;
- this.zAngle = value;
- const obj = this.scene.getObjectByName("cube");
- if (obj) {
- obj.rotation.set(this.xAngle, this.yAngle, this.zAngle);
- }
- },
- carModel(newVal, oldVal) {
- if (newVal && newVal != oldVal) {
- this.initCar(newVal);
- }
- },
- },
- methods: {
-
- initScene() {
- this.scene = new THREE.Scene();
- let axes = new THREE.AxesHelper(1500);
- this.scene.add(axes);
- const gridHelper = new THREE.GridHelper(1000, 100);
- gridHelper.material.opacity = 0.25;
- gridHelper.material.transparent = true;
- this.scene.add(gridHelper);
- return;
-
- this.scene2 = new THREE.Scene();
- let cube = new CoordinateAxes();
-
-
- this.scene2.add(cube);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- const genCubeUrls = function (prefix, postfix) {
- return [
- prefix + "px" + postfix,
- prefix + "nx" + postfix,
- prefix + "py" + postfix,
- prefix + "ny" + postfix,
- prefix + "pz" + postfix,
- prefix + "nz" + postfix,
- ];
- };
- const urls = genCubeUrls(`${this.publicPath}Park3Med/`, ".jpg");
-
- const cubeTextureLoader = new THREE.CubeTextureLoader();
- const environmentMapTexture = cubeTextureLoader.load(urls);
-
- },
-
- initCamera() {
-
- this.camera = new THREE.PerspectiveCamera(
- 75,
- this.container.clientWidth / this.container.clientHeight,
- 0.1,
- 1000
- );
-
-
- this.camera.position.set(200, 200, 200);
-
-
-
- this.camera2 = new THREE.PerspectiveCamera(75, 1, 0.1, 1000);
-
-
-
- },
-
- initRenderer() {
- this.renderer = new THREE.WebGLRenderer({
- antialias: true,
- alpha: true,
- });
- this.renderer.setSize(
- this.container.clientWidth,
- this.container.clientHeight
- );
- this.renderer.setClearColor("#272727");
- this.container.appendChild(this.renderer.domElement);
- },
-
- initLight() {
- var hemiLight = new THREE.HemisphereLight(0xffffff, 0x444444);
- hemiLight.position.set(0, 20, 0);
- this.scene.add(hemiLight);
-
- const light = new THREE.AmbientLight(0x5c5c5c, 0.4);
- this.scene.add(light);
-
-
-
-
-
- const dirLight = new THREE.DirectionalLight(0xffffff, 0.5);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- },
- initTransform() {
-
- this.transformControls = new TransformControls(
- this.camera,
- this.renderer.domElement
- );
- this.transformControls.setMode("translate");
-
- this.transformControls.setSpace("world");
- this.transformControls.addEventListener("objectChange", (e) => {
-
-
-
-
-
-
- if (!this.canDrag) return;
- this.$emit(
- "posChange",
- (e.target.object.position.x + 0.5) >> 0,
- "x"
- );
- this.$emit(
- "posChange",
- (e.target.object.position.y + 0.5) >> 0,
- "y"
- );
- this.$emit(
- "posChange",
- (e.target.object.position.z + 0.5) >> 0,
- "z"
- );
- });
- this.transformControls.addEventListener("mouseDown", (e) => {
- this.controls.enabled = false;
- this.$emit("controlsEnabled", false);
- });
- this.transformControls.addEventListener("mouseUp", (e) => {
- this.controls.enabled = true;
- this.$emit("controlsEnabled", true);
- });
- this.scene.add(this.transformControls);
- },
-
- initContent1(r, position, rotation, type, index) {
- var cubeGeometry = new THREE.ConeGeometry(
- r || 45 * this.scale,
- 150 * this.scale,
- 4,
- 1,
- false
- );
- cubeGeometry.translate(0, -75 * this.scale, 0);
- let obj = {
- color: 0x4c4c4c,
-
- transparent: true,
- opacity: 0.3,
-
-
- lightMapIntensity: 0.1,
-
-
-
-
- };
- if (type === "camera") {
- obj.emissive = 0x0000ff;
-
- } else if (type === "ogt") {
-
-
- obj.emissive = 0x008000;
- } else if (type === "lidar") {
-
-
- obj.emissive = 0xff4500;
- } else if (type === "gps") {
-
-
- obj.emissive = 0x8a2be2;
- }
-
- var cubeMaterial = new THREE.MeshLambertMaterial(obj);
- this.cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
- this.cube.name = this.geometryName || "cube";
- if (position) {
- this.cube.position.x = position.x;
- this.cube.position.y = position.y;
- this.cube.position.z = position.z;
- }
- if (rotation) {
- this.cube.rotateX(rotation.x);
- this.cube.rotateY(rotation.y);
- this.cube.rotateZ(rotation.z);
- }
- this.scene.add(this.cube);
- if (this.transformControls) {
- this.transformControls.attach(this.cube);
- }
- },
-
- initContent(position, rotation, type, index, canMove) {
- let sensorId = this.configList[type][index].sensorId;
- let coordinate = this.allSensor[type].find(
- (i) => i.id === sensorId
- );
- if (!coordinate) {
- coordinate = {
- farDistance: 60,
- nearDistance: 0,
- fovH: 60,
- fovV: 60,
- fovHLeft: 60,
- fovVTop: 60,
- fovHRight: 60,
- fovVBottom: 60,
- };
- }
-
- let r = coordinate.farDistance * 100;
- let r1 = coordinate.nearDistance * 100;
- if (r <= 0 || r1 < 0 || r <= r1) {
- return;
- }
- if (type != "ogt") {
- this.initSenA(
- position,
- rotation,
- coordinate,
- r / (this.scale / 0.6),
- r1 / (this.scale / 0.6),
- type,
- canMove
- );
- } else {
- this.initSenB(
- position,
- rotation,
- coordinate,
- r / (this.scale / 0.6),
- r1 / (this.scale / 0.6),
- type,
- canMove
- );
- }
- },
-
- initSenA(position, rotation, coordinate, r, r1, type, canMove) {
- let x = 0,
- y = 0,
- z = r;
- let a = coordinate.fovH,
- b = coordinate.fovV;
- if (a >= 90) a = 89.99;
- if (b >= 90) b = 89.99;
- x = Math.tan(THREE.MathUtils.degToRad(a)) * r;
- y = Math.tan(THREE.MathUtils.degToRad(b)) * r;
- let pointsArr = [];
- if (r1 === 0) {
- pointsArr = [
- [0, 0, 0],
- [x, y, z],
- [x, -y, z],
- [-x, -y, z],
- [-x, y, z],
- ];
- } else {
- let x1 = 0,
- y1 = 0,
- z1 = r1;
- x1 = Math.tan(THREE.MathUtils.degToRad(a)) * r1;
- y1 = Math.tan(THREE.MathUtils.degToRad(b)) * r1;
- pointsArr = [
- [x1, y1, z1],
- [x1, -y1, z1],
- [-x1, -y1, z1],
- [-x1, y1, z1],
- [x, y, z],
- [x, -y, z],
- [-x, -y, z],
- [-x, y, z],
- ];
- }
- this.initMesh(position, rotation, pointsArr, type, canMove);
- },
-
- initSenB(position, rotation, coordinateA, r, r1, type, canMove) {
- let x1 = 0,
- x2 = 0,
- y1 = 0,
- y2 = 0,
- z1 = r;
- let a = coordinateA.fovHLeft,
- b = coordinateA.fovVTop,
- c = coordinateA.fovHRight,
- d = coordinateA.fovVBottom;
- if (a >= 90) a = 89.99;
- if (b >= 90) b = 89.99;
- if (c >= 90) c = 89.99;
- if (d >= 90) d = 89.99;
- x1 = Math.tan(THREE.MathUtils.degToRad(a)) * r;
- y1 = Math.tan(THREE.MathUtils.degToRad(b)) * r;
- x2 = Math.tan(THREE.MathUtils.degToRad(c)) * r;
- y2 = Math.tan(THREE.MathUtils.degToRad(d)) * r;
- let pointsArr = [];
- if (r1 === 0) {
- pointsArr = [
- [0, 0, 0],
- [x1, y1, z1],
- [x1, -y2, z1],
- [-x2, -y2, z1],
- [-x2, y1, z1],
- ];
- } else {
- let m1 = 0,
- m2 = 0,
- n1 = 0,
- n2 = 0,
- z2 = r1;
- m1 = Math.tan(THREE.MathUtils.degToRad(a)) * r1;
- n1 = Math.tan(THREE.MathUtils.degToRad(b)) * r1;
- m2 = Math.tan(THREE.MathUtils.degToRad(c)) * r1;
- n2 = Math.tan(THREE.MathUtils.degToRad(d)) * r1;
- pointsArr = [
- [m1, n1, z2],
- [m1, -n2, z2],
- [-m2, -n2, z2],
- [-m2, n1, z2],
- [x1, y1, z1],
- [x1, -y2, z1],
- [-x2, -y2, z1],
- [-x2, y1, z1],
- ];
- }
- this.initMesh(position, rotation, pointsArr, type, canMove);
- },
-
- initMesh(position, rotation, pointsArr, type, canMove = false) {
- let points = pointsArr.map(
- (d) => new THREE.Vector3(d[0], d[1], d[2])
- );
- let color = null;
- if (type === "camera") {
- color = 0x0000ff;
- } else if (type === "ogt") {
- color = 0x008000;
- } else if (type === "lidar") {
- color = 0xff4500;
- } else {
- color = 0x0000ff;
- }
- let material = new THREE.MeshPhongMaterial({
- emissive: color,
- color: 0x4c4c4c,
- transparent: true,
- opacity: 0.3,
- lightMapIntensity: 0.1,
- side: THREE.DoubleSide,
- });
- let tixing = new ConvexGeometry(points);
-
- this.cube = new THREE.Mesh(tixing, material);
-
- if (position) {
- this.cube.position.x = position.x;
- this.cube.position.y = position.y;
- this.cube.position.z = position.z;
- }
-
-
-
-
-
- if (canMove) {
- this.cube.name = this.geometryName || "cube";
- if (rotation) {
- this.cube.rotateX(rotation.x);
- this.cube.rotateY(rotation.y);
- this.cube.rotateZ(rotation.z);
- }
- if (this.transformControls) {
- this.transformControls.attach(this.cube);
- }
- } else {
- if (rotation) {
- this.cube.rotation.set(
- (rotation.x * Math.PI) / 180,
- (rotation.y * Math.PI) / 180,
- (rotation.z * Math.PI) / 180
- );
- }
- this.cube.name = this.geometryName || "cubeA";
- this.cacheList.push(this.cube);
- }
- this.scene.add(this.cube);
- },
-
- initDragControls() {
-
- var objects = [];
- for (let i = 0; i < this.scene.children.length; i++) {
- if (this.scene.children[i].isMesh) {
- objects.push(this.scene.children[i]);
- }
- }
- if (this.dragControls) {
- this.dragControls.deactivate();
- this.dragControls.dispose();
- this.dragControls = null;
- }
-
- this.dragControls = new DragControls(
- objects,
- this.camera,
- this.renderer.domElement
- );
-
-
-
-
-
- this.dragControls.addEventListener("drag", (e) => {
-
- if (!this.canDrag) return;
-
-
-
- });
- this.dragControls.addEventListener("dragstart", (e) => {
- this.controls.enabled = false;
- });
- this.dragControls.addEventListener("dragend", (e) => {
- this.controls.enabled = true;
- });
- },
- initCar0(model) {
- if (this.car) {
-
- this.scene.remove(this.car);
- this.removeObj(this.car);
- this.car = null;
- }
-
-
-
-
-
-
- showFullScreenLoading();
- var that = this;
- var loader = new GLTFLoader();
- const dracoLoader = new DRACOLoader();
- dracoLoader.setDecoderPath(`${this.publicPath}draco/`);
- dracoLoader.setDecoderConfig({ type: "js" });
- dracoLoader.preload();
- loader.setDRACOLoader(dracoLoader);
-
-
-
- loader.load(
- model,
- function (obj) {
-
- tryHideFullScreenLoading();
-
-
- obj.scene.rotation.set(
- (-90 * Math.PI) / 180,
- 0,
- (-180 * Math.PI) / 180
- );
- let s = 0;
- if (model.includes("928.glb")) {
- s = that.scale / that.scaleRate;
- } else {
- s = that.scale;
- }
- let scale = 30 * s;
- obj.scene.scale.set(scale, scale, scale);
-
-
-
-
- that.scene.add(obj.scene);
- that.car = obj.scene;
- },
- (xhr) => {
-
-
- },
- (error) => {
-
- tryHideFullScreenLoading();
- console.error(error);
- }
- );
- },
- initCar1() {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- },
- initCar2() {
- var that = this;
- var loader2 = new THREE.ObjectLoader();
-
-
- loader2.load(`${that.publicPath}car.json`, function (obj) {
-
-
- obj.name = "car";
-
-
- obj.scale.set(30, 30, 30);
- obj.rotation.set(
- (-90 * Math.PI) / 180,
- 0,
- (-90 * Math.PI) / 180
- );
-
-
- that.scene.add(obj);
- });
- },
- initCar3() {
- var Loader = new MTLLoader();
- var loader = new OBJLoader();
- var that = this;
- Loader.load(
-
-
-
-
-
-
-
-
-
- `${that.publicPath}lb/1/obj/untitled.mtl`,
- function (materials) {
-
-
-
-
-
-
-
- loader.setMaterials(materials);
- loader.load(
-
-
-
-
- `${that.publicPath}lb/1/obj/untitled.obj`,
-
-
-
-
- function (obj) {
-
- obj.name = "car";
-
-
-
-
-
- for (let i = 0; i < obj.children.length; i++) {
-
-
- obj.children[i].position.set(0, 0, 0);
-
- obj.children[i].rotation.set(
- (-90 * Math.PI) / 180,
- 0,
- (-180 * Math.PI) / 180
- );
-
-
- }
-
-
-
-
- that.scene.add(obj);
-
-
-
-
-
-
-
-
- }
- );
- }
- );
- },
-
- initCar(model) {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (!model) return;
- if (!model.includes(".glb")) return;
- this.initCar0(model);
-
-
-
-
-
-
-
-
-
-
-
- },
-
- init() {
- this.initScene();
- this.initCamera();
- this.initRenderer();
- this.initTransform();
- this.initLight();
-
- this.controls = new OrbitControls(
- this.camera,
-
- document.getElementById("container")
- );
- this.controls.minDistance = 30;
- this.controls.maxDistance = 600;
- this.controls.update();
-
-
-
-
-
-
-
- },
- animate() {
- this.raf = requestAnimationFrame(this.animate);
-
- if (this.transformControls) {
- this.transformControls.update();
- }
- this.controls.update();
-
-
-
-
-
-
-
- this.renderer.render(this.scene, this.camera);
- return;
-
-
-
-
- this.renderer.clearDepth();
-
-
-
-
- this.renderer.setScissorTest(true);
-
-
-
- let insetWidth = this.container.clientWidth / 6;
- let insetHeight = this.container.clientHeight / 6;
- let x = insetHeight / 45;
- let y = insetHeight * 4.2;
- this.renderer.setScissor(x, y, insetWidth, insetHeight);
- this.renderer.setViewport(x, y, insetWidth, insetHeight);
- this.camera2.position.copy(this.camera.position);
- this.camera2.quaternion.copy(this.camera.quaternion);
- this.renderer.render(this.scene2, this.camera2);
-
-
- this.renderer.setScissorTest(false);
- },
- onWindowResize() {
- this.camera.aspect =
- this.container.clientWidth / this.container.clientHeight;
- this.camera.updateProjectionMatrix();
- this.renderer.setSize(
- this.container.clientWidth,
- this.container.clientHeight
- );
- let insetWidth = this.container.clientWidth / 6;
- let insetHeight = this.container.clientHeight / 6;
- this.camera2.aspect = insetWidth / insetHeight;
- this.camera2.updateProjectionMatrix();
- },
- go() {
- this.container = document.getElementById("container");
- this.init();
- this.animate();
- window.addEventListener("resize", this.onWindowResize);
- },
-
- reset(type, index = -1, onlyClear = false) {
- this.canDrag = true;
- if (this.cacheList.length > 0) {
- this.scene.remove(...this.cacheList);
- this.cacheList.forEach((i) => {
- this.clearCache(i);
- });
- this.cacheList = [];
- }
- this.sensor = null;
- const obj1 = this.scene.getObjectByName("cube");
- if (obj1) {
- this.scene.remove(obj1);
- }
- this.xAngle = 0;
- this.yAngle = 0;
- this.zAngle = 0;
- if (this.dragControls) {
- this.dragControls.deactivate();
- this.dragControls.dispose();
- this.dragControls = null;
- }
- if (this.transformControls) {
- this.transformControls.detach();
- }
-
- if (onlyClear) return;
- let z = +this.$parent.formA.sensorX || 0;
- let x = +this.$parent.formA.sensorY || 0;
- let y = +this.$parent.formA.sensorZ || 0;
- let h = +this.$parent.formA.sensorP || 0;
- let p = +this.$parent.formA.sensorR || 0;
- let r = +this.$parent.formA.sensorH || 0;
- x = Math.floor(x / this.rate);
- y = Math.floor(y / this.rate);
- z = Math.floor(z / this.rate);
- if (type != "gps") {
- this.initContent(
- { x, y, z },
- {
-
- x: 0,
- y: 0,
- z: 0,
- },
- type,
- index,
- true
- );
- }
- setTimeout(() => {
- this.initSensor({ x, y, z }, type, true);
- const obj = this.scene.getObjectByName("cube");
- if (!obj) return;
- obj.position.x = x;
- obj.position.y = y;
- obj.position.z = z;
-
-
-
- this.xAngle = (h * Math.PI) / 180;
-
-
- this.yAngle = (p * Math.PI) / 180;
-
-
- this.zAngle = (r * Math.PI) / 180;
- obj.rotation.set(this.xAngle, this.yAngle, this.zAngle);
- }, 0);
- },
-
- initSensor(
- pos = { x: 0, y: 0, z: 0 },
- type = "camera",
- canMove = false
- ) {
- let Loader = new MTLLoader();
- let loader = new OBJLoader();
- let that = this;
- let mtlUrl = "";
- let objUrl = "";
- if (type === "ogt1") {
- var loader2 = new THREE.ObjectLoader();
- loader2.load(
- `${that.publicPath}sensor/ogt/ogt.json`,
- function (obj) {
-
- that.cacheList.push(obj);
- for (let i = 0; i < obj.children.length; i++) {
- obj.children[i].scale.set(0.2, 0.2, 0.2);
- }
- obj.position.set(pos.x, pos.y, pos.z);
- obj.name = "ogt";
- if (canMove) {
- that.sensor = obj;
- }
- that.scene.add(obj);
- }
- );
- return;
- }
- if (type === "ogt1" && this.ogt) {
- setTimeout(() => {
- let obj1 = this.ogt;
-
-
-
- obj1.position.set(pos.x, pos.y, pos.z);
- if (canMove) {
- that.sensor = obj1;
- }
- obj1.name = "ogt";
-
- that.scene.add(obj1);
- }, 600);
- return;
- }
- if (type === "camera") {
- mtlUrl = `${that.publicPath}sensor/camera/camera.mtl`;
- objUrl = `${that.publicPath}sensor/camera/camera.obj`;
- } else if (type === "ogt") {
- mtlUrl = `${that.publicPath}sensor/ogt/millimeter_wave_radar.mtl`;
- objUrl = `${that.publicPath}sensor/ogt/millimeter_wave_radar.obj`;
- } else if (type === "lidar") {
- mtlUrl = `${that.publicPath}sensor/lidar/LIDAR.mtl`;
- objUrl = `${that.publicPath}sensor/lidar/LIDAR.obj`;
- } else if (type === "gps") {
- mtlUrl = `${that.publicPath}sensor/gps/lidar.mtl`;
- objUrl = `${that.publicPath}sensor/gps/lidar.obj`;
- }
- let loading = null;
- if (type === "ogt") {
-
-
-
-
-
-
- showFullScreenLoading();
- }
- Loader.load(
- mtlUrl,
- function (materials) {
-
- loader.setMaterials(materials);
- loader.load(objUrl, function (obj) {
-
-
-
-
-
-
- if (type === "ogt") {
-
- tryHideFullScreenLoading();
- }
- that.cacheList.push(obj);
- for (let i = 0; i < obj.children.length; i++) {
- if (type === "camera") {
-
- obj.children[i].scale.set(0.8, 0.8, 0.8);
- } else if (type === "ogt") {
- obj.children[i].scale.set(0.2, 0.2, 0.2);
- } else if (type === "lidar") {
- obj.children[i].scale.set(0.1, 0.1, 0.1);
- } else if (type === "gps") {
- obj.children[i].scale.set(40, 40, 40);
- }
-
-
-
-
-
- }
- obj.position.set(pos.x, pos.y, pos.z);
-
- if (canMove) {
- that.sensor = obj;
- if (type === "gps" && that.transformControls) {
- that.transformControls.attach(that.sensor);
- }
- }
- that.scene.add(obj);
- });
- },
- (xhr) => {
-
- },
- (error) => {
- if (type === "ogt") {
-
- tryHideFullScreenLoading();
- }
- console.error(error);
- }
- );
- },
-
- initContentToShow(r, position = { x: 0, y: 0, z: 0 }, rotation, type) {
- var cubeGeometry = new THREE.ConeGeometry(
- r || 45 * this.scale,
- 150 * this.scale,
- 4,
- 1,
- false
- );
- cubeGeometry.translate(0, -75 * this.scale, 0);
- let obj = {
- transparent: true,
- opacity: 0.3,
-
- lightMapIntensity: 0.1,
- color: 0x4c4c4c,
- };
- if (type === "camera") {
- obj.emissive = 0x000080;
-
- } else if (type === "ogt") {
- obj.emissive = 0x008000;
-
- } else if (type === "lidar") {
-
-
- obj.emissive = 0xff4500;
- } else if (type === "gps") {
-
-
- obj.emissive = 0x8a2be2;
- }
- var cubeMaterial = new THREE.MeshLambertMaterial(obj);
-
- var cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
- cube.name = this.geometryName || "cubeA";
- cube.rotateX((-90 * Math.PI) / 180);
- if (position) {
- cube.position.x = position.x;
- cube.position.y = position.y;
- cube.position.z = position.z;
- }
- if (rotation) {
-
-
-
-
-
-
- cube.rotation.set(
- ((rotation.x - 90) * Math.PI) / 180,
- (rotation.y * Math.PI) / 180,
- (rotation.z * Math.PI) / 180
- );
- }
- this.cacheList.push(cube);
- this.scene.add(cube);
- },
-
- showSensor(sensor, type) {
- if (sensor && Array.isArray(sensor) && sensor.length > 0) {
- sensor.forEach((item, index) => {
-
- if (
- item.sensorX == null &&
- item.sensorY == null &&
- item.sensorZ == null
- ) {
- return;
- }
- if (type != "gps") {
- this.initContent(
- {
- z: Math.floor(item.sensorX / this.rate || 0),
- x: Math.floor(item.sensorY / this.rate || 0),
- y: Math.floor(item.sensorZ / this.rate || 0),
- },
- {
- x: +item.sensorP,
- y: +item.sensorR,
- z: +item.sensorH,
- },
- type,
- index,
- false
- );
- }
-
- this.initSensor(
- {
- z: Math.floor(item.sensorX / this.rate || 0),
- x: Math.floor(item.sensorY / this.rate || 0),
- y: Math.floor(item.sensorZ / this.rate || 0),
- },
- type,
- false
- );
- });
- }
- },
-
- showAll() {
-
- if (!this.canDrag) return;
- this.canDrag = false;
- if (this.cacheList.length > 0) {
- this.scene.remove(...this.cacheList);
- this.cacheList = [];
- }
- const obj = this.scene.getObjectByName("cube");
- if (obj) {
- this.scene.remove(obj);
- }
- if (this.dragControls) {
- this.dragControls.deactivate();
- this.dragControls.dispose();
- this.dragControls = null;
- }
- if (this.transformControls) {
- this.transformControls.detach();
- }
-
- this.showSensor(this.configList.camera, "camera");
- this.showSensor(this.configList.ogt, "ogt");
- this.showSensor(this.configList.lidar, "lidar");
- this.showSensor(this.configList.gps, "gps");
- },
- removeScene() {
- this.clearScene();
- },
- clearCache(item) {
- if (item.geometry && item.geometry.dispose) item.geometry.dispose();
- if (item.material && item.material.dispose) item.material.dispose();
- },
- clearScene() {
- this.removeObj(this.scene);
- },
- removeObj(obj) {
- let arr = obj.children.filter((x) => x);
- arr.forEach((item) => {
- if (item.children.length) {
- this.removeObj(item);
- } else {
- this.clearCache(item);
- item.clear();
- }
- }),
- obj.clear();
- arr = null;
- },
- showTX() {
- var pointsArr1 = [
-
-
-
-
- [0, 0, 0],
- [10, -11, 66],
- [30, 31, 66],
- [-20, -21, 66],
- [-30, 21, 66],
- ];
- let x = 0,
- y = 0,
- z = 0;
- let r = 60;
- z = r;
- let a = 120,
- b = 40;
- x = Math.tan(THREE.MathUtils.degToRad(a / 2)) * r;
- y = Math.tan(THREE.MathUtils.degToRad(b / 2)) * r;
- let x1 = 0,
- y1 = 0,
- z1 = 0;
- let r1 = 20;
- z1 = r1;
- x1 = Math.tan(THREE.MathUtils.degToRad(a / 2)) * r1;
- y1 = Math.tan(THREE.MathUtils.degToRad(b / 2)) * r1;
- let pointsArr2 = [
- [0, 0, 0],
-
-
-
-
- [-x, y, z],
- [-x, -y, z],
- [x, y, z],
- [x, -y, z],
- ];
- let x2 = 0,
- y2 = 0,
- z2 = 0,
- x3 = 0,
- y3 = 0,
- z3 = 0,
- x4 = 0,
- y4 = 0,
- z4 = 0,
- x6 = 0,
- y6 = 0,
- z6 = 0,
- r2 = 90,
- a2 = 30,
- b2 = 60,
- c2 = 90,
- d2 = 60;
- x2 = Math.tan(THREE.MathUtils.degToRad(a2 / 2)) * r2;
- y2 = Math.tan(THREE.MathUtils.degToRad(b2 / 2)) * r2;
- x3 = Math.tan(THREE.MathUtils.degToRad(c2 / 2)) * r2;
- y3 = Math.tan(THREE.MathUtils.degToRad(d2 / 2)) * r2;
- let pointsArr3 = [
- [0, 0, 0],
- [-x2, y3, r2],
- [-x3, -y3, r2],
- [x2, y2, r2],
- [x3, -y2, r2],
- ];
-
- let points = pointsArr3.map(
- (d) => new THREE.Vector3(d[0], d[1], d[2])
- );
- let material = new THREE.MeshPhongMaterial({
- color: 0x2c85e1,
- shininess: 60,
- specular: 0x2c85e1,
-
-
- });
- let tixing = new ConvexGeometry(points);
-
- let tixingMesh = new THREE.Mesh(tixing, material);
- this.scene.add(tixingMesh);
-
-
-
-
-
-
-
-
-
-
-
- },
- a() {
- let line, thresholdLine, segments, thresholdSegments;
- let renderer, scene, scene2, camera, camera2, controls;
- let raycaster, sphereInter, sphereOnLine;
- let matLine, matThresholdLine;
-
- let insetWidth;
- let insetHeight;
- const pointer = new THREE.Vector2(Infinity, Infinity);
- init();
- animate();
- function init() {
- let container = document.getElementById("container");
- renderer = new THREE.WebGLRenderer({
- antialias: true,
- alpha: true,
- });
- renderer.setPixelRatio(window.devicePixelRatio);
- renderer.setClearColor(0x00ff00);
- renderer.setSize(container.clientWidth, container.clientHeight);
- container.appendChild(renderer.domElement);
- scene = new THREE.Scene();
- camera = new THREE.PerspectiveCamera(
- 40,
- container.clientWidth / container.clientHeight,
- 1,
- 1000
- );
- camera.position.set(-40, 0, 60);
- camera2 = new THREE.PerspectiveCamera(40, 1, 1, 1000);
- camera2.position.copy(camera.position);
- controls = new OrbitControls(camera, renderer.domElement);
- controls.minDistance = 10;
- controls.maxDistance = 500;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- const positions = [];
- const colors = [];
- const points = [];
- for (let i = -50; i < 50; i++) {
- const t = i / 3;
- points.push(
- new THREE.Vector3(
- t * Math.sin(2 * t),
- t,
- t * Math.cos(2 * t)
- )
- );
- }
- const spline = new THREE.CatmullRomCurve3(points);
- const divisions = Math.round(3 * points.length);
- const point = new THREE.Vector3();
- const color = new THREE.Color();
- for (let i = 0, l = divisions; i < l; i++) {
- const t = i / l;
- spline.getPoint(t, point);
- positions.push(point.x, point.y, point.z);
- color.setHSL(t, 1.0, 0.5);
- colors.push(color.r, color.g, color.b);
- }
- const lineGeometry = new LineGeometry();
- lineGeometry.setPositions(positions);
- lineGeometry.setColors(colors);
- const segmentsGeometry = new LineSegmentsGeometry();
- segmentsGeometry.setPositions(positions);
- segmentsGeometry.setColors(colors);
- matLine = new LineMaterial({
- color: 0xffffff,
- linewidth: 1,
- worldUnits: true,
- vertexColors: true,
-
- alphaToCoverage: true,
- });
- matThresholdLine = new LineMaterial({
- color: 0xffffff,
- linewidth: matLine.linewidth,
- worldUnits: true,
-
- transparent: true,
- opacity: 0.2,
- depthTest: false,
- visible: false,
-
- });
-
-
-
-
-
-
-
-
-
-
-
-
-
- line = new Line2(lineGeometry, matLine);
- line.computeLineDistances();
- line.scale.set(1, 1, 1);
-
- var cubeGeometry = new THREE.ConeGeometry(75, 150, 4, 1, false);
- cubeGeometry.translate(0, -75, 0);
- let obj = {
- color: 0x4c4c4c,
-
- transparent: true,
- opacity: 0.3,
-
- emissive: 0x0000ff,
- lightMapIntensity: 0.1,
- };
- var cubeMaterial = new THREE.MeshLambertMaterial(obj);
- let cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
- scene.add(cube);
-
-
-
-
- const geo = new THREE.BufferGeometry();
- geo.setAttribute(
- "position",
- new THREE.Float32BufferAttribute(positions, 3)
- );
- geo.setAttribute(
- "color",
- new THREE.Float32BufferAttribute(colors, 3)
- );
-
- document.addEventListener("pointermove", onPointerMove);
- window.addEventListener("resize", onWindowResize);
- onWindowResize();
- }
- function onWindowResize() {
- camera.aspect = container.clientWidth / container.clientHeight;
- camera.updateProjectionMatrix();
- renderer.setSize(container.clientWidth, container.clientHeight);
- insetWidth = container.clientHeight / 6;
- insetHeight = container.clientHeight / 6;
- camera2.aspect = insetWidth / insetHeight;
- camera2.updateProjectionMatrix();
- }
- function onPointerMove(event) {
- pointer.x = (event.clientX / container.clientWidth) * 2 - 1;
- pointer.y = -(event.clientY / container.clientHeight) * 2 + 1;
- }
- function animate() {
- requestAnimationFrame(animate);
-
- renderer.setClearColor(0xdddddd);
- renderer.setViewport(
- 0,
- 0,
- container.clientWidth,
- container.clientHeight
- );
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- matLine.resolution.set(
- container.clientWidth,
- container.clientHeight
- );
- matThresholdLine.resolution.set(
- container.clientWidth,
- container.clientHeight
- );
-
- renderer.render(scene, camera);
-
-
- renderer.setClearColor(0xff00ff, 1);
- renderer.clearDepth();
- renderer.setScissorTest(true);
- renderer.setScissor(20, 20, insetWidth, insetHeight);
- renderer.setViewport(20, 20, insetWidth, insetHeight);
- camera2.position.copy(camera.position);
- camera2.quaternion.copy(camera.quaternion);
-
- matLine.resolution.set(insetWidth, insetHeight);
- scene2 = new THREE.Scene();
- var cubeGeometry = new THREE.ConeGeometry(75, 150, 6, 1, false);
- cubeGeometry.translate(0, -75, 0);
- let obj = {
- color: 0x4c4c4c,
-
-
-
-
-
- lightMapIntensity: 0.1,
- };
- var cubeMaterial = new THREE.MeshLambertMaterial(obj);
- let cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
- scene2.add(cube);
- renderer.render(scene2, camera2);
- renderer.setScissorTest(false);
- }
- },
- },
- mounted() {
-
- this.go();
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- },
- destroyed() {
- window.removeEventListener("resize", this.onWindowResize);
- cancelAnimationFrame(this.raf);
- if (this.renderer) {
- this.renderer.renderLists.dispose();
- this.renderer.dispose();
- this.renderer.forceContextLoss();
- this.renderer.domElement = null;
- this.renderer.content = null;
- this.renderer = null;
- }
- if (this.dragControls) {
- this.dragControls.deactivate();
- this.dragControls.dispose();
- this.dragControls = null;
- }
- if (this.controls) {
- this.controls.dispose();
- this.controls = null;
- }
- if (this.transformControls) {
- this.transformControls.detach();
- this.transformControls.dispose();
- this.transformControls = null;
- }
- if (this.cacheList.length > 0) {
-
- this.cacheList = [];
- }
- this.clearScene();
- this.scene = null;
- this.scene2 = null;
- this.camera = null;
- this.camera2 = null;
- this.light = null;
- this.geometryName = null;
- this.mesh = null;
- this.cube = null;
- this.container = null;
- this.car = null;
- this.cubeTexture = null;
- this.raf = null;
- THREE.Cache.clear();
- },
- };
- </script>
- <style lang="less" scoped>
- #container {
- width: 100%;
- height: calc(100vh - 125px);
- }
- </style>
|