Line GridFill(SplineBase spline, Line line) { float offset = spline.Offset + spline.Depth; Layer layer = spline.Layer; float resolution = layer.resolution; SplineBase.SplinePattern pattern = spline.Pattern; Color color = new Color(pattern.extra ? 0 : 1, 0, 0, spline.IsHole ? 0.01f : 1); Line xy = new Line(); for (float x = editorMin.x; x < editorMax.x; x += resolution) { for (float z = editorMin.z; z < editorMax.z; z += resolution) { Vector3 point = new Vector3(x, 0, z); if (!point.IsInside(line.points)) { continue; } float y = offset; xy.Add(GetPosition(new Vector2(x, z), y), GetNormal(point, Vector3.zero, Vector3.zero, new Vector2(x, z)), color); } } return(xy); }
static void CheckLibraryLegacyNames() { for (int i = SplineLayers.Count - 1; i >= 0; --i) { Layer layer = SplineLayers[i]; SplineBase.SplinePattern pattern = layer.pattern; if (pattern.extraLayerName == "NoLayerName") { pattern.extraLayerName = GetLayer(pattern.extraLayerIndex, Layers).name; } } }
/// <summary> /// Uppdate mesh data, create mesh /// </summary> /// <param name="spline"></param> public void UpdateMesh(SplineBase spline) { outerLine.Update(); extraOuterLine.Update(); extraInnerLine.Update(); shrinkLine.Update(); innerLine.Update(); transitionPoly.Clear(); extraPoly.Clear(); extraTransitionPoly.Clear(); shrinkPoly.Clear(); corePoly.Clear(); SplineBase.SplinePattern pattern = spline.Pattern; if (pattern.extra) { if (pattern.transition) { transitionPoly.AddSimple(outerLine, extraOuterLine); } extraPoly.AddSimple(extraOuterLine, extraInnerLine); if (pattern.shrink) { if (pattern.extraTransition) { extraTransitionPoly.AddSimple(extraInnerLine, shrinkLine); } shrinkPoly.AddSimple(shrinkLine, innerLine); } else { if (pattern.extraTransition) { extraTransitionPoly.AddSimple(extraInnerLine, innerLine); } } } else { if (pattern.shrink) { if (pattern.transition) { transitionPoly.AddSimple(outerLine, shrinkLine); } shrinkPoly.AddSimple(shrinkLine, innerLine); } else { if (pattern.transition) { transitionPoly.AddSimple(outerLine, innerLine); } } } if (!spline.IsHazard) { corePoly.AddPolygon(innerLine); Layer layer = spline.Layer; if (layer.fillType == Layer.FillType.Grid_Fill) { corePoly.AddSteiner(GridFill(spline, innerLine)); for (int i = 0; i < spline.Transform.childCount; ++i) { SplineBase child = spline.Transform.GetChild(i).GetComponent <SplineBase>(); child.Lines.outerLine.Update(); corePoly.AddChildAsHole(child.Lines.outerLine); } } if (layer.fillType == Layer.FillType.Radial_Fill) { List <Line> xy = RadialFill(spline); for (int i = 0; i < xy.Count; ++i) { corePoly.AddSteiner(xy[i]); } for (int i = 0; i < spline.Transform.childCount; ++i) { SplineBase child = spline.Transform.GetChild(i).GetComponent <SplineBase>(); child.Lines.outerLine.Update(); corePoly.AddChildAsHole(child.Lines.outerLine); } } } if (transitionPoly.IsInUse) { transitionPoly.Triangulate(); } if (extraPoly.IsInUse) { extraPoly.Triangulate(); } if (extraTransitionPoly.IsInUse) { extraTransitionPoly.Triangulate(); } if (shrinkPoly.IsInUse) { shrinkPoly.Triangulate(); } if (corePoly.IsInUse) { corePoly.Triangulate(); } needMeshRefresh = false; }
/// <summary> /// Update line data, fill the containers /// </summary> /// <param name="spline"></param> public void FormLines(SplineBase spline) { outerLine.Clear(); extraOuterLine.Clear(); extraInnerLine.Clear(); shrinkLine.Clear(); innerLine.Clear(); bool isHazard = spline.IsHazard; bool hasParent = spline.HasParent; SplineBase.SplinePattern pattern = spline.Pattern; Color outerColor = new Color(0, 0, 0, hasParent ? 1 : 0); Color extraInnerColor = new Color(1, 0, 0, 1); Color extraOuterColor = new Color(1, 0, 0, 1); Color shrinkColor = new Color(pattern.extra ? 0 : 1, 0, 0, spline.IsHole ? 0.01f : 1); Color innerColor = new Color(pattern.extra ? 0 : 1, 0, 0, spline.IsHole ? 0.01f : 1); float baseOffset = spline.Offset; Vector3[] points = editorLinesPoints; if (isHazard) { baseOffset += 0.01f; } for (int i = 0; i < points.Length - 1; ++i) { float offset = baseOffset; if (isHazard) { outerColor = editorLinesColors[i]; innerColor = editorLinesColors[i]; } Vector2 point = new Vector2(points[i].x, points[i].z); Vector2 normalVector = GetNormalAtIndex(points, i); Vector2 outerPoint2 = point + (pattern.transition ? (pattern.transitionLength * (isHazard ? 0.5f : 1.0f)) * normalVector : Vector2.zero); Vector2 extraOuterPoint2 = outerPoint2 - (pattern.extra ? (pattern.transition ? pattern.transitionLength * normalVector : Vector2.zero) : Vector2.zero); Vector2 extraInnerPoint2 = extraOuterPoint2 - (pattern.extra ? pattern.extraLength * normalVector : Vector2.zero); Vector2 shrinkPoint2 = extraInnerPoint2 - (pattern.extra ? (pattern.extraTransition ? pattern.extraTransitionLength * normalVector : Vector2.zero) : (pattern.transition ? pattern.transitionLength * normalVector : Vector2.zero)); Vector2 innerPoint2 = shrinkPoint2 - (pattern.shrink ? pattern.shrinkLength * normalVector : Vector2.zero); if (!isHazard && !hasParent) { offset *= 0.001f; } Vector3 outerPoint3 = GetPosition(outerPoint2, offset); if (!isHazard && !hasParent) { offset *= 1000; } if (pattern.transition) { offset += pattern.transitionDepth; } Vector3 extraOuterPoint3 = GetPosition(extraOuterPoint2, offset); if (pattern.extra) { offset += pattern.extraDepth; } Vector3 extraInnerPoint3 = GetPosition(extraInnerPoint2, offset); if (pattern.extra && pattern.extraTransition) { offset += pattern.extraTransitionDepth; } Vector3 shrinkPoint3 = GetPosition(shrinkPoint2, offset); if (pattern.shrink) { offset += pattern.shrinkDepth; } Vector3 innerPoint3 = GetPosition(innerPoint2, offset); outerLine.Add(outerPoint3, GetNormal(outerPoint3, Vector3.zero, Vector3.zero, outerPoint2), outerColor); if (pattern.extra) { extraOuterLine.Add(extraOuterPoint3, GetNormal(extraOuterPoint3, (pattern.transition ? outerPoint3 : Vector3.zero), extraInnerPoint3, extraOuterPoint2, spline.Layer.IsBunker), extraOuterColor); extraInnerLine.Add(extraInnerPoint3, GetNormal(extraInnerPoint3, extraOuterPoint3, (pattern.extraTransition ? (pattern.shrink ? shrinkPoint3 : innerPoint3) : Vector3.zero), extraInnerPoint2, spline.Layer.IsBunker), extraInnerColor); } if (pattern.shrink) { shrinkLine.Add(shrinkPoint3, GetNormal(shrinkPoint3, (pattern.extra && pattern.extraTransition ? extraInnerPoint3 : (pattern.transition ? outerPoint3 : Vector3.zero)), innerPoint3, shrinkPoint2), shrinkColor); } innerLine.Add(innerPoint3, GetNormal(innerPoint3, Vector3.zero, Vector3.zero, innerPoint2), innerColor); } }
/// <summary> /// Update mesh from the line data /// </summary> /// <param name="spline"></param> public void UpdateMesh(SplineBase spline) { if (mesh) { MonoBehaviour.DestroyImmediate(mesh); mesh = null; } if (meshPhysics) { MonoBehaviour.DestroyImmediate(meshPhysics); meshPhysics = null; } if (meshFilter) { MonoBehaviour.DestroyImmediate(meshFilter); meshFilter = null; } if (meshCollider && meshCollider.material) { MonoBehaviour.DestroyImmediate(meshCollider.material); meshCollider.material = null; } if (meshCollider && meshCollider.sharedMaterial) { meshCollider.sharedMaterial = null; } if (meshCollider) { MonoBehaviour.DestroyImmediate(meshCollider); meshCollider = null; } if (spline.IsHazard) { return; } SplineBase.SplinePattern pattern = spline.Pattern; List <Vector3> vertices = new List <Vector3>(); List <Vector3> normals = new List <Vector3>(); List <Vector4> tangents = new List <Vector4>(); List <Color> colors = new List <Color>(); mesh = new Mesh(); mesh.Clear(); mesh.name = "Spline Mesh"; int submesh = 0; if (pattern.extra) { if (pattern.transition) { AddPoly(spline.Lines.TransitionPoly, mesh, submesh++, vertices, normals, tangents, colors); } AddPoly(spline.Lines.ExtraPoly, mesh, submesh++, vertices, normals, tangents, colors); if (pattern.extraTransition) { AddPoly(spline.Lines.ExtraTransitionPoly, mesh, submesh++, vertices, normals, tangents, colors); } } else { if (pattern.transition) { AddPoly(spline.Lines.TransitionPoly, mesh, submesh++, vertices, normals, tangents, colors); } } if (pattern.shrink) { AddPoly(spline.Lines.ShrinkPoly, mesh, submesh++, vertices, normals, tangents, colors); } AddPoly(spline.Lines.CorePoly, mesh, submesh++, vertices, normals, tangents, colors); meshFilter = spline.Transform.gameObject.AddComponent <MeshFilter>(); meshFilter.mesh = mesh; meshCollider = spline.Transform.gameObject.AddComponent <MeshCollider>(); meshCollider.sharedMesh = mesh; meshCollider.sharedMaterial = spline.Layer.PhysicsMaterial; }
/// <summary> /// Update mesh material /// </summary> /// <param name="spline"></param> public void UpdateMaterial(SplineBase spline) { if (meshRenderer) { MonoBehaviour.DestroyImmediate(meshRenderer); meshRenderer = null; } if (meshRenderer && meshRenderer.sharedMaterials != null) { meshRenderer.sharedMaterials = null; } for (int i = 0; i < materials.Count; ++i) { MonoBehaviour.DestroyImmediate(materials[i]); materials[i] = null; } if (spline.IsHazard) { return; } SplineBase parent = null; if (spline.HasParent) { parent = spline.Parent; } Layer cLayer = spline.Layer; Layer eLayer = spline.Layer; Layer tLayer = spline.Layer; if (spline.Pattern.extra) { eLayer = spline.ExtraLayer; if (spline.HasParent) { tLayer = parent.Layer; } else { tLayer = eLayer; } } else { if (spline.HasParent) { tLayer = parent.Layer; } } materials.Clear(); SplineBase.SplinePattern pattern = spline.Pattern; if (pattern.extra) { if (pattern.transition) { AddMaterialTransition(materials, tLayer, eLayer); } AddMaterialCore(materials, eLayer); if (pattern.extraTransition) { AddMaterialTransition(materials, cLayer, eLayer); } } else { if (pattern.transition) { AddMaterialTransition(materials, tLayer, cLayer); } } if (pattern.shrink) { AddMaterialCore(materials, cLayer); } AddMaterialCore(materials, cLayer); meshRenderer = spline.Transform.gameObject.AddComponent <MeshRenderer>(); meshRenderer.sharedMaterials = materials.ToArray(); meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; needMaterialRefresh = false; }