增加三维课程事故特效管理模块

This commit is contained in:
sunzhenyu 2021-09-07 18:21:35 +08:00
parent 297e417113
commit 813d694ccc
9 changed files with 230 additions and 41 deletions

View File

@ -4,9 +4,9 @@ export function Fire() {
var last_time_activate = Date.now(); var last_time_activate = Date.now();
this.init = function(scene){ this.createNew = function(scene,pos){
scope.points = new Points(); scope.points = new Points(pos);
scope.points.init(); scope.points.init(pos);
scene.add(scope.points.obj); scene.add(scope.points.obj);
} }
@ -77,9 +77,10 @@ export function Fire() {
}; };
var Points = function() { var Points = function(pos) {
this.movers_num = 3000; this.movers_num = 3000;
this.movers = []; this.movers = [];
this.pos = pos;
this.geometry = null; this.geometry = null;
this.material = null; this.material = null;
this.obj = null; this.obj = null;
@ -88,7 +89,7 @@ export function Fire() {
}; };
Points.prototype = { Points.prototype = {
init: function() { init: function(pos) {
this.createTexture(); this.createTexture();
this.geometry = new THREE.Geometry(); this.geometry = new THREE.Geometry();
this.material = new THREE.PointsMaterial({ this.material = new THREE.PointsMaterial({
@ -105,7 +106,7 @@ Points.prototype = {
for (var i = 0; i < this.movers_num; i++) { for (var i = 0; i < this.movers_num; i++) {
var mover = new Mover(); var mover = new Mover();
mover.init(new THREE.Vector3((10*Math.random()-49), 1.6, (10*Math.random()+11))); mover.init(new THREE.Vector3((10*Math.random()+pos.x),pos.y, (10*Math.random()+pos.z)));
this.movers.push(mover); this.movers.push(mover);
this.geometry.vertices.push(mover.position); this.geometry.vertices.push(mover.position);
} }
@ -121,7 +122,7 @@ Points.prototype = {
mover.applyForce(this.antigravity); mover.applyForce(this.antigravity);
mover.updateVelocity(); mover.updateVelocity();
mover.updatePosition(); mover.updatePosition();
if (mover.position.y > 8) { if (mover.position.y > (this.pos.y+5)) {
mover.inactivate(); mover.inactivate();
} }
} }
@ -132,6 +133,7 @@ Points.prototype = {
}, },
activateMover: function() { activateMover: function() {
var count = 0; var count = 0;
let pos = this.pos;
for (var i = 0; i < this.movers.length; i++) { for (var i = 0; i < this.movers.length; i++) {
var mover = this.movers[i]; var mover = this.movers[i];
@ -140,7 +142,7 @@ Points.prototype = {
var rad2 = getRadian(getRandomInt(0, 360)); var rad2 = getRadian(getRandomInt(0, 360));
var force = getSpherical(rad1, rad2, 1); var force = getSpherical(rad1, rad2, 1);
mover.activate(); mover.activate();
mover.init(new THREE.Vector3((10*Math.random()-49), 5, (10*Math.random()+11))); mover.init(new THREE.Vector3((10*Math.random()+pos.x), pos.y+5, (10*Math.random()+pos.z)));
mover.applyForce(force); mover.applyForce(force);
count++; count++;

View File

@ -76,8 +76,10 @@ export function Lesson3dEditor(dom,lessonData) {
} ); } );
// //
scene.add(transcontrol); scene.add(transcontrol);
let accidentManager = new AccidentManager(scene); let accidentManager = new AccidentManager(scene);
accidentManager.init(); accidentManager.initAccident();
let assetModelManager = new AssetModelManager(scope,scene); let assetModelManager = new AssetModelManager(scope,scene);
if(lessonData){ if(lessonData){
@ -87,6 +89,11 @@ export function Lesson3dEditor(dom,lessonData) {
}else{ }else{
assetModelManager.lessonAssetsLoader(); assetModelManager.lessonAssetsLoader();
} }
if(lessonData.accidentList){
accidentManager.loadAccidentList(lessonData.accidentList)
}
}else{ }else{
assetModelManager.lessonAssetsLoader(); assetModelManager.lessonAssetsLoader();
} }
@ -100,6 +107,7 @@ export function Lesson3dEditor(dom,lessonData) {
render(); render();
scope.controls.update(); scope.controls.update();
// delta = clock.getDelta(); // delta = clock.getDelta();
accidentManager.update();
requestAnimationFrame(animate); requestAnimationFrame(animate);
} }
@ -114,8 +122,11 @@ export function Lesson3dEditor(dom,lessonData) {
this.changeIndex = function(nowIndex){ this.changeIndex = function(nowIndex){
lessonIndex = nowIndex; lessonIndex = nowIndex;
console.log(lessonData.lessonProgress[lessonIndex]);
scope.nowSceneType = lessonData.lessonProgress[lessonIndex].progressScene; scope.nowSceneType = lessonData.lessonProgress[lessonIndex].progressScene;
assetModelManager.changeSceneGroup(scope.nowSceneType); assetModelManager.changeSceneGroup(scope.nowSceneType);
accidentManager.changeSceneGroup(scope.nowSceneType);
// if(lessonData.lessonProgress[lessonIndex].roleName == nowRole){ // if(lessonData.lessonProgress[lessonIndex].roleName == nowRole){
// controlManager.initControlMode(lessonIndex); // controlManager.initControlMode(lessonIndex);
// controlManager.initRoleMode(true,nowRole); // controlManager.initRoleMode(true,nowRole);
@ -133,6 +144,7 @@ export function Lesson3dEditor(dom,lessonData) {
console.log(value2); console.log(value2);
if(type == "changeScene"){ if(type == "changeScene"){
assetModelManager.changeSceneGroup(value1); assetModelManager.changeSceneGroup(value1);
accidentManager.changeSceneGroup(value1);
scope.nowSceneType = value1; scope.nowSceneType = value1;
} }
} }
@ -157,10 +169,32 @@ export function Lesson3dEditor(dom,lessonData) {
} }
this.createAccident = function(accidentData,mousePos){
var mouse = new THREE.Vector2();
var raycaster = new THREE.Raycaster();
mouse.x = ( mousePos.x / window.innerWidth ) * 2 - 1;
mouse.y = - ( mousePos.y / dom.offsetHeight ) * 2 + 1;
raycaster.setFromCamera(mouse,scope.camerass) // 也可以给构造函数传参的形式写
var intersects = raycaster.intersectObjects( scene.children,true );
if(intersects.length>0){
accidentManager.createNewAccident(accidentData,intersects[0].point,scope.nowSceneType);
}
}
this.saveAssetModel = function(){ this.saveAssetModel = function(){
return assetModelManager.saveModelList(); return assetModelManager.saveModelList();
} }
this.saveAccidentModel = function(){
return accidentManager.saveDataList();
}
this.attachModel = function(selectModel){ this.attachModel = function(selectModel){
transcontrol.attach(selectModel); transcontrol.attach(selectModel);
} }
@ -169,4 +203,8 @@ export function Lesson3dEditor(dom,lessonData) {
transcontrol.detach(); transcontrol.detach();
assetModelManager.deleteAsset(selectModel,scope.nowSceneType); assetModelManager.deleteAsset(selectModel,scope.nowSceneType);
} }
this.deleteAccident = function(selectAccident){
accidentManager.deleteAccident(selectAccident,scope.nowSceneType);
}
} }

View File

@ -5,27 +5,132 @@ export function AccidentManager(scene) {
let scope = this; let scope = this;
this.accidentList = []; this.accidentList = [];
this.accidentGroup = new THREE.Group(); this.accidentGroup = new THREE.Group();
//场景中可触发事件模型
this.accidentList = [];
scope.accidentList["standstation"] = [];
scope.accidentList["stopstation"] = [];
scope.accidentList["occ"] = [];
scope.accidentList["device"] = [];
scope.accidentList["xl"] = [];
scope.accidentList["dc"] = [];
let groupList = [];
groupList["standstation"] = new THREE.Group();
groupList["stopstation"] = new THREE.Group();
groupList["occ"] = new THREE.Group();
groupList["device"] = new THREE.Group();
groupList["xl"] = new THREE.Group();
groupList["dc"] = new THREE.Group();
let updateSceneType = "standstation";
scene.add(scope.accidentGroup); scene.add(scope.accidentGroup);
this.init = function(){ this.initAccident = function(nowSceneType){
let fire = new Fire(); let accidentData = [
fire.init(scene); {
id:'1',
name:"火灾",
type:"fire"
}
];
jl3dUpdateAccidentData(accidentData);
} }
this.createNewAccident = function(type,pos){ this.saveDataList = function(){
let saveList = [];
for(let g in scope.accidentList){
for(let i=0;i<scope.accidentList[g].length;i++){
if(scope.accidentList[g][i].showType != "default"){
saveList.push({
id:scope.accidentList[g][i].id,
name:scope.accidentList[g][i].name,
label:scope.accidentList[g][i].label,
type:scope.accidentList[g][i].type,
pos:{
x:scope.accidentList[g][i].pos.x,
y:scope.accidentList[g][i].pos.y,
z:scope.accidentList[g][i].pos.z
},
showType:scope.accidentList[g][i].showType,
sceneType:scope.accidentList[g][i].sceneType,
});
}
}
}
return saveList;
}
let fire = new Fire(); this.changeSceneGroup = function(nowSceneType){
fire.init(scene); if(scope.accidentGroup.children.length>0){
scope.accidentGroup.remove(scope.accidentGroup.children[0]);
}
scope.accidentGroup.add(groupList[nowSceneType]);
jl3dUpdateAccidentlist(scope.accidentList[nowSceneType]);
updateSceneType = nowSceneType;
}
this.createNewAccident = function(type,pos,nowSceneType){
var rand = Math.floor(Math.random () * 900) + 100;
let newAccident = { let newAccident = {
id:"xx", id:rand,
type:type name:type,
label:type+rand,
type:type,
object:{},
pos:pos,
sceneType:nowSceneType,
showType:"loadModel",
}; };
if(type == "fire"){
newAccident.object = new Fire();
newAccident.object.createNew(groupList[nowSceneType],pos);
}
scope.accidentList[nowSceneType].push(newAccident);
jl3dUpdateAccidentlist(scope.accidentList[nowSceneType]);
} }
this.loadAccidentList = function(){ this.deleteAccident = function(selectAccident,nowSceneType){
groupList[nowSceneType].remove(selectAccident.object.points.obj);
console.log(selectAccident);
for(let i=0;i<scope.accidentList[nowSceneType].length;i++){
if(scope.accidentList[nowSceneType][i].id == selectAccident.id){
scope.accidentList[nowSceneType].splice(i,1);
jl3dUpdateAccidentlist(scope.accidentList[nowSceneType]);
break;
}
}
}
this.loadAccidentList = function(accidentList){
console.log(accidentList);
for(let i=0;i<accidentList.length;i++){
let newAccident = {
id:accidentList[i].id,
name:accidentList[i].name,
label:accidentList[i].label,
type:accidentList[i].type,
object:{},
pos:accidentList[i].pos,
sceneType:accidentList[i].sceneType,
showType:"loadModel",
};
if(accidentList[i].type == "fire"){
newAccident.object = new Fire();
newAccident.object.createNew(groupList[accidentList[i].sceneType],accidentList[i].pos);
}
scope.accidentList[accidentList[i].sceneType].push(newAccident);
jl3dUpdateAccidentlist(scope.accidentList[accidentList[i].sceneType]);
}
} }
this.changeAccidentStatus = function(){ this.changeAccidentStatus = function(){
@ -33,7 +138,9 @@ export function AccidentManager(scene) {
} }
this.update = function(){ this.update = function(){
for(let i=0;i<scope.accidentList[updateSceneType].length;i++){
scope.accidentList[updateSceneType][i].object.update();
}
} }
} }

View File

@ -10,6 +10,18 @@ export function AssetModelManager(editor,scene) {
this.otherModel = new THREE.Group(); this.otherModel = new THREE.Group();
//场景中可触发事件模型
this.lessonTriggerList = [];
scope.lessonTriggerList["standstation"] = [];
scope.lessonTriggerList["stopstation"] = [];
scope.lessonTriggerList["occ"] = [];
scope.lessonTriggerList["device"] = [];
scope.lessonTriggerList["xl"] = [];
scope.lessonTriggerList["dc"] = [];
let groupList = []; let groupList = [];
groupList["standstation"] = new THREE.Group(); groupList["standstation"] = new THREE.Group();
groupList["stopstation"] = new THREE.Group(); groupList["stopstation"] = new THREE.Group();
@ -111,17 +123,6 @@ export function AssetModelManager(editor,scene) {
}; };
//场景中可触发事件模型
this.lessonTriggerList = [];
scope.lessonTriggerList["standstation"] = [];
scope.lessonTriggerList["stopstation"] = [];
scope.lessonTriggerList["occ"] = [];
scope.lessonTriggerList["device"] = [];
scope.lessonTriggerList["xl"] = [];
scope.lessonTriggerList["dc"] = [];
this.changeSceneGroup = function(groupType){ this.changeSceneGroup = function(groupType){
// console.log(groupType); // console.log(groupType);
@ -258,7 +259,6 @@ export function AssetModelManager(editor,scene) {
} }
} }
} }
// <el-option label="车站" value="standstation"></el-option> // <el-option label="车站" value="standstation"></el-option>
// <el-option label="停车场" value="stopstation"></el-option> // <el-option label="停车场" value="stopstation"></el-option>
// <el-option label="单体设备" value="device"></el-option> // <el-option label="单体设备" value="device"></el-option>

View File

@ -9,6 +9,7 @@ export function LessonData() {
this.lessonData = { this.lessonData = {
//资源列表 //资源列表
assetList:[], assetList:[],
accidentList:[],
setup:{ setup:{
examMode:"", examMode:"",
checkedRole:"", checkedRole:"",
@ -32,7 +33,7 @@ export function LessonData() {
roleName:"", roleName:"",
roleUse:true, roleUse:true,
score:0, score:0,
progressScene:"", progressScene:"standstation",
nextCode:"", nextCode:"",
nextNode:"", nextNode:"",
triggerType:"", triggerType:"",

View File

@ -2,8 +2,8 @@ export function getBaseUrl() {
let BASE_API; let BASE_API;
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
// BASE_API = 'https://joylink.club/jlcloud'; // BASE_API = 'https://joylink.club/jlcloud';
// BASE_API = 'https://test.joylink.club/jlcloud'; BASE_API = 'https://test.joylink.club/jlcloud';
BASE_API = 'http://192.168.8.152:9000'; // 袁琪 // BASE_API = 'http://192.168.8.152:9000'; // 袁琪
// BASE_API = 'http://192.168.8.167:9000'; // 旭强 // BASE_API = 'http://192.168.8.167:9000'; // 旭强
// BASE_API = 'http://192.168.2.183:9000'; // 张赛 // BASE_API = 'http://192.168.2.183:9000'; // 张赛
// BASE_API = 'http://192.168.8.140:9000'; // 杜康 // BASE_API = 'http://192.168.8.140:9000'; // 杜康

View File

@ -28,6 +28,18 @@
</div> </div>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="场景特效管理" name="accidentlist" >
<div class="progressdiv"
v-for="(elementaccident,indexaccident) in accidentlist" :key="elementaccident.label">
<div class="progressdivtext" >{{elementaccident.label}}</div>
<div class="progressassetimg"
:style="{'background-image': 'url('+localstatic+'/lesson3d/box.png)'}"/>
<div class="delprogressdiv" @click="deleteAccident(elementaccident)" >删除</div>
</div>
</el-tab-pane>
</el-tabs> </el-tabs>
</div> </div>
@ -44,7 +56,7 @@
export default { export default {
name: 'LessonProgress', name: 'LessonProgress',
props:['lessonData','triggerList'], props:['lessonData','triggerList','accidentlist'],
components: { components: {
draggable draggable
}, },
@ -97,6 +109,9 @@
deleteModel(selectedModel){ deleteModel(selectedModel){
this.$emit('deleteModel',selectedModel); this.$emit('deleteModel',selectedModel);
}, },
deleteAccident(selectAccident){
this.$emit('deleteAccident',selectAccident);
}
}, },

View File

@ -28,16 +28,16 @@
</draggable> </draggable>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="特效资源" name="spritTrigger"> <el-tab-pane label="特效资源" name="spritTrigger">
<!-- <Assets-Model></Assets-Model> --> <draggable v-model="accidentDataList" group="accidentDataList" @start="drag=true" @end="drag=false" >
<!-- <draggable v-model="lessonAssetList" group="lessonAssetList" @start="drag=true" @end="drag=false" > <div class="progressdiv" v-for="(item,index) in accidentDataList"@dragend="createAccident($event,item,index)">
<div class="progressdiv" v-for="(item,index) in lessonAssetList"@dragend="createModel($event,item,index)">
<div class="progressdivimg" <div class="progressdivimg"
:style="{'background-image': 'url('+localstatic+'/lesson3d/box.png)'}"/> :style="{'background-image': 'url('+localstatic+'/lesson3d/box.png)'}"/>
<div class="progressdivtext">{{item.packageName}}</div> <div class="progressdivtext">{{item.name}}</div>
</div> </div>
</draggable> --> </draggable>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="图片资源列表" name="picasset"> <el-tab-pane label="图片资源列表" name="picasset">
@ -95,6 +95,7 @@
activeName: 'lessoncomponent', activeName: 'lessoncomponent',
lessonAssetList:[], lessonAssetList:[],
picAssetList:[], picAssetList:[],
accidentDataList:[],
triggerList:[ triggerList:[
{}, {},
{}, {},
@ -111,6 +112,7 @@
}, },
mounted() { mounted() {
window.jl3dUpdateAccidentData = this.jl3dUpdateAccidentData;
this.localstatic = JL3D_LOCAL_STATIC; this.localstatic = JL3D_LOCAL_STATIC;
console.log(this.localstatic); console.log(this.localstatic);
getMap3dModelData("三维课程").then(netdata => { getMap3dModelData("三维课程").then(netdata => {
@ -160,7 +162,13 @@
// console.log(event); // console.log(event);
this.$emit('createModel',item,{x:event.clientX,y:event.clientY}); this.$emit('createModel',item,{x:event.clientX,y:event.clientY});
}, },
createAccident(event,item, index){
this.$emit('createAccident',item.type,{x:event.clientX,y:event.clientY});
},
jl3dUpdateAccidentData(accidentData){
this.accidentDataList = accidentData;
},
}, },
} }

View File

@ -4,6 +4,7 @@
<LessonTools-Manager <LessonTools-Manager
@createModel='createModel' @createModel='createModel'
@createAccident='createAccident'
:lessonTools='lessonTools' :lessonTools='lessonTools'
></LessonTools-Manager> ></LessonTools-Manager>
@ -62,11 +63,13 @@
<Lesson-Progress <Lesson-Progress
:lessonData='lessonData' :lessonData='lessonData'
:triggerList='triggerList' :triggerList='triggerList'
:accidentlist='accidentlist'
@addProgress="addProgress" @addProgress="addProgress"
@changeProgressView="changeProgressView" @changeProgressView="changeProgressView"
@removeProgress="removeProgress" @removeProgress="removeProgress"
@selectModel="selectModel" @selectModel="selectModel"
@deleteModel="deleteModel" @deleteModel="deleteModel"
@deleteAccident="deleteAccident"
> >
</Lesson-Progress> </Lesson-Progress>
@ -163,6 +166,7 @@
data:{}, data:{},
}, },
triggerList:[], triggerList:[],
accidentlist:[],
lessonData:{ lessonData:{
lessonData:{ lessonData:{
lessonProgress:[ lessonProgress:[
@ -209,6 +213,7 @@
}, },
mounted() { mounted() {
window.updateTriggerList = this.updateTriggerList; window.updateTriggerList = this.updateTriggerList;
window.jl3dUpdateAccidentlist = this.jl3dUpdateAccidentlist;
window.editAction = this.editAction; window.editAction = this.editAction;
this.init(this.$route.query.lessonId); this.init(this.$route.query.lessonId);
@ -257,6 +262,11 @@
let assetModelData = this.jl3d.saveAssetModel(); let assetModelData = this.jl3d.saveAssetModel();
saveData.assetList = assetModelData.assetList; saveData.assetList = assetModelData.assetList;
saveData.modelList = assetModelData.modelList; saveData.modelList = assetModelData.modelList;
let accidentData = this.jl3d.saveAccidentModel();
saveData.accidentList = accidentData;
saveData.setup.examMode = this.examMode; saveData.setup.examMode = this.examMode;
saveData.setup.checkedRole = this.checkedRole; saveData.setup.checkedRole = this.checkedRole;
this.netData.data = JSON.stringify(saveData); this.netData.data = JSON.stringify(saveData);
@ -291,6 +301,9 @@
deleteModel(selectedModel){ deleteModel(selectedModel){
this.jl3d.deleteModel(selectedModel); this.jl3d.deleteModel(selectedModel);
}, },
deleteAccident(selectedAccident){
this.jl3d.deleteAccident(selectedAccident);
},
setupclick(){ setupclick(){
this.showSetup = true; this.showSetup = true;
@ -298,11 +311,16 @@
createModel(assetData,mousePos){ createModel(assetData,mousePos){
this.jl3d.createModelTrigger(assetData,mousePos); this.jl3d.createModelTrigger(assetData,mousePos);
}, },
createAccident(accidentData,mousePos){
this.jl3d.createAccident(accidentData,mousePos);
},
updateTriggerList(newTriggerList){ updateTriggerList(newTriggerList){
this.triggerList = newTriggerList; this.triggerList = newTriggerList;
console.log(this.triggerList); console.log(this.triggerList);
}, },
jl3dUpdateAccidentlist(newAccidentlist){
this.accidentlist = newAccidentlist;
},
editAction(type,value1,value2){ editAction(type,value1,value2){
this.jl3d.editActionManager(type,value1,value2); this.jl3d.editActionManager(type,value1,value2);
}, },