PDA

View Full Version : Need to change luminosity on many objects per frame



nurbman
01-21-2009, 10:45 AM
I posted this on the Tips and Tricks but should have posted it here.

This will be my first try at writing a script and need confirmation that it's possible to do what I want. (and possibly some links to similar code) I'm on 9.5.

I want to be able to use a script to change the luminosity on a thousand objects to make them flash at random intervals depending on the frame number. Can this be done in a master lscript?

An example would be 100 columns of cubes, each column with 10 cubes high. (total of 1000 cubes)
The cubes are clones of one original and are cloned so that the cube's name has a number in it that will associate it with a column. (to make selection easier in the script)

I want to have a master (?) script do this:
-every 10 frames during an animation render:
-turn off all currently lit (luminosity ->0 from 100%) cubes
-light a random cube (luminosity -> 100%) in each column for 10 frames duration (only one cube per column)
-keep a list of lit cubes so that they can be turned off 10 frames later

Is there a way to get a single script to monitor and manipulate the objects' per frame settings in a scene without having to set up each object's properties with a script or expression? <-Which would be difficult since you need to make sure that only one per column is lit. I'd also prefer to have a single script manipulate 1000 objects than have 1000 scripts running in all the objects.

Thanks in advance.

xchrisx
01-21-2009, 02:04 PM
right off the bat i see a potential problem that you might run into. with all the objects being clones they all share 1 surface. that means you can only edit 1 surface (which will in turn affect all of them). you would either need them to be separate surfaces or maybe there is a way using ObjectID nodes in the node editor to accomplish this which (unfortunately i am not certain of it) in my opinion would just be a lot harder to accomplish.

nurbman
01-21-2009, 03:27 PM
You're right.
The surfaces are linked. When I change one's color manually, I change them all.
Another option would could be this:

Can I do the same thing but instead of changing the luminance, do object replacement, with a different object that has its luminance turned up to 100%? (same shape and size of object but one from a different file)
After 10 frames, the original object gets put back.

I can do this in a cloned object's Object Replacement field without affecting the other clones, but could it be done in an Lscript?

Thanks

nurbman
01-22-2009, 08:36 PM
Here's some crude code to give an indication of what I think should be possible.

Basically, while rendering, check if the current frame is one you want to do the swap in. If it is, cycle through the objects and pick one that you want to swap and swap it. (It would be much faster to just select an object based on a function that generates the name but this is just an example and should still work)

This code doesn't give any errors but doesn't do anything either when I render it. I assume it's because it's generic rather than master? (it won't run as master)


@version 2.3
@warnings
@script generic
@name TestReplace
// Three clones of Box001 in the scene.
// Box001 (1)
// Box002 (2)
// Box003 (3)

// Want to replace clone 1 with
// Box002.lwo which has 100% luminance for 10 frames

chgobj1 = "C:/Box001.lwo";
chgobj2 = "C:/Box002.lwo";
swapframe1 = 10;
swapframe2 = 20;


//scene = Scene();
create
{
setdesc(prog);
}

process: frame
{
thisframe = frame.newFrame;
switch(thisframe)
{
case swapframe1:
obj=Mesh();
i=1;
while(obj)
{
obj = obj.next();
i++;
if (string(obj.name) == "Box001 (1)")
{
obj.select();
ReplaceWithObject(chgobj2);
}
}

break;


case swapframe2:
obj=Mesh();
i=1;
while(obj)
{
obj = obj.next();
i++;
if (string(obj.name) == "Box001 (1)")
{
obj.select();
ReplaceWithObject(chgobj1);
}
}

break;
}
}

nurbman
01-25-2009, 04:10 AM
Can anyone give a hint as to why the above code doesn't work?

I would think it's something (in one form or another) that everyone would want to do all the time: script a change to an object, or property of one, at specific frames of an animation. (But I can't seem to find any examples for object replacement like this.)

Please ignore the "i" variables, it was a bit of Frankencode that I missed cleaning up.

Thanks

faulknermano
02-03-2009, 07:11 PM
do not use generic. use Object Replacement type script.

also you can use a shader script, but that may be harder.

nurbman
04-18-2009, 07:33 PM
Just to follow this up- I got it working. I can't post code today but here's how I did it.

The problem with cloned objects as mentioned above is that they share the same surface.

What I did was:

- create an extra object with 100% luminosity that would cover the one to be lit up and moved it with lscript.

- the movement would have to be instantaneous between frames so that it would disappear and reappear cleanly with no motion blur. A square wave envelope would do this but it would be tedious to manipulate for thousands of objects. (which there were: 28672 objects in groups of 128 x 16 x14 with 224 lights to move)

-the movement had to be scripted since it had to follow a random pattern.

-the random numbers can't be generated on the fly since the script is run more than once (non-deterministically, it seems) by the system as the frames advance (ack!). They are precomputed and read from an array instead. My first attempt ran the random number function to calculate position in the script in real-time which generated a swarm of position markers as the frame slider was moved - not good.

-code has to be used to keep track of which frame you are in and if the script has already been run. If it's been run, don't run again - it has to ratchet forward, only running once.

-the "light" object moves to the next object based on the object's "clone" number in it's name. Code has to pick an object based on a random number hashed to the object names. There were 224 lights to move but they were in separate locations and were cloned with their group. They all used the same lscript code and moved in relation to their original starting location.