private void ToEnable()
    {
        //min = modelState.MinValue;
        //max = modelState.MaxValue;

        //现阶段 是否还需要父物体碰撞盒?????

        //碰撞体规则,拾取则为子物体的网格碰撞,其他状态为单帧模型的Cube碰撞体
        bool isChild = GlobalVariableBackground.Instance.conManager.isUsePackUp;

        //if (GlobalVariableBackground.Instance.isUseVtk)
        //{
        //单帧父物体 隐藏碰撞以及模型
        GetComponent <MeshRenderer>().enabled = false;
        GetComponent <MeshCollider>().enabled = false;
        if (vtkframe.selfFrameIndex == GlobalVariableBackground.Instance.FrameAllIndex)
        {
            //父物体是否显示碰撞盒 ,该帧不包含切割模型
            if (!isChild && !goHaveCutMode && transform.parent.GetComponent <modelGameObject>().vtkAllFrame.loadFile.dataType == Enums.DataType.Default)
            {
                transform.GetComponent <MeshCollider>().enabled = true;
            }
            else
            {
                transform.GetComponent <MeshCollider>().enabled = false;
            }

            modelGameObject mgo = transform.parent.GetComponent <modelGameObject>();
            //子物体碰撞盒显示条件
            for (int i = 0; i < transform.childCount; i++)
            {
                if ((mgo.vtkAllFrame.loadFile.dataType == Enums.DataType.Default &&
                     (mgo.showMode == Enums.ShowMode.Cell ||
                      mgo.showMode == Enums.ShowMode.CellAndLine)) || mgo.vtkAllFrame.loadFile.dataType == Enums.DataType.Water)
                {
                    //是否有切割对象
                    if (goHaveCutMode)
                    {
                        if (CutModeHide)
                        {
                            transform.GetChild(i).GetComponent <MeshRenderer>().enabled = true;
                        }
                        else
                        {
                            transform.GetChild(i).GetComponent <MeshRenderer>().enabled = false;
                        }
                    }
                    else
                    {
                        transform.GetChild(i).GetComponent <MeshRenderer>().enabled = true;
                    }
                }
                else
                {
                    transform.GetChild(i).GetComponent <MeshRenderer>().enabled = false;
                }
                //isCollider区分是水还是船对象是否有碰撞功能(貌似逻辑有问题)
                //isChild区分是否子对象能拾取碰撞
                //goHaveCutMode区分对象是否含有切割模式对象
                if (isCollider && isChild && !goHaveCutMode)
                {
                    //如果是切割体
                    if (isCutModelGO)
                    {
                        //且未隐藏
                        if (!CutModeHide)
                        {
                            transform.GetChild(i).GetComponent <MeshCollider>().enabled = true;
                        }
                        else
                        {
                            transform.GetChild(i).GetComponent <MeshCollider>().enabled = false;
                        }
                    }
                    else
                    {
                        //不是切割体 且 不含有切割对象
                        transform.GetChild(i).GetComponent <MeshCollider>().enabled = true;
                    }
                }
                else
                {
                    //有切割体 且 切割对象隐藏
                    if (CutModeHide)
                    {
                        transform.GetChild(i).GetComponent <MeshCollider>().enabled = true;
                    }
                    else
                    {
                        transform.GetChild(i).GetComponent <MeshCollider>().enabled = false;
                    }
                }

                if (modelState.symmetricmode != Enums.SymmetricMode.NONE)
                {
                    transform.GetChild(i).GetComponent <ChildMeshManager>().stateUpdate();
                }
            }

            if (pick.lastFrameIndex != GlobalVariableBackground.Instance.FrameAllIndex)
            {
                TableAddValue();
            }


            if (pick.isMeshHave)
            {
                PickUpUpdate();
            }
        }
        else
        {
            for (int i = 0; i < transform.childCount; i++)
            {
                transform.GetChild(i).GetComponent <MeshRenderer>().enabled = false;
                transform.GetChild(i).GetComponent <MeshCollider>().enabled = false;
            }
        }
        //}
    }
