Merge branch 'ubitwork' of ssh://3dhosting.de/var/git/careminster into ubitwork

avinationmerge
ubit 2012-10-07 02:22:28 +02:00
commit 7e1eecdf73
7 changed files with 650 additions and 1070 deletions

View File

@ -4299,8 +4299,8 @@ namespace OpenSim.Region.Framework.Scenes
SceneObjectPart[] parts = m_parts.GetArray();
for (int i = 0; i < parts.Length; i++)
parts[i].CheckSculptAndLoad();
// for (int i = 0; i < parts.Length; i++)
// parts[i].CheckSculptAndLoad();
}
/// <summary>

View File

@ -1095,9 +1095,9 @@ namespace OpenSim.Region.Framework.Scenes
{
actor.Size = m_shape.Scale;
if (Shape.SculptEntry)
CheckSculptAndLoad();
else
// if (Shape.SculptEntry)
// CheckSculptAndLoad();
// else
ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
}
}
@ -1654,8 +1654,8 @@ namespace OpenSim.Region.Framework.Scenes
else
{
PhysActor.PhysicsShapeType = m_physicsShapeType;
if (Shape.SculptEntry)
CheckSculptAndLoad();
// if (Shape.SculptEntry)
// CheckSculptAndLoad();
}
if (ParentGroup != null)
@ -2115,12 +2115,13 @@ namespace OpenSim.Region.Framework.Scenes
if (userExposed)
{
/*
if (dupe.m_shape.SculptEntry && dupe.m_shape.SculptTexture != UUID.Zero)
{
ParentGroup.Scene.AssetService.Get(
dupe.m_shape.SculptTexture.ToString(), dupe, dupe.AssetReceived);
}
*/
bool UsePhysics = ((dupe.Flags & PrimFlags.Physics) != 0);
dupe.DoPhysicsPropertyUpdate(UsePhysics, true);
// dupe.UpdatePhysicsSubscribedEvents(); // not sure...
@ -2142,6 +2143,7 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="id">ID of asset received</param>
/// <param name="sender">Register</param>
/// <param name="asset"></param>
/*
protected void AssetReceived(string id, Object sender, AssetBase asset)
{
if (asset != null)
@ -2151,7 +2153,7 @@ namespace OpenSim.Region.Framework.Scenes
// "[SCENE OBJECT PART]: Part {0} {1} requested mesh/sculpt data for asset id {2} from asset service but received no data",
// Name, UUID, id);
}
*/
/// <summary>
/// Do a physics property update for a NINJA joint.
/// </summary>
@ -2341,9 +2343,9 @@ namespace OpenSim.Region.Framework.Scenes
// If this part is a sculpt then delay the physics update until we've asynchronously loaded the
// mesh data.
if (Shape.SculptEntry)
CheckSculptAndLoad();
else
// if (Shape.SculptEntry)
// CheckSculptAndLoad();
// else
ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
}
}
@ -3125,6 +3127,7 @@ namespace OpenSim.Region.Framework.Scenes
/// Set sculpt and mesh data, and tell the physics engine to process the change.
/// </summary>
/// <param name="texture">The mesh itself.</param>
/*
public void SculptTextureCallback(AssetBase texture)
{
if (m_shape.SculptEntry)
@ -3152,7 +3155,7 @@ namespace OpenSim.Region.Framework.Scenes
}
}
}
*/
/// <summary>
/// Send a full update to the client for the given part
/// </summary>
@ -4377,7 +4380,7 @@ namespace OpenSim.Region.Framework.Scenes
public void UpdateExtraParam(ushort type, bool inUse, byte[] data)
{
m_shape.ReadInUpdateExtraParam(type, inUse, data);
/*
if (type == 0x30)
{
if (m_shape.SculptEntry && m_shape.SculptTexture != UUID.Zero)
@ -4385,7 +4388,7 @@ namespace OpenSim.Region.Framework.Scenes
ParentGroup.Scene.AssetService.Get(m_shape.SculptTexture.ToString(), this, AssetReceived);
}
}
*/
if (ParentGroup != null)
{
ParentGroup.HasGroupChanged = true;
@ -4793,9 +4796,9 @@ namespace OpenSim.Region.Framework.Scenes
}
}
if (Shape.SculptEntry)
CheckSculptAndLoad();
else
// if (Shape.SculptEntry)
// CheckSculptAndLoad();
// else
ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
if (!building)
@ -4898,6 +4901,7 @@ namespace OpenSim.Region.Framework.Scenes
/// <remarks>
/// When the physics engine has finished with it, the sculpt data is discarded to save memory.
/// </remarks>
/*
public void CheckSculptAndLoad()
{
// m_log.DebugFormat("Processing CheckSculptAndLoad for {0} {1}", Name, LocalId);
@ -4925,7 +4929,7 @@ namespace OpenSim.Region.Framework.Scenes
}
}
}
*/
/// <summary>
/// Update the texture entry for this part.
/// </summary>

View File

