Example #1
0
        public void UpdateExtraPhysics(ExtraPhysicsData physdata)
        {
            if (physdata.PhysShapeType == PhysShapeType.invalid || ParentGroup == null)
                return;

            if (PhysicsShapeType != (byte)physdata.PhysShapeType)
            {
                PhysicsShapeType = (byte)physdata.PhysShapeType;

            }

            if(Density != physdata.Density)
                Density = physdata.Density;
            if(GravityModifier != physdata.GravitationModifier)
                GravityModifier = physdata.GravitationModifier;
            if(Friction != physdata.Friction)
                Friction = physdata.Friction;
            if(Restitution != physdata.Bounce)
                Restitution = physdata.Bounce;
        }
Example #2
0
        /// <summary>
        /// Update the flags on a scene object.  This covers properties such as phantom, physics and temporary.
        /// </summary>
        /// <remarks>
        /// This is currently handling the incoming call from the client stack (e.g. LLClientView).
        /// </remarks>
        /// <param name="localID"></param>
        /// <param name="UsePhysics"></param>
        /// <param name="SetTemporary"></param>
        /// <param name="SetPhantom"></param>
        /// <param name="remoteClient"></param>
        protected internal void UpdatePrimFlags(
            uint localID, bool UsePhysics, bool SetTemporary, bool SetPhantom, ExtraPhysicsData PhysData, IClientAPI remoteClient)
        {
            SceneObjectGroup group = GetGroupByPrim(localID);
            if (group != null)
            {
                if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId))
                {
                    // VolumeDetect can't be set via UI and will always be off when a change is made there
                    // now only change volume dtc if phantom off

                    if (PhysData.PhysShapeType == PhysShapeType.invalid) // check for extraPhysics data
                    {
                        bool vdtc;
                        if (SetPhantom) // if phantom keep volumedtc
                            vdtc = group.RootPart.VolumeDetectActive;
                        else // else turn it off
                            vdtc = false;

                        group.UpdatePrimFlags(localID, UsePhysics, SetTemporary, SetPhantom, vdtc);
                    }
                    else
                    {
                        SceneObjectPart part = GetSceneObjectPart(localID);
                        if (part != null)
                        {
                            part.UpdateExtraPhysics(PhysData);
                            if (part.UpdatePhysRequired)
                                remoteClient.SendPartPhysicsProprieties(part);
                        }
                    }
                }
            }
        }
