Browse Source

perf: 删除阴影,优化碰撞检测算法

dev
高志龙 3 years ago
parent
commit
0e097f2246
  1. 69
      public/static/qm/MainMap_QM.js

69
public/static/qm/MainMap_QM.js

@ -1594,16 +1594,6 @@ MainMap_QM = function (callBack, backObj) {
let directionalLight2 = new THREE.DirectionalLight(0xffffff, 0.3) let directionalLight2 = new THREE.DirectionalLight(0xffffff, 0.3)
directionalLight2.name = 'light' directionalLight2.name = 'light'
directionalLight2.position.set(280, 400, -300) directionalLight2.position.set(280, 400, -300)
if (Config.cameraDist.state === '3D') {
directionalLight2.castShadow = true //阴影
directionalLight2.shadow.camera.top = 320
directionalLight2.shadow.camera.bottom = -320
directionalLight2.shadow.camera.right = 320
directionalLight2.shadow.camera.left = -320
directionalLight2.shadow.camera.far = 1200
directionalLight2.shadow.camera.near = 50
directionalLight2.shadow.mapSize.set(1024, 1024)
}
this.scene.add(directionalLight2) this.scene.add(directionalLight2)
this.mixers = [] this.mixers = []
@ -1674,8 +1664,6 @@ MainMap_QM.prototype = {
collada.scene.userData.type = Config.initModelArr[i].type collada.scene.userData.type = Config.initModelArr[i].type
collada.scene.traverse(function (child) { collada.scene.traverse(function (child) {
if (child.type === 'Mesh') { if (child.type === 'Mesh') {
child.castShadow = true
child.receiveShadow = true
if (child.material.map) { if (child.material.map) {
child.material.map.encoding = THREE.LinearEncoding //贴图需要转换成 线性编码 child.material.map.encoding = THREE.LinearEncoding //贴图需要转换成 线性编码
} }
@ -1932,8 +1920,6 @@ MainMap_QM.prototype = {
//加载路径fbx文件 //加载路径fbx文件
object.scene.traverse(function (child) { object.scene.traverse(function (child) {
if (child.type === 'Mesh') { if (child.type === 'Mesh') {
child.castShadow = true
child.receiveShadow = true
if (child.material.map) { if (child.material.map) {
child.material.map.encoding = THREE.LinearEncoding //贴图需要转换成 线性编码 child.material.map.encoding = THREE.LinearEncoding //贴图需要转换成 线性编码
} }
@ -3073,13 +3059,7 @@ MainMap_QM.prototype = {
Map_QM.mapArr[Config.selectBuild][endIndex].allObj.position.y = Config.selectFloor > endIndex ? -1 * Config.doubleDist : Config.doubleDist Map_QM.mapArr[Config.selectBuild][endIndex].allObj.position.y = Config.selectFloor > endIndex ? -1 * Config.doubleDist : Config.doubleDist
} else if (endIndex === -1) { } else if (endIndex === -1) {
//一层 //一层
TweenMax.fromTo(
Map_QM.mapArr[Config.selectBuild][Config.selectFloor].allObj.position,
0.5,
{ y: addFloor * Config.doubleDist },
{ y: 0, ease: Cubic.easeIn }
)
//Map_QM.mapArr[Config.selectBuild][Config.selectFloor].allObj.position.y=0;
Map_QM.mapArr[Config.selectBuild][Config.selectFloor].allObj.position.y=0;
} else { } else {
//三层 //三层
Map_QM.mapArr[Config.selectBuild][Config.selectFloor].allObj.position.y = 0 Map_QM.mapArr[Config.selectBuild][Config.selectFloor].allObj.position.y = 0
@ -3091,8 +3071,7 @@ MainMap_QM.prototype = {
Map_QM.mapArr[Config.selectBuild][maxF].allObj.position.y = Config.doubleDist Map_QM.mapArr[Config.selectBuild][maxF].allObj.position.y = Config.doubleDist
} }
} else { } else {
//Map_QM.mapArr[Config.selectBuild][Config.selectFloor].allObj.position.y=0;
TweenMax.fromTo(Map_QM.mapArr[Config.selectBuild][Config.selectFloor].allObj.position, 0.5, { y: addFloor * Config.doubleDist }, { y: 0, ease: Cubic.easeIn })
Map_QM.mapArr[Config.selectBuild][Config.selectFloor].allObj.position.y=0;
} }
Map_QM.timeOutInit() Map_QM.timeOutInit()
} }
@ -3222,6 +3201,7 @@ MainMap_QM.prototype = {
* @param {Object} 传入检测楼层下标 * @param {Object} 传入检测楼层下标
*/ */
collisionChock: function () { collisionChock: function () {
if (!Config.collision) { if (!Config.collision) {
return return
} }
@ -3262,7 +3242,7 @@ MainMap_QM.prototype = {
}) })
let childs = Map_QM.mapArr[Config.selectBuild][m].labelObj.children let childs = Map_QM.mapArr[Config.selectBuild][m].labelObj.children
childs.forEach(item => { childs.forEach(item => {
item.element.style.visibility = 'visible'
item.element.style.visibility = 'hidden'
}) })
let svgChilds = Map_QM.mapArr[Config.selectBuild][m].svgObj.children let svgChilds = Map_QM.mapArr[Config.selectBuild][m].svgObj.children
let rat = Map_QM.controls.getRotateHorizontal() let rat = Map_QM.controls.getRotateHorizontal()
@ -3278,24 +3258,29 @@ MainMap_QM.prototype = {
let len = childs.length let len = childs.length
for (let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
let obj = childs[i].element let obj = childs[i].element
if (obj.style.visibility == 'visible' && obj.style.transform) {
if (obj.style.visibility == 'hidden' && obj.style.transform) {
obj.style.visibility = 'visible'
let labP = obj.style.transform.split('translate')[2].split(', ') let labP = obj.style.transform.split('translate')[2].split(', ')
for (let j = i + 1; j < len; j++) {
let pb = childs[j].element.style.transform.split('translate')[2].split(', ')
let isCol = Config.isCollision(
new Config.Point(labP[0].substring(1, labP[0].length - 2), labP[1].substring(0, labP[1].length - 3)),
obj.clientWidth,
obj.clientHeight,
new Config.Point(pb[0].substring(1, pb[0].length - 2), pb[1].substring(0, pb[1].length - 3)),
childs[j].element.clientWidth,
childs[j].element.clientHeight
)
if (isCol) {
childs[j].element.style.visibility = 'hidden'
for (let j = 0; j < i; j++) {
if (childs[j].element.style.visibility == 'visible'){
let pb = childs[j].element.style.transform.split('translate')[2].split(', ')
let isCol = Config.isCollision(
new Config.Point(labP[0].substring(1, labP[0].length - 2), labP[1].substring(0, labP[1].length - 3)),
obj.clientWidth,
obj.clientHeight,
new Config.Point(pb[0].substring(1, pb[0].length - 2), pb[1].substring(0, pb[1].length - 3)),
childs[j].element.clientWidth,
childs[j].element.clientHeight
)
if (isCol) {
obj.style.visibility = 'hidden'
break;
}
} }
} }
} }
} }
let iLen = IconChilds.length let iLen = IconChilds.length
for (let ii = 0; ii < iLen; ii++) { for (let ii = 0; ii < iLen; ii++) {
let objIcon = IconChilds[ii].element let objIcon = IconChilds[ii].element
@ -3347,7 +3332,7 @@ MainMap_QM.prototype = {
} }
} }
} }
}, 100)
}, 500)
}, },
/** /**
@ -4691,8 +4676,6 @@ FloorMap_QM.prototype = {
let mod = object.scene let mod = object.scene
mod.traverse(function (child) { mod.traverse(function (child) {
if (child.isMesh) { if (child.isMesh) {
child.receiveShadow = true
child.castShadow = true
if (child.material.map) { if (child.material.map) {
child.material.map.encoding = THREE.LinearEncoding //贴图需要转换成 线性编码 child.material.map.encoding = THREE.LinearEncoding //贴图需要转换成 线性编码
} }
@ -4787,8 +4770,6 @@ FloorMap_QM.prototype = {
borderColor = parseInt(mapData.floorArea.borderColor.replace('#', '0x'), 16) borderColor = parseInt(mapData.floorArea.borderColor.replace('#', '0x'), 16)
floorH = parseInt(mapData.floorArea.toHeight) floorH = parseInt(mapData.floorArea.toHeight)
let mash = this.Model_QM.MyModelShape(floor, hows_f, mapData.floorArea, entColor, borderColor, 10) let mash = this.Model_QM.MyModelShape(floor, hows_f, mapData.floorArea, entColor, borderColor, 10)
mash.receiveShadow = true
mash.castShadow = false
mash.userData = { mash.userData = {
type: 'floor', type: 'floor',
order: this.floorOrder order: this.floorOrder
@ -4811,8 +4792,6 @@ FloorMap_QM.prototype = {
Config.buildHeight = Math.max(parseInt(mapData.buildArea[i].toHeight), Config.buildHeight) Config.buildHeight = Math.max(parseInt(mapData.buildArea[i].toHeight), Config.buildHeight)
buildH = parseInt(mapData.buildArea[i].toHeight) buildH = parseInt(mapData.buildArea[i].toHeight)
let mash = this.Model_QM.MyModelShape(build, hows, mapData.buildArea[i], entColor, borderColor, 30) let mash = this.Model_QM.MyModelShape(build, hows, mapData.buildArea[i], entColor, borderColor, 30)
mash.receiveShadow = true
mash.castShadow = false
mash.userData = { mash.userData = {
type: 'build', type: 'build',
order: this.floorOrder order: this.floorOrder
@ -4882,6 +4861,7 @@ FloorMap_QM.prototype = {
let shopDiv = document.createElement('div') let shopDiv = document.createElement('div')
shopDiv.className = 'shopLabel' shopDiv.className = 'shopLabel'
shopDiv.innerText = show shopDiv.innerText = show
shopDiv.style.visibility = 'hidden'
shopDiv.dataset.name = show shopDiv.dataset.name = show
shopDiv.dataset.nameEn = showE shopDiv.dataset.nameEn = showE
let shopLabel = new THREE.CSS2DObject(shopDiv) let shopLabel = new THREE.CSS2DObject(shopDiv)
@ -5423,7 +5403,6 @@ MyModel_QM.prototype.MyModelShape = function (areaArr, howllowArr, opObj, entity
} else { } else {
mesh.position.z = -1 * parseInt(opObj.toHeight) - 1 mesh.position.z = -1 * parseInt(opObj.toHeight) - 1
} }
mesh.castShadow = true
mesh.renderOrder = indexOrder mesh.renderOrder = indexOrder
mesh.name = opObj.name || '' mesh.name = opObj.name || ''

Loading…
Cancel
Save