new public void Awake() { base.Awake(); falloffMap = Falloff.GenerateFalloffMap(mapWidth, mapHeight); GenerateMap(); ApplyHeightMultiplier(mapSettings.heightMultiplier, mapSettings.heightCurve); }
public static Color[] GenerateColorMap(float[,] noiseMap, TerrainType[] regions, bool useFalloff) { int mapWidth = noiseMap.GetLength(0); int mapHeight = noiseMap.GetLength(1); float[,] falloffMap = Falloff.GenerateFalloffMap(mapWidth, mapHeight); Color[] colorMap = new Color[mapWidth * mapHeight]; for (int y = 0; y < mapHeight; y++) { for (int x = 0; x < mapWidth; x++) { if (useFalloff) { noiseMap[x, y] = Mathf.Clamp01(noiseMap[x, y] - falloffMap[x, y]); } for (int i = 0; i < regions.Length; i++) { if (noiseMap[x, y] <= regions[i].height) { colorMap[y * mapWidth + x] = regions[i].color; break; } } } } return(colorMap); }
float[,] CreateHeightMapLayer(HeightMapSettings settings, int seed, int mapWidth, int offsetX, int offsetY) { float widthFactor = (float)mapWidth / (float)maxWidth; float[,] noiseMap = Noise.GenerateNoiseMap( settings.noiseType, mapWidth, mapWidth, settings.noiseScale * widthFactor, offsetX, offsetY, settings.noiseOctaves, settings.persistence, settings.lacunarity, settings.noiseRedistributionFactor ); float[,] falloffMap = null; if (settings.useFalloff) { falloffMap = Falloff.GenerateFalloffMap(mapWidth, mapWidth); } bool useHydraulicErosion = hydraulicErosion.settings.useHydraulicErosion; if (useHydraulicErosion && settings.mapDepth > 0) { noiseMap = hydraulicErosion.ErodeTerrain(noiseMap, seed); } float[,] heightMap = new float[mapWidth, mapWidth]; // Determine map depth for (int z = 0; z < mapWidth; z++) { for (int x = 0; x < mapWidth; x++) { if (settings.useFalloff && settings.mapDepth > 0) { noiseMap[x, z] = Mathf.Clamp01(noiseMap[x, z] - falloffMap[x, z]); } if (settings.mapDepth == 0) { heightMap[x, z] = 1f; } else { heightMap[x, z] = 2 * (noiseMap[x, z] * settings.mapDepth); } } } return(heightMap); }
public override Pose Calculate() { Col.Calculate(); Prev.Calculate(); Enabled.Calculate(); if (!Enabled.value.value_b) { return(Prev.value); } YPRScale.Calculate(); YPROmega.Calculate(); YPRPhi.Calculate(); OffsetScale.Calculate(); OffsetOmega.Calculate(); OffsetPhi.Calculate(); Tick.Calculate(); Duration.Calculate(); Falloff.Calculate(); if (controller != null && controller.executor != null) { Pose pose = Prev.value; float t = Tick.value.value_f; float d = Mathf.Max(0.001f, Duration.value.value_f); float f = Mathf.Max(0.001f, Falloff.value.value_f); if (t < d && t >= 0) { float scale = Mathf.Pow(1f - t / d, f); pose.yaw += Mathf.Sin((YPROmega.value.value_v.x * t + YPRPhi.value.value_v.x) * 2.0f * Mathf.PI) * YPRScale.value.value_v.x * scale; pose.pitch += Mathf.Sin((YPROmega.value.value_v.y * t + YPRPhi.value.value_v.y) * 2.0f * Mathf.PI) * YPRScale.value.value_v.y * scale; pose.roll += Mathf.Sin((YPROmega.value.value_v.z * t + YPRPhi.value.value_v.z) * 2.0f * Mathf.PI) * YPRScale.value.value_v.z * scale; Vector3 right = pose.rotation * Vector3.right; Vector3 up = pose.rotation * Vector3.up; Vector3 forward = pose.rotation * Vector3.forward; Vector3 ofs = Vector3.zero; ofs += right * Mathf.Sin((OffsetOmega.value.value_v.x * t + OffsetPhi.value.value_v.x) * 2.0f * Mathf.PI) * OffsetScale.value.value_v.x * scale; ofs += up * Mathf.Sin((OffsetOmega.value.value_v.y * t + OffsetPhi.value.value_v.y) * 2.0f * Mathf.PI) * OffsetScale.value.value_v.y * scale; ofs += forward * Mathf.Sin((OffsetOmega.value.value_v.z * t + OffsetPhi.value.value_v.z) * 2.0f * Mathf.PI) * OffsetScale.value.value_v.z * scale; pose.position += ofs; return(pose); } else { return(pose); } } return(Pose.Default); }
void DeformMesh(Vector3 position, float power) { Vector3[] vertices = meshScan.mesh.vertices; float sqrRadius = radius * radius; Vector3 averageNormal = lerpNearestOnMesh.lerpMove(position, meshGoal, percentTowards); // Deform vertices along averaged normal for (int i = 0; i < vertices.Length; i++) { float sqrMagnitude = (vertices[i] - position).sqrMagnitude; // Early out if vertex too far away form position if (sqrMagnitude > sqrRadius) { continue; } float distance = Mathf.Sqrt(sqrMagnitude); float falloff = 0.0f; switch (fallOff) { case Falloff.type.Gauss: falloff = Falloff.Gauss(distance, radius); break; case Falloff.type.Needle: falloff = Falloff.Needle(distance, radius); break; case Falloff.type.Linear: falloff = Falloff.Linear(distance, radius); break; default: Debug.Log("unrecognized falloff type"); break; } vertices[i] += averageNormal * falloff * power; } meshScan.mesh.vertices = vertices; meshScan.mesh.RecalculateNormals(); meshScan.mesh.RecalculateBounds(); }
public static float[,] FalloffData(int resolution) { float[,] falloffMap = new float[resolution, resolution]; float xValue, yValue, value; for (int y = 0; y < resolution; y++) { for (int x = 0; x < resolution; x++) { xValue = x / (float)resolution * 2 - 1; yValue = y / (float)resolution * 2 - 1; value = Mathf.Max(Mathf.Abs(xValue), Mathf.Abs(yValue)); falloffMap[y, x] = Falloff.Evaluate(value); } } return(falloffMap); }
public void GenerateMap() { falloffMap = Falloff.GenerateFalloffMap(mapWidth, mapHeight); DrawMap(); colorMap = ColorMapGenerator.GenerateColorMap(heightMap, regions, mapSettings.useFalloff); }
void BulgeMesh(MeshFilter mf, Vector3 pos, float power, float inRadius) { Vector3 position = mf.transform.InverseTransformPoint(pos); Mesh mesh = mf.mesh; Vector3[] vertices = mesh.vertices; Vector3[] normals = mesh.normals; float sqrRadius = inRadius * inRadius; // Calculate averaged normal of all surrounding vertices Vector3 averageNormal = Vector3.zero; for (int i = 0; i < vertices.Length; i++) { float sqrMagnitude = (vertices[i] - position).sqrMagnitude; // Early out if too far away if (sqrMagnitude > sqrRadius) { continue; } float distance = Mathf.Sqrt(sqrMagnitude); float falloff = Falloff.Linear(distance, inRadius); averageNormal += falloff * normals[i]; } averageNormal = averageNormal.normalized; // Deform vertices along averaged normal for (int i = 0; i < vertices.Length; i++) { float sqrMagnitude = (vertices[i] - position).sqrMagnitude; // Early out if too far away if (sqrMagnitude > sqrRadius) { continue; } float distance = Mathf.Sqrt(sqrMagnitude); float falloff = 0f; switch (fallOff) { case Falloff.type.Gauss: falloff = Falloff.Gauss(distance, inRadius); break; case Falloff.type.Needle: falloff = Falloff.Needle(distance, inRadius); break; default: falloff = Falloff.Linear(distance, inRadius); break; } vertices[i] += averageNormal * falloff * power; } mesh.vertices = vertices; mesh.RecalculateNormals(); mesh.RecalculateBounds(); }
//------------------------------------------------------------------------------------------------------------------------- // TODO: integrate damage filters into explosive effect attributes public virtual void Detonate() { OnDetonate.Invoke(); if (shrapnelPrefab) { foreach (var collider in m_effectOrigin.GetComponentsInChildren <Collider>()) { collider.isTrigger = true; } var shrapnel = GameObject.Instantiate(shrapnelPrefab, m_effectOrigin.position, m_effectOrigin.rotation); shrapnel.SetActive(true); GameObject.Destroy(shrapnel, shrapnelDuration); } //TODO: implement shielding of blast effects Collider[] hitColliders = Physics.OverlapSphere(m_effectOrigin.position + EffectPositionOffset, EffectRadius, AffectedLayers, QueryTriggerInteraction.UseGlobal); var hitDamageables = new List <Damageable>(); //var bodies = new List<Rigidbody>(); //Debug.Log("[BOOM HIT]"); RootMotion.FinalIK.RagdollUtility ragdoll = null; foreach (var hitCollider in hitColliders) { //Debug.Log("[BOOM HIT] " + hit.name); var damageable = hitCollider.GetComponentInParent <Damageable>(); if (damageable) { if (damageable.isServer) { bool firstHit = !hitDamageables.Contains(damageable); if (firstHit) { hitDamageables.Add(damageable); } if (!LimitDamageablesToOneHit || firstHit) { // TODO: more intelligently select the root collider to apply damage effect to var effectRange = Vector3.Distance(hitCollider.transform.position, m_effectOrigin.position) / EffectRadius; int damage = Mathf.RoundToInt(BaseDamage * Falloff.Evaluate(effectRange)); if (damage > 0) { damageable.TakeDamage(damage, hitCollider); } } } // FENG_TODO: not using ragdoll for now based on design; will see if we will enable it in the future bool using_Ragdoll = false; if (using_Ragdoll) { if (!ragdoll) { ragdoll = damageable.GetComponent <RootMotion.FinalIK.RagdollUtility>(); } if (ragdoll && !ragdoll.isRagdoll) { if (m_profile.ragdollDuration > 0) { damageable.StartCoroutine(TempRagdoll(damageable, ragdoll, m_profile.ragdollDuration)); } else if (m_profile.ragdollDuration < 0) { ragdoll.EnableRagdoll(); } } } } // TODO: figure out best way optionally limit force to apply just to root body. Rigidbody rb = hitCollider.GetComponentInParent <Rigidbody>(); if (rb != null) { rb.AddExplosionForce(EffectForce, m_effectOrigin.position + EffectPositionOffset + Random.onUnitSphere, 2 * EffectRadius, 3.0f); //rb.AddForce(EffectForce,, m_effectOrigin.position + EffectPositionOffset, 2 * EffectRadius, 1.0f); } } }
protected override void Update_GenerateMap() { base.begin_update(); if (MeshSource == null) { throw new Exception("EnclosedRegionOffsetOp: must set valid MeshSource to compute!"); } if (MeshSource.HasSpatial == false) { throw new Exception("EnclosedRegionOffsetOp: MeshSource must have spatial data structure!"); } IMesh imesh = MeshSource.GetIMesh(); if (imesh.HasVertexNormals == false) { throw new Exception("EnclosedRegionOffsetOp: input mesh does not have surface normals..."); } if (imesh is DMesh3 == false) { throw new Exception("EnclosedRegionOffsetOp: in current implementation, input mesh must be a DMesh3. Ugh."); } DMesh3 mesh = imesh as DMesh3; ISpatial spatial = MeshSource.GetSpatial(); DCurve3 curve = new DCurve3(CurveSource.GetICurve()); MeshFacesFromLoop loop = new MeshFacesFromLoop(mesh, curve, spatial); // [RMS] this is all f'n ugly! MeshVertexSelection selection = new MeshVertexSelection(mesh); selection.SelectTriangleVertices(loop.InteriorTriangles); // [TODO] do this inline w/ loop below? but then no maxdist! Dictionary <int, double> dists = new Dictionary <int, double>(); double max_dist = 0; foreach (int vid in selection) { Vector3d v = mesh.GetVertex(vid); int inearseg; double nearsegt; double min_dist_sqr = curve.DistanceSquared(v, out inearseg, out nearsegt); min_dist_sqr = Math.Sqrt(min_dist_sqr); max_dist = Math.Max(min_dist_sqr, max_dist); dists[vid] = min_dist_sqr; } lock (Displacement) { Displacement.Clear(); Displacement.Resize(mesh.MaxVertexID); // todo: can do this in parallel... foreach (int vid in selection) { //Vector3d v = mesh.GetVertex(vid); // [TODO]... double dist = max_dist - dists[vid]; double falloff = Falloff.FalloffT(dist / max_dist); Vector3d n = mesh.GetVertexNormal(vid); n = n - n.Dot(normal) * normal; n.Normalize(); Displacement[vid] = falloff * offset_distance * n; } } // smooth it? base.complete_update(); }