@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
69 lines (61 loc) • 2.02 kB
text/typescript
/**
* computes a quaternion
*
*
*
*/
import {Number3} from '../../../types/GlobalTypes';
import {BaseNodeGlMathFunctionArg2GlNode} from './_BaseMathFunction';
import Quaternion from './gl/quaternion.glsl';
import {GlConnectionPointType} from '../utils/io/connections/Gl';
import {FunctionGLDefinition} from './utils/GLDefinition';
enum QuatFromAxisAngleGlNodeInputName {
AXIS = 'axis',
ANGLE = 'angle',
}
const InputNames: Array<QuatFromAxisAngleGlNodeInputName> = [
QuatFromAxisAngleGlNodeInputName.AXIS,
QuatFromAxisAngleGlNodeInputName.ANGLE,
];
interface IDefaultValues {
[QuatFromAxisAngleGlNodeInputName.AXIS]: Number3;
[QuatFromAxisAngleGlNodeInputName.ANGLE]: number;
}
const DEFAULT_AXIS: Number3 = [0, 0, 1];
const DEFAULT_ANGLE: number = 0;
const DefaultValues: IDefaultValues = {
[QuatFromAxisAngleGlNodeInputName.AXIS]: DEFAULT_AXIS,
[QuatFromAxisAngleGlNodeInputName.ANGLE]: DEFAULT_ANGLE,
};
export class QuatFromAxisAngleGlNode extends BaseNodeGlMathFunctionArg2GlNode {
static override type() {
return 'quatFromAxisAngle';
}
override initializeNode() {
super.initializeNode();
this.io.connection_points.set_input_name_function((index: number) => InputNames[index]);
this.io.connection_points.set_expected_input_types_function(() => [
GlConnectionPointType.VEC3,
GlConnectionPointType.FLOAT,
]);
this.io.connection_points.set_expected_output_types_function(() => [GlConnectionPointType.VEC4]);
}
// protected _gl_input_name(index: number) {
// return InputNames[index];
// }
override paramDefaultValue(name: string) {
return DefaultValues[name as QuatFromAxisAngleGlNodeInputName];
}
override gl_method_name(): string {
return 'quatFromAxisAngle';
}
// protected _expected_input_types() {
// return [ConnectionPointType.VEC3, ConnectionPointType.FLOAT];
// }
// protected expected_output_types() {
// return [ConnectionPointType.VEC4];
// }
override gl_function_definitions() {
return [new FunctionGLDefinition(this, Quaternion)];
}
}