public void Init()
        {
            Dictionary <string, string> engineParams = new Dictionary <string, string>();

            engineParams.Add("VehicleEnableAngularVerticalAttraction", "true");
            engineParams.Add("VehicleAngularVerticalAttractionAlgorithm", "1");
            PhysicsScene = BulletSimTestsUtil.CreateBasicPhysicsEngine(engineParams);

            PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateSphere();
            Vector3            pos = new Vector3(100.0f, 100.0f, 0f);

            pos.Z = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos) + 2f;
            TestVehicleInitPosition = pos;
            Vector3 size = new Vector3(1f, 1f, 1f);

            pbs.Scale = size;
            Quaternion rot     = Quaternion.Identity;
            bool       isPhys  = false;
            uint       localID = 123;

            PhysicsScene.AddPrimShape("testPrim", pbs, pos, size, rot, isPhys, localID);
            TestVehicle = (BSPrim)PhysicsScene.PhysObjects[localID];
            // The actual prim shape creation happens at taint time
            PhysicsScene.ProcessTaints();
        }
Example #2
0
        protected SceneObjectPart CreateSceneObjectPart1()
        {
            string             partName       = "My Little Pony";
            UUID               ownerId        = UUID.Parse("00000000-0000-0000-0000-000000000015");
            PrimitiveBaseShape shape          = PrimitiveBaseShape.CreateSphere();
            Vector3            groupPosition  = new Vector3(10, 20, 30);
            Quaternion         rotationOffset = new Quaternion(20, 30, 40, 50);
            Vector3            offsetPosition = new Vector3(5, 10, 15);

            return(new SceneObjectPart(ownerId, shape, groupPosition, rotationOffset, offsetPosition)
            {
                Name = partName
            });
        }
Example #3
0
        private SceneObjectGroup MakeDefaultPrim(string name)
        {
            PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere();

            shape.Scale = new Vector3(0.5f, 0.5f, 0.5f);

            SceneObjectGroup prim = new SceneObjectGroup(m_owner, new Vector3((float)m_scene.RegionInfo.RegionSizeX / 2, (float)m_scene.RegionInfo.RegionSizeY / 2, 25f), shape);

            prim.Name = name;
            prim.DetachFromBackup();
            m_scene.AddNewSceneObject(prim, false);

            return(prim);
        }
        void SetupMatrix(Scene scene)
        {
            // We're going to place a torus of dead cells in world
            float twoPi    = 2f * (float)Math.PI;
            float uSpacing = twoPi / m_xCells;
            float vSpacing = twoPi / m_yCells;
            float uRadians = 0;
            float vRadians = 0;
            int   counter  = 0;

            for (int y = 0; y < m_yCells; y++)
            {
                for (int x = 0; x < m_xCells; x++)
                {
                    //Calculate the cell's position
                    float xPos = m_xCenter + ((m_aRadius + (m_bRadius *
                                                            (float)Math.Cos(vRadians))) *
                                              (float)Math.Cos(uRadians));
                    float yPos = m_yCenter + ((m_aRadius + (m_bRadius *
                                                            (float)Math.Cos(vRadians))) *
                                              (float)Math.Sin(uRadians));
                    float   zPos = m_zCenter + (m_bRadius * (float)Math.Sin(vRadians));
                    Vector3 pos  = new Vector3(xPos, yPos, zPos);
                    //Set the size, shape, texture, and color of the cell
                    PrimitiveBaseShape prim = PrimitiveBaseShape.CreateSphere();
                    //blank texture
                    prim.Textures = new Primitive.TextureEntry(new UUID("5748decc-f629-461c-9a36-a35a236fe36f"));
                    SceneObjectGroup sog  = new SceneObjectGroup(UUID.Zero, pos, prim);
                    float            size = 0.5f + (Math.Abs(((m_xCells - 1) / 2f) - (float)x) / ((m_xCells - 1) / 3f));
                    sog.RootPart.Scale = new Vector3(size, size, size);
                    Primitive.TextureEntry tex = sog.RootPart.Shape.Textures;
                    m_cellStatus[counter]   = 0;
                    tex.DefaultTexture.RGBA = m_deadColor;
                    sog.RootPart.UpdateTexture(tex);
                    sog.RootPart.UpdatePrimFlags(false, false, true, false);
                    //Add the cell to the list of managed objects
                    m_prims.Add(sog);
                    vRadians = vRadians + vSpacing;
                    counter++;
                }
                uRadians = uRadians + uSpacing;
            }
            //Place the managed objects visibly into the scene
            m_running = false;
            foreach (SceneObjectGroup sogr in m_prims)
            {
                scene.AddNewSceneObject(sogr, false);
            }
        }
