public override CollisionShape GetShape(ShapeCustomData sc)
        {
            var result = base.GetShape(sc);

            result.CalculateLocalInertia(this.Mass);
            return(result);
        }
Beispiel #2
0
        public void UpdateResource(IPluginOut ForPin, Device OnDevice)
        {
            if (this.FMeshes.ContainsKey(OnDevice))
            {
                this.FMeshes[OnDevice].Dispose();
                this.FMeshes.Remove(OnDevice);                // = null;
            }


            List <Mesh> meshes = new List <Mesh>();

            if (this.FBodies.SliceCount > 0)
            {
                int cnt = this.FBodies.SliceCount;

                for (int i = 0; i < cnt; i++)
                {
                    RigidBody       body  = this.FBodies[i];
                    CollisionShape  shape = body.CollisionShape;
                    ShapeCustomData sd    = (ShapeCustomData)shape.UserObject;
                    BulletMesh      m     = sd.ShapeDef.GetMesh(OnDevice);
                    meshes.AddRange(m.Meshes);
                }

                this.FMeshes.Add(OnDevice, Mesh.Concatenate(OnDevice, meshes.ToArray(), MeshFlags.Use32Bit | MeshFlags.Managed));
            }
        }
        public void Evaluate(int SpreadMax)
        {
            this.frameBodyOutput.Clear();
            IRigidBodyContainer world = this.worldInput[0];

            if (world != null)
            {
                this.persistedList.UpdateWorld(world);

                if (this.shapesInput.IsConnected)
                {
                    for (int i = 0; i < SpreadMax; i++)
                    {
                        if (doCreate[i])
                        {
                            RigidBodyPose pose = this.initialPoseInput.IsConnected ? this.initialPoseInput[i] : RigidBodyPose.Default;
                            RigidBodyProperties properties = this.initialProperties.IsConnected ? this.initialProperties[i] : RigidBodyProperties.Default;

                            ShapeCustomData shapeData = new ShapeCustomData();
                            shapeData.ShapeDef = this.shapesInput[i];

                            CollisionShape collisionShape = shapeData.ShapeDef.GetShape(shapeData);
                            Vector3 localInertia = Vector3.Zero;

                            Tuple<RigidBody, int> bodyCreateResult = world.CreateRigidBody(collisionShape, ref pose, ref properties, ref localInertia, 0.0f);
                            bodyCreateResult.Item1.CollisionFlags = CollisionFlags.StaticObject;

                            this.persistedList.Append(bodyCreateResult.Item1, bodyCreateResult.Item2);
                            frameBodyOutput.Add(bodyCreateResult.Item1);
                        }
                    }
                }

                this.bodiesOutput.SliceCount = this.persistedList.Bodies.Count;
                this.idOutput.SliceCount = this.persistedList.Ids.Count;

                List<RigidBody> bodies = this.persistedList.Bodies;
                List<int> ids = this.persistedList.Ids;

                for (int i = 0; i < bodies.Count; i++)
                {
                    this.bodiesOutput[i] = bodies[i];
                    this.idOutput[i] = ids[i];
                }

                this.createdBodiesOutput.SliceCount = this.frameBodyOutput.Count;
                for (int i = 0; i < frameBodyOutput.Count; i++)
                {
                    this.createdBodiesOutput[i] = frameBodyOutput[i];
                }
            }
            else
            {
                this.bodiesOutput.SliceCount = 0;
                this.idOutput.SliceCount = 0;
                this.createdBodiesOutput.SliceCount = 0;
            }
        }
        public virtual CollisionShape GetShape(ShapeCustomData sc)
        {
            CollisionShape shape = this.CreateShape();

            shape.LocalScaling = this.Scaling;
            sc.CustomString    = this.CustomString;

            shape.UserObject = sc;


            return(shape);
        }
        public void Evaluate(int SpreadMax)
        {
            this.frameBodyOutput.Clear();
            this.frameIdOutput.Clear();

            if (SpreadMax == 0)
            {
                this.bodiesOutput.SliceCount = 0;
                this.idOutput.SliceCount     = 0;
                return;
            }

            IRigidBodyContainer world = this.worldInput[0];

            if (world != null && this.shapesInput.IsConnected)
            {
                for (int i = 0; i < SpreadMax; i++)
                {
                    if (doCreate[i])
                    {
                        RigidBodyPose       pose       = this.initialPoseInput.IsConnected ? this.initialPoseInput[i] : RigidBodyPose.Default;
                        RigidBodyProperties properties = this.initialProperties.IsConnected ? this.initialProperties[i] : RigidBodyProperties.Default;

                        ShapeCustomData shapeData = new ShapeCustomData();
                        shapeData.ShapeDef = this.shapesInput[i];

                        CollisionShape collisionShape = shapeData.ShapeDef.GetShape(shapeData);
                        Vector3        localInertia   = Vector3.Zero;

                        Tuple <RigidBody, int> bodyCreateResult = world.CreateRigidBody(collisionShape, ref pose, ref properties, ref localInertia, 0.0f, this.customString[i]);
                        bodyCreateResult.Item1.CollisionFlags = CollisionFlags.StaticObject;

                        this.frameBodyOutput.Add(bodyCreateResult.Item1);
                        this.frameIdOutput.Add(bodyCreateResult.Item2);
                    }
                }

                this.bodiesOutput.SliceCount = this.frameBodyOutput.Count;
                this.idOutput.SliceCount     = this.frameIdOutput.Count;

                for (int i = 0; i < frameBodyOutput.Count; i++)
                {
                    this.bodiesOutput[i] = frameBodyOutput[i];
                    this.idOutput[i]     = frameIdOutput[i];
                }
            }
            else
            {
                this.bodiesOutput.SliceCount = 0;
                this.idOutput.SliceCount     = 0;
            }
        }
        protected override CollisionShape CreateShape()
        {
            CompoundShape shape = new CompoundShape();

            foreach (AbstractRigidShapeDefinition shapedef in this.children)
            {
                ShapeCustomData sc = new ShapeCustomData();
                sc.Id       = 0;
                sc.ShapeDef = shapedef;
                shape.AddChildShape((Matrix)shapedef.Pose, shapedef.GetShape(sc));
            }
            return(shape);
        }
        public void Evaluate(int SpreadMax)
        {
            int cnt = 0;

            for (int i = 0; i < SpreadMax; i++)
            {
                RigidBody       body  = this.FBodies[i];
                CollisionShape  shape = body.CollisionShape;
                ShapeCustomData sd    = (ShapeCustomData)shape.UserObject;

                cnt += sd.ShapeDef.ShapeCount;
            }
            this.FMeshOut.SliceCount = cnt;
        }
        public CollisionShape GetShape(ShapeCustomData sc)
        {
            CollisionShape shape = this.CreateShape();

            shape.LocalScaling = this.Scaling;
            sc.CustomString    = this.CustomString;
            if (sc.CustomObject != null)
            {
                sc.CustomObject = (ICloneable)this.CustomObject.Clone();
            }
            shape.UserObject = sc;
            shape.CalculateLocalInertia(this.Mass);

            return(shape);
        }
        protected override CollisionShape CreateShape()
        {
            CompoundShape shape = new CompoundShape();

            foreach (AbstractRigidShapeDefinition shapedef in this.children)
            {
                ShapeCustomData sc = new ShapeCustomData();
                sc.Id       = 0;
                sc.ShapeDef = shapedef;

                Matrix tr  = Matrix.Translation(shapedef.Translation);
                Matrix rot = Matrix.RotationQuaternion(shapedef.Rotation);

                shape.AddChildShape(Matrix.Multiply(rot, tr), shapedef.GetShape(sc));
            }
            return(shape);
        }
        public void Evaluate(int SpreadMax)
        {
            this.FType.SliceCount         = SpreadMax;
            this.FAABBMin.SliceCount      = SpreadMax;
            this.FAABBMax.SliceCount      = SpreadMax;
            this.FCustom.SliceCount       = SpreadMax;
            this.FHasCustomObj.SliceCount = SpreadMax;
            this.FCustomObj.SliceCount    = SpreadMax;
            this.FScaling.SliceCount      = SpreadMax;

            for (int i = 0; i < SpreadMax; i++)
            {
                CollisionShape shape = FShapes[i];

                ShapeCustomData sc = (ShapeCustomData)shape.UserObject;

                Vector3 min;
                Vector3 max;
                shape.GetAabb(Matrix.Identity, out min, out max);

                this.FAABBMin[i] = min.ToVVVVector();
                this.FAABBMax[i] = max.ToVVVVector();
                this.FScaling[i] = shape.LocalScaling.ToVVVVector();

                FType[i]        = shape.ShapeType;
                this.FCustom[i] = sc.CustomString;
                if (sc.CustomObject != null)
                {
                    this.FHasCustomObj[i] = true;
                    this.FCustomObj[i]    = sc.CustomObject;
                }
                else
                {
                    this.FHasCustomObj[i] = false;
                    this.FCustomObj[i]    = null;
                }
            }
        }
        //[Import()]
        //VVVV. FLog;


        public void Evaluate(int SpreadMax)
        {
            if (this.FBodies.PluginIO.IsConnected)
            {
                this.FId.SliceCount              = this.FBodies.SliceCount;
                this.FPosition.SliceCount        = this.FBodies.SliceCount;
                this.FRotation.SliceCount        = this.FBodies.SliceCount;
                this.FShapes.SliceCount          = this.FBodies.SliceCount;
                this.FCustom.SliceCount          = this.FBodies.SliceCount;
                this.FIsNew.SliceCount           = this.FBodies.SliceCount;
                this.FLinVel.SliceCount          = this.FBodies.SliceCount;
                this.FAngVel.SliceCount          = this.FBodies.SliceCount;
                this.FActive.SliceCount          = this.FBodies.SliceCount;
                this.FContactResponse.SliceCount = this.FBodies.SliceCount;
                this.FStatic.SliceCount          = this.FBodies.SliceCount;
                this.FKinematic.SliceCount       = this.FBodies.SliceCount;
                this.FShapeTransform.SliceCount  = this.FBodies.SliceCount;
                this.FHasCustomObj.SliceCount    = this.FBodies.SliceCount;
                this.FCustomObj.SliceCount       = this.FBodies.SliceCount;



                List <Matrix4x4> transforms = new List <Matrix4x4>();

                for (int i = 0; i < SpreadMax; i++)
                {
                    RigidBody body = this.FBodies[i];


                    this.FPosition[i] = new Vector3D(body.MotionState.WorldTransform.M41,
                                                     body.MotionState.WorldTransform.M42, body.MotionState.WorldTransform.M43);

                    Quaternion rot = body.Orientation;
                    this.FRotation[i] = new Vector4D(rot.X, rot.Y, rot.Z, rot.W);

                    this.FLinVel[i] = body.LinearVelocity.ToVVVVector();
                    this.FAngVel[i] = body.AngularVelocity.ToVVVVector();

                    CollisionShape shape = body.CollisionShape;

                    if (shape.IsCompound)
                    {
                        //CompoundShape sp = new CompoundShape(
                        CompoundShape comp = (CompoundShape)shape;
                        this.FShapes[i].SliceCount         = comp.NumChildShapes;
                        this.FShapeTransform[i].SliceCount = comp.NumChildShapes;


                        for (int j = 0; j < comp.NumChildShapes; j++)
                        {
                            CollisionShape child = comp.GetChildShape(j);

                            this.FShapes[i][j] = child;

                            Matrix m = comp.GetChildTransform(j);

                            Matrix4x4 mn = new Matrix4x4(m.M11, m.M12, m.M13, m.M14,
                                                         m.M21, m.M22, m.M23, m.M24, m.M31, m.M32, m.M33, m.M34,
                                                         m.M41, m.M42, m.M43, m.M44);

                            mn *= VMath.Scale(child.LocalScaling.ToVVVVector());
                            this.FShapeTransform[i][j] = mn;
                            //comp.
                            //comp.GetChildTransform(
                            //this.FShapes[i][j].
                        }
                    }
                    else
                    {
                        this.FShapes[i].SliceCount         = 1;
                        this.FShapes[i][0]                 = shape;
                        this.FShapeTransform[i].SliceCount = 1;



                        this.FShapeTransform[i][0] = VMath.Scale(shape.LocalScaling.ToVVVVector());
                        //transforms.Add(VMath.IdentityMatrix);
                    }


                    BodyCustomData bd = (BodyCustomData)body.UserObject;

                    ShapeCustomData sc = (ShapeCustomData)shape.UserObject;

                    this.FActive[i]          = body.IsActive;
                    this.FContactResponse[i] = body.HasContactResponse;
                    this.FStatic[i]          = body.IsStaticObject;
                    this.FKinematic[i]       = body.IsKinematicObject;


                    //this.FShapeCount[i] = sc.ShapeDef.ShapeCount;
                    this.FId[i]     = bd.Id;
                    this.FIsNew[i]  = bd.Created;
                    this.FCustom[i] = bd.Custom;

                    if (bd.CustomObject != null)
                    {
                        this.FHasCustomObj[i] = true;
                        this.FCustomObj[i]    = bd.CustomObject;
                    }
                    else
                    {
                        this.FHasCustomObj[i] = false;
                        this.FCustomObj[i]    = null;
                    }
                }

                //this.FShapeTransform.SliceCount = transforms.Count;
                //this.FShapeTransform.AssignFrom(transforms);
            }
            else
            {
                this.FId.SliceCount             = 0;
                this.FPosition.SliceCount       = 0;
                this.FRotation.SliceCount       = 0;
                this.FShapes.SliceCount         = 0;
                this.FCustom.SliceCount         = 0;
                this.FIsNew.SliceCount          = 0;
                this.FLinVel.SliceCount         = 0;
                this.FAngVel.SliceCount         = 0;
                this.FShapeTransform.SliceCount = 0;
            }
        }
