@threlte/theatre
Version:
Threlte Components for Theatre, an animation library with a professional motion design toolset
41 lines (40 loc) • 1.7 kB
JavaScript
import { color } from './defaults/color.js';
import { degrees } from './defaults/degrees.js';
import { euler } from './defaults/euler.js';
import { generic } from './defaults/generic.js';
import { normalized } from './defaults/normalized.js';
import { side } from './defaults/side.js';
const isFullOrEndingPattern = (fullPropertyPath, pattern) => {
return fullPropertyPath.endsWith(`.${pattern}`) || fullPropertyPath === pattern;
};
export const getDefaultTransformer = (target, path, fullPropertyPath) => {
const property = target[path];
if (property.isEuler)
return euler;
if (property.isColor)
return color;
if (isFullOrEndingPattern(fullPropertyPath, 'rotation.x') ||
isFullOrEndingPattern(fullPropertyPath, 'rotation.y') ||
isFullOrEndingPattern(fullPropertyPath, 'rotation.z') ||
(target.isEuler &&
(fullPropertyPath === 'x' || fullPropertyPath === 'y' || fullPropertyPath === 'z'))) {
return degrees;
}
if (isFullOrEndingPattern(fullPropertyPath, 'r'))
return normalized;
if (isFullOrEndingPattern(fullPropertyPath, 'g'))
return normalized;
if (isFullOrEndingPattern(fullPropertyPath, 'b'))
return normalized;
if (isFullOrEndingPattern(fullPropertyPath, 'opacity'))
return normalized;
if (isFullOrEndingPattern(fullPropertyPath, 'roughness'))
return normalized;
if (isFullOrEndingPattern(fullPropertyPath, 'metalness'))
return normalized;
if (isFullOrEndingPattern(fullPropertyPath, 'transmission'))
return normalized;
if (isFullOrEndingPattern(fullPropertyPath, 'side'))
return side;
return generic;
};