Пример #1
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();
            }
        }
Пример #2
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();
            }
        }