You are not logged in.
...but of course, 'they' can always just be wrong.
I am trying my hand at object scripting for the first time, and I'm actually really impressed with how powerful this can be and I'm thinking I should have gotten into it earlier. Unfortunately, virtually no AOI scripting information exists outside of the scripting documentation, which, although useful as a reference, provides little to no insight into more than the very basics of how to make a scripted object actually work. Almost immediately I stumbled upon two admittedly rather elementary problems which I nevertheless have not been able to solve on the basis of the scripting documentation and the online examples I could find. Namely:
1. Some of the textures I would like to use on scripted objects are procedural textures containing parameters. If I create an object with the intention of applying one of those textures to it, how do I set the values of those parameters? In other words, that thing where you go into the texture window and type in a number for one of the parameters...how do I make the script do that? I thought of the idea of getting the parameters and changing the minimum, maximum and default values all to the value I want, but it appears that all of those are final doubles and so I can't touch them. Where, then, is the variable representing that number you type into the parameter box? Note that I want to be able to do this for layered textures as well as simple textures, if the process happens to be any different.
2. I also want to create some objects and apply layered textures to them, and do various things to the layers, such as select a texture for each layer, change the mapping of that layer (scale, center, rotation, etc), change the parameters of that layer, and set the blending mode for that layer (in particular I want to set the blending mode to 'overlay' or 'overlay - bumps add'). So far, though, every layer I've applied appears to act as if it completely ignores my setting its blending mode, and always acts as if it is set to 'blend'. I haven't tried setting the layer fraction lower than 1 (partly because I don't know how), but I've compared the results of the script to the results of a layered texture manually constructed the way I want it and they are not the same.
So can anyone give me answers with regards to these two questions? If you only know the answer to one of them, that's fine, but I'd rather not that everyone concentrated on just one problem because I really do need both of them solved eventually. Also, please keep the thread open because knowing me I'll probably come up with some other stupid question before long and post it here too and I wouldn't want to make a whole new thread for it. Heck, if I posted a new thread for every stupid question I think up, I'd probably be banned for spamming.
Offline
To confirm -- you have seen the Scripting Tutorial?
[I think] I can answer Q1 quickly enough, since I've previously written a script utilizing that functionality:
Sphere sphObj = new Sphere(1,1,1);
ProceduralTexture3D procTex = script.getScene().getTexture("existingtexture");
sphObj.setTexture(procTex, procTex.getDefaultMapping(sphObj));
ConstantParameterValue hue = new ConstantParameterValue(0.7);
ConstantParameterValue offset = new ConstantParameterValue(1.5);
ConstantParameterValue cycle = new ConstantParameterValue(20);
TextureParameter[] texparams = sphObj.getParameters();
for (int tpit = 0; tpit < texparams.length; tpit++) {
// loop through parameters, searching for the ones we want
String ctexName = texparams[tpit].name;
if (ctexName.equalsIgnoreCase("hue"))
sphObj.setParameterValue(texparams[tpit],hue);// It's the *hue* parameter
else if (ctexName.equalsIgnoreCase("cycle"))// It's the *cycle* rate parameter
sphObj.setParameterValue(texparams[tpit],cycle);
else if (ctexName.equalsIgnoreCase("offset"))// It's the *offset* parameter
sphObj.setParameterValue(texparams[tpit],offset);
}
utrrrongeeb [Art] formerly amateurmodeller

Offline
Yes, I did read the tutorial. It had some good information about creating objects and applying uniform textures, but I didn't notice anything there about either texture parameters or layered textures.
That said, your technique seems to work. Thanks! I'm still not sure how I would take it and apply it to layered textures, though. You seem to be taking the object and looking for a parameter with a certain name, but with multiple textures you could have more than one parameter with the same name (because they're on different layers) that you want to set to different values. Is there any easy way to do this?
Offline
Have a look at the API and Peter's code. They are your best friends. Once you get acquainted you'll find everything you need. In your case, I'd what you get through getTexture() is a LayeredTexture. Look at the code, it says LayeredTexture is a placeholder for LayeredMapping. so use getDefaultMapping on the texture to get the LayeredMapping which, in turn, will return you textures through getLayers(). Etc.
Offline
I have the scripting documentation, as I mentioned, and I know about LayeredTexture, LayeredMapping, addLayer(), etc. In fact I have been able to make a layered texture and change the mapping properties (like scale and center) of individual layers. That which I have not been able to do is to get the layers to show in any mode but 'blend', and to set the parameter values for parameters of individual layers. In the second case the problem is that I can't easily extend utrrrongeeb's technique because he is searching for a parameter based on no more than its name and object and when using layered textures that is not sufficient precision. In the first case, one thing I should mention perhaps is that the behavior I have seen is also consistent with what I would see if only the top layer existed, so I should ask, is it possible that using the addLayer() function would overwrite an existing layer rather than creating a new one?
Offline
get the layers to show in any mode but 'blend'
Try yourLayerMapping.setLayerMode(int layerIndex, int mode); where mode is one of LayeredMapping.BLEND, LayeredMapping.OVERLAY_BLEND_BUMPS, and LayeredMapping.OVERLAY_ADD_BUMPS.
set the parameter values for parameters of individual layers
I'm not sure if yourLayerMapping.getLayerParameters(int layerIndex); is usable here -- I haven't tried it -- but it'd be worth a look.
utrrrongeeb [Art] formerly amateurmodeller

