raycast method

  1. @override
void raycast(
  1. Raycaster raycaster,
  2. List<Intersection> intersects
)
override

Implementation

@override
void raycast(Raycaster raycaster, List<Intersection> intersects) {
  var matrixWorld = this.matrixWorld;
  var raycastTimes = count;

  _mesh.geometry = geometry;
  _mesh.material = material;

  if (_mesh.material == null) return;

  for (var instanceId = 0; instanceId < raycastTimes!; instanceId++) {
    // calculate the world matrix for each instance

    getMatrixAt(instanceId, _instanceLocalMatrix);

    _instanceWorldMatrix.multiplyMatrices(matrixWorld, _instanceLocalMatrix);

    // the mesh represents this single instance

    _mesh.matrixWorld = _instanceWorldMatrix;

    _mesh.raycast(raycaster, _instanceIntersects);

    // process the result of raycast

    for (var i = 0, l = _instanceIntersects.length; i < l; i++) {
      var intersect = _instanceIntersects[i];
      intersect.instanceId = instanceId;
      intersect.object = this;
      intersects.add(intersect);
    }

    _instanceIntersects.length = 0;
  }
}