add suport for materials parameters PRIM_NORMAL, PRIM_SPECULAR and PRIM_ALPHA_MODE of llGetPrimitiveParams(). Im sleeping at this time, this can be very wrong

httptests
UbitUmarov 2017-04-24 07:06:48 +01:00
parent 65a1547209
commit c91e101224
2 changed files with 170 additions and 0 deletions

View File

@ -28,6 +28,7 @@
using System;
using System.Collections.Generic;
using OpenMetaverse;
using OpenMetaverse.StructuredData;
using OpenSim.Framework;
namespace OpenSim.Region.Framework.Scenes
@ -90,6 +91,87 @@ namespace OpenSim.Region.Framework.Scenes
else
return 0;
}
}
public class FaceMaterial
{
public UUID ID;
public UUID NormalMapID = UUID.Zero;
public float NormalOffsetX = 1.0f;
public float NormalOffsetY = 1.0f;
public float NormalRepeatX = 0.0f;
public float NormalRepeatY = 0.0f;
public float NormalRotation = 0.0f;
public UUID SpecularMapID = UUID.Zero;
public float SpecularOffsetX = 1.0f;
public float SpecularOffsetY = 1.0f;
public float SpecularRepeatX = 0.0f;
public float SpecularRepeatY = 0.0f;
public float SpecularRotation = 0.0f;
public Color4 SpecularLightColor = new Color4(255,255,255,255);
public Byte SpecularLightExponent = 51;
public Byte EnvironmentIntensity = 0;
public Byte DiffuseAlphaMode = 1;
public Byte AlphaMaskCutoff = 0;
public FaceMaterial()
{ }
public FaceMaterial(UUID pID, OSDMap mat)
{
ID = pID;
if(mat == null)
return;
float scale = 0.0001f;
NormalMapID = mat["NormMap"].AsUUID();
NormalOffsetX = scale * (float)mat["NormOffsetX"].AsReal();
NormalOffsetY = scale * (float)mat["NormOffsetY"].AsReal();
NormalRepeatX = scale * (float)mat["NormRepeatX"].AsReal();
NormalRepeatY = scale * (float)mat["NormRepeatY"].AsReal();
NormalRotation = scale * (float)mat["NormRotation"].AsReal();
SpecularMapID = mat["SpecMap"].AsUUID();
SpecularOffsetX = scale * (float)mat["SpecOffsetX"].AsReal();
SpecularOffsetY = scale * (float)mat["SpecOffsetY"].AsReal();
SpecularRepeatX = scale * (float)mat["SpecRepeatX"].AsReal();
SpecularRepeatY = scale * (float)mat["SpecRepeatY"].AsReal();
SpecularRotation = scale * (float)mat["SpecRotation"].AsReal();
SpecularLightColor = mat["SpecColor"].AsColor4();
SpecularLightExponent = (Byte)mat["SpecExp"].AsUInteger();
EnvironmentIntensity = (Byte)mat["EnvIntensity"].AsUInteger();
DiffuseAlphaMode = (Byte)mat["DiffuseAlphaMode"].AsUInteger();
AlphaMaskCutoff = (Byte)mat["AlphaMaskCutoff"].AsUInteger();
}
public OSDMap toOSD()
{
OSDMap mat = new OSDMap();
float scale = 10000f;
mat["NormMap"] = NormalMapID;
mat["NormOffsetX"] = (int) (scale * NormalOffsetX);
mat["NormOffsetY"] = (int) (scale * NormalOffsetY);
mat["NormRepeatX"] = (int) (scale * NormalRepeatX);
mat["NormRepeatY"] = (int) (scale * NormalRepeatY);
mat["NormRotation"] = (int) (scale * NormalRotation);
mat["SpecMap"] = SpecularMapID;
mat["SpecOffsetX"] = (int) (scale * SpecularOffsetX);
mat["SpecOffsetY"] = (int) (scale * SpecularOffsetY);
mat["SpecRepeatX"] = (int) (scale * SpecularRepeatX);
mat["SpecRepeatY"] = (int) (scale * SpecularRepeatY);
mat["SpecRotation"] = (int) (scale * SpecularRotation);
mat["SpecColor"] = SpecularLightColor;
mat["SpecExp"] = SpecularLightExponent;
mat["EnvIntensity"] = EnvironmentIntensity;
mat["DiffuseAlphaMode"] = DiffuseAlphaMode;
mat["AlphaMaskCutoff"] = AlphaMaskCutoff;
return mat;
}
}
}

