UNPKG

@polygonjs/polygonjs

Version:

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

46 lines (45 loc) 1.33 kB
"use strict"; import { BaseMethod } from "./_Base"; import { Vector2 } from "three"; const COMPONENT_NAME_0 = [0, "0", "x"]; const COMPONENT_NAME_1 = [1, "1", "y"]; export class CopResExpression extends BaseMethod { constructor() { super(...arguments); this._resolution = new Vector2(); } static requiredArguments() { return [ ["string", "path to node"], ["string", "component_name: x or y"] ]; } findDependency(args) { return this.createDependencyFromIndexOrPath(args); } async processArguments(args) { if (args.length == 1 || args.length == 2) { const indexOrPath = args[0]; const componentName = args[1]; const container = await this.getReferencedNodeContainer(indexOrPath); if (container) { const resolution = container.resolution(); if (componentName) { if (COMPONENT_NAME_0.includes(componentName)) { return resolution[0]; } else { if (COMPONENT_NAME_1.includes(componentName)) { return resolution[1]; } } } else { this._resolution.set(resolution[0], resolution[1]); return this._resolution; } } this._resolution.set(1, 1); return args.length == 1 ? 1 : this._resolution; } return 1; } }