|
@@ -82,24 +82,8 @@ export let openDriveMixin = {
|
|
|
|
|
|
},
|
|
|
mounted() {
|
|
|
- this.initThreeJs();
|
|
|
- this.initOffscreen();
|
|
|
- this.initMaterial();
|
|
|
- this.loadMap("/map/mine3.xodr");
|
|
|
- // setTimeout(() => {
|
|
|
- // this.reloadNewMap("/map/mine3.xodr");
|
|
|
- // }, 5000)
|
|
|
-
|
|
|
- //自适应大小
|
|
|
- window.addEventListener("resize", onWindowResize, false);
|
|
|
-
|
|
|
- //监听画面变化,更新渲染画面,(自适应的大小)
|
|
|
- function onWindowResize() {
|
|
|
- this.camera.aspect = window.innerWidth / window.innerHeight;
|
|
|
- this.camera.updateProjectionMatrix();
|
|
|
- this.renderer.setSize(window.innerWidth, window.innerHeight);
|
|
|
- this.renderer.setPixelRatio(window.devicePixelRatio);
|
|
|
- }
|
|
|
+ this.init();
|
|
|
+ // this.loadMap("/map/mine4.xodr");
|
|
|
},
|
|
|
methods: {
|
|
|
drawPoint(point) {
|
|
@@ -107,7 +91,6 @@ export let openDriveMixin = {
|
|
|
if (arr.length != 0) {
|
|
|
for (let elem of arr) {
|
|
|
if (elem.point.type == point.type) {
|
|
|
- console.log("发生冲突", point)
|
|
|
let index = arr.indexOf(elem);
|
|
|
if (index !== -1) {
|
|
|
arr = [...arr.slice(0, index), ...arr.slice(index + 1)];
|
|
@@ -117,7 +100,7 @@ export let openDriveMixin = {
|
|
|
}
|
|
|
}
|
|
|
const group = new THREE.Group();
|
|
|
- let cricle = new THREE.CircleBufferGeometry(3, 200);
|
|
|
+ let cricle = new THREE.CircleBufferGeometry(5, 200);
|
|
|
let metrial = new THREE.MeshBasicMaterial({
|
|
|
color: 0xff0000
|
|
|
})
|
|
@@ -146,7 +129,7 @@ export let openDriveMixin = {
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
- clearMappingId(){
|
|
|
+ clearMappingId() {
|
|
|
this.mappingLineId = new Map();
|
|
|
},
|
|
|
loadMap(url) {
|
|
@@ -304,7 +287,6 @@ export let openDriveMixin = {
|
|
|
}
|
|
|
|
|
|
this.disposable_objs.push(road_network_geom);
|
|
|
- console.log(this.road_network_material)
|
|
|
let road_network_mesh = new THREE.Mesh(
|
|
|
road_network_geom,
|
|
|
this.road_network_material
|
|
@@ -450,17 +432,17 @@ export let openDriveMixin = {
|
|
|
this.scene.add(roadmark_outline_lines);
|
|
|
|
|
|
/* fit view and camera */
|
|
|
- console.log(refline_lines)
|
|
|
const bbox_reflines = new THREE.Box3().setFromObject(refline_lines);
|
|
|
const max_diag_dist = bbox_reflines.min.distanceTo(bbox_reflines.max);
|
|
|
this.camera.far = max_diag_dist * 1.5;
|
|
|
//controls.autoRotate = fit_view;
|
|
|
|
|
|
- if (fit_view) {
|
|
|
- this.camera.position.set(0, 0, 50);
|
|
|
- // fitViewToBbox(bbox_reflines);
|
|
|
- //fitViewToBbox(bbox_reflines);
|
|
|
- }
|
|
|
+ this.camera.position.set(0, 0, max_diag_dist/3);
|
|
|
+ // if (fit_view) {
|
|
|
+ // this.camera.position.set(0, 0, 50);
|
|
|
+ // // fitViewToBbox(bbox_reflines);
|
|
|
+ // //fitViewToBbox(bbox_reflines);
|
|
|
+ // }
|
|
|
|
|
|
/**
|
|
|
* 网格
|
|
@@ -468,11 +450,14 @@ export let openDriveMixin = {
|
|
|
let bbox_center_pt = new THREE.Vector3();
|
|
|
bbox_reflines.getCenter(bbox_center_pt);
|
|
|
let ground_grid = new THREE.GridHelper(
|
|
|
- max_diag_dist,
|
|
|
+ max_diag_dist * 6,
|
|
|
max_diag_dist / 10,
|
|
|
- 0x2f2f2f,
|
|
|
- 0x2f2f2f
|
|
|
+ 0x2f4f4f,
|
|
|
+ 0x2f4f4f
|
|
|
);
|
|
|
+ // console.log(THREE.InfiniteGridHelper)
|
|
|
+ // let ground_grid = THREE.InfiniteGridHelper(10, 10, new THREE.Color(0x2f4f4f), 500);
|
|
|
+ this.ground_grid = ground_grid;
|
|
|
ground_grid.geometry.rotateX(Math.PI / 2);
|
|
|
ground_grid.position.set(
|
|
|
bbox_center_pt.x,
|
|
@@ -482,19 +467,27 @@ export let openDriveMixin = {
|
|
|
this.disposable_objs.push(ground_grid.geometry);
|
|
|
this.scene.add(ground_grid);
|
|
|
|
|
|
- const rgbeLoader = new RGBELoader();
|
|
|
- rgbeLoader.loadAsync("hdr/index8.hdr").then((loader) => {
|
|
|
- loader.mapping = THREE.EquirectangularRefractionMapping;
|
|
|
- const sphereGeometry = new THREE.SphereBufferGeometry(max_diag_dist * 1.5);
|
|
|
- const sphereMetrial = new THREE.MeshBasicMaterial({
|
|
|
- color: 0xffffff,
|
|
|
- map: loader,
|
|
|
- });
|
|
|
- const sphereMesh = new THREE.Mesh(sphereGeometry, sphereMetrial);
|
|
|
- sphereMesh.geometry.scale(1, 1, -1);
|
|
|
- sphereMesh.rotation.x = Math.PI / 2;
|
|
|
- this.scene.add(sphereMesh);
|
|
|
- });
|
|
|
+ // const rgbeLoader = new RGBELoader();
|
|
|
+ // rgbeLoader.loadAsync("hdr/index8.hdr").then((loader) => {
|
|
|
+ // loader.needsUpdate = true;
|
|
|
+ // loader.mapping = THREE.EquirectangularRefractionMapping;
|
|
|
+ // loader.encoding = THREE.RGBEEncoding; //设置编码属性的值
|
|
|
+ // loader.mapping = THREE.EquirectangularRefractionMapping;
|
|
|
+ // loader.minFilter = THREE.NearestFilter; //当一个纹素覆盖小于一个像素时,贴图将如何采样
|
|
|
+ // loader.magFilter = THREE.NearestFilter; //当一个纹素覆盖大于一个像素时,贴图将如何采样
|
|
|
+ // loader.flipY = true; //翻转图像的Y轴以匹配WebGL纹理坐标空间
|
|
|
+ // // this.scene.background = new THREE.Color(0x2F4F4F);
|
|
|
+ // const sphereGeometry = new THREE.SphereBufferGeometry(max_diag_dist, 100, 100);
|
|
|
+ // const sphereMetrial = new THREE.MeshBasicMaterial({
|
|
|
+ // color: 0xffffff,
|
|
|
+ // map: loader,
|
|
|
+ // });
|
|
|
+ // const sphereMesh = new THREE.Mesh(sphereGeometry, sphereMetrial);
|
|
|
+ // sphereMesh.geometry.scale(1, 1, -1);
|
|
|
+ // sphereMesh.rotation.x = Math.PI / 2;
|
|
|
+ // this.scene.add(sphereMesh);
|
|
|
+ // });
|
|
|
+ // this.scene.environment = new THREE.Color(0x2F4F4F);
|
|
|
|
|
|
/**
|
|
|
* 灯光
|
|
@@ -513,10 +506,10 @@ export let openDriveMixin = {
|
|
|
this.light.target.position.needsUpdate = true;
|
|
|
this.light.target.updateMatrixWorld();
|
|
|
|
|
|
- const t1 = performance.now();
|
|
|
- console.log(
|
|
|
- "Heap size: " + this.ModuleOpenDrive.HEAP8.length / 1024 / 1024 + " mb"
|
|
|
- );
|
|
|
+ // const t1 = performance.now();
|
|
|
+ // console.log(
|
|
|
+ // "Heap size: " + this.ModuleOpenDrive.HEAP8.length / 1024 / 1024 + " mb"
|
|
|
+ // );
|
|
|
|
|
|
|
|
|
//删除数据冗余,避免造成内存泄漏
|
|
@@ -577,6 +570,8 @@ export let openDriveMixin = {
|
|
|
//平行光方向指向原点(0,0,0)
|
|
|
this.scene.add(this.light.target);
|
|
|
}
|
|
|
+
|
|
|
+ window.addEventListener("resize", this.onWindowResize, false);
|
|
|
},
|
|
|
initOffscreen() {
|
|
|
//选择车道线场景
|
|
@@ -661,8 +656,6 @@ export let openDriveMixin = {
|
|
|
});
|
|
|
|
|
|
this.road_network_material = new THREE.MeshPhongMaterial({
|
|
|
- //vertexColors: THREE.VertexColors,
|
|
|
- //版本问题,打印THREE,发现并没有VertexColors,于是查找资料中才发现把vertexColors: THREE.VertexColors设置为vertexColors: true即可
|
|
|
vertexColors: THREE.VertexColors,
|
|
|
wireframe: PARAMS.wireframe, //显示现况
|
|
|
shininess: 20.0,
|
|
@@ -670,45 +663,6 @@ export let openDriveMixin = {
|
|
|
opacity: 0.4,
|
|
|
});
|
|
|
},
|
|
|
- get_geometry(odr_meshunion) {
|
|
|
- const geom = new THREE.BufferGeometry();
|
|
|
- geom.setAttribute(
|
|
|
- "position",
|
|
|
- new THREE.Float32BufferAttribute(
|
|
|
- this.getStdVecEntries(odr_meshunion.vertices, true).flat(),
|
|
|
- 3
|
|
|
- )
|
|
|
- );
|
|
|
- //获取uv坐标
|
|
|
- geom.setAttribute(
|
|
|
- "st",
|
|
|
- new THREE.Float32BufferAttribute(
|
|
|
- this.getStdVecEntries(odr_meshunion.st_coordinates, true).flat(),
|
|
|
- 2
|
|
|
- )
|
|
|
- );
|
|
|
- //设置点颜色
|
|
|
- geom.setAttribute(
|
|
|
- "color",
|
|
|
- new THREE.Float32BufferAttribute(
|
|
|
- new Float32Array(geom.attributes.position.count * 3),
|
|
|
- 3
|
|
|
- )
|
|
|
- );
|
|
|
- //设置几何体唯一编号
|
|
|
- geom.setAttribute(
|
|
|
- "id",
|
|
|
- new THREE.Float32BufferAttribute(
|
|
|
- new Float32Array(geom.attributes.position.count * 4),
|
|
|
- 4
|
|
|
- )
|
|
|
- );
|
|
|
- // geom.setAttribute('ids', new THREE.Float32BufferAttribute(new Float32Array(geom.attributes.position.count * 4), 4));
|
|
|
- //设置几何体索引数据
|
|
|
- geom.setIndex(this.getStdVecEntries(odr_meshunion.indices, true));
|
|
|
- geom.computeVertexNormals();
|
|
|
- return geom;
|
|
|
- },
|
|
|
animate() {
|
|
|
//控制电脑帧频,防止刷屏过快导致的页面刷3D数据刷新过快 控制每秒30次
|
|
|
setTimeout(() => {
|
|
@@ -737,13 +691,12 @@ export let openDriveMixin = {
|
|
|
this.renderer.render(this.st_scene, this.camera);
|
|
|
|
|
|
const lane_id_pixel_buffer = new Float32Array(4);
|
|
|
- //拾取颜色
|
|
|
this.renderer.readRenderTargetPixels(
|
|
|
this.lane_picking_texture,
|
|
|
- 0, //相机截图左上角为坐标原点,相对于截图左上角而言的渲染起始点x坐标
|
|
|
- 0, //相机截图左上角为坐标原点,相对于截图左上角而言的渲染起始点y坐标
|
|
|
- 1, //渲染宽度范围
|
|
|
- 1, //渲染高度范围
|
|
|
+ 0,
|
|
|
+ 0,
|
|
|
+ 1,
|
|
|
+ 1,
|
|
|
this.lane_id_pixel_buffer
|
|
|
);
|
|
|
const roadmark_id_pixel_buffer = new Float32Array(4);
|
|
@@ -764,7 +717,6 @@ export let openDriveMixin = {
|
|
|
1,
|
|
|
this.xyz_pixel_buffer
|
|
|
);
|
|
|
- //记录webgl坐标
|
|
|
xyz_pixel_buffer[0] += this.OpenDriveMap.x_offs;
|
|
|
xyz_pixel_buffer[1] += this.OpenDriveMap.y_offs;
|
|
|
const st_pixel_buffer = new Float32Array(4);
|
|
@@ -779,45 +731,31 @@ export let openDriveMixin = {
|
|
|
|
|
|
this.camera.clearViewOffset();
|
|
|
this.renderer.setRenderTarget(null);
|
|
|
- /**
|
|
|
- * 选中车道离屏渲染
|
|
|
- */
|
|
|
|
|
|
- if (this.isValid(lane_id_pixel_buffer)) {
|
|
|
- //根据颜色值解码成车道ID
|
|
|
+ if (this.isValid(lane_id_pixel_buffer) && false) {
|
|
|
const decoded_lane_id = this.decodeUInt32(lane_id_pixel_buffer);
|
|
|
- //自定义数据中获取所有车段中的所有车道数据
|
|
|
const odr_lanes_mesh =
|
|
|
this.road_network_mesh.userData.odr_road_network_mesh.lanes_mesh;
|
|
|
- //本次选中的区域车道ID是否和上次一样
|
|
|
if (this.INTERSECTED_LANE_ID != decoded_lane_id) {
|
|
|
- //当前是否是初始化状态,如果不是则进行初始化,防止重复初始化
|
|
|
if (this.INTERSECTED_LANE_ID != 0xffffffff) {
|
|
|
- //根据车道ID索引获取车道信息
|
|
|
this.road_network_mesh.geometry.attributes.color.array.fill(
|
|
|
this.COLORS.road
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- //保存选中车道ID
|
|
|
this.INTERSECTED_LANE_ID = decoded_lane_id;
|
|
|
- //根据车道ID获取车道信息
|
|
|
const lane_vert_idx_interval =
|
|
|
odr_lanes_mesh.get_idx_interval_lane(this.INTERSECTED_LANE_ID);
|
|
|
- //获取该车道长度
|
|
|
const vert_count =
|
|
|
lane_vert_idx_interval[1] - lane_vert_idx_interval[0];
|
|
|
- //修改离屏渲染场景中该车道的背景颜色
|
|
|
this.applyVertexColors(
|
|
|
this.road_network_mesh.geometry.attributes.color,
|
|
|
new THREE.Color(this.COLORS.lane_highlight),
|
|
|
lane_vert_idx_interval[0],
|
|
|
vert_count
|
|
|
);
|
|
|
- //手动更新颜色值
|
|
|
this.road_network_mesh.geometry.attributes.color.needsUpdate = true;
|
|
|
}
|
|
|
- //使用过后删除数据冗余,避免造成内存泄漏
|
|
|
odr_lanes_mesh.delete();
|
|
|
} else {
|
|
|
if (this.INTERSECTED_LANE_ID != 0xffffffff) {
|
|
@@ -896,22 +834,38 @@ export let openDriveMixin = {
|
|
|
}
|
|
|
this.renderer.render(this.scene, this.camera);
|
|
|
},
|
|
|
- fillColorLine(roadId, lineId){
|
|
|
- //这里函数lineId参数是road+line的拼接
|
|
|
+ fillColorLine(roadId, lineId) {
|
|
|
lineId = this.mappingLineId.get(roadId + ":" + lineId);
|
|
|
- //自定义数据中获取所有车段中的所有车道数据
|
|
|
const odr_lanes_mesh = this.road_network_mesh.userData.odr_road_network_mesh.lanes_mesh;
|
|
|
- //根据车道ID获取车道信息
|
|
|
const lane_vert_idx_interval = odr_lanes_mesh.get_idx_interval_lane(lineId);
|
|
|
- //获取该车道长度
|
|
|
const vert_count = (lane_vert_idx_interval[1] - lane_vert_idx_interval[0]);
|
|
|
- //修改离屏渲染场景中该车道的背景颜色
|
|
|
- this.applyVertexColors(this.road_network_mesh.geometry.attributes.color, new THREE.Color(this.COLORS.lane_highlight),
|
|
|
- lane_vert_idx_interval[0], vert_count);
|
|
|
- //手动更新颜色值
|
|
|
+ this.applyVertexColors(this.road_network_mesh.geometry.attributes.color, new THREE.Color(this.COLORS
|
|
|
+ .lane_highlight),
|
|
|
+ lane_vert_idx_interval[0], vert_count);
|
|
|
this.road_network_mesh.geometry.attributes.color.needsUpdate = true;
|
|
|
- //使用过后删除数据冗余,避免造成内存泄漏
|
|
|
odr_lanes_mesh.delete();
|
|
|
+ },
|
|
|
+ clearColorLine(roadId, lineId) {
|
|
|
+ lineId = this.mappingLineId.get(roadId + ":" + lineId);
|
|
|
+ const odr_lanes_mesh = this.road_network_mesh.userData.odr_road_network_mesh.lanes_mesh;
|
|
|
+ const lane_vert_idx_interval = odr_lanes_mesh.get_idx_interval_lane(lineId);
|
|
|
+ const vert_count = (lane_vert_idx_interval[1] - lane_vert_idx_interval[0]);
|
|
|
+ this.road_network_mesh.geometry.attributes.color.array.fill(
|
|
|
+ this.COLORS.road
|
|
|
+ );
|
|
|
+ this.road_network_mesh.geometry.attributes.color.needsUpdate = true;
|
|
|
+ odr_lanes_mesh.delete();
|
|
|
+ },
|
|
|
+ onWindowResize() {
|
|
|
+ this.camera.aspect = window.innerWidth / window.innerHeight;
|
|
|
+ this.camera.updateProjectionMatrix();
|
|
|
+ this.renderer.setSize(window.innerWidth, window.innerHeight);
|
|
|
+ this.renderer.setPixelRatio(window.devicePixelRatio);
|
|
|
+ },
|
|
|
+ init(){
|
|
|
+ this.initThreeJs();
|
|
|
+ this.initOffscreen();
|
|
|
+ this.initMaterial();
|
|
|
}
|
|
|
}
|
|
|
}
|