replace objects scale clamp by a more readable clamp. Simplify GroupResize and let rescale factors < 1 also be checked for size limits, Set new scales directly not checking them again.

avinationmerge
UbitUmarov 2015-10-23 01:39:53 +01:00
parent 8ed17f745d
commit 28d4afbe3a
2 changed files with 84 additions and 140 deletions

View File

@ -3795,30 +3795,32 @@ namespace OpenSim.Region.Framework.Scenes
// m_log.DebugFormat( // m_log.DebugFormat(
// "[SCENE OBJECT GROUP]: Group resizing {0} {1} from {2} to {3}", Name, LocalId, RootPart.Scale, scale); // "[SCENE OBJECT GROUP]: Group resizing {0} {1} from {2} to {3}", Name, LocalId, RootPart.Scale, scale);
if (Scene == null)
return;
PhysicsActor pa = m_rootPart.PhysActor; PhysicsActor pa = m_rootPart.PhysActor;
if (Scene != null) float minsize = Scene.m_minNonphys;
{ float maxsize = Scene.m_maxNonphys;
scale.X = Math.Max(Scene.m_minNonphys, Math.Min(Scene.m_maxNonphys, scale.X));
scale.Y = Math.Max(Scene.m_minNonphys, Math.Min(Scene.m_maxNonphys, scale.Y));
scale.Z = Math.Max(Scene.m_minNonphys, Math.Min(Scene.m_maxNonphys, scale.Z));
if (pa != null && pa.IsPhysical) if (pa != null && pa.IsPhysical)
{ {
scale.X = Math.Max(Scene.m_minPhys, Math.Min(Scene.m_maxPhys, scale.X)); minsize = Scene.m_minPhys;
scale.Y = Math.Max(Scene.m_minPhys, Math.Min(Scene.m_maxPhys, scale.Y)); maxsize = Scene.m_maxPhys;
scale.Z = Math.Max(Scene.m_minPhys, Math.Min(Scene.m_maxPhys, scale.Z));
}
} }
scale.X = Util.Clamp(scale.X, minsize, maxsize);
scale.Y = Util.Clamp(scale.Y, minsize, maxsize);
scale.Z = Util.Clamp(scale.Z, minsize, maxsize);
// requested scaling factors
float x = (scale.X / RootPart.Scale.X); float x = (scale.X / RootPart.Scale.X);
float y = (scale.Y / RootPart.Scale.Y); float y = (scale.Y / RootPart.Scale.Y);
float z = (scale.Z / RootPart.Scale.Z); float z = (scale.Z / RootPart.Scale.Z);
SceneObjectPart[] parts = m_parts.GetArray(); SceneObjectPart[] parts = m_parts.GetArray();
if (Scene != null & (x > 1.0f || y > 1.0f || z > 1.0f)) // fix scaling factors so parts don't violate dimensions
{
for(int i = 0;i < parts.Length;i++) for(int i = 0;i < parts.Length;i++)
{ {
SceneObjectPart obPart = parts[i]; SceneObjectPart obPart = parts[i];
@ -3829,106 +3831,51 @@ namespace OpenSim.Region.Framework.Scenes
float f = 1.0f; float f = 1.0f;
float a = 1.0f; float a = 1.0f;
if (pa != null && pa.IsPhysical) if(oldSize.X * x > maxsize)
{ {
if (oldSize.X * x > Scene.m_maxPhys) f = maxsize / oldSize.X;
{
f = m_scene.m_maxPhys / oldSize.X;
a = f / x; a = f / x;
x *= a; x *= a;
y *= a; y *= a;
z *= a; z *= a;
} }
else if (oldSize.X * x < Scene.m_minPhys) else if(oldSize.X * x < minsize)
{ {
f = m_scene.m_minPhys / oldSize.X; f = minsize / oldSize.X;
a = f / x; a = f / x;
x *= a; x *= a;
y *= a; y *= a;
z *= a; z *= a;
} }
if (oldSize.Y * y > Scene.m_maxPhys) if(oldSize.Y * y > maxsize)
{ {
f = m_scene.m_maxPhys / oldSize.Y; f = maxsize / oldSize.Y;
a = f / y; a = f / y;
x *= a; x *= a;
y *= a; y *= a;
z *= a; z *= a;
} }
else if (oldSize.Y * y < Scene.m_minPhys) else if(oldSize.Y * y < minsize)
{ {
f = m_scene.m_minPhys / oldSize.Y; f = minsize / oldSize.Y;
a = f / y; a = f / y;
x *= a; x *= a;
y *= a; y *= a;
z *= a; z *= a;
} }
if (oldSize.Z * z > Scene.m_maxPhys) if(oldSize.Z * z > maxsize)
{ {
f = m_scene.m_maxPhys / oldSize.Z; f = maxsize / oldSize.Z;
a = f / z; a = f / z;
x *= a; x *= a;
y *= a; y *= a;
z *= a; z *= a;
} }
else if (oldSize.Z * z < Scene.m_minPhys) else if(oldSize.Z * z < minsize)
{ {
f = m_scene.m_minPhys / oldSize.Z; f = minsize / oldSize.Z;
a = f / z;
x *= a;
y *= a;
z *= a;
}
}
else
{
if (oldSize.X * x > Scene.m_maxNonphys)
{
f = m_scene.m_maxNonphys / oldSize.X;
a = f / x;
x *= a;
y *= a;
z *= a;
}
else if (oldSize.X * x < Scene.m_minNonphys)
{
f = m_scene.m_minNonphys / oldSize.X;
a = f / x;
x *= a;
y *= a;
z *= a;
}
if (oldSize.Y * y > Scene.m_maxNonphys)
{
f = m_scene.m_maxNonphys / oldSize.Y;
a = f / y;
x *= a;
y *= a;
z *= a;
}
else if (oldSize.Y * y < Scene.m_minNonphys)
{
f = m_scene.m_minNonphys / oldSize.Y;
a = f / y;
x *= a;
y *= a;
z *= a;
}
if (oldSize.Z * z > Scene.m_maxNonphys)
{
f = m_scene.m_maxNonphys / oldSize.Z;
a = f / z;
x *= a;
y *= a;
z *= a;
}
else if (oldSize.Z * z < Scene.m_minNonphys)
{
f = m_scene.m_minNonphys / oldSize.Z;
a = f / z; a = f / z;
x *= a; x *= a;
y *= a; y *= a;
@ -3936,15 +3883,13 @@ namespace OpenSim.Region.Framework.Scenes
} }
} }
} }
}
}
Vector3 prevScale = RootPart.Scale; Vector3 rootScale = RootPart.Scale;
prevScale.X *= x; rootScale.X *= x;
prevScale.Y *= y; rootScale.Y *= y;
prevScale.Z *= z; rootScale.Z *= z;
RootPart.Resize(prevScale); RootPart.Scale = rootScale;
for (int i = 0; i < parts.Length; i++) for (int i = 0; i < parts.Length; i++)
{ {
@ -3962,7 +3907,7 @@ namespace OpenSim.Region.Framework.Scenes
newSize.Y *= y; newSize.Y *= y;
newSize.Z *= z; newSize.Z *= z;
obPart.Resize(newSize); obPart.Scale = newSize;
obPart.UpdateOffSet(currentpos); obPart.UpdateOffSet(currentpos);
} }

