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 <[email protected]>
Subject: Re: Color at Vertices from Clusters
To: "[email protected]"
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.
-----Original Message-----
From: [email protected]
Sent: Tuesday, August 04, 2015 3:50 PM
To: [email protected]
Subject: Softimage Digest, Vol 81, Issue 5
Send Softimage mailing list submissions to
[email protected]
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
[email protected]
You can reach the person managing the list at
[email protected]
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" <[email protected]>
Subject: Re: Color at Vertices from Clusters
To: <[email protected]>
Message-ID: <[email protected]>
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
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 <[email protected]>
Subject: Color at Vertices from Clusters
To: "[email protected]"
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://listproc.autodesk.com/pipermail/softimage/attachments/20150804/0a80192b/attachment.html
------------------------------
_______________________________________________
Softimage mailing list
[email protected]
http://listproc.autodesk.com/mailman/listinfo/softimage
End of Softimage Digest, Vol 81, Issue 5
****************************************