Пример #2
0
    /// <summary>
    /// 获取文件列表
    /// </summary>
    public void VTKGetFileList(Structure_LoadFile structure_loadFile)
    {
        if (structure_loadFile.FileDir == null)
        {
            return;
        }

        List <Others.MaxAndMin> listm = new List <Others.MaxAndMin>();

        if (structure_loadFile.dataType == Enums.DataType.Default)
        {
            StreamReader sr;
            string       file_name = structure_loadFile.FileDir + @"\Arr.mm";
            sr = File.OpenText(file_name);
            string strAboutAttMaxMin = sr.ReadLine();
            sr.Close();
            sr.Dispose();

            string[]         strTempArray = strAboutAttMaxMin.Trim().Split(' ');
            Others.MaxAndMin mn;
            for (int i = 0; i < strTempArray.Length;)
            {
                mn            = new Others.MaxAndMin();
                mn.Attname    = strTempArray[i++];
                mn.Dimension  = Convert.ToInt32(strTempArray[i++]);
                mn.isPointAtt = strTempArray[i++].Contains("point");
                mn.Min        = Convert.ToSingle(strTempArray[i++]);
                mn.Max        = Convert.ToSingle(strTempArray[i++]);
                listm.Add(mn);
            }
        }
        structure_loadFile.name = GetSameName(structure_loadFile.FileDir);

        string extensionName = "*.qf";

        //switch (structure_loadFile.fileType)
        //{
        //    case Enums.FileType.Tecplot:
        //        extensionName = "*.dat";
        //        break;
        //    case Enums.FileType.VTK:
        //        extensionName = "*.vtk";
        //        break;
        //    default:
        //        break;
        //}

        //创建所有帧对象
        VTK_AllFrame AllFrame = new VTK_AllFrame();

        AllFrame.point_MaxAndMin = listm;

        AllFrame.modelState = new Others.ModelState();
        int pointAttIndex = 0;
        int cellAttIndex  = 0;

        for (int i = 0; i < listm.Count; i++)
        {
            if (listm[i].Dimension == 1)
            {
                AllFrame.modelState.isUsecolor = true;
                AllFrame.modelState.isPointAtt = listm[i].isPointAtt;
                if (listm[i].isPointAtt)
                {
                    AllFrame.modelState.attIndex = pointAttIndex;
                }
                else
                {
                    AllFrame.modelState.attIndex = cellAttIndex;
                }
                AllFrame.modelState.maxminIndex = i;
                break;
            }
            else
            {
                if (listm[i].isPointAtt)
                {
                    pointAttIndex++;
                }
                else
                {
                    cellAttIndex++;
                }
            }
        }

        AllFrame.listFrame = new List <VTK_Frame>();

        AllFrame.name = structure_loadFile.name;

        //创建 场景中的 数据模型载体
        GameObject newNodel = new GameObject();

        newNodel.name             = structure_loadFile.name;
        newNodel.transform.parent = transform;
        //挂上 功能脚本
        modelGameObject modelgo = newNodel.AddComponent <modelGameObject>();

        modelgo.vtkAllFrame = AllFrame;
        AllFrame.loadFile   = structure_loadFile;


        DirectoryInfo folder = new DirectoryInfo(structure_loadFile.FileDir);

        FileInfo[] fileinfoArray = folder.GetFiles(extensionName);
        Array.Sort(fileinfoArray, new FileNameSort());

        AllFrame.FileCount = fileinfoArray.Length;

        GlobalVariableBackground.Instance.FrameALLCount = fileinfoArray.Length;

        //加载指定缓存数量的模型数据
        for (int i = 0; i < GlobalVariableBackground.Instance.modelCacheCount; i++)
        {
            GameObject goModelFrame;
            //生成 线程数据包
            goModelFrame = GameObject.Instantiate(GlobalVariableBackground.Instance.modelPerfab);

            goModelFrame.transform.parent = newNodel.transform;

            modelFrameManager modelManager = goModelFrame.AddComponent <modelFrameManager>();
            goModelFrame.AddComponent <ClickGameObjectEvent>();
            modelManager.modelState = AllFrame.modelState;

            Others.ThreadLoadFilePack pack = new Others.ThreadLoadFilePack();

            //pack.strAboutArrMAxMin = strAboutAttMaxMin;

            //创建 单帧
            VTK_Frame frame = new VTK_Frame();
            frame.point_MaxAndMin = AllFrame.point_MaxAndMin;
            modelManager.vtkframe = frame;
            frame.go = goModelFrame;
            modelManager.isCollider = structure_loadFile.dataType == Enums.DataType.Default;
            pack.vtkAllFrame        = AllFrame;
            //填充 线程数据包-》单帧
            pack.vtkFrame = frame;
            //填充 线程数据包-》单一文件
            pack.fileAddres = fileinfoArray[i];
            int fileIndex = i;

            AllFrame.listFrame.Add(frame);

            goModelFrame.name    = AllFrame.name + "#" + fileIndex;
            frame.selfFrameIndex = fileIndex;

            VTKCManager m = new VTKCManager();
            frame.timeStartLession = DateTime.Now;
            m.DisposeData(pack);

            //Thread t = new Thread(m.DisposeData);
            //t.IsBackground = true;
            //t.Start(pack);

            //ThreadPool.QueueUserWorkItem(new WaitCallback(m.DisposeData), pack as object);
        }
        folder        = null;
        fileinfoArray = null;
    }
    // Update is called once per frame

    void Update()
    {
        if (vtkframe != null && vtkframe.isLoadFinish)
        {
            vtkframe.isLoadFinish = false;
            BoxColliderChange();
            //if (transform.parent.GetComponent<modelGameObject>().vtkAllFrame.loadFile.dataType == Enums.DataType.Default)
            //{
            //}
            StartCoroutine("vtkLoadModel");
        }
        if (isLoadModelFininsh)
        {
            isLoadModelFininsh = false;
            dtColorStart       = System.DateTime.Now;
            //ToDrawColor();
            StartCoroutine("ToDrawColor");
        }

        if (isLoadColorFininsh)
        {
            isLoadColorFininsh = false;
            System.DateTime dtColorEnd = System.DateTime.Now;
            ToEnable();

            // TestMothed();

            name = name.Split('#')[0] + "#" + vtkframe.selfFrameIndex;
            vtkframe.timeLoadEnd = System.DateTime.Now;

            GlobalVariableBackground.Instance.conManager.WriteLog(vtkframe.selfFrameIndex +
                                                                  " Lession to threadStart is " + (vtkframe.timeLoadStart - vtkframe.timeStartLession).TotalMilliseconds +
                                                                  "ms, threadStart to threadEnd is " + (vtkframe.timeLoadQFEnd - vtkframe.timeLoadStart).TotalMilliseconds +
                                                                  "ms, threadEnd to Enable is " + (vtkframe.timeLoadEnd - vtkframe.timeLoadQFEnd).TotalMilliseconds +
                                                                  "ms, ColorStart To ColorEnd is " + (dtColorEnd - dtColorStart).TotalMilliseconds +
                                                                  "ms,  AllTime is " + (vtkframe.timeLoadEnd - vtkframe.timeStartLession).TotalMilliseconds + "ms ");

            //float time = System.Convert.ToSingle((vtkframe.timeLoadEnd - vtkframe.timeLoadStart).TotalSeconds / (GlobalVariableBackground.Instance.modelCacheCount / 2));

            //GlobalVariableBackground.Instance.conManager.timeIndex++;

            //GlobalVariableBackground.Instance.conManager.timeArray[GlobalVariableBackground.Instance.conManager.timeIndex % 5] = time;
            //float Sum = 0;
            //for (int i = 0; i < GlobalVariableBackground.Instance.conManager.timeArray.Length; i++)
            //{
            //    Sum += GlobalVariableBackground.Instance.conManager.timeArray[i];
            //}
            //GlobalVariableBackground.Instance.conManager.timeFloat =Mathf.Max(2f, Sum / 5) ;

            // GlobalVariableBackground.Instance.conManager.WriteLog("加载完毕");
            if (isCutModelGO)
            {
                modelGameObject model = transform.parent.GetComponent <modelGameObject>();
                if (model != null)
                {
                    modelFrameManager mf = model.vtkAllFrame.listFrame[vtkframe.selfFrameIndex % GlobalVariableBackground.Instance.modelCacheCount].go.GetComponent <modelFrameManager>();
                    mf.goHaveCutMode = true;
                    mf.ToEnable();
                }
            }

            vtkframe.isAllFinish = true;
        }
    }