* Moved PrimitiveBaseShape subclasses into factory methods - the subclassing scheme won't hold for serialization

* Extracted out the 'old' AddNewPrimitive that places an object at an exact pos, without the raytracing
afrisby
lbsa71 2007-12-28 08:34:38 +00:00
parent 5bd5770ed2
commit 8cd72beb86
8 changed files with 107 additions and 116 deletions

View File

@ -203,7 +203,7 @@ namespace OpenSim.Framework.Data.MySQL
{ {
MainLog.Instance.Notice( MainLog.Instance.Notice(
"No shape found for prim in storage, so setting default box shape"); "No shape found for prim in storage, so setting default box shape");
prim.Shape = BoxShape.Default; prim.Shape = PrimitiveBaseShape.Default;
} }
group.AddPart(prim); group.AddPart(prim);
group.RootPart = prim; group.RootPart = prim;
@ -223,7 +223,7 @@ namespace OpenSim.Framework.Data.MySQL
{ {
MainLog.Instance.Notice( MainLog.Instance.Notice(
"No shape found for prim in storage, so setting default box shape"); "No shape found for prim in storage, so setting default box shape");
prim.Shape = BoxShape.Default; prim.Shape = PrimitiveBaseShape.Default;
} }
createdObjects[new LLUUID(objID)].AddPart(prim); createdObjects[new LLUUID(objID)].AddPart(prim);
} }

View File

@ -112,22 +112,22 @@ namespace OpenSim.Framework
public ProfileShape ProfileShape public ProfileShape ProfileShape
{ {
get { return (ProfileShape) (ProfileCurve & 0xf); } get { return (ProfileShape)(ProfileCurve & 0xf); }
set set
{ {
byte oldValueMasked = (byte) (ProfileCurve & 0xf0); byte oldValueMasked = (byte)(ProfileCurve & 0xf0);
ProfileCurve = (byte) (oldValueMasked | (byte) value); ProfileCurve = (byte)(oldValueMasked | (byte)value);
} }
} }
[XmlIgnore] [XmlIgnore]
public HollowShape HollowShape public HollowShape HollowShape
{ {
get { return (HollowShape) (ProfileCurve & 0xf0); } get { return (HollowShape)(ProfileCurve & 0xf0); }
set set
{ {
byte oldValueMasked = (byte) (ProfileCurve & 0x0f); byte oldValueMasked = (byte)(ProfileCurve & 0x0f);
ProfileCurve = (byte) (oldValueMasked | (byte) value); ProfileCurve = (byte)(oldValueMasked | (byte)value);
} }
} }
@ -145,7 +145,7 @@ namespace OpenSim.Framework
public PrimitiveBaseShape() public PrimitiveBaseShape()
{ {
PCode = (byte) PCodeEnum.Primitive; PCode = (byte)PCodeEnum.Primitive;
ExtraParams = new byte[1]; ExtraParams = new byte[1];
Textures = m_defaultTexture; Textures = m_defaultTexture;
} }
@ -156,6 +156,58 @@ namespace OpenSim.Framework
return shape; return shape;
} }
public static PrimitiveBaseShape CreateBox()
{
PrimitiveBaseShape shape = Create();
shape.PathCurve = (byte)Extrusion.Straight;
shape.ProfileShape = ProfileShape.Square;
shape.PathScaleX = 100;
shape.PathScaleY = 100;
return shape;
}
public static PrimitiveBaseShape CreateCylinder()
{
PrimitiveBaseShape shape = Create();
shape.PathCurve = (byte)Extrusion.Curve1;
shape.ProfileShape = ProfileShape.Square;
shape.PathScaleX = 100;
shape.PathScaleY = 100;
return shape;
}
public static PrimitiveBaseShape Default
{
get
{
PrimitiveBaseShape boxShape = CreateBox();
boxShape.SetScale(0.5f);
return boxShape;
}
}
public void SetScale(float side)
{
Scale = new LLVector3(side, side, side);
}
public void SetHeigth(float heigth)
{
Scale.Z = heigth;
}
public void SetRadius(float radius)
{
Scale.X = Scale.Y = radius * 2f;
}
//void returns need to change of course //void returns need to change of course
public virtual void GetMesh() public virtual void GetMesh()
{ {
@ -163,79 +215,17 @@ namespace OpenSim.Framework
public PrimitiveBaseShape Copy() public PrimitiveBaseShape Copy()
{ {
return (PrimitiveBaseShape) MemberwiseClone(); return (PrimitiveBaseShape)MemberwiseClone();
}
}
public class GenericShape : PrimitiveBaseShape
{
public GenericShape()
: base()
{
}
}
public class BoxShape : PrimitiveBaseShape
{
public BoxShape()
: base()
{
PathCurve = (byte) Extrusion.Straight;
ProfileShape = ProfileShape.Square;
PathScaleX = 100;
PathScaleY = 100;
} }
public BoxShape(float side) public static PrimitiveBaseShape CreateCylinder(float radius, float heigth)
: this()
{ {
SetSide(side); PrimitiveBaseShape shape = CreateCylinder( );
}
public void SetSide(float side) shape.SetHeigth( heigth );
{ shape.SetRadius( radius );
Scale = new LLVector3(side, side, side);
}
public static BoxShape Default return shape;
{
get
{
BoxShape boxShape = new BoxShape();
boxShape.SetSide(0.5f);
return boxShape;
}
}
}
public class CylinderShape : PrimitiveBaseShape
{
public CylinderShape()
: base()
{
PathCurve = (byte) Extrusion.Straight;
ProfileShape = ProfileShape.Circle;
PathScaleX = 100;
PathScaleY = 100;
}
public CylinderShape(float radius, float heigth)
: this()
{
SetRadius(radius);
SetHeigth(heigth);
}
private void SetHeigth(float heigth)
{
Scale.Z = heigth;
}
private void SetRadius(float radius)
{
Scale.X = Scale.Y = radius*2f;
} }
} }
} }

