GetEntities() public method

Returns a list of the entities in the scene. This is a new list so operations perform on the list itself will not affect the original list of objects in the scene.
public GetEntities ( ) : EntityBase[]
return EntityBase[]
Exemplo n.º 1
0
        private static string GetObjectXml(Scene scene)
        {
            string xmlstream = "<scene>";

            List<EntityBase> EntityList = scene.GetEntities();
            List<string> EntityXml = new List<string>();

            foreach (EntityBase ent in EntityList)
            {
                if (ent is SceneObjectGroup)
                {
                    EntityXml.Add(SceneObjectSerializer.ToXml2Format((SceneObjectGroup)ent, false));
                }
            }
            EntityXml.Sort();

            foreach (string xml in EntityXml)
                xmlstream += xml;

            xmlstream += "</scene>";
            return xmlstream;
        }
 void Reset(Scene scene)
 {
     //Returns all plants to their default size, color
     EntityBase[] everyobject = scene.GetEntities();
     SceneObjectGroup sog;
     foreach (EntityBase entity in everyobject)
     {
         if (entity is SceneObjectGroup)
         { //make sure it is an object, not an avatar
             sog = (SceneObjectGroup)entity;
             if (sog.Name.Length > 4)
             { //Avoid an exception on non-plants with short names
                 string objecttype = sog.Name.Substring(0,5);
                 if (objecttype == "Spore")
                 {
                     Primitive.TextureEntry tex = sog.RootPart.Shape.Textures;
                     tex.DefaultTexture.RGBA = m_Brown;
                     sog.RootPart.Scale = m_sporeSize;
                     sog.RootPart.UpdateTextureEntry(tex.GetBytes());
                 }
                 else if (objecttype == "Gamet")
                 {
                     Primitive.TextureEntry tex = sog.RootPart.Shape.Textures;
                     tex.DefaultTexture.RGBA = m_Green;
                     sog.RootPart.Scale = m_gametSize;
                     sog.RootPart.UpdateTextureEntry(tex.GetBytes());
                 }
                 else if (objecttype == "Sporo")
                 {
                     Primitive.TextureEntry tex = sog.RootPart.Shape.Textures;
                     tex.DefaultTexture.RGBA = m_Green;
                     sog.RootPart.Scale = m_sporoSize;
                     sog.RootPart.UpdateTextureEntry(tex.GetBytes());
                 }
             }
         }
     }
 }
 void LocusView(Scene scene, int locus)
 {
     //For a chosen locus, colors plants based on their allele(s)
     int locusmask = (int)(Math.Pow(2, locus - 1));
     EntityBase[] everyobject = scene.GetEntities();
     SceneObjectGroup sog;
     foreach (EntityBase entity in everyobject)
     {
         if (entity is SceneObjectGroup)
         { //make sure it is an object, not an avatar
             sog = (SceneObjectGroup)entity;
             if (sog.Name.Length > 4)
             { //Avoid an exception on non-plants with short names
                 string objecttype = sog.Name.Substring(0,5);
                 if ((objecttype == "Spore") || (objecttype == "Gamet"))
                 {
                     int haplo1 = Int32.Parse(sog.Name.Substring(5));
                     if ((haplo1 & locusmask) == locusmask)
                     { // It has the dominant allele
                         Highlight(sog, m_Red); //highlight it in Red
                     }
                     else
                     { //It has the recessive allele
                         Highlight(sog, m_Blue);
                     }
                 }
                 else if (objecttype == "Sporo")
                 {
                     int geno = Int32.Parse(sog.Name.Substring(5));
                     int haplo1 = (m_haplotypes - 1) & geno;
                     int haplo2 = (geno >> m_loci) & (m_haplotypes - 1);
                     if ((haplo1 & locusmask) == (haplo2 & locusmask))
                     { //It is homozygous...
                         if ((haplo1 & locusmask) == locusmask)
                         { //...dominant
                             Highlight(sog, m_Red);
                         }
                         else
                         { //...recessive
                             Highlight(sog, m_Blue);
                         }
                     }
                     else
                     { //It is heterozygous
                         Highlight(sog, m_Purple);
                     }
                 }
             }
         }
     }
 }
 void LifestageView(Scene scene, string lifestage)
 {
     //Show plants at a particular lifestage
     EntityBase[] everyobject = scene.GetEntities();
     SceneObjectGroup sog;
     foreach (EntityBase entity in everyobject)
     {
         if (entity is SceneObjectGroup)
         { //make sure it is an object, not an avatar
             sog = (SceneObjectGroup)entity;
             if (sog.Name.Length > 4)
             { //Avoid an exception on non-plants with short names
                 string objecttype = sog.Name.Substring(0,5);
                 if (objecttype.ToLower() == lifestage.ToLower())
                 {
                     Highlight(sog, m_Blue);
                 }
             }
         }
     }
 }
 void HeterozygosityView(Scene scene)
 {
     //Show plant using grayscale representing how many loci are heterozygous
     EntityBase[] everyobject = scene.GetEntities();
     SceneObjectGroup sog;
     foreach (EntityBase entity in everyobject)
     {
         if (entity is SceneObjectGroup)
         { //make sure it is an object, not an avatar
             sog = (SceneObjectGroup)entity;
             if (sog.Name.Length > 4)
             { //Avoid an exception on non-plants with short names
                 string objecttype = sog.Name.Substring(0,5);
                 if (objecttype == "Sporo")
                 {
                     float heterozygosity = 0.0f;
                     int locus = 1;
                     int geno = Int32.Parse(sog.Name.Substring(5));
                     int haplo1 = (m_haplotypes - 1) & geno;
                     int haplo2 = (geno >> m_loci) & (m_haplotypes - 1);
                     while (locus <= m_loci)
                     {
                         int locusmask = (int)(Math.Pow(2, locus-1));
                         if ((haplo1 & locusmask) != (haplo2 & locusmask))
                         { // it is heterozygous
                             heterozygosity = heterozygosity + (1.0f / m_loci);
                         }
                         locus ++;
                     }
                     Highlight(sog, new Color4(heterozygosity, heterozygosity, heterozygosity, 1.0f));
                 }
             }
         }
     }
 }
 void HaplotypeView(Scene scene, int haplotype)
 {
     //Show plants with a particular haplotype
     EntityBase[] everyobject = scene.GetEntities();
     SceneObjectGroup sog;
     foreach (EntityBase entity in everyobject)
     {
         if (entity is SceneObjectGroup)
         { //make sure it is an object, not an avatar
             sog = (SceneObjectGroup)entity;
             if (sog.Name.Length > 4)
             { //Avoid an exception on non-plants with short names
                 string objecttype = sog.Name.Substring(0,5);
                 if ((objecttype == "Spore") || (objecttype == "Gamet"))
                 {
                     int haplo1 = Int32.Parse(sog.Name.Substring(5));
                     if (haplo1 == haplotype)
                     {
                         Highlight(sog, m_Blue);
                     }
                 }
                 else if (objecttype == "Sporo")
                 {
                     int geno = Int32.Parse(sog.Name.Substring(5));
                     int haplo1 = (m_haplotypes - 1) & geno;
                     int haplo2 = (geno >> m_loci) & (m_haplotypes - 1);
                     if ((haplo1 == haplotype) || (haplo2 == haplotype))
                     {
                         Highlight(sog, m_Blue);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Retrieves the latest revision of a region in xml form,
        /// converts it to scene object groups and scene presences,
        /// swaps the current scene's entity list with the revision's list.
        /// Note: Since deleted objects while
        /// </summary>
        public void RollbackRegion(Scene scene)
        {
            System.Collections.ArrayList xmllist = null;
            SceneObjectGroup temp = null;
            System.Collections.Hashtable deleteListUUIDs = new Hashtable();
//            Dictionary<LLUUID, EntityBase> SearchList = new Dictionary<LLUUID,EntityBase>();
            Dictionary<UUID, EntityBase> ReplacementList = new Dictionary<UUID,EntityBase>();
            int revision = m_database.GetMostRecentRevision(scene.RegionInfo.RegionID);
//            EntityBase[] searchArray;

            xmllist = m_database.GetRegionObjectXMLList(scene.RegionInfo.RegionID, revision);
            if (xmllist == null)
            {
                m_log.Info("[CMMODEL]: Region (" + scene.RegionInfo.RegionID + ") does not have given revision number (" + revision + ").");
                return;
            }

            m_log.Info("[CMMODEL]: Region (" + scene.RegionInfo.RegionID + ") revision number (" + revision + ").");
            m_log.Info("[CMMODEL]: Scene Objects = " + xmllist.Count);
            m_log.Info("[CMMODEL]: Converting scene entities list to specified revision.");

            m_log.ErrorFormat("[CMMODEL]: 1");

            foreach (string xml in xmllist)
            {
                try
                {
                    temp = SceneObjectSerializer.FromXml2Format(xml);
                    temp.SetScene(scene);
                    foreach (SceneObjectPart part in temp.Children.Values)
                        part.RegionHandle = scene.RegionInfo.RegionHandle;
                    ReplacementList.Add(temp.UUID, (EntityBase)temp);
                }
                catch (Exception e)
                {
                    m_log.Info("[CMMODEL]: Error while creating replacement list for rollback: " + e);
                }
            }

            //If in scene but not in revision and not a client, remove them
            while (true)
            {
                try
                {
                    foreach (EntityBase entity in scene.GetEntities())
                    {
                        if (entity == null)
                            continue;

                        if (entity is ScenePresence)
                        {
                            ReplacementList.Add(entity.UUID, entity);
                            continue;
                        }
                        else //if (!ReplacementList.ContainsKey(entity.UUID))
                            deleteListUUIDs.Add(entity.UUID, 0);
                    }
                }
                catch(Exception e)
                {
                    m_log.ErrorFormat("[CMMODEL]: " + e);
                    deleteListUUIDs.Clear();
                    ReplacementList.Clear();
                    continue;
                }
                break;
            }

            foreach (UUID uuid in deleteListUUIDs.Keys)
            {
                try
                {
                    // I thought that the DeleteGroup() function would handle all of this, but it doesn't. I'm not sure WHAT it handles.
                    ((SceneObjectGroup)scene.Entities[uuid]).DetachFromBackup();
                    scene.PhysicsScene.RemovePrim(((SceneObjectGroup)scene.Entities[uuid]).RootPart.PhysActor);
                    scene.SendKillObject(scene.Entities[uuid].LocalId);
                    scene.SceneGraph.DeleteSceneObject(uuid, false);
                    ((SceneObjectGroup)scene.Entities[uuid]).DeleteGroup(false);
                }
                catch(Exception e)
                {
                    m_log.ErrorFormat("[CMMODEL]: Error while removing objects from scene: " + e);
                }
            }

            lock (scene)
            {
                scene.Entities.Clear();

                foreach (KeyValuePair<UUID,EntityBase> kvp in ReplacementList)
                {
                    scene.Entities.Add(kvp.Value);
                }
            }

            foreach (EntityBase ent in ReplacementList.Values)
            {
                try
                {
                    if (!(ent is SceneObjectGroup))
                        continue;

                    if ((((SceneObjectGroup)ent).RootPart.GetEffectiveObjectFlags() & (uint) PrimFlags.Phantom) == 0)
                        ((SceneObjectGroup)ent).ApplyPhysics(true);
                    ((SceneObjectGroup)ent).AttachToBackup();
                    ((SceneObjectGroup)ent).HasGroupChanged = true; // If not true, then attaching to backup does nothing because no change is detected.
                    ((SceneObjectGroup)ent).ScheduleGroupForFullUpdate();
                }
                catch(Exception e)
                {
                    m_log.ErrorFormat("[CMMODEL]: Error while attaching new scene entities to backup and scheduling for a full update: " + e);
                }
            }
            m_log.Info("[CMMODEL]: Scheduling a backup of new scene object groups to backup.");
            scene.Backup();
        }
Exemplo n.º 8
0
 void EventManager_OnPrimsLoaded(Scene s)
 {
     // let's sniff all the user names referenced by objects in the scene
     m_log.DebugFormat("[USER MANAGEMENT MODULE]: Caching creators' data from {0} ({1} objects)...", s.RegionInfo.RegionName, s.GetEntities().Length);
     s.ForEachSOG(delegate(SceneObjectGroup sog) { CacheCreators(sog); });
 }
Exemplo n.º 9
0
        public static void SaveNamedPrimsToXml2(Scene scene, string primName, string fileName)
        {
            m_log.InfoFormat(
                "[SERIALISER]: Saving prims with name {0} in xml2 format for region {1} to {2}", 
                primName, scene.RegionInfo.RegionName, fileName);

            List<EntityBase> entityList = scene.GetEntities();
            List<EntityBase> primList = new List<EntityBase>();

            foreach (EntityBase ent in entityList)
            {
                if (ent is SceneObjectGroup)
                {
                    if (ent.Name == primName)
                    {
                        primList.Add(ent);
                    }
                }
            }

            SavePrimListToXml2(primList, fileName);
        }
Exemplo n.º 10
0
        public static void SavePrimsToXml2(Scene scene, TextWriter stream, Vector3 min, Vector3 max)
        {
            List<EntityBase> EntityList = scene.GetEntities();

            SavePrimListToXml2(EntityList, stream, min, max);
        }
Exemplo n.º 11
0
        public static void SavePrimsToXml2(Scene scene, string fileName)
        {
            List<EntityBase> EntityList = scene.GetEntities();

            SavePrimListToXml2(EntityList, fileName);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Gets list of assets
        /// </summary>
        /// <param name="scene">The scene where to get the assets</param>
        /// <param name="assetType">Type of the assets to get</param>
        /// <returns>Dictinary of assets found</returns>
        public static Dictionary<UUID, AssetBase> GetAssetList(Scene scene, int assetType)
        {
            Dictionary<UUID, AssetType> assetUuids = new Dictionary<UUID, AssetType>();

            List<EntityBase> entities = scene.GetEntities();
            List<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>();

            Dictionary<UUID, AssetBase> foundObjects = new Dictionary<UUID, AssetBase>();

            foreach (EntityBase entity in entities)
            {
                if (entity is SceneObjectGroup)
                {
                    SceneObjectGroup sceneObject = (SceneObjectGroup)entity;

                    if (!sceneObject.IsDeleted && !sceneObject.IsAttachment)
                        sceneObjects.Add((SceneObjectGroup)entity);
                }
            }

            UuidGatherer assetGatherer = new UuidGatherer(scene.AssetService);

            if (assetType == 0 || assetType == 1) //do this only for textures and sounds
            {
                foreach (SceneObjectGroup sceneObject in sceneObjects)
                {
                    assetGatherer.GatherAssetUuids(sceneObject, assetUuids);
                }
            }

            ModrexObjects module = scene.RequestModuleInterface<ModrexObjects>();
            if (module != null)
            {
                foreach (SceneObjectGroup sceneObject in sceneObjects)
                {
                    RexObjectProperties rop = module.GetObject(sceneObject.RootPart.UUID);
                    AssetBase asset;
                    switch (assetType)
                    {
                        case 1: //sound
                            if (rop.RexSoundUUID != UUID.Zero)
                            {
                                asset = scene.AssetService.Get(rop.RexSoundUUID.ToString());
                                if (asset != null && !foundObjects.ContainsKey(asset.FullID))
                                {
                                    foundObjects.Add(asset.FullID, asset);
                                }
                            }
                            break;
                        case 6: //3d
                            if (rop.RexMeshUUID != UUID.Zero)
                            {
                                asset = scene.AssetService.Get(rop.RexMeshUUID.ToString());
                                if (asset != null && !foundObjects.ContainsKey(asset.FullID))
                                {
                                    foundObjects.Add(asset.FullID, asset);
                                }
                            }
                            if (rop.RexCollisionMeshUUID != UUID.Zero)
                            {
                                asset = scene.AssetService.Get(rop.RexCollisionMeshUUID.ToString());
                                if (asset != null && !foundObjects.ContainsKey(asset.FullID))
                                {
                                    foundObjects.Add(asset.FullID, asset);
                                }
                            }
                            break;
                        case 0: //texture
                            foreach (KeyValuePair<uint, RexMaterialsDictionaryItem> kvp in rop.GetRexMaterials())
                            {
                                asset = scene.AssetService.Get(kvp.Value.AssetID.ToString());
                                if (asset != null && (int)asset.Type == assetType && !foundObjects.ContainsKey(asset.FullID))
                                {
                                    foundObjects.Add(asset.FullID, asset);
                                }
                            }
                            break;
                        case 41: //Particle
                            if (rop.RexParticleScriptUUID != UUID.Zero)
                            {
                                asset = scene.AssetService.Get(rop.RexParticleScriptUUID.ToString());
                                if (asset != null && !foundObjects.ContainsKey(asset.FullID))
                                {
                                    foundObjects.Add(asset.FullID, asset);
                                }
                            }
                            break;
                        case 45: //Material
                            foreach (KeyValuePair<uint, RexMaterialsDictionaryItem> kvp in rop.GetRexMaterials())
                            {
                                asset = scene.AssetService.Get(kvp.Value.AssetID.ToString());
                                if (asset != null && (int)asset.Type == assetType && !foundObjects.ContainsKey(asset.FullID))
                                {
                                    foundObjects.Add(asset.FullID, asset);
                                }
                            }
                            break;
                        case 19: //3d anim
                            if (rop.RexAnimationPackageUUID != UUID.Zero)
                            {
                                asset = scene.AssetService.Get(rop.RexAnimationPackageUUID.ToString());
                                if (asset != null && !foundObjects.ContainsKey(asset.FullID))
                                {
                                    foundObjects.Add(asset.FullID, asset);
                                }
                            }
                            break;

                        case 42: //flash
                            //No way to fetch flash animation from scene, since no reference to it is kept in scene
                            break;
                        default:
                            m_log.Warn("[ASSETS]: Requested list of unknown asset type");
                            break;
                    }
                }
            }

            foreach (KeyValuePair<UUID, AssetType> kvp in assetUuids)
            {
                if (kvp.Value == (AssetType)assetType)
                {
                    AssetBase asset = scene.AssetService.Get(kvp.Key.ToString());
                    if (asset != null && !foundObjects.ContainsKey(asset.FullID))
                    {
                        foundObjects.Add(asset.FullID, asset);
                    }
                }
            }

            return foundObjects;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Compares the scene's object group list to the list of meta entities. If there is an object group that does not have a corresponding meta entity
        /// it is a new part that must have a green aura (for diff mode).
        /// Returns list of ContentManagementEntities
        /// </summary>
        public ArrayList CheckForNewEntitiesMissingAuras(Scene scene)
        {
            ArrayList missingList = null;
            ArrayList newList = new ArrayList();

            m_log.Debug("[CONTENT MANAGEMENT] Checking for new scene object parts in scene: " + scene.RegionInfo.RegionName);

            //Check if the current scene has groups not included in the current list of MetaEntities
            //If so, then the current scene's parts that are new should be marked green.
            missingList = m_MetaEntityCollection.CheckForMissingEntities(scene.GetEntities());

            foreach (Object missingPart in missingList)
            {
                if (m_MetaEntityCollection.Auras.ContainsKey(((SceneObjectPart)missingPart).UUID))
                    continue;
                newList.Add(m_MetaEntityCollection.CreateAuraForNewlyCreatedEntity((SceneObjectPart)missingPart));                
            }
            m_log.Info("Number of missing objects found: " + newList.Count);
            return newList;
        }
Exemplo n.º 14
0
 public void SummarizePopulation(Scene m_scene)
 {
     //Summarize the population data for each scene in scenes
     List <String> names = new List <String>();
     lock (m_scene)
     {
         m_regionCount++;
         EntityBase[] everyObject = m_scene.GetEntities();
         foreach (EntityBase e in everyObject)
         {
             if (e is SceneObjectGroup) // ignore avatars
             {
                 SceneObjectGroup sog = (SceneObjectGroup)e;
                 names.Add(sog.Name);
             }
         }
     }
     foreach (String name in names)
     {
         if (name.Length > 4) //avoid an exception on scene objects with short names
         {
             String objectType = name.Substring(0,5);
             if (objectType == "Spore")
             {
                 m_spores++;
                 int haplo = Int32.Parse(name.Substring(5)); //Parse the haplotype from the object name
                 m_sporeHaplotypes[haplo]++;
             }
             else if (objectType == "Gamet")
             {
                 m_gametophytes++;
                 int haplo = Int32.Parse(name.Substring(5)); //Parse the haplotype from the object name
                 m_gametHaplotypes[haplo]++;
             }
             else if (objectType == "Sporo")
             {
                 m_sporophytes++;
                 int geno = Int32.Parse(name.Substring(5)); //Parse the genotype from the object name
                 int haplo1 = (m_haplotypes - 1) & geno;
                 m_sporoHaplotypes[haplo1]++;
                 int haplo2 = (geno >> m_loci) & (m_haplotypes - 1);
                 m_sporoHaplotypes[haplo2]++;
                 int locus = 1;
                 for(int i = 0; i<m_loci; i++)
                 {
                     if ((haplo1 & locus) == (haplo2 & locus))
                     {
                         //It is homozygous
                         if ((haplo1 & locus) == locus)
                         {
                             //It is homozygous dominant so it has 2 dominant alleles
                             m_dominantAlleles[i] = m_dominantAlleles[i] + 2;
                         }
                     }
                     else
                     {
                         //It is heterozygous so it has one dominant allele
                         m_heterozygotes[i]++;
                         m_dominantAlleles[i]++;
                     }
                     locus = locus * 2;
                 }
             }
         }
     }
 }
Exemplo n.º 15
0
        public static void SavePrimsToXml(Scene scene, string fileName)
        {
            FileStream file = new FileStream(fileName, FileMode.Create);
            StreamWriter stream = new StreamWriter(file);
            int primCount = 0;
            stream.WriteLine("<scene>\n");

            List<EntityBase> EntityList = scene.GetEntities();

            foreach (EntityBase ent in EntityList)
            {
                if (ent is SceneObjectGroup)
                {
                    stream.WriteLine(SceneObjectSerializer.ToOriginalXmlFormat((SceneObjectGroup)ent));
                    primCount++;
                }
            }
            stream.WriteLine("</scene>\n");
            stream.Close();
            file.Close();
        }
Exemplo n.º 16
0
        private void ArchiveOneRegion(Scene scene, string regionDir, Dictionary<UUID, sbyte> assetUuids)
        {
            m_log.InfoFormat("[ARCHIVER]: Writing region {0}", scene.Name);

            EntityBase[] entities = scene.GetEntities();
            List<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>();

            int numObjectsSkippedPermissions = 0;
         
            // Filter entities so that we only have scene objects.
            // FIXME: Would be nicer to have this as a proper list in SceneGraph, since lots of methods
            // end up having to do this
            IPermissionsModule permissionsModule = scene.RequestModuleInterface<IPermissionsModule>();
            foreach (EntityBase entity in entities)
            {
                if (entity is SceneObjectGroup)
                {
                    SceneObjectGroup sceneObject = (SceneObjectGroup)entity;

                    if (!sceneObject.IsDeleted && !sceneObject.IsAttachment)
                    {
                        if (!CanUserArchiveObject(scene.RegionInfo.EstateSettings.EstateOwner, sceneObject, FilterContent, permissionsModule))
                        {
                            // The user isn't allowed to copy/transfer this object, so it will not be included in the OAR.
                            ++numObjectsSkippedPermissions;
                        }
                        else
                        {
                            sceneObjects.Add(sceneObject);
                        }
                    }
                }
            }

            if (SaveAssets)
            {
                UuidGatherer assetGatherer = new UuidGatherer(scene.AssetService, assetUuids);
                int prevAssets = assetUuids.Count;
                    
                foreach (SceneObjectGroup sceneObject in sceneObjects)
                    assetGatherer.AddForInspection(sceneObject);

                assetGatherer.GatherAll();

                m_log.DebugFormat(
                    "[ARCHIVER]: {0} scene objects to serialize requiring save of {1} assets",
                    sceneObjects.Count, assetUuids.Count - prevAssets);
            }

            if (numObjectsSkippedPermissions > 0)
            {
                m_log.DebugFormat(
                    "[ARCHIVER]: {0} scene objects skipped due to lack of permissions",
                    numObjectsSkippedPermissions);
            }

            // Make sure that we also request terrain texture assets
            RegionSettings regionSettings = scene.RegionInfo.RegionSettings;
    
            if (regionSettings.TerrainTexture1 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_1)
                assetUuids[regionSettings.TerrainTexture1] = (sbyte)AssetType.Texture;
                
            if (regionSettings.TerrainTexture2 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_2)
                assetUuids[regionSettings.TerrainTexture2] = (sbyte)AssetType.Texture;
                
            if (regionSettings.TerrainTexture3 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_3)
                assetUuids[regionSettings.TerrainTexture3] = (sbyte)AssetType.Texture;
                
            if (regionSettings.TerrainTexture4 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_4)
                assetUuids[regionSettings.TerrainTexture4] = (sbyte)AssetType.Texture;

            Save(scene, sceneObjects, regionDir);
        }
Exemplo n.º 17
0
// TODO: unused:
//         private void ShadeBuildings(Bitmap map)
//         {
//             lock (map)
//             {
//                 lock (m_scene.Entities)
//                 {
//                     foreach (EntityBase entity in m_scene.Entities.Values)
//                     {
//                         if (entity is SceneObjectGroup)
//                         {
//                             SceneObjectGroup sog = (SceneObjectGroup) entity;
//
//                             foreach (SceneObjectPart primitive in sog.Children.Values)
//                             {
//                                 int x = (int) (primitive.AbsolutePosition.X - (primitive.Scale.X / 2));
//                                 int y = (int) (primitive.AbsolutePosition.Y - (primitive.Scale.Y / 2));
//                                 int w = (int) primitive.Scale.X;
//                                 int h = (int) primitive.Scale.Y;
//
//                                 int dx;
//                                 for (dx = x; dx < x + w; dx++)
//                                 {
//                                     int dy;
//                                     for (dy = y; dy < y + h; dy++)
//                                     {
//                                         if (x < 0 || y < 0)
//                                             continue;
//                                         if (x >= map.Width || y >= map.Height)
//                                             continue;
//
//                                         map.SetPixel(dx, dy, Color.DarkGray);
//                                     }
//                                 }
//                             }
//                         }
//                     }
//                 }
//             }
//         }

        private Bitmap DrawObjectVolume(Scene whichScene, Bitmap mapbmp)
        {
            int tc = 0;
            double[,] hm = whichScene.Heightmap.GetDoubles();
            tc = Environment.TickCount;
            m_log.Info("[MAPTILE]: Generating Maptile Step 2: Object Volume Profile");
            List<EntityBase> objs = whichScene.GetEntities();
            Dictionary<uint, DrawStruct> z_sort = new Dictionary<uint, DrawStruct>();
            //SortedList<float, RectangleDrawStruct> z_sort = new SortedList<float, RectangleDrawStruct>();
            List<float> z_sortheights = new List<float>();
            List<uint> z_localIDs = new List<uint>();

            lock (objs)
            {
                foreach (EntityBase obj in objs)
                {
                    // Only draw the contents of SceneObjectGroup
                    if (obj is SceneObjectGroup)
                    {
                        SceneObjectGroup mapdot = (SceneObjectGroup)obj;
                        Color mapdotspot = Color.Gray; // Default color when prim color is white
                        // Loop over prim in group
                        foreach (SceneObjectPart part in mapdot.Children.Values)
                        {
                            if (part == null)
                                continue;

                            // Draw if the object is at least 1 meter wide in any direction
                            if (part.Scale.X > 1f || part.Scale.Y > 1f || part.Scale.Z > 1f)
                            {
                                // Try to get the RGBA of the default texture entry..
                                //
                                try
                                {
                                    // get the null checks out of the way
                                    // skip the ones that break
                                    if (part == null)
                                        continue;

                                    if (part.Shape == null)
                                        continue;

                                    if (part.Shape.PCode == (byte)PCode.Tree || part.Shape.PCode == (byte)PCode.NewTree || part.Shape.PCode == (byte)PCode.Grass)
                                        continue; // eliminates trees from this since we don't really have a good tree representation
                                    // if you want tree blocks on the map comment the above line and uncomment the below line
                                    //mapdotspot = Color.PaleGreen;

                                    if (part.Shape.Textures == null)
                                        continue;

                                    if (part.Shape.Textures.DefaultTexture == null)
                                        continue;

                                    Color4 texcolor = part.Shape.Textures.DefaultTexture.RGBA;

                                    // Not sure why some of these are null, oh well.

                                    int colorr = 255 - (int)(texcolor.R * 255f);
                                    int colorg = 255 - (int)(texcolor.G * 255f);
                                    int colorb = 255 - (int)(texcolor.B * 255f);

                                    if (!(colorr == 255 && colorg == 255 && colorb == 255))
                                    {
                                        //Try to set the map spot color
                                        try
                                        {
                                            // If the color gets goofy somehow, skip it *shakes fist at Color4
                                            mapdotspot = Color.FromArgb(colorr, colorg, colorb);
                                        }
                                        catch (ArgumentException)
                                        {
                                        }
                                    }
                                }
                                catch (IndexOutOfRangeException)
                                {
                                    // Windows Array
                                }
                                catch (ArgumentOutOfRangeException)
                                {
                                    // Mono Array
                                }

                                Vector3 pos = part.GetWorldPosition();

                                // skip prim outside of retion
                                if (pos.X < 0.0f || pos.X >= 256.0f || pos.Y < 0.0f || pos.Y >= 256.0f)
                                    continue;

                                // skip prim in non-finite position
                                if (Single.IsNaN(pos.X) || Single.IsNaN(pos.Y) ||
                                    Single.IsInfinity(pos.X) || Single.IsInfinity(pos.Y))
                                    continue;

                                // Figure out if object is under 256m above the height of the terrain
                                bool isBelow256AboveTerrain = false;

                                try
                                {
                                    isBelow256AboveTerrain = (pos.Z < ((float)hm[(int)pos.X, (int)pos.Y] + 256f));
                                }
                                catch (Exception)
                                {
                                }

                                if (isBelow256AboveTerrain)
                                {
                                    // Translate scale by rotation so scale is represented properly when object is rotated
                                    Vector3 lscale = new Vector3(part.Shape.Scale.X, part.Shape.Scale.Y, part.Shape.Scale.Z);
                                    Vector3 scale = new Vector3();
                                    Vector3 tScale = new Vector3();
                                    Vector3 axPos = new Vector3(pos.X,pos.Y,pos.Z);

                                    Quaternion llrot = part.GetWorldRotation();
                                    Quaternion rot = new Quaternion(llrot.W, llrot.X, llrot.Y, llrot.Z);
                                    scale = lscale * rot;

                                    // negative scales don't work in this situation
                                    scale.X = Math.Abs(scale.X);
                                    scale.Y = Math.Abs(scale.Y);
                                    scale.Z = Math.Abs(scale.Z);

                                    // This scaling isn't very accurate and doesn't take into account the face rotation :P
                                    int mapdrawstartX = (int)(pos.X - scale.X);
                                    int mapdrawstartY = (int)(pos.Y - scale.Y);
                                    int mapdrawendX = (int)(pos.X + scale.X);
                                    int mapdrawendY = (int)(pos.Y + scale.Y);

                                    // If object is beyond the edge of the map, don't draw it to avoid errors
                                    if (mapdrawstartX < 0 || mapdrawstartX > 255 || mapdrawendX < 0 || mapdrawendX > 255
                                                          || mapdrawstartY < 0 || mapdrawstartY > 255 || mapdrawendY < 0
                                                          || mapdrawendY > 255)
                                        continue;

#region obb face reconstruction part duex
                                    Vector3[] vertexes = new Vector3[8];

                                    // float[] distance = new float[6];
                                    Vector3[] FaceA = new Vector3[6]; // vertex A for Facei
                                    Vector3[] FaceB = new Vector3[6]; // vertex B for Facei
                                    Vector3[] FaceC = new Vector3[6]; // vertex C for Facei
                                    Vector3[] FaceD = new Vector3[6]; // vertex D for Facei

                                    tScale = new Vector3(lscale.X, -lscale.Y, lscale.Z);
                                    scale = ((tScale * rot));
                                    vertexes[0] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
                                    // vertexes[0].x = pos.X + vertexes[0].x;
                                    //vertexes[0].y = pos.Y + vertexes[0].y;
                                    //vertexes[0].z = pos.Z + vertexes[0].z;

                                    FaceA[0] = vertexes[0];
                                    FaceB[3] = vertexes[0];
                                    FaceA[4] = vertexes[0];

                                    tScale = lscale;
                                    scale = ((tScale * rot));
                                    vertexes[1] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));

                                    // vertexes[1].x = pos.X + vertexes[1].x;
                                    // vertexes[1].y = pos.Y + vertexes[1].y;
                                    //vertexes[1].z = pos.Z + vertexes[1].z;

                                    FaceB[0] = vertexes[1];
                                    FaceA[1] = vertexes[1];
                                    FaceC[4] = vertexes[1];

                                    tScale = new Vector3(lscale.X, -lscale.Y, -lscale.Z);
                                    scale = ((tScale * rot));

                                    vertexes[2] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));

                                    //vertexes[2].x = pos.X + vertexes[2].x;
                                    //vertexes[2].y = pos.Y + vertexes[2].y;
                                    //vertexes[2].z = pos.Z + vertexes[2].z;

                                    FaceC[0] = vertexes[2];
                                    FaceD[3] = vertexes[2];
                                    FaceC[5] = vertexes[2];

                                    tScale = new Vector3(lscale.X, lscale.Y, -lscale.Z);
                                    scale = ((tScale * rot));
                                    vertexes[3] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));

                                    //vertexes[3].x = pos.X + vertexes[3].x;
                                    // vertexes[3].y = pos.Y + vertexes[3].y;
                                    // vertexes[3].z = pos.Z + vertexes[3].z;

                                    FaceD[0] = vertexes[3];
                                    FaceC[1] = vertexes[3];
                                    FaceA[5] = vertexes[3];

                                    tScale = new Vector3(-lscale.X, lscale.Y, lscale.Z);
                                    scale = ((tScale * rot));
                                    vertexes[4] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));

                                    // vertexes[4].x = pos.X + vertexes[4].x;
                                    // vertexes[4].y = pos.Y + vertexes[4].y;
                                    // vertexes[4].z = pos.Z + vertexes[4].z;

                                    FaceB[1] = vertexes[4];
                                    FaceA[2] = vertexes[4];
                                    FaceD[4] = vertexes[4];

                                    tScale = new Vector3(-lscale.X, lscale.Y, -lscale.Z);
                                    scale = ((tScale * rot));
                                    vertexes[5] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));

                                    // vertexes[5].x = pos.X + vertexes[5].x;
                                    // vertexes[5].y = pos.Y + vertexes[5].y;
                                    // vertexes[5].z = pos.Z + vertexes[5].z;

                                    FaceD[1] = vertexes[5];
                                    FaceC[2] = vertexes[5];
                                    FaceB[5] = vertexes[5];

                                    tScale = new Vector3(-lscale.X, -lscale.Y, lscale.Z);
                                    scale = ((tScale * rot));
                                    vertexes[6] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));

                                    // vertexes[6].x = pos.X + vertexes[6].x;
                                    // vertexes[6].y = pos.Y + vertexes[6].y;
                                    // vertexes[6].z = pos.Z + vertexes[6].z;

                                    FaceB[2] = vertexes[6];
                                    FaceA[3] = vertexes[6];
                                    FaceB[4] = vertexes[6];

                                    tScale = new Vector3(-lscale.X, -lscale.Y, -lscale.Z);
                                    scale = ((tScale * rot));
                                    vertexes[7] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));

                                    // vertexes[7].x = pos.X + vertexes[7].x;
                                    // vertexes[7].y = pos.Y + vertexes[7].y;
                                    // vertexes[7].z = pos.Z + vertexes[7].z;

                                    FaceD[2] = vertexes[7];
                                    FaceC[3] = vertexes[7];
                                    FaceD[5] = vertexes[7];
#endregion

                                    //int wy = 0;

                                    //bool breakYN = false; // If we run into an error drawing, break out of the
                                    // loop so we don't lag to death on error handling
                                    DrawStruct ds = new DrawStruct();
                                    ds.brush = new SolidBrush(mapdotspot);
                                    //ds.rect = new Rectangle(mapdrawstartX, (255 - mapdrawstartY), mapdrawendX - mapdrawstartX, mapdrawendY - mapdrawstartY);

                                    ds.trns = new face[FaceA.Length];

                                    for (int i = 0; i < FaceA.Length; i++)
                                    {
                                        Point[] working = new Point[5];
                                        working[0] = project(FaceA[i], axPos);
                                        working[1] = project(FaceB[i], axPos);
                                        working[2] = project(FaceD[i], axPos);
                                        working[3] = project(FaceC[i], axPos);
                                        working[4] = project(FaceA[i], axPos);

                                        face workingface = new face();
                                        workingface.pts = working;

                                        ds.trns[i] = workingface;
                                    }

                                    z_sort.Add(part.LocalId, ds);
                                    z_localIDs.Add(part.LocalId);
                                    z_sortheights.Add(pos.Z);

                                    //for (int wx = mapdrawstartX; wx < mapdrawendX; wx++)
                                    //{
                                        //for (wy = mapdrawstartY; wy < mapdrawendY; wy++)
                                        //{
                                            //m_log.InfoFormat("[MAPDEBUG]: {0},{1}({2})", wx, (255 - wy),wy);
                                            //try
                                            //{
                                                // Remember, flip the y!
                                            //    mapbmp.SetPixel(wx, (255 - wy), mapdotspot);
                                            //}
                                            //catch (ArgumentException)
                                            //{
                                            //    breakYN = true;
                                            //}

                                            //if (breakYN)
                                            //    break;
                                        //}

                                        //if (breakYN)
                                        //    break;
                                    //}
                                } // Object is within 256m Z of terrain
                            } // object is at least a meter wide
                        } // loop over group children
                    } // entitybase is sceneobject group
                } // foreach loop over entities

                float[] sortedZHeights = z_sortheights.ToArray();
                uint[] sortedlocalIds = z_localIDs.ToArray();

                // Sort prim by Z position
                Array.Sort(sortedZHeights, sortedlocalIds);

                Graphics g = Graphics.FromImage(mapbmp);

                for (int s = 0; s < sortedZHeights.Length; s++)
                {
                    if (z_sort.ContainsKey(sortedlocalIds[s]))
                    {
                        DrawStruct rectDrawStruct = z_sort[sortedlocalIds[s]];
                        for (int r = 0; r < rectDrawStruct.trns.Length; r++ )
                        {
                            g.FillPolygon(rectDrawStruct.brush,rectDrawStruct.trns[r].pts);
                        }
                        //g.FillRectangle(rectDrawStruct.brush , rectDrawStruct.rect);
                    }
                }

                g.Dispose();
            } // lock entities objs

            m_log.Info("[MAPTILE]: Generating Maptile Step 2: Done in " + (Environment.TickCount - tc) + " ms");
            return mapbmp;
        }
