Look at my blog & gt;> ThingJS spotlight functional attributes is official sample out I'll pack (nearly 200)
CodePudding user response:
var app=new THING. The app ({
Url: 'https://www.thingjs.com/static/models/storehouse',
});
//parameter
Var dataObj={
'type' : 'SpotLight',
'lightAngle: 30,
'intensity' : 1,
'penumbra: 0.5,
'castShadow: false,
'the position' : null,
'height' : 0,
'color: 0 XFFFFFF,
'short' : null,
'target' : null,
'helper' : true,
};
//forklift
Let car1.
Let car2;
//the current lighting
Let curLight;
Let curLightPosition;
//create the spotlight method
The function createSpotLight (position, target) {
DataObj [' lightAngle]=30;
DataObj [' intensity ']=0.5;
DataObj [' penumbra ']=0.5;
DataObj [' castShadow]=false;
DataObj [' position ']=position;
DataObj [' short ']=25;
DataObj [' color ']=0 XFFFFFF;
DataObj [' helper ']=true;
DataObj [' follow ']=false;
//create the spotlight
Var spotLight=app. The create (dataObj);
CurLight=spotLight;
CurLightPosition=spotLight. The position;
CreateSpotLightControlPanel (spotLight);
}
.
//register the mouse events, check whether the press 'shift' key, press the set the spotlight follow the mouse position
App. On (' mousemove ', function (ev) {
if (! CurLight) {
return;
}
if (! Ev. ShiftKey) {
return;
}
Var pickedPosition=ev. PickedPosition;
If (pickedPosition) {
CurLight. LookAt (pickedPosition);
}
})
//register setting load event
App. On (' load ', function (ev) {
//the main light intensity is set to 0, highlight the spotlight effect
App. Lighting={
MainLight: {
Intensity: 0
}
};
//get scene with id 'car01' and 'car02' forklift
Car1=app. Query (' car01) [0];
Car2=app. Query (' car02) [0];
//parameter 1:5 meters above the car2 create a spotlight
//parameter 2: the location of the initial target is set to car1
CreateSpotLight (THING. Math. AddVector (car2. The position of [0, 5, 0]), car1. Position);
//create a circular path
Var path=[];
Var radius=6;
For (var degree=0; Degree & lt;=360; Degree +=10) {
Var x=Math. Cos (math.h degree * 2 * PI/360) * radius;
Var z=Math. Sin (math.h degree * 2 * PI/360) * radius;
Path. Push (THING. Math. AddVector (car1. The position of (x, 0, z)));
}
//let car1 along a circular path movement
Car1. MovePath ({
OrientToPath: true,//the object moves along the direction to the path
Path: the path,
Time: 10 * 1000,
//loop type
//THING. LoopType. Repeat cycle
//THING. LoopType. PingPong reciprocating cycle
LoopType: THING. LoopType. Repeat
});
The console. The log (" hold down the 'shift' spotlight can track the mouse position (open 'follow objects' after failure) ");
})