Three. js source code annotation (forty-two) Light/AreaLight. js

Source: Internet
Author: User

Three. js source code annotation (forty-two) Light/AreaLight. js

 

Reprinted please keep this sentence: Wuji-this blog focuses on Agile development and mobile and IOT device research: data visualization, GOLANG, Html5, WEBGL, THREE. JS. Otherwise, the post from this blog will not be reprinted or reprinted. Thank you for your cooperation.


I also just started learning. Sorry for the errors in many places.

The following code is a comment on the Light/AreaLight. JS file in the THREE. js source code file.

 

/*** @ Author MPanknin/http://www.redplant.de/* @ author alteredq/http://alteredqualia.com/* // AreaLight method according to set the color attribute of the light, the intensity attribute intensity creates a plane light (area light ). the function functions of the AreaLight object are implemented by using a function prototype object constructed by // definition. Different from other light sources, the AreaLight object is a two-dimensional area light source whose brightness is not only related to the intensity, it is also related to the area size. /// by changing the width, height, and normal attributes of the light, the area light can simulate the light injected into the window. /// TODO: The AreaLight light has not implemented shadow in this version .??? /// Example: // var light = new THREE. areaLight (0xff0000, 1); // create a flat light object // light. position. set (50, 50, 30); // set the location // light. rotation. set (-0.3, 0.3, 0.002); // set the angle // light. width = 10; // set the width // light. height = 1; // set the height /// scene. add (lignt); // add the scenario *////AreaLight///Light color attributes ///The light intensity. The default value is 1 ///
 
  
Returns AreaLight, region light.
 THREE. areaLight = function (color, intensity) {THREE. light. call (this, color); // call the call method of the Light object, and hand over the method originally belongs to the Light to the current object AreaLight for use. this. normal = new THREE. vector3 (0,-1, 0); // The normal of the Area light. you can set or obtain the unit vector of the Area light to confirm that the area light is shining correctly. this is calculated in a local space. this. right = new THREE. vector3 (1, 0, 0); // this. intensity = (intensity! = Undefined )? Intensity: 1; // color attribute of the light. If not specified, the light is initialized to 1. this. width = 1.0; // The width of the Area light, initialized to 1.0this.height = 1.0; // The height of the Area light, initialized to 1.0 // WebGL is calculated by multiplying the light intensity by the attenuation coefficient, // attenuation (attenuation coefficient) = 1'/(this. constantAttenuation + this. distance * this. linearAttenuation + this. quadraticAttenuation * this. distance * this. distance) this. constantAttenuation = 1.5; // constant attenuation coefficient. The greater the coefficient, the faster the decay. This. linearAttenuation = 0.5; // linear attenuation coefficient. The larger the coefficient, the faster the decay. This. quadraticAttenuation = 0.1; // The square coefficient of attenuation. The greater the coefficient, the faster the decay .}; /*************************************** **************************************** * ********** The function definition provided by the AreaLight object is shown below, some of them inherit from the Light method through prototype ********************************* **************************************** * *************/THREE. areaLight. prototype = Object. create (THREE. light. prototype); // AreaLight object from THREE. the prototype of Light inherits all attribute methods.


Http://www.bkjia.com/kf/201412/359019.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.