1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 12:22:03 +08:00
trois/src/tools.js

34 lines
813 B
JavaScript
Raw Normal View History

2020-09-14 22:57:11 +08:00
export function setFromProp(o, prop) {
if (prop instanceof Object) {
2020-09-17 16:57:13 +08:00
Object.entries(prop).forEach(([key, value]) => {
2020-09-14 22:57:11 +08:00
o[key] = value;
2020-09-17 16:57:13 +08:00
});
2020-09-14 22:57:11 +08:00
}
};
2020-09-16 21:30:39 +08:00
2020-10-02 00:22:01 +08:00
export function propsValues(props, exclude) {
const values = {};
Object.entries(props).forEach(([key, value]) => {
if (!exclude || (exclude && !exclude.includes(key))) {
values[key] = value;
}
});
return values;
};
2020-09-16 21:30:39 +08:00
export function lerp(value1, value2, amount) {
amount = amount < 0 ? 0 : amount;
amount = amount > 1 ? 1 : amount;
return value1 + (value2 - value1) * amount;
};
2020-09-17 03:11:45 +08:00
export function lerpv3(v1, v2, amount) {
v1.x = lerp(v1.x, v2.x, amount);
v1.y = lerp(v1.y, v2.y, amount);
v1.z = lerp(v1.z, v2.z, amount);
};
2020-09-29 03:03:35 +08:00
export function limit(val, min, max) {
return val < min ? min : (val > max ? max : val);
};