예제 #1
0
        internal List <PhysX.Shape> AssignToActor(PhysX.RigidActor actor, PhysX.Material material, PhysX.Math.Matrix localPose, bool physical)
        {
            switch (_shapeType)
            {
            case ShapeType.PrimitiveBox:
            case ShapeType.PrimitiveSphere:
                return(new List <PhysX.Shape> {
                    CreatePrimitiveShape(actor, material, ref localPose, physical)
                });

            case ShapeType.TriMesh:
                return(new List <PhysX.Shape> {
                    CreateTrimeshShape(actor, material, ref localPose)
                });

            case ShapeType.DecomposedConvexHulls:
            case ShapeType.SingleConvex:
                return(this.AssignHullsToActor(actor, material, localPose, physical));

            case ShapeType.Null:
                return(new List <PhysX.Shape>(0));

            default:
                throw new InvalidOperationException("Can not assign shape to actor: shapeType is missing or invalid");
            }
        }
예제 #2
0
        private PhysX.Shape CreateTrimeshShape(PhysX.RigidActor actor, PhysX.Material material, ref PhysX.Math.Matrix localPose)
        {
            PhysX.Shape shape = actor.CreateShape(_triMesh, material, localPose);
            shape.RestOffset = REST_OFFSET;

            return(shape);
        }
예제 #3
0
        private void SwapGroundActor(Tuple <PhysX.RigidActor, PhysX.Shape, PhysX.TriangleMesh> groundActor)
        {
            if (_groundActor != null)
            {
                _scene.RemoveActor(_groundActor);
                _groundActor.Dispose();

                if (!_groundShape.Disposed)
                {
                    _groundShape.Dispose();
                }

                _mesh.Dispose();
            }

            _groundActor = groundActor.Item1;
            _groundShape = groundActor.Item2;
            _mesh        = groundActor.Item3;

            _groundActor.UserData = this;

            CollisionGroup.SetCollisionGroup(CollisionGroupFlag.Ground, _groundShape);

            _scene.AddActor(_groundActor);
        }
예제 #4
0
        private PhysX.Shape CreatePrimitiveShape(PhysX.RigidActor actor, PhysX.Material material, ref PhysX.Math.Matrix localPose,
                                                 bool physical)
        {
            PhysX.Shape shape = actor.CreateShape(_primitiveGeom, material, localPose);
            shape.RestOffset = REST_OFFSET;

            if (physical && Settings.Instance.UseCCD)
            {
                //enable CCD
                shape.Flags |= PhysX.ShapeFlag.UseSweptBounds;
            }

            return(shape);
        }
예제 #5
0
        public void Dispose()
        {
            if (_groundActor != null)
            {
                _groundActor.Dispose();
                _groundActor = null;
            }

            if (_mesh != null)
            {
                _mesh.Dispose();
                _mesh = null;
            }
        }
예제 #6
0
        private List <PhysX.Shape> AssignHullsToActor(PhysX.RigidActor actor, PhysX.Material material, PhysX.Math.Matrix localPose,
                                                      bool physical)
        {
            List <PhysX.Shape> hulls = new List <PhysX.Shape>();

            foreach (PhysX.ConvexMeshGeometry geom in _convexHulls)
            {
                PhysX.Shape shape = actor.CreateShape(geom, material, localPose);
                shape.RestOffset = REST_OFFSET;

                if (physical && Settings.Instance.UseCCD)
                {
                    //enable CCD
                    shape.Flags |= PhysX.ShapeFlag.UseSweptBounds;
                }

                hulls.Add(shape);
            }

            return(hulls);
        }
예제 #7
0
        private void ChangeToChild(PhysxPrim parent, OpenMetaverse.Vector3 localPos, OpenMetaverse.Quaternion localRot)
        {
            _parentPrim = parent;

            //this prim no longer has its old shape or its actor
            _scene.PrimBecameChild(this);

            //if we have children, we need to unref their shapes here, as our new parent (ours and our children)
            //may require different shape types and will be rebuilt
            this.DeleteActor(_actor, _myShape, _isPhysical, DeleteActorFlags.UnrefChildShapes);

            _actor = null;
            _dynActor = null;
            _myShape = null;

            _position = localPos;
            _rotation = localRot;
        }