View File

@ -1016,42 +1016,43 @@ namespace OpenSim.Region.Environment.Scenes
// It's wrong many times though. // It's wrong many times though.
LLVector3 pos = GetNewRezLocation(RayStart, RayEnd, RayTargetID, rot, bypassRaycast, RayEndIsIntersection); LLVector3 pos = GetNewRezLocation(RayStart, RayEnd, RayTargetID, rot, bypassRaycast, RayEndIsIntersection);
if (PermissionsMngr.CanRezObject(ownerID, pos)) if (PermissionsMngr.CanRezObject(ownerID, pos))
{ {
// rez ON the ground, not IN the ground
// rez ON the ground, not IN the ground
pos.Z += 0.25F; pos.Z += 0.25F;
SceneObjectGroup sceneOb = AddNewPrim(ownerID, pos, rot, shape);
new SceneObjectGroup(this, m_regionHandle, ownerID, PrimIDAllocate(), pos, rot, shape); }
AddEntity(sceneOb); }
SceneObjectPart rootPart = sceneOb.GetChildPart(sceneOb.UUID);
// if grass or tree, make phantom public virtual void AddNewPrim(LLUUID ownerID, LLVector3 pos, LLQuaternion rot, PrimitiveBaseShape shape)
//rootPart.ApplySanePermissions(); {
if ((rootPart.Shape.PCode == 95) || (rootPart.Shape.PCode == 255) || (rootPart.Shape.PCode == 111)) SceneObjectGroup sceneOb =
{ new SceneObjectGroup(this, m_regionHandle, ownerID, PrimIDAllocate(), pos, rot, shape);
rootPart.AddFlag(LLObject.ObjectFlags.Phantom);
//rootPart.ObjectFlags += (uint)LLObject.ObjectFlags.Phantom; AddEntity(sceneOb);
} SceneObjectPart rootPart = sceneOb.GetChildPart(sceneOb.UUID);
// if not phantom, add to physics // if grass or tree, make phantom
bool UsePhysics = (((rootPart.ObjectFlags & (uint) LLObject.ObjectFlags.Physics) > 0) && m_physicalPrim); //rootPart.ApplySanePermissions();
if ((rootPart.ObjectFlags & (uint) LLObject.ObjectFlags.Phantom) == 0) if ((rootPart.Shape.PCode == 95) || (rootPart.Shape.PCode == 255) || (rootPart.Shape.PCode == 111))
{ {
rootPart.PhysActor = rootPart.AddFlag(LLObject.ObjectFlags.Phantom);
PhysicsScene.AddPrimShape( //rootPart.ObjectFlags += (uint)LLObject.ObjectFlags.Phantom;
rootPart.Name, }
rootPart.Shape, // if not phantom, add to physics
new PhysicsVector(pos.X, pos.Y, pos.Z), bool UsePhysics = (((rootPart.ObjectFlags & (uint) LLObject.ObjectFlags.Physics) > 0) && m_physicalPrim);
new PhysicsVector(shape.Scale.X, shape.Scale.Y, shape.Scale.Z), if ((rootPart.ObjectFlags & (uint) LLObject.ObjectFlags.Phantom) == 0)
new Quaternion(), UsePhysics); {
// subscribe to physics events. rootPart.PhysActor =
rootPart.DoPhysicsPropertyUpdate(UsePhysics, true); PhysicsScene.AddPrimShape(
} rootPart.Name,
rootPart.Shape,
new PhysicsVector(pos.X, pos.Y, pos.Z),
new PhysicsVector(shape.Scale.X, shape.Scale.Y, shape.Scale.Z),
new Quaternion(), UsePhysics);
// subscribe to physics events.
rootPart.DoPhysicsPropertyUpdate(UsePhysics, true);
} }
} }

View File

