is it possible to select faces base on vertex colour?

Discussions concerning programming of SOFTIMAGE©
User avatar
Pete
Posts: 118
Joined: 16 Jun 2009, 07:28

is it possible to select faces base on vertex colour?

Post by Pete » 16 Oct 2012, 03:23

Hi there,

Just wondering if anyone knows if it's possible to select faces based on vertex colour?

Thanks
Pete

EricTRocks
Moderator
Posts: 754
Joined: 25 Nov 2009, 00:41

Re: is it possible to select faces base on vertex colour?

Post by EricTRocks » 16 Oct 2012, 05:45

I believe you can however, the vertex color actually colors samples (usually 4 samples per vertex if the mesh is all quads, more or less with irregular geo). You'll have to get the average and if its above / below a certain tolerance then you'll have to add that vertex index to a list. Then after you iterate over all the vertices clear the selection and add the vertices from that list to the selection.
Eric Thivierge
Lead Kraken Developer, Fabric Engine
http://fabric-engine.github.io/Kraken

User avatar
Pete
Posts: 118
Joined: 16 Jun 2009, 07:28

Re: is it possible to select faces base on vertex colour?

Post by Pete » 16 Oct 2012, 07:40

Thanks Eric, but I think that sounds a little above my level. I'm not really even sure how to select a sample through scripting :)

iamVFX
Posts: 697
Joined: 24 Sep 2010, 16:28

Re: is it possible to select faces base on vertex colour?

Post by iamVFX » 16 Oct 2012, 07:53

Pete wrote:I'm not really even sure how to select a sample through scripting :)
Like so: http://procedural.tumblr.com/post/10642106975

EricTRocks
Moderator
Posts: 754
Joined: 25 Nov 2009, 00:41

Re: is it possible to select faces base on vertex colour?

Post by EricTRocks » 16 Oct 2012, 08:05

Well the sample is different than a point / vertex but the method iamVFX posted will get you close you just have to change the selection filter I believe.

Anywho, I dug up an old script that you can pick apart and tinker with to get you started:

Code: Select all

# Python
from win32com.client import constants as c
from win32com.client import Dispatch as d

xsi = Application
log = xsi.LogMessage
collSel = xsi.Selection

DEBUG = 0

def runMe():    
    oPickVertexMap = xsi.PickElement(c.siPropertyFilter, "Pick Vertex Map", "Pick Vertex Map")
    if oPickVertexMap("ButtonPressed") == 0:
        log("Command Cancelled", 4)
        return False
        
    oVertexMap = oPickVertexMap("PickedElement")
    if oVertexMap.Type != "vertexcolor":
        log("Picked Object is not a vertex color map. Command Cancelled.", 4)
        return False
        
    xsi.FreezeModeling(oVertexMap)
    
    oPickTgtPolys = xsi.PickElement(c.siPolygonFilter, "Pick Target Polygons", "Pick Target Polygons")
    if oPickTgtPolys("ButtonPressed") == 0:
        log("Command Cancelled",4)
        return False
    
    lTgtPolys = list(oPickTgtPolys("PickedElement").SubComponent.ElementArray)
    aVertexColors = list(oVertexMap.Elements.Array)
    
    collFacets = oVertexMap.Parent3DObject.ActivePrimitive.Geometry.Facets
    lFacets = [x for x in collFacets if list(x.SubComponent.ElementArray)[0] in lTgtPolys]
    for eachFacet in lFacets:
        lSamples = list(eachFacet.Samples.IndexArray)
        for intSampleIndex in lSamples:
            sRed = aVertexColors[0][intSampleIndex]
            sBlue = aVertexColors[1][intSampleIndex]
            sGreen = aVertexColors[2][intSampleIndex]
            
            log(str(sRed) + "," + str(sBlue) + "," + str(sGreen))
    
runMe()

Eric Thivierge
Lead Kraken Developer, Fabric Engine
http://fabric-engine.github.io/Kraken

User avatar
Pete
Posts: 118
Joined: 16 Jun 2009, 07:28

Re: is it possible to select faces base on vertex colour?

Post by Pete » 16 Oct 2012, 09:14

Hey thanks guys,
I'll see what I can do! I've never used python before but i'll see how i go.

Pete

EricTRocks
Moderator
Posts: 754
Joined: 25 Nov 2009, 00:41

Re: is it possible to select faces base on vertex colour?

Post by EricTRocks » 16 Oct 2012, 09:24

Lots of good resources out there for learning Python. Probably should compile a list and post it as a sticky thread. The main thing is actually learning the Softimage Object Model and then you can hack together small tools to speed up your normal workflow.

Good luck and post back your progress. Will help to share with others and this is a good place to ask for some help.
Eric Thivierge
Lead Kraken Developer, Fabric Engine
http://fabric-engine.github.io/Kraken

User avatar
Pete
Posts: 118
Joined: 16 Jun 2009, 07:28

Re: is it possible to select faces base on vertex colour?

Post by Pete » 16 Oct 2012, 09:26

Will do! Hopefully I get something going :)

User avatar
Hirazi Blue
Administrator
Posts: 5113
Joined: 04 Jun 2009, 10:15

Re: is it possible to select faces base on vertex colour?

Post by Hirazi Blue » 16 Oct 2012, 10:21

I can't guarantee this still works, but the "Vertex Color Tools" by Andrea Padovan (available still in the local backup at rray.de, even with a x64 version) sports a "Color to Selection" option, that might be useful in this case, as it gives the option to convert to a sample/point/edge/polygon selection. Specify Color and acceptable deviation, select what kind of components you want to select and press select.
;)
Stay safe, sane & healthy!

EricTRocks
Moderator
Posts: 754
Joined: 25 Nov 2009, 00:41

Re: is it possible to select faces base on vertex colour?

Post by EricTRocks » 16 Oct 2012, 10:34

Boo! Spoil the learning why don't you! :P
Eric Thivierge
Lead Kraken Developer, Fabric Engine
http://fabric-engine.github.io/Kraken

User avatar
Pete
Posts: 118
Joined: 16 Jun 2009, 07:28

Re: is it possible to select faces base on vertex colour?

Post by Pete » 17 Oct 2012, 07:41

Ha, thanks guys!
That add on is doing the job so it's kinda crushing my will to learn the python way :)
I did manage to get it to take notice of the samples that were within an alpha range I was looking for.