From a0265300aa09be0bdd2d4629d6a22394d5b219be Mon Sep 17 00:00:00 2001 From: dan miller Date: Sat, 29 Sep 2007 03:56:36 +0000 Subject: Hollow prims (box only), thanks Gerard! Enjoy --- .../Region/Environment/Scenes/Scene.Inventory.cs | 9 +- OpenSim/Region/Environment/Scenes/Scene.cs | 13 +- .../Region/Environment/Scenes/SceneObjectGroup.cs | 29 +++- OpenSim/Region/Environment/Scenes/ScenePresence.cs | 2 +- .../BasicPhysicsPlugin/BasicPhysicsPlugin.cs | 10 +- .../Region/Physics/BulletXPlugin/BulletXPlugin.cs | 14 +- OpenSim/Region/Physics/Manager/PhysicsScene.cs | 14 +- OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 187 +++++++++++++++++++-- OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs | 12 +- prebuild.xml | 9 + 10 files changed, 264 insertions(+), 35 deletions(-) diff --git a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs index 81c0b73..bcc02ea 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs @@ -429,12 +429,17 @@ namespace OpenSim.Region.Environment.Scenes group.AbsolutePosition = pos; SceneObjectPart rootPart = group.GetChildPart(group.UUID); if ((rootPart.ObjectFlags & (uint) LLObject.ObjectFlags.Phantom) == 0) - rootPart.PhysActor = phyScene.AddPrim( + { + PrimitiveBaseShape pbs = rootPart.Shape; + rootPart.PhysActor = phyScene.AddPrimShape( + rootPart.Name, + pbs, new PhysicsVector(rootPart.AbsolutePosition.X, rootPart.AbsolutePosition.Y, rootPart.AbsolutePosition.Z), new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z), new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X, rootPart.RotationOffset.Y, rootPart.RotationOffset.Z)); + } } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 8ad8147..579ec90 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -531,7 +531,9 @@ namespace OpenSim.Region.Environment.Scenes AddEntityFromStorage(prim); SceneObjectPart rootPart = prim.GetChildPart(prim.UUID); if ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Phantom) == 0) - rootPart.PhysActor = phyScene.AddPrim( + rootPart.PhysActor = phyScene.AddPrimShape( + rootPart.Name, + rootPart.Shape, new PhysicsVector(rootPart.AbsolutePosition.X, rootPart.AbsolutePosition.Y, rootPart.AbsolutePosition.Z), new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z), @@ -579,7 +581,10 @@ namespace OpenSim.Region.Environment.Scenes // if not phantom, add to physics if ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Phantom) == 0) rootPart.PhysActor = - phyScene.AddPrim(new PhysicsVector(pos.X, pos.Y, pos.Z), + phyScene.AddPrimShape( + rootPart.Name, + rootPart.Shape, + new PhysicsVector(pos.X, pos.Y, pos.Z), new PhysicsVector(shape.Scale.X, shape.Scale.Y, shape.Scale.Z), new Quaternion()); } @@ -662,7 +667,9 @@ namespace OpenSim.Region.Environment.Scenes SceneObjectPart rootPart = obj.GetChildPart(obj.UUID); if ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Phantom) == 0) - rootPart.PhysActor = phyScene.AddPrim( + rootPart.PhysActor = phyScene.AddPrimShape( + rootPart.Name, + rootPart.Shape, new PhysicsVector(rootPart.AbsolutePosition.X, rootPart.AbsolutePosition.Y, rootPart.AbsolutePosition.Z), new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z), diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs index 890008d..da9f366 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs @@ -314,12 +314,16 @@ namespace OpenSim.Region.Environment.Scenes /// may need to create a new Physics actor. if (dupe.RootPart.PhysActor != null) { - dupe.RootPart.PhysActor = m_scene.PhysScene.AddPrim( - new PhysicsVector(dupe.RootPart.AbsolutePosition.X, dupe.RootPart.AbsolutePosition.Y, - dupe.RootPart.AbsolutePosition.Z), - new PhysicsVector(dupe.RootPart.Scale.X, dupe.RootPart.Scale.Y, dupe.RootPart.Scale.Z), - new Quaternion(dupe.RootPart.RotationOffset.W, dupe.RootPart.RotationOffset.X, - dupe.RootPart.RotationOffset.Y, dupe.RootPart.RotationOffset.Z)); + PrimitiveBaseShape pbs = dupe.RootPart.Shape; + + dupe.RootPart.PhysActor = m_scene.PhysScene.AddPrimShape( + dupe.RootPart.Name, + pbs, + new PhysicsVector(dupe.RootPart.AbsolutePosition.X, dupe.RootPart.AbsolutePosition.Y, dupe.RootPart.AbsolutePosition.Z), + new PhysicsVector(dupe.RootPart.Scale.X, dupe.RootPart.Scale.Y, dupe.RootPart.Scale.Z), + new Axiom.Math.Quaternion(dupe.RootPart.RotationOffset.W, dupe.RootPart.RotationOffset.X, + dupe.RootPart.RotationOffset.Y, dupe.RootPart.RotationOffset.Z)); + } List partList = new List(m_parts.Values); @@ -838,6 +842,17 @@ namespace OpenSim.Region.Environment.Scenes { part.UpdateShape(shapeBlock); } + if (m_rootPart.PhysActor != null) + { + this.m_scene.PhysScene.RemovePrim(m_rootPart.PhysActor); + m_rootPart.PhysActor = m_scene.PhysScene.AddPrimShape( + m_rootPart.Name, + m_rootPart.Shape, + new PhysicsVector(m_rootPart.AbsolutePosition.X, m_rootPart.AbsolutePosition.Y, m_rootPart.AbsolutePosition.Z), + new PhysicsVector(m_rootPart.Scale.X, m_rootPart.Scale.Y, m_rootPart.Scale.Z), + new Axiom.Math.Quaternion(m_rootPart.RotationOffset.W, m_rootPart.RotationOffset.X, + m_rootPart.RotationOffset.Y, m_rootPart.RotationOffset.Z)); + } } #endregion @@ -1252,4 +1267,4 @@ namespace OpenSim.Region.Environment.Scenes Text = text; } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs index 0338572..428b771 100644 --- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs @@ -914,7 +914,7 @@ namespace OpenSim.Region.Environment.Scenes new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y, AbsolutePosition.Z); - m_physicsActor = scene.AddAvatar(pVec); + m_physicsActor = scene.AddAvatar(this.Firstname+"."+this.Lastname, pVec); } internal void Close() diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs index 31861b4..85d9ff6 100644 --- a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs +++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs @@ -27,6 +27,7 @@ */ using System.Collections.Generic; using Axiom.Math; +using OpenSim.Framework.Types; using OpenSim.Region.Physics.Manager; namespace OpenSim.Region.Physics.BasicPhysicsPlugin @@ -72,7 +73,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin } - public override PhysicsActor AddAvatar(PhysicsVector position) + public override PhysicsActor AddAvatar(string avName, PhysicsVector position) { BasicActor act = new BasicActor(); act.Position = position; @@ -95,10 +96,17 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin } +/* public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation) { return null; } +*/ + public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation) + { + return null; + } + public override void Simulate(float timeStep) { diff --git a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs index 6d8e1a8..af13d02 100644 --- a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs +++ b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs @@ -30,6 +30,7 @@ #region References using System; using System.Collections.Generic; +using OpenSim.Framework.Types; using OpenSim.Region.Physics.Manager; using Axiom.Math; using AxiomQuaternion = Axiom.Math.Quaternion; @@ -252,7 +253,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin this._heightmap = new float[65536]; } - public override PhysicsActor AddAvatar(PhysicsVector position) + public override PhysicsActor AddAvatar(string avName, PhysicsVector position) { PhysicsVector pos = new PhysicsVector(); pos.X = position.X; @@ -276,7 +277,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin } } } - public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, AxiomQuaternion rotation) + PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, AxiomQuaternion rotation) { BulletXPrim newPrim = null; lock (BulletXLock) @@ -286,6 +287,11 @@ namespace OpenSim.Region.Physics.BulletXPlugin } return newPrim; } + public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, AxiomQuaternion rotation) + { + return AddPrim(position, size, rotation); + } + public override void RemovePrim(PhysicsActor prim) { if (prim is BulletXPrim) @@ -709,7 +715,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin { _startTransform.Translation = BulletXMaths.PhysicsVectorToXnaVector3(pos); //For now all prims are boxes - CollisionShape _collisionShape = new BoxShape(BulletXMaths.PhysicsVectorToXnaVector3(_size) / 2.0f); + CollisionShape _collisionShape = new XnaDevRu.BulletX.BoxShape(BulletXMaths.PhysicsVectorToXnaVector3(_size) / 2.0f); DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset); MonoXnaCompactMaths.Vector3 _localInertia = new MonoXnaCompactMaths.Vector3(); _collisionShape.CalculateLocalInertia(Mass, out _localInertia); //Always when mass > 0 @@ -912,7 +918,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin MonoXnaCompactMaths.Vector3 _newsize; _newsize = BulletXMaths.PhysicsVectorToXnaVector3(_newSize); //For now all prims are Boxes - rigidBody.CollisionShape = new BoxShape(BulletXMaths.PhysicsVectorToXnaVector3(_newSize) / 2.0f); + rigidBody.CollisionShape = new XnaDevRu.BulletX.BoxShape(BulletXMaths.PhysicsVectorToXnaVector3(_newSize) / 2.0f); } private void ReOrient() { diff --git a/OpenSim/Region/Physics/Manager/PhysicsScene.cs b/OpenSim/Region/Physics/Manager/PhysicsScene.cs index 9e3f6ea..bd06fa1 100644 --- a/OpenSim/Region/Physics/Manager/PhysicsScene.cs +++ b/OpenSim/Region/Physics/Manager/PhysicsScene.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ +using OpenSim.Framework.Types; using OpenSim.Framework.Console; using Axiom.Math; @@ -40,13 +41,13 @@ namespace OpenSim.Region.Physics.Manager } } - public abstract PhysicsActor AddAvatar(PhysicsVector position); + public abstract PhysicsActor AddAvatar(string avName, PhysicsVector position); public abstract void RemoveAvatar(PhysicsActor actor); public abstract void RemovePrim(PhysicsActor prim); - public abstract PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation); + public abstract PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation); public abstract void Simulate(float timeStep); @@ -65,7 +66,7 @@ namespace OpenSim.Region.Physics.Manager { private static int m_workIndicator; - public override PhysicsActor AddAvatar(PhysicsVector position) + public override PhysicsActor AddAvatar(string avName, PhysicsVector position) { MainLog.Instance.Verbose("NullPhysicsScene : AddAvatar({0})", position); return PhysicsActor.Null; @@ -81,11 +82,18 @@ namespace OpenSim.Region.Physics.Manager } +/* public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation) { MainLog.Instance.Verbose("NullPhysicsScene : AddPrim({0},{1})", position, size); return PhysicsActor.Null; } +*/ + public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation) + { + MainLog.Instance.Verbose("NullPhysicsScene : AddPrim({0},{1})", position, size); + return PhysicsActor.Null; + } public override void Simulate(float timeStep) { diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs index 8d142ab..e7592fb 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs @@ -28,10 +28,17 @@ using System; using System.Threading; using System.Collections.Generic; + +using libsecondlife; +using libsecondlife.Utilities; + using Axiom.Math; using Ode.NET; +using OpenSim.Framework.Types; +using OpenSim.Framework.Console; using OpenSim.Region.Physics.Manager; + namespace OpenSim.Region.Physics.OdePlugin { /// @@ -77,8 +84,11 @@ namespace OpenSim.Region.Physics.OdePlugin private IntPtr LandGeom; private double[] _heightmap; private d.NearCallback nearCallback; + public d.TriCallback triCallback; + public d.TriArrayCallback triArrayCallback; private List _characters = new List(); private List _prims = new List(); + public Dictionary geom_name_map=new Dictionary(); private d.ContactGeom[] contacts = new d.ContactGeom[30]; private d.Contact contact; @@ -89,6 +99,8 @@ namespace OpenSim.Region.Physics.OdePlugin public OdeScene() { nearCallback = near; + triCallback = TriCallback; + triArrayCallback = TriArrayCallback; contact.surface.mode |= d.ContactFlags.Approx1 | d.ContactFlags.SoftCFM | d.ContactFlags.SoftERP; contact.surface.mu = 10.0f; contact.surface.bounce = 0.9f; @@ -112,12 +124,33 @@ namespace OpenSim.Region.Physics.OdePlugin private void near(IntPtr space, IntPtr g1, IntPtr g2) { // no lock here! It's invoked from within Simulate(), which is thread-locked + if (g1 == g2) + return; // Can't collide with yourself + IntPtr b1 = d.GeomGetBody(g1); IntPtr b2 = d.GeomGetBody(g2); + if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact)) return; - int count = d.Collide(g1, g2, 500, contacts, d.ContactGeom.SizeOf); + d.GeomClassID id = d.GeomGetClass(g1); + if (id==d.GeomClassID.TriMeshClass) + { + String name1 = null; + String name2 = null; + if (!geom_name_map.TryGetValue(g1, out name1)) + { + name1 = "null"; + } + if (!geom_name_map.TryGetValue(g2, out name2)) + { + name2 = "null"; + } + +// MainLog.Instance.Verbose("near: A collision was detected between {1} and {2}", 0, name1, name2); + } + + int count = d.Collide(g1, g2, contacts.GetLength(0), contacts, d.ContactGeom.SizeOf); for (int i = 0; i < count; i++) { contact.geom = contacts[i]; @@ -139,21 +172,24 @@ namespace OpenSim.Region.Physics.OdePlugin } } - public override PhysicsActor AddAvatar(PhysicsVector position) + public override PhysicsActor AddAvatar(string avName, PhysicsVector position) { PhysicsVector pos = new PhysicsVector(); pos.X = position.X; pos.Y = position.Y; pos.Z = position.Z; - OdeCharacter newAv = new OdeCharacter(this, pos); + OdeCharacter newAv = new OdeCharacter(avName, this, pos); _characters.Add(newAv); return newAv; } public override void RemoveAvatar(PhysicsActor actor) { - ((OdeCharacter)actor).Destroy(); - _characters.Remove((OdeCharacter)actor); + lock (OdeLock) + { + ((OdeCharacter)actor).Destroy(); + _characters.Remove((OdeCharacter)actor); + } } public override void RemovePrim(PhysicsActor prim) @@ -168,7 +204,7 @@ namespace OpenSim.Region.Physics.OdePlugin } } - public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation) + PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, Quaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) { PhysicsVector pos = new PhysicsVector(); pos.X = position.X; @@ -186,12 +222,91 @@ namespace OpenSim.Region.Physics.OdePlugin OdePrim newPrim; lock (OdeLock) { - newPrim = new OdePrim(this, pos, siz, rot); + newPrim = new OdePrim(name, this, pos, siz, rot, mesh, pbs); } _prims.Add(newPrim); return newPrim; } + + public int TriArrayCallback(System.IntPtr trimesh, System.IntPtr refObject, int[] triangleIndex, int triCount) + { +/* String name1 = null; + String name2 = null; + + if (!geom_name_map.TryGetValue(trimesh, out name1)) + { + name1 = "null"; + } + if (!geom_name_map.TryGetValue(refObject, out name2)) + { + name2 = "null"; + } + + MainLog.Instance.Verbose("TriArrayCallback: A collision was detected between {1} and {2}", 0, name1, name2); +*/ + return 1; + } + + public int TriCallback(System.IntPtr trimesh, System.IntPtr refObject, int triangleIndex) + { + + String name1 = null; + String name2 = null; + + if (!geom_name_map.TryGetValue(trimesh, out name1)) + { + Console.WriteLine("+++ nulling " + name1); + name1 = "null"; + } + if (!geom_name_map.TryGetValue(refObject, out name2)) + { + Console.WriteLine("+++ nulling " + name2); + name2 = "null"; + } + +// MainLog.Instance.Verbose("TriCallback: A collision was detected between {1} and {2}. Index was {3}", 0, name1, name2, triangleIndex); + + d.Vector3 v0 = new d.Vector3(); + d.Vector3 v1 = new d.Vector3(); + d.Vector3 v2 = new d.Vector3(); + + d.GeomTriMeshGetTriangle(trimesh, 0, ref v0, ref v1, ref v2); + MainLog.Instance.Debug("Triangle {0} is <{1},{2},{3}>, <{4},{5},{6}>, <{7},{8},{9}>", triangleIndex, v0.X, v0.Y, v0.Z, v1.X, v1.Y, v1.Z, v2.X, v2.Y, v2.Z); + + return 1; + } + + + public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation) + { + PhysicsActor result; + + switch(pbs.ProfileShape) + { + case ProfileShape.Square: + /// support simple box & hollow box now; later, more shapes + if (pbs.ProfileHollow == 0) + { + result = AddPrim(primName, position, size, rotation, null, null); + } + else + { + Mesh mesh = Meshmerizer.CreateMesh(pbs, size); + result = AddPrim(primName, position, size, rotation, mesh, pbs); + } + break; + + default: + result = AddPrim(primName, position, size, rotation, null, null); + break; + } + + return result; + } + + + public override void Simulate(float timeStep) { lock (OdeLock) @@ -247,6 +362,8 @@ namespace OpenSim.Region.Physics.OdePlugin d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 256, 256, 256, 256, 1.0f, 0.0f, 2.0f, 0); d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256); LandGeom = d.CreateHeightfield(space, HeightmapData, 1); + this.geom_name_map[LandGeom]="Terrain"; + d.Matrix3 R = new d.Matrix3(); Quaternion q1 = Quaternion.FromAngleAxis(1.5707f, new Vector3(1, 0, 0)); @@ -285,7 +402,7 @@ namespace OpenSim.Region.Physics.OdePlugin public IntPtr capsule_geom; public d.Mass capsule_mass; - public OdeCharacter(OdeScene parent_scene, PhysicsVector pos) + public OdeCharacter(String avName, OdeScene parent_scene, PhysicsVector pos) { _velocity = new PhysicsVector(); _position = pos; @@ -300,6 +417,8 @@ namespace OpenSim.Region.Physics.OdePlugin d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z); d.GeomSetBody(capsule_geom, BoundingCapsule); } + parent_scene.geom_name_map[capsule_geom]=avName; + } public override bool Flying @@ -454,6 +573,8 @@ namespace OpenSim.Region.Physics.OdePlugin lock (OdeScene.OdeLock) { d.GeomDestroy(this.capsule_geom); + Console.WriteLine("+++ removing geom"); + this._parent_scene.geom_name_map.Remove(this.capsule_geom); d.BodyDestroy(this.BoundingCapsule); } } @@ -466,18 +587,35 @@ namespace OpenSim.Region.Physics.OdePlugin private PhysicsVector _size; private PhysicsVector _acceleration; private Quaternion _orientation; + private Mesh _mesh; + private PrimitiveBaseShape _pbs; + private OdeScene _parent_scene; public IntPtr prim_geom; + public IntPtr _triMeshData; - public OdePrim(OdeScene parent_scene, PhysicsVector pos, PhysicsVector size, Quaternion rotation) + public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size, + Quaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) { _velocity = new PhysicsVector(); _position = pos; _size = size; _acceleration = new PhysicsVector(); _orientation = rotation; + _mesh = mesh; + _pbs = pbs; + _parent_scene = parent_scene; + lock (OdeScene.OdeLock) { - prim_geom = d.CreateBox(parent_scene.space, _size.X, _size.Y, _size.Z); + if (mesh!=null) + { + setMesh(parent_scene, mesh); + } + else + { + prim_geom = d.CreateBox(parent_scene.space, _size.X, _size.Y, _size.Z); + } + d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); d.Quaternion myrot = new d.Quaternion(); myrot.W = rotation.w; @@ -485,9 +623,25 @@ namespace OpenSim.Region.Physics.OdePlugin myrot.Y = rotation.y; myrot.Z = rotation.z; d.GeomSetQuaternion(prim_geom, ref myrot); + parent_scene.geom_name_map[prim_geom] = primName; // don't do .add() here; old geoms get recycled with the same hash } } + public void setMesh(OdeScene parent_scene, Mesh mesh) + { + float[] vertexList = mesh.getVertexListAsFloat(); // Note, that vertextList is pinned in memory + int[] indexList = mesh.getIndexListAsInt(); // Also pinned, needs release after usage + int VertexCount = vertexList.GetLength(0) / 3; + int IndexCount = indexList.GetLength(0); + + _triMeshData = d.GeomTriMeshDataCreate(); + + d.GeomTriMeshDataBuildSimple(_triMeshData, vertexList, 3 * sizeof(float), VertexCount, indexList, IndexCount, 3 * sizeof(int)); + d.GeomTriMeshDataPreprocess(_triMeshData); + + prim_geom = d.CreateTriMesh(parent_scene.space, _triMeshData, parent_scene.triCallback, parent_scene.triArrayCallback, null); + } + public override bool Flying { get @@ -526,7 +680,18 @@ namespace OpenSim.Region.Physics.OdePlugin _size = value; lock (OdeScene.OdeLock) { - d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z); + if (_mesh != null) // We deal with a mesh here + { + string oldname = _parent_scene.geom_name_map[prim_geom]; + d.GeomDestroy(prim_geom); + Mesh mesh = Meshmerizer.CreateMesh(_pbs, _size); + setMesh(_parent_scene, mesh); + _parent_scene.geom_name_map[prim_geom] = oldname; + } + else + { + d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z); + } } } } diff --git a/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs b/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs index ba9fe36..d45bfd1 100644 --- a/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs +++ b/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs @@ -27,6 +27,7 @@ */ using System; using System.Collections.Generic; +using OpenSim.Framework.Types; using OpenSim.Region.Physics.Manager; using PhysXWrapper; using Quaternion=Axiom.Math.Quaternion; @@ -86,14 +87,14 @@ namespace OpenSim.Region.Physics.PhysXPlugin } - public override PhysicsActor AddAvatar(PhysicsVector position) + public override PhysicsActor AddAvatar(string avName, PhysicsVector position) { Vec3 pos = new Vec3(); pos.X = position.X; pos.Y = position.Y; pos.Z = position.Z; PhysXCharacter act = new PhysXCharacter( scene.AddCharacter(pos)); - act.Position = position; + act.Position = position; _characters.Add(act); return act; } @@ -108,7 +109,7 @@ namespace OpenSim.Region.Physics.PhysXPlugin } - public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation) + PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation) { Vec3 pos = new Vec3(); pos.X = position.X; @@ -122,6 +123,11 @@ namespace OpenSim.Region.Physics.PhysXPlugin _prims.Add(act); return act; } + public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation) + { + return AddPrim(position, size, rotation); + } + public override void Simulate(float timeStep) { try diff --git a/prebuild.xml b/prebuild.xml index bbd403c..7e4d46d 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -199,6 +199,7 @@ ../../../../bin/ + @@ -224,6 +225,7 @@ ../../../../bin/ + @@ -244,8 +246,10 @@ ../../../../bin/ + + @@ -267,6 +271,9 @@ ../../../../bin/ + + + @@ -289,7 +296,9 @@ ../../../../bin/ + + -- cgit v1.1