Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Copyright (c) 2019 Hamza Merzic
- # Permission is hereby granted, free of charge, to any person obtaining a copy
- # of this software and associated documentation files (the "Software"), to deal
- # in the Software without restriction, including without limitation the rights
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- # copies of the Software, and to permit persons to whom the Software is
- # furnished to do so, subject to the following conditions:
- # The above copyright notice and this permission notice shall be included in all
- # copies or substantial portions of the Software.
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- # SOFTWARE.
- if [ "$#" -ne 1 ] || ! [ -f "$1" ]; then
- echo "Usage: $0 FILE" >&2
- exit 1
- fi
- mkdir -p results
- clean_mesh='<!DOCTYPE FilterScript>
- <FilterScript>
- <filter name="Remove Duplicate Faces"/>
- <filter name="Remove Duplicate Vertices"/>
- <filter name="Remove Faces from Non Manifold Edges"/>
- <filter name="Re-Compute Face Normals"/>
- <filter name="Re-Compute Vertex Normals">
- <Param enum_val1="By Angle" type="RichEnum" enum_val2="By Area" value="0" enum_val3="As defined by N. Max" description="Weighting Mode:" tooltip="" name="weightMode" enum_cardinality="4" enum_val0="None (avg)"/>
- </filter>
- </FilterScript>'
- compute_geometry='<!DOCTYPE FilterScript>
- <FilterScript>
- <filter name="Transform: Scale, Normalize">
- <Param description="X Axis" type="RichFloat" tooltip="Scaling" value="100" name="axisX"/>
- <Param description="Y Axis" type="RichFloat" tooltip="Scaling" value="1" name="axisY"/>
- <Param description="Z Axis" type="RichFloat" tooltip="Scaling" value="1" name="axisZ"/>
- <Param description="Uniform Scaling" type="RichBool" tooltip="If selected an uniform scaling (the same for all the three axis) is applied (the X axis value is used)" value="true" name="uniformFlag"/>
- <Param description="Center of scaling:" enum_cardinality="3" type="RichEnum" enum_val1="barycenter" tooltip="Choose a method" value="0" enum_val2="custom point" name="scaleCenter" enum_val0="origin"/>
- <Param description="Custom center" type="RichPoint3f" x="0" tooltip="This scaling center is used only if the custom point option is chosen." z="0" name="customCenter" y="0"/>
- <Param description="Scale to Unit bbox" type="RichBool" tooltip="If selected, the object is scaled to a box whose sides are at most 1 unit lenght" value="false" name="unitFlag"/>
- <Param description="Freeze Matrix" type="RichBool" tooltip="The transformation is explicitly applied, and the vertex coordinates are actually changed" value="true" name="Freeze"/>
- <Param description="Apply to all visible Layers" type="RichBool" tooltip="If selected the filter will be applied to all visible mesh layers" value="false" name="allLayers"/>
- </filter>
- <xmlfilter name="Compute Geometric Measures"/>
- </FilterScript>'
- {
- infile=$1
- bname=$(basename "$infile")
- outfile="results/${bname%.*}.dae"
- outfile_tmp="results/${bname%.*}.stl"
- logfile1="results/${bname%.*}_tmp.log"
- logfile2="results/${bname%.*}.log"
- rm -f $outfile $outfile_tmp $logfile1 $logfile2
- assimp export $infile $outfile_tmp
- assimp export $outfile_tmp $outfile
- meshlabserver -l $logfile1 -i $outfile -o $outfile -s <(echo -e $clean_mesh)
- meshlabserver -l $logfile2 -i $outfile -s <(echo -e $compute_geometry)
- } &> /dev/null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement