UnityMol  0.9.6-875
UnityMol viewer / In developement
BondCubeStyle.cs
Go to the documentation of this file.
1 
66 
67 namespace Molecule.View.DisplayBond {
68  using UnityEngine;
69  using System.Collections;
70  using System.Collections.Generic;
71  using Molecule.Model;
72  using Molecule.Control;
73  using UI;
75  public class BondCubeStyle:IBondStyle {
76  public int number=1;
77 
78  public List<int[]> bondEPList;
79  private Camera mainCam;
80 
81  public static GameObject BondCubeParent = new GameObject("BondCubeParent");
82 
83  public BondCubeStyle() {
84  }
85 
86  public void DisplayBonds() {
87  UIData.shadow = false;
88 
89  mainCam = Camera.main;
91  bondEPList=MoleculeModel.bondCAList;
92  else
93  bondEPList=MoleculeModel.bondEPList;
94 
95  int Number=bondEPList.Count/number;
96 
97  if(UIData.bondtype==UIData.BondType.cube) {
98 
99 
100  Debug.Log("DisplayBonds??bondEPList.Count " + bondEPList.Count);
101 
102  for(int i=0;i<Number;i++){
103  CreateCylinder(i*number);
104  }
105 
106  GameObject cbManagerObj = GameObject.FindGameObjectWithTag("CubeBondManager");
107  CubeBondManager cbManager = cbManagerObj.GetComponent<CubeBondManager>();
108  cbManager.Init();
109 
110  // HERE COMES THE BONDMANAGER
111  }
112  else if(UIData.bondtype==UIData.BondType.hyperstick) {
113 
114  Debug.Log("Bonds?? bondEPList.Count :: " + bondEPList.Count);
115 
116  for(int i=0;i<Number;i++){
117  CreateCylinderByShader(i*number);
118  }
119  GameObject hsManagerObj = GameObject.FindGameObjectWithTag("HStickManager");
120  HStickManager hsManager = hsManagerObj.GetComponent<HStickManager>();
121  hsManager.Init();
122 
123 // GameObject hbManagerObj = GameObject.FindGameObjectWithTag("HBallManager");
124 // HBallManager hbManager = hbManagerObj.GetComponent<HBallManager>();
125 // hbManager.findBonds();
126 // if (UIData.atomtype == UIData.AtomType.hyperball)
127 // {
128 // if (hbManager.ellipsoidViewEnabled() == true)
129 // {
130 // Debug.Log ("+++++++++BONDCUBESTULE - Ellipsoid View enabled");
131 // hbManager.RenderEllipsoids();
132 // }
133 // else {
134 // Debug.Log ("+++++++++BONDCUBESTULE - Ellipsoid View disabled");
135 // hbManager.RenderAtoms();
136 // }
137 // }
138  }
139  /*
140  else if(UIData.bondtype==UIData.BondType.bbhyperstick) {
141  if(UIData.secondarystruct)
142  bondEPList=MoleculeModel.bondCAList;
143  else
144  bondEPList=MoleculeModel.bondEPList;
145  Debug.Log("DisplayBonds??bondEPList.Count " + bondEPList.Count);
146  int Number=bondEPList.Count/number;
147 
148  for(int i=0;i<Number;i++){
149  CreateBBCylinderByShader(i*number);
150  if(i%10000 == 0)
151  yield return null;
152  }
153  }
154  */
155  }
156 
157  //Hypersticks
158  private void CreateCylinderByShader(int i) {
159  GameObject Stick;
160 
161  int[] atomsIds = bondEPList[i] as int[];
162  // Stick=GameObject.CreatePrimitive(PrimitiveType.Cube);
163  Stick = (GameObject)GameObject.Instantiate(Resources.Load("HStickPrefab"));
164  /*RuntimePlatform platform = Application.platform;
165  switch(platform) {
166  case RuntimePlatform.WindowsPlayer:
167  case RuntimePlatform.WindowsWebPlayer:
168  case RuntimePlatform.WindowsEditor:
169  Stick.GetComponent<Renderer>().material.shader=Shader.Find("StickImproved2");
170  break;
171  default :
172  Stick.GetComponent<Renderer>().material.shader=Shader.Find("StickImproved2");
173  break;
174  }*/
175  StickUpdate comp = Stick.GetComponent<StickUpdate>();
176  //Debug.Log("BOND : " + atomsIds[0] + " - " + atomsIds[1]);
177  comp.atomnumber1 = atomsIds[0];
178  comp.atomnumber2 = atomsIds[1];
179 
180 
181 
182  comp.enabled = true;
183  Stick.GetComponent<Renderer>().material.SetFloat("_Shrink", StickUpdate.shrink);
184  Stick.tag="Club";
185  Stick.GetComponent<Collider>().enabled = false;
186  float[] posAtom1 = MoleculeModel.atomsLocationlist[atomsIds[0]];
187 
188 
189  Stick.transform.position = new Vector3(posAtom1[0],posAtom1[1],posAtom1[2]);
190  Stick.transform.parent = BondCubeParent.transform;
191  }
192 
193 
194  //Cubes
195  private void CreateCylinder(int i) {
196 /* GameObject cylinder;
197  MeshFilter filter;
198  Mesh cylinderMesh;
199  cylinder=GameObject.CreatePrimitive(PrimitiveType.Cube);
200  filter=cylinder.GetComponent<MeshFilter>();
201  cylinderMesh=filter.mesh;
202  filter.mesh=new Mesh();
203  CombineInstance []instances=new CombineInstance[end-start];
204 */
205  int[] atomsIds = bondEPList[i] as int[];
206  GameObject o=GameObject.CreatePrimitive(PrimitiveType.Cube);
207  o.GetComponent<Renderer>().material=(Material)Resources.Load("Materials/CubeBoneMaterial");
208  BondCubeUpdate comp = o.AddComponent<BondCubeUpdate>();
209 
210 
211  comp.atomnumber1 = atomsIds[0];
212  comp.atomnumber2 = atomsIds[1];
213 // o.transform.position = location[0];
214 // o.transform.LookAt(location[1]);
215  o.transform.localScale=new Vector3(0.1f,0.1f,1f);
216  o.tag="Club";
217  o.transform.parent = BondCubeParent.transform;
218  }
219 
220 
221  //Billboard hypersticks (not used anymore)
222  private void CreateBBCylinderByShader(int i) {
223  GameObject Stick;
224  if(UIData.toggleClip)
225  Stick=Clip4HyperStick.CreateClip();
226  else
227  Stick=GameObject.CreatePrimitive(PrimitiveType.Plane);
228 
229  int[] atomsIds = bondEPList[i] as int[];
230 
231  Stick.transform.Rotate(new Vector3(0,-180,0));
232  Stick.AddComponent<CameraFacingBillboard>();
233  Stick.GetComponent<CameraFacingBillboard>().cameraToLookAt = mainCam;
234  RuntimePlatform platform = Application.platform;
235  switch(platform) {
236  case RuntimePlatform.WindowsPlayer:
237  case RuntimePlatform.WindowsWebPlayer:
238  case RuntimePlatform.WindowsEditor:
239  Stick.GetComponent<Renderer>().material.shader=Shader.Find("FvNano/Stick HyperBalls 2 OpenGL");
240  break;
241  default :
242  Stick.GetComponent<Renderer>().material.shader=Shader.Find("FvNano/Stick HyperBalls 2 OpenGL");
243  break;
244  }
245  Stick.AddComponent<StickUpdate>();
246 
247  StickUpdate comp = Stick.GetComponent<StickUpdate>();
248 
249  comp.atomnumber1 = atomsIds[0];
250  comp.atomnumber2 = atomsIds[1];
251 
252 
253  comp.enabled = true;
254  Stick.GetComponent<Renderer>().material.SetFloat("_Shrink", 0.01f);
255  Stick.tag="Club";
256  Stick.transform.parent = BondCubeParent.transform;
257  }
258 
259  }
260 
261 }
static List< int[]> bondCAList
The bonds between carbon alpha in the CA-Spline.
static bool secondarystruct
Switch between all atoms and C-alpha trace or BFactor secondary structure representation.
Definition: UIData.cs:176
static GameObject CreateClip()
override void Init()
Initializes this instance of the manager.
static bool toggleClip
Definition: UIData.cs:122
override void Init()
Initializes this instance of the manager.
int atomnumber1
Definition: StickUpdate.cs:85
int atomnumber2
Definition: StickUpdate.cs:86
!WiP Includes FLAGS of GUI.
Definition: UIData.cs:78
static BondType bondtype
Definition: UIData.cs:141
static List< int[]> bondEPList
The bonds between atoms.
static bool shadow
Definition: UIData.cs:198
static float shrink
Definition: StickUpdate.cs:76
Definition: GUIDisplay.cs:66
static List< float[]> atomsLocationlist
The coordinates of each atom.