Example #3
0
        protected LSL_List SetPrimParams(SceneObjectPart part, LSL_List rules, string originFunc, ref uint rulesParsed)
        {
            int idx = 0;
            int idxStart = 0;

            bool positionChanged = false;
            LSL_Vector currentPosition = GetPartLocalPos(part);

            try
            {
                while (idx < rules.Length)
                {
                    ++rulesParsed;
                    int code = rules.GetLSLIntegerItem(idx++);

                    int remain = rules.Length - idx;
                    idxStart = idx;

                    int face;
                    LSL_Vector v;

                    switch (code)
                    {
                        case (int)ScriptBaseClass.PRIM_POSITION:
                        case (int)ScriptBaseClass.PRIM_POS_LOCAL:
                            if (remain < 1)
                                return null;

                            v=rules.GetVector3Item(idx++);
                            positionChanged = true;
                            currentPosition = GetSetPosTarget(part, v, currentPosition);

                            break;
                        case (int)ScriptBaseClass.PRIM_SIZE:
                            if (remain < 1)
                                return null;

                            v=rules.GetVector3Item(idx++);
                            SetScale(part, v);

                            break;
                        case (int)ScriptBaseClass.PRIM_ROTATION:
                            if (remain < 1)
                                return null;

                            LSL_Rotation q = rules.GetQuaternionItem(idx++);
                            // try to let this work as in SL...
                            if (part.ParentID == 0)
                            {
                                // special case: If we are root, rotate complete SOG to new rotation
                                SetRot(part, q);
                            }
                            else
                            {
                                // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
                                SceneObjectPart rootPart = part.ParentGroup.RootPart;
                                SetRot(part, rootPart.RotationOffset * (Quaternion)q);
                            }

                            break;

                        case (int)ScriptBaseClass.PRIM_TYPE:
                            if (remain < 3)
                                return null;

                            code = (int)rules.GetLSLIntegerItem(idx++);

                            remain = rules.Length - idx;
                            float hollow;
                            LSL_Vector twist;
                            LSL_Vector taper_b;
                            LSL_Vector topshear;
                            float revolutions;
                            float radiusoffset;
                            float skew;
                            LSL_Vector holesize;
                            LSL_Vector profilecut;

                            switch (code)
                            {
                                case (int)ScriptBaseClass.PRIM_TYPE_BOX:
                                    if (remain < 6)
                                        return null;

                                    face = (int)rules.GetLSLIntegerItem(idx++);
                                    v = rules.GetVector3Item(idx++); // cut
                                    hollow = (float)rules.GetLSLFloatItem(idx++);
                                    twist = rules.GetVector3Item(idx++);
                                    taper_b = rules.GetVector3Item(idx++);
                                    topshear = rules.GetVector3Item(idx++);

                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
                                        (byte)ProfileShape.Square, (byte)Extrusion.Straight);
                                    break;

                                case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER:
                                    if (remain < 6)
                                        return null;

                                    face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
                                    v = rules.GetVector3Item(idx++); // cut
                                    hollow = (float)rules.GetLSLFloatItem(idx++);
                                    twist = rules.GetVector3Item(idx++);
                                    taper_b = rules.GetVector3Item(idx++);
                                    topshear = rules.GetVector3Item(idx++);
                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
                                        (byte)ProfileShape.Circle, (byte)Extrusion.Straight);
                                    break;

                                case (int)ScriptBaseClass.PRIM_TYPE_PRISM:
                                    if (remain < 6)
                                        return null;

                                    face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
                                    v = rules.GetVector3Item(idx++); //cut
                                    hollow = (float)rules.GetLSLFloatItem(idx++);
                                    twist = rules.GetVector3Item(idx++);
                                    taper_b = rules.GetVector3Item(idx++);
                                    topshear = rules.GetVector3Item(idx++);
                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
                                        (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Straight);
                                    break;

                                case (int)ScriptBaseClass.PRIM_TYPE_SPHERE:
                                    if (remain < 5)
                                        return null;

                                    face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
                                    v = rules.GetVector3Item(idx++); // cut
                                    hollow = (float)rules.GetLSLFloatItem(idx++);
                                    twist = rules.GetVector3Item(idx++);
                                    taper_b = rules.GetVector3Item(idx++); // dimple
                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b,
                                        (byte)ProfileShape.HalfCircle, (byte)Extrusion.Curve1);
                                    break;

                                case (int)ScriptBaseClass.PRIM_TYPE_TORUS:
                                    if (remain < 11)
                                        return null;

                                    face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
                                    v = rules.GetVector3Item(idx++); //cut
                                    hollow = (float)rules.GetLSLFloatItem(idx++);
                                    twist = rules.GetVector3Item(idx++);
                                    holesize = rules.GetVector3Item(idx++);
                                    topshear = rules.GetVector3Item(idx++);
                                    profilecut = rules.GetVector3Item(idx++);
                                    taper_b = rules.GetVector3Item(idx++); // taper_a
                                    revolutions = (float)rules.GetLSLFloatItem(idx++);
                                    radiusoffset = (float)rules.GetLSLFloatItem(idx++);
                                    skew = (float)rules.GetLSLFloatItem(idx++);
                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
                                        revolutions, radiusoffset, skew, (byte)ProfileShape.Circle, (byte)Extrusion.Curve1);
                                    break;

                                case (int)ScriptBaseClass.PRIM_TYPE_TUBE:
                                    if (remain < 11)
                                        return null;

                                    face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
                                    v = rules.GetVector3Item(idx++); //cut
                                    hollow = (float)rules.GetLSLFloatItem(idx++);
                                    twist = rules.GetVector3Item(idx++);
                                    holesize = rules.GetVector3Item(idx++);
                                    topshear = rules.GetVector3Item(idx++);
                                    profilecut = rules.GetVector3Item(idx++);
                                    taper_b = rules.GetVector3Item(idx++); // taper_a
                                    revolutions = (float)rules.GetLSLFloatItem(idx++);
                                    radiusoffset = (float)rules.GetLSLFloatItem(idx++);
                                    skew = (float)rules.GetLSLFloatItem(idx++);
                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
                                        revolutions, radiusoffset, skew, (byte)ProfileShape.Square, (byte)Extrusion.Curve1);
                                    break;

                                case (int)ScriptBaseClass.PRIM_TYPE_RING:
                                    if (remain < 11)
                                        return null;

                                    face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
                                    v = rules.GetVector3Item(idx++); //cut
                                    hollow = (float)rules.GetLSLFloatItem(idx++);
                                    twist = rules.GetVector3Item(idx++);
                                    holesize = rules.GetVector3Item(idx++);
                                    topshear = rules.GetVector3Item(idx++);
                                    profilecut = rules.GetVector3Item(idx++);
                                    taper_b = rules.GetVector3Item(idx++); // taper_a
                                    revolutions = (float)rules.GetLSLFloatItem(idx++);
                                    radiusoffset = (float)rules.GetLSLFloatItem(idx++);
                                    skew = (float)rules.GetLSLFloatItem(idx++);
                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
                                        revolutions, radiusoffset, skew, (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Curve1);
                                    break;

                                case (int)ScriptBaseClass.PRIM_TYPE_SCULPT:
                                    if (remain < 2)
                                        return null;

                                    string map = rules.Data[idx++].ToString();
                                    face = (int)rules.GetLSLIntegerItem(idx++); // type
                                    SetPrimitiveShapeParams(part, map, face, (byte)Extrusion.Curve1);
                                    break;
                            }

                            break;

                        case (int)ScriptBaseClass.PRIM_TEXTURE:
                            if (remain < 5)
                                return null;

                            face=(int)rules.GetLSLIntegerItem(idx++);
                            string tex=rules.Data[idx++].ToString();
                            LSL_Vector repeats=rules.GetVector3Item(idx++);
                            LSL_Vector offsets=rules.GetVector3Item(idx++);
                            double rotation=(double)rules.GetLSLFloatItem(idx++);

                            SetTexture(part, tex, face);
                            ScaleTexture(part, repeats.x, repeats.y, face);
                            OffsetTexture(part, offsets.x, offsets.y, face);
                            RotateTexture(part, rotation, face);

                            break;

                        case (int)ScriptBaseClass.PRIM_COLOR:
                            if (remain < 3)
                                return null;

                            face=(int)rules.GetLSLIntegerItem(idx++);
                            LSL_Vector color=rules.GetVector3Item(idx++);
                            double alpha=(double)rules.GetLSLFloatItem(idx++);

                            part.SetFaceColorAlpha(face, color, alpha);

                            break;

                        case (int)ScriptBaseClass.PRIM_FLEXIBLE:
                            if (remain < 7)
                                return null;

                            bool flexi = rules.GetLSLIntegerItem(idx++);
                            int softness = rules.GetLSLIntegerItem(idx++);
                            float gravity = (float)rules.GetLSLFloatItem(idx++);
                            float friction = (float)rules.GetLSLFloatItem(idx++);
                            float wind = (float)rules.GetLSLFloatItem(idx++);
                            float tension = (float)rules.GetLSLFloatItem(idx++);
                            LSL_Vector force = rules.GetVector3Item(idx++);

                            SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force);

                            break;

                        case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
                            if (remain < 5)
                                return null;
                            bool light = rules.GetLSLIntegerItem(idx++);
                            LSL_Vector lightcolor = rules.GetVector3Item(idx++);
                            float intensity = (float)rules.GetLSLFloatItem(idx++);
                            float radius = (float)rules.GetLSLFloatItem(idx++);
                            float falloff = (float)rules.GetLSLFloatItem(idx++);

                            SetPointLight(part, light, lightcolor, intensity, radius, falloff);

                            break;

                        case (int)ScriptBaseClass.PRIM_GLOW:
                            if (remain < 2)
                                return null;
                            face = rules.GetLSLIntegerItem(idx++);
                            float glow = (float)rules.GetLSLFloatItem(idx++);

                            SetGlow(part, face, glow);

                            break;

                        case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
                            if (remain < 3)
                                return null;
                            face = (int)rules.GetLSLIntegerItem(idx++);
                            int shiny = (int)rules.GetLSLIntegerItem(idx++);
                            Bumpiness bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++);

                            SetShiny(part, face, shiny, bump);

                            break;

                         case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
                             if (remain < 2)
                                 return null;
                             face = rules.GetLSLIntegerItem(idx++);
                             bool st = rules.GetLSLIntegerItem(idx++);
                             SetFullBright(part, face , st);
                             break;

                         case (int)ScriptBaseClass.PRIM_MATERIAL:
                             if (remain < 1)
                                 return null;
                             int mat = rules.GetLSLIntegerItem(idx++);
                             if (mat < 0 || mat > 7)
                                 return null;

                             part.Material = Convert.ToByte(mat);
                             break;

                         case (int)ScriptBaseClass.PRIM_PHANTOM:
                             if (remain < 1)
                                 return null;

                             string ph = rules.Data[idx++].ToString();
                             part.ParentGroup.ScriptSetPhantomStatus(ph.Equals("1"));

                             break;

                         case (int)ScriptBaseClass.PRIM_PHYSICS:
                            if (remain < 1)
                                 return null;
                             string phy = rules.Data[idx++].ToString();
                             bool physics;

                             if (phy.Equals("1"))
                                 physics = true;
                             else
                                 physics = false;

                             part.ScriptSetPhysicsStatus(physics);
                             break;

                        case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
                            if (remain < 1)
                                return null;

                            int shape_type = rules.GetLSLIntegerItem(idx++);

                            ExtraPhysicsData physdata = new ExtraPhysicsData();
                            physdata.Density = part.Density;
                            physdata.Bounce = part.Restitution;
                            physdata.GravitationModifier = part.GravityModifier;
                            physdata.PhysShapeType = (PhysShapeType)shape_type;

                            part.UpdateExtraPhysics(physdata);

                            break;

                        case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
                            if (remain < 1)
                                return null;
                            string temp = rules.Data[idx++].ToString();

                            part.ParentGroup.ScriptSetTemporaryStatus(temp.Equals("1"));

                            break;

                        case (int)ScriptBaseClass.PRIM_TEXGEN:
                            if (remain < 2)
                                return null;
                                //face,type
                            face = rules.GetLSLIntegerItem(idx++);
                            int style = rules.GetLSLIntegerItem(idx++);
                            SetTexGen(part, face, style);
                            break;
                        case (int)ScriptBaseClass.PRIM_TEXT:
                            if (remain < 3)
                                return null;
                            string primText = rules.GetLSLStringItem(idx++);
                            LSL_Vector primTextColor = rules.GetVector3Item(idx++);
                            LSL_Float primTextAlpha = rules.GetLSLFloatItem(idx++);
                            Vector3 av3 = Util.Clip(primTextColor, 0.0f, 1.0f);
                            part.SetText(primText, av3, Util.Clip((float)primTextAlpha, 0.0f, 1.0f));

                            break;
                        case (int)ScriptBaseClass.PRIM_NAME:
                            if (remain < 1)
                                return null;
                            string primName = rules.GetLSLStringItem(idx++);
                            part.Name = primName;
                            break;
                        case (int)ScriptBaseClass.PRIM_DESC:
                            if (remain < 1)
                                return null;
                            string primDesc = rules.GetLSLStringItem(idx++);
                            part.Description = primDesc;
                            break;
                        case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
                            if (remain < 1)
                                return null;
                            SetRot(part, rules.GetQuaternionItem(idx++));
                            break;
                        case (int)ScriptBaseClass.PRIM_OMEGA:
                            if (remain < 3)
                                return null;
                            LSL_Vector axis = rules.GetVector3Item(idx++);
                            LSL_Float spinrate = rules.GetLSLFloatItem(idx++);
                            LSL_Float gain = rules.GetLSLFloatItem(idx++);
                            TargetOmega(part, axis, (double)spinrate, (double)gain);
                            break;
                        case (int)ScriptBaseClass.PRIM_SLICE:
                            if (remain < 1)
                                return null;
                            LSL_Vector slice = rules.GetVector3Item(idx++);
                            part.UpdateSlice((float)slice.x, (float)slice.y);
                            break;
                        case (int)ScriptBaseClass.PRIM_LINK_TARGET:
                            if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
                                return null;

                            return rules.GetSublist(idx, -1);
                    }
                }
            }
            catch (InvalidCastException e)
            {
                Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
            }
            finally
            {
                if (positionChanged)
                {
                    if (part.ParentGroup.RootPart == part)
                    {
                        SceneObjectGroup parent = part.ParentGroup;
                        parent.UpdateGroupPosition(currentPosition);
                    }
                    else
                    {
                        part.OffsetPosition = currentPosition;
                        SceneObjectGroup parent = part.ParentGroup;
                        parent.HasGroupChanged = true;
                        parent.ScheduleGroupForTerseUpdate();
                    }
                }
            }

            return null;
        }
