vue-3d-model icon indicating copy to clipboard operation
vue-3d-model copied to clipboard

Smoothing STL Model

Open giuliobrugnaro opened this issue 5 years ago • 5 comments

I am using the model-stl component to display STL files. For most of them, their "resolution" is quite low (due to conversion) and they have segmented corners instead of smooth round ones (see attached screenshot). Is there a way to smooth the STL model during the visualization? I know there is the 'smoothing' prop for OBJ models. Thanks!

stl

giuliobrugnaro avatar Nov 25 '19 18:11 giuliobrugnaro

@hujiulong is flatShading false by default for the model-stl? Could it be a way to achieve the smoothing for STL files? If so, could you indicate me where I can change this option? Thanks!

giuliobrugnaro avatar Nov 27 '19 15:11 giuliobrugnaro

Hi @hujiulong , do you have any suggestions for me? I haven't managed yet to figure out how to address the issue ;/

giuliobrugnaro avatar Dec 09 '19 21:12 giuliobrugnaro

This rendering result is because the geometry has no normals, you can choose to bring the normal information when exporting the model, Or, like the smooth prop of obj-model, recalculate the normals.

hujiulong avatar Dec 10 '19 03:12 hujiulong

Thank you @hujiulong. I have tried to replicate what happens for the smooth prop of obj-model in the stl-model component (see below), but the result is even weirder (see picture). Am I missing something?

methods: {
    getObject(geometry) {
    geometry = toIndexed(geometry);
    geometry.computeFaceNormals();
    geometry.computeVertexNormals();
    return new Mesh(geometry, new MeshPhongMaterial());
    },
  },

Capture2

This is the results with only geometry = toIndexed(geometry);

Capture3

giuliobrugnaro avatar Dec 11 '19 17:12 giuliobrugnaro

@hujiulong I have modified the getObject function in the model-stl component as below but unfortunately the result is still similar to the previous images. Do you have any suggestion? I'm stuck and not sure what to try next. Thank you!

    getObject(geometry) {

    geometry = new Geometry().fromBufferGeometry( geometry );
    geometry.mergeVertices();
    geometry.computeVertexNormals();
    geometry.computeFaceNormals();
    geometry = new BufferGeometry().fromGeometry( geometry );
    
    return new Mesh(geometry, new MeshPhongMaterial());
    },

giuliobrugnaro avatar Dec 18 '19 06:12 giuliobrugnaro