Color at Vertices from Clusters

85 views
Skip to first unread message

Francisco Criado

unread,
Aug 4, 2015, 12:34:10 AM8/4/15
to soft...@listproc.autodesk.com
Hi list!

As i never used vertex colors (shame on me) and now being in the situation of starting to use them frequently in our pipeline, got to ask, if there is any chance to create color at vertices from polygon clusters.
Any tip is more than welcome.

Francisco.



--
Sent from Gmail Mobile

Andreas Bystrom

unread,
Aug 4, 2015, 12:42:39 AM8/4/15
to soft...@listproc.autodesk.com
if I understood what you want to do correctly, you can rendermap directly into vertex colors, so if you have materials applied on your clusters (yuck) you can then rendermap that result.


Martin

unread,
Aug 4, 2015, 2:34:42 AM8/4/15
to soft...@listproc.autodesk.com
I think you need to explain it better because at least I don't know what do you want to do.

Do you want to bake a texture to v.color?
Do you want to define an specific color on vertices that are included in a poly cluster?
bake occlusion to specific clusters?

Martin
Sent from my iPhone

Francisco Criado

unread,
Aug 4, 2015, 7:24:32 AM8/4/15
to soft...@listproc.autodesk.com
Hi Martin,
yes indeed i would like to define cavs on vertices that are included in a polygon cluster, for exporting on my fbx after that.
The only method i found until now is painting cavs and thought that maybe if i already had clusters i could use that to create color at vertices.

thanks.

Francisco.

Francisco Criado

unread,
Aug 4, 2015, 7:25:59 AM8/4/15
to soft...@listproc.autodesk.com
Hi Andreas,

i'm going to try your method!  thanks for the tip.

Francisco.

Francois Lord

unread,
Aug 4, 2015, 9:24:13 AM8/4/15
to soft...@listproc.autodesk.com

Francisco Criado

unread,
Aug 4, 2015, 10:04:06 AM8/4/15
to soft...@listproc.autodesk.com
Hi Francois,

tried your script but drops error at line 14.

F.

--


Francois Lord

unread,
Aug 4, 2015, 11:55:28 AM8/4/15
to soft...@listproc.autodesk.com
uhhh... right...
it needs tools from the library.
line 14 can be replaced with those 4 lines:

from win32com.client import Dispatch
from win32com.client import constants as c
xsi = Dispatch('XSI.Application').Application
log = xsi.LogMessage


but line 15 cannot be replaced easily. It needs a package from our library.

Sorry.

Francois Lord

unread,
Aug 4, 2015, 11:59:17 AM8/4/15
to soft...@listproc.autodesk.com
Here is the file you need for line 15 to work. Put somewhere in your PYTHONPATH.

https://dl.dropboxusercontent.com/u/399522/TEMP/progressBar.py

Matt Lind

unread,
Aug 4, 2015, 6:51:09 PM8/4/15
to soft...@listproc.autodesk.com
Here's a variation of a tool I used in games production.
 
Works with multi-selections and will apply the color found in the polygon cluster’s PPG.  This allows you to choose your colors at will and as often as you like.  Just copy n’ paste this code into a file called “ML_VertexColorFromPolygonCluster.js” and drop into the ‘plugins’ folder of any workgroup to start using.  Will appear in Model/Animate/Render > [Get] Property > Map Paint Tools > ML VertexColor from PolygonCluster.  Can also be called from scripting.
 
You don’t want to use rendermap because it’ll have precision errors and result in color bleed in some tight spots or when there are polygon islands.
 
 
Matt
 
 
 
//-------------------start of script (JScript)-----------------------------------------------
//========================================================================================
// ML_VertexColorFromPolygonCluster()
//
// Transfers color from polygons in polygon cluster to vertex color property using cluster color.
//========================================================================================
 
//===================================================================
// Constants()
//===================================================================
function Constants()
{
    this.PRG        = "ML_VertexColorFromPolygonCluster";
    this.MENU_LABEL = "ML VertexColor from PolygonCluster";
}
 
//===================================================================
// XSILoadPlugin() - Registers plugin with XSI
//
//===================================================================
function XSILoadPlugin( oPluginRegistrar )
{
    var oConstants = new Constants();
   
    oPluginRegistrar.Author = "Matt Lind";
    oPluginRegistrar.Name   = oConstants.PRG;
    oPluginRegistrar.Email  = "";
    oPluginRegistrar.URL    = "";
    oPluginRegistrar.Major  = 1;
    oPluginRegistrar.Minor  = 0;
 
    oPluginRegistrar.RegisterCommand( oConstants.PRG, oConstants.PRG );
   
    oPluginRegistrar.RegisterMenu( siMenuTbGetPropertyMapPaintID, oConstants.PRG + "Menu", false, false );    // Model > [Modify] Component
   
    return( true );
}
 
