internal override float SignedDistance(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { Vector3 localPosition = position - m_translation; Vector3.Transform(ref localPosition, ref m_invRotation, out localPosition); var primaryDistance = new Vector2(localPosition.X, localPosition.Z).Length() - m_primaryRadius; var signedDistance = new Vector2(primaryDistance, localPosition.Y).Length() - m_secondaryRadius; var potentialHalfDeviation = m_potentialHalfDeviation + lodVoxelSize; if (signedDistance > potentialHalfDeviation) return 1f; else if (signedDistance < -potentialHalfDeviation) return -1f; if (m_enableModulation) { Debug.Assert(m_deviationFrequency != 0f); float normalizer = 0.5f * m_deviationFrequency; var tmp = localPosition * normalizer; float halfDeviationRatio = (float)macroModulator.GetValue(tmp.X, tmp.Y, tmp.Z); signedDistance -= halfDeviationRatio * m_secondaryHalfDeviation; } if (m_enableModulation && -m_detailSize < signedDistance && signedDistance < m_detailSize) { Debug.Assert(m_detailFrequency != 0f); float normalizer = 0.5f * m_detailFrequency; var tmp = localPosition * normalizer; signedDistance += m_detailSize * (float)detailModulator.GetValue(tmp.X, tmp.Y, tmp.Z); } return signedDistance / lodVoxelSize; }
public MyCsgShapePlanet(Vector3 translation, ref MyCsgShapePlanetShapeAttributes shapeAttributes, ref MyCsgShapePlanetHillAttributes hillAttributes, ref MyCsgShapePlanetHillAttributes canyonAttributes, float deviationFrequency = 0, float detailFrequency = 0) { m_translation = translation; m_shapeAttributes = shapeAttributes; m_hillAttributes = hillAttributes; m_canyonAttributes = canyonAttributes; m_canyonBlendTreshold = m_canyonAttributes.Treshold + m_canyonAttributes.BlendTreshold; m_hillBlendTreshold = m_hillAttributes.Treshold - m_hillAttributes.BlendTreshold; m_shapeAttributes.Radius = (shapeAttributes.Diameter / 2.0f) * (1 - shapeAttributes.DeviationScale * m_hillAttributes.SizeRatio); m_shapeAttributes.Diameter = m_shapeAttributes.Radius * 2.0f; m_halfDeviation = (shapeAttributes.Diameter / 2.0f) * shapeAttributes.DeviationScale; m_deviationFrequency = deviationFrequency; m_detailFrequency = detailFrequency; m_hillHalfDeviation = m_halfDeviation * m_hillAttributes.SizeRatio; m_canyonHalfDeviation = m_halfDeviation * m_canyonAttributes.SizeRatio; m_enableModulation = true; m_hillModule = new MyCompositeNoise(hillAttributes.NumNoises, hillAttributes.Frequency / m_shapeAttributes.Radius); ComputeDerivedProperties(); }
public MyTerrace(IMyModule module, bool invert = false) { Module = module; Invert = invert; ControlPoints = new List<double>(2); }
public MyAdd(IMyModule sourceModule1, IMyModule sourceModule2) { System.Diagnostics.Debug.Assert(sourceModule1 != null && sourceModule2 != null); Source1 = sourceModule1; Source2 = sourceModule2; }
public MyCompositeLayeredOreDeposit(MyCsgShapeBase shape, MyMaterialLayer[] materialLayers,IMyModule noise, MyCompositeOrePlanetDeposit oresDeposits) : base(shape, null) { m_materialLayers = materialLayers; m_noise = noise; m_oreDeposits = oresDeposits; }
internal override float SignedDistance(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { var pa = position - m_pointA; var ba = m_pointB - m_pointA; float h = MathHelper.Clamp(pa.Dot(ref ba) / ba.LengthSquared(), 0.0f, 1.0f); float signedDistance = (pa - ba * h).Length() - m_radius; var potentialHalfDeviation = m_potentialHalfDeviation + lodVoxelSize; if (signedDistance > potentialHalfDeviation) return 1f; else if (signedDistance < -potentialHalfDeviation) return -1f; if (m_enableModulation) { Debug.Assert(m_deviationFrequency != 0f); var halfDeviationRatio = (float)macroModulator.GetValue( position.X * m_deviationFrequency, position.Y * m_deviationFrequency, position.Z * m_deviationFrequency); signedDistance -= halfDeviationRatio * m_halfDeviation; } if (m_enableModulation && -m_detailSize < signedDistance && signedDistance < m_detailSize) { Debug.Assert(m_detailFrequency != 0f); signedDistance += m_detailSize * (float)detailModulator.GetValue( position.X * m_detailFrequency, position.Y * m_detailFrequency, position.Z * m_detailFrequency); } return signedDistance / lodVoxelSize; }
internal override float SignedDistance(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { #if USE_CORRECT_COMPUTATION // The only difference between SignedDistanceUnchecked() and SignedDistance() is that the latter clamps the result. return MathHelper.Clamp(SignedDistanceUnchecked(ref position, lodVoxelSize, macroModulator, detailModulator), -1f, 1f); #else // This attempts to optimize queries by detecting cases where the result would be clamped. // Given simple distance computation performed here, it's actually slower than computing distance and clamping the result, // but if noise was applied to the result, this culling can save a lot. However, it can also hide incorrect distance // computation, so before optimizing, be sure clamp variant above works correctly. ContainmentType outerContainment, innerContainment; BoundingBox box = BoundingBox.CreateFromHalfExtent(m_translation, m_halfExtents + lodVoxelSize); box.Contains(ref position, out outerContainment); if (outerContainment == ContainmentType.Disjoint) return 1; box = BoundingBox.CreateFromHalfExtent(m_translation, m_halfExtents - lodVoxelSize); box.Contains(ref position, out innerContainment); if (innerContainment == ContainmentType.Contains) return -1; return SignedDistanceUnchecked(ref position, lodVoxelSize, macroModulator, detailModulator); #endif }
internal override float SignedDistance(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { Vector3 localPosition = position - m_translation; float distance = localPosition.Length(); if ((m_innerRadius - lodVoxelSize) > distance) return -1f; if ((m_outerRadius + lodVoxelSize) < distance) return 1f; float halfDeviationRatio; if (m_enableModulation) { Debug.Assert(m_deviationFrequency != 0f); float normalizer = m_deviationFrequency * m_radius / distance; var tmp = localPosition * normalizer; halfDeviationRatio = (float)macroModulator.GetValue(tmp.X, tmp.Y, tmp.Z); } else { halfDeviationRatio = 0f; } float signedDistance = distance - m_radius - halfDeviationRatio * m_halfDeviation; if (m_enableModulation && -m_detailSize < signedDistance && signedDistance < m_detailSize) { Debug.Assert(m_detailFrequency != 0f); float normalizer = m_detailFrequency * m_radius / distance; var tmp = localPosition * normalizer; signedDistance += m_detailSize * (float)detailModulator.GetValue(tmp.X, tmp.Y, tmp.Z); } return signedDistance / lodVoxelSize; }
public MyCsgShapePlanet(MyRandom random, Vector3 translation, ref MyCsgShapePlanetShapeAttributes shapeAttributes, ref MyCsgShapePlanetHillAttributes hillAttributes, ref MyCsgShapePlanetHillAttributes canyonAttributes, float deviationFrequency = 0, float detailFrequency = 0) { m_translation = translation; m_random = random; m_shapeAttributes = shapeAttributes; m_hillAttributes = hillAttributes; m_canyonAttributes = canyonAttributes; m_canyonBlendTreshold = m_canyonAttributes.Treshold + m_canyonAttributes.BlendTreshold; m_hillBlendTreshold = m_hillAttributes.Treshold - m_hillAttributes.BlendTreshold; m_shapeAttributes.Radius = (shapeAttributes.Radius/2.0f) * (1 - shapeAttributes.DeviationScale * m_hillAttributes.SizeRatio); m_halfDeviation = (shapeAttributes.Radius / 2.0f) * shapeAttributes.DeviationScale; m_deviationFrequency = deviationFrequency; m_detailFrequency = detailFrequency; m_hillHalfDeviation = m_halfDeviation * m_hillAttributes.SizeRatio; m_canyonHalfDeviation = m_halfDeviation * m_canyonAttributes.SizeRatio; m_enableModulation = true; m_hillModule = new MyCompositeNoise(hillAttributes.NumNoises, hillAttributes.Frequency / m_shapeAttributes.Radius, random); m_canyonModule = new MyCompositeNoise(canyonAttributes.NumNoises, canyonAttributes.Frequency / m_shapeAttributes.Radius, random); m_normalModule = new MySimplexFast(seed: random.Next(), frequency: shapeAttributes.NormalNoiseFrequency / m_shapeAttributes.Radius); ComputeDerivedProperties(); }
private float SignedDistanceInternal(float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator, ref Vector3 localPosition, float distance) { float halfDeviationRatio; if (m_enableModulation) { Debug.Assert(m_deviationFrequency != 0f); float normalizer = m_deviationFrequency * m_radius / distance; var tmp = localPosition * normalizer; halfDeviationRatio = (float)macroModulator.GetValue(tmp.X, tmp.Y, tmp.Z); } else { halfDeviationRatio = 0f; } float signedDistance = distance - m_radius - halfDeviationRatio * m_halfDeviation; if (m_enableModulation && -m_detailSize < signedDistance && signedDistance < m_detailSize) { Debug.Assert(m_detailFrequency != 0f); float normalizer = m_detailFrequency * m_radius / distance; var tmp = localPosition * normalizer; signedDistance += m_detailSize * (float)detailModulator.GetValue(tmp.X, tmp.Y, tmp.Z); } return signedDistance / lodVoxelSize; }
internal override float SignedDistanceUnchecked(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { Vector3 localPosition = position - m_translation; float distance = localPosition.Length(); return SignedDistanceInternal(lodVoxelSize, distance); }
internal override float SignedDistance(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { if (m_exclusionSphere.SignedDistance(ref position, 0, macroModulator, detailModulator) < 0.0f) { return float.MaxValue; } return m_sphere.SignedDistance(ref position, lodVoxelSize, macroModulator, detailModulator); }
public MyPower(IMyModule baseModule, IMyModule powerModule, double powerOffset = 0.0) { System.Diagnostics.Debug.Assert(baseModule != null && powerModule != null); Base = baseModule; Power = powerModule; this.powerOffset = powerOffset; }
public MyBinarize(IMyModule module, double threshold = 0.0) { System.Diagnostics.Debug.Assert(module != null); Threshold = threshold; Module = module; }
public MyExponent(IMyModule module, double exponent = 2.0) { System.Diagnostics.Debug.Assert(module != null); Exponent = exponent; Module = module; }
public MyCurve(IMyModule module) { System.Diagnostics.Debug.Assert(module != null); Module = module; ControlPoints = new List<MyCurveControlPoint>(4); }
public MyBendFilter(IMyModule module, double clampRangeMin, double clampRangeMax, double outOfRangeMin, double outOfRangeMax) { this.Module = module; this.m_rangeSizeInverted = 1.0/(clampRangeMax - clampRangeMin); this.m_clampingMin = clampRangeMin; this.m_clampingMax = clampRangeMax; this.OutOfRangeMin = outOfRangeMin; this.OutOfRangeMax = outOfRangeMax; }
public MyClamp(IMyModule module, double lowerBound = -1.0, double upperBound = 1.0) { System.Diagnostics.Debug.Assert(module != null); LowerBound = lowerBound; UpperBound = upperBound; Module = module; }
public MyBlend(IMyModule sourceModule1, IMyModule sourceModule2, IMyModule weight) { System.Diagnostics.Debug.Assert(sourceModule1 != null && sourceModule2 != null && weight != null); Source1 = sourceModule1; Source2 = sourceModule2; Weight = weight; }
internal override float SignedDistance(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { Vector3 localPosition = position - m_translation; float distance = localPosition.Length(); if ((m_innerRadius - lodVoxelSize) > distance) return -1f; if ((m_outerRadius + lodVoxelSize) < distance) return 1f; return SignedDistanceInternal(lodVoxelSize, macroModulator, detailModulator, ref localPosition, distance); }
internal override float SignedDistance(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { Vector3 localPosition = position - m_translation; float distance = localPosition.Length(); if ((m_radius - lodVoxelSize) > distance) return -1f; if ((m_radius + lodVoxelSize) < distance) return 1f; float signedDistance = distance - m_radius; return signedDistance / lodVoxelSize; }
internal override float SignedDistance(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { var pa = position - m_pointA; var ba = m_pointB - m_pointA; float h = MathHelper.Clamp(pa.Dot(ref ba) / ba.LengthSquared(), 0.0f, 1.0f); float signedDistance = (pa - ba * h).Length() - m_radius; var potentialHalfDeviation = m_potentialHalfDeviation + lodVoxelSize; if (signedDistance > potentialHalfDeviation) return 1f; else if (signedDistance < -potentialHalfDeviation) return -1f; return SignedDistanceInternal(ref position, lodVoxelSize, macroModulator, detailModulator, ref signedDistance); }
internal override float SignedDistance(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { Vector3 localPosition = position - m_translation; Vector3.Transform(ref localPosition, ref m_invRotation, out localPosition); var primaryDistance = new Vector2(localPosition.X, localPosition.Z).Length() - m_primaryRadius; var signedDistance = new Vector2(primaryDistance, localPosition.Y).Length() - m_secondaryRadius; var potentialHalfDeviation = m_potentialHalfDeviation + lodVoxelSize; if (signedDistance > potentialHalfDeviation) return 1f; else if (signedDistance < -potentialHalfDeviation) return -1f; return SignedDistanceInternal(lodVoxelSize, macroModulator, detailModulator, ref localPosition, ref signedDistance); }
internal override float SignedDistanceUnchecked(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { #if USE_CORRECT_COMPUTATION // Correct computation of signed distance from the surface of box (based on materials by Iñigo Quilez). // Does not apply noise or anything. Just simple distance. var relPos = position - m_translation; var d = Vector3.Abs(relPos) - m_halfExtents; float signedDistance = Math.Min(Math.Max(d.X, Math.Max(d.Y, d.Z)), 0f) + (Vector3.Max(d, Vector3.Zero)).Length(); return signedDistance / lodVoxelSize; #else // Incorrect, since Clamp will not modify the position when it's inside // the box, resulting in -0f for all values inside, which is not correct distance. var min = m_translation - m_halfExtents; var max = m_translation + m_halfExtents; var box = new BoundingBox(min, max); var clamp = Vector3.Clamp(position, min, max); float sign = box.Contains(position) == ContainmentType.Contains ? -1 : 1; float distance = sign * Vector3.Distance(clamp, position); return distance / lodVoxelSize; #endif }
private float SignedDistanceInternal(float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator, ref Vector3 localPosition, ref float signedDistance) { if (m_enableModulation) { Debug.Assert(m_deviationFrequency != 0f); float normalizer = 0.5f * m_deviationFrequency; var tmp = localPosition * normalizer; float halfDeviationRatio = (float)macroModulator.GetValue(tmp.X, tmp.Y, tmp.Z); signedDistance -= halfDeviationRatio * m_secondaryHalfDeviation; } if (m_enableModulation && -m_detailSize < signedDistance && signedDistance < m_detailSize) { Debug.Assert(m_detailFrequency != 0f); float normalizer = 0.5f * m_detailFrequency; var tmp = localPosition * normalizer; signedDistance += m_detailSize * (float)detailModulator.GetValue(tmp.X, tmp.Y, tmp.Z); } return signedDistance / lodVoxelSize; }
private float SignedDistanceInternal(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator, ref float signedDistance) { if (m_enableModulation) { Debug.Assert(m_deviationFrequency != 0f); var halfDeviationRatio = (float)macroModulator.GetValue( position.X * m_deviationFrequency, position.Y * m_deviationFrequency, position.Z * m_deviationFrequency); signedDistance -= halfDeviationRatio * m_halfDeviation; } if (m_enableModulation && -m_detailSize < signedDistance && signedDistance < m_detailSize) { Debug.Assert(m_detailFrequency != 0f); signedDistance += m_detailSize * (float)detailModulator.GetValue( position.X * m_detailFrequency, position.Y * m_detailFrequency, position.Z * m_detailFrequency); } return signedDistance / lodVoxelSize; }
private void GenerateObject(MyProceduralCell cell, MyObjectSeed objectSeed, ref int index, MyRandom random, IMyModule densityFunctionFilled, IMyModule densityFunctionRemoved) { cell.AddObject(objectSeed); switch (objectSeed.Type) { case MyObjectSeedType.Asteroid: break; case MyObjectSeedType.AsteroidCluster: objectSeed.Type = MyObjectSeedType.Asteroid; m_tmpClusterBoxes.Add(objectSeed.BoundingVolume); for (int i = 0; i < OBJECT_MAX_IN_CLUSTER; ++i) { var direction = MyProceduralWorldGenerator.GetRandomDirection(random); var size = GetClusterObjectSize(random.NextDouble()); var distance = MathHelper.Lerp(OBJECT_MIN_DISTANCE_CLUSTER, OBJECT_MAX_DISTANCE_CLUSTER, random.NextDouble()); var clusterObjectPosition = objectSeed.BoundingVolume.Center + direction * (size + objectSeed.BoundingVolume.HalfExtents.Length() * 2 + distance); ProfilerShort.Begin("Density functions"); double valueRemoved = -1; if (densityFunctionRemoved != null) { valueRemoved = densityFunctionRemoved.GetValue(clusterObjectPosition.X, clusterObjectPosition.Y, clusterObjectPosition.Z); if (valueRemoved <= -1) { ProfilerShort.End(); continue; } } var valueFilled = densityFunctionFilled.GetValue(clusterObjectPosition.X, clusterObjectPosition.Y, clusterObjectPosition.Z); if (densityFunctionRemoved != null) { if (valueRemoved < valueFilled) { ProfilerShort.End(); continue; } } ProfilerShort.End(); if (valueFilled < OBJECT_DENSITY_CLUSTER) // -1..+1 { var clusterObjectSeed = new MyObjectSeed(cell, clusterObjectPosition, size); clusterObjectSeed.Seed = random.Next(); clusterObjectSeed.Index = index++; clusterObjectSeed.Type = GetClusterSeedType(random.NextDouble()); bool overlaps = false; foreach (var box in m_tmpClusterBoxes) { if (overlaps |= clusterObjectSeed.BoundingVolume.Intersects(box)) { break; } } if (!overlaps) { m_tmpClusterBoxes.Add(clusterObjectSeed.BoundingVolume); GenerateObject(cell, clusterObjectSeed, ref index, random, densityFunctionFilled, densityFunctionRemoved); } } } m_tmpClusterBoxes.Clear(); break; case MyObjectSeedType.EncounterAlone: case MyObjectSeedType.EncounterSingle: case MyObjectSeedType.EncounterMulti: break; default: throw new InvalidBranchException(); break; } }
internal override float SignedDistance(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { var pa = position - m_pointA; var ba = m_pointB - m_pointA; float h = MathHelper.Clamp(pa.Dot(ref ba) / ba.LengthSquared(), 0.0f, 1.0f); float signedDistance = (pa - ba * h).Length() - m_radius; var potentialHalfDeviation = m_potentialHalfDeviation + lodVoxelSize; if (signedDistance > potentialHalfDeviation) { return(1f); } else if (signedDistance < -potentialHalfDeviation) { return(-1f); } return(SignedDistanceInternal(ref position, lodVoxelSize, macroModulator, detailModulator, ref signedDistance)); }
private float SignedDistanceInternal(float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator, ref Vector3 localPosition, float distance) { if (distance > 0.0f) { float signedDistance = distance - m_averageRadius; Vector3I samplePos; Vector2 pos = Vector2.Zero; MyCsgPrecomputedHelpres.CalculateSamplePosition(ref localPosition, out samplePos, ref pos, m_header.Resolution); float value = GetValueForPosition(ref samplePos, ref pos, true); return((signedDistance - value) / lodVoxelSize); } return(0.0f); }
internal override float SignedDistanceUnchecked(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { Vector3 localPosition = position - m_translation; Vector3.Transform(ref localPosition, ref m_invRotation, out localPosition); var primaryDistance = new Vector2(localPosition.X, localPosition.Z).Length() - m_primaryRadius; var signedDistance = new Vector2(primaryDistance, localPosition.Y).Length() - m_secondaryRadius; return SignedDistanceInternal(lodVoxelSize, macroModulator, detailModulator, ref localPosition, ref signedDistance); }
private void GenerateObject(MyProceduralCell cell, MyObjectSeed objectSeed, ref int index, MyRandom random, IMyModule densityFunctionFilled, IMyModule densityFunctionRemoved) { cell.AddObject(objectSeed); IMyAsteroidFieldDensityFunction func = objectSeed.UserData as IMyAsteroidFieldDensityFunction; if (func != null) { ChildrenAddDensityFunctionRemoved(func); } switch (objectSeed.Type) { case MyObjectSeedType.Moon: break; case MyObjectSeedType.Planet: m_tmpClusterBoxes.Add(objectSeed.BoundingVolume); for (int i = 0; i < MOONS_MAX; ++i) { var direction = GetRandomDirection(random); var size = MathHelper.Lerp(MOON_SIZE_MIN, MOON_SIZE_MAX, random.NextDouble()); var distance = MathHelper.Lerp(MOON_DISTANCE_MIN, MOON_DISTANCE_MAX, random.NextDouble()); var position = objectSeed.BoundingVolume.Center + direction * (size + objectSeed.BoundingVolume.HalfExtents.Length() * 2 + distance); ProfilerShort.Begin("GetValue"); var value = densityFunctionFilled.GetValue(position.X, position.Y, position.Z); ProfilerShort.End(); if (value < MOON_DENSITY) // -1..+1 { var clusterObjectSeed = new MyObjectSeed(cell, position, size); clusterObjectSeed.Seed = random.Next(); clusterObjectSeed.Type = MyObjectSeedType.Moon; clusterObjectSeed.Index = index++; clusterObjectSeed.UserData = new MySphereDensityFunction(position, OBJECT_SEED_RADIUS, OBJECT_SEED_RADIUS); bool overlaps = false; foreach (var box in m_tmpClusterBoxes) { if (overlaps |= clusterObjectSeed.BoundingVolume.Intersects(box)) { break; } } if (!overlaps) { m_tmpClusterBoxes.Add(clusterObjectSeed.BoundingVolume); GenerateObject(cell, clusterObjectSeed, ref index, random, densityFunctionFilled, densityFunctionRemoved); } } } m_tmpClusterBoxes.Clear(); break; case MyObjectSeedType.Empty: break; default: throw new InvalidBranchException(); break; } }
public MyPower(IMyModule baseModule, IMyModule powerModule, double powerOffset = 0.0) { Base = baseModule; Power = powerModule; this.powerOffset = powerOffset; }
public MyInvert(IMyModule module) { System.Diagnostics.Debug.Assert(module != null); Module = module; }
public MyBinarize(IMyModule module, double threshold = 0.0) { Threshold = threshold; Module = module; }
public MySinus(IMyModule module) { this.module = module; }
public MyMultiply(IMyModule sourceModule1, IMyModule sourceModule2) { Source1 = sourceModule1; Source2 = sourceModule2; }
internal override float SignedDistance(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { Vector3 localPosition = position - m_translation; float distance = localPosition.Length(); if ((m_radius - lodVoxelSize) > distance) { return(-1f); } if ((m_radius + lodVoxelSize) < distance) { return(1f); } float signedDistance = distance - m_radius; return(signedDistance / lodVoxelSize); }
private void GenerateObject(MyProceduralCell cell, MyObjectSeed objectSeed, ref int index, MyRandom random, IMyModule densityFunctionFilled, IMyModule densityFunctionRemoved) { cell.AddObject(objectSeed); IMyAsteroidFieldDensityFunction func = objectSeed.UserData as IMyAsteroidFieldDensityFunction; if (func != null) { ChildrenAddDensityFunctionRemoved(func); } switch (objectSeed.Params.Type) { case MyObjectSeedType.Moon: break; case MyObjectSeedType.Planet: m_tmpClusterBoxes.Add(objectSeed.BoundingVolume); for (int i = 0; i < MOONS_MAX; ++i) { var direction = MyProceduralWorldGenerator.GetRandomDirection(random); var size = MathHelper.Lerp(MOON_SIZE_MIN, MOON_SIZE_MAX, random.NextDouble()); var distance = MathHelper.Lerp(MOON_DISTANCE_MIN, MOON_DISTANCE_MAX, random.NextDouble()); var position = objectSeed.BoundingVolume.Center + direction * (size + objectSeed.BoundingVolume.HalfExtents.Length() * 2 + distance); ProfilerShort.Begin("GetValue"); var value = densityFunctionFilled.GetValue(position.X, position.Y, position.Z); ProfilerShort.End(); if (value < MOON_DENSITY) // -1..+1 { var clusterObjectSeed = new MyObjectSeed(cell, position, size); clusterObjectSeed.Params.Seed = random.Next(); clusterObjectSeed.Params.Type = MyObjectSeedType.Moon; clusterObjectSeed.Params.Index = index++; clusterObjectSeed.UserData = new MySphereDensityFunction(position, MOON_SIZE_MAX / 2.0 * GRAVITY_SIZE_MULTIPLIER + FALLOFF, FALLOFF); bool overlaps = false; foreach (var box in m_tmpClusterBoxes) { if (overlaps |= clusterObjectSeed.BoundingVolume.Intersects(box)) { break; } } if (!overlaps) { m_tmpClusterBoxes.Add(clusterObjectSeed.BoundingVolume); GenerateObject(cell, clusterObjectSeed, ref index, random, densityFunctionFilled, densityFunctionRemoved); } } } m_tmpClusterBoxes.Clear(); break; case MyObjectSeedType.Empty: break; default: throw new InvalidBranchException(); break; } }
internal override float SignedDistance(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { if (m_exclusionSphere.SignedDistance(ref position, 0, macroModulator, detailModulator) < 0.0f) { return(float.MaxValue); } return(m_sphere.SignedDistance(ref position, lodVoxelSize, macroModulator, detailModulator)); }
internal override float SignedDistanceUnchecked(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { var pa = position - m_pointA; var ba = m_pointB - m_pointA; float h = MathHelper.Clamp(pa.Dot(ref ba) / ba.LengthSquared(), 0.0f, 1.0f); float signedDistance = (pa - ba * h).Length() - m_radius; return(SignedDistanceInternal(ref position, lodVoxelSize, macroModulator, detailModulator, ref signedDistance)); }
protected override MyProceduralCell GenerateProceduralCell(ref VRageMath.Vector3I cellId) { MyProceduralCell cell = new MyProceduralCell(cellId, this); ProfilerShort.Begin("GenerateObjectSeedsCell"); IMyModule densityFunctionFilled = GetCellDensityFunctionFilled(cell.BoundingVolume); if (densityFunctionFilled == null) { ProfilerShort.End(); return(null); } IMyModule densityFunctionRemoved = GetCellDensityFunctionRemoved(cell.BoundingVolume); int cellSeed = GetCellSeed(ref cellId); var random = MyRandom.Instance; using (random.PushSeed(cellSeed)) { int index = 0; Vector3I subCellId = Vector3I.Zero; Vector3I max = new Vector3I(SUBCELLS - 1); for (var iter = new Vector3I.RangeIterator(ref Vector3I.Zero, ref max); iter.IsValid(); iter.GetNext(out subCellId)) { // there is a bug in the position calculation which can very rarely cause overlaping objects but backwards compatibility so meh Vector3D position = new Vector3D(random.NextDouble(), random.NextDouble(), random.NextDouble()); position += (Vector3D)subCellId / SUBCELL_SIZE; position += cellId; position *= CELL_SIZE; if (!MyEntities.IsInsideWorld(position)) { continue; } ProfilerShort.Begin("Density functions"); double valueRemoved = -1; if (densityFunctionRemoved != null) { valueRemoved = densityFunctionRemoved.GetValue(position.X, position.Y, position.Z); if (valueRemoved <= -1) { ProfilerShort.End(); continue; } } var valueFilled = densityFunctionFilled.GetValue(position.X, position.Y, position.Z); if (densityFunctionRemoved != null) { if (valueRemoved < valueFilled) { ProfilerShort.End(); continue; } } ProfilerShort.End(); if (valueFilled < m_objectDensity) // -1..+1 { var objectSeed = new MyObjectSeed(cell, position, GetObjectSize(random.NextDouble())); objectSeed.Type = GetSeedType(random.NextDouble()); objectSeed.Seed = random.Next(); objectSeed.Index = index++; GenerateObject(cell, objectSeed, ref index, random, densityFunctionFilled, densityFunctionRemoved); } } } ProfilerShort.End(); return(cell); }
private float SignedDistanceInternal(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator, ref float signedDistance) { if (base.m_enableModulation) { float num = (float)macroModulator.GetValue((double)(position.X * this.m_deviationFrequency), (double)(position.Y * this.m_deviationFrequency), (double)(position.Z * this.m_deviationFrequency)); signedDistance -= num * this.m_halfDeviation; } if ((base.m_enableModulation && (-base.m_detailSize < signedDistance)) && (signedDistance < base.m_detailSize)) { signedDistance += base.m_detailSize * ((float)detailModulator.GetValue((double)(position.X * this.m_detailFrequency), (double)(position.Y * this.m_detailFrequency), (double)(position.Z * this.m_detailFrequency))); } return(signedDistance / lodVoxelSize); }
public MyRemapTo01(IMyModule module) { this.Module = module; }
private void GenerateObject(MyProceduralCell cell, MyObjectSeed objectSeed, ref int index, MyRandom random, IMyModule densityFunction) { cell.AddObject(objectSeed); switch (objectSeed.Type) { case MyObjectSeedType.Asteroid: m_asteroidSeedCount++; break; case MyObjectSeedType.AsteroidCluster: objectSeed.Type = MyObjectSeedType.Asteroid; m_asteroidSeedCount++; m_tmpClusterBoxes.Add(objectSeed.BoundingVolume); for (int j = 0; j < OBJECT_MAX_IN_CLUSTER; ++j) { var direction = GetRandomDirection(random); var size = GetClusterObjectSize(random.NextDouble()); var distance = MathHelper.Lerp(OBJECT_MIN_DISTANCE_CLUSTER, OBJECT_MAX_DISTANCE_CLUSTER, random.NextDouble()); var clusterObjectPosition = objectSeed.BoundingVolume.Center + direction * (size + objectSeed.BoundingVolume.HalfExtents.Length() * 2 + distance); ProfilerShort.Begin("GetValue"); var value = densityFunction.GetValue(clusterObjectPosition.X, clusterObjectPosition.Y, clusterObjectPosition.Z); ProfilerShort.End(); if (value < OBJECT_DENSITY_CLUSTER) // -1..+1 { var clusterObjectSeed = new MyObjectSeed(cell, clusterObjectPosition, size); clusterObjectSeed.Seed = random.Next(); clusterObjectSeed.Index = index++; clusterObjectSeed.Type = GetClusterSeedType(random.NextDouble()); bool overlaps = false; foreach (var box in m_tmpClusterBoxes) { if (overlaps |= clusterObjectSeed.BoundingVolume.Intersects(box)) { break; } } if (!overlaps) { m_tmpClusterBoxes.Add(clusterObjectSeed.BoundingVolume); GenerateObject(cell, clusterObjectSeed, ref index, random, densityFunction); } } } m_tmpClusterBoxes.Clear(); break; case MyObjectSeedType.EncounterAlone: case MyObjectSeedType.EncounterSingle: case MyObjectSeedType.EncounterMulti: m_encounterSeedCount++; break; default: throw new InvalidBranchException(); break; } }
public MyCurve(IMyModule module) { Module = module; ControlPoints = new List <MyCurveControlPoint>(4); }
internal override float SignedDistanceUnchecked(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { #if USE_CORRECT_COMPUTATION // Correct computation of signed distance from the surface of box (based on materials by Iñigo Quilez). // Does not apply noise or anything. Just simple distance. var relPos = position - m_translation; var d = Vector3.Abs(relPos) - m_halfExtents; float signedDistance = Math.Min(Math.Max(d.X, Math.Max(d.Y, d.Z)), 0f) + (Vector3.Max(d, Vector3.Zero)).Length(); return(signedDistance / lodVoxelSize); #else // Incorrect, since Clamp will not modify the position when it's inside // the box, resulting in -0f for all values inside, which is not correct distance. var min = m_translation - m_halfExtents; var max = m_translation + m_halfExtents; var box = new BoundingBox(min, max); var clamp = Vector3.Clamp(position, min, max); float sign = box.Contains(position) == ContainmentType.Contains ? -1 : 1; float distance = sign * Vector3.Distance(clamp, position); return(distance / lodVoxelSize); #endif }
public MyCylinder(IMyModule module) { Module = module; }
public MyBlend(IMyModule sourceModule1, IMyModule sourceModule2, IMyModule weight) { Source1 = sourceModule1; Source2 = sourceModule2; Weight = weight; }
internal abstract float SignedDistance(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator);
private float SignedDistanceInternal(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator, ref float signedDistance) { if (m_enableModulation) { Debug.Assert(m_deviationFrequency != 0f); var halfDeviationRatio = (float)macroModulator.GetValue( position.X * m_deviationFrequency, position.Y * m_deviationFrequency, position.Z * m_deviationFrequency); signedDistance -= halfDeviationRatio * m_halfDeviation; } if (m_enableModulation && -m_detailSize < signedDistance && signedDistance < m_detailSize) { Debug.Assert(m_detailFrequency != 0f); signedDistance += m_detailSize * (float)detailModulator.GetValue( position.X * m_detailFrequency, position.Y * m_detailFrequency, position.Z * m_detailFrequency); } return(signedDistance / lodVoxelSize); }
internal override float SignedDistance(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { Vector3 vector = position - this.m_pointA; Vector3 v = this.m_pointB - this.m_pointA; float single1 = vector.Dot(ref v); float signedDistance = (vector - (v * MathHelper.Clamp((float)(single1 / v.LengthSquared()), (float)0f, (float)1f))).Length() - this.m_radius; float num3 = this.m_potentialHalfDeviation + lodVoxelSize; return((signedDistance <= num3) ? ((signedDistance >= -num3) ? this.SignedDistanceInternal(ref position, lodVoxelSize, macroModulator, detailModulator, ref signedDistance) : -1f) : 1f); }
public MyExponent(IMyModule module, double exponent = 2.0) { Exponent = exponent; Module = module; }
internal override float SignedDistanceUnchecked(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { Vector3 vector = position - this.m_pointA; Vector3 v = this.m_pointB - this.m_pointA; float single1 = vector.Dot(ref v); float signedDistance = (vector - (v * MathHelper.Clamp((float)(single1 / v.LengthSquared()), (float)0f, (float)1f))).Length() - this.m_radius; return(this.SignedDistanceInternal(ref position, lodVoxelSize, macroModulator, detailModulator, ref signedDistance)); }
internal override float SignedDistance(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { float distance = (position - this.m_translation).Length(); return(((this.m_radius - lodVoxelSize) <= distance) ? (((this.m_radius + lodVoxelSize) >= distance) ? this.SignedDistanceInternal(lodVoxelSize, distance) : 1f) : -1f); }
internal override float SignedDistance(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { #if USE_CORRECT_COMPUTATION // The only difference between SignedDistanceUnchecked() and SignedDistance() is that the latter clamps the result. return(MathHelper.Clamp(SignedDistanceUnchecked(ref position, lodVoxelSize, macroModulator, detailModulator), -1f, 1f)); #else // This attempts to optimize queries by detecting cases where the result would be clamped. // Given simple distance computation performed here, it's actually slower than computing distance and clamping the result, // but if noise was applied to the result, this culling can save a lot. However, it can also hide incorrect distance // computation, so before optimizing, be sure clamp variant above works correctly. ContainmentType outerContainment, innerContainment; BoundingBox box = BoundingBox.CreateFromHalfExtent(m_translation, m_halfExtents + lodVoxelSize); box.Contains(ref position, out outerContainment); if (outerContainment == ContainmentType.Disjoint) { return(1); } box = BoundingBox.CreateFromHalfExtent(m_translation, m_halfExtents - lodVoxelSize); box.Contains(ref position, out innerContainment); if (innerContainment == ContainmentType.Contains) { return(-1); } return(SignedDistanceUnchecked(ref position, lodVoxelSize, macroModulator, detailModulator)); #endif }
internal override float SignedDistanceUnchecked(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { float distance = (position - this.m_translation).Length(); return(this.SignedDistanceInternal(lodVoxelSize, distance)); }
internal override float SignedDistance(ref Vector3 position, float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator) { var pa = position - m_pointA; var ba = m_pointB - m_pointA; float h = MathHelper.Clamp(pa.Dot(ref ba) / ba.LengthSquared(), 0.0f, 1.0f); float signedDistance = (pa - ba * h).Length() - m_radius; var potentialHalfDeviation = m_potentialHalfDeviation + lodVoxelSize; if (signedDistance > potentialHalfDeviation) { return(1f); } else if (signedDistance < -potentialHalfDeviation) { return(-1f); } if (m_enableModulation) { Debug.Assert(m_deviationFrequency != 0f); var halfDeviationRatio = (float)macroModulator.GetValue( position.X * m_deviationFrequency, position.Y * m_deviationFrequency, position.Z * m_deviationFrequency); signedDistance -= halfDeviationRatio * m_halfDeviation; } if (m_enableModulation && -m_detailSize < signedDistance && signedDistance < m_detailSize) { Debug.Assert(m_detailFrequency != 0f); signedDistance += m_detailSize * (float)detailModulator.GetValue( position.X * m_detailFrequency, position.Y * m_detailFrequency, position.Z * m_detailFrequency); } return(signedDistance / lodVoxelSize); }
internal virtual void GenerateNoiseHelpTexture(int storageSize, IMyModule macroModulator) { }
public MyCompositeLayeredOreDeposit(MyCsgShapeBase shape, MyMaterialLayer[] materialLayers,IMyModule noise) : base(shape, null) { m_materialLayers = materialLayers; m_noise = noise; }
public MyPanCakeFieldDesityFunction(MyRandom random, double frequency) { noise = new MySimplexFast(random.Next(), frequency); }