PDA

View Full Version : How to use the server() method to get a shader?



dballesg
09-09-2007, 11:43 AM
Hi,

I've been trying to use the server() method to find if a shader is applied to a surface.

From the docs, looks like the shaders are applied by object??¿¿ Not a very intuitive design.

So I tried this:




// Get the object ID where the surface belongs
tmp_obj = Mesh();

// Check if the processed surface has a shader
pserver = tmp_obj.server(SERVER_SHADER_H);



And ALWAYS returns nil in pserver. And yes, I have an scene with a shader applied to an object, I even debugged the script with that code and returns fine the OA of the object.

I need to know if I am using it wrong, or if it is bug.

If it is the second, it will trash a scritp of 2000 lines of code that it is working, but I really neeed to find wich shaders are applied to each surface.

David

Dodgy
09-09-2007, 04:21 PM
Have you tried it on the surface object agent?

dballesg
09-10-2007, 12:30 AM
Hi Dodgy,

Yes and always get the "invalid object method server()" :(

David

dballesg
10-08-2007, 01:05 PM
Hi,

Bumping this.

Any developers on the team out there that can give an explanation on how to use it, or at least confirm is a bug?

David

Jarno
10-08-2007, 09:27 PM
server() does not support getting of shader plugins (not in LScript, nor in the LWSDK). server() only works for plugins associated with an object (e.g. motion modifiers), or for plugins which have no association but are global (e.g. volumetrics). Shader plugins are associated with a particular surface. I think there is currently no way of querying what shader plugins are attached to a given surface.

---JvdL---

dballesg
10-09-2007, 01:36 AM
Hi Jarno,

Thanks for the info.

I was trying to create a "fake" shader that will store certain values and later through a Master LScript query wich surfaces got that shader applied and use comRing to get the values passed?

I was a crazy idea? Any suggestion on how can I do it with that fake shader?

Having a method that could query ANY type of plugin I think would be useful.

David

Jarno
10-09-2007, 02:26 AM
If those shaders are all on the same comring, you could have the master lscript send a "who is there?" message, to which all the existing shader instances reply. The master lscript then uses those replies to know what shaders are there.

---JvdL---

dballesg
10-09-2007, 02:36 AM
Thanks for the answer Jarno.

BTW a Shader doesn't know to which surface is applied right? In the same way you can not ask a surface which Shader is applied to it?

David.

Lightwolf
10-09-2007, 02:43 AM
BTW a Shader doesn't know to which surface is applied right?

It does:


The context argument to the create function is the LWSurfaceID for the surface. LWSurfaceID is defined in the lwsurf.h header file and is used by the surface functions global.

Cheers,
Mike

dballesg
10-09-2007, 04:14 AM
Hi Mike,

That is from the SDK point of view, what about LScript? :)

The only property I can see on a shader data member in LSCript is objID (from LScript Reference.pdf:

objID (READ-ONLY)
objID is a pointer to an Object Agent that represents the object being shaded.

So I can not find out I think which shader is applied to which surface, or which surface have certain shader applied.

David

Lightwolf
10-09-2007, 04:27 AM
Hi Mike,

That is from the SDK point of view, what about LScript? :)

I have no idea... why not write the shader as a plugin? ;)

Cheers,
Mike

dballesg
10-09-2007, 04:30 AM
Hi again Mike,

Because is part of the Indigo Exporter I am doing! :) And the idea of use fake shaders to collect the data of Indigo materials was given to me by.... (drums sound here) YOU ;)

Aside I got the exporter quite advanced until I stopped due I am looking to solve this in an elegant and easy way to do it for the user. And in fact I quite liked your idea! :)

David

ana027
10-12-2007, 05:20 PM
I don't know how is the sdk of lw but I believe that perhaps this exporter will make more easy with master script. No ¿?

At the moment I'm writing a procedural texture with Julia fractal and I can change the surface values with lscritp.

dballesg
10-13-2007, 10:56 AM
HI Ana,

The exporter IS a master script. The problem, It is I want to ask a surface WHICH shader has applied. So I can determine which Indigo material you applied to each surface. To do that I sue fake shaders wrote on LSCript as well.

The problem is that the server() method has not beign designed with that on mind, as Jarno pointed. looks like there is no way (yet I hope) to do it in this way.

Anyhow I'm still thinking on other ways to solve it.

David

ana027
10-13-2007, 12:46 PM
There is one thing, you can make the exporter with the objects, camera and a basic surface for all objects. After you can edit the xml file with the xml indigo editor to change the surface in the xml. The problem are the uv textures.

ana027
10-13-2007, 12:51 PM
Here is an example of the surface lscript, perhaps this little example can help you:


@version 2.5
@warnings
@script generic

objName = "Earth";
surfName = "GlobeSurface";