//===================================================================
// XSIUnloadPlugin() - Removes plugin from XSI
//
//===================================================================
function XSIUnloadPlugin( oPluginRegistrar )
{
    return( true );
}
 
//===================================================================
// Menu_Init()
//
//===================================================================
function ML_VertexColorFromPolygonClusterMenu_Init( oContext )
{
    var oConstants = new Constants();
    var oMenu      = oContext.Source;
   
    // Event to call when user chooses tool from the interface
    oMenu.AddCallbackItem( oConstants.MENU_LABEL, oConstants.PRG + "Menu_OnClicked" );
}
 
//===================================================================
// Menu_OnClicked()
//
//===================================================================
function ML_VertexColorFromPolygonClusterMenu_OnClicked( oContext )
{
    var oConstants = new Constants();
   
    // Prompt user to pick inputs and outputs
    var aArguments = new Array();
    aArguments[0] = Selection;
 
    if ( aArguments == null ) {
        LogMessage( oConstants.PRG + " cancelled" );
        return( true );
    }
   
    // Launch the command
    var oCustomOperator = Application.ExecuteCommand( oConstants.PRG, aArguments );
   
    return( true );
}
 
//===================================================================
// Init() - Executed when command invoked 1st time after loading in XSI.
//
//===================================================================
function ML_VertexColorFromPolygonCluster_Init( oContext )
{
    var oCommand = oContext.Source;
   
    oCommand.Tooltip     = "Transfers color from polygons in polygon cluster to vertex color property.";
    oCommand.Description = oCommand.Tooltip + "  Colors derived from the polygon cluster property.";
    oCommand.ReturnValue = true;
   
    // Add arguments
    var oArguments = oCommand.Arguments;
 
    oArguments.AddWithHandler( "oSourceObjects", siArgHandlerCollection );
   
    return( true );
}
 
//===================================================================
// Term() - Executed when terminated.
//
//===================================================================
function ML_VertexColorFromPolygonCluster_Term( oContext )
{
    var oCommand = oContext.Source;
}
 
//==========================================================================
// main()
//
//==========================================================================
function ML_VertexColorFromPolygonCluster_Execute( oSourceObjects )
{
    var oPolygonMeshes = SIFilter( oSourceObjects, siPolyMeshFilter, true, siQuickSearch );
   
    if ( !oPolygonMeshes || oPolygonMeshes.Count <= 0 ) {
        LogMessage( "Invalid selection", siError );
        return(-1);
    }
   
    for ( var i = 0; i < oPolygonMeshes.Count; i++ ) {
   
        var oPolygonMesh = oPolygonMeshes(i);
       
        WriteColor( oPolygonMesh );
    }
   
    return(0);
}
 
//=========================================================
// WriteColor()
//
//=========================================================
function WriteColor( oPolygonMesh )
{   
    var oPolygons       = oPolygonMesh.ActivePrimitive.Geometry.Polygons;
    var oSampleClusters = oPolygonMesh.ActivePrimitive.Geometry.Clusters.Filter( "sample" );
    var oVertexColor    = null;
   
    // Look for existing vertex color clusterproperty
    for ( var i = 0; i < oSampleClusters.Count && !oVertexColor; i++ ) {
   
        var oSampleCluster = oSampleClusters(i);
        var oVertexColors  = oSampleCluster.Properties.Filter( "vertexcolor" );
       
        if ( oVertexColors.Count > 0 ) {
            var oVertexColor = oVertexColors(0);
        }
    }
   
    // Verify
    if ( !oVertexColor ) {
        if ( !oSampleClusters || oSampleClusters.Count <= 0 ) {
            var oSampleCluster = oPolygonMesh.ActivePrimitive.Geometry.AddCluster( siSampledPointCluster );
            oSampleCluster.Name = "SampleCluster";
        }
        // create vertex color clusterproperty
        var oVertexColor  = oSampleCluster.AddProperty( "Vertex color" );
        oVertexColor.Name = "PolygonClusterColors";
    }
   
    var oVertexColorData         = XSIFactory.CreateGridData();
    oVertexColorData.RowCount    = oPolygonMesh.ActivePrimitive.Geometry.Nodes.Count;
    oVertexColorData.ColumnCount = 4;
   
    //------------------------------------
    // Get polygons from polygon clusters
    //------------------------------------
    var oPolygonClusters = oPolygonMesh.ActivePrimitive.Geometry.Clusters.Filter( "poly" );
   
    for ( var i = 0; i < oPolygonClusters.Count; i++ ) {
   
        var oPolygonCluster = oPolygonClusters(i);
       
        // get polygon cluster color
        var aColor = new Array(
            ( oPolygonCluster.Parameters( "Red"   ).value / 255.0 ),
            ( oPolygonCluster.Parameters( "Green" ).value / 255.0 ),
            ( oPolygonCluster.Parameters( "Blue"  ).value / 255.0 ),
            1.0
        );
       
        var aPolygonIndices = ( oPolygonCluster.Elements.Array ).toArray();
       
        for ( var j = 0; j < aPolygonIndices.length; j++ ) {
       
            var PolygonIndex = aPolygonIndices[j];
            var oPolygon     = oPolygons( PolygonIndex );
            var oNodes       = oPolygon.Nodes;
           
            for ( var k = 0; k < oNodes.Count; k++ ) {
                oVertexColorData.SetRowValues( oNodes(k).Index, aColor );
            }
        }
    }
   
    oVertexColor.Elements.Array = oVertexColorData.Data;
   
    return(0);
}
//------------------------ end of script (JScript) ---------------------------------
 
 
 
 
 
 
 