Example #5
0
        public void Init()
        {
            Dictionary<string, string> engineParams = new Dictionary<string, string>();
            engineParams.Add("UseBulletRaycast", "true");
            _physicsScene = BulletSimTestsUtil.CreateBasicPhysicsEngine(engineParams);

            PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateSphere();
            Vector3 pos = new Vector3(100.0f, 100.0f, 50f);
            _targetSpherePosition = pos;
            Vector3 size = new Vector3(10f, 10f, 10f);
            pbs.Scale = size;
            Quaternion rot = Quaternion.Identity;
            bool isPhys = false;

            _physicsScene.AddPrimShape("TargetSphere", pbs, pos, size, rot, isPhys, _targetLocalID);
            _targetSphere = (BSPrim)_physicsScene.PhysObjects[_targetLocalID];
            // The actual prim shape creation happens at taint time
            _physicsScene.ProcessTaints();

        }
        // -----------------------------------------------------------------
        /// <summary>
        /// Create one of the objects
        /// </summary>
        // -----------------------------------------------------------------
        private SceneObjectGroup CreateSortableObject()
        {
            Quaternion         rot   = new Quaternion(Vector3.Zero, 1);
            PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere();
            Vector3            pos   = new Vector3();

            pos.X = (float)(m_random.NextDouble() * m_range.X) + m_startingpos.X;
            pos.Y = (float)(m_random.NextDouble() * m_range.Y) + m_startingpos.Y;
            pos.Z = (float)(m_random.NextDouble() * m_range.Z) + m_startingpos.Z;

            SceneObjectPart sop = new SceneObjectPart(UUID.Zero, shape, pos, rot, Vector3.Zero);

            sop.Name         = "quicksort object";
            sop.Scale        = new Vector3(0.2f, 0.2f, 0.2f);
            sop.ObjectFlags |= (uint)PrimFlags.Phantom;


            // Change the color of the object
            // Vector3 color = new Vector3(m_random.Next(256),m_random.Next(256),m_random.Next(256));
            Vector3 color = RandomColor();
            Color4  texcolor;

            Primitive.TextureEntry tex = sop.Shape.Textures;
            texcolor   = tex.DefaultTexture.RGBA;
            texcolor.R = Util.Clip((float)color.X, 0.0f, 1.0f);
            texcolor.G = Util.Clip((float)color.Y, 0.0f, 1.0f);
            texcolor.B = Util.Clip((float)color.Z, 0.0f, 1.0f);
            tex.DefaultTexture.RGBA = texcolor;
            sop.Shape.Textures      = tex;

            SceneObjectGroup sog = new SceneObjectGroup(sop);

            // sog.SetRootPart(sop);
            sog.Color = System.Drawing.Color.FromArgb(0, (int)(color.X * 0xff), (int)(color.Y * 0xff), (int)(color.Z * 0xff));
            sog.Text  = string.Format("obj: {0}", SortValue(sog));

            // sog.SetText("obj",color,1.0);

            return(sog);
        }
