Jump to content

Using a script to apply Normal and Specular textures


anselm Hexicola
 Share

You are about to reply to a thread that has been inactive for 1056 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I have been trying to do this with no success.

Here is what I wrote :-

integer linknum=2; //or whatever
integer face=3;  //or whatever

vector white=<1.0,1.0,1.0>;

string diffuse;
string normal;

default
{
   state_entry()
   {
	diffuse=llGetInventoryName(INVENTORY_TEXTURE,0); //let's assume I used my alphabet
	normal=llGetInventoryName(INVENTORY_TEXTURE,1); //ditto
		
	llSetLinkPrimitiveParams(linknum,
              [PRIM_TEXTURE,face,diffuse,<1,1,0>,ZERO_VECTOR,1.0,                        
               PRIM_NORMAL,face,normal,<10,10,0>,ZERO_VECTOR,1.0,
               PRIM_SPECULAR,face,TEXTURE_BLANK,<10,10,0>,ZERO_VECTOR,1.0,white,20,20]);

	}
}

 This does not set the appearance of my object in the same way that I can do manually via the Edit window.

  It does apply the ordinary (= diffuse) texture, but not the bump and shiny ones.

  I think I have used the right set of parameters for SLPP's, but maybe not.

 Can any of you manage to do this, and, if so, how?

  • Thanks 1
Link to comment
Share on other sites

That's exactly how I have done it, and it works like a dream.  The only differences I can see are that I have used stored texture UUIDs instead of applied textures from inventory and  I have applied a specular texture instead of TEXTURE_BLANK.  Otherwise, I have used exactly that same setup with success.

  • Thanks 1
Link to comment
Share on other sites

Yes, you are right as usual.

I wrote my post  away from my PC; and the included code snippet  was from memory. Consequently, it was misleading as to my problem.

The following shows it better, I hope.

integer linknum=2; //or whateverinteger face=3;  //or whatevervector white=<1.0,1.0,1.0>;string diffuse;string normal;default{   state_entry()   {	diffuse=llGetInventoryName(INVENTORY_TEXTURE,0); //let's assume I used my alphabet	normal=llGetInventoryName(INVENTORY_TEXTURE,1); //ditto			llSetLinkPrimitiveParams(linknum,	 [//PRIM_TEXTURE,face,diffuse,<1,1,0>,ZERO_VECTOR,1.0,                                    PRIM_NORMAL,face,normal,<10,10,0>,ZERO_VECTOR,1.0,            PRIM_SPECULAR,face,TEXTURE_BLANK,<10,10,0>,ZERO_VECTOR,1.0,white,20,20]);	}}

 [edited because I inadvertently "posted" before finishing my post!]

In other words, if the diffuse texture is not supplied in the SLPP's call (AND that face does not have a texture already*), then the Normal and Specularity maps do not get applied.

This is NOT the case using the Edit window. Here one can give these same Normal and Spec. textures to an untextured face: see screenshot ...

no diffuse.png

* this often is the case with say, a mesh upload

Link to comment
Share on other sites


anselm Hexicola wrote:

In other words, if the diffuse texture is not supplied in the SLPP's call (AND that face does not have a texture already*), then the Normal and Specularity maps do not get applied.

* this often is the case with say, a mesh upload

That's very interesting, and deserves a jira if confirmed. I can't get in to test this, but if I were reading a jira, I'd wonder: For those faces where this fails, what gets returned by llGetLinkPrimitiveParams(... PRIM_TEXTURE ...) -- the NULL_KEY ? And if so, can one render any already-textured face immune to specular and normal maps by re-painting it with a NULL_KEY diffuse texture? Or does it have to be virginal in some way?

Link to comment
Share on other sites

That is indeed odd, because every face does have a texture, by definition.  If you have not put a texture on it yourself, it has either TEXTURE_BLANK ("5748decc-f629-461c-9a36-a35a221fe21f") or TEXTURE_PLYWOOD ("89556747-24cb-43ed-920b-47caed15465f").  Unless I'm mistaken -- I could be -- newly rezzed uploaded mesh model has TEXTURE_BLANK.

Link to comment
Share on other sites

I made the following and put it in the linkset I showed in that screenshot (it was a wee bit small to see much, I admit!)

Then I clicked on the face concerned.

 

default{	state_entry()	{		llSay(0, "Hello, Avatar!");	}	touch_start(integer total_number)	{		integer linknum=llDetectedLinkNumber(0);		integer face=llDetectedTouchFace(0)				string applied_texture=llList2String(llGetLinkPrimitiveParams(linknum,[PRIM_TEXTURE,face]),0);		llOwnerSay("applied_texture is "+applied_texture);	}}

 

[Excerpt from my Chat log]

[12:14] prim cube: applied_texture is 5748decc-f629-461c-9a36-a35a221fe21f

 

(which is the key given by the LSL Portal for TEXTURE_BLANK)

Link to comment
Share on other sites

You wonder " Or does it have to be virginal in some way?"

..not sure if this is exactly what you are curious about, but what I found is this:-

