Orient instance to camera

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
  11 November 2012
Orient instance to camera

Hi all,

can anyone help with orienting my instanced geometry to camera, like you get when using sprites (shown in green on the attached scene), whilst also maintaining the aim direction of velocity. I guess I need to use an expression on something like Aim Up Axis to point them to camera?

Scene attached.

Attached Files
File Type: zip instancer_test.mb.zip (37.2 KB, 5 views)
  11 November 2012
Alternatively, how do you get sprites to twist in the direction of travel (aim direction = velocity) on a path when using curve flow?


Last edited by wizlon : 11 November 2012 at 04:07 PM.
  11 November 2012
Try setting the up vector == to velocity and the aim vector == to camera position.
  11 November 2012
Are you saying set - Aim World Up from the Instancer (Geometry Replacement) Rotation Options rollout to Velocity and Aim Direction to Camera Position?

Camera Position doesn't exists in the list and I don't know how to add these on a per particle basis.
  11 November 2012
to get an aim vector to camera for each particle you do

particleShape.position - camera.position

you can get camera position by doing xform -q on the camera. im not at my work computer so cant show the right code but it would be something like....

vector $camXpos = `xform -q -xyz camera1`;

vector $myCamAimVector = particleShape1.position - $camXpos;

not sure if syntax is correct but it's along those lines.
  11 November 2012
Thanks Daniel.

Trawling through some old posts yesterday ( http://forums.cgsociety.org/showthr...nce+face+camera)

I found this code:

$camPos=`xform -q -ws -t camera1`;
particleShape1.aim = $myVector;

and followed these instructions:

- create new particlePP vector attribute, called "aim" (i would rather call it aimPP)
- in particleShape atribute editor right click on the field beside aim atribute and choose
runtime expression before dynamics
- then write the expression wich Bonedaddy has posted and hit create
-than go into instancer (geometry replacement) in atribute editor under particleShape
-go to rotation options and choose aim or aimPP (whathever u have name it) for aim direction

it didn't work.

I'll try your code later and see if I can get it working.


  11 November 2012
That wont work either. My code is doing the same thing but you need to do one thing to make it work which I can see looking at the code.

xform returns an array and you need to convert it to a vector to make it subtractable from another vector.

So you do something like this....

$myCamArray = `xform blah blah blah`;
//returns array [x, y, z]. now convert to vector.....

$myCamVector = <<$myCamArray[0], $myCamArray[1],$myCamArray[2]>>;

then you can go and do the subtact thing. Also I dont think you have to cast myVector into aimPP. You can set the instancer to directly read the first vector.
  11 November 2012
Thanks for helping with this Daniel.

I know I'm asking a lot, but could you possibly apply your code to the first scene I posted 'Instancer Test' so I can pick it apart and learn from it. This is so far away from my comfort zone as a Lighter, I need all the help I can get.


  11 November 2012
I think you have enough to do it yourself. If I do it for you then you wont learn anything!

It's very simple if you break it down into steps. here's the psuedocode..

1) float $myCamArray[] = `xform camera translate`
2) vector $myCamVector = << $myCamArray[0], $myCamArray[1], $myCamArray[2]>>;
3)vector $partPos = particle position;
4)vector $aimVector = $partPos - $myCamVector;

Have another go. Being outside of your comfort zone is the best way to learn. If you really can't do it then send me what you got up to and I can check that. I hope this comes accross as intended in trying to be helpful.
  11 November 2012
Agreed Daniel. Trial and error is a great way to learn. With expressions I usually find it is something so simple between working and broken, a missing bracket or ; I wish I did much more of this stuff.

I'll give it my best shot and post the scene later.

  11 November 2012
with much help from my colleague we (he) arrived at this:

//get camera position as float array and cast into vector
float $camPos[] =`xform -q -a -ws -t camera1`;
vector $camVector = <<$camPos[0], $camPos[1], $camPos[2]>>;

//get particles position in world space as a vector
vector $particlePos=particleShape1.position;

//calculate the new vector which points to camera
vector $aimToCamera = $particlePos - $camVector;

//feed the new vector into the particles aimPP attribute
particleShape1.aimPP = $aimToCamera;

Thanks again for all your help.
  11 November 2012
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 05:14 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.