Example #7
0
        public void TestLoadIarPathWithEscapedChars()
        {
            TestHelpers.InMethod();
//            log4net.Config.XmlConfigurator.Configure();

            string itemName             = "You & you are a mean/man/";
            string humanEscapedItemName = @"You & you are a mean\/man\/";
            string userPassword         = "******";

            InventoryArchiverModule archiverModule = new InventoryArchiverModule();

            Scene scene = new SceneHelpers().SetupScene();

            SceneHelpers.SetupSceneModules(scene, archiverModule);

            // Create user
            string userFirstName = "Jock";
            string userLastName  = "Stirrup";
            UUID   userId        = UUID.Parse("00000000-0000-0000-0000-000000000020");

            UserAccountHelpers.CreateUserWithInventory(scene, userFirstName, userLastName, userId, "meowfood");

            // Create asset
            SceneObjectGroup object1;
            SceneObjectPart  part1;
            {
                string             partName       = "part name";
                UUID               ownerId        = UUID.Parse("00000000-0000-0000-0000-000000000040");
                PrimitiveBaseShape shape          = PrimitiveBaseShape.CreateSphere();
                Vector3            groupPosition  = new Vector3(10, 20, 30);
                Quaternion         rotationOffset = new Quaternion(20, 30, 40, 50);
                Vector3            offsetPosition = new Vector3(5, 10, 15);

                part1
                    = new SceneObjectPart(
                          ownerId, shape, groupPosition, rotationOffset, offsetPosition);
                part1.Name = partName;

                object1 = new SceneObjectGroup(part1);
                scene.AddNewSceneObject(object1, false);
            }

            UUID      asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
            AssetBase asset1   = AssetHelpers.CreateAsset(asset1Id, object1);

            scene.AssetService.Store(asset1);

            // Create item
            UUID item1Id            = UUID.Parse("00000000-0000-0000-0000-000000000080");
            InventoryItemBase item1 = new InventoryItemBase();

            item1.Name    = itemName;
            item1.AssetID = asset1.FullID;
            item1.ID      = item1Id;
            InventoryFolderBase objsFolder
                = InventoryArchiveUtils.FindFoldersByPath(scene.InventoryService, userId, "Objects")[0];

            item1.Folder = objsFolder.ID;
            scene.AddInventoryItem(item1);

            MemoryStream archiveWriteStream = new MemoryStream();

            archiverModule.OnInventoryArchiveSaved += SaveCompleted;

            mre.Reset();
            archiverModule.ArchiveInventory(
                UUID.Random(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream);
            mre.WaitOne(60000, false);

            // LOAD ITEM
            MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray());

            archiverModule.DearchiveInventory(UUID.Random(), userFirstName, userLastName, "Scripts", userPassword, archiveReadStream);

            InventoryItemBase foundItem1
                = InventoryArchiveUtils.FindItemByPath(
                      scene.InventoryService, userId, "Scripts/Objects/" + humanEscapedItemName);

            Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1");
//            Assert.That(
//                foundItem1.CreatorId, Is.EqualTo(userUuid),
//                "Loaded item non-uuid creator doesn't match that of the loading user");
            Assert.That(
                foundItem1.Name, Is.EqualTo(itemName),
                "Loaded item name doesn't match saved name");
        }
        public void TestSerializeXml2()
        {
            TestHelper.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            string             rpName      = "My Little Pony";
            UUID               rpUuid      = UUID.Parse("00000000-0000-0000-0000-000000000064");
            UUID               rpCreatorId = UUID.Parse("00000000-0000-0000-0000-000000000015");
            PrimitiveBaseShape shape       = PrimitiveBaseShape.CreateSphere();
//            Vector3 groupPosition = new Vector3(10, 20, 30);
//            Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
//            Vector3 offsetPosition = new Vector3(5, 10, 15);

            SceneObjectPart rp = new SceneObjectPart();

            rp.UUID      = rpUuid;
            rp.Name      = rpName;
            rp.CreatorID = rpCreatorId;
            rp.Shape     = shape;

            SceneObjectGroup so = new SceneObjectGroup(rp);

            // Need to add the object to the scene so that the request to get script state succeeds
            m_scene.AddSceneObject(so);

            Dictionary <string, object> options = new Dictionary <string, object>();

            options["old-guids"] = true;
            string xml2 = m_serialiserModule.SerializeGroupToXml2(so, options);

            XmlTextReader xtr = new XmlTextReader(new StringReader(xml2));

            xtr.ReadStartElement("SceneObjectGroup");
            xtr.ReadStartElement("SceneObjectPart");

            UUID   uuid      = UUID.Zero;
            string name      = null;
            UUID   creatorId = UUID.Zero;

            while (xtr.Read() && xtr.Name != "SceneObjectPart")
            {
                if (xtr.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                switch (xtr.Name)
                {
                case "UUID":
                    xtr.ReadStartElement("UUID");
                    uuid = UUID.Parse(xtr.ReadElementString("Guid"));
                    xtr.ReadEndElement();
                    break;

                case "Name":
                    name = xtr.ReadElementContentAsString();
                    break;

                case "CreatorID":
                    xtr.ReadStartElement("CreatorID");
                    creatorId = UUID.Parse(xtr.ReadElementString("Guid"));
                    xtr.ReadEndElement();
                    break;
                }
            }

            xtr.ReadEndElement();
            xtr.ReadStartElement("OtherParts");
            xtr.ReadEndElement();
            xtr.Close();

            // TODO: More checks
            Assert.That(uuid, Is.EqualTo(rpUuid));
            Assert.That(name, Is.EqualTo(rpName));
            Assert.That(creatorId, Is.EqualTo(rpCreatorId));
        }
        public void TestSerializeXml()
        {
            TestHelper.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            string             rpName      = "My Little Donkey";
            UUID               rpUuid      = UUID.Parse("00000000-0000-0000-0000-000000000964");
            UUID               rpCreatorId = UUID.Parse("00000000-0000-0000-0000-000000000915");
            PrimitiveBaseShape shape       = PrimitiveBaseShape.CreateSphere();
//            Vector3 groupPosition = new Vector3(10, 20, 30);
//            Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
//            Vector3 offsetPosition = new Vector3(5, 10, 15);

            SceneObjectPart rp = new SceneObjectPart();

            rp.UUID      = rpUuid;
            rp.Name      = rpName;
            rp.CreatorID = rpCreatorId;
            rp.Shape     = shape;

            SceneObjectGroup so = new SceneObjectGroup(rp);

            // Need to add the object to the scene so that the request to get script state succeeds
            m_scene.AddSceneObject(so);

            string xml = SceneObjectSerializer.ToOriginalXmlFormat(so);

            XmlTextReader xtr = new XmlTextReader(new StringReader(xml));

            xtr.ReadStartElement("SceneObjectGroup");
            xtr.ReadStartElement("RootPart");
            xtr.ReadStartElement("SceneObjectPart");

            UUID   uuid      = UUID.Zero;
            string name      = null;
            UUID   creatorId = UUID.Zero;

            while (xtr.Read() && xtr.Name != "SceneObjectPart")
            {
                if (xtr.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                switch (xtr.Name)
                {
                case "UUID":
                    xtr.ReadStartElement("UUID");
                    try
                    {
                        uuid = UUID.Parse(xtr.ReadElementString("UUID"));
                        xtr.ReadEndElement();
                    }
                    catch { }     // ignore everything but <UUID><UUID>...</UUID></UUID>
                    break;

                case "Name":
                    name = xtr.ReadElementContentAsString();
                    break;

                case "CreatorID":
                    xtr.ReadStartElement("CreatorID");
                    creatorId = UUID.Parse(xtr.ReadElementString("UUID"));
                    xtr.ReadEndElement();
                    break;
                }
            }

            xtr.ReadEndElement();
            xtr.ReadEndElement();
            xtr.ReadStartElement("OtherParts");
            xtr.ReadEndElement();
            xtr.Close();

            // TODO: More checks
            Assert.That(uuid, Is.EqualTo(rpUuid));
            Assert.That(name, Is.EqualTo(rpName));
            Assert.That(creatorId, Is.EqualTo(rpCreatorId));
        }
        [TestCase(7, 2, 5f, 5f, 32, 0f)] /* default hull parameters */
        public void GeomHullConvexDecomp(int maxDepthSplit,
                                         int maxDepthSplitForSimpleShapes,
                                         float concavityThresholdPercent,
                                         float volumeConservationThresholdPercent,
                                         int maxVertices,
                                         float maxSkinWidth)
        {
            // Setup the physics engine to use the C# version of convex decomp
            Dictionary <string, string> engineParams = new Dictionary <string, string>();

            engineParams.Add("MeshSculptedPrim", "true");           // ShouldMeshSculptedPrim
            engineParams.Add("ForceSimplePrimMeshing", "false");    // ShouldForceSimplePrimMeshing
            engineParams.Add("UseHullsForPhysicalObjects", "true"); // ShouldUseHullsForPhysicalObjects
            engineParams.Add("ShouldRemoveZeroWidthTriangles", "true");
            engineParams.Add("ShouldUseBulletHACD", "false");
            engineParams.Add("ShouldUseSingleConvexHullForPrims", "true");
            engineParams.Add("ShouldUseGImpactShapeForPrims", "false");
            engineParams.Add("ShouldUseAssetHulls", "true");

            engineParams.Add("CSHullMaxDepthSplit", maxDepthSplit.ToString());
            engineParams.Add("CSHullMaxDepthSplitForSimpleShapes", maxDepthSplitForSimpleShapes.ToString());
            engineParams.Add("CSHullConcavityThresholdPercent", concavityThresholdPercent.ToString());
            engineParams.Add("CSHullVolumeConservationThresholdPercent", volumeConservationThresholdPercent.ToString());
            engineParams.Add("CSHullMaxVertices", maxVertices.ToString());
            engineParams.Add("CSHullMaxSkinWidth", maxSkinWidth.ToString());

            PhysicsScene = BulletSimTestsUtil.CreateBasicPhysicsEngine(engineParams);

            PrimitiveBaseShape pbs;
            Vector3            pos;
            Vector3            size;
            Quaternion         rot;
            bool isPhys;

            // Cylinder
            pbs   = PrimitiveBaseShape.CreateCylinder();
            pos   = new Vector3(100.0f, 100.0f, 0f);
            pos.Z = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos) + 10f;
            ObjectInitPosition = pos;
            size      = new Vector3(2f, 2f, 2f);
            pbs.Scale = size;
            rot       = Quaternion.Identity;
            isPhys    = true;
            uint cylinderLocalID = 123;

            PhysicsScene.AddPrimShape("testCylinder", pbs, pos, size, rot, isPhys, cylinderLocalID);
            BSPrim primTypeCylinder = (BSPrim)PhysicsScene.PhysObjects[cylinderLocalID];

            // Hollow Cylinder
            pbs = PrimitiveBaseShape.CreateCylinder();
            pbs.ProfileHollow = (ushort)(0.70f * 50000);
            pos   = new Vector3(110.0f, 110.0f, 0f);
            pos.Z = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos) + 10f;
            ObjectInitPosition = pos;
            size      = new Vector3(2f, 2f, 2f);
            pbs.Scale = size;
            rot       = Quaternion.Identity;
            isPhys    = true;
            uint hollowCylinderLocalID = 124;

            PhysicsScene.AddPrimShape("testHollowCylinder", pbs, pos, size, rot, isPhys, hollowCylinderLocalID);
            BSPrim primTypeHollowCylinder = (BSPrim)PhysicsScene.PhysObjects[hollowCylinderLocalID];

            // Torus
            // ProfileCurve = Circle, PathCurve = Curve1
            pbs = PrimitiveBaseShape.CreateSphere();
            pbs.ProfileShape = (byte)ProfileShape.Circle;
            pbs.PathCurve    = (byte)Extrusion.Curve1;
            pbs.PathScaleX   = 100; // default hollow info as set in the viewer
            pbs.PathScaleY   = (int)(.25f / 0.01f) + 200;
            pos   = new Vector3(120.0f, 120.0f, 0f);
            pos.Z = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos) + 10f;
            ObjectInitPosition = pos;
            size      = new Vector3(2f, 4f, 4f);
            pbs.Scale = size;
            rot       = Quaternion.Identity;
            isPhys    = true;
            uint torusLocalID = 125;

            PhysicsScene.AddPrimShape("testTorus", pbs, pos, size, rot, isPhys, torusLocalID);
            BSPrim primTypeTorus = (BSPrim)PhysicsScene.PhysObjects[torusLocalID];

            // The actual prim shape creation happens at taint time
            PhysicsScene.ProcessTaints();

            // Check out the created hull shapes and report their characteristics
            ReportShapeGeom(primTypeCylinder);
            ReportShapeGeom(primTypeHollowCylinder);
            ReportShapeGeom(primTypeTorus);
        }
