aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/Meshing/SculptMap.cs
diff options
context:
space:
mode:
authorDiva Canto2010-05-07 21:29:56 -0700
committerDiva Canto2010-05-07 21:29:56 -0700
commita58859a0d4206c194c9c56212218e2cafc2cc373 (patch)
treefed51a4e40c344b76f6b8b4d5c5b2ec0d2e142e4 /OpenSim/Region/Physics/Meshing/SculptMap.cs
parentimprove handling of undersize sculpt textures (diff)
downloadopensim-SC-a58859a0d4206c194c9c56212218e2cafc2cc373.zip
opensim-SC-a58859a0d4206c194c9c56212218e2cafc2cc373.tar.gz
opensim-SC-a58859a0d4206c194c9c56212218e2cafc2cc373.tar.bz2
opensim-SC-a58859a0d4206c194c9c56212218e2cafc2cc373.tar.xz
GridUserService in place. Replaces the contrived concept of storing user's home and position info in the presence service. WARNING: I violated a taboo by deleting 2 migration files and simplifying the original table creation for Presence. This should not cause any problems to anyone, though. Things will work with the new simplified table, as well as with the previous contrived one. If there are any problems, solving them is as easy as dropping the presence table and deleting its row in the migrations table. The presence info only exists during a user's session anyway.
BTW, the Meshing files want to be committed too -- EOFs.
Diffstat (limited to 'OpenSim/Region/Physics/Meshing/SculptMap.cs')
-rw-r--r--OpenSim/Region/Physics/Meshing/SculptMap.cs352
1 files changed, 176 insertions, 176 deletions
diff --git a/OpenSim/Region/Physics/Meshing/SculptMap.cs b/OpenSim/Region/Physics/Meshing/SculptMap.cs
index 4906cf6..d2d71de 100644
--- a/OpenSim/Region/Physics/Meshing/SculptMap.cs
+++ b/OpenSim/Region/Physics/Meshing/SculptMap.cs
@@ -1,176 +1,176 @@
1/* 1/*
2 * Copyright (c) Contributors 2 * Copyright (c) Contributors
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the 12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28// to build without references to System.Drawing, comment this out 28// to build without references to System.Drawing, comment this out
29#define SYSTEM_DRAWING 29#define SYSTEM_DRAWING
30 30
31using System; 31using System;
32using System.Collections.Generic; 32using System.Collections.Generic;
33using System.Text; 33using System.Text;
34 34
35#if SYSTEM_DRAWING 35#if SYSTEM_DRAWING
36using System.Drawing; 36using System.Drawing;
37using System.Drawing.Imaging; 37using System.Drawing.Imaging;
38 38
39namespace PrimMesher 39namespace PrimMesher
40{ 40{
41 public class SculptMap 41 public class SculptMap
42 { 42 {
43 public int width; 43 public int width;
44 public int height; 44 public int height;
45 public byte[] redBytes; 45 public byte[] redBytes;
46 public byte[] greenBytes; 46 public byte[] greenBytes;
47 public byte[] blueBytes; 47 public byte[] blueBytes;
48 48
49 public SculptMap() 49 public SculptMap()
50 { 50 {
51 } 51 }
52 52
53 public SculptMap(Bitmap bm, int lod) 53 public SculptMap(Bitmap bm, int lod)
54 { 54 {
55 int bmW = bm.Width; 55 int bmW = bm.Width;
56 int bmH = bm.Height; 56 int bmH = bm.Height;
57 57
58 if (bmW == 0 || bmH == 0) 58 if (bmW == 0 || bmH == 0)
59 throw new Exception("SculptMap: bitmap has no data"); 59 throw new Exception("SculptMap: bitmap has no data");
60 60
61 int numLodPixels = lod * 2 * lod * 2; // (32 * 2)^2 = 64^2 pixels for default sculpt map image 61 int numLodPixels = lod * 2 * lod * 2; // (32 * 2)^2 = 64^2 pixels for default sculpt map image
62 62
63 bool needsScaling = false; 63 bool needsScaling = false;
64 64
65 width = bmW; 65 width = bmW;
66 height = bmH; 66 height = bmH;
67 while (width * height > numLodPixels) 67 while (width * height > numLodPixels)
68 { 68 {
69 width >>= 1; 69 width >>= 1;
70 height >>= 1; 70 height >>= 1;
71 needsScaling = true; 71 needsScaling = true;
72 } 72 }
73 73
74 74
75 75
76 try 76 try
77 { 77 {
78 if (needsScaling) 78 if (needsScaling)
79 bm = ScaleImage(bm, width, height, 79 bm = ScaleImage(bm, width, height,
80 System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor); 80 System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor);
81 } 81 }
82 82
83 catch (Exception e) 83 catch (Exception e)
84 { 84 {
85 throw new Exception("Exception in ScaleImage(): e: " + e.ToString()); 85 throw new Exception("Exception in ScaleImage(): e: " + e.ToString());
86 } 86 }
87 87
88 if (width * height > lod * lod) 88 if (width * height > lod * lod)
89 { 89 {
90 width >>= 1; 90 width >>= 1;
91 height >>= 1; 91 height >>= 1;
92 } 92 }
93 93
94 int numBytes = (width + 1) * (height + 1); 94 int numBytes = (width + 1) * (height + 1);
95 redBytes = new byte[numBytes]; 95 redBytes = new byte[numBytes];
96 greenBytes = new byte[numBytes]; 96 greenBytes = new byte[numBytes];
97 blueBytes = new byte[numBytes]; 97 blueBytes = new byte[numBytes];
98 98
99 int byteNdx = 0; 99 int byteNdx = 0;
100 100
101 try 101 try
102 { 102 {
103 for (int y = 0; y <= height; y++) 103 for (int y = 0; y <= height; y++)
104 { 104 {
105 for (int x = 0; x <= width; x++) 105 for (int x = 0; x <= width; x++)
106 { 106 {
107 int bmY = y < height ? y * 2 : y * 2 - 1; 107 int bmY = y < height ? y * 2 : y * 2 - 1;
108 int bmX = x < width ? x * 2 : x * 2 - 1; 108 int bmX = x < width ? x * 2 : x * 2 - 1;
109 Color c = bm.GetPixel(bmX, bmY); 109 Color c = bm.GetPixel(bmX, bmY);
110 110
111 redBytes[byteNdx] = c.R; 111 redBytes[byteNdx] = c.R;
112 greenBytes[byteNdx] = c.G; 112 greenBytes[byteNdx] = c.G;
113 blueBytes[byteNdx] = c.B; 113 blueBytes[byteNdx] = c.B;
114 114
115 ++byteNdx; 115 ++byteNdx;
116 } 116 }
117 } 117 }
118 } 118 }
119 catch (Exception e) 119 catch (Exception e)
120 { 120 {
121 throw new Exception("Caught exception processing byte arrays in SculptMap(): e: " + e.ToString()); 121 throw new Exception("Caught exception processing byte arrays in SculptMap(): e: " + e.ToString());
122 } 122 }
123 123
124 width++; 124 width++;
125 height++; 125 height++;
126 } 126 }
127 127
128 public List<List<Coord>> ToRows(bool mirror) 128 public List<List<Coord>> ToRows(bool mirror)
129 { 129 {
130 int numRows = height; 130 int numRows = height;
131 int numCols = width; 131 int numCols = width;
132 132
133 List<List<Coord>> rows = new List<List<Coord>>(numRows); 133 List<List<Coord>> rows = new List<List<Coord>>(numRows);
134 134
135 float pixScale = 1.0f / 255; 135 float pixScale = 1.0f / 255;
136 136
137 int rowNdx, colNdx; 137 int rowNdx, colNdx;
138 int smNdx = 0; 138 int smNdx = 0;
139 139
140 for (rowNdx = 0; rowNdx < numRows; rowNdx++) 140 for (rowNdx = 0; rowNdx < numRows; rowNdx++)
141 { 141 {
142 List<Coord> row = new List<Coord>(numCols); 142 List<Coord> row = new List<Coord>(numCols);
143 for (colNdx = 0; colNdx < numCols; colNdx++) 143 for (colNdx = 0; colNdx < numCols; colNdx++)
144 { 144 {
145 if (mirror) 145 if (mirror)
146 row.Add(new Coord(-(redBytes[smNdx] * pixScale - 0.5f), (greenBytes[smNdx] * pixScale - 0.5f), blueBytes[smNdx] * pixScale - 0.5f)); 146 row.Add(new Coord(-(redBytes[smNdx] * pixScale - 0.5f), (greenBytes[smNdx] * pixScale - 0.5f), blueBytes[smNdx] * pixScale - 0.5f));
147 else 147 else
148 row.Add(new Coord(redBytes[smNdx] * pixScale - 0.5f, greenBytes[smNdx] * pixScale - 0.5f, blueBytes[smNdx] * pixScale - 0.5f)); 148 row.Add(new Coord(redBytes[smNdx] * pixScale - 0.5f, greenBytes[smNdx] * pixScale - 0.5f, blueBytes[smNdx] * pixScale - 0.5f));
149 149
150 ++smNdx; 150 ++smNdx;
151 } 151 }
152 rows.Add(row); 152 rows.Add(row);
153 } 153 }
154 return rows; 154 return rows;
155 } 155 }
156 156
157 private Bitmap ScaleImage(Bitmap srcImage, int destWidth, int destHeight, 157 private Bitmap ScaleImage(Bitmap srcImage, int destWidth, int destHeight,
158 System.Drawing.Drawing2D.InterpolationMode interpMode) 158 System.Drawing.Drawing2D.InterpolationMode interpMode)
159 { 159 {
160 Bitmap scaledImage = new Bitmap(srcImage, destWidth, destHeight); 160 Bitmap scaledImage = new Bitmap(srcImage, destWidth, destHeight);
161 scaledImage.SetResolution(96.0f, 96.0f); 161 scaledImage.SetResolution(96.0f, 96.0f);
162 162
163 Graphics grPhoto = Graphics.FromImage(scaledImage); 163 Graphics grPhoto = Graphics.FromImage(scaledImage);
164 grPhoto.InterpolationMode = interpMode; 164 grPhoto.InterpolationMode = interpMode;
165 165
166 grPhoto.DrawImage(srcImage, 166 grPhoto.DrawImage(srcImage,
167 new Rectangle(0, 0, destWidth, destHeight), 167 new Rectangle(0, 0, destWidth, destHeight),
168 new Rectangle(0, 0, srcImage.Width, srcImage.Height), 168 new Rectangle(0, 0, srcImage.Width, srcImage.Height),
169 GraphicsUnit.Pixel); 169 GraphicsUnit.Pixel);
170 170
171 grPhoto.Dispose(); 171 grPhoto.Dispose();
172 return scaledImage; 172 return scaledImage;
173 } 173 }
174 } 174 }
175} 175}
176#endif 176#endif