Three. js source code annotation (forty-three) Light/SpotLight. js

Source: Internet
Author: User

Three. js source code annotation (forty-three) Light/SpotLight. 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/SpotLight. JS file in the THREE. js source code file.

 

/*** @ Author alteredq/http://alteredqualia.com/* // SpotLight method according to the set light color, intensity property intensity, distance property distance, the illumination angle of the light. The attenuation speed exponent creates a spot light source (spotlight ). /// the function functions of the SpotLight object are implemented by defining the constructed function prototype object. /// NOTE: SpotLight lighting implements shadow, but you need to use MeshLambertMaterial or MeshPhongMaterial in the scene. // The following annotations are directly Excerpted from: http://www.cnblogs.com/yiyezhai/archive/2012/12/24/2829991.html/// Example: /// var light = new THREE. spotLight (0xff0000, 1,100, Math. PI/2, 5); // create a light object // light. position. set (50, 50, 30); // set the location // light. castShadow = true; // enable shadow // light. shadowMapWidth = 1024; // set the shadow width to 1024 pixels. // light. shadowMapHeight = 1024; // set the shadow height to 1024 pixels. // light. shadowCameraNear = 500; // The near attribute of the area of the Shadow head. // light. shadowCameraFar = 4000; // specifies the far attribute of the area of the Shadow intercept. // light. shadowCameraFov = 30; // specifies the fov attribute of the area of the Shadow intercept. // scene. add (lignt); // add the scenario *////SpotLight///Light color attributes ///The light intensity. The default value is 1 ///The Length attribute of the Light, starting from the position of the light, which degrades to the length of distance. The default value is 0 ///The lighting angle attribute of the spotlight. Unit: radians. The default value is 60 degrees ///The attenuation speed attribute of the spotlight from the illumination point. The default value is 10 ///
 
  
Returns SpotLight, a spot light source.
 THREE. spotLight = function (color, intensity, distance, angle, exponent) {THREE. light. call (this, color); // call the call method of the Light object and hand over the method originally belongs to the Light object to SpotLight for use. this. position. set (0, 1, 0); // set the lighting position to, 0this.tar get = new THREE. object3D (); // create a target object, which is an Object3D object. this. intensity = (intensity! = Undefined )? Intensity: 1; // The color attribute of the light. If not specified, the light is initialized to 1. (the default value is 1 for the light density. Because the three values of RGB are 0 ~ Between 255, does not reflect the intensity change of the light, the stronger the light, the object surface is brighter .) This. distance = (distance! = Undefined )? Distance: 0; // The Light Length attribute. If not specified, the light is initialized to 0. (attenuation distance. The default value is 0, and there is no attenuation in the light. If the value is not 0, the light degrades from the position (actually the plane in which the position is located) to the distance, the light intensity is 0) this. angle = (angle! = Undefined )? Angle: Math. PI/3; // The lighting angle attribute of the spotlight. Unit: radians. The default value is 60 degrees. this. exponent = (exponent! = Undefined )? Exponent: 10; // The attenuation speed index of the spotlight from the illumination point. The default value is 10this. castShadow = false; // Boolean value. The default value is false. If this value is set to true, all surfaces are masked by pixel, this consumes a lot of computing. This. onlyShadow = false; // Boolean value, which controls whether to generate only shadow and not "illuminate" the object. The default value is false. This mode may have some special applications. // This. shadowCameraNear = 50; // shadowCameraNear, shadowCameraFar, shadowCameraFov attributes, near the head of the head, defines a range (the head of the head), and does not calculate the shadows of objects outside the range, near is 50this by default. shadowCameraFar = 5000; // shadowCameraNear, shadowCameraFar, and shadowCameraFov attributes. The remote end of the intercept defines a range (intercept body) and does not calculate the shadow of objects outside the range, far is 5000this by default. shadowCameraFov = 50; // shadowCameraNear, shadowCameraFar, and shadowCameraFov attributes. You can define a range (a range) without calculating the shadows of objects outside the range, fov is 50 by default, this. shadowCameraVisible = false; // set shadowCameraVisible to true. The frame of the light is displayed in the scene for debugging. shadowBias = 0; // the offset of the shadow, this. shadowDarkness = 0.5; // The effect of shadow on the brightness of an object. The default value is 0.5this.shadowMapWidth = 512; // The Shadow width, in pixels. The default value is. shadowMapHeight = 512; // specifies the shadow height, in pixels. The default value is 512. // TODO: I have not figured out the following. I will add a detailed comment on this later. shadowMap = null; // specifies the shadow texture and the WebGLRenderTarget object. It seems very complicated and I have not figured it out. I will add detailed annotations later. this. shadowMapSize = null; // the size of the Shadow image. Note that the shadowMapSize must meet the texture requirements in OpenGL (n + 2n of 2) this. shadowCamera = null; // shadow camera, THREE. perspectiveCamera object, this. shadowMatrix = null; // shadowMatrix }; /*************************************** **************************************** * ********** the function definitions provided by the SpotLight object are as follows, some of them inherit from the Light method through prototype ********************************* **************************************** * *************/THREE. spotLight. prototype = Object. create (THREE. light. prototype); // SpotLight object from THREE. the Light prototype inherits all attribute methods/* clone method // clone method to clone the SpotLight object *////Clone///
 
  
Returns the cloned SpotLight object.
 THREE. spotLight. prototype. clone = function () {var light = new THREE. spotLight (); THREE. light. prototype. clone. call (this, light); // call THREE. light. clone method: clone the spotlight object // copy the previous light.tar get = this.tar get of the current headlight object. clone (); light. intensity = this. intensity; light. distance = this. distance; light. angle = this. angle; light. exponent = this. exponent; light. castShadow = this. castShadow; light. onlyShadow = this. onlyShadow; // light. shadowCameraNear = this. shadowCameraNear; light. shadowCameraFar = this. shadowCameraFar; light. shadowCameraFov = this. shadowCameraFov; light. shadowCameraVisible = this. shadowCameraVisible; light. shadowBias = this. shadowBias; light. shadowDarkness = this. shadowDarkness; light. shadowMapWidth = this. shadowMapWidth; light. shadowMapHeight = this. shadowMapHeight; return light; // return the object of the cloned spotlight light source };
Http://www.bkjia.com/kf/201412/359017.html previous

 

Related Article

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.