예제 #8
0
        public void Execute(PhysxScene scene)
        {
            if (Shape == null)
            {
                PhysicsProperties properties = PhysicsProperties.DeserializeOrCreateNew(scene, _material, _serializedPhysicsProperties);
                _hasVdSet = properties.VolumeDetectActive;

                scene.MeshingStageImpl.QueueForMeshing(_primName, _pbs, _size, _lod, 
                    (_flags & PhysicsScene.AddPrimShapeFlags.Physical) != 0 || _hasVdSet, 
                    _serializedPhysicsShapes,
                    (_flags & PhysxScene.AddPrimShapeFlags.FromCrossing) == PhysicsScene.AddPrimShapeFlags.FromCrossing,
                        delegate(PhysicsShape meshedShape)
                        {
                            Shape = meshedShape;
                            scene.QueueCommand(this);
                        }
                    );
            }
            else
            {
                bool isPhysical = (_flags & PhysicsScene.AddPrimShapeFlags.Physical) != 0;
                if (_hasVdSet)
                {
                    isPhysical = false;
                }

                CollisionGroupFlag collisionGroup = (_flags & PhysicsScene.AddPrimShapeFlags.Phantom) == 0 ? CollisionGroupFlag.Normal : CollisionGroupFlag.PhysicalPhantom;
                if (_parent == null)
                {
                    bool kinematicStatic;

                    PhysicsProperties properties = PhysicsProperties.DeserializeOrCreateNew(scene, _material, _serializedPhysicsProperties);

                    Actor = PhysxActorFactory.CreateProperInitialActor(Shape, scene, _position, _rotation, _flags, out kinematicStatic, properties.PhysxMaterial);

                    FinalPrim = new PhysxPrim(scene, _pbs, _position, _rotation, Shape, Actor, isPhysical, properties, collisionGroup);
                    scene.AddPrimSync(FinalPrim, isPhysical, kinematicStatic);
                }
                else
                {
                    PhysicsProperties properties = PhysicsProperties.DeserializeOrCreateNew(scene, _material, _serializedPhysicsProperties);

                    FinalPrim = new PhysxPrim(_parent, scene, _pbs, _position, _rotation, Shape, null, isPhysical, properties, collisionGroup);
                    _parent.LinkPrimAsChildSync(Shape, FinalPrim, _position, _rotation, false);
                }

                if (_hasVdSet)
                {
                    FinalPrim.SetVolumeDetectSync(true);
                }

                if ((_flags & PhysicsScene.AddPrimShapeFlags.StartSuspended) != 0)
                {
                    FinalPrim.SuspendPhysicsSync(_interpolateTime);
                }

                FinalPrim.DynamicsPostcheck();

                FinalPrim.SetInitialVelocities(_velocity, _angularVelocity);

                if ((_flags & PhysicsScene.AddPrimShapeFlags.Interpolate) != 0)
                {
                    FinalPrim.SuspendPhysicsSync(_interpolateTime);
                    FinalPrim.ResumePhysicsSync(true);
                }

                this.FinshedEvent.Set();
            }
        }
예제 #9
0
        public void Dispose()
        {
            if (_groundActor != null)
            {
                _groundActor.Dispose();
                _groundActor = null;
            }

            if (_mesh != null)
            {
                _mesh.Dispose();
                _mesh = null;
            }
        }
예제 #10
0
        private void SwapGroundActor(Tuple<PhysX.RigidActor, PhysX.Shape, PhysX.TriangleMesh> groundActor)
        {
            if (_groundActor != null)
            {
                _scene.RemoveActor(_groundActor);
                _groundActor.Dispose();

                if (!_groundShape.Disposed)
                {
                    _groundShape.Dispose();
                }

                _mesh.Dispose();
            }

            _groundActor = groundActor.Item1;
            _groundShape = groundActor.Item2;
            _mesh = groundActor.Item3;

            _groundActor.UserData = this;

            CollisionGroup.SetCollisionGroup(CollisionGroupFlag.Ground, _groundShape);

            _scene.AddActor(_groundActor);
        }
