From d199767e6991d6f368661fce9c5a072e564b8a4b Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Sun, 25 Oct 2009 23:16:12 -0700 Subject: Experimental change of PhysicsVector to Vector3. Untested --- OpenSim/Region/Physics/Meshing/HelperTypes.cs | 62 +++++++++++++++++++-------- OpenSim/Region/Physics/Meshing/Mesh.cs | 7 +-- OpenSim/Region/Physics/Meshing/Meshmerizer.cs | 21 ++++----- 3 files changed, 56 insertions(+), 34 deletions(-) (limited to 'OpenSim/Region/Physics/Meshing') diff --git a/OpenSim/Region/Physics/Meshing/HelperTypes.cs b/OpenSim/Region/Physics/Meshing/HelperTypes.cs index 232245f..8cd8dcf 100644 --- a/OpenSim/Region/Physics/Meshing/HelperTypes.cs +++ b/OpenSim/Region/Physics/Meshing/HelperTypes.cs @@ -33,30 +33,52 @@ using OpenMetaverse; using OpenSim.Region.Physics.Manager; using OpenSim.Region.Physics.Meshing; -public class Vertex : PhysicsVector, IComparable +public class Vertex : IComparable { + Vector3 vector; + + public float X + { + get { return vector.X; } + set { vector.X = value; } + } + + public float Y + { + get { return vector.Y; } + set { vector.Y = value; } + } + + public float Z + { + get { return vector.Z; } + set { vector.Z = value; } + } + public Vertex(float x, float y, float z) - : base(x, y, z) { + vector.X = x; + vector.Y = y; + vector.Z = z; } public Vertex normalize() { - float tlength = length(); - if (tlength != 0) + float tlength = vector.Length(); + if (tlength != 0f) { float mul = 1.0f / tlength; - return new Vertex(X * mul, Y * mul, Z * mul); + return new Vertex(vector.X * mul, vector.Y * mul, vector.Z * mul); } else { - return new Vertex(0, 0, 0); + return new Vertex(0f, 0f, 0f); } } public Vertex cross(Vertex v) { - return new Vertex(Y * v.Z - Z * v.Y, Z * v.X - X * v.Z, X * v.Y - Y * v.X); + return new Vertex(vector.Y * v.Z - vector.Z * v.Y, vector.Z * v.X - vector.X * v.Z, vector.X * v.Y - vector.Y * v.X); } // disable warning: mono compiler moans about overloading @@ -160,9 +182,9 @@ public class Vertex : PhysicsVector, IComparable return X * v.X + Y * v.Y + Z * v.Z; } - public Vertex(PhysicsVector v) - : base(v.X, v.Y, v.Z) + public Vertex(Vector3 v) { + vector = v; } public Vertex Clone() @@ -175,11 +197,15 @@ public class Vertex : PhysicsVector, IComparable return new Vertex((float) Math.Cos(angle), (float) Math.Sin(angle), 0.0f); } + public float Length() + { + return vector.Length(); + } public virtual bool Equals(Vertex v, float tolerance) { - PhysicsVector diff = this - v; - float d = diff.length(); + Vertex diff = this - v; + float d = diff.Length(); if (d < tolerance) return true; @@ -369,22 +395,22 @@ public class Triangle return s1 + ";" + s2 + ";" + s3; } - public PhysicsVector getNormal() + public Vector3 getNormal() { // Vertices // Vectors for edges - PhysicsVector e1; - PhysicsVector e2; + Vector3 e1; + Vector3 e2; - e1 = new PhysicsVector(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z); - e2 = new PhysicsVector(v1.X - v3.X, v1.Y - v3.Y, v1.Z - v3.Z); + e1 = new Vector3(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z); + e2 = new Vector3(v1.X - v3.X, v1.Y - v3.Y, v1.Z - v3.Z); // Cross product for normal - PhysicsVector n = PhysicsVector.cross(e1, e2); + Vector3 n = Vector3.Cross(e1, e2); // Length - float l = n.length(); + float l = n.Length(); // Normalized "normal" n = n/l; diff --git a/OpenSim/Region/Physics/Meshing/Mesh.cs b/OpenSim/Region/Physics/Meshing/Mesh.cs index e8a3e19..f781ff9 100644 --- a/OpenSim/Region/Physics/Meshing/Mesh.cs +++ b/OpenSim/Region/Physics/Meshing/Mesh.cs @@ -31,6 +31,7 @@ using System.IO; using System.Runtime.InteropServices; using OpenSim.Region.Physics.Manager; using PrimMesher; +using OpenMetaverse; namespace OpenSim.Region.Physics.Meshing { @@ -141,12 +142,12 @@ namespace OpenSim.Region.Physics.Meshing } } - public List getVertexList() + public List getVertexList() { - List result = new List(); + List result = new List(); foreach (Vertex v in m_vertices.Keys) { - result.Add(v); + result.Add(new Vector3(v.X, v.Y, v.Z)); } return result; } diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs index 01093e2..a90a89a 100644 --- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs +++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs @@ -61,7 +61,6 @@ namespace OpenSim.Region.Physics.Meshing public class Meshmerizer : IMesher { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - //private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Setting baseDir to a path will enable the dumping of raw files // raw files can be imported by blender so a visual inspection of the results can be done @@ -160,7 +159,7 @@ namespace OpenSim.Region.Physics.Meshing float minZ = float.MaxValue; float maxZ = float.MinValue; - foreach (Vertex v in meshIn.getVertexList()) + foreach (Vector3 v in meshIn.getVertexList()) { if (v != null) { @@ -185,7 +184,7 @@ namespace OpenSim.Region.Physics.Meshing } - private ulong GetMeshKey(PrimitiveBaseShape pbs, PhysicsVector size, float lod) + private ulong GetMeshKey(PrimitiveBaseShape pbs, Vector3 size, float lod) { ulong hash = 5381; @@ -245,9 +244,9 @@ namespace OpenSim.Region.Physics.Meshing hash = ((hash << 5) + hash) + (ulong)((byte)c); return ((hash << 5) + hash) + (ulong)(c >> 8); } - - private Mesh CreateMeshFromPrimMesher(string primName, PrimitiveBaseShape primShape, PhysicsVector size, float lod) + + private Mesh CreateMeshFromPrimMesher(string primName, PrimitiveBaseShape primShape, Vector3 size, float lod) { PrimMesh primMesh; PrimMesher.SculptMesh sculptMesh; @@ -289,9 +288,6 @@ namespace OpenSim.Region.Physics.Meshing ManagedImage managedImage; // we never use this OpenJPEG.DecodeToImage(primShape.SculptData, out managedImage, out idata); - // Remove the reference to the encoded JPEG2000 data so it can be GCed - primShape.SculptData = Utils.EmptyBytes; - if (cacheSculptMaps) { try { idata.Save(decodedSculptFileName, ImageFormat.MemoryBmp); } @@ -315,8 +311,6 @@ namespace OpenSim.Region.Physics.Meshing } } - - PrimMesher.SculptMesh.SculptType sculptType; switch ((OpenMetaverse.SculptType)primShape.SculptType) { @@ -351,7 +345,6 @@ namespace OpenSim.Region.Physics.Meshing coords = sculptMesh.coords; faces = sculptMesh.faces; } - else { float pathShearX = primShape.PathShearX < 128 ? (float)primShape.PathShearX * 0.01f : (float)(primShape.PathShearX - 256) * 0.01f; @@ -466,6 +459,8 @@ namespace OpenSim.Region.Physics.Meshing faces = primMesh.faces; } + // Remove the reference to any JPEG2000 sculpt data so it can be GCed + primShape.SculptData = Utils.EmptyBytes; int numCoords = coords.Count; int numFaces = faces.Count; @@ -488,12 +483,12 @@ namespace OpenSim.Region.Physics.Meshing return mesh; } - public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size, float lod) + public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod) { return CreateMesh(primName, primShape, size, lod, false); } - public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size, float lod, bool isPhysical) + public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical) { Mesh mesh = null; ulong key = 0; -- cgit v1.1