Call for help for calculate outline for a mesh? #1717
Replies: 2 comments 1 reply
-
|
Hi @WallanceLee! There's no feature built into glTF Transform to compute the edges of a geometry. To give the same result as THREE.EdgesGeometry you would compute and iterate over all edges of a Primitive, and keep only sharp edges (on an angle below some threshold). How you would encode the edges in the glTF file is up to you, but one simple way would be to add one or more Primitives to each existing Mesh. Suppose a Mesh has 2 primitives (type = TRIANGLES) initially. You'd add 2 more primitives (type = LINES) sharing the same position vertex attribute (POSITION) as the originals, but with different indices representing only the selected edges. Pseudocode: for (const mesh of document.getRoot().listMeshes()) {
const srcPrims = mesh.listPrimitives();
for (const prim of srcPrims) {
mesh.addPrimitive(createEdgePrim(document, prim));
}
}
function createEdgePrim(document: Document, prim: Primitive): Primitive {
const edgePrim = document.createPrimitive()
.setName(prim.getName() + '_edges')
.setMode(Primitive.Mode.LINES)
.setAttribute('POSITION', prim.getAttribute('POSITION'));
// Compute edges, select edges with angle < threshold, write indices.
// See https://github.com/mrdoob/three.js/blob/dev/src/geometries/EdgesGeometry.js.
return edgePrim;
} |
Beta Was this translation helpful? Give feedback.
-
|
#1720 Please give me some advice. Thanks for your time. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to implement a function like threejs EdgeGeometry, and store theme as mesh or node extra field in GLTF file? Have glTF-transform supported this function?
Beta Was this translation helpful? Give feedback.
All reactions