View File

@ -11298,6 +11298,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
break;
case (int)ScriptBaseClass.PRIM_NORMAL:
case (int)ScriptBaseClass.PRIM_SPECULAR:
case (int)ScriptBaseClass.PRIM_ALPHA_MODE:
if (remain < 1)
return new LSL_List();
face = (int)rules.GetLSLIntegerItem(idx++);
tex = part.Shape.Textures;
if (face == ScriptBaseClass.ALL_SIDES)
{
for (face = 0; face < GetNumberOfSides(part); face++)
{
Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
getLSLFaceMaterial(ref res, code, texface);
}
}
else
{
if (face >= 0 && face < GetNumberOfSides(part))
{
Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
getLSLFaceMaterial(ref res, code, texface);
}
}
break;
case (int)ScriptBaseClass.PRIM_LINK_TARGET:
// TODO: Should be issuing a runtime script warning in this case.
@ -11311,6 +11337,68 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return new LSL_List();
}
private void getLSLFaceMaterial(ref LSL_List res, int code, Primitive.TextureEntryFace texface)
{
UUID matID = texface.MaterialID;
if(matID != UUID.Zero)
{
AssetBase MatAsset = World.AssetService.Get(matID.ToString());
if(MatAsset != null)
{
Byte[] data = MatAsset.Data;
OSDMap osdmat = (OSDMap)OSDParser.DeserializeLLSDXml(data);
if(osdmat != null && osdmat.ContainsKey("NormMap"))
{
FaceMaterial mat = new FaceMaterial(matID, osdmat);
if(code == ScriptBaseClass.PRIM_NORMAL)
{
res.Add(new LSL_String(mat.NormalMapID.ToString()));
res.Add(new LSL_Vector(mat.NormalOffsetX, mat.NormalOffsetY, 0));
res.Add(new LSL_Vector(mat.NormalRepeatX, mat.NormalRepeatY, 0));
res.Add(new LSL_Float(mat.NormalRotation));
}
else if(code == ScriptBaseClass.PRIM_SPECULAR )
{
res.Add(new LSL_String(mat.SpecularMapID.ToString()));
res.Add(new LSL_Vector(mat.SpecularOffsetX, mat.SpecularOffsetY, 0));
res.Add(new LSL_Vector(mat.SpecularRepeatX, mat.SpecularRepeatY, 0));
res.Add(new LSL_Vector(mat.SpecularLightColor.R, mat.SpecularLightColor.G, mat.SpecularLightColor.B));
res.Add(new LSL_Integer(mat.SpecularLightExponent));
res.Add(new LSL_Integer(mat.EnvironmentIntensity));
}
else if(code == ScriptBaseClass.PRIM_ALPHA_MODE)
{
res.Add(new LSL_Integer(mat.DiffuseAlphaMode));
res.Add(new LSL_Integer(mat.AlphaMaskCutoff));
}
return;
}
}
matID = UUID.Zero;
}
if(matID == UUID.Zero)
{
if(code == (int)ScriptBaseClass.PRIM_NORMAL || code == (int)ScriptBaseClass.PRIM_SPECULAR )
{
res.Add(new LSL_String(UUID.Zero.ToString()));
res.Add(new LSL_Vector(1.0, 1.0, 0));
res.Add(new LSL_Vector(0, 0, 0));
res.Add(new LSL_Float(0));
if(code == (int)ScriptBaseClass.PRIM_SPECULAR)
{
res.Add(new LSL_Vector(1.0, 1.0, 1.0));
res.Add(new LSL_Integer(51));
res.Add(new LSL_Integer(0));
}
}
else if(code == (int)ScriptBaseClass.PRIM_ALPHA_MODE)
{
res.Add(new LSL_Integer(1));
res.Add(new LSL_Integer(0));
}
}
}
public LSL_List llGetPrimMediaParams(int face, LSL_List rules)
{