PDA

View Full Version : Object replacement in a specific frame - possible in Lscript?



nurbman
01-25-2009, 06:24 PM
Here's some code that sort of works but has the following problems.

-It goes to frame 10 and replaces the Box1 (1) and also replaces the next clone because it was renamed to Box (1) when the first switch was made.

-The bigger problem is that the object switch is retroactive. It swaps the objects through the whole timeline. Even if I set keys at frames 0, 10, 20, 30 etc.
It renders as if the object was swapped at frame 0.

I haven't looked at master class scripts. Is there a way to set this up so that objects are replaced during specific frames of an animation? This shouldn't be as hard as it seems, or is it?

Thanks


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


@version 2.3
@warnings
@script generic
@name TestReplace

generic

{

Scene();


// Three clones of Box001 in the scene.
// Box1 (1)
// Box2 (2)
// Box3 (3)

// Want to replace clone 1 Box (1) with
// Box2.lwo which has 100% luminance, for 10 frames

chgobj1 = "C:/Box1.lwo";
chgobj2 = "C:/Box2.lwo";


TimeVar = Scene().currenttime;
FrameSpeedVar = Scene().fps;

FrameVar = TimeVar * FrameSpeedVar;


GoToFrame(FrameVar + 10);

myobj=Mesh();
while(myobj)
{

strvar = myobj.name;
if (string(strvar) == "Box1 (1)")
{
myobj.select();
ReplaceWithObject(chgobj2);
}
myobj = myobj.next();
}



GoToFrame(FrameVar + 20);

myobj=Mesh();
while(myobj)
{

strvar = myobj.name;
if (string(strvar) == "Box2")
{
myobj.select();
ReplaceWithObject(chgobj1);
}
myobj = myobj.next();
}

}

Sorry, the code indentation markup isn't working for some reason.

evenflcw
01-25-2009, 06:35 PM
There is a specific plugin/script class for this. You'll find chapters covering it in both the LScript User- aswell as Reference Manual.

nurbman
01-25-2009, 08:31 PM
Do you mean the Replacer.LS (Changer v1.01)? Hmmm. I was going to write that it wouldn't work because it has to be put in each object's properties box, but you got me thinking....

I was hoping to be able to run a single piece of code that can pick an object and replace it for a few frames while rendering. (or have the script set it up to render that way) That's what scripting should be able to do. I would have thought that this would be the main thing Lscript would facilitate. Maybe there's another way using Master Class scripts at render time but this might work also.....

Sort of like:
-every 10 frames, a modified Changer script with no user input, looks at an array read from disk to see if it's their turn to do an object replacement. They would calculate whether or not they do it based on their own name.
I originally thought that there didn't seem to be any way for them (hundreds of scripts in properties boxes) to use a shared variable or communicate, but being able to read a file from disk with all the times pre-computed would work just as well.

All I'm trying to do is have some objects blink on and off (lights or luminance changes) but I need to be able to control the blinking in a specific sequence, and have it apply to hundreds of objects where the blinking is related and not toally random but random in certain spots. (like have three columns of 10 lights blinking randomly in each column - random blinking but no column has more than one light on at a time)

Sound possible?

evenflcw
01-25-2009, 11:07 PM
I don't know what "Replacer.LS (Changer v1.01)" is, but you should be able to assign and unassign an object replacement script just like you can any other script via Apply- and RemoveServer commands, so no need to do that manually for 100 items. Furthermore, this could be handled entirely by a master script, which on scene load would apply the replacement script, and on scene close would remove it (or somesuch). All plugin data is stored and managed by the master.

Indeed, if you want to control multiple entities (items, surfaces or whatever) from one place, a master script is the proper thing to use, but in conjunction with whatever you want to be editing, ie motion mod for motion, displacement mod for displ etc. The master script will manage everything whereas the object replacement/motion mod/displ mod etc will get the job done (properly). Communications can be done via file, comring or globalstore.

Mind you, I don't think commands can be envoked when network rendering, which would be the main reason to use the object replacement class rather than just issuing commands through a master. If there is a way to edit a property without invoking a command it is the way you should prefer imho.

But I'm not 100% sure what it is you want to do and building stuff like this isn't something you should attempt at your first go at LScript. If you're unsure, I'd start with the Master only version, which you seem to already have your head wrapped around - it will still allow you to implement the "business logic" of the system - and this can be reused later if you decide to change the implementation (using for example the server-client/master-slave approach as described above).

PS. Hopefully I am making some sense and you atleast get some ideas from my ramblings. :)

nurbman
01-26-2009, 12:23 AM
The Replacer.LS (Changer v1.01) script is on P.91 of the Lscript User manual. (the one with the 2002 copyright date) I have the PDF with the updates to 2.8 but haven't gotten through it yet.
I'll look into the Apply and RemoveServer commands. I hadn't thought about using a script to apply other scripts. That sounds interesting.
I probably won't be network rendering but the limitations you mentioned are good to know in case I have to.

If I can do the example I posted, 3 columns of 10 cubes randomly blinking (or changing color or luminance) but only one per column at a time, I'll be able to do what I want. (illustrate hundreds of computer registers in operation)

Thanks for your help. I'll try a few things and post them if they work.

xchrisx
01-26-2009, 01:46 PM
have you thought about perhaps using a dissolve instead of object replacement?

nurbman
01-26-2009, 05:21 PM
Any other possibilities are welcome. How would a dissolve be set up? Can a dissolve expose an underlying light or bright color?

That brings up an interesting strategy...Can you shoot randomly positioned particles in sequence so that they trigger a dissolve or color change when close to an object? Can you shoot particles one at a time, randomly spread over a flat 2d area? (to randomly hit the faces of several stacked cubes)

If so, no calculations would be needed, just the ability to randomly shoot particles at the things you want to light up. The objects themselves keep track of particles and if they are close enough, a change is triggered. As long as only one particle goes by every 10 frames, only one object lights up at a time.
Is this do-able? It would be really cool if it was.

xchrisx
01-26-2009, 09:35 PM
Actually I was referring to the render options for the specific object. Dissolve allows you to control the visibility of an object during render time.
In layout:
object properties > render > object dissolve press the E button. Click on that and set your keyframes for 0% to 100%. 100% is fully transparent.