UNPKG

@polygonjs/polygonjs

Version:

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

22 lines (21 loc) 1.01 kB
"use strict"; import { BufferAttribute, BufferGeometry, MathUtils } from "three"; import { BaseSopOperation } from "../../../../../engine/operations/sop/_Base"; import { ObjectType } from "../../../Constant"; import { sdfMaterialMesh } from "../SDFConstant"; import { toCreasedNormals } from "../../../../../modules/three/examples/jsm/utils/BufferGeometryUtils"; export function SDFGeometryToObject3D(sdfGeometry, options) { const geometry = SDFGeometryToBufferGeometry(sdfGeometry, options); return BaseSopOperation.createObject( geometry, ObjectType.MESH, sdfMaterialMesh(options.meshesColor, options.wireframe) ); } export function SDFGeometryToBufferGeometry(sdfGeometry, options) { const sdfMesh = sdfGeometry.getMesh(); const geometry = new BufferGeometry(); geometry.setAttribute("position", new BufferAttribute(sdfMesh.vertProperties, 3)); geometry.setIndex(new BufferAttribute(sdfMesh.triVerts, 1)); return toCreasedNormals(geometry, MathUtils.degToRad(options.facetAngle)); }