@ -74,10 +74,6 @@ namespace OpenSim.Region.Physics.Meshing
private const string baseDir = null; //"rawFiles";
#endif
private bool cacheSculptMaps = true;
private bool cacheSculptAlphaMaps = true;
private string decodedSculptMapPath = null;
private bool useMeshiesPhysicsMesh = false;
private float minSizeForComplexMesh = 0.2f; // prims with all dimensions smaller than this will have a bounding box mesh
@ -92,29 +88,9 @@ namespace OpenSim.Region.Physics.Meshing
IConfig start_config = config.Configs["Startup"];
IConfig mesh_config = config.Configs["Mesh"];
decodedSculptMapPath = start_config.GetString("DecodedSculptMapPath","j2kDecodeCache");
cacheSculptMaps = start_config.GetBoolean("CacheSculptMaps", cacheSculptMaps);
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
cacheSculptAlphaMaps = false;
}
else
cacheSculptAlphaMaps = cacheSculptMaps;
if(mesh_config != null)
useMeshiesPhysicsMesh = mesh_config.GetBoolean("UseMeshiesPhysicsMesh", useMeshiesPhysicsMesh);
try
{
if (!Directory.Exists(decodedSculptMapPath))
Directory.CreateDirectory(decodedSculptMapPath);
}
catch (Exception e)
{
m_log.WarnFormat("[SCULPT]: Unable to create {0} directory: ", decodedSculptMapPath, e.Message);
}
}
/// <summary>
@ -444,7 +420,7 @@ namespace OpenSim.Region.Physics.Meshing
// physics_shape is an array of OSDMaps, one for each submesh
if (decodedMeshOsd is OSDArray)
{
// Console.WriteLine("decodedMeshOsd for {0} - {1}", primName, Util.GetFormattedXml(decodedMeshOsd));
// Console.WriteLine("decodedMeshOsd for {0} - {1}", primName, Util.GetFormattedXml(decodedMeshOsd));
decodedMeshOsdArray = (OSDArray)decodedMeshOsd;
foreach (OSD subMeshOsd in decodedMeshOsdArray)
@ -717,29 +693,7 @@ namespace OpenSim.Region.Physics.Meshing
faces = new List<Face>();
PrimMesher.SculptMesh sculptMesh;
Image idata = null;
string decodedSculptFileName = "";
if (cacheSculptMaps && primShape.SculptTexture != UUID.Zero)
{
decodedSculptFileName = System.IO.Path.Combine(decodedSculptMapPath, "smap_" + primShape.SculptTexture.ToString());
try
{
if (File.Exists(decodedSculptFileName))
{
idata = Image.FromFile(decodedSculptFileName);
}
}
catch (Exception e)
{
m_log.Error("[SCULPT]: unable to load cached sculpt map " + decodedSculptFileName + " " + e.Message);
}
//if (idata != null)
// m_log.Debug("[SCULPT]: loaded cached map asset for map ID: " + primShape.SculptTexture.ToString());
}
if (idata == null)
{
if (primShape.SculptData == null || primShape.SculptData.Length == 0)
return false;
@ -748,25 +702,15 @@ namespace OpenSim.Region.Physics.Meshing
OpenMetaverse.Imaging.ManagedImage unusedData;
OpenMetaverse.Imaging.OpenJPEG.DecodeToImage(primShape.SculptData, out unusedData, out idata);
unusedData = null;
if (idata == null)
{
// In some cases it seems that the decode can return a null bitmap without throwing
// an exception
m_log.WarnFormat("[PHYSICS]: OpenJPEG decoded sculpt data for {0} to a null bitmap. Ignoring.", primName);
return false;
}
unusedData = null;
//idata = CSJ2K.J2kImage.FromBytes(primShape.SculptData);
if (cacheSculptMaps && (cacheSculptAlphaMaps || (((ImageFlags)(idata.Flags) & ImageFlags.HasAlpha) ==0)))
// don't cache images with alpha channel in linux since mono can't load them correctly)
{
try { idata.Save(decodedSculptFileName, ImageFormat.MemoryBmp); }
catch (Exception e) { m_log.Error("[SCULPT]: unable to cache sculpt map " + decodedSculptFileName + " " + e.Message); }
}
}
catch (DllNotFoundException)
{
@ -783,7 +727,6 @@ namespace OpenSim.Region.Physics.Meshing
m_log.Error("[PHYSICS]: Unable to generate a Sculpty physics proxy. Sculpty texture decode failed: " + ex.Message);
return false;
}
}
PrimMesher.SculptMesh.SculptType sculptType;
// remove mirror and invert bits
@ -1048,7 +991,6 @@ namespace OpenSim.Region.Physics.Meshing
return ((hash << 5) + hash) + (ulong)(c >> 8);
}
public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod)
{
return CreateMesh(primName, primShape, size, lod, false,false);

View File

@ -172,7 +172,6 @@ namespace OpenSim.Region.Physics.OdePlugin
// force lower density for testing
m_density = 3.0f;
mu = parent_scene.AvatarFriction;
walkDivisor = walk_divisor;

View File

@ -18,26 +18,63 @@ using OpenMetaverse;
namespace OpenSim.Region.Physics.OdePlugin
{
public enum meshWorkerCmnds : byte
{
nop = 0,
addnew,
changefull,
changesize,
changeshapetype,
getmesh,
}
public class ODEPhysRepData
{
public PhysicsActor actor;
public PrimitiveBaseShape pbs;
public IMesh mesh;
public Vector3 size;
public Vector3 OBB;
public Vector3 OBBOffset;
public float volume;
public float physCost;
public float streamCost;
public byte shapetype;
public bool hasOBB;
public bool hasMeshVolume;
public AssetState assetState;
public UUID? assetID;
public meshWorkerCmnds comand;
}
public class ODEMeshWorker
{
private ILog m_log;
private OdeScene m_scene;
private IMesher m_mesher;
public bool meshSculptedPrim = true;
public bool forceSimplePrimMeshing = false;
public float meshSculptLOD = 32;
public float MeshSculptphysicalLOD = 32;
private IntPtr m_workODEspace = IntPtr.Zero;
public ODEMeshWorker(OdeScene pScene, ILog pLog, IMesher pMesher, IntPtr pWorkSpace, IConfig pConfig)
private OpenSim.Framework.BlockingQueue<ODEPhysRepData> createqueue = new OpenSim.Framework.BlockingQueue<ODEPhysRepData>();
private bool m_running;
private Thread m_thread;
public ODEMeshWorker(OdeScene pScene, ILog pLog, IMesher pMesher, IConfig pConfig)
{
m_scene = pScene;
m_log = pLog;
m_mesher = pMesher;
m_workODEspace = pWorkSpace;
if (pConfig != null)
{
@ -46,8 +83,177 @@ namespace OpenSim.Region.Physics.OdePlugin
meshSculptLOD = pConfig.GetFloat("mesh_lod", meshSculptLOD);
MeshSculptphysicalLOD = pConfig.GetFloat("mesh_physical_lod", MeshSculptphysicalLOD);
}
m_running = true;
m_thread = new Thread(DoWork);
m_thread.Start();
}
private void DoWork()
{
while(m_running)
{
ODEPhysRepData nextRep = createqueue.Dequeue();
if(!m_running)
return;
if (nextRep == null)
continue;
if (m_scene.haveActor(nextRep.actor))
{
switch (nextRep.comand)
{
case meshWorkerCmnds.changefull:
case meshWorkerCmnds.changeshapetype:
case meshWorkerCmnds.changesize:
if (CreateActorPhysRep(nextRep) && m_scene.haveActor(nextRep.actor))
m_scene.AddChange(nextRep.actor, changes.PhysRepData, nextRep);
break;
case meshWorkerCmnds.addnew:
if (CreateActorPhysRep(nextRep))
m_scene.AddChange(nextRep.actor, changes.AddPhysRep, nextRep);
break;
case meshWorkerCmnds.getmesh:
DoRepDataGetMesh(nextRep);
break;
}
}
}
}
public void Stop()
{
m_running = false;
m_thread.Abort();
}
public void ChangeActorPhysRep(PhysicsActor actor, PrimitiveBaseShape pbs,
Vector3 size, byte shapetype)
{
ODEPhysRepData repData = new ODEPhysRepData();
repData.actor = actor;
repData.pbs = pbs;
repData.size = size;
repData.shapetype = shapetype;
// if (CheckMeshDone(repData))
{
CheckMeshDone(repData);
CalcVolumeData(repData);
m_scene.AddChange(actor, changes.PhysRepData, repData);
return;
}
// repData.comand = meshWorkerCmnds.changefull;
// createqueue.Enqueue(repData);
}
public void NewActorPhysRep(PhysicsActor actor, PrimitiveBaseShape pbs,
Vector3 size, byte shapetype)
{
ODEPhysRepData repData = new ODEPhysRepData();
repData.actor = actor;
repData.pbs = pbs;
repData.size = size;
repData.shapetype = shapetype;
// bool done = CheckMeshDone(repData);
CheckMeshDone(repData);
CalcVolumeData(repData);
m_scene.AddChange(actor, changes.AddPhysRep, repData);
// if (done)
return;
// repData.comand = meshWorkerCmnds.addnew;
// createqueue.Enqueue(repData);
}
public void RequestMeshAsset(ODEPhysRepData repData)
{
if (repData.assetState != AssetState.needAsset)
return;
if (repData.assetID == null || repData.assetID == UUID.Zero)
return;
repData.mesh = null;
repData.assetState = AssetState.loadingAsset;
repData.comand = meshWorkerCmnds.getmesh;
createqueue.Enqueue(repData);
}
public bool CreateActorPhysRep(ODEPhysRepData repData)
{
getMesh(repData);
IMesh mesh = repData.mesh;
if (mesh != null)
{
IntPtr vertices, indices;
int vertexCount, indexCount;
int vertexStride, triStride;
mesh.getVertexListAsPtrToFloatArray(out vertices, out vertexStride, out vertexCount);
mesh.getIndexListAsPtrToIntArray(out indices, out triStride, out indexCount);
if (vertexCount == 0 || indexCount == 0)
{
m_log.WarnFormat("[PHYSICS]: Invalid mesh data on prim {0} mesh UUID {1}",
repData.actor.Name, repData.pbs.SculptTexture.ToString());
repData.assetState = AssetState.AssetFailed;
repData.hasOBB = false;
repData.mesh = null;
m_scene.mesher.ReleaseMesh(mesh);
}
else
{
repData.OBBOffset = mesh.GetCentroid();
repData.OBB = mesh.GetOBB();
repData.hasOBB = true;
repData.physCost = 0.0013f * (float)indexCount;
// todo
repData.streamCost = 1.0f;
mesh.releaseSourceMeshData();
}
}
CalcVolumeData(repData);
return true;
}
public void AssetLoaded(ODEPhysRepData repData)
{
if (m_scene.haveActor(repData.actor))
{
if (needsMeshing(repData.pbs)) // no need for pbs now?
{
repData.comand = meshWorkerCmnds.changefull;
createqueue.Enqueue(repData);
}
}
}
public void DoRepDataGetMesh(ODEPhysRepData repData)
{
if (!repData.pbs.SculptEntry)
return;
if (repData.assetState != AssetState.loadingAsset)
return;
if (repData.assetID == null || repData.assetID == UUID.Zero)
return;
if (repData.assetID != repData.pbs.SculptTexture)
return;
RequestAssetDelegate assetProvider = m_scene.RequestAssetMethod;
if (assetProvider == null)
return;
ODEAssetRequest asr = new ODEAssetRequest(this, assetProvider, repData, m_log);
}
/// <summary>
/// Routine to figure out if we need to mesh this prim with our mesher
/// </summary>
@ -169,194 +375,151 @@ namespace OpenSim.Region.Physics.OdePlugin
return true;
}
public IMesh getMesh(PhysicsActor actor, PrimitiveBaseShape ppbs, Vector3 psize, byte pshapetype)
public bool CheckMeshDone(ODEPhysRepData repData)
{
if (!(actor is OdePrim))
return null;
PhysicsActor actor = repData.actor;
PrimitiveBaseShape pbs = repData.pbs;
repData.mesh = null;
repData.hasOBB = false;
if (!needsMeshing(pbs))
{
repData.assetState = AssetState.noNeedAsset;
return true;
}
if (pbs.SculptEntry)
{
if (repData.assetState == AssetState.AssetFailed)
{
if (pbs.SculptTexture == repData.assetID)
return true;
}
}
else
{
repData.assetState = AssetState.noNeedAsset;
repData.assetID = null;
}
IMesh mesh = null;
PrimitiveBaseShape pbs = ppbs;
Vector3 size = psize;
byte shapetype = pshapetype;
if (needsMeshing(pbs))
Vector3 size = repData.size;
byte shapetype = repData.shapetype;
bool convex;
int clod = (int)LevelOfDetail.High;
if (shapetype == 0)
convex = false;
else
{
bool convex;
int clod = (int)LevelOfDetail.High;
if (shapetype == 0)
convex = false;
else
convex = true;
if (pbs.SculptType != (byte)SculptType.Mesh)
clod = (int)LevelOfDetail.Low;
}
mesh = m_mesher.GetMesh(actor.Name, pbs, size, clod, true, convex);
if (mesh == null)
{
if (pbs.SculptEntry)
{
convex = true;
if (pbs.SculptType != (byte)SculptType.Mesh)
clod = (int)LevelOfDetail.Low;
}
mesh = m_mesher.GetMesh(actor.Name, pbs, size, clod, true, convex);
if (mesh == null)
{
if (!pbs.SculptEntry)
return m_mesher.CreateMesh(actor.Name, pbs, size, clod, true, convex);
if (pbs.SculptTexture == UUID.Zero)
return null;
if (pbs.SculptType != (byte)SculptType.Mesh)
{ // check for sculpt decoded image on cache)
if (File.Exists(System.IO.Path.Combine("j2kDecodeCache", "smap_" + pbs.SculptTexture.ToString())))
return m_mesher.CreateMesh(actor.Name, pbs, size, clod, true, convex);
if (pbs.SculptTexture != null && pbs.SculptTexture != UUID.Zero)
{
repData.assetID = pbs.SculptTexture;
repData.assetState = AssetState.needAsset;
}
if (pbs.SculptData != null && pbs.SculptData.Length > 0)
return m_mesher.CreateMesh(actor.Name, pbs, size, clod, true, convex);
ODEAssetRequest asr;
RequestAssetDelegate assetProvider = m_scene.RequestAssetMethod;
if (assetProvider != null)
asr = new ODEAssetRequest(this, assetProvider, actor, pbs, m_log);
return null;
else
repData.assetState = AssetState.AssetFailed;
}
}
return mesh;
}
private bool GetTriMeshGeo(ODEPhysRepData repData)
{
IntPtr vertices, indices;
IntPtr triMeshData = IntPtr.Zero;
IntPtr geo = IntPtr.Zero;
int vertexCount, indexCount;
int vertexStride, triStride;
PhysicsActor actor = repData.actor;
IMesh mesh = repData.mesh;
if (mesh == null)
{
mesh = getMesh(repData.actor, repData.pbs, repData.size, repData.shapetype);
}
if (mesh == null)
return false;
mesh.getVertexListAsPtrToFloatArray(out vertices, out vertexStride, out vertexCount); // Note, that vertices are fixed in unmanaged heap
mesh.getIndexListAsPtrToIntArray(out indices, out triStride, out indexCount); // Also fixed, needs release after usage
if (vertexCount == 0 || indexCount == 0)
{
m_log.WarnFormat("[PHYSICS]: Invalid mesh data on prim {0} mesh UUID {1}",
actor.Name, repData.pbs.SculptTexture.ToString());
mesh.releaseSourceMeshData();
return false;
}
repData.OBBOffset = mesh.GetCentroid();
repData.OBB = mesh.GetOBB();
repData.hasOBB = true;
repData.physCost = 0.0013f * (float)indexCount;
mesh.releaseSourceMeshData();
try
repData.mesh = mesh;
if (pbs.SculptEntry)
{
triMeshData = d.GeomTriMeshDataCreate();
d.GeomTriMeshDataBuildSimple(triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride);
d.GeomTriMeshDataPreprocess(triMeshData);
m_scene.waitForSpaceUnlock(m_workODEspace);
geo = d.CreateTriMesh(m_workODEspace, triMeshData, null, null, null);
repData.assetState = AssetState.AssetOK;
repData.assetID = pbs.SculptTexture;
pbs.SculptData = Utils.EmptyBytes;
}
catch (Exception e)
{
m_log.ErrorFormat("[PHYSICS]: SetGeom Mesh failed for {0} exception: {1}", actor.Name, e);
if (triMeshData != IntPtr.Zero)
{
d.GeomTriMeshDataDestroy(triMeshData);
repData.triMeshData = IntPtr.Zero;
}
repData.geo = IntPtr.Zero;
return false;
}
repData.geo = geo;
repData.triMeshData = triMeshData;
repData.curSpace = m_workODEspace;
return true;
}
public ODEPhysRepData CreateActorPhysRep(PhysicsActor actor, PrimitiveBaseShape pbs, IMesh pMesh, Vector3 size, byte shapetype)
public bool getMesh(ODEPhysRepData repData)
{
ODEPhysRepData repData = new ODEPhysRepData();
PhysicsActor actor = repData.actor;
repData.actor = actor;
repData.pbs = pbs;
repData.mesh = pMesh;
repData.size = size;
repData.shapetype = shapetype;
PrimitiveBaseShape pbs = repData.pbs;
IntPtr geo = IntPtr.Zero;
bool hasMesh = false;
if (needsMeshing(pbs))
repData.mesh = null;
repData.hasOBB = false;
if (!needsMeshing(pbs))
return false;
if (pbs.SculptEntry)
{
if (GetTriMeshGeo(repData))
hasMesh = true;
else
repData.NoColide = true;
if (repData.assetState == AssetState.AssetFailed)
{
if (pbs.SculptTexture == repData.assetID)
return true;
}
}
if (!hasMesh)
repData.assetState = AssetState.noNeedAsset;
IMesh mesh = null;
Vector3 size = repData.size;
byte shapetype = repData.shapetype;
bool convex;
int clod = (int)LevelOfDetail.High;
if (shapetype == 0)
convex = false;
else
{
if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1
&& size.X == size.Y && size.Y == size.Z)
{ // it's a sphere
m_scene.waitForSpaceUnlock(m_workODEspace);
try
convex = true;
if (pbs.SculptType != (byte)SculptType.Mesh)
clod = (int)LevelOfDetail.Low;
}
mesh = m_mesher.GetMesh(actor.Name, pbs, size, clod, true, convex);
if (mesh == null)
{
if (pbs.SculptEntry)
{
if (pbs.SculptTexture == UUID.Zero)
return false;
repData.assetID = pbs.SculptTexture;
repData.assetState = AssetState.AssetOK;
if (pbs.SculptData == null || pbs.SculptData.Length == 0)
{
geo = d.CreateSphere(m_workODEspace, size.X * 0.5f);
}
catch (Exception e)
{
m_log.WarnFormat("[PHYSICS]: Create sphere failed: {0}", e);
return null;
}
}
else
{// do it as a box
m_scene.waitForSpaceUnlock(m_workODEspace);
try
{
//Console.WriteLine(" CreateGeom 4");
geo = d.CreateBox(m_workODEspace, size.X, size.Y, size.Z);
}
catch (Exception e)
{
m_log.Warn("[PHYSICS]: Create box failed: {0}", e);
return null;
repData.assetState = AssetState.needAsset;
return false;
}
}
repData.physCost = 0.1f;
repData.streamCost = 1.0f;
repData.geo = geo;
mesh = m_mesher.CreateMesh(actor.Name, pbs, size, clod, true, convex);
}
repData.curSpace = m_workODEspace;
CalcVolumeData(repData);
repData.mesh = mesh;
repData.pbs.SculptData = Utils.EmptyBytes;
return repData;
}
if (mesh == null)
{
if (pbs.SculptEntry)
repData.assetState = AssetState.AssetFailed;
public void ChangeActorPhysRep(PhysicsActor actor, PrimitiveBaseShape pbs,
Vector3 size, byte shapetype, MeshWorkerChange what)
{
ODEPhysRepData repData = CreateActorPhysRep(actor, pbs, null, size, shapetype);
repData.changed |= what;
if (repData != null && actor != null)
((OdePrim)actor).AddChange(changes.PhysRepData, repData);
return false;
}
if (pbs.SculptEntry)
repData.assetState = AssetState.AssetOK;
return true;
}
private void CalculateBasicPrimVolume(ODEPhysRepData repData)
@ -662,46 +825,12 @@ namespace OpenSim.Region.Physics.OdePlugin
private void CalcVolumeData(ODEPhysRepData repData)
{
float volume;
Vector3 OBB = repData.size;
Vector3 OBBoffset;
IntPtr geo = repData.geo;
if (geo == IntPtr.Zero || repData.triMeshData == IntPtr.Zero)
{
OBB.X *= 0.5f;
OBB.Y *= 0.5f;
OBB.Z *= 0.5f;
repData.OBB = OBB;
repData.OBBOffset = Vector3.Zero;
}
else if (!repData.hasOBB) // should this happen?
{
d.AABB AABB;
d.GeomGetAABB(geo, out AABB); // get the AABB from engine geom
OBB.X = (AABB.MaxX - AABB.MinX) * 0.5f;
OBB.Y = (AABB.MaxY - AABB.MinY) * 0.5f;
OBB.Z = (AABB.MaxZ - AABB.MinZ) * 0.5f;
repData.OBB = OBB;
OBBoffset.X = (AABB.MaxX + AABB.MinX) * 0.5f;
OBBoffset.Y = (AABB.MaxY + AABB.MinY) * 0.5f;
OBBoffset.Z = (AABB.MaxZ + AABB.MinZ) * 0.5f;
repData.OBBOffset = Vector3.Zero;
}
// also its own inertia and mass
// keep using basic shape mass for now
CalculateBasicPrimVolume(repData);
if (repData.hasOBB)
{
OBB = repData.OBB;
Vector3 OBB = repData.OBB;
float pc = repData.physCost;
float psf = OBB.X * (OBB.Y + OBB.Z) + OBB.Y * OBB.Z;
psf *= 1.33f * .2f;
pc *= psf;
if (pc < 0.1f)
pc = 0.1f;
@ -709,54 +838,79 @@ namespace OpenSim.Region.Physics.OdePlugin
repData.physCost = pc;
}
else
{
Vector3 OBB = repData.size;
OBB.X *= 0.5f;
OBB.Y *= 0.5f;
OBB.Z *= 0.5f;
repData.OBB = OBB;
repData.OBBOffset = Vector3.Zero;
repData.physCost = 0.1f;
repData.streamCost = 1.0f;
}
CalculateBasicPrimVolume(repData);
}
}
public class ODEAssetRequest
{
PhysicsActor m_actor;
ODEMeshWorker m_worker;
PrimitiveBaseShape m_pbs;
private ILog m_log;
ODEPhysRepData repData;
public ODEAssetRequest(ODEMeshWorker pWorker, RequestAssetDelegate provider,
PhysicsActor pActor, PrimitiveBaseShape ppbs, ILog plog)
ODEPhysRepData pRepData, ILog plog)
{
m_actor = pActor;
m_worker = pWorker;
m_pbs = ppbs;
m_log = plog;
repData = pRepData;
repData.assetState = AssetState.AssetFailed;
if (provider == null)
return;
UUID assetID = m_pbs.SculptTexture;
if (repData.assetID == null)
return;
UUID assetID = (UUID) repData.assetID;
if (assetID == UUID.Zero)
return;
repData.assetState = AssetState.loadingAsset;
provider(assetID, ODEassetReceived);
}
void ODEassetReceived(AssetBase asset)
{
if (m_actor != null && m_pbs != null)
repData.assetState = AssetState.AssetFailed;
if (asset != null)
{
if (asset != null)
if (asset.Data != null && asset.Data.Length > 0)
{
if (asset.Data != null && asset.Data.Length > 0)
{
m_pbs.SculptData = asset.Data;
m_actor.Shape = m_pbs;
}
else
m_log.WarnFormat("[PHYSICS]: asset provider returned invalid mesh data for prim {0} asset UUID {1}.",
m_actor.Name, asset.ID.ToString());
if (!repData.pbs.SculptEntry)
return;
if (repData.pbs.SculptTexture != repData.assetID)
return;
// asset get may return a pointer to the same asset data
// for similar prims and we destroy with it
// so waste a lot of time stressing gc and hoping it clears things
// TODO avoid this
repData.pbs.SculptData = new byte[asset.Data.Length];
asset.Data.CopyTo(repData.pbs.SculptData,0);
repData.assetState = AssetState.AssetOK;
m_worker.AssetLoaded(repData);
}
else
m_log.WarnFormat("[PHYSICS]: asset provider returned null asset fo mesh of prim {0}.",
m_actor.Name);
m_log.WarnFormat("[PHYSICS]: asset provider returned invalid mesh data for prim {0} asset UUID {1}.",
repData.actor.Name, asset.ID.ToString());
}
else
m_log.WarnFormat("[PHYSICS]: asset provider returned null asset fo mesh of prim {0}.",
repData.actor.Name);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -60,29 +60,6 @@ namespace OpenSim.Region.Physics.OdePlugin
public int lastframe;
}
public class ODEPhysRepData
{
public PhysicsActor actor;
public IntPtr geo = IntPtr.Zero;
public IntPtr triMeshData = IntPtr.Zero;
public IMesh mesh;
public IntPtr curSpace = IntPtr.Zero;
public PrimitiveBaseShape pbs;
public Vector3 size = Vector3.Zero;
public Vector3 OBB = Vector3.Zero;
public Vector3 OBBOffset = Vector3.Zero;
public float volume;
public float physCost = 0.0f;
public float streamCost = 0;
public MeshWorkerChange changed;
public byte shapetype = 0;
public bool NoColide = false;
public bool hasOBB = false;
public bool hasMeshVolume = false;
}
// colision flags of things others can colide with
// rays, sensors, probes removed since can't be colided with
@ -133,13 +110,16 @@ namespace OpenSim.Region.Physics.OdePlugin
light = 7 // compatibility with old viewers
}
[Flags]
public enum MeshWorkerChange : uint
public enum AssetState : byte
{
none = 0,
size = 1,
shape = 2,
shapetype = 3,
noNeedAsset = 0,
needAsset = 1,
loadingAsset = 2,
procAsset = 3,
AssetOK = 4,
AssetFailed = 0xff
}
public enum changes : int
@ -180,6 +160,7 @@ namespace OpenSim.Region.Physics.OdePlugin
Size,
Shape,
PhysRepData,
AddPhysRep,
CollidesWater,
VolumeDtc,
@ -330,7 +311,6 @@ namespace OpenSim.Region.Physics.OdePlugin
public IntPtr TopSpace; // the global space
public IntPtr ActiveSpace; // space for active prims
public IntPtr StaticSpace; // space for the static things around
public IntPtr WorkSpace; // no collisions work space
// some speedup variables
private int spaceGridMaxX;
@ -342,7 +322,7 @@ namespace OpenSim.Region.Physics.OdePlugin
private IntPtr[] staticPrimspaceOffRegion;
public Object OdeLock;
private static Object SimulationLock;
public static Object SimulationLock;
public IMesher mesher;
@ -403,7 +383,6 @@ namespace OpenSim.Region.Physics.OdePlugin
// now the major subspaces
ActiveSpace = d.HashSpaceCreate(TopSpace);
StaticSpace = d.HashSpaceCreate(TopSpace);
WorkSpace = d.HashSpaceCreate(TopSpace);
}
catch
{
@ -413,12 +392,10 @@ namespace OpenSim.Region.Physics.OdePlugin
d.HashSpaceSetLevels(TopSpace, -2, 8);
d.HashSpaceSetLevels(ActiveSpace, -2, 8);
d.HashSpaceSetLevels(StaticSpace, -2, 8);
d.HashSpaceSetLevels(WorkSpace, -2, 8);
// demote to second level
d.SpaceSetSublevel(ActiveSpace, 1);
d.SpaceSetSublevel(StaticSpace, 1);
d.SpaceSetSublevel(WorkSpace, 1);
d.GeomSetCategoryBits(ActiveSpace, (uint)(CollisionCategories.Space |
CollisionCategories.Geom |
@ -436,8 +413,6 @@ namespace OpenSim.Region.Physics.OdePlugin
));
d.GeomSetCollideBits(StaticSpace, 0);
d.GeomSetCategoryBits(WorkSpace, 0);
d.GeomSetCollideBits(WorkSpace, 0);
contactgroup = d.JointGroupCreate(0);
//contactgroup
@ -518,7 +493,7 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
m_meshWorker = new ODEMeshWorker(this, m_log, meshmerizer, WorkSpace, physicsconfig);
m_meshWorker = new ODEMeshWorker(this, m_log, meshmerizer, physicsconfig);
HalfOdeStep = ODE_STEPSIZE * 0.5f;
odetimestepMS = (int)(1000.0f * ODE_STEPSIZE +0.5f);
@ -1316,6 +1291,15 @@ namespace OpenSim.Region.Physics.OdePlugin
_collisionEventPrimRemove.Add(obj);
}
public override float TimeDilation
{
get { return m_timeDilation; }
}
public override bool SupportsNINJAJoints
{
get { return false; }
}
#region Add/Remove Entities
@ -1371,59 +1355,6 @@ namespace OpenSim.Region.Physics.OdePlugin
((OdeCharacter) actor).Destroy();
}
private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation,
PrimitiveBaseShape pbs, bool isphysical, uint localID)
{
Vector3 pos = position;
Vector3 siz = size;
Quaternion rot = rotation;
OdePrim newPrim;
lock (OdeLock)
{
newPrim = new OdePrim(name, this, pos, siz, rot, pbs, isphysical,false,0,localID);
lock (_prims)
_prims.Add(newPrim);
}
return newPrim;
}
private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation,
PrimitiveBaseShape pbs, bool isphysical, bool isPhantom, uint localID)
{
Vector3 pos = position;
Vector3 siz = size;
Quaternion rot = rotation;
OdePrim newPrim;
lock (OdeLock)
{
newPrim = new OdePrim(name, this, pos, siz, rot, pbs, isphysical, isPhantom, 0, localID);
lock (_prims)
_prims.Add(newPrim);
}
return newPrim;
}
private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation,
PrimitiveBaseShape pbs, bool isphysical, bool isPhantom, byte shapeType, uint localID)
{
Vector3 pos = position;
Vector3 siz = size;
Quaternion rot = rotation;
OdePrim newPrim;
lock (OdeLock)
{
newPrim = new OdePrim(name, this, pos, siz, rot, pbs, isphysical, isPhantom, shapeType, localID);
lock (_prims)
_prims.Add(newPrim);
}
return newPrim;
}
public void addActivePrim(OdePrim activatePrim)
{
@ -1444,44 +1375,39 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
private PhysicsActor AddPrim(String name, Vector3 position, Vector3 size, Quaternion rotation,
PrimitiveBaseShape pbs, bool isphysical, bool isPhantom, byte shapeType, uint localID)
{
OdePrim newPrim;
lock (OdeLock)
{
newPrim = new OdePrim(name, this, position, size, rotation, pbs, isphysical, isPhantom, shapeType, localID);
lock (_prims)
_prims.Add(newPrim);
}
return newPrim;
}
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, uint localid)
{
return AddPrim(primName, position, size, rotation, pbs, isPhysical, isPhantom, localid);
return AddPrim(primName, position, size, rotation, pbs, isPhysical, isPhantom, 0 , localid);
}
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
{
#if SPAM
m_log.DebugFormat("[PHYSICS]: Adding physics actor to {0}", primName);
#endif
return AddPrim(primName, position, size, rotation, pbs, isPhysical, localid);
return AddPrim(primName, position, size, rotation, pbs, isPhysical,false, 0, localid);
}
public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, byte shapeType, uint localid)
{
#if SPAM
m_log.DebugFormat("[PHYSICS]: Adding physics actor to {0}", primName);
#endif
return AddPrim(primName, position, size, rotation, pbs, isPhysical,isPhantom, shapeType, localid);
}
public override float TimeDilation
{
get { return m_timeDilation; }
}
public override bool SupportsNINJAJoints
{
get { return false; }
}
public void remActivePrim(OdePrim deactivatePrim)
{
lock (_activeprims)
@ -1534,6 +1460,28 @@ namespace OpenSim.Region.Physics.OdePlugin
}
}
public bool havePrim(OdePrim prm)
{
lock (_prims)
return _prims.Contains(prm);
}
public bool haveActor(PhysicsActor actor)
{
if (actor is OdePrim)
{
lock (_prims)
return _prims.Contains((OdePrim)actor);
}
else if (actor is OdeCharacter)
{
lock (_characters)
return _characters.Contains((OdeCharacter)actor);
}
return false;
}
#endregion
#region Space Separation Calculation
@ -1706,20 +1654,9 @@ namespace OpenSim.Region.Physics.OdePlugin
{
if (world == IntPtr.Zero)
return 0;
d.WorldSetQuickStepNumIterations(world, curphysiteractions);
// adjust number of iterations per step
// try
// {
d.WorldSetQuickStepNumIterations(world, curphysiteractions);
/* }
catch (StackOverflowException)
{
m_log.Error("[PHYSICS]: The operating system wasn't able to allocate enough memory for the simulation. Restarting the sim.");
// ode.drelease(world);
base.TriggerPhysicsBasedRestart();
}
*/
while (step_time > HalfOdeStep && nodeframes < 10) //limit number of steps so we don't say here for ever
{
try
@ -1747,8 +1684,9 @@ namespace OpenSim.Region.Physics.OdePlugin
}
catch
{
m_log.Warn("[PHYSICS]: doChange failed for a actor");
};
m_log.WarnFormat("[PHYSICS]: doChange failed for a actor {0} {1}",
item.actor.Name, item.what.ToString());
}
}
ttmp = Util.EnvironmentTickCountSubtract(ttmpstart);
if (ttmp > 20)
@ -2491,6 +2429,9 @@ namespace OpenSim.Region.Physics.OdePlugin
*/
public override void Dispose()
{
if (m_meshWorker != null)
m_meshWorker.Stop();
lock (OdeLock)
{
m_rayCastManager.Dispose();