UNPKG

@polygonjs/polygonjs

Version:

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

104 lines (103 loc) 3.6 kB
"use strict"; import { object3DFactory, pointClassFactoryEnsured, pointInstanceFactoryEnsured, vertexClassFactoryEnsured, vertexInstanceFactoryEnsured, primitiveClassFactoryEnsured, primitiveInstanceFactoryEnsured, objectClassFactoryEnsured, objectInstanceFactoryEnsured } from "./modules/three/ThreeModule"; import { AttribClass } from "./Constant"; const coreFactoryFunctions = [object3DFactory]; export function registerFactoryFunctions(checkFunctions) { coreFactoryFunctions.push(checkFunctions); } export function corePointClassFactory(object) { for (const factoryFunction of coreFactoryFunctions) { const result = factoryFunction.pointClass(object); if (result) { return result; } } return object3DFactory.pointClass(object) || pointClassFactoryEnsured(); } export function corePointInstanceFactory(object, index = 0) { for (const factoryFunction of coreFactoryFunctions) { const result = factoryFunction.pointInstance(object, index); if (result) { return result; } } return object3DFactory.pointInstance(object, index) || pointInstanceFactoryEnsured(object, index); } export function coreVertexClassFactory(object) { for (const factoryFunction of coreFactoryFunctions) { const result = factoryFunction.vertexClass(object); if (result) { return result; } } return object3DFactory.vertexClass(object) || vertexClassFactoryEnsured(); } export function coreVertexInstanceFactory(object, index = 0) { for (const factoryFunction of coreFactoryFunctions) { const result = factoryFunction.vertexInstance(object, index); if (result) { return result; } } return object3DFactory.vertexInstance(object, index) || vertexInstanceFactoryEnsured(object, index); } export function corePrimitiveClassFactory(object) { for (const factoryFunction of coreFactoryFunctions) { const result = factoryFunction.primitiveClass(object); if (result) { return result; } } return object3DFactory.primitiveClass(object) || primitiveClassFactoryEnsured(); } export function corePrimitiveInstanceFactory(object, index = 0) { for (const factoryFunction of coreFactoryFunctions) { const result = factoryFunction.primitiveInstance(object, index); if (result) { return result; } } return object3DFactory.primitiveInstance(object, index) || primitiveInstanceFactoryEnsured(object, index); } export function coreObjectClassFactory(object) { for (const factoryFunction of coreFactoryFunctions) { const result = factoryFunction.objectClass(object); if (result) { return result; } } return object3DFactory.objectClass(object) || objectClassFactoryEnsured(); } export function coreObjectInstanceFactory(object, index = 0) { for (const factoryFunction of coreFactoryFunctions) { const result = factoryFunction.objectInstance(object, index); if (result) { return result; } } return object3DFactory.objectInstance(object, index) || objectInstanceFactoryEnsured(object); } export const ENTITY_CLASS_FACTORY = { [AttribClass.POINT]: corePointClassFactory, [AttribClass.VERTEX]: coreVertexClassFactory, [AttribClass.PRIMITIVE]: corePrimitiveClassFactory, [AttribClass.OBJECT]: coreObjectClassFactory, [AttribClass.CORE_GROUP]: null }; export const ENTITY_INSTANCE_FACTORY = { [AttribClass.POINT]: corePointInstanceFactory, [AttribClass.VERTEX]: coreVertexInstanceFactory, [AttribClass.PRIMITIVE]: corePrimitiveInstanceFactory, [AttribClass.OBJECT]: coreObjectInstanceFactory, [AttribClass.CORE_GROUP]: null };