代码移植

This commit is contained in:
ival 2019-07-26 13:32:43 +08:00
parent 75be303baf
commit 9f5130a4f2
389 changed files with 76296 additions and 329 deletions

18
index.html Normal file
View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title></title>
<script src="/static/inflate.min.js"></script>
</head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

241
src/api/chat.js Normal file
View File

@ -0,0 +1,241 @@
import request from '@/utils/request';
export function postDataBd(data) {
return request({
url: `/api/audio/bd?group=${data.group}&conversationId=${data.conversationId}`,
method: 'post',
data: data.file,
});
}
// 创建/获取会话id
export function getConversation(data) {
return request({
url: `/api/audio/conversation`,
method: 'get',
params: {
group: data.group,
userId: data.userId,
code: data.code
}
});
}
export function postDataXf(data) {
return request({
url: `/api/audio/xf`,
method: 'post',
data: data
});
}
// 获取语音历史记录
export function getHistoryVoice(code) {
return request({
url: `/api/audio/${code}/history`,
method: 'get'
});
}
// 文字聊天 发送文字
export function chatWithText(data, group) {
return request({
url: `/api/jointTraining/chatWithText?group=${group}`,
method: 'post',
data: {
message: data,
}
});
}
// 文字聊天 发送文字
export function chatWithAudio(file, group) {
return request({
url: `/api/jointTraining/chatWithAudio?group=${group}`,
method: 'post',
data: file
});
}
// 文字聊天 发送文字
export function getJoinTrainCode(data, group) {
return request({
url: `/api/jointTraining/qrCode?group=${group}`,
method: 'post',
data: data
});
}
// 创建房间
export function postCreateRoom(data) {
return request({
url: `/api/jointTraining/room`,
method: 'post',
data: data
});
}
// 检查房间存在
export function checkRoomExist(params) {
return request({
url: `/api/simulationRoom`,
method: 'get',
params
});
}
// 获取房间详情
export function postRoomDetail(group) {
return request({
url: `/api/jointTraining/room/${group}`,
method: 'get',
});
}
// 销毁房间
export function deljointTrainRoom(group) {
return request({
url: `/api/jointTraining/room`,
method: 'delete',
params: {
group: group,
}
});
}
// 查询有权限房间列表
export function getjointTrainList() {
return request({
url: `/api/jointTraining/room/list`,
method: 'get'
});
}
// 加入房间
export function getjointTraining(group) {
return request({
url: `/api/jointTraining/room/join`,
method: 'put',
params: {
group: group,
}
});
}
// 设置人员角色
export function putUserRoles(data, group) {
return request({
url: `/api/jointTraining/room/user/role?group=${group}`,
method: 'put',
data: data
});
}
// 设置人员角色
export function getJointTrainRoomUserList(group) {
return request({
url: `/api/jointTraining/room/${group}/user/list`,
method: 'get',
});
}
// 离开房间接口
export function putJointTrainingExit(group) {
return request({
url: `/api/jointTraining/room/exit`,
method: 'put',
params: {
group: group,
}
});
}
// 开始联合演练
export function startJointTraining(group) {
return request({
url: `/api/jointTraining/room/simulation`,
method: 'post',
params: {
group: group
}
});
}
// 获取个人信息
export function getUserRoles(group) {
return request({
url: `/api/jointTraining/room/user/role`,
method: 'get',
params: {
group: group
}
});
}
// 返回房间
export function putJointTrainingState() {
return request({
url: `/api/jointTraining/room/back`,
method: 'put',
});
}
// 踢出用户
export function putJointTrainingUserkicked(userId, group) {
return request({
url: `/api/jointTraining/room/user`,
method: 'put',
params: {
userId: userId,
group: group,
}
});
}
// 管理员结束所有人的仿真
export function putJointTrainingSimulation(group) {
return request({
url: `/api/jointTraining/room/simulation/all`,
method: 'put',
params: {
group: group,
}
});
}
// 结束仿真返回房间
export function putJointTrainingSimulationUser(group) {
return request({
url: `/api/jointTraining/room/simulation/user/exit`,
method: 'put',
params: {
group: group,
}
});
}
// 进入仿真
export function putJointTrainingSimulationEntrance(group) {
return request({
url: `/api/jointTraining/room/simulation/user/entrance`,
method: 'put',
params: {
group: group,
}
});
}
/**
* 权限获取(房间权限)
*/
export function getPermissionJoint(group) {
return request({
url: '/api/jointTraining/qrCode',
method: 'get',
params: {
group: group
}
});
}

View File

@ -0,0 +1,77 @@
import request from '@/utils/request';
/** 获取地图版本信息*/
export function getPublishMapVersion(skinStyle) {
return request({
url: `/api/map/${skinStyle}/version`,
method: 'get'
});
}
/** 获取发布地图详细内容*/
export function getPublishMapDetail(skinStyle) {
let datad = request({
url: `/api/map/${skinStyle}/details`,
method: 'get'
});
return datad.then();
}
/** 根据地图id获取地图信息*/
export function getPublishMapInfo(mapId) {
return request({
url: `/api/map/${mapId}`,
method: 'get'
});
}
/** 获取草稿地图详细内容*/
export function getMapDetail(id) {
return request({
url: `/api/mapBuild/${id}/mapDataDetail`,
method: 'get'
});
}
/** 创建地图3d数据*/
export function set3dMapData(data) {
return request({
url: `/api/mapBuild/3dMapData`,
method: 'post',
data: data
});
}
/**通过地图id获取地图3d数据*/
export function get3dMapData(mapId) {
return request({
url: `/api/mapBuild/3dMapData/${mapId}`,
method: 'get'
});
}
/** 更新地图3d数据*/
export function update3dMapData(data) {
return request({
url: `/api/mapBuild/3dMapData/${data.id}`,
method: 'put',
data: data
});
}
/** 获取模型资源列表*/
export function loadmap3dModel() {
return request({
url: `/api/map3dModel/all`,
method: 'get'
});
}
export function getPublish3dMapDetail(skinStyle) {
let datad = request({
url: `/api/map/${skinStyle}/3dMapData`,
method: 'get'
});
return datad.then();
}

View File

@ -2,67 +2,67 @@ import request from '@/utils/request';
/** 获取发布的课程列表*/
export function getPublishLessonList() {
return request({
url: '/api/lesson',
method: 'get'
});
return request({
url: '/api/lesson',
method: 'get'
});
}
/** 获取发布列表树*/
export function getPublishLessonTree(params) {
return request({
url: '/api/lesson/tree',
method: 'get',
params: params || {}
});
return request({
url: '/api/lesson/tree',
method: 'get',
params: params || {}
});
}
/** 获取发布课程列表*/
export function getPublishLessonDetail(data) {
return request({
url: `/api/lesson/${data.id}`,
method: 'get'
});
return request({
url: `/api/lesson/${data.id}`,
method: 'get'
});
}
/** 发布课程分页列表列表*/
export function publishLessonList(param) {
return request({
url: `/api/lesson/publishedLesson`,
method: 'get',
params: param
});
return request({
url: `/api/lesson/publishedLesson`,
method: 'get',
params: param
});
}
/** 删除发布课程*/
export function delPublishLesson(lessonId) {
return request({
url: `/api/lesson/publishedLesson/${lessonId}`,
method: 'delete'
});
return request({
url: `/api/lesson/publishedLesson/${lessonId}`,
method: 'delete'
});
}
/** 发布课程上架*/
/**发布课程上架*/
export function putLessonOnLine(id) {
return request({
url: `/api/lesson/${id}/onLine`,
method: 'put'
});
return request({
url: `/api/lesson/${id}/onLine`,
method: 'put',
});
}
/** 发布课程下架*/
/**发布课程下架*/
export function putLessonOffLine(id) {
return request({
url: `/api/lesson/${id}/offLine`,
method: 'put'
});
return request({
url: `/api/lesson/${id}/offLine`,
method: 'put',
});
}
/**
* 获取地图产品下的课程列表
*/
export function getCommodityProductLesson(prdCode) {
return request({
url: `/api/lesson/${prdCode}/list`,
method: 'get'
});
}
return request({
url: `/api/lesson/${prdCode}/list`,
method: 'get',
});
}

View File

@ -1,77 +1,68 @@
import request from '@/utils/request';
// 修改密码
export function changePassword(userId, data) {
return request({
url: `/api/login/${userId}/password`,
method: 'put',
data: data
});
}
// 账号密码 其他系统
export function login(params) {
return request({
url: '/api/login',
method: 'post',
data: params
});
return request({
url: '/api/login',
method: 'post',
data: params
});
}
// 获取登陆url 二维码 其他系统
export function getLoginUrl(params) {
return request({
url: '/api/login/url',
method: 'get',
params: params
});
return request({
url: '/api/login/url',
method: 'get',
params: params
});
}
// 获取登录信息
export function getInfo(token) {
return request({
url: '/api/login/getUserInfo',
method: 'get',
params: { token }
});
return request({
url: '/api/login/getUserInfo',
method: 'get',
params: { token }
});
}
// 登出
export function logout(token) {
return request({
url: '/api/login/logout',
method: 'get',
params: {
token
}
});
return request({
url: '/api/login/logout',
method: 'get',
params: {
token
}
});
}
// 检查登陆状态
export function checkLoginStatus(sessionId) {
return new Promise((resolve, reject) => {
request({
url: '/api/login/checkStatus',
method: 'get',
params: {
sessionId: sessionId
}
}).then(response => {
if (response.data.status === '2') {
resolve(response);
} else {
reject(response);
}
}).catch(error => {
reject(error);
});
});
return new Promise((resolve, reject) => {
request({
url: '/api/login/checkStatus',
method: 'get',
params: {
sessionId: sessionId
}
}).then(response => {
if (response.data.status === '2') {
resolve(response);
} else {
reject(response);
}
}).catch(error => {
reject(error);
});
});
}
// 检测持续在线 防止掉线在大屏或者仿真系统下
export function checkLoginLine() {
return request({
url: '/api/cache/heartBeat',
method: 'get'
});
return request({
url: '/api/cache/heartBeat',
method: 'get',
});
}

View File

@ -2,68 +2,68 @@ import request from '@/utils/request';
/** 分页查询皮肤*/
export function getSkinStylePageList(params) {
return request({
url: `/api/mapSkin`,
method: 'get',
params: params
});
return request({
url: `/api/mapSkin`,
method: 'get',
params: params
});
}
/** 添加皮肤*/
export function addSkinStyle(data) {
return request({
url: `/api/mapSkin`,
method: 'post',
data: data
});
return request({
url: `/api/mapSkin`,
method: 'post',
data: data
});
}
/** 删除皮肤*/
export function delSkinStyle(id) {
return request({
url: `/api/mapSkin/${id}`,
method: 'delete'
});
return request({
url: `/api/mapSkin/${id}`,
method: 'delete'
});
}
/** 查询地图皮肤 */
export function querySkinStyle(id) {
return request({
url: `/api/mapSkin/${id}`,
method: 'get'
});
return request({
url: `/api/mapSkin/${id}`,
method: 'get'
});
}
/** 修改地图皮肤*/
export function updateSkinStyle(data) {
return request({
url: `/api/mapSkin/${data.id}`,
method: 'put',
data: data
});
return request({
url: `/api/mapSkin/${data.id}`,
method: 'put',
data: data
});
}
/** 通过皮肤Code更新地图皮肤*/
export function updateSkinStyleByCode(data) {
return request({
url: `/api/mapSkin/${data.code}/update`,
method: 'put',
data: data
});
return request({
url: `/api/mapSkin/${data.code}/update`,
method: 'put',
data: data
});
}
/** 查询皮肤是否存在*/
export function querySkinStyleExistByCode(code) {
return request({
url: `/api/mapSkin/${code}/exist`,
method: 'get'
});
return request({
url: `/api/mapSkin/${code}/exist`,
method: 'get'
});
}
/** 获取皮肤列表*/
export function getSkinStyleList() {
return request({
url: `/api/mapSkin/list`,
method: 'get'
});
return request({
url: `/api/mapSkin/list`,
method: 'get'
});
}

40
src/api/quest.js Normal file
View File

@ -0,0 +1,40 @@
import request from '@/utils/request';
/** 分页查找仿真任务*/
export function getQuestPageList(params) {
return request({
url: `/api/quest/paging`,
method: 'get',
params: params
});
}
/** 创建任务 */
export function createQuest(data) {
return request({
url: `/api/quest`,
method: 'post',
data
});
}
/** 根据任务id删除任务 */
export function deleteQuest(id) {
return request({
url: `/api/quest/${id}`,
method: 'delete'
});
}
/** 根据id查询任务基础信息 */
export function getQuestById(id) {
return request({
url: `/api/quest/${id}`,
method: 'get',
});
}
/** 更新任务基本信息 */
export function updateQuest(id, data) {
return request({
url: `/api/quest/${id}`,
method: 'put',
data
});
}

379
src/api/runplan.js Normal file
View File

@ -0,0 +1,379 @@
import request from '@/utils/request';
/**
* 获取运行图列表
*/
export function getRunPlanList() {
return request({
url: '/api/rp/tree',
method: 'get'
});
}
/**
* 获取地图速度等级列表
*/
export function getSpeedLevels(skinStyle) {
return request({
url: `/api/rp/${skinStyle}/speed`,
method: 'get',
});
}
/**
* 新建地图速度等级列表
*/
export function newSpeedLevels(data) {
return request({
url: '/api/rp/speed',
method: 'post',
data: data
});
}
/**
* 获取运行图的车站列表
*/
export function getStationList(mapId) {
return request({
url: `/api/rp/station/${mapId}`,
method: 'get',
});
}
/**
* 通过皮肤获取运行图车站列表
*/
export function getStationListBySkinStyle(skinStyle) {
return request({
url: `/api/rp/station/${skinStyle}/bySkin`,
method: 'get',
});
}
/**
* 创建运行图
*/
export function newRunPlan(data) {
return request({
url: '/api/rp',
method: 'post',
data: data
});
}
/**
* 查询运行图获取数据
*/
export function queryRunPlan(planId) {
return request({
url: `/api/rp/${planId}`,
method: 'get'
});
}
/**
* 删除运行图
*/
export function deleteRunPlan(planId) {
return request({
url: `/api/rp/${planId}`,
method: 'delete'
});
}
/**
* 发布运行图
*/
export function publishRunPlan(data) {
return request({
url: `/api/rp/${data.planId}/publish`,
method: 'post',
data: data
});
}
/**
* 导入真实运行图
*/
export function importRunPlan(data) {
return request({
url: `/api/rp/${data.skinStyle}/prdPlan`,
method: 'post',
data: data.runPlanList
});
}
/** 获取运行图停车点列表*/
export function getRunPlanStopPointList(skinStyle) {
return request({
url: `/api/rp/stopPoint/${skinStyle}`,
method: 'get',
});
}
/** 运行图*/
export function getRpListByMapId(mapId) {
return request({
url: `/api/rp/${mapId}/list`,
method: 'get'
});
}
/** 获取站间运行时间*/
export function getStationRunning(skinStyle) {
return request({
url: `/api/rp/${skinStyle}/stationRunning`,
method: 'get'
});
}
/** 设置站间运行时间*/
export function setStationRunning(skinStyle, data) {
return request({
url: `/api/rp/${skinStyle}/stationRunning`,
method: 'put',
data: data
});
}
/** 创建运行图*/
export function createEmptyPlan(data) {
return request({
url: `/api/rp`,
method: 'post',
data: data
});
}
/** 查询运行图服务号是否存在*/
export function checkServiceNumberExist({ planId, serviceNumber }) {
return request({
url: `/api/rp/${planId}/${serviceNumber}/service`,
method: 'get'
});
}
/** 查询交路列表*/
export function getRoutingList(planId) {
return request({
url: `/api/rp/${planId}/routingList`,
method: 'get'
});
}
/** 根据交路查询交路区段列表*/
export function querySectionListByRouting({ planId, routingCode }) {
return request({
url: `/api/rp/${planId}/${routingCode}/routingSectionList`,
method: 'get'
});
}
/** 有效性检查*/
export function planEffectiveCheck(planId) {
return request({
url: `/api/rp/${planId}/check`,
method: 'get'
});
}
/** 增加计划*/
export function addPlanService(data) {
return request({
url: `/api/rp/${data.planId}/service`,
method: 'post',
data: data,
});
}
/** 删除计划*/
export function deletePlanService(data) {
return request({
url: `/api/rp/${data.planId}/service/${data.serviceNumber}`,
method: 'delete'
});
}
/** 复制计划*/
export function duplicateService(data) {
return request({
url: `/api/rp/${data.planId}/service/${data.serviceNumber}`,
method: 'post',
data: data
});
}
/** 修改计划*/
// export function updatePlanService(data) {
// return request({
// url: `/api/rp/${data.planId}/service/${data.serviceNumber}`,
// method: 'put',
// data: data
// })
// }
/** 增加任务*/
export function addPlanTrip(data) {
return request({
url: `/api/rp/${data.planId}/${data.serviceNumber}/trip`,
method: 'post',
data: data,
});
}
/** 删除任务*/
export function deletePlanTrip(params) {
return request({
url: `/api/rp/${params.planId}/trip/${params.SDTNumber}`,
method: 'delete',
params: { deleteBefore: params.deleteBefore }
});
}
/** 修改任务*/
export function updatePlanTrip(data) {
return request({
url: `/api/rp/${data.planId}/trip/${data.SDTNumber}`,
method: 'put',
data: data
});
}
/** 根据车次号查询交路*/
export function getRoutingBySDTNumber(params) {
return request({
url: `/api/rp/${params.planId}/routing`,
method: 'get',
params: {
SDTNumber: params.SDTNumber
}
});
}
/** 运行图仿真测试*/
export function runPlanNotify({ planId }) {
return request({
url: `/api/rp/${planId}/simulation`,
method: 'get',
});
}
/** 获取运行计划模板列表*/
export function runPlanTemplateList(params) {
return request({
url: '/api/runPlan/template',
method: 'get',
params: params
});
}
/** 删除运行图模板*/
export function deleteRunPlanTemplate(planId) {
return request({
url: `/api/runPlan/template/${planId}`,
method: 'delete'
});
}
/** 生成通用每日运行图*/
export function generateCommonRunPlanEveryDay(planId) {
return request({
url: `/api/runPlan/template/generate/${planId}`,
method: 'post'
});
}
/** 生成用户每日运行图*/
export function generateUserRunPlanEveryDay(planId, group) {
return request({
url: `/api/runPlan/daily/privilege/${planId}?group=${group}`,
method: 'post'
});
}
/** 获取运行计划每日列表*/
export function runPlanEveryDayList(params) {
return request({
url: '/api/runPlan/daily',
method: 'get',
params: params
});
}
/** 删除运行图每日计划*/
export function deleteRunPlanEveryDay(planId) {
return request({
url: `/api/runPlan/daily/${planId}`,
method: 'delete'
});
}
/** 获取地图运行图的车次号*/
export function getPublishMapTrainNos(skinStyle) {
return request({
url: `/api/runPlan/daily/${skinStyle}/trainNos`,
method: 'get'
});
}
/** 获取服务号、车组号*/
export function getPublishMapTrainServerNos(skinStyle) {
return request({
url: `/api/runPlan/daily/${skinStyle}/serverNos`,
method: 'get'
});
}
/** 分页查询加载计划*/
export function getRunPlanLoadList(params) {
return request({
url: `/api/runPlan/daily/runPlanLoad`,
method: 'get',
params: params
});
}
/** 创建加载计划*/
export function createRunPlanLoad(data) {
return request({
url: `/api/runPlan/daily/runPlanLoad`,
method: 'post',
data: data
});
}
/** 管理创建通用加载计划*/
export function createRunPlanCommon(data) {
return request({
url: `/api/runPlan/daily/runPlanLoad/common`,
method: 'post',
data: data
});
}
/** 删除加载计划*/
export function deleteRunPlanLoad(planId) {
return request({
url: `/api/runPlan/daily/runPlanLoad/${planId}`,
method: 'delete'
});
}
/** 查询模板运行图数据*/
export function queryRunPlanTemplate(planId) {
return request({
url: `/api/runPlan/template/${planId}`,
method: 'get'
})
}
/** 查询当日运行图数据*/
export function queryRunPlanDaily(planId) {
return request({
url: `/api/runPlan/daily/${planId}`,
method: 'get'
})
}

370
src/api/simulation.js Normal file
View File

@ -0,0 +1,370 @@
import request from '@/utils/request';
/** 获取故障规则列表*/
export function getFailureGenerateRules(params) {
return request({
url: `/api/simulation/failureGenerateRules`,
method: 'get',
params: params
});
}
/** 设置自动故障*/
export function setFailureMode(data, group) {
return request({
url: `/api/simulation/${group}/failureMode`,
method: 'post',
data: data,
});
}
/**
* 仿真系统按计划行车
*/
export function runDiagramStart(params, group) {
return request({
url: `/api/simulation/${group}/start`,
method: 'put',
params: params
});
}
/**
* 仿真系统结束计划行车
*/
export function runDiagramOver(group) {
return request({
url: `/api/simulation/${group}/over`,
method: 'put',
});
}
/**
* 退出仿真系统
*/
export function runDiagramQuit(group) {
return request({
url: `/api/simulation/${group}/quit`,
method: 'put',
});
}
/** 获取仿真系统时间*/
export function runDiagramGetTime(group) {
return request({
url: `/api/simulation/${group}/systemTime`,
method: 'get'
});
}
// 查看是否开始按计划行车
export function runDiagramIsStart(group) {
return request({
url: `/api/simulation/${group}/isRunPlanStart`,
method: 'get'
});
}
/**
* 仿真系统CBTC
* @param {*} mapId
*/
export function simulationNotify({ mapId, code }) {
return request({
url: `/api/simulation/${mapId}/${code}`,
method: 'get'
});
}
/**
* 大屏系统CBTC
* @param {*} mapId
*/
export function bitScreenNotify({ mapId }) {
return request({
url: `/api/simulation/bigScreen/${mapId}`,
method: 'get'
});
}
/**
* 实训系统CBTC
* @param {*} data
*/
export function trainingNotify({ trainingId }) {
return request({
url: `/api/simulation/training/${trainingId}`,
method: 'get'
});
}
/**
* 考试系统CBTC
* @param {*} data
*/
export function examNotify({ examId }) {
return request({
url: `/api/simulation/exam/${examId}`,
method: 'get'
});
}
/**获取用户实训列表*/
export function getSimulationList(data) {
return request({
url: `/api/simulation/stats`,
method: 'get',
params: data
});
}
/**添加用户仿真数据*/
export function postSimulationStats(data) {
return request({
url: `/api/simulation/stats`,
method: 'post',
data: data
});
}
/**更新用户仿真数据*/
export function putSimulationStats(data) {
return request({
url: `/api/simulation/${data.id}/stats`,
method: 'put',
data: data
});
}
/**删除用户仿真数据*/
export function deleteSimulationStats(statsId) {
return request({
url: `/api/simulation/${statsId}`,
method: 'delete',
});
}
/** 获取用户鼠标左键选中的设备信息*/
export function letfMouseSelectDevice(deviceCode, group) {
return request({
url: `/api/simulation/${group}/device/${deviceCode}`,
method: 'get',
});
}
/** 获取每日运行图*/
export function getEveryDayRunPlanData(group) {
return request({
url: `/api/simulation/${group}/runPlan`,
method: 'get',
});
}
/** 生成手机同步仿真二维码*/
// export function getSimulationQrCodeUrl(group) {
// return request({
// url: `/api/simulation/${group}/qrCode`,
// method: 'post'
// });
// }
/** 录制脚本仿真*/
export function scriptRecordNotify(questId) {
return request({
url: `/api/simulation/questRecord/${questId}`,
method: 'get'
})
}
/** 保存剧本背景*/
export function saveScriptScenes(group) {
return request({
url: `/api/simulation/${group}/questRecord/scenes`,
method: 'post'
})
}
/** 保存录制任务数据*/
export function saveScriptData(group) {
return request({
url: `/api/simulation/${group}/questRecord`,
method: 'post',
});
}
/** 清除仿真剧本数据*/
export function dumpScriptData(scriptId) {
return request({
url: `/api/simulation/${scriptId}/clearScriptRecord`,
method: 'post'
});
}
/** 查询录制剧本步骤*/
export function queryScriptStep(group) {
return request({
url: `/api/simulation/${group}/scriptRecordStage`,
method: 'get'
});
}
/** 获取指定时间里可加载列车的个数*/
export function getDesignatedTimeTrainNum(params, group) {
return request({
url: `/api/simulation/${group}/plan/trainNum`,
method: 'get',
params
})
}
/** 根据成员角色查询设备列表*/
export function getDevicesByRole(group, params) {
return request({
url: `/api/simulation/${group}/role/devices`,
method: 'get',
params
})
}
/** 获取任务录制的成员角色列表 */
export function getMembersByGroup(group) {
return request({
url: `/api/simulation/${group}/questRecord/members`,
method: 'get',
})
}
/** 添加任务角色成员 */
export function postQuestMember(group, data) {
return request({
url: `/api/simulation/${group}/questRecord/member`,
method: 'post',
data
})
}
/** 删除任务角色成员 */
export function deleteQuestMember(group, memberId) {
return request({
url: `/api/simulation/${group}/questRecord/member/${memberId}`,
method: 'delete',
})
}
// /** 添加/修改任务角色行为 */
export function postMemberBehavior(group, memberId, data) {
return request({
url: `/api/simulation/${group}/questRecord/${memberId}/behavior`,
method: 'post',
data
})
}
/** 删除任务角色行为 */
export function deleteMemberBehavior(group, memberId, behaviorId) {
return request({
url: `/api/simulation/${group}/questRecord/${memberId}/behavior/${behaviorId}`,
method: 'delete'
})
}
/** 删除任务角色行为动作 */
export function deleteMemberBehaviorAction(group, memberId, behaviorId, actionId) {
return request({
url: `/api/simulation/${group}/questRecord/${memberId}/behavior/${behaviorId}/action/${actionId}`,
method: 'delete'
})
}
/** 添加/修改任务角色行为动作 */
export function postMemberBehaviorAction(group, memberId, behaviorId, data) {
return request({
url: `/api/simulation/${group}/questRecord/${memberId}/behavior/${behaviorId}/action`,
method: 'post',
data
})
}
/** 添加/修改任务目标条件*/
export function postTargetConditionAction(group, data) {
return request({
url: `/api/simulation/${group}/questRecord/targetCondition`,
method: 'post',
data
})
}
/** 删除任务目标条件*/
export function deleteTargetConditionAction(group, tcId) {
return request({
url: `/api/simulation/${group}/questRecord/targetCondition/${tcId}`,
method: 'delete'
})
}
/** 分页查询存在的仿真 */
export function getExistingSimulation(params) {
return request({
url: `/api/simulation/manage/page`,
method: 'get',
params,
});
}
/** 删除存在的仿真 */
export function deleteExistingSimulation(group) {
return request({
url: `/api/simulation/manage/${group}`,
method: 'delete',
});
}
/** 根据设备类型获取设备列表 */
export function getDeviceCodeByDeviceType(group, params) {
return request({
url: `/api/simulation/${group}/deviceType/devices`,
method: 'get',
params
});
}
/** 根据设备类型获取设备条件列表 */
export function getDeviceCoditionByDeviceType(params) {
return request({
url: `/api/simulation/deviceType/conditions`,
method: 'get',
params
});
}
/** 获取任务录制的数据*/
export function getQuestRecord(group) {
return request({
url: `/api/simulation/${group}/questRecord`,
method: 'get',
});
}
/** 加载任务*/
export function loadQuest(questId, group) {
return request({
url: `/api/simulation/${group}/quest/${questId}`,
method: 'post',
});
}
/** 退出任务*/
export function quitQuest(group) {
return request({
url: `/api/simulation/${group}/quest`,
method: 'put'
})
}
/** 根据group获取仿真对象*/
export function getSimulationInfo(group) {
return request({
url: `/api/simulation/${group}`,
method: 'get'
})
}

View File

@ -0,0 +1,67 @@
import request from '@/utils/request';
/** 分页查询仿真记录*/
export function getSimulationRelpayList(params) {
return request({
url: `/api/simulationRecord`,
method: 'get',
params: params
});
}
// 删除回放
export function delSimulationRecord(replayId) {
return request({
url: `/api/simulationRecord/${replayId}`,
method: 'delete',
});
}
/** 回放*/
export function simulationRelpay(replayId) {
return request({
url: `/api/simulationRecord/${replayId}/playBack`,
method: 'get'
});
}
// 结束回放
export function putsSimulationRecord(replayId) {
return request({
url: `/api/simulationRecord/${replayId}/over`,
method: 'put',
});
}
// 暂停回放
export function putsSimulationRecordPause(replayId) {
return request({
url: `/api/simulationRecord/${replayId}/pause`,
method: 'put',
});
}
// 播放回放
export function putsSimulationRecordPlay(replayId) {
return request({
url: `/api/simulationRecord/${replayId}/play`,
method: 'put',
});
}
// 设置速度回放
export function putsSimulationRecordPlaySpeed(replayId, speed) {
return request({
url: `/api/simulationRecord/${replayId}/playSpeed?playSpeed=${speed}`,
method: 'put',
});
}
// 播放
export function putsSimulationRecordplayTime(replayId, offsetSeconds) {
return request({
url: `/api/simulationRecord/${replayId}/playTime?offsetSeconds=${offsetSeconds}`,
method: 'put',
});
}

9
src/api/table.js Normal file
View File

@ -0,0 +1,9 @@
import request from '@/utils/request';
export function getList(params) {
return request({
url: '/table/list',
method: 'get',
params
});
}

View File

@ -1,9 +0,0 @@
import request from '@/utils/request';
/** 获取发布地图详细内容*/
export function getPublishMapDetail(skinStyle) {
return request({
url: `/api/map/${skinStyle}/details`,
method: 'get'
});
}

View File

@ -1,99 +0,0 @@
import request from '@/utils/request';
/** 查询用户参数*/
export function getUserConfigInfo() {
return request({
url: '/api/user/config',
method: 'get'
});
}
// /** 注册用户*/
// export function createUserInfo(data) {
// return request({
// url: '/api/userinfo/create',
// method: 'put',
// data: data
// });
// }
// /** 根据用户Id获取用户信息*/
// export function getUserInfoByOpenId(params) {
// return request({
// url: '/api/userinfo/getByOpenId',
// method: 'get',
// params: params
// });
// }
// /** 根据姓名或者手机号查询用户*/
// export function getUserInfoByNameOrMobile(params) {
// return request({
// url: '/api/userinfo/nameOrMobile',
// method: 'get',
// params: params
// });
// }
// /** 设置用户参数*/
// export function setUserConfigInfo(data) {
// return request({
// url: '/api/user/config',
// method: 'post',
// data: data
// });
// }
// /** 获取销售列表*/
// export function getSellerList() {
// return request({
// url: `/api/user/seller`,
// method: 'get'
// });
// }
// /** 查询用户列表*/
// export function getUserList(params) {
// return request({
// url: `/api/user`,
// method: 'get',
// params: params
// });
// }
// /** 模糊查询用户 昵称、名称、手机号*/
// export function getDimUserList(params) {
// return request({
// url: `/api/user/fuzzy`,
// method: 'get',
// params: params
// });
// }
// /** 获取用户订阅地图列表*/
// export function getUserSubscribe(userId) {
// return request({
// url: `/api/user/subscribe/${userId}`,
// method: 'get'
// });
// }
// /** 保存用户订阅地图列表*/
// export function saveUserSubscribe(data) {
// return request({
// url: '/api/user/subscribe',
// method: 'post',
// data: data
// });
// }
// // 修改用户权限
// export function putRoles(data) {
// return request({
// url: `/api/user/${data.id}/role`,
// method: 'put',
// data: data
// });
// }

BIN
src/assets/downSection.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
src/assets/home/demon1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

BIN
src/assets/home/demon2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
src/assets/home/home1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
src/assets/home/home1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

BIN
src/assets/home/home2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
src/assets/home/home2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

BIN
src/assets/home/home3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
src/assets/home/home3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

BIN
src/assets/home/home4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

BIN
src/assets/home/plan1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

BIN
src/assets/home/plan2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
src/assets/home/plan3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
src/assets/home/tring1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 KiB

BIN
src/assets/home/tring2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 KiB

BIN
src/assets/home/tring3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

BIN
src/assets/home/tring4.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

BIN
src/assets/home/tring5.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

BIN
src/assets/home/tring6.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB

BIN
src/assets/jl3d/mmi.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
src/assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

1
src/assets/logo.svg Normal file
View File

