aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/ContentManagementSystem/MetaEntity.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/ContentManagementSystem/MetaEntity.cs219
1 files changed, 219 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/ContentManagementSystem/MetaEntity.cs b/OpenSim/Region/Environment/Modules/ContentManagementSystem/MetaEntity.cs
new file mode 100644
index 0000000..f0763d3
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/ContentManagementSystem/MetaEntity.cs
@@ -0,0 +1,219 @@
1// MetaEntity.cs
2// User: bongiojp
3//
4// TODO:
5// Create a physics manager to the meta object if there isn't one or the object knows of no scene but the user wants physics enabled.
6
7
8using System;
9using System.Collections.Generic;
10using System.Drawing;
11using libsecondlife;
12using Nini.Config;
13using OpenSim.Framework;
14using OpenSim.Region.Environment.Interfaces;
15using OpenSim.Region.Environment.Scenes;
16using log4net;
17using OpenSim.Region.Physics.Manager;
18using Axiom.Math;
19
20namespace OpenSim.Region.Environment.Modules.ContentManagement
21{
22 public class MetaEntity
23 {
24 protected static readonly ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
25
26 protected SceneObjectGroup m_Entity = null; // The scene object group that represents this meta entity.
27 protected uint m_metaLocalid;
28
29 // Settings for transparency of metaentity
30 public const float NONE = 0f;
31 public const float TRANSLUCENT = .5f;
32 public const float INVISIBLE = .95f;
33
34 public Scene Scene
35 {
36 get { return m_Entity.Scene; }
37 }
38
39 public SceneObjectPart RootPart
40 {
41 get { return m_Entity.RootPart; }
42 set { m_Entity.RootPart = value; }
43 }
44
45 public LLUUID UUID
46 {
47 get { return m_Entity.UUID; }
48 set { m_Entity.UUID = value; }
49 }
50
51 public uint LocalId
52 {
53 get { return m_Entity.LocalId; }
54 set { m_Entity.LocalId = value; }
55 }
56
57 public SceneObjectGroup ObjectGroup
58 {
59 get { return m_Entity; }
60 }
61
62 public Dictionary<LLUUID, SceneObjectPart> Children
63 {
64 get { return m_Entity.Children; }
65 set { m_Entity.Children = value; }
66 }
67
68 public int PrimCount
69 {
70 get { return m_Entity.PrimCount; }
71 }
72
73 public MetaEntity()
74 {
75 }
76
77 /// <summary>
78 /// Makes a new meta entity by copying the given scene object group.
79 /// The physics boolean is just a stub right now.
80 /// </summary>
81 public MetaEntity(SceneObjectGroup orig, bool physics)
82 {
83 m_Entity = orig.Copy(orig.RootPart.OwnerID, orig.RootPart.GroupID, false);
84 Initialize(physics);
85 }
86
87 /// <summary>
88 /// Takes an XML description of a scene object group and converts it to a meta entity.
89 /// </summary>
90 public MetaEntity(string objectXML, Scene scene, bool physics)
91 {
92 m_Entity = new SceneObjectGroup(objectXML);
93 m_Entity.SetScene(scene);
94 Initialize(physics);
95 }
96
97 // The metaentity objectgroup must have unique localids as well as unique uuids.
98 // localids are used by the client to refer to parts.
99 // uuids are sent to the client and back to the server to identify parts on the server side.
100 /// <summary>
101 /// Changes localids and uuids of m_Entity.
102 /// </summary>
103 protected void Initialize(bool physics)
104 {
105 //make new uuids
106 Dictionary<LLUUID, SceneObjectPart> parts = new Dictionary<LLUUID, SceneObjectPart>();
107 foreach(SceneObjectPart part in m_Entity.Children.Values)
108 {
109 part.ResetIDs(part.LinkNum);
110 parts.Add(part.UUID, part);
111 }
112
113 // make new localids
114 foreach (SceneObjectPart part in m_Entity.Children.Values)
115 part.LocalId = m_Entity.Scene.PrimIDAllocate();
116
117 //finalize
118 m_Entity.UpdateParentIDs();
119 m_Entity.RootPart.PhysActor = null;
120 m_Entity.Children = parts;
121
122 }
123
124 public void SendFullUpdate(IClientAPI client)
125 {
126 // Not sure what clientFlags should be but 0 seems to work
127 SendFullUpdate(client, 0);
128 }
129 public void SendFullUpdateToAll()
130 {
131 uint clientFlags = 0;
132 m_Entity.Scene.ClientManager.ForEachClient(delegate(IClientAPI controller)
133 { m_Entity.SendFullUpdateToClient(controller, clientFlags); }
134 );
135 }
136
137 public void SendFullUpdate(IClientAPI client, uint clientFlags)
138 {
139 m_Entity.SendFullUpdateToClient(client, clientFlags);
140 }
141
142 /// <summary>
143 /// Hides the metaentity from a single client.
144 /// </summary>
145 public virtual void Hide(IClientAPI client)
146 {
147 //This deletes the group without removing from any databases.
148 //This is important because we are not IN any database.
149 //m_Entity.FakeDeleteGroup();
150 foreach( SceneObjectPart part in m_Entity.Children.Values)
151 client.SendKillObject(m_Entity.RegionHandle, part.LocalId);
152 }
153
154 /// <summary>
155 /// Sends a kill object message to all clients, effectively "hiding" the metaentity even though it's still on the server.
156 /// </summary>
157 public virtual void HideFromAll()
158 {
159 foreach( SceneObjectPart part in m_Entity.Children.Values)
160 m_Entity.Scene.ClientManager.ForEachClient(delegate(IClientAPI controller)
161 { controller.SendKillObject(m_Entity.RegionHandle, part.LocalId); }
162 );
163 }
164
165 /// <summary>
166 /// Makes a single SceneObjectPart see through.
167 /// </summary>
168 /// <param name="part">
169 /// A <see cref="SceneObjectPart"/>
170 /// The part to make see through
171 /// </param>
172 /// <param name="transparencyAmount">
173 /// A <see cref="System.Single"/>
174 /// The degree of transparency to imbue the part with, 0f being solid and .95f being invisible.
175 /// </param>
176 public static void SetPartTransparency(SceneObjectPart part, float transparencyAmount)
177 {
178 LLObject.TextureEntry tex = null;
179 LLColor texcolor;
180 try
181 {
182 tex = part.Shape.Textures;
183 texcolor = new LLColor();
184 }
185 catch(Exception)
186 {
187 //m_log.ErrorFormat("[Content Management]: Exception thrown while accessing textures of scene object: " + e);
188 return;
189 }
190
191 for (uint i = 0; i < tex.FaceTextures.Length; i++)
192 {
193 try {
194 if (tex.FaceTextures[i] != null)
195 {
196 texcolor = tex.FaceTextures[i].RGBA;
197 texcolor.A = transparencyAmount;
198 tex.FaceTextures[i].RGBA = texcolor;
199 }
200 }
201 catch (Exception)
202 {
203 //m_log.ErrorFormat("[Content Management]: Exception thrown while accessing different face textures of object: " + e);
204 continue;
205 }
206 }
207 try {
208 texcolor = tex.DefaultTexture.RGBA;
209 texcolor.A = transparencyAmount;
210 tex.DefaultTexture.RGBA = texcolor;
211 part.Shape.TextureEntry = tex.ToBytes();
212 }
213 catch (Exception)
214 {
215 //m_log.Info("[Content Management]: Exception thrown while accessing default face texture of object: " + e);
216 }
217 }
218 }
219} \ No newline at end of file