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; } }
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; } }
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; } }