aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
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
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 'OpenSim/Region')
-rw-r--r--OpenSim/Region/Environment/Scenes/Scene.cs2
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs13
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneObjectPart.cs8
-rw-r--r--OpenSim/Region/Physics/Meshing/Meshmerizer.cs92
-rw-r--r--OpenSim/Region/Physics/Meshing/SculptMesh.cs162
5 files changed, 209 insertions, 68 deletions
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
index 5ce3c7b..1f66744 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -1134,7 +1134,7 @@ namespace OpenSim.Region.Environment.Scenes
1134 SceneObjectPart rootPart = group.GetChildPart(group.UUID); 1134 SceneObjectPart rootPart = group.GetChildPart(group.UUID);
1135 rootPart.ObjectFlags &= ~(uint)LLObject.ObjectFlags.Scripted; 1135 rootPart.ObjectFlags &= ~(uint)LLObject.ObjectFlags.Scripted;
1136 rootPart.TrimPermissions(); 1136 rootPart.TrimPermissions();
1137 1137 group.CheckSculptAndLoad();
1138 group.ApplyPhysics(m_physicalPrim); 1138 group.ApplyPhysics(m_physicalPrim);
1139 //rootPart.DoPhysicsPropertyUpdate(UsePhysics, true); 1139 //rootPart.DoPhysicsPropertyUpdate(UsePhysics, true);
1140 } 1140 }
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
index 033a419..aae6af8 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
@@ -2546,5 +2546,18 @@ namespace OpenSim.Region.Environment.Scenes
2546 } 2546 }
2547 return retmass; 2547 return retmass;
2548 } 2548 }
2549 public void CheckSculptAndLoad()
2550 {
2551 lock (m_parts)
2552 {
2553 foreach (SceneObjectPart part in m_parts.Values)
2554 {
2555 if (part.Shape.SculptEntry && part.Shape.SculptTexture != LLUUID.Zero)
2556 {
2557 m_scene.AssetCache.GetAsset(part.Shape.SculptTexture, part.SculptTextureCallback, true);
2558 }
2559 }
2560 }
2561 }
2549 } 2562 }
2550} 2563}
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
index 0075a22..9502627 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
@@ -1568,6 +1568,10 @@ namespace OpenSim.Region.Environment.Scenes
1568 byte[] extraP = new byte[Shape.ExtraParams.Length]; 1568 byte[] extraP = new byte[Shape.ExtraParams.Length];
1569 Array.Copy(Shape.ExtraParams, extraP, extraP.Length); 1569 Array.Copy(Shape.ExtraParams, extraP, extraP.Length);
1570 dupe.Shape.ExtraParams = extraP; 1570 dupe.Shape.ExtraParams = extraP;
1571 if (dupe.m_shape.SculptEntry && dupe.m_shape.SculptTexture != LLUUID.Zero)
1572 {
1573 m_parentGroup.Scene.AssetCache.GetAsset(dupe.m_shape.SculptTexture, dupe.SculptTextureCallback, true);
1574 }
1571 bool UsePhysics = ((dupe.ObjectFlags & (uint) LLObject.ObjectFlags.Physics) != 0); 1575 bool UsePhysics = ((dupe.ObjectFlags & (uint) LLObject.ObjectFlags.Physics) != 0);
1572 dupe.DoPhysicsPropertyUpdate(UsePhysics, true); 1576 dupe.DoPhysicsPropertyUpdate(UsePhysics, true);
1573 1577
@@ -1939,6 +1943,10 @@ namespace OpenSim.Region.Environment.Scenes
1939 if (texture != null) 1943 if (texture != null)
1940 { 1944 {
1941 m_shape.SculptData = texture.Data; 1945 m_shape.SculptData = texture.Data;
1946 if (PhysActor != null)
1947 {
1948 PhysActor.Shape = m_shape;
1949 }
1942 } 1950 }
1943 } 1951 }
1944 1952
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
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 }