If the relevant line is

 llSetLinkPrimitiveParams(linknum,              [PRIM_TEXTURE,face,,<1,1,0>,ZERO_VECTOR,1.0,                                       PRIM_NORMAL,face,normal,<10,10,0>,ZERO_VECTOR,1.0,               PRIM_SPECULAR,face,TEXTURE_BLANK,<10,10,0>,ZERO_VECTOR,1.0,white,20,20]);

 then it will not show materials UNTIL the object face has been given another diffuse texture ("scratched metal", whatever).

Running the code again will work now.  See below

no diffuse 2.png

Link to comment
Share on other sites

It might seem overly pernickety to be spending time looking at this little glitch. However ...

Consider this scenario (which was my own challenge.)

You make a multi-object mesh (whose constituent parts are such that together they make a seamless whole); for instance a missile casing or a chocolate Easter egg or anything that shatters into bits when Unlinked.

Now, applying a texture to the various faces of the uploaded linkset would be tricky and tedious with the Edit window. Scripts can in theory do the task better.

Also, it might be the case that a good visual result can be achieved without any Diffuse texture - just selective Colour tinting and application of  a Normal map.

Anyway ... here was what worked for me:-

 

llSetLinkPrimitiveParams(linknum,   [PRIM_TEXTURE,face,,<1,1,0>,ZERO_VECTOR,1.0,,face,mode,mask,	                            PRIM_NORMAL,face,normal,<10,10,0>,ZERO_VECTOR,1.0,    PRIM_SPECULAR,face,TEXTURE_BLANK,  <10,10,0>,ZERO_VECTOR,1.0,white,20,20]);llSleep(sec);
llSetLinkPrimitiveParams(linknum, [PRIM_TEXTURE,face,,<1,1,0>,ZERO_VECTOR,1.0, PRIM_NORMAL,face,normal,<10,10,0>,ZERO_VECTOR,1.0, PRIM_SPECULAR,face,TEXTURE_BLANK,<10,10,0>,ZERO_VECTOR,1.0,white,20,20]);

 

Basically, I found that if one wants to completely automate the texturing process (ie. not intervene with the Edit window), then one has to run the code twice - 1st time with any texture other than "TEXTURE_BLANK"; 2nd time with it.

Interestingly, it seems best to set the ALPHA_MODE (highlighted in blue above) on the 1st run-through.

  • Like 1
Link to comment
Share on other sites

I was only ever looking to get my own thing working - which I have now!

I have only a very vague idea of what a JIRA is; I looked it up on Wikipedia - the entry was terse and a bit above my head.

In the grand scheme of things, I doubt that this is worth pursuing any further other than noting that there does seem to be a work-around. (AND I would love it if you and other more experienced users of the SL/LSL tools could find a spare moment to confirm that my little bits of observation and code are indeed valid.)

Link to comment
Share on other sites

  • 6 years later...

I try to improve the script by combining the 3 areas texture,normal,specular.

I think this could be the ultimate hud.

 

RECEPTOR OBJECT

 

default
{
    
     state_entry()
    {
        llListen(-69,"",NULL_KEY,"");
    }
    

   listen(integer channel, string name, key id, string msg)
    {
         if (llGetOwner() == llGetOwnerKey(id))
         if (msg == "text1" )
         {
        llSetTexture("a3e061d1-c9b1-ce89-2de9-addc39506563", 2 );
        llSetTexture("77873a5d-ab44-ff8f-6a9a-d6087b5adb00", 3 );
        llSetTexture("77873a5d-ab44-ff8f-6a9a-d6087b5adb00", 1 );
        llSetTexture("77873a5d-ab44-ff8f-6a9a-d6087b5adb00", 4 );
        llSetPrimitiveParams([ PRIM_SPECULAR, ALL_SIDES, "3a97e824-fd26-1d9f-ffe7-00d0264e6631", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0, <0.275, 0.624, 0.832>, 51, 0]);
llSetPrimitiveParams([ PRIM_NORMAL, ALL_SIDES, "1ece3148-6cea-f9eb-2152-9902944dbc3d", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0 ]);
          }
           if (llGetOwner() == llGetOwnerKey(id))
         if (msg == "text2" )
         {
        llSetTexture("4c1f2066-861a-bce8-4d50-efa0a521a543", 1 );
        llSetTexture("80fce838-825b-a490-e17b-48f7dd51a6e8", 4 );
        llSetTexture("77873a5d-ab44-ff8f-6a9a-d6087b5adb00", 2 );
        llSetTexture("77873a5d-ab44-ff8f-6a9a-d6087b5adb00", 3 );
        llSetPrimitiveParams([ PRIM_SPECULAR, ALL_SIDES, "4dcc7f31-c8a7-6575-09ed-5fd8059534a7", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0,<1.000, 1.000, 1.000>, 51, 0]);
llSetPrimitiveParams([ PRIM_NORMAL, ALL_SIDES, "4c1751ad-b848-b230-1cc7-134c066df4c2", <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0 ]);
          }
    }
}

 

HUD BUTTONS  1

 

             
default{

    touch_start(integer total_number)
    {
           llSay(-69,"text1");
            

      }

}

HUD BUTTONS 2

             
default{

    touch_start(integer total_number)
    {
           llSay(-69,"text2");
            

      }

}

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1056 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...