@ -0,0 +1 @@
<svg id="图层_1" data-name="图层 1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 154 143.56"><defs><style>.cls-1,.cls-10,.cls-2,.cls-3,.cls-4,.cls-5,.cls-6,.cls-7,.cls-8,.cls-9{fill-rule:evenodd;}.cls-1{fill:url(#GradientFill_1);}.cls-2{fill:url(#GradientFill_1-2);}.cls-3{fill:url(#GradientFill_1-3);}.cls-4{fill:url(#GradientFill_1-4);}.cls-5{fill:url(#GradientFill_1-5);}.cls-6{fill:url(#GradientFill_1-6);}.cls-7{fill:url(#GradientFill_1-7);}.cls-8{fill:url(#GradientFill_1-8);}.cls-9{fill:url(#GradientFill_1-9);}.cls-10{fill:url(#GradientFill_1-10);}.cls-11{font-size:36px;fill:#231815;font-family:TRENDS;}</style><radialGradient id="GradientFill_1" cx="420.92" cy="632.65" r="114.02" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#fff"/><stop offset="0.37" stop-color="#8f82bc"/><stop offset="0.6" stop-color="#1d2088"/><stop offset="0.87" stop-color="#1d2088"/><stop offset="1" stop-color="#1d2088"/></radialGradient><radialGradient id="GradientFill_1-2" cx="420.92" cy="632.65" r="114.03" xlink:href="#GradientFill_1"/><radialGradient id="GradientFill_1-3" cx="420.92" cy="632.65" r="114.02" xlink:href="#GradientFill_1"/><radialGradient id="GradientFill_1-4" cx="420.92" cy="639.14" r="114.02" xlink:href="#GradientFill_1"/><radialGradient id="GradientFill_1-5" cx="420.92" cy="632.65" r="114.02" xlink:href="#GradientFill_1"/><radialGradient id="GradientFill_1-6" cx="420.92" cy="632.65" r="114.02" xlink:href="#GradientFill_1"/><radialGradient id="GradientFill_1-7" cx="420.92" cy="632.65" r="114.02" xlink:href="#GradientFill_1"/><radialGradient id="GradientFill_1-8" cx="420.92" cy="632.65" r="114.02" xlink:href="#GradientFill_1"/><radialGradient id="GradientFill_1-9" cx="420.92" cy="632.65" r="114.02" xlink:href="#GradientFill_1"/><radialGradient id="GradientFill_1-10" cx="420.92" cy="639.14" r="114.02" xlink:href="#GradientFill_1"/></defs><title>矢量版玖琏LOGO</title><path class="cls-1" d="M408.58,547.15l-16.5-18s-4.5,14.66-5,24L401.25,563Z" transform="translate(-343.92 -529.15)"/><path class="cls-2" d="M399.25,568.48c-12.17-13.5-37.33-22-37.33-22,2.5,67.17,51.16,72.67,51.16,72.67C392.75,596.81,399.25,568.48,399.25,568.48Z" transform="translate(-343.92 -529.15)"/><path class="cls-3" d="M402.75,620.31s-31.83-10.5-41.33-48.33l-17.5-2S357.25,617.65,402.75,620.31Z" transform="translate(-343.92 -529.15)"/><path class="cls-4" d="M364.75,610.15l-20.67,5.66c29.34,23.67,66.17,9.67,66.17,9.67C379.08,626.48,364.75,610.15,364.75,610.15Z" transform="translate(-343.92 -529.15)"/><path class="cls-5" d="M420.92,622.66l-.5.49h1Z" transform="translate(-343.92 -529.15)"/><path class="cls-6" d="M420.92,536.81h0s-17.84,19-17.84,44.17c0,22.7,14.91,38.75,17.84,41.68,2.93-2.93,17.83-19,17.83-41.68C438.75,555.81,420.92,536.81,420.92,536.81Z" transform="translate(-343.92 -529.15)"/><path class="cls-7" d="M454.75,553.15c-.5-9.34-5-24-5-24l-16.5,18L440.59,563Z" transform="translate(-343.92 -529.15)"/><path class="cls-8" d="M479.92,546.48s-25.17,8.5-37.33,22c0,0,6.5,28.33-13.84,50.67C428.75,619.15,477.42,613.65,479.92,546.48Z" transform="translate(-343.92 -529.15)"/><path class="cls-9" d="M439.09,620.31c45.5-2.66,58.83-50.33,58.83-50.33l-17.5,2C470.92,609.81,439.09,620.31,439.09,620.31Z" transform="translate(-343.92 -529.15)"/><path class="cls-10" d="M431.59,625.48s36.83,14,66.16-9.67l-20.66-5.66S462.75,626.48,431.59,625.48Z" transform="translate(-343.92 -529.15)"/><text class="cls-11" transform="translate(4.59 138.5)">玖琏科技</text></svg>

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
src/assets/logo1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

BIN
src/assets/logo_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

BIN
src/assets/upSection.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

283
src/directives.js Normal file
View File

@ -0,0 +1,283 @@
/* eslint-disable no-useless-escape */
import Vue from 'vue';
import store from '@/store';
/**
*元素获取焦点v-dialogDrag
* @param {*} el
* @param {*} binding
*/
Vue.directive('focus', {
// 当被绑定的元素插入到 DOM 中时
inserted: function (el, obj) {
// 这是需要页面刚加载就能进行聚焦操作使用的钩子函数,可以省略的,视具体需求而定
// 对值进行判断
if (obj.value) {
// 聚焦元素
el.focus();
}
},
// 当指令所在组件的 VNode 及其子 VNode 全部更新后调用
// 这是每当绑定的值发生改变时触发的钩子函数
componentUpdated: function (el, obj) {
if (obj.value) {
el.focus();
}
}
});
/**
*弹窗拖拽v-dialogDrag
* @param {*} el
* @param {*} binding
* @param {*} vnode
* @param {*} oldvNode
*/
Vue.directive('dialogDrag', {
bind(el) {
const dialogHeaderEl = el.querySelector('.el-dialog__header');
const dragDom = el.querySelector('.el-dialog');
dialogHeaderEl.style.cursor = 'move';
/** 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);*/
const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null);
dialogHeaderEl.onmousedown = (e) => {
/** 鼠标按下,计算当前元素距离可视区的距离*/
const disX = e.clientX - dialogHeaderEl.offsetLeft;
const disY = e.clientY - dialogHeaderEl.offsetTop;
/** 获取到的值带px 正则匹配替换*/
let styL, styT;
/** 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为px*/
if (sty.left.includes('%')) {
// eslint-disable-next-line no-useless-escape
styL = +document.body.clientWidth * (+sty.left.replace(/\%/g, '') / 100);
styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100);
} else {
// eslint-disable-next-line no-useless-escape
styL = +sty.left.replace(/\px/g, '');
// eslint-disable-next-line no-useless-escape
styT = +sty.top.replace(/\px/g, '');
}
document.onmousemove = function (e) {
/** 通过事件委托,计算移动的距离*/
const l = e.clientX - disX;
const t = e.clientY - disY;
/** 移动当前元素*/
dragDom.style.left = `${l + styL}px`;
dragDom.style.top = `${t + styT}px`;
/** 刷新提示标签位置*/
store.dispatch('training/emitTipFresh');
/** 将此时的位置传出去*/
// binding.value({ x: e.pageX, y: e.pageY });
};
document.onmouseup = function () {
document.onmousemove = null;
document.onmouseup = null;
};
};
}
});
/**
*弹窗宽度拖大,拖小dialogDragWidth
* @param {*} el
* @param {*} binding
* @param {*} vnode
* @param {*} oldvNode
*/
Vue.directive('dialogDragWidth', {
bind(el, binding) {
const dragDom = binding.value.$el.querySelector('.el-dialog');
el.onmousedown = (e) => {
/** 鼠标按下,计算当前元素距离可视区的距离*/
const disX = e.clientX - el.offsetLeft;
document.onmousemove = function (e) {
/** 移动时禁用默认事件*/
e.preventDefault();
/** 通过事件委托,计算移动的距离*/
const l = e.clientX - disX;
dragDom.style.width = `${l}px`;
};
document.onmouseup = function () {
document.onmousemove = null;
document.onmouseup = null;
};
};
}
});
/**
* 弹窗拖拽v-quickEntryDrag
* @param {*} el
* @param {*} binding
* @param {*} vnode
* @param {*} oldvNode
*/
Vue.directive('quickMenuDrag', {
bind(el) {
const dragDom = el;
dragDom.style.cursor = 'move';
/** 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);*/
const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null);
dragDom.onmousedown = (e) => {
/** 鼠标按下,计算当前元素距离可视区的距离*/
const disX = e.clientX;
const disY = e.clientY;
/** 获取到的值带px 正则匹配替换*/
let styL, styT;
/** 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为px*/
if (sty.left.includes('%')) {
styL = +document.body.clientWidth * (+sty.left.replace(/\%/g, '') / 100);
styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100);
} else {
styL = +sty.left.replace(/\px/g, '');
styT = +sty.top.replace(/\px/g, '');
}
document.onmousemove = function (e) {
/** 通过事件委托,计算移动的距离*/
const l = e.clientX - disX;
const t = e.clientY - disY;
/** 移动当前元素*/
dragDom.style.left = `${l + styL}px`;
dragDom.style.top = `${t + styT}px`;
/** 将此时的位置传出去*/
// binding.value({ x: e.pageX, y: e.pageY });
};
document.onmouseup = function () {
document.onmousemove = null;
document.onmouseup = null;
};
};
}
});
/**
*vue-自定义指令-拖拽 v-drag
*/
Vue.directive('drag', {
bind(el) {
const dragDom = el.querySelector('.reminder-box');
const dragRight = el.querySelector('.drag-right');
const dragLeft = el.querySelector('.drag-left');
const dragBottom = el.querySelector('.drag-bottom');
const dragTop = el.querySelector('.drag-top');
const dragBody = el.querySelector('.tip-body');
const body = el.querySelector('.tip-body-box');
dragRight.onmousedown = (e) => {
document.onselectstart = function () {
return false;
};
// 宽度拖拽
var iEvent = e || event;
var disX = iEvent.clientX;
var disW = dragDom.offsetWidth;
document.onmousemove = function (e) {
var iEvent = e || event;
if (disW + (iEvent.clientX - disX) > 350) {
dragDom.style.width = disW + (iEvent.clientX - disX) + 'px';
}
};
document.onmouseup = function () {
document.onmousemove = null;
document.onmouseup = null;
document.onselectstart = null;
};
};
dragLeft.onmousedown = (e) => {
document.onselectstart = function () {
return false;
};
// 宽度拖拽
var iEvent = e || event;
var disX = iEvent.clientX;
var disW = dragDom.offsetWidth;
var OFFLeft = dragDom.offsetLeft;
document.onmousemove = function (e) {
const iEvent = e || event;
const width = disW - (iEvent.clientX - disX);
if (width > 350) {
dragDom.style.width = disW - (iEvent.clientX - disX) + 'px';
dragDom.style.left = OFFLeft + (iEvent.clientX - disX) + 'px';
}
};
document.onmouseup = function () {
document.onmousemove = null;
document.onmouseup = null;
document.onselectstart = null;
};
};
dragBottom.onmousedown = (e) => {
document.onselectstart = function () {
return false;
};
// 宽度拖拽
var iEvent = e || event;
var disY = iEvent.clientY;
var disH = dragDom.offsetHeight;
document.onmousemove = function (e) {
var iEvent = e || event;
if (disH + (iEvent.clientY - disY) > 200) {
dragDom.style.height = disH + (iEvent.clientY - disY) + 'px';
body.style.height = disH + (iEvent.clientY - disY) - 40 + 'px';
dragBody.style.height = disH + (iEvent.clientY - disY) - 100 + 'px';
}
};
document.onmouseup = function () {
document.onmousemove = null;
document.onmouseup = null;
document.onselectstart = null;
};
};
dragTop.onmousedown = (e) => {
document.onselectstart = function () {
return false;
};
// 宽度拖拽
var iEvent = e || event;
var disY = iEvent.clientY;
var disH = dragDom.offsetHeight;
var OOFTop = dragDom.offsetTop;
document.onmousemove = function (e) {
var iEvent = e || event;
if (disH - (iEvent.clientY - disY) > 200) {
dragDom.style.height = disH - (iEvent.clientY - disY) + 'px';
body.style.height = disH - (iEvent.clientY - disY) - 40 + 'px';
dragBody.style.height = disH - (iEvent.clientY - disY) - 100 + 'px';
dragDom.style.top = OOFTop + (iEvent.clientY - disY) + 'px';
}
};
document.onmouseup = function () {
document.onmousemove = null;
document.onmouseup = null;
document.onselectstart = null;
};
};
}
});

View File

@ -0,0 +1,30 @@
export function Helper(scene){
//创建辅助网格平面
// let planeGeometry = new THREE.PlaneBufferGeometry( 40000, 40000 );
// planeGeometry.rotateX( - Math.PI / 2 );
// let planeMaterial = new THREE.ShadowMaterial( { opacity: 0.2 } );
// let plane = new THREE.Mesh( planeGeometry, planeMaterial );
// plane.position.y = 10;
// plane.receiveShadow = true;
// jlmap3dedit.meshplane = plane;
// jlmap3dedit.scene.add(plane );
// planeGeometry.dispose();
// planeMaterial.dispose();
//定义全局光
let ambientLight = new THREE.AmbientLight( 0xC5C1AA, 1.3);
scene.add( ambientLight );
let light = new THREE.HemisphereLight( 0xffffff, 0x444444 );
light.position.set( 0, 200, 0 );
scene.add( light );
// //辅助网格
// let helper = new THREE.GridHelper( 20000, 10 );
// helper.position.y = -2;
// helper.material.opacity = 0.25;
// helper.material.transparent = true;
// jlmap3dedit.scene.add( helper );
}

View File

@ -0,0 +1,36 @@
export function Materialload(jlmap3dedit){
settexture(jlmap3dedit.materiallist,"red",'../../static/material/signal/1.jpg');
settexture(jlmap3dedit.materiallist,"yellow",'../../static/material/signal/2.jpg');
settexture( jlmap3dedit.materiallist,"green",'../../static/material/signal/3.jpg');
settexture( jlmap3dedit.materiallist,"black",'../../static/material/signal/5.jpg');
//console.log(jlmap3dedit.materiallist);
}
function settexture(materiallist,name,textureurl){
var loader = new THREE.TextureLoader();
// 加载一个资源
loader.load(
// 资源URL
textureurl,
// onLoad回调
function ( texture ) {
texture.name = name;
materiallist.push(texture);
},
// 目前暂不支持onProgress的回调
undefined,
// onError回调
function ( err ) {
console.error( 'An error happened.' );
}
);
}

View File

@ -0,0 +1,7 @@
export function SetCamera(dom) {
var camera = new THREE.PerspectiveCamera(70, dom.clientWidth/dom.clientHeight, 1, 2000);
camera.position.set( 0, 0, 0 );
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
return camera;
}

View File

@ -0,0 +1,6 @@
export function SetRender(dom) {
var renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setSize(dom.clientWidth, dom.clientHeight);
renderer.setSize( window.innerWidth, window.innerHeight );
return renderer;
}

View File

@ -0,0 +1,16 @@
export function SetScene() {
var scene = new THREE.Scene();
var cubeTextureLoader = new THREE.CubeTextureLoader();
cubeTextureLoader.setPath( '../../static/skybox/city/' );
var cubeTexture = cubeTextureLoader.load( [
'px.jpg', 'nx.jpg',
'py.jpg', 'ny.jpg',
'pz.jpg', 'nz.jpg',
] );
scene.background = cubeTexture;
cubeTexture.dispose();
return scene;
}

View File

