14 namespace Molecule.View.DisplayBond {
    18     using System.Collections.Generic;
    31         public static GameObject BondMeshParent = 
new GameObject(
"BondMeshParent");
    41             GameObject hsmeshManagerObj = GameObject.FindGameObjectWithTag(
"HStickMeshManager");
    43             hsmeshManager.enabled = 
true;
    45             if(BondMeshParent.transform.Find(
"BondMesh0")){
    56             meshesGO = 
new List<GameObject>();
    57             DisplayBondsMethodByMesh(bondEPList.Count);
    63             hsmeshManager.enabled = 
true;
    75             int currentVertex = 0;
    78             GameObject currentGO = GameObject.CreatePrimitive(PrimitiveType.Cube);
    79             currentGO.transform.name = 
"BondMesh0";
    80             currentGO.transform.parent = BondMeshParent.transform;
    81             GameObject.Destroy(currentGO.GetComponent<Collider>());
    83             GameObject tmp = GameObject.CreatePrimitive(PrimitiveType.Cube);
    84             Mesh tmpMesh = tmp.GetComponent<MeshFilter>().mesh;
    85             GameObject.Destroy(tmp.GetComponent<Collider>());
    88             int VERTICES_IN_CUBE = tmpMesh.vertices.Length;
    89             int LIMIT_VERTICES_IN_MESH = 65536;
    90             int totalVertices = nb_sticks*VERTICES_IN_CUBE;
    91             int maxSticksinMesh = (int)LIMIT_VERTICES_IN_MESH/VERTICES_IN_CUBE;
    92             int currentSticksinMesh = (int)Mathf.Min(maxSticksinMesh,nb_sticks - (idmesh*maxSticksinMesh));
    95             int nb_meshes_needed = (int)Mathf.Ceil(totalVertices/(
float)LIMIT_VERTICES_IN_MESH);
    97             Mesh[] combinedMeshes = 
new Mesh[nb_meshes_needed];
    98             combinedMeshes[idmesh] = 
new Mesh();
   100             List<Vector3> newVertices = 
new List<Vector3>();
   101             List<Vector2> newUV = 
new List<Vector2>();
   102             List<int> newTriangles = 
new List<int>();
   104             coordStickTexture = 
new Dictionary<int,KeyValuePair<int,int> >();
   108             Texture2D[] newTextures = 
new Texture2D[nb_meshes_needed];
   109             newTextures[idmesh] =  
new Texture2D(NBPARAM,currentSticksinMesh,TextureFormat.ARGB32, 
false);
   110             float brightness=1.0f,attenuation=0.0f,shrink=0.4f,visibility=1.0f,scale=1.0f,ellipse=1.0f;
   116             for(
int i=0;i<nb_sticks;i++){
   119                 if(currentVertex + tmpMesh.vertices.Length >= LIMIT_VERTICES_IN_MESH){
   121                     combinedMeshes[idmesh].vertices = newVertices.ToArray();
   122                     combinedMeshes[idmesh].uv = newUV.ToArray();
   123                     combinedMeshes[idmesh].triangles = newTriangles.ToArray();
   124                     combinedMeshes[idmesh].Optimize();
   125                     currentGO.GetComponent<MeshFilter>().mesh.Clear();
   126                     currentGO.GetComponent<MeshFilter>().mesh = combinedMeshes[idmesh];
   127                     meshesGO.Add(currentGO);
   130                     newTextures[idmesh].Apply(
false,
false);
   131                     newTextures[idmesh].wrapMode = TextureWrapMode.Clamp;
   132                     newTextures[idmesh].filterMode = FilterMode.Point;
   134                     Material curMat = currentGO.GetComponent<Renderer>().material;
   135                     curMat.shader = Shader.Find(
"FvNano/Sticks HyperBalls Merged");
   137                     curMat.SetTexture(
"_MainTex",newTextures[idmesh]);
   138                     curMat.SetTexture(
"_MatCap",(Texture)Resources.Load(
"lit_spheres/divers/daphz05"));
   139                     curMat.SetTexture(
"_MatCap2",(Texture)Resources.Load(
"lit_spheres/divers/daphz05"));
   140                     curMat.SetFloat(
"_Brightness",brightness);
   141                     curMat.SetFloat(
"_Attenuation",attenuation);
   142                     curMat.SetFloat(
"_NBParam",(
float)NBPARAM);
   143                     curMat.SetFloat(
"_NBSticks",(
float)currentSticksinMesh);
   144                     curMat.SetFloat(
"_Shrink",shrink);
   145                     curMat.SetFloat(
"_Visibility",visibility);
   146                     curMat.SetFloat(
"_Scale",scale);
   147                     curMat.SetFloat(
"_EllipseFactor",ellipse);
   148                     currentGO.GetComponent<Renderer>().shadowCastingMode = ShadowCastingMode.Off;
   149                     currentGO.GetComponent<Renderer>().receiveShadows = 
false;
   151                     currentGO = GameObject.CreatePrimitive(PrimitiveType.Cube);
   152                     currentGO.transform.name = 
"BondMesh"+(idmesh+1).ToString();
   153                     currentGO.transform.parent = BondMeshParent.transform;
   154                     GameObject.Destroy(currentGO.GetComponent<Collider>());
   158                     newTriangles.Clear();
   160                     currentSticksinMesh = (int)Mathf.Min(maxSticksinMesh,nb_sticks - (idmesh*maxSticksinMesh));
   161                     newTextures[idmesh] =  
new Texture2D(NBPARAM,currentSticksinMesh,TextureFormat.ARGB32, 
false);
   162                     combinedMeshes[idmesh] = 
new Mesh();
   169                 int[] atomsIds = bondEPList[i] as 
int[];
   195                 Vector3 posAtom1 = 
new Vector3();
   196                 Vector3 posAtom2 = 
new Vector3();
   207                 foreach(Vector3 v 
in tmpMesh.vertices){
   208                     newVertices.Add(Vector3.Scale(v,
new Vector3(a1Model.scale/100,a1Model.scale/100,a1Model.scale/100))+posAtom1);
   210                     newUV.Add(
new Vector2(cptSticks,0f));
   213                 foreach(
int tri 
in tmpMesh.triangles)
   214                     newTriangles.Add(tri+currentVertex);
   217                 coordStickTexture.Add(i,
new KeyValuePair<int,int>(idmesh,cptSticks));
   223                 newTextures[idmesh].SetPixel(2,cptSticks ,a1Model.baseColor);
   224                 newTextures[idmesh].SetPixel(3,cptSticks ,a2Model.baseColor);
   235                 newTextures[idmesh].SetPixel(10,cptSticks ,
new Vector4(visibility,0f,0f,0f));
   237                 Vector3 light = Vector3.zero;
   253                 currentVertex+=tmpMesh.vertices.Length;
   257             combinedMeshes[idmesh].vertices = newVertices.ToArray();
   258             combinedMeshes[idmesh].uv = newUV.ToArray();
   259             combinedMeshes[idmesh].triangles = newTriangles.ToArray();
   260             combinedMeshes[idmesh].Optimize();
   261             currentGO.GetComponent<MeshFilter>().mesh.Clear();
   262             currentGO.GetComponent<MeshFilter>().mesh = combinedMeshes[idmesh];
   263             meshesGO.Add(currentGO);
   266             newTextures[idmesh].Apply(
false,
false);
   267             newTextures[idmesh].wrapMode = TextureWrapMode.Clamp;
   268             newTextures[idmesh].filterMode = FilterMode.Point;
   270             Material lastMat = currentGO.GetComponent<Renderer>().material;
   271             lastMat.shader = Shader.Find(
"FvNano/Sticks HyperBalls Merged");
   273             lastMat.SetTexture(
"_MainTex",newTextures[idmesh]);
   274             lastMat.SetTexture(
"_MatCap",(Texture)Resources.Load(
"lit_spheres/divers/daphz05"));
   275             lastMat.SetTexture(
"_MatCap2",(Texture)Resources.Load(
"lit_spheres/divers/daphz05"));
   276             lastMat.SetFloat(
"_Brightness",brightness);
   277             lastMat.SetFloat(
"_Attenuation",attenuation);
   278             lastMat.SetFloat(
"_NBParam",(
float)NBPARAM);
   279             lastMat.SetFloat(
"_NBSticks",(
float)currentSticksinMesh);
   280             lastMat.SetFloat(
"_Shrink",shrink);
   281             lastMat.SetFloat(
"_Visibility",visibility);
   282             lastMat.SetFloat(
"_Scale",scale);
   283             lastMat.SetFloat(
"_EllipseFactor",ellipse);
   284             currentGO.GetComponent<Renderer>().receiveShadows = 
false;
   285             currentGO.GetComponent<Renderer>().shadowCastingMode = ShadowCastingMode.Off;
   286             GameObject.Destroy(tmp);
 
static List< int[]> bondCAList
The bonds between carbon alpha in the CA-Spline. 
 
List< GameObject > meshesGO
 
void DisplayBondsMethodByMesh(int nb_sticks)
 
static bool secondarystruct
Switch between all atoms and C-alpha trace or BFactor secondary structure representation. 
 
GameObject[] hstick_meshes
 
override void Init()
Initalizes this instance. 
 
Dictionary< int, KeyValuePair< int, int > > coordStickTexture
 
static List< AtomModel > atomsTypelist
The type of each atom. 
 
static Vector4 EncodeFloatRGBA(float v)
 
override void EnableRenderers()
Enables the renderers for the entire set of balls and sticks. 
 
Dictionary< int, KeyValuePair< int, int > > coordStickTexture
 
!WiP Includes FLAGS of GUI. 
 
static List< int[]> bondEPList
The bonds between atoms. 
 
static List< float[]> atomsLocationlist
The coordinates of each atom.