aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/World/Warp3DMap
diff options
context:
space:
mode:
authorUbitUmarov2016-08-23 10:58:34 +0100
committerUbitUmarov2016-08-23 10:58:34 +0100
commit8eacc6b2077b302132eae82ce4bf22bf35b62ac5 (patch)
treeced0a9dbf708780c51a1b35b2831686d02186a74 /OpenSim/Region/CoreModules/World/Warp3DMap
parentchange strange rotation in legacy MapImageModule (untested) (diff)
downloadopensim-SC_OLD-8eacc6b2077b302132eae82ce4bf22bf35b62ac5.zip
opensim-SC_OLD-8eacc6b2077b302132eae82ce4bf22bf35b62ac5.tar.gz
opensim-SC_OLD-8eacc6b2077b302132eae82ce4bf22bf35b62ac5.tar.bz2
opensim-SC_OLD-8eacc6b2077b302132eae82ce4bf22bf35b62ac5.tar.xz
replace warp3D.dll by a newer modified version. (only minor testing done :(
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Warp3DMap')
-rw-r--r--OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs158
1 files changed, 54 insertions, 104 deletions
diff --git a/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs b/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs
index 443eee1..e2c1c01 100644
--- a/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs
+++ b/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs
@@ -35,7 +35,7 @@ using System.Reflection;
35using CSJ2K; 35using CSJ2K;
36using Nini.Config; 36using Nini.Config;
37using log4net; 37using log4net;
38using Rednettle.Warp3D; 38using Warp3D;
39using Mono.Addins; 39using Mono.Addins;
40 40
41using OpenSim.Framework; 41using OpenSim.Framework;
@@ -76,11 +76,10 @@ 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
83 private Bitmap lastImage = null; 82// private Bitmap lastImage = null;
84 private DateTime lastImageTime = DateTime.MinValue; 83 private DateTime lastImageTime = DateTime.MinValue;
85 84
86 #region Region Module interface 85 #region Region Module interface
@@ -107,10 +106,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
107 = Util.GetConfigVarFromSections<float>(m_config, "TexturePrimSize", configSections, m_texturePrimSize); 106 = Util.GetConfigVarFromSections<float>(m_config, "TexturePrimSize", configSections, m_texturePrimSize);
108 m_renderMeshes 107 m_renderMeshes
109 = Util.GetConfigVarFromSections<bool>(m_config, "RenderMeshes", configSections, m_renderMeshes); 108 = Util.GetConfigVarFromSections<bool>(m_config, "RenderMeshes", configSections, m_renderMeshes);
110 m_useAntiAliasing 109 }
111 = Util.GetConfigVarFromSections<bool>(m_config, "UseAntiAliasing", configSections, m_useAntiAliasing);
112
113 }
114 110
115 public void AddRegion(Scene scene) 111 public void AddRegion(Scene scene)
116 { 112 {
@@ -201,21 +197,14 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
201 int width = viewport.Width; 197 int width = viewport.Width;
202 int height = viewport.Height; 198 int height = viewport.Height;
203 199
204 if (m_useAntiAliasing)
205 {
206 width *= 2;
207 height *= 2;
208 }
209
210 WarpRenderer renderer = new WarpRenderer(); 200 WarpRenderer renderer = new WarpRenderer();
211 201
212 renderer.CreateScene(width, height); 202 if(!renderer.CreateScene(width, height))
213 renderer.Scene.autoCalcNormals = false; 203 return new Bitmap(width,height);
214 204
215 #region Camera 205 #region Camera
216 206
217 warp_Vector pos = ConvertVector(viewport.Position); 207 warp_Vector pos = ConvertVector(viewport.Position);
218 pos.z -= 0.001f; // Works around an issue with the Warp3D camera
219 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));
220 209
221 renderer.Scene.defaultCamera.setPos(pos); 210 renderer.Scene.defaultCamera.setPos(pos);
@@ -247,24 +236,8 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
247 renderer.Render(); 236 renderer.Render();
248 Bitmap bitmap = renderer.Scene.getImage(); 237 Bitmap bitmap = renderer.Scene.getImage();
249 238
250 if (m_useAntiAliasing) 239 renderer.Scene.destroy();
251 { 240 renderer.Reset();
252 using (Bitmap origBitmap = bitmap)
253 bitmap = ImageUtils.ResizeImage(origBitmap, viewport.Width, viewport.Height);
254 }
255
256 // XXX: It shouldn't really be necesary to force a GC here as one should occur anyway pretty shortly
257 // afterwards. It's generally regarded as a bad idea to manually GC. If Warp3D is using lots of memory
258 // then this may be some issue with the Warp3D code itself, though it's also quite possible that generating
259 // this map tile simply takes a lot of memory.
260 foreach (var o in renderer.Scene.objectData.Values)
261 {
262 warp_Object obj = (warp_Object)o;
263 obj.vertexData = null;
264 obj.triangleData = null;
265 }
266
267 renderer.Scene.removeAllObjects();
268 renderer = null; 241 renderer = null;
269 viewport = null; 242 viewport = null;
270 243
@@ -301,9 +274,9 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
301 float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight; 274 float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight;
302 275
303 renderer.AddPlane("Water", m_scene.RegionInfo.RegionSizeX * 0.5f); 276 renderer.AddPlane("Water", m_scene.RegionInfo.RegionSizeX * 0.5f);
304 renderer.Scene.sceneobject("Water").setPos(m_scene.RegionInfo.RegionSizeX / 2 - 0.5f, 277 renderer.Scene.sceneobject("Water").setPos(m_scene.RegionInfo.RegionSizeX * 0.5f - 0.5f,
305 waterHeight, 278 waterHeight,
306 m_scene.RegionInfo.RegionSizeY / 2 - 0.5f); 279 m_scene.RegionInfo.RegionSizeY * 0.5f - 0.5f);
307 280
308 warp_Material waterColorMaterial = new warp_Material(ConvertColor(WATER_COLOR)); 281 warp_Material waterColorMaterial = new warp_Material(ConvertColor(WATER_COLOR));
309 waterColorMaterial.setReflectivity(0); // match water color with standard map module thanks lkalif 282 waterColorMaterial.setReflectivity(0); // match water color with standard map module thanks lkalif
@@ -319,53 +292,53 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
319 { 292 {
320 ITerrainChannel terrain = m_scene.Heightmap; 293 ITerrainChannel terrain = m_scene.Heightmap;
321 294
295 float regionsx = m_scene.RegionInfo.RegionSizeX;
296 float regionsy = m_scene.RegionInfo.RegionSizeY;
297
322 // 'diff' is the difference in scale between the real region size and the size of terrain we're buiding 298 // 'diff' is the difference in scale between the real region size and the size of terrain we're buiding
323 float diff = (float)m_scene.RegionInfo.RegionSizeX / 256f; 299 float diff = regionsx / 256f;
324 300
325 warp_Object obj = new warp_Object(256 * 256, 255 * 255 * 2); 301 int npointsx =(int)(regionsx / diff);
302 int npointsy =(int)(regionsy / diff);
303
304 float invsx = 1.0f / regionsx;
305 float invsy = 1.0f / (float)m_scene.RegionInfo.RegionSizeY;
326 306
327 // Create all the vertices for the terrain 307 // Create all the vertices for the terrain
328 for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff) 308 warp_Object obj = new warp_Object();
309 for (float y = 0; y < regionsy; y += diff)
329 { 310 {
330 for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff) 311 for (float x = 0; x < regionsx; x += diff)
331 { 312 {
332 warp_Vector pos = ConvertVector(x, y, (float)terrain[(int)x, (int)y]); 313 warp_Vector pos = ConvertVector(x , y , (float)terrain[(int)x, (int)y]);
333 obj.addVertex(new warp_Vertex(pos, 314 obj.addVertex(new warp_Vertex(pos, x * invsx, 1.0f - y * invsy));
334 x / (float)m_scene.RegionInfo.RegionSizeX,
335 (((float)m_scene.RegionInfo.RegionSizeY) - y) / m_scene.RegionInfo.RegionSizeY));
336 } 315 }
337 } 316 }
338 317
339 // Now that we have all the vertices, make another pass and create 318 // Now that we have all the vertices, make another pass and
340 // the normals for each of the surface triangles and 319 // create the list of triangle indices.
341 // create the list of triangle indices. 320 float invdiff = 1.0f / diff;
342 for (float y = 0; y < m_scene.RegionInfo.RegionSizeY; y += diff) 321 int limx = npointsx - 1;
322 int limy = npointsy - 1;
323 for (float y = 0; y < regionsy; y += diff)
343 { 324 {
344 for (float x = 0; x < m_scene.RegionInfo.RegionSizeX; x += diff) 325 for (float x = 0; x < regionsx; x += diff)
345 { 326 {
346 float newX = x / diff; 327 float newX = x * invdiff;
347 float newY = y / diff; 328 float newY = y * invdiff;
348 if (newX < 255 && newY < 255) 329 if (newX < limx && newY < limy)
349 { 330 {
350 int v = (int)newY * 256 + (int)newX; 331 int v = (int)newY * npointsx + (int)newX;
351
352 // Normal for a triangle made up of three adjacent vertices
353 Vector3 v1 = new Vector3(newX, newY, (float)terrain[(int)x, (int)y]);
354 Vector3 v2 = new Vector3(newX + 1, newY, (float)terrain[(int)(x + 1), (int)y]);
355 Vector3 v3 = new Vector3(newX, newY + 1, (float)terrain[(int)x, ((int)(y + 1))]);
356 warp_Vector norm = ConvertVector(SurfaceNormal(v1, v2, v3));
357 norm = norm.reverse();
358 obj.vertex(v).n = norm;
359 332
360 // Make two triangles for each of the squares in the grid of vertices 333 // Make two triangles for each of the squares in the grid of vertices
361 obj.addTriangle( 334 obj.addTriangle(
362 v, 335 v,
363 v + 1, 336 v + 1,
364 v + 256); 337 v + npointsx);
365 338
366 obj.addTriangle( 339 obj.addTriangle(
367 v + 256 + 1, 340 v + npointsx + 1,
368 v + 256, 341 v + npointsx,
369 v + 1); 342 v + 1);
370 } 343 }
371 } 344 }
@@ -398,14 +371,10 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
398 Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out globalX, out globalY); 371 Util.RegionHandleToWorldLoc(m_scene.RegionInfo.RegionHandle, out globalX, out globalY);
399 372
400 warp_Texture texture; 373 warp_Texture texture;
401 using ( 374 using (Bitmap image = TerrainSplat.Splat(
402 Bitmap image
403 = TerrainSplat.Splat(
404 terrain, textureIDs, startHeights, heightRanges, 375 terrain, textureIDs, startHeights, heightRanges,
405 new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain)) 376 new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain))
406 {
407 texture = new warp_Texture(image); 377 texture = new warp_Texture(image);
408 }
409 378
410 warp_Material material = new warp_Material(texture); 379 warp_Material material = new warp_Material(texture);
411 material.setReflectivity(50); 380 material.setReflectivity(50);
@@ -431,11 +400,13 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
431 private void CreatePrim(WarpRenderer renderer, SceneObjectPart prim, 400 private void CreatePrim(WarpRenderer renderer, SceneObjectPart prim,
432 bool useTextures) 401 bool useTextures)
433 { 402 {
434 const float MIN_SIZE = 2f; 403 const float MIN_SIZE_SQUARE = 4f;
435 404
436 if ((PCode)prim.Shape.PCode != PCode.Prim) 405 if ((PCode)prim.Shape.PCode != PCode.Prim)
437 return; 406 return;
438 if (prim.Scale.LengthSquared() < MIN_SIZE * MIN_SIZE) 407 float primScaleLenSquared = prim.Scale.LengthSquared();
408
409 if (primScaleLenSquared < MIN_SIZE_SQUARE)
439 return; 410 return;
440 411
441 FacetedMesh renderMesh = null; 412 FacetedMesh renderMesh = null;
@@ -459,13 +430,13 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
459 else // It's sculptie 430 else // It's sculptie
460 { 431 {
461 IJ2KDecoder imgDecoder = m_scene.RequestModuleInterface<IJ2KDecoder>(); 432 IJ2KDecoder imgDecoder = m_scene.RequestModuleInterface<IJ2KDecoder>();
462 if (imgDecoder != null) 433 if(imgDecoder != null)
463 { 434 {
464 Image sculpt = imgDecoder.DecodeToImage(sculptAsset); 435 Image sculpt = imgDecoder.DecodeToImage(sculptAsset);
465 if (sculpt != null) 436 if(sculpt != null)
466 { 437 {
467 renderMesh = m_primMesher.GenerateFacetedSculptMesh(omvPrim, (Bitmap)sculpt, 438 renderMesh = m_primMesher.GenerateFacetedSculptMesh(omvPrim,(Bitmap)sculpt,
468 DetailLevel.Medium); 439 DetailLevel.Medium);
469 sculpt.Dispose(); 440 sculpt.Dispose();
470 } 441 }
471 } 442 }
@@ -483,20 +454,6 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
483 if (renderMesh == null) 454 if (renderMesh == null)
484 return; 455 return;
485 456
486 warp_Vector primPos = ConvertVector(prim.GetWorldPosition());
487 warp_Quaternion primRot = ConvertQuaternion(prim.RotationOffset);
488
489 warp_Matrix m = warp_Matrix.quaternionMatrix(primRot);
490
491 if (prim.ParentID != 0)
492 {
493 SceneObjectGroup group = m_scene.SceneGraph.GetGroupByPrim(prim.LocalId);
494 if (group != null)
495 m.transform(warp_Matrix.quaternionMatrix(ConvertQuaternion(group.RootPart.RotationOffset)));
496 }
497
498 warp_Vector primScale = ConvertVector(prim.Scale);
499
500 string primID = prim.UUID.ToString(); 457 string primID = prim.UUID.ToString();
501 458
502 // Create the prim faces 459 // Create the prim faces
@@ -504,27 +461,18 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
504 for (int i = 0; i < renderMesh.Faces.Count; i++) 461 for (int i = 0; i < renderMesh.Faces.Count; i++)
505 { 462 {
506 Face face = renderMesh.Faces[i]; 463 Face face = renderMesh.Faces[i];
507 string meshName = primID + "-Face-" + i.ToString(); 464 string meshName = primID + i.ToString();
508 465
509 // Avoid adding duplicate meshes to the scene 466 // Avoid adding duplicate meshes to the scene
510 if (renderer.Scene.objectData.ContainsKey(meshName)) 467 if (renderer.Scene.objectData.ContainsKey(meshName))
511 {
512 continue; 468 continue;
513 }
514
515 warp_Object faceObj = new warp_Object(face.Vertices.Count, face.Indices.Count / 3);
516 469
470 warp_Object faceObj = new warp_Object();
517 for (int j = 0; j < face.Vertices.Count; j++) 471 for (int j = 0; j < face.Vertices.Count; j++)
518 { 472 {
519 Vertex v = face.Vertices[j]; 473 Vertex v = face.Vertices[j];
520
521 warp_Vector pos = ConvertVector(v.Position); 474 warp_Vector pos = ConvertVector(v.Position);
522 warp_Vector norm = ConvertVector(v.Normal); 475 warp_Vertex vert = new warp_Vertex(pos, v.TexCoord.X, v.TexCoord.Y);
523
524 if (prim.Shape.SculptTexture == UUID.Zero)
525 norm = norm.reverse();
526 warp_Vertex vert = new warp_Vertex(pos, norm, v.TexCoord.X, v.TexCoord.Y);
527
528 faceObj.addVertex(vert); 476 faceObj.addVertex(vert);
529 } 477 }
530 478
@@ -539,17 +487,19 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
539 Primitive.TextureEntryFace teFace = prim.Shape.Textures.GetFace((uint)i); 487 Primitive.TextureEntryFace teFace = prim.Shape.Textures.GetFace((uint)i);
540 Color4 faceColor = GetFaceColor(teFace); 488 Color4 faceColor = GetFaceColor(teFace);
541 string materialName = String.Empty; 489 string materialName = String.Empty;
542 if (m_texturePrims && prim.Scale.LengthSquared() > m_texturePrimSize*m_texturePrimSize) 490 if (m_texturePrims && primScaleLenSquared > m_texturePrimSize*m_texturePrimSize)
543 materialName = GetOrCreateMaterial(renderer, faceColor, teFace.TextureID); 491 materialName = GetOrCreateMaterial(renderer, faceColor, teFace.TextureID);
544 else 492 else
545 materialName = GetOrCreateMaterial(renderer, faceColor); 493 materialName = GetOrCreateMaterial(renderer, faceColor);
546 494
495 warp_Vector primPos = ConvertVector(prim.GetWorldPosition());
496 warp_Quaternion primRot = ConvertQuaternion(prim.GetWorldRotation());
497 warp_Matrix m = warp_Matrix.quaternionMatrix(primRot);
547 faceObj.transform(m); 498 faceObj.transform(m);
548 faceObj.setPos(primPos); 499 faceObj.setPos(primPos);
549 faceObj.scaleSelf(primScale.x, primScale.y, primScale.z); 500 faceObj.scaleSelf(prim.Scale.X, prim.Scale.Z, prim.Scale.Y);
550 501
551 renderer.Scene.addObject(meshName, faceObj); 502 renderer.Scene.addObject(meshName, faceObj);
552
553 renderer.SetObjectMaterial(meshName, materialName); 503 renderer.SetObjectMaterial(meshName, materialName);
554 } 504 }
555 } 505 }