自动化test

This commit is contained in:
sunzhenyu 2019-09-11 18:12:52 +08:00
parent 4e1f95e900
commit 33442d2969
5 changed files with 300 additions and 53 deletions

View File

@ -42,7 +42,8 @@ export function Jlmap3ddata(mapid,scope){
console.log(isSection); console.log(isSection);
if(isSection == true){ if(isSection == true){
init3d(editmapid,data.data); initobj(editmapid,data.data.id);
//init3d(editmapid,data.data);
}else{ }else{
// console.log(editmapid); // console.log(editmapid);
// console.log(data.data.id); // console.log(data.data.id);
@ -74,6 +75,7 @@ export function Jlmap3ddata(mapid,scope){
console.log(mapid); console.log(mapid);
getMapDetail(mapid).then(data => { getMapDetail(mapid).then(data => {
let mapdata = data.data; let mapdata = data.data;
console.log(mapdata);
//console.log(data3did); //console.log(data3did);
jlmap3ddata.id = data3did; jlmap3ddata.id = data3did;
jlmap3ddata.mapId = mapid; jlmap3ddata.mapId = mapid;
@ -84,7 +86,7 @@ export function Jlmap3ddata(mapid,scope){
//初始化站台 //初始化站台
jlmap3ddata.stationstandlist = new StationStandList(); jlmap3ddata.stationstandlist = new StationStandList();
jlmap3ddata.trainlisttest = new TrainListTest(); jlmap3ddata.trainlisttest = new TrainListTest();
LinkList(mapdata.linkList,scene);
assetloader.assetinit(scene) assetloader.assetinit(scene)
.then(function(data){ .then(function(data){
//console.log(data); //console.log(data);
@ -107,7 +109,7 @@ export function Jlmap3ddata(mapid,scope){
loadingInstance.close(); loadingInstance.close();
}); });
//初始化信号 //初始化信号
SetObj(mapdata,scope); //SetObj(mapdata,scope);
}); });
} }

View File

@ -36,8 +36,32 @@ export function Sectionaction(){
} }
} }
//点击事件 //点击事件
this.raycaster = function(data){ this.raycaster = function(data,type){
console.log(); console.log("sa");
if(type == "test"){
let modellist = data.scene.getObjectByName("link").children;
//定义光线
let raycaster = new THREE.Raycaster();
//定义平面鼠标点击坐标
let mouse = new THREE.Vector2();
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera( mouse, data.camera );
let intersects1;
for(let i=0;i<modellist.length;i++){
intersects1 = raycaster.intersectObject(modellist[i]);
if(intersects1[0]){
console.log(intersects1[0].object.code);
console.log(modellist[i].code);
if(intersects1[0].object.code == modellist[i].code){
return modellist[i];
}
}
}
return null;
}else{
if(scope.on == true){ if(scope.on == true){
//定义光线 //定义光线
@ -66,6 +90,8 @@ export function Sectionaction(){
} }
} }
}
this.changemodel = function(jlmap3dedit,changedata){ this.changemodel = function(jlmap3dedit,changedata){
console.log(changedata); console.log(changedata);
let scene = jlmap3dedit.scene; let scene = jlmap3dedit.scene;

View File

@ -10,7 +10,7 @@ export function LinkList(data,scene){
lineGeometry.vertices.push(new THREE.Vector3(data[i].rp.x, 1, data[i].rp.y)); lineGeometry.vertices.push(new THREE.Vector3(data[i].rp.x, 1, data[i].rp.y));
let line = new THREE.Line(lineGeometry, new THREE.LineDashedMaterial({ let line = new THREE.Line(lineGeometry, new THREE.LineDashedMaterial({
color: 0x080808,//线段的颜色 color: 0xffffff,//线段的颜色
dashSize: 1,//短划线的大小 dashSize: 1,//短划线的大小
gapSize: 3//短划线之间的距离 gapSize: 3//短划线之间的距离
})); }));
@ -22,10 +22,222 @@ export function LinkList(data,scene){
line.distancey = data[i].rp.y-data[i].lp.y; line.distancey = data[i].rp.y-data[i].lp.y;
line.computeLineDistances();//不可或缺的,若无,则线段不能显示为虚线 line.computeLineDistances();//不可或缺的,若无,则线段不能显示为虚线
groups.add(line); groups.add(line);
groups.position.z = 400; groups.position.z = 2000;
linklist.push(line); linklist.push(line);
} }
scene.add(groups); scene.add(groups);
return linklist; let linksgroup = new THREE.Group();
linksgroup.name = "link";
scene.add(linksgroup);
console.log(linksgroup);
linktest(data,scene);
// return linklist;
function linktest(data,scene){
let texture = new THREE.TextureLoader().load( '../../static/material/guidao/z025111.png' );
texture.repeat.set(1,1);
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
// texture.repeat.x = 2000;
let testmaterial = new THREE.MeshPhongMaterial( { map: texture } );
let testmesh1 = new THREE.Mesh( new THREE.PlaneBufferGeometry( 1, 4 ), testmaterial );
testmesh1.rotation.x = - Math.PI / 2;
let reallinks = [];
let testlink;
testlink = data;
if(data){
let index,startdata;
for(let n=0;n<data.length;n++){
if(data[n].leftFdCode == undefined && data[n].leftSdCode == undefined && data[n].rightFdCode ){
if(startdata){
if(data[n].lp.x<startdata.lp.x){
startdata = data[n];
index = n;
}
}else{
startdata = data[n];
index = n;
}
// n = data.length;
}
}
buildmodel(startdata);
reallinks.push(startdata);
data.splice(index,1);
for(let i=0;i<reallinks.length;i++){
console.log(data.length);
for(let j=0;j<data.length;j++){
if(reallinks[i].leftFdCode && j>=0){
if(reallinks[i].leftFdCode == data[j].code){
buildmodel(data[j],reallinks[i],j,"left");
reallinks.push(data[j]);
data.splice(j,1);
j--;
}
}
if(reallinks[i].leftSdCode && j>=0){
if(reallinks[i].leftSdCode == data[j].code){
buildmodel(data[j],reallinks[i],j,"left");
reallinks.push(data[j]);
data.splice(j,1);
j--;
}
}
if(reallinks[i].rightFdCode && j>=0){
if(reallinks[i].rightFdCode == data[j].code){
buildmodel(data[j],reallinks[i],j,"right");
reallinks.push(data[j]);
data.splice(j,1);
j--;
}
}
if(reallinks[i].rightSdCode && j>=0){
if(reallinks[i].rightSdCode == data[j].code){
buildmodel(data[j],reallinks[i],j,"right");
reallinks.push(data[j]);
data.splice(j,1);
j--;
}
}
} }
}
function checklink(code,data){
if(code == data.leftFdCode){
}
if(code == data.leftSdCode){
}
if(code == data.rightFdCode){
}
if(code == data.rightSdCode){
}
}
function buildmodel(data,mdata,sx,direct){
console.log("sa");
let len = data.lengthFact;
let testmesh2 = testmesh1.clone(true);
let newgeometry = new THREE.PlaneBufferGeometry( 1, 4 );
for(let j=0;j<testmesh2.geometry.attributes.position.array.length;j++){
if(testmesh2.geometry.attributes.position.array[j]== 0.5){
newgeometry.attributes.position.array[j] = len-10;
}
}
newgeometry.attributes.uv.array[2] = len-10;
newgeometry.attributes.uv.array[6] = len-10;
newgeometry.attributes.position.needsUpdate = true;
newgeometry.attributes.uv.needsUpdate = true;
testmesh2.geometry = newgeometry;
testmesh2.geometry.computeBoundingBox();
testmesh2.geometry.center();
testmesh2.material.needsUpdate = true;
// data.lp.y *= 10;
// data.rp.y *= 10;
if(mdata){
if(direct == "leftfd"){
data.rp.x = mdata.lp.x;
data.rp.y = mdata.lp.y;
data.lp.x = data.rp.x - data.lengthFact;
data.lp.y = data.rp.y;
testmesh2.position.x = (data.lp.x + data.rp.x)/2;
testmesh2.position.z = (data.lp.y + data.rp.y)/2;
}
if(direct == "rightfd"){
data.lp.x = mdata.rp.x;
data.lp.y = mdata.rp.y;
data.rp.x = data.lp.x + data.lengthFact;
data.rp.y = data.lp.y;
testmesh2.position.x = (data.lp.x + data.rp.x)/2;
testmesh2.position.z = (data.lp.y + data.rp.y)/2;
}
if(direct == "left"){
let dx = Math.abs(data.lp.x - data.rp.x);
    let dy = Math.abs(data.lp.y - data.rp.y);
    let distance = Math.sqrt(Math.pow(dx,2)+Math.pow(dy,2));
data.lp.x = (data.lp.x-data.rp.x)*data.lengthFact/distance+mdata.lp.x;
data.lp.y = (data.lp.y-data.rp.y)*data.lengthFact/distance+mdata.lp.y;
data.rp.x = mdata.lp.x;
data.rp.y = mdata.lp.y;
testmesh2.position.x = (data.rp.x + data.lp.x)/2;
testmesh2.position.z = (data.rp.y + data.lp.y)/2;
let axix = new THREE.Vector3(1,0,0);
let axixnow = new THREE.Vector3(data.rp.x-data.lp.x,0,data.rp.y-data.lp.y);
let rotenum = axixnow.angleTo(axix);
//不同坐标系方向值不同
if(data.lp.y>data.rp.y){
testmesh2.rotation.z = rotenum;
}else {
testmesh2.rotation.z = -rotenum;
}
}
if(direct == "right"){
let dx = Math.abs(data.lp.x - data.rp.x);
    let dy = Math.abs(data.lp.y - data.rp.y);
    let distance = Math.sqrt(Math.pow(dx,2)+Math.pow(dy,2));
data.rp.x = (data.rp.x-data.lp.x)*data.lengthFact/distance+mdata.rp.x;
data.rp.y = (data.rp.y-data.lp.y)*data.lengthFact/distance+mdata.rp.y;
data.lp.x = mdata.rp.x;
data.lp.y = mdata.rp.y;
testmesh2.position.x = (data.lp.x + data.rp.x)/2;
testmesh2.position.z = (data.lp.y + data.rp.y)/2;
let axix = new THREE.Vector3(1,0,0);
let axixnow = new THREE.Vector3(data.rp.x-data.lp.x,0,data.rp.y-data.lp.y);
let rotenum = axixnow.angleTo(axix);
//不同坐标系方向值不同
if(data.lp.y>data.rp.y){
testmesh2.rotation.z = rotenum;
}else {
testmesh2.rotation.z = -rotenum;
}
}
}else{
data.lp.x = data.lp.x;
data.rp.x = data.lp.x + data.lengthFact;
testmesh2.position.x = (data.lp.x + data.rp.x)/2;
testmesh2.position.z = (data.lp.y + data.rp.y)/2;
}
testmesh2.position.y = 10;
testmesh2.code = data.code;
var box = new THREE.BoxHelper( testmesh2, 0xff0000 );
scene.add( box );
linksgroup.add( testmesh2 );
}
}
}
}

View File

@ -152,14 +152,21 @@ export function JLmap3dEdit(dom, data, mapid) {
} }
this.actiommode = function(changedata){ this.actiommode = function(changedata){
console.log(changedata);
console.log(scope.editmode); console.log(scope.editmode);
// console.log(scope.actionmode); // console.log(scope.actionmode);
// console.log(changedata); // console.log(changedata);
if(scope.editmode == "trackedit"){ if(changedata == "trackreplace"){
scope.selectmodel = scope.action.sectionaction.changemodel(scope,changedata); scope.editmode == "trackedit";
scope.eventon();
} }
// if(scope.editmode == "trackedit"){
// scope.selectmodel = scope.action.sectionaction.changemodel(scope,changedata);
// }
if(scope.actionmode == "signaledit"){ if(scope.actionmode == "signaledit"){
scope.selectmodel = scope.action.signalaction.changemodel(scope,changedata); scope.selectmodel = scope.action.signalaction.changemodel(scope,changedata);
} }
@ -208,7 +215,7 @@ export function JLmap3dEdit(dom, data, mapid) {
//从站台对象组获取点击目标 //从站台对象组获取点击目标
if(scope.editmode == "trackedit"){ if(scope.editmode == "trackedit"){
scope.selectmodel = scope.action.sectionaction.raycaster(scope); scope.selectmodel = scope.action.sectionaction.raycaster(scope,"test");
} }
if(scope.editmode == "signaledit"){ if(scope.editmode == "signaledit"){

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 KiB