Date: Tue, 4 Aug 2015 01:33:51 -0300
From: Francisco Criado <malcr...@gmail.com>
Subject: Color at Vertices from Clusters

Francisco Criado

unread,
Aug 5, 2015, 4:18:54 PM8/5/15
to soft...@listproc.autodesk.com
Hi guys!

thank you all for the different aproaches. Matt tried your Java script with and nothing happens, have any idea what may be?
Francois, i will try your script tonight and let you know how it goes :)
Thanks for everything guys.

F.




Matt Lind

unread,
Aug 5, 2015, 8:09:41 PM8/5/15
to soft...@listproc.autodesk.com
I tested my code and it works just fine here. Please make sure it is
installed correctly and functioning. If there are any errors in the script
log, post them here (other than "invalid selection" which is a user error).

Since you're dealing with vertex colors, make sure your viewport's display
options are set to display them. Sometimes they are overridden by materials
or turned off completely. An easy way to check is set shade mode to
'constant'.

Vertex colors are also subservient to materials. Each material can only
display a single vertex color property at a time and you must assign the
vertex color property to the material before it will appear in the viewport.
For trivial cases such as single material with single vertex color property,
Softimage will figure it out automatically. However, if the object has
multiple materials or multiple vertex color properties, you must select each
material (in the scene explorer), open it's PPG, navigate to the "OpenGL"
tab, and manually assign the vertex color property to the material via the
dropdown menu at the bottom of the PPG. If your object has multiple
materials, you'll need to repeat this process for each material on the
object (Yes, it's a complete pain-in-the-ass and a gripe of many game
developers). Multi-selection PPGs don't always work for this and has proven
to be flakey.

Finally, make sure you have assigned a color to your polygon cluster. By
default they'll render as grey or green. Test on a simple grid if necessary
by manually creating polygon clusters and assigning colors to them. Then
run the tool to verify the colors are written to the vertex color property.

If all the above is done correctly, you should only need to select the
polygon mesh object(s), run my tool, and voila!


Matt



Date: Wed, 5 Aug 2015 01:18:51 -0300
From: Francisco Criado <malcr...@gmail.com>
Subject: Re: Color at Vertices from Clusters
To: "soft...@listproc.autodesk.com"

-----Original Message-----
From: softimag...@listproc.autodesk.com
Sent: Tuesday, August 04, 2015 3:50 PM
To: soft...@listproc.autodesk.com
Subject: Softimage Digest, Vol 81, Issue 5

Send Softimage mailing list submissions to
soft...@listproc.autodesk.com

To subscribe or unsubscribe via the World Wide Web, visit
http://listproc.autodesk.com/mailman/listinfo/softimage
or, via email, send a message with subject or body 'help' to
softimag...@listproc.autodesk.com

You can reach the person managing the list at
softima...@listproc.autodesk.com

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Softimage digest..."


Today's Topics:

1. Re: Color at Vertices from Clusters (Matt Lind)


----------------------------------------------------------------------

Message: 1
Date: Tue, 4 Aug 2015 15:50:45 -0700
From: "Matt Lind" <spey...@hotmail.com>
Subject: Re: Color at Vertices from Clusters
To: <soft...@listproc.autodesk.com>
Message-ID: <COL129-DS6101D1AD...@phx.gbl>
Content-Type: text/plain; charset="utf-8"

Here's a variation of a tool I used in games production.

Works with multi-selections and will apply the color found in the polygon
cluster?s PPG. This allows you to choose your colors at will and as often
as you like. Just copy n? paste this code into a file called
?ML_VertexColorFromPolygonCluster.js? and drop into the ?plugins? folder of
any workgroup to start using. Will appear in Model/Animate/Render > [Get]
Property > Map Paint Tools > ML VertexColor from PolygonCluster. Can also
be called from scripting.

You don?t want to use rendermap because it?ll have precision errors and
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://listproc.autodesk.com/pipermail/softimage/attachments/20150804/0a80192b/attachment.html

------------------------------

_______________________________________________
Softimage mailing list
Soft...@listproc.autodesk.com
http://listproc.autodesk.com/mailman/listinfo/softimage


End of Softimage Digest, Vol 81, Issue 5
****************************************

Reply all
Reply to author
Forward
0 new messages