View File

@ -3073,18 +3073,17 @@ namespace OpenSim.Region.Framework.Scenes
if (ParentGroup.Scene != null) if (ParentGroup.Scene != null)
{ {
scale.X = Math.Max(ParentGroup.Scene.m_minNonphys, Math.Min(ParentGroup.Scene.m_maxNonphys, scale.X)); float minsize = ParentGroup.Scene.m_minNonphys;
scale.Y = Math.Max(ParentGroup.Scene.m_minNonphys, Math.Min(ParentGroup.Scene.m_maxNonphys, scale.Y)); float maxsize = ParentGroup.Scene.m_maxNonphys;
scale.Z = Math.Max(ParentGroup.Scene.m_minNonphys, Math.Min(ParentGroup.Scene.m_maxNonphys, scale.Z));
if (pa != null && pa.IsPhysical) if (pa != null && pa.IsPhysical)
{ {
scale.X = Math.Max(ParentGroup.Scene.m_minPhys, Math.Min(ParentGroup.Scene.m_maxPhys, scale.X)); minsize = ParentGroup.Scene.m_minPhys;
scale.Y = Math.Max(ParentGroup.Scene.m_minPhys, Math.Min(ParentGroup.Scene.m_maxPhys, scale.Y)); maxsize = ParentGroup.Scene.m_maxPhys;
scale.Z = Math.Max(ParentGroup.Scene.m_minPhys, Math.Min(ParentGroup.Scene.m_maxPhys, scale.Z));
} }
scale.X = Util.Clamp(scale.X, minsize, maxsize);
scale.Y = Util.Clamp(scale.Y, minsize, maxsize);
scale.Z = Util.Clamp(scale.Z, minsize, maxsize);
} }
// m_log.DebugFormat("[SCENE OBJECT PART]: Resizing {0} {1} to {2}", Name, LocalId, scale); // m_log.DebugFormat("[SCENE OBJECT PART]: Resizing {0} {1} to {2}", Name, LocalId, scale);
Scale = scale; Scale = scale;