Beispiel #12
0
        public override void Evaluate(int SpreadMax)
        {
            for (int i = 0; i < SpreadMax; i++)
            {
                if (this.CanCreate(i))
                {
                    wheelRadius       = FwheelRadius[0];
                    wheelWidth        = FwheelWidth[0];
                    CUBE_HALF_EXTENTS = FwheelDistance[0];

                    RaycastVehicle vehicle;

                    AbstractRigidShapeDefinition shapedef = this.FShapes[i];
                    ShapeCustomData sc = new ShapeCustomData();
                    sc.ShapeDef = shapedef;


                    CompoundShape compound = new CompoundShape();



                    CollisionShape chassisShape = shapedef.GetShape(sc);
                    Matrix         localTrans   = Matrix.Translation(Vector3.UnitY);
                    compound.AddChildShape(localTrans, chassisShape);

                    float mass = shapedef.Mass;

                    bool isDynamic = (mass != 0.0f);
                    isFrontWheel = true;

                    Vector3 localInertia = Vector3.Zero;
                    if (isDynamic)
                    {
                        chassisShape.CalculateLocalInertia(mass, out localInertia);
                    }

                    Vector3D pos = this.FPosition[i];
                    Vector4D rot = this.FRotation[i];

                    DefaultMotionState ms = BulletUtils.CreateMotionState(pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, rot.w);


                    RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, ms, compound, localInertia);
                    RigidBody carChassis             = new RigidBody(rbInfo);

                    BodyCustomData bd = new BodyCustomData();

                    carChassis.UserObject = bd;
                    bd.Id     = this.FWorld[0].GetNewBodyId();
                    bd.Custom = this.FCustom[i];

                    this.FWorld[0].Register(carChassis);


                    RaycastVehicle.VehicleTuning tuning           = new RaycastVehicle.VehicleTuning();
                    VehicleRaycaster             vehicleRayCaster = new DefaultVehicleRaycaster(this.FWorld[0].World);
                    vehicle = new RaycastVehicle(tuning, carChassis, vehicleRayCaster);



                    carChassis.ActivationState = ActivationState.DisableDeactivation;
                    this.FWorld[0].World.AddAction(vehicle);



                    // choose coordinate system
                    vehicle.SetCoordinateSystem(rightIndex, upIndex, forwardIndex);

                    Vector3   connectionPointCS0 = new Vector3(CUBE_HALF_EXTENTS - (0.3f * wheelWidth), FconnectionHeight[0], 2 * CUBE_HALF_EXTENTS - wheelRadius);
                    WheelInfo a = vehicle.AddWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, FsuspensionRestLength[0], wheelRadius, tuning, isFrontWheel);

                    connectionPointCS0 = new Vector3(-CUBE_HALF_EXTENTS + (0.3f * wheelWidth), FconnectionHeight[0], 2 * CUBE_HALF_EXTENTS - wheelRadius);
                    vehicle.AddWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, FsuspensionRestLength[0], wheelRadius, tuning, isFrontWheel);

                    isFrontWheel       = false;
                    connectionPointCS0 = new Vector3(-CUBE_HALF_EXTENTS + (0.3f * wheelWidth), FconnectionHeight[0], -2 * CUBE_HALF_EXTENTS + wheelRadius);
                    vehicle.AddWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, FsuspensionRestLength[0], wheelRadius, tuning, isFrontWheel);

                    connectionPointCS0 = new Vector3(CUBE_HALF_EXTENTS - (0.3f * wheelWidth), FconnectionHeight[0], -2 * CUBE_HALF_EXTENTS + wheelRadius);
                    vehicle.AddWheel(connectionPointCS0, wheelDirectionCS0, wheelAxleCS, FsuspensionRestLength[0], wheelRadius, tuning, isFrontWheel);


                    for (i = 0; i < vehicle.NumWheels; i++)
                    {
                        WheelInfo wheel = vehicle.GetWheelInfo(i);
                        wheel.SuspensionStiffness     = FsuspensionStiffness[0];
                        wheel.WheelDampingRelaxation  = FDampingRelaxation[0];
                        wheel.WheelDampingCompression = FDampingCompression[0];
                        wheel.FrictionSlip            = FwheelFriction[0];
                        wheel.RollInfluence           = FrollInfluence[0];
                        wheel.MaxSuspensionTravelCm   = FmaxSuspensionTravelCm[0];
                        wheel.MaxSuspensionForce      = FmaxSuspensionForce[0];
                    }

                    FOutVehicle.SliceCount = 1;
                    FOutVehicle[0]         = vehicle;
                }
            }
        }
        public void Evaluate(int SpreadMax)
        {
            this.frameBodyOutput.Clear();
            this.frameIdOutput.Clear();

            if (SpreadMax == 0)
            {
                this.bodiesOutput.SliceCount = 0;
                this.idOutput.SliceCount     = 0;
                return;
            }

            IRigidBodyContainer world = this.worldInput[0];

            if (world != null && this.shapesInput.IsConnected)
            {
                for (int i = 0; i < SpreadMax; i++)
                {
                    if (doCreate[i])
                    {
                        RigidBodyPose             pose             = this.initialPoseInput.IsConnected ? this.initialPoseInput[i] : RigidBodyPose.Default;
                        RigidBodyProperties       properties       = this.initialProperties.IsConnected ? this.initialProperties[i] : RigidBodyProperties.Default;
                        RigidBodyMotionProperties motionProperties = this.initialMotionProperties.IsConnected ? this.initialMotionProperties[i] : new RigidBodyMotionProperties();

                        ShapeCustomData            shapeData = new ShapeCustomData();
                        DynamicShapeDefinitionBase shape     = this.shapesInput[i];
                        shapeData.ShapeDef = shape;

                        CollisionShape collisionShape = shapeData.ShapeDef.GetShape(shapeData);

                        //Build mass for dynamic object
                        Vector3 localinertia = Vector3.Zero;
                        if (shape.Mass > 0.0f)
                        {
                            collisionShape.CalculateLocalInertia(shape.Mass, out localinertia);
                        }

                        Tuple <RigidBody, int> createBodyResult = world.CreateRigidBody(collisionShape, ref pose, ref properties, ref localinertia, shape.Mass);

                        createBodyResult.Item1.ApplyMotionProperties(ref motionProperties);

                        this.frameBodyOutput.Add(createBodyResult.Item1);
                        this.frameIdOutput.Add(createBodyResult.Item2);
                    }
                }

                this.bodiesOutput.SliceCount = this.frameBodyOutput.Count;
                this.idOutput.SliceCount     = this.frameIdOutput.Count;

                for (int i = 0; i < frameBodyOutput.Count; i++)
                {
                    this.bodiesOutput[i] = frameBodyOutput[i];
                    this.idOutput[i]     = frameIdOutput[i];
                }
            }
            else
            {
                this.bodiesOutput.SliceCount = 0;
                this.idOutput.SliceCount     = 0;
            }
        }
