public void OnGUI()
    {
        EditorGUILayout.BeginVertical();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Mesh Script");
        meshScript = (MeshScript)EditorGUILayout.ObjectField(meshScript, typeof(MeshScript), true);
        EditorGUILayout.EndHorizontal();

        if (GUILayout.Button("Find Mesh"))
        {
            meshScript.findChildren();
            Undo.RegisterCreatedObjectUndo(meshScript.gameObject, "FindMesh");
        }

        EditorGUILayout.BeginHorizontal();
        translate = EditorGUILayout.Vector3Field("Vector :", translate);
        EditorGUILayout.EndHorizontal();

        if (GUILayout.Button("Make translate"))
        {
            meshScript.translate(translate);
            Undo.RegisterCreatedObjectUndo(meshScript.gameObject, "TranslateMesh");
        }

        if (GUILayout.Button("Make rotation"))
        {
            meshScript.rotate(translate);
            Undo.RegisterCreatedObjectUndo(meshScript.gameObject, "RotateMesh");
        }

        EditorGUILayout.EndVertical();
    }
Example #2
0
    private void OnValidate()
    {
        foreach (Transform obj in transform)
        {
            StartCoroutine(Destroy(obj.gameObject));
        }

        GameObject   newObj = new GameObject("Cube");
        var          mesh   = MeshScript.GetNewMesh(Vector3.up, vertexWidth, vertexHeight, Color.black);
        HalfEdgeMesh heMesh = null;

        Vector3[] directions = { Vector3.down, Vector3.back, Vector3.forward, Vector3.right, Vector3.left };
        foreach (var dir in directions)
        {
            var meshIter = MeshScript.GetNewMesh(dir, vertexWidth, vertexHeight, Color.black);
            heMesh = HalfEdgeMesh.CombineMeshes(ref mesh, meshIter);
        }

        var meshScript = newObj.AddComponent <MeshScript>();

        newObj.transform.parent = transform;
        newObj.AddComponent <MeshRenderer>().sharedMaterial = meshMaterial;
        newObj.AddComponent <MeshFilter>().sharedMesh       = mesh;
        meshScript.mesh         = mesh;
        meshScript.localUp      = Vector3.up;
        meshScript.vertexHeight = vertexHeight;
        meshScript.vertexWidth  = vertexWidth;
        meshScript.initMesh();
        meshScript.heMesh = heMesh;
    }
Example #3
0
    void GenMesh(List <Vector3> myVerts, float gravityScale, int pushDir, Vector3 pos, Vector3 scale, float weight)
    {
        Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon();
        poly.outside = myVerts;

        GameObject myObj = Poly2Mesh.CreateGameObject(poly);

        myObj.transform.position   = pos;
        myObj.transform.localScale = scale;
        myObj.gameObject.tag       = "Target";

        myObj.AddComponent <PolygonCollider2D>().points = myHelpers.L3ToV2(myVerts);

        myObj.GetComponent <Renderer>().material.shader      = Shader.Find("Sprites/Default");
        myObj.GetComponent <Renderer>().material.mainTexture = tex;

        Mesh myMesh = myObj.GetComponent <MeshFilter>().mesh;

        myMesh.uv = GetUV(myMesh.vertices);

        MeshScript meshScript = myObj.AddComponent <MeshScript>();

        meshScript.CurrentRotation = 0f;
        meshScript.OriginWeight    = weight;
        meshScript.OriginArea      = meshScript.MyArea = myHelpers.getArea(myObj);
        meshScript.MyCenter        = myHelpers.GetCentroid(myVerts);

        myObj.AddComponent <Rigidbody2D>().gravityScale = gravityScale;
    }
Example #4
0
    void prepareMeshes(GameObject myObj, List <Vector3> allVerts, List <Vector3>[] myNewVerts, Vector3[] centerInterPoints)
    {
        Mesh myMesh = myObj.GetComponent <MeshFilter>().mesh;

        Material  myMat = myObj.GetComponent <Renderer>().material;
        Texture2D tex   = (Texture2D)myMat.mainTexture;

        Vector3[] allVertsMesh;
        Vector2[] allUV;

        Vector2 parentVelocity = myObj.GetComponent <Rigidbody2D>().velocity;
        float   parentGravity  = myObj.GetComponent <Rigidbody2D>().gravityScale;

        MeshScript meshScript = myObj.GetComponent <MeshScript>();

        float originArea   = meshScript.OriginArea;
        float originWeight = meshScript.OriginWeight;
        float prevAngle    = meshScript.CurrentRotation;

        float angle = myObj.transform.localEulerAngles.z;

        angle = (angle > 180) ? angle - 360 : angle;
        angle = angle + prevAngle;

        GenMeshForUV(myMesh.uv, allVerts, out allVertsMesh, out allUV, angle);

        for (int i = 0; i < myNewVerts.Length; i++)
        {
            GenMeshSplit(allVertsMesh, allUV, myNewVerts[i], centerInterPoints[i], tex, angle, parentVelocity, parentGravity, originArea, originWeight);
        }
    }
Example #5
0
        public override void OnInspectorGUI()
        {
            MeshScript meshScript = (MeshScript)target;

            DrawDefaultInspector();
            if (GUILayout.Button("Generate"))
            {
                meshScript.GenerateMesh();
            }
        }
Example #6
0
    void GenMeshSplit(Vector3[] parentVerts, Vector2[] parentUV, List <Vector3> myVerts, Vector3 centerInterPoint, Texture tex, float rotAngle, Vector2 parentVelocity, float parentGravity, float originArea, float originWeight)
    {
        Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon();
        poly.outside = myVerts;
        GameObject myObj = Poly2Mesh.CreateGameObject(poly);

        myObj.gameObject.tag = "Target";

        Material myMat = myObj.GetComponent <Renderer>().material;

        myMat.shader      = Shader.Find("Sprites/Default");
        myMat.mainTexture = tex;

        Mesh myMesh = myObj.GetComponent <MeshFilter>().mesh;

        myMesh.uv = deductUV(parentVerts, parentUV, myMesh.vertices);


        MeshScript meshScript = myObj.AddComponent <MeshScript>();

        meshScript.ShowPerc        = ShowPercentage;
        meshScript.CurrentRotation = rotAngle;
        meshScript.OriginWeight    = originWeight;
        meshScript.OriginArea      = originArea;

        float myArea = myHelpers.getArea(myObj);

        meshScript.MyArea = myArea;

        meshScript.MyCenter = myHelpers.GetCentroid(myVerts);

        myObj.AddComponent <PolygonCollider2D>().points = myHelpers.L3ToV2(myVerts);

        Rigidbody2D myRB = myObj.AddComponent <Rigidbody2D>();

        myRB.gravityScale = parentGravity;

        myRB.velocity = parentVelocity;

        myRB.mass = (myArea * originWeight) / originArea;
        applyForceObj.MyRBS.Add(myRB);

        Vector3 myDir = myHelpers.GetCentroid(myVerts) - centerInterPoint;

        applyForceObj.MyDirs.Add(myDir.normalized);
    }