增加三维沙盘第一人称漫游,修改三维沙盘天气

This commit is contained in:
sunzhenyu 2021-12-14 17:26:10 +08:00
parent f2ceea6567
commit 72eebe0388
11 changed files with 590 additions and 224 deletions

View File

@ -7,7 +7,7 @@ NODE_ENV = 'development'
# VUE_APP_BASE_API = 'http://192.168.3.4:9000'
VUE_APP_BASE_API = 'http://192.168.3.6:9000'
VUE_APP_VOICE_API = 'http://119.3.163.89/oss/joylink'
VUE_APP_UPLOAD_API = 'https://upload.joylink.club'
VUE_APP_UPLOAD_API = 'http://119.3.163.89/upload'
VUE_APP_BASE_SITE='https://test.joylink.club/cbtc'
# VUE_APP_VOICE_API = 'http://192.168.8.110:9008'

View File

@ -342,7 +342,11 @@ export function Jl3ddeviceNew(dom,group,token,skinCode) {
scope.raycasterstatus = false;
scope.nowobject = null;
updatemenulist();
if(data._type == "Station"){
console.log(data);
}
if (data._type == "Switch") {
// scope.modelmanager.switchmodel.locateType = data.body.locateType;
scope.modelmanager.switchmodel.code = data.code;

View File

@ -16,7 +16,8 @@ import { SetLights } from '@/jlmap3d/config/SetLights';
import { WeatherManager } from '@/jlmap3d/config/WeatherManager';
//controls
//controlManager.oribitControl
import { ControlManager } from '@/jlmap3d/jl3dsimulation/manager/controlmanager.js';
import { OrbitControls } from '@/jlmap3d/main/control/OrbitControls';
// import { DragControls } from '@/jlmap3d/main/control/DragControls';
@ -41,35 +42,18 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup,project) {
let scope = this;
this.dom = dom;
//初始化webgl渲染
let renderer = SetRender(dom);
renderer.domElement.style.position = "absolute";
renderer.domElement.style.top = "0";
document.getElementById('testjlmap3d').appendChild(renderer.domElement);
//定义相机
let camera = SetCamera(dom);
//定义场景(渲染容器)
let scene = SetScene(project);
let scenesimulation = new THREE.Group();
let scenestation = new THREE.Group();
scene.add(scenesimulation);
scene.add(scenestation);
let controlManager = new ControlManager( dom,scene);
let weatherManager = new WeatherManager(scene);
scene.add(weatherManager.skybox);
// scene.add(weatherManager.instance);
// scene.add(sphere);
//定义镜头操作
let controls = new THREE.OrbitControls(camera);
controls.maxPolarAngle = Math.PI/2;
// controls.screenSpacePanning = true;
//controls.minPolarAngle = Math.PI/8;
controls.maxDistance = 800;
//模型加载器
this.assetloader = new AssetLoader();
//替换材质组,例:信号机不同灯光
@ -82,8 +66,6 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup,project) {
this.selectmodel = null;
//鼠标点击模型切换
this.raycasterswitch = "null";
//选中物体描边方框
this.helpbox = null;
//车门,站台门道岔动画构造器
this.mixers = [];
//模型操作命令组
@ -97,6 +79,7 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup,project) {
let trainlisttest = null;
let realsectionlist = null;
let rails = null;
let backgroundModel = null;
//轨道相机
let camerarail = {
@ -119,7 +102,7 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup,project) {
scope.jsonwebworknew = new Worker(JL3D_LOCAL_STATIC+"/workertest/jsonworkernew.js");
scope.Subscribe = new Jlmap3dSubscribeNew(scope,routegroup,scope.jsonwebworknew);
scope.Subscribe.socketon(scope.Subscribe.topic);
SimulationLoadNew(mapnetdata,scope,netdata.data,mapdata,camera,controls,scenesimulation,project);
SimulationLoadNew(mapnetdata,scope,netdata.data,mapdata,controlManager.orbitCamera,controlManager.oribitControl,scenesimulation,project);
});
});
@ -134,14 +117,18 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup,project) {
requestAnimationFrame(animate);
//根据相机渲染场景
// sphere
// if(sphere){
// sphere.position.x = camera.position.x;
// sphere.position.z = camera.position.z;
// }
weatherManager.update(camera.position);
// console.log(camera.position);
renderer.render(scene,camera);
if(controlManager.controlMode == "free"){
controlManager.updateOrbitControl();
}
if(controlManager.controlMode == "fps"){
controlManager.updateFpsControl();
}
if(controlManager.controlMode == "train"){
controlManager.updateTrainControl();
}
weatherManager.update(controlManager.orbitCamera.position);
// console.log(controlManager.orbitCamera.position);
// stats.update();
}
@ -154,7 +141,7 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup,project) {
if(scope.datatype == "new"){
}else{
UpdateTrain(camera,trainlisttest);
UpdateTrain(controlManager.orbitCamera,trainlisttest);
}
delta = clock.getDelta();
@ -174,13 +161,13 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup,project) {
}else{
let point = camerarail.curve.getPointAt(camerarail.progress);
let tangent = camerarail.curve.getPointAt(camerarail.progress+0.001);
camera.position.x = point.x;
camera.position.y = point.y;
camera.position.z = point.z;
controlManager.orbitCamera.position.x = point.x;
controlManager.orbitCamera.position.y = point.y;
controlManager.orbitCamera.position.z = point.z;
camerarail.progress += 0.003;
// controls.target = new THREE.Vector3(point.x+1,point.y,point.z);
controls.target = new THREE.Vector3(tangent.x,tangent.y,tangent.z);
controls.update();
// controlManager.oribitControl.target = new THREE.Vector3(point.x+1,point.y,point.z);
controlManager.oribitControl.target = new THREE.Vector3(tangent.x,tangent.y,tangent.z);
controlManager.oribitControl.update();
point = null;
}
@ -193,11 +180,9 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup,project) {
//释放场景缓存关闭渲染循环
this.dispose = function(){
renderer.setAnimationLoop(null);
renderer.dispose();
scene.dispose();
controls.dispose();
camera = null;
controlManager.oribitControl.dispose();
controlManager.orbitCamera = null;
scope.assetloader = null;
mapdata = null;
@ -205,7 +190,6 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup,project) {
scope.materiallist = null;
scope.selectmodel = null;
scope.helpbox = null;
scope.mixers = null;
scope.actions = null;
scope.Subscribe = null;
@ -213,13 +197,6 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup,project) {
//scope = null;
}
this.rayswitch = function(value){
this.raycasterswitch = value;
if(scope.helpbox){
scene.remove( scope.helpbox );
scope.helpbox = null;
}
};
//切换显示车站信息
this.showstationmsg = function(showtype){
@ -252,15 +229,15 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup,project) {
}
//开启轨道镜头交互
this.animateon = function(){
controls.enabled = true;
controlManager.oribitControl.enabled = true;
};
//关闭轨道镜头交互
this.animateoff = function(){
controls.enabled = false;
controlManager.oribitControl.enabled = false;
};
//更新加载后数据
this.loaderdata = function(loadsectionlist,loadlinklist,loadsignallist,loadstationstandlist,loadtrainlisttest,loadrealsectionlist,loadrails){
this.loaderdata = function(loadsectionlist,loadlinklist,loadsignallist,loadstationstandlist,loadtrainlisttest,loadrealsectionlist,loadrails,bgmodel){
sectionlist = loadsectionlist;
linklist = loadlinklist;
@ -270,140 +247,79 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup,project) {
trainlisttest = loadtrainlisttest;
realsectionlist = loadrealsectionlist;
rails = loadrails;
backgroundModel = bgmodel;
}
this.eventon = function(){
//raycaster交互模型点击事件
document.getElementById("testjlmap3d").addEventListener( "mousedown", onselect, false );
//窗口自适应
window.addEventListener( 'resize', onWindowResize, false );
document.getElementById("testjlmap3d").addEventListener( "mousedown", onselect, false );
controls.update();
};
this.eventoff = function(){
//console.log("off");
//raycaster交互模型点击事件
document.getElementById("testjlmap3d").removeEventListener( "mousedown", onselect, false );
//窗口自适应
window.removeEventListener( 'resize', onWindowResize, false );
};
this.enterStopStation = function(){
jl3dSimulationGlobeFunction('changeview','fps');
controlManager.attachFpsCamera(backgroundModel,{x:-2212,y:10.7,z:-15.7});
}
//根据菜单选项切换相机位置
this.updatecamera = function(mesh,type){
if(type == "station"){
camera.position.x = mesh.position.x;
camera.position.y = mesh.position.y+800;
camera.position.z = mesh.position.z+300;
controlManager.orbitCamera.position.x = mesh.position.x;
controlManager.orbitCamera.position.y = mesh.position.y+800;
controlManager.orbitCamera.position.z = mesh.position.z+300;
//更新相机方向
controls.target = new THREE.Vector3(mesh.position.x,mesh.position.y,mesh.position.z);
}
if(type == "train"){
camera.position.x = mesh.position.x;
camera.position.y = mesh.position.y+800;
camera.position.z = mesh.children[2].matrixWorld.elements[14]+300;
//更新相机方向
controls.target = new THREE.Vector3(mesh.position.x,mesh.position.y,mesh.children[2].matrixWorld.elements[14]);
controlManager.oribitControl.target = new THREE.Vector3(mesh.position.x,mesh.position.y,mesh.position.z);
if(stationstandlist && trainlisttest){
controlManager.oribitControl.upmodeldirect(stationstandlist,trainlisttest);
}
controlManager.oribitControl.update();
}
if(stationstandlist && trainlisttest){
controls.upmodeldirect(stationstandlist,trainlisttest);
if(type == "train"){
controlManager.attachTrainCamera(mesh);
}
controls.update();
}
//窗口自适应
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
this.backFpsView = function(){
controlManager.deattachFpsCamera();
if(stationstandlist && trainlisttest){
controlManager.oribitControl.upmodeldirect(stationstandlist,trainlisttest);
}
controlManager.oribitControl.update();
}
this.backTrainView = function(){
controlManager.deattachTrainCamera();
if(stationstandlist && trainlisttest){
controlManager.oribitControl.upmodeldirect(stationstandlist,trainlisttest);
}
controlManager.oribitControl.update();
}
//三维交互点击事件函数
function onselect(event) {
if(event.button == "0"){
//定义光线
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;
if(controlManager.controlMode != 'fps'){
//定义光线
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, camera );
if(scope.helpbox){
scene.remove( scope.helpbox );
scope.helpbox = null;
}
raycaster.setFromCamera( mouse, controlManager.orbitCamera );
if(scope.raycasterswitch == "stand"){
//从站台对象组获取点击目标
let intersects1 = raycaster.intersectObjects( stationstandlist.textlist);
let intersects1 = raycaster.intersectObjects( stationstandlist.group.children,true);
//获取最近处点击到的模型对象
if(intersects1[0]){
//遍历对象组获取对象坐标更新相机数据
for(let j=0;j<stationstandlist.list.length;j++){
if(intersects1[0].object.name == stationstandlist.list[j].mesh.code){
camera.position.x = stationstandlist.list[j].mesh.position.x;
camera.position.y = stationstandlist.list[j].mesh.position.y+200;
camera.position.z = stationstandlist.list[j].mesh.position.z+300;
//更新相机方向
controls.target = new THREE.Vector3(stationstandlist.list[j].mesh.position.x,stationstandlist.list[j].mesh.position.y,stationstandlist.list[j].mesh.position.z);
controls.update();
}
if(!intersects1[0].object.modeltype){
jl3dSimulationGlobeFunction('changeview','fps');
controlManager.attachFpsCamera(intersects1[0].object.parent,intersects1[0].point);
}
}
}
if(scope.raycasterswitch == "train"){
let intersects = raycaster.intersectObjects( trainlisttest.textlist);
if(intersects[0]){
for(let j=0;j<trainlisttest.list.length;j++){
if(intersects[0].object.name == trainlisttest.list[j].name){
// console.log(trainlisttest.list[j].position.x);
// console.log(trainlisttest.list[j].position.y);
// console.log(trainlisttest.list[j].children[2].matrixWorld.elements[14]);
camera.position.x = trainlisttest.list[j].position.x;
camera.position.y = 200;
camera.position.z = trainlisttest.list[j].children[2].matrixWorld.elements[14]+300;
//console.log(camera.position);
controls.target = new THREE.Vector3(trainlisttest.list[j].children[2].matrixWorld.elements[12],trainlisttest.list[j].children[2].matrixWorld.elements[13],trainlisttest.list[j].children[2].matrixWorld.elements[14]);
controls.update();
}
}
}
}
if(scope.raycasterswitch == "section"){
//console.log(sectionlist.sections.modellist);
let intersects = raycaster.intersectObjects( linklist.linksgroup.children,true);
if(intersects[0]){
// console.log(intersects[0].object);
scope.helpbox = new THREE.BoxHelper( intersects[0].object, 0xff0000 );
scene.add( scope.helpbox );
}
}
if(scope.raycasterswitch == "signal"){
let intersects = raycaster.intersectObjects( signallist.group.children,true);
if(intersects[0]){
// console.log(intersects[0].object.matrixWorld);
scope.helpbox = new THREE.BoxHelper( intersects[0].object, 0xff0000 );
scene.add( scope.helpbox );
}
}
if(scope.raycasterswitch == "switch"){
console.log(sectionlist);
let intersects = raycaster.intersectObjects( sectionlist.switchs.modellist,true);
if(intersects[0]){
scope.helpbox = new THREE.BoxHelper( intersects[0].object, 0xff0000 );
scene.add( scope.helpbox );
}
}
}
}
@ -441,8 +357,8 @@ export function JLmap3d(dom, data,skinCode,storemod,routegroup,project) {
// points.push(new THREE.Vector3(stationp1.x+40,3,stationp1.z+15));
// controls.target = new THREE.Vector3(camera.position.x+1,camera.position.y,camera.position.z);
// controls.update();
// controlManager.oribitControl.target = new THREE.Vector3(controlManager.orbitCamera.position.x+1,controlManager.orbitCamera.position.y,controlManager.orbitCamera.position.z);
// controlManager.oribitControl.update();
camerarail.curve = new THREE.CatmullRomCurve3(points);
}

View File

@ -0,0 +1,428 @@
import { Capsule } from '@/jlmap3d/utils/math/Capsule.js';
import { Octree } from '@/jlmap3d/utils/math/Octree.js';
import { JL3D_LOCAL_STATIC } from '@/api/jlmap3d/assets3d.js';
import { OBJLoader } from '@/jlmap3d/main/loaders/OBJLoader';
export function ControlManager(dom,scene,lessonData,lessonIndex) {
let scope = this;
this.controlMode = "free";
this.controls = {};
this.nowCamera = null;
this.eventHitMode = false;
let modelManager;
let examList = {};
let examData = {};
let eventBoxs = [];
let raycasterBoxs = [];
let actionList = [];
let eventTrigger;
let nowActions = [];
let allOverAction;
let trainDeviceMode = false;
let fpsMouseStatus = false;
var audiopbm = JL3D_LOCAL_STATIC+'/lesson3d/audio/pbm.wav';
audiopbm = new Audio(audiopbm);
let renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(dom.offsetWidth, dom.offsetHeight);
// renderer.autoClear = false;
renderer.sortObjects = true;
renderer.domElement.style.position = "absolute";
renderer.domElement.style.top = "0";
document.getElementById('testjlmap3d').appendChild(renderer.domElement);
this.orbitCamera = new THREE.PerspectiveCamera(60, dom.clientWidth/dom.clientHeight, 1, 4000);
this.orbitCamera.position.set(0, 0, 0);
this.orbitCamera.aspect = window.innerWidth / window.innerHeight;
this.orbitCamera.updateProjectionMatrix();
this.oribitControl = new THREE.OrbitControls(scope.orbitCamera,dom);
this.oribitControl.maxPolarAngle = Math.PI / 2;
this.oribitControl.maxDistance = 800;
this.oribitControl.update();
let trainCamera = new THREE.PerspectiveCamera( 75,dom.offsetWidth / dom.offsetHeight, 0.1, 1000 );
trainCamera.aspect = dom.offsetWidth / dom.offsetHeight;
trainCamera.updateProjectionMatrix();
let fpsCamera = new THREE.PerspectiveCamera( 75,dom.offsetWidth / dom.offsetHeight, 0.1, 6000 );
fpsCamera.aspect = dom.offsetWidth / dom.offsetHeight;
fpsCamera.rotation.order = 'YXZ';
let attachBox = new THREE.Mesh(
new THREE.BoxGeometry(1,1.5, 1),
new THREE.MeshBasicMaterial({color: 0xff00000,transparent: true,opacity: 0 })//RED box
);
let hitBox = new THREE.Box3(new THREE.Vector3(), new THREE.Vector3());
hitBox.setFromObject(attachBox);
scene.add(attachBox);
//fps control
const GRAVITY = 30;
const NUM_SPHERES = 20;
const SPHERE_RADIUS = 0.1;
const sphereGeometry = new THREE.SphereGeometry( SPHERE_RADIUS, 16, 16 );
const sphereMaterial = new THREE.MeshStandardMaterial( { color: 0x888855, roughness: 0.8, metalness: 0.5, } );
const spheres = [];
let sphereIdx = 0;
for ( let i = 0; i < NUM_SPHERES; i ++ ) {
const sphere = new THREE.Mesh( sphereGeometry, sphereMaterial );
scene.add( sphere );
spheres.push( { mesh: sphere, collider: new THREE.Sphere( new THREE.Vector3( 0, - 100, 0 ), SPHERE_RADIUS ), velocity: new THREE.Vector3() } );
}
const worldOctree = new Octree();
const playerCollider = new Capsule( new THREE.Vector3( 0, 10, 0 ), new THREE.Vector3( 0, 11.5, 0 ), 1 );
// playerCollider.set(
// new THREE.Vector3(
// lessonData.lessonProgress[lessonIndex].cameraPosition.x,
// lessonData.lessonProgress[lessonIndex].cameraPosition.y,
// lessonData.lessonProgress[lessonIndex].cameraPosition.z),
// new THREE.Vector3(
// lessonData.lessonProgress[lessonIndex].cameraPosition.x,
// lessonData.lessonProgress[lessonIndex].cameraPosition.y+1.5,
// lessonData.lessonProgress[lessonIndex].cameraPosition.z ), 1);
// attachBox.position.x = lessonData.lessonProgress[lessonIndex].cameraPosition.x;
// attachBox.position.y = lessonData.lessonProgress[lessonIndex].cameraPosition.y ;
// attachBox.position.z = lessonData.lessonProgress[lessonIndex].cameraPosition.z;
const playerVelocity = new THREE.Vector3();
const playerDirection = new THREE.Vector3();
let playerOnFloor = false;
const keyStates = {};
let clock = new THREE.Clock();
let nowStation = "";
this.attachFpsCamera = function(mesh,point){
nowStation = mesh;
worldOctree.fromGraphNode( nowStation );
scope.nowCamera = fpsCamera;
scope.oribitControl.enabled = false;
attachBox.position.x = point.x;
attachBox.position.y = point.y;
attachBox.position.z = point.z;
playerCollider.set(
new THREE.Vector3(
point.x,
point.y,
point.z),
new THREE.Vector3(
point.x,
point.y+1.5,
point.z ), 1);
scope.orbitCamera.position.x = point.x;
scope.orbitCamera.position.y = point.y+800;
scope.orbitCamera.position.z = point.z+300;
//更新相机方向
scope.oribitControl.target = new THREE.Vector3(point.x,point.y,point.z);
scope.controlMode = "fps";
}
this.deattachFpsCamera = function(){
scope.oribitControl.enabled = true;
scope.controlMode = "free";
scope.orbitCamera.position.x = nowStation.position.x;
scope.orbitCamera.position.y = nowStation.position.y+800;
scope.orbitCamera.position.z = nowStation.children[2].matrixWorld.elements[14]+300;
//更新相机方向
scope.oribitControl.target = new THREE.Vector3(nowStation.position.x,nowStation.position.y,nowStation.children[2].matrixWorld.elements[14]);
scope.oribitControl.enabled = true;
// playerCollider = new Capsule( new THREE.Vector3( 0, 10, 0 ), new THREE.Vector3( 0, 11.9, 0 ), 1 );
}
let nowTrain = "";
this.attachTrainCamera = function(mesh){
scope.oribitControl.enabled = false;
nowTrain = mesh;
this.controlMode = "train";
mesh.children[0].add(trainCamera);
trainCamera.position.x = 10;
trainCamera.position.y = 0;
trainCamera.position.z = 4.5;
trainCamera.rotation.x = Math.PI/2;
trainCamera.rotation.y = -Math.PI/2;
}
this.deattachTrainCamera = function(){
scope.oribitControl.enabled = true;
scope.controlMode = "free";
scope.orbitCamera.position.x = nowTrain.position.x;
scope.orbitCamera.position.y = nowTrain.position.y+800;
scope.orbitCamera.position.z = nowTrain.children[2].matrixWorld.elements[14]+300;
//更新相机方向
scope.oribitControl.target = new THREE.Vector3(nowTrain.position.x,nowTrain.position.y,nowTrain.children[2].matrixWorld.elements[14]);
scope.oribitControl.enabled = true;
}
this.updateOrbitControl = function(){
scope.oribitControl.update();
render(scope.orbitCamera);
};
this.updateFpsControl = function(){
const deltaTime = Math.min( 0.1, clock.getDelta() );
controls( deltaTime );
updatePlayer( deltaTime );
updateSpheres( deltaTime );
render(fpsCamera);
};
this.updateTrainControl = function(){
render(trainCamera);
}
this.updatePos = function(pos){
playerCollider.set(
new THREE.Vector3(
pos.x,
pos.y,
pos.z),
new THREE.Vector3(
pos.x,
pos.y+1.5,
pos.z ), 1);
}
document.addEventListener( 'keydown', ( event ) => {
keyStates[ event.code ] = true;
} );
document.addEventListener( 'keyup', ( event ) => {
keyStates[ event.code ] = false;
} );
document.addEventListener( 'mousedown', (event) => {
fpsMouseStatus = true;
});
document.body.addEventListener( 'mousemove', ( event ) => {
if(fpsMouseStatus == true){
fpsCamera.rotation.y -= event.movementX / 500;
fpsCamera.rotation.x -= event.movementY / 500;
}
// if ( document.pointerLockElement === document.body ) {
// }
} );
document.addEventListener( 'mouseup', () => {
fpsMouseStatus = false;
} );
function playerCollitions() {
const result = worldOctree.capsuleIntersect( playerCollider );
playerOnFloor = false;
if ( result ) {
playerOnFloor = result.normal.y > 0;
if ( ! playerOnFloor ) {
playerVelocity.addScaledVector( result.normal, - result.normal.dot( playerVelocity ) );
}
playerCollider.translate( result.normal.multiplyScalar( result.depth ) );
}
}
function updatePlayer( deltaTime ) {
if ( playerOnFloor ) {
const damping = Math.exp( - 3 * deltaTime ) - 1;
playerVelocity.addScaledVector( playerVelocity, damping );
} else {
if(playerVelocity.y>-10){
playerVelocity.y -= GRAVITY * deltaTime;
}
}
const deltaPosition = playerVelocity.clone().multiplyScalar( deltaTime );
playerCollider.translate( deltaPosition );
playerCollitions();
fpsCamera.position.copy( playerCollider.end );
}
function spheresCollisions() {
for ( let i = 0; i < spheres.length; i ++ ) {
const s1 = spheres[ i ];
for ( let j = i + 1; j < spheres.length; j ++ ) {
const s2 = spheres[ j ];
const d2 = s1.collider.center.distanceToSquared( s2.collider.center );
const r = s1.collider.radius + s2.collider.radius;
const r2 = r * r;
if ( d2 < r2 ) {
const normal = s1.collider.clone().center.sub( s2.collider.center ).normalize();
const v1 = normal.clone().multiplyScalar( normal.dot( s1.velocity ) );
const v2 = normal.clone().multiplyScalar( normal.dot( s2.velocity ) );
s1.velocity.add( v2 ).sub( v1 );
s2.velocity.add( v1 ).sub( v2 );
const d = ( r - Math.sqrt( d2 ) ) / 2;
s1.collider.center.addScaledVector( normal, d );
s2.collider.center.addScaledVector( normal, - d );
}
}
}
}
function updateSpheres( deltaTime ) {
spheres.forEach( sphere =>{
sphere.collider.center.addScaledVector( sphere.velocity, deltaTime );
const result = worldOctree.sphereIntersect( sphere.collider );
if ( result ) {
sphere.velocity.addScaledVector( result.normal, - result.normal.dot( sphere.velocity ) * 1.5 );
sphere.collider.center.add( result.normal.multiplyScalar( result.depth ) );
} else {
sphere.velocity.y -= GRAVITY * deltaTime;
}
const damping = Math.exp( - 1.5 * deltaTime ) - 1;
sphere.velocity.addScaledVector( sphere.velocity, damping );
spheresCollisions();
sphere.mesh.position.copy( sphere.collider.center );
} );
}
function getForwardVector() {
fpsCamera.getWorldDirection( playerDirection );
playerDirection.y = 0;
playerDirection.normalize();
return playerDirection;
}
function getSideVector() {
fpsCamera.getWorldDirection( playerDirection );
playerDirection.y = 0;
playerDirection.normalize();
playerDirection.cross( fpsCamera.up );
return playerDirection;
}
function controls( deltaTime ) {
const speed = 25;
if ( playerOnFloor ) {
if ( keyStates[ 'KeyW' ] ) {
playerVelocity.add( getForwardVector().multiplyScalar( speed * deltaTime ) );
}
if ( keyStates[ 'KeyS' ] ) {
playerVelocity.add( getForwardVector().multiplyScalar( - speed * deltaTime ) );
}
if ( keyStates[ 'KeyA' ] ) {
playerVelocity.add( getSideVector().multiplyScalar( - speed * deltaTime ) );
}
if ( keyStates[ 'KeyD' ] ) {
playerVelocity.add( getSideVector().multiplyScalar( speed * deltaTime ) );
}
if ( keyStates[ 'Space' ] ) {
playerVelocity.y = 10;
}
}
}
function render(camera){
renderer.render( scene, camera );
}
window.onresize = function () {
scope.orbitCamera.aspect = window.innerWidth / window.innerHeight;
scope.orbitCamera.updateProjectionMatrix();
fpsCamera.aspect = window.innerWidth / window.innerHeight;
fpsCamera.updateProjectionMatrix();
renderer.setSize(dom.offsetWidth,dom.offsetHeight);
}
}

View File

@ -1,7 +1,7 @@
import { Capsule } from '@/jlmap3d/lesson3d/math/Capsule.js';
import { Capsule } from '@/jlmap3d/utils/math/Capsule.js';
import { Octree } from '@/jlmap3d/lesson3d/math/Octree.js';
import { Octree } from '@/jlmap3d/utils/math/Octree.js';
import { JL3D_LOCAL_STATIC } from '@/api/jlmap3d/assets3d.js';
import { OBJLoader } from '@/jlmap3d/main/loaders/OBJLoader';

View File

@ -23,6 +23,8 @@ export function SimulationLoadNew(data,scope,netdata,mapdata,camera,controls,sce
let jlmap3ddata = mapdata;
let assetloader = scope.assetloader;
let bgmodel = null;
let mixers = scope.mixers;
let actions = scope.actions;
@ -48,7 +50,6 @@ export function SimulationLoadNew(data,scope,netdata,mapdata,camera,controls,sce
let mapdata = data;
//初始化轨道和道岔
// lengthfact(data);
sectionlist = new SectionListN();
signallist = new SignalListN();
switchlist = new SwitchListN();
@ -117,6 +118,7 @@ export function SimulationLoadNew(data,scope,netdata,mapdata,camera,controls,sce
if(scope.assetloader.modellist[mn].type == "suidao"){
// scope.assetloader.modellist[mn].mesh.deviceType = "suidaobg";
scene.add(scope.assetloader.modellist[mn].mesh);
bgmodel = scope.assetloader.modellist[mn].mesh;
mn = scope.assetloader.modellist.length;
}
}
@ -169,7 +171,7 @@ export function SimulationLoadNew(data,scope,netdata,mapdata,camera,controls,sce
controls.upmodeldirect(stationstandlist,trainlisttest);
controls.update();
backdata.loaderdata(sectionlist,linklist,signallist,stationstandlist,trainlisttest,realsectionlist,rails);
backdata.loaderdata(sectionlist,linklist,signallist,stationstandlist,trainlisttest,realsectionlist,rails,bgmodel);
scope.Subscribe.updatamap(sectionlist,linklist,signallist,stationstandlist,trainlisttest,realsectionlist,rails,tdt,scope.materiallist,scope.actions,scope.sceneload);
scope.webwork.postMessage("on");
scope.jsonwebworknew.postMessage("connect");

View File

@ -110,6 +110,7 @@ export function StationStandListN() {
let textmaterial = new THREE.MeshBasicMaterial( { side: THREE.DoubleSide,map:textt ,transparent: true} );
let textplane = new THREE.Mesh( textgeometry, textmaterial );
textplane.name = stationdata[i].code;
textplane.modeltype = "textplane";
textplane.position.y = 80;
textplane.rotation.x = Math.PI/2;
//textplane.position.x = -30;
@ -363,7 +364,7 @@ export function StationStandListN() {
let textmaterial = new THREE.MeshBasicMaterial( { side: THREE.DoubleSide,map:textt ,transparent: true} );
let textplane = new THREE.Mesh( textgeometry, textmaterial );
textplane.name = standsdata[i].code;
textplane.modeltype = "textplane";
textplane.position.y = 70;
textplane.rotation.x = Math.PI/2;
textplane.position.z = 80;

View File

@ -1,7 +1,7 @@
import { Capsule } from '@/jlmap3d/lesson3d/math/Capsule.js';
import { Capsule } from '@/jlmap3d/utils/math/Capsule.js';
import { Octree } from '@/jlmap3d/lesson3d/math/Octree.js';
import { Octree } from '@/jlmap3d/utils/math/Octree.js';
import { JL3D_LOCAL_STATIC } from '@/api/jlmap3d/assets3d.js';
import { OBJLoader } from '@/jlmap3d/main/loaders/OBJLoader';

View File

@ -1,5 +1,5 @@
import { Capsule } from '@/jlmap3d/lesson3d/math/Capsule.js';
import { Capsule } from '@/jlmap3d/utils/math/Capsule.js';
var Octree = ( function () {
var _v1 = new THREE.Vector3();

View File

@ -2,23 +2,30 @@
<div class="jalmap3ddiv">
<div class="display-draft">
<div class="configmenu" v-show="viewStatus == 'train'">
<el-button-group>
<!-- <el-button type="primary" @click="raystand">站台选择</el-button>
<el-button type="primary" @click="raytrain">列车选择</el-button> -->
<el-button type="primary" @click="railmove">{{ $t('jlmap3d.cameraRailMove') }}</el-button>
<!-- <el-button type="primary" @click="raysection">{{$t('jlmap3d.trackCheck')}}</el-button>
<el-button type="primary" @click="rayswitch">{{$t('jlmap3d.turnoutCheck')}}</el-button>
<el-button type="primary" @click="raysignal">{{$t('jlmap3d.signalCheck')}}</el-button> -->
<!-- <el-button type="primary" @click="sandboxtest">沙盘测试</el-button> -->
<el-button type="primary" @click="back">{{ $t('global.exit') }}</el-button>
<el-button type="primary" @click="backTrainView" >退出列车视角</el-button>
</el-button-group>
</div>
<Jlmap3d-Menu :trainlist="trainlist" :stationlist="stationlist" @sstation="sstation" @strain="strain" />
<div class="configmenu" v-show="viewStatus == 'fps'">
<el-button-group>
<el-button type="primary" @click="backFpsView" >退出漫游</el-button>
</el-button-group>
</div>
<Jlmap3d-Config @showstationmsg="showstationmsg" @showtrainmsg="showtrainmsg" @changeweather="changeweather"/>
<div class="display-draft" v-show="viewStatus == 'free'">
<el-button-group>
<el-button v-show=" project == 'say'" type="primary" @click="enterStopStation" >进入停车场</el-button>
<el-button type="primary" @click="railmove">{{ $t('jlmap3d.cameraRailMove') }}</el-button>
<el-button type="primary" @click="back">{{ $t('global.exit') }}</el-button>
</el-button-group>
</div>
<Jlmap3d-Menu v-show="viewStatus == 'free'" :trainlist="trainlist" :stationlist="stationlist" @sstation="sstation" @strain="strain" />
<Jlmap3d-Config v-show="viewStatus == 'free'" @showstationmsg="showstationmsg" @showtrainmsg="showtrainmsg" @changeweather="changeweather"/>
<!-- <Jlmap3d-Msg v-bind:msgdata="msgdata" >
</Jlmap3d-Msg > -->
@ -62,29 +69,31 @@ export default {
},
data() {
return {
trainlist: null,
stationlist: null,
msgdata: null,
project:'',
viewStatus:'free',
trainlist: null,
stationlist: null,
msgdata: null,
training: {
id: '',
name: '',
remarks: ''
},
training: {
id: '',
name: '',
remarks: ''
},
mapdata: null,
jlmap3d: null,
selectmodel: null,
mapid:null,
group:null,
token:null,
loadingProjectList: ['login', 'design', 'xty', 'designxty', 'gzb', 'designxty', 'xadt', 'designxadt', 'drts', 'designdrts', 'hlsdrts', 'designhlsdrts']
mapdata: null,
jlmap3d: null,
selectmodel: null,
mapid:null,
group:null,
token:null,
loadingProjectList: ['login', 'design', 'xty', 'designxty', 'gzb', 'designxty', 'xadt', 'designxadt', 'drts', 'designdrts', 'hlsdrts', 'designhlsdrts']
};
},
watch: {
'$store.state.socket.simulationOver':function(val) {
this.back();
}
},
},
beforeDestroy() {
// console.log("destroy");
@ -105,6 +114,7 @@ export default {
},
mounted() {
window.updatemenulist = this.updatemenulist;
window.jl3dSimulationGlobeFunction = this.jl3dSimulationGlobeFunction;
this.getParams();
// console.log("");
@ -121,41 +131,23 @@ export default {
if (this.jlmap3d == null) {
this.init(skinCode, group);
} else {
// this.jlmap3d.restart();
this.jlmap3d.eventon();
this.jlmap3d.animateon();
}
},
init: function (skinCode, group) {
const mapdata = this.$store.getters['map/map'];
const dom = document.getElementById('app');
const project = this.$route.query.project;
this.project = this.$route.query.project;
// console.log(project);
if (project) {
if (this.project) {
this.jlmap3d = new JLmap3d(dom, mapdata, skinCode, this.$store, group, project);
this.jlmap3d = new JLmap3d(dom, mapdata, skinCode, this.$store, group, this.project);
} else {
this.jlmap3d = new JLmap3d(dom, mapdata, skinCode, this.$store, group, '');
}
this.jlmap3d.eventon();
},
raystand() {
this.jlmap3d.rayswitch('stand');
},
raytrain() {
this.jlmap3d.rayswitch('train');
},
raysection() {
this.jlmap3d.rayswitch('section');
},
raysignal() {
this.jlmap3d.rayswitch('signal');
},
rayswitch() {
this.jlmap3d.rayswitch('switch');
},
railmove() {
this.jlmap3d.camerarailmove();
@ -187,12 +179,28 @@ export default {
this.jlmap3d.updatecamera(changedata.mesh, 'station');
},
strain(changedata) {
if (changedata.dispose == false) {
this.jlmap3d.updatecamera(changedata, 'train');
this.viewStatus = 'train';
}
},
backFpsView(){
this.viewStatus = 'free';
this.jlmap3d.backFpsView();
},
backTrainView(){
this.viewStatus = 'free';
this.jlmap3d.backTrainView();
},
jl3dSimulationGlobeFunction(type,data){
if(type == 'changeview'){
this.viewStatus = data;
}
},
enterStopStation(){
this.jlmap3d.enterStopStation();
},
sandboxtest(){
const routeData = this.$router.resolve({
path:'/jlmap3d/jl3dsandboxtest',
@ -205,7 +213,7 @@ export default {
lineCode:this.lineCode
}
});
window.open(routeData.href, '_blank');
window.open(routeData.href, '_blank');
// window.open(routeData.href, '_blank');
},
back() {
@ -219,7 +227,6 @@ export default {
window.close();
}
// this.$emit('showpanel');
// this.jlmap3d.eventoff();
// this.jlmap3d.animateoff();
// this.jlmap3d = null;
}
@ -262,6 +269,14 @@ export default {
color: #fff;
}
.configmenu {
/* z-index: 1000; */
position: absolute;
float: right;
right: 40px;
top: 28px;
}
.display-draft {
/* z-index: 1000; */
position: absolute;