The thing is if we apply obj.to_mesh(scene, use_apply_modifiers, 'PREVIEW'), if the obj_type != 'MESH', the mesh is temporary and the export does not work properly. So we need to use the obj.data instead. This way the objects that the type is not MESH are properly exported.
Also if curves are used, the bpy.data.curves.tag(False) needs to be added also.
Description
Event Timeline
eeh, apologies for late review.
looking into the patch, and I cant see any bug. the file loads fine in freewrl, with and without modifiers being applied. (without I had to move the `P` away so it wasnt obscured by the non subsurf pen)
infact using obj.data seems incorrect here because when modifiers are applied the same data can be very different depending on which objects export.
Can you show an example where the current code fails?, or explain whats incorrect about patch-test.blend's export?, from my tests this works ok with existing code.
Thanks for looking into it.
The thing is if you export to X3D because a mesh is created the id of all created meshes will all be the same "coords_ME_Mesh_001" . This way all meshes from all created meshes will get the same id which is not unique.
When in export_object function:
elif obj_type in {'MESH', 'CURVE', 'SURF', 'FONT', 'SURFACE'}: # I think SURF is not needed anymore (check if SURFACE covers it)
if (obj_type != 'MESH') or (use_apply_modifiers and obj.is_modified(scene, 'PREVIEW')):
try:
me = obj.to_mesh(scene, use_apply_modifiers, 'PREVIEW')
me.name = obj.data.name + '.Mesh' # The default name is 'Mesh' for all newly created meshes
# me.tag = obj.data.tag # Because the mesh is temporary cannot be used for reference
#print ("Info: data.tag [%s]" % (obj.data.tag))
except:
me = None
else:
me = obj.data
I see that you use obj.data, that is why I used always this info and not the mesh that in some cases is temporary.
Furthermore in def writeIndexedFaceSet there is a test if mesh.tag. Because these meshes are temporary unless you store them in a list you cannot reuse them.
Trying to state the problem. When meshes are created for the purpose of transforming obj to meshes with obj.to_mesh, that newly created mesh does not old a unique name. If the object is referenced by other the reference will be to the object and not to the temporary mesh.
I'm not a python programmer, so I minimized the changes. Probably you can change the code more cleanly.
I use https://savage.nps.edu/X3D-Edit/#Downloads just to check the validity and use xj3d to embedded into a Java program.
Please tell me if I was too confusing.
these meshes are intentionally never re-used at the moment,
applied an alternative fix r2764.
thanks for looking into this all the same, and for spotting it ofcourse.
closing.