sampleFace method

dynamic sampleFace(
  1. dynamic faceIndex,
  2. dynamic targetPosition,
  3. dynamic targetNormal,
  4. dynamic targetColor,
)

Implementation

sampleFace( faceIndex, targetPosition, targetNormal, targetColor ) {

  var u = this.randomFunction();
  var v = this.randomFunction();

  if ( u + v > 1 ) {

    u = 1 - u;
    v = 1 - v;

  }

  _face.a.fromBufferAttribute( this.positionAttribute, faceIndex * 3 );

  _face.b.fromBufferAttribute( this.positionAttribute, faceIndex * 3 + 1 );

  _face.c.fromBufferAttribute( this.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 && this.colorAttribute != undefined ) {

    _face.a.fromBufferAttribute( this.colorAttribute, faceIndex * 3 );

    _face.b.fromBufferAttribute( this.colorAttribute, faceIndex * 3 + 1 );

    _face.c.fromBufferAttribute( this.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;

}