PDA

View Full Version : Updating Mesh Changes constantly



dogzer
04-22-2008, 12:19 PM
Hi, i'm trying to code something that's able to handle an object's morph according to another object's position.
I managed to modify a morphmixer's value according to a null's position. But it doesnt update as I move the null.
First I put my code in newtime:


newtime: id, frame, time
{
currTime = time;
pos = SuperBola.getPosition(time);
morph2.setKeyValue(0,pos.x);
}

But it doesnt update very often, only when frames are procesed... So I tried putting my code in process. But still it didn't update, in fact, it was very slow.

Another thing that I noticed is that layout acted weird when I applyed my lscript plugin into the object's displacement panel. When I select another object, the screen doesnt update right away.

Basicaly I'd like to be able to move the null around and watch how the morph gets affected.

Where's my whole code:


@warnings
@version 2.3
@script displace
@name SuperBola v1.0

morph1;
morph2;
Morph1Name = "beso";
Morph2Name = "abre";
SuperBolaName = "SuperBola";
SuperBola;
currTime;

chlist = 1;

Channels;


create: da
{
SuperBola = Mesh(SuperBolaName);
group = ChannelGroup("boca");
morph1 = channelSearch(group,Morph1Name);
morph2 = channelSearch(group,Morph2Name);

}

newtime: id, frame, time
{
currTime = time;
pos = SuperBola.getPosition(time);
morph2.setKeyValue(0,pos.x);
}

process: da
{
pos = SuperBola.getPosition(currTime);
morph2.setKeyValue(0,pos.x);
}

options
{

reqbegin("SuperBola v1.0");

c1 = ctlpopup("Channels",chlist,Channels);
ctlposition(c1,0,0);

retrun if !reqpost();
reqend();
}


channelSearch: group, name
{
channel = group.firstChannel();

while(true)
{
if(channel != nil)
{
if (channel.name == name)
return channel;
}
else return 0;
channel = group.nextChannel();
}
}

evenflcw
04-23-2008, 08:39 AM
I'm not 100% sure about displacement plugins, but when dealing with motion modifiers you have to tell LW what items the modifier is dependant on. Only when these mentioned items are edited the modifier will reevaluate. This is essential for interactive plugins.

The function for this is effectedby(). It is not specified in the pdf manuals, only release docs and here:

http://www.mikegreen.name/Lscript/Source/Common_Commands.htm#effectedby

dogzer
04-23-2008, 09:03 AM
Hey, that worked perfectly! Even as a displacement plugin it worked.

There's still one more problem. When I apply the plugin, layout becomes a little weird... I select objects, and the screen doesn't update, I have to rotate the perspective view or change the time bar so the screen updates. It does select the object! but the screen doesnt updates. If I unselect the plugin layout works ok again. Any idea why that happens?

evenflcw
04-23-2008, 09:41 AM
Not a clue. If you can figure out under what exact states/circumstances this happens, you could look out for that in process() and call Refresh()/RefreshNow() or Redraw()/RedrawNow() to remedy it. Mind you, you should not be calling these all the time, as it might not be necessary and will slow LW down considerable if called all the time and also might kill the effects of other scripts/plugins.

Perhaps you could attach some code so others could try and see if it happens to them aswell?

dogzer
04-23-2008, 02:53 PM
@warnings
@version 2.3
@script displace
@name SuperBola v1.0

morph1;
morph2;
Morph1Name = "beso";
Morph2Name = "abre";
SuperBolaName = "SuperBola";
SuperBola;




create: da
{
SuperBola = Mesh(SuperBolaName);
effectedby(SuperBolaName);
group = ChannelGroup("boca");
morph1 = channelSearch(group,Morph1Name);
morph2 = channelSearch(group,Morph2Name);

}

newtime: id, frame, time
{
pos = SuperBola.getPosition(time);
morph2.setKeyValue(0,pos.x*2);
}

process: da
{

}

options
{
}


channelSearch: group, name
{
channel = group.firstChannel();

while(true)
{
if(channel != nil)
{
if (channel.name == name)
return channel;
}
else return 0;
channel = group.nextChannel();
}
}

That's my code.

I discovered that the line of code that causes the no screen redraw after I select a new object is morph2.setKeyValue(0,pos.x*2); that i put in the newtime function... I'm going to try to understand better how modifying channel keys work.

evenflcw
04-24-2008, 07:32 AM
First of all, move all the motion editing into the process callback (ie. both lines in newtime to process; and reinstate the currTime variable). Motion editing has no place in newtime. Imho newtime should be used for any "preprocessing" that you might need when time changes. Process should be used for what you really want to do. Try that first.

One could also argue that you shouldn't be using a Displacement Modifier for this at all as you really aren't doing any displacement in your script, but simply controlling that of another. In which case a custom object or a motion modifier might have been more appropriate. But I'd agree that it would make more sense to a user that it looks like a displacement modifier.

Is it also your intention to not be able to animate with this script but simply edit a single keyframe? Or are you just taking it one step at a time?

dogzer
04-24-2008, 09:13 AM
Yeah, i'm taking one step at a time, hehe. I'm still learning. My objetive is be able to handle an object morph's completely using lscript to rig all morhps to a single object's position. I want to create a simple to use rig for my morphs, in wich I have a null that controls all morphs.

I'd need a way to know if the null that control the morphs has been just changed, that way i can either create a new morph key in the current frame, only when the object is changed, right?
I could check in process if the current nulls position myself but if there is a predefined function for this it would be better!