Example #11
0
        public void TestSaveOarV0_2()
        {
            TestHelper.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            ArchiverModule   archiverModule   = new ArchiverModule();
            SerialiserModule serialiserModule = new SerialiserModule();
            TerrainModule    terrainModule    = new TerrainModule();

            Scene scene = SceneSetupHelpers.SetupScene(false);

            SceneSetupHelpers.SetupSceneModules(scene, archiverModule, serialiserModule, terrainModule);

            SceneObjectPart part1;

            // Create and add prim 1
            {
                string             partName       = "My Little Pony";
                UUID               ownerId        = UUID.Parse("00000000-0000-0000-0000-000000000015");
                PrimitiveBaseShape shape          = PrimitiveBaseShape.CreateSphere();
                Vector3            groupPosition  = new Vector3(10, 20, 30);
                Quaternion         rotationOffset = new Quaternion(20, 30, 40, 50);
                Vector3            offsetPosition = new Vector3(5, 10, 15);

                part1
                    = new SceneObjectPart(
                          ownerId, shape, groupPosition, rotationOffset, offsetPosition);
                part1.Name = partName;

                scene.AddNewSceneObject(new SceneObjectGroup(part1), false);
            }

            SceneObjectPart part2;

            // Create and add prim 2
            {
                string             partName       = "Action Man";
                UUID               ownerId        = UUID.Parse("00000000-0000-0000-0000-000000000016");
                PrimitiveBaseShape shape          = PrimitiveBaseShape.CreateCylinder();
                Vector3            groupPosition  = new Vector3(90, 80, 70);
                Quaternion         rotationOffset = new Quaternion(60, 70, 80, 90);
                Vector3            offsetPosition = new Vector3(20, 25, 30);

                part2
                    = new SceneObjectPart(
                          ownerId, shape, groupPosition, rotationOffset, offsetPosition);
                part2.Name = partName;

                scene.AddNewSceneObject(new SceneObjectGroup(part2), false);
            }

            MemoryStream archiveWriteStream = new MemoryStream();

            scene.EventManager.OnOarFileSaved += SaveCompleted;

            Guid requestId = new Guid("00000000-0000-0000-0000-808080808080");

            lock (this)
            {
                archiverModule.ArchiveRegion(archiveWriteStream, requestId);
                //AssetServerBase assetServer = (AssetServerBase)scene.CommsManager.AssetCache.AssetServer;
                //while (assetServer.HasWaitingRequests())
                //    assetServer.ProcessNextRequest();

                Monitor.Wait(this, 60000);
            }

            Assert.That(m_lastRequestId, Is.EqualTo(requestId));

            byte[]           archive           = archiveWriteStream.ToArray();
            MemoryStream     archiveReadStream = new MemoryStream(archive);
            TarArchiveReader tar = new TarArchiveReader(archiveReadStream);

            bool   gotControlFile          = false;
            bool   gotObject1File          = false;
            bool   gotObject2File          = false;
            string expectedObject1FileName = string.Format(
                "{0}_{1:000}-{2:000}-{3:000}__{4}.xml",
                part1.Name,
                Math.Round(part1.GroupPosition.X), Math.Round(part1.GroupPosition.Y), Math.Round(part1.GroupPosition.Z),
                part1.UUID);
            string expectedObject2FileName = string.Format(
                "{0}_{1:000}-{2:000}-{3:000}__{4}.xml",
                part2.Name,
                Math.Round(part2.GroupPosition.X), Math.Round(part2.GroupPosition.Y), Math.Round(part2.GroupPosition.Z),
                part2.UUID);

            string filePath;

            TarArchiveReader.TarEntryType tarEntryType;

            while (tar.ReadEntry(out filePath, out tarEntryType) != null)
            {
                if (ArchiveConstants.CONTROL_FILE_PATH == filePath)
                {
                    gotControlFile = true;
                }
                else if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH))
                {
                    string fileName = filePath.Remove(0, ArchiveConstants.OBJECTS_PATH.Length);

                    if (fileName.StartsWith(part1.Name))
                    {
                        Assert.That(fileName, Is.EqualTo(expectedObject1FileName));
                        gotObject1File = true;
                    }
                    else if (fileName.StartsWith(part2.Name))
                    {
                        Assert.That(fileName, Is.EqualTo(expectedObject2FileName));
                        gotObject2File = true;
                    }
                }
            }

            Assert.That(gotControlFile, Is.True, "No control file in archive");
            Assert.That(gotObject1File, Is.True, "No object1 file in archive");
            Assert.That(gotObject2File, Is.True, "No object2 file in archive");

            // TODO: Test presence of more files and contents of files.
        }
