Re: Move an object to the ground
Posted: 11 May 2016, 18:35
Which version of XSI do you have?
unofficial SOFTIMAGE© community
https://si-community.com/community/
Ok Thanks DanielDaniel Brassard wrote:I am not in front of XSI at the moment. I'll see what I can whip up tonight.
Cheers!
Thanks Dude I know it it is a good tool but it is not what I am looking forFXDude wrote:Martin Yara's M|Aligner seems to do very smilar things to the the tool you referenced, except also works with point + edges..
Code: Select all
sel = Application.Selection(0)
Application.CreatePrim("Grid", "MeshSurface", "", "")
Application.SetValue("grid.Name", "tempGrid", "")
Application.SelectObj("tempGrid", "", True)
Application.AddToSelection(sel, "", True)
Application.Align("", "siY", "siAlignGMIDDLE", "siAlignGMIN", "siAlignGMIDDLE", "siAlignGMIDDLE", "siAlignFMIN", "siAlignGMIDDLE", False)
Application.DeleteObj("tempGrid")
Code: Select all
// Example using an input transform to preserve scaling and rotation
// Works in XSI v10.0 and up
var oSelection = Application.Selection;
for (var oItem = 0; oItem < oSelection.Count; oItem++ ) {
LogMessage (oSelection(oItem).Name) ;
oTransform = oSelection(oItem).Kinematics.Local.Transform ;
// find the bounding box
var vba = new VBArray( oSelection(oItem).GetBoundingBox(oTransform) );
var jsa = vba.toArray();
// Report the min and max
var minX = jsa[0];
var minY = jsa[1];
var minZ = jsa[2];
var maxX = jsa[3];
var maxY = jsa[4];
var maxZ = jsa[5];
var centerX = (minX + maxX)/2 ;
var centerY = (minY + maxY)/2 ;
var centerZ = (minZ + maxZ)/2 ;
var toGroundY = - minY;
LogMessage( "min:" + minX + ", " + minY + ", " + minZ ) ;
LogMessage( "max:" + maxX + ", " + maxY + ", " + maxZ ) ;
LogMessage( "center:" + centerX + ", " + centerY + ", " + centerZ ) ;
LogMessage( "toGroundY:" + toGroundY ) ;
Translate(oSelection(oItem), 0, toGroundY, 0, siAbsolute, siLocal, siObj, siY, null, null, null, null, null, null, null, null, null, 0, null);
}
Code: Select all
// Example using an input transform to preserve scaling and rotation
//
var oSelection = Application.Selection;
for (var oItem = 0; oItem < oSelection.Count; oItem++ ) {
// Calculate the local transform of the object to take into account the rotation and scaling
oTransform = oSelection(oItem).Kinematics.Local.Transform ;
// find the bounding box using X3DObject.GetBoundingBox
var vba = new VBArray( oSelection(oItem).GetBoundingBox(oTransform) );
var jsa = vba.toArray();
// calculate the ground translation to translate the object to ground
var toGroundY = - jsa[1];
// Translate the object to ground
Translate(oSelection(oItem), 0, toGroundY, 0, siAbsolute, siLocal, siObj, siY, null, null, null, null, null, null, null, null, null, 0, null);
}
Code: Select all
/* Script created by Daniel Brassard (2015)
This script is a mimic of the Rest On Ground tool in LW
Modify to your liking if you wish. Cheers!
This script should work with Softimage v10.0 (2012) and up
*/
// Rest On Ground
// Create a temporary custom property that will hold the user's choices
var oPPG = XSIFactory.CreateObject("CustomProperty")
oPPG.Name = "RestOnGround" ;
oPPG.AddParameter3( "RestAxis", siString, 1 );
oPPG.AddParameter3( "CenterX", siBool, true ) ;
oPPG.AddParameter3( "CenterY", siBool, true );
oPPG.AddParameter3( "CenterZ", siBool, true );
oPPG.AddParameter3( "Sense", siString, 1.0 );
oLayout = oPPG.PPGLayout
oLayout.AddGroup();
oLayout.AddRow();
aRestAxis = new Array ("X", 0, "Y", 1, "Z", 2 );
oLayout.AddEnumControl( "RestAxis", aRestAxis, "Rest Axis:", siControlRadio ) ;
oLayout.EndRow();
oLayout.AddItem( "CenterX", "Center: X Axis" ) ;
oLayout.AddItem( "CenterY", "Center: Y Axis" ) ;
oLayout.AddItem( "CenterZ", "Center: Z Axis" ) ;
oLayout.AddRow();
aSense = new Array ("Above +", 1.0 , "Below -", -1.0 );
oLayout.AddEnumControl( "Sense", aSense, "Sense:", siControlRadio );
oLayout.EndRow();
oLayout.EndGroup();
oLayout.AddRow();
oLayout.AddButton( "OK", "OK") ;
oLayout.AddButton( "Cancel", "Cancel");
oLayout.EndRow();
oLayout.Logic = OK_OnClicked.toString() + Cancel_OnClicked.toString() ;
oLayout.Language = "JScript" ;
InspectObj( oPPG,null,"Rest On Ground" );
function OK_OnClicked()
{
Logmessage ( RestAxis.value );
// Here a real plug-in would actually
// do the calculation
// Destroy the Custom Property (optional)
DeleteObj( PPG.Inspected ) ;
PPG.Close() ;
return;
}
function Cancel_OnClicked()
{
Logmessage ( "Cancelled by User" );
// Destroy the Custom Property (optional)
DeleteObj( PPG.Inspected ) ;
PPG.Close() ;
return;
}
Code: Select all
// Example using an input transform to preserve scaling and rotation
//
var oSelection = Application.Selection;
for (var oItem = 0; oItem < oSelection.Count; oItem++ ) {
// Calculate the local transform of the object to take into account the rotation and scaling
oTransform = oSelection(oItem).Kinematics.Local.Transform ;
// find the bounding box using X3DObject.GetBoundingBox
var vba = new VBArray( oSelection(oItem).GetBoundingBox(oTransform) );
var jsa = vba.toArray();
// calculate the ground translation to translate the object to ground
var toGroundY = - jsa[1];
// Translate the object to ground
Translate(oSelected(oItem), 0, toGroundY, 0, siAbsolute, siLocal, siObj, siXYZ, null, null, null, null, null, null, null, null, null, 0, null);
}
I don't think so for radiobuttons,Daniel Brassard wrote:P.S. Does anybody know how to force the radio button in the AddEnumControl to be on the same row?
siControlIconList - IconList
Similar to a siControlRadio, except each item is represented by a bitmap on the screen rather than by a text label. Only .bmp files are supported, and the filenames of these files are specified in the PPGItem.UIItems list.
Supported attributes are siUIColumnCnt, siUILineCnt, siUIColumnGap, siUILineGap, siUISelectionColor, and siUIUseSelectionIcon.
Icon Buttons
Icon button controls display a group of bitmap icons that the user can select along with an optional animation divot and an optional label. They are associated to an underlying parameter of any numeric type.
You create them using the PPGLayout.AddEnumControl method with the siControlIconList control type enum.Code: Select all
// 1D array of iconpath,value pairs var path = XSIUtils.BuildPath( Application.InstallationPath(siFactoryPath), "Application", "layouts", "bitmaps" ); var aListItems = new Array( path+"\\hairpanel.bmp", 0, path+"\\toolbar_highlight.bmp", 1, path+"\\weightpanel.bmp", 2 ); oLayout.AddEnumControl( "PanelPicker", aListItems, "Panel Picker", siControlIconList );
Good idea to change the sense label to above and below groundDaniel Brassard wrote:Hi mc_axe,
Yes, this is the LW mimic version of rest on ground. Y being rest on XZ plane (the ground). Myself I would re-label it so we understood which plane the object would rest (the ground would therefore be plane XZ) but in the translate scenario you go up or down on Y to bring your object on the ground so most of the time you would translate in Y, that is why it is coded that way (for now).
The other concept is "sense" which I don't get, I will probably re-label this "rest" .. above ground (+) or below ground (-).
I am open to suggestions to make it more intuitive to SI users.
Yesmc_axe wrote:Awesome stuff Daniel! first script works fine! Keep it up!
on this line:Object doesn't support this property or method
Code: Select all
var vba = new VBArray( oSelection(oItem).GetBoundingBox(oTransform) );