UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

57 lines (56 loc) 1.67 kB
"use strict"; import { JsConnectionPointType } from "../nodes/utils/io/connections/Js"; import { clamp as _clamp } from "../../core/math/_Module"; const RGB = ["r", "g", "b"]; const XY = ["x", "y"]; const XYZ = ["x", "y", "z"]; const XYZW = ["x", "y", "z", "w"]; const COMPONENT_BY_JS_TYPE = { [JsConnectionPointType.COLOR]: RGB, [JsConnectionPointType.VECTOR2]: XY, [JsConnectionPointType.VECTOR3]: XYZ, [JsConnectionPointType.VECTOR4]: XYZW }; export function componentsForType(type) { return COMPONENT_BY_JS_TYPE[type] || []; } export function _v2Function(src, target, _func) { target.x = _func(src.x); target.y = _func(src.y); return target; } export function _v3Function(src, target, _func) { target.x = _func(src.x); target.y = _func(src.y); target.z = _func(src.z); return target; } export function absV2(src, target) { return _v2Function(src, target, Math.abs); } export function absV3(src, target) { return _v3Function(src, target, Math.abs); } export function maxV3Components(src) { return Math.max(src.x, Math.max(src.y, src.z)); } export function vector3Clamp(src, min, max, target) { target.x = _clamp(src.x, min.x, max.x); target.y = _clamp(src.y, min.y, max.y); target.z = _clamp(src.z, min.z, max.z); return target; } export function maxV3Component(src, target, value) { target.x = Math.max(src.x, value); target.y = Math.max(src.y, value); target.z = Math.max(src.z, value); return target; } export function vector2MaxScalar(src, scalar, target) { target.x = Math.max(src.x, scalar); target.y = Math.max(src.y, scalar); return target; } export function vector2Dot(src) { return src.dot(src); }