示例#1
0
        public override PhysicsActor AddAvatar(string avName, Vector3 position, Quaternion rotation, Vector3 size,
                                               bool isFlying, uint localID, UUID UUID)
        {
            if (!m_initialized)
            {
                return(null);
            }

            BSCharacter actor = new BSCharacter(localID, avName, this, position, size, isFlying);

            actor.UUID = UUID;
            lock (PhysObjects)
                PhysObjects.Add(localID, actor);

            // TODO: Remove kludge someday.
            // We must generate a collision for avatars whether they collide or not.
            // This is required by WhiteCore to update avatar animations, etc.
            lock (m_avatars)
                m_avatars.Add(actor);

            return(actor);
        }
示例#2
0
        public override void RemoveAvatar(PhysicsActor actor)
        {
            // MainConsole.Instance.DebugFormat("{0}: RemoveAvatar", LogHeader);

            if (!m_initialized)
            {
                return;
            }

            BSCharacter bsactor = actor as BSCharacter;

            if (bsactor != null)
            {
                try
                {
                    lock (PhysObjects)
                        PhysObjects.Remove(bsactor.LocalID);
                    // Remove kludge someday
                    lock (m_avatars)
                        m_avatars.Remove(bsactor);
                }
                catch (Exception e)
                {
                    MainConsole.Instance.WarnFormat("{0}: Attempt to remove avatar that is not in physics scene: {1}",
                                                    LogHeader, e);
                }
                bsactor.Destroy();
                // bsactor.dispose();
            }
            else
            {
                MainConsole.Instance.ErrorFormat(
                    "{0}: Requested to remove avatar that is not a BSCharacter. ID={1}, type={2}",
                    LogHeader, actor.LocalID, actor.GetType().Name);
            }
        }
示例#3
0
        public override PhysicsActor AddAvatar(string avName, Vector3 position, Quaternion rotation, Vector3 size,
            bool isFlying, uint localID, UUID UUID)
        {
            if (!m_initialized) return null;

            BSCharacter actor = new BSCharacter(localID, avName, this, position, size, isFlying);
            actor.UUID = UUID;
            lock (PhysObjects)
                PhysObjects.Add(localID, actor);

            // TODO: Remove kludge someday.
            // We must generate a collision for avatars whether they collide or not.
            // This is required by WhiteCore to update avatar animations, etc.
            lock (m_avatars)
                m_avatars.Add(actor);

            return actor;
        }
        bool CreateGeom(bool forceRebuild, BSPhysObject prim, PhysicalDestructionCallback shapeCallback)
        {
            bool ret                 = false;
            bool haveShape           = false;
            bool nativeShapePossible = true;
            PrimitiveBaseShape pbs   = prim.BaseShape;

            // Kludge to create the capsule for the avatar.
            // TODO: Remove/redo this when BSShapeAvatar is working!!
            BSCharacter theChar = prim as BSCharacter;

            if (theChar != null)
            {
                DereferenceExistingShape(prim, shapeCallback);
                switch (BSParam.AvatarShape)
                {
                case AvatarShapeCapsule:
                    prim.PhysShape = BSShapeNative.GetReference(PhysicsScene, prim, BSPhysicsShapeType.SHAPE_CAPSULE,
                                                                FixedShapeKey.KEY_CAPSULE);
                    ret       = true;
                    haveShape = true;
                    break;

                case AvatarShapeCube:
                    prim.PhysShape = BSShapeNative.GetReference(PhysicsScene, prim, BSPhysicsShapeType.SHAPE_BOX,
                                                                FixedShapeKey.KEY_CAPSULE);
                    ret       = true;
                    haveShape = true;
                    break;

                case AvatarShapeOvoid:
                    // Saddly, Bullet doesn't scale spheres so this doen't work as an avatar shape
                    prim.PhysShape = BSShapeNative.GetReference(PhysicsScene, prim, BSPhysicsShapeType.SHAPE_SPHERE,
                                                                FixedShapeKey.KEY_CAPSULE);
                    ret       = true;
                    haveShape = true;
                    break;

                case AvatarShapeMesh:
                    break;

                default:
                    break;
                }
            }

            // If the prim attributes are simple, this could be a simple Bullet native shape
            // Native shapes work whether to object is static or physical.
            if (!haveShape && nativeShapePossible && pbs != null && PrimHasNoCuts(pbs) &&
                (!pbs.SculptEntry || (pbs.SculptEntry && !BSParam.ShouldMeshSculptedPrim)))
            {
                // Get the scale of any existing shape so we can see if the new shape is same native type and same size.
                OMV.Vector3 scaleOfExistingShape = OMV.Vector3.Zero;
                if (prim.PhysShape.HasPhysicalShape)
                {
                    scaleOfExistingShape = PhysicsScene.PE.GetLocalScaling(prim.PhysShape.physShapeInfo);
                }
                if (DDetail)
                {
                    DetailLog(
                        "{0},BSShapeCollection.CreateGeom,maybeNative,force={1},primScale={2},primSize={3},primShape={4}",
                        prim.LocalID, forceRebuild, prim.Scale, prim.Size, prim.PhysShape.physShapeInfo.shapeType);
                }

                // It doen't look like Bullet scales native spheres so make sure the scales are all equal
                if ((pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1) &&
                    pbs.Scale.X == pbs.Scale.Y && pbs.Scale.Y == pbs.Scale.Z)
                {
                    haveShape = true;
                    if (forceRebuild || prim.PhysShape.ShapeType != BSPhysicsShapeType.SHAPE_SPHERE)
                    {
                        DereferenceExistingShape(prim, shapeCallback);
                        prim.PhysShape = BSShapeNative.GetReference(PhysicsScene, prim, BSPhysicsShapeType.SHAPE_SPHERE,
                                                                    FixedShapeKey.KEY_SPHERE);
                        ret = true;
                    }
                    if (DDetail)
                    {
                        DetailLog("{0},BSShapeCollection.CreateGeom,sphere,force={1},rebuild={2},shape={3}",
                                  prim.LocalID, forceRebuild, ret, prim.PhysShape);
                    }
                }
                // If we didn't make a sphere, maybe a box will work.
                if (!haveShape && pbs.ProfileShape == ProfileShape.Square && pbs.PathCurve == (byte)Extrusion.Straight)
                {
                    haveShape = true;
                    if (forceRebuild || prim.Scale != scaleOfExistingShape ||
                        prim.PhysShape.ShapeType != BSPhysicsShapeType.SHAPE_BOX)
                    {
                        DereferenceExistingShape(prim, shapeCallback);
                        prim.PhysShape = BSShapeNative.GetReference(PhysicsScene, prim, BSPhysicsShapeType.SHAPE_BOX,
                                                                    FixedShapeKey.KEY_BOX);
                        ret = true;
                    }
                    if (DDetail)
                    {
                        DetailLog("{0},BSShapeCollection.CreateGeom,box,force={1},rebuild={2},shape={3}", prim.LocalID,
                                  forceRebuild, ret, prim.PhysShape);
                    }
                }
            }

            // If a simple shape is not happening, create a mesh and possibly a hull.
            if (!haveShape && pbs != null)
            {
                ret = CreateGeomMeshOrHull(prim, shapeCallback);
            }

            return(ret);
        }