Пример #1
0
        public bool TryGetConvexShape(PrimitivePhysicsShapeType physicsShape, ObjectPart.PrimitiveShape shape, out PhysicsShapeReference physics)
        {
            if (physicsShape == PrimitivePhysicsShapeType.None)
            {
                physics = null;
                return(false);
            }
            else if (shape.Type == PrimitiveShapeType.Sculpt)
            {
                switch (shape.SculptType)
                {
                case PrimitiveSculptType.Mesh:
                    return(TryGetConvexShapeFromMesh(physicsShape, shape, out physics));

                default:
                    /* calculate convex from sculpt */
                    return(TryGetConvexShapeFromPrim(physicsShape, shape, out physics));
                }
            }
            else
            {
                /* calculate convex from prim mesh */
                return(TryGetConvexShapeFromPrim(physicsShape, shape, out physics));
            }
        }
 PhysicsConvexShape ISimulationDataPhysicsConvexStorageInterface.this[ObjectPart.PrimitiveShape primShape]
 {
     get
     {
         PhysicsConvexShape shape;
         if (!((ISimulationDataPhysicsConvexStorageInterface)this).TryGetValue(primShape, out shape))
         {
             throw new KeyNotFoundException();
         }
         return(shape);
     }
     set
     {
         using (var conn = new NpgsqlConnection(m_ConnectionString))
         {
             conn.Open();
             var param = new Dictionary <string, object>
             {
                 ["ShapeKey"]   = primShape.Serialization,
                 ["ConvexData"] = value.SerializedData
             };
             conn.ReplaceInto("primphysics", param, new string[] { "ShapeKey" }, m_EnableOnConflict);
         }
     }
 }
Пример #3
0
 internal void DecrementUseCount(ObjectPart.PrimitiveShape primshape, PhysicsConvexShape shape)
 {
     if (0 == Interlocked.Decrement(ref shape.UseCount))
     {
         m_Lock.AcquireWriterLock(() => m_ConvexShapesByPrimShape.RemoveIf(primshape, (PhysicsConvexShape s) => s.UseCount == 0));
     }
 }
        bool ISimulationDataPhysicsConvexStorageInterface.TryGetValue(ObjectPart.PrimitiveShape primShape, out PhysicsConvexShape shape)
        {
            using (var conn = new NpgsqlConnection(m_ConnectionString))
            {
                conn.Open();
                using (var cmd = new NpgsqlCommand("SELECT \"ConvexData\" FROM primphysics WHERE \"ShapeKey\"=@id LIMIT 1", conn))
                {
                    cmd.Parameters.AddParameter("@id", primShape.Serialization);
                    using (NpgsqlDataReader dbReader = cmd.ExecuteReader())
                    {
                        if (dbReader.Read())
                        {
                            shape = new PhysicsConvexShape
                            {
                                SerializedData = dbReader.GetBytes("ConvexData")
                            };
                            return(true);
                        }
                    }
                }
            }

            shape = null;
            return(false);
        }
        public bool Run()
        {
            PhysicsShapeReference physicsShapeRef;

            DumpParams(m_Shape);
            ObjectPart.PrimitiveShape ps = new ObjectPart.PrimitiveShape
            {
                DecodedParams = m_Shape
            };
            m_Log.Info("---- Transformed to physics shape manager accepted format ----");
            m_Log.InfoFormat("PhysicsShapeType: {0}", m_PhysicsShapeType);
            DumpParams(ps.DecodedParams);
            if (!m_PhysicsShapeManager.TryGetConvexShape(m_PhysicsShapeType, ps, out physicsShapeRef))
            {
                m_Log.Error("Could not generate physics hull shape");
                return(false);
            }

            PhysicsConvexShape convexShape = physicsShapeRef;

            int hullidx = 0;

            foreach (PhysicsConvexShape.ConvexHull hull in convexShape.Hulls)
            {
                m_Log.InfoFormat("Hull {0}: Generated vertices: {1}", hullidx, hull.Vertices.Count);
                m_Log.InfoFormat("Hull {0}: Generated triangles: {1}", hullidx, hull.Triangles.Count / 3);
                ++hullidx;
            }
            m_Log.InfoFormat("Generated hulls: {0}", hullidx);

            /* write a blender .raw */
            ((PhysicsConvexShape)physicsShapeRef).DumpToBlenderRaw(m_OutputFileName);
            return(true);
        }
Пример #6
0
        protected override void DetachAttachment(DetachEntry entry)
        {
            ObjectGroup grp = CurrentScene.ObjectGroups[entry.ObjectID];

            try
            {
                CurrentScene.Remove(grp);
            }
            catch
            {
                return;
            }
            Attachments.Remove(grp.ID);

            /* only serialize changed and/or scripted attachments */
            bool isChanged  = false;
            bool isScripted = false;

            foreach (ObjectPart part in grp.Values)
            {
                isChanged  = isChanged || part.IsChanged;
                isScripted = isScripted || part.IsScripted;
                ObjectPart.PrimitiveShape shape = part.Shape;
                shape.State = 0;
                part.Shape  = shape;
            }

            if (isChanged || isScripted)
            {
                UUID newAssetID;
                try
                {
                    AssetData data = grp.Asset();
                    newAssetID = data.ID;
                    AssetService.Store(data);
                }
                catch
                {
                    return;
                }
                try
                {
                    InventoryItem item = InventoryService.Item[ID, entry.ItemID];
                    if (item.AssetType != AssetType.Object)
                    {
                        return;
                    }
                    else
                    {
                        item.AssetID = newAssetID;
                        InventoryService.Item.Update(item);
                    }
                }
                catch
                {
                    return;
                }
            }
        }
Пример #7
0
        public void HandleObjectShape(Message m)
        {
            var req = (ObjectShape)m;

            if (req.CircuitSessionID != req.SessionID ||
                req.CircuitAgentID != req.AgentID)
            {
                return;
            }

            IAgent agent;

            if (!Agents.TryGetValue(req.AgentID, out agent))
            {
                return;
            }

            foreach (ObjectShape.Data d in req.ObjectData)
            {
#if DEBUG
                m_Log.DebugFormat("ObjectShape localid={0}", d.ObjectLocalID);
#endif

                ObjectPart prim;
                if (!Primitives.TryGetValue(d.ObjectLocalID, out prim))
                {
                    continue;
                }

                if (!CanEdit(agent, prim.ObjectGroup, prim.ObjectGroup.GlobalPosition))
                {
                    continue;
                }

                ObjectPart.PrimitiveShape shape = prim.Shape;
                shape.PathCurve        = d.PathCurve;
                shape.ProfileCurve     = d.ProfileCurve;
                shape.PathBegin        = d.PathBegin;
                shape.PathEnd          = d.PathEnd;
                shape.PathScaleX       = d.PathScaleX;
                shape.PathScaleY       = d.PathScaleY;
                shape.PathShearX       = d.PathShearX;
                shape.PathShearY       = d.PathShearY;
                shape.PathTwist        = d.PathTwist;
                shape.PathTwistBegin   = d.PathTwistBegin;
                shape.PathRadiusOffset = d.PathRadiusOffset;
                shape.PathTaperX       = d.PathTaperX;
                shape.PathTaperY       = d.PathTaperY;
                shape.PathRevolutions  = d.PathRevolutions;
                shape.PathSkew         = d.PathSkew;
                shape.ProfileBegin     = d.ProfileBegin;
                shape.ProfileEnd       = d.ProfileEnd;
                shape.ProfileHollow    = d.ProfileHollow;

                prim.Shape = shape;
            }
        }
 bool ISimulationDataPhysicsConvexStorageInterface.Remove(ObjectPart.PrimitiveShape primShape)
 {
     using (var conn = new NpgsqlConnection(m_ConnectionString))
     {
         conn.Open();
         using (var cmd = new NpgsqlCommand("DELETE FROM primphysics WHERE \"ShapeKey\"=@id", conn))
         {
             cmd.Parameters.AddParameter("@id", primShape.Serialization);
             return(cmd.ExecuteNonQuery() > 0);
         }
     }
 }
 bool ISimulationDataPhysicsConvexStorageInterface.ContainsKey(ObjectPart.PrimitiveShape primShape)
 {
     using (var conn = new NpgsqlConnection(m_ConnectionString))
     {
         conn.Open();
         using (var cmd = new NpgsqlCommand("SELECT NULL FROM primphysics WHERE \"ShapeKey\"=@id LIMIT 1", conn))
         {
             cmd.Parameters.AddParameter("@id", primShape.Serialization);
             using (NpgsqlDataReader dbReader = cmd.ExecuteReader())
             {
                 return(dbReader.Read());
             }
         }
     }
 }
Пример #10
0
 public int GetAnimeshState(ScriptInstance instance, LSLKey key)
 {
     lock (instance)
     {
         ObjectPart part;
         if (instance.Part.ObjectGroup.Scene.Primitives.TryGetValue(key.AsUUID, out part))
         {
             ObjectPart.PrimitiveShape shape = part.Shape;
             if (shape.SculptType == PrimitiveSculptType.Mesh &&
                 shape.Type == PrimitiveShapeType.Sculpt)
             {
                 return(((part.ExtendedMesh.Flags & ExtendedMeshParams.MeshFlags.AnimatedMeshEnabled) != 0).ToLSLBoolean());
             }
         }
     }
     return(0);
 }
