diff options
author | dan miller | 2007-11-05 12:25:53 +0000 |
---|---|---|
committer | dan miller | 2007-11-05 12:25:53 +0000 |
commit | fdb57b28b164f239de0f976b967b79dc2ca5f6ae (patch) | |
tree | e998ae9c7dd6e248e794e35ca19678e3b6f6fad1 /OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | |
parent | Changed it so opensim.exe should scan for new application plugins every time ... (diff) | |
download | opensim-SC-fdb57b28b164f239de0f976b967b79dc2ca5f6ae.zip opensim-SC-fdb57b28b164f239de0f976b967b79dc2ca5f6ae.tar.gz opensim-SC-fdb57b28b164f239de0f976b967b79dc2ca5f6ae.tar.bz2 opensim-SC-fdb57b28b164f239de0f976b967b79dc2ca5f6ae.tar.xz |
prim cuts in ODE
Much thanks to Gerhard!
Merged with Darok's recent changes re: physical prims
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 121 |
1 files changed, 95 insertions, 26 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs index f1db034..9ac43bf 100644 --- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs +++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | |||
@@ -32,6 +32,8 @@ using Axiom.Math; | |||
32 | using Ode.NET; | 32 | using Ode.NET; |
33 | using OpenSim.Framework; | 33 | using OpenSim.Framework; |
34 | using OpenSim.Region.Physics.Manager; | 34 | using OpenSim.Region.Physics.Manager; |
35 | using OpenSim.Region.Physics.OdePlugin.Meshing; | ||
36 | |||
35 | 37 | ||
36 | namespace OpenSim.Region.Physics.OdePlugin | 38 | namespace OpenSim.Region.Physics.OdePlugin |
37 | { | 39 | { |
@@ -274,6 +276,7 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
274 | 276 | ||
275 | public int TriCallback(IntPtr trimesh, IntPtr refObject, int triangleIndex) | 277 | public int TriCallback(IntPtr trimesh, IntPtr refObject, int triangleIndex) |
276 | { | 278 | { |
279 | /* | ||
277 | String name1 = null; | 280 | String name1 = null; |
278 | String name2 = null; | 281 | String name2 = null; |
279 | 282 | ||
@@ -294,45 +297,52 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
294 | 297 | ||
295 | d.GeomTriMeshGetTriangle(trimesh, 0, ref v0, ref v1, ref v2); | 298 | d.GeomTriMeshGetTriangle(trimesh, 0, ref v0, ref v1, ref v2); |
296 | // 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); | 299 | // 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); |
297 | 300 | */ | |
298 | return 1; | 301 | return 1; |
299 | } | 302 | } |
300 | 303 | ||
304 | |||
305 | public bool needsMeshing(PrimitiveBaseShape pbs) | ||
306 | { | ||
307 | if (pbs.ProfileHollow != 0) | ||
308 | return true; | ||
309 | |||
310 | if ((pbs.ProfileBegin != 0) || pbs.ProfileEnd != 0) | ||
311 | return true; | ||
312 | |||
313 | return false; | ||
314 | } | ||
301 | 315 | ||
302 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, | 316 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, |
303 | PhysicsVector size, Quaternion rotation) //To be removed | 317 | PhysicsVector size, Quaternion rotation) //To be removed |
304 | { | 318 | { |
305 | return this.AddPrimShape(primName, pbs, position, size, rotation, false); | 319 | return this.AddPrimShape(primName, pbs, position, size, rotation, false); |
306 | } | 320 | } |
321 | |||
307 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, | 322 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, |
308 | PhysicsVector size, Quaternion rotation, bool isPhysical) | 323 | PhysicsVector size, Quaternion rotation, bool isPhysical) |
309 | { | 324 | { |
310 | PhysicsActor result; | 325 | PhysicsActor result; |
326 | Mesh mesh = null; | ||
311 | 327 | ||
312 | switch (pbs.ProfileShape) | 328 | switch (pbs.ProfileShape) |
313 | { | 329 | { |
314 | case ProfileShape.Square: | 330 | case ProfileShape.Square: |
315 | /// support simple box & hollow box now; later, more shapes | 331 | /// support simple box & hollow box now; later, more shapes |
316 | if (pbs.ProfileHollow == 0) | 332 | if (needsMeshing(pbs)) |
317 | { | ||
318 | result = AddPrim(primName, position, size, rotation, null, null); | ||
319 | } | ||
320 | else | ||
321 | { | 333 | { |
322 | Mesh mesh = Meshmerizer.CreateMesh(pbs, size); | 334 | mesh = Meshmerizer.CreateMesh(primName, pbs, size); |
323 | result = AddPrim(primName, position, size, rotation, mesh, pbs); | ||
324 | } | 335 | } |
325 | break; | 336 | |
326 | |||
327 | default: | ||
328 | result = AddPrim(primName, position, size, rotation, null, null); | ||
329 | break; | 337 | break; |
330 | } | 338 | } |
339 | |||
340 | result = AddPrim(primName, position, size, rotation, mesh, pbs); | ||
341 | |||
331 | 342 | ||
332 | return result; | 343 | return result; |
333 | } | 344 | } |
334 | 345 | ||
335 | |||
336 | public override void Simulate(float timeStep) | 346 | public override void Simulate(float timeStep) |
337 | { | 347 | { |
338 | step_time += timeStep; | 348 | step_time += timeStep; |
@@ -551,6 +561,13 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
551 | set { } | 561 | set { } |
552 | } | 562 | } |
553 | 563 | ||
564 | public override PrimitiveBaseShape Shape | ||
565 | { | ||
566 | set | ||
567 | { | ||
568 | return; | ||
569 | } | ||
570 | } | ||
554 | 571 | ||
555 | public override PhysicsVector Velocity | 572 | public override PhysicsVector Velocity |
556 | { | 573 | { |
@@ -753,6 +770,12 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
753 | } | 770 | } |
754 | } | 771 | } |
755 | 772 | ||
773 | public override bool IsPhysical | ||
774 | { | ||
775 | get { return false; } | ||
776 | set { return; } | ||
777 | } | ||
778 | |||
756 | public void setMesh(OdeScene parent_scene, Mesh mesh) | 779 | public void setMesh(OdeScene parent_scene, Mesh mesh) |
757 | { | 780 | { |
758 | float[] vertexList = mesh.getVertexListAsFloat(); // Note, that vertextList is pinned in memory | 781 | float[] vertexList = mesh.getVertexListAsFloat(); // Note, that vertextList is pinned in memory |
@@ -769,12 +792,6 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
769 | prim_geom = d.CreateTriMesh(parent_scene.space, _triMeshData, parent_scene.triCallback, null, null); | 792 | prim_geom = d.CreateTriMesh(parent_scene.space, _triMeshData, parent_scene.triCallback, null, null); |
770 | } | 793 | } |
771 | 794 | ||
772 | public override bool IsPhysical | ||
773 | { | ||
774 | get { return false; } | ||
775 | set { return; } | ||
776 | } | ||
777 | |||
778 | public override bool Flying | 795 | public override bool Flying |
779 | { | 796 | { |
780 | get { return false; //no flying prims for you | 797 | get { return false; //no flying prims for you |
@@ -810,18 +827,70 @@ namespace OpenSim.Region.Physics.OdePlugin | |||
810 | _size = value; | 827 | _size = value; |
811 | lock (OdeScene.OdeLock) | 828 | lock (OdeScene.OdeLock) |
812 | { | 829 | { |
813 | if (_mesh != null) // We deal with a mesh here | 830 | string oldname = _parent_scene.geom_name_map[prim_geom]; |
831 | |||
832 | // Cleanup of old prim geometry | ||
833 | d.GeomDestroy(prim_geom); | ||
834 | if (_mesh != null) | ||
814 | { | 835 | { |
815 | string oldname = _parent_scene.geom_name_map[prim_geom]; | 836 | // Cleanup meshing here |
816 | d.GeomDestroy(prim_geom); | 837 | } |
817 | Mesh mesh = Meshmerizer.CreateMesh(_pbs, _size); | 838 | |
839 | // Construction of new prim | ||
840 | if (this._parent_scene.needsMeshing(_pbs)) | ||
841 | { | ||
842 | Mesh mesh = Meshmerizer.CreateMesh(oldname, _pbs, _size); | ||
818 | setMesh(_parent_scene, mesh); | 843 | setMesh(_parent_scene, mesh); |
819 | _parent_scene.geom_name_map[prim_geom] = oldname; | 844 | } else { |
845 | prim_geom = d.CreateBox(_parent_scene.space, _size.X, _size.Y, _size.Z); | ||
846 | } | ||
847 | _parent_scene.geom_name_map[prim_geom] = oldname; | ||
848 | |||
849 | d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); | ||
850 | d.Quaternion myrot = new d.Quaternion(); | ||
851 | myrot.W = _orientation.w; | ||
852 | myrot.X = _orientation.x; | ||
853 | myrot.Y = _orientation.y; | ||
854 | myrot.Z = _orientation.z; | ||
855 | d.GeomSetQuaternion(prim_geom, ref myrot); | ||
856 | } | ||
857 | } | ||
858 | } | ||
859 | |||
860 | public override PrimitiveBaseShape Shape | ||
861 | { | ||
862 | set | ||
863 | { | ||
864 | _pbs = value; | ||
865 | lock (OdeScene.OdeLock) | ||
866 | { | ||
867 | string oldname = _parent_scene.geom_name_map[prim_geom]; | ||
868 | |||
869 | // Cleanup of old prim geometry | ||
870 | d.GeomDestroy(prim_geom); | ||
871 | if (_mesh != null) | ||
872 | { | ||
873 | // Cleanup meshing here | ||
820 | } | 874 | } |
821 | else | 875 | |
876 | // Construction of new prim | ||
877 | if (this._parent_scene.needsMeshing(_pbs)) | ||
822 | { | 878 | { |
823 | d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z); | 879 | Mesh mesh = Meshmerizer.CreateMesh(oldname, _pbs, _size); |
880 | setMesh(_parent_scene, mesh); | ||
881 | } else { | ||
882 | prim_geom = d.CreateBox(_parent_scene.space, _size.X, _size.Y, _size.Z); | ||
824 | } | 883 | } |
884 | _parent_scene.geom_name_map[prim_geom] = oldname; | ||
885 | |||
886 | d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); | ||
887 | d.Quaternion myrot = new d.Quaternion(); | ||
888 | myrot.W = _orientation.w; | ||
889 | myrot.X = _orientation.x; | ||
890 | myrot.Y = _orientation.y; | ||
891 | myrot.Z = _orientation.z; | ||
892 | d.GeomSetQuaternion(prim_geom, ref myrot); | ||
893 | |||
825 | } | 894 | } |
826 | } | 895 | } |
827 | } | 896 | } |