Re: particle instance direction constraint

Date : Tue, 11 Apr 2006 17:27:57 -0400
To : XSI(at)Softimage.COM
From : Kris Rivel <kris(at)krisrivel.com>
Subject : Re: particle instance direction constraint
Awesome, thanks Andy.  I'll try this and let you know how it works out.

Kris

Andy Nicholas wrote:
Hi Kris,

I've tried this and I think this should work.

Add an "Every N Frame" event to the particles, and set the event "value" to
zero so that the event triggers at every update. Set the event Action to
"Script" and on the Script tab, set the ScriptContext to "Per Particle".

You can then use something like this as your script:

//-----------------------------------------------------

var ppos = XSIMath.CreateVector3()
ppos.Copy(inParticle.Position);

var col = new ActiveXObject("XSI.Collection");
col.Items="Camera";
cam = col(0);
var campos = XSIMath.CreateVector3();
cam.kinematics.global.transform.GetTranslation(campos);
var xdir = XSIMath.CreateVector3();
var ydir = XSIMath.CreateVector3();
var zdir = XSIMath.CreateVector3();
ydir.Set(0,1,0);
zdir.sub(campos,ppos);
zdir.NormalizeInPlace();
xdir.cross(ydir,zdir);
xdir.NormalizeInPlace();
ydir.cross(zdir,xdir);
ydir.NormalizeInPlace();

var mat = XSIMath.CreateMatrix3();
mat.Set(xdir.x, xdir.y, xdir.z, ydir.x, ydir.y, ydir.z, zdir.x, zdir.y,
zdir.z);
var rot = XSIMath.CreateRotation();
rot.SetFromMatrix3(mat);
var angles = XSIMath.CreateVector3();
rot.GetXYZAngles(angles);

inParticle.Rotation = angles;

//-----------------------------------------------------


Obviously, you'll need to change the string "Camera" to whatever you need the particles to look at. This script points the z axis of the particle at the camera, so you might need to alter this to work with what you've got.

The other thing to note, is that you might get better performance if you use
an external script file, since you'll be able to move the
"XSIMath.CreateXXXXXX" and "new ActiveXObject" calls outside the update
function so they only get called once (just make sure you initialise the
objects properly).

Cheers

Andy




-----Original Message----- From: owner-xsi(at)Softimage.COM [mailto:owner-xsi(at)Softimage.COM] On Behalf Of Kris Rivel Sent: 10 April 2006 23:16 To: XSI List Server Subject: particle instance direction constraint

I'm looking to have all my particle instances point towards the camera. Can this be done? I have too many and can't plot them out as objects....I
need them to remain as particle instances. Any ideas?


Kris

---
Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body:
unsubscribe xsi


--- Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body: unsubscribe xsi



--- Unsubscribe? Mail Majordomo(at)Softimage.COM with the following text in body: unsubscribe xsi


Search the XSI List archives here or use the advanced search form to search across mailing lists. Searching help is available.
This site supposedly brought to you by Benjamin Grosser and the Imaging Technology Group.