a few changes/fix (?)

avinationmerge
UbitUmarov 2012-10-07 23:54:15 +01:00
parent 48d8fbc9ae
commit a1fcfe8677
4 changed files with 112 additions and 117 deletions

View File

@ -1113,17 +1113,17 @@ namespace OpenSim.Region.Physics.Meshing
Mesh mesh = (Mesh)imesh; Mesh mesh = (Mesh)imesh;
int curRefCount = mesh.RefCount;
curRefCount--;
if (curRefCount > 0)
{
mesh.RefCount = curRefCount;
return;
}
lock (m_uniqueMeshes) lock (m_uniqueMeshes)
{ {
int curRefCount = mesh.RefCount;
curRefCount--;
if (curRefCount > 0)
{
mesh.RefCount = curRefCount;
return;
}
mesh.RefCount = 0; mesh.RefCount = 0;
m_uniqueMeshes.Remove(mesh.Key); m_uniqueMeshes.Remove(mesh.Key);
lock (m_uniqueReleasedMeshes) lock (m_uniqueReleasedMeshes)

View File

@ -18,6 +18,23 @@ using OpenMetaverse;
namespace OpenSim.Region.Physics.OdePlugin namespace OpenSim.Region.Physics.OdePlugin
{ {
public enum MeshState : byte
{
noNeed = 0,
loadingAsset = 1,
AssetOK = 0x0f, // 00001111
NeedMask = 0x30, // 00110000
needMesh = 0x10, // 00010000
needAsset = 0x20, // 00100000
FailMask = 0xC0, // 11000000
AssetFailed = 0x40, // 01000000
MeshFailed = 0x80 // 10000000
}
public enum meshWorkerCmnds : byte public enum meshWorkerCmnds : byte
{ {
nop = 0, nop = 0,
@ -43,13 +60,11 @@ namespace OpenSim.Region.Physics.OdePlugin
public byte shapetype; public byte shapetype;
public bool hasOBB; public bool hasOBB;
public bool hasMeshVolume; public bool hasMeshVolume;
public AssetState assetState; public MeshState meshState;
public UUID? assetID; public UUID? assetID;
public meshWorkerCmnds comand; public meshWorkerCmnds comand;
} }
public class ODEMeshWorker public class ODEMeshWorker
{ {
@ -138,16 +153,10 @@ namespace OpenSim.Region.Physics.OdePlugin
repData.size = size; repData.size = size;
repData.shapetype = shapetype; repData.shapetype = shapetype;
// if (CheckMeshDone(repData)) CheckMeshDone(repData);
{ CalcVolumeData(repData);
CheckMeshDone(repData); m_scene.AddChange(actor, changes.PhysRepData, repData);
CalcVolumeData(repData); return;
m_scene.AddChange(actor, changes.PhysRepData, repData);
return;
}
// repData.comand = meshWorkerCmnds.changefull;
// createqueue.Enqueue(repData);
} }
public void NewActorPhysRep(PhysicsActor actor, PrimitiveBaseShape pbs, public void NewActorPhysRep(PhysicsActor actor, PrimitiveBaseShape pbs,
@ -159,39 +168,43 @@ namespace OpenSim.Region.Physics.OdePlugin
repData.size = size; repData.size = size;
repData.shapetype = shapetype; repData.shapetype = shapetype;
// bool done = CheckMeshDone(repData);
CheckMeshDone(repData); CheckMeshDone(repData);
CalcVolumeData(repData); CalcVolumeData(repData);
m_scene.AddChange(actor, changes.AddPhysRep, repData); m_scene.AddChange(actor, changes.AddPhysRep, repData);
// if (done)
return;
// repData.comand = meshWorkerCmnds.addnew;
// createqueue.Enqueue(repData);
} }
public void RequestMeshAsset(ODEPhysRepData repData) public void RequestMesh(ODEPhysRepData repData)
{ {
if (repData.assetState != AssetState.needAsset)
return;
repData.mesh = null; repData.mesh = null;
if (repData.assetID == null || repData.assetID == UUID.Zero) if (repData.meshState == MeshState.needMesh)
{ {
repData.assetState = AssetState.noNeedAsset;
repData.comand = meshWorkerCmnds.changefull; repData.comand = meshWorkerCmnds.changefull;
createqueue.Enqueue(repData); createqueue.Enqueue(repData);
return;
} }
else if (repData.meshState == MeshState.needAsset)
{
PrimitiveBaseShape pbs = repData.pbs;
repData.assetState = AssetState.loadingAsset; // check if we got outdated
repData.comand = meshWorkerCmnds.getmesh; if (!pbs.SculptEntry || pbs.SculptTexture == UUID.Zero)
createqueue.Enqueue(repData); {
repData.meshState = MeshState.noNeed;
return;
}
if (pbs.SculptTexture != repData.assetID)
return;
repData.meshState = MeshState.loadingAsset;
repData.comand = meshWorkerCmnds.getmesh;
createqueue.Enqueue(repData);
}
} }
// creates and prepares a mesh to use and calls parameters estimation
public bool CreateActorPhysRep(ODEPhysRepData repData) public bool CreateActorPhysRep(ODEPhysRepData repData)
{ {
getMesh(repData); getMesh(repData);
@ -210,7 +223,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{ {
m_log.WarnFormat("[PHYSICS]: Invalid mesh data on prim {0} mesh UUID {1}", m_log.WarnFormat("[PHYSICS]: Invalid mesh data on prim {0} mesh UUID {1}",
repData.actor.Name, repData.pbs.SculptTexture.ToString()); repData.actor.Name, repData.pbs.SculptTexture.ToString());
repData.assetState = AssetState.AssetFailed; repData.meshState = MeshState.MeshFailed;
repData.hasOBB = false; repData.hasOBB = false;
repData.mesh = null; repData.mesh = null;
m_scene.mesher.ReleaseMesh(mesh); m_scene.mesher.ReleaseMesh(mesh);
@ -237,6 +250,8 @@ namespace OpenSim.Region.Physics.OdePlugin
createqueue.Enqueue(repData); createqueue.Enqueue(repData);
} }
} }
else
repData.pbs.SculptData = Utils.EmptyBytes;
} }
public void DoRepDataGetMesh(ODEPhysRepData repData) public void DoRepDataGetMesh(ODEPhysRepData repData)
@ -244,7 +259,7 @@ namespace OpenSim.Region.Physics.OdePlugin
if (!repData.pbs.SculptEntry) if (!repData.pbs.SculptEntry)
return; return;
if (repData.assetState != AssetState.loadingAsset) if (repData.meshState != MeshState.loadingAsset)
return; return;
if (repData.assetID == null || repData.assetID == UUID.Zero) if (repData.assetID == null || repData.assetID == UUID.Zero)
@ -381,34 +396,19 @@ namespace OpenSim.Region.Physics.OdePlugin
return true; return true;
} }
// see if we need a mesh and if so if we have a cached one
// called with a new repData
public bool CheckMeshDone(ODEPhysRepData repData) public bool CheckMeshDone(ODEPhysRepData repData)
{ {
PhysicsActor actor = repData.actor; PhysicsActor actor = repData.actor;
PrimitiveBaseShape pbs = repData.pbs; PrimitiveBaseShape pbs = repData.pbs;
repData.mesh = null;
repData.hasOBB = false;
if (!needsMeshing(pbs)) if (!needsMeshing(pbs))
{ {
repData.assetState = AssetState.noNeedAsset; repData.meshState = MeshState.noNeed;
return true; 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; IMesh mesh = null;
Vector3 size = repData.size; Vector3 size = repData.size;
@ -425,7 +425,9 @@ namespace OpenSim.Region.Physics.OdePlugin
if (pbs.SculptType != (byte)SculptType.Mesh) if (pbs.SculptType != (byte)SculptType.Mesh)
clod = (int)LevelOfDetail.Low; clod = (int)LevelOfDetail.Low;
} }
mesh = m_mesher.GetMesh(actor.Name, pbs, size, clod, true, convex); mesh = m_mesher.GetMesh(actor.Name, pbs, size, clod, true, convex);
if (mesh == null) if (mesh == null)
{ {
if (pbs.SculptEntry) if (pbs.SculptEntry)
@ -433,13 +435,13 @@ namespace OpenSim.Region.Physics.OdePlugin
if (pbs.SculptTexture != null && pbs.SculptTexture != UUID.Zero) if (pbs.SculptTexture != null && pbs.SculptTexture != UUID.Zero)
{ {
repData.assetID = pbs.SculptTexture; repData.assetID = pbs.SculptTexture;
repData.assetState = AssetState.needAsset; repData.meshState = MeshState.needAsset;
} }
else else
repData.assetState = AssetState.AssetFailed; repData.meshState = MeshState.MeshFailed;
} }
else else
repData.assetState = AssetState.needAsset; repData.meshState = MeshState.needMesh;
return false; return false;
} }
@ -447,14 +449,14 @@ namespace OpenSim.Region.Physics.OdePlugin
repData.mesh = mesh; repData.mesh = mesh;
if (pbs.SculptEntry) if (pbs.SculptEntry)
{ {
repData.assetState = AssetState.AssetOK; repData.meshState = MeshState.AssetOK;
repData.assetID = pbs.SculptTexture; repData.assetID = pbs.SculptTexture;
pbs.SculptData = Utils.EmptyBytes;
} }
pbs.SculptData = Utils.EmptyBytes;
return true; return true;
} }
public bool getMesh(ODEPhysRepData repData) public bool getMesh(ODEPhysRepData repData)
{ {
PhysicsActor actor = repData.actor; PhysicsActor actor = repData.actor;
@ -467,16 +469,19 @@ namespace OpenSim.Region.Physics.OdePlugin
if (!needsMeshing(pbs)) if (!needsMeshing(pbs))
return false; return false;
if (repData.meshState == MeshState.MeshFailed)
return false;
if (pbs.SculptEntry) if (pbs.SculptEntry)
{ {
if (repData.assetState == AssetState.AssetFailed) if (repData.meshState == MeshState.AssetFailed)
{ {
if (pbs.SculptTexture == repData.assetID) if (pbs.SculptTexture == repData.assetID)
return true; return true;
} }
} }
repData.assetState = AssetState.noNeedAsset; repData.meshState = MeshState.noNeed;
IMesh mesh = null; IMesh mesh = null;
Vector3 size = repData.size; Vector3 size = repData.size;
@ -492,7 +497,10 @@ namespace OpenSim.Region.Physics.OdePlugin
if (pbs.SculptType != (byte)SculptType.Mesh) if (pbs.SculptType != (byte)SculptType.Mesh)
clod = (int)LevelOfDetail.Low; clod = (int)LevelOfDetail.Low;
} }
// check cached
mesh = m_mesher.GetMesh(actor.Name, pbs, size, clod, true, convex); mesh = m_mesher.GetMesh(actor.Name, pbs, size, clod, true, convex);
if (mesh == null) if (mesh == null)
{ {
if (pbs.SculptEntry) if (pbs.SculptEntry)
@ -501,17 +509,16 @@ namespace OpenSim.Region.Physics.OdePlugin
return false; return false;
repData.assetID = pbs.SculptTexture; repData.assetID = pbs.SculptTexture;
repData.assetState = AssetState.AssetOK; repData.meshState = MeshState.AssetOK;
if (pbs.SculptData == null || pbs.SculptData.Length == 0) if (pbs.SculptData == null || pbs.SculptData.Length == 0)
{ {
repData.assetState = AssetState.needAsset; repData.meshState = MeshState.needAsset;
return false; return false;
} }
} }
mesh = m_mesher.CreateMesh(actor.Name, pbs, size, clod, true, convex); mesh = m_mesher.CreateMesh(actor.Name, pbs, size, clod, true, convex);
} }
repData.mesh = mesh; repData.mesh = mesh;
@ -520,13 +527,14 @@ namespace OpenSim.Region.Physics.OdePlugin
if (mesh == null) if (mesh == null)
{ {
if (pbs.SculptEntry) if (pbs.SculptEntry)
repData.assetState = AssetState.AssetFailed; repData.meshState = MeshState.AssetFailed;
else
repData.meshState = MeshState.MeshFailed;
return false; return false;
} }
if (pbs.SculptEntry) repData.meshState = MeshState.AssetOK;
repData.assetState = AssetState.AssetOK;
return true; return true;
} }
@ -866,7 +874,7 @@ namespace OpenSim.Region.Physics.OdePlugin
m_log = plog; m_log = plog;
repData = pRepData; repData = pRepData;
repData.assetState = AssetState.AssetFailed; repData.meshState = MeshState.AssetFailed;
if (provider == null) if (provider == null)
return; return;
@ -877,29 +885,27 @@ namespace OpenSim.Region.Physics.OdePlugin
if (assetID == UUID.Zero) if (assetID == UUID.Zero)
return; return;
repData.assetState = AssetState.loadingAsset; repData.meshState = MeshState.loadingAsset;
provider(assetID, ODEassetReceived); provider(assetID, ODEassetReceived);
} }
void ODEassetReceived(AssetBase asset) void ODEassetReceived(AssetBase asset)
{ {
repData.assetState = AssetState.AssetFailed; repData.meshState = MeshState.AssetFailed;
if (asset != null) if (asset != null)
{ {
if (asset.Data != null && asset.Data.Length > 0) if (asset.Data != null && asset.Data.Length > 0)
{ {
repData.meshState = MeshState.noNeed;
if (!repData.pbs.SculptEntry) if (!repData.pbs.SculptEntry)
return; return;
if (repData.pbs.SculptTexture != repData.assetID) if (repData.pbs.SculptTexture != repData.assetID)
return; 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]; repData.pbs.SculptData = new byte[asset.Data.Length];
asset.Data.CopyTo(repData.pbs.SculptData,0); asset.Data.CopyTo(repData.pbs.SculptData,0);
repData.assetState = AssetState.AssetOK; repData.meshState = MeshState.AssetOK;
m_worker.AssetLoaded(repData); m_worker.AssetLoaded(repData);
} }
else else

View File

@ -146,7 +146,7 @@ namespace OpenSim.Region.Physics.OdePlugin
private PrimitiveBaseShape _pbs; private PrimitiveBaseShape _pbs;
private UUID? m_assetID; private UUID? m_assetID;
private AssetState m_assetState; private MeshState m_meshState;
public OdeScene _parent_scene; public OdeScene _parent_scene;
@ -1341,15 +1341,18 @@ namespace OpenSim.Region.Physics.OdePlugin
if (vertexCount == 0 || indexCount == 0) if (vertexCount == 0 || indexCount == 0)
{ {
m_log.WarnFormat("[PHYSICS]: Invalid mesh data on OdePrim {0} mesh UUID {1}", m_log.WarnFormat("[PHYSICS]: Invalid mesh data on OdePrim {0}, mesh {1}",
Name, _pbs.SculptTexture.ToString()); Name, _pbs.SculptEntry ? _pbs.SculptTexture.ToString() : "primMesh");
m_hasOBB = false; m_hasOBB = false;
m_OBBOffset = Vector3.Zero; m_OBBOffset = Vector3.Zero;
m_OBB = _size * 0.5f; m_OBB = _size * 0.5f;
m_physCost = 0.1f; m_physCost = 0.1f;
m_streamCost = 1.0f; m_streamCost = 1.0f;
_parent_scene.mesher.ReleaseMesh(mesh); _parent_scene.mesher.ReleaseMesh(mesh);
m_assetState = AssetState.AssetFailed; m_meshState = MeshState.MeshFailed;
m_mesh = null; m_mesh = null;
return false; return false;
} }
@ -1360,7 +1363,7 @@ namespace OpenSim.Region.Physics.OdePlugin
d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride); d.GeomTriMeshDataBuildSimple(_triMeshData, vertices, vertexStride, vertexCount, indices, indexCount, triStride);
d.GeomTriMeshDataPreprocess(_triMeshData); d.GeomTriMeshDataPreprocess(_triMeshData);
prim_geom = d.CreateTriMesh(IntPtr.Zero, _triMeshData, null, null, null); prim_geom = d.CreateTriMesh(m_targetSpace, _triMeshData, null, null, null);
} }
catch (Exception e) catch (Exception e)
@ -1385,7 +1388,7 @@ namespace OpenSim.Region.Physics.OdePlugin
m_physCost = 0.1f; m_physCost = 0.1f;
m_streamCost = 1.0f; m_streamCost = 1.0f;
_parent_scene.mesher.ReleaseMesh(mesh); _parent_scene.mesher.ReleaseMesh(mesh);
m_assetState = AssetState.AssetFailed; m_meshState = MeshState.AssetFailed;
m_mesh = null; m_mesh = null;
return false; return false;
} }
@ -1404,7 +1407,7 @@ namespace OpenSim.Region.Physics.OdePlugin
m_NoColide = false; m_NoColide = false;
if (m_assetState == AssetState.AssetFailed) if ((m_meshState & MeshState.FailMask) != 0)
m_NoColide = true; m_NoColide = true;
else if(m_mesh != null) else if(m_mesh != null)
@ -1422,7 +1425,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{ // it's a sphere { // it's a sphere
try try
{ {
geo = d.CreateSphere(IntPtr.Zero, _size.X * 0.5f); geo = d.CreateSphere(m_targetSpace, _size.X * 0.5f);
} }
catch (Exception e) catch (Exception e)
{ {
@ -1434,7 +1437,7 @@ namespace OpenSim.Region.Physics.OdePlugin
{// do it as a box {// do it as a box
try try
{ {
geo = d.CreateBox(IntPtr.Zero, _size.X, _size.Y, _size.Z); geo = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
} }
catch (Exception e) catch (Exception e)
{ {
@ -2748,7 +2751,7 @@ namespace OpenSim.Region.Physics.OdePlugin
m_mesh = repData.mesh; m_mesh = repData.mesh;
m_assetID = repData.assetID; m_assetID = repData.assetID;
m_assetState = repData.assetState; m_meshState = repData.meshState;
m_hasOBB = repData.hasOBB; m_hasOBB = repData.hasOBB;
m_OBBOffset = repData.OBBOffset; m_OBBOffset = repData.OBBOffset;
@ -2781,12 +2784,12 @@ namespace OpenSim.Region.Physics.OdePlugin
else else
MakeBody(); MakeBody();
if (m_assetState == AssetState.needAsset) if ((m_meshState & MeshState.NeedMask) != 0)
{ {
repData.size = _size; repData.size = _size;
repData.pbs = _pbs; repData.pbs = _pbs;
repData.shapetype = m_shapetype; repData.shapetype = m_shapetype;
_parent_scene.m_meshWorker.RequestMeshAsset(repData); _parent_scene.m_meshWorker.RequestMesh(repData);
} }
} }
} }
@ -2820,7 +2823,7 @@ namespace OpenSim.Region.Physics.OdePlugin
m_mesh = repData.mesh; m_mesh = repData.mesh;
m_assetID = repData.assetID; m_assetID = repData.assetID;
m_assetState = repData.assetState; m_meshState = repData.meshState;
m_hasOBB = repData.hasOBB; m_hasOBB = repData.hasOBB;
m_OBBOffset = repData.OBBOffset; m_OBBOffset = repData.OBBOffset;
@ -2832,12 +2835,9 @@ namespace OpenSim.Region.Physics.OdePlugin
if (prim_geom != IntPtr.Zero) if (prim_geom != IntPtr.Zero)
{ {
m_targetSpace = IntPtr.Zero;
UpdatePrimBodyData(); UpdatePrimBodyData();
_parent_scene.actor_name_map[prim_geom] = this; _parent_scene.actor_name_map[prim_geom] = this;
d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
d.Quaternion myrot = new d.Quaternion(); d.Quaternion myrot = new d.Quaternion();
@ -2847,7 +2847,6 @@ namespace OpenSim.Region.Physics.OdePlugin
myrot.W = _orientation.W; myrot.W = _orientation.W;
d.GeomSetQuaternion(prim_geom, ref myrot); d.GeomSetQuaternion(prim_geom, ref myrot);
if (m_isphysical) if (m_isphysical)
{ {
if (chp) if (chp)
@ -2869,13 +2868,14 @@ namespace OpenSim.Region.Physics.OdePlugin
} }
resetCollisionAccounting(); resetCollisionAccounting();
if (m_assetState == AssetState.needAsset) }
{
repData.size = _size; if ((m_meshState & MeshState.NeedMask) != 0)
repData.pbs = _pbs; {
repData.shapetype = m_shapetype; repData.size = _size;
_parent_scene.m_meshWorker.RequestMeshAsset(repData); repData.pbs = _pbs;
} repData.shapetype = m_shapetype;
_parent_scene.m_meshWorker.RequestMesh(repData);
} }
} }

View File

@ -111,17 +111,6 @@ namespace OpenSim.Region.Physics.OdePlugin
light = 7 // compatibility with old viewers light = 7 // compatibility with old viewers
} }
public enum AssetState : byte
{
noNeedAsset = 0,
needAsset = 1,
loadingAsset = 2,
procAsset = 3,
AssetOK = 4,
AssetFailed = 0xff
}
public enum changes : int public enum changes : int
{ {
Add = 0, // arg null. finishs the prim creation. should be used internally only ( to remove later ?) Add = 0, // arg null. finishs the prim creation. should be used internally only ( to remove later ?)