How to use the SpotLight function from three

Find comprehensive JavaScript three.SpotLight code examples handpicked from public code repositorys.

79
80
81
82
83
84
85
86
87
88
this.camera = camera;



scene.add( new THREE.AmbientLight( 0xf0f0f0 ) );
var light = new THREE.SpotLight( 0xffffff, 1.5 );
light.position.set( 0, 1500, 200 );
light.castShadow = true;
light.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 70, 1, 200, 2000 ) );
light.shadow.bias = -0.000222;
fork icon16
star icon39
watch icon8

159
160
161
162
163
164
165
166
167

const whiteColor = 0xffffff;
const lightMain = new THREE.HemisphereLight(whiteColor, 0xffffff, 0.42);
scene.add(lightMain);

const lightDir1 = new THREE.SpotLight(whiteColor, 0.98251, 30, Math.PI / 4, 2, 2);
lightDir1.position.set(5, 7, 5);
lightDir1.castShadow = true;
scene.add(lightDir1);
fork icon9
star icon77
watch icon5

+ 5 other calls in file

215
216
217
218
219
220
221
222
223
224
function addLigth(color, position){
    
    group = new THREE.Group();

    var bulbGeometry = new THREE.SphereGeometry(1, boxSize[1]/4, boxSize[1]/4);
    var spotLight = new THREE.SpotLight(Number(color));
    var bulbLight = new THREE.PointLight(Number(color), 0.1);
    
    bulbLight.power = 0.25;
    bulbLight.decay = 1;
fork icon26
star icon28
watch icon0

+ 2 other calls in file

293
294
295
296
297
298
299
300
301
302
  lightNode = new THREE.PointLight(color);
  lightNode.distance = range;
  break;

case "spot":
  lightNode = new THREE.SpotLight(color);
  lightNode.distance = range;
  // Handle spotlight properties.
  lightDef.spot = lightDef.spot || {};
  lightDef.spot.innerConeAngle =
fork icon3
star icon7
watch icon8

+ 14 other calls in file

440
441
442
443
444
445
446
447
448
449
    lightNode = new THREE.PointLight( color );
    lightNode.distance = range;
    break;

case 'spot':
    lightNode = new THREE.SpotLight( color );
    lightNode.distance = range; // Handle spotlight properties.

    lightDef.spot = lightDef.spot || {};
    lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0;
fork icon2
star icon10
watch icon0

528
529
530
531
532
533
534
535
536
537
case 'point':
    lightNode = new three.PointLight(color);
    lightNode.distance = range;
    break;
case 'spot':
    lightNode = new three.SpotLight(color);
    lightNode.distance = range;
    lightDef.spot = lightDef.spot || {};
    lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0;
    lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== undefined ? lightDef.spot.outerConeAngle : Math.PI / 4.0;
fork icon2
star icon7
watch icon0

134
135
136
137
138
139
140
141
142
143
  // 环境光-均匀的照亮场景中的所有物体,不能投射阴影
  const Alight = new THREE.AmbientLight(0x404040)
  this.scene.add(Alight)

  // 添加聚光灯
  const light = new THREE.SpotLight({ color: '#fff' })
  // 需要开启阴影投射
  light.castShadow = true
  return light
}
fork icon1
star icon7
watch icon2

98
99
100
101
102
103
104
105
106
107
this.scene.add(this.planeAudio);

this.plane = new Plane();
this.scene.add(this.plane);

this.spotLight = new THREE.SpotLight( 0xffffff );
this.spotLight.position.set( 0, 1000, 0 );
this.spotLight.castShadow = true;
this.spotLight.shadowMapWidth = 1024;
this.spotLight.shadowMapHeight = 1024;
fork icon3
star icon6
watch icon1

138
139
140
141
142
143
144
145
146

const cameraZ = (boundingBox.max.z - boundingBox.min.z) * 15;
camera.position.z = 500; //cameraZ;

const addLight = (xx, yy) => {
  let spotLight = new THREE.SpotLight(0xffffff);
  spotLight.position.set(xx, yy, 100);

  spotLight.castShadow = true;
fork icon1
star icon5
watch icon2

67
68
69
70
71
72
73
74
75
76
  opacity: 0.2
});

// Lighting
const ambient = new THREE.AmbientLight(0x404040);
const spotlight = new THREE.SpotLight(0xffffff);
const lightHelper = new THREE.SpotLightHelper(spotlight);

// Voxels
const selectionGlow = new THREE.PointLight(0xffffff, 1, 50);
fork icon1
star icon1
watch icon0

+ 17 other calls in file

1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597