예제 #11
0
 private static void SetCommonProperties(PhysxScene scene, PhysicsShape shape, OpenMetaverse.Vector3 position, OpenMetaverse.Quaternion rotation, PhysX.RigidActor physActor,
                                         bool physical, Material material)
 {
     shape.AssignToActor(physActor, material.PhyMaterial, physical);
     physActor.GlobalPose =
         PhysX.Math.Matrix.RotationQuaternion(new PhysX.Math.Quaternion(rotation.X, rotation.Y, rotation.Z, rotation.W)) *
         PhysX.Math.Matrix.Translation(position.X, position.Y, position.Z);
 }
예제 #12
0
        private void GenerateActorsFromTrimesh(PhysX.TriangleMeshGeometry triangleMeshShapeDesc, out PhysX.RigidActor hfActor, out PhysX.Shape shape)
        {
            //PhysX.Math.Matrix.RotationYawPitchRoll(0f, (float)Math.PI / 2, 0f) * PhysX.Math.Matrix.Translation(0f, 0f, 0f)

            //PhysX.RigidDynamic dynActor = _scene.Physics.CreateRigidDynamic();
            //dynActor.Flags |= PhysX.RigidDynamicFlags.Kinematic;
            //hfActor = dynActor;

            hfActor = _scene.Physics.CreateRigidStatic();

            shape = hfActor.CreateShape(triangleMeshShapeDesc, Material.GROUND.PhyMaterial);
        }
예제 #13
0
        private void GenerateActorsFromMeshStream(Stream ms, out PhysX.TriangleMesh triangleMesh, out PhysX.RigidActor hfActor, out PhysX.Shape shape)
        {
            triangleMesh = _scene.Physics.CreateTriangleMesh(ms);
            PhysX.TriangleMeshGeometry triangleMeshShapeDesc = new PhysX.TriangleMeshGeometry(triangleMesh);

            GenerateActorsFromTrimesh(triangleMeshShapeDesc, out hfActor, out shape);
        }
예제 #14
0
        private void AssignActor(PhysX.RigidActor myActor, PhysicsShape newShape, bool isPhysical, DeleteActorFlags flags)
        {
            PhysX.RigidActor oldActor = _actor;
            PhysicsShape oldShape = null;
            
            if (newShape != null)
            {
                oldShape = _myShape;
                _myShape = newShape;
            }

            _actor = myActor;
            
            if (_actor != null && _actor is PhysX.RigidDynamic)
            {
                _dynActor = (PhysX.RigidDynamic)_actor;
                CacheMassData();
            }
            else
            {
                _dynActor = null;
            }

            bool wasPhysical = _isPhysical;
            _isPhysical = isPhysical;

            if (HasActor) _scene.SceneImpl.AddActor(_actor);       //add to physx scene
            this.DeleteActor(oldActor, oldShape, wasPhysical, flags);

            if (_actor != null)
            {
                _actor.UserData = this;
                this.IndexAndConfigurePrimaryShapes();
            }

            ClearForcesAndSendUpdate();
            ChangeGravityIfNeeded();
        }
예제 #15
0
 internal List <PhysX.Shape> AssignToActor(PhysX.RigidActor actor, PhysX.Material material, bool physical)
 {
     return(AssignToActor(actor, material, PhysX.Math.Matrix.Identity, physical));
 }