Example #12
0
        public void TestSaveItemToIarV0_1()
        {
            TestHelper.InMethod();
//            log4net.Config.XmlConfigurator.Configure();

            InventoryArchiverModule archiverModule = new InventoryArchiverModule(true);

            Scene scene = SceneSetupHelpers.SetupScene("Inventory");

            SceneSetupHelpers.SetupSceneModules(scene, archiverModule);

            // Create user
            string userFirstName = "Jock";
            string userLastName  = "Stirrup";
            string userPassword  = "******";
            UUID   userId        = UUID.Parse("00000000-0000-0000-0000-000000000020");

            UserProfileTestUtils.CreateUserWithInventory(scene, userFirstName, userLastName, userId, userPassword);

            // Create asset
            SceneObjectGroup object1;
            SceneObjectPart  part1;
            {
                string             partName       = "My Little Dog Object";
                UUID               ownerId        = UUID.Parse("00000000-0000-0000-0000-000000000040");
                PrimitiveBaseShape shape          = PrimitiveBaseShape.CreateSphere();
                Vector3            groupPosition  = new Vector3(10, 20, 30);
                Quaternion         rotationOffset = new Quaternion(20, 30, 40, 50);
                Vector3            offsetPosition = new Vector3(5, 10, 15);

                part1
                    = new SceneObjectPart(
                          ownerId, shape, groupPosition, rotationOffset, offsetPosition);
                part1.Name = partName;

                object1 = new SceneObjectGroup(part1);
                scene.AddNewSceneObject(object1, false);
            }

            UUID      asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
            AssetBase asset1   = AssetHelpers.CreateAsset(asset1Id, object1);

            scene.AssetService.Store(asset1);

            // Create item
            UUID              item1Id   = UUID.Parse("00000000-0000-0000-0000-000000000080");
            string            item1Name = "My Little Dog";
            InventoryItemBase item1     = new InventoryItemBase();

            item1.Name    = item1Name;
            item1.AssetID = asset1.FullID;
            item1.ID      = item1Id;
            InventoryFolderBase objsFolder
                = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects")[0];

            item1.Folder = objsFolder.ID;
            scene.AddInventoryItem(item1);

            MemoryStream archiveWriteStream = new MemoryStream();

            archiverModule.OnInventoryArchiveSaved += SaveCompleted;

            mre.Reset();
            archiverModule.ArchiveInventory(
                Guid.NewGuid(), userFirstName, userLastName, "Objects/" + item1Name, userPassword, archiveWriteStream);
            mre.WaitOne(60000, false);

            byte[]           archive           = archiveWriteStream.ToArray();
            MemoryStream     archiveReadStream = new MemoryStream(archive);
            TarArchiveReader tar = new TarArchiveReader(archiveReadStream);

            //bool gotControlFile = false;
            bool gotObject1File = false;
            //bool gotObject2File = false;
            string expectedObject1FileName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1);
            string expectedObject1FilePath = string.Format(
                "{0}{1}",
                ArchiveConstants.INVENTORY_PATH,
                expectedObject1FileName);

            string filePath;

            TarArchiveReader.TarEntryType tarEntryType;

