Search code examples
autodeskautodesk-forgeautodesk-viewer

What is the Three.Face3 in viewer.impl.hitTestViewport returned object?


What is the Three.face in the object returned by viewer.impl.hitTestViewport()?

Here's an example:

enter image description here

What does it represent?


Solution

  • Just look at the source code in the three.js viewer implementation at line #8228.

    // File:src/core/Face3.js
    
      /**
       * @author mrdoob / http://mrdoob.com/
       * @author alteredq / http://alteredqualia.com/
       */
    
      THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
    
        this.a = a;
        this.b = b;
        this.c = c;
    
        this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
        this.vertexNormals = normal instanceof Array ? normal : [];
    
        this.color = color instanceof THREE.Color ? color : new THREE.Color();
        this.vertexColors = color instanceof Array ? color : [];
    
        this.vertexTangents = [];
    
        this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
    
      };
    
      THREE.Face3.prototype = {
    
        constructor: THREE.Face3,
    
        clone: function () {
    
          var face = new THREE.Face3( this.a, this.b, this.c );
    
          face.normal.copy( this.normal );
          face.color.copy( this.color );
    
          face.materialIndex = this.materialIndex;
    
          for ( var i = 0, il = this.vertexNormals.length; i < il; i ++ ) {
    
            face.vertexNormals[ i ] = this.vertexNormals[ i ].clone();
    
          }
    
          for ( var i = 0, il = this.vertexColors.length; i < il; i ++ ) {
    
            face.vertexColors[ i ] = this.vertexColors[ i ].clone();
    
          }
    
          for ( var i = 0, il = this.vertexTangents.length; i < il; i ++ ) {
    
            face.vertexTangents[ i ] = this.vertexTangents[ i ].clone();
    
          }
    
          return face;
    
        }
    
      };
    

    Take also a look at the three.js Face3 documentation:

    Triangular face used in Geometry. These are created automatically for all standard geometry types, however if you are building a custom geometry you will have to create them manually.