PDA

View Full Version : Adjust camera position with sliders (Lscript n00b)



VincentB
12-15-2010, 01:58 AM
Hi Guys,

After writing a quick modeler lscript for my colleague, I wanted to write a layout script to help smoothen the workflow. We have a huge scene with lots of objects, I want to write a script so I can move the camera towards a selected objected and with some sliders rotate around the object and adjust the camera position.

Right now I'm getting stuck at the very basics. I'm trying to get my rendercamera at the position of the selected object and use a slider control to vary the y-position of the camera. If I can get this to work, I'm confident in my math skills to get all the other controls to work as needed ;-)

Right now I have this bit of non-functional code:



@version 2.3
@warnings
@script motion
@name CameraControl

scene = Scene();
cutime = scene.currenttime;
fps = scene.fps;
frame = cutime*fps;
rendercam = scene.renderCamera(cutime);
campos = rendercam.getPosition(frame);
sly = 0.0

create
{
setdesc("Camera to Object");
}

process: ma, frame, time
{
// Get object position
pos = ma.get(ROTATION,cutime);
campos.x = pos.x;
campos.z = pos.z
campos.y = pos.y + sly;
}

options
{
reqbegin("Camera to Object");
c1 = ctlnumber("Rendercam, Y-position",camy);
return if !reqpost();

sly = getvalue(c1);
reqend();
}


Any help would be greatly appreciated, I don't know whether trying to controle the position of the camera while selecting an object is a problem?

Vincent

evenflcw
12-15-2010, 06:17 PM
Since you're using a motion modifier, selection is not an issue. But what you have to realize is that motion modifying will not alter any keys. Without keys how are you gonna store any animation? If you wish to create animation using this tool you will need to either create a new envelope or edit an existing envelope. (Read about channel and envelope agents in the docs).

Another issue is the horrendous implementation of the minislider controls in lscript, or rather the lack thereof. if you want it too look and feel proper, you have either build your own controls or hack some together using existing controls. And it still won't be perfect. Search the lscript forum for threads on how to create the minisliders you need by combining existing controls.

Below is code for an interactive slider (note the lack of float values). The panel is also non-modal, so you can have it open at all times.


@version 2.3
@warnings
@script motion
@name CameraControl


MAX = 100000000000;
MIN = -MAX;
cam_pos_offset;

create
{
cam_pos_offset = <0,0,0>;
setdesc("Camera to Object");
}

process: ma, frame, time
{
//get keyframed value
pos = ma.get(POSITION, time);

//add on our offset
pos += cam_pos_offset;

//lastly tell LW to apply the modified position
ma.set(POSITION, pos);
}

options
//this is the blueprint for a non-modal panel.
//we no longer fetch the user input only once using getvalue, but continually.
//instead of getvalue, we set up a ctlrefresh function that is called
//everytime the user plays with the control.
{
if(reqisopen())
reqend();

reqbegin("Camera to Object");
c1 = ctlminislider("Rendercam, Y-position", cam_pos_offset.y, MIN, MAX);

ctlrefresh(c1, "UpdateOnUserInput"); //links c1 to function UpdateOnUserInput

reqopen();
}

UpdateOnUserInput: value
//called when c1 is modified
{
cam_pos_offset.y = value;
}

VincentB
12-16-2010, 02:42 PM
Hi Dan,

Thank you so much for your reply! I'm not trying to create an animation (the motion script in the header has survived through a lot of experimentation with lscript). Your piece of code is really helpfull, I will search the forums about the minislider. From just reading the user guide, the slider implementation seemed ok but that's probably my newbie naivety ;-)

Thanks again for the reply.

Vincent

evenflcw
12-19-2010, 02:34 PM
Your welcome. Glad I could help some.