Offline
utrrrongeeb wrote:
Try yourLayerMapping.setLayerMode(int layerIndex, int mode); where mode is one of LayeredMapping.BLEND, LayeredMapping.OVERLAY_BLEND_BUMPS, and LayeredMapping.OVERLAY_ADD_BUMPS.
Yes, I've tried those. They don't seem to work. They also don't work even if I use their literal values (0, 2, 1). Either the layer mode is still being recognized as 'blend', or the system is not recognizing more than one layer (the top layer), I can't tell which.
For the record, I'm accessing the layer through using addLayer() and then for the 'which' I'm using getNumLayers()-1. I assumed this was the way they would be accessed if they were numbered like a normal array, but just to make sure I did try getNumLayers() and getNumLayers()-2 and both of them failed where the version above succeeded, so I seem to be on the right track there.
I'm not sure if yourLayerMapping.getLayerParameters(int layerIndex); is usable here -- I haven't tried it -- but it'd be worth a look.
Okay thanks, I'll take a look at it.
EDIT: Doesn't seem to work. Where [Object3D].getParameters() works okay, [LayeredMapping].getLayerParameters() seems to return something that results in a null pointer exception when I use [Object3D].setParameterValue(). Unless it's because I'm accessing the layer the wrong way?
Last edited by green_meklar (June 12, 2009, 10:54 am)
Offline
Forwarded to Sourceforge scripting forum :
http://sourceforge.net/forum/forum.php?forum_id=228117
Offline
No need for that! I'm probably just making some simple noob mistake due to a failure to understand the documentation. You know how 90+% of all bugs consistently turn out to be simpler than what you were expecting, right?
Another thing I should note though is that the version on my machine is 2.5, so if anything said by anyone here is applicable only to later versions, please make a mention of it.
Offline
Uh uh, it seems Peter has a godly status we common priests don't have. However, it seems appropriate for someone whose first thought after completing the ray tracer code was probably 'Fiat Lux'.
More seriously I think Peter will be willing to answer a question on layered texture, a powerful feature we seldom talk about (and maybe we'll get a lecture on how layered textures work, too).
Offline
First of all, upgrade to 2.7.2! 2.5 was released close to two years ago, and a lot of bugs have been fixed since then. It's possible you're running into one of them. Simply calling setLayerMode() should be all you need to do.
Regarding how to find the parameter you want, there are a few methods of LayeredMapping you should take a look at. getLayerBlendingParameter() returns the parameter for a particular layer's blending fraction. getLayerParameters() returns all the parameters for a particular layer.
If you still have problems after upgrading, could you post some code showing exactly what you're doing? Then I should be able to tell why it isn't working.
Peter
Offline
Uh uh, it seems Peter has a godly status we common priests don't have.
I know. He scares me. 
2.5 was released close to two years ago, and a lot of bugs have been fixed since then. It's possible you're running into one of them.
From what I've heard, the accepted thing to do in programming is to assume that any bug is your own fault, and subsequently exhaust every possibility along those lines, however remote, before daring to suggest that any blame be placed on the person who set up the system you're programming for. I'm no expert in any programming language, much less Beanshell which I haven't even used before at all, and I consider it far more likely that I've overlooked something than that anyone involved in setting up AOI 2.5 could have made an error like this and neglected to test it.
Regarding how to find the parameter you want, there are a few methods of LayeredMapping you should take a look at. getLayerBlendingParameter() returns the parameter for a particular layer's blending fraction. getLayerParameters() returns all the parameters for a particular layer.
Uh huh, but in utrrrongeeb's example he then simply called [Object3D].setParameterValue(). Not only does this by itself not seem to contain enough information to set a parameter on a layered texture, given that it contains no layer index while the TextureParameter[] array was acquired through specifying a layer index (indicating that a different array would be associated with each layer), it also doesn't seem to work in practice.
EDIT: As I suspected, I also couldn't make it work in either 2.6.1 (what I happened to have on my other machine) or 2.7.2. Here's the kind of thing I'm doing for parameters of single textures:
//where pobject is an Object3D, paramlist is a TextureParameter[], pname is a String and pvalue is a double:
texparam(pobject,paramlist,pname,pvalue)
{
for(nextp=0;nextp<paramlist.length;nextp++)
{
npname=paramlist[nextp].name;
if(npname.equals(pname))
{
pobject.setParameterValue(paramlist[nextp],new ConstantParameterValue(pvalue));
}
}
}
//where cobject is an Object3D, lm is a LayeredMapping and t_paint is a Texture:
addcolor(cobject,lm)
{
thiscolor=t_paint.duplicate();
lm.addLayer(thiscolor);
lm.setLayerMapping(lm.getNumLayers()-1,thiscolor.getDefaultMapping(cobject));
lm.setLayerMode(lm.getNumLayers()-1,2);
texparam(cobject,lm.getLayerParameters(lm.getNumLayers()-1),"Hue",0.5);
texparam(cobject,lm.getLayerParameters(lm.getNumLayers()-1),"Saturation",0.5);
texparam(cobject,lm.getLayerParameters(lm.getNumLayers()-1),"Lightness",0.5);
}Last edited by green_meklar (June 12, 2009, 11:00 pm)
Offline
green_meklar wrote:
I know. He scares me.
What, is it the fangs? I thought they were kind of cute! Hmph.
Uh huh, but in utrrrongeeb's example he then simply called [Object3D].setParameterValue(). Not only does this by itself not seem to contain enough information to set a parameter on a layered texture, given that it contains no layer index while the TextureParameter[] array was acquired through specifying a layer index (indicating that a different array would be associated with each layer), it also doesn't seem to work in practice.
The argument to setParameterValue() is a TextureParameter object, and that object contains a lot more information than just a name. It's up to you to figure out which TextureParameter object to use, but setParameterValue() will know which layer that corresponds to.
Regarding setLayerMode(), I see what the problem is. addLayer() adds the new layer as layer 0, not layer getNumLayers()-1. This is... um... perhaps not entirely intuitive. I thought it would make more sense that way, since the newly added layer would be the top one, but it is a little unconventional. What can I say? It seemed like a good idea at the time.
Maybe I should look into changing it...
Peter
Offline
What, is it the fangs? I thought they were kind of cute!
You mean like these?
Regarding setLayerMode(), I see what the problem is. addLayer() adds the new layer as layer 0, not layer getNumLayers()-1.
Hmm. I see. That would explain a lot, wouldn't it? I'll go try it after I post, and see if either of my problems is still there afterwards.
I thought it would make more sense that way
It makes a lot of sense in that it reduces the length and complexity of script code (not to mention avoiding an extra method call and integer operation), but I for one find it really counterintuitive. Could just be me, though. I'm not too used to the Java paradigm yet, still kind of a procedurally-minded guy.
EDIT: The layer modes appear to be working properly now when I used 0 instead of getNumLayers()-1. Thanks! For the life of me I still can't get the layered texture parameters to work, though. I feel like I've tried just about everything.
Last edited by green_meklar (June 13, 2009, 5:39 pm)
Offline
Thats... thats... so... cute!
Ok, how does this sound? I'll mark addLayer() as deprecated. Then I'll add a new method, insertLayer(), that lets you specify the position you want the new layer at. And it will also let you specify the TextureMapping and blending mode at the same time.
Peter
Offline