@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
835 lines (814 loc) • 36.9 kB
text/typescript
import {Plane} from '@jscad/modeling/src/maths/plane';
import {
AnimationAction,
AnimationMixer,
Box3,
Camera,
CatmullRomCurve3,
Color,
Matrix4,
Quaternion,
Vector2,
Vector3,
Vector4,
Intersection,
Material,
Object3D,
Ray,
Sphere,
Texture,
Euler,
} from 'three';
import {ParamInitValuesTypeMap} from '../../../../params/types/ParamInitValuesTypeMap';
import {ParamType} from '../../../../poly/ParamType';
import {BaseConnectionPoint} from './_Base';
import {BaseParamType} from '../../../../params/_Base';
import {BaseNodeType} from '../../../_Base';
export enum JsConnectionPointType {
ANIMATION_MIXER = 'AnimationMixer',
ANIMATION_ACTION = 'AnimationAction',
BOOLEAN = 'boolean',
BOOLEAN_ARRAY = 'boolean[]',
BOX3 = 'Box3',
CAMERA = 'Camera',
CATMULL_ROM_CURVE3 = 'CatmullRomCurve3',
COLOR = 'Color',
COLOR_ARRAY = 'Color[]',
EULER = 'Euler',
EULER_ARRAY = 'Euler[]',
FLOAT = 'float',
FLOAT_ARRAY = 'float[]',
INT = 'int',
INT_ARRAY = 'int[]',
INTERSECTION = 'Intersection',
INTERSECTION_ARRAY = 'Intersection[]',
MATERIAL = 'Material',
MATRIX4 = 'Matrix4',
MATRIX4_ARRAY = 'Matrix4[]',
NODE = 'Node',
OBJECT_3D = 'Object3D',
OBJECT_3D_ARRAY = 'Object3D[]',
PARAM = 'Param',
PLANE = 'Plane',
QUATERNION = 'Quaternion',
QUATERNION_ARRAY = 'Quaternion[]',
RAY = 'Ray',
SPHERE = 'Sphere',
STRING = 'string',
STRING_ARRAY = 'string[]',
TEXTURE = 'Texture',
TEXTURE_ARRAY = 'Texture[]',
TRIGGER = 'trigger',
VECTOR2 = 'Vector2',
VECTOR2_ARRAY = 'Vector2[]',
VECTOR3 = 'Vector3',
VECTOR3_ARRAY = 'Vector3[]',
VECTOR4 = 'Vector4',
VECTOR4_ARRAY = 'Vector4[]',
// MAT3 = 'mat3',
// MAT4 = 'mat4',
}
export type PrimitiveArrayElement = boolean | number | string;
export type VectorArrayElement = Color | Euler | Matrix4 | Quaternion | Vector2 | Vector3 | Vector4;
const NUMBER_JS_CONNECTION_TYPES = new Set([JsConnectionPointType.FLOAT, JsConnectionPointType.INT]);
const PRIMITIVE_JS_CONNECTION_TYPES = new Set([
JsConnectionPointType.BOOLEAN,
JsConnectionPointType.FLOAT,
JsConnectionPointType.INT,
JsConnectionPointType.STRING,
]);
const VECTOR_JS_CONNECTION_TYPES = new Set([
JsConnectionPointType.VECTOR2,
JsConnectionPointType.VECTOR3,
JsConnectionPointType.VECTOR4,
]);
export const JS_CONNECTION_TYPES_FOR_CONSTANT = [
JsConnectionPointType.BOOLEAN,
JsConnectionPointType.COLOR,
JsConnectionPointType.FLOAT,
JsConnectionPointType.INT,
JsConnectionPointType.STRING,
JsConnectionPointType.VECTOR2,
JsConnectionPointType.VECTOR3,
JsConnectionPointType.VECTOR4,
];
export function isJsConnectionPointNumber(type: JsConnectionPointType) {
return NUMBER_JS_CONNECTION_TYPES.has(type);
}
export function isJsConnectionPointPrimitive(type: JsConnectionPointType) {
return PRIMITIVE_JS_CONNECTION_TYPES.has(type);
}
export function isJsConnectionPointVector(type: JsConnectionPointType) {
return VECTOR_JS_CONNECTION_TYPES.has(type);
}
export function isJsConnectionPointArray(type: JsConnectionPointType) {
return ARRAY_JS_CONNECTION_TYPES_SET.has(type as JsConnectionPointTypeArray);
}
//
//
// ALL Js Data types in an array
//
//
export const JS_CONNECTION_POINT_TYPES: Array<JsConnectionPointType> = [
JsConnectionPointType.ANIMATION_MIXER,
JsConnectionPointType.ANIMATION_ACTION,
JsConnectionPointType.BOX3,
JsConnectionPointType.BOOLEAN,
JsConnectionPointType.BOOLEAN_ARRAY,
JsConnectionPointType.CAMERA,
JsConnectionPointType.CATMULL_ROM_CURVE3,
JsConnectionPointType.COLOR,
JsConnectionPointType.COLOR_ARRAY,
JsConnectionPointType.EULER,
JsConnectionPointType.EULER_ARRAY,
JsConnectionPointType.FLOAT,
JsConnectionPointType.FLOAT_ARRAY,
JsConnectionPointType.INT,
JsConnectionPointType.INT_ARRAY,
JsConnectionPointType.INTERSECTION,
JsConnectionPointType.INTERSECTION_ARRAY,
JsConnectionPointType.MATERIAL,
JsConnectionPointType.MATRIX4,
JsConnectionPointType.MATRIX4_ARRAY,
JsConnectionPointType.NODE,
JsConnectionPointType.OBJECT_3D,
JsConnectionPointType.OBJECT_3D_ARRAY,
JsConnectionPointType.PARAM,
JsConnectionPointType.PLANE,
JsConnectionPointType.QUATERNION,
JsConnectionPointType.QUATERNION_ARRAY,
JsConnectionPointType.RAY,
JsConnectionPointType.SPHERE,
JsConnectionPointType.STRING,
JsConnectionPointType.STRING_ARRAY,
JsConnectionPointType.TEXTURE,
JsConnectionPointType.TEXTURE_ARRAY,
JsConnectionPointType.TRIGGER,
JsConnectionPointType.VECTOR2,
JsConnectionPointType.VECTOR2_ARRAY,
JsConnectionPointType.VECTOR3,
JsConnectionPointType.VECTOR3_ARRAY,
JsConnectionPointType.VECTOR4,
JsConnectionPointType.VECTOR4_ARRAY,
// JsConnectionPointType.MAT3,
// JsConnectionPointType.MAT4,
];
type JsConnectionPointTypeToArrayTypeMapGeneric = {[key in JsConnectionPointType]: JsConnectionPointType};
export interface JsIConnectionPointTypeToArrayTypeMap extends JsConnectionPointTypeToArrayTypeMapGeneric {
[]: JsConnectionPointType.ANIMATION_MIXER;
[]: JsConnectionPointType.ANIMATION_ACTION;
[]: JsConnectionPointType.BOOLEAN_ARRAY;
[]: JsConnectionPointType.BOOLEAN_ARRAY;
[]: JsConnectionPointType.BOX3;
[]: JsConnectionPointType.CAMERA;
[]: JsConnectionPointType.CATMULL_ROM_CURVE3;
[]: JsConnectionPointType.COLOR_ARRAY;
[]: JsConnectionPointType.COLOR_ARRAY;
[]: JsConnectionPointType.EULER_ARRAY;
[]: JsConnectionPointType.EULER_ARRAY;
[]: JsConnectionPointType.FLOAT_ARRAY;
[]: JsConnectionPointType.FLOAT_ARRAY;
[]: JsConnectionPointType.INT_ARRAY;
[]: JsConnectionPointType.INT_ARRAY;
[]: JsConnectionPointType.INTERSECTION_ARRAY;
[]: JsConnectionPointType.INTERSECTION_ARRAY;
[]: JsConnectionPointType.MATERIAL; //
[]: JsConnectionPointType.MATRIX4_ARRAY; //
[]: JsConnectionPointType.MATRIX4_ARRAY; //
[]: JsConnectionPointType.NODE; //
[]: JsConnectionPointType.OBJECT_3D_ARRAY; //
[]: JsConnectionPointType.OBJECT_3D_ARRAY; //
[]: JsConnectionPointType.PARAM; //
[]: JsConnectionPointType.PLANE; //
[]: JsConnectionPointType.QUATERNION_ARRAY; //
[]: JsConnectionPointType.QUATERNION_ARRAY; //
[]: JsConnectionPointType.RAY; //
[]: JsConnectionPointType.SPHERE; //
[]: JsConnectionPointType.STRING_ARRAY;
[]: JsConnectionPointType.STRING_ARRAY;
[]: JsConnectionPointType.TEXTURE_ARRAY;
[]: JsConnectionPointType.TEXTURE_ARRAY;
[]: JsConnectionPointType.TRIGGER;
[]: JsConnectionPointType.VECTOR2_ARRAY;
[]: JsConnectionPointType.VECTOR2_ARRAY;
[]: JsConnectionPointType.VECTOR3_ARRAY;
[]: JsConnectionPointType.VECTOR3_ARRAY;
[]: JsConnectionPointType.VECTOR4_ARRAY;
[]: JsConnectionPointType.VECTOR4_ARRAY;
}
export const JsConnectionPointTypeToArrayTypeMap: JsIConnectionPointTypeToArrayTypeMap = {
[]: JsConnectionPointType.ANIMATION_MIXER,
[]: JsConnectionPointType.ANIMATION_ACTION,
[]: JsConnectionPointType.BOOLEAN_ARRAY,
[]: JsConnectionPointType.BOOLEAN_ARRAY,
[]: JsConnectionPointType.BOX3,
[]: JsConnectionPointType.CAMERA,
[]: JsConnectionPointType.CATMULL_ROM_CURVE3,
[]: JsConnectionPointType.COLOR_ARRAY,
[]: JsConnectionPointType.COLOR_ARRAY,
[]: JsConnectionPointType.EULER_ARRAY,
[]: JsConnectionPointType.EULER_ARRAY,
[]: JsConnectionPointType.FLOAT_ARRAY,
[]: JsConnectionPointType.FLOAT_ARRAY,
[]: JsConnectionPointType.INT_ARRAY,
[]: JsConnectionPointType.INT_ARRAY,
[]: JsConnectionPointType.INTERSECTION_ARRAY,
[]: JsConnectionPointType.INTERSECTION_ARRAY,
[]: JsConnectionPointType.MATERIAL,
[]: JsConnectionPointType.MATRIX4_ARRAY,
[]: JsConnectionPointType.MATRIX4_ARRAY,
[]: JsConnectionPointType.NODE,
[]: JsConnectionPointType.OBJECT_3D_ARRAY,
[]: JsConnectionPointType.OBJECT_3D_ARRAY,
[]: JsConnectionPointType.PARAM,
[]: JsConnectionPointType.PLANE,
[]: JsConnectionPointType.QUATERNION_ARRAY,
[]: JsConnectionPointType.QUATERNION_ARRAY,
[]: JsConnectionPointType.RAY,
[]: JsConnectionPointType.SPHERE, //
[]: JsConnectionPointType.STRING_ARRAY,
[]: JsConnectionPointType.STRING_ARRAY,
[]: JsConnectionPointType.TEXTURE_ARRAY,
[]: JsConnectionPointType.TEXTURE_ARRAY,
// [ActorConnectionPointType.TRACKING_RESULT_HAND]: ActorConnectionPointType.TRACKING_RESULT_HAND,
[]: JsConnectionPointType.TRIGGER,
[]: JsConnectionPointType.VECTOR2_ARRAY,
[]: JsConnectionPointType.VECTOR2_ARRAY,
[]: JsConnectionPointType.VECTOR3_ARRAY,
[]: JsConnectionPointType.VECTOR3_ARRAY,
[]: JsConnectionPointType.VECTOR4_ARRAY,
[]: JsConnectionPointType.VECTOR4_ARRAY,
};
type JsConnectionPointTypeFromArrayTypeMapGeneric = {[key in JsConnectionPointType]: JsConnectionPointType};
export interface JsIConnectionPointTypeFromArrayTypeMap extends JsConnectionPointTypeFromArrayTypeMapGeneric {
[]: JsConnectionPointType.ANIMATION_MIXER;
[]: JsConnectionPointType.ANIMATION_ACTION;
[]: JsConnectionPointType.BOOLEAN;
[]: JsConnectionPointType.BOOLEAN;
[]: JsConnectionPointType.BOX3;
[]: JsConnectionPointType.CAMERA;
[]: JsConnectionPointType.CATMULL_ROM_CURVE3;
[]: JsConnectionPointType.COLOR;
[]: JsConnectionPointType.COLOR;
[]: JsConnectionPointType.EULER;
[]: JsConnectionPointType.EULER;
[]: JsConnectionPointType.FLOAT;
[]: JsConnectionPointType.FLOAT;
[]: JsConnectionPointType.INT;
[]: JsConnectionPointType.INT;
[]: JsConnectionPointType.INTERSECTION;
[]: JsConnectionPointType.INTERSECTION;
[]: JsConnectionPointType.MATERIAL; //
[]: JsConnectionPointType.MATRIX4; //
[]: JsConnectionPointType.MATRIX4; //
[]: JsConnectionPointType.NODE; //
[]: JsConnectionPointType.OBJECT_3D; //
[]: JsConnectionPointType.OBJECT_3D; //
[]: JsConnectionPointType.PARAM; //
[]: JsConnectionPointType.PLANE; //
[]: JsConnectionPointType.QUATERNION; //
[]: JsConnectionPointType.QUATERNION; //
[]: JsConnectionPointType.RAY; //
[]: JsConnectionPointType.SPHERE; //
[]: JsConnectionPointType.STRING;
[]: JsConnectionPointType.STRING;
[]: JsConnectionPointType.TEXTURE;
[]: JsConnectionPointType.TEXTURE;
[]: JsConnectionPointType.TRIGGER;
[]: JsConnectionPointType.VECTOR2;
[]: JsConnectionPointType.VECTOR2;
[]: JsConnectionPointType.VECTOR3;
[]: JsConnectionPointType.VECTOR3;
[]: JsConnectionPointType.VECTOR4;
[]: JsConnectionPointType.VECTOR4;
}
export const JsConnectionPointTypeFromArrayTypeMap: JsIConnectionPointTypeFromArrayTypeMap = {
[]: JsConnectionPointType.ANIMATION_MIXER,
[]: JsConnectionPointType.ANIMATION_ACTION,
[]: JsConnectionPointType.BOOLEAN,
[]: JsConnectionPointType.BOOLEAN,
[]: JsConnectionPointType.BOX3,
[]: JsConnectionPointType.CAMERA,
[]: JsConnectionPointType.CATMULL_ROM_CURVE3,
[]: JsConnectionPointType.COLOR,
[]: JsConnectionPointType.COLOR,
[]: JsConnectionPointType.EULER,
[]: JsConnectionPointType.EULER,
[]: JsConnectionPointType.FLOAT,
[]: JsConnectionPointType.FLOAT,
[]: JsConnectionPointType.INT,
[]: JsConnectionPointType.INT,
[]: JsConnectionPointType.INTERSECTION,
[]: JsConnectionPointType.INTERSECTION,
[]: JsConnectionPointType.MATERIAL,
[]: JsConnectionPointType.MATRIX4,
[]: JsConnectionPointType.MATRIX4,
[]: JsConnectionPointType.NODE,
[]: JsConnectionPointType.OBJECT_3D,
[]: JsConnectionPointType.OBJECT_3D,
[]: JsConnectionPointType.PARAM,
[]: JsConnectionPointType.PLANE,
[]: JsConnectionPointType.QUATERNION,
[]: JsConnectionPointType.QUATERNION,
[]: JsConnectionPointType.RAY,
[]: JsConnectionPointType.SPHERE, //
[]: JsConnectionPointType.STRING,
[]: JsConnectionPointType.STRING,
[]: JsConnectionPointType.TEXTURE,
[]: JsConnectionPointType.TEXTURE,
// [ActorConnectionPointType.TRACKING_RESULT_HAND]: ActorConnectionPointType.TRACKING_RESULT_HAND,
[]: JsConnectionPointType.TRIGGER,
[]: JsConnectionPointType.VECTOR2,
[]: JsConnectionPointType.VECTOR2,
[]: JsConnectionPointType.VECTOR3,
[]: JsConnectionPointType.VECTOR3,
[]: JsConnectionPointType.VECTOR4,
[]: JsConnectionPointType.VECTOR4,
};
export type ArrayableConnectionPointType =
| JsConnectionPointType.BOOLEAN
| JsConnectionPointType.COLOR
| JsConnectionPointType.FLOAT
| JsConnectionPointType.INT
| JsConnectionPointType.INTERSECTION
| JsConnectionPointType.MATRIX4
| JsConnectionPointType.QUATERNION
| JsConnectionPointType.STRING
| JsConnectionPointType.TEXTURE
| JsConnectionPointType.VECTOR2
| JsConnectionPointType.VECTOR3
| JsConnectionPointType.VECTOR4;
export const ARRAYABLE_CONNECTION_TYPES: Set<ArrayableConnectionPointType> = new Set([
JsConnectionPointType.BOOLEAN,
JsConnectionPointType.COLOR,
JsConnectionPointType.FLOAT,
JsConnectionPointType.INT,
JsConnectionPointType.INTERSECTION,
JsConnectionPointType.MATRIX4,
JsConnectionPointType.QUATERNION,
JsConnectionPointType.STRING,
JsConnectionPointType.TEXTURE,
JsConnectionPointType.VECTOR2,
JsConnectionPointType.VECTOR3,
JsConnectionPointType.VECTOR4,
]);
export type JsConnectionPointTypeArray =
| JsConnectionPointType.BOOLEAN_ARRAY
| JsConnectionPointType.COLOR_ARRAY
| JsConnectionPointType.FLOAT_ARRAY
| JsConnectionPointType.INT_ARRAY
| JsConnectionPointType.INTERSECTION_ARRAY
| JsConnectionPointType.MATRIX4_ARRAY
| JsConnectionPointType.OBJECT_3D_ARRAY
| JsConnectionPointType.QUATERNION_ARRAY
| JsConnectionPointType.STRING_ARRAY
| JsConnectionPointType.TEXTURE_ARRAY
| JsConnectionPointType.VECTOR2_ARRAY
| JsConnectionPointType.VECTOR3_ARRAY
| JsConnectionPointType.VECTOR4_ARRAY;
export const ARRAY_JS_CONNECTION_TYPES: Array<JsConnectionPointTypeArray> = [
JsConnectionPointType.BOOLEAN_ARRAY,
JsConnectionPointType.COLOR_ARRAY,
JsConnectionPointType.FLOAT_ARRAY,
JsConnectionPointType.INT_ARRAY,
JsConnectionPointType.INTERSECTION_ARRAY,
JsConnectionPointType.MATRIX4_ARRAY,
JsConnectionPointType.OBJECT_3D_ARRAY,
JsConnectionPointType.QUATERNION_ARRAY,
JsConnectionPointType.STRING_ARRAY,
JsConnectionPointType.TEXTURE_ARRAY,
JsConnectionPointType.VECTOR2_ARRAY,
JsConnectionPointType.VECTOR3_ARRAY,
JsConnectionPointType.VECTOR4_ARRAY,
];
export const ARRAY_JS_CONNECTION_TYPES_SET: Set<JsConnectionPointTypeArray> = new Set(ARRAY_JS_CONNECTION_TYPES);
export type ParamConvertibleJsType =
| JsConnectionPointType.BOOLEAN
| JsConnectionPointType.COLOR
| JsConnectionPointType.FLOAT
| JsConnectionPointType.INT
| JsConnectionPointType.STRING
| JsConnectionPointType.VECTOR2
| JsConnectionPointType.VECTOR3
| JsConnectionPointType.VECTOR4;
export const PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES: Array<ParamConvertibleJsType> = [
JsConnectionPointType.BOOLEAN,
JsConnectionPointType.COLOR,
JsConnectionPointType.FLOAT,
JsConnectionPointType.INT,
JsConnectionPointType.STRING,
JsConnectionPointType.VECTOR2,
JsConnectionPointType.VECTOR3,
JsConnectionPointType.VECTOR4,
];
export type PointAttributeJsType =
| JsConnectionPointType.COLOR
| JsConnectionPointType.FLOAT
| JsConnectionPointType.INT
| JsConnectionPointType.VECTOR2
| JsConnectionPointType.VECTOR3
| JsConnectionPointType.VECTOR4;
export const POINT_ATTRIBUTE_JS_CONNECTION_POINT_TYPES: Array<PointAttributeJsType> = [
JsConnectionPointType.COLOR,
JsConnectionPointType.FLOAT,
JsConnectionPointType.INT,
JsConnectionPointType.VECTOR2,
JsConnectionPointType.VECTOR3,
JsConnectionPointType.VECTOR4,
];
//
//
// GET DATA TYPE
//
//
export type JsDataType =
| PrimitiveArrayElement
| Array<PrimitiveArrayElement>
| VectorArrayElement
| Array<VectorArrayElement>
| AnimationMixer
| AnimationAction
| Box3
| Camera
| CatmullRomCurve3
| Euler
| Euler[]
| Intersection
| Array<Intersection>
| Material
| Object3D
| Array<Object3D>
| Ray
| Sphere
| Texture
| Array<Texture>
| BaseNodeType
| BaseParamType
| null;
type JSConnectionPointTypeToDataTypeMapGeneric = {[key in JsConnectionPointType]: JsDataType};
export interface JsIConnectionPointTypeToDataTypeMap extends JSConnectionPointTypeToDataTypeMapGeneric {
[]: AnimationMixer;
[]: AnimationAction;
[]: boolean;
[]: boolean[];
[]: Box3;
[]: Camera;
[]: CatmullRomCurve3;
[]: Color;
[]: Color[];
[]: Euler;
[]: Euler[];
[]: number;
[]: number[];
[]: number;
[]: number[];
[]: Intersection;
[]: Intersection[];
[]: Material;
[]: Matrix4;
[]: Matrix4[];
[]: BaseNodeType;
[]: Object3D;
[]: Object3D[];
[]: BaseParamType;
[]: Plane;
[]: Quaternion;
[]: Quaternion[];
[]: Ray;
[]: Sphere;
[]: string;
[]: string[];
[]: Texture;
[]: Texture[];
[]: null;
[]: Vector2;
[]: Vector2[];
[]: Vector3;
[]: Vector3[];
[]: Vector4;
[]: Vector4[];
}
// export const JsConnectionPointTypeToParamTypeMap: JsIConnectionPointTypeToDataTypeMap = {
// [JsConnectionPointType.ANIMATION_MIXER]: AnimationMixer;
// [JsConnectionPointType.ANIMATION_ACTION]: AnimationAction;
// [JsConnectionPointType.BOOLEAN]: boolean,
// [JsConnectionPointType.BOOLEAN_ARRAY]: boolean[],
// [JsConnectionPointType.BOX3]: Box3,
// [JsConnectionPointType.CAMERA]: Camera,
// [JsConnectionPointType.CATMULL_ROM_CURVE3]: ParamType.BUTTON,
// [JsConnectionPointType.COLOR]: ParamType.COLOR,
// [JsConnectionPointType.COLOR_ARRAY]: ParamType.BUTTON,
// [JsConnectionPointType.FLOAT]: ParamType.FLOAT,
// [JsConnectionPointType.FLOAT_ARRAY]: ParamType.BUTTON,
// [JsConnectionPointType.INT]: ParamType.INTEGER,
// [JsConnectionPointType.INT_ARRAY]: ParamType.BUTTON,
// [JsConnectionPointType.INTERSECTION]: ParamType.BUTTON,
// [JsConnectionPointType.INTERSECTION_ARRAY]: ParamType.BUTTON,
// [JsConnectionPointType.MATERIAL]: ParamType.BUTTON,
// [JsConnectionPointType.MATRIX4]: ParamType.BUTTON,
// [JsConnectionPointType.MATRIX4_ARRAY]: ParamType.BUTTON,
// [JsConnectionPointType.OBJECT_3D]: ParamType.BUTTON,
// [JsConnectionPointType.PLANE]: ParamType.BUTTON,
// [JsConnectionPointType.QUATERNION]: ParamType.BUTTON,
// [JsConnectionPointType.QUATERNION_ARRAY]: ParamType.BUTTON,
// [JsConnectionPointType.RAY]: ParamType.BUTTON,
// [JsConnectionPointType.SPHERE]: ParamType.BUTTON,
// [JsConnectionPointType.STRING]: ParamType.STRING,
// [JsConnectionPointType.STRING_ARRAY]: ParamType.BUTTON,
// [JsConnectionPointType.TEXTURE]: ParamType.BUTTON,
// [JsConnectionPointType.TEXTURE_ARRAY]: ParamType.BUTTON,
// [JsConnectionPointType.TRIGGER]: ParamType.BUTTON,
// [JsConnectionPointType.VECTOR2]: ParamType.VECTOR2,
// [JsConnectionPointType.VECTOR2_ARRAY]: ParamType.BUTTON,
// [JsConnectionPointType.VECTOR3]: ParamType.VECTOR3,
// [JsConnectionPointType.VECTOR3_ARRAY]: ParamType.BUTTON,
// [JsConnectionPointType.VECTOR4]: ParamType.VECTOR4,
// [JsConnectionPointType.VECTOR4_ARRAY]: ParamType.BUTTON,
// // [JsConnectionPointType.MAT3]: undefined,
// // [JsConnectionPointType.MAT4]: undefined,
// };
//
//
// Map to convert from a Js Data type to a ParamType
//
//
type JSConnectionPointTypeToParamTypeMapGeneric = {[key in JsConnectionPointType]: ParamType | undefined};
export interface JsIConnectionPointTypeToParamTypeMap extends JSConnectionPointTypeToParamTypeMapGeneric {
[]: ParamType.BUTTON;
[]: ParamType.BUTTON;
[]: ParamType.BOOLEAN;
[]: ParamType.BUTTON;
[]: ParamType.BUTTON;
[]: ParamType.BUTTON;
[]: ParamType.BUTTON;
[]: ParamType.COLOR;
[]: ParamType.BUTTON;
[]: ParamType.BUTTON;
[]: ParamType.BUTTON;
[]: ParamType.FLOAT;
[]: ParamType.BUTTON;
[]: ParamType.INTEGER;
[]: ParamType.BUTTON;
[]: ParamType.BUTTON;
[]: ParamType.BUTTON;
[]: ParamType.BUTTON;
[]: ParamType.BUTTON;
[]: ParamType.BUTTON;
[]: ParamType.NODE_PATH;
[]: ParamType.BUTTON;
[]: ParamType.BUTTON;
[]: ParamType.PARAM_PATH;
[]: ParamType.BUTTON;
[]: ParamType.BUTTON;
[]: ParamType.BUTTON;
[]: ParamType.BUTTON;
[]: ParamType.BUTTON;
[]: ParamType.STRING;
[]: ParamType.BUTTON;
[]: ParamType.BUTTON;
[]: ParamType.BUTTON;
[]: ParamType.BUTTON;
[]: ParamType.VECTOR2;
[]: ParamType.BUTTON;
[]: ParamType.VECTOR3;
[]: ParamType.BUTTON;
[]: ParamType.VECTOR4;
[]: ParamType.BUTTON;
// [JsConnectionPointType.MAT3]: undefined;
// [JsConnectionPointType.MAT4]: undefined;
}
export const JsConnectionPointTypeToParamTypeMap: JsIConnectionPointTypeToParamTypeMap = {
[]: ParamType.BUTTON,
[]: ParamType.BUTTON,
[]: ParamType.BOOLEAN,
[]: ParamType.BUTTON,
[]: ParamType.BUTTON,
[]: ParamType.BUTTON,
[]: ParamType.BUTTON,
[]: ParamType.COLOR,
[]: ParamType.BUTTON,
[]: ParamType.BUTTON,
[]: ParamType.BUTTON,
[]: ParamType.FLOAT,
[]: ParamType.BUTTON,
[]: ParamType.INTEGER,
[]: ParamType.BUTTON,
[]: ParamType.BUTTON,
[]: ParamType.BUTTON,
[]: ParamType.BUTTON,
[]: ParamType.BUTTON,
[]: ParamType.BUTTON,
[]: ParamType.NODE_PATH,
[]: ParamType.BUTTON,
[]: ParamType.BUTTON,
[]: ParamType.PARAM_PATH,
[]: ParamType.BUTTON,
[]: ParamType.BUTTON,
[]: ParamType.BUTTON,
[]: ParamType.BUTTON,
[]: ParamType.BUTTON,
[]: ParamType.STRING,
[]: ParamType.BUTTON,
[]: ParamType.BUTTON,
[]: ParamType.BUTTON,
[]: ParamType.BUTTON,
[]: ParamType.VECTOR2,
[]: ParamType.BUTTON,
[]: ParamType.VECTOR3,
[]: ParamType.BUTTON,
[]: ParamType.VECTOR4,
[]: ParamType.BUTTON,
// [JsConnectionPointType.MAT3]: undefined,
// [JsConnectionPointType.MAT4]: undefined,
};
//
//
// Map to convert from a ParamType to GL Data type
//
//
type JsParamTypeToConnectionPointTypeMapGeneric = {[key in ParamType]: JsConnectionPointType | undefined};
export interface IJsParamTypeToConnectionPointTypeMap extends JsParamTypeToConnectionPointTypeMapGeneric {
[]: JsConnectionPointType.BOOLEAN;
[]: JsConnectionPointType.COLOR;
[]: JsConnectionPointType.FLOAT;
[]: JsConnectionPointType.INT;
[]: undefined;
[]: JsConnectionPointType.VECTOR2;
[]: JsConnectionPointType.VECTOR3;
[]: JsConnectionPointType.VECTOR4;
[]: undefined;
[]: JsConnectionPointType.NODE;
[]: JsConnectionPointType.PARAM;
[]: undefined;
[]: JsConnectionPointType.STRING;
}
export const JsParamTypeToConnectionPointTypeMap: IJsParamTypeToConnectionPointTypeMap = {
[]: JsConnectionPointType.BOOLEAN,
[]: JsConnectionPointType.COLOR,
[]: JsConnectionPointType.FLOAT,
[]: JsConnectionPointType.INT,
[]: undefined,
[]: JsConnectionPointType.VECTOR2,
[]: JsConnectionPointType.VECTOR3,
[]: JsConnectionPointType.VECTOR4,
[]: undefined,
[]: JsConnectionPointType.NODE,
[]: JsConnectionPointType.PARAM,
[]: undefined,
[]: JsConnectionPointType.STRING,
};
//
//
// Map of Js Data type default values
//
//
export type ConnectionPointInitValueMapGeneric = {
[]: ParamInitValuesTypeMap[JsIConnectionPointTypeToParamTypeMap[key]];
};
export const JsConnectionPointInitValueMap: ConnectionPointInitValueMapGeneric = {
[]: null,
[]: null,
[]: false,
[]: null,
[]: null,
[]: null,
[]: null,
[]: [1, 1, 1],
[]: null,
[]: null,
[]: null,
[]: 0,
[]: null,
[]: 0,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: '',
[]: null,
[]: null,
[]: '',
[]: null,
[]: null,
[]: null,
[]: null,
[]: null,
[]: '',
[]: null,
[]: null,
[]: null,
[]: null,
[]: [0, 0],
[]: null,
[]: [0, 0, 0],
[]: null,
[]: [0, 0, 0, 0],
[]: null,
// [JsConnectionPointType.MAT3]: [0],
// [JsConnectionPointType.MAT4]: [0],
};
//
//
// Map of Js Data type component counts
//
//
export type ConnectionPointComponentsCountMapGeneric = {
[]: number;
};
export const JsConnectionPointComponentsCountMap: ConnectionPointComponentsCountMapGeneric = {
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 3,
[]: 1,
[]: 3,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 1,
[]: 2,
[]: 1,
[]: 3,
[]: 1,
[]: 4,
[]: 1,
};
export interface JsConnectionPointData<T extends JsConnectionPointType> {
name: string;
type: T;
isArray?: boolean;
}
interface JsConnectionPointOptions<T extends JsConnectionPointType> {
inNodeDefinition?: boolean;
init_value?: ConnectionPointInitValueMapGeneric[T];
}
export const JS_CONNECTION_POINT_IN_NODE_DEF: JsConnectionPointOptions<JsConnectionPointType> = {
inNodeDefinition: true,
};
export class JsConnectionPoint<T extends JsConnectionPointType> extends BaseConnectionPoint {
protected override _json: JsConnectionPointData<T> | undefined;
protected override _init_value?: ConnectionPointInitValueMapGeneric[T];
protected _isArray: boolean;
constructor(_name: string, protected override _type: T, protected _options?: JsConnectionPointOptions<T>) {
super(_name, _type);
// if (this._init_value === undefined) {
this._isArray = ARRAY_JS_CONNECTION_TYPES_SET.has(_type as JsConnectionPointTypeArray);
this._init_value = JsConnectionPointInitValueMap[this._type];
// }
if (_options) {
this._inNodeDefinition = _options.inNodeDefinition == true;
if (_options.init_value != null) {
this._init_value = _options.init_value;
}
}
}
override type() {
return this._type;
}
override are_types_matched(src_type: string, dest_type: string): boolean {
return src_type == dest_type;
}
get param_type(): JsIConnectionPointTypeToParamTypeMap[T] {
return JsConnectionPointTypeToParamTypeMap[this._type];
}
override get init_value() {
return this._init_value;
}
override toJSON(): JsConnectionPointData<T> {
return (this._json = this._json || this._createJSON());
}
protected override _createJSON(): JsConnectionPointData<T> {
return {
name: this._name,
type: this._type,
isArray: this._isArray,
};
}
}
export type BaseJsConnectionPoint = JsConnectionPoint<JsConnectionPointType>;