29 using System.Collections.Generic;
32 using OpenSim.Framework;
33 using OpenSim.Region.PhysicsModules.SharedBase;
34 using OpenSim.Region.PhysicsModule.Meshing;
35 using OpenSim.Region.PhysicsModules.ConvexDecompositionDotNet;
37 using OMV = OpenMetaverse;
39 namespace OpenSim.
Region.PhysicsModule.BulletS
47 public int Vertices {
get; set; }
48 private int m_hullCount;
49 private int[] m_verticesPerHull;
54 m_verticesPerHull = null;
61 m_verticesPerHull =
new int[m_hullCount];
62 Array.Clear(m_verticesPerHull, 0, m_hullCount);
64 get {
return m_hullCount; }
68 if (m_verticesPerHull != null && hullNum < m_verticesPerHull.Length)
70 m_verticesPerHull[hullNum] = vertices;
75 if (m_verticesPerHull != null && hullNum < m_verticesPerHull.Length)
77 return m_verticesPerHull[hullNum];
83 StringBuilder buff =
new StringBuilder();
88 buff.Append(
"verts=");
89 buff.Append(Vertices.ToString());
92 if (Vertices > 0 && HullCount > 0) buff.Append(
",");
96 buff.Append(
"nHulls=");
97 buff.Append(HullCount.ToString());
99 buff.Append(
"hullVerts=");
100 for (
int ii = 0; ii < HullCount; ii++)
102 if (ii != 0) buff.Append(
",");
103 buff.Append(GetVerticesPerHull(ii).ToString());
107 return buff.ToString();
113 private static string LogHeader =
"[BULLETSIM SHAPE]";
115 public int referenceCount {
get; set; }
116 public DateTime lastReferenced {
get; set; }
123 lastReferenced = DateTime.Now;
130 lastReferenced = DateTime.Now;
131 physShapeInfo = pShape;
144 lastReferenced = DateTime.Now;
151 lastReferenced = DateTime.Now;
155 public abstract void Dereference(
BSScene physicsScene);
158 public virtual bool HasPhysicalShape
162 if (physShapeInfo != null)
163 return physShapeInfo.HasPhysicalShape;
172 if (physShapeInfo != null && physShapeInfo.HasPhysicalShape)
173 ret = physShapeInfo.shapeType;
179 public virtual string AddrString
183 if (physShapeInfo != null)
184 return physShapeInfo.AddrString;
191 StringBuilder buff =
new StringBuilder();
192 if (physShapeInfo == null)
194 buff.Append(
"<noPhys");
198 buff.Append(
"<phy=");
199 buff.Append(physShapeInfo.ToString());
202 buff.Append(referenceCount.ToString());
204 return buff.ToString();
207 #region Common shape routines
212 float lod = BSParam.MeshLOD;
214 lod = BSParam.SculptLOD;
217 float maxAxis = Math.Max(size.X, Math.Max(size.Y, size.Z));
218 if (maxAxis > BSParam.MeshMegaPrimThreshold)
219 lod = BSParam.MeshMegaPrimLOD;
222 return pbs.GetMeshKey(size, lod);
243 prim.PrimAssetState = BSPhysObject.PrimAssetCondition.FailedMeshing;
244 physicsScene.Logger.WarnFormat(
"{0} Fetched asset would not mesh. prim={1}, texture={2}",
245 LogHeader, UsefulPrimInfo(physicsScene, prim), prim.BaseShape.SculptTexture);
246 physicsScene.DetailLog(
"{0},BSShape.VerifyMeshCreated,setFailed,prim={1},tex={2}",
247 prim.LocalID, UsefulPrimInfo(physicsScene, prim), prim.BaseShape.SculptTexture);
254 && prim.PrimAssetState != BSPhysObject.PrimAssetCondition.Waiting
255 && prim.BaseShape.SculptTexture != OMV.UUID.Zero
258 physicsScene.DetailLog(
"{0},BSShape.VerifyMeshCreated,fetchAsset,objNam={1},tex={2}",
259 prim.LocalID, prim.PhysObjectName, prim.BaseShape.SculptTexture);
261 prim.PrimAssetState = BSPhysObject.PrimAssetCondition.Waiting;
265 if (assetProvider != null)
271 bool assetFound =
false;
272 string mismatchIDs = String.Empty;
277 yprim.BaseShape.SculptData = asset.Data;
281 yprim.PrimAssetState = BSPhysObject.PrimAssetCondition.Fetched;
282 yprim.ForceBodyShapeRebuild(
false );
287 mismatchIDs = yprim.BaseShape.SculptTexture.ToString() +
"/" + asset.
ID;
292 yprim.PrimAssetState = BSPhysObject.PrimAssetCondition.FailedAssetFetch;
294 physicsScene.DetailLog(
"{0},BSShape.VerifyMeshCreated,fetchAssetCallback,found={1},isSculpt={2},ids={3}",
295 yprim.LocalID, assetFound, yprim.BaseShape.SculptEntry, mismatchIDs );
300 xprim.PrimAssetState = BSPhysObject.PrimAssetCondition.FailedAssetFetch;
301 physicsScene.Logger.ErrorFormat(
"{0} Physical object requires asset but no asset provider. Name={1}",
302 LogHeader, physicsScene.PhysicsSceneName);
309 physicsScene.Logger.WarnFormat(
"{0} Mesh failed to fetch asset. prim={1}, texture={2}",
310 LogHeader, UsefulPrimInfo(physicsScene, prim), prim.BaseShape.SculptTexture);
311 physicsScene.DetailLog(
"{0},BSShape.VerifyMeshCreated,wasFailed,prim={1},tex={2}",
312 prim.LocalID, UsefulPrimInfo(physicsScene, prim), prim.BaseShape.SculptTexture);
316 physicsScene.Logger.WarnFormat(
"{0} Mesh asset would not mesh. prim={1}, texture={2}",
317 LogHeader, UsefulPrimInfo(physicsScene, prim), prim.BaseShape.SculptTexture);
318 physicsScene.DetailLog(
"{0},BSShape.VerifyMeshCreated,wasFailedMeshing,prim={1},tex={2}",
319 prim.LocalID, UsefulPrimInfo(physicsScene, prim), prim.BaseShape.SculptTexture);
325 BSShape fillShape = BSShapeNative.GetReference(physicsScene,
prim, BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_BOX);
326 physicsScene.DetailLog(
"{0},BSShape.VerifyMeshCreated,boxTempShape", prim.LocalID);
328 return fillShape.physShapeInfo;
334 buff.Append(
"/pos=");
335 buff.Append(prim.RawPosition.ToString());
338 buff.Append(
"/rgn=");
339 buff.Append(pScene.PhysicsSceneName);
341 return buff.ToString();
344 #endregion // Common shape routines
364 private static string LogHeader =
"[BULLETSIM SHAPE NATIVE]";
373 return new BSShapeNative(CreatePhysicalNativeShape(physicsScene, prim, shapeType, shapeKey));
382 ret =
new BSShapeNative(CreatePhysicalNativeShape(pPhysicsScene, pPrim,
383 physShapeInfo.shapeType, (
FixedShapeKey)physShapeInfo.shapeKey));
394 if (physShapeInfo.HasPhysicalShape)
396 physicsScene.DetailLog(
"{0},BSShapeNative.Dereference,deleteNativeShape,shape={1}", BSScene.DetailLogZero,
this);
397 physicsScene.PE.DeleteCollisionShape(physicsScene.World, physShapeInfo);
399 physShapeInfo.Clear();
410 nativeShapeData.Type = shapeType;
411 nativeShapeData.ID = prim.LocalID;
412 nativeShapeData.Scale = prim.Scale;
413 nativeShapeData.Size = prim.Scale;
414 nativeShapeData.MeshKey = (ulong)shapeKey;
415 nativeShapeData.HullKey = (ulong)shapeKey;
419 newShape = physicsScene.PE.BuildCapsuleShape(physicsScene.World, 1f, 1f, prim.Scale);
420 physicsScene.DetailLog(
"{0},BSShapeNative,capsule,scale={1}", prim.LocalID, prim.Scale);
424 newShape = physicsScene.PE.BuildNativeShape(physicsScene.World, nativeShapeData);
428 physicsScene.Logger.ErrorFormat(
"{0} BuildPhysicalNativeShape failed. ID={1}, shape={2}",
429 LogHeader, prim.LocalID, shapeType);
431 newShape.shapeType = shapeType;
432 newShape.isNativeShape =
true;
433 newShape.shapeKey = (UInt64)shapeKey;
443 private static string LogHeader =
"[BULLETSIM SHAPE MESH]";
452 System.UInt64 newMeshKey = BSShape.ComputeShapeKey(prim.Size, prim.BaseShape, out lod);
457 if (Meshes.TryGetValue(newMeshKey, out retMesh))
460 retMesh.IncrementReference();
466 BulletShape newShape = retMesh.CreatePhysicalMesh(physicsScene, prim, newMeshKey, prim.BaseShape, prim.Size, lod);
469 newShape = VerifyMeshCreated(physicsScene, newShape, prim);
470 if (!newShape.isNativeShape || prim.AssetFailed() )
474 Meshes.Add(newMeshKey, retMesh);
477 retMesh.physShapeInfo = newShape;
480 physicsScene.DetailLog(
"{0},BSShapeMesh,getReference,mesh={1},size={2},lod={3}", prim.LocalID, retMesh, prim.Size, lod);
488 if (physShapeInfo.HasPhysicalShape && physShapeInfo.isNativeShape)
491 ret = BSShapeNative.GetReference(pPhysicsScene, pPrim, BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_BOX);
496 IncrementReference();
505 this.DecrementReference();
506 physicsScene.DetailLog(
"{0},BSShapeMesh.Dereference,shape={1}", BSScene.DetailLogZero,
this);
532 public delegate
BulletShape CreateShapeCall(
BulletWorld world,
int indicesCount,
int[] indices,
int verticesCount,
float[] vertices );
536 return BSShapeMesh.CreatePhysicalMeshShape(physicsScene, prim, newMeshKey, pbs, size, lod,
539 shapeInfo.Vertices = vC;
540 return physicsScene.PE.CreateMeshShape(w, iC, i, vC, v);
553 IMesh meshData = null;
554 lock (physicsScene.
mesher)
556 meshData = physicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod,
564 if (meshData != null)
569 pbs.SculptData =
new byte[0];
570 prim.PrimAssetState = BSPhysObject.PrimAssetCondition.Unknown;
573 int[] indices = meshData.getIndexListAsInt();
574 int realIndicesIndex = indices.Length;
575 float[] verticesAsFloats = meshData.getVertexListAsFloat();
577 if (BSParam.ShouldRemoveZeroWidthTriangles)
582 realIndicesIndex = 0;
583 for (
int tri = 0; tri < indices.Length; tri += 3)
586 int v1 = indices[tri + 0] * 3;
587 int v2 = indices[tri + 1] * 3;
588 int v3 = indices[tri + 2] * 3;
590 if (!( ( verticesAsFloats[v1 + 0] == verticesAsFloats[v2 + 0]
591 && verticesAsFloats[v1 + 1] == verticesAsFloats[v2 + 1]
592 && verticesAsFloats[v1 + 2] == verticesAsFloats[v2 + 2])
593 || ( verticesAsFloats[v2 + 0] == verticesAsFloats[v3 + 0]
594 && verticesAsFloats[v2 + 1] == verticesAsFloats[v3 + 1]
595 && verticesAsFloats[v2 + 2] == verticesAsFloats[v3 + 2])
596 || ( verticesAsFloats[v1 + 0] == verticesAsFloats[v3 + 0]
597 && verticesAsFloats[v1 + 1] == verticesAsFloats[v3 + 1]
598 && verticesAsFloats[v1 + 2] == verticesAsFloats[v3 + 2]) )
602 indices[realIndicesIndex + 0] = indices[tri + 0];
603 indices[realIndicesIndex + 1] = indices[tri + 1];
604 indices[realIndicesIndex + 2] = indices[tri + 2];
605 realIndicesIndex += 3;
609 physicsScene.DetailLog(
"{0},BSShapeMesh.CreatePhysicalMesh,key={1},origTri={2},realTri={3},numVerts={4}",
610 BSScene.DetailLogZero, newMeshKey.ToString(
"X"), indices.Length / 3, realIndicesIndex / 3, verticesAsFloats.Length / 3);
612 if (realIndicesIndex != 0)
614 newShape = makeShape(physicsScene.
World, realIndicesIndex, indices, verticesAsFloats.Length / 3, verticesAsFloats);
619 prim.PrimAssetState = BSPhysObject.PrimAssetCondition.FailedMeshing;
620 physicsScene.Logger.DebugFormat(
"{0} All mesh triangles degenerate. Prim={1}", LogHeader, UsefulPrimInfo(physicsScene, prim) );
621 physicsScene.DetailLog(
"{0},BSShapeMesh.CreatePhysicalMesh,allDegenerate,key={1}", prim.LocalID, newMeshKey);
624 newShape.shapeKey = newMeshKey;
636 #pragma warning disable 414
637 private static string LogHeader =
"[BULLETSIM SHAPE HULL]";
638 #pragma warning restore 414
649 System.UInt64 newHullKey = BSShape.ComputeShapeKey(prim.Size, prim.BaseShape, out lod);
654 if (Hulls.TryGetValue(newHullKey, out retHull))
657 retHull.IncrementReference();
663 BulletShape newShape = retHull.CreatePhysicalHull(physicsScene, prim, newHullKey, prim.BaseShape, prim.Size, lod);
666 newShape = VerifyMeshCreated(physicsScene, newShape, prim);
667 if (!newShape.isNativeShape || prim.AssetFailed())
670 Hulls.Add(newHullKey, retHull);
672 retHull.physShapeInfo = newShape;
675 physicsScene.DetailLog(
"{0},BSShapeHull,getReference,hull={1},size={2},lod={3}", prim.LocalID, retHull, prim.Size, lod);
683 if (physShapeInfo.HasPhysicalShape && physShapeInfo.isNativeShape)
686 ret = BSShapeNative.GetReference(pPhysicsScene, pPrim, BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_BOX);
691 IncrementReference();
700 this.DecrementReference();
701 physicsScene.DetailLog(
"{0},BSShapeHull.Dereference,shape={1}", BSScene.DetailLogZero,
this);
706 List<ConvexResult> m_hulls;
712 IMesh meshData = null;
713 List<List<OMV.Vector3>> allHulls = null;
714 lock (physicsScene.
mesher)
717 meshData = physicsScene.mesher.CreateMesh(prim.PhysObjectName, pbs, size, lod,
true ,
false ,
false,
false);
720 if (meshData != null && BSParam.ShouldUseAssetHulls)
723 if (realMesher != null)
725 allHulls = realMesher.GetConvexHulls(size);
727 if (allHulls == null)
729 physicsScene.DetailLog(
"{0},BSShapeHull.CreatePhysicalHull,assetHulls,noAssetHull", prim.LocalID);
735 if (allHulls != null && BSParam.ShouldUseAssetHulls)
737 int hullCount = allHulls.Count;
738 shapeInfo.HullCount = hullCount;
739 int totalVertices = 1;
742 foreach (List<OMV.Vector3> hullVerts
in allHulls)
745 totalVertices += hullVerts.Count * 3;
747 float[] convHulls =
new float[totalVertices];
749 convHulls[0] = (float)hullCount;
752 foreach (List<OMV.Vector3> hullVerts
in allHulls)
754 convHulls[jj + 0] = hullVerts.Count;
755 convHulls[jj + 1] = 0f;
756 convHulls[jj + 2] = 0f;
757 convHulls[jj + 3] = 0f;
759 foreach (
OMV.Vector3 oneVert in hullVerts)
761 convHulls[jj + 0] = oneVert.X;
762 convHulls[jj + 1] = oneVert.Y;
763 convHulls[jj + 2] = oneVert.Z;
766 shapeInfo.SetVerticesPerHull(hullIndex, hullVerts.Count);
771 newShape = physicsScene.PE.CreateHullShape(physicsScene.World, hullCount, convHulls);
773 physicsScene.DetailLog(
"{0},BSShapeHull.CreatePhysicalHull,assetHulls,hulls={1},totVert={2},shape={3}",
774 prim.LocalID, hullCount, totalVertices, newShape);
782 physicsScene.DetailLog(
"{0},BSShapeHull.CreatePhysicalHull,bulletHACD,entry", prim.LocalID);
783 BSShape meshShape = BSShapeMesh.GetReference(physicsScene,
true, prim);
785 if (meshShape.physShapeInfo.HasPhysicalShape)
787 HACDParams parms =
new HACDParams();
788 parms.maxVerticesPerHull = BSParam.BHullMaxVerticesPerHull;
789 parms.minClusters = BSParam.BHullMinClusters;
790 parms.compacityWeight = BSParam.BHullCompacityWeight;
791 parms.volumeWeight = BSParam.BHullVolumeWeight;
792 parms.concavity = BSParam.BHullConcavity;
793 parms.addExtraDistPoints = BSParam.NumericBool(BSParam.BHullAddExtraDistPoints);
794 parms.addNeighboursDistPoints = BSParam.NumericBool(BSParam.BHullAddNeighboursDistPoints);
795 parms.addFacesPoints = BSParam.NumericBool(BSParam.BHullAddFacesPoints);
796 parms.shouldAdjustCollisionMargin = BSParam.NumericBool(BSParam.BHullShouldAdjustCollisionMargin);
799 physicsScene.DetailLog(
"{0},BSShapeHull.CreatePhysicalHull,hullFromMesh,beforeCall", prim.LocalID, newShape.HasPhysicalShape);
800 newShape = physicsScene.PE.BuildHullShapeFromMesh(physicsScene.World, meshShape.physShapeInfo, parms);
801 physicsScene.DetailLog(
"{0},BSShapeHull.CreatePhysicalHull,hullFromMesh,shape={1}", prim.LocalID, newShape);
804 shapeInfo.HullCount = 1;
805 BSShapeMesh maybeMesh = meshShape as BSShapeMesh;
806 if (maybeMesh != null)
807 shapeInfo.SetVerticesPerHull(0, maybeMesh.shapeInfo.Vertices);
808 meshShape.Dereference(physicsScene);
810 physicsScene.DetailLog(
"{0},BSShapeHull.CreatePhysicalHull,bulletHACD,exit,hasBody={1}", prim.LocalID, newShape.HasPhysicalShape);
816 if (prim.
PrimAssetState == BSPhysObject.PrimAssetCondition.Fetched)
819 pbs.SculptData =
new byte[0];
820 prim.PrimAssetState = BSPhysObject.PrimAssetCondition.Unknown;
823 int[] indices = meshData.getIndexListAsInt();
824 List<OMV.Vector3> vertices = meshData.getVertexList();
827 List<int> convIndices =
new List<int>();
828 List<float3> convVertices =
new List<float3>();
829 for (
int ii = 0; ii < indices.GetLength(0); ii++)
831 convIndices.Add(indices[ii]);
833 foreach (
OMV.Vector3 vv in vertices)
835 convVertices.Add(
new float3(vv.X, vv.Y, vv.Z));
838 uint maxDepthSplit = (uint)BSParam.CSHullMaxDepthSplit;
839 if (BSParam.CSHullMaxDepthSplit != BSParam.CSHullMaxDepthSplitForSimpleShapes)
844 if (BSShapeCollection.PrimHasNoCuts(pbs))
846 maxDepthSplit = (uint)BSParam.CSHullMaxDepthSplitForSimpleShapes;
851 m_hulls =
new List<ConvexResult>();
853 dcomp.mIndices = convIndices;
854 dcomp.mVertices = convVertices;
855 dcomp.mDepth = maxDepthSplit;
856 dcomp.mCpercent = BSParam.CSHullConcavityThresholdPercent;
857 dcomp.mPpercent = BSParam.CSHullVolumeConservationThresholdPercent;
858 dcomp.mMaxVertices = (uint)BSParam.CSHullMaxVertices;
859 dcomp.mSkinWidth = BSParam.CSHullMaxSkinWidth;
862 convexBuilder.process(dcomp);
864 physicsScene.DetailLog(
"{0},BSShapeCollection.CreatePhysicalHull,key={1},inVert={2},inInd={3},split={4},hulls={5}",
865 BSScene.DetailLogZero, newHullKey, indices.GetLength(0), vertices.Count, maxDepthSplit, m_hulls.Count);
887 int hullCount = m_hulls.Count;
888 int totalVertices = 1;
892 totalVertices += cr.HullIndices.Count * 3;
894 float[] convHulls =
new float[totalVertices];
896 convHulls[0] = (float)hullCount;
909 convHulls[jj++] = cr.HullIndices.Count;
910 convHulls[jj++] = 0f;
911 convHulls[jj++] = 0f;
912 convHulls[jj++] = 0f;
915 convHulls[jj++] = verts[ind].x;
916 convHulls[jj++] = verts[ind].y;
917 convHulls[jj++] = verts[ind].z;
921 newShape = physicsScene.PE.CreateHullShape(physicsScene.World, hullCount, convHulls);
923 newShape.shapeKey = newHullKey;
961 private static string LogHeader =
"[BULLETSIM SHAPE COMPOUND]";
962 public static Dictionary<string, BSShapeCompound> CompoundShapes =
new Dictionary<string, BSShapeCompound>();
972 CompoundShapes.Add(ret.AddrString, ret);
979 IncrementReference();
987 this.DecrementReference();
988 physicsScene.DetailLog(
"{0},BSShapeCompound.Dereference,shape={1}", BSScene.DetailLogZero,
this);
989 if (referenceCount <= 0)
994 physicsScene.Logger.ErrorFormat(
"{0} Attempt to free a compound shape that is not compound!! type={1}, ptr={2}",
995 LogHeader, physShapeInfo.shapeType, physShapeInfo.AddrString);
996 physicsScene.DetailLog(
"{0},BSShapeCollection.DereferenceCompound,notACompoundShape,type={1},ptr={2}",
997 BSScene.DetailLogZero, physShapeInfo.shapeType, physShapeInfo.AddrString);
1001 int numChildren = physicsScene.PE.GetNumberOfCompoundChildren(physShapeInfo);
1002 physicsScene.DetailLog(
"{0},BSShapeCollection.DereferenceCompound,shape={1},children={2}",
1003 BSScene.DetailLogZero, physShapeInfo, numChildren);
1006 for (
int ii = numChildren - 1; ii >= 0; ii--)
1008 BulletShape childShape = physicsScene.PE.RemoveChildShapeFromCompoundShapeIndex(physShapeInfo, ii);
1009 DereferenceAnonCollisionShape(physicsScene, childShape);
1012 lock (CompoundShapes)
1013 CompoundShapes.Remove(physShapeInfo.AddrString);
1014 physicsScene.PE.DeleteCollisionShape(physicsScene.World, physShapeInfo);
1020 lock (CompoundShapes)
1022 string addr = pShape.AddrString;
1023 return CompoundShapes.TryGetValue(addr, out outCompound);
1028 BulletShape cShape = physicsScene.PE.CreateCompoundShape(physicsScene.World,
false);
1034 private void DereferenceAnonCollisionShape(BSScene physicsScene, BulletShape pShape)
1037 physicsScene.DetailLog(
"{0},BSShapeCompound.DereferenceAnonCollisionShape,shape={1}",
1038 BSScene.DetailLogZero, pShape);
1039 BSShapeMesh meshDesc;
1040 if (BSShapeMesh.TryGetMeshByPtr(pShape, out meshDesc))
1042 meshDesc.Dereference(physicsScene);
1047 BSShapeHull hullDesc;
1048 if (BSShapeHull.TryGetHullByPtr(pShape, out hullDesc))
1050 hullDesc.Dereference(physicsScene);
1055 BSShapeConvexHull chullDesc;
1056 if (BSShapeConvexHull.TryGetConvexHullByPtr(pShape, out chullDesc))
1058 chullDesc.Dereference(physicsScene);
1063 BSShapeGImpact gImpactDesc;
1064 if (BSShapeGImpact.TryGetGImpactByPtr(pShape, out gImpactDesc))
1066 gImpactDesc.Dereference(physicsScene);
1072 BSShapeCompound compoundDesc;
1073 if (BSShapeCompound.TryGetCompoundByPtr(pShape, out compoundDesc))
1075 compoundDesc.Dereference(physicsScene);
1081 if (physicsScene.PE.IsNativeShape(pShape))
1084 BSShapeNative nativeShape =
new BSShapeNative(pShape);
1085 nativeShape.Dereference(physicsScene);
1089 physicsScene.Logger.WarnFormat(
"{0} DereferenceAnonCollisionShape. Did not find shape. {1}",
1106 #pragma warning disable 414
1107 private static string LogHeader =
"[BULLETSIM SHAPE CONVEX HULL]";
1108 #pragma warning restore 414
1118 System.UInt64 newMeshKey = BSShape.ComputeShapeKey(prim.Size, prim.BaseShape, out lod);
1120 physicsScene.DetailLog(
"{0},BSShapeConvexHull,getReference,newKey={1},size={2},lod={3}",
1121 prim.LocalID, newMeshKey.ToString(
"X"), prim.
Size, lod);
1126 if (ConvexHulls.TryGetValue(newMeshKey, out retConvexHull))
1129 retConvexHull.IncrementReference();
1137 BSShape baseMesh = BSShapeMesh.GetReference(physicsScene,
false , prim);
1144 convexShape = baseMesh.physShapeInfo;
1148 convexShape = physicsScene.PE.BuildConvexHullShapeFromMesh(physicsScene.World, baseMesh.physShapeInfo);
1149 convexShape.shapeKey = newMeshKey;
1150 ConvexHulls.Add(convexShape.shapeKey, retConvexHull);
1151 physicsScene.DetailLog(
"{0},BSShapeConvexHull.GetReference,addingNewlyCreatedShape,shape={1}",
1152 BSScene.DetailLogZero, convexShape);
1156 baseMesh.Dereference(physicsScene);
1158 retConvexHull.physShapeInfo = convexShape;
1161 return retConvexHull;
1167 IncrementReference();
1175 this.DecrementReference();
1176 physicsScene.DetailLog(
"{0},BSShapeConvexHull.Dereference,shape={1}", BSScene.DetailLogZero,
this);
1198 outHull = foundDesc;
1208 #pragma warning disable 414
1209 private static string LogHeader =
"[BULLETSIM SHAPE GIMPACT]";
1210 #pragma warning restore 414
1220 System.UInt64 newMeshKey = BSShape.ComputeShapeKey(prim.Size, prim.BaseShape, out lod);
1222 physicsScene.DetailLog(
"{0},BSShapeGImpact,getReference,newKey={1},size={2},lod={3}",
1223 prim.LocalID, newMeshKey.ToString(
"X"), prim.
Size, lod);
1228 if (GImpacts.TryGetValue(newMeshKey, out retGImpact))
1231 retGImpact.IncrementReference();
1236 BulletShape newShape = retGImpact.CreatePhysicalGImpact(physicsScene, prim, newMeshKey, prim.BaseShape, prim.Size, lod);
1239 newShape = VerifyMeshCreated(physicsScene, newShape, prim);
1240 newShape.shapeKey = newMeshKey;
1241 if (!newShape.isNativeShape || prim.AssetFailed())
1246 GImpacts.Add(newMeshKey, retGImpact);
1249 retGImpact.physShapeInfo = newShape;
1258 return BSShapeMesh.CreatePhysicalMeshShape(physicsScene, prim, newMeshKey, pbs, size, lod,
1259 (w, iC, i, vC, v) =>
1261 shapeInfo.Vertices = vC;
1262 return physicsScene.PE.CreateGImpactShape(w, iC, i, vC, v);
1271 if (physShapeInfo.HasPhysicalShape && physShapeInfo.isNativeShape)
1274 ret = BSShapeNative.GetReference(pPhysicsScene, pPrim, BSPhysicsShapeType.SHAPE_BOX, FixedShapeKey.KEY_BOX);
1279 IncrementReference();
1289 this.DecrementReference();
1290 physicsScene.DetailLog(
"{0},BSShapeGImpact.Dereference,shape={1}", BSScene.DetailLogZero,
this);
1312 outHull = foundDesc;
1321 #pragma warning disable 414
1322 private static string LogHeader =
"[BULLETSIM SHAPE AVATAR]";
1323 #pragma warning restore 414
1366 private const float Aup = 0.5f;
1367 private const float Bup = 0.4f;
1368 private const float Cup = 0.3f;
1369 private const float Dup = -0.4f;
1370 private const float Eup = -0.5f;
1373 private const float Awid = 0.25f;
1374 private const float Bwid = 0.3f;
1375 private const float Cwid = 0.5f;
1376 private const float Dwid = 0.3f;
1377 private const float Ewid = 0.2f;
1380 private const float Afwid = 0.0f;
1381 private const float Bfwid = 0.2f;
1382 private const float Cfwid = 0.4f;
1383 private const float Dfwid = 0.2f;
1384 private const float Efwid = 0.0f;
1387 private const float Adep = 0f;
1388 private const float Bdep = 0.3f;
1389 private const float Cdep = 0.5f;
1390 private const float Ddep = 0.2f;
1391 private const float Edep = 0f;
1393 private OMV.Vector3[] avatarVertices = {
1394 new OMV.Vector3( 0.0f, -Awid, Aup),
1395 new OMV.Vector3( 0.0f, +Awid, Aup),
1397 new OMV.Vector3( 0.0f, -Bwid, Bup),
1398 new OMV.Vector3(+Bdep, -Bfwid, Bup),
1399 new OMV.Vector3(+Bdep, +Bfwid, Bup),
1400 new OMV.Vector3( 0.0f, +Bwid, Bup),
1401 new OMV.Vector3(-Bdep, +Bfwid, Bup),
1402 new OMV.Vector3(-Bdep, -Bfwid, Bup),
1404 new OMV.Vector3( 0.0f, -Cwid, Cup),
1405 new OMV.Vector3(+Cdep, -Cfwid, Cup),
1406 new OMV.Vector3(+Cdep, +Cfwid, Cup),
1407 new OMV.Vector3( 0.0f, +Cwid, Cup),
1408 new OMV.Vector3(-Cdep, +Cfwid, Cup),
1409 new OMV.Vector3(-Cdep, -Cfwid, Cup),
1411 new OMV.Vector3( 0.0f, -Dwid, Dup),
1412 new OMV.Vector3(+Ddep, -Dfwid, Dup),
1413 new OMV.Vector3(+Ddep, +Dfwid, Dup),
1414 new OMV.Vector3( 0.0f, +Dwid, Dup),
1415 new OMV.Vector3(-Ddep, +Dfwid, Dup),
1416 new OMV.Vector3(-Ddep, -Dfwid, Dup),
1418 new OMV.Vector3( 0.0f, -Ewid, Eup),
1419 new OMV.Vector3( 0.0f, +Ewid, Eup),
1423 private enum Ind :
int
1426 B0, B1, B2, B3, B4, B5,
1427 C0, C1, C2, C3, C4, C5,
1428 D0, D1, D2, D3, D4, D5,
1433 private Ind[] avatarIndices = {
1434 Ind.A0, Ind.B0, Ind.B1,
1435 Ind.A0, Ind.B1, Ind.B2, Ind.B2, Ind.A3, Ind.A0,
1436 Ind.A3, Ind.B2, Ind.B3,
1437 Ind.A3, Ind.B3, Ind.B4,
1438 Ind.A3, Ind.B4, Ind.B5, Ind.B5, Ind.A0, Ind.A3,
1439 Ind.A0, Ind.B5, Ind.B0,
1441 Ind.B0, Ind.C0, Ind.C1, Ind.C1, Ind.B1, Ind.B0,
1442 Ind.B1, Ind.C1, Ind.C2, Ind.C2, Ind.B2, Ind.B1,
1443 Ind.B2, Ind.C2, Ind.C3, Ind.C3, Ind.B3, Ind.B2,
1444 Ind.B3, Ind.C3, Ind.C4, Ind.C4, Ind.B4, Ind.B3,
1445 Ind.B4, Ind.C4, Ind.C5, Ind.C5, Ind.B5, Ind.B4,
1446 Ind.B5, Ind.C5, Ind.C0, Ind.C0, Ind.B0, Ind.B5,
1448 Ind.C0, Ind.D0, Ind.D1, Ind.D1, Ind.C1, Ind.C0,
1449 Ind.C1, Ind.D1, Ind.D2, Ind.D2, Ind.C2, Ind.C1,
1450 Ind.C2, Ind.D2, Ind.D3, Ind.D3, Ind.C3, Ind.C2,
1451 Ind.C3, Ind.D3, Ind.D4, Ind.D4, Ind.C4, Ind.C3,
1452 Ind.C4, Ind.D4, Ind.D5, Ind.D5, Ind.C5, Ind.C4,
1453 Ind.C5, Ind.D5, Ind.D0, Ind.D0, Ind.C0, Ind.C5,
1455 Ind.E0, Ind.D0, Ind.D1,
1456 Ind.E0, Ind.D1, Ind.D2, Ind.D2, Ind.E3, Ind.E0,
1457 Ind.E3, Ind.D2, Ind.D3,
1458 Ind.E3, Ind.D3, Ind.D4,
1459 Ind.E3, Ind.D4, Ind.D5, Ind.D5, Ind.E0, Ind.E3,
1460 Ind.E0, Ind.D5, Ind.D0,
static BSShape GetReference(BSScene physicsScene)
static BSShape GetReference(BSScene physicsScene, bool forceRebuild, BSPhysObject prim)
override void Dereference(BSScene physicsScene)
static String UsefulPrimInfo(BSScene pScene, BSPhysObject prim)
override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim)
static bool TryGetConvexHullByPtr(BulletShape pShape, out BSShapeConvexHull outHull)
override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim)
override void Dereference(BSScene physicsScene)
static bool TryGetHullByPtr(BulletShape pShape, out BSShapeHull outHull)
void SetVerticesPerHull(int hullNum, int vertices)
virtual bool HasPhysicalShape
override void Dereference(BSScene physicsScene)
virtual void DecrementReference()
BSShapeConvexHull(BulletShape pShape)
static BSShape GetReference(BSScene physicsScene, bool forceRebuild, BSPhysObject prim)
static BSShape GetReference(BSScene physicsScene, BSPhysObject prim, BSPhysicsShapeType shapeType, FixedShapeKey shapeKey)
BulletShape physShapeInfo
int GetVerticesPerHull(int hullNum)
override string ToString()
BSShapeNative(BulletShape pShape)
Asset class. All Assets are reference by this class or a class derived from this class ...
virtual bool AssetFailed()
abstract bool IsCompound(BulletShape shape)
static BSShape GetReference(BSPhysObject prim)
virtual bool ReferenceSame(BulletShape xx)
override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim)
BSShapeGImpact(BulletShape pShape)
override string ToString()
PrimitiveBaseShape BaseShape
delegate void RequestAssetDelegate(UUID assetID, AssetReceivedDelegate callback)
override void Dereference(BSScene physicsScene)
override BSShape GetReference(BSScene physicsScene, BSPhysObject prim)
static BSShape GetReference()
static BulletShape CreatePhysicalMeshShape(BSScene physicsScene, BSPhysObject prim, System.UInt64 newMeshKey, PrimitiveBaseShape pbs, OMV.Vector3 size, float lod, CreateShapeCall makeShape)
override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim)
BSShapeCompound(BulletShape pShape)
static BSShape GetReference(BSScene physicsScene, bool forceRebuild, BSPhysObject prim)
BSShapeHull(BulletShape pShape)
static BSShape GetReference(BSScene physicsScene, bool forceRebuild, BSPhysObject prim)
override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim)
List< float3 > HullVertices
PrimAssetCondition PrimAssetState
static bool TryGetMeshByPtr(BulletShape pShape, out BSShapeMesh outMesh)
static System.UInt64 ComputeShapeKey(OMV.Vector3 size, PrimitiveBaseShape pbs, out float retLod)
static bool TryGetGImpactByPtr(BulletShape pShape, out BSShapeGImpact outHull)
override void Dereference(BSScene physicsScene)
BSShape(BulletShape pShape)
override BSShape GetReference(BSScene pPhysicsScene, BSPhysObject pPrim)
override void Dereference(BSScene physicsScene)
BSShapeMesh(BulletShape pShape)
virtual void IncrementReference()
string ID
Asset MetaData ID (transferring from UUID to string ID)
static bool TryGetCompoundByPtr(BulletShape pShape, out BSShapeCompound outCompound)
static BulletShape VerifyMeshCreated(BSScene physicsScene, BulletShape newShape, BSPhysObject prim)
override void Dereference(BSScene physicsScene)
override BSShape GetReference(BSScene physicsScene, BSPhysObject prim)
override void Dereference(BSScene physicsScene)