import CybeSingle from '../scripts/CybeSingle.js';
let lgIndex = 0
let glflag = true
let indexTemp = 0
let xuanjiaAc1 = (() => {
let frames = []
for (let i = 0; i < 6; i++) {
for (let n = 0; n < 10; n++) {
frames.push(i * 10 + n)
}
}
for (let i = 5; i > -3; i--) {
for (let n = 9; n > -1; n--) {
frames.push(i * 10 + n)
}
}
return frames
})()
let xuanjiaAc2 = (() => {
let frames = []
for (let i = -2; i < 0; i++) {
for (let n = 0; n < 10; n++) {
frames.push(i * 10 + n)
}
}
frames.push(0)
return frames
})()
/**
* 构造视车三维云实例.
* @constructor
* @param {string} elementId - canvas场景挂载dom节点id.
* @param {string} sourcePath - 3d资源路径*(项目相对目录).
*/
const Cyberide = function({
elementId,
sourcePath
}) {
this.elementId = elementId;
this.sourcePath = sourcePath
}
Cyberide.prototype = {
/**
* 初始化
* @param {function} foo - 初始化回调函数(比如回调结束loading动画).
*/
init(foo) {
let elementId = this.elementId;
this.syb = new CybeSingle({
id: elementId
})
window.jike = this
this.syb.sourcePath = this.sourcePath
// this.syb.fooBack = foo
this.syb.loadProductInfo(693).then(() => {
setTimeout(() => {
// this.loadLgById(1)
this.syb.changeCompot(0)
this.syb.changeEt(60, false, false)
this.syb.changeEt(60, false, true)
this.removeGround()
foo()
// if(t1){
// this.syb.cr.drawer.controls.target.x = t1.x
// this.syb.cr.drawer.controls.target.y = t1.y
// this.syb.cr.drawer.controls.target.z = t1.z
// }
// if(o1){
// this.syb.cr.drawer.controls.object.position.x = o1.x
// this.syb.cr.drawer.controls.object.position.y = o1.y
// this.syb.cr.drawer.controls.object.position.z = o1.z
// }
}, 1000)
// this.syb.loadProductInfo1(693).then(()=>{
// })
});
},
getCameraPosition() {
return {
t1: this.syb.cr.drawer.controls.target,
o1: this.syb.cr.drawer.controls.object.position
}
},
/**
* 重置相机
* 重置摆放位置以及相机视角
*/
resetCamera() {
this.syb.cr.drawer.controls.reset()
},
removeGround() {
return new Promise((resove) => {
let list = this.syb.cr.drawer.mainScene.children
for (let i in list) {
if (list[i].name == 'Root Scene') {
this.syb.cr.drawer.mainScene.remove(list[i])
}
}
setTimeout(() => {
this.syb.cr.drawer.mainScene.children[2].visible = true
resove()
}, 50)
})
},
/**
* 切换轮毂
* @param index {Number}轮毂共5个
切换到轮毂1,默认轮胎为轮胎1
切换到轮毂2、3、4,默认轮胎为轮胎3
切换到轮毂5,默认轮胎为轮胎5
*/
loadLgById: function(index) {
index--
let names = ['wheel1', 'wheel2', 'wheel3', 'wheel4', 'wheel5']
lgIndex = index
this.syb.loadLgById(names[index])
// if (names[index] == 'wheel1') {
// // this.syb.changeInitParam(0)
// this.loadLtById(1)
// changeArgars1(this.syb)
// } else if (names[index] == 'wheel5') {
// // this.syb.changeInitParam(1)
// this.loadLtById(5)
// changeArgars(this.syb)
// } else {
// // this.syb.changeInitParam(0)
// this.loadLtById(3)
// changeArgars2(this.syb)
// }
},
/**
* 切换轮胎
* @param index {Number} 轮胎编号,轮胎共6个
轮毂1 的状态下只能切换 轮胎1、轮胎2
轮毂2、轮毂3、轮毂4的状态下只能切换轮胎3、轮胎4
轮毂5 的状态下只能切换轮胎5、轮胎6
*/
loadLtById: function(index) {
// if (lgIndex == 0) {
// if (index != 1 && index != 2) {
// console.log('当前轮毂1,只能切换轮胎1,2')
// return
// }
// } else if (lgIndex == 4) {
// if (index != 5 && index != 6) {
// console.log('当前轮毂5,只能切换轮胎5,6')
// return
// }
// } else {
// if (index == 1 || index == 2 || index == 5 || index == 6) {
// console.log('切换失败!')
// return
// }
// }
let tyres = ['tyre1', 'tyre2', 'tyre3', 'tyre4', 'tyre5', 'tyre6']
this.syb.loadLtById(tyres[--index])
console.log(tyres[index])
},
/**
* 显示与影藏动画触发圆点
* @param flag {Boolean},是否显示,显示:true;影藏:false
*/
isShowHot: function(flag) {
if (glflag == flag) {
return
}
glflag = flag
// this.tempHot = []
for (let [key, value] of this.syb.cr.hotSprites.spriteMap) {
// if (key.includes('hot')) {
// value.material.map = null
value.material.opacity = flag
value.material.needsUpdate = true;
// value.visible = false
// }
// this.tempHot.push(value.visible)
}
},
/**
* 切换悬架
* @param index {Number}} 悬架编号,共5个选择:1:200mm;2:180mm;3:165mm;4:150mm;5:130mm;
*/
changeSuspension(index) {
index--
let list = [
[.04,.05],
[.03,.04],
[.02,.03],
[.01,.02],
[0,.01],
]
this.syb.changeXj(list[index][0],true)
this.syb.changeXj(list[index][1],false)
// if (indexTemp != 0) {
// return
// }
// indexTemp = 1
// console.log(this.syb.cr.mainCar.innerComp.bxj)
// let temp = this
// function change1(indexv) {
// if (index == 2) {
// return
// }
// indexv++
// setTimeout(() => {
// temp.syb.changeXj(xuanjiaAc1[indexv] / 1000, false)
// temp.syb.changeXj(xuanjiaAc1[indexv] / 1000, true)
// if (indexv < xuanjiaAc1.length - 1) {
// change1(indexv)
// } else {
// indexTemp = 0
// }
// }, 10)
// }
// function change2(indexv) {
// indexv++
// setTimeout(() => {
// temp.syb.changeXj(xuanjiaAc2[indexv] / 1000, false)
// temp.syb.changeXj(xuanjiaAc2[indexv] / 1000, true)
// if (indexv < xuanjiaAc2.length - 1) {
// change2(indexv)
// } else {
// indexTemp = 0
// }
// }, 10)
// }
// if (index == 1) {
// let v = 0
// change1(v)
// }
// if (index == 2) {
// let v = 0
// change2(v)
// }
},
/**
* 切换卡钳
* @param index {Number} 前卡钳,共2个选择,1:四活塞卡钳,2:双活塞卡钳
*/
loadInitCaiperOfFront: function(index) {
index--
this.syb.loadInitCaiperOfFront(['break1', 'break2'][index])
},
/**
* 切换颜色
* @param index {Number} 换颜色,共6个选择,1:电光蓝 2:极光紫,3:星尘红,4:镭射灰 ,5:极昼白,6:碳素黑
*/
setColor: function(index) {
let list = [
'6ba9fa',
'433b52',
'f00216',
'8E8F98',
'f7faff',
'030303',
]
let i = --index
let temp = {
clearcoat: 0.2,
color: parseInt("0x" + list[i]),
flake: i == 4 ? false : true,
metalness: 0.3,
normalScale: 0.01,
roughness: 0.01
}
this.syb.setColor(temp)
this.syb.changeWheelColr(i)
},
/**
* 切换组件
* @param index {Number} 换套件,共3个选择,1:车身同色;2:钢琴漆黑色运动组件;3:撞色车顶
*/
changeCompot: function(index) {
this.syb.changeCompot(index - 1)
}
};
function changeLgSize(cyb, size, front) {
// console.log("changesize" ,size);
let types = ["fr", "fl", "br", "bl"];
if (front) {
types = ["fr", "fl"];
} else {
types = ["br", "bl"];
}
let rsize = cyb.cr.mainCar.getInnerCompParam("sizeValue", "basePlate", ["lg", "fr"])
cyb.resetLDiameter(); //调整厚度之前设置参数
for (let type of types) {
cyb.cr.mainCar.changeLunChicun({
x: size / rsize,
y: size / rsize
}, type);
cyb.cr.mainCar.changeLunTChicun({
x: size / rsize,
y: size / rsize
}, type);
cyb.cr.mainCar.changeLtCebiHoudu(size / rsize, type); //尺寸改变的时候调整厚度
}
}
function changeArgars(cyb) {
cyb.params.lt.flatter = 55
cyb.params.lg.sizeValue = 19
cyb.cr.mainCar.innerComp.fxj = 0;
cyb.params.ltb.flatter = 55
cyb.params.lgb.sizeValue = 19
cyb.cr.mainCar.innerComp.bxj = 0;
cyb.params.lg.jValue = 9
cyb.params.lt.tireWidth = 255
cyb.params.lgb.jValue = 9
cyb.params.ltb.tireWidth = 255
cyb.cr.mainCar.refreshBdPose();
changeLgSize(cyb, 19, true);
changeLgSize(cyb, 19, false);
cyb.changeWdith(9, 0, false, false)
cyb.changeWdith(9, 0, false, true)
cyb.changeLtHoudu(false)
cyb.changeLtHoudu(true)
}
function changeArgars1(cyb) {
cyb.params.lt.flatter = 40
cyb.params.lg.sizeValue = 22
cyb.cr.mainCar.innerComp.fxj = 0;
cyb.params.ltb.flatter = 40
cyb.params.lgb.sizeValue = 22
cyb.cr.mainCar.innerComp.bxj = 0;
cyb.params.lg.jValue = 9.5
cyb.params.lt.tireWidth = 265
cyb.params.lgb.jValue = 9.5
cyb.params.ltb.tireWidth = 265
cyb.cr.mainCar.refreshBdPose();
changeLgSize(cyb, 22, true);
changeLgSize(cyb, 22, false);
cyb.changeWdith(9.5, 0, false, false)
cyb.changeWdith(9.5, 0, false, true)
cyb.changeLtHoudu(false)
cyb.changeLtHoudu(true)
}
function changeArgars2(cyb) {
cyb.params.lt.flatter = 45
cyb.params.lg.sizeValue = 21
cyb.cr.mainCar.innerComp.fxj = 0;
cyb.params.ltb.flatter = 45
cyb.params.lgb.sizeValue = 21
cyb.cr.mainCar.innerComp.bxj = 0;
cyb.params.lg.jValue = 9
cyb.params.lt.tireWidth = 255
cyb.params.lgb.jValue = 9
cyb.params.ltb.tireWidth = 255
cyb.cr.mainCar.refreshBdPose();
changeLgSize(cyb, 21, true);
changeLgSize(cyb, 21, false);
cyb.changeWdith(9, 0, false, false)
cyb.changeWdith(9, 0, false, true)
cyb.changeLtHoudu(false)
cyb.changeLtHoudu(true)
}
export default Cyberide