internal void SetTexPrimitiveParams(PrimitiveParamsType paramtype, AnArray.MarkEnumerator enumerator, ref UpdateChangedFlags flags, ref bool isUpdated, string paramtypename, bool updateParams)
 {
     m_TextureEntryLock.AcquireWriterLock(-1);
     try
     {
         var faces = GetFaces(ParamsHelper.GetInteger(enumerator, paramtypename));
         enumerator.MarkPosition();
         foreach (var face in faces)
         {
             enumerator.GoToMarkPosition();
             SetTexPrimitiveParams(face, paramtype, enumerator, ref flags, ref isUpdated, updateParams);
         }
         m_TextureEntryBytes = m_TextureEntry.GetBytes();
     }
     finally
     {
         m_TextureEntryLock.ReleaseWriterLock();
     }
 }
Exemplo n.º 2
0
        public void SetPrimitiveParams(AnArray.MarkEnumerator enumerator)
        {
            PrimitiveParamsType paramtype = ParamsHelper.GetPrimParamType(enumerator);

            switch (paramtype)
            {
            case PrimitiveParamsType.Name:
                Name = ParamsHelper.GetString(enumerator, "PRIM_NAME");
                break;

            case PrimitiveParamsType.Desc:
                Description = ParamsHelper.GetString(enumerator, "PRIM_DESC");
                break;

            case PrimitiveParamsType.Position:
                Position = ParamsHelper.GetVector(enumerator, "PRIM_POSITION");
                break;

            case PrimitiveParamsType.PosLocal:
                LocalPosition = ParamsHelper.GetVector(enumerator, "PRIM_POS_LOCAL");
                break;

            case PrimitiveParamsType.Rotation:
                GlobalRotation = ParamsHelper.GetRotation(enumerator, "PRIM_ROTATION").Normalize();
                break;

            case PrimitiveParamsType.RotLocal:
                LocalRotation = ParamsHelper.GetRotation(enumerator, "PRIM_ROT_LOCAL").Normalize();
                break;

            default:
                if (Enum.IsDefined(typeof(PrimitiveParamsType), (int)paramtype))
                {
                    throw new LocalizedScriptErrorException(this, "PRIM0NotAllowedForAgents", "{0} not allowed for agents", paramtype.GetLslName());
                }
                else
                {
                    throw new LocalizedScriptErrorException(this, "PRIMInvalidParameterType0", "Invalid primitive parameter type {0}", paramtype.GetLslName());
                }
            }
        }
        private void SetTexPrimitiveParams(TextureEntryFace face, PrimitiveParamsType type, AnArray.MarkEnumerator enumerator, ref UpdateChangedFlags flags, ref bool isUpdated, bool updateParams)
        {
            switch (type)
            {
            case PrimitiveParamsType.Texture:
            {
                UUID    textureID = m_Part.GetTextureParam(enumerator, "PRIM_TEXTURE");
                Vector3 repeats   = ParamsHelper.GetVector(enumerator, "PRIM_TEXTURE");
                Vector3 offsets   = ParamsHelper.GetVector(enumerator, "PRIM_TEXTURE");
                float   rot       = (float)ParamsHelper.GetDouble(enumerator, "PRIM_TEXTURE");

                if (updateParams)
                {
                    if (m_Part.TryFetchTexture(textureID))
                    {
                        face.TextureID = textureID;
                    }
                    face.RepeatU  = (float)repeats.X;
                    face.RepeatV  = (float)repeats.Y;
                    face.OffsetU  = (float)offsets.X;
                    face.OffsetV  = (float)offsets.Y;
                    face.Rotation = rot;
                    flags        |= UpdateChangedFlags.Texture;
                    isUpdated     = true;
                }
            }
            break;

            case PrimitiveParamsType.Color:
            {
                Vector3 color = ParamsHelper.GetVector(enumerator, "PRIM_COLOR");
                double  alpha = ParamsHelper.GetDouble(enumerator, "PRIM_COLOR").Clamp(0, 1);
                if (updateParams)
                {
                    face.TextureColor = new ColorAlpha(color, alpha);
                    flags            |= UpdateChangedFlags.Color;
                    isUpdated         = true;
                }
            }
            break;

            case PrimitiveParamsType.Alpha:
            {
                double alpha = ParamsHelper.GetDouble(enumerator, "PRIM_ALPHA").Clamp(0, 1);
                if (updateParams)
                {
                    ColorAlpha color = face.TextureColor;
                    color.A           = alpha;
                    face.TextureColor = color;
                    flags            |= UpdateChangedFlags.Color;
                    isUpdated         = true;
                }
            }
            break;

            case PrimitiveParamsType.BumpShiny:
            {
                Shininess shiny = (Shininess)ParamsHelper.GetInteger(enumerator, "PRIM_BUMP_SHINY");
                Bumpiness bump  = (Bumpiness)ParamsHelper.GetInteger(enumerator, "PRIM_BUMP_SHINY");
                if (updateParams)
                {
                    face.Shiny = shiny;
                    face.Bump  = bump;
                    flags     |= UpdateChangedFlags.Texture;
                    isUpdated  = true;
                }
            }
            break;

            case PrimitiveParamsType.FullBright:
            {
                bool fbright = ParamsHelper.GetBoolean(enumerator, "PRIM_FULLBRIGHT");
                if (updateParams)
                {
                    face.FullBright = fbright;
                    flags          |= UpdateChangedFlags.Color;
                    isUpdated       = true;
                }
            }
            break;

            case PrimitiveParamsType.TexGen:
            {
                MappingType mapType = (MappingType)ParamsHelper.GetInteger(enumerator, "PRIM_TEXGEN");
                if (updateParams)
                {
                    face.TexMapType = mapType;
                    flags          |= UpdateChangedFlags.Texture;
                    isUpdated       = true;
                }
            }
            break;

            case PrimitiveParamsType.Glow:
            {
                float glow = (float)ParamsHelper.GetDouble(enumerator, "PRIM_GLOW").Clamp(0, 1);
                if (updateParams)
                {
                    face.Glow = glow;
                    flags    |= UpdateChangedFlags.Color;
                    isUpdated = true;
                }
            }
            break;

            case PrimitiveParamsType.AlphaMode:
                /* [ PRIM_ALPHA_MODE, integer face, integer alpha_mode, integer mask_cutoff ] */
            {
                Material mat;
                try
                {
                    mat = m_Part.ObjectGroup.Scene.GetMaterial(face.MaterialID);
                }
                catch
                {
                    mat = new Material();
                }
                mat.DiffuseAlphaMode = ParamsHelper.GetInteger(enumerator, "PRIM_ALPHA_MODE");
                mat.AlphaMaskCutoff  = ParamsHelper.GetInteger(enumerator, "PRIM_ALPHA_MODE");

                if (updateParams)
                {
                    mat.DiffuseAlphaMode = mat.DiffuseAlphaMode.Clamp(0, 3);
                    mat.AlphaMaskCutoff  = mat.AlphaMaskCutoff.Clamp(0, 3);
                    mat.MaterialID       = UUID.Random;
                    m_Part.ObjectGroup.Scene.StoreMaterial(mat);
                    face.MaterialID = mat.MaterialID;
                    flags          |= UpdateChangedFlags.Texture;
                    isUpdated       = true;
                }
            }
            break;

            case PrimitiveParamsType.Normal:
                /* [ PRIM_NORMAL, integer face, string texture, vector repeats, vector offsets, float rotation_in_radians ] */
            {
                UUID    texture  = m_Part.GetTextureParam(enumerator, "PRIM_NORMAL");
                Vector3 repeats  = ParamsHelper.GetVector(enumerator, "PRIM_NORMAL");
                Vector3 offsets  = ParamsHelper.GetVector(enumerator, "PRIM_NORMAL");
                double  rotation = ParamsHelper.GetDouble(enumerator, "PRIM_NORMAL");

                if (updateParams)
                {
                    repeats.X *= Material.MATERIALS_MULTIPLIER;
                    repeats.Y *= Material.MATERIALS_MULTIPLIER;
                    offsets.X *= Material.MATERIALS_MULTIPLIER;
                    offsets.Y *= Material.MATERIALS_MULTIPLIER;
                    rotation  %= Math.PI * 2;
                    rotation  *= Material.MATERIALS_MULTIPLIER;

                    Material mat;
                    try
                    {
                        mat = m_Part.ObjectGroup.Scene.GetMaterial(face.MaterialID);
                    }
                    catch
                    {
                        mat = new Material();
                    }
                    mat.NormMap      = texture;
                    mat.NormOffsetX  = (int)Math.Round(offsets.X);
                    mat.NormOffsetY  = (int)Math.Round(offsets.Y);
                    mat.NormRepeatX  = (int)Math.Round(repeats.X);
                    mat.NormRepeatY  = (int)Math.Round(repeats.Y);
                    mat.NormRotation = (int)Math.Round(rotation);
                    mat.MaterialID   = UUID.Random;
                    if (m_Part.TryFetchTexture(texture))
                    {
                        m_Part.ObjectGroup.Scene.StoreMaterial(mat);
                        face.MaterialID = mat.MaterialID;
                    }
                    flags    |= UpdateChangedFlags.Texture;
                    isUpdated = true;
                }
            }
            break;

            case PrimitiveParamsType.Specular:
                /* [ PRIM_SPECULAR, integer face, string texture, vector repeats, vector offsets, float rotation_in_radians, vector color, integer glossiness, integer environment ] */
            {
                UUID    texture = m_Part.GetTextureParam(enumerator, "PRIM_NORMAL");
                Vector3 repeats = ParamsHelper.GetVector(enumerator, "PRIM_SPECULAR");
                Vector3 offsets = ParamsHelper.GetVector(enumerator, "PRIM_SPECULAR");
                repeats *= Material.MATERIALS_MULTIPLIER;
                offsets *= Material.MATERIALS_MULTIPLIER;
                double rotation = ParamsHelper.GetDouble(enumerator, "PRIM_SPECULAR");
                rotation %= Math.PI * 2;
                rotation *= Material.MATERIALS_MULTIPLIER;
                var color       = new ColorAlpha(ParamsHelper.GetVector(enumerator, "PRIM_SPECULAR"), 1);
                int glossiness  = ParamsHelper.GetInteger(enumerator, "PRIM_SPECULAR");
                int environment = ParamsHelper.GetInteger(enumerator, "PRIM_SPECULAR");
                if (updateParams)
                {
                    environment = environment.Clamp(0, 255);
                    glossiness  = glossiness.Clamp(0, 255);
                    Material mat;
                    try
                    {
                        mat = m_Part.ObjectGroup.Scene.GetMaterial(face.MaterialID);
                    }
                    catch
                    {
                        mat = new Material();
                    }
                    mat.SpecColor    = color;
                    mat.SpecMap      = texture;
                    mat.SpecOffsetX  = (int)Math.Round(offsets.X);
                    mat.SpecOffsetY  = (int)Math.Round(offsets.Y);
                    mat.SpecRepeatX  = (int)Math.Round(repeats.X);
                    mat.SpecRepeatY  = (int)Math.Round(repeats.Y);
                    mat.SpecRotation = (int)Math.Round(rotation);
                    mat.EnvIntensity = environment;
                    mat.SpecExp      = glossiness;
                    mat.MaterialID   = UUID.Random;
                    if (m_Part.TryFetchTexture(texture))
                    {
                        m_Part.ObjectGroup.Scene.StoreMaterial(mat);
                        face.MaterialID = mat.MaterialID;
                    }
                    flags    |= UpdateChangedFlags.Texture;
                    isUpdated = true;
                }
            }
            break;

            default:
                throw new ArgumentException($"Internal error! Primitive parameter type {type} should not be passed to PrimitiveFace");
            }
        }
Exemplo n.º 4
0
 public void SetPrimitiveParams(AnArray.MarkEnumerator enumerator)
 {
     /* intentionally left empty */
 }