Page 2 of 4

Re: Move an object to the ground

Posted: 11 May 2016, 18:35
by Daniel Brassard
Which version of XSI do you have?

Re: Move an object to the ground

Posted: 11 May 2016, 18:38
by wireframex
2012 SP1 and 2015 SP2

Re: Move an object to the ground

Posted: 11 May 2016, 18:46
by Daniel Brassard
I am not in front of XSI at the moment. I'll see what I can whip up tonight.

Cheers!

Re: Move an object to the ground

Posted: 11 May 2016, 18:57
by FXDude
Martin Yara's M|Aligner seems to do very smilar things to the the tool you referenced, except also works with point + edges..

http://skymill.co.jp/tools/Softimage/mA ... gnerEN.htm


Image

Image

Perhaps you could then map some of those functions to keys? (copying commands from log)

Re: Move an object to the ground

Posted: 11 May 2016, 19:04
by wireframex
Daniel Brassard wrote:I am not in front of XSI at the moment. I'll see what I can whip up tonight.
Cheers!
Ok Thanks Daniel
FXDude wrote:Martin Yara's M|Aligner seems to do very smilar things to the the tool you referenced, except also works with point + edges..
Thanks Dude I know it it is a good tool but it is not what I am looking for

Re: Move an object to the ground

Posted: 11 May 2016, 22:50
by FXDude
Hum, indeed it seems to do everything except aligning objects by their bounding boxes.

Which I thought was say Y-Min, Y-Max, X-Min etc... ,
but those align the selected objects at their *centers* to... say the bottom-most object's center (Y-Min)
or at '0' (or other specified distance from world center)

It weird because the 'Equidistance between objects' considers object bounding boxes, so I would have though it wouldnt be a big stretch for alignments to also consider object boundaries...

So perhaps checking-out how selected objects boundaries are determined in the equidisytance bit, to perhaps allow aligning these objects as if their centers were at their bottoms, tops, or sides ?

It would make that tool even more awesome and complete! (and useful)

Perhaps also bringing it up to Martin as he is still around?
(Unlike Origin (Piotrek) who is quite unfortunately not)

Re: Move an object to the ground

Posted: 11 May 2016, 23:34
by AceMastermind
I am not a programmer but I managed to make this work. Here is a simple script based on what I was posting about earlier that will bring the bottom of an object's bounding box to Y=0, or the "ground".
You can drag this into a toolbar and make a script button, then select one object and run the script. :D

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")

Re: Move an object to the ground

Posted: 12 May 2016, 15:12
by Daniel Brassard
Hi all,

So I had a crack at it yesterday (designed the interface and some test code to check behaviour). The JScript test code below works for one object selected and takes into account the rotation or scaling of the object but it will not work for multiple objects selected. Somehow the bounding box average all selected objects and none of them goes to ground.

Maybe someone will see where I made a mistake in the code and correct me.

Here what I have so far (I have a bunch of LogMessage to check behaviour, that will ultimately be removed and the code cleaned up in the final code):

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);

}
And the code without the logmessage and tests

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);
}

Re: Move an object to the ground

Posted: 12 May 2016, 15:22
by Daniel Brassard
And the designs of the UI (if you are curious). It's a mokup that do nothing right now but will be modified with the correct code when I am satisfy with the code to execute after I solved the behaviour.

Cheers!

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;
   }

P.S. Does anybody know how to force the radio button in the AddEnumControl to be on the same row?

Re: Move an object to the ground

Posted: 12 May 2016, 16:41
by Daniel Brassard
OK, something to try ...

In the translate command, I put "null" in the inputObjs field. The translate default value is "selected objects" which would make sense to translate all the objects selected at once. I need to change that to oSelection(oItem) to forced it to only execute on the selected object that I want inside the loop.

To Test tonight.

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);
}

Re: Move an object to the ground

Posted: 12 May 2016, 17:47
by mc_axe
Awesome stuff Daniel! first script works fine! Keep it up!

Only one question does Rest on axis X, Y , Z means rest on YZ,XZ,XY planes?

Re: Move an object to the ground

Posted: 12 May 2016, 18:16
by Daniel Brassard
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.

Re: Move an object to the ground

Posted: 12 May 2016, 18:59
by FXDude
Pretty cool :-!
Daniel Brassard wrote:P.S. Does anybody know how to force the radio button in the AddEnumControl to be on the same row?
I don't think so for radiobuttons,
but perhaps with a more or less elaborate way, IconList controls (bmps with pressed states) work .
(SI radio buttons can easily be screenshot/cropped to 16x16 bitmaps)


http://softimage.wiki.softimage.com/sdk ... olIconList
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.

http://softimage.wiki.softimage.com/sdk ... ttons.htm#
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 );

Re: Move an object to the ground

Posted: 12 May 2016, 21:31
by wireframex
Good job Daniel :)
Daniel 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.
Good idea to change the sense label to above and below ground :)

Phil

Re: Move an object to the ground

Posted: 12 May 2016, 21:33
by wireframex
mc_axe wrote:Awesome stuff Daniel! first script works fine! Keep it up!
Yes
I'm very happy with it --> I put it already on a button :)

Re: Move an object to the ground

Posted: 12 May 2016, 22:40
by AceMastermind
Not working in Softimage Mod Tool 7.5, throwing this error:
Object doesn't support this property or method
on this line:

Code: Select all

var vba = new VBArray( oSelection(oItem).GetBoundingBox(oTransform) );


If Daniel doesn't fix this error in his, my "ground object" script works in 7.5 if anyone needs it:
http://www.si-community.com/community/v ... 819#p54819
:)