const initScene = function () {
    var light = new THREE.AmbientLight(0x404040); // soft white light
    app.scene.add(light);


    app.spotLight = new THREE.SpotLight(0xffffff, 1, 200, 10);
    app.spotLight.position.set(0, 5, 50);
    app.spotLight.update = (dt) => {
        let normal = new THREE.Vector3().copy(app.controls.target);

fork icon1
star icon1
watch icon0

843
844
845
846
847
848
849
850
851
852
this._yokeDummy = new THREE.Object3D();
this._beamDummy = new THREE.Object3D();
this._targetDummy = new THREE.Object3D();
this._boxHelperDummy = new THREE.Object3D();

this._spotLight = new THREE.SpotLight(
  this.colorTemp,
  SPOTLIGHT_PHYSICALLY_CORRECT_INTENSITY,
  SPOTLIGHT_PHYSICALLY_CORRECT_DISTANCE,
  MovingHead.degToRad(this.angle),
fork icon0
star icon7
watch icon0

+ 3 other calls in file

21
22
23
24
25
26
27
28
29
30
// add the scene to render in
this.scene = new three.Scene()
// this.scene.fog = new three.Fog(0x333333, 5, 40)

// add light to scene
const light = new three.SpotLight(0xffffff, 1)
light.position.set(-50, 50, 0)

// const h = new three.SpotLightHelper(light, 1, 0x333333)
// this.scene.add(h)
fork icon0
star icon2
watch icon0

354
355
356
357
358
359
360
361
362
363
  lightNode = new _three.PointLight(color);
  lightNode.distance = range;
  break;

case 'spot':
  lightNode = new _three.SpotLight(color);
  lightNode.distance = range; // Handle spotlight properties.

  lightDef.spot = lightDef.spot || {};
  lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0;
fork icon0
star icon1
watch icon0

74
75
76
77
78
79
80
81
82
83
light.shadow.radius = 1;
scene.add(light);

console.log(light.shadow);

var lightOp = new THREE.SpotLight(0xaaccff, 1, 0);
lightOp.position.set(50, 20, -35);
// lightOp.castShadow = true;
// lightOp.shadow.bias = 0.0001;
// lightOp.shadow.mapSize.width = 2048;
fork icon0
star icon1
watch icon0

+ 5 other calls in file

1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
		penumbra = THREE.Math.degToRad( lightAttribute.OuterAngle.value );
		penumbra = Math.max( penumbra, 1 );

	}

	model = new THREE.SpotLight( color, intensity, distance, angle, penumbra, decay );
	break;

default:
	console.warn( 'FBXLoader: Unknown light type ' + lightAttribute.LightType.value + ', defaulting to a THREE.PointLight.' );
fork icon0
star icon0
watch icon1

+ 88 other calls in file

1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
	light = new THREE.PointLight( color, intensity, distance );
	break;

case 'spot':

	light = new THREE.SpotLight( color, intensity, distance, angle );
	light.position.set(0, 0, 1);
	break;

case 'ambient':
fork icon0
star icon0
watch icon2

+ 10 other calls in file

118
119
120
121
122
123
124
125
126
127
this.scene.add( ambient );
var directionalLight = new THREE.DirectionalLight( 0xdddddd );
directionalLight.position.set( 1, 1, 1 ).normalize();
this.scene.add( directionalLight );

var spot1   = new THREE.SpotLight( 0xffffff, 1 );
// spot1.position.set( 10, 20, 10 );
spot1.position.set( 10, 20, -30 );
spot1.angle = 0.25;
spot1.distance = 1024;
fork icon0
star icon0
watch icon1

201
202
203
204
205
206
207
208
209
210
  this.controls.push(new KeyboardControls(this));
  this.controls.push(new GamepadControls(this));
}

addLights () {
  var directionalLight = new THREE.SpotLight(0xffffff, 1.2);
  directionalLight.position.set(1, 1, 1).multiplyScalar(100);
  directionalLight.target.position.set(0, 0, 0);
  directionalLight.castShadow = true;
  directionalLight.shadow = new THREE.LightShadow(new THREE.PerspectiveCamera(25, 1, 10, 500));
fork icon0
star icon0
watch icon0

+ 7 other calls in file

152
153
154
155
156
157
158
159
160
161
controls.enabled = !options.enableSwoopingCamera;

const scene = new THREE.Scene();

//const light = new THREE.DirectionalLight(0xfff0dd, 1);
const light = new THREE.SpotLight(0xfff0dd, 0.5);
light.position.set(radius * 2 + 100, radius * 2, 100);
light.castShadow = true;
light.shadow.mapSize.set(5200, 5200);
scene.add(light);
fork icon0
star icon0
watch icon0

+ 3 other calls in file

Other functions in three

Sorted by popularity

function icon

three.Vector3 is the most popular function in three (22341 examples)