Пример #11
0
 public void EnableAnimesh(ScriptInstance instance, LSLKey key, int enable)
 {
     lock (instance)
     {
         ObjectPart part;
         if (instance.Part.ObjectGroup.Scene.Primitives.TryGetValue(key.AsUUID, out part))
         {
             ObjectPart.PrimitiveShape shape = part.Shape;
             if (shape.SculptType == PrimitiveSculptType.Mesh &&
                 shape.Type == PrimitiveShapeType.Sculpt)
             {
                 part.ExtendedMesh = new ExtendedMeshParams
                 {
                     Flags = enable != 0 ?
                             ExtendedMeshParams.MeshFlags.AnimatedMeshEnabled :
                             ExtendedMeshParams.MeshFlags.None
                 };
             }
         }
     }
 }
        public bool Run()
        {
            PhysicsShapeReference physicsShapeRef;
            bool success = true;

            foreach (PrimitiveShapeType shapeType in new PrimitiveShapeType[] { PrimitiveShapeType.Box, PrimitiveShapeType.Cylinder, PrimitiveShapeType.Prism, PrimitiveShapeType.Ring, PrimitiveShapeType.Sphere, PrimitiveShapeType.Torus, PrimitiveShapeType.Tube })
            {
                foreach (PrimitiveProfileShape profileShape in new PrimitiveProfileShape[] { PrimitiveProfileShape.Circle, PrimitiveProfileShape.EquilateralTriangle, PrimitiveProfileShape.HalfCircle, PrimitiveProfileShape.IsometricTriangle, PrimitiveProfileShape.RightTriangle, PrimitiveProfileShape.Square })
                {
                    foreach (PrimitiveProfileHollowShape hollowShape in new PrimitiveProfileHollowShape[] { PrimitiveProfileHollowShape.Circle, PrimitiveProfileHollowShape.Same, PrimitiveProfileHollowShape.Square, PrimitiveProfileHollowShape.Triangle })
                    {
                        foreach (PrimitivePhysicsShapeType physicsShapeType in new PrimitivePhysicsShapeType[] { PrimitivePhysicsShapeType.Convex, PrimitivePhysicsShapeType.Prim })
                        {
                            foreach (PrimitiveExtrusion pathCurve in new PrimitiveExtrusion[] { PrimitiveExtrusion.Curve1, PrimitiveExtrusion.Curve2, PrimitiveExtrusion.Default, PrimitiveExtrusion.Straight })
                            {
                                for (double pathbegin = 0; pathbegin < 1; pathbegin += 0.1)
                                {
                                    for (double pathend = 0; pathend < 1; pathend += 0.1)
                                    {
                                        for (double profilebegin = 0; profilebegin < 1; profilebegin += 0.1)
                                        {
                                            for (double profileend = 0; profileend < 1; profileend += 0.1)
                                            {
                                                for (double revolutions = 1; revolutions < 4; revolutions += 0.5)
                                                {
                                                    for (double twistbegin = -1; twistbegin < 1; twistbegin += 0.1)
                                                    {
                                                        for (double twistend = -1; twistend < 1; twistend += 0.1)
                                                        {
                                                            /*
                                                             * public double RadiusOffset;
                                                             */
                                                            for (double hollow = 0; hollow < 0.90; hollow += 0.1)
                                                            {
                                                                for (double skew = -0.9; skew < 0.9; skew += 0.1)
                                                                {
                                                                    for (double topshearx = -1; topshearx < 1; topshearx += 0.1)
                                                                    {
                                                                        for (double topsheary = -1; topsheary < 1; topsheary += 0.1)
                                                                        {
                                                                            for (double taperx = -1; taperx < 1; taperx += 0.1)
                                                                            {
                                                                                for (double tapery = -1; tapery < 1; tapery += 0.1)
                                                                                {
                                                                                    for (double pathscalex = 0; pathscalex < 1; pathscalex += 0.1)
                                                                                    {
                                                                                        for (double pathscaley = 0; pathscaley < 1; pathscaley += 0.1)
                                                                                        {
                                                                                            var shape = new ObjectPart.PrimitiveShape.Decoded();
                                                                                            shape.ProfileShape  = profileShape;
                                                                                            shape.ShapeType     = shapeType;
                                                                                            shape.HoleShape     = hollowShape;
                                                                                            shape.ProfileHollow = hollow;
                                                                                            shape.PathCurve     = pathCurve;
                                                                                            shape.Revolutions   = revolutions;
                                                                                            shape.PathBegin     = pathbegin;
                                                                                            shape.PathEnd       = pathend;
                                                                                            shape.TwistBegin    = twistbegin;
                                                                                            shape.TwistEnd      = twistend;
                                                                                            shape.ProfileBegin  = profilebegin;
                                                                                            shape.ProfileEnd    = profileend;
                                                                                            shape.TopShear.X    = topshearx;
                                                                                            shape.TopShear.Y    = topsheary;
                                                                                            shape.Taper.X       = taperx;
                                                                                            shape.Taper.Y       = tapery;
                                                                                            shape.PathScale.X   = pathscalex;
                                                                                            shape.PathScale.Y   = pathscaley;
                                                                                            shape.Skew          = skew;

                                                                                            var ps = new ObjectPart.PrimitiveShape
                                                                                            {
                                                                                                DecodedParams = shape
                                                                                            };

                                                                                            m_Log.Info("---- Transformed to physics shape manager accepted format ----");
                                                                                            m_Log.InfoFormat("PhysicsShapeType: {0}/{1}", physicsShapeType, shapeType);
                                                                                            m_Log.Info($"Serialized data {physicsShapeType.ToString()}/{ps.Serialization.ToHexString()}");
                                                                                            try
                                                                                            {
                                                                                                if (!m_PhysicsShapeManager.TryGetConvexShape(physicsShapeType, ps, out physicsShapeRef))
                                                                                                {
                                                                                                    DumpParams(shape);
                                                                                                    m_Log.Error("Could not generate physics hull shape");
                                                                                                    success = false;
                                                                                                    continue;
                                                                                                }
                                                                                            }
                                                                                            catch (Exception e)
                                                                                            {
                                                                                                DumpParams(shape);
                                                                                                m_Log.Error("Could not generate physics hull shape", e);
                                                                                                continue;
                                                                                            }

                                                                                            PhysicsConvexShape convexShape = physicsShapeRef;

                                                                                            int hullidx = 0;
                                                                                            foreach (PhysicsConvexShape.ConvexHull hull in convexShape.Hulls)
                                                                                            {
                                                                                                m_Log.InfoFormat("Hull {0}: Generated vertices: {1}", hullidx, hull.Vertices.Count);
                                                                                                m_Log.InfoFormat("Hull {0}: Generated triangles: {1}", hullidx, hull.Triangles.Count / 3);
                                                                                                ++hullidx;
                                                                                            }
                                                                                            m_Log.InfoFormat("Generated hulls: {0}", hullidx);
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                /* write a blender .raw */
                                //                ((PhysicsConvexShape)physicsShapeRef).DumpToBlenderRaw(m_OutputFileName);
                            }
                        }
                    }
                }
            }

            return(success);
        }
Пример #13
0
        PhysicsConvexShape ISimulationDataPhysicsConvexStorageInterface.this[ObjectPart.PrimitiveShape primShape]
        {
            get { return(m_ConvexShapesByPrimShape[primShape]); }

            set { m_ConvexShapesByPrimShape[primShape] = value; }
        }
Пример #14
0
        private bool TryGetConvexShapeFromPrim(PrimitivePhysicsShapeType physicsShape, ObjectPart.PrimitiveShape shape, out PhysicsShapeReference physicshaperef)
        {
            PhysicsConvexShape    physicshape;
            PhysicsShapeReference physicshaperes = null;
            bool s = m_Lock.AcquireReaderLock(() =>
            {
                if (m_ConvexShapesByPrimShape.TryGetValue(shape, out physicshape))
                {
                    physicshaperes = new PhysicsShapePrimShapeReference(shape, this, physicshape);
                    return(true);
                }
                return(false);
            });

            if (s)
            {
                physicshaperef = physicshaperes;
                return(true);
            }

            if (m_DisableCache || !m_SimulationStorage.PhysicsConvexShapes.TryGetValue(shape, out physicshape))
            {
                /* we may produce additional meshes sometimes but it is better not to lock while generating the mesh */
                physicshape = ConvertToMesh(physicsShape, shape);
                if (physicshape == null)
                {
                    physicshaperef = null;
                    return(false);
                }
                foreach (PhysicsConvexShape.ConvexHull hull in physicshape.Hulls)
                {
                    if (hull.Vertices.Count == 0)
                    {
                        if (shape.Type == PrimitiveShapeType.Sculpt)
                        {
                            m_Log.WarnFormat("Physics shape of sculpt generated a 0 point hull: {0} / {1}", physicsShape, shape.Serialization.ToHexString());
                        }
                        else
                        {
                            m_Log.WarnFormat("Physics shape of prim generated a 0 point hull: {0} / {1} / {2} / {3}", physicsShape, shape.PCode, shape.Type, shape.Serialization.ToHexString());
                        }
                        physicshaperef = null;
                        return(false);
                    }
                }
                m_SimulationStorage.PhysicsConvexShapes[shape] = physicshape;
            }

            /* we only lock out the decrement use count here */
            physicshaperef = m_Lock.AcquireReaderLock(() =>
            {
                try
                {
                    m_ConvexShapesByPrimShape.Add(shape, physicshape);
                }
                catch
                {
                    physicshape = m_ConvexShapesByPrimShape[shape];
                }
                return(new PhysicsShapePrimShapeReference(shape, this, physicshape));
            });

            return(true);
        }
Пример #15
0
 internal PhysicsShapePrimShapeReference(ObjectPart.PrimitiveShape primshape, PhysicsShapeManager manager, PhysicsConvexShape shape)
     : base(manager, shape)
 {
     m_Shape = new ObjectPart.PrimitiveShape(primshape);
 }
Пример #16
0
        private PhysicsConvexShape ConvertToMesh(PrimitivePhysicsShapeType physicsShape, ObjectPart.PrimitiveShape shape)
        {
            PhysicsConvexShape convexShape = null;
            bool hasHullList = false;

            if (shape.Type == PrimitiveShapeType.Sculpt && shape.SculptType == PrimitiveSculptType.Mesh)
            {
                var m = new LLMesh(m_AssetService[shape.SculptMap]);
                if (physicsShape == PrimitivePhysicsShapeType.Convex)
                {
#if DEBUG
                    m_Log.DebugFormat("Selected convex of {0}/{1}/{2}", shape.Type, shape.SculptType, shape.SculptMap);
#endif
                    if (m.HasConvexPhysics())
                    {
                        try
                        {
#if DEBUG
                            m_Log.DebugFormat("Using convex of {0}/{1}/{2}", shape.Type, shape.SculptType, shape.SculptMap);
#endif
                            convexShape = m.GetConvexPhysics(false);
                            hasHullList = convexShape.HasHullList;
                            return(convexShape);
                        }
                        catch (NoSuchMeshDataException)
                        {
                            /* no shape */
#if DEBUG
                            m_Log.DebugFormat("No convex in asset of {0}/{1}/{2}", shape.Type, shape.SculptType, shape.SculptMap);
#endif
                        }
                        catch (Exception e)
                        {
                            m_Log.Warn($"Failed to get convex data of {shape.SculptType} {shape.SculptMap}", e);
                        }
                    }
#if DEBUG
                    else
                    {
                        m_Log.DebugFormat("No convex shape in {0}/{1}/{2}", shape.Type, shape.SculptType, shape.SculptMap);
                    }
#endif
                    if (convexShape == null)
                    {
#if DEBUG
                        m_Log.DebugFormat("Using decompose to single convex for {0}/{1}/{2}", shape.Type, shape.SculptType, shape.SculptMap);
#endif
                        MeshLOD lod = m.GetLOD(LLMesh.LodLevel.LOD3);
                        lod.Optimize();
                        convexShape = DecomposeConvex(lod, true);
                    }
                }
                else
                {
#if DEBUG
                    m_Log.DebugFormat("Selected detailed physics of {0}/{1}/{2}", shape.Type, shape.SculptType, shape.SculptMap);
#endif
                    if (m.HasLOD(LLMesh.LodLevel.Physics))
                    {
                        /* check for physics mesh before giving out the single hull */
#if DEBUG
                        m_Log.DebugFormat("Using detailed physics of {0}/{1}/{2}", shape.Type, shape.SculptType, shape.SculptMap);
#endif
                        MeshLOD lod = m.GetLOD(LLMesh.LodLevel.Physics);
                        lod.Optimize();
                        convexShape = DecomposeConvex(lod);
                    }
                    else if (m.HasConvexPhysics())
                    {
#if DEBUG
                        m_Log.DebugFormat("Using convex of {0}/{1}/{2}", shape.Type, shape.SculptType, shape.SculptMap);
#endif
                        try
                        {
                            convexShape = m.GetConvexPhysics(true);
                            hasHullList = convexShape.HasHullList;
                        }
                        catch (NoSuchMeshDataException)
                        {
                            /* no shape */
#if DEBUG
                            m_Log.DebugFormat("No suitable convex in asset of {0}/{1}/{2}", shape.Type, shape.SculptType, shape.SculptMap);
#endif
                        }
                        catch (Exception e)
                        {
                            m_Log.Warn($"Failed to get convex data of {shape.Type}/{shape.SculptType}/{shape.SculptMap}", e);
                        }
                        if (convexShape == null)
                        {
                            /* this way we keep convex hull type functional by having it only get active on PrimitivePhysicsShapeType.Prim */
#if DEBUG
                            m_Log.DebugFormat("Using decompose to convex for {0}/{1}/{2}", shape.Type, shape.SculptType, shape.SculptMap);
#endif
                            MeshLOD lod = m.GetLOD(LLMesh.LodLevel.LOD3);
                            lod.Optimize();
                            convexShape = DecomposeConvex(lod);
                        }
                    }
                }
            }
            else
            {
#if DEBUG
                m_Log.DebugFormat("Using decompose to convex for {0}/{1}/{2}", shape.Type, shape.SculptType, shape.SculptMap);
#endif
                MeshLOD m = shape.ToMesh(m_AssetService);
                m.Optimize();
                convexShape = DecomposeConvex(m, physicsShape == PrimitivePhysicsShapeType.Convex);
            }

            return(convexShape);
        }
Пример #17
0
        private bool TryGetConvexShapeFromMesh(PrimitivePhysicsShapeType physicsShape, ObjectPart.PrimitiveShape shape, out PhysicsShapeReference physicshaperef)
        {
            PhysicsConvexShape    physicshape;
            PhysicsShapeReference physicshaperes = null;
            UUID meshId = shape.SculptMap;
            bool s      = m_Lock.AcquireReaderLock(() =>
            {
                if (m_ConvexShapesBySculptMesh.TryGetValue(GetMeshKey(meshId, physicsShape), out physicshape))
                {
                    physicshaperes = new PhysicsShapeMeshReference(meshId, physicsShape, this, physicshape);
                    return(true);
                }
                return(false);
            });

            if (s)
            {
                physicshaperef = physicshaperes;
                return(true);
            }

            if (m_DisableCache || !m_SimulationStorage.PhysicsConvexShapes.TryGetValue(meshId, physicsShape, out physicshape))
            {
                /* we may produce additional meshes sometimes but it is better not to lock while generating the mesh */
                physicshape = ConvertToMesh(physicsShape, shape);
                if (physicshape == null)
                {
                    physicshaperef = null;
                    return(false);
                }
                foreach (PhysicsConvexShape.ConvexHull hull in physicshape.Hulls)
                {
                    if (hull.Vertices.Count == 0)
                    {
                        m_Log.WarnFormat("Physics shape of mesh generated a 0 point hull: {0} / {1}", physicsShape, meshId);
                        physicshaperef = null;
                        return(false);
                    }
                }
                m_SimulationStorage.PhysicsConvexShapes[meshId, physicsShape] = physicshape;
            }

            /* we only lock out the decrement use count here */
            physicshaperef = m_Lock.AcquireReaderLock(() =>
            {
                try
                {
                    m_ConvexShapesBySculptMesh.Add(GetMeshKey(meshId, physicsShape), physicshape);
                }
                catch
                {
                    physicshape = m_ConvexShapesBySculptMesh[GetMeshKey(meshId, physicsShape)];
                }
                return(new PhysicsShapeMeshReference(meshId, physicsShape, this, physicshape));
            });

            return(true);
        }
Пример #18
0
 bool ISimulationDataPhysicsConvexStorageInterface.Remove(ObjectPart.PrimitiveShape primShape) =>
 m_ConvexShapesByPrimShape.Remove(primShape);
        public void Startup(ConfigurationLoader loader)
        {
            IConfig config = loader.Config.Configs[GetType().FullName];

            m_AssetService        = loader.GetService <AssetServiceInterface>(config.GetString("AssetService", "AssetService"));
            m_PhysicsShapeManager = loader.GetService <PhysicsShapeManager>(config.GetString("PhysicsShapeManager", "PhysicsShapeManager"));

            string physicsShapeType = config.GetString("PhysicsShapeType", "prim").ToLowerInvariant();

            switch (physicsShapeType)
            {
            case "none":
                m_PhysicsShapeType = PrimitivePhysicsShapeType.None;
                break;

            case "prim":
                m_PhysicsShapeType = PrimitivePhysicsShapeType.Prim;
                break;

            case "convex":
                m_PhysicsShapeType = PrimitivePhysicsShapeType.Convex;
                break;

            default:
                throw new ConfigurationLoader.ConfigurationErrorException(string.Format("Invalid PhysicsShapeType: {0}", physicsShapeType));
            }

            if (config.Contains("HexData"))
            {
                ObjectPart.PrimitiveShape p = new ObjectPart.PrimitiveShape
                {
                    Serialization = config.GetString("HexData").FromHexStringToByteArray()
                };
                m_Shape = p.DecodedParams;
            }
            else
            {
                string shapeType = config.GetString("ShapeType", "Box").ToLowerInvariant();
                switch (shapeType)
                {
                case "box":
                    m_Shape.ShapeType = PrimitiveShapeType.Box;
                    break;

                case "cylinder":
                    m_Shape.ShapeType = PrimitiveShapeType.Cylinder;
                    break;

                case "prism":
                    m_Shape.ShapeType = PrimitiveShapeType.Prism;
                    break;

                case "sphere":
                    m_Shape.ShapeType = PrimitiveShapeType.Sphere;
                    break;

                case "torus":
                    m_Shape.ShapeType = PrimitiveShapeType.Torus;
                    break;

                case "tube":
                    m_Shape.ShapeType = PrimitiveShapeType.Tube;
                    break;

                case "ring":
                    m_Shape.ShapeType = PrimitiveShapeType.Ring;
                    break;

                case "sculpt":
                    m_Shape.ShapeType = PrimitiveShapeType.Sculpt;
                    break;

                default:
                    throw new ConfigurationLoader.ConfigurationErrorException(string.Format("Invalid ShapeType: {0}", shapeType));
                }

                string sculptType = config.GetString("SculptType", "sphere").ToLowerInvariant();
                switch (sculptType)
                {
                case "sphere":
                    m_Shape.SculptType = PrimitiveSculptType.Sphere;
                    break;

                case "torus":
                    m_Shape.SculptType = PrimitiveSculptType.Torus;
                    break;

                case "plane":
                    m_Shape.SculptType = PrimitiveSculptType.Plane;
                    break;

                case "cylinder":
                    m_Shape.SculptType = PrimitiveSculptType.Cylinder;
                    break;

                case "mesh":
                    m_Shape.SculptType = PrimitiveSculptType.Mesh;
                    break;

                default:
                    throw new ConfigurationLoader.ConfigurationErrorException(string.Format("Invalid SculptType: {0}", sculptType));
                }

                if (config.Contains("SculptMapID"))
                {
                    m_Shape.SculptMap = new UUID(config.GetString("SculptMapID"));
                }

                if (config.Contains("SculptMapFile"))
                {
                    if (!config.Contains("SculptMapID"))
                    {
                        throw new ConfigurationLoader.ConfigurationErrorException("SculptMap parameter not present");
                    }
                    byte[] data;
                    using (var fs = new FileStream(config.GetString("SculptMapFile"), FileMode.Open))
                    {
                        var fileLength = (int)fs.Length;
                        data = new byte[fileLength];
                        if (fileLength != fs.Read(data, 0, fileLength))
                        {
                            throw new ConfigurationLoader.ConfigurationErrorException("Failed to load file");
                        }
                    }
                    var assetdata = new AssetData
                    {
                        Data = data,
                        Type = m_Shape.SculptType == PrimitiveSculptType.Mesh ? AssetType.Mesh : AssetType.Texture,
                        ID   = m_Shape.SculptMap,
                        Name = "PrimToMesh imported"
                    };
                    m_AssetService.Store(assetdata);
                }

                if (config.GetBoolean("IsSculptInverted", false))
                {
                    m_Shape.IsSculptInverted = true;
                }
                if (config.GetBoolean("IsSculptMirrored", false))
                {
                    m_Shape.IsSculptMirrored = true;
                }

                string profileShape = config.GetString("ProfileShape", "Circle").ToLowerInvariant();
                switch (profileShape)
                {
                case "circle":
                    m_Shape.ProfileShape = PrimitiveProfileShape.Circle;
                    break;

                case "square":
                    m_Shape.ProfileShape = PrimitiveProfileShape.Square;
                    break;

                case "isometrictriangle":
                    m_Shape.ProfileShape = PrimitiveProfileShape.IsometricTriangle;
                    break;

                case "equilateraltriangle":
                    m_Shape.ProfileShape = PrimitiveProfileShape.EquilateralTriangle;
                    break;

                case "righttriangle":
                    m_Shape.ProfileShape = PrimitiveProfileShape.RightTriangle;
                    break;

                case "halfcircle":
                    m_Shape.ProfileShape = PrimitiveProfileShape.HalfCircle;
                    break;

                default:
                    throw new ConfigurationLoader.ConfigurationErrorException(string.Format("Invalid ProfileShape: {0}", profileShape));
                }

                string holeShape = config.GetString("HollowShape", "Same").ToLowerInvariant();
                switch (holeShape)
                {
                case "same":
                    m_Shape.HoleShape = PrimitiveProfileHollowShape.Same;
                    break;

                case "circle":
                    m_Shape.HoleShape = PrimitiveProfileHollowShape.Circle;
                    break;

                case "square":
                    m_Shape.HoleShape = PrimitiveProfileHollowShape.Square;
                    break;

                case "triangle":
                    m_Shape.HoleShape = PrimitiveProfileHollowShape.Triangle;
                    break;

                default:
                    throw new ConfigurationLoader.ConfigurationErrorException(string.Format("Invalid HollowShape: {0}", holeShape));
                }

                m_Shape.ProfileBegin  = double.Parse(config.GetString("ProfileBegin", "0"), CultureInfo.InvariantCulture);
                m_Shape.ProfileEnd    = double.Parse(config.GetString("ProfileEnd", "1"), CultureInfo.InvariantCulture);
                m_Shape.ProfileHollow = double.Parse(config.GetString("ProfileHollow", "0"), CultureInfo.InvariantCulture);
                m_Shape.IsHollow      = m_Shape.ProfileHollow > 0;
                m_Shape.PathBegin     = double.Parse(config.GetString("PathBegin", "0"), CultureInfo.InvariantCulture);
                m_Shape.PathEnd       = double.Parse(config.GetString("PathEnd", "1"), CultureInfo.InvariantCulture);
                m_Shape.IsOpen        = m_Shape.ProfileBegin > 0 || m_Shape.ProfileEnd < 1f;
                m_Shape.PathScale.X   = double.Parse(config.GetString("PathScaleX", "0"), CultureInfo.InvariantCulture);
                m_Shape.PathScale.Y   = double.Parse(config.GetString("PathScaleY", "0"), CultureInfo.InvariantCulture);
                m_Shape.TopShear.X    = double.Parse(config.GetString("TopShearX", "0"), CultureInfo.InvariantCulture);
                m_Shape.TopShear.Y    = double.Parse(config.GetString("TopShearY", "0"), CultureInfo.InvariantCulture);
                m_Shape.TwistBegin    = double.Parse(config.GetString("TwistBegin", "0"), CultureInfo.InvariantCulture);
                m_Shape.TwistEnd      = double.Parse(config.GetString("TwistEnd", "0"), CultureInfo.InvariantCulture);
                m_Shape.RadiusOffset  = double.Parse(config.GetString("RadiusOffset", "0"), CultureInfo.InvariantCulture);
                m_Shape.Taper.X       = double.Parse(config.GetString("TaperX", "0"), CultureInfo.InvariantCulture);
                m_Shape.Taper.Y       = double.Parse(config.GetString("TaperY", "0"), CultureInfo.InvariantCulture);
                m_Shape.Revolutions   = double.Parse(config.GetString("Revolutions", "1"), CultureInfo.InvariantCulture);
                m_Shape.Skew          = double.Parse(config.GetString("Skew", "0"), CultureInfo.InvariantCulture);
            }

            m_OutputFileName = config.GetString("OutputFilename");
        }
Пример #20
0
        public bool Run()
        {
            m_Log.Info("Test num of faces 1 encoding");
            bool success = true;

            ObjectPart.PrimitiveShape shape = new ObjectPart.PrimitiveShape
            {
                PCode        = PrimitiveCode.Prim,
                ProfileCurve = (byte)PrimitiveProfileShape.Circle,
                PathCurve    = (byte)PrimitiveExtrusion.Curve1,
                PathScaleX   = 100,
                PathScaleY   = 150
            };

            if (!shape.IsSane)
            {
                m_Log.Error("faces 1 encoding not sane");
                success = false;
            }

            if (shape.NumberOfSides != 1)
            {
                m_Log.Error("faces 1 encoding not showing 1 faces");
                success = false;
            }


            m_Log.Info("Test num of faces 2 encoding");
            shape = new ObjectPart.PrimitiveShape
            {
                PCode         = PrimitiveCode.Prim,
                ProfileCurve  = (byte)PrimitiveProfileShape.Circle,
                PathCurve     = (byte)PrimitiveExtrusion.Curve1,
                ProfileHollow = 27500,
                PathScaleX    = 100,
                PathScaleY    = 150
            };

            if (!shape.IsSane)
            {
                m_Log.Error("faces 2 encoding not sane");
                success = false;
            }

            if (shape.NumberOfSides != 2)
            {
                m_Log.Error("faces 2 encoding not showing 2 faces");
                success = false;
            }


            m_Log.Info("Test num of faces 3 encoding");
            shape = new ObjectPart.PrimitiveShape
            {
                PCode        = PrimitiveCode.Prim,
                ProfileCurve = (byte)PrimitiveProfileShape.Circle,
                PathCurve    = (byte)PrimitiveExtrusion.Straight,
                PathScaleX   = 100,
                PathScaleY   = 100
            };

            if (!shape.IsSane)
            {
                m_Log.Error("faces 3 encoding not sane");
                success = false;
            }

            if (shape.NumberOfSides != 3)
            {
                m_Log.Error("faces 3 encoding not showing 3 faces");
                success = false;
            }

            m_Log.Info("Test num of faces 4 encoding");
            shape = new ObjectPart.PrimitiveShape
            {
                PCode         = PrimitiveCode.Prim,
                ProfileCurve  = (byte)PrimitiveProfileShape.Circle,
                PathCurve     = (byte)PrimitiveExtrusion.Straight,
                ProfileHollow = 27500,
                PathScaleX    = 100,
                PathScaleY    = 100
            };

            if (!shape.IsSane)
            {
                m_Log.Error("faces 4 encoding not sane");
                success = false;
            }

            if (shape.NumberOfSides != 4)
            {
                m_Log.Error("faces 4 encoding not showing 4 faces");
                success = false;
            }

            m_Log.Info("Test num of faces 5 encoding");
            shape = new ObjectPart.PrimitiveShape
            {
                PCode        = PrimitiveCode.Prim,
                ProfileCurve = (byte)PrimitiveProfileShape.EquilateralTriangle,
                PathCurve    = (byte)PrimitiveExtrusion.Straight,
                PathScaleX   = 100,
                PathScaleY   = 100
            };

            if (!shape.IsSane)
            {
                m_Log.Error("faces 5 encoding not sane");
                success = false;
            }

            if (shape.NumberOfSides != 5)
            {
                m_Log.Error("faces 5 encoding not showing 5 faces");
                success = false;
            }

            m_Log.Info("Test num of faces 6 encoding");
            shape = new ObjectPart.PrimitiveShape
            {
                PCode        = PrimitiveCode.Prim,
                ProfileCurve = (byte)PrimitiveProfileShape.Square,
                PathCurve    = (byte)PrimitiveExtrusion.Straight,
                PathScaleX   = 100,
                PathScaleY   = 100
            };

            if (!shape.IsSane)
            {
                m_Log.Error("faces 6 encoding not sane");
                success = false;
            }

            if (shape.NumberOfSides != 6)
            {
                m_Log.Error("faces 6 encoding not showing 6 faces");
                success = false;
            }

            m_Log.Info("Test num of faces 7 encoding");
            shape = new ObjectPart.PrimitiveShape
            {
                PCode         = PrimitiveCode.Prim,
                ProfileCurve  = (byte)PrimitiveProfileShape.Square,
                PathCurve     = (byte)PrimitiveExtrusion.Straight,
                ProfileHollow = 27500,
                PathScaleX    = 100,
                PathScaleY    = 100
            };

            if (!shape.IsSane)
            {
                m_Log.Error("faces 7 encoding not sane");
                success = false;
            }
            if (shape.NumberOfSides != 7)
            {
                m_Log.Error("faces 7 encoding not showing 7 faces");
                success = false;
            }


            m_Log.Info("Test num of faces 8 encoding");
            shape = new ObjectPart.PrimitiveShape
            {
                PCode        = PrimitiveCode.Prim,
                ProfileCurve = (byte)PrimitiveProfileShape.Square,
                PathCurve    = (byte)PrimitiveExtrusion.Straight,
                ProfileBegin = 9375,
                PathScaleX   = 100,
                PathScaleY   = 100
            };

            if (!shape.IsSane)
            {
                m_Log.Error("faces 8 encoding not sane");
                success = false;
            }

            if (shape.NumberOfSides != 8)
            {
                m_Log.Error("faces 8 encoding not showing 8 faces");
                success = false;
            }

            m_Log.Info("Test num of faces 9 encoding");
            shape = new ObjectPart.PrimitiveShape
            {
                PCode         = PrimitiveCode.Prim,
                ProfileCurve  = (byte)PrimitiveProfileShape.Square,
                PathCurve     = (byte)PrimitiveExtrusion.Straight,
                ProfileBegin  = 9375,
                ProfileHollow = 27500,
                PathScaleX    = 100,
                PathScaleY    = 100
            };

            if (!shape.IsSane)
            {
                m_Log.Error("faces 9 encoding not sane");
                success = false;
            }

            if (shape.NumberOfSides != 9)
            {
                m_Log.Error("faces 9 encoding not showing 9 faces");
                success = false;
            }

            m_Log.Info("****** Use actual function *****");
            m_Log.Info("Test num of faces 1 encoding");
            shape = new ObjectPart.PrimitiveShape
            {
                PCode      = PrimitiveCode.Prim,
                SculptType = PrimitiveSculptType.Mesh
            };

            shape.SetMeshNumFaces(1);

            if (!shape.IsSane)
            {
                m_Log.Error("faces 1 encoding not sane");
                success = false;
            }

            if (shape.NumberOfSides != 1)
            {
                m_Log.Error("faces 1 encoding not showing 1 faces");
                success = false;
            }


            m_Log.Info("Test num of faces 2 encoding");
            shape.SetMeshNumFaces(2);

            if (!shape.IsSane)
            {
                m_Log.Error("faces 2 encoding not sane");
                success = false;
            }

            if (shape.NumberOfSides != 2)
            {
                m_Log.Error("faces 2 encoding not showing 2 faces");
                success = false;
            }


            m_Log.Info("Test num of faces 3 encoding");
            shape.SetMeshNumFaces(3);

            if (!shape.IsSane)
            {
                m_Log.Error("faces 3 encoding not sane");
                success = false;
            }

            if (shape.NumberOfSides != 3)
            {
                m_Log.Error("faces 3 encoding not showing 3 faces");
                success = false;
            }

            m_Log.Info("Test num of faces 4 encoding");
            shape.SetMeshNumFaces(4);

            if (!shape.IsSane)
            {
                m_Log.Error("faces 4 encoding not sane");
                success = false;
            }

            if (shape.NumberOfSides != 4)
            {
                m_Log.Error("faces 4 encoding not showing 4 faces");
                success = false;
            }

            m_Log.Info("Test num of faces 5 encoding");
            shape.SetMeshNumFaces(5);

            if (!shape.IsSane)
            {
                m_Log.Error("faces 5 encoding not sane");
                success = false;
            }

            if (shape.NumberOfSides != 5)
            {
                m_Log.Error("faces 5 encoding not showing 5 faces");
                success = false;
            }

            m_Log.Info("Test num of faces 6 encoding");
            shape.SetMeshNumFaces(6);

            if (!shape.IsSane)
            {
                m_Log.Error("faces 6 encoding not sane");
                success = false;
            }

            if (shape.NumberOfSides != 6)
            {
                m_Log.Error("faces 6 encoding not showing 6 faces");
                success = false;
            }

            m_Log.Info("Test num of faces 7 encoding");
            shape.SetMeshNumFaces(7);

            if (!shape.IsSane)
            {
                m_Log.Error("faces 7 encoding not sane");
                success = false;
            }
            if (shape.NumberOfSides != 7)
            {
                m_Log.Error("faces 7 encoding not showing 7 faces");
                success = false;
            }

            m_Log.Info("Test num of faces 8 encoding");
            shape.SetMeshNumFaces(8);

            if (!shape.IsSane)
            {
                m_Log.Error("faces 8 encoding not sane");
                success = false;
            }

            if (shape.NumberOfSides != 8)
            {
                m_Log.Error("faces 8 encoding not showing 8 faces");
                success = false;
            }

            m_Log.Info("Test num of faces 9 encoding");
            shape.SetMeshNumFaces(9);

            if (!shape.IsSane)
            {
                m_Log.Error("faces 9 encoding not sane");
                success = false;
            }

            if (shape.NumberOfSides != 9)
            {
                m_Log.Error("faces 9 encoding not showing 9 faces");
                success = false;
            }

            return(success);
        }
        public void EnumerateUsedAssets(Action <UUID> action)
        {
            using (var conn = new MySqlConnection(m_ConnectionString))
            {
                conn.Open();
                using (MySqlCommand cmd = new MySqlCommand("SELECT DISTINCT AssetId FROM primitems", conn))
                {
                    using (MySqlDataReader dbReader = cmd.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            action(dbReader.GetUUID("AssetId"));
                        }
                    }
                }

                using (var cmd = new MySqlCommand("SELECT EnvironmentSettings FROM environmentsettings", conn))
                {
                    using (MySqlDataReader dbReader = cmd.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            WindLightSettings settings;
                            using (MemoryStream ms = new MemoryStream(dbReader.GetBytes("EnvironmentSettings")))
                            {
                                settings = WindLightSettings.Deserialize(ms);
                            }
                            if (settings.WaterSettings.NormalMap != UUID.Zero)
                            {
                                action(settings.WaterSettings.NormalMap);
                            }
                        }
                    }
                }

                using (var cmd = new MySqlCommand("SELECT DISTINCT NormalMapTexture FROM lightshare", conn))
                {
                    using (MySqlDataReader dbReader = cmd.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            UUID id = dbReader.GetUUID("NormalMapTexture");
                            if (id != UUID.Zero)
                            {
                                action(id);
                            }
                        }
                    }
                }

                using (var cmd = new MySqlCommand("SELECT DISTINCT TerrainTexture1, TerrainTexture2, TerrainTexture3, TerrainTexture4 FROM regionsettings", conn))
                {
                    using (MySqlDataReader dbReader = cmd.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            UUID id;

                            id = dbReader.GetUUID("TerrainTexture1");
                            if (id != UUID.Zero)
                            {
                                action(id);
                            }
                            id = dbReader.GetUUID("TerrainTexture2");
                            if (id != UUID.Zero)
                            {
                                action(id);
                            }
                            id = dbReader.GetUUID("TerrainTexture3");
                            if (id != UUID.Zero)
                            {
                                action(id);
                            }
                            id = dbReader.GetUUID("TerrainTexture4");
                            if (id != UUID.Zero)
                            {
                                action(id);
                            }
                        }
                    }
                }

                using (var cmd = new MySqlCommand("SELECT PrimitiveShapeData, ParticleSystem, TextureEntryBytes, ProjectionData, LoopedSoundData, ImpactSoundData FROM prims", conn))
                {
                    using (MySqlDataReader dbReader = cmd.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            ObjectPart.PrimitiveShape shape = new ObjectPart.PrimitiveShape {
                                Serialization = dbReader.GetBytes("PrimitiveShapeData")
                            };
                            ParticleSystem             particleSystem = new ParticleSystem(dbReader.GetBytes("ParticleSystem"), 0);
                            TextureEntry               te             = new TextureEntry(dbReader.GetBytes("TextureEntryBytes"));
                            ObjectPart.ProjectionParam proj           = new ObjectPart.ProjectionParam {
                                DbSerialization = dbReader.GetBytes("ProjectionData")
                            };
                            ObjectPart.SoundParam sound = new ObjectPart.SoundParam {
                                Serialization = dbReader.GetBytes("LoopedSoundData")
                            };
                            ObjectPart.CollisionSoundParam colsound = new ObjectPart.CollisionSoundParam {
                                Serialization = dbReader.GetBytes("ImpactSoundData")
                            };
                            if (shape.SculptMap != UUID.Zero)
                            {
                                action(shape.SculptMap);
                            }
                            foreach (UUID refid in particleSystem.References)
                            {
                                if (refid != UUID.Zero)
                                {
                                    action(refid);
                                }
                            }
                            foreach (UUID refid in te.References)
                            {
                                if (refid != UUID.Zero)
                                {
                                    action(refid);
                                }
                            }
                            if (proj.ProjectionTextureID != UUID.Zero)
                            {
                                action(proj.ProjectionTextureID);
                            }
                            if (sound.SoundID != UUID.Zero)
                            {
                                action(sound.SoundID);
                            }
                            if (colsound.ImpactSound != UUID.Zero)
                            {
                                action(colsound.ImpactSound);
                            }
                        }
                    }
                }
            }
        }
        public bool Run()
        {
            bool success = true;

            m_Log.Info("Number of faces 1");
            var shape = new ObjectPart.PrimitiveShape
            {
                PCode            = PrimitiveCode.Prim,
                PathCurve        = 32,
                ProfileCurve     = 5,
                PathBegin        = 0,
                PathEnd          = 0,
                PathScaleX       = 100,
                PathScaleY       = 100,
                PathShearX       = 0,
                PathShearY       = 0,
                PathTwist        = 0,
                PathTwistBegin   = 0,
                PathRadiusOffset = 0,
                PathTaperX       = 0,
                PathTaperY       = 0,
                PathRevolutions  = 0,
                PathSkew         = 0,
                ProfileBegin     = 0,
                ProfileEnd       = 0,
                ProfileHollow    = 0,
            };

            if (shape.NumberOfSides != 1)
            {
                success = false;
                m_Log.InfoFormat("FAIL Got {0}", shape.NumberOfSides);
            }

            m_Log.Info("Number of faces 2");
            shape = new ObjectPart.PrimitiveShape
            {
                PCode            = PrimitiveCode.Prim,
                PathCurve        = 32,
                ProfileCurve     = 5,
                PathBegin        = 0,
                PathEnd          = 0,
                PathScaleX       = 100,
                PathScaleY       = 165,
                PathShearX       = 0,
                PathShearY       = 0,
                PathTwist        = 0,
                PathTwistBegin   = 0,
                PathRadiusOffset = 0,
                PathTaperX       = 0,
                PathTaperY       = 0,
                PathRevolutions  = 0,
                PathSkew         = 0,
                ProfileBegin     = 0,
                ProfileEnd       = 0,
                ProfileHollow    = 250,
            };
            if (shape.NumberOfSides != 2)
            {
                success = false;
                m_Log.InfoFormat("FAIL Got {0}", shape.NumberOfSides);
            }

            m_Log.Info("Number of faces 3");
            shape = new ObjectPart.PrimitiveShape
            {
                PCode            = PrimitiveCode.Prim,
                PathCurve        = 16,
                ProfileCurve     = 0,
                PathBegin        = 0,
                PathEnd          = 0,
                PathScaleX       = 100,
                PathScaleY       = 100,
                PathShearX       = 0,
                PathShearY       = 0,
                PathTwist        = 0,
                PathTwistBegin   = 0,
                PathRadiusOffset = 0,
                PathTaperX       = 0,
                PathTaperY       = 0,
                PathRevolutions  = 0,
                PathSkew         = 0,
                ProfileBegin     = 0,
                ProfileEnd       = 0,
                ProfileHollow    = 0,
            };
            if (shape.NumberOfSides != 3)
            {
                success = false;
                m_Log.InfoFormat("FAIL Got {0}", shape.NumberOfSides);
            }

            m_Log.Info("Number of faces 4");
            shape = new ObjectPart.PrimitiveShape
            {
                PCode            = PrimitiveCode.Prim,
                PathCurve        = 16,
                ProfileCurve     = 0,
                PathBegin        = 0,
                PathEnd          = 0,
                PathScaleX       = 100,
                PathScaleY       = 100,
                PathShearX       = 0,
                PathShearY       = 0,
                PathTwist        = 0,
                PathTwistBegin   = 0,
                PathRadiusOffset = 0,
                PathTaperX       = 0,
                PathTaperY       = 0,
                PathRevolutions  = 0,
                PathSkew         = 0,
                ProfileBegin     = 0,
                ProfileEnd       = 0,
                ProfileHollow    = 25000,
            };
            if (shape.NumberOfSides != 4)
            {
                success = false;
                m_Log.InfoFormat("FAIL Got {0}", shape.NumberOfSides);
            }

            m_Log.Info("Number of faces 5");
            shape = new ObjectPart.PrimitiveShape
            {
                PCode            = PrimitiveCode.Prim,
                PathCurve        = 16,
                ProfileCurve     = 3,
                PathBegin        = 0,
                PathEnd          = 0,
                PathScaleX       = 100,
                PathScaleY       = 100,
                PathShearX       = 0,
                PathShearY       = 0,
                PathTwist        = 0,
                PathTwistBegin   = 0,
                PathRadiusOffset = 0,
                PathTaperX       = 0,
                PathTaperY       = 0,
                PathRevolutions  = 0,
                PathSkew         = 0,
                ProfileBegin     = 0,
                ProfileEnd       = 0,
                ProfileHollow    = 0,
            };
            if (shape.NumberOfSides != 5)
            {
                success = false;
                m_Log.InfoFormat("FAIL Got {0}", shape.NumberOfSides);
            }

            m_Log.Info("Number of faces 6");
            shape = new ObjectPart.PrimitiveShape
            {
                PCode            = PrimitiveCode.Prim,
                PathCurve        = 16,
                ProfileCurve     = 1,
                PathBegin        = 0,
                PathEnd          = 0,
                PathScaleX       = 100,
                PathScaleY       = 100,
                PathShearX       = 0,
                PathShearY       = 0,
                PathTwist        = 0,
                PathTwistBegin   = 0,
                PathRadiusOffset = 0,
                PathTaperX       = 0,
                PathTaperY       = 0,
                PathRevolutions  = 0,
                PathSkew         = 0,
                ProfileBegin     = 0,
                ProfileEnd       = 0,
                ProfileHollow    = 0,
            };
            if (shape.NumberOfSides != 6)
            {
                success = false;
                m_Log.InfoFormat("FAIL Got {0}", shape.NumberOfSides);
            }

#if SEEMS_TO_HAVE_SPECIAL_HANDLING
            m_Log.Info("Number of faces 7");
            shape = new ObjectPart.PrimitiveShape
            {
                PCode            = PrimitiveCode.Prim,
                PathCurve        = 16,
                ProfileCurve     = 1,
                PathBegin        = 0,
                PathEnd          = 0,
                PathScaleX       = 100,
                PathScaleY       = 100,
                PathShearX       = 0,
                PathShearY       = 0,
                PathTwist        = 0,
                PathTwistBegin   = 0,
                PathRadiusOffset = 0,
                PathTaperX       = 0,
                PathTaperY       = 0,
                PathRevolutions  = 0,
                PathSkew         = 0,
                ProfileBegin     = 0,
                ProfileEnd       = 12500,
                ProfileHollow    = 0,
            };
            if (shape.NumberOfSides != 7)
            {
                success = false;
                m_Log.InfoFormat("FAIL Got {0}", shape.NumberOfSides);
            }
#endif

            m_Log.Info("Number of faces 8");
            shape = new ObjectPart.PrimitiveShape
            {
                PCode            = PrimitiveCode.Prim,
                PathCurve        = 16,
                ProfileCurve     = 1,
                PathBegin        = 0,
                PathEnd          = 0,
                PathScaleX       = 100,
                PathScaleY       = 100,
                PathShearX       = 0,
                PathShearY       = 0,
                PathTwist        = 0,
                PathTwistBegin   = 0,
                PathRadiusOffset = 0,
                PathTaperX       = 0,
                PathTaperY       = 0,
                PathRevolutions  = 0,
                PathSkew         = 0,
                ProfileBegin     = 0,
                ProfileEnd       = 6250,
                ProfileHollow    = 0,
            };
            if (shape.NumberOfSides != 8)
            {
                success = false;
                m_Log.InfoFormat("FAIL Got {0}", shape.NumberOfSides);
            }
            return(success);
        }
Пример #23
0
        private void GetObjectMatches(RayData ray, RayTestHitFlags flags, List <RayResult> results)
        {
            foreach (ObjectGroup grp in m_Scene.ObjectGroups)
            {
                if (grp.IsAttached)
                {
                    /* ignore attachments */
                    continue;
                }

                /* flag checks are cheap so do those first */
                if (((flags & RayTestHitFlags.NonPhantom) != 0 && !grp.IsPhantom) ||
                    ((flags & RayTestHitFlags.Phantom) != 0 && grp.IsPhantom) ||
                    ((flags & RayTestHitFlags.NonPhysical) != 0 && !grp.IsPhysics) ||
                    ((flags & RayTestHitFlags.Physical) != 0 && grp.IsPhysics))
                {
                    /* found a flag match */
                }
                else
                {
                    continue;
                }

                BoundingBox bbox;
                grp.GetBoundingBox(out bbox);
                bbox.CenterOffset = grp.GlobalPosition;
                bbox.Size        *= grp.GlobalRotation;
                bbox.Size         = bbox.Size.ComponentMax(-bbox.Size);
                double distance = IntersectBox(ray, ref bbox);
                if (distance < 0)
                {
                    /* only process if linkset bounding box is hit */
                    continue;
                }

                foreach (ObjectPart part in grp.ValuesByKey1)
                {
                    part.GetBoundingBox(out bbox);
                    distance = IntersectBox(ray, ref bbox);
                    if (distance < 0)
                    {
                        /* skip if not hit */
                        continue;
                    }

                    var res = new RayResult
                    {
                        ObjectId = grp.ID,
                        PartId   = part.ID
                    };

                    /* calculate actual HitPoint and HitNormal */
                    ObjectPart.PrimitiveShape shape = part.Shape;

                    MeshLOD lod = null;
                    if (shape.Type == PrimitiveShapeType.Sculpt && shape.SculptType == PrimitiveSculptType.Mesh)
                    {
                        var m = new LLMesh(m_Scene.AssetService[shape.SculptMap]);
                        foreach (LLMesh.LodLevel level in LodOrder)
                        {
                            if (m.HasLOD(level))
                            {
                                lod = m.GetLOD(level);
                                break;
                            }
                        }
                    }
                    else
                    {
                        lod = shape.ToMesh(m_Scene.AssetService);
                    }

                    if (lod != null)
                    {
                        lod.Optimize();
                        Vector3 normal;
                        foreach (Triangle tri in lod.Triangles)
                        {
                            double dist = IntersectTri(ray,
                                                       lod.Vertices[tri.Vertex1],
                                                       lod.Vertices[tri.Vertex2],
                                                       lod.Vertices[tri.Vertex3],
                                                       out normal);

                            if (dist >= 0)
                            {
                                res.HitNormalWorld = normal;
                                res.HitPointWorld  = ray.Origin + ray.Direction * dist;
                                results.Add(res);
                                break;
                            }
                        }
                    }
                }
            }
        }
Пример #24
0
        public UInt32 ObjectAdd(ObjectAdd p)
        {
            var rezparams = new RezObjectParams();
            var group     = new Object.ObjectGroup();
            var part      = new ObjectPart();

            group.Add(1, part.ID, part);
            group.Name = "Primitive";
            IAgent agent      = Agents[p.AgentID];
            UGUI   agentOwner = agent.Owner;

            group.LastOwner        = agentOwner;
            part.Creator           = agentOwner;
            rezparams.RezzingAgent = agentOwner;
            ObjectPart.PrimitiveShape pshape = part.Shape;
            pshape.PCode            = p.PCode;
            part.Material           = p.Material;
            pshape.PathCurve        = p.PathCurve;
            pshape.ProfileCurve     = p.ProfileCurve;
            pshape.PathBegin        = p.PathBegin;
            pshape.PathEnd          = p.PathEnd;
            pshape.PathScaleX       = p.PathScaleX;
            pshape.PathScaleY       = p.PathScaleY;
            pshape.PathShearX       = p.PathShearX;
            pshape.PathShearY       = p.PathShearY;
            pshape.PathTwist        = p.PathTwist;
            pshape.PathTwistBegin   = p.PathTwistBegin;
            pshape.PathRadiusOffset = p.PathRadiusOffset;
            pshape.PathTaperX       = p.PathTaperX;
            pshape.PathTaperY       = p.PathTaperY;
            pshape.PathRevolutions  = p.PathRevolutions;
            pshape.PathSkew         = p.PathSkew;
            pshape.ProfileBegin     = p.ProfileBegin;
            pshape.ProfileEnd       = p.ProfileEnd;
            pshape.ProfileHollow    = p.ProfileHollow;

            rezparams.RayStart             = p.RayStart;
            rezparams.RayEnd               = p.RayEnd;
            rezparams.RayTargetID          = p.RayTargetID;
            rezparams.RayEndIsIntersection = p.RayEndIsIntersection;
            rezparams.Scale    = p.Scale;
            rezparams.Rotation = p.Rotation;
            pshape.State       = p.State;
            group.AttachPoint  = p.LastAttachPoint;

            part.Size          = Vector3.One / 2.0;
            part.BaseMask      = p.BasePermissions;
            part.EveryoneMask  = p.EveryOnePermissions;
            part.OwnerMask     = p.CurrentPermissions;
            part.NextOwnerMask = p.NextOwnerPermissions;
            part.GroupMask     = p.GroupPermissions;
            part.Shape         = pshape;
            group.Group.ID     = p.GroupID;
            part.ObjectGroup   = group;
            part.Size          = Vector3.One / 2f;

            /* initial setup of object */
            part.UpdateData(ObjectPartLocalizedInfo.UpdateDataFlags.All);

            var selectedList = agent.SelectedObjects(ID);

            foreach (UUID old in selectedList.GetAndClear())
            {
                ObjectPart oldSelectedPart;
                if (Primitives.TryGetValue(old, out oldSelectedPart))
                {
                    agent.ScheduleUpdate(oldSelectedPart.UpdateInfo, ID);
                }
            }
            selectedList.Add(part.ID);

            return(RezObject(group, rezparams));
        }
Пример #25
0
        private static void ProcessInstances(AnArray instanceList, MeshInventoryItem item, AssetData objectAsset = null)
        {
            var grp = new ObjectGroup();

            foreach (Map instanceData in instanceList.OfType <Map>())
            {
                var shape = new ObjectPart.PrimitiveShape
                {
                    SculptType       = PrimitiveSculptType.Mesh,
                    ProfileCurve     = 1,
                    PathBegin        = 0,
                    PathCurve        = 16,
                    PathEnd          = 0,
                    PathRadiusOffset = 0,
                    PathRevolutions  = 0,
                    PathScaleX       = 100,
                    PathScaleY       = 100,
                    PathShearX       = 0,
                    PathShearY       = 0,
                    PathSkew         = 0,
                    PathTaperX       = 0,
                    PathTaperY       = 0,
                    PathTwist        = 0,
                    PathTwistBegin   = 0,
                    PCode            = PrimitiveCode.Prim,
                    ProfileBegin     = 9375,
                    ProfileEnd       = 0,
                    ProfileHollow    = 0,
                    State            = 0,
                    SculptMap        = item.MeshMap[instanceData["mesh"].AsInt]
                };

                int numfaces;
                if (item.MeshFaces.TryGetValue(instanceData["mesh"].AsInt, out numfaces))
                {
                    shape.SetMeshNumFaces(numfaces);
                }

                var part = new ObjectPart
                {
                    Name             = item.Name,
                    Shape            = shape,
                    IsReturnAtEdge   = true,
                    Size             = GetVector(instanceData["scale"]),
                    PhysicsShapeType = (PrimitivePhysicsShapeType)instanceData["physics_shape_type"].AsInt,
                    Material         = (PrimitiveMaterial)instanceData["material"].AsInt
                };

                grp.AddLink(part);

                /* use our build in transformation */
                grp.GlobalPosition = GetVector(instanceData["position"]);
                grp.GlobalRotation = GetRotation(instanceData["rotation"]);

                var  faceList = (AnArray)instanceData["face_list"];
                var  te       = new TextureEntry();
                uint faceidx  = 0;

                foreach (Map face in faceList.OfType <Map>())
                {
                    TextureEntryFace teface = te[faceidx];
                    IValue           iv;

                    teface.FullBright   = face["fullbright"].AsBoolean;
                    teface.TextureColor = GetColorAlpha(face["diffuse_color"]);

                    if (face.TryGetValue("image", out iv))
                    {
                        teface.TextureID = item.TextureMap[iv.AsInt];
                    }

                    if (face.TryGetValue("scales", out iv))
                    {
                        teface.RepeatU = (float)iv.AsReal;
                    }

                    if (face.TryGetValue("scalet", out iv))
                    {
                        teface.RepeatV = (float)iv.AsReal;
                    }

                    if (face.TryGetValue("offsets", out iv))
                    {
                        teface.OffsetU = (float)iv.AsReal;
                    }

                    if (face.TryGetValue("offsett", out iv))
                    {
                        teface.OffsetV = (float)iv.AsReal;
                    }

                    if (face.TryGetValue("imagerot", out iv))
                    {
                        teface.Rotation = (float)iv.AsReal;
                    }

                    ++faceidx;
                }
                part.TextureEntry = te;
                part.Owner        = item.Owner;
                part.Creator      = item.Owner;
                part.OwnerMask    = InventoryPermissionsMask.Every;
                part.BaseMask     = InventoryPermissionsMask.Every;
            }

            grp.Owner     = item.Owner;
            grp.LastOwner = item.Owner;

            AssetData objectasset = grp.Asset(XmlSerializationOptions.WriteXml2 | XmlSerializationOptions.WriteOwnerInfo);

            if (objectAsset != null)
            {
                objectAsset.Data = objectasset.Data;
                item.AssetID     = objectAsset.ID;
                objectAsset.Type = AssetType.Object;
            }
            else
            {
                item.AssetID = objectasset.ID;
                item.Assets.Add(objectasset);
            }
        }
Пример #26
0
 bool ISimulationDataPhysicsConvexStorageInterface.TryGetValue(ObjectPart.PrimitiveShape primShape, out PhysicsConvexShape shape) =>
 m_ConvexShapesByPrimShape.TryGetValue(primShape, out shape);
Пример #27
0
        public void HandleObjectExtraParams(Message m)
        {
            const ushort FlexiEP        = 0x10;
            const ushort LightEP        = 0x20;
            const ushort SculptEP       = 0x30;
            const ushort ProjectionEP   = 0x40;
            const ushort ExtendedMeshEP = 0x70;

            var req = (ObjectExtraParams)m;

            if (req.CircuitSessionID != req.SessionID ||
                req.CircuitAgentID != req.AgentID)
            {
                return;
            }
            IAgent agent;

            if (!Agents.TryGetValue(req.AgentID, out agent))
            {
                return;
            }

            foreach (var data in req.ObjectData)
            {
#if DEBUG
                m_Log.DebugFormat("ObjectExtraParams localid={0}", data.ObjectLocalID);
#endif

                ObjectPart part;
                if (!Primitives.TryGetValue(data.ObjectLocalID, out part))
                {
                    continue;
                }
                if (!CanEdit(agent, part.ObjectGroup, part.ObjectGroup.GlobalPosition))
                {
                    continue;
                }

                switch (data.ParamType)
                {
                case FlexiEP:
                    if (!data.ParamInUse)
                    {
                        FlexibleParam flexi = part.Flexible;
                        flexi.IsFlexible = false;
                        part.Flexible    = flexi;
                    }
                    else
                    {
                        part.Flexible = FlexibleParam.FromUdpDataBlock(data.ParamData);
                    }
                    break;

                case LightEP:
                    if (!data.ParamInUse)
                    {
                        PointLightParam light = part.PointLight;
                        light.IsLight   = false;
                        part.PointLight = light;
                    }
                    else
                    {
                        part.PointLight = PointLightParam.FromUdpDataBlock(data.ParamData);
                    }
                    break;

                case SculptEP:
                    if (data.ParamInUse && data.ParamData.Length >= 17)
                    {
                        byte[] param = data.ParamData;
                        ObjectPart.PrimitiveShape shape = part.Shape;
                        shape.SculptMap        = new UUID(param, 0);
                        shape.SculptType       = (PrimitiveSculptType)(param[16] & 0x3F);
                        shape.IsSculptInverted = (param[16] & 0x40) != 0;
                        shape.IsSculptMirrored = (param[16] & 0x80) != 0;
                        part.Shape             = shape;
                    }
                    break;

                case ProjectionEP:
                    if (!data.ParamInUse)
                    {
                        ProjectionParam proj = part.Projection;
                        proj.IsProjecting = false;
                        part.Projection   = proj;
                    }
                    else
                    {
                        part.Projection = ProjectionParam.FromUdpDataBlock(data.ParamData);
                    }
                    break;

                case ExtendedMeshEP:
                    if (!data.ParamInUse)
                    {
                        ExtendedMeshParams mesh = part.ExtendedMesh;
                        mesh.Flags        = ExtendedMeshParams.MeshFlags.None;
                        part.ExtendedMesh = mesh;
                    }
                    else
                    {
                        part.ExtendedMesh = ExtendedMeshParams.FromUdpDataBlock(data.ParamData);
                    }
                    break;
                }
            }
        }
Пример #28
0
        protected override void DetachAttachment(DetachEntry entry)
        {
            var grp = Circuits[entry.SceneID].Scene.ObjectGroups[entry.ObjectID];

            try
            {
                Circuits[entry.SceneID].Scene.Remove(grp);
            }
            catch
            {
                return;
            }
            Attachments.Remove(grp.ID);

            /* only serialize changed and/or scripted attachments */
            var isChanged  = false;
            var isScripted = false;

            foreach (var part in grp.Values)
            {
                isChanged  = isChanged || part.IsChanged;
                isScripted = isScripted || part.IsScripted;
                ObjectPart.PrimitiveShape shape = part.Shape;
                shape.State = 0;
                part.Shape  = shape;
            }

            if (isChanged || isScripted)
            {
                UUID newAssetID;
                try
                {
                    var data = grp.Asset();
                    newAssetID = data.ID;
                    AssetService.Store(data);
                }
                catch
                {
                    SendAlertMessage(this.GetLanguageString(CurrentCulture, "CouldNotStoreAttachmentData", "Could not store attachment data"), SceneID);
                    return;
                }
                try
                {
                    var item = InventoryService.Item[ID, entry.ItemID];
                    if (item.AssetType != AssetType.Object)
                    {
                        SendAlertMessage(this.GetLanguageString(CurrentCulture, "CouldNotStoreAttachmentData", "Could not store attachment data"), SceneID);
                    }
                    else
                    {
                        item.AssetID = newAssetID;
                        /* we stored the new perm flags in asset, so no need for overwrite anymore */
                        item.Flags &= ~InventoryFlags.PermOverwriteMask;
                        InventoryService.Item.Update(item);
                    }
                }
                catch
                {
                    SendAlertMessage(this.GetLanguageString(CurrentCulture, "CouldNotStoreAttachmentDataWithinItem", "Could not store attachment data within item"), SceneID);
                }
            }
        }
        public override bool Run()
        {
            ISimulationDataPhysicsConvexStorageInterface m_PhysicsStorage = SimulationData.PhysicsConvexShapes;
            var shape = new PhysicsConvexShape();
            var hull  = new PhysicsConvexShape.ConvexHull();

            hull.Vertices.Add(Vector3.UnitX);
            hull.Vertices.Add(Vector3.UnitY);
            hull.Vertices.Add(Vector3.UnitZ);
            hull.Triangles.Add(0);
            hull.Triangles.Add(1);
            hull.Triangles.Add(2);
            shape.Hulls.Add(hull);
            var shapeKey = new ObjectPart.PrimitiveShape();
            PhysicsConvexShape test;

            m_Log.Info("Testing non-existence 1");
            if (m_PhysicsStorage.ContainsKey(shapeKey))
            {
                return(false);
            }
            m_Log.Info("Testing non-existence 2");
            if (m_PhysicsStorage.TryGetValue(shapeKey, out test))
            {
                return(false);
            }
            m_Log.Info("Testing non-existence 3");
            try
            {
                shape = m_PhysicsStorage[shapeKey];
                return(false);
            }
            catch (KeyNotFoundException)
            {
                /* we should see this one */
            }
            m_Log.Info("Testing non-existence 4");
            if (m_PhysicsStorage.Remove(shapeKey))
            {
                return(false);
            }

            m_Log.Info("Create physics convex shape");
            m_PhysicsStorage[shapeKey] = shape;

            m_Log.Info("Testing existence 1");
            if (!m_PhysicsStorage.ContainsKey(shapeKey))
            {
                return(false);
            }
            m_Log.Info("Testing existence 2");
            if (!m_PhysicsStorage.TryGetValue(shapeKey, out test))
            {
                return(false);
            }
            m_Log.Info("Testing equality");
            if (!test.SerializedData.SequenceEqual(shape.SerializedData))
            {
                return(false);
            }
            m_Log.Info("Testing existence 3");
            shape = m_PhysicsStorage[shapeKey];
            m_Log.Info("Testing equality");
            if (!test.SerializedData.SequenceEqual(shape.SerializedData))
            {
                return(false);
            }
            m_Log.Info("Testing existence 4");
            if (!m_PhysicsStorage.Remove(shapeKey))
            {
                return(false);
            }

            return(true);
        }
Пример #30
0
 public static MeshLOD ToMesh(this ObjectPart.PrimitiveShape shape, AssetServiceInterface assetService) =>
 shape.DecodedParams.ToMesh(assetService);