Пример #1
0
    public virtual bool EditLoad(LEditTextFile file)
    {
        Reset();

        file.SkipLine(_Key_ConvexDataHead);
        mFlags = file.LoadValueLine <uint>(_Key_ConvexFlag);
        int vertnum = file.LoadValueLine <int>(_Key_VertexNum);

        for (int i = 0; i < vertnum; i++)
        {
            Vector3 vec = file.LoadVector3Line(_Key_Vertex);
            mLstVertices.Add(vec);
        }
        int facenum = file.LoadValueLine <int>(_Key_FaceNum);

        for (int i = 0; i < facenum; i++)
        {
            CovFace face = new CovFace();
            face.EditLoad(file);
            mLstCovFace.Add(face);
        }
        //mAABBDirty = true;

        return(true);
    }
Пример #2
0
    void OnGUI()
    {
        GUILayout.BeginVertical();

        cc = EditorGUILayout.ObjectField("凸包文件:", cc, typeof(ConvexCollection)) as ConvexCollection;

        if (GUILayout.Button("创建Convexdatas"))
        {
            cc = ScriptableObject.CreateInstance <ConvexCollection>();
            AssetDatabase.CreateAsset(cc, "Assets/Resources/ConvexDataCollection.asset");
            AssetDatabase.SaveAssets();
        }

        if (GUILayout.Button("创建Convex"))
        {
            GameObject cur = Selection.activeGameObject;
            if (cur != null)
            {
                Mesh m = cur.GetComponent <MeshFilter>().sharedMesh;
                if (m != null)
                {
                    ConvexData cd = new ConvexData();
                    if (ConvexUtil.MakeHull(m, cur.transform, "", ref cd))
                    {
                        cc.ConvexDatas.Add(cd);
                    }
                }
            }
        }

        if (GUILayout.Button("从文件添加凸包"))
        {
            LEditTextFile tf = new LEditTextFile();
            tf.OpenRead("convex.txt");

            ConvexData cd = new ConvexData();
            cd.EditLoad(tf);
            cc.ConvexDatas.Add(cd);

            tf.Close();
        }

        if (GUILayout.Button("显示凸包"))
        {
            cc.DebugRender(debugShow);
            debugShow = !debugShow;
        }

        if (GUILayout.Button("保存"))
        {
            AssetDatabase.DeleteAsset("Assets/Resources/ConvexDataCollection.asset");
            AssetDatabase.CreateAsset(cc, "Assets/Resources/ConvexDataCollection.asset");

            AssetDatabase.SaveAssets();
        }
    }
Пример #3
0
    public bool EditSave(LEditTextFile file)
    {
        file.SaveVector3Line(_Key_FaceNormal, Normal);
        file.SaveValueLine <float>(_Key_FaceDist, Dist);
        int elenum = GetEdgeNum();

        file.SaveValueLine <int>(_Key_FaceEleNum, elenum);
        for (int i = 0; i < elenum; i++)
        {
            file.SaveValueLine <int>(_Key_FaceEleVid, mLstVIDs[i]);
            file.SaveVector3Line(_Key_FaceEleNormal, Vector3.up); //废弃
            file.SaveValueLine <float>(_Key_FaceEleDist, 0);      //废弃
        }
        return(true);
    }
Пример #4
0
    public bool EditLoad(LEditTextFile file)
    {
        Normal = file.LoadVector3Line(_Key_FaceNormal);
        Dist   = file.LoadValueLine <float>(_Key_FaceDist);
        int elenum = file.LoadValueLine <int>(_Key_FaceEleNum);

        for (int i = 0; i < elenum; i++)
        {
            HalfSpace hs  = new HalfSpace();
            int       vid = file.LoadValueLine <int>(_Key_FaceEleVid);
            hs.Normal = file.LoadVector3Line(_Key_FaceEleNormal);
            hs.Dist   = file.LoadValueLine <float>(_Key_FaceEleDist);
            AddElement(vid);
        }
        return(true);
    }
Пример #5
0
    public virtual bool EditSave(LEditTextFile file)
    {
        file.SaveStrLine(_Key_ConvexDataHead, "");
        file.SaveValueLine <uint>(_Key_ConvexFlag, mFlags);
        int vertnum = GetVertexNum();

        file.SaveValueLine <int>(_Key_VertexNum, vertnum);
        for (int i = 0; i < vertnum; i++)
        {
            file.SaveVector3Line(_Key_Vertex, mLstVertices[i]);
        }
        int facenum = GetFaceNum();

        file.SaveValueLine <int>(_Key_FaceNum, facenum);
        for (int i = 0; i < facenum; i++)
        {
            mLstCovFace[i].EditSave(file);
        }
        return(true);
    }