Example #4
0
        /// <summary>
        /// Update the flags on a scene object.  This covers properties such as phantom, physics and temporary.
        /// </summary>
        /// <remarks>
        /// This is currently handling the incoming call from the client stack (e.g. LLClientView).
        /// </remarks>
        /// <param name="localID"></param>
        /// <param name="UsePhysics"></param>
        /// <param name="SetTemporary"></param>
        /// <param name="SetPhantom"></param>
        /// <param name="remoteClient"></param>
        protected internal void UpdatePrimFlags(
            uint localID, bool UsePhysics, bool SetTemporary, bool SetPhantom, ExtraPhysicsData PhysData, IClientAPI remoteClient)
        {
            SceneObjectGroup group = GetGroupByPrim(localID);
            if (group != null)
            {
                if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId))
                {
                    // VolumeDetect can't be set via UI and will always be off when a change is made there
                    // now only change volume dtc if phantom off

                    bool wantedPhys = UsePhysics;
                    if (PhysData.PhysShapeType == PhysShapeType.invalid) // check for extraPhysics data
                    {
                        bool vdtc;
                        if (SetPhantom) // if phantom keep volumedtc
                            vdtc = group.RootPart.VolumeDetectActive;
                        else // else turn it off
                            vdtc = false;

                        group.UpdatePrimFlags(localID, UsePhysics, SetTemporary, SetPhantom, vdtc);
                    }
                    else
                    {
                        SceneObjectPart part = GetSceneObjectPart(localID);
                        if (part != null)
                        {
                            part.UpdateExtraPhysics(PhysData);
                            if (part.UpdatePhysRequired && remoteClient != null)
                                remoteClient.SendPartPhysicsProprieties(part);
                        }
                    }

                    if (wantedPhys != group.UsesPhysics && remoteClient != null)
                    {
                        remoteClient.SendAlertMessage("Object physics canceled because exceeds the limit of " +
                            m_parentScene.m_linksetPhysCapacity + " physical prims with shape type not set to None");
                        group.RootPart.ScheduleFullUpdate();
                    }
                }
            }
        }
Example #5
0
        private void SetPhysicsMaterial(SceneObjectPart part, int material_bits,
                float material_density, float material_friction,
                float material_restitution, float material_gravity_modifier)
        {
            ExtraPhysicsData physdata = new ExtraPhysicsData();
            physdata.PhysShapeType = (PhysShapeType)part.PhysicsShapeType;
            physdata.Density = part.Density;
            physdata.Friction = part.Friction;
            physdata.Bounce = part.Restitution;
            physdata.GravitationModifier = part.GravityModifier;

            if ((material_bits & (int)ScriptBaseClass.DENSITY) != 0)
                physdata.Density = material_density;
            if ((material_bits & (int)ScriptBaseClass.FRICTION) != 0)
                physdata.Friction = material_friction;
            if ((material_bits & (int)ScriptBaseClass.RESTITUTION) != 0)
                physdata.Bounce = material_restitution;
            if ((material_bits & (int)ScriptBaseClass.GRAVITY_MULTIPLIER) != 0)
                physdata.GravitationModifier = material_gravity_modifier;

            part.UpdateExtraPhysics(physdata);
        }