예제 #16
0
        public void Execute(PhysxScene scene)
        {
            bool isPhysical = (_flags & PhysicsScene.AddPrimShapeFlags.Physical) != 0;

            if (_rootHasVdSet)
            {
                isPhysical = false;
            }

            if (_newPrimaryShape == null)
            {
                bool first = true;
                foreach (BulkShapeData shape in _shapes)
                {
                    BulkShapeData   thisShape = shape;
                    SceneObjectPart thisPart  = (SceneObjectPart)thisShape.Part;
                    String          primName  = String.Empty;
                    if (thisPart != null)
                    {
                        primName = thisPart.Name;
                    }
                    if (first)
                    {
                        _primaryShapeData = thisShape;
                        PhysicsProperties properties = PhysicsProperties.DeserializeOrCreateNew(scene, shape.Material, shape.PhysicsProperties);
                        _rootHasVdSet = properties.VolumeDetectActive;

                        if (_rootHasVdSet)
                        {
                            isPhysical = false;
                        }

                        scene.MeshingStageImpl.QueueForMeshing(primName, shape.Pbs, shape.Size, Meshing.MeshingStage.SCULPT_MESH_LOD,
                                                               isPhysical || _rootHasVdSet, shape.SerializedShapes,
                                                               (_flags& PhysxScene.AddPrimShapeFlags.FromCrossing) == PhysicsScene.AddPrimShapeFlags.FromCrossing,
                                                               delegate(PhysicsShape meshedShape)
                        {
                            _newPrimaryShape = meshedShape;
                            _meshedShapes.Add(thisShape, meshedShape);
                            if (++_meshedSoFar == _totalNumShapes)
                            {
                                scene.QueueCommand(this);
                            }
                        }
                                                               );

                        first = false;
                    }
                    else
                    {
                        scene.MeshingStageImpl.QueueForMeshing(primName, shape.Pbs, shape.Size, Meshing.MeshingStage.SCULPT_MESH_LOD,
                                                               isPhysical || _rootHasVdSet, shape.SerializedShapes,
                                                               (_flags& PhysxScene.AddPrimShapeFlags.FromCrossing) == PhysicsScene.AddPrimShapeFlags.FromCrossing,
                                                               delegate(PhysicsShape meshedShape)
                        {
                            _meshedShapes.Add(thisShape, meshedShape);
                            if (++_meshedSoFar == _totalNumShapes)
                            {
                                scene.QueueCommand(this);
                            }
                        }
                                                               );
                    }
                }
            }
            else
            {
                OpenMetaverse.Vector3 rootVelocity        = OpenMetaverse.Vector3.Zero;
                OpenMetaverse.Vector3 rootAngularVelocity = OpenMetaverse.Vector3.Zero;

                //we have all the shapes for the parent and all children, time to construct the group
                bool      first    = true;
                PhysxPrim rootPrim = null;

                CollisionGroupFlag collisionGroup = (_flags & PhysicsScene.AddPrimShapeFlags.Phantom) == 0 ? CollisionGroupFlag.Normal : CollisionGroupFlag.PhysicalPhantom;
                foreach (BulkShapeData shape in _shapes)
                {
                    if (first)
                    {
                        bool kinematicStatic;

                        PhysicsProperties properties = PhysicsProperties.DeserializeOrCreateNew(scene, shape.Material, shape.PhysicsProperties);

                        PhysX.RigidActor actor = PhysxActorFactory.CreateProperInitialActor(_newPrimaryShape, scene, shape.Position, shape.Rotation, _flags, out kinematicStatic,
                                                                                            properties.PhysxMaterial);

                        rootPrim = new PhysxPrim(scene, shape.Pbs, shape.Position, shape.Rotation, _newPrimaryShape, actor,
                                                 isPhysical, properties, collisionGroup);

                        scene.AddPrimSync(rootPrim, isPhysical, kinematicStatic);

                        shape.OutActor = rootPrim;

                        rootVelocity        = shape.Velocity;
                        rootAngularVelocity = shape.AngularVelocity;

                        first = false;
                    }
                    else
                    {
                        PhysicsShape phyShape = _meshedShapes[shape];

                        PhysicsProperties properties = PhysicsProperties.DeserializeOrCreateNew(scene, shape.Material, shape.PhysicsProperties);

                        PhysxPrim childPrim = new PhysxPrim(rootPrim, scene, shape.Pbs, shape.Position, shape.Rotation, phyShape,
                                                            null, isPhysical, properties, collisionGroup);
                        rootPrim.LinkPrimAsChildSync(phyShape, childPrim, shape.Position, shape.Rotation, true);

                        shape.OutActor = childPrim;
                    }
                }

                rootPrim.UpdateMassAndInertia();

                if (_rootHasVdSet)
                {
                    rootPrim.SetVolumeDetectSync(_rootHasVdSet);
                }

                if ((_flags & PhysicsScene.AddPrimShapeFlags.StartSuspended) != 0)
                {
                    rootPrim.SuspendPhysicsSync(_primaryShapeData.ObjectReceivedOn);
                }

                rootPrim.DynamicsPostcheck();

                rootPrim.SetInitialVelocities(rootVelocity, rootAngularVelocity);

                if ((_flags & PhysicsScene.AddPrimShapeFlags.Interpolate) != 0)
                {
                    rootPrim.SuspendPhysicsSync(_primaryShapeData.ObjectReceivedOn);
                    rootPrim.ResumePhysicsSync(true);
                }

                FinishedEvent.Set();
            }
        }
