コード例 #1
0
    public override void OnInspectorGUI()
    {
        MegaMeshPage mod = (MegaMeshPage)target;

        //bool rebuild = DrawDefaultInspector();
#if !UNITY_5 && !UNITY_2017 && !UNITY_2018 && !UNITY_2019
        EditorGUIUtility.LookLikeControls();
#endif

        mod.Width      = EditorGUILayout.FloatField("Width", mod.Width);
        mod.Length     = EditorGUILayout.FloatField("Length", mod.Length);
        mod.Height     = EditorGUILayout.FloatField("Height", mod.Height);
        mod.WidthSegs  = EditorGUILayout.IntField("Width Segs", mod.WidthSegs);
        mod.LengthSegs = EditorGUILayout.IntField("Length Segs", mod.LengthSegs);
        mod.HeightSegs = EditorGUILayout.IntField("Height Segs", mod.HeightSegs);
        mod.genUVs     = EditorGUILayout.Toggle("Gen UVs", mod.genUVs);
        mod.rotate     = EditorGUILayout.FloatField("Rotate", mod.rotate);
        mod.PivotBase  = EditorGUILayout.Toggle("Pivot Base", mod.PivotBase);
        mod.PivotEdge  = EditorGUILayout.Toggle("Pivot Edge", mod.PivotEdge);
        mod.tangents   = EditorGUILayout.Toggle("Tangents", mod.tangents);
#if UNITY_5_5 || UNITY_5_6 || UNITY_2017 || UNITY_2018 || UNITY_2019
#else
        mod.optimize = EditorGUILayout.Toggle("Optimize", mod.optimize);
#endif

        if (GUI.changed)                //rebuild )
        {
            mod.Rebuild();
        }
    }
コード例 #2
0
    static void CreatePageMesh()
    {
        Vector3 pos = Vector3.zero;

        if (UnityEditor.SceneView.lastActiveSceneView != null)
        {
            pos = UnityEditor.SceneView.lastActiveSceneView.pivot;
        }

        GameObject go = new GameObject("Page Mesh");

        MeshFilter mf = go.AddComponent <MeshFilter>();

        mf.sharedMesh = new Mesh();
        MeshRenderer mr = go.AddComponent <MeshRenderer>();

        Material[] mats = new Material[3];

        mr.sharedMaterials = mats;
        MegaMeshPage pm = go.AddComponent <MegaMeshPage>();

        go.transform.position  = pos;
        Selection.activeObject = go;
        pm.Rebuild();
    }
コード例 #3
0
ファイル: USShowBook.cs プロジェクト: sjb8100/src
        private void InitBook()
        {
            //------------------------------------------------------------------------
            //Awake
            pBookPosition = new GameObject("Book");
            pBookPosition.transform.localPosition = new Vector3(0, -1000, 0);

            //创建plane
            pPageTemplate = GameObject.CreatePrimitive(PrimitiveType.Plane);
            pPageTemplate.transform.localPosition = new Vector3(0, -2000, 0);

            pBookPage  = new GameObject[nPageNumber];
            pMaterials = new Material[pTexture2D.Length];
            pMaterial  = new Material[2];
            //------------------------------------------------------------------------
            //------------------------------------------------------------------------
            //------------------------------------------------------------------------

            for (int i = 0; i < pTexture2D.Length; i++)
            {
                Material mat = new Material(Shader.Find("Diffuse"));
                mat.mainTexture = (Texture2D)pTexture2D[i];
                pMaterials[i]   = mat;
            }


            for (int i = 0; i < nPageNumber; i++)
            {
                pBookPage[i]                  = (GameObject)Instantiate(pPageTemplate);
                pBookPage[i].name             = (i + 1).ToString(); //改名
                pBookPage[i].transform.parent = pBookPosition.transform;

                pMeshRender = pBookPage[i].GetComponent <MeshRenderer>();

                pMaterial[0] = pMaterials[2 * i];
                pMaterial[1] = pMaterials[2 * i + 1];

                pMeshRender.materials = pMaterial;

                pBookPage[i].transform.localPosition = new Vector3(0, -i * 0.01f, 0);

                pMegaModifyObjectScript = pBookPage[i].AddComponent <MegaModifyObject>();
                pMegaPageFlipScript     = pBookPage[i].AddComponent <MegaPageFlip>();
                pMegaMeshPageScript     = pBookPage[i].AddComponent <MegaMeshPage>();
                pMegaMeshPageScript.Rebuild();
            }
        }
