diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs | 239 |
1 files changed, 96 insertions, 143 deletions
diff --git a/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs b/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs index 383a67f..4934ebd 100644 --- a/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs +++ b/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs | |||
@@ -35,7 +35,7 @@ using System.Reflection; | |||
35 | using CSJ2K; | 35 | using CSJ2K; |
36 | using Nini.Config; | 36 | using Nini.Config; |
37 | using log4net; | 37 | using log4net; |
38 | using Rednettle.Warp3D; | 38 | using Warp3D; |
39 | using Mono.Addins; | 39 | using Mono.Addins; |
40 | 40 | ||
41 | using OpenSim.Framework; | 41 | using OpenSim.Framework; |
@@ -76,10 +76,12 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
76 | private bool m_texturePrims = true; // true if should texture the rendered prims | 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 | 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 | 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 | 79 | ||
81 | private bool m_Enabled = false; | 80 | private bool m_Enabled = false; |
82 | 81 | ||
82 | // private Bitmap lastImage = null; | ||
83 | private DateTime lastImageTime = DateTime.MinValue; | ||
84 | |||
83 | #region Region Module interface | 85 | #region Region Module interface |
84 | 86 | ||
85 | public void Initialise(IConfigSource source) | 87 | public void Initialise(IConfigSource source) |
@@ -94,9 +96,9 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
94 | 96 | ||
95 | m_Enabled = true; | 97 | m_Enabled = true; |
96 | 98 | ||
97 | m_drawPrimVolume | 99 | m_drawPrimVolume |
98 | = Util.GetConfigVarFromSections<bool>(m_config, "DrawPrimOnMapTile", configSections, m_drawPrimVolume); | 100 | = Util.GetConfigVarFromSections<bool>(m_config, "DrawPrimOnMapTile", configSections, m_drawPrimVolume); |
99 | m_textureTerrain | 101 | m_textureTerrain |
100 | = Util.GetConfigVarFromSections<bool>(m_config, "TextureOnMapTile", configSections, m_textureTerrain); | 102 | = Util.GetConfigVarFromSections<bool>(m_config, "TextureOnMapTile", configSections, m_textureTerrain); |
101 | m_texturePrims | 103 | m_texturePrims |
102 | = Util.GetConfigVarFromSections<bool>(m_config, "TexturePrims", configSections, m_texturePrims); | 104 | = Util.GetConfigVarFromSections<bool>(m_config, "TexturePrims", configSections, m_texturePrims); |
@@ -104,10 +106,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
104 | = Util.GetConfigVarFromSections<float>(m_config, "TexturePrimSize", configSections, m_texturePrimSize); | 106 | = Util.GetConfigVarFromSections<float>(m_config, "TexturePrimSize", configSections, m_texturePrimSize); |
105 | m_renderMeshes | 107 | m_renderMeshes |
106 | = Util.GetConfigVarFromSections<bool>(m_config, "RenderMeshes", configSections, m_renderMeshes); | 108 | = Util.GetConfigVarFromSections<bool>(m_config, "RenderMeshes", configSections, m_renderMeshes); |
107 | m_useAntiAliasing | 109 | } |
108 | = Util.GetConfigVarFromSections<bool>(m_config, "UseAntiAliasing", configSections, m_useAntiAliasing); | ||
109 | |||
110 | } | ||
111 | 110 | ||
112 | public void AddRegion(Scene scene) | 111 | public void AddRegion(Scene scene) |
113 | { | 112 | { |
@@ -118,14 +117,9 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
118 | 117 | ||
119 | List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory()); | 118 | List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory()); |
120 | if (renderers.Count > 0) | 119 | if (renderers.Count > 0) |
121 | { | 120 | m_log.Info("[MAPTILE]: Loaded prim mesher " + renderers[0]); |
122 | m_primMesher = RenderingLoader.LoadRenderer(renderers[0]); | ||
123 | m_log.DebugFormat("[WARP 3D IMAGE MODULE]: Loaded prim mesher {0}", m_primMesher); | ||
124 | } | ||
125 | else | 121 | else |
126 | { | 122 | m_log.Info("[MAPTILE]: No prim mesher loaded, prim rendering will be disabled"); |
127 | m_log.Debug("[WARP 3D IMAGE MODULE]: No prim mesher loaded, prim rendering will be disabled"); | ||
128 | } | ||
129 | 123 | ||
130 | m_scene.RegisterModuleInterface<IMapImageGenerator>(this); | 124 | m_scene.RegisterModuleInterface<IMapImageGenerator>(this); |
131 | } | 125 | } |
@@ -158,18 +152,36 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
158 | 152 | ||
159 | public Bitmap CreateMapTile() | 153 | public Bitmap CreateMapTile() |
160 | { | 154 | { |
161 | // Vector3 camPos = new Vector3(127.5f, 127.5f, 221.7025033688163f); | 155 | /* this must be on all map, not just its image |
162 | // Camera above the middle of the region | 156 | if ((DateTime.Now - lastImageTime).TotalSeconds < 3600) |
157 | { | ||
158 | return (Bitmap)lastImage.Clone(); | ||
159 | } | ||
160 | */ | ||
161 | |||
162 | List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory()); | ||
163 | if (renderers.Count > 0) | ||
164 | { | ||
165 | m_primMesher = RenderingLoader.LoadRenderer(renderers[0]); | ||
166 | } | ||
167 | |||
163 | Vector3 camPos = new Vector3( | 168 | Vector3 camPos = new Vector3( |
164 | m_scene.RegionInfo.RegionSizeX/2 - 0.5f, | 169 | m_scene.RegionInfo.RegionSizeX / 2 - 0.5f, |
165 | m_scene.RegionInfo.RegionSizeY/2 - 0.5f, | 170 | m_scene.RegionInfo.RegionSizeY / 2 - 0.5f, |
166 | 221.7025033688163f); | 171 | 221.7025033688163f); |
167 | // Viewport viewing down onto the region | 172 | // Viewport viewing down onto the region |
168 | Viewport viewport = new Viewport(camPos, -Vector3.UnitZ, 1024f, 0.1f, | 173 | Viewport viewport = new Viewport(camPos, -Vector3.UnitZ, 1024f, 0.1f, |
169 | (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY, | 174 | (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY, |
170 | (float)m_scene.RegionInfo.RegionSizeX, (float)m_scene.RegionInfo.RegionSizeY ); | 175 | (float)m_scene.RegionInfo.RegionSizeX, (float)m_scene.RegionInfo.RegionSizeY); |
171 | // Fill the viewport and return the image | 176 | |
172 | return CreateMapTile(viewport, false); | 177 | Bitmap tile = CreateMapTile(viewport, false); |
178 | m_primMesher = null; | ||
179 | return tile; | ||
180 | /* | ||
181 | lastImage = tile; | ||
182 | lastImageTime = DateTime.Now; | ||
183 | return (Bitmap)lastImage.Clone(); | ||
184 | */ | ||
173 | } | 185 | } |
174 | 186 | ||
175 | public Bitmap CreateViewImage(Vector3 camPos, Vector3 camDir, float fov, int width, int height, bool useTextures) | 187 | public Bitmap CreateViewImage(Vector3 camPos, Vector3 camDir, float fov, int width, int height, bool useTextures) |
@@ -185,21 +197,14 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
185 | int width = viewport.Width; | 197 | int width = viewport.Width; |
186 | int height = viewport.Height; | 198 | int height = viewport.Height; |
187 | 199 | ||
188 | if (m_useAntiAliasing) | ||
189 | { | ||
190 | width *= 2; | ||
191 | height *= 2; | ||
192 | } | ||
193 | |||
194 | WarpRenderer renderer = new WarpRenderer(); | 200 | WarpRenderer renderer = new WarpRenderer(); |
195 | 201 | ||
196 | renderer.CreateScene(width, height); | 202 | if(!renderer.CreateScene(width, height)) |
197 | renderer.Scene.autoCalcNormals = false; | 203 | return new Bitmap(width,height); |
198 | 204 | ||
199 | #region Camera | 205 | #region Camera |
200 | 206 | ||
201 | warp_Vector pos = ConvertVector(viewport.Position); | 207 | warp_Vector pos = ConvertVector(viewport.Position); |
202 | pos.z -= 0.001f; // Works around an issue with the Warp3D camera | ||
203 | warp_Vector lookat = warp_Vector.add(ConvertVector(viewport.Position), ConvertVector(viewport.LookDirection)); | 208 | warp_Vector lookat = warp_Vector.add(ConvertVector(viewport.Position), ConvertVector(viewport.LookDirection)); |
204 | 209 | ||
205 | renderer.Scene.defaultCamera.setPos(pos); | 210 | renderer.Scene.defaultCamera.setPos(pos); |
@@ -207,9 +212,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
207 | 212 | ||
208 | if (viewport.Orthographic) | 213 | if (viewport.Orthographic) |
209 | { | 214 | { |
210 | renderer.Scene.defaultCamera.isOrthographic = true; | 215 | renderer.Scene.defaultCamera.setOrthographic(true,viewport.OrthoWindowWidth, viewport.OrthoWindowHeight); |
211 | renderer.Scene.defaultCamera.orthoViewWidth = viewport.OrthoWindowWidth; | ||
212 | renderer.Scene.defaultCamera.orthoViewHeight = viewport.OrthoWindowHeight; | ||
213 | } | 216 | } |
214 | else | 217 | else |
215 | { | 218 | { |
@@ -231,24 +234,8 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
231 | renderer.Render(); | 234 | renderer.Render(); |
232 | Bitmap bitmap = renderer.Scene.getImage(); | 235 | Bitmap bitmap = renderer.Scene.getImage(); |
233 | 236 | ||
234 | if (m_useAntiAliasing) | 237 | renderer.Scene.destroy(); |
235 | { | 238 | renderer.Reset(); |
236 | using (Bitmap origBitmap = bitmap) | ||
237 | bitmap = ImageUtils.ResizeImage(origBitmap, viewport.Width, viewport.Height); | ||
238 | } | ||
239 | |||
240 | // XXX: It shouldn't really be necesary to force a GC here as one should occur anyway pretty shortly | ||
241 | // afterwards. It's generally regarded as a bad idea to manually GC. If Warp3D is using lots of memory | ||
242 | // then this may be some issue with the Warp3D code itself, though it's also quite possible that generating | ||
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; | 239 | renderer = null; |
253 | viewport = null; | 240 | viewport = null; |
254 | 241 | ||
@@ -285,12 +272,12 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
285 | float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight; | 272 | float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight; |
286 | 273 | ||
287 | renderer.AddPlane("Water", m_scene.RegionInfo.RegionSizeX * 0.5f); | 274 | renderer.AddPlane("Water", m_scene.RegionInfo.RegionSizeX * 0.5f); |
288 | renderer.Scene.sceneobject("Water").setPos(m_scene.RegionInfo.RegionSizeX/2 - 0.5f, | 275 | renderer.Scene.sceneobject("Water").setPos(m_scene.RegionInfo.RegionSizeX * 0.5f - 0.5f, |
289 | waterHeight, | 276 | waterHeight, |
290 | m_scene.RegionInfo.RegionSizeY/2 - 0.5f ); | 277 | m_scene.RegionInfo.RegionSizeY * 0.5f - 0.5f); |
291 | 278 | ||
292 | warp_Material waterColorMaterial = new warp_Material(ConvertColor(WATER_COLOR)); | 279 | warp_Material waterColorMaterial = new warp_Material(ConvertColor(WATER_COLOR)); |
293 | waterColorMaterial.setReflectivity(0); // match water color with standard map module thanks lkalif | 280 | waterColorMaterial.setReflectivity(0); // match water color with standard map module thanks lkalif |
294 | waterColorMaterial.setTransparency((byte)((1f - WATER_COLOR.A) * 255f)); | 281 | waterColorMaterial.setTransparency((byte)((1f - WATER_COLOR.A) * 255f)); |
295 | renderer.Scene.addMaterial("WaterColor", waterColorMaterial); | 282 | renderer.Scene.addMaterial("WaterColor", waterColorMaterial); |
296 | renderer.SetObjectMaterial("Water", "WaterColor"); | 283 | renderer.SetObjectMaterial("Water", "WaterColor"); |
@@ -303,53 +290,53 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
303 | { | 290 | { |
304 | ITerrainChannel terrain = m_scene.Heightmap; | 291 | ITerrainChannel terrain = m_scene.Heightmap; |
305 | 292 | ||
293 | float regionsx = m_scene.RegionInfo.RegionSizeX; | ||
294 | float regionsy = m_scene.RegionInfo.RegionSizeY; | ||
295 | |||
306 | // 'diff' is the difference in scale between the real region size and the size of terrain we're buiding | 296 | // '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; | 297 | float diff = regionsx / 256f; |
308 | 298 | ||
309 | warp_Object obj = new warp_Object(256 * 256, 255 * 255 * 2); | 299 | int npointsx =(int)(regionsx / diff); |
300 | int npointsy =(int)(regionsy / diff); | ||
301 | |||
302 | float invsx = 1.0f / regionsx; | ||
303 | float invsy = 1.0f / (float)m_scene.RegionInfo.RegionSizeY; | ||
310 | 304 | ||
311 | // Create all the vertices for the terrain | 305 | // Create all the vertices for the terrain |
312 | for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff) | 306 | warp_Object obj = new warp_Object(); |
307 | for (float y = 0; y < regionsy; y += diff) | ||
313 | { | 308 | { |
314 | for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff) | 309 | for (float x = 0; x < regionsx; x += diff) |
315 | { | 310 | { |
316 | warp_Vector pos = ConvertVector(x, y, (float)terrain[(int)x, (int)y]); | 311 | warp_Vector pos = ConvertVector(x , y , (float)terrain[(int)x, (int)y]); |
317 | obj.addVertex(new warp_Vertex(pos, | 312 | obj.addVertex(new warp_Vertex(pos, x * invsx, 1.0f - y * invsy)); |
318 | x / (float)m_scene.RegionInfo.RegionSizeX, | ||
319 | (((float)m_scene.RegionInfo.RegionSizeY) - y) / m_scene.RegionInfo.RegionSizeY) ); | ||
320 | } | 313 | } |
321 | } | 314 | } |
322 | 315 | ||
323 | // Now that we have all the vertices, make another pass and create | 316 | // Now that we have all the vertices, make another pass and |
324 | // the normals for each of the surface triangles and | 317 | // create the list of triangle indices. |
325 | // create the list of triangle indices. | 318 | float invdiff = 1.0f / diff; |
326 | for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff) | 319 | int limx = npointsx - 1; |
320 | int limy = npointsy - 1; | ||
321 | for (float y = 0; y < regionsy; y += diff) | ||
327 | { | 322 | { |
328 | for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff) | 323 | for (float x = 0; x < regionsx; x += diff) |
329 | { | 324 | { |
330 | float newX = x / diff; | 325 | float newX = x * invdiff; |
331 | float newY = y / diff; | 326 | float newY = y * invdiff; |
332 | if (newX < 255 && newY < 255) | 327 | if (newX < limx && newY < limy) |
333 | { | 328 | { |
334 | int v = (int)newY * 256 + (int)newX; | 329 | int v = (int)newY * npointsx + (int)newX; |
335 | |||
336 | // Normal for a triangle made up of three adjacent vertices | ||
337 | Vector3 v1 = new Vector3(newX, newY, (float)terrain[(int)x, (int)y]); | ||
338 | Vector3 v2 = new Vector3(newX + 1, newY, (float)terrain[(int)(x + 1), (int)y]); | ||
339 | Vector3 v3 = new Vector3(newX, newY + 1, (float)terrain[(int)x, ((int)(y + 1))]); | ||
340 | warp_Vector norm = ConvertVector(SurfaceNormal(v1, v2, v3)); | ||
341 | norm = norm.reverse(); | ||
342 | obj.vertex(v).n = norm; | ||
343 | 330 | ||
344 | // Make two triangles for each of the squares in the grid of vertices | 331 | // Make two triangles for each of the squares in the grid of vertices |
345 | obj.addTriangle( | 332 | obj.addTriangle( |
346 | v, | 333 | v, |
347 | v + 1, | 334 | v + 1, |
348 | v + 256); | 335 | v + npointsx); |
349 | 336 | ||
350 | obj.addTriangle( | 337 | obj.addTriangle( |
351 | v + 256 + 1, | 338 | v + npointsx + 1, |
352 | v + 256, | 339 | v + npointsx, |
353 | v + 1); | 340 | v + 1); |
354 | } | 341 | } |
355 | } | 342 | } |
@@ -382,18 +369,15 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
382 | Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out globalX, out globalY); | 369 | Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out globalX, out globalY); |
383 | 370 | ||
384 | warp_Texture texture; | 371 | warp_Texture texture; |
385 | using ( | 372 | using (Bitmap image = TerrainSplat.Splat( |
386 | Bitmap image | 373 | terrain, textureIDs, startHeights, heightRanges, |
387 | = TerrainSplat.Splat(terrain, textureIDs, startHeights, heightRanges, | ||
388 | new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain)) | 374 | new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain)) |
389 | { | ||
390 | texture = new warp_Texture(image); | 375 | texture = new warp_Texture(image); |
391 | } | ||
392 | 376 | ||
393 | warp_Material material = new warp_Material(texture); | 377 | warp_Material material = new warp_Material(texture); |
394 | material.setReflectivity(50); | 378 | material.setReflectivity(50); |
395 | renderer.Scene.addMaterial("TerrainColor", material); | 379 | renderer.Scene.addMaterial("TerrainColor", material); |
396 | renderer.Scene.material("TerrainColor").setReflectivity(0); // reduces tile seams a bit thanks lkalif | 380 | renderer.Scene.material("TerrainColor").setReflectivity(0); // reduces tile seams a bit thanks lkalif |
397 | renderer.SetObjectMaterial("Terrain", "TerrainColor"); | 381 | renderer.SetObjectMaterial("Terrain", "TerrainColor"); |
398 | } | 382 | } |
399 | 383 | ||
@@ -414,11 +398,13 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
414 | private void CreatePrim(WarpRenderer renderer, SceneObjectPart prim, | 398 | private void CreatePrim(WarpRenderer renderer, SceneObjectPart prim, |
415 | bool useTextures) | 399 | bool useTextures) |
416 | { | 400 | { |
417 | const float MIN_SIZE = 2f; | 401 | const float MIN_SIZE_SQUARE = 4f; |
418 | 402 | ||
419 | if ((PCode)prim.Shape.PCode != PCode.Prim) | 403 | if ((PCode)prim.Shape.PCode != PCode.Prim) |
420 | return; | 404 | return; |
421 | if (prim.Scale.LengthSquared() < MIN_SIZE * MIN_SIZE) | 405 | float primScaleLenSquared = prim.Scale.LengthSquared(); |
406 | |||
407 | if (primScaleLenSquared < MIN_SIZE_SQUARE) | ||
422 | return; | 408 | return; |
423 | 409 | ||
424 | FacetedMesh renderMesh = null; | 410 | FacetedMesh renderMesh = null; |
@@ -442,25 +428,14 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
442 | else // It's sculptie | 428 | else // It's sculptie |
443 | { | 429 | { |
444 | IJ2KDecoder imgDecoder = m_scene.RequestModuleInterface<IJ2KDecoder>(); | 430 | IJ2KDecoder imgDecoder = m_scene.RequestModuleInterface<IJ2KDecoder>(); |
445 | if (imgDecoder != null) | 431 | if(imgDecoder != null) |
446 | { | 432 | { |
447 | try | 433 | Image sculpt = imgDecoder.DecodeToImage(sculptAsset); |
434 | if(sculpt != null) | ||
448 | { | 435 | { |
449 | Image sculpt = imgDecoder.DecodeToImage(sculptAsset); | 436 | renderMesh = m_primMesher.GenerateFacetedSculptMesh(omvPrim,(Bitmap)sculpt, |
450 | if (sculpt != null) | 437 | DetailLevel.Medium); |
451 | { | 438 | sculpt.Dispose(); |
452 | renderMesh = m_primMesher.GenerateFacetedSculptMesh(omvPrim, (Bitmap)sculpt, | ||
453 | DetailLevel.Medium); | ||
454 | sculpt.Dispose(); | ||
455 | } | ||
456 | } | ||
457 | catch (Exception e) | ||
458 | { | ||
459 | Vector3 objectPos = prim.ParentGroup.RootPart.AbsolutePosition; | ||
460 | //// TODO - print out owner of SceneObjectPart prim. | ||
461 | m_log.Warn(string.Format("[WARP 3D IMAGE MODULE]: Failed to decode asset {0} @ {1},{2},{3} - {4}.", | ||
462 | omvPrim.Sculpt.SculptTexture, objectPos.X, objectPos.Y, objectPos.Z, | ||
463 | prim.ParentGroup.RootPart.Name)); | ||
464 | } | 439 | } |
465 | } | 440 | } |
466 | } | 441 | } |
@@ -477,20 +452,6 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
477 | if (renderMesh == null) | 452 | if (renderMesh == null) |
478 | return; | 453 | return; |
479 | 454 | ||
480 | warp_Vector primPos = ConvertVector(prim.GetWorldPosition()); | ||
481 | warp_Quaternion primRot = ConvertQuaternion(prim.RotationOffset); | ||
482 | |||
483 | warp_Matrix m = warp_Matrix.quaternionMatrix(primRot); | ||
484 | |||
485 | if (prim.ParentID != 0) | ||
486 | { | ||
487 | SceneObjectGroup group = m_scene.SceneGraph.GetGroupByPrim(prim.LocalId); | ||
488 | if (group != null) | ||
489 | m.transform(warp_Matrix.quaternionMatrix(ConvertQuaternion(group.RootPart.RotationOffset))); | ||
490 | } | ||
491 | |||
492 | warp_Vector primScale = ConvertVector(prim.Scale); | ||
493 | |||
494 | string primID = prim.UUID.ToString(); | 455 | string primID = prim.UUID.ToString(); |
495 | 456 | ||
496 | // Create the prim faces | 457 | // Create the prim faces |
@@ -498,27 +459,18 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
498 | for (int i = 0; i < renderMesh.Faces.Count; i++) | 459 | for (int i = 0; i < renderMesh.Faces.Count; i++) |
499 | { | 460 | { |
500 | Face face = renderMesh.Faces[i]; | 461 | Face face = renderMesh.Faces[i]; |
501 | string meshName = primID + "-Face-" + i.ToString(); | 462 | string meshName = primID + i.ToString(); |
502 | 463 | ||
503 | // Avoid adding duplicate meshes to the scene | 464 | // Avoid adding duplicate meshes to the scene |
504 | if (renderer.Scene.objectData.ContainsKey(meshName)) | 465 | if (renderer.Scene.objectData.ContainsKey(meshName)) |
505 | { | ||
506 | continue; | 466 | continue; |
507 | } | ||
508 | |||
509 | warp_Object faceObj = new warp_Object(face.Vertices.Count, face.Indices.Count / 3); | ||
510 | 467 | ||
468 | warp_Object faceObj = new warp_Object(); | ||
511 | for (int j = 0; j < face.Vertices.Count; j++) | 469 | for (int j = 0; j < face.Vertices.Count; j++) |
512 | { | 470 | { |
513 | Vertex v = face.Vertices[j]; | 471 | Vertex v = face.Vertices[j]; |
514 | |||
515 | warp_Vector pos = ConvertVector(v.Position); | 472 | warp_Vector pos = ConvertVector(v.Position); |
516 | warp_Vector norm = ConvertVector(v.Normal); | 473 | warp_Vertex vert = new warp_Vertex(pos, v.TexCoord.X, v.TexCoord.Y); |
517 | |||
518 | if (prim.Shape.SculptTexture == UUID.Zero) | ||
519 | norm = norm.reverse(); | ||
520 | warp_Vertex vert = new warp_Vertex(pos, norm, v.TexCoord.X, v.TexCoord.Y); | ||
521 | |||
522 | faceObj.addVertex(vert); | 474 | faceObj.addVertex(vert); |
523 | } | 475 | } |
524 | 476 | ||
@@ -533,17 +485,19 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
533 | Primitive.TextureEntryFace teFace = prim.Shape.Textures.GetFace((uint)i); | 485 | Primitive.TextureEntryFace teFace = prim.Shape.Textures.GetFace((uint)i); |
534 | Color4 faceColor = GetFaceColor(teFace); | 486 | Color4 faceColor = GetFaceColor(teFace); |
535 | string materialName = String.Empty; | 487 | string materialName = String.Empty; |
536 | if (m_texturePrims && prim.Scale.LengthSquared() > m_texturePrimSize*m_texturePrimSize) | 488 | if (m_texturePrims && primScaleLenSquared > m_texturePrimSize*m_texturePrimSize) |
537 | materialName = GetOrCreateMaterial(renderer, faceColor, teFace.TextureID); | 489 | materialName = GetOrCreateMaterial(renderer, faceColor, teFace.TextureID); |
538 | else | 490 | else |
539 | materialName = GetOrCreateMaterial(renderer, faceColor); | 491 | materialName = GetOrCreateMaterial(renderer, faceColor); |
540 | 492 | ||
493 | warp_Vector primPos = ConvertVector(prim.GetWorldPosition()); | ||
494 | warp_Quaternion primRot = ConvertQuaternion(prim.GetWorldRotation()); | ||
495 | warp_Matrix m = warp_Matrix.quaternionMatrix(primRot); | ||
541 | faceObj.transform(m); | 496 | faceObj.transform(m); |
542 | faceObj.setPos(primPos); | 497 | faceObj.setPos(primPos); |
543 | faceObj.scaleSelf(primScale.x, primScale.y, primScale.z); | 498 | faceObj.scaleSelf(prim.Scale.X, prim.Scale.Z, prim.Scale.Y); |
544 | 499 | ||
545 | renderer.Scene.addObject(meshName, faceObj); | 500 | renderer.Scene.addObject(meshName, faceObj); |
546 | |||
547 | renderer.SetObjectMaterial(meshName, materialName); | 501 | renderer.SetObjectMaterial(meshName, materialName); |
548 | } | 502 | } |
549 | } | 503 | } |
@@ -576,7 +530,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
576 | 530 | ||
577 | if (!fetched) | 531 | if (!fetched) |
578 | { | 532 | { |
579 | // Fetch the texture, decode and get the average color, | 533 | // Fetch the texture, decode and get the average color, |
580 | // then save it to a temporary metadata asset | 534 | // then save it to a temporary metadata asset |
581 | AssetBase textureAsset = m_scene.AssetService.Get(face.TextureID.ToString()); | 535 | AssetBase textureAsset = m_scene.AssetService.Get(face.TextureID.ToString()); |
582 | if (textureAsset != null) | 536 | if (textureAsset != null) |
@@ -671,7 +625,6 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
671 | #endregion Rendering Methods | 625 | #endregion Rendering Methods |
672 | 626 | ||
673 | #region Static Helpers | 627 | #region Static Helpers |
674 | |||
675 | // Note: axis change. | 628 | // Note: axis change. |
676 | private static warp_Vector ConvertVector(float x, float y, float z) | 629 | private static warp_Vector ConvertVector(float x, float y, float z) |
677 | { | 630 | { |
@@ -725,10 +678,10 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
725 | { | 678 | { |
726 | width = bitmap.Width; | 679 | width = bitmap.Width; |
727 | height = bitmap.Height; | 680 | height = bitmap.Height; |
728 | 681 | ||
729 | BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, bitmap.PixelFormat); | 682 | BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, bitmap.PixelFormat); |
730 | pixelBytes = (bitmap.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4; | 683 | pixelBytes = (bitmap.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4; |
731 | 684 | ||
732 | // Sum up the individual channels | 685 | // Sum up the individual channels |
733 | unsafe | 686 | unsafe |
734 | { | 687 | { |
@@ -737,7 +690,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
737 | for (int y = 0; y < height; y++) | 690 | for (int y = 0; y < height; y++) |
738 | { | 691 | { |
739 | byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride); | 692 | byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride); |
740 | 693 | ||
741 | for (int x = 0; x < width; x++) | 694 | for (int x = 0; x < width; x++) |
742 | { | 695 | { |
743 | b += row[x * pixelBytes + 0]; | 696 | b += row[x * pixelBytes + 0]; |
@@ -752,7 +705,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
752 | for (int y = 0; y < height; y++) | 705 | for (int y = 0; y < height; y++) |
753 | { | 706 | { |
754 | byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride); | 707 | byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride); |
755 | 708 | ||
756 | for (int x = 0; x < width; x++) | 709 | for (int x = 0; x < width; x++) |
757 | { | 710 | { |
758 | b += row[x * pixelBytes + 0]; | 711 | b += row[x * pixelBytes + 0]; |