checkBufferGeometryIntersection function
Intersection?
checkBufferGeometryIntersection(
- Object3D object,
- Material material,
- Raycaster raycaster,
- Ray ray,
- BufferAttribute<NativeArray<num>> position,
- dynamic morphPosition,
- dynamic morphTargetsRelative,
- dynamic uv,
- dynamic uv2,
- int a,
- int b,
- int c,
)
Implementation
Intersection? checkBufferGeometryIntersection(
Object3D object,
Material material,
Raycaster raycaster,
Ray ray,
BufferAttribute position,
morphPosition,
morphTargetsRelative,
uv,
uv2,
int a,
int b,
int c) {
_vA.fromBuffer(position, a);
_vB.fromBuffer(position, b);
_vC.fromBuffer(position, c);
final morphInfluences = object.morphTargetInfluences;
if (morphPosition != null && morphInfluences.isNotEmpty) {
_morphA.setValues(0, 0, 0);
_morphB.setValues(0, 0, 0);
_morphC.setValues(0, 0, 0);
for (int i = 0, il = morphPosition.length; i < il; i++) {
double influence = morphInfluences[i];
final morphAttribute = morphPosition[i];
if (influence == 0) continue;
_tempA.fromBuffer(morphAttribute, a);
_tempB.fromBuffer(morphAttribute, b);
_tempC.fromBuffer(morphAttribute, c);
if (morphTargetsRelative) {
_morphA.addScaled(_tempA, influence);
_morphB.addScaled(_tempB, influence);
_morphC.addScaled(_tempC, influence);
} else {
_morphA.addScaled(_tempA.sub(_vA), influence);
_morphB.addScaled(_tempB.sub(_vB), influence);
_morphC.addScaled(_tempC.sub(_vC), influence);
}
}
_vA.add(_morphA);
_vB.add(_morphB);
_vC.add(_morphC);
}
if (object is SkinnedMesh) {
object.applyBoneTransform(a, _vA);
object.applyBoneTransform(b, _vB);
object.applyBoneTransform(c, _vC);
}
final intersection = checkIntersection(
object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint);
if (intersection != null) {
if (uv != null) {
_uvA.fromBuffer(uv, a);
_uvB.fromBuffer(uv, b);
_uvC.fromBuffer(uv, c);
intersection.uv = TriangleUtil.getUV(_intersectionPoint, _vA, _vB, _vC,
_uvA, _uvB, _uvC, Vector2.zero());
}
if (uv2 != null) {
_uvA.fromBuffer(uv2, a);
_uvB.fromBuffer(uv2, b);
_uvC.fromBuffer(uv2, c);
intersection.uv2 = TriangleUtil.getUV(_intersectionPoint, _vA, _vB,
_vC, _uvA, _uvB, _uvC, Vector2.zero());
}
final face = Face.fromJson(
{"a": a, "b": b, "c": c, "normal": Vector3.zero(), "materialIndex": 0});
TriangleUtil.getNormal(_vA, _vB, _vC, face.normal);
intersection.face = face;
}
return intersection;
}