generic
{
// Create the Mesh Object Agent.
meshObj = Mesh(objName);

if(meshObj)
{
// Create the Surface Object Agent.
surfObj = Surface(surfName);

if(surfObj)
{
//Get some of the values.
colr = surfObj.getValue(SURFCOLR);
lumi = surfObj.getValue(SURFLUMI);
diff = surfObj.getValue(SURFDIFF);
spec = surfObj.getValue(SURFSPEC);
refl = surfObj.getValue(SURFREFL);
trans = surfObj.getValue(SURFTRAN);

// Display whichever values you want here.

info(colr);
}
else
error("This is not the ", surfName, " surface!");
}
else
error("This is not the ", objName, " object!");
}

Layout Commands

ana027
10-13-2007, 12:54 PM
Here is more docs about the surface objects:



Surface Object Agents




The Surface() constructor can generate an Object Agent for an existing surface, or it can create a new surface for an object. The constructor can be called with no arguments, and the first surface defined in the system will be returned.

surfObj = Surface();

If the Surface() constructor is called with an integer value, it returns the surface in the system that corresponds to that index value.

surfObj = Surface(1);

When you provide a surface name, the constructor returns that surface if it is already defined in the system. If it does not exist, a 'nil' value is returned under Layout, and a new surface with that name is generated for the current object under Modeler.

surfName = Surface("Surface Name");

Provided a Mesh Object Agent, the constructor returns a list of the surface names defined for that object.

meshObj = Mesh("cow");

surfNames = Surface(meshObj);

Under Layout, you can create a new surface for an object. You provide the Mesh Object Agent to receive the surface as the first argument, and the name of the surface as the second argument.

meshObj = Mesh("cow");

surfNames = Surface(meshObj, "New Surface");

Constants

The following channel constants have been defined in LScript for use with the Surface Object Agent:

SURFCOLR Base Color (vector)

SURFLUMI Luminosity (number)

SURFDIFF Diffuse (number)

SURFSPEC Specularity (number)

SURFREFL Reflectivity (number)

SURFTRAN Transparency (number)

SURFTRNL Translucency (number)

SURFRIND IOR (number)

SURFBUMP Bump (number)

SURFGLOS Glossiness (number)

SURFBUF1 Special Buffer 1 (number)

SURFBUF2 Special Buffer 2 (number)

SURFBUF3 Special Buffer 3 (number)

SURFBUF4 Special Buffer 4 (number)

SURFSHRP Diffuse Sharpness (number)

SURFSMAN Smoothing Angle (degrees)

SURFRSAN Reflection Seam Angle (degrees)

SURFTSAN Refraction Seam Angle (degrees)

SURFRBLR Reflection Blur (number)

SURFTBLR Refraction Blur (number)

SURFCLRF Color Filter (number)

SURFCLRH Color Highlights (number)

SURFADTR Additive Transparency (number)

SURFAVAL Alpha Value (number)

SURFGVAL Glow Value (number)

SURFLCOL Line Color (vector)

SURFLSIZ Line Size (number)

SURFSIDE Sidedness (integer)

SURFGLOW Glow (Boolean)

SURFLINE Render Outlines (Boolean)

SURFRIMG Reflection Image (Image OA)

SURFTIMG Refraction Image (Image OA)

SURFVCOL Vertex Coloring (number)

Data Members

name
name is the name of the surface.

Methods:

getValue(channel)
getValue(channel) returns the specific value setting for the channel (whose type is defined above).

getEnvelope(channel)
getEnvelope(channel) returns the Envelope Object Agent associated with the specified channel. If no envelope exists, getEnvelope() will return ‘nil.’

getTexture(channel)
getTexture(channel) returns the Texture Object Agent associated with the specified channel. If no texture exists, getTexture() will return ‘nil.’

Example:

This example demonstrates using the Surface Object Agents. You must load the "objects/geography/genearth/earth.lwo" object from the LightWave content into Layout in order for this example to work properly.

@version 2.5
@warnings
@script generic

objName = "Earth";
surfName = "GlobeSurface";

generic
{
// Create the Mesh Object Agent.
meshObj = Mesh(objName);

if(meshObj)
{
// Create the Surface Object Agent.
surfObj = Surface(surfName);

if(surfObj)
{
//Get some of the values.
colr = surfObj.getValue(SURFCOLR);
lumi = surfObj.getValue(SURFLUMI);
diff = surfObj.getValue(SURFDIFF);
spec = surfObj.getValue(SURFSPEC);
refl = surfObj.getValue(SURFREFL);
trans = surfObj.getValue(SURFTRAN);

// Display whichever values you want here.

info(colr);
}
else
error("This is not the ", surfName, " surface!");
}
else
error("This is not the ", objName, " object!");
}

Layout Commands

Surf_SetSurf \surfacename\\meshname\ or Surf_SetSurf \surfacename
This sets the surface in layout to be edited, where surface name is a string, the name of the surface to be selected, and meshname is the name of the mesh which that surface is a part of. The backslashes are necessary.

Surf_SetInt channel integer
This sets the surface in layout to be edited. The channel is one of the below in string form (EG Luminosity) and the integer is one of 0 (base colour), 1(envelope) or 2(texture).


I used these docs to write now my script of procedural surface.