Skip to content

Commit

Permalink
Arch: Added more meshing options for Collada exporter - fixes #2341
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Dec 2, 2015
1 parent 9f4c54d commit 1acf487
Show file tree
Hide file tree
Showing 2 changed files with 278 additions and 2 deletions.
255 changes: 255 additions & 0 deletions src/Mod/Arch/Resources/ui/preferences-dae.ui
Expand Up @@ -56,6 +56,246 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Mesher</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefComboBox" name="comboBox">
<property name="toolTip">
<string>The mesher to use. If using netgen, make sure netgen is enabled in the Mesh module</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>ColladaMesher</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Arch</cstring>
</property>
<item>
<property name="text">
<string>Builtin</string>
</property>
</item>
<item>
<property name="text">
<string>Mefisto</string>
</property>
</item>
<item>
<property name="text">
<string>Netgen</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Builtin and mefisto mesher options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Tessellation</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefDoubleSpinBox" name="doubleSpinBox_2">
<property name="toolTip">
<string>The tessellation value to use with the builtin and mefisto meshers</string>
</property>
<property name="decimals">
<number>4</number>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
<property name="prefEntry" stdset="0">
<cstring>ColladaTessellation</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Arch</cstring>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Netgen mesher options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Grading</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefDoubleSpinBox" name="doubleSpinBox_3">
<property name="toolTip">
<string>The grading value to use for netgen meshing</string>
</property>
<property name="decimals">
<number>4</number>
</property>
<property name="value">
<double>0.300000000000000</double>
</property>
<property name="prefEntry" stdset="0">
<cstring>ColladaGrading</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Arch</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Segments per edge</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefSpinBox" name="spinBox">
<property name="toolTip">
<string>The maximum number of segments per edge</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="value">
<number>1</number>
</property>
<property name="prefEntry" stdset="0">
<cstring>ColladaSegsPerEdge</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Arch</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Segments per radius</string>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefSpinBox" name="spinBox_2">
<property name="toolTip">
<string>The number of segments per radius</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="value">
<number>2</number>
</property>
<property name="prefEntry" stdset="0">
<cstring>ColladaSegsPerRadius</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Arch</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="Gui::PrefCheckBox" name="checkBox">
<property name="toolTip">
<string>Allow second order</string>
</property>
<property name="text">
<string>Second order</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>ColladaSecondOrder</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Arch</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="Gui::PrefCheckBox" name="checkBox_2">
<property name="toolTip">
<string>Allows optimization</string>
</property>
<property name="text">
<string>Optimize</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>ColladaOptimize</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Arch</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="Gui::PrefCheckBox" name="checkBox_3">
<property name="toolTip">
<string>Allow quad faces</string>
</property>
<property name="text">
<string>Allow quads</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>ColladaAllowQuads</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Arch</cstring>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand All @@ -77,6 +317,21 @@
<layoutdefault spacing="6" margin="11"/>
<pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
<customwidgets>
<customwidget>
<class>Gui::PrefSpinBox</class>
<extends>QSpinBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefCheckBox</class>
<extends>QCheckBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefComboBox</class>
<extends>QComboBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefDoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
Expand Down
25 changes: 23 additions & 2 deletions src/Mod/Arch/importDAE.py
Expand Up @@ -21,7 +21,7 @@
#* *
#***************************************************************************

import FreeCAD, Mesh, os, numpy
import FreeCAD, Mesh, os, numpy, MeshPart
if FreeCAD.GuiUp:
from DraftTools import translate
else:
Expand All @@ -45,6 +45,27 @@ def checkCollada():
return False
else:
return True

def triangulate(shape):
"triangulates the given face"
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
mesher = p.GetInt("ColladaMesher",0)
tessellation = p.GetFloat("ColladaTessellation",1.0)
grading = p.GetFloat("ColladaGrading",0.3)
segsperedge = p.GetInt("ColladaSegsPerEdge",1)
segsperradius = p.GetInt("ColladaSegsPerRadius",2)
secondorder = p.GetBool("ColladaSecondOrder",False)
optimize = p.GetBool("ColladaOptimize",True)
allowquads = p.GetBool("ColladaAllowQuads",False)
if mesher == 0:
return shape.tessellate(tessellation)
elif mesher == 1:
return MeshPart.meshFromShape(Shape=shape,MaxLength=tessellation).Topology
else:
return MeshPart.meshFromShape(Shape=shape,GrowthRate=grading,SegPerEdge=segsperedge,
SegPerRadius=segsperradius,SecondOrder=secondorder,Optimize=optimize,
AllowQuad=allowquads).Topology


def open(filename):
"called when freecad wants to open a file"
Expand Down Expand Up @@ -131,7 +152,7 @@ def export(exportList,filename,tessellation=1):
m = None
if obj.isDerivedFrom("Part::Feature"):
print "exporting object ",obj.Name, obj.Shape
m = Mesh.Mesh(obj.Shape.tessellate(tessellation))
m = Mesh.Mesh(triangulate(obj.Shape))
elif obj.isDerivedFrom("Mesh::Feature"):
print "exporting object ",obj.Name, obj.Mesh
m = obj.Mesh
Expand Down

0 comments on commit 1acf487

Please sign in to comment.