Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Making a mesh copy under the same transform

Making a mesh copy under the same transform

Sebastian_Wiendl
Enthusiast Enthusiast
1,870 Views
5 Replies
Message 1 of 6

Making a mesh copy under the same transform

Sebastian_Wiendl
Enthusiast
Enthusiast

Hi everyone,

 

I've got a scene with just a basic sphere ("pSphere1") in it, and I put 3 materials on it.

copy_issue1.png

All that I am trying to do is to make a copy of the mesh under the same transform, using mel.

The duplicate and instance functions only work on transforms, i.e. not mesh shapes by themselves, so it seemed the most logical to create a duplicate, then reparent the mesh shape, and delete the copy transform.

 

I am doing this:

duplicate -name "copy" "pSphere1";
parent -s -r "copyShape" "pSphere1";
delete "copy";

If I do this and visualize the new mesh, it shows without materials (even though it appears to be connected in the hyper/node graph).

copy_issue2.png

 

But oddly enough, if I first call:

duplicate -name "copy" "pSphere1";

And then as a separate call do:

parent -s -r "copyShape" "pSphere1";
delete "copy";

Then it all works fine. 

copy_issue3.png

 

It looks to me that if I call the `parent` right away, something about the `duplicate` might not have finished processing.

Not sure if this makes any sense?

 

Is there a way to force `parent` to be called only after duplicate is 100% finished? I tried pause -sec 3, but that didn't do the trick.

 

Maybe I am approaching this the wrong way and there is a much easier way to do this?

Maybe create a new mesh under the pSphere1 transform and copy all materials and attributes over? But that seems like a lot of work when duplicate takes care of all of this for me already.

 

Any help would be much appreciated.

 

Cheers,

Sebastian

0 Likes
Accepted solutions (1)
1,871 Views
5 Replies
Replies (5)
Message 2 of 6

trs_andre
Collaborator
Collaborator

Hi!

You can add the following command after the first three lines.

 

transferAttributes -transferPositions 0 -transferNormals 0 -transferUVs 2 -transferColors 2 -sampleSpace 1 -searchMethod 3-flipUVs 0 -colorBorders 1 ;

 

This way, the color information will be copied from the source to the destination mesh.

Hope it helps!

André Moreira

Game Developer / Technical Artist

LinkedIn

0 Likes
Message 3 of 6

Sebastian_Wiendl
Enthusiast
Enthusiast

Hi @trs_andre ,

 

Thanks so much for getting back to me.

This seems to solve the issues as far as I can tell so far.

Any idea why this is required? Maya bug?

 

Cheers,
Sebastian

Message 4 of 6

zewt
Collaborator
Collaborator
Accepted solution

That's a viewport bug.  The viewport doesn't update shaders for the mesh correctly here.  One way you can work around this is to refresh the UI after duplicating:

 

 

duplicate -name "copy" "pSphere1";
refresh;
parent -s -r "copyShape" "pSphere1";
delete "copy";

If you're doing a lot of work in a script and this has to be done a lot, that might slow things down, since it'll refresh the whole UI and all viewports, but most of the time this is fine.  Another way you can work around it is to run "ogs -reset" when you're done, which will simply force the viewport to refresh all shaders, which also clears this up.

 

 

By the way, if what you're actually doing is setting up a custom deformer chain manually (that's the main reason I can think of to do this), 2020 has a new deformableShape command that makes this a lot easier.  It lets you create and query "orig" meshes, in the same way that deformers do when they're created.  I don't think it was mentioned anywhere in the release notes, but:

 

http://help.autodesk.com/cloudhelp/2020/ENU/Maya-Tech-Docs/CommandsPython/deformableShape.html

 

Message 5 of 6

trs_andre
Collaborator
Collaborator

Sorry for the late reply.

I'm glad it solved the issue to you!

@zewt wrote in the previous message quite a great explanation with a few solutions that might help you not only in this case but in other similar ones as well!

Please let us know if you still encounter some kind of problem 😉

André Moreira

Game Developer / Technical Artist

LinkedIn

Message 6 of 6

Sebastian_Wiendl
Enthusiast
Enthusiast

Thanks so much @trs_andre and @zewt,

 

This solved my issue. I think ogs -reset is the best one in this case, but I appreciate all of the information, and as you said, it'll definitely come handy in other situations.

 

Yes, this is for a custom deformer. I'm having a look at the deformableShape command to see if that works for my purpose. This is really helpful.

 

Again, thanks so much.

 

Cheers,

Sebastian