Difference between revisions of "PRIM MATERIAL"

From Second Life Wiki
Jump to: navigation, search
m
m (<lsl> tag to <source>)
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{#if:
+
<onlyinclude>{{#if:
{{LSL_Constants/PrimitiveParams}}
+
 
 +
{{#vardefine:material_const|{{LSL Const|PRIM_MATERIAL|integer|2|c=Used to {{GetSet|{{{1|}}}|get|set|/}} the prim's material}}}}
 +
 
 +
{{#vardefine:p_material_desc|PRIM_MATERIAL_* flag}}
 +
 
 +
}}</onlyinclude>{{#if:
 +
 
 
}}{{LSL Constant
 
}}{{LSL Constant
 +
|inject-2={{LSL PrimitiveParam Categorize|Prim}}
 
|name=PRIM_MATERIAL
 
|name=PRIM_MATERIAL
 
|type=integer
 
|type=integer
 
|value=2
 
|value=2
 
|float=
 
|float=
<center><font size="3">[http://youtube.com/watch?v=6OXYO61kQCA Video tutorial about material]</font></center>
+
<center style="font-size:125%;">[http://youtube.com/watch?v=6OXYO61kQCA Video tutorial about material]</center>
 
<videoflash>6OXYO61kQCA</videoflash>
 
<videoflash>6OXYO61kQCA</videoflash>
 
|desc=Sets the prim material. Material does not affect mass, but does affect friction, bounce (elasticity), and collision sound. On a wood incline of 33 degrees, the example script below gave the following results:
 
|desc=Sets the prim material. Material does not affect mass, but does affect friction, bounce (elasticity), and collision sound. On a wood incline of 33 degrees, the example script below gave the following results:
  
 
{{{!}} class="sortable" {{Prettytable}}
 
{{{!}} class="sortable" {{Prettytable}}
{{!}}+ Table detailing maximum velocity and distance traveled down the incline.
+
{{!}}+ <font style="font-size:80%;">Table detailing maximum velocity and distance traveled down the incline.</font>
 
{{!}}- {{Hl2}}
 
{{!}}- {{Hl2}}
 
!Type
 
!Type
!Velocity
+
!Velocity <font style="font-size:80%;">({{HoverText|m/s|meters per second}})</font>
!Distance
+
!Distance <font style="font-size:80%;">({{HoverText|m|meters}})</font>
 
{{!}}-
 
{{!}}-
 
{{!}}[[PRIM_MATERIAL_STONE|Stone]]
 
{{!}}[[PRIM_MATERIAL_STONE|Stone]]
Line 46: Line 53:
 
{{!}}-
 
{{!}}-
 
{{!}}}
 
{{!}}}
|pa={{LSL Constant/List|i_front=[&#32;[[PRIM_MATERIAL]],&#32;|i_end=&nbsp;]
+
|pa={{LSL Constant/List|i_front=[&#32;{{#var:material_const}},&#32;|i_end=&nbsp;]
 
|text=When used with [[llSetPrimitiveParams]] & [[llSetLinkPrimitiveParams]]
 
|text=When used with [[llSetPrimitiveParams]] & [[llSetLinkPrimitiveParams]]
 
|i1_type=integer|i1_name=material
 
|i1_type=integer|i1_name=material
 +
|toc=llSetPrimitiveParams
 
}}
 
}}
|pb={{LSL Constant/List|i_front=[[llGetPrimitiveParams]]([&nbsp;[[PRIM_MATERIAL]]|i_end=&nbsp;]);|
+
|pb={{LSL Constant/List|i_front=[[llGetPrimitiveParams]]([&nbsp;{{#var:material_const}}|i_end=&nbsp;]);|
 
|r_front=Returns the list [&nbsp;|r_end=&nbsp;]
 
|r_front=Returns the list [&nbsp;|r_end=&nbsp;]
 
|text
 
|text
 
|r1_type=integer|r1_name=material
 
|r1_type=integer|r1_name=material
 +
|toc=llGetPrimitiveParams
 
}}
 
}}
 
|examples=
 
|examples=
<lsl>
+
<source lang="lsl2">// © 2008 by Karzita Zabaleta
// © 2008 by Karzita Zabaleta
+
 
// Author of Scripting Your World, Wiley, October 2008.
 
// Author of Scripting Your World, Wiley, October 2008.
  
Line 133: Line 141:
 
         }
 
         }
 
     }
 
     }
}
+
}</source>
</lsl>
+
 
|constants=
 
|constants=
 
{{!}}
 
{{!}}
Line 145: Line 152:
 
{{LSL DefineRow||[[changed]]|}}
 
{{LSL DefineRow||[[changed]]|}}
 
|location
 
|location
|cat1=Prim
+
|haiku={{Haiku|The prims we conjure|can have many qualities.|There's more than plywood?}}
|cat2=Collision
+
|cat1=Collision
|cat3
+
|cat2=Prim/Materials
 +
|cat3=Material
 
|cat4
 
|cat4
}}
+
|}}

Latest revision as of 15:42, 23 January 2015

Description

Constant: integer PRIM_MATERIAL = 2;

The integer constant PRIM_MATERIAL has the value 2

Sets the prim material. Material does not affect mass, but does affect friction, bounce (elasticity), and collision sound. On a wood incline of 33 degrees, the example script below gave the following results:

Table detailing maximum velocity and distance traveled down the incline.
Type Velocity (m/s) Distance (m)
Stone 0.453181 0.361655
Metal 5.475444 10.211180
Glass 6.483150 11.678304
Wood 2.154549 9.433724
Flesh 0.351543 0.188043
Plastic 4.502428 9.590952
Rubber 0.374964 0.187106

llSetPrimitiveParams

[ PRIM_MATERIAL, integer material ]
• integer material PRIM_MATERIAL_* flag

When used with llSetPrimitiveParams & llSetLinkPrimitiveParams

llGetPrimitiveParams

llGetPrimitiveParams([ PRIM_MATERIAL ]);

Returns the list [ integer material ]

• integer material PRIM_MATERIAL_* flag

Related Articles

Constants

material Flags Description Friction Restitution
PRIM_MATERIAL_STONE 0 stone 0.8 0.4
PRIM_MATERIAL_METAL 1 metal 0.3 0.4
PRIM_MATERIAL_GLASS 2 glass 0.2 0.7
PRIM_MATERIAL_WOOD 3 wood 0.6 0.5
PRIM_MATERIAL_FLESH 4 flesh 0.9 0.3
PRIM_MATERIAL_PLASTIC 5 plastic 0.4 0.7
PRIM_MATERIAL_RUBBER 6 rubber 0.9 0.9
PRIM_MATERIAL_LIGHT 7 light, DEPRECATED: Looks the same as [ PRIM_FULLBRIGHT, ALL_SIDES, TRUE ] 0.6 0.5

Functions

•  llSetPrimitiveParams
•  llSetLinkPrimitiveParams
•  llGetPrimitiveParams

Events

•  changed

Examples

// © 2008 by Karzita Zabaleta
// Author of Scripting Your World, Wiley, October 2008.
 
list gMaterialTypes = [
  "STONE",
  "METAL",
  "GLASS",
  "WOOD",
  "FLESH",
  "PLASTIC",
  "RUBBER"
];
 
vector   gHomePosition;
rotation gHomeRotation;
integer  gWaitCount = 0; 
float    gMaxVelMag;
integer  gPrimMaterial;
 
moveTo(vector origin, vector destination) {
    float dist = llVecDist(origin, destination);
    integer passes = llCeil( llLog(dist/10.0) / llLog(2.0) );
    integer i;
    list params = [PRIM_POSITION, destination];
    for (i=0; i<passes; i++) {
        params = (params=[]) + params + params;
    }
    // actually move the prim, now
    llSetPrimitiveParams(params);
}
 
returnHome()
{
    llSetStatus(STATUS_PHYSICS, FALSE);
    moveTo(llGetPos(),gHomePosition);
    llSetTimerEvent(0);
    llSetRot(gHomeRotation);
}
 
calculate_velocity()
{
    float velMag = llVecMag(llGetVel());
    if (velMag > gMaxVelMag) {
        gMaxVelMag = velMag;
    }
}
 
default
{
    state_entry() {
        gHomePosition = llGetPos();
        gHomeRotation = llGetRot();
    }
    on_rez(integer _n) {
        llResetScript();
    }
    touch_start(integer n) {
        gMaxVelMag = 0;
        llSetPrimitiveParams([PRIM_MATERIAL, gPrimMaterial]);
        llSetStatus(STATUS_PHYSICS,TRUE);
        llSetTimerEvent(0.1);
        llResetTime();
        gWaitCount=0;
        gPrimMaterial++;
        if (gPrimMaterial == 7 ) gPrimMaterial = 0;
    }
    timer() {
        calculate_velocity();
        gWaitCount++;
        if (gWaitCount > 100) { // 10 seconds
            string type = llList2String( gMaterialTypes, gPrimMaterial-1 );
            llOwnerSay(type+" reached maximum velocity of "+(string)gMaxVelMag+
                       " and traveled "+(string)llVecDist(llGetPos(), gHomePosition)+" meters.");
            returnHome();
        }
    }
}

Deep Notes

Search JIRA for related Issues

Signature

integer PRIM_MATERIAL = 2;

Haiku

The prims we conjure
can have many qualities.
There's more than plywood?