Created
July 23, 2021 20:20
-
-
Save n1ckfg/c29002eecce02736fee2137c25efe994 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #@title <b>MeshLab Resampler</b> | |
| #@markdown <ol><li>Set these options:</li></ol> | |
| # https://pymeshlab.readthedocs.io/en/latest/ | |
| # https://pymeshlab.readthedocs.io/en/latest/filter_list.html | |
| # https://pymeshlab.readthedocs.io/en/latest/io_format_list.html | |
| !pip install pymeshlab | |
| import pymeshlab as ml | |
| from google.colab import files | |
| from pathlib import Path | |
| # * * * * * * * * * * | |
| #@markdown <ul><li><i>This will be your approximate percentage reduction in file size.</i></li></ul> | |
| samplePercentage = 0.05 #@param | |
| #@markdown <ul><li><i>Common file format options are ply, obj, xyz.</i></li></ul> | |
| outputFormat = "ply" #@param {type:"string"} | |
| # * * * * * * * * * * | |
| uploadList = files.upload() | |
| for inputFileName in uploadList: | |
| outputFileName = Path(inputFileName).stem + "_resampled." + outputFormat.lower() | |
| ms = ml.MeshSet() | |
| ms.load_new_mesh(inputFileName) | |
| newSampleNum = int(ms.current_mesh().vertex_number() * samplePercentage) | |
| if (newSampleNum < 1): | |
| newSampleNum = 1 | |
| ms.apply_filter("poisson_disk_sampling", samplenum=newSampleNum, subsample=True) | |
| ms.save_current_mesh(outputFileName) | |
| files.download(outputFileName) | |
| #@markdown <ol start=2><li>Click <b>Play</b> to run the script.</li><li>Click the <b>Choose</b> button when it appears, and select files to upload.</li><li>Click <b>Allow</b> if prompted, to permit downloading multiple files.</li><li>The files will download automatically when processing is complete.</li></ol> | |
| #@markdown <br> | |
| #@markdown — P.S. Double-click this panel to see the Python code. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment