Home Coding, Scripting, Shaders

Autodesk 3DS Max: Getting all vertices from a bone in a skin modifier?

polycounter lvl 6
Offline / Send Message
MrQuetch polycounter lvl 6
Hello.

So, I posted a similar thread like this a few days ago. I apologize for the strong similarities. I've managed to progress further, thanks to Klunk's code. But, I'm running into some more trouble that I unfortunately cannot resolve. I've already looked into this for several hours, and still cannot get it working as expected. I'm not sure that the code here actually gets all of the vertices from a model - as it's crucial that I need to return even the dead vertices within a model - which doesn't seem to be happening. Perhaps I'm using the function incorrectly. But, I don't think I am as it is returning some of the vertices. Keep in mind, all of the vertices must be connected to a bone - even if they are dead. Does anyone have any other ideas for this particular problem? I'm truly stumped.

Here's Klunk's code:
  1. fn CollectAllVertsOnlyInfluencedByBone skin_mod bone_index =
  2. (
  3. num_verts = skinOps.GetNumberVertices skin_mod;
  4. for v = 1 to num_verts where skinOps.GetVertexWeightCount skin_mod v == 1 and
  5. skinOps.GetVertexWeightBoneID skin_mod v 1 == bone_index collect v;
  6. )

Replies

  • monster
    Offline / Send Message
    monster polycounter
    Uh, if you don't mind them becoming selected you can just do this: 

    1. fn CollectAllVertsOnlyInfluencedByBone skin_mod bone_index =
    2. (
    3. skinOps.SelectBone skin_mod bone_index
    4. skinOps.selectVerticesByBone skin_mod
    5. skinOps.GetSelectedVertices skin_mod
    6. )
    7.  
    8. verts = CollectAllVertsOnlyInfluencedByBone $.skin (skinOps.getSelectedBone $.skin)
    In Max 2018 and older you need to have the Skin Modifier showing in the Modify Panel. 
  • MrQuetch
    Offline / Send Message
    MrQuetch polycounter lvl 6
    monster said:
    Uh, if you don't mind them becoming selected you can just do this: 

    1. fn CollectAllVertsOnlyInfluencedByBone skin_mod bone_index =
    2. (
    3. skinOps.SelectBone skin_mod bone_index
    4. skinOps.selectVerticesByBone skin_mod
    5. skinOps.GetSelectedVertices skin_mod
    6. )
    7.  
    8. verts = CollectAllVertsOnlyInfluencedByBone $.skin (skinOps.getSelectedBone $.skin)
    In Max 2018 and older you need to have the Skin Modifier showing in the Modify Panel. 
    Hi, Monster.

    I apologize for the late reply. I'm using Max 2017. All of that code works except for, "skinOps.GetSelectedVertices". I get an exception error when I try and run it. The code isn't highlighted, either. Is there another way to get the selected bones with a custom function?

    Other than that - this is good. I appreciate it.
  • monster
    Offline / Send Message
    monster polycounter
    Huh, I guess they added that in 2019 as well as the other perf improvements to skin.
    You can use this function:

    1. fn getSelectedSkinVerticies skinMod =
    2. (
    3. local ss=#{}
    4. local count = skinOps.GetNumberVertices skinMod
    5. local isVertexSelected = skinops.isVertexSelected
    6.  
    7. ss[count] = false
    8. for v = 1 to count where (isVertexSelected skinMod v) == 1 do ss[v] = true
    9.  
    10. ss
    11. )
    12.  
    13. fn CollectAllVertsOnlyInfluencedByBone skin_mod bone_index =
    14. (
    15. skinOps.SelectBone skin_mod bone_index
    16. skinOps.selectVerticesByBone skin_mod
    17. getSelectedSkinVerticies skin_mod
    18. )
    19.  
    20. verts = CollectAllVertsOnlyInfluencedByBone $.skin (skinOps.getSelectedBone $.skin)
    21.  


  • MrQuetch
    Offline / Send Message
    MrQuetch polycounter lvl 6
    monster said:
    Huh, I guess they added that in 2019 as well as the other perf improvements to skin.
    You can use this function:

    1. fn getSelectedSkinVerticies skinMod =
    2. (
    3. local ss=#{}
    4. local count = skinOps.GetNumberVertices skinMod
    5. local isVertexSelected = skinops.isVertexSelected
    6.  
    7. ss[count] = false
    8. for v = 1 to count where (isVertexSelected skinMod v) == 1 do ss[v] = true
    9.  
    10. ss
    11. )
    12.  
    13. fn CollectAllVertsOnlyInfluencedByBone skin_mod bone_index =
    14. (
    15. skinOps.SelectBone skin_mod bone_index
    16. skinOps.selectVerticesByBone skin_mod
    17. getSelectedSkinVerticies skin_mod
    18. )
    19.  
    20. verts = CollectAllVertsOnlyInfluencedByBone $.skin (skinOps.getSelectedBone $.skin)
    21.  


    Thank you very much, Monster.

    I should consider looking into the newer version of Max at some point.

    It's nice that there are still ways of programming for older Maxscript. But, I'm beginning to see why it would be better to move on.
Sign In or Register to comment.