sampleFace method
dynamic
sampleFace(
- dynamic faceIndex,
- dynamic targetPosition,
- dynamic targetNormal,
- dynamic targetColor,
Implementation
sampleFace(faceIndex, targetPosition, targetNormal, targetColor) {
var u = randomFunction();
var v = randomFunction();
if (u + v > 1) {
u = 1 - u;
v = 1 - v;
}
_face.a.fromBufferAttribute(positionAttribute, faceIndex * 3);
_face.b.fromBufferAttribute(positionAttribute, faceIndex * 3 + 1);
_face.c.fromBufferAttribute(positionAttribute, faceIndex * 3 + 2);
targetPosition
.set(0, 0, 0)
.addScaledVector(_face.a, u)
.addScaledVector(_face.b, v)
.addScaledVector(_face.c, 1 - (u + v));
if (targetNormal != undefined) {
_face.getNormal(targetNormal);
}
if (targetColor != undefined && colorAttribute != undefined) {
_face.a.fromBufferAttribute(colorAttribute, faceIndex * 3);
_face.b.fromBufferAttribute(colorAttribute, faceIndex * 3 + 1);
_face.c.fromBufferAttribute(colorAttribute, faceIndex * 3 + 2);
_color.set(0, 0, 0).addScaledVector(_face.a, u).addScaledVector(_face.b, v).addScaledVector(_face.c, 1 - (u + v));
targetColor.r = _color.x;
targetColor.g = _color.y;
targetColor.b = _color.z;
}
return this;
}