Three. js source code annotation (forty-four) Light/DirectionalLight. js

Source: Internet
Author: User

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

 

/*** @ Author mrdoob/http://mrdoob.com/* @ author alteredq/http://alteredqualia.com/* // DirectionalLight method depending on the set color property of the light, the intensity attribute intensity creates a parallel optical source. /// functional functions of DirectionalLight objects are implemented using the defined 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 *////DirectionalLight///Light color attributes ///The light intensity. The default value is 1 ///
 
  
Returns DirectionalLight, a parallel light source.
 THREE. directionalLight = 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 DirectionalLight 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. 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 attribute, near the orthogonal projection cube, defines a range (orthogonal projection cube), does not calculate the shadow of objects outside the range, near is 50this by default. shadowCameraFar = 5000; // shadowCameraFar attributes, the far end of the orthogonal projection cube, defining a range (orthogonal projection cube) without calculating the shadow of objects outside the range. The default far value is 5000this. shadowCameraLeft =-500; // The shadowCameraLeft attribute defines a range (orthogonal projection cube) on the left end of the orthogonal projection cube without calculating the shadow of objects outside the range. The default value of left is 500this. shadowCameraRight = 500; // shadowCameraRight attribute, right end of the orthogonal projection cube, which defines a range (orthogonal projection cube) without calculating the shadow of objects outside the range. right is the default value. 500this. shadowCameraTop = 500; // shadowCameraTop attribute, top of the orthogonal projection cube, defines a range (orthogonal projection cube), does not calculate the shadow of objects outside the range, top is 500this by default. shadowCameraBottom =-500; // shadowCameraBottom attribute, Bottom of the orthogonal projection cube, defines a range (orthogonal projection cube), does not calculate the shadow of objects outside the range, Bottom is 500this by default. 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 shadowDarkness, in the unit Pixel, 512this by default. shadowMapHeight = 512; // shadow texture height, in pixels. The default value is 512/* for parallel light, WebGL can use cascading shadow textures (or become parallel shadow textures) it has good shadow quality, especially long-distance viewing. Cascading shadows gradually increase by dividing the visible area and use the same size in each shadow texture. The result is that objects close to the viewer will get more shadow pasters than objects farther away. For the quality and performance of the parallel light shadow, the shadow distance is very important. Like the shadow cascade, the shadow distance can be set in quality settings, which can easily reduce the shadow range to reduce hardware performance consumption. At the end of the Shadow distance, the shadow fades out, and objects farther away have no shadow. In most cases, shadows farther away in the scene are not noticeable! */This. shadowCascade = false; // shadow cascade this. shadowCascadeOffset = new THREE. vector3 (0, 0,-1000); // shadow cascade offset distance this. shadowCascadeCount = 2; // when two shadow cascade operations are used, the entire Shadow distance is divided into two blocks by default, which are smaller blocks near the observer and larger blocks in the distance. this. shadowCascadeBias = [0, 0, 0]; // shadow cascade offset array this. shadowCascadeWidth = [512,512,512]; // shadowCascadeWidth array this. shadowCascadeHeight = [512,512,512]; // shadow cascade height array this. shadowCascadeNearZ = [-1.000, 0.990, 0.998]; // shadow cascade near this. shadowCascadeFarZ = [0.990, 0.998, 1.000]; // shadow cascade remote location this. shadowCascadeArray = []; // shadowCascadeArray cascade array // TODO: I am not clear about 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 definition provided by the DirectionalLight object is as follows, some of them inherit from the Light method through prototype ********************************* **************************************** * *************/THREE. directionalLight. prototype = Object. create (THREE. light. prototype); // DirectionalLight object from THREE. the Light prototype inherits all attribute methods/* clone method // clone method to clone the DirectionalLight object *////Clone///
 
  
Returns the cloned DirectionalLight object.
 THREE. directionalLight. prototype. clone = function () {var light = new THREE. directionalLight (); THREE. light. prototype. clone. call (this, light); // call THREE. light. clone method: clone a Parallel Object // copy the current light.tar get = this.tar get. clone (); light. intensity = this. intensity; light. castShadow = this. castShadow; light. onlyShadow = this. onlyShadow; // light. shadowCameraNear = this. shadowCameraNear; light. shadowCameraFar = this. shadowCameraFar; light. shadowCameraLeft = this. shadowCameraLeft; light. shadowCameraRight = this. shadowCameraRight; light. shadowCameraTop = this. shadowCameraTop; light. shadowCameraBottom = this. shadowCameraBottom; light. shadowCameraVisible = this. shadowCameraVisible; light. shadowBias = this. shadowBias; light. shadowDarkness = this. shadowDarkness; light. shadowMapWidth = this. shadowMapWidth; light. shadowMapHeight = this. shadowMapHeight; // light. shadowCascade = this. shadowCascade; light. shadowCascadeOffset. copy (this. shadowCascadeOffset); light. shadowCascadeCount = this. shadowCascadeCount; light. shadowCascadeBias = this. shadowCascadeBias. slice (0); light. shadowCascadeWidth = this. shadowCascadeWidth. slice (0); light. shadowCascadeHeight = this. shadowCascadeHeight. slice (0); light. shadowCascadeNearZ = this. shadowCascadeNearZ. slice (0); light. shadowCascadeFarZ = this. shadowCascadeFarZ. slice (0); return light; // returns the cloned parallel light object };
Http://www.bkjia.com/kf/201412/359015.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.