How to use the DirectionalLight function from three
Find comprehensive JavaScript three.DirectionalLight code examples handpicked from public code repositorys.
GitHub: K3D-tools/K3D-jupyter
590 591 592 593 594 595 596 597 598
// The two back lights, one on the left of the object as seen from the observer and one on the right, fill on // the high-contrast areas behind the object. To enforce the relationship between the different lights, the // intensity of the fill, back and headlights are set as a ratio to the key light brightness. Thus, the // brightness of all the lights in the scene can be changed by changing the key light intensity. this.keyLight = new THREE.DirectionalLight(0xffffff); // key this.headLight = new THREE.DirectionalLight(0xffffff); // head this.fillLight = new THREE.DirectionalLight(0xffffff); // fill this.backLight = new THREE.DirectionalLight(0xffffff); // back
116
804
0
+ 3 other calls in file
52 53 54 55 56 57 58 59 60
this.scene.fog = new THREE.FogExp2(background); var directionalLight1 = new THREE.DirectionalLight(0xFFFFFF, 1.2); directionalLight1.position.set(0.2, 0.2, -1).normalize(); var directionalLight2 = new THREE.DirectionalLight(0xFFFFFF, 1.2); directionalLight2.position.set(0.2, 0.2, 1).normalize(); var ambientLight = new THREE.AmbientLight(0x202020);
17
78
8
+ 41 other calls in file
14 15 16 17 18 19 20 21 22
// Basic Lambert white var lambertWhite = new THREE.MeshLambertMaterial({ color: 0xaaaaaa, side: THREE.DoubleSide }); // Set light var directionalLight = new THREE.DirectionalLight( 0xffffff, 1 ); directionalLight.color.setHSL(0.1, 1, 0.95); directionalLight.position.set(1, 3, 2); directionalLight.position.multiplyScalar(10);
31
0
2
+ 15 other calls in file
GitHub: kentywang/Agamari
99 100 101 102 103 104 105 106 107 108
createLevel(); // lighting hemisphereLight = new THREE.HemisphereLight('#004570', someColors['pink'], 0.8); shadowLight = new THREE.DirectionalLight('#4ECDC4', 0.3); shadowLight.castShadow = true; shadowLight.shadow.camera.left = -400;
15
47
10
+ 15 other calls in file
GitHub: shinseed/BIMServer-NodeJs
186 187 188 189 190 191 192 193 194 195
// light var light = new THREE.DirectionalLight(0xffffff); light.position.set(1, 1, 1); this.scene.add(light); // var light = new THREE.DirectionalLight(0x002288); // light.position.set(-1, -1, -1);
13
28
7
+ 3 other calls in file
GitHub: avocadojesus/hackaholics
53 54 55 56 57 58 59 60 61 62
controls.domElement = container; controls.rollSpeed = Math.PI / 24; controls.autoForward = false; controls.dragToLook = false; dirLight = new THREE.DirectionalLight( 0xffffff ); dirLight.position.set( -1, 0, 1 ).normalize(); scene.add( dirLight ); var materialNormalMap = new THREE.MeshPhongMaterial( {
0
3
5
GitHub: mattdesl/filmic-gl
16 17 18 19 20 21 22 23 24 25
point.position.y = 80; scene.add(point); var hemi = new THREE.HemisphereLight(0x5babc2, 0x8d5f2e, 1); var dir = new THREE.DirectionalLight(0x5babc2, 0.5); dir.position.y = 50; dir.position.x = 10; dir.position.z = -10; dir.castShadow = true;
2
51
7
164 165 166 167 168 169 170 171 172 173
scene = new THREE.Scene(); sceneCube = new THREE.Scene(); // Lights var ambient = new THREE.AmbientLight( 0xffffff, 0.3 ); scene.add( ambient ); var sunlight = new THREE.DirectionalLight( 0xffffff, 1 ) sunlight.position.set(50, 100, 300); // Approximate vector towards sun in background image scene.add( sunlight ); // Textures var urls = [
75
0
1
31 32 33 34 35 36 37 38 39 40
let clock = new THREE.Clock(); let loader = new THREE.TextureLoader(); let material = new THREE.MeshStandardMaterial({ vertexColors: THREE.VertexColors, map: new THREE.DataTexture(new Uint8Array(3).fill(255), 1, 1, THREE.RGBFormat) }); let ambientLight = new THREE.AmbientLight(0xFFFFFF, 0.8); let directionalLight = new THREE.DirectionalLight(0xFFFFFF, 0.5); let pointLight = new THREE.PointLight(0xFFFFFF, 0.5); let cube = new THREE.Mesh(new THREE.BoxBufferGeometry(0.2, 0.2, 0.2), material.clone()); let sphere = new THREE.Mesh(initColors(new THREE.SphereBufferGeometry(0.1, 20, 20)), material.clone());
10
53
4
GitHub: cfry/dde
217 218 219 220 221 222 223 224 225 226
//camera.lookAt( scene.position ); } function createLights(){ /* doesn't do anything //var light = new THREE.PointLight( 0xFFFF00 ); var light = new THREE.DirectionalLight( 0xffffff, 0.5 ); light.position.set( 10, 10, 10 ); scene.add( light ); */ //renderer.setClearColor( 0xdddddd, 1); //makes a gray background color instead of black
24
38
12
169 170 171 172 173 174 175 176 177 178
scene = new THREE.Scene(); // var ambient = new THREE.AmbientLight( 0x444444 ); // scene.add( ambient ); // var directionalLight = new THREE.DirectionalLight( 0xffeedd ); // directionalLight.position.set( 0, 0, 1 ).normalize(); // scene.add( directionalLight ); // var sphereBufferGeometry = new THREE.SphereBufferGeometry( 5, 10, 10 );
5
23
3
+ 5 other calls in file
GitHub: TimothyStiles/meshdiff
48 49 50 51 52 53 54 55 56 57
controls.noPan = false; } function addShadowedLight( x, y, z, color, intensity ) { var directionalLight = new THREE.DirectionalLight( color, intensity ); directionalLight.position.set( x, y, z ); scene.add( directionalLight ); directionalLight.castShadow = true;
2
13
1
GitHub: VCityTeam/UD-Viz
106 107 108 109 110 111 112 113 114 115
* @param {THREE.Scene} scene - the scene where to add lights * @returns {{directionalLight:THREE.DirectionalLight, ambientLight:THREE.AmbientLight}} - lights added */ addLights: function (scene) { // Lights const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5); directionalLight.position.set(100, 100, 500); directionalLight.target.position.set(0, 0, 0); directionalLight.updateMatrixWorld(); scene.add(directionalLight);
15
10
0
+ 4 other calls in file
GitHub: amatelus/paintcoin
172 173 174 175 176 177 178 179 180
initLight() { const frontLight = new THREE.DirectionalLight(0xffffff, 1.25); frontLight.position.set(0, 0.5, 2); this.scene.add(frontLight); const backLight = new THREE.DirectionalLight(0xffffff, 1.25); backLight.position.set(0, 0.5, -2); this.scene.add(backLight); }
2
3
2
+ 11 other calls in file
217 218 219 220 221 222 223 224 225 226
this.camera.position.set(0, 0, 35); this.camera.lookAt(new THREE.Vector3(0, 0, 0)); this.scene.add(this.camera); // Our key light is at a 3/4 angle from our subject. this.directionalLight = new THREE.DirectionalLight(0xffffff, .75); this.directionalLight.position.set(-1, 1, 0); this.scene.add(this.directionalLight); // Our fill light normalizes the colors, making white 100% white.
1
11
1
+ 3 other calls in file
47 48 49 50 51 52 53 54 55 56
} gui.add(options, 'strategy', ['Proxy Geometry', 'Ray Marching']); scene.add(new THREE.AxisHelper(20)); scene.add(new THREE.DirectionalLight(0xffffff, 1)); var proxyGeometry = new ProxyGeometry(); var boxMesh = new THREE.Mesh(BoxGeometry, ProxyMaterial);
11
3
6
282 283 284 285 286 287 288 289 290
var range = lightDef.range !== undefined ? lightDef.range : 0; switch (lightDef.type) { case "directional": lightNode = new THREE.DirectionalLight(color); lightNode.target.position.set(0, 0, -1); lightNode.add(lightNode.target); break;
3
7
8
+ 14 other calls in file
3396 3397 3398 3399 3400 3401 3402 3403 3404
let light = new THREE.AmbientLight( 0xffffff, 0.5 ); // soft white light this.scene.add( light ); const directionalLight = new THREE.DirectionalLight( 0xffffff, .5 ); directionalLight.position.set( 1, 1, 1 ); this.scene.add( directionalLight ); }
3
7
0
+ 17 other calls in file
GitHub: audunsh/evince
143 144 145 146 147 148 149 150 151 152
let light = new THREE.DirectionalLight(0xfff0dd, 1); light.position.set(0, 5, 10); this.scene.add(light); let directionalLight = new THREE.DirectionalLight( 0xffffff, .5 ); directionalLight.position.set( 1, 1, 1 ); this.scene.add( directionalLight ); //let alight = new THREE.AmbientLight( 0x202020, 5 ); // soft white light
3
7
0
+ 3 other calls in file
GitHub: OpenSlicer/OpenSlicer
35 36 37 38 39 40 41 42 43 44 45
} let numLayers = 0 let canvas = document.getElementById('canvas') let camera, scene, renderer, controls let camLight = new THREE.DirectionalLight(0xffffff, 0.75) let mainObj let wireframeObj let normalsHelper let mainGeom
2
14
0
+ 5 other calls in file
three.Vector3 is the most popular function in three (22341 examples)