Exemplo n.º 18
0
        private Bitmap DrawObjectVolume(Scene whichScene, Bitmap mapbmp)
        {
            int tc = 0;
            double[,] hm = whichScene.Heightmap.GetDoubles(whichScene);
            tc = Environment.TickCount;
            //m_log.Info("[MAPTILE]: Generating Maptile Step 2: Object Volume Profile");
            EntityBase[] objs = whichScene.GetEntities();
            Dictionary<uint, DrawStruct> z_sort = new Dictionary<uint, DrawStruct>();
            //SortedList<float, RectangleDrawStruct> z_sort = new SortedList<float, RectangleDrawStruct>();
            List<float> z_sortheights = new List<float>();
            List<uint> z_localIDs = new List<uint>();

            lock (objs)
            {
                foreach (EntityBase obj in objs)
                {
                    // Only draw the contents of SceneObjectGroup
                    if (obj is SceneObjectGroup)
                    {
                        SceneObjectGroup mapdot = (SceneObjectGroup)obj;
                        Color mapdotspot = Color.Gray; // Default color when prim color is white
                        
                        // Loop over prim in group
                        foreach (SceneObjectPart part in mapdot.ChildrenList)
                        {
                            if (part == null)
                                continue;

                            // Draw if the object is at least .5 meter wide in any direction
                            if (part.Scale.X > .5f || part.Scale.Y > .5f || part.Scale.Z > .5f)
                            {
                                Vector3 pos = part.GetWorldPosition();

                                // skip prim outside of retion
                                if (pos.X < 0f || pos.X > 256f || pos.Y < 0f || pos.Y > 256f)
                                    continue;

                                // skip prim in non-finite position
                                if (Single.IsNaN(pos.X) || Single.IsNaN(pos.Y) ||
                                    Single.IsInfinity(pos.X) || Single.IsInfinity(pos.Y))
                                    continue;

                                // Figure out if object is under 256m above the height of the terrain
                                bool isBelow256AboveTerrain = false;

                                try
                                {
                                    isBelow256AboveTerrain = (pos.Z < ((float)hm[(int)pos.X, (int)pos.Y] + 256f));
                                }
                                catch (Exception)
                                {
                                }

                                if (isBelow256AboveTerrain)
                                {
                                    // Try to get the RGBA of the default texture entry..
                                    //
                                    try
                                    {
                                        // get the null checks out of the way
                                        // skip the ones that break
                                        if (part == null)
                                            continue;

                                        if (part.Shape == null)
                                            continue;

                                        if (part.Shape.PCode == (byte)PCode.Tree || part.Shape.PCode == (byte)PCode.NewTree || part.Shape.PCode == (byte)PCode.Grass)
                                            continue; // eliminates trees from this since we don't really have a good tree representation
                                        // if you want tree blocks on the map comment the above line and uncomment the below line
                                        //mapdotspot = Color.PaleGreen;

                                        Primitive.TextureEntry textureEntry = part.Shape.Textures;

                                        if (textureEntry == null || textureEntry.DefaultTexture == null)
                                            continue;
                                        Color texcolor = Color.Black;
                                        try
                                        {
                                            Primitive.TextureEntryFace tx = part.Shape.Textures.CreateFace(6);
                                            texcolor = computeAverageColor(tx.TextureID, Color.Black);
                                        }
                                        catch (Exception)
                                        {
                                            texcolor = Color.FromArgb((int)textureEntry.DefaultTexture.RGBA.A, (int)textureEntry.DefaultTexture.RGBA.R, (int)textureEntry.DefaultTexture.RGBA.G, (int)textureEntry.DefaultTexture.RGBA.B);
                                        }

                                        if (!(texcolor.R == 255 && texcolor.G == 255 && texcolor.B == 255))
                                        {
                                            // Try to set the map spot color
                                            // If the color gets goofy somehow, skip it *shakes fist at Color4
                                            mapdotspot = texcolor;
                                        }
                                    }
                                    catch (IndexOutOfRangeException)
                                    {
                                        // Windows Array
                                    }
                                    catch (ArgumentOutOfRangeException)
                                    {
                                        // Mono Array
                                    }
                                    // Translate scale by rotation so scale is represented properly when object is rotated
                                    Vector3 lscale = new Vector3(part.Shape.Scale.X, part.Shape.Scale.Y, part.Shape.Scale.Z);
                                    Vector3 scale = new Vector3();
                                    Vector3 tScale = new Vector3();
                                    Vector3 axPos = new Vector3(pos.X, pos.Y, pos.Z);

                                    scale = lscale * part.GetWorldRotation();

                                    // negative scales don't work in this situation
                                    scale.X = Math.Abs(scale.X);
                                    scale.Y = Math.Abs(scale.Y);
                                    scale.Z = Math.Abs(scale.Z);

                                    // This scaling isn't very accurate and doesn't take into account the face rotation :P
                                    int mapdrawstartX = (int)(pos.X - scale.X);
                                    int mapdrawstartY = (int)(pos.Y - scale.Y);
                                    int mapdrawendX = (int)(pos.X + scale.X);
                                    int mapdrawendY = (int)(pos.Y + scale.Y);

                                    // If object is beyond the edge of the map, don't draw it to avoid errors
                                    if (mapdrawstartX < 0 || mapdrawstartX > ((int)Constants.RegionSize - 1) || mapdrawendX < 0 || mapdrawendX > ((int)Constants.RegionSize - 1)
                                                          || mapdrawstartY < 0 || mapdrawstartY > ((int)Constants.RegionSize - 1) || mapdrawendY < 0
                                                          || mapdrawendY > ((int)Constants.RegionSize - 1))
                                        continue;

                                    #region obb face reconstruction part duex
                                    Vector3[] vertexes = new Vector3[8];

                                    // float[] distance = new float[6];
                                    Vector3[] FaceA = new Vector3[6]; // vertex A for Facei
                                    Vector3[] FaceB = new Vector3[6]; // vertex B for Facei
                                    Vector3[] FaceC = new Vector3[6]; // vertex C for Facei
                                    Vector3[] FaceD = new Vector3[6]; // vertex D for Facei

                                    tScale = new Vector3(lscale.X, -lscale.Y, lscale.Z);
                                    scale = ((tScale * part.GetWorldRotation()));
                                    vertexes[0] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));
                                    // vertexes[0].x = pos.X + vertexes[0].x;
                                    //vertexes[0].y = pos.Y + vertexes[0].y;
                                    //vertexes[0].z = pos.Z + vertexes[0].z;

                                    FaceA[0] = vertexes[0];
                                    FaceB[3] = vertexes[0];
                                    FaceA[4] = vertexes[0];

                                    tScale = lscale;
                                    scale = ((tScale * part.GetWorldRotation()));
                                    vertexes[1] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));

                                    // vertexes[1].x = pos.X + vertexes[1].x;
                                    // vertexes[1].y = pos.Y + vertexes[1].y;
                                    //vertexes[1].z = pos.Z + vertexes[1].z;

                                    FaceB[0] = vertexes[1];
                                    FaceA[1] = vertexes[1];
                                    FaceC[4] = vertexes[1];

                                    tScale = new Vector3(lscale.X, -lscale.Y, -lscale.Z);
                                    scale = ((tScale * part.GetWorldRotation()));

                                    vertexes[2] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));

                                    //vertexes[2].x = pos.X + vertexes[2].x;
                                    //vertexes[2].y = pos.Y + vertexes[2].y;
                                    //vertexes[2].z = pos.Z + vertexes[2].z;

                                    FaceC[0] = vertexes[2];
                                    FaceD[3] = vertexes[2];
                                    FaceC[5] = vertexes[2];

                                    tScale = new Vector3(lscale.X, lscale.Y, -lscale.Z);
                                    scale = ((tScale * part.GetWorldRotation()));
                                    vertexes[3] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));

                                    //vertexes[3].x = pos.X + vertexes[3].x;
                                    // vertexes[3].y = pos.Y + vertexes[3].y;
                                    // vertexes[3].z = pos.Z + vertexes[3].z;

                                    FaceD[0] = vertexes[3];
                                    FaceC[1] = vertexes[3];
                                    FaceA[5] = vertexes[3];

                                    tScale = new Vector3(-lscale.X, lscale.Y, lscale.Z);
                                    scale = ((tScale * part.GetWorldRotation()));
                                    vertexes[4] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));

                                    // vertexes[4].x = pos.X + vertexes[4].x;
                                    // vertexes[4].y = pos.Y + vertexes[4].y;
                                    // vertexes[4].z = pos.Z + vertexes[4].z;

                                    FaceB[1] = vertexes[4];
                                    FaceA[2] = vertexes[4];
                                    FaceD[4] = vertexes[4];

                                    tScale = new Vector3(-lscale.X, lscale.Y, -lscale.Z);
                                    scale = ((tScale * part.GetWorldRotation()));
                                    vertexes[5] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));

                                    // vertexes[5].x = pos.X + vertexes[5].x;
                                    // vertexes[5].y = pos.Y + vertexes[5].y;
                                    // vertexes[5].z = pos.Z + vertexes[5].z;

                                    FaceD[1] = vertexes[5];
                                    FaceC[2] = vertexes[5];
                                    FaceB[5] = vertexes[5];

                                    tScale = new Vector3(-lscale.X, -lscale.Y, lscale.Z);
                                    scale = ((tScale * part.GetWorldRotation()));
                                    vertexes[6] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));

                                    // vertexes[6].x = pos.X + vertexes[6].x;
                                    // vertexes[6].y = pos.Y + vertexes[6].y;
                                    // vertexes[6].z = pos.Z + vertexes[6].z;

                                    FaceB[2] = vertexes[6];
                                    FaceA[3] = vertexes[6];
                                    FaceB[4] = vertexes[6];

                                    tScale = new Vector3(-lscale.X, -lscale.Y, -lscale.Z);
                                    scale = ((tScale * part.GetWorldRotation()));
                                    vertexes[7] = (new Vector3((pos.X + scale.X), (pos.Y + scale.Y), (pos.Z + scale.Z)));

                                    // vertexes[7].x = pos.X + vertexes[7].x;
                                    // vertexes[7].y = pos.Y + vertexes[7].y;
                                    // vertexes[7].z = pos.Z + vertexes[7].z;

                                    FaceD[2] = vertexes[7];
                                    FaceC[3] = vertexes[7];
                                    FaceD[5] = vertexes[7];
                                    #endregion

                                    //int wy = 0;

                                    //bool breakYN = false; // If we run into an error drawing, break out of the
                                    // loop so we don't lag to death on error handling
                                    DrawStruct ds = new DrawStruct();
                                    ds.brush = new SolidBrush(mapdotspot);
                                    if (mapdot.RootPart.Shape.ProfileShape == ProfileShape.Circle)
                                    {
                                        ds.dr = DrawRoutine.Ellipse;
                                        Vector3 Location = new Vector3(part.AbsolutePosition.X - (part.Scale.X / 2),
                                            (256 - (part.AbsolutePosition.Y + (part.Scale.Y / 2))),
                                            0);
                                        Location = Location * part.GetWorldRotation();
                                        ds.rect = new Rectangle((int)Location.X, (int)Location.Y, (int)Math.Abs(part.Shape.Scale.X), (int)Math.Abs(part.Shape.Scale.Y));
                                    }
                                    else //if (mapdot.RootPart.Shape.ProfileShape == ProfileShape.Square)
                                    {
                                        ds.dr = DrawRoutine.Rectangle;
                                        //ds.rect = new Rectangle(mapdrawstartX, (255 - mapdrawstartY), mapdrawendX - mapdrawstartX, mapdrawendY - mapdrawstartY);

                                        ds.trns = new face[FaceA.Length];

                                        for (int i = 0; i < FaceA.Length; i++)
                                        {
                                            Point[] working = new Point[5];
                                            working[0] = project(FaceA[i], axPos);
                                            working[1] = project(FaceB[i], axPos);
                                            working[2] = project(FaceD[i], axPos);
                                            working[3] = project(FaceC[i], axPos);
                                            working[4] = project(FaceA[i], axPos);

                                            face workingface = new face();
                                            workingface.pts = working;

                                            ds.trns[i] = workingface;
                                        }
                                    }

                                    z_sort.Add(part.LocalId, ds);
                                    z_localIDs.Add(part.LocalId);
                                    z_sortheights.Add(pos.Z);
                                } // Object is within 256m Z of terrain
                            } // object is at least a meter wide
                        } // loop over group children
                    } // entitybase is sceneobject group
                } // foreach loop over entities

                float[] sortedZHeights = z_sortheights.ToArray();
                uint[] sortedlocalIds = z_localIDs.ToArray();

                // Sort prim by Z position
                Array.Sort(sortedZHeights, sortedlocalIds);

                Graphics g = Graphics.FromImage(mapbmp);

                for (int s = 0; s < sortedZHeights.Length; s++)
                {
                    if (z_sort.ContainsKey(sortedlocalIds[s]))
                    {
                        DrawStruct rectDrawStruct = z_sort[sortedlocalIds[s]];
                        if (rectDrawStruct.dr == DrawRoutine.Rectangle)
                        {
                            for (int r = 0; r < rectDrawStruct.trns.Length; r++)
                            {
                                g.FillPolygon(rectDrawStruct.brush, rectDrawStruct.trns[r].pts);
                            }
                        }
                        else if (rectDrawStruct.dr == DrawRoutine.Ellipse)
                        {
                            g.FillEllipse(rectDrawStruct.brush, rectDrawStruct.rect);
                        }
                        //g.FillRectangle(rectDrawStruct.brush , rectDrawStruct.rect);
                    }
                }

                g.Dispose();
            } // lock entities objs

            //m_log.Info("[MAPTILE]: Generating Maptile Step 2: Done in " + (Environment.TickCount - tc) + " ms");
            return mapbmp;
        }
