diff options
author | Teravus Ovares | 2008-05-09 07:50:00 +0000 |
---|---|---|
committer | Teravus Ovares | 2008-05-09 07:50:00 +0000 |
commit | b7baa3cd2aa60324f52118e565465475c669ec80 (patch) | |
tree | 99ce1c16edb1e0f8895e255e83c563ea489a5882 /OpenSim/Region/Physics/Meshing | |
parent | Thank you, Melanie for a patch that helps conversion (diff) | |
download | opensim-SC-b7baa3cd2aa60324f52118e565465475c669ec80.zip opensim-SC-b7baa3cd2aa60324f52118e565465475c669ec80.tar.gz opensim-SC-b7baa3cd2aa60324f52118e565465475c669ec80.tar.bz2 opensim-SC-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 'OpenSim/Region/Physics/Meshing')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 92 | ||||
-rw-r--r-- | OpenSim/Region/Physics/Meshing/SculptMesh.cs | 162 |
2 files changed, 187 insertions, 67 deletions
diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index 9c6dff4..1d2f986 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs | |||
@@ -1209,7 +1209,29 @@ namespace OpenSim.Region.Physics.Meshing | |||
1209 | 1209 | ||
1210 | return m; | 1210 | return m; |
1211 | } | 1211 | } |
1212 | private SculptMesh CreateSculptMesh(string primName, PrimitiveBaseShape primShape, PhysicsVector size) | ||
1213 | { | ||
1214 | SculptMesh sm = new SculptMesh(primShape.SculptData); | ||
1215 | // Scale the mesh based on our prim scale | ||
1216 | foreach (Vertex v in sm.vertices) | ||
1217 | { | ||
1218 | v.X *= 0.5f; | ||
1219 | v.Y *= 0.5f; | ||
1220 | v.Z *= 0.5f; | ||
1221 | v.X *= size.X; | ||
1222 | v.Y *= size.Y; | ||
1223 | v.Z *= size.Z; | ||
1224 | } | ||
1225 | // This was built with the normals pointing inside.. | ||
1226 | // therefore we have to invert the normals | ||
1227 | foreach (Triangle t in sm.triangles) | ||
1228 | { | ||
1229 | t.invertNormal(); | ||
1230 | } | ||
1231 | sm.DumpRaw(baseDir, primName, "Sculpt"); | ||
1232 | return sm; | ||
1212 | 1233 | ||
1234 | } | ||
1213 | public static void CalcNormals(Mesh mesh) | 1235 | public static void CalcNormals(Mesh mesh) |
1214 | { | 1236 | { |
1215 | int iTriangles = mesh.triangles.Count; | 1237 | int iTriangles = mesh.triangles.Count; |
@@ -1317,43 +1339,53 @@ namespace OpenSim.Region.Physics.Meshing | |||
1317 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size) | 1339 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size) |
1318 | { | 1340 | { |
1319 | Mesh mesh = null; | 1341 | Mesh mesh = null; |
1320 | 1342 | if (primShape.SculptEntry && primShape.SculptType != (byte)0 && primShape.SculptData.Length > 0) | |
1321 | switch (primShape.ProfileShape) | ||
1322 | { | 1343 | { |
1323 | case ProfileShape.Square: | 1344 | SculptMesh smesh = CreateSculptMesh(primName, primShape, size); |
1324 | mesh = CreateBoxMesh(primName, primShape, size); | 1345 | mesh = (Mesh)smesh; |
1325 | CalcNormals(mesh); | 1346 | CalcNormals(mesh); |
1326 | break; | 1347 | } |
1327 | case ProfileShape.Circle: | 1348 | else |
1328 | if (primShape.PathCurve == (byte)Extrusion.Straight) | 1349 | { |
1329 | { | 1350 | switch (primShape.ProfileShape) |
1330 | mesh = CreateCyllinderMesh(primName, primShape, size); | 1351 | { |
1331 | CalcNormals(mesh); | 1352 | case ProfileShape.Square: |
1332 | } | 1353 | mesh = CreateBoxMesh(primName, primShape, size); |
1333 | break; | ||
1334 | case ProfileShape.HalfCircle: | ||
1335 | if (primShape.PathCurve == (byte)Extrusion.Curve1) | ||
1336 | { | ||
1337 | mesh = CreateSphereMesh(primName, primShape, size); | ||
1338 | CalcNormals(mesh); | 1354 | CalcNormals(mesh); |
1339 | } | 1355 | break; |
1340 | break; | 1356 | case ProfileShape.Circle: |
1357 | if (primShape.PathCurve == (byte)Extrusion.Straight) | ||
1358 | { | ||
1359 | mesh = CreateCyllinderMesh(primName, primShape, size); | ||
1360 | CalcNormals(mesh); | ||
1361 | } | ||
1362 | break; | ||
1363 | case ProfileShape.HalfCircle: | ||
1364 | if (primShape.PathCurve == (byte)Extrusion.Curve1) | ||
1365 | { | ||
1366 | mesh = CreateSphereMesh(primName, primShape, size); | ||
1367 | CalcNormals(mesh); | ||
1368 | } | ||
1369 | break; | ||
1341 | 1370 | ||
1342 | case ProfileShape.EquilateralTriangle: | 1371 | case ProfileShape.EquilateralTriangle: |
1343 | mesh = CreatePrismMesh(primName, primShape, size); | 1372 | mesh = CreatePrismMesh(primName, primShape, size); |
1344 | CalcNormals(mesh); | 1373 | CalcNormals(mesh); |
1345 | break; | 1374 | break; |
1346 | 1375 | ||
1347 | default: | 1376 | default: |
1348 | mesh = CreateBoxMesh(primName, primShape, size); | 1377 | mesh = CreateBoxMesh(primName, primShape, size); |
1349 | CalcNormals(mesh); | 1378 | CalcNormals(mesh); |
1350 | //Set default mesh to cube otherwise it'll return | 1379 | //Set default mesh to cube otherwise it'll return |
1351 | // null and crash on the 'setMesh' method in the physics plugins. | 1380 | // null and crash on the 'setMesh' method in the physics plugins. |
1352 | //mesh = null; | 1381 | //mesh = null; |
1353 | break; | 1382 | break; |
1383 | } | ||
1354 | } | 1384 | } |
1355 | 1385 | ||
1356 | return mesh; | 1386 | return mesh; |
1357 | } | 1387 | } |
1388 | |||
1389 | |||
1358 | } | 1390 | } |
1359 | } | 1391 | } |
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 | |||
1 | using System; | 28 | using System; |
2 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
3 | using System.Drawing; | 30 | using System.Drawing; |
@@ -8,23 +35,34 @@ using Image = System.Drawing.Image; | |||
8 | 35 | ||
9 | namespace OpenSim.Region.Physics.Meshing | 36 | namespace 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 | } |