コード例 #4
0
ファイル: MegaShape.cs プロジェクト: HackPotter/MetaB5
    // Best if we calc the normals to avoid issues at join
    public void BuildMesh()
    {
        if (makeMesh)
        {
            //makeMesh = false;

            float sdist = stepdist * 0.1f;
            if (splines[0].length / sdist > 1500.0f)
            {
                sdist = splines[0].length / 1500.0f;
            }

            Vector3 size = Vector3.zero;
            verts.Clear();
            uvs.Clear();
            tris.Clear();
            tris1.Clear();
            tris2.Clear();
            tris = MegaTriangulator.Triangulate(this, splines[0], sdist, ref verts, ref uvs, ref tris, Pivot, ref size);

            if (shapemesh == null)
            {
                MeshFilter mf = gameObject.GetComponent <MeshFilter>();

                if (mf == null)
                {
                    mf = gameObject.AddComponent <MeshFilter>();
                }

                mf.sharedMesh = new Mesh();
                MeshRenderer mr = gameObject.GetComponent <MeshRenderer>();
                if (mr == null)
                {
                    mr = gameObject.AddComponent <MeshRenderer>();
                }

                Material[] mats = new Material[3];

                mr.sharedMaterials = mats;

                shapemesh = mf.sharedMesh;                      //Utils.GetMesh(gameObject);
            }

            int vcount = verts.Count;
            int tcount = tris.Count;

            if (Height < 0.0f)
            {
                Height = 0.0f;
            }
            float h = Height;                   //Mathf.Abs(Height);

            Matrix4x4 tm1 = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(UVRotate.x, UVRotate.y, 0.0f), new Vector3(UVScale.x, 1.0f, UVScale.y));

            //Vector3 size = shapemesh.bounds.size;

            if (GenUV)
            {
                uvs.Clear();                    // need to stop triangulator doing uvs
                Vector2 uv  = Vector2.zero;
                Vector3 uv1 = Vector3.zero;
                for (int i = 0; i < verts.Count; i++)
                {
                    uv1.x = (verts[i].x);                       // * UVScale.x) + UVOffset.x;	// * UVScale.x;
                    uv1.z = (verts[i].z);                       // * UVScale.y) + UVOffset.y;	// * UVScale.y;

                    if (!PhysUV)
                    {
                        uv1.x /= size.x;
                        uv1.z /= size.z;
                    }
                    uv1  = tm1.MultiplyPoint3x4(uv1);
                    uv.x = uv1.x + UVOffset.x;
                    uv.y = uv1.z + UVOffset.y;
                    uvs.Add(uv);
                }
            }

            if (DoubleSided && h != 0.0f)
            {
                //vcount = verts.Count;
                for (int i = 0; i < vcount; i++)
                {
                    Vector3 p = verts[i];

                    if (UseHeightCurve)
                    {
                        float alpha = MegaTriangulator.m_points[i].z / splines[0].length;
                        p.y -= h * heightCrv.Evaluate(alpha + heightOff);
                    }
                    else
                    {
                        p.y -= h;
                    }

                    verts.Add(p);                       //verts[i]);
                    uvs.Add(uvs[i]);
                }

                //tcount = tris.Count;
                for (int i = tcount - 1; i >= 0; i--)
                {
                    tris1.Add(tris[i] + vcount);
                }
            }
#if true
            // Do edge
            if (h != 0.0f)
            {
                int vc = verts.Count;

                Vector3 ep  = Vector3.zero;
                Vector2 euv = Vector2.zero;

                tm1 = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(UVRotate1.x, UVRotate1.y, 0.0f), new Vector3(UVScale1.x, 1.0f, UVScale1.y));

                // Top loop
                for (int i = 0; i < MegaTriangulator.m_points.Count; i++)
                {
                    ep = verts[i];
                    //ep.x = MegaTriangulator.m_points[i].x;
                    //ep.y = 0.0f;
                    //ep.z = MegaTriangulator.m_points[i].y;
                    verts.Add(ep);

                    //euv.x = (MegaTriangulator.m_points[i].z / splines[0].length) * 4.0f;
                    //euv.x = (MegaTriangulator.m_points[i].z * UVScale1.x) + UVOffset1.x;	// / splines[0].length) * 4.0f;
                    //euv.y = UVOffset1.y;	//0.0f;

                    ep.x = (MegaTriangulator.m_points[i].z);                            // * UVScale1.x) + UVOffset1.x;	// / splines[0].length) * 4.0f;

                    if (!PhysUV)
                    {
                        ep.x /= size.x;
                    }

                    ep.y = 0.0f;
                    ep.z = 0.0f;                        //UVOffset1.y;	//0.0f;

                    ep    = tm1.MultiplyPoint3x4(ep);
                    euv.x = ep.x + UVOffset1.x;
                    euv.y = ep.z + UVOffset1.y;

                    uvs.Add(euv);
                }
                // Add first point again
                ep = verts[0];
                //ep.y -= h * heightCrv.Evaluate(0.0f);
                verts.Add(ep);

                //euv.x = 1.0f * 4.0f;	//MegaTriangulator.m_points[0].z / splines[0].length;
                euv.x = (splines[0].length * UVScale1.x) + UVOffset1.x;                 //1.0f * 4.0f;	//MegaTriangulator.m_points[0].z / splines[0].length;
                if (!PhysUV)
                {
                    euv.x /= size.x;
                }
                euv.y = 0.0f + UVOffset1.y;
                uvs.Add(euv);

                // Bot loop
                float hd = 1.0f;

                for (int i = 0; i < MegaTriangulator.m_points.Count; i++)
                {
                    float alpha = MegaTriangulator.m_points[i].z / splines[0].length;

                    ep = verts[i];
                    if (UseHeightCurve)
                    {
                        hd = heightCrv.Evaluate(alpha + heightOff);
                    }

                    ep.y -= h * hd;                             //heightCrv.Evaluate(alpha);

                    verts.Add(ep);

                    ep.x = (MegaTriangulator.m_points[i].z); // * UVScale1.x) + UVOffset1.x;	// / splines[0].length) * 4.0f;
                    ep.z = ep.y;                             //0.0f;	//UVOffset1.y;	//0.0f;
                    ep.y = 0.0f;

                    if (!PhysUV)
                    {
                        ep.x /= size.x;
                        ep.z /= (h * hd);
                    }
                    ep    = tm1.MultiplyPoint3x4(ep);
                    euv.x = ep.x + UVOffset1.x;
                    euv.y = ep.z + UVOffset1.y;

                    //euv.x = (MegaTriangulator.m_points[i].z / splines[0].length) * 4.0f;
                    //euv.x = (MegaTriangulator.m_points[i].z * UVScale1.x) + UVOffset1.x;
                    //euv.y = ((h * hd) * UVScale1.y) + UVOffset1.y;	//1.0f;
                    uvs.Add(euv);
                }
                // Add first point again
                ep = verts[0];

                if (UseHeightCurve)
                {
                    hd = heightCrv.Evaluate(0.0f + heightOff);
                }

                ep.y -= h * hd;                 //heightCrv.Evaluate(0.0f);
                verts.Add(ep);

                ep.x = (MegaTriangulator.m_points[0].z); // * UVScale1.x) + UVOffset1.x;	// / splines[0].length) * 4.0f;
                ep.z = ep.y;                             //0.0f;	//UVOffset1.y;	//0.0f;
                ep.y = 0.0f;

                if (!PhysUV)
                {
                    ep.x /= size.x;
                    ep.z /= (h * hd);
                }
                ep    = tm1.MultiplyPoint3x4(ep);
                euv.x = ep.x + UVOffset1.x;
                euv.y = ep.z + UVOffset1.y;

                //euv.x = (MegaTriangulator.m_points[i].z / splines[0].length) * 4.0f;
                //euv.x = (MegaTriangulator.m_points[i].z * UVScale1.x) + UVOffset1.x;
                //euv.y = ((h * hd) * UVScale1.y) + UVOffset1.y;	//1.0f;
                uvs.Add(euv);

                //euv.x = 1.0f;	//MegaTriangulator.m_points[0].z / splines[0].length;
                //euv.x = (splines[0].length * UVScale1.x) + UVOffset1.x;	//MegaTriangulator.m_points[0].z / splines[0].length;
                //euv.y = (h * hd * UVScale1.y) + UVOffset1.y;	//1.0f;

                //if ( !PhysUV )
                //{
                //	euv.x /= size.x;
                //	euv.y /=
                //}
                //uvs.Add(euv);

                // Faces
                int ecount = MegaTriangulator.m_points.Count + 1;

                int ip = 0;
                for (ip = 0; ip < MegaTriangulator.m_points.Count; ip++)
                {
                    tris2.Add(ip + vc);
                    tris2.Add(ip + vc + ecount);
                    tris2.Add(ip + vc + 1);

                    tris2.Add(ip + vc + 1);
                    tris2.Add(ip + vc + ecount);
                    tris2.Add(ip + vc + ecount + 1);
                }
#if false
                tris.Add(ip + vc);
                tris.Add(ip + vc + ecount);
                tris.Add(vc);

                tris.Add(vc);
                tris.Add(ip + vc + ecount);
                tris.Add(vc + ecount);
#endif
            }
#endif
            shapemesh.Clear();

            shapemesh.vertices = verts.ToArray();
            shapemesh.uv       = uvs.ToArray();

            shapemesh.subMeshCount = 3;
            shapemesh.SetTriangles(tris.ToArray(), 0);
            shapemesh.SetTriangles(tris1.ToArray(), 1);
            shapemesh.SetTriangles(tris2.ToArray(), 2);

            //shapemesh.triangles = tris.ToArray();
            shapemesh.RecalculateNormals();
            shapemesh.RecalculateBounds();

            if (CalcTangents)
            {
                MegaMeshPage.BuildTangents(shapemesh);
            }

            //if ( mesh != null )
            //{
            //BuildMesh(mesh);
            //MegaModifyObject mo = GetComponent<MegaModifyObject>();
            //if ( mo != null )
            //{
            //	mo.MeshUpdated();
            //}
            //}
        }
    }