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:
    fn CollectAllVertsOnlyInfluencedByBone skin_mod bone_index =
    (
        num_verts = skinOps.GetNumberVertices skin_mod;
        for v = 1 to num_verts  where skinOps.GetVertexWeightCount skin_mod v == 1 and 
            skinOps.GetVertexWeightBoneID skin_mod v 1 == bone_index collect v;
    )    

Replies

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

    fn CollectAllVertsOnlyInfluencedByBone skin_mod bone_index =
    (
    	skinOps.SelectBone skin_mod bone_index
    	skinOps.selectVerticesByBone skin_mod
    	skinOps.GetSelectedVertices skin_mod
    )
    
    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: 

    fn CollectAllVertsOnlyInfluencedByBone skin_mod bone_index =
    (
    	skinOps.SelectBone skin_mod bone_index
    	skinOps.selectVerticesByBone skin_mod
    	skinOps.GetSelectedVertices skin_mod
    )
    
    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:

    fn getSelectedSkinVerticies skinMod =
    (
    	local ss=#{}
    	local count = skinOps.GetNumberVertices skinMod
    	local isVertexSelected = skinops.isVertexSelected
    
    	ss[count] = false
    	for v = 1 to count where (isVertexSelected skinMod v) == 1 do ss[v] = true
    
    	ss
    )
    
    fn CollectAllVertsOnlyInfluencedByBone skin_mod bone_index =
    (
    	skinOps.SelectBone skin_mod bone_index
    	skinOps.selectVerticesByBone skin_mod
    	getSelectedSkinVerticies skin_mod
    )
    
    verts = CollectAllVertsOnlyInfluencedByBone $.skin (skinOps.getSelectedBone $.skin)
    
    


  • 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:

    fn getSelectedSkinVerticies skinMod =
    (
    	local ss=#{}
    	local count = skinOps.GetNumberVertices skinMod
    	local isVertexSelected = skinops.isVertexSelected
    
    	ss[count] = false
    	for v = 1 to count where (isVertexSelected skinMod v) == 1 do ss[v] = true
    
    	ss
    )
    
    fn CollectAllVertsOnlyInfluencedByBone skin_mod bone_index =
    (
    	skinOps.SelectBone skin_mod bone_index
    	skinOps.selectVerticesByBone skin_mod
    	getSelectedSkinVerticies skin_mod
    )
    
    verts = CollectAllVertsOnlyInfluencedByBone $.skin (skinOps.getSelectedBone $.skin)
    
    


    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.