Parenting, world matrix, keeping transforms in the code.

I'm trying to write a custom operator that will insert empties in a parented chain of objects, keeping the existing hierarchy, but having the objects parented to the empties instead of the next link on the chain.

I think my snag is not on writing the code itself, but on the fundamental understanding of world matrices and inverted matrices. I managed to get the parenting to remain, but the objects are being moved to the world origin and I'm stumped.

Does anyone have a good resource suggestion for understanding that subject? Or any insight that might help me keep the objects put lol. 

I'll eventually try to add bones parenting to this mix and I think it'll be important to understand it on that scenario too.

Thanks!!

1 love
Reply
  • Dwayne Savage(dillenbata3) replied

    I'm not sure on the world matric, but I know my old enemy the Inverted matric. When rigging this can be the cause of many problems. It is simple to show, but difficult to explain.(At least for me). I'll go beginner friendly for other people so bare with me on this. Start Blender in default setup. Add a Monkey(shift+a->mesh->monkey) and move it 3 meters on the Y axis(Press GY3 and left click or press enter). Select the monkey, shift+select the cube, and press ctrl+p->object. Select the cube and move it 2 meter on the z axis(press GZ2). Select the monkey and open n-panel(Press N and click Item tab) you will see that the monkey's location(XYZ) is 0, 3, 0. That is because when you parented it to the cube it's point of reference is changed from the world/global origin to the cubes local origin. Select both cube and monkey and press alt+G to clear the location. They both jump to the world origin. Now press ctrl+z to undo clearing the location. Then press alt+P->clear parent. The monkey will jump down since it's point of reference for the transforms(Location in this case) is now back to the world origin. Select the monkey, shift+select the cube, and press ctrl+P->object. The monkey doesn't move. select the monkey and it's location is still 0,3,0 even though it's 2 meters lower than the cube. If you select both and press alt+g the monkey will still be 2 meters below the cube. That is because of the inverse matric. How did it get created? The cube was not zeroed out to the world. It was 2 meters up on the Z location. The inverse matric then set's the inverse(In this case -2) of your transform to get it zeroed out. Side Note: for Scale it's 1ed out. You can clear the inverse by selecting the monkey and pressing alt+p->clear inverse(It may say inverse table or parent inverse depending on your Blender version) There are constraints like the child of constraint that have buttons to clear and set the inverse. The inverse can also cause problems with some modifiers like curve. So there are case where you will need to clear the inverse. I wished there was a panel to show the inverse settings. My understanding is it is read only and can only be changed thru operators. 

    2 loves
  • Nathi Tappan(nathitappan) replied

    Wow! Sorry it took me so long to respond dillenbata3, I forgot to subscribe to the thread.

    Thank you so much for detailed walk through!! It sure helped me visualize it. It's definitely the matrix generating the problems. Because I tested with seemingly two exact alike chains, but with the only thing different was which option in the ctrl+p menu was chosen. Different results with my operator.

    I think I'll do it manually to an copy the lines from to the script like Spencer shows us, until I get the problem fixed manually. Then it might be easier to set the for loops and such to ensure the operator always gets the same outcome. 

    Thanks again, that was very helpful.

    1 love