Exemplo n.º 19
0
        /// <summary>
        /// Initialise all variables needed to be used by this ray tracer model. 
        /// </summary>
        /// <param name="scene">The scene in the world</param>
        /// <param name="setOfvariables">Set of variable values from the remote control</param>
        /// <param name="_scriptID">UUID of the script which called this function</param>
        public void Initialise(Scene _scene, string _setOfVariables, UUID _scriptID)
        {
            m_scene = _scene;
            m_commsMod = m_scene.RequestModuleInterface<IScriptModuleComms>();
            scriptID = _scriptID;
            setOfVariables = _setOfVariables;

            //Initialise variables parsed from the remote control. 
            int noOfInitVar = initialiseVariables(setOfVariables);
            m_log.DebugFormat("[RAY TRACER INITIALISATION]: total number of initialised variables = " + noOfInitVar.ToString());

            //Get all the entities in the world
            try { m_prims = m_scene.GetEntities(); }
            catch (Exception ex) { }

            //Initialise transmitter and receiver.
            if (!findTransmitterAndReceiver())
            {
                m_log.DebugFormat("[Ray Tracer PostInit] Transmitter and/or receiver not Found!");
                throw new Exception("Cannot find either Transmitter Tx or Receiver Ry");
            }

            //Initialise worldObjects. WorldObjects contains all the parts of the objects in the world which
            //the distance from itself to the transmitter is less than the MAX_DISTANCE. This is to reduce the
            //number of parts that we have to look at, i.e. reduces the computations time to find reflections. 

            worldObjects = new List<SceneObjectPart>();
            for (int i = 0; i < m_prims.Length; i++)
            {
                if (m_prims[i] is SceneObjectGroup)
                {
                    SceneObjectGroup sog = (SceneObjectGroup)m_prims[i];
                    sog.ForEachPart(delegate(SceneObjectPart part)
                    {
                        if (Vector3.Distance(part.AbsolutePosition, transmitter.RootPart.AbsolutePosition) <= MAX_DISTANCE || part.Name.CompareTo("Ry") == 0)
                        {
                            worldObjects.Add(part);
                        }
                    });
                }
            }
            //Initialise pathList for all reflections from 0 to max reflection
            pathHits = new Dictionary<string, PathFromTxToRy>[MAX_REFLECTIONS + 1];
            for (int i = 0; i < MAX_REFLECTIONS + 1; i++)
            {
                pathHits[i] = new Dictionary<string, PathFromTxToRy>();
            }
            
            m_log.DebugFormat("[RAY TRACER INITIALISATION]: Complete!");

        }