/// <summary> /// This returns a random ball that will fit well with the handle passed in /// </summary> public static WeaponSpikeBallDNA GetRandomDNA(WeaponHandleDNA handle) { WeaponSpikeBallDNA retVal = new WeaponSpikeBallDNA(); Random rand = StaticRandom.GetRandomForThread(); // Radius retVal.Radius = GetRandomRadius(handle.Radius, handle.Length); #region Material // Choose a ball material that goes with the handle's material //NOTE: This is assuming that the ball is an appropriate radius for the handle it will be attached to. //A large soft wood could safely handle a very small ball, etc WeaponSpikeBallMaterial[] ballMaterials = null; switch (handle.HandleMaterial) { case WeaponHandleMaterial.Soft_Wood: ballMaterials = new[] { WeaponSpikeBallMaterial.Wood, WeaponSpikeBallMaterial.Composite }; break; case WeaponHandleMaterial.Hard_Wood: ballMaterials = new[] { WeaponSpikeBallMaterial.Wood, WeaponSpikeBallMaterial.Bronze_Iron, WeaponSpikeBallMaterial.Iron_Steel, WeaponSpikeBallMaterial.Composite, WeaponSpikeBallMaterial.Klinth }; break; case WeaponHandleMaterial.Bronze: case WeaponHandleMaterial.Iron: case WeaponHandleMaterial.Steel: ballMaterials = new[] { WeaponSpikeBallMaterial.Bronze_Iron, WeaponSpikeBallMaterial.Iron_Steel, WeaponSpikeBallMaterial.Moon }; break; case WeaponHandleMaterial.Composite: ballMaterials = new[] { WeaponSpikeBallMaterial.Bronze_Iron, WeaponSpikeBallMaterial.Iron_Steel, WeaponSpikeBallMaterial.Composite, WeaponSpikeBallMaterial.Klinth, WeaponSpikeBallMaterial.Moon }; break; case WeaponHandleMaterial.Klinth: ballMaterials = new[] { WeaponSpikeBallMaterial.Bronze_Iron, WeaponSpikeBallMaterial.Iron_Steel, WeaponSpikeBallMaterial.Klinth, WeaponSpikeBallMaterial.Moon }; break; case WeaponHandleMaterial.Moon: ballMaterials = new[] { WeaponSpikeBallMaterial.Iron_Steel, WeaponSpikeBallMaterial.Klinth, WeaponSpikeBallMaterial.Moon }; break; default: throw new ApplicationException("Unknown WeaponHandleMaterial: " + handle.HandleMaterial.ToString()); } // Choose one from the filtered list retVal.Material = rand.NextItem(ballMaterials); #endregion #region Color ColorHSV?basedOn = null; if (handle.MaterialsForCustomizable != null && handle.MaterialsForCustomizable.Length > 0 && !string.IsNullOrEmpty(handle.MaterialsForCustomizable[0].DiffuseColor)) { basedOn = UtilityWPF.ColorFromHex(handle.MaterialsForCustomizable[0].DiffuseColor).ToHSV(); } switch (retVal.Material) { case WeaponSpikeBallMaterial.Composite: retVal.MaterialsForCustomizable = WeaponHandleDNA.GetRandomMaterials_Composite(null, basedOn); break; case WeaponSpikeBallMaterial.Klinth: retVal.MaterialsForCustomizable = WeaponHandleDNA.GetRandomMaterials_Klinth(null, basedOn); break; } #endregion return(retVal); }
private static void GetModel_Rod_Composite(Model3DGroup geometries, WeaponHandleDNA dna, WeaponHandleDNA finalDNA, WeaponMaterialCache materials) { Random rand = StaticRandom.GetRandomForThread(); finalDNA.MaterialsForCustomizable = WeaponHandleDNA.GetRandomMaterials_Composite(dna.MaterialsForCustomizable); var from = dna.KeyValues; var to = finalDNA.KeyValues; double halfLength = dna.Length / 2d; double halfBeamThickness = dna.Radius / 8d; double halfCoreThickness = (dna.Radius * .66d) / 2d; double washerRadius = dna.Radius * 1.1; double washerThickness1 = WeaponDNA.GetKeyValue("washerThickness1", from, to, dna.Length * rand.NextPercent(.015d, .5d)); double washerThickness2 = WeaponDNA.GetKeyValue("washerThickness2", from, to, dna.Length * rand.NextPercent(.15d, .5d)); double washerOffset = WeaponDNA.GetKeyValue("washerOffset", from, to, rand.NextPercent(.05d, .5d)); var material = GetModel_Rod_Composite_Material(finalDNA.MaterialsForCustomizable[0]); //NOTE: The beam/core dimensions shouldn't be randomized. This should look like a manufactured, almost mass produced product #region beams // Beam1 GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-halfLength, -dna.Radius, -halfBeamThickness), new Point3D(halfLength, dna.Radius, halfBeamThickness)); geometries.Children.Add(geometry); // Beam2 geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-halfLength, -halfBeamThickness, -dna.Radius), new Point3D(halfLength, halfBeamThickness, dna.Radius)); geometries.Children.Add(geometry); #endregion #region core material = GetModel_Rod_Composite_Material(finalDNA.MaterialsForCustomizable[1]); geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetCube_IndependentFaces(new Point3D(-halfLength, -halfCoreThickness, -halfCoreThickness), new Point3D(halfLength, halfCoreThickness, halfCoreThickness)); geometry.Transform = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), 45)); geometries.Children.Add(geometry); #endregion #region washers material = GetModel_Rod_Composite_Material(finalDNA.MaterialsForCustomizable[2]); var locations = new Tuple <double, double>[] { Tuple.Create(0d, washerThickness1), Tuple.Create(washerOffset, washerThickness1), Tuple.Create(.5d, washerThickness2), Tuple.Create(1d - washerOffset, washerThickness1), Tuple.Create(1d, washerThickness1) }; foreach (var loc in locations) { geometry = new GeometryModel3D(); geometry.Material = material; geometry.BackMaterial = material; geometry.Geometry = UtilityWPF.GetCylinder_AlongX(8, washerRadius, loc.Item2); geometry.Transform = new TranslateTransform3D(-halfLength + (dna.Length * loc.Item1), 0, 0); geometries.Children.Add(geometry); } #endregion }