@ -43,7 +43,7 @@ namespace SimpleApp
public RotatingWheel(ulong regionHandle, SceneObjectGroup parent, LLUUID ownerID, uint localID, public RotatingWheel(ulong regionHandle, SceneObjectGroup parent, LLUUID ownerID, uint localID,
LLVector3 groupPosition, LLVector3 offsetPosition, LLQuaternion rotationDirection) LLVector3 groupPosition, LLVector3 offsetPosition, LLQuaternion rotationDirection)
: base( : base(
regionHandle, parent, ownerID, localID, new CylinderShape(0.5f, 0.2f), groupPosition, offsetPosition regionHandle, parent, ownerID, localID, PrimitiveBaseShape.CreateCylinder(0.5f, 0.2f), groupPosition, offsetPosition
) )
{ {
m_rotationDirection = rotationDirection; m_rotationDirection = rotationDirection;
@ -64,7 +64,7 @@ namespace SimpleApp
public ComplexObject(Scene scene, ulong regionHandle, LLUUID ownerID, uint localID, LLVector3 pos) public ComplexObject(Scene scene, ulong regionHandle, LLUUID ownerID, uint localID, LLVector3 pos)
: base(scene, regionHandle, ownerID, localID, pos, BoxShape.Default) : base(scene, regionHandle, ownerID, localID, pos, PrimitiveBaseShape.Default)
{ {
m_rotationDirection = new LLQuaternion(0.05f, 0.1f, 0.15f); m_rotationDirection = new LLQuaternion(0.05f, 0.1f, 0.15f);

View File

@ -39,7 +39,7 @@ namespace SimpleApp
private PerformanceCounter m_counter; private PerformanceCounter m_counter;
public CpuCounterObject(Scene world, ulong regionHandle, LLUUID ownerID, uint localID, LLVector3 pos) public CpuCounterObject(Scene world, ulong regionHandle, LLUUID ownerID, uint localID, LLVector3 pos)
: base(world, regionHandle, ownerID, localID, pos, BoxShape.Default) : base(world, regionHandle, ownerID, localID, pos, PrimitiveBaseShape.Default)
{ {
String objectName = "Processor"; String objectName = "Processor";
String counterName = "% Processor Time"; String counterName = "% Processor Time";

View File

@ -36,7 +36,7 @@ namespace SimpleApp
public class FileSystemObject : SceneObjectGroup public class FileSystemObject : SceneObjectGroup
{ {
public FileSystemObject(Scene world, FileInfo fileInfo, LLVector3 pos) public FileSystemObject(Scene world, FileInfo fileInfo, LLVector3 pos)
: base(world, world.RegionInfo.RegionHandle, LLUUID.Zero, world.NextLocalId, pos, BoxShape.Default) : base(world, world.RegionInfo.RegionHandle, LLUUID.Zero, world.NextLocalId, pos, PrimitiveBaseShape.Default)
{ {
//float size = (float) Math.Pow((double) fileInfo.Length, (double) 1/3)/5; //float size = (float) Math.Pow((double) fileInfo.Length, (double) 1/3)/5;
// rootPrimitive.ResizeGoup(new LLVector3(size, size, size)); // rootPrimitive.ResizeGoup(new LLVector3(size, size, size));

View File

@ -199,7 +199,7 @@ namespace OpenSim.DataStore.MSSQL
{ {
MainLog.Instance.Notice( MainLog.Instance.Notice(
"No shape found for prim in storage, so setting default box shape"); "No shape found for prim in storage, so setting default box shape");
prim.Shape = BoxShape.Default; prim.Shape = PrimitiveBaseShape.Default;
} }
group.AddPart(prim); group.AddPart(prim);
group.RootPart = prim; group.RootPart = prim;
@ -219,7 +219,7 @@ namespace OpenSim.DataStore.MSSQL
{ {
MainLog.Instance.Notice( MainLog.Instance.Notice(
"No shape found for prim in storage, so setting default box shape"); "No shape found for prim in storage, so setting default box shape");
prim.Shape = BoxShape.Default; prim.Shape = PrimitiveBaseShape.Default;
} }
createdObjects[new LLUUID(objID)].AddPart(prim); createdObjects[new LLUUID(objID)].AddPart(prim);
} }

View File

@ -265,7 +265,7 @@ namespace OpenSim.DataStore.MonoSqlite
{ {
MainLog.Instance.Notice( MainLog.Instance.Notice(
"No shape found for prim in storage, so setting default box shape"); "No shape found for prim in storage, so setting default box shape");
prim.Shape = BoxShape.Default; prim.Shape = PrimitiveBaseShape.Default;
} }
group.AddPart(prim); group.AddPart(prim);
group.RootPart = prim; group.RootPart = prim;
@ -285,7 +285,7 @@ namespace OpenSim.DataStore.MonoSqlite
{ {
MainLog.Instance.Notice( MainLog.Instance.Notice(
"No shape found for prim in storage, so setting default box shape"); "No shape found for prim in storage, so setting default box shape");
prim.Shape = BoxShape.Default; prim.Shape = PrimitiveBaseShape.Default;
} }
createdObjects[new LLUUID(objID)].AddPart(prim); createdObjects[new LLUUID(objID)].AddPart(prim);
} }