UNPKG

@polygonjs/polygonjs

Version:

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

172 lines (171 loc) 5.29 kB
"use strict"; import { Quaternion, Vector3 } from "three"; import { ObjectNamedFunction1, ObjectNamedFunction2 } from "./_Base"; import { getObjectPropertyRef } from "../../core/reactivity/ObjectPropertyReactivity"; import { dummyReadRefVal } from "../../core/reactivity/CoreReactivity"; import { _matchArrayLength } from "./_ArrayUtils"; import { getObjectChildrenCountRef } from "../../core/reactivity/ObjectHierarchyReactivity"; export class getObjectProperty extends ObjectNamedFunction1 { static type() { return "getObjectProperty"; } func(object3D, propertyName) { dummyReadRefVal(getObjectPropertyRef(object3D, propertyName).value); return object3D[propertyName]; } } export class getObjectWorldPosition extends ObjectNamedFunction1 { static type() { return "getObjectWorldPosition"; } func(object3D, target) { dummyReadRefVal(this.timeController.timeUniform().value); object3D.getWorldPosition(target); return target; } } export class object3DLocalToWorld extends ObjectNamedFunction2 { static type() { return "object3DLocalToWorld"; } func(object3D, position, target) { dummyReadRefVal(this.timeController.timeUniform().value); target.copy(position); object3D.localToWorld(target); return target; } } export class object3DWorldToLocal extends ObjectNamedFunction2 { static type() { return "object3DWorldToLocal"; } func(object3D, position, target) { dummyReadRefVal(this.timeController.timeUniform().value); target.copy(position); object3D.worldToLocal(target); return target; } } function _getChildrenPropertiesVector3(propertyName) { return function(object3D, targets) { dummyReadRefVal(getObjectChildrenCountRef(object3D).value); _matchArrayLength(object3D.children, targets, () => new Vector3()); let i = 0; const children = object3D.children; for (let child of children) { dummyReadRefVal(getObjectPropertyRef(child, propertyName).value); targets[i].copy(child[propertyName]); i++; } return targets; }; } function _getChildrenPropertiesQuaternion(propertyName) { return function(object3D, targets) { dummyReadRefVal(getObjectChildrenCountRef(object3D).value); _matchArrayLength(object3D.children, targets, () => new Quaternion()); let i = 0; const children = object3D.children; for (let child of children) { dummyReadRefVal(getObjectPropertyRef(child, propertyName).value); targets[i].copy(child[propertyName]); i++; } return targets; }; } function _getChildrenPropertiesBoolean(propertyName) { return function(object3D, targets) { dummyReadRefVal(getObjectChildrenCountRef(object3D).value); _matchArrayLength(object3D.children, targets, () => false); let i = 0; const children = object3D.children; for (let child of children) { dummyReadRefVal(getObjectPropertyRef(child, propertyName).value); targets[i] = child[propertyName]; i++; } return targets; }; } export class getChildrenPropertiesPosition extends ObjectNamedFunction1 { constructor() { super(...arguments); this.func = _getChildrenPropertiesVector3("position"); } static type() { return "getChildrenPropertiesPosition"; } } export class getChildrenPropertiesQuaternion extends ObjectNamedFunction1 { constructor() { super(...arguments); this.func = _getChildrenPropertiesQuaternion("quaternion"); } static type() { return "getChildrenPropertiesQuaternion"; } } export class getChildrenPropertiesScale extends ObjectNamedFunction1 { constructor() { super(...arguments); this.func = _getChildrenPropertiesVector3("scale"); } static type() { return "getChildrenPropertiesScale"; } } export class getChildrenPropertiesUp extends ObjectNamedFunction1 { constructor() { super(...arguments); this.func = _getChildrenPropertiesVector3("up"); } static type() { return "getChildrenPropertiesUp"; } } export class getChildrenPropertiesVisible extends ObjectNamedFunction1 { constructor() { super(...arguments); this.func = _getChildrenPropertiesBoolean("visible"); } static type() { return "getChildrenPropertiesVisible"; } } export class getChildrenPropertiesMatrixAutoUpdate extends ObjectNamedFunction1 { constructor() { super(...arguments); this.func = _getChildrenPropertiesBoolean("matrixAutoUpdate"); } static type() { return "getChildrenPropertiesMatrixAutoUpdate"; } } export class getChildrenPropertiesCastShadow extends ObjectNamedFunction1 { constructor() { super(...arguments); this.func = _getChildrenPropertiesBoolean("castShadow"); } static type() { return "getChildrenPropertiesCastShadow"; } } export class getChildrenPropertiesReceiveShadow extends ObjectNamedFunction1 { constructor() { super(...arguments); this.func = _getChildrenPropertiesBoolean("receiveShadow"); } static type() { return "getChildrenPropertiesReceiveShadow"; } } export class getChildrenPropertiesFrustumCulled extends ObjectNamedFunction1 { constructor() { super(...arguments); this.func = _getChildrenPropertiesBoolean("frustumCulled"); } static type() { return "getChildrenPropertiesFrustumCulled"; } }