示例#1
0
    /*
     * private string GetClosest(Vector3 pos) {
     *      float minDist = float.MaxValue;
     *      float dist;
     *      string type = "";
     *      for(int i=0; i<locations.Count; i++) {
     *              dist = Vector3.SqrMagnitude(pos - locations[i]);
     *              if (dist < minDist) {
     *                      minDist = dist;
     *                      type = types[i];
     *              }
     *      }
     *      return type;
     * }
     *
     * private void ColorVerticesWithLists(Mesh mesh) {
     *      int nbVertices = mesh.vertices.Length;
     *      Vector3[] vertices = mesh.vertices;
     *      Color32[] meshColors = new Color32[nbVertices];
     *      string type;
     *
     *      for(int i=0; i<nbVertices; i++) {
     *              type = GetClosest(vertices[i]);
     *              meshColors[i] = AtomModel.GetAtomColor(type);
     *      }
     *      mesh.colors32 = meshColors;
     * }
     */

    private void ColorVertices(Mesh mesh)
    {
        int          nbVertices = mesh.vertices.Length;
        float        valtype;
        List <float> BFactorList = MoleculeModel.BFactorList;

        Vector3[] vertices   = mesh.vertices;
        Color32[] meshColors = new Color32[nbVertices];

        if (slowColoring)
        {
            List <float[]> atomLocs = MoleculeModel.atomsLocationlist;
            atomLocations = new List <Vector3>();
            for (int i = 0; i < atomLocs.Count; i++)
            {
                atomLocations.Add(new Vector3(atomLocs[i][0], atomLocs[i][1], atomLocs[i][2]));
            }
            atomColors = MoleculeModel.atomsColorList;
        }

        string type;

        for (int i = 0; i < nbVertices; i++)
        {
            //if(UI.UIData.atomtype == UI.UIData.AtomType.particleball){
            type = atomTree.GetClosestAtomType(vertices[i]);
            if (UI.UIData.surfColChain)
            {
                Ribbons.InitCol();
                meshColors[i] = Ribbons.GetColorChain(type);
            }
            else if (UI.UIData.surfColHydroKD)
            {
                HydrophobicScales.InitKyteDoo();
                meshColors[i] = HydrophobicScales.GetColorHydro(type);
            }
            else if (UI.UIData.surfColHydroEng)
            {
                HydrophobicScales.InitEngleman();
                meshColors[i] = HydrophobicScales.GetColorHydro(type);
            }

            else if (UI.UIData.surfColHydroEis)
            {
                HydrophobicScales.InitEisenberg();
                meshColors[i] = HydrophobicScales.GetColorHydro(type);
            }
            else if (UI.UIData.surfColPChim)
            {
                HydrophobicScales.InitPhysChim();
                meshColors[i] = HydrophobicScales.GetColorHydro(type);
            }
            else if (UI.UIData.surfColHydroWO)
            {
                HydrophobicScales.InitWhiteOct();
                meshColors[i] = HydrophobicScales.GetColorHydro(type);
            }
            else if (UI.UIData.surfColBF)
            {
                valtype = float.Parse(type);
                if (valmax == 0)
                {
                    valmin = BFactorRep.GetMin(BFactorList);
                    valmax = BFactorRep.GetMax(BFactorList);
                }
                valtype       = (valtype - valmin) / (valmax - valmin);
                bftype        = BFactorRep.GetBFStyle(valtype);
                meshColors[i] = AtomModel.GetModel(bftype).baseColor;
            }
            else
            {
                meshColors[i] = MoleculeModel.GetAtomColor(type);
            }

            //This part of the code wasn't working
            //Anyway i dunno why we want to use another way to color surfaces when not in particles mode
            //}

            /*else
             *      if(slowColoring){
             *              meshColors[i] = GetClosestAtomColor(vertices[i]);
             *      }else{
             *              type = atomTree.GetClosestAtomType(vertices[i]);
             *              meshColors[i] = MoleculeModel.GetAtomColor(type);
             *              //meshColors[i] = atomTree.GetClosestAtomColor(vertices[i]);
             * }*/
        }
        mesh.colors32 = meshColors;
    }