Three.js Source Note (43) Light/spotlight.js

Source: Internet
Author: User
Tags truncated

Commercial Territory (http://blog.csdn.net/omni360/)

This article follows "Attribution-non-commercial use-consistent" authoring public agreement

Reprint Please keep this sentence: Business Domain-this blog focuses on Agile development and mobile and IoT device research: Data visualization, Golang, HTML5, WEBGL, three. JS, Otherwise, from this blog article refused to reprint or reprint, thank you for your cooperation.


I was just beginning to learn, a lot of things are definitely wrong and please forgive me.

The following code is a comment for the light/spotlight.js file in the three.js source file.

More updates in: Https://github.com/omni360/three.js.sourcecode


/** * @author alteredq/http://alteredqualia.com/*//*///spotlight method based on setting the color of the light, strength properties intensity, distance attribute distance, The illumination angle of the light angle, the attenuation speed exponent creates the spot light source (spotlights). The function function of the///spotlight object is implemented by the function prototype object that defines the construct.///Note:spotlight type light to achieve a shadow, But you need to use meshlambertmaterial in the scene or meshphongmaterial///the following comments directly 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 light object///Light.position.set (50,50,30);//Set Position///light.castshadow = true;/ /Turn on Shadow///light.shadowmapwidth = 1024; The shadow map width is set to 1024 pixels///light.shadowmapheight = 1024; Shadow map height is set to 1024 pixels///light.shadowcameranear = 500;//shadow of the flat head body area near Property///light.shadowcamerafar = 4000;//Shadow of the flat head body area far property Light.shadowcamerafov = 30;//Shadow of the flat head body area of the FoV property///scene.add (LIGNT);//Join Scene *////<summary>spotlight</ Summary>///<param name = "Color" type= "three. Color > Light </param>///<param name = "Intensity" type= "number" > the intensity of the light, the default is 1</param>///< param name = "Distance" type= "NumbeR "> The length attribute of the light, starting from the position position of the light, attenuation, attenuation to distance length, default is 0</param>///<param name =" angle "type=" number "> The spotlight's light illumination angle property, in radians, is the default 60-degree angle of radians </param>///<param name = "exponent" type= "number" > The Attenuation Speed property of the spotlight from the irradiation point, which defaults to 10 </param>///<returns type= "SpotLight" > Return SpotLight, Spotlight light. </returns>three. SpotLight = function (color, intensity, distance, angle, exponent) {three. Light.call (this, color);//Call method of the light object is called, the method that originally belongs to light is given to the current object spotlight to use. This.position.set (0, 1, 0);// The Location property of the light is initialized to 0,1,0this.target = new three. Object3d ();//Create a target point object, the target point object is a Object3d object. this.intensity = (intensity!== undefined)? intensity:1;//the Color property of the light, if not specified, is initialized to 1. (The density of the light, the default is 1.) Because the RGB three values are between 0~255, does not reflect the intensity of the light changes, the stronger the light, the surface of the object is brighter. ) This.distance = (distance!== undefined)? distance:0;//the length property of the light, if not specified, is initialized to 0. (Attenuation distance, default value is 0, light has no attenuation, if it is a non-0 value, the light starts to decay from the position position (actually the plane where the position is located), and after attenuation to distance distance, the illumination intensity intensity 0) This.angle = ( Angle!== undefined)? angle:math.pi/3;//Spotlight Light illumination angle property, in radians, by default is the radian of the 60 degree angle this.exponent = (exponent!== undefined)? The attenuation velocity exponent of the exponent:10;//spotlight from the point of exposure, by default is 10this.castshadow = false;//Boolean, default is False, and if set to true, all surfaces are calculated by cell to see if they are obscured in the light direction, This consumes a lot of computation. This.onlyshadow = false;//Boolean, which controls whether only shadows are generated without "illuminating" the object, which defaults to false. This model may have some special application. This.shadowcameranear = 50;//shadowcameranear,shadowcamerafar,shadowcamerafov property, the proximal end of the flat-truncated head, defines a range (flat-truncated head body), The shadow of an object outside the range is not computed, and near the default is the 50this.shadowcamerafar = 5000;//shadowcameranear,shadowcamerafar,shadowcamerafov property, the distal end of the flat-truncated body, Defines a range (the flat truncated head body), does not calculate the shadow of objects outside the range, far by default is 5000this.shadowcamerafov = 50;//shadowcameranear,shadowcamerafar, The Shadowcamerafov property, the horizontal truncated head body field of view, defines a range (flat truncated head body), does not calculate the shadow of an object outside the range, the FOV default is 50,this.shadowcameravisible = false;// Shadowcameravisible is set to true to display the light frame in the scene, which facilitates debugging This.shadowbias = 0;//The offset of the shadow map, this.shadowdarkness = The effect of the 0.5;//shadow on the brightness of the object, The default is 0.5this.shadowmapwidth = 512; Shadow map width, per pixel, default 512this.shadowmapheight = 512; Shadow map height, unit pixels, default 512//todo: The following are completely not understood, after the detailed comments This.shadowmap = null;//Specify the shadow map, Webglrendertarget object, here seems very complex, completely do not understand, Fill in the detailed comments later. This.shadowmapsize = null;//the size of the shadow map, note that this should conform to the openThe requirements for textures in GL (n-square +2n of 2) This.shadowcamera = null;//Shadow Map camera, three. Perspectivecamera object, This.shadowmatrix = null;//Shadow map Matrix};/******************************************************** The following is the definition of the functional function provided by the spotlight object, partially inherited from the light method by prototype **************************** /three. Spotlight.prototype = Object.create (three. Light.prototype);//spotlight object inherits all property methods from Three.light's prototype/*clone method///clone method Clone Spotlight Object *////<summary>clone </summary>///<returns type= "SpotLight" > returns the cloned SpotLight object </returns>three. SpotLight.prototype.clone = function () {var light = new three. SpotLight (); Three. Light.prototype.clone.call (this, light);//Call the THREE.Light.clone method, clone the Spotlight object//Copy the properties of the current lighting object light.target = This.target.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;//returns the object of the cloned spotlight source};


Commercial Territory (http://blog.csdn.net/omni360/)

This article follows "Attribution-non-commercial use-consistent" authoring public agreement

Reprint Please keep this sentence: Business Domain-this blog focuses on Agile development and mobile and IoT device research: Data visualization, Golang, HTML5, WEBGL, three. JS, Otherwise, from this blog article refused to reprint or reprint, thank you for your cooperation.


The following code is a comment for the light/spotlight.js file in the three.js source file.

More updates in: Https://github.com/omni360/three.js.sourcecode

Three.js Source Note (43) Light/spotlight.js

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.