55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
let ObjectNames
|
|
let Values
|
|
let Dir
|
|
let ModelRotateWorker
|
|
let AnimObjectArray
|
|
let ModelMotionAttributeWorker
|
|
let RotationValue
|
|
let RotateSpeed
|
|
let Direction = 1
|
|
|
|
onmessage = function (e) {
|
|
ObjectNames = e.data.ObjectNames
|
|
Values = e.data.Values
|
|
Dir = e.data.Dir
|
|
ModelRotateWorker = e.data.ModelRotateWorker
|
|
RotationValue = e.data.RotationValue
|
|
RotateSpeed = e.data.RotateSpeed
|
|
modelRotationWorker(e.data.ObjectNames, e.data.Dir, e.data.Values, e.data.RotationValue)
|
|
}
|
|
|
|
function modelRotationWorker(objectNames, Dir, Values, rotationValue) {
|
|
|
|
let m = ModelRotateWorker
|
|
Dir = parseInt(Dir)
|
|
|
|
if (m.state === Dir) return
|
|
if (Dir === 0) {
|
|
m.doAnimation = false
|
|
m.state = 0
|
|
self.close();
|
|
clearInterval(m.myVarSetInterval)
|
|
} else {
|
|
clearInterval(m.myVarSetInterval)
|
|
m.state = Dir
|
|
if (Dir === 1) {
|
|
Direction = Values / Math.abs(Values)
|
|
m.doAnimation = true
|
|
m.myVarSetInterval = setInterval(()=> {
|
|
if(m.state === 1){
|
|
rotationValue += RotateSpeed * Direction
|
|
self.postMessage({
|
|
objectNames: objectNames,
|
|
rotation: rotationValue
|
|
})
|
|
} else {
|
|
clearInterval(m.myVarSetInterval)
|
|
// Worker 线程结束
|
|
self.close();
|
|
m.doAnimation = false
|
|
}
|
|
},500 / (3 * Math.abs(Values)))
|
|
}
|
|
}
|
|
}
|