@ -0,0 +1,685 @@
import StompClient from '@/utils/sock';
import { getTrainingCbtcDemon, runDiagramStart, runDiagramOver, setTrainingCbtcInitTime } from '@/api/simulation';
import { creatSubscribe, clearSubscribe, displayTopic, screenTopic, } from '@/utils/stomp';
import { handleToken } from '@/utils/auth';
import router from '@/router';
//定于仿真socket接口
export function Jlmap3dSubscribe(jlmap3d) {
let scope = this;
this.map = null;
var trainlisttest = null;
var sectionlist = null;
var signallist = null;
var stationstandlist = null;
var sectionlist = null;
var materials = null;
var actions = null;
var scenes = null;
var code = null;
var drivingcode = null;
var drivingspeed = null;
var drivingaptspeed = null;
let driverswitch = false;
let stoptimer = null;
let num = 30;
let pointstand = null;
//run as plane = 01;
//reset = 02;
var datatype = "00";
this.teststomp = new StompClient();
this.topic = "/user/queue/simulation/jl3d";
let header = {'X-Token': handleToken() };
this.updatamap = function(mapdata,materiallist,nowaction,scene){
//console.log(mapdata);
scope.map = mapdata;
trainlisttest = this.map.trainlisttest;
sectionlist = this.map.sectionlist;
signallist = this.map.signallist;
stationstandlist = this.map.stationstandlist;
sectionlist = this.map.sectionlist;
materials = materiallist;
scenes = scene;
actions = nowaction;
}
this.socketon = function(topic){
try {
//console.log("teststomp");
scope.teststomp.subscribe(topic, callback,header);
} catch (error) {
console.error('websocket订阅失败');
}
}
this.socketoff = function(topic){
scope.teststomp.unsubscribe(topic);
for(let i=0;i<trainlisttest.group.children.length;i++){
if(trainlisttest.group.children[i].dispose == false){
code = trainlisttest.group.children[i].name;
trainlisttest.list[code].rotation.y = 0;
trainlisttest.list[code].doorStatus = "01";
trainlisttest.list[code].speed = 0;
trainlisttest.group.children[i].dispose = true;
trainlisttest.group.children[i].position.x = -50000;
trainlisttest.group.children[i].position.y = -50000;
trainlisttest.group.remove(trainlisttest.group.children[i]);
i--;
}
}
}
// 仿真socket接口回调函数
function callback(Response) {
//对象化数据
let data = JSON.parse(Response.body);
//遍历后台数据
//判断消息类型
// if(data.type == "Simulation_TrainPosition"){
//
//
// }
if(data.type == "Simulation_Driver_Change"){
drivingcode = data.body.code;
jlmap3d.updatedrivingcode( data.body.code);
}
if(data.type == "Simulation_TrainSpeed"){
if(trainlisttest){
for(let tl = 0;tl<data.body.length;tl++){
code = data.body[tl].id;
trainlisttest.list[code].speed = data.body[tl].v;
if(trainlisttest.list[code].runMode == "02"){
if(trainlisttest.list[code].isStandTrack == true){
trainlisttest.list[code].speeds = parseFloat(data.body[tl].v*10/36/17/trainlisttest.list[code].len);
}else{
trainlisttest.list[code].speeds = parseFloat(data.body[tl].v*10/36/20/trainlisttest.list[code].len);
}
}else{
trainlisttest.list[code].speeds = parseFloat(data.body[tl].v*10/36/20/trainlisttest.list[code].len);
}
if(code == drivingcode){
jlmap3d.updatenowspeed(data.body[tl].v);
if(data.body[tl].atpv){
jlmap3d.updateatpspeed(data.body[tl].atpv);
}else{
jlmap3d.updateatpspeed(-1);
}
if(data.body[tl].atov){
jlmap3d.updateatospeed(data.body[tl].atov);
}else{
jlmap3d.updateatospeed(-1);
}
}
}
}
}
if(data.type == "SJL3D_TrainStatus"){
for(let i=data.body.length-1;i>=0;i--){
if(data.body[i]._type == "Train"){
//console.log(data.body[i]);
//遍历列车对象组
if(trainlisttest){
code = data.body[i].code;
//剔除不显示的车
//找到对应列车
if( trainlisttest.list[code]){
if(code == drivingcode){
driverswitch = data.body[i].runMode;
jlmap3d.updatetrainnum(data.body[i].groupNumber);
// console.log(trainlisttest.list[code].progress);
let syncdata = {
type:"Train",
code:code,
sectionCode:data.body[i].sectionCode,
percent:0,
};
if(trainlisttest.list[code].isStandTrack == true && trainlisttest.list[code].progress>0.95 && trainlisttest.list[code].speed<=0){
if(data.body[i].directionType == "02"){
syncdata.percent = 1-(sectionlist.sections.datalist[data.body[i].sectionCode].rstop/trainlisttest.list[code].len);
}else{
syncdata.percent = sectionlist.sections.datalist[data.body[i].sectionCode].lstop/trainlisttest.list[code].len;
}
scope.teststomp.send("/app/topic/simulation/wgu3d",syncdata);
}else{
if(data.body[i].directionType == "02"){
syncdata.percent = trainlisttest.list[code].progress;
}else{
syncdata.percent = 1 - trainlisttest.list[code].progress;
}
scope.teststomp.send("/app/topic/simulation/wgu3d",syncdata);
}
if(data.body[i].parkRemainTime>0){
jlmap3d.updatestoptime("停站时间:"+parseInt(data.body[i].parkRemainTime));
}else{
if(data.body[i].runMode == "02"){
jlmap3d.updatestoptime("列车自动驾驶中");
}else{
if(trainlisttest.list[code].isStandTrack == true && trainlisttest.list[code].progress>0.95 && trainlisttest.list[code].speed<=0){
// if(stoptimer){
//
// }else{
// stoptimer = setInterval(function(){
// if(num >=0){
// jlmap3d.updatestoptime("停站时间:"+num);
// num --;
// }
// },1000);
// }
}else{
jlmap3d.updatestoptime("列车人工驾驶中");
}
}
}
// if(trainlisttest.list[code].speed > 0){
// if(stoptimer){
// clearInterval( stoptimer );
// stoptimer = null;
// num = 30;
// }
// }
}
trainlisttest.list[code].runMode = data.body[i].runMode;
//车门开关验证
// if(data.body[i].directionType == "02"){
if(trainlisttest.list[code].doorStatus != data.body[i].doorStatus && data.body[i].doorStatus == "01"){
//console.log("close");
trainlisttest.list[code].doorStatus = "01";
for(let an=actions[code].top.length-1;an>=0;an--){
actions[code].top[an].reset();
actions[code].top[an].time = actions[code].top[an]._clip.duration;
actions[code].top[an].timeScale = -1;
actions[code].top[an].play();
}
}else if(trainlisttest.list[code].doorStatus != data.body[i].doorStatus && data.body[i].doorStatus == "02"){
//console.log("open");
trainlisttest.list[code].doorStatus = "02";
for(let an=actions[code].top.length-1;an>=0;an--){
actions[code].top[an].reset();
actions[code].top[an].time = 0;
actions[code].top[an].timeScale = 1;
actions[code].top[an].play();
}
}
// }else{
// if(trainlisttest.list[code].doorStatus != data.body[i].doorStatus && data.body[i].doorStatus == "01"){
// //console.log("close");
// trainlisttest.list[code].doorStatus = "01";
// for(let an=actions[code].down.length-1;an>=0;an--){
// actions[code].down[an].reset();
// actions[code].down[an].time = actions[code].top[an]._clip.duration;
// actions[code].down[an].timeScale = -1;
// actions[code].down[an].play();
// }
// }else if(trainlisttest.list[code].doorStatus != data.body[i].doorStatus && data.body[i].doorStatus == "02"){
// //console.log("open");
// trainlisttest.list[code].doorStatus = "02";
// for(let an=actions[code].down.length-1;an>=0;an--){
// actions[code].down[an].reset();
// actions[code].down[an].time = 0;
// actions[code].down[an].timeScale = 1;
// actions[code].down[an].play();
// }
// }
// }
//遍历获取所在轨道
if(trainlisttest.list[code].dispose != data.body[i].dispose && data.body[i].dispose == false){
if(sectionlist.sections.datalist[data.body[i].sectionCode].code){
trainlisttest.group.add(trainlisttest.list[code]);
trainlisttest.list[code].position.y = 0;
trainlisttest.list[code].progress = 0;
trainlisttest.list[code].oldoffset = data.body[i].sectionOffsetPercent;
trainlisttest.list[code].dispose = false;
trainlisttest.list[code].nowcode = data.body[i].sectionCode;
trainlisttest.list[code].nextcode = data.body[i].nextSectionCode;
let vexlist = [];
let endrotation = null;
if(data.body[i].directionType == "02"){//向右
let offset = null;
let rotaposx = null;
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x>sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x){
offset = sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x-sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x;
rotaposx = sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x+offset*data.body[i].sectionOffsetPercent;
}else{
offset = sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x-sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x;
rotaposx = sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x+offset*data.body[i].sectionOffsetPercent;
}
let rotaposz = sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].z;
trainlisttest.list[code].rotation.y = 0;
trainlisttest.list[code].position.x = rotaposx;
trainlisttest.list[code].position.y = 0;
for(let tl=0;tl<6;tl++){
trainlisttest.list[code].children[tl].position.z = rotaposz;
}
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x>sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x){
vexlist.push(new THREE.Vector3(rotaposx,0,rotaposz));
for(let m=sectionlist.sections.datalist[data.body[i].sectionCode].rail.length-1;m>=0;m--){
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x>rotaposx){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}else{
vexlist.push(new THREE.Vector3(rotaposx,0,rotaposz));
for(let m=0;m<sectionlist.sections.datalist[data.body[i].sectionCode].rail.length;m++){
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x>rotaposx){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}
trainlisttest.list[code].status = "02";
}else if(data.body[i].directionType == "03"){//向左
trainlisttest.list[code].dispose = false;
trainlisttest.group.add(trainlisttest.list[code]);
let offset = null;
let rotaposx = null;
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x>sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x){
offset = sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x-sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x;
rotaposx = sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x+offset*data.body[i].sectionOffsetPercent;
}else{
offset = sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x-sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x;
rotaposx = sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x+offset*data.body[i].sectionOffsetPercent;
}
let rotaposz = sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].z;
trainlisttest.list[code].rotation.y = Math.PI;
trainlisttest.list[code].position.x = rotaposx;
trainlisttest.list[code].position.y = 0;
for(let tl=0;tl<6;tl++){
trainlisttest.list[code].children[tl].position.z = rotaposz;
}
if(data.body[i].groupNumber == "001"){
}
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x<sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x){
vexlist.push(new THREE.Vector3(rotaposx,0,rotaposz));
for(let m=sectionlist.sections.datalist[data.body[i].sectionCode].rail.length-1;m>=0;m--){
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x<rotaposx){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}else{
vexlist.push(new THREE.Vector3(rotaposx,0,rotaposz));
for(let m=0;m<sectionlist.sections.datalist[data.body[i].sectionCode].rail.length;m++){
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x<rotaposx){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}
trainlisttest.list[code].status = "03";
}
trainlisttest.list[code].curve = new THREE.CatmullRomCurve3(vexlist);
trainlisttest.list[code].isStandTrack = sectionlist.sections.datalist[data.body[i].sectionCode].isStandTrack;
trainlisttest.list[code].progress = 0;
trainlisttest.list[code].len = sectionlist.sections.datalist[data.body[i].sectionCode].distance;
trainlisttest.list[code].speed = data.body[i].speed;
trainlisttest.list[code].speeds = parseFloat(data.body[i].speed*10/36/20/trainlisttest.list[code].len);
}
}else if(trainlisttest.list[code].dispose != data.body[i].dispose && data.body[i].dispose == true){
trainlisttest.group.remove(trainlisttest.list[code]);
trainlisttest.list[code].progress = null;
trainlisttest.list[code].dispose = true;
code = trainlisttest.group.children[i].name;
trainlisttest.list[code].rotation.y = 0;
trainlisttest.list[code].doorStatus = "01";
trainlisttest.list[code].speed = 0;
trainlisttest.list[code].position.x = -50000;
trainlisttest.list[code].position.y = -50000;
}else if(trainlisttest.list[code].dispose == data.body[i].dispose && data.body[i].dispose == false){
if(sectionlist.sections.datalist[data.body[i].sectionCode].code){
if(driverswitch == "02" && code == drivingcode){
jlmap3d.updatenowspeed(data.body[i].speed);
if(data.body[i].atpSpeed){
jlmap3d.updateatpspeed(data.body[i].atpSpeed);
}else{
jlmap3d.updateatpspeed(-1);
}
if(data.body[i].targetSpeed){
jlmap3d.updateatospeed(data.body[i].targetSpeed);
}else{
jlmap3d.updateatospeed(-1);
}
if(data.body[i].maLen){
jlmap3d.updatenowlen(data.body[i].maLen);
}else{
jlmap3d.updatenowlen(0);
}
// if(trainlisttest.list[code].isStandTrack == true){
// pointstand = null;
// if(data.body[i].directionType == "02"){
// pointstand = trainlisttest.list[code].curve.getPointAt(data.body[i].sectionOffsetPercent);
// }else{
// pointstand = trainlisttest.list[code].curve.getPointAt(1-data.body[i].sectionOffsetPercent);
// }
// console.log(data.body[i].sectionOffsetPercent)
// console.log(pointstand.x);
//
// trainlisttest.list[code].position.x = pointstand.x;
// }
}
if(driverswitch == "05" && code == drivingcode){
if(data.body[i].maLen){
jlmap3d.updatenowlen(data.body[i].maLen);
}else{
jlmap3d.updatenowlen(0);
}
}
if(trainlisttest.list[code].nowcode != data.body[i].sectionCode || trainlisttest.list[code].nextcode != data.body[i].nextSectionCode){
trainlisttest.list[code].nowcode = data.body[i].sectionCode;
trainlisttest.list[code].nextcode = data.body[i].nextSectionCode;
let vexlist = [];
let endrotation = null;
if(data.body[i].directionType == "02"){//向右
if(trainlisttest.list[code].status != data.body[i].directionType){
let rotaposx = trainlisttest.list[code].children[5].matrixWorld.elements[12];
let rotaposz = trainlisttest.list[code].children[0].matrixWorld.elements[14];
trainlisttest.list[code].rotation.y = 0;
trainlisttest.list[code].position.x = rotaposx;
for(let tl=0;tl<6;tl++){
trainlisttest.list[code].children[tl].position.z = rotaposz;
}
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x>sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x){
vexlist.push(new THREE.Vector3(trainlisttest.list[code].position.x,0,trainlisttest.list[code].children[0].matrixWorld.elements[14]));
for(let m=sectionlist.sections.datalist[data.body[i].sectionCode].rail.length-1;m>=0;m--){
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x>trainlisttest.list[code].position.x){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}else{
vexlist.push(new THREE.Vector3(trainlisttest.list[code].position.x,0,trainlisttest.list[code].children[0].matrixWorld.elements[14]));
for(let m=0;m<sectionlist.sections.datalist[data.body[i].sectionCode].rail.length;m++){
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x>trainlisttest.list[code].position.x){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}
}else{
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x>sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x){
for(let m=sectionlist.sections.datalist[data.body[i].sectionCode].rail.length-1;m>=0;m--){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}else{
for(let m=0;m<sectionlist.sections.datalist[data.body[i].sectionCode].rail.length;m++){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
trainlisttest.list[code].rotation.y = 0;
}
trainlisttest.list[code].status = "02";
}else if(data.body[i].directionType == "03"){//向左
if(trainlisttest.list[code].status != data.body[i].directionType){
let rotaposx = trainlisttest.list[code].children[5].matrixWorld.elements[12];
let rotaposz = Math.abs(trainlisttest.list[code].children[0].matrixWorld.elements[14]);
trainlisttest.list[code].rotation.y = Math.PI;
trainlisttest.list[code].position.x = rotaposx;
for(let tl=0;tl<6;tl++){
trainlisttest.list[code].children[tl].position.z = rotaposz;
}
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x<sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x){
vexlist.push(new THREE.Vector3(trainlisttest.list[code].position.x,0,trainlisttest.list[code].children[0].matrixWorld.elements[14]));
for(let m=sectionlist.sections.datalist[data.body[i].sectionCode].rail.length-1;m>=0;m--){
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x<trainlisttest.list[code].position.x){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}else{
vexlist.push(new THREE.Vector3(trainlisttest.list[code].position.x,0,trainlisttest.list[code].children[0].matrixWorld.elements[14]));
for(let m=0;m<sectionlist.sections.datalist[data.body[i].sectionCode].rail.length;m++){
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x<trainlisttest.list[code].position.x){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}
}else{
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x<sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x){
for(let m=sectionlist.sections.datalist[data.body[i].sectionCode].rail.length-1;m>=0;m--){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}else{
for(let m=0;m<sectionlist.sections.datalist[data.body[i].sectionCode].rail.length;m++){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
trainlisttest.list[code].rotation.y = Math.PI;
}
trainlisttest.list[code].status = "03";
}
trainlisttest.list[code].curve = new THREE.CatmullRomCurve3(vexlist);
trainlisttest.list[code].isStandTrack = sectionlist.sections.datalist[data.body[i].sectionCode].isStandTrack;
trainlisttest.list[code].len = sectionlist.sections.datalist[data.body[i].sectionCode].distance;
trainlisttest.list[code].progress = 0;
trainlisttest.list[code].speed = data.body[i].speed;
trainlisttest.list[code].speeds = parseFloat(data.body[i].speed*10/36/20/trainlisttest.list[code].len);
}
}
}
}
}
}
}
}
if(data.type == "Simulation_DeviceStatus"){
for(let i=data.body.length-1;i>=0;i--){
//0xFFFFFF
//0xCD0000 红
//0xEEEE00 黄
//0x32CD32 绿
if(data.body[i]._type == "Signal"){
if(signallist){
signalupdate(data.body[i]);
}
}
if(data.body[i]._type == "StationStand"){
if(actions){
standupdate(data.body[i]);
}
}
if(data.body[i]._type == "Switch"){
if(sectionlist){
switchupdate(data.body[i]);
}
}
}
}
}
function standupdate(data){
code = data.code;
if( actions[code]){
if(data.screenDoorOpenStatus == "02" && actions[code].status == "01"){
actions[code].status = "00";
}
if(data.screenDoorOpenStatus == "02" && actions[code].status == "00"){
actions[code].status = "02";
actions[code].action.reset();
actions[code].action.time = 0;
actions[code].action.timeScale = 1;
actions[code].action.play();
}
if(data.screenDoorOpenStatus == "01" && actions[code].status == "02"){
actions[code].status = "00";
}
if(data.screenDoorOpenStatus == "01" && actions[code].status == "00"){
actions[code].status = "01";
actions[code].action.reset();
actions[code].action.time = actions[code].action._clip.duration;
actions[code].action.timeScale = -1;
actions[code].action.play();
}
}
}
function signalupdate(data){
code = data.code;
if(data.lightType == "01"){
if(signallist.list[code].mesh.code){
signallist.list[code].mesh.status = data.status;
//55
//33
//77
//关闭
if(data.status == "01"){
signallist.list[code].mesh.children[0].material.map = materials[3];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[0];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[3];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
//开放
if(data.status == "02"){
if(data.switchLocateType == "01"){
signallist.list[code].mesh.children[0].material.map = materials[2];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[3];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[3];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
if(data.switchLocateType == "02"){
signallist.list[code].mesh.children[0].material.map = materials[3];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[3];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[1];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
}
//引导
if(data.status == "03"){
signallist.list[code].mesh.children[0].material.map = materials[3];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[0];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[1];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
//封锁
if(data.status == "04"){
signallist.list[code].mesh.children[0].material.map = materials[3];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[3];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[3];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
//故障
if(data.status == "05"){
signallist.list[code].mesh.children[0].material.map = materials[3];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[3];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[3];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
}
}else if(data.lightType == "01"){
if(signallist.list[code].mesh.code){
signallist.list[code].mesh.children[0].material.map = materials[3];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[3];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[3];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
}
}
function switchupdate(data){
code = data.code;
for(let j=sectionlist.switchs.modellist.length-1;j>=0;j--){
if(sectionlist.switchs.modellist[j].code == code){
if(sectionlist.switchs.modellist[j].locateType != data.locateType){
if(data.locateType == "02"){
if(actions[sectionlist.switchs.modellist[j].code]){
sectionlist.switchs.modellist[j].locateType = data.locateType;
actions[sectionlist.switchs.modellist[j].code].reset();
actions[sectionlist.switchs.modellist[j].code].time = 0;
actions[sectionlist.switchs.modellist[j].code].timeScale = 1;
actions[sectionlist.switchs.modellist[j].code].play();
}
}else if(data.locateType == "01"){
if(actions[sectionlist.switchs.modellist[j].code]){
sectionlist.switchs.modellist[j].locateType = data.locateType;
actions[sectionlist.switchs.modellist[j].code].reset();
actions[sectionlist.switchs.modellist[j].code].time = actions[sectionlist.switchs.modellist[j].code]._clip.duration;
actions[sectionlist.switchs.modellist[j].code].timeScale = -1;
actions[sectionlist.switchs.modellist[j].code].play();
}
}
}
j = 0;
}
}
}
}

View File

@ -0,0 +1,452 @@
import StompClient from '@/utils/sock';
import { displayTopic } from '@/utils/stomp';
import { handleToken } from '@/utils/auth';
import router from '@/router';
//定于仿真socket接口
export function Jlmap3dSubscribe(worker) {
let scope = this;
this.map = null;
let webworker = worker;
var trainlisttest = null;
var sectionlist = null;
var signallist = null;
var stationstandlist = null;
var sectionlist = null;
var materials = null;
var actions = null;
var scenes = null;
var code = null;
this.teststomp = new StompClient();
this.topic = displayTopic;
let header = { group: router.currentRoute.query.group, 'X-Token': handleToken() };
this.updatamap = function (mapdata, materiallist, nowaction, scene) {
//console.log(mapdata);
scope.map = mapdata;
trainlisttest = this.map.trainlisttest;
sectionlist = this.map.sectionlist;
signallist = this.map.signallist;
stationstandlist = this.map.stationstandlist;
sectionlist = this.map.sectionlist;
materials = materiallist;
scenes = scene;
actions = nowaction;
}
this.socketon = function (topic) {
try {
//console.log("teststomp");
scope.teststomp.subscribe(topic, callback, header);
} catch (error) {
console.error('websocket订阅失败');
}
}
this.socketoff = function (topic) {
scope.teststomp.unsubscribe(topic);
}
// 仿真socket接口回调函数
function callback(Response) {
//对象化数据
let data = JSON.parse(Response.body);
//遍历后台数据
//判断消息类型
// if(data.type == "Simulation_TrainPosition"){
//
//
// }
if (data.type == "Simulation_DeviceStatus") {
if (data.body.length < 200) {
for (let i = data.body.length - 1; i >= 0; i--) {
if (data.body[i]._type == "Train") {
//console.log(data.body[i]);
//遍历列车对象组
//console.log(data.body[i]);
if (trainlisttest) {
code = data.body[i].code;
//剔除不显示的车
//找到对应列车
if (trainlisttest.list[code]) {
//车门开关验证
// if(data.body[i].directionType == "02"){
if (trainlisttest.list[code].doorStatus != data.body[i].doorStatus && data.body[i].doorStatus == "01") {
//console.log("close");
trainlisttest.list[code].doorStatus = "01";
for (let an = actions[code].top.length - 1; an >= 0; an--) {
actions[code].top[an].reset();
actions[code].top[an].time = actions[code].top[an]._clip.duration;
actions[code].top[an].timeScale = -1;
actions[code].top[an].play();
}
} else if (trainlisttest.list[code].doorStatus != data.body[i].doorStatus && data.body[i].doorStatus == "02") {
//console.log("open");
trainlisttest.list[code].doorStatus = "02";
for (let an = actions[code].top.length - 1; an >= 0; an--) {
actions[code].top[an].reset();
actions[code].top[an].time = 0;
actions[code].top[an].timeScale = 1;
actions[code].top[an].play();
}
}
// }else{
// if(trainlisttest.list[code].doorStatus != data.body[i].doorStatus && data.body[i].doorStatus == "01"){
// //console.log("close");
// trainlisttest.list[code].doorStatus = "01";
// for(let an=actions[code].down.length-1;an>=0;an--){
// actions[code].down[an].reset();
// actions[code].down[an].time = actions[code].top[an]._clip.duration;
// actions[code].down[an].timeScale = -1;
// actions[code].down[an].play();
// }
// }else if(trainlisttest.list[code].doorStatus != data.body[i].doorStatus && data.body[i].doorStatus == "02"){
// //console.log("open");
// trainlisttest.list[code].doorStatus = "02";
// for(let an=actions[code].down.length-1;an>=0;an--){
// actions[code].down[an].reset();
// actions[code].down[an].time = 0;
// actions[code].down[an].timeScale = 1;
// actions[code].down[an].play();
// }
// }
// }
//遍历获取所在轨道
if (trainlisttest.list[code].dispose != data.body[i].dispose && data.body[i].dispose == false) {
trainlisttest.group.add(trainlisttest.list[code]);
if (sectionlist.sections.datalist[data.body[i].sectionCode].code) {
trainlisttest.list[code].position.y = 0;
trainlisttest.list[code].progress = 0;
trainlisttest.list[code].oldoffset = data.body[i].sectionOffsetPercent;
trainlisttest.list[code].dispose = false;
if (data.body[i].directionType == "02") {
trainlisttest.list[code].status = "02";
trainlisttest.list[code].rotation.y = 0;
} else if (data.body[i].directionType == "03") {
trainlisttest.list[code].status = "03";
trainlisttest.list[code].rotation.y = Math.PI;
}
}
} else if (trainlisttest.list[code].dispose != data.body[i].dispose && data.body[i].dispose == true) {
trainlisttest.group.remove(trainlisttest.list[code]);
trainlisttest.list[code].progress = null;
trainlisttest.list[code].dispose = true;
} else if (trainlisttest.list[code].dispose == data.body[i].dispose && data.body[i].dispose == false) {
if (sectionlist.sections.datalist[data.body[i].sectionCode].code) {
if (trainlisttest.list[code].nowcode != data.body[i].sectionCode || trainlisttest.list[code].nextcode != data.body[i].nextSectionCode) {
trainlisttest.list[code].nowcode = data.body[i].sectionCode;
trainlisttest.list[code].nextcode = data.body[i].nextSectionCode;
let vexlist = [];
let endrotation = null;
if (data.body[i].directionType == "02") {//向右
if (trainlisttest.list[code].status != data.body[i].directionType) {
console.log(trainlisttest.list[code].position);
console.log(trainlisttest.list[code].children[5].matrixWorld);
trainlisttest.list[code].position.x = trainlisttest.list[code].children[5].matrixWorld.elements[12];
trainlisttest.list[code].children[0].position.z = trainlisttest.list[code].children[0].matrixWorld.elements[14];
trainlisttest.list[code].children[1].position.z = trainlisttest.list[code].children[1].matrixWorld.elements[14];
trainlisttest.list[code].children[2].position.z = trainlisttest.list[code].children[2].matrixWorld.elements[14];
trainlisttest.list[code].children[3].position.z = trainlisttest.list[code].children[3].matrixWorld.elements[14];
trainlisttest.list[code].children[4].position.z = trainlisttest.list[code].children[4].matrixWorld.elements[14];
trainlisttest.list[code].children[5].position.z = trainlisttest.list[code].children[5].matrixWorld.elements[14];
if (sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x > sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x) {
vexlist.push(new THREE.Vector3(trainlisttest.list[code].position.x, 0, trainlisttest.list[code].children[0].matrixWorld.elements[14]));
for (let m = sectionlist.sections.datalist[data.body[i].sectionCode].rail.length - 1; m >= 0; m--) {
if (sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x > trainlisttest.list[code].position.x) {
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
} else {
vexlist.push(new THREE.Vector3(trainlisttest.list[code].position.x, 0, trainlisttest.list[code].children[0].matrixWorld.elements[14]));
for (let m = 0; m < sectionlist.sections.datalist[data.body[i].sectionCode].rail.length; m++) {
if (sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x > trainlisttest.list[code].position.x) {
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}
} else {
if (sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x > sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x) {
for (let m = sectionlist.sections.datalist[data.body[i].sectionCode].rail.length - 1; m >= 0; m--) {
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
} else {
for (let m = 0; m < sectionlist.sections.datalist[data.body[i].sectionCode].rail.length; m++) {
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}
trainlisttest.list[code].status = "02";
trainlisttest.list[code].rotation.y = 0;
} else if (data.body[i].directionType == "03") {//向左
if (trainlisttest.list[code].status != data.body[i].directionType) {
trainlisttest.list[code].position.x = trainlisttest.list[code].children[5].matrixWorld.elements[12];
trainlisttest.list[code].children[0].position.z = trainlisttest.list[code].children[0].matrixWorld.elements[14];
trainlisttest.list[code].children[1].position.z = trainlisttest.list[code].children[1].matrixWorld.elements[14];
trainlisttest.list[code].children[2].position.z = trainlisttest.list[code].children[2].matrixWorld.elements[14];
trainlisttest.list[code].children[3].position.z = trainlisttest.list[code].children[3].matrixWorld.elements[14];
trainlisttest.list[code].children[4].position.z = trainlisttest.list[code].children[4].matrixWorld.elements[14];
trainlisttest.list[code].children[5].position.z = trainlisttest.list[code].children[5].matrixWorld.elements[14];
//
if (sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x < sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x) {
vexlist.push(new THREE.Vector3(trainlisttest.list[code].position.x, 0, trainlisttest.list[code].children[0].matrixWorld.elements[14]));
for (let m = sectionlist.sections.datalist[data.body[i].sectionCode].rail.length - 1; m >= 0; m--) {
if (sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x < trainlisttest.list[code].position.x) {
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
} else {
vexlist.push(new THREE.Vector3(trainlisttest.list[code].position.x, 0, trainlisttest.list[code].children[0].matrixWorld.elements[14]));
for (let m = 0; m < sectionlist.sections.datalist[data.body[i].sectionCode].rail.length; m++) {
if (sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x < trainlisttest.list[code].position.x) {
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}
} else {
//
if (sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x < sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x) {
for (let m = sectionlist.sections.datalist[data.body[i].sectionCode].rail.length - 1; m >= 0; m--) {
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
} else {
for (let m = 0; m < sectionlist.sections.datalist[data.body[i].sectionCode].rail.length; m++) {
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}
trainlisttest.list[code].status = "03";
trainlisttest.list[code].rotation.y = Math.PI;
}
trainlisttest.list[code].curve = new THREE.CatmullRomCurve3(vexlist);
// console.log(trainlisttest.list[code].curve.points);
// console.log(data.body[i].speed)
// console.log(sectionlist.sections.datalist[data.body[i].sectionCode].distance);
trainlisttest.list[code].speeds = data.body[i].speed * 10 / 36 / 11 / sectionlist.sections.datalist[data.body[i].sectionCode].distance;
trainlisttest.list[code].progress = 0;
}
// console.log("speed");
// console.log(data.body[i].speed);
// console.log(trainlisttest.list[code].speed);
if (data.body[i].speed != trainlisttest.list[code].speed) {
trainlisttest.list[code].speed = data.body[i].speed;
trainlisttest.list[code].speeds = data.body[i].speed * 10 / 36 / 11 / sectionlist.sections.datalist[data.body[i].sectionCode].distance;
// if(trainlisttest.list[code].speeds > 0.1){
// console.log(data.body[i]);
// console.log(data.body[i].speed)
// console.log(sectionlist.sections.datalist[data.body[i].sectionCode].distance);
// console.log(trainlisttest.list[code].speeds);
// }
}
}
}
}
}
}
//0xFFFFFF
//0xCD0000 红
//0xEEEE00 黄
//0x32CD32 绿
if (data.body[i]._type == "Signal") {
if (signallist) {
code = data.body[i].code;
if (data.body[i].lightType == "01") {
if (signallist.list[code].mesh.code) {
signallist.list[code].mesh.status = data.body[i].status;
//55
//33
//77
//关闭
if (data.body[i].status == "01") {
signallist.list[code].mesh.children[0].material.map = materials[3];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[0];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[3];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
//开放
if (data.body[i].status == "02") {
if (data.body[i].switchLocateType == "01") {
signallist.list[code].mesh.children[0].material.map = materials[2];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[3];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[3];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
if (data.body[i].switchLocateType == "02") {
signallist.list[code].mesh.children[0].material.map = materials[3];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[3];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[1];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
}
//引导
if (data.body[i].status == "03") {
signallist.list[code].mesh.children[0].material.map = materials[3];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[0];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[1];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
//封锁
if (data.body[i].status == "04") {
signallist.list[code].mesh.children[0].material.map = materials[3];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[3];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[3];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
//故障
if (data.body[i].status == "05") {
signallist.list[code].mesh.children[0].material.map = materials[3];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[3];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[3];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
}
} else if (data.body[i].lightType == "01") {
if (signallist.list[code].mesh.code) {
signallist.list[code].mesh.children[0].material.map = materials[3];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[3];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[3];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
}
}
}
if (data.body[i]._type == "StationStand") {
if (actions) {
code = data.body[i].code;
if (data.body[i].screenDoorOpenStatus == "02" && actions[code].status == "01") {
actions[code].status = "00";
}
if (data.body[i].screenDoorOpenStatus == "02" && actions[code].status == "00") {
actions[code].status = "02";
actions[code].action.reset();
actions[code].action.time = 0;
actions[code].action.timeScale = 1;
actions[code].action.play();
}
if (data.body[i].screenDoorOpenStatus == "01" && actions[code].status == "02") {
actions[code].status = "00";
}
if (data.body[i].screenDoorOpenStatus == "01" && actions[code].status == "00") {
actions[code].status = "01";
actions[code].action.reset();
actions[code].action.time = actions[code].action._clip.duration;
actions[code].action.timeScale = -1;
actions[code].action.play();
}
}
}
if (data.body[i]._type == "Switch") {
if (sectionlist) {
code = data.body[i].code;
for (let j = sectionlist.switchs.modellist.length - 1; j >= 0; j--) {
if (sectionlist.switchs.modellist[j].code == code) {
if (sectionlist.switchs.modellist[j].locateType != data.body[i].locateType) {
if (data.body[i].locateType == "02") {
sectionlist.switchs.modellist[j].locateType = data.body[i].locateType;
actions[sectionlist.switchs.modellist[j].code].reset();
actions[sectionlist.switchs.modellist[j].code].time = 0;
actions[sectionlist.switchs.modellist[j].code].timeScale = 1;
actions[sectionlist.switchs.modellist[j].code].play();
} else if (data.body[i].locateType == "01") {
sectionlist.switchs.modellist[j].locateType = data.body[i].locateType;
actions[sectionlist.switchs.modellist[j].code].reset();
actions[sectionlist.switchs.modellist[j].code].time = actions[sectionlist.switchs.modellist[j].code]._clip.duration;
actions[sectionlist.switchs.modellist[j].code].timeScale = -1;
actions[sectionlist.switchs.modellist[j].code].play();
}
}
//console.log(sectionlist.group[j].name);
j = 0;
}
}
}
}
}
} else if (data.body.length > 200) {
}
}
}
}

View File

@ -0,0 +1,390 @@
/**
* 摄像机控制用户交互此类只实现键盘交互移动如果需要鼠标交互转动视角使用其子类PointerLockControls或者MouseControls
* @constructor
* @param {THREE.Camera} camera 需要控制的摄像机
* @param {Number} height 高度相当于观察者身高默认1.6
*/
function FreeControls(camera, height) {
var _scope = this;
var _PI_2 = Math.PI / 2;
var _forward = false;
var _backward = false;
var _right = false;
var _left = false;
var _up = false;
var _down = false;
var _up_whirl = false;
var _down_whirl = false;
var _left_whirl = false;
var _right_whirl = false;
this._camera = camera;
this._pitchObject = new THREE.Object3D();
this._yawObject = new THREE.Object3D();
/**
* 控制器使能
* @type {Boolean}
*/
this.enabled = false;
/**
* 摄像机移动速度默认2
* @type {Number}
*/
this.v_delta =0.5;
/**
* 上帝模式开关默认false
* @type {Boolean}
*/
this.godView = false;
/**
* 摄像机高度观察者身高
* @type {Number}
*/
this.height = (height ? height : 1.6);
/**
* 移动控制按键
* @type {Object}
* @property {Number} FORWARD 向前走按键的KEYCODE
* @property {Number} BACKWARD 向后走按键的KEYCODE
* @property {Number} LEFT 向左走按键的KEYCODE
* @property {Number} RIGHT 向右走按键的KEYCODE
*/
this.keys = {
FORWARD: 87,
BACKWARD: 83,
LEFT: 65,
RIGHT: 68
}
this._camera.rotation.set(0, 0, 0);
this._pitchObject.add(this._camera);
this._yawObject.position.y = this.height;
this._yawObject.add(this._pitchObject);
this._pitchObject.rotation.set(0, 0, 0);
this._yawObject.rotation.set(0, 0, 0);
document.addEventListener('keydown', onKeyDown, false);
document.addEventListener('keyup', onKeyUp, false);
// Touch handling code
document.addEventListener('touchstart', onTouchStart, false);
document.addEventListener('touchend', onTouchEnd, false);
document.addEventListener('touchmove', onTouchMove, false);
//viewport.addEventListener('touchstart', function(event) {
function onTouchStart(event) {
var touches = event.touches;
switch(touches.length) {
case 1: // Single finger looks around
//startLook(touches[0].pageX, touches[0].pageY);
break;
case 2: // Two fingers moves
//startMove(touches[0].pageX, touches[0].pageY);
break;
case 3: // Three finger tap jumps
//playerMover.jump();
break;
default:
return;
}
event.stopPropagation();
event.preventDefault();
}
//viewport.addEventListener('touchend', function(event) {
function onTouchEnd(event) {
//endLook();
return false;
}
//viewport.addEventListener('touchmove', function(event) {
function onTouchMove(event) {
var touches = event.touches;
switch(touches.length) {
case 1:
//moveLook(touches[0].pageX, touches[0].pageY);
break;
case 2:
//moveUpdate(touches[0].pageX, touches[0].pageY, 16);
break;
default:
return;
}
event.stopPropagation();
event.preventDefault();
}
/**
* 更新相机位置
* @param {Number} delta 两次调用之间的时间差
* @return {undefined}
*/
var rotation_delta_x = 0;
var rotation_delta_y = 0;
this.update = function (delta) {
delta = 4;
if (!_scope.enabled) return;
var rotation_ratio = 0.5;
if ( !_up_whirl && !_down_whirl && !_left_whirl && !_right_whirl) {
// if(mode == 2 ){
// _scope._pitchObject.rotation.x = headControls.getPitchObject().rotation.x + rotation_delta_x;
// _scope._pitchObject.rotation.x = Math.max(-_PI_2, Math.min(_PI_2, _scope._pitchObject.rotation.x));
// _scope._yawObject.rotation.y = headControls.getObject().rotation.y + rotation_delta_y;
// _scope._yawObject.rotation.z = headControls.getObject().rotation.z ;
// }
}
if (_forward || _backward || _left || _right || _up || _down
|| _up_whirl || _down_whirl || _left_whirl || _right_whirl) {
var delta_new = 0.4;
var translation = new THREE.Vector3(0, 0, 0);
if (_scope.godView) {
if (_forward) {
translation.z -= _scope.v_delta * Math.cos(_scope._pitchObject.rotation.x) * delta;
translation.y += _scope.v_delta * Math.sin(_scope._pitchObject.rotation.x) * delta;
}
if (_backward) {
translation.z += _scope.v_delta * Math.cos(_scope._pitchObject.rotation.x) * delta;
translation.y -= _scope.v_delta * Math.sin(_scope._pitchObject.rotation.x) * delta;
}
} else {
if (_forward)
{
translation.z -= _scope.v_delta * delta * delta_new;
}
if (_backward)
{
translation.z += _scope.v_delta * delta * delta_new;
}
}
if (_left){
translation.x -= _scope.v_delta * delta * delta_new;
}
if (_right){
translation.x += _scope.v_delta * delta * delta_new;
}
if(_up){
translation.y += _scope.v_delta * delta * delta_new;
}
if(_down){
translation.y -= _scope.v_delta * delta * delta_new;
}
if(_up_whirl)
{
_scope._pitchObject.rotation.x += _scope.v_delta * delta * rotation_ratio;
//限制向上抬头90度
_scope._pitchObject.rotation.x = Math.max(-_PI_2, Math.min(_PI_2, _scope._pitchObject.rotation.x));
rotation_delta_x += _scope.v_delta * delta * rotation_ratio;
}
if(_down_whirl)
{
_scope._pitchObject.rotation.x -= _scope.v_delta * delta * rotation_ratio;
//限制向下低头90度
_scope._pitchObject.rotation.x = Math.max(-_PI_2, Math.min(_PI_2, _scope._pitchObject.rotation.x));
rotation_delta_x -= _scope.v_delta * delta * rotation_ratio;
}
if(_left_whirl)
{
_scope._yawObject.rotation.y += _scope.v_delta * delta * rotation_ratio;
rotation_delta_y += _scope.v_delta * delta * rotation_ratio;
}
if(_right_whirl)
{
_scope._yawObject.rotation.y -= _scope.v_delta * delta * rotation_ratio;
rotation_delta_y -= _scope.v_delta * delta * rotation_ratio;
}
_scope._yawObject.translateX(translation.x);
_scope._yawObject.translateY(translation.y);
_scope._yawObject.translateZ(translation.z);
//console.log(_scope._yawObject.position);
}
if (!_scope.godView) {
// _scope._yawObject.position.y = _scope.height;
}
}
/**
* 获取相机云台关于相机位置的调整应该实施于由此函数返回的Object3D
* @return {THREE.Object3D} 相机云台
*/
this.getObject = function () {
return this._yawObject;
};
/**
* 获取相机空间朝向只读
* @return {THREE.Vector3} 相机空间朝向
*/
this.getDirection = function () {
var direction = new THREE.Vector3(0, 0, -1);
var rotation = new THREE.Euler(0, 0, 0, 'YXZ');
var v = new THREE.Vector3();
rotation.set(this._pitchObject.rotation.x, this._yawObject.rotation.y, 0);
v.copy(direction).applyEuler(rotation);
return v;
};
function onKeyDown(event) {
switch(event.keyCode) {
case _scope.keys.FORWARD:
_forward = true;
break;
case 38: // up
_up_whirl = true;
break;
case _scope.keys.BACKWARD:
_backward = true;
break;
case 40: // down
_down_whirl = true;
break;
case _scope.keys.LEFT:
_left = true;
break;
case 37: // _left
_left_whirl = true;
break;
case _scope.keys.RIGHT:
_right = true;
break;
case 39: // _right
_right_whirl = true;
break;
case 81:
_up = true;
break;
case 69:
_down = true;
break;
}
}
function onKeyUp(event) {
switch(event.keyCode) {
case _scope.keys.FORWARD:
_forward = false;
break;
case 38: // up
_up_whirl = false;
break;
case _scope.keys.BACKWARD:
_backward = false;
break;
case 40: // down
_down_whirl = false;
break;
case _scope.keys.LEFT:
_left = false;
break;
case 37: // _left
_left_whirl = false;
break;
case _scope.keys.RIGHT:
_right = false;
break;
case 39: // _right
_right_whirl = false;
break;
case 81:
_up = false;
break;
case 69:
_down = false;
break;
}
}
}
export function MouseControls(camera, height) {
var caozuo = 1;
var lastX,lastY;
FreeControls.call(this, camera, height);
var _scope = this;
var _PI_2 = Math.PI / 2;
var _mouseDown = false;
document.addEventListener('keydown', FreeControls.onKeyDown, false);
document.addEventListener('mousemove', onMouseMove, false);
document.addEventListener('mousedown', onMouseDown, false);
document.addEventListener('mouseup', onMouseUp, false);
this.removeEventListeners = function (){
document.removeEventListener('mousemove', onMouseMove, false);
document.removeEventListener('mousedown', onMouseDown, false);
document.removeEventListener('mouseup', onMouseUp, false);
document.removeEventListener('keydown', FreeControls.onKeyDown, false);
}
function onMouseMove(event) {
if(caozuo ==1){
if (_scope.enabled === false || _mouseDown === false) return;
event.preventDefault();
event.stopPropagation();
var currentX = event.clientX;
var currentY = event.clientY;
var movementX = currentX - lastX;
var movementY = currentY - lastY;
_scope._yawObject.rotation.y -= movementX * 0.001;
_scope._pitchObject.rotation.x -= movementY * 0.001;
_scope._pitchObject.rotation.x = Math.max(-_PI_2, Math.min(_PI_2, _scope._pitchObject.rotation.x));
lastX = currentX;
lastY = currentY;
}else{
}
}
function onMouseDown (event) {
if(caozuo ==1){
if (_scope.enabled === false) return;
_mouseDown = true;
event.preventDefault();
event.stopPropagation();
lastX = event.clientX;
lastY = event.clientY;
}else{
}
}
function onMouseUp (event) {
if(caozuo ==1){
_mouseDown = false;
event.preventDefault();
event.stopPropagation();
}else{
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,164 @@
import { getPublishMapDetail,getMapDetail,set3dMapData,get3dMapData } from '@/api/jlmap3d/load3ddata';
//原始信息obj化提供给三维建模
import {SetObj} from '@/jlmap3d/edit/utils/SetObj.js';
//componnent
import {SectionList} from '@/jlmap3d/edit/testmodel/SectionList.js';
import {SignalList} from '@/jlmap3d/edit/testmodel/SignalList.js';
import {StationStandList} from '@/jlmap3d/edit/testmodel/StationStandList.js';
import {TrainList} from '@/jlmap3d/edit/testmodel/TrainList.js';
import {TrainListTest} from '@/jlmap3d/edit/testmodel/TrainListTest.js';
import {LinkList} from '@/jlmap3d/edit/testmodel/LinkList.js';
import {RealSectionList} from '@/jlmap3d/edit/testmodel/RealSectionList.js';
import axios from 'axios';
import {getmodels} from '@/jlmap3d/edit/connect/getmodels';
import { Loading } from 'element-ui';
// import {SwitchModel} from '@/jlmap3d/model/SwitchModel.js';
export function Jlmap3ddata(mapid,scope){
let editmapid = mapid;
let scene = scope.scene;
let jlmap3ddata = scope.mapdata;
let assetloader = scope.assetloader;
let loadingInstance = Loading.service({ fullscreen: true });
get3dMapData(editmapid).then(data => {
//console.log(data);
if(data.code == "200"){
//console.log("数据存在");
let isSection = false;
//console.log(data.data);
if(data.data.assets){
let assets = JSON.parse(data.data.assets);
for(let i=0;i<assets.length;i++){
if(assets[i].deviceType == "mapSection"){
isSection = true;
}
}
}
if(isSection == true){
init3d(editmapid,data.data);
}else{
// console.log(editmapid);
// console.log(data.data.id);
initobj(editmapid,data.data.id);
}
}
}).catch(error => {
//console.log(error);
if(error.code == "30001"){
//console.log("没有三维数据");
let params = {mapId:editmapid};
set3dMapData(params).then(data => {
if(data.code == "200"){
//console.log("创建三维数据成功");
//console.log(data);
initobj(editmapid,data.data.id);
}
}).catch(error => {
//console.log(error);
});
}
});
function initobj(mapid,data3did){
console.log(mapid);
getMapDetail(mapid).then(data => {
let mapdata = data.data;
//console.log(data3did);
jlmap3ddata.id = data3did;
jlmap3ddata.mapId = mapid;
console.log(jlmap3ddata.mapId);
//初始化轨道和道岔 暂时
jlmap3ddata.sectionlist = new SectionList();
jlmap3ddata.signallist = new SignalList();
//初始化站台
jlmap3ddata.stationstandlist = new StationStandList();
jlmap3ddata.trainlisttest = new TrainListTest();
assetloader.assetinit(scene)
.then(function(data){
//console.log(data);
return jlmap3ddata.sectionlist.initpromise(mapdata.sectionList,mapdata.switchList,scene);
})
.then(function(data){
//console.log(data);
return jlmap3ddata.signallist.initpromise(mapdata.signalList,scene,assetloader);
})
.then(function(data){
//console.log(data);
return jlmap3ddata.stationstandlist.initpromise(mapdata.stationList,mapdata.stationStandList,scene,assetloader);
})
.then(function(data){
//console.log(data);
return jlmap3ddata.trainlisttest.initpromise(mapdata.trainList,scene,assetloader);
})
.then(function(data){
//console.log(data);
loadingInstance.close();
});
//初始化信号
SetObj(mapdata,scope);
});
}
function init3d(mapid,netdata){
getMapDetail(mapid).then(data => {
jlmap3ddata.id = netdata.id;
jlmap3ddata.mapId = mapid;
let mapdata = data.data;
//初始化轨道和道岔 暂时
jlmap3ddata.sectionlist = new SectionList();
jlmap3ddata.signallist = new SignalList();
//初始化站台
jlmap3ddata.stationstandlist = new StationStandList();
//初始化测试列车
jlmap3ddata.trainlisttest = new TrainListTest();
jlmap3ddata.realsectionlist = new RealSectionList();
assetloader.setmodellist(netdata.assets);
assetloader.assetpromise(scene)
.then(function(data){
//console.log(data);
return jlmap3ddata.sectionlist.initpromise(mapdata.sectionList,mapdata.switchList,scene);
})
.then(function(data){
//console.log(data);
return jlmap3ddata.signallist.initpromise(mapdata.signalList,scene,assetloader,netdata.signals);
})
.then(function(data){
//console.log(data);
return jlmap3ddata.stationstandlist.initpromise(mapdata.stationList,mapdata.stationStandList,scene,assetloader,netdata.stands);
})
.then(function(data){
//console.log(data);
return jlmap3ddata.trainlisttest.initpromise(mapdata.trainList,scene,assetloader);
})
.then(function(data){
//console.log(data);
return jlmap3ddata.realsectionlist.initpromise(jlmap3ddata,scene,assetloader);
})
.then(function(data){
//console.log(data);
loadingInstance.close();
});
});
}
}

View File

@ -0,0 +1,389 @@
//轨道对象操作
export function Pathaction(){
let scope = this;
//开关
this.on = true;
//修改名称
this.setname = function(){
if(scope.on == true){
}
}
//改变类型
this.settype = function(){
if(scope.on == true){
}
}
//改变坐标
this.setpos = function(){
if(scope.on == true){
}
}
//改变角度
this.setrota = function(){
if(scope.on == true){
}
}
//改变拉伸值
this.setscle = function(){
if(scope.on == true){
}
}
this.drawline = function(jlmap3dedit,splineHelperObjects){
if(scope.on == true){
var rayhelper;//画图辅助线
let lineswitch = 0;
var linenew;
document.onmousedown = function(event){
jlmap3dedit.selectswitch = false;
console.log(event.button);
//辅助线段
let point1;
if(event.button == 2){
jlmap3dedit.selectswitch = true;
document.onmousedown = null;
lineswitch = null;
console.log(linenew);
if(linenew){
jlmap3dedit.scene.remove( linenew );
}
}else if(event.button == 0){
if(lineswitch == 0){
point1 = mouserray(event,jlmap3dedit);
console.log("new");
if(point1){
linenew = addline(point1,1,jlmap3dedit.splineHelperObjects,jlmap3dedit.scene);
jlmap3dedit.mapdata.path.push(linenew);
jlmap3dedit.scene.add( linenew );
lineswitch = 1;
}
}else if(lineswitch == 1){
let point = {
x:(linenew.geometry.vertices[0].x+linenew.geometry.vertices[1].x)/2,
y:linenew.geometry.vertices[1].y,
z:(linenew.geometry.vertices[0].z+linenew.geometry.vertices[1].z)/2
};
var raycaster = new THREE.Raycaster(new THREE.Vector3(point.x,point.y,point.z),new THREE.Vector3(0,-1,0).normalize());
for(let i=0;i<jlmap3dedit.mapdata.sectionlist.sections.modellist.length;i++){
var intersects = raycaster.intersectObject(jlmap3dedit.mapdata.sectionlist.sections.modellist[i]);
if(intersects[0]){
if(intersects[0].object.code == jlmap3dedit.mapdata.sectionlist.sections.modellist[i].code){
jlmap3dedit.mapdata.sectionlist.sections.datalist[i].rail = [];
jlmap3dedit.scene.remove(jlmap3dedit.mapdata.sectionlist.sections.datalist[i].railline);
for(let n=0;n<linenew.geometry.vertices.length;n++){
jlmap3dedit.mapdata.sectionlist.sections.datalist[i].rail.push(linenew.geometry.vertices[n]);
}
jlmap3dedit.mapdata.sectionlist.sections.datalist[i].railline = linenew;
console.log(jlmap3dedit.mapdata.sectionlist.sections.datalist[i].rail);
i = jlmap3dedit.mapdata.sectionlist.sections.modellist.length;
}
}
}
lineswitch = 0;
linenew = null;
}
document.onmousemove = function(ev){
if(lineswitch == 1){
let point2 = mouserray(ev,jlmap3dedit);
if(point2){
//判断线的垂直水平
if((point2.x>(point1.x-6)&&point2.x<(point1.x+6))&& point1.z != point2.z){
point2.x = point1.x;
}else if((point2.z>(point1.z-6)&&point2.z<(point1.z+6)) && point1.x != point2.x){
point2.z = point1.z;
}
//更新辅助线段
linenew.children[1].position.x = point2.x;
linenew.children[1].position.z = point2.z;
linenew.geometry.vertices[1].x = point2.x;
linenew.geometry.vertices[1].z = point2.z;
linenew.geometry.verticesNeedUpdate = true;
}
}
document.onmouseup = function(event){
if(lineswitch == 0){
document.onmousemove = null;
document.onmouseup = null;
}
}
}
}
}
}
}
this.drawcurve = function(jlmap3dedit){
if(scope.on == true){
var rayhelper;//画图辅助线
let lineswitch = 0;
var linenew;
document.onmousedown = function(event){
console.log(event.button);
//辅助线段
let point1;
if(event.button == 2){
document.onmousedown = null;
lineswitch = null;
console.log(linenew);
if(linenew){
jlmap3dedit.scene.remove( linenew );
}
}else if(event.button == 0){
if(lineswitch == 0){
point1 = mouserray(event,jlmap3dedit);
if(point1){
linenew = addline(point1,2,jlmap3dedit.splineHelperObjects,jlmap3dedit.scene);
jlmap3dedit.scene.add( linenew );
lineswitch = 1;
}
}else if(lineswitch == 1){
let point = {
x:linenew.geometry.vertices[1].x,
y:linenew.geometry.vertices[1].y,
z:linenew.geometry.vertices[1].z
};
var raycaster = new THREE.Raycaster(new THREE.Vector3(point.x,point.y,point.z),new THREE.Vector3(0,-1,0).normalize());
for(let i=0;i<jlmap3dedit.mapdata.sectionlist.sections.modellist.length;i++){
var intersects = raycaster.intersectObject(jlmap3dedit.mapdata.sectionlist.sections.modellist[i]);
if(intersects[0]){
if(intersects[0].object.code == jlmap3dedit.mapdata.sectionlist.sections.modellist[i].code){
jlmap3dedit.mapdata.sectionlist.sections.datalist[i].rail = [];
for(let n=0;n<linenew.geometry.vertices.length;n++){
jlmap3dedit.mapdata.sectionlist.sections.datalist[i].rail.push(linenew.geometry.vertices[n]);
}
console.log(jlmap3dedit.mapdata.sectionlist.sections.datalist[i]);
console.log(jlmap3dedit.mapdata.sectionlist.sections.datalist[i].rail);
}
}
}
lineswitch = 0;
linenew = null;
}
document.onmousemove = function(ev){
if(lineswitch == 1){
let point2 = mouserray(ev,jlmap3dedit);
if(point2){
linenew.children[2].position.x = point2.x;
linenew.children[2].position.z = point2.z;
linenew.children[1].position.x = (point1.x+point2.x)/2;
linenew.children[1].position.z = (point1.z+point2.z)/2;
//更新辅助线段
linenew.geometry.vertices[2].x = point2.x;
linenew.geometry.vertices[2].z = point2.z;
linenew.geometry.vertices[1].x = (point1.x+point2.x)/2;
linenew.geometry.vertices[1].z = (point1.z+point2.z)/2;
linenew.geometry.verticesNeedUpdate = true;
}
}
document.onmouseup = function(event){
if(lineswitch == 0){
document.onmousemove = null;
document.onmouseup = null;
}
}
}
}
}
}
}
//点击事件
this.raycaster = function(data){
console.log();
if(scope.on == true){
//定义光线
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 );
console.log(data.splineHelperObjects);
let intersects1;
intersects1 = raycaster.intersectObjects( data.splineHelperObjects);
if(intersects1[0]){
console.log(intersects1[0]);
return intersects1[0].object;
}
return null;
}
}
//鼠标点击事件判断初始位置做校验
var raycaster = new THREE.Raycaster();
var mouse = new THREE.Vector2();
function mouserray(mousep,jlmap3dedit,helppoints){
var resultpoint;
if(mousep.clientX <(window.innerWidth*0.2) ||mousep.clientX >(window.innerWidth*0.8) ){
}else{
mouse.x = (mousep.clientX / window.innerWidth) * 2 - 1;
mouse.y = -(mousep.clientY / window.innerHeight) * 2 + 1;
raycaster.setFromCamera( mouse, jlmap3dedit.camera );
console.log(jlmap3dedit.assetloader.modellist[3].mesh);
var intersects = raycaster.intersectObjects(jlmap3dedit.assetloader.modellist[3].mesh.children);
console.log(intersects);
if(intersects[0]){
resultpoint = intersects[0].point;
return resultpoint;
}
}
}
function addline(point1,num,splineHelperObjects,scene){
let material = new THREE.LineBasicMaterial({color: 0xEEC900});
let geometry = new THREE.Geometry();
let object;
if(num == 1){
geometry.vertices.push(new THREE.Vector3(point1.x, 20, point1.z ),new THREE.Vector3( point1.x+1, 20, point1.z+1 ));
object = new THREE.Line( geometry, material );
for(let i=0;i<object.geometry.vertices.length;i++){
let newhelper = addlinehelper(object.geometry.vertices[i],i,splineHelperObjects,scene);
object.add(newhelper);
}
}else if(num == 2){
geometry.vertices.push(new THREE.Vector3(point1.x, 10, point1.z ),new THREE.Vector3(point1.x+0.5, 10, point1.z+0.5 ),new THREE.Vector3( point1.x+1, 10, point1.z+1 ));
object = new THREE.Line( geometry, material );
for(let i=0;i<object.geometry.vertices.length;i++){
let newhelper = addlinehelper(object.geometry.vertices[i],i,splineHelperObjects,scene);
object.add(newhelper);
}
}
return object;
}
function addlinehelper( position,num,splineHelperObjects,scene ) {
var geometry = new THREE.CircleBufferGeometry( 5,16);
var material = new THREE.MeshLambertMaterial( { color:0x0000FF } );
var object = new THREE.Mesh( geometry, material );
object.rotation.x = -Math.PI/2;
object.name = "linehelper";
object.num = num;
if ( position ) {
object.position.copy( position );
}
splineHelperObjects.push(object);
scene.add(object);
return object;
}
}

View File

@ -0,0 +1,120 @@
//轨道对象操作
export function Sectionaction(){
let scope = this;
//开关
this.on = true;
//修改名称
this.setname = function(){
if(scope.on == true){
}
}
//改变类型
this.settype = function(){
if(scope.on == true){
}
}
//改变坐标
this.setpos = function(){
if(scope.on == true){
}
}
//改变角度
this.setrota = function(){
if(scope.on == true){
}
}
//改变拉伸值
this.setscl = function(){
if(scope.on == true){
}
}
//点击事件
this.raycaster = function(data){
console.log();
if(scope.on == true){
//定义光线
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;
console.log(data.mapdata.sectionlist.sections.modellist[0]);
for(let i=0;i<data.mapdata.sectionlist.sections.modellist.length;i++){
intersects1 = raycaster.intersectObject(data.mapdata.sectionlist.sections.modellist[i]);
if(intersects1[0]){
console.log(intersects1[0].object.code);
console.log(data.mapdata.sectionlist.sections.modellist[i].code);
if(intersects1[0].object.code == data.mapdata.sectionlist.sections.modellist[i].code){
return data.mapdata.sectionlist.sections.modellist[i];
}
}
}
return null;
}
}
this.changemodel = function(jlmap3dedit,changedata){
console.log(changedata);
let scene = jlmap3dedit.scene;
let assetloader = jlmap3dedit.assetloader;
let isnewmodel = true;
//判断是否是未加载模型
for(let i=0;i<assetloader.modellist.length;i++){
console.log(assetloader.modellist[i].assetUrl);
if(changedata.assetUrl == assetloader.modellist[i].assetUrl){
isnewmodel = false;
i = assetloader.modellist.length;
}
}
console.log(isnewmodel);
jlmap3dedit.assetloader.loadnewsection(changedata,jlmap3dedit);
// for(let i=0;i<jlmap3dedit.mapdata.signallist.list.length;i++){
// if(jlmap3dedit.selectmodel.code == jlmap3dedit.mapdata.signallist.list[i].mesh.code){
// console.log("change");
// let num = i;
//
// //判断是否修改模型
// console.log(changedata.id );
// console.log(jlmap3dedit.mapdata.signallist.list[i].mesh.name);
// if(changedata.id != jlmap3dedit.mapdata.signallist.list[i].mesh.name){
//
// if(isnewmodel == true){
// console.log("new");
// return jlmap3dedit.assetloader.loadnewasset(jlmap3dedit,changedata,num);
//
// }else{
// console.log("old");
// return jlmap3dedit.assetloader.loadoldasset(jlmap3dedit,changedata,num);
//
// }
// }else{
// console.log("same");
// return jlmap3dedit.selectmodel;
// }
//
//
// i = jlmap3dedit.mapdata.signallist.list.length+1;
// }
//
// }
}
}

View File

@ -0,0 +1,108 @@
//信号灯对象操作
export function Signalaction(){
let scope = this;
//开关
this.on = true;
//修改名称
this.setname = function(){
if(scope.on == true){
}
}
//改变类型
this.settype = function(){
if(scope.on == true){
}
}
//改变坐标
this.setpos = function(){
if(scope.on == true){
}
}
//改变角度
this.setrota = function(){
if(scope.on == true){
}
}
//改变拉伸值
this.setscl = function(){
if(scope.on == true){
}
}
//点击事件
this.raycaster = function(data){
if(scope.on == true){
//定义光线
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<data.mapdata.signallist.list.length;i++){
intersects1 = raycaster.intersectObjects( data.mapdata.signallist.list[i].mesh.children);
if(intersects1[0]){
if(intersects1[0].object.code == data.mapdata.signallist.list[i].mesh.code){
return data.mapdata.signallist.list[i].mesh;
}
}
}
return null;
}
}
this.changemodel = function(jlmap3dedit,changedata){
console.log(changedata);
let isnewmodel = true;
//判断是否是未加载模型
for(let i=0;i<jlmap3dedit.assetloader.modellist.length;i++){
console.log(jlmap3dedit.assetloader.modellist[i].assetUrl);
if(changedata.assetUrl == jlmap3dedit.assetloader.modellist[i].assetUrl){
isnewmodel = false;
i = jlmap3dedit.assetloader.modellist.length;
}
}
let scene = jlmap3dedit.scene;
for(let i=0;i<jlmap3dedit.mapdata.signallist.list.length;i++){
if(jlmap3dedit.selectmodel.code == jlmap3dedit.mapdata.signallist.list[i].mesh.code){
console.log("change");
let num = i;
//判断是否修改模型
console.log(changedata.id );
console.log(jlmap3dedit.mapdata.signallist.list[i].mesh.name);
if(changedata.id != jlmap3dedit.mapdata.signallist.list[i].mesh.name){
if(isnewmodel == true){
console.log("new");
return jlmap3dedit.assetloader.loadnewasset(jlmap3dedit,changedata,num);
}else{
console.log("old");
return jlmap3dedit.assetloader.loadoldasset(jlmap3dedit,changedata,num);
}
}else{
console.log("same");
return jlmap3dedit.selectmodel;
}
i = jlmap3dedit.mapdata.signallist.list.length+1;
}
}
}
}

View File

@ -0,0 +1,69 @@
//站台对象操作
export function Stationaction(){
let scope = this;
//开关
this.on = true;
//修改名称
this.setname = function(){
if(scope.on == true){
}
}
//改变类型
this.settype = function(){
if(scope.on == true){
}
}
//改变坐标
this.setpos = function(){
if(scope.on == true){
}
}
//改变角度
this.setrota = function(){
if(scope.on == true){
}
}
//改变拉伸值
this.setscl = function(){
if(scope.on == true){
}
}
//点击事件
this.raycaster = function(data){
if(scope.on == true){
//定义光线
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;
console.log( data.mapdata.stationstandlist);
for(let i=0;i<data.mapdata.stationstandlist.group.children.length;i++){
intersects1 = raycaster.intersectObjects( data.mapdata.stationstandlist.group.children[i].children);
if(intersects1[0]){
console.log(intersects1[0]);
console.log(data.mapdata.stationstandlist.group.children[i]);
if(intersects1[0].object.code == data.mapdata.stationstandlist.group.children[i].code){
return data.mapdata.stationstandlist.group.children[i];
}
}
}
return null;
}
}
}

View File

@ -0,0 +1,68 @@
//道岔对象操作
export function Switchaction(){
let scope = this;
//开关
this.on = true;
//修改名称
this.setname = function(){
if(scope.on == true){
}
}
//改变类型
this.settype = function(){
if(scope.on == true){
}
}
//改变坐标
this.setpos = function(){
if(scope.on == true){
}
}
//改变角度
this.setrota = function(){
if(scope.on == true){
}
}
//改变拉伸值
this.setscl = function(){
if(scope.on == true){
}
}
//点击事件
this.raycaster = function(data){
if(scope.on == true){
//定义光线
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<data.mapdata.sectionlist.switchs.modellist.length;i++){
intersects1 = raycaster.intersectObjects( data.mapdata.sectionlist.switchs.modellist[i].children);
if(intersects1[0]){
if(intersects1[0].object.code == data.mapdata.sectionlist.switchs.modellist[i].code){
//console.log(intersects1[0].object.name);
return data.mapdata.sectionlist.switchs.modellist[i];
}
}
}
return null;
}
}
}

View File

@ -0,0 +1,68 @@
//列车对象操作
export function Trainaction(){
let scope = this;
//开关
this.on = true;
//修改名称
this.setname = function(){
if(scope.on == true){
}
}
//改变类型
this.settype = function(){
if(scope.on == true){
}
}
//改变坐标
this.setpos = function(){
if(scope.on == true){
}
}
//改变角度
this.setrota = function(){
if(scope.on == true){
}
}
//改变拉伸值
this.setscl = function(){
if(scope.on == true){
}
}
//点击事件
this.raycaster = function(data){
if(scope.on == true){
//定义光线
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<data.mapdata.trainlisttest.list.length;i++){
intersects1 = raycaster.intersectObjects( data.mapdata.trainlisttest.list[i].children);
if(intersects1[0]){
if(intersects1[0].object.name == data.mapdata.trainlisttest.list[i].name){
//console.log(intersects1[0].object.name);
console.log(data.mapdata.trainlisttest.list[i]);
return data.mapdata.trainlisttest.list[i];
}
}
}
return null;
}
}
}

View File

@ -0,0 +1,40 @@
import {Pathaction} from '@/jlmap3d/edit/action/pathaction'
import {Sectionaction} from '@/jlmap3d/edit/action/sectionaction'
import {Signalaction} from '@/jlmap3d/edit/action/signalaction'
import {Stationaction} from '@/jlmap3d/edit/action/stationaction'
import {Trainaction} from '@/jlmap3d/edit/action/trainaction'
import {Switchaction} from '@/jlmap3d/edit/action/switchaction'
//对象操作管理器你
export function Actionmanage(){
let scope = this;
//开关
this.pathaction = new Pathaction();
this.sectionaction = new Sectionaction();
this.signalaction = new Signalaction();
this.stationaction = new Stationaction();
this.trainaction = new Trainaction();
this.switchaction = new Switchaction();
this.dispose = function(){
this.pathaction = null;
this.sectionaction = null;
this.signalaction = null;
this.stationaction = null;
this.trainaction = null;
this.switchaction = null;
}
}

View File

@ -0,0 +1,134 @@
//import request from '@/utils/request';
export function getmodels(data) {
console.log(data);
let postmap = {
id:data.mapdata.id,
mapId:data.mapdata.mapId,
assets:"null",
sections:"null",
signals:"null",
trains:"null",
stands:"null",
switchs:"null"
};
if(data.mapdata.sectionlist.sections== undefined){
return postmap;
}
if(data == undefined){
return postmap;
}else{
//资源
let assets = [];
for(let i=0;i<data.assetloader.modellist.length;i++){
let asset = {
id:data.assetloader.modellist[i].id,
name:data.assetloader.modellist[i].name,
deviceType:data.assetloader.modellist[i].deviceType,
type:data.assetloader.modellist[i].type,
assetUrl:data.assetloader.modellist[i].assetUrl
}
assets.push(asset);
}
postmap.assets = JSON.stringify(assets);
//区段
let sections = [];
for(let i=0;i<data.mapdata.sectionlist.sections.datalist.length;i++){
let section = {
uuid:data.mapdata.sectionlist.sections.datalist[i].uuid,
name:data.mapdata.sectionlist.sections.datalist[i].name,
index:data.mapdata.sectionlist.sections.datalist[i].index,
isStandTrack:data.mapdata.sectionlist.sections.datalist[i].isStandTrack,
rail:data.mapdata.sectionlist.sections.datalist[i].rail,
distance:data.mapdata.sectionlist.sections.datalist[i].distance,
position:data.mapdata.sectionlist.sections.modellist[i].position,
rotation:data.mapdata.sectionlist.sections.modellist[i].rotation,
scale:data.mapdata.sectionlist.sections.modellist[i].scale
}
sections.push(section);
}
postmap.sections = JSON.stringify(sections);
//道岔
let switchs = [];
for(let i=0;i<data.mapdata.sectionlist.switchs.datalist.length;i++){
console.log(data.mapdata.sectionlist.switchs.datalist);
let switcha = {
uuid:data.mapdata.sectionlist.switchs.datalist[i].uuid,
name:data.mapdata.sectionlist.switchs.datalist[i].name,
index:data.mapdata.sectionlist.switchs.datalist[i].index,
position:data.mapdata.sectionlist.switchs.modellist[i].position,
rotation:data.mapdata.sectionlist.switchs.modellist[i].rotation,
scale:data.mapdata.sectionlist.switchs.modellist[i].scale
}
switchs.push(switcha);
}
postmap.switchs = JSON.stringify(switchs);
//信号
let signals = [];
for(let i=0;i<data.mapdata.signallist.list.length;i++){
let signal = {
uuid:data.mapdata.signallist.list[i].mesh.uuid,
name:data.mapdata.signallist.list[i].mesh.name,
modelid:data.mapdata.signallist.list[i].mesh.modelid,
code:data.mapdata.signallist.list[i].mesh.code,
position:data.mapdata.signallist.list[i].mesh.position,
rotation:data.mapdata.signallist.list[i].mesh.rotation,
scale:data.mapdata.signallist.list[i].mesh.scale
}
signals.push(signal);
}
postmap.signals = JSON.stringify(signals);
//车站
let stands = [];
for(let i=0;i<data.mapdata.stationstandlist.list.length;i++){
console.log(data.mapdata.stationstandlist.list[i]);
let station = {
uuid:data.mapdata.stationstandlist.list[i].uuid,
code:data.mapdata.stationstandlist.list[i].code,
name:data.mapdata.stationstandlist.list[i].name,
modelid:data.mapdata.stationstandlist.list[i].modelid,
position:data.mapdata.stationstandlist.list[i].mesh.position,
rotation:data.mapdata.stationstandlist.list[i].mesh.rotation,
scale:data.mapdata.stationstandlist.list[i].mesh.scale,
direction1:{
name:data.mapdata.stationstandlist.list[i].direction1.name,
code:null
},
direction2:{
name:data.mapdata.stationstandlist.list[i].direction1.name,
code:null
}
}
stands.push(station);
}
postmap.stands = JSON.stringify(stands);
//列车
let trains = [];
for(let i=0;i<data.assetloader.modellist.length;i++){
if(data.assetloader.modellist[i].deviceType == "train"){
let train = {
id:data.assetloader.modellist[i].id,
name:data.assetloader.modellist[i].name,
deviceType:data.assetloader.modellist[i].deviceType,
type:data.assetloader.modellist[i].type,
assetUrl:data.assetloader.modellist[i].assetUrl
}
trains.push(train);
}
}
postmap.trains = JSON.stringify(trains);
return postmap;
}
}

View File

@ -0,0 +1,10 @@
import request from '@/utils/request';
/** 获取路径单元列表*/
export function getmodels(data) {
return request({
url: 'http://192.168.3.23:1337/model_load',
method: 'get',
params: data
});
}

View File

@ -0,0 +1,286 @@
/*
* @author zz85 / https://github.com/zz85
* @author mrdoob / http://mrdoob.com
* Running this will allow you to drag three.js objects around the screen.
*/
THREE.DragControls = function ( _objects, _camera, _domElement ) {
if ( _objects instanceof THREE.Camera ) {
console.warn( 'THREE.DragControls: Constructor now expects ( objects, camera, domElement )' );
var temp = _objects; _objects = _camera; _camera = temp;
}
var _plane = new THREE.Plane();
var _raycaster = new THREE.Raycaster();
var _mouse = new THREE.Vector2();
var _offset = new THREE.Vector3();
var _intersection = new THREE.Vector3();
var _worldPosition = new THREE.Vector3();
var _inverseMatrix = new THREE.Matrix4();
var _selected = null, _hovered = null;
//
var scope = this;
function activate() {
_domElement.addEventListener( 'mousemove', onDocumentMouseMove, false );
_domElement.addEventListener( 'mousedown', onDocumentMouseDown, false );
_domElement.addEventListener( 'mouseup', onDocumentMouseCancel, false );
_domElement.addEventListener( 'mouseleave', onDocumentMouseCancel, false );
_domElement.addEventListener( 'touchmove', onDocumentTouchMove, false );
_domElement.addEventListener( 'touchstart', onDocumentTouchStart, false );
_domElement.addEventListener( 'touchend', onDocumentTouchEnd, false );
}
function deactivate() {
_domElement.removeEventListener( 'mousemove', onDocumentMouseMove, false );
_domElement.removeEventListener( 'mousedown', onDocumentMouseDown, false );
_domElement.removeEventListener( 'mouseup', onDocumentMouseCancel, false );
_domElement.removeEventListener( 'mouseleave', onDocumentMouseCancel, false );
_domElement.removeEventListener( 'touchmove', onDocumentTouchMove, false );
_domElement.removeEventListener( 'touchstart', onDocumentTouchStart, false );
_domElement.removeEventListener( 'touchend', onDocumentTouchEnd, false );
}
function dispose() {
deactivate();
}
function onDocumentMouseMove( event ) {
event.preventDefault();
var rect = _domElement.getBoundingClientRect();
_mouse.x = ( ( event.clientX - rect.left ) / rect.width ) * 2 - 1;
_mouse.y = - ( ( event.clientY - rect.top ) / rect.height ) * 2 + 1;
_raycaster.setFromCamera( _mouse, _camera );
if ( _selected && scope.enabled ) {
if ( _raycaster.ray.intersectPlane( _plane, _intersection ) ) {
_selected.position.copy( _intersection.sub( _offset ).applyMatrix4( _inverseMatrix ) );
}
scope.dispatchEvent( { type: 'drag', object: _selected } );
return;
}
_raycaster.setFromCamera( _mouse, _camera );
var intersects = _raycaster.intersectObjects( _objects );
if ( intersects.length > 0 ) {
var object = intersects[ 0 ].object;
_plane.setFromNormalAndCoplanarPoint( _camera.getWorldDirection( _plane.normal ), _worldPosition.setFromMatrixPosition( object.matrixWorld ) );
if ( _hovered !== object ) {
scope.dispatchEvent( { type: 'hoveron', object: object } );
_domElement.style.cursor = 'pointer';
_hovered = object;
}
} else {
if ( _hovered !== null ) {
scope.dispatchEvent( { type: 'hoveroff', object: _hovered } );
_domElement.style.cursor = 'auto';
_hovered = null;
}
}
}
function onDocumentMouseDown( event ) {
event.preventDefault();
_raycaster.setFromCamera( _mouse, _camera );
var intersects = _raycaster.intersectObjects( _objects );
if ( intersects.length > 0 ) {
_selected = intersects[ 0 ].object;
if ( _raycaster.ray.intersectPlane( _plane, _intersection ) ) {
_inverseMatrix.getInverse( _selected.parent.matrixWorld );
_offset.copy( _intersection ).sub( _worldPosition.setFromMatrixPosition( _selected.matrixWorld ) );
}
_domElement.style.cursor = 'move';
scope.dispatchEvent( { type: 'dragstart', object: _selected } );
}
}
function onDocumentMouseCancel( event ) {
event.preventDefault();
if ( _selected ) {
scope.dispatchEvent( { type: 'dragend', object: _selected } );
_selected = null;
}
_domElement.style.cursor = _hovered ? 'pointer' : 'auto';
}
function onDocumentTouchMove( event ) {
event.preventDefault();
event = event.changedTouches[ 0 ];
var rect = _domElement.getBoundingClientRect();
_mouse.x = ( ( event.clientX - rect.left ) / rect.width ) * 2 - 1;
_mouse.y = - ( ( event.clientY - rect.top ) / rect.height ) * 2 + 1;
_raycaster.setFromCamera( _mouse, _camera );
if ( _selected && scope.enabled ) {
if ( _raycaster.ray.intersectPlane( _plane, _intersection ) ) {
_selected.position.copy( _intersection.sub( _offset ).applyMatrix4( _inverseMatrix ) );
}
scope.dispatchEvent( { type: 'drag', object: _selected } );
return;
}
}
function onDocumentTouchStart( event ) {
event.preventDefault();
event = event.changedTouches[ 0 ];
var rect = _domElement.getBoundingClientRect();
_mouse.x = ( ( event.clientX - rect.left ) / rect.width ) * 2 - 1;
_mouse.y = - ( ( event.clientY - rect.top ) / rect.height ) * 2 + 1;
_raycaster.setFromCamera( _mouse, _camera );
var intersects = _raycaster.intersectObjects( _objects );
if ( intersects.length > 0 ) {
_selected = intersects[ 0 ].object;
_plane.setFromNormalAndCoplanarPoint( _camera.getWorldDirection( _plane.normal ), _worldPosition.setFromMatrixPosition( _selected.matrixWorld ) );
if ( _raycaster.ray.intersectPlane( _plane, _intersection ) ) {
_inverseMatrix.getInverse( _selected.parent.matrixWorld );
_offset.copy( _intersection ).sub( _worldPosition.setFromMatrixPosition( _selected.matrixWorld ) );
}
_domElement.style.cursor = 'move';
scope.dispatchEvent( { type: 'dragstart', object: _selected } );
}
}
function onDocumentTouchEnd( event ) {
event.preventDefault();
if ( _selected ) {
scope.dispatchEvent( { type: 'dragend', object: _selected } );
_selected = null;
}
_domElement.style.cursor = 'auto';
}
activate();
// API
this.enabled = true;
this.activate = activate;
this.deactivate = deactivate;
this.dispose = dispose;
// Backward compatibility
this.setObjects = function () {
console.error( 'THREE.DragControls: setObjects() has been removed.' );
};
this.on = function ( type, listener ) {
console.warn( 'THREE.DragControls: on() has been deprecated. Use addEventListener() instead.' );
scope.addEventListener( type, listener );
};
this.off = function ( type, listener ) {
console.warn( 'THREE.DragControls: off() has been deprecated. Use removeEventListener() instead.' );
scope.removeEventListener( type, listener );
};
this.notify = function ( type ) {
console.error( 'THREE.DragControls: notify() has been deprecated. Use dispatchEvent() instead.' );
scope.dispatchEvent( { type: type } );
};
};
THREE.DragControls.prototype = Object.create( THREE.EventDispatcher.prototype );
THREE.DragControls.prototype.constructor = THREE.DragControls;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,31 @@
export function LinkList(data,scene){
let groups = new THREE.Group();
let linklist = [];
for(let i=0;i<data.length;i++){
let lineGeometry = new THREE.Geometry();//生成几何体
lineGeometry.vertices.push(new THREE.Vector3(data[i].lp.x, 1, data[i].lp.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({
color: 0x080808,//线段的颜色
dashSize: 1,//短划线的大小
gapSize: 3//短划线之间的距离
}));
line.name = data[i].code;
line.lengthFact = data[i].lengthFact;
line.lp = data[i].lp;
line.rp = data[i].rp;
line.distancex = data[i].rp.x-data[i].lp.x;
line.distancey = data[i].rp.y-data[i].lp.y;
line.computeLineDistances();//不可或缺的,若无,则线段不能显示为虚线
groups.add(line);
groups.position.z = 400;
linklist.push(line);
}
scene.add(groups);
return linklist;
}

View File

@ -0,0 +1,184 @@
import {RealSectionModel} from '@/jlmap3d/edit/testmodel/RealSectionModel.js';
export function RealSectionList(data) {
let scope = this;
this.type = "sectionlist";
this.list = [];
this.group = [];
this.switch = [];
this.initpromise = function(jlmap3ddata,scene,assetloader){
return new Promise(function(resolve, reject){
let modelnum = null;
for(let i=0;i<assetloader.modellist.length;i++){
if(assetloader.modellist[i].deviceType == "mapSection"){
modelnum = i;
}
}
let newmesh = assetloader.modellist[modelnum].mesh;
//let mixer = new THREE.AnimationMixer( newmesh );
////console.log(jlmap3ddata.sectionlist);
for(let i=0;i<newmesh.children.length;i++){
let name = newmesh.children[i].name.split("_");
let newmeshname = name[0]+"_"+name[1]+"_"+name[2]+"."+name[3];
////console.log(newmeshname);
if(name[0] == "Switch"){
for(let j=0;j<jlmap3ddata.sectionlist.switchs.datalist.length;j++){
if(jlmap3ddata.sectionlist.switchs.datalist[j].name == newmeshname){
//绿色道岔
var box = new THREE.BoxHelper( newmesh.children[i], 0x00EE00 );
scene.add(box);
let nowname = jlmap3ddata.sectionlist.switchs.datalist[j].name;
let nowcode = jlmap3ddata.sectionlist.switchs.datalist[j].code;
newmesh.children[i].name = nowname;
newmesh.children[i].code = nowcode;
for(let n=0;n<newmesh.children[i].children.length;n++){
newmesh.children[i].children[n].code = nowcode;
}
jlmap3ddata.sectionlist.switchs.modellist[j] = newmesh.children[i];
j = jlmap3ddata.sectionlist.switchs.datalist.length;
}
}
}
if(name[0] == "Section"){
//console.log(newmesh.children[i]);
//物理区段
for(let j=0;j<jlmap3ddata.sectionlist.sections.datalist.length;j++){
if(jlmap3ddata.sectionlist.sections.datalist[j].name == newmeshname){
if(jlmap3ddata.sectionlist.sections.datalist[j].isStandTrack == true){
//红色站台区段
var box = new THREE.BoxHelper( newmesh.children[i], 0xff0000 );
}else{
//蓝色其他区段
var box = new THREE.BoxHelper( newmesh.children[i], 0x0000ff );
}
scene.add( box );
let nowname = jlmap3ddata.sectionlist.sections.datalist[j].name;
let nowcode = jlmap3ddata.sectionlist.sections.datalist[j].code;
newmesh.children[i].name = nowname;
newmesh.children[i].code = nowcode;
jlmap3ddata.sectionlist.sections.modellist[j] = newmesh.children[i];
j = jlmap3ddata.sectionlist.sections.datalist.length;
}
}
}
}
scene.add(newmesh);
resolve("loadedrealsection");
});
}
this.init = function(jlmap3ddata,scene,assetloader){
let newmesh = assetloader.modellist[2].mesh;
//let mixer = new THREE.AnimationMixer( newmesh );
////console.log(jlmap3ddata.sectionlist);
for(let i=0;i<newmesh.children.length;i++){
let name = newmesh.children[i].name.split("_");
let newmeshname = name[0]+"_"+name[1]+"_"+name[2]+"."+name[3];
////console.log(newmeshname);
if(name[0] == "Switch"){
for(let j=0;j<jlmap3ddata.sectionlist.switchs.datalist.length;j++){
if(jlmap3ddata.sectionlist.switchs.datalist[j].name == newmeshname){
//绿色道岔
var box = new THREE.BoxHelper( newmesh.children[i], 0x00EE00 );
scene.add(box);
let nowname = jlmap3ddata.sectionlist.switchs.datalist[j].name;
let nowcode = jlmap3ddata.sectionlist.switchs.datalist[j].code;
newmesh.children[i].name = nowname;
newmesh.children[i].code = nowcode;
for(let n=0;n<newmesh.children[i].children.length;n++){
newmesh.children[i].children[n].code = nowcode;
}
jlmap3ddata.sectionlist.switchs.modellist[j] = newmesh.children[i];
j = jlmap3ddata.sectionlist.switchs.datalist.length;
}
}
}
if(name[0] == "Section"){
//物理区段
for(let j=0;j<jlmap3ddata.sectionlist.sections.datalist.length;j++){
if(jlmap3ddata.sectionlist.sections.datalist[j].name == newmeshname){
if(jlmap3ddata.sectionlist.sections.datalist[j].isStandTrack == true){
//红色站台区段
var box = new THREE.BoxHelper( newmesh.children[i], 0xff0000 );
}else{
//蓝色其他区段
var box = new THREE.BoxHelper( newmesh.children[i], 0x0000ff );
}
scene.add( box );
let nowname = jlmap3ddata.sectionlist.sections.datalist[j].name;
let nowcode = jlmap3ddata.sectionlist.sections.datalist[j].code;
newmesh.children[i].name = nowname;
newmesh.children[i].code = nowcode;
jlmap3ddata.sectionlist.sections.modellist[j] = newmesh.children[i];
j = jlmap3ddata.sectionlist.sections.datalist.length;
}
}
}
if(name[0] == "Singal"){
for(let j=0;j<jlmap3ddata.signallist.list.length;j++){
if(jlmap3ddata.signallist.list[j].mesh.code == newmeshname){
jlmap3ddata.signallist.list[j].mesh.position.x = newmesh.children[i].position.x;
jlmap3ddata.signallist.list[j].mesh.position.y = newmesh.children[i].position.y;
jlmap3ddata.signallist.list[j].mesh.position.z = newmesh.children[i].position.z;
j = jlmap3ddata.signallist.list.length;
}
}
}
}
scene.add(newmesh);
}
this.update = function(){
}
this.renderon = function(){
}
this.renderoff = function(){
}
this.dispose = function(){
}
}

View File

@ -0,0 +1,8 @@
export function RealSectionModel(data) {
var scope = this;
this.mesh = null;
this.meshurl = null;
this.picurl = null;
}

View File

@ -0,0 +1,185 @@
import {SectionModel} from '@/jlmap3d/edit/testmodel/SectionModel.js';
import {SwitchModel} from '@/jlmap3d/edit/testmodel/SwitchModel.js';
export function SectionList() {
let scope = this;
this.type = "sectionlist";
this.sections = {
datalist:[],
modellist:[]
};
this.switchs = {
datalist:[],
modellist:[]
};
this.initpromise = function (sectiondata,switchdata,scene){
return new Promise(function(resolve, reject){
//遍历区段
for(let i=0;i<sectiondata.length;i++){
if(sectiondata[i].type == "01"){
//初始化区段对象数据
let newsection = new SectionModel(sectiondata);
newsection.name = sectiondata[i].code;
newsection.code = sectiondata[i].code;
newsection.index = i;
newsection.isStandTrack = sectiondata[i].isStandTrack;
newsection.type = sectiondata[i].type;
scope.sections.datalist.push(newsection);
scope.sections.modellist.push("");
}
}
//定义区分道岔组
let switchlist = [];
//遍历道岔数据
for(let i=0;i<switchdata.length;i++){
//道岔信息
let newswitch = {
code:null,
pa:null,
pb:null,
pc:null,
paname:null,
pbname:null,
pcname:null
};
//获取道岔分辨的点 PS:可能修改动态判断
for(let j=0;j<sectiondata.length;j++){
if(switchdata[i].sectionACode == sectiondata[j].code){
newswitch.pa = sectiondata[j].points;
newswitch.paname = switchdata[i].sectionACode;
}
if(switchdata[i].sectionBCode == sectiondata[j].code){
newswitch.pb = sectiondata[j].points;
newswitch.pbname = switchdata[i].sectionBCode;
}
if(switchdata[i].sectionCCode == sectiondata[j].code){
newswitch.pc = sectiondata[j].points;
newswitch.pcname = switchdata[i].sectionCCode;
}
if(newswitch.pa != null && newswitch.pb!= null && newswitch.pc != null){
newswitch.code = switchdata[i].code;
switchlist.push(newswitch);
j = sectiondata.length;
}
}
}
//道岔贴图
//遍历道岔信息组合轨道
for(let i=0;i<switchlist.length;i++){
//道岔对象组
let newswitch = new SwitchModel();
newswitch.name = switchlist[i].code;
newswitch.code = switchlist[i].code;
newswitch.index = i;
scope.switchs.datalist.push(newswitch);
scope.switchs.modellist.push("");
}
resolve("loadersection");
});
}
this.init = function(sectiondata,switchdata,scene){
//遍历区段
for(let i=0;i<sectiondata.length;i++){
if(sectiondata[i].type == "01"){
//初始化区段对象数据
let newsection = new SectionModel(sectiondata);
newsection.name = sectiondata[i].code;
newsection.code = sectiondata[i].code;
newsection.index = i;
newsection.isStandTrack = sectiondata[i].isStandTrack;
newsection.type = sectiondata[i].type;
scope.sections.datalist.push(newsection);
scope.sections.modellist.push("");
}
}
//定义区分道岔组
let switchlist = [];
//遍历道岔数据
for(let i=0;i<switchdata.length;i++){
//道岔信息
let newswitch = {
code:null,
pa:null,
pb:null,
pc:null,
paname:null,
pbname:null,
pcname:null
};
//获取道岔分辨的点 PS:可能修改动态判断
for(let j=0;j<sectiondata.length;j++){
if(switchdata[i].sectionACode == sectiondata[j].code){
newswitch.pa = sectiondata[j].points;
newswitch.paname = switchdata[i].sectionACode;
}
if(switchdata[i].sectionBCode == sectiondata[j].code){
newswitch.pb = sectiondata[j].points;
newswitch.pbname = switchdata[i].sectionBCode;
}
if(switchdata[i].sectionCCode == sectiondata[j].code){
newswitch.pc = sectiondata[j].points;
newswitch.pcname = switchdata[i].sectionCCode;
}
if(newswitch.pa != null && newswitch.pb!= null && newswitch.pc != null){
newswitch.code = switchdata[i].code;
switchlist.push(newswitch);
j = sectiondata.length;
}
}
}
//道岔贴图
//遍历道岔信息组合轨道
for(let i=0;i<switchlist.length;i++){
//道岔对象组
let newswitch = new SwitchModel();
newswitch.name = switchlist[i].code;
newswitch.code = switchlist[i].code;
newswitch.index = i;
scope.switchs.datalist.push(newswitch);
scope.switchs.modellist.push("");
}
}
this.update = function(){
}
this.renderon = function(){
}
this.renderoff = function(){
}
this.dispose = function(){
}
}

View File

@ -0,0 +1,26 @@
export function SectionModel(data) {
var scope = this;
//命名
this.name = null;
//code
this.code = null;
//索引位置
this.index = null;
//轨迹点
this.rail = [];
this.railline = null;
//长度
this.distance = [];
this.isStandTrack = null;
this.type = null;
//指向模型
this.mesh = null;
// //模型地址
// this.meshurl = null;
// //贴图地址
// this.picurl = null;
}

View File

@ -0,0 +1,145 @@
import {SignalModel} from '@/jlmap3d/model/SignalModel.js';
export function SignalList() {
let scope = this;
this.type = "signallist";
this.list = [];
this.group = new THREE.Group();
this.initpromise = function(data,scene,assetloader,netdata){
return new Promise(function(resolve, reject){
scope.group.name = "signal";
//遍历信号数据
let netsignal = null;
let haddata = false;
if(netdata){
netsignal = JSON.parse(netdata);
haddata = true;
}
for(let i=0;i<data.length;i++){
let newsignal = new SignalModel(data[i]);
let num;
if(haddata == false){
for(let j=0;j<assetloader.modellist.length;j++){
if(assetloader.modellist[j].deviceType == "signal"){
num = j;
}
}
let newmesh = assetloader.modellist[num].mesh.clone(true);
newmesh.name = assetloader.modellist[num].name;
newmesh.modelid = assetloader.modellist[num].id;
newmesh.code = data[i].code;
for(let j=0;j<newmesh.children.length;j++){
newmesh.children[j].code = data[i].code;
}
//根据线路方向修改信号灯位置
if(data[i].directionType == "01"){
newmesh.position.set(data[i].position.x,1,data[i].position.y-10);
newmesh.rotation.z = ( Math.PI / 2 );
}else if(data[i].directionType == "02"){
newmesh.position.set(data[i].position.x,1,data[i].position.y+10);
newmesh.rotation.z = ( - Math.PI / 2 );
}
newsignal.mesh = newmesh;
newsignal.mesh.status = "01";
scope.group.add(newsignal.mesh);
scope.list.push(newsignal);
}else{
for(let j=0;j<assetloader.modellist.length;j++){
if(assetloader.modellist[j].id == netsignal[i].modelid){
num = j;
}
}
let newmesh = assetloader.modellist[num].mesh.clone(true);
newmesh.uuid = netsignal[i].id;
newmesh.name = netsignal[i].name;
newmesh.modelid = assetloader.modellist[num].id;
newmesh.code = netsignal[i].code;
for(let j=0;j<newmesh.children.length;j++){
newmesh.children[j].code = netsignal[i].code;
}
newmesh.position.x = netsignal[i].position.x;
newmesh.position.y = netsignal[i].position.y;
newmesh.position.z = netsignal[i].position.z;
newmesh.rotation.x = netsignal[i].rotation._x;
newmesh.rotation.y = netsignal[i].rotation._y;
newmesh.rotation.z = netsignal[i].rotation._z;
newmesh.scale.x = netsignal[i].scale.x;
newmesh.scale.y = netsignal[i].scale.y;
newmesh.scale.z = netsignal[i].scale.z;
newsignal.mesh = newmesh;
newsignal.mesh.status = "01";
scope.group.add(newsignal.mesh);
scope.list.push(newsignal);
}
}
scene.add(scope.group);
resolve("loadedsignal");
});
}
this.init = function(data,realsectionlist,scene,assetloader){
scope.group.name = "signal";
//遍历信号数据
for(let i=0;i<data.length;i++){
let newsignal = new SignalModel(data);
let newmesh = assetloader.modellist[0].mesh.clone(true);
newmesh.name = assetloader.modellist[0].id;
newmesh.code = data[i].code;
for(let j=0;j<newmesh.children.length;j++){
newmesh.children[j].code = data[i].code;
}
//根据线路方向修改信号灯位置
if(data[i].directionType == "01"){
newmesh.position.set(data[i].position.x,1,data[i].position.y-10);
newmesh.rotation.z = ( Math.PI / 2 );
}else if(data[i].directionType == "02"){
newmesh.position.set(data[i].position.x,1,data[i].position.y+10);
newmesh.rotation.z = ( - Math.PI / 2 );
}
//newmesh.scale.set(0.1,0.1,0.1);
newsignal.mesh = newmesh;
newsignal.mesh.status = "01";
scope.group.add(newsignal.mesh);
scope.list.push(newsignal);
}
scene.add(scope.group);
}
this.update = function(){
}
this.renderon = function(){
}
this.renderoff = function(){
}
this.dispose = function(){
}
}

View File

@ -0,0 +1,36 @@
export function SignalModel(data) {
this.uuid = null;
this.code = null;
this.name = null;
this.modelid = null;
this.type = null;
this.direction = null;
this.ismodel = false;
this.istexture = false;
this.modelurl = null;
// this.textures = {
// red:null,
// yellor:null,
// green:null
// }
// this.position = {
// x:0,
// y:0,
// z:0
// };
// this.rotation = {
// x:0,
// y:0,
// z:0
// };
// this.scale = {
// x:0,
// y:0,
// z:0
// }
this.mesh = null;
this.meshurl = null;
this.picurl = null;
}

View File

@ -0,0 +1,183 @@
import {StationStandModel} from '@/jlmap3d/model/StationStandModel.js';
export function StationStandList() {
let scope = this;
this.type = "stationstandlist";
this.list = [];
this.group = new THREE.Group();
this.textlist = [];
this.initpromise = function(stationdata,stationstanddata,scene,assetloader,netdata){
return new Promise(function(resolve, reject){
let netstand = null;
let haddata = false;
if(netdata){
netstand = JSON.parse(netdata);
haddata = true;
}
scope.group.name = "station";
scene.add(scope.group);
//遍历车站数据
for(let i=0;i<stationdata.length;i++){
let newstationstand = new StationStandModel(stationdata);
//判断站台是否显示
if(stationdata[i].visible == true){
//遍历车站站台数据
for(let j=0;j<stationstanddata.length;j++){
//收集有效车站数据
if(stationstanddata[j].stationCode == stationdata[i].code){
newstationstand.name = stationdata[i].name;
newstationstand.code = stationdata[i].code;
if(stationstanddata[j].direction == "01"){
newstationstand.direction1.position = stationstanddata[j].position;
newstationstand.direction1.name = stationstanddata[j].code;
newstationstand.direction1.screenDoorOpenStatus = "01";
newstationstand.width = stationstanddata[j].width*2;
newstationstand.height = stationstanddata[j].height;
}
if(stationstanddata[j].direction == "02"){
newstationstand.direction2.position = stationstanddata[j].position;
newstationstand.direction2.name = stationstanddata[j].code;
newstationstand.direction2.screenDoorOpenStatus = "01";
}
}
}
scope.list.push(newstationstand);
}
}
//建立需要显示车的车站模型对象
for(let i=0;i<scope.list.length;i++){
let num;
if(haddata == false){
for(let j=0;j<assetloader.modellist.length;j++){
if(assetloader.modellist[j].deviceType == "stand"){
num = j;
}
}
scope.list[i].mesh = assetloader.modellist[num].mesh.clone(true);
scope.list[i].uuid = assetloader.modellist[num].uuid;
scope.list[i].id = assetloader.modellist[num].id;
scope.list[i].modelid = assetloader.modellist[num].id;
scope.list[i].mesh.code = scope.list[i].code;
for(let j=0;j<scope.list[i].mesh.children.length;j++){
scope.list[i].mesh.children[j].code = scope.list[i].code;
}
scope.list[i].mesh.position.set(scope.list[i].direction1.position.x,-20000,( scope.list[i].direction2.position.y + scope.list[i].direction1.position.y)/2+scope.list[i].height/2 );
let textgeometry = new THREE.PlaneBufferGeometry( 128, 64, 1 );
let textmaterial = new THREE.MeshBasicMaterial( { side: THREE.DoubleSide,map: new THREE.CanvasTexture(getTextCanvas(stationdata[i])),transparent: true} );
let textplane = new THREE.Mesh( textgeometry, textmaterial );
textplane.name = stationdata[i].code;
textplane.position.y = 60;
textplane.rotation.x = 30;
//textplane.position.x = -30;
scope.list[i].mesh.add(textplane);
scope.group.add(scope.list[i].mesh);
}else{
for(let j=0;j<assetloader.modellist.length;j++){
if(assetloader.modellist[j].id == netstand[i].modelid){
num = j;
}
}
scope.list[i].mesh = assetloader.modellist[num].mesh.clone(true);
scope.list[i].mesh.name = netstand[i].name;
scope.list[i].mesh.code = netstand[i].code;
scope.list[i].id = netstand[i].id;
scope.list[i].modelid = netstand[i].modelid;
for(let j=0;j<scope.list[i].mesh.children.length;j++){
scope.list[i].mesh.children[j].code = netstand[i].code;
}
scope.list[i].mesh.position.x = netstand[i].position.x;
scope.list[i].mesh.position.y = netstand[i].position.y;
scope.list[i].mesh.position.z = netstand[i].position.z;
// scope.list[i].mesh.rotation.x = netstand[i].rotation._x;
// scope.list[i].mesh.rotation.y = netstand[i].rotation._y;
// scope.list[i].mesh.rotation.z = netstand[i].rotation._z;
scope.list[i].mesh.scale.x = netstand[i].scale.x;
scope.list[i].mesh.scale.y = netstand[i].scale.y;
scope.list[i].mesh.scale.z = netstand[i].scale.z;
let textgeometry = new THREE.PlaneBufferGeometry( 128, 64, 1 );
let textmaterial = new THREE.MeshBasicMaterial( { side: THREE.DoubleSide,map: new THREE.CanvasTexture(getTextCanvas(stationdata[i])),transparent: true} );
let textplane = new THREE.Mesh( textgeometry, textmaterial );
textplane.name = stationdata[i].code;
textplane.position.y = 60;
textplane.rotation.x = 30;
//textplane.position.x = -30;
scope.list[i].mesh.add(textplane);
scope.group.add(scope.list[i].mesh);
}
// scene.add(plane);
}
resolve("loadedstation");
});
}
this.update = function(){
}
this.renderon = function(){
}
this.renderoff = function(){
}
this.dispose = function(){
}
}
//canvas文字贴图方法
//PS:待提炼 增强功能
function getTextCanvas(text){
var canvas = document.getElementById('canvastexture');
// let width = 128;
// let height = 64;
// canvas.style.width = width + "px";
// canvas.style.height = height + "px";
var ctx = canvas.getContext('2d');
ctx.fillStyle = '#FFFFFF';
ctx.fillRect(0, 0,128,64);
ctx.font = "500px";
ctx.fillStyle = '#000000';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.clearRect(0,0,128,64);
ctx.fillText(text.name, 128/2,64/4);
ctx.fillText(text.runPlanName, 128/2,64*2/4);
ctx.fillText(text.kmPost, 128/2,64*3/4);
let data = ctx.getImageData(0, 0,128,64);
return data;
}

View File

@ -0,0 +1,35 @@
export function StationStandModel(opts) {
var scope = this;
this.uuid = null;
this.code = null;
this.name = null;
this.modelid = null;
this.type = null;
this.ismodel = false;
this.istexture = false;
this.modelurl = null;
this.direction1= {
position:null,
name:null,
screenDoorOpenStatus:null,
mesh:null,
openpos:[],
closepos:[]
}
this.direction2= {
position:null,
name:null,
screenDoorOpenStatus:null,
mesh:null,
openpos:[],
closepos:[]
}
this.mesh = null;
this.meshurl = null;
this.picurl = null;
}

View File

@ -0,0 +1,29 @@
import {SwitchModel} from '@/jlmap3d/model/SwitchModel.js';
export function SwitchList() {
this.type = "switchlist";
this.list = null;
this.init = function(){
}
this.update = function(){
}
this.renderon = function(){
}
this.renderoff = function(){
}
this.dispose = function(){
}
}

View File

@ -0,0 +1,22 @@
export function SwitchModel() {
var scope = this;
//命名
this.name = null;
//code
this.code = null;
//索引位置
this.index = null;
//轨迹点
this.rail = [];
//长度
this.distance = null;
this.action = null;
//指向模型
this.mesh = null;
// //模型地址
// this.meshurl = null;
// //贴图地址
// this.picurl = null;
}

View File

@ -0,0 +1,107 @@
import {TrainModel} from '@/jlmap3d/model/TrainModel.js';
export function TrainList() {
let scope = this;
this.type = "trainlist";
this.list = [];
this.group = [];
this.textlist = [];
this.init = function(data,scene){
scope.group = new THREE.Group();
scope.group.name = "train";
scene.add(scope.group);
// model
THREE.Loader.Handlers.add( /\.dds$/i, new THREE.DDSLoader() ) ;
for(let i=0;i<data.length;i++){
new THREE.MTLLoader().setPath( '../../static/model/train/' ).load( 'train.mtl', function ( materials ) {
materials.preload();
new THREE.OBJLoader().setMaterials( materials ).setPath( '../../static/model/train/' ).load( 'train.obj', function ( object ) {
object.name = data[i].code;
object.position.z = 30000;
object.position.y = 2;
let textgeometry = new THREE.PlaneBufferGeometry( 64, 32, 1 );
let textmaterial = new THREE.MeshBasicMaterial( { side: THREE.DoubleSide,map: new THREE.CanvasTexture(getTextCanvas(data[i])),transparent: true} );
let textplane = new THREE.Mesh( textgeometry, textmaterial );
textplane.name = data[i].code;
textplane.position.y = 30;
//textplane.rotation.x = Math.PI/2;
scope.textlist.push(textplane);
object.add(textplane);
let newtrain = {};
newtrain.mesh = object;
newtrain.mesh.scale.set(0.5,0.5,0.5);
newtrain.mesh.first = false;
scope.list.push(newtrain);
scope.group.add(newtrain.mesh);
}, onProgress, onError );
} );
}
}
this.update = function(){
}
this.renderon = function(){
}
this.renderoff = function(){
}
this.dispose = function(){
}
}
let onProgress = function ( xhr ) {
if ( xhr.lengthComputable ) {
let percentComplete = xhr.loaded / xhr.total * 100;
//console.log( Math.round( percentComplete, 2 ) + '% downloaded' );
}
};
let onError = function () { };
function getTextCanvas(text){
var width=128, height=64;
var canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
canvas.style.width = width + "px";
canvas.style.height = height + "px";
var ctx = canvas.getContext('2d');
ctx.fillStyle = '#FFFFFF';
ctx.fillRect(0, 0, width, height);
ctx.font = 1+'px';
ctx.fillStyle = '#000000';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.clearRect(0,0,width,height);
//ctx.fillText(text.trainNumber, width/2,height/4);
ctx.fillText("车组号:"+text.trainNumber, width/2,height*2/4);
//ctx.fillText(text.trainModel.name, width/2,height*3/4);
return canvas;
}

View File

@ -0,0 +1,175 @@
import {TrainModel} from '@/jlmap3d/model/TrainModel.js';
export function TrainListTest() {
let scope = this;
this.type = "trainlist";
this.list = [];
this.group = [];
this.textlist = [];
this.initpromise = function(data,scene,assetloader){
return new Promise(function(resolve, reject){
//列车节数
let trainnum = 4;
//遍历列车数据
for(let i=0;i<data.length;i++){
// let group = new THREE.Group();
// //创建列车模型
// for(let j=0;j<trainnum;j++){
// let geometry = new THREE.BoxBufferGeometry( 10, 4, 5 );
// let material = new THREE.MeshBasicMaterial( {color: 0x3A5FCD} );
// let train = new THREE.Mesh( geometry, material );
// train.name = data[i].code;
// train.position.set(j*11,2,0);
// group.add(train);
// }
let newmesh;
for(let n=0;n<assetloader.modellist.length;n++){
if(assetloader.modellist[n].deviceType == "train"){
newmesh = assetloader.modellist[n].mesh.clone(true);
n = assetloader.modellist.length;
}
}
for(let j=0;j<newmesh.children.length;j++){
newmesh.children[j].name = data[i].code;
//newmesh.children[j].rotation.y = 0.05*j;
}
//创建列车字牌
let textgeometry = new THREE.PlaneBufferGeometry( 128, 64, 1 );
let textmaterial = new THREE.MeshBasicMaterial( { side: THREE.DoubleSide,map: new THREE.CanvasTexture(getTextCanvas(data[i])),transparent: true} );
let textplane = new THREE.Mesh( textgeometry, textmaterial );
textplane.name = data[i].code;
textplane.position.y = 30;
textplane.position.x = -30;
//textplane.rotation.x = Math.PI;
scope.textlist.push(textplane);
newmesh.add(textplane);
//group.add(textplane);
newmesh.first = false;
newmesh.name = data[i].code;
newmesh.groupNumber = data[i].groupNumber;
newmesh.position.set(20,2,-20*i);
//newmesh.rotation.y = Math.PI/2;
newmesh.movelist = [];
newmesh.rotelist = [];
newmesh.endpoint = null;
scope.list.push(newmesh);
//scene.add(newmesh);
}
resolve("loadedtrain");
});
}
this.init = function(data,scene,assetloader){
//列车节数
let trainnum = 4;
//遍历列车数据
for(let i=0;i<data.length;i++){
// let group = new THREE.Group();
// //创建列车模型
// for(let j=0;j<trainnum;j++){
// let geometry = new THREE.BoxBufferGeometry( 10, 4, 5 );
// let material = new THREE.MeshBasicMaterial( {color: 0x3A5FCD} );
// let train = new THREE.Mesh( geometry, material );
// train.name = data[i].code;
// train.position.set(j*11,2,0);
// group.add(train);
// }
let newmesh = assetloader.modellist[1].mesh.clone(true);
for(let j=0;j<newmesh.children.length;j++){
newmesh.children[j].name = data[i].code;
//newmesh.children[j].rotation.y = 0.05*j;
}
//创建列车字牌
let textgeometry = new THREE.PlaneBufferGeometry( 128, 64, 1 );
let textmaterial = new THREE.MeshBasicMaterial( { side: THREE.DoubleSide,map: new THREE.CanvasTexture(getTextCanvas(data[i])),transparent: true} );
let textplane = new THREE.Mesh( textgeometry, textmaterial );
textplane.name = data[i].code;
textplane.position.y = 30;
textplane.position.x = -30;
//textplane.rotation.x = Math.PI;
scope.textlist.push(textplane);
newmesh.add(textplane);
//group.add(textplane);
newmesh.first = false;
newmesh.name = data[i].code;
newmesh.groupNumber = data[i].groupNumber;
newmesh.position.set(20,2,-20*i);
//newmesh.rotation.y = Math.PI/2;
newmesh.movelist = [];
newmesh.rotelist = [];
newmesh.endpoint = null;
scope.list.push(newmesh);
scene.add(newmesh);
}
}
this.update = function(){
}
this.renderon = function(){
}
this.renderoff = function(){
}
this.dispose = function(){
}
}
let onProgress = function ( xhr ) {
if ( xhr.lengthComputable ) {
let percentComplete = xhr.loaded / xhr.total * 100;
//console.log( Math.round( percentComplete, 2 ) + '% downloaded' );
}
};
let onError = function () { };
//canvas文字贴图方法
//PS:待提炼 增强功能
function getTextCanvas(text){
var canvas = document.getElementById('canvastexture');
// let width = 128;
// let height = 64;
// canvas.style.width = width + "px";
// canvas.style.height = height + "px";
var ctx = canvas.getContext('2d');
ctx.fillStyle = '#FFFFFF';
ctx.fillRect(0, 0,128,64);
ctx.font = "500px";
ctx.fillStyle = '#000000';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.clearRect(0,0,128,64);
////console.log(text.groupNumber);
//ctx.fillText(text.trainNumber, width/2,height/4);
ctx.fillText("车组号:"+text.groupNumber, 128/2,64*2/4);
//ctx.fillText(text.trainModel.name, width/2,height*3/4);
let data = ctx.getImageData(0, 0,128,64);
return data;
}

View File

@ -0,0 +1,8 @@
export function TrainModel(opts) {
var scope = this;
this.mesh = null;
this.meshurl = null;
this.picurl = null;
}

View File

@ -0,0 +1,209 @@
export function SetObj(data,scope) {
let group = new THREE.Group();
scope.scene.add(group);
group.name = "obj";
var signalgeometry = new THREE.PlaneBufferGeometry( 5,5 );
var signalmaterial = new THREE.MeshLambertMaterial( { color:0x0000FF } );
var sectionmaterial = new THREE.MeshLambertMaterial( { color:0x000FFF } );
var switchgeometry = new THREE.PlaneBufferGeometry( 3,3 );
let switchmaterial = new THREE.MeshLambertMaterial( { color:0xFF0000 });
var stationgeometry = new THREE.PlaneBufferGeometry( 5,5 );
let stationmaterial = new THREE.MeshLambertMaterial( { color:0xFF0000 });
//遍历信号数据
for(let i=0;i<data.signalList.length;i++){
var object = new THREE.Mesh( signalgeometry, signalmaterial );
object.name = data.signalList[i].code;
//根据线路方向修改信号灯位置
if(data.signalList[i].directionType == "01"){
object.position.set(data.signalList[i].position.x,1,data.signalList[i].position.y-10);
object.rotation.x = ( -Math.PI / 2 );
}else if(data.signalList[i].directionType == "02"){
object.position.set(data.signalList[i].position.x,1,data.signalList[i].position.y+10);
object.rotation.x = ( - Math.PI / 2 );
}
group.add(object);
}
//遍历区段
for(let i=0;i<data.sectionList.length;i++){
//获取区段左右坐标点
let point1 = data.sectionList[i].points[0];
let point2 = data.sectionList[i].points[1];
//过滤无效数据
if(data.sectionList[i].type == "01"){
if(data.sectionList[i].points.length>=3){
console.log(data.sectionList[i]);
for(let j=1;j<data.sectionList[i].points.length;j++){
point1 = data.sectionList[i].points[j-1];
point2 = data.sectionList[i].points[j];
let dx = Math.abs(point1.x - point2.x);
      let dy = Math.abs(point1.y - point2.y);
      //let distance = Math.sqrt(Math.pow(dx,2)+Math.pow(dy,2));
let distance = data.sectionList[i].offsetRight - data.sectionList[i].offsetLeft;
//获取区段中心点坐标
let posx = (point1.x+point2.x)/2;
let posy = (point1.y+point2.y)/2;
let sectiongeometry = new THREE.PlaneBufferGeometry( distance, 5, 32 );
let section = new THREE.Mesh( sectiongeometry, sectionmaterial );
section.name = data.sectionList[i].code;
section.rotation.x = -Math.PI/2;
//判断方向 PS:方法待提炼
let axix = new THREE.Vector3(1,0,0);
let axixnow = new THREE.Vector3(point2.x-point1.x,0,point2.y-point1.y);
let rotenum = axixnow.angleTo(axix);
//不同坐标系方向值不同
if(point1.y>point2.y){
section.rotation.z = rotenum;
}else {
section.rotation.z = -rotenum;
}
section.position.set(posx,1,posy);
group.add(section);
}
}else{
//获取区段长度
let dx = Math.abs(point1.x - point2.x);
      let dy = Math.abs(point1.y - point2.y);
      //let distance = Math.sqrt(Math.pow(dx,2)+Math.pow(dy,2));
let distance = data.sectionList[i].offsetRight - data.sectionList[i].offsetLeft;
//获取区段中心点坐标
let posx = (point1.x+point2.x)/2;
let posy = (point1.y+point2.y)/2;
//判断是否道岔
//创建模型
let sectiongeometry = new THREE.PlaneBufferGeometry( distance, 5, 32 );
let section = new THREE.Mesh( sectiongeometry, sectionmaterial );
section.name = data.sectionList[i].code;
section.rotation.x = -Math.PI/2;
//判断方向 PS:方法待提炼
let axix = new THREE.Vector3(1,0,0);
let axixnow = new THREE.Vector3(point2.x-point1.x,0,point2.y-point1.y);
let rotenum = axixnow.angleTo(axix);
//不同坐标系方向值不同
if(point1.y>point2.y){
section.rotation.z = rotenum;
}else {
section.rotation.z = -rotenum;
}
section.position.set(posx,1,posy);
group.add(section);
}
}
}
//定义区分道岔组
let switchlist = [];
//遍历道岔数据
for(let i=0;i<data.switchList.length;i++){
//道岔信息
let newswitch = {
code:null,
pa:null,
pb:null,
pc:null
};
//获取道岔分辨的点 PS:可能修改动态判断
for(let j=0;j<data.sectionList.length;j++){
if(data.switchList[i].sectionACode == data.sectionList[j].code){
newswitch.pa = data.sectionList[j].points;
}
if(data.switchList[i].sectionBCode == data.sectionList[j].code){
newswitch.pb = data.sectionList[j].points;
}
if(data.switchList[i].sectionCCode == data.sectionList[j].code){
newswitch.pc = data.sectionList[j].points;
}
if(newswitch.pa != null && newswitch.pb!= null && newswitch.pc != null){
newswitch.code = data.switchList[i].code;
switchlist.push(newswitch);
j = data.sectionList.length+1;
}
}
}
for(let i=0;i<switchlist.length;i++){
var object = new THREE.Mesh( switchgeometry, switchmaterial );
object.name = switchlist[i].code;
object.position.x = (switchlist[i].pa[0].x+switchlist[i].pb[1].x)/2;
object.position.y = 1;
object.position.z = (switchlist[i].pa[0].y+switchlist[i].pb[1].y)/2;
object.rotation.x = -Math.PI/2;
group.add(object);
}
let stationlists = [];
for(let i=0;i<data.stationList.length;i++){
let newstationstand = {
stationcode:null,
direction1:null,
direction1pos:null,
direction2:null,
direction2pos:null
};
//判断站台是否显示
if(data.stationList[i].visible == true){
newstationstand.stationcode = data.stationList[i].code;
//遍历车站站台数据
for(let j=0;j<data.stationStandList.length;j++){
//收集有效车站数据
if(data.stationStandList[j].stationCode == data.stationList[i].code){
if(data.stationStandList[j].direction == "01"){
newstationstand.direction1 = data.stationStandList[j].code;
newstationstand.direction1pos = data.stationStandList[j].position;
}
if(data.stationStandList[j].direction == "02"){
newstationstand.direction2 = data.stationStandList[j].code;
newstationstand.direction2pos = data.stationStandList[j].position;
}
}
}
stationlists.push(newstationstand);
}
}
for(let i=0;i<stationlists.length;i++){
var object = new THREE.Mesh( stationgeometry, stationmaterial );
object.name = stationlists[i].stationcode;
object.position.set(stationlists[i].direction1pos.x,0,(stationlists[i].direction1pos.y+stationlists[i].direction2pos.y)/2);
object.rotation.x = -Math.PI/2;
group.add(object);
}
scope.exportmodel = group;
//console.log(group);
}

View File

@ -0,0 +1,70 @@
//cad画图对齐辅助
export function Drawhelp(pointing,helppoints){
var result;
var mindistance;
for(var i=0;i<helppoints.length;i++){
var raycaster1 = new THREE.Raycaster(new THREE.Vector3(pointing.x,5,pointing.z),new THREE.Vector3(1,0,0).normalize());
var raycaster2 = new THREE.Raycaster(new THREE.Vector3(pointing.x,5,pointing.z),new THREE.Vector3(-1,0,0).normalize());
var raycaster3 = new THREE.Raycaster(new THREE.Vector3(pointing.x,5,pointing.z),new THREE.Vector3(0,0,1).normalize());
var raycaster4 = new THREE.Raycaster(new THREE.Vector3(pointing.x,5,pointing.z),new THREE.Vector3(0,0,-1).normalize());
var intersects1 = raycaster1.intersectObjects( helppoints[i] );
var intersects2 = raycaster2.intersectObjects( helppoints[i] );
var intersects3 = raycaster3.intersectObjects( helppoints[i] );
var intersects4 = raycaster4.intersectObjects( helppoints[i] );
//// //console.log(raycaster1);
if(intersects1[0] != undefined){
// // //console.log("intersects1");
// // //console.log(intersects1[0]);
intersects1[0].name = "1";
mindistance = intersects1[0].distance;
result = intersects1[0];
}
if(intersects2[0] != undefined){
// // //console.log("intersects2");
// // //console.log(mindistance);
intersects2[0].name = "2";
if(mindistance == undefined){
mindistance = intersects2[0].distance;
result = intersects2[0];
}else if(intersects2[0].distance < mindistance){
mindistance = intersects2[0].distance;
result = intersects2[0];
}
}
if(intersects3[0] != undefined){
// // //console.log("intersects3");
// // //console.log(mindistance);
intersects3[0].name = "3";
if(mindistance == undefined){
mindistance = intersects3[0].distance;
result = intersects3[0];
}else if(intersects3[0].distance < mindistance){
mindistance = intersects3[0].distance;
result = intersects3[0];
}
}
if(intersects4[0] != undefined){
// // //console.log("intersects4");
// // //console.log(mindistance);
intersects4[0].name = "4";
if(mindistance == undefined){
mindistance = intersects4[0].distance;
result = intersects4[0];
}else if(intersects4[0].distance < mindistance){
mindistance = intersects4[0].distance;
result = intersects4[0];
}
}
}
raycaster1 = null;
raycaster2 = null;
raycaster3 = null;
raycaster4 = null;
return result;
}

14
src/jlmap3d/jl3ddata.js Normal file
View File

@ -0,0 +1,14 @@
export function Jl3ddata() {
let scope = this;
this.id = null;
this.mapId = null;
this.sectionlist = null;
this.linklist = null;
this.signallist = null;
this.stationstandlist = null;
this.trainlisttest = null;
this.realsectionlist = null;
this.path = [];
}

View File

View File

@ -0,0 +1,394 @@
import Vue from 'vue';
//main
import {Three} from '@/jlmap3d/main/three.min.js';
//模型loader
import { AssetLoader } from '@/jlmap3d/main/loaders/AssetLoader.js';
import {DDSLoader} from '@/jlmap3d/main/loaders/DDSLoader.js';
import {OBJLoader} from '@/jlmap3d/main/loaders/OBJLoader.js';
import {MTLLoader} from '@/jlmap3d/main/loaders/MTLLoader.js';
import { FBXLoader } from '@/jlmap3d/main/loaders/FBXLoader.js';
//controls
import {OrbitControls} from '@/jlmap3d/control/OrbitControls.js';
import { DragControls } from '@/jlmap3d/edit/control/DragControls.js';
//component
import {Helper} from '@/jlmap3d/component/Helper';
//data
import { Jl3ddata } from '@/jlmap3d/jl3ddata';
//setconfig
import { SetCamera } from '@/jlmap3d/config/Camera';
import { SetRender } from '@/jlmap3d/config/Render';
import { SetScene } from '@/jlmap3d/config/Scene';
//加载器
import { ModelLoad } from '@/jlmap3d/jl3dsimulation/simulationloader';
//connect
import {Jl3dDriving} from '@/jlmap3d/jl3dsimulation/moveupdate/DrivingConnect';
//import {Jlmap3dSubscribe} from '@/jlmap3d/connect/TrainingConnectTest';
import { getPublishMapVersion, getPublishMapDetail,getPublish3dMapDetail} from '@/api/jlmap3d/load3ddata';
//utils
import { UpdateTrain } from '@/jlmap3d/jl3dsimulation/moveupdate/UpdateTrain';
//import { UpdateTrain } from '@/jlmap3d/utils/UpdateTrainTest';
import { ReStart } from '@/jlmap3d/utils/ReStart';
import {Stats} from '@/jlmap3d/main/lib/stats.min.js';
import {MouseControls} from '@/jlmap3d/control/FirstControls';
var clock = new THREE.Clock();
export function JLmapDriving(dom, data,skinStyle) {
let scope = this;
this.dom = dom;
//渲染循环开关
this.animateswitch = false;
//初始化webgl渲染
let renderer = SetRender(dom);
dom.appendChild(renderer.domElement);
//定义相机
let camera = SetCamera(dom);
//定义场景(渲染容器)
let scene = SetScene();
let speed = 0;
let drivingcode = null;
//模型加载器
this.assetloader = new AssetLoader();
//替换材质组,例:信号机不同灯光
this.materiallist = [];
//初始化场景线框和灯光 暂时
Helper(scene);
//点击选中的模型
this.selectmodel = null;
//鼠标点击模型切换
this.raycasterswitch = "stand";
//选中物体描边方框
this.helpbox = null;
//车门,站台门道岔动画构造器
this.mixers = [];
//模型操作命令组
this.actions = {};
this.nowspeed = null;
this.nowmxlen = null;
this.atpspeed = null;
this.atospeed = null;
this.trainnum = null;
this.stime = null;
this.webwork=new Worker("../../static/workertest/trainworker.js");
//地图模型数据
let mapdata = new Jl3ddata();
let camera2 = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 2000 );
camera2.name = "camera2";
let controls3 = new MouseControls(camera2, 1.6);
controls3.enabled = true;
scene.add(controls3.getObject());
//订阅仿真socket
this.Subscribe = new Jl3dDriving(scope);
//连接到通信
//console.log(this.Subscribe.config);
//this.webwork.postMessage(this.Subscribe.teststomp);
this.Subscribe.socketon(scope.Subscribe.topic);
//初始化加载数据和模型
getPublish3dMapDetail(skinStyle).then(netdata => {
ModelLoad(data,scope,netdata.data,mapdata,camera,controls3,scene);
});
//let stats = new Stats();
//dom.appendChild( stats.dom );
//开启渲染
animate();
startWorker();
//动画时间
let delta;
//循环渲染函数
function animate() {
//循环渲染
//requestAnimationFrame(animate);
//renderer.setAnimationLoop(animate);
requestAnimationFrame(animate);
//判断渲染是否开启
if(scope.animateswitch == true){
//根据相机渲染场景
renderer.render(scene,camera2);
//updatcontrols();
controls3.update();
//检测动画构造器播放动画
}
}
function updatcontrols(){
if(drivingcode){
controls3.getObject().position.x = mapdata.trainlisttest.list[drivingcode].matrixWorld.elements[12]-27;
controls3.getObject().position.y=10;
controls3.getObject().position.z = mapdata.trainlisttest.list[drivingcode].children[0].matrixWorld.elements[14];
}
}
function startWorker(){
if(typeof(Worker)!=="undefined"){
scope.webwork.onmessage = function (event) {
//更新列车位置
// stats.update();
UpdateTrain(camera,mapdata.trainlisttest);
delta = clock.getDelta();
for(let i=scope.mixers.length-1;i>=0;i--){
if ( scope.mixers[i] ){
scope.mixers[i].update( delta );
}
}
};
}
}
this.updatenowspeed = function(speed){
scope.nowspeed = speed;
}
this.updatenowlen = function(maLen){
scope.nowmxlen = maLen;
}
this.updateatpspeed = function(atpspeed){
scope.atpspeed = atpspeed;
}
this.updateatospeed = function(atospeed){
scope.atospeed = atospeed;
}
this.updatetrainnum = function(trainnum){
scope.trainnum = trainnum;
}
this.updatestoptime = function(stime){
scope.stime = stime;
}
this.updatedrivingcode = function(code){
drivingcode = code;
mapdata.trainlisttest.list[drivingcode].children[0].add(controls3.getObject());
mapdata.trainlisttest.list[drivingcode].children[0].add(scope.assetloader.modellist[4].mesh);
controls3.getObject().position.x = 40;
controls3.getObject().position.y= 12.5;
controls3.getObject().rotation.y = -Math.PI/2;
scope.assetloader.modellist[4].mesh.position.x = 34;
scope.assetloader.modellist[4].mesh.position.y = 0;
}
this.dispose = function(){
renderer.setAnimationLoop(null);
renderer.dispose();
scene.dispose();
// controls.dispose();
camera = null;
scope.assetloader = null;
mapdata = null;
scope.selectmodel = null;
scope.materiallist = null;
scope.selectmodel = null;
scope.helpbox = null;
scope.mixers = null;
scope.actions = null;
scope.Subscribe = null;
//console.log(scope);
//scope = null;
}
this.rayswitch = function(value){
this.raycasterswitch = value;
if(scope.helpbox){
scene.remove( scope.helpbox );
scope.helpbox = null;
}
};
this.showstationmsg = function(showtype){
if(showtype == "show"){
for(let st=0;st<mapdata.stationstandlist.group.children.length;st++){
mapdata.stationstandlist.group.children[st].add(mapdata.stationstandlist.textlist[st]);
}
}else{
for(let st=0;st<mapdata.stationstandlist.group.children.length;st++){
mapdata.stationstandlist.group.children[st].remove(mapdata.stationstandlist.textlist[st]);
}
}
};
this.showtrainmsg = function(showtype){
if(showtype == "show"){
for(let st=0;st<mapdata.trainlisttest.textlist.length;st++){
mapdata.trainlisttest.list[mapdata.trainlisttest.textlist[st].tcode].children[0].add(mapdata.trainlisttest.textlist[st]);
}
}else{
for(let st=0;st<mapdata.trainlisttest.textlist.length;st++){
mapdata.trainlisttest.list[mapdata.trainlisttest.textlist[st].tcode].children[0].remove(mapdata.trainlisttest.textlist[st]);
}
}
};
this.restart = function(){
ReStart(mapdata);
};
this.animateon = function(){
//controls.enabled = false;
scope.animateswitch = true;
};
this.animateoff = function(){
//controls.enabled = false;
scope.animateswitch = false;
};
this.endsocket = function(){
scope.Subscribe.socketoff(scope.Subscribe.topic);
};
this.eventon = function(){
//raycaster交互模型点击事件
document.getElementById("jlsimulation").addEventListener( "mousedown", onselect, false );
//窗口自适应
window.addEventListener( 'resize', onWindowResized, false );
//controls.update();
};
this.eventoff = function(){
//console.log("off");
//raycaster交互模型点击事件
document.getElementById("jlsimulation").removeEventListener( "mousedown", onselect, false );
//窗口自适应
window.removeEventListener( 'resize', onWindowResized, false );
};
this.updatecamera = function(mesh,type){
if(type == "simulation"){
camera.position.x = mesh.position.x-300;
camera.position.y = 100;
camera.position.z = mesh.children[0].position.z;
//controls.target = new THREE.Vector3(mesh.position.x,0,mesh.children[0].position.z);
}
//console.log(mesh);
if(type == "station"){
camera.position.x = mesh.position.x;
camera.position.y = mesh.position.y+800;
camera.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;
}
}
function onWindowResized() {
//窗口自适应
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
//三维交互点击事件函数
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;
raycaster.setFromCamera( mouse, camera );
if(scope.helpbox){
scene.remove( scope.helpbox );
scope.helpbox = null;
}
if(scope.raycasterswitch == "stand"){
//从站台对象组获取点击目标
let intersects1 = raycaster.intersectObjects( mapdata.stationstandlist.textlist);
//获取最近处点击到的模型对象
if(intersects1[0]){
//遍历对象组获取对象坐标更新相机数据
for(let j=0;j<mapdata.stationstandlist.list.length;j++){
if(intersects1[0].object.name == mapdata.stationstandlist.list[j].mesh.code){
camera.position.x = mapdata.stationstandlist.list[j].mesh.position.x;
camera.position.y = mapdata.stationstandlist.list[j].mesh.position.y+200;
camera.position.z = mapdata.stationstandlist.list[j].mesh.position.z+300;
//更新相机方向
// controls.target = new THREE.Vector3(mapdata.stationstandlist.list[j].mesh.position.x,mapdata.stationstandlist.list[j].mesh.position.y,mapdata.stationstandlist.list[j].mesh.position.z);
// controls.update();
}
}
}
}
if(scope.raycasterswitch == "train"){
let intersects = raycaster.intersectObjects( mapdata.trainlisttest.textlist);
if(intersects[0]){
for(let j=0;j<mapdata.trainlisttest.list.length;j++){
if(intersects[0].object.name == mapdata.trainlisttest.list[j].name){
camera.position.x = mapdata.trainlisttest.list[j].position.x;
camera.position.y = 200;
camera.position.z = mapdata.trainlisttest.list[j].children[2].matrixWorld.elements[14]+300;
}
}
}
}
if(scope.raycasterswitch == "section"){
//console.log(mapdata.sectionlist.sections.modellist);
let intersects = raycaster.intersectObjects( mapdata.sectionlist.sections.modellist,true);
if(intersects[0]){
scope.helpbox = new THREE.BoxHelper( intersects[0].object, 0xff0000 );
scene.add( scope.helpbox );
}
}
if(scope.raycasterswitch == "signal"){
let intersects = raycaster.intersectObjects( mapdata.signallist.group.children,true);
if(intersects[0]){
scope.helpbox = new THREE.BoxHelper( intersects[0].object, 0xff0000 );
scene.add( scope.helpbox );
}
}
if(scope.raycasterswitch == "switch"){
let intersects = raycaster.intersectObjects( mapdata.sectionlist.switchs.modellist,true);
if(intersects[0]){
scope.helpbox = new THREE.BoxHelper( intersects[0].object, 0xff0000 );
scene.add( scope.helpbox );
}
}
}
}
}

View File

@ -0,0 +1,688 @@
import StompClient from '@/utils/sock';
import { getTrainingCbtcDemon, runDiagramStart, runDiagramOver, setTrainingCbtcInitTime } from '@/api/simulation';
import { creatSubscribe, clearSubscribe, displayTopic, screenTopic, } from '@/utils/stomp';
import { handleToken } from '@/utils/auth';
import router from '@/router';
//定于仿真socket接口
export function Jl3dDriving(jlmap3d) {
let scope = this;
this.map = null;
var trainlisttest = null;
var sectionlist = null;
var signallist = null;
var stationstandlist = null;
var sectionlist = null;
var materials = null;
var actions = null;
var scenes = null;
var code = null;
var drivingcode = null;
var drivingspeed = null;
var drivingaptspeed = null;
let driverswitch = false;
let stoptimer = null;
let num = 30;
let pointstand = null;
//run as plane = 01;
//reset = 02;
var datatype = "00";
this.teststomp = new StompClient();
this.topic = "/user/queue/simulation/jl3d";
let header = {'X-Token': handleToken() };
this.updatamap = function(mapdata,materiallist,nowaction,scene){
//console.log(mapdata);
scope.map = mapdata;
trainlisttest = this.map.trainlisttest;
sectionlist = this.map.sectionlist;
signallist = this.map.signallist;
stationstandlist = this.map.stationstandlist;
sectionlist = this.map.sectionlist;
materials = materiallist;
scenes = scene;
actions = nowaction;
}
this.socketon = function(topic){
try {
//console.log("teststomp");
scope.teststomp.subscribe(topic, callback,header);
} catch (error) {
console.error('websocket订阅失败');
}
}
this.socketoff = function(topic){
scope.teststomp.unsubscribe(topic);
for(let i=0;i<trainlisttest.group.children.length;i++){
if(trainlisttest.group.children[i].dispose == false){
code = trainlisttest.group.children[i].name;
trainlisttest.list[code].rotation.y = 0;
trainlisttest.list[code].doorStatus = "01";
trainlisttest.list[code].speed = 0;
trainlisttest.group.children[i].dispose = true;
trainlisttest.group.children[i].position.x = -50000;
trainlisttest.group.children[i].position.y = -50000;
trainlisttest.group.remove(trainlisttest.group.children[i]);
i--;
}
}
}
// 仿真socket接口回调函数
function callback(Response) {
//对象化数据
let data = JSON.parse(Response.body);
//遍历后台数据
//判断消息类型
// if(data.type == "Simulation_TrainPosition"){
//
//
// }
if(data.type == "Simulation_Driver_Change"){
drivingcode = data.body.code;
jlmap3d.updatedrivingcode( data.body.code);
}
if(data.type == "Simulation_TrainSpeed"){
if(trainlisttest){
for(let tl = 0;tl<data.body.length;tl++){
code = data.body[tl].id;
trainlisttest.list[code].speed = data.body[tl].v;
if(trainlisttest.list[code].runMode == "02"){
if(trainlisttest.list[code].isStandTrack == true){
trainlisttest.list[code].speeds = parseFloat(data.body[tl].v*10/36/19/trainlisttest.list[code].len);
}else{
trainlisttest.list[code].speeds = parseFloat(data.body[tl].v*10/36/20/trainlisttest.list[code].len);
}
}else{
trainlisttest.list[code].speeds = parseFloat(data.body[tl].v*10/36/20/trainlisttest.list[code].len);
}
if(code == drivingcode){
if(data.body[tl].v >0){
jlmap3d.updatenowspeed(data.body[tl].v);
}else{
jlmap3d.updatenowspeed(Math.abs(data.body[tl].v));
}
if(data.body[tl].atpv){
jlmap3d.updateatpspeed(data.body[tl].atpv);
}else{
jlmap3d.updateatpspeed(-1);
}
if(data.body[tl].atov){
jlmap3d.updateatospeed(data.body[tl].atov);
}else{
jlmap3d.updateatospeed(-1);
}
}
}
}
}
if(data.type == "SJL3D_TrainStatus"){
for(let i=data.body.length-1;i>=0;i--){
if(data.body[i]._type == "Train"){
//遍历列车对象组
if(trainlisttest){
code = data.body[i].code;
//剔除不显示的车
//找到对应列车
if( trainlisttest.list[code]){
if(code == drivingcode){
driverswitch = data.body[i].runMode;
jlmap3d.updatetrainnum(data.body[i].groupNumber);
// console.log(trainlisttest.list[code].progress);
let syncdata = {
type:"Train",
code:code,
sectionCode:data.body[i].sectionCode,
percent:0,
};
if(trainlisttest.list[code].isStandTrack == true && trainlisttest.list[code].progress>0.95 && trainlisttest.list[code].speed<=0){
if(data.body[i].directionType == "02"){
syncdata.percent = 1-(sectionlist.sections.datalist[data.body[i].sectionCode].rstop/trainlisttest.list[code].len);
}else{
syncdata.percent = sectionlist.sections.datalist[data.body[i].sectionCode].lstop/trainlisttest.list[code].len;
}
scope.teststomp.send("/app/topic/simulation/wgu3d",syncdata);
}else{
if(data.body[i].directionType == "02"){
syncdata.percent = trainlisttest.list[code].progress;
}else{
syncdata.percent = 1 - trainlisttest.list[code].progress;
}
scope.teststomp.send("/app/topic/simulation/wgu3d",syncdata);
}
if(data.body[i].parkRemainTime>0){
jlmap3d.updatestoptime("停站时间:"+parseInt(data.body[i].parkRemainTime));
}else{
if(data.body[i].runMode == "02"){
jlmap3d.updatestoptime("列车自动驾驶中");
}else{
if(trainlisttest.list[code].isStandTrack == true && trainlisttest.list[code].progress>0.95 && trainlisttest.list[code].speed<=0){
// if(stoptimer){
//
// }else{
// stoptimer = setInterval(function(){
// if(num >=0){
// jlmap3d.updatestoptime("停站时间:"+num);
// num --;
// }
// },1000);
// }
}else{
jlmap3d.updatestoptime("列车人工驾驶中");
}
}
}
// if(trainlisttest.list[code].speed > 0){
// if(stoptimer){
// clearInterval( stoptimer );
// stoptimer = null;
// num = 30;
// }
// }
}
trainlisttest.list[code].runMode = data.body[i].runMode;
//车门开关验证
if(data.body[i].directionType == "02"){
if(trainlisttest.list[code].doorStatus != data.body[i].doorStatus && data.body[i].doorStatus == "01"){
//console.log("close");
trainlisttest.list[code].doorStatus = "01";
for(let an=actions[code].top.length-1;an>=0;an--){
actions[code].top[an].reset();
actions[code].top[an].time = actions[code].top[an]._clip.duration;
actions[code].top[an].timeScale = -1;
actions[code].top[an].play();
}
}else if(trainlisttest.list[code].doorStatus != data.body[i].doorStatus && data.body[i].doorStatus == "02"){
//console.log("open");
trainlisttest.list[code].doorStatus = "02";
for(let an=actions[code].top.length-1;an>=0;an--){
actions[code].top[an].reset();
actions[code].top[an].time = 0;
actions[code].top[an].timeScale = 1;
actions[code].top[an].play();
}
}
}else{
if(trainlisttest.list[code].doorStatus != data.body[i].doorStatus && data.body[i].doorStatus == "01"){
//console.log("close");
trainlisttest.list[code].doorStatus = "01";
for(let an=actions[code].down.length-1;an>=0;an--){
actions[code].down[an].reset();
actions[code].down[an].time = actions[code].top[an]._clip.duration;
actions[code].down[an].timeScale = -1;
actions[code].down[an].play();
}
}else if(trainlisttest.list[code].doorStatus != data.body[i].doorStatus && data.body[i].doorStatus == "02"){
//console.log("open");
trainlisttest.list[code].doorStatus = "02";
for(let an=actions[code].down.length-1;an>=0;an--){
actions[code].down[an].reset();
actions[code].down[an].time = 0;
actions[code].down[an].timeScale = 1;
actions[code].down[an].play();
}
}
}
//遍历获取所在轨道
if(trainlisttest.list[code].dispose != data.body[i].dispose && data.body[i].dispose == false){
if(sectionlist.sections.datalist[data.body[i].sectionCode].code){
trainlisttest.group.add(trainlisttest.list[code]);
trainlisttest.list[code].position.y = 0;
trainlisttest.list[code].progress = 0;
trainlisttest.list[code].oldoffset = data.body[i].sectionOffsetPercent;
trainlisttest.list[code].dispose = false;
trainlisttest.list[code].nowcode = data.body[i].sectionCode;
trainlisttest.list[code].nextcode = data.body[i].nextSectionCode;
let vexlist = [];
let endrotation = null;
if(data.body[i].directionType == "02"){//向右
let offset = null;
let rotaposx = null;
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x>sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x){
offset = sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x-sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x;
rotaposx = sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x+offset*data.body[i].sectionOffsetPercent;
}else{
offset = sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x-sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x;
rotaposx = sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x+offset*data.body[i].sectionOffsetPercent;
}
let rotaposz = sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].z;
trainlisttest.list[code].rotation.y = 0;
trainlisttest.list[code].position.x = rotaposx;
trainlisttest.list[code].position.y = 0;
for(let tl=0;tl<6;tl++){
trainlisttest.list[code].children[tl].position.z = rotaposz;
}
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x>sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x){
vexlist.push(new THREE.Vector3(rotaposx,0,rotaposz));
for(let m=sectionlist.sections.datalist[data.body[i].sectionCode].rail.length-1;m>=0;m--){
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x>rotaposx){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}else{
vexlist.push(new THREE.Vector3(rotaposx,0,rotaposz));
for(let m=0;m<sectionlist.sections.datalist[data.body[i].sectionCode].rail.length;m++){
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x>rotaposx){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}
trainlisttest.list[code].status = "02";
}else if(data.body[i].directionType == "03"){//向左
trainlisttest.list[code].dispose = false;
trainlisttest.group.add(trainlisttest.list[code]);
let offset = null;
let rotaposx = null;
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x>sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x){
offset = sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x-sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x;
rotaposx = sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x+offset*data.body[i].sectionOffsetPercent;
}else{
offset = sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x-sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x;
rotaposx = sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x+offset*data.body[i].sectionOffsetPercent;
}
let rotaposz = sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].z;
trainlisttest.list[code].rotation.y = Math.PI;
trainlisttest.list[code].position.x = rotaposx;
trainlisttest.list[code].position.y = 0;
for(let tl=0;tl<6;tl++){
trainlisttest.list[code].children[tl].position.z = rotaposz;
}
if(data.body[i].groupNumber == "001"){
}
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x<sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x){
vexlist.push(new THREE.Vector3(rotaposx,0,rotaposz));
for(let m=sectionlist.sections.datalist[data.body[i].sectionCode].rail.length-1;m>=0;m--){
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x<rotaposx){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}else{
vexlist.push(new THREE.Vector3(rotaposx,0,rotaposz));
for(let m=0;m<sectionlist.sections.datalist[data.body[i].sectionCode].rail.length;m++){
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x<rotaposx){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}
trainlisttest.list[code].status = "03";
}
trainlisttest.list[code].curve = new THREE.CatmullRomCurve3(vexlist);
trainlisttest.list[code].isStandTrack = sectionlist.sections.datalist[data.body[i].sectionCode].isStandTrack;
trainlisttest.list[code].progress = 0;
trainlisttest.list[code].len = sectionlist.sections.datalist[data.body[i].sectionCode].distance;
trainlisttest.list[code].speed = data.body[i].speed;
trainlisttest.list[code].speeds = parseFloat(data.body[i].speed*10/36/20/trainlisttest.list[code].len);
}
}else if(trainlisttest.list[code].dispose != data.body[i].dispose && data.body[i].dispose == true){
trainlisttest.group.remove(trainlisttest.list[code]);
trainlisttest.list[code].progress = null;
trainlisttest.list[code].dispose = true;
code = trainlisttest.group.children[i].name;
trainlisttest.list[code].rotation.y = 0;
trainlisttest.list[code].doorStatus = "01";
trainlisttest.list[code].speed = 0;
trainlisttest.list[code].position.x = -50000;
trainlisttest.list[code].position.y = -50000;
}else if(trainlisttest.list[code].dispose == data.body[i].dispose && data.body[i].dispose == false){
if(sectionlist.sections.datalist[data.body[i].sectionCode].code){
if(driverswitch == "02" && code == drivingcode){
jlmap3d.updatenowspeed(data.body[i].speed);
if(data.body[i].atpSpeed){
jlmap3d.updateatpspeed(data.body[i].atpSpeed);
}else{
jlmap3d.updateatpspeed(-1);
}
if(data.body[i].targetSpeed){
jlmap3d.updateatospeed(data.body[i].targetSpeed);
}else{
jlmap3d.updateatospeed(-1);
}
if(data.body[i].maLen){
jlmap3d.updatenowlen(data.body[i].maLen);
}else{
jlmap3d.updatenowlen(0);
}
// if(trainlisttest.list[code].isStandTrack == true){
// pointstand = null;
// if(data.body[i].directionType == "02"){
// pointstand = trainlisttest.list[code].curve.getPointAt(data.body[i].sectionOffsetPercent);
// }else{
// pointstand = trainlisttest.list[code].curve.getPointAt(1-data.body[i].sectionOffsetPercent);
// }
// console.log(data.body[i].sectionOffsetPercent)
// console.log(pointstand.x);
//
// trainlisttest.list[code].position.x = pointstand.x;
// }
}
if(driverswitch == "05" && code == drivingcode){
if(data.body[i].maLen){
jlmap3d.updatenowlen(data.body[i].maLen);
}else{
jlmap3d.updatenowlen(0);
}
}
if(trainlisttest.list[code].nowcode != data.body[i].sectionCode || trainlisttest.list[code].nextcode != data.body[i].nextSectionCode){
trainlisttest.list[code].nowcode = data.body[i].sectionCode;
trainlisttest.list[code].nextcode = data.body[i].nextSectionCode;
let vexlist = [];
let endrotation = null;
if(data.body[i].directionType == "02"){//向右
if(trainlisttest.list[code].status != data.body[i].directionType){
let rotaposx = trainlisttest.list[code].children[5].matrixWorld.elements[12];
let rotaposz = trainlisttest.list[code].children[0].matrixWorld.elements[14];
trainlisttest.list[code].rotation.y = 0;
trainlisttest.list[code].position.x = rotaposx;
for(let tl=0;tl<6;tl++){
trainlisttest.list[code].children[tl].position.z = rotaposz;
}
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x>sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x){
vexlist.push(new THREE.Vector3(trainlisttest.list[code].position.x,0,trainlisttest.list[code].children[0].matrixWorld.elements[14]));
for(let m=sectionlist.sections.datalist[data.body[i].sectionCode].rail.length-1;m>=0;m--){
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x>trainlisttest.list[code].position.x){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}else{
vexlist.push(new THREE.Vector3(trainlisttest.list[code].position.x,0,trainlisttest.list[code].children[0].matrixWorld.elements[14]));
for(let m=0;m<sectionlist.sections.datalist[data.body[i].sectionCode].rail.length;m++){
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x>trainlisttest.list[code].position.x){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}
}else{
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x>sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x){
for(let m=sectionlist.sections.datalist[data.body[i].sectionCode].rail.length-1;m>=0;m--){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}else{
for(let m=0;m<sectionlist.sections.datalist[data.body[i].sectionCode].rail.length;m++){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
trainlisttest.list[code].rotation.y = 0;
}
trainlisttest.list[code].status = "02";
}else if(data.body[i].directionType == "03"){//向左
if(trainlisttest.list[code].status != data.body[i].directionType){
let rotaposx = trainlisttest.list[code].children[5].matrixWorld.elements[12];
let rotaposz = Math.abs(trainlisttest.list[code].children[0].matrixWorld.elements[14]);
trainlisttest.list[code].rotation.y = Math.PI;
trainlisttest.list[code].position.x = rotaposx;
for(let tl=0;tl<6;tl++){
trainlisttest.list[code].children[tl].position.z = rotaposz;
}
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x<sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x){
vexlist.push(new THREE.Vector3(trainlisttest.list[code].position.x,0,trainlisttest.list[code].children[0].matrixWorld.elements[14]));
for(let m=sectionlist.sections.datalist[data.body[i].sectionCode].rail.length-1;m>=0;m--){
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x<trainlisttest.list[code].position.x){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}else{
vexlist.push(new THREE.Vector3(trainlisttest.list[code].position.x,0,trainlisttest.list[code].children[0].matrixWorld.elements[14]));
for(let m=0;m<sectionlist.sections.datalist[data.body[i].sectionCode].rail.length;m++){
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m].x<trainlisttest.list[code].position.x){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
}
}else{
if(sectionlist.sections.datalist[data.body[i].sectionCode].rail[0].x<sectionlist.sections.datalist[data.body[i].sectionCode].rail[1].x){
for(let m=sectionlist.sections.datalist[data.body[i].sectionCode].rail.length-1;m>=0;m--){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}else{
for(let m=0;m<sectionlist.sections.datalist[data.body[i].sectionCode].rail.length;m++){
vexlist.push(sectionlist.sections.datalist[data.body[i].sectionCode].rail[m]);
}
}
trainlisttest.list[code].rotation.y = Math.PI;
}
trainlisttest.list[code].status = "03";
}
trainlisttest.list[code].curve = new THREE.CatmullRomCurve3(vexlist);
trainlisttest.list[code].isStandTrack = sectionlist.sections.datalist[data.body[i].sectionCode].isStandTrack;
trainlisttest.list[code].len = sectionlist.sections.datalist[data.body[i].sectionCode].distance;
trainlisttest.list[code].progress = 0;
trainlisttest.list[code].speed = data.body[i].speed;
trainlisttest.list[code].speeds = parseFloat(data.body[i].speed*10/36/20/trainlisttest.list[code].len);
}
}
}
}
}
}
}
}
if(data.type == "Simulation_DeviceStatus"){
for(let i=data.body.length-1;i>=0;i--){
//0xFFFFFF
//0xCD0000 红
//0xEEEE00 黄
//0x32CD32 绿
if(data.body[i]._type == "Signal"){
if(signallist){
signalupdate(data.body[i]);
}
}
if(data.body[i]._type == "StationStand"){
if(actions){
standupdate(data.body[i]);
}
}
if(data.body[i]._type == "Switch"){
if(sectionlist){
switchupdate(data.body[i]);
}
}
}
}
}
function standupdate(data){
code = data.code;
if( actions[code]){
if(data.screenDoorOpenStatus == "02" && actions[code].status == "01"){
actions[code].status = "00";
}
if(data.screenDoorOpenStatus == "02" && actions[code].status == "00"){
actions[code].status = "02";
actions[code].action.reset();
actions[code].action.time = 0;
actions[code].action.timeScale = 1;
actions[code].action.play();
}
if(data.screenDoorOpenStatus == "01" && actions[code].status == "02"){
actions[code].status = "00";
}
if(data.screenDoorOpenStatus == "01" && actions[code].status == "00"){
actions[code].status = "01";
actions[code].action.reset();
actions[code].action.time = actions[code].action._clip.duration;
actions[code].action.timeScale = -1;
actions[code].action.play();
}
}
}
function signalupdate(data){
code = data.code;
if(data.lightType == "01"){
if(signallist.list[code].mesh.code){
signallist.list[code].mesh.status = data.status;
//55
//33
//77
//关闭
if(data.status == "01"){
signallist.list[code].mesh.children[0].material.map = materials[3];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[0];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[3];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
//开放
if(data.status == "02"){
if(data.switchLocateType == "01"){
signallist.list[code].mesh.children[0].material.map = materials[2];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[3];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[3];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
if(data.switchLocateType == "02"){
signallist.list[code].mesh.children[0].material.map = materials[3];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[3];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[1];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
}
//引导
if(data.status == "03"){
signallist.list[code].mesh.children[0].material.map = materials[3];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[0];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[1];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
//封锁
if(data.status == "04"){
signallist.list[code].mesh.children[0].material.map = materials[3];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[3];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[3];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
//故障
if(data.status == "05"){
signallist.list[code].mesh.children[0].material.map = materials[3];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[3];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[3];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
}
}else if(data.lightType == "01"){
if(signallist.list[code].mesh.code){
signallist.list[code].mesh.children[0].material.map = materials[3];
signallist.list[code].mesh.children[0].material.map.needsUpdate = true;
signallist.list[code].mesh.children[1].material.map = materials[3];
signallist.list[code].mesh.children[1].material.map.needsUpdate = true;
signallist.list[code].mesh.children[2].material.map = materials[3];
signallist.list[code].mesh.children[2].material.map.needsUpdate = true;
}
}
}
function switchupdate(data){
code = data.code;
for(let j=sectionlist.switchs.modellist.length-1;j>=0;j--){
if(sectionlist.switchs.modellist[j].code == code){
if(sectionlist.switchs.modellist[j].locateType != data.locateType){
if(data.locateType == "02"){
if(actions[sectionlist.switchs.modellist[j].code]){
sectionlist.switchs.modellist[j].locateType = data.locateType;
actions[sectionlist.switchs.modellist[j].code].reset();
actions[sectionlist.switchs.modellist[j].code].time = 0;
actions[sectionlist.switchs.modellist[j].code].timeScale = 1;
actions[sectionlist.switchs.modellist[j].code].play();
}
}else if(data.locateType == "01"){
if(actions[sectionlist.switchs.modellist[j].code]){
sectionlist.switchs.modellist[j].locateType = data.locateType;
actions[sectionlist.switchs.modellist[j].code].reset();
actions[sectionlist.switchs.modellist[j].code].time = actions[sectionlist.switchs.modellist[j].code]._clip.duration;
actions[sectionlist.switchs.modellist[j].code].timeScale = -1;
actions[sectionlist.switchs.modellist[j].code].play();
}
}
}
j = 0;
}
}
}
}

View File

@ -0,0 +1,275 @@
export function UpdateTrain(camera,traindata,control){
if(traindata != undefined ){
for(let j=traindata.group.children.length-1;j>=0;j--){
//判断是否有移动事件
if(traindata.group.children[j].dispose == false){
if(traindata.group.children[j].progress != null){
let trainmodel = traindata.group.children[j];
if(trainmodel.speeds > 0 && trainmodel.speeds){
let speed = null;
if(traindata.group.children[j].progress<1){
let movecurve = trainmodel.curve;
if(trainmodel.status == "03"){
if(movecurve.points.length>1){
let point = movecurve.getPointAt(traindata.group.children[j].progress);
if(Math.abs( point.z -trainmodel.children[0].matrixWorld.elements[14]) >0.1){
trainmodel.children[0].up = new THREE.Vector3(-1,0,0);
let tangent = movecurve.getTangentAt(traindata.group.children[j].progress).normalize();
trainmodel.children[0].axis.crossVectors(trainmodel.children[0].up, tangent).normalize();
let radians = Math.acos(trainmodel.children[0].up.dot(tangent));
trainmodel.children[0].quaternion.setFromAxisAngle(trainmodel.children[0].axis, radians);
let rotas = {
posr:point,
rota:trainmodel.children[0].rotation.y
}
trainmodel.children[1].rotalist.push(rotas);
let offsetz = parseFloat(trainmodel.children[0].matrixWorld.elements[14]) - parseFloat(point.z);
trainmodel.children[0].position.z += offsetz;
//trainmodel.position.z = point.z;
}
trainmodel.position.x = point.x;
trainmodel.position.y = 0;
if(trainmodel.children[1].rotalist.length > 0 || trainmodel.children[2].rotalist.length > 0 || trainmodel.children[3].rotalist.length > 0 || trainmodel.children[4].rotalist.length > 0|| trainmodel.children[5].rotalist.length > 0){
for(let rs = 1;rs<6;rs++){
//console.log(rs);
if(trainmodel.children[rs].rotalist[0]){
let offsetz = parseFloat(trainmodel.children[rs].matrixWorld.elements[14]) - parseFloat(trainmodel.children[rs].rotalist[0].posr.z);
trainmodel.children[rs].position.z += offsetz;
for(let xh=0;xh<trainmodel.children[rs].rotalist.length;xh++){
if((trainmodel.children[rs].matrixWorld.elements[12]-38)<=trainmodel.children[rs].rotalist[0].posr.x){
if(rs != 5){
let asd = trainmodel.children[rs].rotalist[0];
trainmodel.children[rs+1].rotalist.push(asd);
}
trainmodel.children[rs].rotation.y = trainmodel.children[rs].rotalist[0].rota;
trainmodel.children[rs].rotalist.splice(0,1)
xh--;
}else{
xh = trainmodel.children[rs].rotalist.length;
}
}
//console.log(trainmodel.children[rs].rotalist.length);
}
}
}
trainmodel.progress += trainmodel.speeds;
}
}
if(trainmodel.status == "02"){
if(movecurve.points.length>1){
let point = movecurve.getPointAt(trainmodel.progress);
if(Math.abs( point.z -trainmodel.children[0].matrixWorld.elements[14]) >0.1){
trainmodel.children[0].up = new THREE.Vector3(1,0,0);
let tangent = movecurve.getTangentAt(traindata.group.children[j].progress).normalize();
trainmodel.children[0].axis.crossVectors(trainmodel.children[0].up, tangent).normalize();
let radians = Math.acos(trainmodel.children[0].up.dot(tangent));
trainmodel.children[0].quaternion.setFromAxisAngle(trainmodel.children[0].axis, radians);
let rotas = {
posr:point,
rota:trainmodel.children[0].rotation.y
}
trainmodel.children[1].rotalist.push(rotas);
let offsetz = parseFloat(point.z) - parseFloat(trainmodel.children[0].matrixWorld.elements[14]);
trainmodel.children[0].position.z += offsetz;
//trainmodel.position.z = point.z;
}
trainmodel.position.x = point.x;
trainmodel.position.y = 0;
if(trainmodel.children[1].rotalist.length > 0 || trainmodel.children[2].rotalist.length > 0 || trainmodel.children[3].rotalist.length > 0 || trainmodel.children[4].rotalist.length > 0|| trainmodel.children[5].rotalist.length > 0){
for(let rs = 1;rs<6;rs++){
//console.log(rs);
if(trainmodel.children[rs].rotalist[0]){
let offsetz = parseFloat(trainmodel.children[rs].rotalist[0].posr.z) - parseFloat(trainmodel.children[rs].matrixWorld.elements[14]);
trainmodel.children[rs].position.z += offsetz;
for(let xh=0;xh<trainmodel.children[rs].rotalist.length;xh++){
if((trainmodel.children[rs].matrixWorld.elements[12]+38)>=trainmodel.children[rs].rotalist[0].posr.x){
if(rs != 5){
let asd = trainmodel.children[rs].rotalist[0];
trainmodel.children[rs+1].rotalist.push(asd);
}
//let offsetx = trainmodel.children[1].matrixWorld.elements[12]-trainmodel.children[0].children[3].matrixWorld.elements[12];
trainmodel.children[rs].rotation.y = trainmodel.children[rs].rotalist[0].rota;
trainmodel.children[rs].rotalist.splice(0,1)
xh--;
}else{
xh = trainmodel.children[rs].rotalist.length;
}
}
//console.log(trainmodel.children[rs].rotalist.length);
}
}
// console.log(trainmodel.rotalist);
}
trainmodel.progress += trainmodel.speeds;
}
}
}
}else if(trainmodel.speeds < 0 && trainmodel.speeds){
let speed = null;
if(traindata.group.children[j].progress<1){
let movecurve = trainmodel.curve;
if(trainmodel.status == "03" && trainmodel.progress>0){
if(movecurve.points.length>1){
let point = movecurve.getPointAt(traindata.group.children[j].progress);
if(Math.abs( point.z -trainmodel.children[0].matrixWorld.elements[14]) >0.1){
trainmodel.children[0].up = new THREE.Vector3(-1,0,0);
let tangent = movecurve.getTangentAt(traindata.group.children[j].progress).normalize();
trainmodel.children[0].axis.crossVectors(trainmodel.children[0].up, tangent).normalize();
let radians = Math.acos(trainmodel.children[0].up.dot(tangent));
trainmodel.children[0].quaternion.setFromAxisAngle(trainmodel.children[0].axis, radians);
let rotas = {
posr:point,
rota:trainmodel.children[0].rotation.y
}
trainmodel.children[1].rotalist.push(rotas);
let offsetz = parseFloat(trainmodel.children[0].matrixWorld.elements[14]) - parseFloat(point.z);
trainmodel.children[0].position.z += offsetz;
//trainmodel.position.z = point.z;
}
trainmodel.position.x = point.x;
trainmodel.position.y = 0;
if(trainmodel.children[1].rotalist.length > 0 || trainmodel.children[2].rotalist.length > 0 || trainmodel.children[3].rotalist.length > 0 || trainmodel.children[4].rotalist.length > 0|| trainmodel.children[5].rotalist.length > 0){
for(let rs = 1;rs<6;rs++){
//console.log(rs);
if(trainmodel.children[rs].rotalist[0]){
let offsetz = parseFloat(trainmodel.children[rs].matrixWorld.elements[14]) - parseFloat(trainmodel.children[rs].rotalist[0].posr.z);
trainmodel.children[rs].position.z += offsetz;
for(let xh=0;xh<trainmodel.children[rs].rotalist.length;xh++){
if((trainmodel.children[rs].matrixWorld.elements[12]-38)<=trainmodel.children[rs].rotalist[0].posr.x){
if(rs != 5){
let asd = trainmodel.children[rs].rotalist[0];
trainmodel.children[rs+1].rotalist.push(asd);
}
trainmodel.children[rs].rotation.y = trainmodel.children[rs].rotalist[0].rota;
trainmodel.children[rs].rotalist.splice(0,1)
xh--;
}else{
xh = trainmodel.children[rs].rotalist.length;
}
}
//console.log(trainmodel.children[rs].rotalist.length);
}
}
}
if(trainmodel.progress > -(trainmodel.speeds)){
trainmodel.progress += trainmodel.speeds;
}
}
}
if(trainmodel.status == "02"){
if(movecurve.points.length>1 && trainmodel.progress>0){
let point = movecurve.getPointAt(trainmodel.progress);
if(Math.abs( point.z -trainmodel.children[0].matrixWorld.elements[14]) >0.1){
trainmodel.children[0].up = new THREE.Vector3(1,0,0);
let tangent = movecurve.getTangentAt(traindata.group.children[j].progress).normalize();
trainmodel.children[0].axis.crossVectors(trainmodel.children[0].up, tangent).normalize();
let radians = Math.acos(trainmodel.children[0].up.dot(tangent));
trainmodel.children[0].quaternion.setFromAxisAngle(trainmodel.children[0].axis, radians);
let rotas = {
posr:point,
rota:trainmodel.children[0].rotation.y
}
trainmodel.children[1].rotalist.push(rotas);
let offsetz = parseFloat(point.z) - parseFloat(trainmodel.children[0].matrixWorld.elements[14]);
trainmodel.children[0].position.z += offsetz;
//trainmodel.position.z = point.z;
}
trainmodel.position.x = point.x;
trainmodel.position.y = 0;
if(trainmodel.children[1].rotalist.length > 0 || trainmodel.children[2].rotalist.length > 0 || trainmodel.children[3].rotalist.length > 0 || trainmodel.children[4].rotalist.length > 0|| trainmodel.children[5].rotalist.length > 0){
for(let rs = 1;rs<6;rs++){
//console.log(rs);
if(trainmodel.children[rs].rotalist[0]){
let offsetz = parseFloat(trainmodel.children[rs].rotalist[0].posr.z) - parseFloat(trainmodel.children[rs].matrixWorld.elements[14]);
trainmodel.children[rs].position.z += offsetz;
for(let xh=0;xh<trainmodel.children[rs].rotalist.length;xh++){
if((trainmodel.children[rs].matrixWorld.elements[12]+38)>=trainmodel.children[rs].rotalist[0].posr.x){
if(rs != 5){
let asd = trainmodel.children[rs].rotalist[0];
trainmodel.children[rs+1].rotalist.push(asd);
}
//let offsetx = trainmodel.children[1].matrixWorld.elements[12]-trainmodel.children[0].children[3].matrixWorld.elements[12];
trainmodel.children[rs].rotation.y = trainmodel.children[rs].rotalist[0].rota;
trainmodel.children[rs].rotalist.splice(0,1)
xh--;
}else{
xh = trainmodel.children[rs].rotalist.length;
}
}
//console.log(trainmodel.children[rs].rotalist.length);
}
}
// console.log(trainmodel.rotalist);
}
if(trainmodel.progress > -(trainmodel.speeds)){
trainmodel.progress += trainmodel.speeds;
}
}
}
}
}
}
}
}
}
}

View File

@ -0,0 +1,193 @@
//componnent
import {SectionList} from '@/jlmap3d/model/SectionList.js';
import {SignalList} from '@/jlmap3d/model/SignalList.js';
import {StationStandList} from '@/jlmap3d/model/StationStandList.js';
import {TrainList} from '@/jlmap3d/model/TrainList.js';
import {RealSectionList} from '@/jlmap3d/model/RealSectionList.js';
import {Materialload} from '@/jlmap3d/component/Materialload.js';
import { Loading } from 'element-ui';
// import {SwitchModel} from '@/jlmap3d/model/SwitchModel.js';
export function ModelLoad(data,scope,netdata,mapdata,camera,controls,scene){
//console.log(mapdata);
Materialload(scope);
//console.log(data);
//console.log(scope);
let sceneload = scene;
let jlmap3ddata = mapdata;
let assetloader = scope.assetloader;
let animateswitch = scope.animateswitch;
let mixers = scope.mixers;
let actions = scope.actions;
let loadingInstance = Loading.service({ fullscreen: true });
let isSection = false;
if(netdata.assets){
let assetsdata = JSON.parse(netdata.assets);
for(let i=0;i<assetsdata.length;i++){
if(assetsdata[i].deviceType == "mapSection"){
isSection = true;
}
}
}
if(isSection == true){
init3d(data,netdata);
}else{
loadingInstance.close();
alert("没有三维数据");
}
function init3d(data,netdata){
let mapdata = data;
// console.log(data);
//初始化轨道和道岔 暂时
lengthfact(data);
jlmap3ddata.sectionlist = new SectionList();
jlmap3ddata.signallist = new SignalList();
//初始化站台
jlmap3ddata.stationstandlist = new StationStandList();
//初始化测试列车
jlmap3ddata.trainlisttest = new TrainList();
jlmap3ddata.realsectionlist = new RealSectionList();
assetloader.setmodellist(netdata.assets);
assetloader.assetpromise(sceneload)
.then(function(data){
//console.log(data);
return jlmap3ddata.stationstandlist.initpromise(mapdata.stationList,mapdata.stationStandList,sceneload,assetloader,netdata.stands,mixers,actions);
})
.then(function(data){
//console.log(data);
//console.log(assetloader);
return jlmap3ddata.trainlisttest.initpromise(mapdata.trainList,sceneload,assetloader,mixers,actions);
})
.then(function(data){
//console.log(data);
return jlmap3ddata.sectionlist.initpromise(mapdata.sectionList,mapdata.switchList,sceneload);
})
.then(function(data){
//console.log(data);
return jlmap3ddata.realsectionlist.initpromise(jlmap3ddata,sceneload,assetloader,mixers,actions);
})
.then(function(data){
//console.log(data);
return jlmap3ddata.signallist.initpromise(mapdata.signalList,sceneload,assetloader,netdata.signals);
})
.then(function(data){
return new Promise(function(resolve, reject){
let loader = new THREE.OBJLoader( );
loader.load( '../../static/rail/fuzhoupath.obj', function ( obj ) {
let object = obj;
//console.log(object.children.length);
let rail = [];
for(let i=0;i<object.children.length;i++){
let name = object.children[i].name.split("_");
let newmeshname = name[0]+"_"+name[1]+"_"+name[2]+"."+name[3];
let vexlist = [];
//console.log( object.children[i].geometry.attributes.position.array);
for(let j=0;j<object.children[i].geometry.attributes.position.array.length;j){
//console.log(object.children[i].geometry.attributes.position.array[j]);
let ved = new THREE.Vector3( object.children[i].geometry.attributes.position.array[j], object.children[i].geometry.attributes.position.array[j+1], object.children[i].geometry.attributes.position.array[j+2] );
j=j+3;
vexlist.push(ved);
}
if(jlmap3ddata.sectionlist.sections.datalist[newmeshname].code){
jlmap3ddata.sectionlist.sections.datalist[newmeshname].rail = vexlist;
//console.log(jlmap3ddata.sectionlist.sections.datalist[n].rail.length);
}
}
resolve("loadedrealsection");
}, onProgress, onError );
});
})
.then(function(data){
for(let mn=0;mn<scope.assetloader.modellist.length;mn++){
if(scope.assetloader.modellist[mn].name && scope.assetloader.modellist[mn].name == "驾驶台"){
scope.assetloader.modellist[mn].mesh.position.y = -50000;
scene.add(scope.assetloader.modellist[mn].mesh);
}
if(scope.assetloader.modellist[mn].name && scope.assetloader.modellist[mn].name == "suidao"){
scene.add(scope.assetloader.modellist[mn].mesh);
}
}
scope.animateswitch = true;
mapdata = jlmap3ddata;
scope.Subscribe.updatamap(mapdata,scope.materiallist,scope.actions,scope.sceneload);
scope.webwork.postMessage("on");
loadingInstance.close();
});
}
function onProgress( xhr ) {
if ( xhr.lengthComputable ) {
let percentComplete = xhr.loaded / xhr.total * 100;
//console.log( 'model ' + Math.round( percentComplete, 2 ) + '% downloaded' );
}
}
function onError() {}
}
function lengthfact(data){
let linklist = [];
//console.log(data);
for(let i=0;i<data.linkList.length;i++){
let dx = Math.abs(data.linkList[i].lp.x - data.linkList[i].rp.x);
    let dy = Math.abs(data.linkList[i].lp.y - data.linkList[i].rp.y);
    let distance = Math.sqrt(Math.pow(dx,2)+Math.pow(dy,2));
let link = {
code:data.linkList[i].code,
lengthfact:data.linkList[i].lengthFact,
distance:distance
};
linklist.push(link);
}
let sectionlist = [];
for(let i=0;i<data.sectionList.length;i++){
for(let j=0;j<linklist.length;j++){
if(linklist[j].code == data.sectionList[i].linkCode){
let sectionoffset = data.sectionList[i].offsetRight - data.sectionList[i].offsetLeft;
let sectionlengthfact = sectionoffset/linklist[j].distance*linklist[j].lengthfact
let section = {
code:data.sectionList[i].code,
lengthfact:sectionoffset
};
sectionlist.push(section);
j = linklist.length;
}
}
}
//console.log(sectionlist);
}

340
src/jlmap3d/jlmap3d.js Normal file
View File

@ -0,0 +1,340 @@
import Vue from 'vue';
//main
import {Three} from '@/jlmap3d/main/three.min.js';
//模型loader
import { AssetLoader } from '@/jlmap3d/main/loaders/AssetLoader.js';
import {DDSLoader} from '@/jlmap3d/main/loaders/DDSLoader.js';
import {OBJLoader} from '@/jlmap3d/main/loaders/OBJLoader.js';
import {MTLLoader} from '@/jlmap3d/main/loaders/MTLLoader.js';
import { FBXLoader } from '@/jlmap3d/main/loaders/FBXLoader.js';
//controls
import {OrbitControls} from '@/jlmap3d/control/OrbitControls.js';
import { DragControls } from '@/jlmap3d/edit/control/DragControls.js';
//component
import {Helper} from '@/jlmap3d/component/Helper';
//data
import { Jl3ddata } from '@/jlmap3d/jl3ddata';
//setconfig
import { SetCamera } from '@/jlmap3d/config/Camera';
import { SetRender } from '@/jlmap3d/config/Render';
import { SetScene } from '@/jlmap3d/config/Scene';
//加载器
import { ModelLoad } from '@/jlmap3d/model/ModelLoad';
//connect
import {Jlmap3dSubscribe} from '@/jlmap3d/connect/TrainingConnect';
//import {Jlmap3dSubscribe} from '@/jlmap3d/connect/TrainingConnectTest';
import { getPublishMapVersion, getPublishMapDetail,getPublish3dMapDetail} from '@/api/jlmap3d/load3ddata';
//utils
import { UpdateTrain } from '@/jlmap3d/utils/UpdateTrain';
//import { UpdateTrain } from '@/jlmap3d/utils/UpdateTrainTest';
// import { ReStart } from '@/jlmap3d/utils/ReStart';
import {Stats} from '@/jlmap3d/main/lib/stats.min.js';
var clock = new THREE.Clock();
export function JLmap3d(dom, data,skinStyle) {
let scope = this;
this.dom = dom;
//渲染循环开关
this.animateswitch = false;
//初始化webgl渲染
let renderer = SetRender(dom);
dom.appendChild(renderer.domElement);
//定义相机
let camera = SetCamera(dom);
//定义场景(渲染容器)
let scene = SetScene();
//定义镜头操作
let controls = new THREE.OrbitControls(camera);
controls.maxPolarAngle = Math.PI/2;
//controls.minPolarAngle = Math.PI/8;
controls.maxDistance = 1500;
//模型加载器
this.assetloader = new AssetLoader();
//替换材质组,例:信号机不同灯光
this.materiallist = [];
//初始化场景线框和灯光 暂时
Helper(scene);
//点击选中的模型
this.selectmodel = null;
//鼠标点击模型切换
this.raycasterswitch = "stand";
//选中物体描边方框
this.helpbox = null;
//车门,站台门道岔动画构造器
this.mixers = [];
//模型操作命令组
this.actions = {};
this.webwork=new Worker("../../static/workertest/trainworker.js");
//地图模型数据
let mapdata = new Jl3ddata();
//订阅仿真socket
this.Subscribe = new Jlmap3dSubscribe(this.webwork);
//连接到通信
//console.log(this.Subscribe.config);
//this.webwork.postMessage(this.Subscribe.teststomp);
this.Subscribe.socketon(scope.Subscribe.topic);
//初始化加载数据和模型
getPublish3dMapDetail(skinStyle).then(netdata => {
ModelLoad(data,scope,netdata.data,mapdata,camera,controls,scene);
});
//
// let stats = new Stats();
// dom.appendChild( stats.dom );
//开启渲染
animate();
startWorker();
//动画时间
let delta;
//循环渲染函数
function animate() {
//循环渲染
//requestAnimationFrame(animate);
//renderer.setAnimationLoop(animate);
requestAnimationFrame(animate);
//判断渲染是否开启
if(scope.animateswitch == true){
//根据相机渲染场景
renderer.render(scene,camera);
//检测动画构造器播放动画
//stats.update();
}
}
function startWorker(){
if(typeof(Worker)!=="undefined"){
scope.webwork.onmessage = function (event) {
//更新列车位置
UpdateTrain(camera,mapdata.trainlisttest);
delta = clock.getDelta();
for(let i=scope.mixers.length-1;i>=0;i--){
if ( scope.mixers[i] ){
scope.mixers[i].update( delta );
}
}
};
}
}
this.dispose = function(){
renderer.setAnimationLoop(null);
renderer.dispose();
scene.dispose();
controls.dispose();
camera = null;
scope.assetloader = null;
mapdata = null;
scope.selectmodel = null;
scope.materiallist = null;
scope.selectmodel = null;
scope.helpbox = null;
scope.mixers = null;
scope.actions = null;
scope.Subscribe = null;
//console.log(scope);
//scope = null;
}
this.rayswitch = function(value){
this.raycasterswitch = value;
if(scope.helpbox){
scene.remove( scope.helpbox );
scope.helpbox = null;
}
};
this.showstationmsg = function(showtype){
if(showtype == "show"){
for(let st=0;st<mapdata.stationstandlist.group.children.length;st++){
mapdata.stationstandlist.group.children[st].add(mapdata.stationstandlist.textlist[st]);
}
}else{
for(let st=0;st<mapdata.stationstandlist.group.children.length;st++){
mapdata.stationstandlist.group.children[st].remove(mapdata.stationstandlist.textlist[st]);
}
}
};
this.showtrainmsg = function(showtype){
if(showtype == "show"){
for(let st=0;st<mapdata.trainlisttest.textlist.length;st++){
mapdata.trainlisttest.list[mapdata.trainlisttest.textlist[st].tcode].children[0].add(mapdata.trainlisttest.textlist[st]);
}
}else{
for(let st=0;st<mapdata.trainlisttest.textlist.length;st++){
mapdata.trainlisttest.list[mapdata.trainlisttest.textlist[st].tcode].children[0].remove(mapdata.trainlisttest.textlist[st]);
}
}
};
// this.restart = function(){
// ReStart(mapdata);
// };
this.animateon = function(){
controls.enabled = true;
scope.animateswitch = true;
};
this.animateoff = function(){
controls.enabled = false;
scope.animateswitch = false;
};
this.eventon = function(){
//raycaster交互模型点击事件
document.getElementById("testjlmap3d").addEventListener( "mousedown", onselect, false );
//窗口自适应
window.addEventListener( 'resize', onWindowResize, false );
controls.update();
};
this.eventoff = function(){
//console.log("off");
//raycaster交互模型点击事件
document.getElementById("testjlmap3d").removeEventListener( "mousedown", onselect, false );
//窗口自适应
window.removeEventListener( 'resize', onWindowResize, false );
};
this.updatecamera = function(mesh,type){
//console.log(mesh);
if(type == "station"){
camera.position.x = mesh.position.x;
camera.position.y = mesh.position.y+800;
camera.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]);
}
controls.upmodeldirect(mapdata);
controls.update();
}
function onWindowResize() {
//窗口自适应
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
//三维交互点击事件函数
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;
raycaster.setFromCamera( mouse, camera );
if(scope.helpbox){
scene.remove( scope.helpbox );
scope.helpbox = null;
}
if(scope.raycasterswitch == "stand"){
//从站台对象组获取点击目标
let intersects1 = raycaster.intersectObjects( mapdata.stationstandlist.textlist);
//获取最近处点击到的模型对象
if(intersects1[0]){
//遍历对象组获取对象坐标更新相机数据
for(let j=0;j<mapdata.stationstandlist.list.length;j++){
if(intersects1[0].object.name == mapdata.stationstandlist.list[j].mesh.code){
camera.position.x = mapdata.stationstandlist.list[j].mesh.position.x;
camera.position.y = mapdata.stationstandlist.list[j].mesh.position.y+200;
camera.position.z = mapdata.stationstandlist.list[j].mesh.position.z+300;
//更新相机方向
controls.target = new THREE.Vector3(mapdata.stationstandlist.list[j].mesh.position.x,mapdata.stationstandlist.list[j].mesh.position.y,mapdata.stationstandlist.list[j].mesh.position.z);
controls.update();
}
}
}
}
if(scope.raycasterswitch == "train"){
let intersects = raycaster.intersectObjects( mapdata.trainlisttest.textlist);
if(intersects[0]){
for(let j=0;j<mapdata.trainlisttest.list.length;j++){
if(intersects[0].object.name == mapdata.trainlisttest.list[j].name){
// console.log(mapdata.trainlisttest.list[j].position.x);
// console.log(mapdata.trainlisttest.list[j].position.y);
// console.log(mapdata.trainlisttest.list[j].children[2].matrixWorld.elements[14]);
camera.position.x = mapdata.trainlisttest.list[j].position.x;
camera.position.y = 200;
camera.position.z = mapdata.trainlisttest.list[j].children[2].matrixWorld.elements[14]+300;
//console.log(camera.position);
controls.target = new THREE.Vector3(mapdata.trainlisttest.list[j].children[2].matrixWorld.elements[12],mapdata.trainlisttest.list[j].children[2].matrixWorld.elements[13],mapdata.trainlisttest.list[j].children[2].matrixWorld.elements[14]);
controls.update();
}
}
}
}
if(scope.raycasterswitch == "section"){
//console.log(mapdata.sectionlist.sections.modellist);
let intersects = raycaster.intersectObjects( mapdata.sectionlist.sections.modellist,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( mapdata.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"){
let intersects = raycaster.intersectObjects( mapdata.sectionlist.switchs.modellist,true);
if(intersects[0]){
scope.helpbox = new THREE.BoxHelper( intersects[0].object, 0xff0000 );
scene.add( scope.helpbox );
}
}
}
}
}

262
src/jlmap3d/jlmap3dedit.js Normal file
View File

@ -0,0 +1,262 @@
import Vue from 'vue';
//main
import { Three } from '@/jlmap3d/main/three.min.js';
//模型loader
import { AssetLoader } from '@/jlmap3d/main/loaders/AssetLoader.js';
import { DDSLoader } from '@/jlmap3d/main/loaders/DDSLoader.js';
import { OBJLoader } from '@/jlmap3d/main/loaders/OBJLoader.js';
import { MTLLoader } from '@/jlmap3d/main/loaders/MTLLoader.js';
import { FBXLoader } from '@/jlmap3d/main/loaders/FBXLoader.js';
//export
import { OBJExporter} from '@/jlmap3d/main/export/OBJExporter.js';
//controls
import {OrbitControlsedit} from '@/jlmap3d/edit/control/OrbitControlsEdit.js';
import { TransformControls } from '@/jlmap3d/edit/control/TransformControls.js';
import { DragControls } from '@/jlmap3d/edit/control/DragControls.js';
//component
import { Helper } from '@/jlmap3d/component/Helper'
//setconfig
import { SetCamera } from '@/jlmap3d/config/Camera'
import { SetRender } from '@/jlmap3d/config/Render'
import { SetScene } from '@/jlmap3d/config/Scene'
//加载器
import { Jlmap3ddata } from '@/jlmap3d/edit/Jlmap3ddata'
//操作管理器
import { Actionmanage } from '@/jlmap3d/edit/actionmanage'
//connect
import { Jlmap3dSubscribe } from '@/jlmap3d/connect/TrainingConnect'
//utils
export function JLmap3dEdit(dom, data, mapid) {
var scope = this;
this.dom = dom;
this.animateswitch = true;
this.selectswitch = true;
this.selectmodel = null;
//编辑器区分模型点击
this.editmode = null;
//区分编辑器action功能
this.actionmode = null;
this.map2ddata = null;
//objmodel
this.exportmodel = null;
//初始化webgl渲染
this.renderer = SetRender(dom);
this.splineHelperObjects = [];
dom.appendChild(this.renderer.domElement);
//定义相机
this.camera = new THREE.PerspectiveCamera(70, dom.clientWidth/dom.clientHeight, 1, 20000);
this.camera.aspect = window.innerWidth / window.innerHeight;
this.camera.updateProjectionMatrix();
this.camera.position.set(0,0,1800);
//定义场景(渲染容器)
this.scene = SetScene();
//定义镜头操作
this.controls = new THREE.OrbitControlsedit( this.camera);
this.controls.update();
this.transcontrol = new THREE.TransformControls( this.camera, this.renderer.domElement );
this.transcontrol.addEventListener( 'change', render );
this.transcontrol.addEventListener( 'dragging-changed', function ( event ) {
scope.controls.enabled = ! event.value;
scope.selectswitch = ! event.value;
} );
this.scene.add(this.transcontrol);
this.assetloader = new AssetLoader();
//this.assetloader.assetinit(scope.scene);
this.action = new Actionmanage();
this.action.switchaction.on = true;
Helper(scope.scene);
this.mapdata = {
id:null,
mapId:null,
sectionlist:null,
linklist:null,
signallist:null,
stationstandlist:null,
trainlisttest:null,
realsectionlist:null,
path:[]
};
Jlmap3ddata(mapid,scope);
//循环渲染
animate();
//循环渲染函数
function animate() {
if(scope.animateswitch == true){
requestAnimationFrame(animate);
scope.renderer.render(scope.scene,scope.camera);
// scope.controls.update();
}
}
this.restart = function(){
ReStart(scope.mapdata);
};
this.animateon = function(){
scope.animateswitch = true;
controls.enabled = true;
scope.Subscribe.socketon(scope.Subscribe.topic);
animate();
};
this.animateoff = function(){
scope.animateswitch = false;
scope.Subscribe.socketoff(scope.Subscribe.topic);
};
this.eventon = function(){
//console.log("on");
//raycaster交互模型点击事件
document.getElementById("testdraw").addEventListener( "mousedown", onselect, false );
//窗口自适应
window.addEventListener( 'resize', onWindowResize, false );
controls.enabled = true;
scope.controls.update();
};
this.eventoff = function(){
//console.log("off");
//raycaster交互模型点击事件
document.getElementById("testdraw").removeEventListener( "mousedown", onselect, false );
//窗口自适应
window.removeEventListener( 'resize', onWindowResize, false );
};
this.export = function(){
var exporter = new THREE.OBJExporter();
var result = exporter.parse( scope.exportmodel );
console.log(result);
}
this.actiommode = function(changedata){
console.log(scope.editmode);
// console.log(scope.actionmode);
// console.log(changedata);
if(scope.editmode == "trackedit"){
scope.selectmodel = scope.action.sectionaction.changemodel(scope,changedata);
}
if(scope.actionmode == "signaledit"){
scope.selectmodel = scope.action.signalaction.changemodel(scope,changedata);
}
// if(scope.editmode == "stationedit"){
// scope.selectmodel = scope.action.stationaction.raycaster(scope);
// }
//
// if(scope.editmode == "trainedit"){
// scope.selectmodel = scope.action.trainaction.raycaster(scope);
// }
//
// if(scope.editmode == "switchedit"){
// scope.selectmodel = scope.action.switchaction.raycaster(scope);
// }
if(scope.editmode == "pathedit"){
if(scope.actionmode == "drawrail"){
//console.log("drawrail");
scope.selectmodel = scope.action.pathaction.drawline(scope);
}
if(scope.actionmode == "drawcurve"){
scope.selectmodel = scope.action.pathaction.drawcurve(scope);
}
}
}
function onWindowResize() {
//窗口自适应
scope.camera.aspect = window.innerWidth / window.innerHeight;
scope.camera.updateProjectionMatrix();
scope.renderer.setSize( window.innerWidth, window.innerHeight );
}
//三维交互点击事件函数
function onselect(event) {
//console.log("select");
//console.log("select");
if(scope.selectswitch == true){
scope.transcontrol.detach();
//从站台对象组获取点击目标
if(scope.editmode == "trackedit"){
scope.selectmodel = scope.action.sectionaction.raycaster(scope);
}
if(scope.editmode == "signaledit"){
scope.selectmodel = scope.action.signalaction.raycaster(scope);
}
if(scope.editmode == "stationedit"){
scope.selectmodel = scope.action.stationaction.raycaster(scope);
}
if(scope.editmode == "trainedit"){
scope.selectmodel = scope.action.trainaction.raycaster(scope);
}
if(scope.editmode == "switchedit"){
scope.selectmodel = scope.action.switchaction.raycaster(scope);
}
if(scope.editmode == "pathedit"){
scope.selectmodel = scope.action.pathaction.raycaster(scope);
//console.log(scope.selectmodel);
}
if(scope.selectmodel != null){
//console.log(scope.selectmodel.rotation);
scope.transcontrol.attach( scope.selectmodel );
}
}
}
function render() {
scope.renderer.render( scope.scene, scope.camera );
}
}

View File

@ -0,0 +1,262 @@
/**
* @author mrdoob / http://mrdoob.com/
*/
THREE.OBJExporter = function () {};
THREE.OBJExporter.prototype = {
constructor: THREE.OBJExporter,
parse: function ( object ) {
var output = '';
var indexVertex = 0;
var indexVertexUvs = 0;
var indexNormals = 0;
var vertex = new THREE.Vector3();
var normal = new THREE.Vector3();
var uv = new THREE.Vector2();
var i, j, k, l, m, face = [];
var parseMesh = function ( mesh ) {
var nbVertex = 0;
var nbNormals = 0;
var nbVertexUvs = 0;
var geometry = mesh.geometry;
var normalMatrixWorld = new THREE.Matrix3();
if ( geometry instanceof THREE.Geometry ) {
geometry = new THREE.BufferGeometry().setFromObject( mesh );
}
if ( geometry instanceof THREE.BufferGeometry ) {
// shortcuts
var vertices = geometry.getAttribute( 'position' );
var normals = geometry.getAttribute( 'normal' );
var uvs = geometry.getAttribute( 'uv' );
var indices = geometry.getIndex();
// name of the mesh object
output += 'g ' + mesh.name + '\n';
// name of the mesh material
if ( mesh.material && mesh.material.name ) {
output += 'usemtl ' + mesh.material.name + '\n';
}
// vertices
if ( vertices !== undefined ) {
for ( i = 0, l = vertices.count; i < l; i ++, nbVertex ++ ) {
vertex.x = vertices.getX( i );
vertex.y = vertices.getY( i );
vertex.z = vertices.getZ( i );
// transfrom the vertex to world space
vertex.applyMatrix4( mesh.matrixWorld );
// transform the vertex to export format
output += 'v ' + vertex.x + ' ' + vertex.y + ' ' + vertex.z + '\n';
}
}
// uvs
if ( uvs !== undefined ) {
for ( i = 0, l = uvs.count; i < l; i ++, nbVertexUvs ++ ) {
uv.x = uvs.getX( i );
uv.y = uvs.getY( i );
// transform the uv to export format
output += 'vt ' + uv.x + ' ' + uv.y + '\n';
}
}
// normals
if ( normals !== undefined ) {
normalMatrixWorld.getNormalMatrix( mesh.matrixWorld );
for ( i = 0, l = normals.count; i < l; i ++, nbNormals ++ ) {
normal.x = normals.getX( i );
normal.y = normals.getY( i );
normal.z = normals.getZ( i );
// transfrom the normal to world space
normal.applyMatrix3( normalMatrixWorld );
// transform the normal to export format
output += 'vn ' + normal.x + ' ' + normal.y + ' ' + normal.z + '\n';
}
}
// faces
if ( indices !== null ) {
for ( i = 0, l = indices.count; i < l; i += 3 ) {
for ( m = 0; m < 3; m ++ ) {
j = indices.getX( i + m ) + 1;
face[ m ] = ( indexVertex + j ) + ( normals || uvs ? '/' + ( uvs ? ( indexVertexUvs + j ) : '' ) + ( normals ? '/' + ( indexNormals + j ) : '' ) : '' );
}
// transform the face to export format
output += 'f ' + face.join( ' ' ) + "\n";
}
} else {
for ( i = 0, l = vertices.count; i < l; i += 3 ) {
for ( m = 0; m < 3; m ++ ) {
j = i + m + 1;
face[ m ] = ( indexVertex + j ) + ( normals || uvs ? '/' + ( uvs ? ( indexVertexUvs + j ) : '' ) + ( normals ? '/' + ( indexNormals + j ) : '' ) : '' );
}
// transform the face to export format
output += 'f ' + face.join( ' ' ) + "\n";
}
}
} else {
console.warn( 'THREE.OBJExporter.parseMesh(): geometry type unsupported', geometry );
}
// update index
indexVertex += nbVertex;
indexVertexUvs += nbVertexUvs;
indexNormals += nbNormals;
};
var parseLine = function ( line ) {
var nbVertex = 0;
var geometry = line.geometry;
var type = line.type;
if ( geometry instanceof THREE.Geometry ) {
geometry = new THREE.BufferGeometry().setFromObject( line );
}
if ( geometry instanceof THREE.BufferGeometry ) {
// shortcuts
var vertices = geometry.getAttribute( 'position' );
// name of the line object
output += 'g ' + line.name + '\n';
if ( vertices !== undefined ) {
for ( i = 0, l = vertices.count; i < l; i ++, nbVertex ++ ) {
vertex.x = vertices.getX( i );
vertex.y = vertices.getY( i );
vertex.z = vertices.getZ( i );
// transfrom the vertex to world space
vertex.applyMatrix4( line.matrixWorld );
// transform the vertex to export format
output += 'v ' + vertex.x + ' ' + vertex.y + ' ' + vertex.z + '\n';
}
}
if ( type === 'Line' ) {
output += 'l ';
for ( j = 1, l = vertices.count; j <= l; j ++ ) {
output += ( indexVertex + j ) + ' ';
}
output += '\n';
}
if ( type === 'LineSegments' ) {
for ( j = 1, k = j + 1, l = vertices.count; j < l; j += 2, k = j + 1 ) {
output += 'l ' + ( indexVertex + j ) + ' ' + ( indexVertex + k ) + '\n';
}
}
} else {
console.warn( 'THREE.OBJExporter.parseLine(): geometry type unsupported', geometry );
}
// update index
indexVertex += nbVertex;
};
object.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) {
parseMesh( child );
}
if ( child instanceof THREE.Line ) {
parseLine( child );
}
} );
return output;
}
};

15
src/jlmap3d/main/inflate.min.js vendored Normal file
View File

@ -0,0 +1,15 @@
/** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */ (function() {'use strict';var l=void 0,aa=this;function r(c,d){var a=c.split("."),b=aa;!(a[0]in b)&&b.execScript&&b.execScript("var "+a[0]);for(var e;a.length&&(e=a.shift());)!a.length&&d!==l?b[e]=d:b=b[e]?b[e]:b[e]={}};var t="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array&&"undefined"!==typeof DataView;function v(c){var d=c.length,a=0,b=Number.POSITIVE_INFINITY,e,f,g,h,k,m,n,p,s,x;for(p=0;p<d;++p)c[p]>a&&(a=c[p]),c[p]<b&&(b=c[p]);e=1<<a;f=new (t?Uint32Array:Array)(e);g=1;h=0;for(k=2;g<=a;){for(p=0;p<d;++p)if(c[p]===g){m=0;n=h;for(s=0;s<g;++s)m=m<<1|n&1,n>>=1;x=g<<16|p;for(s=m;s<e;s+=k)f[s]=x;++h}++g;h<<=1;k<<=1}return[f,a,b]};function w(c,d){this.g=[];this.h=32768;this.d=this.f=this.a=this.l=0;this.input=t?new Uint8Array(c):c;this.m=!1;this.i=y;this.r=!1;if(d||!(d={}))d.index&&(this.a=d.index),d.bufferSize&&(this.h=d.bufferSize),d.bufferType&&(this.i=d.bufferType),d.resize&&(this.r=d.resize);switch(this.i){case A:this.b=32768;this.c=new (t?Uint8Array:Array)(32768+this.h+258);break;case y:this.b=0;this.c=new (t?Uint8Array:Array)(this.h);this.e=this.z;this.n=this.v;this.j=this.w;break;default:throw Error("invalid inflate mode");
}}var A=0,y=1,B={t:A,s:y};
w.prototype.k=function(){for(;!this.m;){var c=C(this,3);c&1&&(this.m=!0);c>>>=1;switch(c){case 0:var d=this.input,a=this.a,b=this.c,e=this.b,f=d.length,g=l,h=l,k=b.length,m=l;this.d=this.f=0;if(a+1>=f)throw Error("invalid uncompressed block header: LEN");g=d[a++]|d[a++]<<8;if(a+1>=f)throw Error("invalid uncompressed block header: NLEN");h=d[a++]|d[a++]<<8;if(g===~h)throw Error("invalid uncompressed block header: length verify");if(a+g>d.length)throw Error("input buffer is broken");switch(this.i){case A:for(;e+
g>b.length;){m=k-e;g-=m;if(t)b.set(d.subarray(a,a+m),e),e+=m,a+=m;else for(;m--;)b[e++]=d[a++];this.b=e;b=this.e();e=this.b}break;case y:for(;e+g>b.length;)b=this.e({p:2});break;default:throw Error("invalid inflate mode");}if(t)b.set(d.subarray(a,a+g),e),e+=g,a+=g;else for(;g--;)b[e++]=d[a++];this.a=a;this.b=e;this.c=b;break;case 1:this.j(ba,ca);break;case 2:for(var n=C(this,5)+257,p=C(this,5)+1,s=C(this,4)+4,x=new (t?Uint8Array:Array)(D.length),S=l,T=l,U=l,u=l,M=l,F=l,z=l,q=l,V=l,q=0;q<s;++q)x[D[q]]=
C(this,3);if(!t){q=s;for(s=x.length;q<s;++q)x[D[q]]=0}S=v(x);u=new (t?Uint8Array:Array)(n+p);q=0;for(V=n+p;q<V;)switch(M=E(this,S),M){case 16:for(z=3+C(this,2);z--;)u[q++]=F;break;case 17:for(z=3+C(this,3);z--;)u[q++]=0;F=0;break;case 18:for(z=11+C(this,7);z--;)u[q++]=0;F=0;break;default:F=u[q++]=M}T=t?v(u.subarray(0,n)):v(u.slice(0,n));U=t?v(u.subarray(n)):v(u.slice(n));this.j(T,U);break;default:throw Error("unknown BTYPE: "+c);}}return this.n()};
var G=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],D=t?new Uint16Array(G):G,H=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258],I=t?new Uint16Array(H):H,J=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0],K=t?new Uint8Array(J):J,L=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],da=t?new Uint16Array(L):L,ea=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,
13,13],N=t?new Uint8Array(ea):ea,O=new (t?Uint8Array:Array)(288),P,fa;P=0;for(fa=O.length;P<fa;++P)O[P]=143>=P?8:255>=P?9:279>=P?7:8;var ba=v(O),Q=new (t?Uint8Array:Array)(30),R,ga;R=0;for(ga=Q.length;R<ga;++R)Q[R]=5;var ca=v(Q);function C(c,d){for(var a=c.f,b=c.d,e=c.input,f=c.a,g=e.length,h;b<d;){if(f>=g)throw Error("input buffer is broken");a|=e[f++]<<b;b+=8}h=a&(1<<d)-1;c.f=a>>>d;c.d=b-d;c.a=f;return h}
function E(c,d){for(var a=c.f,b=c.d,e=c.input,f=c.a,g=e.length,h=d[0],k=d[1],m,n;b<k&&!(f>=g);)a|=e[f++]<<b,b+=8;m=h[a&(1<<k)-1];n=m>>>16;if(n>b)throw Error("invalid code length: "+n);c.f=a>>n;c.d=b-n;c.a=f;return m&65535}
w.prototype.j=function(c,d){var a=this.c,b=this.b;this.o=c;for(var e=a.length-258,f,g,h,k;256!==(f=E(this,c));)if(256>f)b>=e&&(this.b=b,a=this.e(),b=this.b),a[b++]=f;else{g=f-257;k=I[g];0<K[g]&&(k+=C(this,K[g]));f=E(this,d);h=da[f];0<N[f]&&(h+=C(this,N[f]));b>=e&&(this.b=b,a=this.e(),b=this.b);for(;k--;)a[b]=a[b++-h]}for(;8<=this.d;)this.d-=8,this.a--;this.b=b};
w.prototype.w=function(c,d){var a=this.c,b=this.b;this.o=c;for(var e=a.length,f,g,h,k;256!==(f=E(this,c));)if(256>f)b>=e&&(a=this.e(),e=a.length),a[b++]=f;else{g=f-257;k=I[g];0<K[g]&&(k+=C(this,K[g]));f=E(this,d);h=da[f];0<N[f]&&(h+=C(this,N[f]));b+k>e&&(a=this.e(),e=a.length);for(;k--;)a[b]=a[b++-h]}for(;8<=this.d;)this.d-=8,this.a--;this.b=b};
w.prototype.e=function(){var c=new (t?Uint8Array:Array)(this.b-32768),d=this.b-32768,a,b,e=this.c;if(t)c.set(e.subarray(32768,c.length));else{a=0;for(b=c.length;a<b;++a)c[a]=e[a+32768]}this.g.push(c);this.l+=c.length;if(t)e.set(e.subarray(d,d+32768));else for(a=0;32768>a;++a)e[a]=e[d+a];this.b=32768;return e};
w.prototype.z=function(c){var d,a=this.input.length/this.a+1|0,b,e,f,g=this.input,h=this.c;c&&("number"===typeof c.p&&(a=c.p),"number"===typeof c.u&&(a+=c.u));2>a?(b=(g.length-this.a)/this.o[2],f=258*(b/2)|0,e=f<h.length?h.length+f:h.length<<1):e=h.length*a;t?(d=new Uint8Array(e),d.set(h)):d=h;return this.c=d};
w.prototype.n=function(){var c=0,d=this.c,a=this.g,b,e=new (t?Uint8Array:Array)(this.l+(this.b-32768)),f,g,h,k;if(0===a.length)return t?this.c.subarray(32768,this.b):this.c.slice(32768,this.b);f=0;for(g=a.length;f<g;++f){b=a[f];h=0;for(k=b.length;h<k;++h)e[c++]=b[h]}f=32768;for(g=this.b;f<g;++f)e[c++]=d[f];this.g=[];return this.buffer=e};
w.prototype.v=function(){var c,d=this.b;t?this.r?(c=new Uint8Array(d),c.set(this.c.subarray(0,d))):c=this.c.subarray(0,d):(this.c.length>d&&(this.c.length=d),c=this.c);return this.buffer=c};function W(c,d){var a,b;this.input=c;this.a=0;if(d||!(d={}))d.index&&(this.a=d.index),d.verify&&(this.A=d.verify);a=c[this.a++];b=c[this.a++];switch(a&15){case ha:this.method=ha;break;default:throw Error("unsupported compression method");}if(0!==((a<<8)+b)%31)throw Error("invalid fcheck flag:"+((a<<8)+b)%31);if(b&32)throw Error("fdict flag is not supported");this.q=new w(c,{index:this.a,bufferSize:d.bufferSize,bufferType:d.bufferType,resize:d.resize})}
W.prototype.k=function(){var c=this.input,d,a;d=this.q.k();this.a=this.q.a;if(this.A){a=(c[this.a++]<<24|c[this.a++]<<16|c[this.a++]<<8|c[this.a++])>>>0;var b=d;if("string"===typeof b){var e=b.split(""),f,g;f=0;for(g=e.length;f<g;f++)e[f]=(e[f].charCodeAt(0)&255)>>>0;b=e}for(var h=1,k=0,m=b.length,n,p=0;0<m;){n=1024<m?1024:m;m-=n;do h+=b[p++],k+=h;while(--n);h%=65521;k%=65521}if(a!==(k<<16|h)>>>0)throw Error("invalid adler-32 checksum");}return d};var ha=8;r("Zlib.Inflate",W);r("Zlib.Inflate.prototype.decompress",W.prototype.k);var X={ADAPTIVE:B.s,BLOCK:B.t},Y,Z,$,ia;if(Object.keys)Y=Object.keys(X);else for(Z in Y=[],$=0,X)Y[$++]=Z;$=0;for(ia=Y.length;$<ia;++$)Z=Y[$],r("Zlib.Inflate.BufferType."+Z,X[Z]);}).call(window);

5
src/jlmap3d/main/lib/stats.min.js vendored Normal file
View File

@ -0,0 +1,5 @@
// stats.js - http://github.com/mrdoob/stats.js
export function Stats(){function h(a){c.appendChild(a.dom);return a}function k(a){for(var d=0;d<c.children.length;d++)c.children[d].style.display=d===a?"block":"none";l=a}var l=0,c=document.createElement("div");c.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000";c.addEventListener("click",function(a){a.preventDefault();k(++l%c.children.length)},!1);var g=(performance||Date).now(),e=g,a=0,r=h(new Stats.Panel("FPS","#0ff","#002")),f=h(new Stats.Panel("MS","#0f0","#020"));
if(self.performance&&self.performance.memory)var t=h(new Stats.Panel("MB","#f08","#201"));k(0);return{REVISION:16,dom:c,addPanel:h,showPanel:k,begin:function(){g=(performance||Date).now()},end:function(){a++;var c=(performance||Date).now();f.update(c-g,200);if(c>e+1E3&&(r.update(1E3*a/(c-e),100),e=c,a=0,t)){var d=performance.memory;t.update(d.usedJSHeapSize/1048576,d.jsHeapSizeLimit/1048576)}return c},update:function(){g=this.end()},domElement:c,setMode:k}};
Stats.Panel=function(h,k,l){var c=Infinity,g=0,e=Math.round,a=e(window.devicePixelRatio||1),r=80*a,f=48*a,t=3*a,u=2*a,d=3*a,m=15*a,n=74*a,p=30*a,q=document.createElement("canvas");q.width=r;q.height=f;q.style.cssText="width:80px;height:48px";var b=q.getContext("2d");b.font="bold "+9*a+"px Helvetica,Arial,sans-serif";b.textBaseline="top";b.fillStyle=l;b.fillRect(0,0,r,f);b.fillStyle=k;b.fillText(h,t,u);b.fillRect(d,m,n,p);b.fillStyle=l;b.globalAlpha=.9;b.fillRect(d,m,n,p);return{dom:q,update:function(f,
v){c=Math.min(c,f);g=Math.max(g,f);b.fillStyle=l;b.globalAlpha=1;b.fillRect(0,0,r,m);b.fillStyle=k;b.fillText(e(f)+" "+h+" ("+e(c)+"-"+e(g)+")",t,u);b.drawImage(q,d+a,m,n-a,p,d,m,n-a,p);b.fillRect(d+n-a,m,a,p);b.fillStyle=l;b.globalAlpha=.9;b.fillRect(d+n-a,m,a,e((1-f/v)*p))}}};"object"===typeof module;

View File

@ -0,0 +1,418 @@
import { AssetModel } from '@/jlmap3d/main/loaders/model/Assetmodel';
import { Assetmaterial } from '@/jlmap3d/main/loaders/model/Assetmaterial';
import { Loading } from 'element-ui';
let defaultsignal = {
id:"3",
name:"低位三灯",
deviceType:"signal",
type:"low",
picUrl:"",
assetUrl:"https://joylink.club/oss/models/signal/d3d.FBX"
}
let defaulttrain = {
id:"9",
name:"6节列车",
deviceType:"train",
type:"num4",
picUrl:"",
assetUrl:"https://joylink.club/oss/models/train/train.FBX"
}
let defaultstation = {
id:"8",
name:"福州车站",
deviceType:"stand",
type:"num4",
picUrl:"",
assetUrl:"https://joylink.club/oss/models/station/fuzhou/fuzhou.FBX"
}//https://joylink.club/oss/models/station/fuzhou/fuzhou.FBX
//../../static/model/station/zhantai715(2).FBX
let defaultswitch = {
id:"11",
name:"道岔",
deviceType:"switch",
type:"fuzhou",
picUrl:"",
assetUrl:"../../static/model/daocha/daocha.FBX"
}
let defaultdriver = {
id:"15",
name:"驾驶台",
deviceType:"driver",
type:"driver",
picUrl:"",
assetUrl:"https://joylink.club/oss/models/driver/driver.FBX"
}
let defaultsuidao = {
id:"16",
name:"suidao",
deviceType:"suidao",
type:"suidao",
picUrl:"",
assetUrl:"https://joylink.club/oss/models/suidao/suidao.FBX"
}//https://joylink.club/oss/models/suidao/suidao.FBX
//../../static/model/
export function AssetLoader(){
let scope = this;
this.name = null;
this.modellist = [];
this.materiallist = [];
//初始化资源加载器
this.setmodellist = function (data){
let defaultmodel1 = new AssetModel(defaultsignal);
scope.modellist.push(defaultmodel1);
let defaultmodel2 = new AssetModel(defaulttrain);
scope.modellist.push(defaultmodel2);
let defaultmodel3 = new AssetModel(defaultstation);
scope.modellist.push(defaultmodel3);
let defaultmodel4 = new AssetModel(defaultswitch);
scope.modellist.push(defaultmodel4);
let driver = new AssetModel(defaultdriver);
scope.modellist.push(driver);
let suidao = new AssetModel(defaultsuidao);
scope.modellist.push(suidao);
let modeldata = JSON.parse(data);
for(let j=0;j<modeldata.length;j++){
let had = false;
for(let i=0;i<scope.modellist.length;i++){
if(scope.modellist[i].id == modeldata[j].id){
had = true;
i = scope.modellist.length;
}
}
if(had == false){
let model = new AssetModel(modeldata[j]);
scope.modellist.push(modeldata[j]);
}
}
}
this.assetpromise = function (scene){
let initlist = [];
for(let i=0;i<scope.modellist.length;i++){
initlist.push(fbxpromise(scope.modellist[i]));
}
return new Promise(function(resolve, reject){
Promise.all(initlist).then((result) => {
////console.log(result);
resolve("loaderassets"); //['成功了', 'success']
}).catch((error) => {
//console.log(error);
});
});
}
this.assetinit = function(scene){
return new Promise(function(resolve, reject){
let signal = new AssetModel(defaultsignal);
scope.modellist.push(signal);
let train = new AssetModel(defaulttrain);
scope.modellist.push(train);
let station = new AssetModel(defaultstation);
scope.modellist.push(station);
fbxpromise(signal)
.then(function(data){
////console.log(data);
return fbxpromise(train);
})
.then(function(data){
////console.log(data);
return fbxpromise(station);
})
.then(function(data){
////console.log(scope.modellist);
resolve("loaderassets");
});
});
}
this.loadnewsection = function(newdata,jlmap3dedit){
let loadingInstance = Loading.service({ fullscreen: true });
let scene = jlmap3dedit.scene;
let newmodel = new AssetModel(newdata);
let jlmap3ddata = jlmap3dedit.mapdata;
scope.modellist.push(newmodel);
scene.remove(jlmap3dedit.exportmodel);
var loader = new THREE.FBXLoader();
loader.load( newdata.assetUrl, function ( object ) {
let newmesh = object;
//let mixer = new THREE.AnimationMixer( newmesh );
////console.log(jlmap3ddata.sectionlist);
for(let i=0;i<newmesh.children.length;i++){
let name = newmesh.children[i].name.split("_");
let newmeshname = name[0]+"_"+name[1]+"_"+name[2]+"."+name[3];
if(name[0] == "Switch"){
for(let j=0;j<jlmap3ddata.sectionlist.switchs.datalist.length;j++){
if(jlmap3ddata.sectionlist.switchs.datalist[j].name == newmeshname){
//绿色道岔
var box = new THREE.BoxHelper( newmesh.children[i], 0x00EE00 );
scene.add(box);
let nowname = jlmap3ddata.sectionlist.switchs.datalist[j].name;
let nowcode = jlmap3ddata.sectionlist.switchs.datalist[j].code;
newmesh.children[i].name = nowname;
newmesh.children[i].code = nowcode;
for(let n=0;n<newmesh.children[i].children.length;n++){
newmesh.children[i].children[n].code = nowcode;
}
jlmap3ddata.sectionlist.switchs.modellist[j] = newmesh.children[i];
j = jlmap3ddata.sectionlist.switchs.datalist.length;
}
}
}
if(name[0] == "Section"){
//物理区段
for(let j=0;j<jlmap3ddata.sectionlist.sections.datalist.length;j++){
if(jlmap3ddata.sectionlist.sections.datalist[j].name == newmeshname){
if(jlmap3ddata.sectionlist.sections.datalist[j].isStandTrack == true){
//红色站台区段
var box = new THREE.BoxHelper( newmesh.children[i], 0xff0000 );
}else{
//蓝色其他区段
var box = new THREE.BoxHelper( newmesh.children[i], 0x0000ff );
}
scene.add( box );
let nowname = jlmap3ddata.sectionlist.sections.datalist[j].name;
let nowcode = jlmap3ddata.sectionlist.sections.datalist[j].code;
newmesh.children[i].name = nowname;
newmesh.children[i].code = nowcode;
jlmap3ddata.sectionlist.sections.modellist[j] = newmesh.children[i];
j = jlmap3ddata.sectionlist.sections.datalist.length;
}
}
}
if(name[0] == "Singal"){
for(let j=0;j<jlmap3ddata.signallist.list.length;j++){
if(jlmap3ddata.signallist.list[j].mesh.code == newmeshname){
jlmap3ddata.signallist.list[j].mesh.position.x = newmesh.children[i].position.x;
jlmap3ddata.signallist.list[j].mesh.position.y = newmesh.children[i].position.y;
jlmap3ddata.signallist.list[j].mesh.position.z = newmesh.children[i].position.z;
j = jlmap3ddata.signallist.list.length;
}
}
}
if(name[0] == "Station"){
for(let j=0;j<jlmap3ddata.stationstandlist.list.length;j++){
if(jlmap3ddata.stationstandlist.list[j].mesh.code == newmeshname){
jlmap3ddata.stationstandlist.list[j].mesh.position.x = newmesh.children[i].position.x;
jlmap3ddata.stationstandlist.list[j].mesh.position.y = newmesh.children[i].position.y;
jlmap3ddata.stationstandlist.list[j].mesh.position.z = newmesh.children[i].position.z;
j = jlmap3ddata.stationstandlist.list.length;
}
}
}
}
scene.add(newmesh);
loadingInstance.close();
//console.log("add");
} );
}
//新载入资源
this.loadnewasset = function(jlmap3dedit,newdata,num){
let newmodel = new AssetModel(newdata);
scope.modellist.push(newmodel);
fbxload(newmodel);
var loader = new THREE.FBXLoader();
loader.load( newdata.assetUrl, function ( object ) {
jlmap3dedit.transcontrol.detach();
jlmap3dedit.mapdata.signallist.group.remove(jlmap3dedit.mapdata.signallist.list[num].mesh);
object.name = newdata.uuid;
object.code = jlmap3dedit.mapdata.signallist.list[num].mesh.code;
for(let j=0;j<object.children.length;j++){
object.children[j].code = jlmap3dedit.mapdata.signallist.list[num].mesh.code;
}
object.position.x = jlmap3dedit.mapdata.signallist.list[num].mesh.position.x;
object.position.y = jlmap3dedit.mapdata.signallist.list[num].mesh.position.y;
object.position.z = jlmap3dedit.mapdata.signallist.list[num].mesh.position.z;
object.rotation.x = jlmap3dedit.mapdata.signallist.list[num].mesh.rotation.x;
object.rotation.y = jlmap3dedit.mapdata.signallist.list[num].mesh.rotation.y;
object.rotation.z = jlmap3dedit.mapdata.signallist.list[num].mesh.rotation.z;
object.scale.x = jlmap3dedit.mapdata.signallist.list[num].mesh.scale.x;
object.scale.y = jlmap3dedit.mapdata.signallist.list[num].mesh.scale.y;
object.scale.z = jlmap3dedit.mapdata.signallist.list[num].mesh.scale.z;
//object.scale.set(0.1,0.1,0.1);
jlmap3dedit.mapdata.signallist.list[num].mesh = null;
jlmap3dedit.mapdata.signallist.list[num].mesh = object;
jlmap3dedit.mapdata.signallist.group.add( object );
jlmap3dedit.transcontrol.attach(jlmap3dedit.selectmodel);
jlmap3dedit.selectmodel = jlmap3dedit.mapdata.signallist.list[num].mesh;
return jlmap3dedit.selectmodel;
} );
}
this.loadoldasset = function(jlmap3dedit,newdata,num){
let assetnum = null;
for(let i=0;i<scope.modellist.length;i++){
if(newdata.uuid == scope.modellist[i].uuid){
assetnum = i;
}
}
jlmap3dedit.transcontrol.detach();
jlmap3dedit.mapdata.signallist.group.remove(jlmap3dedit.mapdata.signallist.list[num].mesh);
let newmesh = scope.modellist[assetnum].mesh.clone(true);
newmesh.name = scope.modellist[assetnum].uuid;
newmesh.code = jlmap3dedit.mapdata.signallist.list[num].mesh.code;
for(let j=0;j<newmesh.children.length;j++){
newmesh.children[j].code = jlmap3dedit.mapdata.signallist.list[num].mesh.code;
}
newmesh.position.x = jlmap3dedit.mapdata.signallist.list[num].mesh.position.x;
newmesh.position.y = jlmap3dedit.mapdata.signallist.list[num].mesh.position.y;
newmesh.position.z = jlmap3dedit.mapdata.signallist.list[num].mesh.position.z;
newmesh.rotation.x = jlmap3dedit.mapdata.signallist.list[num].mesh.rotation.x;
newmesh.rotation.y = jlmap3dedit.mapdata.signallist.list[num].mesh.rotation.y;
newmesh.rotation.z = jlmap3dedit.mapdata.signallist.list[num].mesh.rotation.z;
jlmap3dedit.mapdata.signallist.list[num].mesh = null;
jlmap3dedit.mapdata.signallist.list[num].mesh = newmesh;
jlmap3dedit.mapdata.signallist.group.add( jlmap3dedit.mapdata.signallist.list[num].mesh );
jlmap3dedit.transcontrol.attach(jlmap3dedit.mapdata.signallist.list[num].mesh);
jlmap3dedit.selectmodel = jlmap3dedit.mapdata.signallist.list[num].mesh;
return jlmap3dedit.selectmodel;
}
//去除未加载资源并释放内存
this.updatelist = function(){
}
//创建新模型
this.createmodel = function(){
}
//创建新材质
this.creatematerial = function(){
}
function fbxload(asset){
var loader = new THREE.FBXLoader();
loader.load( asset.assetUrl, function ( object ) {
//object.scale.set(0.1,0.1,0.1);
asset.mesh = object;
} );
}
function fbxpromise(asset){
return new Promise(function(resolve, reject){
var loader = new THREE.FBXLoader();
loader.load( asset.assetUrl, function ( object ) {
let mixer = new THREE.AnimationMixer( object );
object.traverse(function (node) {//获取其中对象
node.frustumCulled = true;
});
if(asset.deviceType == "train"){
let realtrain = new THREE.Group();
for(let j=6;j>0;j--){
let name = "c"+j;
for(let i=0;i<object.children.length;i++){
if(object.children[i].name == name){
object.children[i].position.x = object.children[i].position.x+38.1;
//object.children[i].position.y = j*10;
realtrain.add(object.children[i]);
i--;
}
}
}
asset.mesh = realtrain;
asset.animations = object.animations[0].tracks;
}else{
asset.mesh = object;
}
//object.scale.set(0.1,0.1,0.1);
resolve("fbxload");
} );
});
}
}

View File

@ -0,0 +1,272 @@
/*
* @author mrdoob / http://mrdoob.com/
*/
THREE.DDSLoader = function ( manager ) {
THREE.CompressedTextureLoader.call( this, manager );
this._parser = THREE.DDSLoader.parse;
};
THREE.DDSLoader.prototype = Object.create( THREE.CompressedTextureLoader.prototype );
THREE.DDSLoader.prototype.constructor = THREE.DDSLoader;
THREE.DDSLoader.parse = function ( buffer, loadMipmaps ) {
var dds = { mipmaps: [], width: 0, height: 0, format: null, mipmapCount: 1 };
// Adapted from @toji's DDS utils
// https://github.com/toji/webgl-texture-utils/blob/master/texture-util/dds.js
// All values and structures referenced from:
// http://msdn.microsoft.com/en-us/library/bb943991.aspx/
var DDS_MAGIC = 0x20534444;
var DDSD_CAPS = 0x1,
DDSD_HEIGHT = 0x2,
DDSD_WIDTH = 0x4,
DDSD_PITCH = 0x8,
DDSD_PIXELFORMAT = 0x1000,
DDSD_MIPMAPCOUNT = 0x20000,
DDSD_LINEARSIZE = 0x80000,
DDSD_DEPTH = 0x800000;
var DDSCAPS_COMPLEX = 0x8,
DDSCAPS_MIPMAP = 0x400000,
DDSCAPS_TEXTURE = 0x1000;
var DDSCAPS2_CUBEMAP = 0x200,
DDSCAPS2_CUBEMAP_POSITIVEX = 0x400,
DDSCAPS2_CUBEMAP_NEGATIVEX = 0x800,
DDSCAPS2_CUBEMAP_POSITIVEY = 0x1000,
DDSCAPS2_CUBEMAP_NEGATIVEY = 0x2000,
DDSCAPS2_CUBEMAP_POSITIVEZ = 0x4000,
DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x8000,
DDSCAPS2_VOLUME = 0x200000;
var DDPF_ALPHAPIXELS = 0x1,
DDPF_ALPHA = 0x2,
DDPF_FOURCC = 0x4,
DDPF_RGB = 0x40,
DDPF_YUV = 0x200,
DDPF_LUMINANCE = 0x20000;
function fourCCToInt32( value ) {
return value.charCodeAt( 0 ) +
( value.charCodeAt( 1 ) << 8 ) +
( value.charCodeAt( 2 ) << 16 ) +
( value.charCodeAt( 3 ) << 24 );
}
function int32ToFourCC( value ) {
return String.fromCharCode(
value & 0xff,
( value >> 8 ) & 0xff,
( value >> 16 ) & 0xff,
( value >> 24 ) & 0xff
);
}
function loadARGBMip( buffer, dataOffset, width, height ) {
var dataLength = width * height * 4;
var srcBuffer = new Uint8Array( buffer, dataOffset, dataLength );
var byteArray = new Uint8Array( dataLength );
var dst = 0;
var src = 0;
for ( var y = 0; y < height; y ++ ) {
for ( var x = 0; x < width; x ++ ) {
var b = srcBuffer[ src ]; src ++;
var g = srcBuffer[ src ]; src ++;
var r = srcBuffer[ src ]; src ++;
var a = srcBuffer[ src ]; src ++;
byteArray[ dst ] = r; dst ++; //r
byteArray[ dst ] = g; dst ++; //g
byteArray[ dst ] = b; dst ++; //b
byteArray[ dst ] = a; dst ++; //a
}
}
return byteArray;
}
var FOURCC_DXT1 = fourCCToInt32( "DXT1" );
var FOURCC_DXT3 = fourCCToInt32( "DXT3" );
var FOURCC_DXT5 = fourCCToInt32( "DXT5" );
var FOURCC_ETC1 = fourCCToInt32( "ETC1" );
var headerLengthInt = 31; // The header length in 32 bit ints
// Offsets into the header array
var off_magic = 0;
var off_size = 1;
var off_flags = 2;
var off_height = 3;
var off_width = 4;
var off_mipmapCount = 7;
var off_pfFlags = 20;
var off_pfFourCC = 21;
var off_RGBBitCount = 22;
var off_RBitMask = 23;
var off_GBitMask = 24;
var off_BBitMask = 25;
var off_ABitMask = 26;
var off_caps = 27;
var off_caps2 = 28;
var off_caps3 = 29;
var off_caps4 = 30;
// Parse header
var header = new Int32Array( buffer, 0, headerLengthInt );
if ( header[ off_magic ] !== DDS_MAGIC ) {
console.error( 'THREE.DDSLoader.parse: Invalid magic number in DDS header.' );
return dds;
}
if ( ! header[ off_pfFlags ] & DDPF_FOURCC ) {
console.error( 'THREE.DDSLoader.parse: Unsupported format, must contain a FourCC code.' );
return dds;
}
var blockBytes;
var fourCC = header[ off_pfFourCC ];
var isRGBAUncompressed = false;
switch ( fourCC ) {
case FOURCC_DXT1:
blockBytes = 8;
dds.format = THREE.RGB_S3TC_DXT1_Format;
break;
case FOURCC_DXT3:
blockBytes = 16;
dds.format = THREE.RGBA_S3TC_DXT3_Format;
break;
case FOURCC_DXT5:
blockBytes = 16;
dds.format = THREE.RGBA_S3TC_DXT5_Format;
break;
case FOURCC_ETC1:
blockBytes = 8;
dds.format = THREE.RGB_ETC1_Format;
break;
default:
if ( header[ off_RGBBitCount ] === 32
&& header[ off_RBitMask ] & 0xff0000
&& header[ off_GBitMask ] & 0xff00
&& header[ off_BBitMask ] & 0xff
&& header[ off_ABitMask ] & 0xff000000 ) {
isRGBAUncompressed = true;
blockBytes = 64;
dds.format = THREE.RGBAFormat;
} else {
console.error( 'THREE.DDSLoader.parse: Unsupported FourCC code ', int32ToFourCC( fourCC ) );
return dds;
}
}
dds.mipmapCount = 1;
if ( header[ off_flags ] & DDSD_MIPMAPCOUNT && loadMipmaps !== false ) {
dds.mipmapCount = Math.max( 1, header[ off_mipmapCount ] );
}
var caps2 = header[ off_caps2 ];
dds.isCubemap = caps2 & DDSCAPS2_CUBEMAP ? true : false;
if ( dds.isCubemap && (
! ( caps2 & DDSCAPS2_CUBEMAP_POSITIVEX ) ||
! ( caps2 & DDSCAPS2_CUBEMAP_NEGATIVEX ) ||
! ( caps2 & DDSCAPS2_CUBEMAP_POSITIVEY ) ||
! ( caps2 & DDSCAPS2_CUBEMAP_NEGATIVEY ) ||
! ( caps2 & DDSCAPS2_CUBEMAP_POSITIVEZ ) ||
! ( caps2 & DDSCAPS2_CUBEMAP_NEGATIVEZ )
) ) {
console.error( 'THREE.DDSLoader.parse: Incomplete cubemap faces' );
return dds;
}
dds.width = header[ off_width ];
dds.height = header[ off_height ];
var dataOffset = header[ off_size ] + 4;
// Extract mipmaps buffers
var faces = dds.isCubemap ? 6 : 1;
for ( var face = 0; face < faces; face ++ ) {
var width = dds.width;
var height = dds.height;
for ( var i = 0; i < dds.mipmapCount; i ++ ) {
if ( isRGBAUncompressed ) {
var byteArray = loadARGBMip( buffer, dataOffset, width, height );
var dataLength = byteArray.length;
} else {
var dataLength = Math.max( 4, width ) / 4 * Math.max( 4, height ) / 4 * blockBytes;
var byteArray = new Uint8Array( buffer, dataOffset, dataLength );
}
var mipmap = { "data": byteArray, "width": width, "height": height };
dds.mipmaps.push( mipmap );
dataOffset += dataLength;
width = Math.max( width >> 1, 1 );
height = Math.max( height >> 1, 1 );
}
}
return dds;
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,583 @@
/**
* Loads a Wavefront .mtl file specifying materials
*
* @author angelxuanchang
*/
THREE.MTLLoader = function ( manager ) {
this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
};
THREE.MTLLoader.prototype = {
constructor: THREE.MTLLoader,
/**
* Loads and parses a MTL asset from a URL.
*
* @param {String} url - URL to the MTL file.
* @param {Function} [onLoad] - Callback invoked with the loaded object.
* @param {Function} [onProgress] - Callback for download progress.
* @param {Function} [onError] - Callback for download errors.
*
* @see setPath setResourcePath
*
* @note In order for relative texture references to resolve correctly
* you must call setResourcePath() explicitly prior to load.
*/
load: function ( url, onLoad, onProgress, onError ) {
var scope = this;
var path = ( this.path === undefined ) ? THREE.LoaderUtils.extractUrlBase( url ) : this.path;
var loader = new THREE.FileLoader( this.manager );
loader.setPath( this.path );
loader.load( url, function ( text ) {
onLoad( scope.parse( text, path ) );
}, onProgress, onError );
},
/**
* Set base path for resolving references.
* If set this path will be prepended to each loaded and found reference.
*
* @see setResourcePath
* @param {String} path
* @return {THREE.MTLLoader}
*
* @example
* mtlLoader.setPath( 'assets/obj/' );
* mtlLoader.load( 'my.mtl', ... );
*/
setPath: function ( path ) {
this.path = path;
return this;
},
/**
* Set base path for additional resources like textures.
*
* @see setPath
* @param {String} path
* @return {THREE.MTLLoader}
*
* @example
* mtlLoader.setPath( 'assets/obj/' );
* mtlLoader.setResourcePath( 'assets/textures/' );
* mtlLoader.load( 'my.mtl', ... );
*/
setResourcePath: function ( path ) {
this.resourcePath = path;
return this;
},
setTexturePath: function ( path ) {
console.warn( 'THREE.MTLLoader: .setTexturePath() has been renamed to .setResourcePath().' );
return this.setResourcePath( path );
},
setCrossOrigin: function ( value ) {
this.crossOrigin = value;
return this;
},
setMaterialOptions: function ( value ) {
this.materialOptions = value;
return this;
},
/**
* Parses a MTL file.
*
* @param {String} text - Content of MTL file
* @return {THREE.MTLLoader.MaterialCreator}
*
* @see setPath setResourcePath
*
* @note In order for relative texture references to resolve correctly
* you must call setResourcePath() explicitly prior to parse.
*/
parse: function ( text, path ) {
var lines = text.split( '\n' );
var info = {};
var delimiter_pattern = /\s+/;
var materialsInfo = {};
for ( var i = 0; i < lines.length; i ++ ) {
var line = lines[ i ];
line = line.trim();
if ( line.length === 0 || line.charAt( 0 ) === '#' ) {
// Blank line or comment ignore
continue;
}
var pos = line.indexOf( ' ' );
var key = ( pos >= 0 ) ? line.substring( 0, pos ) : line;
key = key.toLowerCase();
var value = ( pos >= 0 ) ? line.substring( pos + 1 ) : '';
value = value.trim();
if ( key === 'newmtl' ) {
// New material
info = { name: value };
materialsInfo[ value ] = info;
} else {
if ( key === 'ka' || key === 'kd' || key === 'ks' || key ==='ke' ) {
var ss = value.split( delimiter_pattern, 3 );
info[ key ] = [ parseFloat( ss[ 0 ] ), parseFloat( ss[ 1 ] ), parseFloat( ss[ 2 ] ) ];
} else {
info[ key ] = value;
}
}
}
var materialCreator = new THREE.MTLLoader.MaterialCreator( this.resourcePath || path, this.materialOptions );
materialCreator.setCrossOrigin( this.crossOrigin );
materialCreator.setManager( this.manager );
materialCreator.setMaterials( materialsInfo );
return materialCreator;
}
};
/**
* Create a new THREE-MTLLoader.MaterialCreator
* @param baseUrl - Url relative to which textures are loaded
* @param options - Set of options on how to construct the materials
* side: Which side to apply the material
* THREE.FrontSide (default), THREE.BackSide, THREE.DoubleSide
* wrap: What type of wrapping to apply for textures
* THREE.RepeatWrapping (default), THREE.ClampToEdgeWrapping, THREE.MirroredRepeatWrapping
* normalizeRGB: RGBs need to be normalized to 0-1 from 0-255
* Default: false, assumed to be already normalized
* ignoreZeroRGBs: Ignore values of RGBs (Ka,Kd,Ks) that are all 0's
* Default: false
* @constructor
*/
THREE.MTLLoader.MaterialCreator = function ( baseUrl, options ) {
this.baseUrl = baseUrl || '';
this.options = options;
this.materialsInfo = {};
this.materials = {};
this.materialsArray = [];
this.nameLookup = {};
this.side = ( this.options && this.options.side ) ? this.options.side : THREE.FrontSide;
this.wrap = ( this.options && this.options.wrap ) ? this.options.wrap : THREE.RepeatWrapping;
};
THREE.MTLLoader.MaterialCreator.prototype = {
constructor: THREE.MTLLoader.MaterialCreator,
crossOrigin: 'anonymous',
setCrossOrigin: function ( value ) {
this.crossOrigin = value;
return this;
},
setManager: function ( value ) {
this.manager = value;
},
setMaterials: function ( materialsInfo ) {
this.materialsInfo = this.convert( materialsInfo );
this.materials = {};
this.materialsArray = [];
this.nameLookup = {};
},
convert: function ( materialsInfo ) {
if ( ! this.options ) return materialsInfo;
var converted = {};
for ( var mn in materialsInfo ) {
// Convert materials info into normalized form based on options
var mat = materialsInfo[ mn ];
var covmat = {};
converted[ mn ] = covmat;
for ( var prop in mat ) {
var save = true;
var value = mat[ prop ];
var lprop = prop.toLowerCase();
switch ( lprop ) {
case 'kd':
case 'ka':
case 'ks':
// Diffuse color (color under white light) using RGB values
if ( this.options && this.options.normalizeRGB ) {
value = [ value[ 0 ] / 255, value[ 1 ] / 255, value[ 2 ] / 255 ];
}
if ( this.options && this.options.ignoreZeroRGBs ) {
if ( value[ 0 ] === 0 && value[ 1 ] === 0 && value[ 2 ] === 0 ) {
// ignore
save = false;
}
}
break;
default:
break;
}
if ( save ) {
covmat[ lprop ] = value;
}
}
}
return converted;
},
preload: function () {
for ( var mn in this.materialsInfo ) {
this.create( mn );
}
},
getIndex: function ( materialName ) {
return this.nameLookup[ materialName ];
},
getAsArray: function () {
var index = 0;
for ( var mn in this.materialsInfo ) {
this.materialsArray[ index ] = this.create( mn );
this.nameLookup[ mn ] = index;
index ++;
}
return this.materialsArray;
},
create: function ( materialName ) {
if ( this.materials[ materialName ] === undefined ) {
this.createMaterial_( materialName );
}
return this.materials[ materialName ];
},
createMaterial_: function ( materialName ) {
// Create material
var scope = this;
var mat = this.materialsInfo[ materialName ];
var params = {
name: materialName,
side: this.side
};
function resolveURL( baseUrl, url ) {
if ( typeof url !== 'string' || url === '' )
return '';
// Absolute URL
if ( /^https?:\/\//i.test( url ) ) return url;
return baseUrl + url;
}
function setMapForType( mapType, value ) {
if ( params[ mapType ] ) return; // Keep the first encountered texture
var texParams = scope.getTextureParams( value, params );
var map = scope.loadTexture( resolveURL( scope.baseUrl, texParams.url ) );
map.repeat.copy( texParams.scale );
map.offset.copy( texParams.offset );
map.wrapS = scope.wrap;
map.wrapT = scope.wrap;
params[ mapType ] = map;
}
for ( var prop in mat ) {
var value = mat[ prop ];
var n;
if ( value === '' ) continue;
switch ( prop.toLowerCase() ) {
// Ns is material specular exponent
case 'kd':
// Diffuse color (color under white light) using RGB values
params.color = new THREE.Color().fromArray( value );
break;
case 'ks':
// Specular color (color when light is reflected from shiny surface) using RGB values
params.specular = new THREE.Color().fromArray( value );
break;
case 'ke':
// Emissive using RGB values
params.emissive = new THREE.Color().fromArray( value );
break;
case 'map_kd':
// Diffuse texture map
setMapForType( "map", value );
break;
case 'map_ks':
// Specular map
setMapForType( "specularMap", value );
break;
case 'map_ke':
// Emissive map
setMapForType( "emissiveMap", value );
break;
case 'norm':
setMapForType( "normalMap", value );
break;
case 'map_bump':
case 'bump':
// Bump texture map
setMapForType( "bumpMap", value );
break;
case 'map_d':
// Alpha map
setMapForType( "alphaMap", value );
params.transparent = true;
break;
case 'ns':
// The specular exponent (defines the focus of the specular highlight)
// A high exponent results in a tight, concentrated highlight. Ns values normally range from 0 to 1000.
params.shininess = parseFloat( value );
break;
case 'd':
n = parseFloat( value );
if ( n < 1 ) {
params.opacity = n;
params.transparent = true;
}
break;
case 'tr':
n = parseFloat( value );
if ( this.options && this.options.invertTrProperty ) n = 1 - n;
if ( n > 0 ) {
params.opacity = 1 - n;
params.transparent = true;
}
break;
default:
break;
}
}
this.materials[ materialName ] = new THREE.MeshPhongMaterial( params );
return this.materials[ materialName ];
},
getTextureParams: function ( value, matParams ) {
var texParams = {
scale: new THREE.Vector2( 1, 1 ),
offset: new THREE.Vector2( 0, 0 )
};
var items = value.split( /\s+/ );
var pos;
pos = items.indexOf( '-bm' );
if ( pos >= 0 ) {
matParams.bumpScale = parseFloat( items[ pos + 1 ] );
items.splice( pos, 2 );
}
pos = items.indexOf( '-s' );
if ( pos >= 0 ) {
texParams.scale.set( parseFloat( items[ pos + 1 ] ), parseFloat( items[ pos + 2 ] ) );
items.splice( pos, 4 ); // we expect 3 parameters here!
}
pos = items.indexOf( '-o' );
if ( pos >= 0 ) {
texParams.offset.set( parseFloat( items[ pos + 1 ] ), parseFloat( items[ pos + 2 ] ) );
items.splice( pos, 4 ); // we expect 3 parameters here!
}
texParams.url = items.join( ' ' ).trim();
return texParams;
},
loadTexture: function ( url, mapping, onLoad, onProgress, onError ) {
var texture;
var loader = THREE.Loader.Handlers.get( url );
var manager = ( this.manager !== undefined ) ? this.manager : THREE.DefaultLoadingManager;
if ( loader === null ) {
loader = new THREE.TextureLoader( manager );
}
if ( loader.setCrossOrigin ) loader.setCrossOrigin( this.crossOrigin );
texture = loader.load( url, onLoad, onProgress, onError );
if ( mapping !== undefined ) texture.mapping = mapping;
return texture;
}
};

Some files were not shown because too many files have changed in this diff Show More