aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/Meshing/SculptMesh.cs
diff options
context:
space:
mode:
authorTeravus Ovares2008-05-09 07:50:00 +0000
committerTeravus Ovares2008-05-09 07:50:00 +0000
commitb7baa3cd2aa60324f52118e565465475c669ec80 (patch)
tree99ce1c16edb1e0f8895e255e83c563ea489a5882 /OpenSim/Region/Physics/Meshing/SculptMesh.cs
parentThank you, Melanie for a patch that helps conversion (diff)
downloadopensim-SC_OLD-b7baa3cd2aa60324f52118e565465475c669ec80.zip
opensim-SC_OLD-b7baa3cd2aa60324f52118e565465475c669ec80.tar.gz
opensim-SC_OLD-b7baa3cd2aa60324f52118e565465475c669ec80.tar.bz2
opensim-SC_OLD-b7baa3cd2aa60324f52118e565465475c669ec80.tar.xz
* Valid Sculpted prim now collide properly.
* The first time you set the sculpted texture of a prim you might have to futz with it to get it to generate a sculpted physics proxy * Note that there are already issues in Trunk, (such as the prim scaling issue and prim jumping issue. Essentially editing is difficult right now) * This just adds to the experimental nature of trunk. :D
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/Meshing/SculptMesh.cs162
1 files changed, 125 insertions, 37 deletions
diff --git a/OpenSim/Region/Physics/Meshing/SculptMesh.cs b/OpenSim/Region/Physics/Meshing/SculptMesh.cs
index ff9964e..924c4d3 100644
--- a/OpenSim/Region/Physics/Meshing/SculptMesh.cs
+++ b/OpenSim/Region/Physics/Meshing/SculptMesh.cs
@@ -1,3 +1,30 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
1using System; 28using System;
2using System.Collections.Generic; 29using System.Collections.Generic;
3using System.Drawing; 30using System.Drawing;
@@ -8,23 +35,34 @@ using Image = System.Drawing.Image;
8 35
9namespace OpenSim.Region.Physics.Meshing 36namespace OpenSim.Region.Physics.Meshing
10{ 37{
38 // This functionality based on the XNA SculptPreview by John Hurliman.
11 public class SculptMesh : Mesh 39 public class SculptMesh : Mesh
12 { 40 {
13 Image idata = null; 41 Image idata = null;
14 Bitmap bLOD = null; 42 Bitmap bLOD = null;
15 Bitmap bBitmap = null; 43 Bitmap bBitmap = null;
16 44
17 Vertex northpole = (Vertex)Vertex.Zero; 45 Vertex northpole = new Vertex(0, 0, 0);
18 Vertex southpole = (Vertex)Vertex.Zero; 46 Vertex southpole = new Vertex(0, 0, 0);
19 47
20 private int lod = 64; 48 private int lod = 32;
21 private const float RANGE = 128.0f; 49 private const float RANGE = 128.0f;
22 50
23 public SculptMesh(byte[] jpegData) 51 public SculptMesh(byte[] jpegData)
24 { 52 {
25 idata = OpenJPEG.DecodeToImage(jpegData); 53 idata = OpenJPEG.DecodeToImage(jpegData);
26 if (idata != null) 54 if (idata != null)
55 {
27 bBitmap = new Bitmap(idata); 56 bBitmap = new Bitmap(idata);
57 if (bBitmap.Width == bBitmap.Height)
58 {
59 DoLOD();
60
61 LoadPoles();
62
63 processSculptTexture();
64 }
65 }
28 66
29 67
30 } 68 }
@@ -37,17 +75,18 @@ namespace OpenSim.Region.Physics.Meshing
37 } 75 }
38 private void LoadPoles() 76 private void LoadPoles()
39 { 77 {
40 northpole = (Vertex)Vertex.Zero; 78 northpole = new Vertex(0, 0, 0);
41 for (int x = 0; x < bBitmap.Width; x++) 79 for (int x = 0; x < bLOD.Width; x++)
42 { 80 {
43 northpole += ColorToVertex(GetPixel(0, 0)); 81 northpole += ColorToVertex(GetPixel(0, 0));
44 } 82 }
45 northpole /= bBitmap.Width; 83 northpole /= bLOD.Width;
46 84
47 southpole = (Vertex)Vertex.Zero; 85 southpole = new Vertex(0, 0, 0);
48 for (int x = 0; x < bBitmap.Width; x++) 86 for (int x = 0; x < bLOD.Width; x++)
49 { 87 {
50 southpole += ColorToVertex(GetPixel(bBitmap.Height - 1, (bBitmap.Height - 1))); 88 //System.Console.WriteLine("Height: " + bLOD.Height.ToString());
89 southpole += ColorToVertex(GetPixel(bLOD.Height - 1, (bLOD.Height - 1)));
51 } 90 }
52 southpole /= bBitmap.Width; 91 southpole /= bBitmap.Width;
53 } 92 }
@@ -182,12 +221,16 @@ namespace OpenSim.Region.Physics.Meshing
182 { 221 {
183 v1 = ColorToVertex(GetPixel(x, y)); 222 v1 = ColorToVertex(GetPixel(x, y));
184 } 223 }
224
185 // Add the vertex for use later 225 // Add the vertex for use later
186 Add(v1); 226 if (!vertices.Contains(v1))
227 Add(v1);
228
187 sVertices[y * COLUMNS + x] = v1; 229 sVertices[y * COLUMNS + x] = v1;
230 //System.Console.WriteLine("adding: " + v1.ToString());
188 } 231 }
189 Vertex tempVertex = vertices[y * COLUMNS]; 232 //Vertex tempVertex = vertices[y * COLUMNS];
190 sVertices[y * COLUMNS + x_max] = tempVertex; 233 // sVertices[y * COLUMNS + x_max] = tempVertex;
191 } 234 }
192 235
193 // Create the Triangles 236 // Create the Triangles
@@ -199,32 +242,77 @@ namespace OpenSim.Region.Physics.Meshing
199 242
200 for (x = 0; x < x_max; x++) 243 for (x = 0; x < x_max; x++)
201 { 244 {
202 Triangle tri1 = new Triangle(sVertices[(y * COLUMNS + x)], sVertices[(y * COLUMNS + (x + 1))], 245 Vertex vt11 = sVertices[(y * COLUMNS + x)];
203 sVertices[((y + 1) * COLUMNS + (x + 1))]); 246 Vertex vt12 = sVertices[(y * COLUMNS + (x + 1))];
204 //indices[i++] = (ushort)(y * COLUMNS + x); 247 Vertex vt13 = sVertices[((y + 1) * COLUMNS + (x + 1))];
205 //indices[i++] = (ushort)(y * COLUMNS + (x + 1)); 248 if (vt11 != null && vt12 != null && vt13 != null)
206 //indices[i++] = (ushort)((y + 1) * COLUMNS + (x + 1)); 249 {
207 Add(tri1); 250 if (vt11 != vt12 && vt11 != vt13 && vt12 != vt13)
208 Triangle tri2 = new Triangle(sVertices[(y * COLUMNS + x)],sVertices[((y + 1) * COLUMNS + (x + 1))], 251 {
209 sVertices[((y + 1) * COLUMNS + x)]); 252 Triangle tri1 = new Triangle(vt11, vt12, vt13);
210 253 //indices[i++] = (ushort)(y * COLUMNS + x);
211 Add(tri2); 254 //indices[i++] = (ushort)(y * COLUMNS + (x + 1));
212 //indices[i++] = (ushort)(y * COLUMNS + x); 255 //indices[i++] = (ushort)((y + 1) * COLUMNS + (x + 1));
213 //indices[i++] = (ushort)((y + 1) * COLUMNS + (x + 1)); 256 Add(tri1);
214 //indices[i++] = (ushort)((y + 1) * COLUMNS + x); 257 }
258 }
259
260 Vertex vt21 = sVertices[(y * COLUMNS + x)];
261 Vertex vt22 = sVertices[((y + 1) * COLUMNS + (x + 1))];
262 Vertex vt23 = sVertices[((y + 1) * COLUMNS + x)];
263 if (vt21 != null && vt22 != null && vt23 != null)
264 {
265 if (vt21.Equals(vt22, 0.022f) || vt21.Equals(vt23, 0.022f) || vt22.Equals(vt23, 0.022f))
266 {
267 }
268 else
269 {
270 Triangle tri2 = new Triangle(vt21, vt22, vt23);
271 //indices[i++] = (ushort)(y * COLUMNS + x);
272 //indices[i++] = (ushort)((y + 1) * COLUMNS + (x + 1));
273 //indices[i++] = (ushort)((y + 1) * COLUMNS + x);
274 Add(tri2);
275 }
276 }
277
278 }
279 Vertex vt31 = sVertices[(y * x_max + x)];
280 Vertex vt32 = sVertices[(y * x_max + 0)];
281 Vertex vt33 = sVertices[((y + 1) * x_max + 0)];
282 if (vt31 != null && vt32 != null && vt33 != null)
283 {
284 if (vt31.Equals(vt32, 0.022f) || vt31.Equals(vt33, 0.022f) || vt32.Equals(vt33, 0.022f))
285 {
286 }
287 else
288 {
289 //Triangle tri3 = new Triangle(vt31, vt32, vt33);
290 // Wrap the last cell in the row around
291 //indices[i++] = (ushort)(y * x_max + x); //a
292 //indices[i++] = (ushort)(y * x_max + 0); //b
293 //indices[i++] = (ushort)((y + 1) * x_max + 0); //c
294 //Add(tri3);
295 }
296 }
297
298 Vertex vt41 = sVertices[(y * x_max + x)];
299 Vertex vt42 = sVertices[((y + 1) * x_max + 0)];
300 Vertex vt43 = sVertices[((y + 1) * x_max + x)];
301 if (vt41 != null && vt42 != null && vt43 != null)
302 {
303 if (vt41.Equals(vt42, 0.022f) || vt31.Equals(vt43, 0.022f) || vt32.Equals(vt43, 0.022f))
304 {
305 }
306 else
307 {
308 //Triangle tri4 = new Triangle(vt41, vt42, vt43);
309 //indices[i++] = (ushort)(y * x_max + x); //a
310 //indices[i++] = (ushort)((y + 1) * x_max + 0); //b
311 //indices[i++] = (ushort)((y + 1) * x_max + x); //c
312 //Add(tri4);
313 }
215 } 314 }
216 Triangle tri3 = new Triangle(sVertices[(y * x_max + x)], sVertices[(y * x_max + 0)], sVertices[((y + 1) * x_max + 0)]); 315
217 Add(tri3);
218 // Wrap the last cell in the row around
219 //indices[i++] = (ushort)(y * x_max + x); //a
220 //indices[i++] = (ushort)(y * x_max + 0); //b
221 //indices[i++] = (ushort)((y + 1) * x_max + 0); //c
222
223 Triangle tri4 = new Triangle(sVertices[(y * x_max + x)], sVertices[((y + 1) * x_max + 0)], sVertices[((y + 1) * x_max + x)]);
224 Add(tri4);
225 //indices[i++] = (ushort)(y * x_max + x); //a
226 //indices[i++] = (ushort)((y + 1) * x_max + 0); //b
227 //indices[i++] = (ushort)((y + 1) * x_max + x); //c
228 } 316 }
229 } 317 }
230 } 318 }