How subdivide GLTF model?

Hello everyone? . How to subdivide GLTF model?
code:

        var subdivisions = 2;
        var modifier = new SubdivisionModifier(subdivisions);
        new GLTFLoader().load(
          objPath,
          function (gltf) {
            gltf.scene.traverse((o) => {
              if (o.isMesh) {
                o.geometry = modifier.modify(o.geometry);
                scene.add(o);
              }
            });
        )

error:
TypeError: Cannot read property ‘length’ of undefined
at SubdivisionModifier.smooth

Can you share a sample jsfiddle or the model + entire error message?
Either the model is not loaded, or corrupted in some way, but there’s 12 occurrences of length in SubdivisionModifier.smooth so it’s hard to tell which part fails rn.

1 Like

See the example in https://threejs.org/examples/?q=sub#webgl_modifier_subdivision. SubdivisionModifier requires the legacy Geometry class, whereas most loaders create the newer BufferGeometry type. You may need to convert backward as shown there. In general it’s often best to do subdivision in a tool like Blender, rather than in your JS application.

2 Likes