Three. js source code annotation (fifty-three) Material/MeshLambertMaterial. js

Source: Internet
Author: User

Three. js source code annotation (fifty-three) Material/MeshLambertMaterial. js

 


/*** @ Author mrdoob/http://mrdoob.com/* @ author alteredq/http://alteredqualia.com/** parameters = {* color:
 
  
, * Ambient:
  
   
, * Emissive:
   
    
, * Opacity:
    
     
, ** Map: new THREE. texture (), ** lightMap: new THREE. texture (), ** specularMap: new THREE. texture (), ** alphaMap: new THREE. texture (), ** envMap: new THREE. textureCube ([posx, negx, posy, negy, posz, negz]), * combine: THREE. multiply, * reflectivity vity:
     
      
, * RefractionRatio:
      
        , ** Shading: THREE. SmoothShading, * blending: THREE. NormalBlending, * depthTest:
       
         , * DepthWrite:
        
          , ** Wireframe:
         
           , * WireframeLinewidth:
          
            , ** VertexColors: THREE. NoColors/THREE. VertexColors/THREE. FaceColors, ** skinning:
           
             , * MorphTargets:
            
              , * MorphNormals:
             
               , ** Fog:
              
                *} * // The MeshPhongMaterial method creates the Lambert (lanbert) material type for mesh (mesh) based on the parameters parameter, and computes the shiny material type for each pixel, /// the format of the parameters parameter is shown above. the MeshPhongMaterial object function is implemented by defining the constructed function prototype object. most attribute Methods inherit from the Material's base class Material. *////
               MeshLambertMaterial///
               Material attribute parameters in JSON format of string type ///
               
                 Returns MeshLambertMaterial, mesh lanbert material.
               THREE. meshLambertMaterial = function (parameters) {THREE. material. call (this); // call the call method of the Material object, and hand over the method originally belonging to the Material to the current object MeshLambertMaterial to use this. color = new THREE. color (0 xffffff); // diffuse Color. The default value is 0 xffffff, Which is white. ambient = new THREE. color (0 xffffff); // environment Color. The default value is 0 xffffff, Which is white and multiplied by the Color of the ambient light object. emissive = new THREE. color (0x000000); // self-emitting (fluorescent) Color. The default value is 0x000000. It is black and the solid Color is not affected by other lights. /* this. w RapAround and this. coloring language associated with wrapRGB // diffuse scattering # ifdef WRAP_AROUND, float spotDiffuseWeightFull = max (dot (normal, spotVector), 0.0 );, float density = max (0.5 * dot (normal, spotVector) + 0.5, 0.0);, vec3 spotDiffuseWeight = mix (vec3 (spotDiffuseWeightFull), vec3 (spotDiffuseWeightHalf), wrapRGB );, genType mix (genType x, genType y, genType a), genType mix (genType x, genType y, floa T a) returns the Linear mixture of x and y, for example, x * (1 −a) + y * a # else, float spotDiffuseWeight = max (dot (normal, spotVector ), 0.0);, # endif, */this. wrapAround = false; // is it a mask ?? // TODO: this. wrapAround and this. wrapRGB attributes are ambiguous and need to be tested. this. wrapRGB = new THREE. vector3 (1, 1, 1); // by setting the value of wrapRGB, the color of the material is linearly mixed according to the formula described above. this. map = null; // normal texture, the default value is null/******************************** why Lightmapping is used **************************************** *********************************** reference: http://blog.sina.com.cn/s/blog_5b6cb9500101cplo.html1.is lightmapping required for the ingress? In short, real-time lighting computing is very time-consuming. As more light sources increase, computing time will multiply. When Lightmap is used to simulate the effect of a light, you do not need to compute the light, which greatly improves the performance. Of course, it is okay if you don't need the lighting effect. The specific requirement depends on the project requirements. The simplest way is to bake the texture vertices directly in 3dmas or maya. **************************************** **************************************** **************************************** * **/This. lightMap = null // lightMap. The default value is null. this. specularMap = null; // specifies the highlight texture. The default value is nullthis. alphaMap = null; // transparent channel texture. The default value is nullthis. envMap = null; // environment TEXTURE. The default value is null // texture constants // TEXTURE constant, which is used to set the material mixing mode. // THREE is available. multiplyOperation, multiply, and translate the layers in photoshop into a stacked bottom. // THREE. mixOperation, // mixed mode // THREE. addOper Ation, // Add mode // reference: http://avnpc.com/pages/photoshop-layer-blending-algorithm//reference ://todo: can more modes be implemented? // Normal mode // Dissolve dissolution mode // Dancing Dissolve dynamic dissolution mode // Darken darkening mode // Multiply front-piece stacked bottom mode // Linear Burn Linear deepening mode // Color Burn color deepening mode // Classic Color Burn is compatible with earlier versions of Color Burn mode // Add mode // Lighten brightening mode // Screen mode // Linear Dodge Linear fade mode/ /Overlay superposition mode // Soft Light mode // Hard Light glare mode // Liner Light linear addition mode // Vivid Light clear addition mode // Din Light blocking mode/ /Hard Mix strong light hybrid mode // Difference Differential Mode // Classic Difference compatibility Earlier versions of the differential mode // Exclusion mode // Hue Color mode // Saturation mode // Color mode // Luminosity height mode. // The layer modes listed above affect the changes by mixing the upper and lower layers of the color channels, while the lower layer modes affect the mixed changes through the Alpha channel of the layer. // Stencel Alpha: Alpha channel mode // stencel Luma: brightness mode // Slihouette Alpha: Alpha channel profile // Slihouette Luma: brightness profile // Alpha Add: alpha addition // Luminescent Premul: cold light mode. /**************** Hybrid mode formula ******************** **************************************** **************************************** * ********** formula for calculating the mixing mode of Photoshop Layers, everyone must be very familiar with it. Here I will describe the calculation formulas of various mixed modes in detail, hoping to help you understand the mixed modes of layers and write them in a rush, please criticize and correct your shortcomings. The hybrid mode can closely combine the color values of the two layers to create a large amount of effects. Behind these effects are some simple mathematical formulas. Next I will introduce the mathematical formulas for all mixed modes in photoshop cs2. Opacity is also introduced. The formula described below applies only to RGB Images. These formulas will no longer apply to Lab color images. Opacity C = d * A + (1-d) * relative to Opacity, the opposite is transparency. The relationship between these two terms is similar to the relationship between positive and negative: the opacity of 100% is the transparency of 0%. This hybrid mode is relatively simple. In this hybrid mode, if the order of the two layers is different, the results will be different (except for 50% transparency of course ). In this formula, A represents the color value of the above layer pixels (A = pixel value/255), and d represents the transparency of the layer, B Indicates the color value of the pixels below (B = pixel value/255), and C indicates the color value of the mixed pixels (the actual result pixel value should be 255 * C ). This formula is also applied to the layer mask. In this case, d represents the brightness of the pixel at the given position in the mask layer. Darken B <= A: C = BB> = A: C = A this mode uses A relatively dark pixel as the output after comparing the upper and lower pixels. Note, the pixels of each different color channel are compared independently, and the color value is relatively small as the output result. The lower layer indicates the layer in which the stacked order is located, the upper layer indicates the layer where the stacked order is located. Lighten brightening B <= A: C = AB> A: C = B this mode is similar to the previous one. The difference is that the color value is greater (that is, brighter) as the output result. Multiply front slice stacked C = A * B this effect will be two standard color values (based on 0 .. 1) After multiplication, the output results can be described as: two slides are superimposed and then displayed, and the transmitted light needs to be used separately through these two slides, thus being weakened twice. Screen Filter C = 1-(1-A) * (1-B) can also be written as 1-C = (1-A) * (1-B). This mode is the opposite of the previous one, after the standard color values of the upper and lower layers are multiplied, the output result will be brighter than the two pixel values (as if the two projectors respectively perform projection on one layer, and then projected onto the same screen ). From the second formula, we can see that if the two layers are reversed and mixed in Multiply mode, the results will be exactly the same as those after the two layers are mixed in Screen mode. Color Dodge Color fades C = B/(1-A) In this mode, the brightness of the upper layer determines the exposure of the lower layer. If the upper layer is brighter, the more light the lower layer gets, that is, the brighter the lower layer gets. If the upper layer is pure black, that is, there is no brightness, it will not affect the lower layer. If the upper layer is pure white, the lower layer is exposed except where the pixel is 255, and all other places are white (that is, 255, not exposed ). The blackest result is not lower than the lower pixel value. Color Burn Color deepening C = 1-(1-B)/A this mode is the opposite of the previous mode. If the upper layer is darker, the lower layer gets less light. If the upper layer is black, the lower layer gets darker. If the upper layer is white, the lower layer will not be affected. The brightest result is not higher than the lower pixel value. Linear Dodge Linear subtraction C = A + B adds the color values of the upper and lower layers. The result is brighter. Linear Burn Linear deepening C = A + B-1 if the sum of pixels on the upper and lower layers is less than 255, the output will be pure black. If the upper layer is reversed, the result is purely mathematical subtraction. Overlay overlays B <= 0.5: C = 2 * A * BB> 0.5: C = 1-2 * (1-A) * (1-B) based on the lower color values, this mode may be Multiply or Screen mode. The upper layer determines the intensity of the lower intermediate tone offset. If the upper layer is 50% Gray, the result is completely the lower pixel value. If the upper layer is darker than 50%, the middle tones of the lower layer will be shifted to the dark place. If the upper layer is brighter than 50%, the middle tones of the lower layer will be shifted to the bright place. For the upper layer is darker than 50%, the color bands below the lower middle tones are reduced (originally 0 ~ 2*0.4*0.5, now 0 ~ 2*0.3*0.5), with the color band becoming wider than the intermediate tone (Originally 2*0.4*0.5 ~ 1, now 2*0.3*0.5 ~ 1 ). And vice versa. Hard Light A <= 0.5: C = 2 * A * BA> 0.5: C = 1-2 * (1-A) * (1-B) This mode completely corresponds to Overlay mode, the order of the two layers. If the color above the upper layer is higher than 50% Gray, the lower layer is brighter, and vice versa. Soft Light A <= 0.5: C = (2 * A-1) * (B-B * B) + BA> 0.5: C = (2 * A-1) * (sqrt (B) -B) + B. This mode is similar to the upper layer, where the Gamma value ranges from 2.0 to 0.5. The result is a very soft combination. Vivid Light A <= 0.5: C = 1-(1-B)/2 * AA> 0.5: C = B/(2 * (1-A )) this mode greatly increases the contrast, especially in bright and dark places. It can be considered that Color Burn and Color Dodge are used in the dark. Linear Light C = B + 2 * The contrast increased by this mode is weaker than the previous mode. Similar to Linear Burn, it only deepens the influence of the upper layer. Pin Light Spot Light B <2 * A-1: C = 2 * A-12 * A-1
               
                 2 * A: C = 2 * A the result of this mode is that the intermediate tone is almost unchanged, but the two sides are A combination of Darken and Lighte. Hard Mix solid color mixing A <1-B: C = 0A> 1-B: C = 1 this mode causes the final result to contain only 6 basic colors, each channel is either 0 or 255. Difference C = | A-B | absolute value of upper and lower tones. This mode is mainly used to compare two different versions of images. If the two are identical, the result is black. Exclusion exclude C = A + B-2 * A * B bright image area will lead to another layer of reverse, very dark area will lead to another layer completely unchanged. Hue color phase HcScYc = HASBYB the color of the output image is the upper layer, and the saturation and brightness are kept as the lower layer. For the gray upper layer, the result is the decolored lower layer. Saturation HcScYc = the Saturation of the HBSAYB output image is the upper layer, and the tone and brightness are kept as the lower layer. Color HcScYc = HASAYB: the brightness of the output image is lower, and the tone and saturation are maintained at the upper layer. Luminosity brightness HcScYc = HBSBYA the brightness of the output image is the upper layer, and the tone and saturation are kept as the lower layer. Dissolve dissolution this mode is not actually dissolved, so it is not suitable for Dissolve. Its performance is just similar to Normal. It randomly selects some pixels from the upper layer as transparency so that it can see the lower layer. As the lower the transparency of the upper layer, the more lower the area can see. If the upper layer is completely opaque, the effect will not be different from Normal. * ***************************** Mixed Mode Formula ******* **************************************** **************************************** * **********/this. combine = THREE. multiplyOperation; // mixed mode this. reflectivity = 1; // reflectivity. The default value is 1this. refractionRatio = 0.98; // refractive index. The default value is 0.98this.fog = true; // fog effect. this is enabled by default. shading = THREE. smoothShading; this. wireframe = false; // render the ry in a box. the default value is falsethis. wireframeLinewidth = 1; // The width of the wireframe. The default value is 1. /*************************************** ******************************* * ******* The lineCap attribute specifies how a line segment ends. It is valid only when a wide line segment is drawn. The valid values of this attribute are shown in the following table. The default value is round. The default value butt specifies that the line segment should have no line caps. The end point of a line is straight and orthogonal to the line direction. This line segment is not extended beyond its endpoint. The value of round specifies that the line segment should carry a semi-circular line cap. The diameter of the half circle is equal to the width of the line segment, and the line segment expands half of the width of the line segment outside the endpoint. The value of square indicates that a line segment should carry a rectangular line cap. This value is the same as butt, but the line segment expands half of its width. The lineJoin attribute sets or returns the type of the created corner when two lines converge. Note: The value of miter is affected by the miterLimit attribute. Default Value: The round value describes the bevel creation angle. Round creates a rounded corner. The default value is miter. Create a tip. **************************************** ******************************* * ********/This. wireframeLinecap = 'round '; // the style of the Line Segment endpoint of the wireframe. The default value is round. Similar to the attributes in the html canvas, the options include butt, round, and squarethis. wireframeLinejoin = 'round '; // type of the Line Segment corner of the wireframe. When the two lines converge, the default value is round. Similar to the attributes in the html canvas, there are also round, bevel, miter // TODO? This. vertexColors = THREE. noColors; // vertex color. The default value is THREE. noColors. of course, THREE can also be created. vertexColors/THREE. faceColors and other options show the flexibility of javascript .; this. skinning = false; // defines whether the material uses skin. The default value is falsethis. morphTargets = false; // defines whether the material sets the target deformation animation. The default value is falsethis. morphNormals = false; // defines whether to reverse (Transform) The normal. The default value is falsethis. setValues (parameters); // call the setValues method of the Material class and assign the parameter parameters to the attributes of the current MeshLambertMaterial Material .}; /*************************************** * ************************ the method attribute definition of the MeshLambertMaterial object is as follows, inherited from Material ************************************* * ***********************/THREE. meshLambertMaterial. prototype = Object. create (THREE. material. prototype);/* clone method // clone method to clone the MeshLambertMaterial object ,*////
                Clone///
                MeshLambertMaterial object; optional .///
                
                  Returns the cloned MeshLambertMaterial object.
                THREE. meshLambertMaterial. prototype. clone = function () {// copy the attributes of the material one by one var material = new THREE. meshLambertMaterial (); THREE. material. prototype. clone. call (this, material); material. color. copy (this. color); material. ambient. copy (this. ambient); material. emissive. copy (this. emissive); material. wrapAround = this. wrapAround; material. wrapRGB. copy (this. wrapRGB); material. map = this. map; material. lightMap = this. lightMap; material. specularMap = this. specularMap; material. alphaMap = this. alphaMap; material. envMap = this. envMap; material. combine = this. combine; material. reflectivity = this. reflectiial; material. refractionRatio = this. refractionRatio; material. fog = this. fog; material. shading = this. shading; material. wireframe = this. wireframe; material. wireframeLinewidth = this. wireframeLinewidth; material. wireframeLinecap = this. wireframeLinecap; material. wireframeLinejoin = this. wireframeLinejoin; material. vertexColors = this. vertexColors; material. skinning = this. skinning; material. morphTargets = this. morphTargets; material. morphNormals = this. morphNormals; return material; // returns the cloned MeshLambertMaterial object };
               
              
             
            
           
          
         
        
       
      
     
    
   
  
 

Http://www.bkjia.com/kf/201412/359014.html previous

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.