Beispiel #14
0
        public void Evaluate(int SpreadMax)
        {
            IRigidBulletWorld inputWorld = this.worldInput[0];

            SpreadMax = 1;

            if (inputWorld != null)
            {
                this.persistedList.UpdateWorld(inputWorld);

                if (this.chassisShape.IsConnected)
                {
                    for (int i = 0; i < SpreadMax; i++)
                    {
                        if (this.doCreate[i])
                        {
                            RigidBodyPose       initialPose = this.initialPoseInput.IsConnected ? this.initialPoseInput[i] : RigidBodyPose.Default;
                            RigidBodyProperties properties  = this.initialProperties.IsConnected ? this.initialProperties[i] : RigidBodyProperties.Default;

                            ShapeCustomData            shapeData = new ShapeCustomData();
                            DynamicShapeDefinitionBase chassisShapeDefinition = this.chassisShape[i];

                            CollisionShape chassisShape = chassisShapeDefinition.GetShape(shapeData);
                            shapeData.ShapeDef = chassisShapeDefinition;

                            RaycastVehicle vehicle;
                            CompoundShape  compoundShape = new CompoundShape();

                            Matrix localTrans = Matrix.Translation(Vector3.UnitY);
                            compoundShape.AddChildShape(localTrans, chassisShape);

                            //Build mass for dynamic object
                            Vector3 localInertia = Vector3.Zero;
                            if (chassisShapeDefinition.Mass > 0.0f)
                            {
                                compoundShape.CalculateLocalInertia(chassisShapeDefinition.Mass, out localInertia);
                            }

                            Tuple <RigidBody, int> createBodyResult = inputWorld.CreateRigidBody(chassisShape, ref initialPose, ref properties, ref localInertia, chassisShapeDefinition.Mass, this.customString[i]);
                            RigidBody carChassis = createBodyResult.Item1;

                            RaycastVehicle.VehicleTuning tuning           = new RaycastVehicle.VehicleTuning();
                            DefaultVehicleRaycaster      vehicleRayCaster = new DefaultVehicleRaycaster(inputWorld.World);
                            vehicle = new RaycastVehicle(tuning, carChassis, vehicleRayCaster);
                            vehicle.SetCoordinateSystem(rightIndex, upIndex, forwardIndex);

                            carChassis.ActivationState = ActivationState.DisableDeactivation;
                            inputWorld.World.AddAction(vehicle);

                            int wheelCount = this.wheelConstruction.SliceCount;

                            //Add wheels
                            for (int j = 0; j < this.wheelConstruction[i].SliceCount; j++)
                            {
                                WheelConstructionProperties wcs = this.wheelConstruction[i][j];
                                Vector3   connectionPointCS0    = wcs.localPosition.ToBulletVector();
                                WheelInfo wheel = vehicle.AddWheel(connectionPointCS0, wcs.wheelDirection.ToBulletVector(), wcs.wheelAxis.ToBulletVector(), wcs.SuspensionRestLength, wcs.WheelRadius, tuning, wcs.isFrontWheel);
                            }

                            //Set Wheel Properties
                            WheelProperties wis = this.wheelInfoSettings[i] != null ? this.wheelInfoSettings[i] : new WheelProperties();
                            for (int j = 0; j < vehicle.NumWheels; j++)
                            {
                                WheelInfo wheel = vehicle.GetWheelInfo(j);
                                wheel.SuspensionStiffness      = wis.SuspensionStiffness;
                                wheel.WheelsDampingRelaxation  = wis.WheelsDampingRelaxation;
                                wheel.WheelsDampingCompression = wis.WheelsDampingCompression;
                                wheel.FrictionSlip             = wis.FrictionSlip;
                                wheel.RollInfluence            = wis.RollInfluence;
                            }

                            BodyCustomData bd = (BodyCustomData)carChassis.UserObject;
                            bd.Vehicle = vehicle;

                            this.persistedList.Append(createBodyResult.Item1, createBodyResult.Item2);
                        }
                    }


                    List <RigidBody> bodies = this.persistedList.Bodies;
                    this.vehicleOutput.SliceCount = bodies.Count;
                    this.chassisOutput.SliceCount = bodies.Count;
                    for (int i = 0; i < bodies.Count; i++)
                    {
                        BodyCustomData bd = (BodyCustomData)bodies[i].UserObject;
                        this.vehicleOutput[i] = bd.Vehicle;
                        this.chassisOutput[i] = bodies[i];
                    }
                }
            }
            else
            {
                this.vehicleOutput.SliceCount = 0;
                this.chassisOutput.SliceCount = 0;
            }
        }
