Exemplo n.º 1
0
        /// <summary>
        /// The AddPrimShape calls are pseudo synchronous by default.
        /// </summary>
        /// <param name="primName"></param>
        /// <param name="pbs"></param>
        /// <param name="position"></param>
        /// <param name="size"></param>
        /// <param name="rotation"></param>
        /// <returns></returns>
        public override PhysicsActor AddPrimShape(string primName, AddPrimShapeFlags flags, BulkShapeData shapeData)
        {
            Commands.CreateObjectCmd createObj = new Commands.CreateObjectCmd(
                null, primName, shapeData.Pbs, shapeData.Position, shapeData.Size, shapeData.Rotation, shapeData.Velocity,
                shapeData.AngularVelocity, Meshing.MeshingStage.SCULPT_MESH_LOD, flags, (Material)shapeData.Material,
                shapeData.PhysicsProperties, shapeData.SerializedShapes, shapeData.ObjectReceivedOn);

            this.QueueCommand(createObj);

            createObj.FinshedEvent.Wait(); //wait for meshing and all prerequisites to complete
            createObj.Dispose();

            return(createObj.FinalPrim);
        }
Exemplo n.º 2
0
        /*
         * public override PhysicsActor AddPrim(OpenMetaverse.Vector3 position, OpenMetaverse.Vector3 size, Quaternion rotation)
         * {
         *  return null;
         * }
         */

        public override PhysicsActor AddPrimShape(string primName, AddPrimShapeFlags flags, BulkShapeData shapeData)
        {
            return(null);
        }
Exemplo n.º 3
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();
            }
        }
Exemplo n.º 4
0
        public override PhysicsActor AddPrimShape(string primName, AddPrimShapeFlags flags, BulkShapeData shapeData)
        {
            byte[] serializedPhysicsProperties = shapeData.PhysicsProperties;
            BasicPhysicsProperties properties = BasicPhysicsProperties.DeserializeOrCreateNew(this, shapeData.Material, serializedPhysicsProperties);

            bool isPhysical = (flags & PhysicsScene.AddPrimShapeFlags.Physical) != 0;
            return new BasicPrim(this, shapeData.Pbs, shapeData.Position, shapeData.Rotation, /*Shape, Actor,*/ isPhysical, properties/*, collisionGroup*/);
        }