What's the best way to modify a mesh export and then undo changes?

What's the best way to modify a mesh export and then undo changes?

malcolm_341
Collaborator Collaborator
686 Views
10 Replies
Message 1 of 11

What's the best way to modify a mesh export and then undo changes?

malcolm_341
Collaborator
Collaborator

Hi, I've wondered this for quite some time. I have a script that needs to make some modifications to existing meshes in the scene, then export as .fbx without modifying the original meshes. I usually do this by putting the objects in a group to get around the name clashing, but that won't work here because the group gets exported with the .fbx and that's not desired. Basically I'm looking for a way to modify some meshes while keeping names without the scene actually getting modified after the export completes. The only thing I could think of is to paste names back and forth which seems a bit dangerous, is that way most people are doing it?

0 Likes
687 Views
10 Replies
Replies (10)
Message 2 of 11

Kahylan
Advisor
Advisor

Hi!

 

So your main problem is the name clashing, which you want to avoid so you can delete the new nodes and the old ones stay the same after?

 

I could think of some approaches to do that.

 

You could just using your group method that you are normally doing and just avoid exporting your group by using listRelatives to select everything inside the group and the -s flag in the FBXExport command to just export the selection.

 

Or you could create a temporary file, so saving the file, saving it again under a different name, then doing the modifications in the new file and once the fbx is exported deleting the new file and reopening the original file. Thats what most renderers do to avoid corrupting scene files if something goes wrong during batchrendering. The downside of this is that you would lose your undo queue.

 

Another way to preserve the names of your nodes is to create a temporary namespace. Create a namespace, put all your objects into it, then create a group to avoid nameclashing, duplicate the objects into it. Take the children of the group out of the namespace and unparent them from the group. Once the export is completed you delete the duplicates and remove the namespace again. This way you rename your objects in a way that you can easily remove again once you are done.

 

Could one of these approaches be what you are looking for?

 

I hope it helps!

Message 3 of 11

teddude75
Collaborator
Collaborator

This can be done with referencing. If you reference your mesh, this will preserve your original mesh and it can't be deleted.

1. reference mesh

2. edit mesh (extrude, tweak verts, etc.) 

3. export edited mesh

4. Delete history (this you will have to do in the node editor). If you select your shape node and all the nodes connected (not the shading network) to that and hit delete, it will only delete everything that is not referenced.  

5. reload your reference

deleteHistory.png

 If it says polySurfaceShape that is is your edited mesh that you can delete.

0 Likes
Message 4 of 11

teddude75
Collaborator
Collaborator

This might help also. https://vimeo.com/459686052

Message 5 of 11

malcolm_341
Collaborator
Collaborator

Thanks for your suggestions Does the -s flag in the FBXExport command take the children with it or just the selection, if that worked that would be the easiest and safest way I think. Right now I've got it set up to put things in a group and paste names back and forth, it works, but it feels brittle to me. I'll also investigate names spaces, I've never used those before.

0 Likes
Message 6 of 11

malcolm_341
Collaborator
Collaborator

How do you reference a mesh that already exists in your scene I didn't think that was possible?

Message 7 of 11

malcolm_341
Collaborator
Collaborator

Thank for the suggestion, I don't think the tweak node will work because one of the operations I need to do is freeze transform and the tweak node appears to be for geometry modification.

Message 8 of 11

teddude75
Collaborator
Collaborator

You need to export it or save a file with only your original mesh in it. Then, reference that into your scene. It's unclear what you are trying to do. Is this a rig? Do you want it to be an fbx? Is it just the naming that's the problem? If that's the case a simple script and toggle a name. Can you explain more?

Message 9 of 11

Kahylan
Advisor
Advisor

Sadly I realised that using the -s flag will also take export the parent group. I wasn't at my work computer when I wrote that and remembered it wrong.

 

But, If you have your original meshes grouped and until the FBX export is complete, you can quite easily get around the name clashing.

 

You simply group your meshes, then you duplicate the group. You run all the modifications to the meshes in the group, then you parent those meshes to world, select them and use FBXEport with the -s flag. Afterwards you delete your selection, unparent the originals and delete the groups.

 

Message 10 of 11

malcolm_341
Collaborator
Collaborator

Hi everyone, thanks for your suggestions. I'm trying to export selection as a .fbx file where the user chooses settings to apply on export without modifying the current scene. The UI is a bunch of checkboxes, for example freeze transform without affecting the original meshes in the scene and the tool will primarily be used on meshes, but it's nice to have it work on any selection. So far name spaces seem to be the best route because grouping can change the hierarchy of the scene if the user has child meshes selected and I want the tool to work on export selected. I'm going to try to implement the name space idea and see if that works out.

Message 11 of 11

malcolm_341
Collaborator
Collaborator

And here's the path I'm going with, hopefully I won't run into any blockers SelectAll; saved the day because it selects all top parents of the hierarchy rather than actually selecting all nodes, without that the user selection could easily break the hierarchy with grouping and un-parenting as the script runs.

 

-Fix child node selection> put everything in a group> create name space> duplicate so new meshes go into name space> un-parent to world root> remove name space> export selection> delete duplicate meshes and remove temp group.

string $selection[] = `ls -sl`;
SelectAll;
string $tempGroup1 = `group -name "m341_fbxHandler_temp_group"`;
select $selection;

//Deselect child nodes to fix drag select in viewport messing up hierarchy
string $children[] = `listRelatives -allDescendents -fullPath`;
select -deselect $children;

//Create name space to fix name clashing
namespace -addNamespace "m341_fbxHandler_temp_NS";
namespace -set "m341_fbxHandler_temp_NS";

//Duplicate to root hierarchy
duplicate -rr;
parent -w;

//Remove name space
namespace -set ":";
namespace -mv "m341_fbxHandler_temp_NS" ":" -force;
namespace -removeNamespace "m341_fbxHandler_temp_NS";

//Export
//Do some stuff here

//Clean up
Delete;
ungroup $tempGroup1;
select $selection;