예제 #17
0
        public void Execute(PhysxScene scene)
        {
            if (Shape == null)
            {
                PhysicsProperties properties = PhysicsProperties.DeserializeOrCreateNew(scene, _material, _serializedPhysicsProperties);
                _hasVdSet = properties.VolumeDetectActive;

                scene.MeshingStageImpl.QueueForMeshing(_primName, _pbs, _size, _lod,
                                                       (_flags& PhysicsScene.AddPrimShapeFlags.Physical) != 0 || _hasVdSet,
                                                       _serializedPhysicsShapes,
                                                       (_flags& PhysxScene.AddPrimShapeFlags.FromCrossing) == PhysicsScene.AddPrimShapeFlags.FromCrossing,
                                                       delegate(PhysicsShape meshedShape)
                {
                    Shape = meshedShape;
                    scene.QueueCommand(this);
                }
                                                       );
            }
            else
            {
                bool isPhysical = (_flags & PhysicsScene.AddPrimShapeFlags.Physical) != 0;
                if (_hasVdSet)
                {
                    isPhysical = false;
                }

                CollisionGroupFlag collisionGroup = (_flags & PhysicsScene.AddPrimShapeFlags.Phantom) == 0 ? CollisionGroupFlag.Normal : CollisionGroupFlag.PhysicalPhantom;
                if (_parent == null)
                {
                    bool kinematicStatic;

                    PhysicsProperties properties = PhysicsProperties.DeserializeOrCreateNew(scene, _material, _serializedPhysicsProperties);

                    Actor = PhysxActorFactory.CreateProperInitialActor(Shape, scene, _position, _rotation, _flags, out kinematicStatic, properties.PhysxMaterial);

                    FinalPrim = new PhysxPrim(scene, _pbs, _position, _rotation, Shape, Actor, isPhysical, properties, collisionGroup);
                    scene.AddPrimSync(FinalPrim, isPhysical, kinematicStatic);
                }
                else
                {
                    PhysicsProperties properties = PhysicsProperties.DeserializeOrCreateNew(scene, _material, _serializedPhysicsProperties);

                    FinalPrim = new PhysxPrim(_parent, scene, _pbs, _position, _rotation, Shape, null, isPhysical, properties, collisionGroup);
                    _parent.LinkPrimAsChildSync(Shape, FinalPrim, _position, _rotation, false);
                }

                if (_hasVdSet)
                {
                    FinalPrim.SetVolumeDetectSync(true);
                }

                if ((_flags & PhysicsScene.AddPrimShapeFlags.StartSuspended) != 0)
                {
                    FinalPrim.SuspendPhysicsSync(_interpolateTime);
                }

                FinalPrim.DynamicsPostcheck();

                FinalPrim.SetInitialVelocities(_velocity, _angularVelocity);

                if ((_flags & PhysicsScene.AddPrimShapeFlags.Interpolate) != 0)
                {
                    FinalPrim.SuspendPhysicsSync(_interpolateTime);
                    FinalPrim.ResumePhysicsSync(true);
                }

                this.FinshedEvent.Set();
            }
        }