private MeshBase GetChoosenMesh(MeshCreator meshCreator) { switch (meshCreator.meshType) { case MeshCreator.MeshType.Triangle: return(TriangleMesh.AddTriangle(meshCreator.transform.position, meshCreator.triangleVertex1, meshCreator.triangleVertex2, meshCreator.triangleVertex3, Space.World, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Rectangle: return(RectangleMesh.AddRectangle(meshCreator.transform.position, meshCreator.boxSize, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Circle: return(CircleMesh.AddCircle(meshCreator.transform.position, meshCreator.circleRadius, meshCreator.circleSides, meshCreator.circleUseCircleCollider, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Quadrangle: Vector2[] verts = new Vector2[4] { meshCreator.quadrangleVertex1, meshCreator.quadrangleVertex2, meshCreator.quadrangleVertex3, meshCreator.quadrangleVertex4 }; return(QuadrangleMesh.AddQuadrangle(meshCreator.transform.position, verts, Space.World, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Ellipse: return(EllipseMesh.AddEllipse(meshCreator.transform.position, meshCreator.ellipseHorizontalRadius, meshCreator.ellipseVerticalRadius, meshCreator.ellipseSides, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.PointedCircle: return(PointedCircleMesh.AddPointedCircle(meshCreator.transform.position, meshCreator.pointedCircleRadius, meshCreator.pointedCircleSides, meshCreator.pointedCircleShift, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Cake: return(CakeMesh.AddCakeMesh(meshCreator.transform.position, meshCreator.cakeRadius, meshCreator.cakeSides, meshCreator.cakeSidesToFill, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Convex: return(ConvexMesh.AddConvexMesh(meshCreator.transform.position, MeshHelper.ConvertVec2ToVec3(meshCreator.convexPoints), Space.World, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Star: return(StarMesh.AddStar(meshCreator.transform.position, meshCreator.starRadiusA, meshCreator.starRadiusB, meshCreator.starSides, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Gear: return(GearMesh.AddGear(meshCreator.transform.position, meshCreator.gearInnerRadius, meshCreator.gearRootRadius, meshCreator.gearOuterRadius, meshCreator.gearSides, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Line: return(LineMesh.AddLine(meshCreator.transform.position, meshCreator.linePoints.ToArray(), meshCreator.lineWidth, meshCreator.lineUseDoubleCollider, Space.World, meshCreator.material, meshCreator.attachRigidbody)); } return(null); }
private StarMesh AddStar() { Vector3 pos = new Vector3(1.5f, 3, -0.1f); StarMesh starMesh = StarMesh.AddStar(pos, 0.7f, 1.4f, 12, null, false); starMesh.SetColor(Color.yellow); return(starMesh); }
public void SetUpBody(GenerationSettings.StarSettings starSettings, bool setPositions = true) { // this is called when a celestial body is wanting to be set up to be a star // add a rigidbody to the body if (rb is null) { rb = gameObject.AddComponent <Rigidbody>(); } // set the type of body bodyType = starSettings.bodyType; // set up the visual sphere here visualSphere = new GameObject(gameObject.name + " visuals"); visualSphere.transform.parent = transform; //CelestialBodyMesh meshConstructor = visualSphere.AddComponent<CelestialBodyMesh>(); //meshConstructor.Generate(starSettings.structureSettings, starSettings.colorSettings); // set the properties of the body from the settings surfaceGravity = starSettings.surfaceGravity; radius = starSettings.radius; mass = radius * radius * surfaceGravity / Universe.gravitationalConstant; axisTilt = starSettings.axisTilt; axialSpinSpeed = starSettings.axialSpin; Quaternion upRot = Quaternion.AngleAxis(axisTilt, Vector3.forward); localUpAxis = upRot * Vector3.up; StarMesh sm = visualSphere.AddComponent <StarMesh>(); sm.Setup(starSettings.temperature); // set up the transform transform.localScale = Vector3.one; visualSphere.transform.localScale = Vector3.one * radius * 2; visualSphere.transform.localRotation = upRot; // setup the rigidbody rb.mass = mass; // each object is given a unique id that is generated through its settings ID = starSettings.id; if (setPositions) { // set up the initial velocity // for a star in a single star system, we dont need initial velocity // as the star is not moving initially relative to all other objects // in the system initialVelocity = Vector3.zero; rb.position = Vector3.zero; } }
private void AddStar(Vector3 pos) { float rA = Random.Range(0.1f, 0.5f); float rB = rA + Random.Range(0.1f, 0.6f); int sides = Random.Range(3, 30); StarMesh star = StarMesh.AddStar(pos, rA, rB, sides, material); star.SetTexture(otherTexture); }
static Sun GenerateSun(Star star) { GameObject go = new GameObject("sun"); Sun sun = go.AddComponent <Sun>(); MeshRenderer meshRenderer = go.AddComponent <MeshRenderer>(); Universe universe = Object.FindObjectOfType(typeof(Universe)) as Universe; meshRenderer.sharedMaterial = universe.SunMaterial; Color color = StarMesh.GetStarColor(star); Mesh mesh = GenerateMesh(color); MeshFilter meshFilter = go.AddComponent <MeshFilter>(); meshFilter.sharedMesh = mesh; sun.OriginalPos = new Vector3(star.X, star.Y, star.Z); System.Collections.Generic.List <Exoplanet> planets = star.Planets; if (star.GetName() == "Sol") { planets = GetOurPlanets(); } if (planets != null && planets.Count > 0) { sun.CreatePlanets(planets); } //if (star.Planets != null && star.Planets.Count > 0) { // sun.CreatePlanets (star.Planets); //} sun.transform.localScale = Vector3.zero; return(sun); }
static GameObject GenerateMesh(Star[] stars, int offset, int count, float minMag, float maxMag, bool sun = false) { Vector3[] starVectors = new Vector3[count]; for (int i = 0; i < count; i++) { starVectors[i] = new Vector3(stars[i + offset].X, stars[i + offset].Y, stars[i + offset].Z); } Vector3[] vertices = new Vector3[starVectors.Length * 4]; Vector2[] uvs = new Vector2[starVectors.Length * 4]; int[] triangles = new int[starVectors.Length * 6]; Color[] colors = new Color[starVectors.Length * 4]; int vertIndex = 0; int uvIndex = 0; int triangleIndex = 0; for (int i = 0; i < starVectors.Length; i++) { int vert1 = vertIndex++; int vert2 = vertIndex++; int vert3 = vertIndex++; int vert4 = vertIndex++; Color color = GetStarColor(stars[i + offset]); // Abs MAg float absMag = stars[i + offset].AbsMag; float normalizedMag = (absMag - minMag) / (maxMag - minMag); color.a = 1 - normalizedMag; colors[vert1] = color; colors[vert2] = color; colors[vert3] = color; colors[vert4] = color; Vector3 position = Vector3.zero; if (sun == false) { position = starVectors[i]; } vertices[vert1] = position; vertices[vert2] = position; vertices[vert3] = position; vertices[vert4] = position; uvs[uvIndex++] = new Vector2(1, 1); uvs[uvIndex++] = new Vector2(1, -1); uvs[uvIndex++] = new Vector2(-1, -1); uvs[uvIndex++] = new Vector2(-1, 1); triangles[triangleIndex++] = vert1; triangles[triangleIndex++] = vert2; triangles[triangleIndex++] = vert3; triangles[triangleIndex++] = vert3; triangles[triangleIndex++] = vert4; triangles[triangleIndex++] = vert1; } Mesh mesh = new Mesh(); mesh.vertices = vertices; mesh.uv = uvs; mesh.colors = colors; mesh.name = "starMesh"; mesh.triangles = triangles; mesh.RecalculateBounds(); GameObject go = new GameObject("starMesh"); StarMesh starMesh = go.AddComponent <StarMesh>(); MeshFilter meshFilter = go.GetComponent <MeshFilter>(); MeshRenderer meshRenderer = go.GetComponent <MeshRenderer>(); go.AddComponent <Scaler>(); meshFilter.sharedMesh = mesh; meshRenderer.sharedMaterial = starMesh.Material; return(go); }
private MeshBase GetChoosenMesh(MeshCreator meshCreator) { float?minArea = meshCreator.splineSimplification != SplineSimplification.Type.None ? meshCreator.minAbsoluteSplineArea : (float?)null; switch (meshCreator.meshType) { case MeshCreator.MeshType.Triangle: return(TriangleMesh.AddTriangle(meshCreator.transform.position, meshCreator.triangleVertex1, meshCreator.triangleVertex2, meshCreator.triangleVertex3, Space.World, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Rectangle: return(RectangleMesh.AddRectangle(meshCreator.transform.position, meshCreator.boxSize, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Circle: return(CircleMesh.AddCircle(meshCreator.transform.position, meshCreator.circleRadius, meshCreator.circleSides, meshCreator.circleUseCircleCollider, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Quadrangle: Vector2[] verts = new Vector2[4] { meshCreator.quadrangleVertex1, meshCreator.quadrangleVertex2, meshCreator.quadrangleVertex3, meshCreator.quadrangleVertex4 }; return(QuadrangleMesh.AddQuadrangle(meshCreator.transform.position, verts, Space.World, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Ellipse: return(EllipseMesh.AddEllipse(meshCreator.transform.position, meshCreator.ellipseHorizontalRadius, meshCreator.ellipseVerticalRadius, meshCreator.ellipseSides, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.PointedCircle: return(PointedCircleMesh.AddPointedCircle(meshCreator.transform.position, meshCreator.pointedCircleRadius, meshCreator.pointedCircleSides, meshCreator.pointedCircleShift, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Cake: return(CakeMesh.AddCakeMesh(meshCreator.transform.position, meshCreator.cakeRadius, meshCreator.cakeSides, meshCreator.cakeSidesToFill, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Convex: return(ConvexMesh.AddConvexMesh(meshCreator.transform.position, MeshHelper.ConvertVec2ToVec3(meshCreator.convexPoints), meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Star: return(StarMesh.AddStar(meshCreator.transform.position, meshCreator.starRadiusA, meshCreator.starRadiusB, meshCreator.starSides, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Gear: return(GearMesh.AddGear(meshCreator.transform.position, meshCreator.gearInnerRadius, meshCreator.gearRootRadius, meshCreator.gearOuterRadius, meshCreator.gearSides, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.Line: return(LineMesh.AddLine(meshCreator.transform.position, meshCreator.linePoints.ToArray(), meshCreator.lineWidth, meshCreator.lineUseDoubleCollider, Space.World, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.TriangulatedMesh: return(TriangulatedMesh.Add(meshCreator.transform.position, meshCreator.triangulatedPoints.ToArray(), meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.SplineShape: return(SplineShapeMesh.AddSplineShape(meshCreator.transform.position, meshCreator.splinePoints.ToArray(), meshCreator.splineResolution, minArea, Space.World, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.SplineCurve: return(SplineCurveMesh.AddSplineCurve(meshCreator.transform.position, meshCreator.splineCurvePoints.ToArray(), meshCreator.splineResolution, meshCreator.splineCurveWidth, meshCreator.splineCurveUseDoubleCollider, minArea, Space.World, meshCreator.material, meshCreator.attachRigidbody)); case MeshCreator.MeshType.SplineConvexShape: return(ConvexSplineMesh.AddConvexSpline(meshCreator.transform.position, meshCreator.convexSplinePoints.ToArray(), meshCreator.splineResolution, minArea, Space.World, meshCreator.material, meshCreator.attachRigidbody)); default: throw new System.ArgumentOutOfRangeException(); } }