public MeshBuilder Create() { CircleMesh circleMesh = new CircleMesh(); circleMesh.radius = radius; circleMesh.direction1 = direction1; circleMesh.direction2 = direction2; circleMesh.totalVertices = totalPerimeterVertices; Vector3 direction3 = Vector3.Cross(direction1, direction2).normalized; MeshBuilder upCircle = circleMesh.Create() .Translate(0.5f * height * direction3); MeshBuilder downCircle = circleMesh.Create() .Translate(-0.5f * height * direction3); MeshUnion meshUnion = new MeshUnion(); meshUnion.size = height; meshUnion.totalSegments = totalVerticalSegments; MeshBuilder tunnel = meshUnion.Create(upCircle, downCircle); return(MeshBuilder.Join(upCircle, downCircle).Join(tunnel)); }
private void AddBall() { Vector3 position = transform.position + new Vector3(Random.Range(-8f, 8f), 0); CircleMesh ball = CircleMesh.AddCircle(position, 0.5f, 32, true, material); ball.SetTexture(otherTexture); }
public MeshBuilder Create() { CircleMesh circleMesh = new CircleMesh(); circleMesh.radius = radius; circleMesh.direction1 = direction1; circleMesh.direction2 = direction2; circleMesh.totalVertices = totalPerimeterVertices; if ((direction3 - Vector3.up).magnitude < 0.001f) { direction3 = Vector3.Cross(direction1, direction2).normalized; } MeshBuilder baseCircle = circleMesh.Create() .Translate(-0.5f * height * direction3); MeshBuilder top = new MeshBuilder(); top.AddVertice(new Vector3(0f, -0.5f * height, 0f) + height * direction3, "border"); MeshUnion meshUnion = new MeshUnion(); meshUnion.size = height; meshUnion.totalSegments = totalVerticalSegments; MeshBuilder cone = meshUnion.Create(top, baseCircle); return(cone.Join(baseCircle)); }
public void CreatMesh() { MeshFilter meshFilter = (MeshFilter)GameObject.Find("face").GetComponent(typeof(MeshFilter)); Mesh mesh = meshFilter.mesh; Vector3[] vertices = new Vector3[positions.Count]; int[] triangles = new int[(positions.Count - 2) * 3]; vertices = positions.ToArray(); mesh.vertices = vertices; int start = 0; int end = positions.Count - 2; //for (int i = start; i < end; i++) { // for (int j = 0; j < 3; j++) { // if (i % 2 == 0) { // triangles[3 * i + j] = i + j; // } else { // triangles[3 * i + j] = i + 2 - j; // } // } //} //meshFilter.mesh = LineMesh.CreateLine(vertices[0], vertices[vertices.Length-1], Color.red); //meshFilter.mesh = LineMesh.CreateCoordSystemAxesLines(1, Color.red); //meshFilter.mesh = BoxMesh.CreateWireBox(1, 1, 1, Color.red); meshFilter.mesh = CircleMesh.CreateCircleXY(2, 5, Color.red); mesh.triangles = triangles; }
private void Awake() { m_LEDColorGenController = this.gameObject.GetComponent <LEDColorGenController>(); m_boids = this.gameObject.GetComponent <SimpleBoidsTreeOfVoice>(); if (m_boidLEDInstanceMaterial == null) { Debug.LogError("The global Variable m_boidLEDInstanceMaterial is not defined in Inspector"); // EditorApplication.Exit(0); Application.Quit(); //return; } m_instanceMeshCircle = new CircleMesh(m_unitRadius); // m_instanceMeshCylinder = new CylinderMesh(m_unitHeight, m_cylinderRadiusScale, nbSides, nbHeightSeg); //m_boidInstanceMesh = m_instanceMeshCylinder.m_mesh; m_boidInstanceMesh = m_instanceMeshCircle.m_mesh; m_boidLEDArgsBuffer = new ComputeBuffer( 1, m_boidLEDArgs.Length * sizeof(uint), ComputeBufferType.IndirectArguments ); } // Awake()
private void Divide(Vector2 firstPoint, Vector2 secondPoint) { Vector2[] verticesFirstArray; ushort[] trianglesFirstArray; Vector2[] verticesSecondArray; ushort[] trianglesSecondArray; CircleMesh.CutCircleNew(pizzaSprite, firstPoint, secondPoint, out verticesFirstArray, out trianglesFirstArray, out verticesSecondArray, out trianglesSecondArray); float firstArea = CalculateArea(verticesFirstArray); float secondArea = CalculateArea(verticesSecondArray); if (firstArea > secondArea) { pizzaSprite.OverrideGeometry(verticesFirstArray, trianglesFirstArray); CreatePeace(verticesSecondArray, trianglesSecondArray); dispalyText.Invoke((secondArea / fullArea) * 100f); } else { pizzaSprite.OverrideGeometry(verticesSecondArray, trianglesSecondArray); CreatePeace(verticesFirstArray, trianglesFirstArray); dispalyText.Invoke((firstArea / fullArea) * 100f); } RecalculateCollider(); }
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 void AddCircle(Vector3 pos) { float radius = Random.Range(0.5f, 1.5f); int sides = Random.Range(8, 16); CircleMesh circle = CircleMesh.AddCircle(pos, radius, sides, sides > 8, material); circle.GetComponent <MeshBase>().SetTexture(roundTexture); }
float unitRadius = 1f; // radius = 1m private void Awake() { // initialize me // check if the global component object is defined if (m_boidInstanceMaterial == null) { Debug.LogError("The global Variable _boidInstanceMaterial is not defined in Inspector"); // EditorApplication.Exit(0); return; } m_instanceMeshCircle = new CircleMesh(unitRadius); m_instanceMeshCylinder = new CylinderMesh(height, radius, nbSides, nbHeightSeg); m_boidArgsBuffer = new ComputeBuffer( 1, // count m_boidArgs.Length * sizeof(uint), ComputeBufferType.IndirectArguments ); if (m_useCircleMesh) // use 2D boids => creat the mesh in a script { m_boidInstanceMesh = m_instanceMeshCircle.m_mesh; } else { m_boidInstanceMesh = m_instanceMeshCylinder.m_mesh; } // else { // Debug.LogError("useCircleMesh or useSphereMesh should be checked"); // //If we are running in a standalone build of the game // #if UNITY_STANDALONE // //Quit the application // Application.Quit(); // #endif // //If we are running in the editor // #if UNITY_EDITOR // //Stop playing the scene // // UnityEditor.EditorApplication.isPlaying = false; // //Setting isPlaying delays the result until after all script code has completed for this frame. // EditorApplication.Exit(0); // #endif // } //Debug.Log("number of indices="); //Debug.Log(_instanceMesh.GetIndexCount(0)); }
// Use this for initialization void Start() { collider = GetComponent <PolygonCollider2D>(); pizzaSprite = GetComponent <SpriteRenderer>().sprite; Vector2[] vertices; ushort[] triangles; CircleMesh.CalculateCircleMeshData(pizzaSprite, 40, out vertices, out triangles); pizzaSprite.OverrideGeometry(vertices, triangles); RecalculateCollider(); fullArea = CalculateArea(vertices); }
private void AddRearWheel(GameObject body, Vector3 position) { carElements[1] = new GameObject(); //build rear wheel CircleMesh rearWheelScript = carElements[1].AddComponent <CircleMesh>(); float radius = Random.Range(0.2f, 1f); int sides = Random.Range(15, 30); rearWheelScript.Build(radius, sides, true, material); carElements[1].transform.position = position; //add pasive hinge rearWheelScript.AddHingeJoint(new JointMotor2D { motorSpeed = 0, maxMotorTorque = 0 }, body.GetComponent <Rigidbody2D>()); rearWheelScript.C_MR.material.color = Color.black; rearWheelScript.SetPhysicsMaterialProperties(0, 10f); }
public void Generate() { MeshBuilder baseMesh1 = new MeshBuilder(); QuadMesh.Create(baseMesh1, Vector3.right * baseSize.x, Vector3.forward * baseSize.y); baseMesh1 = ExtrudeMesh.From(baseMesh1, Vector3.up * height1).Join(baseMesh1); MeshBuilder circleMesh = CircleMesh.Create(height2, 0f, 180f, -Vector3.forward, Vector3.up). Translate(Vector3.up * height1 + Vector3.forward * 0.5f * baseSize.y); circleMesh = ExtrudeMesh.From(circleMesh, Vector3.right * baseSize.x).Join(circleMesh); MeshFilter filter = gameObject.GetComponent <MeshFilter>(); Mesh mesh = MeshBuilder.Join(baseMesh1, circleMesh).CreateMesh(); mesh.RecalculateBounds(); filter.mesh = mesh; }
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(); } }
public MeshManager() { Circle = new CircleMesh(this); }
// Use this for initialization void Start() { script = this.gameObject.AddComponent <CircleMesh>(); script.Build(1, 30, true, material); }