public static void AddVein(MyMwcObjectBuilder_VoxelMap builder, float thickness, Vector3 position, Random rnd, MyMwcVoxelMaterialsEnum material, float veinAngleDev, int maxLevel, int level = 0) { int numSplits = 2;// rnd.Next(2, 4); List<Vector3> targets = new List<Vector3>(numSplits); float handDist = thickness * 1.5f; for (int iSplit = 0; iSplit < numSplits; iSplit++) { // Hands per line int numHands = rnd.Next(8, 12); Vector3 direction = rnd.Direction(); Vector3 target = position; for (int i = 0; i < numHands; i++) { direction = rnd.Direction(direction, veinAngleDev); target += direction * handDist; // TODO: uncomment this to see material better (shown as tunnels, not only as voxel material) //var voxelHand = new MyMwcObjectBuilder_VoxelHand_Sphere(target, thickness - 1, MyMwcVoxelHandModeTypeEnum.SUBTRACT); //voxelHand.VoxelHandMaterial = material; //builder.VoxelHandShapes.Add(voxelHand); var voxelHand2 = new MyMwcObjectBuilder_VoxelHand_Sphere(new MyMwcPositionAndOrientation(target, Vector3.Forward, Vector3.Up), thickness, MyMwcVoxelHandModeTypeEnum.SET_MATERIAL); voxelHand2.VoxelHandMaterial = material; builder.VoxelHandShapes.Add(voxelHand2); } targets.Add(target); } if (level < maxLevel) { foreach (var t in targets) { AddVein(builder, thickness * 0.7f, t, rnd, material, veinAngleDev, maxLevel, level + 1); } } }
void AddAsteroidField(MySolarSystemMapEntity entity) { Vector3 areaPos = EntityPosition(entity, m_currentCamera); float areaRadius = KmToGameUnits(entity.Radius); float blendSizeLower = SectorToGameUnits(10000); float blendSizeUpper = SectorToGameUnits(150000); float minAsteroidFieldDist = SectorToGameUnits(20000); float maxAsteroidFieldDist = SectorToGameUnits(200000); // Size of billboards in fraction of whole size const float billboardSizeRatio = 0.2f; const int billboardsPerAsteroidField = 25; float radius = billboardSizeRatio * areaRadius; Random rnd = new Random(entity.Sector.X ^ entity.Sector.Y ^ entity.Sector.Z ^ (int)entity.PositionInSector.X ^ (int)entity.PositionInSector.Y ^ (int)entity.PositionInSector.Z); for (int i = 0; i < billboardsPerAsteroidField; i++) { Vector3 dir = rnd.Direction(); float maxDist = areaRadius - radius; Vector3 pos = areaPos + dir * maxDist; float dist = pos.Length(); float alphaLower = CalculateBlend(minAsteroidFieldDist, minAsteroidFieldDist + blendSizeLower, dist); float alphaUpper = 1 - CalculateBlend(maxAsteroidFieldDist, maxAsteroidFieldDist + blendSizeUpper, dist); float alpha = alphaLower * alphaUpper; if (alpha < float.Epsilon) { return; } Vector4 color = entity.Color.ToVector4(); color *= alpha; //color.W = alpha; /*if (dist < minAsteroidFieldDist || dist > maxAsteroidFieldDist) { return; }*/ MyTransparentGeometry.AddBillboardOriented(MyTransparentMaterialEnum.SolarMapAsteroidField, color, pos, m_currentCamera.Up, m_currentCamera.Left, radius, -2); } }