polygonjs-engine
Version:
node-based webgl 3D engine https://polygonjs.com
179 lines (167 loc) • 5.68 kB
text/typescript
import {ParamInitValuesTypeMap} from '../../../../params/types/ParamInitValuesTypeMap';
import {ParamType} from '../../../../poly/ParamType';
export enum JsConnectionPointType {
BOOL = 'bool',
INT = 'int',
FLOAT = 'float',
VEC2 = 'vec2',
VEC3 = 'vec3',
VEC4 = 'vec4',
// MAT3 = 'mat3',
// MAT4 = 'mat4',
}
//
//
// ALL GL Data types in an array
//
//
export const JS_CONNECTION_POINT_TYPES: Array<JsConnectionPointType> = [
JsConnectionPointType.BOOL,
JsConnectionPointType.INT,
JsConnectionPointType.FLOAT,
JsConnectionPointType.VEC2,
JsConnectionPointType.VEC3,
JsConnectionPointType.VEC4,
// JsConnectionPointType.MAT3,
// JsConnectionPointType.MAT4,
];
//
//
// Map to convert from a Js Data type to a ParamType
//
//
type ConnectionPointTypeToParamTypeMapGeneric = {[key in JsConnectionPointType]: ParamType | undefined};
export interface IConnectionPointTypeToParamTypeMap extends ConnectionPointTypeToParamTypeMapGeneric {
[]: ParamType.BOOLEAN;
[]: ParamType.INTEGER;
[]: ParamType.FLOAT;
[]: ParamType.VECTOR2;
[]: ParamType.VECTOR3;
[]: ParamType.VECTOR4;
// [JsConnectionPointType.MAT3]: undefined;
// [JsConnectionPointType.MAT4]: undefined;
}
export const JsConnectionPointTypeToParamTypeMap: IConnectionPointTypeToParamTypeMap = {
[]: ParamType.BOOLEAN,
[]: ParamType.INTEGER,
[]: ParamType.FLOAT,
[]: ParamType.VECTOR2,
[]: ParamType.VECTOR3,
[]: ParamType.VECTOR4,
// [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.BOOL;
[]: JsConnectionPointType.VEC3;
[]: JsConnectionPointType.INT;
[]: JsConnectionPointType.FLOAT;
[]: undefined;
[]: JsConnectionPointType.VEC2;
[]: JsConnectionPointType.VEC3;
[]: JsConnectionPointType.VEC4;
[]: undefined;
[]: undefined;
[]: undefined;
[]: undefined;
[]: undefined;
[]: undefined;
[]: undefined;
}
export const JsParamTypeToConnectionPointTypeMap: IJsParamTypeToConnectionPointTypeMap = {
[]: JsConnectionPointType.BOOL,
[]: JsConnectionPointType.VEC3,
[]: JsConnectionPointType.INT,
[]: JsConnectionPointType.FLOAT,
[]: undefined,
[]: JsConnectionPointType.VEC2,
[]: JsConnectionPointType.VEC3,
[]: JsConnectionPointType.VEC4,
[]: undefined,
[]: undefined,
[]: undefined,
[]: undefined,
[]: undefined,
[]: undefined,
[]: undefined,
};
//
//
// Map of Js Data type default values
//
//
export type ConnectionPointInitValueMapGeneric = {
[]: ParamInitValuesTypeMap[IConnectionPointTypeToParamTypeMap[key]];
};
export const JsConnectionPointInitValueMap: ConnectionPointInitValueMapGeneric = {
[]: false,
[]: 0,
[]: 0,
[]: [0, 0],
[]: [0, 0, 0],
[]: [0, 0, 0, 0],
// [JsConnectionPointType.MAT3]: [0],
// [JsConnectionPointType.MAT4]: [0],
};
//
//
// Map of Js Data type component counts
//
//
export type ConnectionPointComponentsCountMapGeneric = {
[]: number;
};
export const GlConnectionPointComponentsCountMap: ConnectionPointComponentsCountMapGeneric = {
[]: 1,
[]: 1,
[]: 1,
[]: 2,
[]: 3,
[]: 4,
};
export interface JsConnectionPointData<T extends JsConnectionPointType> {
name: string;
type: T;
}
import {BaseConnectionPoint} from './_Base';
export class JsConnectionPoint<T extends JsConnectionPointType> extends BaseConnectionPoint {
protected _json: JsConnectionPointData<T> | undefined;
protected _init_value: any;
constructor(
protected _name: string,
protected _type: T // protected _init_value?: ConnectionPointInitValueMapGeneric[T]
) {
super(_name, _type);
// if (this._init_value === undefined) {
this._init_value = JsConnectionPointInitValueMap[this._type];
// }
}
type() {
return this._type;
}
are_types_matched(src_type: string, dest_type: string): boolean {
return src_type == dest_type;
}
get param_type(): IConnectionPointTypeToParamTypeMap[T] {
return JsConnectionPointTypeToParamTypeMap[this._type];
}
get init_value() {
return this._init_value;
}
toJSON(): JsConnectionPointData<T> {
return (this._json = this._json || this._create_json());
}
protected _create_json(): JsConnectionPointData<T> {
return {
name: this._name,
type: this._type,
};
}
}
export type BaseJsConnectionPoint = JsConnectionPoint<JsConnectionPointType>;