sideCollide.ts 763 字节
Newer Older
6
UPDATE  
622eda98dfef6c4fdb84ccca 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
//legacy

import * as THREE from 'three'

onmessage = (
  msg: MessageEvent<{
    count: number
    matrices: THREE.InstancedBufferAttribute[]
    position: THREE.Vector3
  }>
) => {
  let meshes = []

  let raycaster = new THREE.Raycaster(
    new THREE.Vector3(
      msg.data.position.x,
      msg.data.position.y - 1,
      msg.data.position.z
    ),
    new THREE.Vector3(1, 0, 0),
    0,
    0.6
  )

  for (let matrix of msg.data.matrices) {
    let mesh = new THREE.InstancedMesh(
      new THREE.BoxGeometry(1, 1, 1),
      new THREE.MeshBasicMaterial(),
      msg.data.count
    )
    mesh.instanceMatrix = matrix
    meshes.push(mesh)
  }
  if (raycaster.intersectObjects(meshes).length) {
    postMessage(true)
  } else {
    postMessage(false)
  }
}