Beispiel #15
0
        public void Evaluate(int SpreadMax)
        {
            this.frameBodyOutput.Clear();

            IRigidBodyContainer inputWorld = this.worldInput[0];

            if (inputWorld != null)
            {
                this.persistedList.UpdateWorld(inputWorld);

                if (this.shapesInput.IsConnected)
                {
                    for (int i = 0; i < SpreadMax; i++)
                    {
                        if (doCreate[i])
                        {
                            RigidBodyPose             pose             = this.initialPoseInput.IsConnected ? this.initialPoseInput[i] : RigidBodyPose.Default;
                            RigidBodyProperties       properties       = this.initialProperties.IsConnected ? this.initialProperties[i] : RigidBodyProperties.Default;
                            RigidBodyMotionProperties motionProperties = this.initialMotionProperties.IsConnected ? this.initialMotionProperties[i] : new RigidBodyMotionProperties();

                            ShapeCustomData            shapeData = new ShapeCustomData();
                            DynamicShapeDefinitionBase shape     = this.shapesInput[i];
                            shapeData.ShapeDef = shape;

                            CollisionShape collisionShape = shapeData.ShapeDef.GetShape(shapeData);

                            //Build mass for dynamic object
                            Vector3 localinertia = Vector3.Zero;
                            if (shape.Mass > 0.0f)
                            {
                                collisionShape.CalculateLocalInertia(shape.Mass, out localinertia);
                            }

                            Tuple <RigidBody, int> createBodyResult = inputWorld.CreateRigidBody(collisionShape, ref pose, ref properties, ref localinertia, shape.Mass);
                            createBodyResult.Item1.CollisionFlags |= CollisionFlags.KinematicObject;

                            createBodyResult.Item1.ApplyMotionProperties(ref motionProperties);

                            this.persistedList.Append(createBodyResult.Item1, createBodyResult.Item2);
                            frameBodyOutput.Add(createBodyResult.Item1);
                        }
                    }
                }

                this.bodiesOutput.SliceCount = this.persistedList.Bodies.Count;
                this.idOutput.SliceCount     = this.persistedList.Ids.Count;

                List <RigidBody> bodies = this.persistedList.Bodies;
                List <int>       ids    = this.persistedList.Ids;

                for (int i = 0; i < bodies.Count; i++)
                {
                    this.bodiesOutput[i] = bodies[i];
                    this.idOutput[i]     = ids[i];
                }

                this.createdBodiesOutput.SliceCount = this.frameBodyOutput.Count;
                for (int i = 0; i < frameBodyOutput.Count; i++)
                {
                    this.createdBodiesOutput[i] = frameBodyOutput[i];
                }
            }
            else
            {
                this.bodiesOutput.SliceCount        = 0;
                this.idOutput.SliceCount            = 0;
                this.createdBodiesOutput.SliceCount = 0;
            }
        }
        protected RigidBody CreateBody(int i, out int id)
        {
            if (this.CanCreate(i))
            {
                AbstractRigidShapeDefinition shapedef = this.FShapes[i];

                ShapeCustomData sc = new ShapeCustomData();
                sc.ShapeDef = shapedef;

                Vector3D pos = this.FPosition[i];
                Vector4D rot = this.FRotation[i];

                DefaultMotionState ms = BulletUtils.CreateMotionState(pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, rot.w);

                CollisionShape shape = shapedef.GetShape(sc);


                Vector3 localinertia = Vector3.Zero;
                if (!this.FKinematic[i] && !this.FStatic[i])
                {
                    if (shapedef.Mass > 0.0f)
                    {
                        shape.CalculateLocalInertia(shapedef.Mass, out localinertia);
                    }
                }

                RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(shapedef.Mass,
                                                                                 ms, shape, localinertia);
                rbInfo.Friction    = this.FFriction[i];
                rbInfo.Restitution = this.FRestitution[i];

                RigidBody body = new RigidBody(rbInfo);

                if (!this.FActive[i])
                {
                    body.ActivationState |= ActivationState.DisableSimulation;
                }
                if (!this.FAllowSleep[i])
                {
                    body.ActivationState = ActivationState.DisableDeactivation;
                }


                body.LinearVelocity  = this.FLinearVelocity[i].ToBulletVector();
                body.AngularVelocity = this.FAngularVelocity[i].ToBulletVector();
                body.CollisionFlags  = CollisionFlags.None;

                if (!this.FContactResponse[i])
                {
                    body.CollisionFlags |= CollisionFlags.NoContactResponse;
                }
                if (this.FKinematic[i])
                {
                    body.CollisionFlags |= CollisionFlags.KinematicObject;
                }
                if (this.FStatic[i])
                {
                    body.CollisionFlags |= CollisionFlags.StaticObject;
                }

                BodyCustomData bd = new BodyCustomData();

                body.UserObject = bd;
                bd.Id           = this.FWorld[0].GetNewBodyId();
                bd.Custom       = this.FCustom[i];

                if (this.FCustomObj.PluginIO.IsConnected)
                {
                    bd.CustomObject = (ICloneable)this.FCustomObj[i].Clone();
                }
                else
                {
                    bd.CustomObject = null;
                }

                this.FWorld[0].Register(body);
                id = bd.Id;
                return(body);
            }
            else
            {
                id = -1;
                return(null);
            }
        }