@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
63 lines (62 loc) • 1.93 kB
JavaScript
;
import {
registerFactoryFunctions
} from "../../CoreObjectFactory";
import { SDF_OBJECT_TYPES_SET } from "./SDFCommon";
import { SDFCoreObject } from "./SDFCoreObject";
import { SDFPoint } from "./SDFPoint";
import { SDFVertex } from "./SDFVertex";
import { SDFPrimitive } from "./SDFPrimitive";
export function onSDFModuleRegister(poly) {
const pointClassFactory = (object) => {
if (SDF_OBJECT_TYPES_SET.has(object.type)) {
return SDFPoint;
}
};
const pointInstanceFactory = (object, index = 0) => {
if (SDF_OBJECT_TYPES_SET.has(object.type)) {
return new SDFPoint(object, index);
}
};
const vertexClassFactory = (object) => {
if (SDF_OBJECT_TYPES_SET.has(object.type)) {
return SDFVertex;
}
};
const vertexInstanceFactory = (object, index = 0) => {
if (SDF_OBJECT_TYPES_SET.has(object.type)) {
return new SDFVertex(object, index);
}
};
const primitiveClassFactory = (object) => {
if (SDF_OBJECT_TYPES_SET.has(object.type)) {
return SDFPrimitive;
}
};
const primitiveInstanceFactory = (object, index = 0) => {
if (SDF_OBJECT_TYPES_SET.has(object.type)) {
return new SDFPrimitive(object, index);
}
};
const objectClassFactory = (object) => {
if (SDF_OBJECT_TYPES_SET.has(object.type)) {
return SDFCoreObject;
}
};
const objectInstanceFactory = (object, index = 0) => {
if (SDF_OBJECT_TYPES_SET.has(object.type)) {
return new SDFCoreObject(object, index);
}
};
const factoryFunctions = {
pointClass: pointClassFactory,
pointInstance: pointInstanceFactory,
vertexClass: vertexClassFactory,
vertexInstance: vertexInstanceFactory,
primitiveClass: primitiveClassFactory,
primitiveInstance: primitiveInstanceFactory,
objectClass: objectClassFactory,
objectInstance: objectInstanceFactory
};
registerFactoryFunctions(factoryFunctions);
}