export to obj with groups and same mesh

A subforum specific to the development of the OpenFoam-based workbenches ( Cfd https://github.com/qingfengxia/Cfd and CfdOF https://github.com/jaheyns/CfdOF )

Moderator: oliveroxtoby

User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

export to obj with groups and same mesh

Post by bernd »

There has been group export added to obj recently ...

The OpenFoam guys are quit excited about this feature :) They wonder if it is possible to use the same mesh for the different exported groups. Attached a FreeCAD file. To get different groups I extracted the three different shapes from the fusion. They all where selected and exported to *.obj. The file than has three groups, but they gets meshed independent. See attached screen from reimport.

Is it possible to export parts (groups of faces ore single faces) of the fusion into differend groups but have the whole fusion meshed consistently.
cyclone--bhb.fcstd
(24.09 KiB) Downloaded 143 times
cyclone6.obj
(20.51 KiB) Downloaded 175 times
reimport screen: EDIT: made a red circle to mark the problem
screen.jpg
screen.jpg (78.6 KiB) Viewed 11255 times

Code: Select all

export_objs = []
export_objs.append(App.ActiveDocument.getObject("Shape"))
export_objs.append(App.ActiveDocument.getObject("Compound"))
export_objs.append(App.ActiveDocument.getObject("Shape001"))
export_file = u"C:/Users/bhb/Desktop/0110--openfoam--meshgroups/cyclone6.obj"
Mesh.export(export_objs, export_file)
Last edited by bernd on Wed Aug 03, 2016 2:21 pm, edited 1 time in total.
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: export to obj with groups and same mesh

Post by wmayer »

The export works this way:
1. Internally a tmp. global mesh object is created
2. For every selected object another mesh is created if possible (at the moment for mesh & part objects)
3. The points and faces of this mesh are added to the global mesh and a named segment is created for the new data (the segment is needed to handle the grouping stuff)
4. The global mesh goes to the obj export function and inside there first all points are written out and then for every segment a new group is created and the corresponding face indexes are written out
They wonder if it is possible to use the same mesh for the different exported groups.
No, it's not possible this way and I'm not sure what they want to achieve with this.
The file than has three groups, but they gets meshed independent.
Yes, and isn't this the sense of it?

Recently there was on the German forum an issue where somebody selected a few objects, exported them to obj and was not happy that on import in his other application it was one big mesh. He wanted to have independent mesh objects.
Is it possible to export parts (groups of faces ore single faces) of the fusion into differend groups but have the whole fusion meshed consistently.
The export function cannot decide how to do the meshing because in one case someone needs it this way and in another case someone else needs it differently. If a shape must be meshed consistently then the input shape must be at least a compound or even a shell or solid -- not independent faces. However, then the compound (or shell or solid) appears as a single mesh in the obj file afterwards.
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: export to obj with groups and same mesh

Post by bernd »

wmayer wrote:
They wonder if it is possible to use the same mesh for the different exported groups.
No, it's not possible this way and I'm not sure what they want to achieve with this.
My misstake. I should have been writing:

They wonder if it is possible to use the same edge, node and face data for the different exported groups (meshes).

After reimport there should be 3 meshes, but it should look like in the screen attached. I marked the differnce in the first post screen.
screen.jpg
screen.jpg (84.57 KiB) Viewed 11259 times
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: export to obj with groups and same mesh

Post by wmayer »

They wonder if it is possible to use the same edge, node and face data for the different exported groups (meshes).
I see what you mean. As said before this is too complex for the mesh export function to handle it all. And it has actually not much to do with the obj export as such.

What we need is a special function e.g. in the tessellation panel from the MeshPart module where you can say "Mesh together but keep separate". There we could add an option where several shapes are selected and meshed together but for each shape its own mesh in the document is created.
Afterwards you select the created meshes and export them as obj.
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: export to obj with groups and same mesh

Post by wmayer »

Just tried your example and apparently creating a compound is not sufficient. This means we need a shell to have the faces sewed together because otherwise the individual shapes are meshed independently again.
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: export to obj with groups and same mesh

Post by bernd »

wmayer wrote:What we need is a special function e.g. in the tessellation panel from the MeshPart module where you can say "Mesh together but keep separate". There we could add an option where several shapes are selected and meshed together but for each shape its own mesh in the document is created.
Afterwards you select the created meshes and export them as obj.
For me it seams this is exactly what these guys need. Let's wait for chris to comment this.

EDIT: related: viewtopic.php?f=3&t=4284&p=75302&hilit=openfoam#p75302
cfdfoundation
Posts: 4
Joined: Sat Jan 10, 2015 4:12 pm

Re: export to obj with groups and same mesh

Post by cfdfoundation »

Firstly, the inclusion of group names in the obj (surface) mesh export is very useful when we use the obj mesh for volume meshing with snappyHexMesh in OpenFOAM for CFD. This is highly appreciated.

The slight weakness is that the different grouped regions of the surface are meshed separately so the overall mesh includes gaps and overlaps. It is better that a closed volume, e.g. a cylinder, is strictly closed in the tesselated form.

So, indeed, it would be very helpful to have a function as described by wmayer as "Mesh together but keep separate".
Ideally, vertices along the interface between regions should be shared, not duplicated. I imagine they may get duplicated during meshing, but I don't know if there is a function that can filter out duplicates. If not, OpenFOAM has the surfaceMergePoints utility that can remove the duplicate vertices from an OBJ file. - chris
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: export to obj with groups and same mesh

Post by wmayer »

With the latest changes this is now possible at least in Python. From Bernd's example there is an object "Fusion". For its faces 7 and 8 a separate mesh should be created and the other faces should go into one mesh. Here is the code to achieve this in Python:

Code: Select all

import Mesh

shape=App.ActiveDocument.Fusion.Shape
shape.tessellate(0.1)

# for each face gets its tessellation and create a tmp. mesh
face_mesh=[Mesh.Mesh(shape.getFacesFromSubelement("Face",i+1)) for i in range(len(shape.Faces))]

mesh1=face_mesh[6]
mesh2=face_mesh[7]
face_mesh.remove(mesh1)
face_mesh.remove(mesh2)

# create one mesh from all other faces
mesh3=Mesh.Mesh()
[mesh3.addMesh(i) for i in face_mesh]
# in case it causes duplicate points, remove them
mesh3.removeDuplicatedPoints()

Mesh.show(mesh1)
Mesh.show(mesh2)
Mesh.show(mesh3)
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: export to obj with groups and same mesh

Post by bernd »

and here the file ...
cyclone7.obj
(626.76 KiB) Downloaded 181 times
:D

BTW:
I tried to get a more rough tessellation but changing the parameter in shape.tessellate(0.1) did not do the trick :?
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: export to obj with groups and same mesh

Post by wmayer »

I tried to get a more rough tessellation but changing the parameter in shape.tessellate(0.1) did not do the trick
When meshing a shape the data are attached to the Brep structure and subsequent calls of the meshing function have no effect. You have to clean the Brep structure from the mesh and then a call of the meshing function creates a new mesh.

In Python you can use the method "cleaned" which returns a copy of the shape without mesh data. Then use tessellate with a different tolerance.
Post Reply