diff options
author | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
commit | 134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch) | |
tree | 216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs | |
parent | More changing to production grid. Double oops. (diff) | |
download | opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2 opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz |
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs | 260 |
1 files changed, 201 insertions, 59 deletions
diff --git a/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs b/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs index 5e0dfa7..5f2534b 100644 --- a/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs +++ b/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs | |||
@@ -31,21 +31,25 @@ using System.Drawing; | |||
31 | using System.Drawing.Imaging; | 31 | using System.Drawing.Imaging; |
32 | using System.IO; | 32 | using System.IO; |
33 | using System.Reflection; | 33 | using System.Reflection; |
34 | |||
34 | using CSJ2K; | 35 | using CSJ2K; |
35 | using Nini.Config; | 36 | using Nini.Config; |
36 | using log4net; | 37 | using log4net; |
37 | using Rednettle.Warp3D; | 38 | using Rednettle.Warp3D; |
38 | using Mono.Addins; | 39 | using Mono.Addins; |
39 | using OpenMetaverse; | 40 | |
40 | using OpenMetaverse.Imaging; | ||
41 | using OpenMetaverse.Rendering; | ||
42 | using OpenMetaverse.StructuredData; | ||
43 | using OpenSim.Framework; | 41 | using OpenSim.Framework; |
44 | using OpenSim.Region.Framework.Interfaces; | 42 | using OpenSim.Region.Framework.Interfaces; |
45 | using OpenSim.Region.Framework.Scenes; | 43 | using OpenSim.Region.Framework.Scenes; |
46 | using OpenSim.Region.Physics.Manager; | 44 | using OpenSim.Region.PhysicsModules.SharedBase; |
47 | using OpenSim.Services.Interfaces; | 45 | using OpenSim.Services.Interfaces; |
48 | 46 | ||
47 | using OpenMetaverse; | ||
48 | using OpenMetaverse.Assets; | ||
49 | using OpenMetaverse.Imaging; | ||
50 | using OpenMetaverse.Rendering; | ||
51 | using OpenMetaverse.StructuredData; | ||
52 | |||
49 | using WarpRenderer = global::Warp3D.Warp3D; | 53 | using WarpRenderer = global::Warp3D.Warp3D; |
50 | 54 | ||
51 | namespace OpenSim.Region.CoreModules.World.Warp3DMap | 55 | namespace OpenSim.Region.CoreModules.World.Warp3DMap |
@@ -58,11 +62,22 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
58 | 62 | ||
59 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 63 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
60 | 64 | ||
65 | #pragma warning disable 414 | ||
66 | private static string LogHeader = "[WARP 3D IMAGE MODULE]"; | ||
67 | #pragma warning restore 414 | ||
68 | |||
61 | private Scene m_scene; | 69 | private Scene m_scene; |
62 | private IRendering m_primMesher; | 70 | private IRendering m_primMesher; |
63 | private IConfigSource m_config; | ||
64 | private Dictionary<UUID, Color4> m_colors = new Dictionary<UUID, Color4>(); | 71 | private Dictionary<UUID, Color4> m_colors = new Dictionary<UUID, Color4>(); |
65 | private bool m_useAntiAliasing = false; // TODO: Make this a config option | 72 | |
73 | private IConfigSource m_config; | ||
74 | private bool m_drawPrimVolume = true; // true if should render the prims on the tile | ||
75 | private bool m_textureTerrain = true; // true if to create terrain splatting texture | ||
76 | private bool m_texturePrims = true; // true if should texture the rendered prims | ||
77 | private float m_texturePrimSize = 48f; // size of prim before we consider texturing it | ||
78 | private bool m_renderMeshes = false; // true if to render meshes rather than just bounding boxes | ||
79 | private bool m_useAntiAliasing = false; // true if to anti-alias the rendered image | ||
80 | |||
66 | private bool m_Enabled = false; | 81 | private bool m_Enabled = false; |
67 | 82 | ||
68 | #region Region Module interface | 83 | #region Region Module interface |
@@ -71,11 +86,27 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
71 | { | 86 | { |
72 | m_config = source; | 87 | m_config = source; |
73 | 88 | ||
74 | IConfig startupConfig = m_config.Configs["Startup"]; | 89 | string[] configSections = new string[] { "Map", "Startup" }; |
75 | if (startupConfig.GetString("MapImageModule", "MapImageModule") != "Warp3DImageModule") | 90 | |
91 | if (Util.GetConfigVarFromSections<string>( | ||
92 | m_config, "MapImageModule", configSections, "MapImageModule") != "Warp3DImageModule") | ||
76 | return; | 93 | return; |
77 | 94 | ||
78 | m_Enabled = true; | 95 | m_Enabled = true; |
96 | |||
97 | m_drawPrimVolume | ||
98 | = Util.GetConfigVarFromSections<bool>(m_config, "DrawPrimOnMapTile", configSections, m_drawPrimVolume); | ||
99 | m_textureTerrain | ||
100 | = Util.GetConfigVarFromSections<bool>(m_config, "TextureOnMapTile", configSections, m_textureTerrain); | ||
101 | m_texturePrims | ||
102 | = Util.GetConfigVarFromSections<bool>(m_config, "TexturePrims", configSections, m_texturePrims); | ||
103 | m_texturePrimSize | ||
104 | = Util.GetConfigVarFromSections<float>(m_config, "TexturePrimSize", configSections, m_texturePrimSize); | ||
105 | m_renderMeshes | ||
106 | = Util.GetConfigVarFromSections<bool>(m_config, "RenderMeshes", configSections, m_renderMeshes); | ||
107 | m_useAntiAliasing | ||
108 | = Util.GetConfigVarFromSections<bool>(m_config, "UseAntiAliasing", configSections, m_useAntiAliasing); | ||
109 | |||
79 | } | 110 | } |
80 | 111 | ||
81 | public void AddRegion(Scene scene) | 112 | public void AddRegion(Scene scene) |
@@ -127,33 +158,28 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
127 | 158 | ||
128 | public Bitmap CreateMapTile() | 159 | public Bitmap CreateMapTile() |
129 | { | 160 | { |
130 | Vector3 camPos = new Vector3(127.5f, 127.5f, 221.7025033688163f); | 161 | // Vector3 camPos = new Vector3(127.5f, 127.5f, 221.7025033688163f); |
131 | Viewport viewport = new Viewport(camPos, -Vector3.UnitZ, 1024f, 0.1f, (int)Constants.RegionSize, (int)Constants.RegionSize, (float)Constants.RegionSize, (float)Constants.RegionSize); | 162 | // Camera above the middle of the region |
163 | Vector3 camPos = new Vector3( | ||
164 | m_scene.RegionInfo.RegionSizeX/2 - 0.5f, | ||
165 | m_scene.RegionInfo.RegionSizeY/2 - 0.5f, | ||
166 | 221.7025033688163f); | ||
167 | // Viewport viewing down onto the region | ||
168 | Viewport viewport = new Viewport(camPos, -Vector3.UnitZ, 1024f, 0.1f, | ||
169 | (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY, | ||
170 | (float)m_scene.RegionInfo.RegionSizeX, (float)m_scene.RegionInfo.RegionSizeY ); | ||
171 | // Fill the viewport and return the image | ||
132 | return CreateMapTile(viewport, false); | 172 | return CreateMapTile(viewport, false); |
133 | } | 173 | } |
134 | 174 | ||
135 | public Bitmap CreateViewImage(Vector3 camPos, Vector3 camDir, float fov, int width, int height, bool useTextures) | 175 | public Bitmap CreateViewImage(Vector3 camPos, Vector3 camDir, float fov, int width, int height, bool useTextures) |
136 | { | 176 | { |
137 | Viewport viewport = new Viewport(camPos, camDir, fov, (float)Constants.RegionSize, 0.1f, width, height); | 177 | Viewport viewport = new Viewport(camPos, camDir, fov, Constants.RegionSize, 0.1f, width, height); |
138 | return CreateMapTile(viewport, useTextures); | 178 | return CreateMapTile(viewport, useTextures); |
139 | } | 179 | } |
140 | 180 | ||
141 | public Bitmap CreateMapTile(Viewport viewport, bool useTextures) | 181 | public Bitmap CreateMapTile(Viewport viewport, bool useTextures) |
142 | { | 182 | { |
143 | bool drawPrimVolume = true; | ||
144 | bool textureTerrain = true; | ||
145 | |||
146 | try | ||
147 | { | ||
148 | IConfig startupConfig = m_config.Configs["Startup"]; | ||
149 | drawPrimVolume = startupConfig.GetBoolean("DrawPrimOnMapTile", drawPrimVolume); | ||
150 | textureTerrain = startupConfig.GetBoolean("TextureOnMapTile", textureTerrain); | ||
151 | } | ||
152 | catch | ||
153 | { | ||
154 | m_log.Warn("[WARP 3D IMAGE MODULE]: Failed to load StartupConfig"); | ||
155 | } | ||
156 | |||
157 | m_colors.Clear(); | 183 | m_colors.Clear(); |
158 | 184 | ||
159 | int width = viewport.Width; | 185 | int width = viewport.Width; |
@@ -166,6 +192,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
166 | } | 192 | } |
167 | 193 | ||
168 | WarpRenderer renderer = new WarpRenderer(); | 194 | WarpRenderer renderer = new WarpRenderer(); |
195 | |||
169 | renderer.CreateScene(width, height); | 196 | renderer.CreateScene(width, height); |
170 | renderer.Scene.autoCalcNormals = false; | 197 | renderer.Scene.autoCalcNormals = false; |
171 | 198 | ||
@@ -197,8 +224,8 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
197 | renderer.Scene.addLight("Light2", new warp_Light(new warp_Vector(-1f, -1f, 1f), 0xffffff, 0, 100, 40)); | 224 | renderer.Scene.addLight("Light2", new warp_Light(new warp_Vector(-1f, -1f, 1f), 0xffffff, 0, 100, 40)); |
198 | 225 | ||
199 | CreateWater(renderer); | 226 | CreateWater(renderer); |
200 | CreateTerrain(renderer, textureTerrain); | 227 | CreateTerrain(renderer, m_textureTerrain); |
201 | if (drawPrimVolume) | 228 | if (m_drawPrimVolume) |
202 | CreateAllPrims(renderer, useTextures); | 229 | CreateAllPrims(renderer, useTextures); |
203 | 230 | ||
204 | renderer.Render(); | 231 | renderer.Render(); |
@@ -214,6 +241,18 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
214 | // afterwards. It's generally regarded as a bad idea to manually GC. If Warp3D is using lots of memory | 241 | // afterwards. It's generally regarded as a bad idea to manually GC. If Warp3D is using lots of memory |
215 | // then this may be some issue with the Warp3D code itself, though it's also quite possible that generating | 242 | // then this may be some issue with the Warp3D code itself, though it's also quite possible that generating |
216 | // this map tile simply takes a lot of memory. | 243 | // this map tile simply takes a lot of memory. |
244 | foreach (var o in renderer.Scene.objectData.Values) | ||
245 | { | ||
246 | warp_Object obj = (warp_Object)o; | ||
247 | obj.vertexData = null; | ||
248 | obj.triangleData = null; | ||
249 | } | ||
250 | |||
251 | renderer.Scene.removeAllObjects(); | ||
252 | renderer = null; | ||
253 | viewport = null; | ||
254 | |||
255 | m_colors.Clear(); | ||
217 | GC.Collect(); | 256 | GC.Collect(); |
218 | m_log.Debug("[WARP 3D IMAGE MODULE]: GC.Collect()"); | 257 | m_log.Debug("[WARP 3D IMAGE MODULE]: GC.Collect()"); |
219 | 258 | ||
@@ -240,61 +279,74 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
240 | 279 | ||
241 | #region Rendering Methods | 280 | #region Rendering Methods |
242 | 281 | ||
282 | // Add a water plane to the renderer. | ||
243 | private void CreateWater(WarpRenderer renderer) | 283 | private void CreateWater(WarpRenderer renderer) |
244 | { | 284 | { |
245 | float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight; | 285 | float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight; |
246 | 286 | ||
247 | renderer.AddPlane("Water", 256f * 0.5f); | 287 | renderer.AddPlane("Water", m_scene.RegionInfo.RegionSizeX * 0.5f); |
248 | renderer.Scene.sceneobject("Water").setPos(127.5f, waterHeight, 127.5f); | 288 | renderer.Scene.sceneobject("Water").setPos(m_scene.RegionInfo.RegionSizeX/2 - 0.5f, |
289 | waterHeight, | ||
290 | m_scene.RegionInfo.RegionSizeY/2 - 0.5f ); | ||
249 | 291 | ||
250 | renderer.AddMaterial("WaterColor", ConvertColor(WATER_COLOR)); | 292 | warp_Material waterColorMaterial = new warp_Material(ConvertColor(WATER_COLOR)); |
251 | renderer.Scene.material("WaterColor").setReflectivity(0); // match water color with standard map module thanks lkalif | 293 | waterColorMaterial.setReflectivity(0); // match water color with standard map module thanks lkalif |
252 | renderer.Scene.material("WaterColor").setTransparency((byte)((1f - WATER_COLOR.A) * 255f)); | 294 | waterColorMaterial.setTransparency((byte)((1f - WATER_COLOR.A) * 255f)); |
295 | renderer.Scene.addMaterial("WaterColor", waterColorMaterial); | ||
253 | renderer.SetObjectMaterial("Water", "WaterColor"); | 296 | renderer.SetObjectMaterial("Water", "WaterColor"); |
254 | } | 297 | } |
255 | 298 | ||
299 | // Add a terrain to the renderer. | ||
300 | // Note that we create a 'low resolution' 256x256 vertex terrain rather than trying for | ||
301 | // full resolution. This saves a lot of memory especially for very large regions. | ||
256 | private void CreateTerrain(WarpRenderer renderer, bool textureTerrain) | 302 | private void CreateTerrain(WarpRenderer renderer, bool textureTerrain) |
257 | { | 303 | { |
258 | ITerrainChannel terrain = m_scene.Heightmap; | 304 | ITerrainChannel terrain = m_scene.Heightmap; |
259 | float[] heightmap = terrain.GetFloatsSerialised(); | 305 | |
306 | // 'diff' is the difference in scale between the real region size and the size of terrain we're buiding | ||
307 | float diff = (float)m_scene.RegionInfo.RegionSizeX / 256f; | ||
260 | 308 | ||
261 | warp_Object obj = new warp_Object(256 * 256, 255 * 255 * 2); | 309 | warp_Object obj = new warp_Object(256 * 256, 255 * 255 * 2); |
262 | 310 | ||
263 | for (int y = 0; y < 256; y++) | 311 | // Create all the vertices for the terrain |
312 | for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff) | ||
264 | { | 313 | { |
265 | for (int x = 0; x < 256; x++) | 314 | for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff) |
266 | { | 315 | { |
267 | int v = y * 256 + x; | 316 | warp_Vector pos = ConvertVector(x, y, (float)terrain[(int)x, (int)y]); |
268 | float height = heightmap[v]; | 317 | obj.addVertex(new warp_Vertex(pos, |
269 | 318 | x / (float)m_scene.RegionInfo.RegionSizeX, | |
270 | warp_Vector pos = ConvertVector(new Vector3(x, y, height)); | 319 | (((float)m_scene.RegionInfo.RegionSizeY) - y) / m_scene.RegionInfo.RegionSizeY) ); |
271 | obj.addVertex(new warp_Vertex(pos, (float)x / 255f, (float)(255 - y) / 255f)); | ||
272 | } | 320 | } |
273 | } | 321 | } |
274 | 322 | ||
275 | for (int y = 0; y < 256; y++) | 323 | // Now that we have all the vertices, make another pass and create |
324 | // the normals for each of the surface triangles and | ||
325 | // create the list of triangle indices. | ||
326 | for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff) | ||
276 | { | 327 | { |
277 | for (int x = 0; x < 256; x++) | 328 | for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff) |
278 | { | 329 | { |
279 | if (x < 255 && y < 255) | 330 | float newX = x / diff; |
331 | float newY = y / diff; | ||
332 | if (newX < 255 && newY < 255) | ||
280 | { | 333 | { |
281 | int v = y * 256 + x; | 334 | int v = (int)newY * 256 + (int)newX; |
282 | 335 | ||
283 | // Normal | 336 | // Normal for a triangle made up of three adjacent vertices |
284 | Vector3 v1 = new Vector3(x, y, heightmap[y * 256 + x]); | 337 | Vector3 v1 = new Vector3(newX, newY, (float)terrain[(int)x, (int)y]); |
285 | Vector3 v2 = new Vector3(x + 1, y, heightmap[y * 256 + x + 1]); | 338 | Vector3 v2 = new Vector3(newX + 1, newY, (float)terrain[(int)(x + 1), (int)y]); |
286 | Vector3 v3 = new Vector3(x, y + 1, heightmap[(y + 1) * 256 + x]); | 339 | Vector3 v3 = new Vector3(newX, newY + 1, (float)terrain[(int)x, ((int)(y + 1))]); |
287 | warp_Vector norm = ConvertVector(SurfaceNormal(v1, v2, v3)); | 340 | warp_Vector norm = ConvertVector(SurfaceNormal(v1, v2, v3)); |
288 | norm = norm.reverse(); | 341 | norm = norm.reverse(); |
289 | obj.vertex(v).n = norm; | 342 | obj.vertex(v).n = norm; |
290 | 343 | ||
291 | // Triangle 1 | 344 | // Make two triangles for each of the squares in the grid of vertices |
292 | obj.addTriangle( | 345 | obj.addTriangle( |
293 | v, | 346 | v, |
294 | v + 1, | 347 | v + 1, |
295 | v + 256); | 348 | v + 256); |
296 | 349 | ||
297 | // Triangle 2 | ||
298 | obj.addTriangle( | 350 | obj.addTriangle( |
299 | v + 256 + 1, | 351 | v + 256 + 1, |
300 | v + 256, | 352 | v + 256, |
@@ -309,7 +361,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
309 | float[] startHeights = new float[4]; | 361 | float[] startHeights = new float[4]; |
310 | float[] heightRanges = new float[4]; | 362 | float[] heightRanges = new float[4]; |
311 | 363 | ||
312 | RegionSettings regionInfo = m_scene.RegionInfo.RegionSettings; | 364 | OpenSim.Framework.RegionSettings regionInfo = m_scene.RegionInfo.RegionSettings; |
313 | 365 | ||
314 | textureIDs[0] = regionInfo.TerrainTexture1; | 366 | textureIDs[0] = regionInfo.TerrainTexture1; |
315 | textureIDs[1] = regionInfo.TerrainTexture2; | 367 | textureIDs[1] = regionInfo.TerrainTexture2; |
@@ -327,14 +379,12 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
327 | heightRanges[3] = (float)regionInfo.Elevation2NE; | 379 | heightRanges[3] = (float)regionInfo.Elevation2NE; |
328 | 380 | ||
329 | uint globalX, globalY; | 381 | uint globalX, globalY; |
330 | Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out globalX, out globalY); | 382 | Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out globalX, out globalY); |
331 | 383 | ||
332 | warp_Texture texture; | 384 | warp_Texture texture; |
333 | |||
334 | using ( | 385 | using ( |
335 | Bitmap image | 386 | Bitmap image |
336 | = TerrainSplat.Splat( | 387 | = TerrainSplat.Splat(terrain, textureIDs, startHeights, heightRanges, |
337 | heightmap, textureIDs, startHeights, heightRanges, | ||
338 | new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain)) | 388 | new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain)) |
339 | { | 389 | { |
340 | texture = new warp_Texture(image); | 390 | texture = new warp_Texture(image); |
@@ -355,7 +405,6 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
355 | m_scene.ForEachSOG( | 405 | m_scene.ForEachSOG( |
356 | delegate(SceneObjectGroup group) | 406 | delegate(SceneObjectGroup group) |
357 | { | 407 | { |
358 | CreatePrim(renderer, group.RootPart, useTextures); | ||
359 | foreach (SceneObjectPart child in group.Parts) | 408 | foreach (SceneObjectPart child in group.Parts) |
360 | CreatePrim(renderer, child, useTextures); | 409 | CreatePrim(renderer, child, useTextures); |
361 | } | 410 | } |
@@ -372,8 +421,48 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
372 | if (prim.Scale.LengthSquared() < MIN_SIZE * MIN_SIZE) | 421 | if (prim.Scale.LengthSquared() < MIN_SIZE * MIN_SIZE) |
373 | return; | 422 | return; |
374 | 423 | ||
424 | FacetedMesh renderMesh = null; | ||
375 | Primitive omvPrim = prim.Shape.ToOmvPrimitive(prim.OffsetPosition, prim.RotationOffset); | 425 | Primitive omvPrim = prim.Shape.ToOmvPrimitive(prim.OffsetPosition, prim.RotationOffset); |
376 | FacetedMesh renderMesh = m_primMesher.GenerateFacetedMesh(omvPrim, DetailLevel.Medium); | 426 | |
427 | if (m_renderMeshes) | ||
428 | { | ||
429 | if (omvPrim.Sculpt != null && omvPrim.Sculpt.SculptTexture != UUID.Zero) | ||
430 | { | ||
431 | // Try fetchinng the asset | ||
432 | byte[] sculptAsset = m_scene.AssetService.GetData(omvPrim.Sculpt.SculptTexture.ToString()); | ||
433 | if (sculptAsset != null) | ||
434 | { | ||
435 | // Is it a mesh? | ||
436 | if (omvPrim.Sculpt.Type == SculptType.Mesh) | ||
437 | { | ||
438 | AssetMesh meshAsset = new AssetMesh(omvPrim.Sculpt.SculptTexture, sculptAsset); | ||
439 | FacetedMesh.TryDecodeFromAsset(omvPrim, meshAsset, DetailLevel.Highest, out renderMesh); | ||
440 | meshAsset = null; | ||
441 | } | ||
442 | else // It's sculptie | ||
443 | { | ||
444 | IJ2KDecoder imgDecoder = m_scene.RequestModuleInterface<IJ2KDecoder>(); | ||
445 | if (imgDecoder != null) | ||
446 | { | ||
447 | Image sculpt = imgDecoder.DecodeToImage(sculptAsset); | ||
448 | if (sculpt != null) | ||
449 | { | ||
450 | renderMesh = m_primMesher.GenerateFacetedSculptMesh(omvPrim, (Bitmap)sculpt, | ||
451 | DetailLevel.Medium); | ||
452 | sculpt.Dispose(); | ||
453 | } | ||
454 | } | ||
455 | } | ||
456 | } | ||
457 | } | ||
458 | } | ||
459 | |||
460 | // If not a mesh or sculptie, try the regular mesher | ||
461 | if (renderMesh == null) | ||
462 | { | ||
463 | renderMesh = m_primMesher.GenerateFacetedMesh(omvPrim, DetailLevel.Medium); | ||
464 | } | ||
465 | |||
377 | if (renderMesh == null) | 466 | if (renderMesh == null) |
378 | return; | 467 | return; |
379 | 468 | ||
@@ -432,7 +521,11 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
432 | 521 | ||
433 | Primitive.TextureEntryFace teFace = prim.Shape.Textures.GetFace((uint)i); | 522 | Primitive.TextureEntryFace teFace = prim.Shape.Textures.GetFace((uint)i); |
434 | Color4 faceColor = GetFaceColor(teFace); | 523 | Color4 faceColor = GetFaceColor(teFace); |
435 | string materialName = GetOrCreateMaterial(renderer, faceColor); | 524 | string materialName = String.Empty; |
525 | if (m_texturePrims && prim.Scale.LengthSquared() > m_texturePrimSize*m_texturePrimSize) | ||
526 | materialName = GetOrCreateMaterial(renderer, faceColor, teFace.TextureID); | ||
527 | else | ||
528 | materialName = GetOrCreateMaterial(renderer, faceColor); | ||
436 | 529 | ||
437 | faceObj.transform(m); | 530 | faceObj.transform(m); |
438 | faceObj.setPos(primPos); | 531 | faceObj.setPos(primPos); |
@@ -521,10 +614,59 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
521 | return name; | 614 | return name; |
522 | } | 615 | } |
523 | 616 | ||
617 | public string GetOrCreateMaterial(WarpRenderer renderer, Color4 faceColor, UUID textureID) | ||
618 | { | ||
619 | string materialName = "Color-" + faceColor.ToString() + "-Texture-" + textureID.ToString(); | ||
620 | |||
621 | if (renderer.Scene.material(materialName) == null) | ||
622 | { | ||
623 | renderer.AddMaterial(materialName, ConvertColor(faceColor)); | ||
624 | if (faceColor.A < 1f) | ||
625 | { | ||
626 | renderer.Scene.material(materialName).setTransparency((byte) ((1f - faceColor.A)*255f)); | ||
627 | } | ||
628 | warp_Texture texture = GetTexture(textureID); | ||
629 | if (texture != null) | ||
630 | renderer.Scene.material(materialName).setTexture(texture); | ||
631 | } | ||
632 | |||
633 | return materialName; | ||
634 | } | ||
635 | |||
636 | private warp_Texture GetTexture(UUID id) | ||
637 | { | ||
638 | warp_Texture ret = null; | ||
639 | |||
640 | byte[] asset = m_scene.AssetService.GetData(id.ToString()); | ||
641 | |||
642 | if (asset != null) | ||
643 | { | ||
644 | IJ2KDecoder imgDecoder = m_scene.RequestModuleInterface<IJ2KDecoder>(); | ||
645 | |||
646 | try | ||
647 | { | ||
648 | using (Bitmap img = (Bitmap)imgDecoder.DecodeToImage(asset)) | ||
649 | ret = new warp_Texture(img); | ||
650 | } | ||
651 | catch (Exception e) | ||
652 | { | ||
653 | m_log.Warn(string.Format("[WARP 3D IMAGE MODULE]: Failed to decode asset {0}, exception ", id), e); | ||
654 | } | ||
655 | } | ||
656 | |||
657 | return ret; | ||
658 | } | ||
659 | |||
524 | #endregion Rendering Methods | 660 | #endregion Rendering Methods |
525 | 661 | ||
526 | #region Static Helpers | 662 | #region Static Helpers |
527 | 663 | ||
664 | // Note: axis change. | ||
665 | private static warp_Vector ConvertVector(float x, float y, float z) | ||
666 | { | ||
667 | return new warp_Vector(x, z, y); | ||
668 | } | ||
669 | |||
528 | private static warp_Vector ConvertVector(Vector3 vector) | 670 | private static warp_Vector ConvertVector(Vector3 vector) |
529 | { | 671 | { |
530 | return new warp_Vector(vector.X, vector.Z, vector.Y); | 672 | return new warp_Vector(vector.X, vector.Z, vector.Y); |