BoundingMesh.js 1.5 KB

123456789101112131415161718192021222324
  1. //skybox
  2. import * as THREE from 'three'
  3. export default class BoundingMesh extends THREE.Mesh {
  4. constructor(boundingBox, material, skyHeight = 50) {
  5. //boundingBox = boundingBox.clone().expandByScalar(0.01) //许钟文改: 稍微放大了一丢丢的,避免和其他mesh冲突闪烁。尤其在飞入飞出时,地面闪烁一下,好像是和chunk冲突。过去是和marker冲突。
  6. //大部分没有mesh的都是户外,所以放大些,作为天空盒背景. 另外地板因为可能破损,所以position向上提升使最低高度不变
  7. boundingBox = boundingBox.clone().expandByVector(new THREE.Vector3(skyHeight, skyHeight, skyHeight))
  8. var size = new THREE.Vector3()
  9. boundingBox.getSize(size)
  10. var geometry = new THREE.BoxGeometry(size.x, size.y, size.z)
  11. //geometry.boundingBox = boundingBox; //xzw delete 较早:这句加上不对。因为后面算鼠标与skybox交点时 要用到的是boundingbox加上position才是真实skybox真实位置,所以boundingbox要居中的,而不应该是整体模型所在的位置。
  12. geometry.computeBoundingBox() //需要重新计算对称的bounding, 在获取鼠标交点时需要。否则热点加不上
  13. super(geometry, material)
  14. var center = new THREE.Vector3()
  15. boundingBox.getCenter(center)
  16. skyHeight && (center.y += skyHeight - 0.1)
  17. this.position.copy(center)
  18. this.frustumCulled = !1
  19. //flag && this.add(new THREE.WireframeHelper(this))
  20. }
  21. }