//            Console.WriteLine("Reading archive");

            while (tar.ReadEntry(out filePath, out tarEntryType) != null)
            {
                Console.WriteLine("Got {0}", filePath);

//                if (ArchiveConstants.CONTROL_FILE_PATH == filePath)
//                {
//                    gotControlFile = true;
//                }

                if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH) && filePath.EndsWith(".xml"))
                {
//                    string fileName = filePath.Remove(0, "Objects/".Length);
//
//                    if (fileName.StartsWith(part1.Name))
//                    {
                    Assert.That(expectedObject1FilePath, Is.EqualTo(filePath));
                    gotObject1File = true;
//                    }
//                    else if (fileName.StartsWith(part2.Name))
//                    {
//                        Assert.That(fileName, Is.EqualTo(expectedObject2FileName));
//                        gotObject2File = true;
//                    }
                }
            }

//            Assert.That(gotControlFile, Is.True, "No control file in archive");
            Assert.That(gotObject1File, Is.True, "No item1 file in archive");
//            Assert.That(gotObject2File, Is.True, "No object2 file in archive");

            // TODO: Test presence of more files and contents of files.
        }
Example #13
0
        public void TestSaveIarV0p1()
        {
            TestHelper.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            InventoryArchiverModule archiverModule = new InventoryArchiverModule();

            Scene scene = SceneSetupHelpers.SetupScene(false);

            SceneSetupHelpers.SetupSceneModules(scene, archiverModule);
            CommunicationsManager cm = scene.CommsManager;

            // Create user
            string userFirstName = "Jock";
            string userLastName  = "Stirrup";
            UUID   userId        = UUID.Parse("00000000-0000-0000-0000-000000000020");

            cm.UserAdminService.AddUser(userFirstName, userLastName, string.Empty, string.Empty, 1000, 1000, userId);
            CachedUserInfo userInfo = cm.UserProfileCacheService.GetUserDetails(userId);

            userInfo.FetchInventory();

            // Create asset
            SceneObjectGroup object1;
            SceneObjectPart  part1;
            {
                string             partName       = "My Little Dog Object";
                UUID               ownerId        = UUID.Parse("00000000-0000-0000-0000-000000000040");
                PrimitiveBaseShape shape          = PrimitiveBaseShape.CreateSphere();
                Vector3            groupPosition  = new Vector3(10, 20, 30);
                Quaternion         rotationOffset = new Quaternion(20, 30, 40, 50);
                Vector3            offsetPosition = new Vector3(5, 10, 15);

                part1
                    = new SceneObjectPart(
                          ownerId, shape, groupPosition, rotationOffset, offsetPosition);
                part1.Name = partName;

                object1 = new SceneObjectGroup(part1);
                scene.AddNewSceneObject(object1, false);
            }

            UUID      asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
            AssetBase asset1   = new AssetBase();

            asset1.FullID = asset1Id;
            asset1.Data   = Encoding.ASCII.GetBytes(SceneObjectSerializer.ToXml2Format(object1));
            cm.AssetCache.AddAsset(asset1);

            // Create item
            UUID item1Id            = UUID.Parse("00000000-0000-0000-0000-000000000080");
            InventoryItemBase item1 = new InventoryItemBase();

            item1.Name    = "My Little Dog";
            item1.AssetID = asset1.FullID;
            item1.ID      = item1Id;
            item1.Folder  = userInfo.RootFolder.FindFolderByPath("Objects").ID;
            scene.AddInventoryItem(userId, item1);

            MemoryStream archiveWriteStream = new MemoryStream();

            archiverModule.OnInventoryArchiveSaved += SaveCompleted;

            lock (this)
            {
                archiverModule.ArchiveInventory(userFirstName, userLastName, "Objects", archiveWriteStream);
                AssetServerBase assetServer = (AssetServerBase)scene.CommsManager.AssetCache.AssetServer;
                while (assetServer.HasWaitingRequests())
                {
                    assetServer.ProcessNextRequest();
                }

                Monitor.Wait(this, 60000);
            }

            byte[]           archive           = archiveWriteStream.ToArray();
            MemoryStream     archiveReadStream = new MemoryStream(archive);
            TarArchiveReader tar = new TarArchiveReader(archiveReadStream);

            InventoryFolderImpl objectsFolder = userInfo.RootFolder.FindFolderByPath("Objects");

            //bool gotControlFile = false;
            bool gotObject1File = false;
            //bool gotObject2File = false;
            string expectedObject1FilePath = string.Format(
                "{0}{1}/{2}_{3}.xml",
                ArchiveConstants.INVENTORY_PATH,
                string.Format(
                    "Objects{0}{1}", ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR, objectsFolder.ID),
                item1.Name,
                item1Id);

/*
 *          string expectedObject2FileName = string.Format(
 *              "{0}_{1:000}-{2:000}-{3:000}__{4}.xml",
 *              part2.Name,
 *              Math.Round(part2.GroupPosition.X), Math.Round(part2.GroupPosition.Y), Math.Round(part2.GroupPosition.Z),
 *              part2.UUID);
 */

            string filePath;

            TarArchiveReader.TarEntryType tarEntryType;

            while (tar.ReadEntry(out filePath, out tarEntryType) != null)
            {
                Console.WriteLine("Got {0}", filePath);

                /*
                 * if (ArchiveConstants.CONTROL_FILE_PATH == filePath)
                 * {
                 *  gotControlFile = true;
                 * }
                 */
                if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH) && filePath.EndsWith(".xml"))
                {
                    //string fileName = filePath.Remove(0, "Objects/".Length);

                    //if (fileName.StartsWith(part1.Name))
                    //{
                    Assert.That(filePath, Is.EqualTo(expectedObject1FilePath));
                    gotObject1File = true;
                    //}
                    //else if (fileName.StartsWith(part2.Name))
                    //{
                    //    Assert.That(fileName, Is.EqualTo(expectedObject2FileName));
                    //    gotObject2File = true;
                    //}
                }
            }

            //Assert.That(gotControlFile, Is.True, "No control file in archive");
            Assert.That(gotObject1File, Is.True, "No item1 file in archive");
            //Assert.That(gotObject2File, Is.True, "No object2 file in archive");

            // TODO: Test presence of more files and contents of files.
        }