UnityMol  0.9.6-875
UnityMol viewer / In developement
AtomCubeStyle.cs
Go to the documentation of this file.
1 
66 
67 namespace Molecule.View.DisplayAtom {
68  using System;
69  using UnityEngine;
70  using System.Collections;
71  using System.Collections.Generic;
72  using Molecule.Model;
73  using UI;
74  using Molecule.Control;
75  using System.Globalization;
76 
77  public class AtomCubeStyle : IAtomStyle {
78 
79  private float[] scale=new float[7];
80  public static ArrayList atomOrderList;
81  public static ArrayList atomOrderListArray;
82  private Camera mainCamera = null;
83 
84  public static GameObject AtomCubeParent = new GameObject("AtomCubeParent");
85 
87  //private GameObject[] hyperballs;
88 
89  public AtomCubeStyle() {
90 
91 
92  scale[0]=(MoleculeModel.carbonScale)/100;
93  scale[1]=(MoleculeModel.nitrogenScale)/100;
94  scale[2]=(MoleculeModel.oxygenScale)/100;
95  scale[3]=(MoleculeModel.sulphurScale)/100;
96  scale[4]=(MoleculeModel.phosphorusScale)/100;
97  scale[5]=(MoleculeModel.hydrogenScale)/100;
98  scale[6]=(MoleculeModel.unknownScale)/100;
99  }
100 
101  //Create atoms according to type. Particles are created only once except if display is forced
102  public void DisplayAtoms (UIData.AtomType type_atom, bool force_display = false) {
103  if(mainCamera == null)
104  mainCamera = Camera.main;
105  UIData.shadow = false;
106 
107  if(type_atom != UIData.AtomType.particleball || !UIData.isParticlesInitialized ||force_display) {
108  //if(!UIData.isCubeLoaded){
109 
110  if(AtomCubeParent == null)
111  AtomCubeParent = new GameObject("AtomCubeParent");
112 
113  AtomCubeParent.tag = "HBCubes";
114 
115  if(MoleculeModel.atoms != null) {
116  MoleculeModel.atoms.Clear();
117  MoleculeModel.atoms=null;
118  }
119 
120  MoleculeModel.atoms=new ArrayList();
121  atomtype = type_atom;
122  DisplayAtomMethodByCube();
123  if(UIData.atomtype == UIData.AtomType.cube){
124  UIData.shadow = true;
125  UIData.isCubeLoaded = true;
126  }
127  else if(UIData.atomtype == UIData.AtomType.hyperball)
128  UIData.isHBallLoaded = true;
129  //}
130  }
131  }
132 
133 
134  private void DisplayAtomMethodByCube() {
135 
136 // ArrayList atomListByType;
137 
138  if(atomtype != UIData.AtomType.particleball && atomtype != UIData.AtomType.particleballalphablend) {
141  else
143  }
144 
147  else
149 
150  if(atomtype==UIData.AtomType.combinemeshball) {
151  GameObject SpriteManager=GameObject.Find("SpriteManager");
152  Meshcombine combineComp = SpriteManager.GetComponent<Meshcombine>();
153  combineComp.GoOn();
154  }
155 
156  //Aurélien : the reaction is now ready to start :)
157  Reaction.isReady = true;//The arraylist MoleculeModel.atoms contains a GameObject for each atom and can now be used in Molecule3D's Update() method.
158  }
159 
160  public static Color HexToColor(string hexColor) {
161  //Remove # if present
162  if (hexColor.IndexOf('#') != -1)
163  hexColor = hexColor.Replace("#", "");
164 
165  int red = 0;
166  int green = 0;
167  int blue = 0;
168 
169  if (hexColor.Length == 6) {
170  //#RRGGBB
171  red = int.Parse(hexColor.Substring(0, 2), NumberStyles.AllowHexSpecifier);
172  green = int.Parse(hexColor.Substring(2, 2), NumberStyles.AllowHexSpecifier);
173  blue = int.Parse(hexColor.Substring(4, 2), NumberStyles.AllowHexSpecifier);
174  } else if (hexColor.Length == 3) {
175  //#RGB
176  red = int.Parse(hexColor[0].ToString() + hexColor[0].ToString(), NumberStyles.AllowHexSpecifier);
177  green = int.Parse(hexColor[1].ToString() + hexColor[1].ToString(), NumberStyles.AllowHexSpecifier);
178  blue = int.Parse(hexColor[2].ToString() + hexColor[2].ToString(), NumberStyles.AllowHexSpecifier);
179  }
180 
181  Color hexcolor= new Color(red/255f,green/255f,blue/255f);
182  return hexcolor;
183  }
184 
185 // private ArrayList AtomListByAxisOrder(ArrayList alist)
186  public ArrayList AtomListByAxisOrder(IList alist) {
187  Debug.Log("Entering :: AtomListByAxisOrder");
188  ArrayList atomListByOrder=new ArrayList();
189 
190  for(int i=0;i<alist.Count;i++) {
191  float typenumber=0f;
192  string type;
194  type = (MoleculeModel.CaSplineTypeList[i] as AtomModel).type;
195  else
196  type = (MoleculeModel.atomsTypelist[i] as AtomModel).type;
197 
198  switch(type) {
199  case "C":
200  typenumber=0f;
201  break;
202  case "N":
203  typenumber=1f;
204  break;
205  case "O":
206  typenumber=2f;
207  break;
208  case "S":
209  typenumber=3f;
210  break;
211  case "P":
212  typenumber=4f;
213  break;
214  case "H":
215  typenumber=5f;
216  break;
217  default:
218  typenumber=6f;
219  break;
220  }
221  float[] atom=new float[5];
222  atom[0]=(alist[i] as float[])[0];
223  atom[1]=(alist[i] as float[])[1];
224  atom[2]=(alist[i] as float[])[2];
225  atom[3]=typenumber;
226  atom[4]=i;
227  atomListByOrder.Add(atom);
228  }
229 // atomListByOrder=alist;//if we write like this directly, it will change the order of alist.
230  atomListByOrder.Sort(new StructComparer());
231 
232  return atomListByOrder;
233  }
234 
235 
236 
237 
238 
239  private void DisplayAtomCube(IList coordinates, IList atomModels) {
240  List<GameObject> goList = new List<GameObject>();
241  for(int i=0; i < coordinates.Count; i++){
242  goList.Add(CreateAtomHB(i, coordinates, atomModels));
243  }
244  CubeManager.cubeGameObjects = goList.ToArray();
245 
246  if(UIData.atomtype == UIData.AtomType.hyperball) {
247  GameObject hbManagerObj = GameObject.FindGameObjectWithTag("HBallManager");
248  HBallManager hbManager = hbManagerObj.GetComponent<HBallManager>();
249  hbManager.Init();
250  }
251  else if(UIData.atomtype == UIData.AtomType.optihb){
252  GameObject hbmeshManagerObj = GameObject.FindGameObjectWithTag("HBallMeshManager");
253  HBallMeshManager hbmeshManager = hbmeshManagerObj.GetComponent<HBallMeshManager>();
254  hbmeshManager.Init();
255  }
256  else {
257  GameObject cubeManagerObj = GameObject.FindGameObjectWithTag("CubeManager");
258  CubeManager cubeManager = cubeManagerObj.GetComponent<CubeManager>();
259  cubeManager.Init();
260  }
261 
262  }
263 
264  //iType : Atom category
265  private void DisplayAtomCube(ArrayList atomsLocation,int iType) {
266  Color c = new Color();
267  Vector3 v = new Vector3();
268 
269 // int atom1number = 0;
270 // int atom2number = 0;
271  bool isxgmml = UI.GUIDisplay.file_extension=="xgmml";
272  if(isxgmml) {
273 // atom1number=AtomCubeStyle.atomOrderList.IndexOf(oratom1number);
274 // atom2number=AtomCubeStyle.atomOrderList.IndexOf(oratom2number);
275  }
276  else {
277  switch(iType) {
278  case 0:c= (MoleculeModel.carbonColor.color);v=new Vector3(1.7f*scale[0],1.7f*scale[0],1.7f*scale[0]);break;//c
279  case 1:c= (MoleculeModel.nitrogenColor.color);v=new Vector3(1.55f*scale[1],1.55f*scale[1],1.55f*scale[1]);break;//n
280  case 2:c= (MoleculeModel.oxygenColor.color);v=new Vector3(1.52f*scale[2],1.52f*scale[2],1.52f*scale[2]);break;//o
281  case 3:c= (MoleculeModel.sulphurColor.color);v=new Vector3(2.27f*scale[3],2.27f*scale[3],2.27f*scale[3]);break;//s
282  case 4:c= (MoleculeModel.phosphorusColor.color);v=new Vector3(1.18f*scale[4],1.18f*scale[4],1.18f*scale[4]);break;//p
283  case 5:c= (MoleculeModel.hydrogenColor.color);v=new Vector3(1.2f*scale[5],1.2f*scale[5],1.2f*scale[5]);break;//h
284  default:c= (MoleculeModel.unknownColor.color);v=new Vector3(1.0f*scale[6],1.0f*scale[6],1.0f*scale[6]);break;//unknown
285  }
286  }
287 
288  int Number=atomsLocation.Count;
289 // CreateAtomArray(Number);
290  for(int k=0;k<Number;k++) {
291  int order=(int)((atomOrderListArray[iType] as ArrayList)[k]);
292  if(isxgmml) {
293  float pointradius=((MoleculeModel.CSRadiusList[order]) as float[])[0];
294  c=HexToColor((MoleculeModel.CSColorList[order] as string[])[0]);
295  v=new Vector3(pointradius,pointradius,pointradius);
296  }
297 // Debug.Log(order);
298 
299  if(atomtype==UIData.AtomType.hyperball||atomtype==UIData.AtomType.cube) {
300  CreateAtomHB(iType,k,atomsLocation,c,v,order);
301 // EfficientCreateAtomHB(iType, k, atomsLocation, c, v, order);
302  }
303 
304  else if(atomtype==UIData.AtomType.raycasting)
305  CreateAtomRC(iType,k,(k+1),atomsLocation,c,v,order);
306  else if(atomtype==UIData.AtomType.rcbillboard)
307  CreateAtomRCBB(iType,k,(k+1),atomsLocation,c,v,order);
308  else if(atomtype==UIData.AtomType.hbbillboard)
309  CreateAtomHBBB(iType,k,(k+1),atomsLocation,c,v,order);
310  else if(atomtype==UIData.AtomType.rcsprite)
311  CreateAtomRCSprite(iType,k,(k+1),atomsLocation,c,v,order);
312  else if(atomtype==UIData.AtomType.multihyperball)
313  CreateAtomMtHyperBall(iType,k,(k+1),atomsLocation,c,v,order);
314  else if(atomtype==UIData.AtomType.combinemeshball)
315  CreateCombineMeshHyperBall(iType,k,(k+1),atomsLocation,c,v,order);
316  else if(atomtype==UIData.AtomType.particleball)
317  CreateAtomHB(iType,k,atomsLocation,c,v,order);
318 
319  }
320 
321  }
322 
323 /*
324  private void CreateAtomArray(int size) {
325  Debug.Log("AtomArray");
326  Debug.Log(size);
327  hyperballs = new GameObject[size];
328  GameObject first = GameObject.CreatePrimitive(PrimitiveType.Cube);
329  first.transform.parent = AtomCubeParent.transform;
330  hyperballs[0] = first;
331  for(int i=1; i<size; i++)
332  hyperballs[i] = (GameObject) GameObject.Instantiate(first);
333  }
334 */
335 
336  //iAtom : Atom index in atomLocationalist
337  private GameObject CreateAtomHB(int iAtom, IList coordinates, IList atomModels) {
338  GameObject Atom;
339 
340  if(atomtype==UIData.AtomType.hyperball)
341  Atom = (GameObject)GameObject.Instantiate(Resources.Load("CubeHBPrefab"));
342  else
343  Atom = (GameObject)GameObject.Instantiate(Resources.Load("CubeCubePrefab"));
344 
345  Atom.SetActive(true);
346  // Atom = GameObject.CreatePrimitive(PrimitiveType.Cube);
347  float[] fLocation = coordinates[iAtom] as float[];
348  Vector3 location=new Vector3(fLocation[0],fLocation[1],fLocation[2]);
349 
350  AtomModel atomModel = atomModels[iAtom] as AtomModel;
351 
352  Atom.transform.Translate(location);
353  Atom.transform.parent = AtomCubeParent.transform;
354 
355  MoleculeModel.atoms.Add(Atom);
356 
357  if(atomtype==UIData.AtomType.hyperball) {
358  //Test platform to choose the good shader
359  /*RuntimePlatform platform = Application.platform;
360  switch(platform) {
361  case RuntimePlatform.WindowsPlayer:
362  case RuntimePlatform.WindowsWebPlayer:
363  case RuntimePlatform.WindowsEditor:
364  Atom.GetComponent<Renderer>().material.shader=Shader.Find("FvNano/Ball HyperBalls OpenGL 2");
365  break;
366  default :
367  Atom.GetComponent<Renderer>().material.shader=Shader.Find("FvNano/Ball HyperBalls OpenGL 2");
368 // Atom.renderer.material.shader=Shader.Find("Custom/BallImprovedZ");
369  break;
370  }*/
371 
372  // Atom.AddComponent<BallUpdateHB>();
373  if(UI.GUIDisplay.file_extension=="xgmml")
374  Atom.GetComponent<BallUpdateHB>().z=(float)(fLocation[2]);
375  }
376  else {
377  // Atom.AddComponent<BallUpdateCube>();
378  BallUpdateCube comp1 = Atom.GetComponent<BallUpdateCube>();
379  comp1.SetRayonFactor(atomModel.scale/100);
380  }
381 
382 
383  BallUpdate comp = Atom.GetComponent<BallUpdate>();
384 
385 // Debug.Log ("%%%%%%%%%%%%%%%%%%%%% Creating Atom");
386 // Debug.Log (iAtom);
387  comp.rayon = atomModel.radius;
388  comp.atomcolor = atomModel.baseColor;
389  comp.number = iAtom;
390 // Debug.Log (comp.number);
391  comp.oldrayonFactor = atomModel.scale/100; // Why division by 100 ???
392 
393  if(UI.GUIDisplay.file_extension=="xgmml") {
394  comp.rayon = ((MoleculeModel.CSRadiusList[iAtom]) as float[])[0];
395  comp.atomcolor = HexToColor((MoleculeModel.CSColorList[iAtom] as string[])[0]);
396  }
397 
398  Atom.GetComponent<Renderer>().material.SetColor("_Color", comp.atomcolor);
399 
400  comp.enabled = true;
402 
403  Atom.tag = atomModel.type;
404 
405  if(atomtype==UIData.AtomType.particleball)
406  Atom.GetComponent<Renderer>().enabled = false;
407 
408  BoxCollider collider = Atom.GetComponent<Collider>() as BoxCollider;
409  float newSize = atomModel.radius * 60 / 100;
410  collider.size = new Vector3(newSize,newSize,newSize);
411 
412  //Aurélien : Adding the atom's index to the GameObject
413  // Atom.AddComponent<AtomIndex>();
414  AtomIndex link = Atom.GetComponent<AtomIndex>();
415  link.index = (int)fLocation[3];
416 
417  return Atom;
418  }
419 
420  //iType : Atom type index (element)
421  //iAtom : Atom index in atomLocationalist
422  private void CreateAtomHB(int iType, int iAtom, ArrayList atomLocationalist, Color c, Vector3 v, int order) {
423  GameObject Atom;
424 
425  if(atomtype==UIData.AtomType.hyperball)
426  Atom = (GameObject)GameObject.Instantiate(Resources.Load("CubeHBPrefab"));
427  else
428  Atom = (GameObject)GameObject.Instantiate(Resources.Load("CubeCubePrefab"));
429 
430  Atom.SetActive(true);
431 
432 /*
433  UnityEngine.Object.Destroy(Atom.collider);
434  Object.DestroyImmediate(Atom.collider);
435  GameObject.DestroyImmediate(Atom.collider); // "good" one
436  Atom.AddComponent<Rigidbody>();
437  Atom.rigidbody.isKinematic = true;
438  Debug.Log("Atom collider?");
439  Debug.Log(Atom.collider.ToString());
440  GameObject.DestroyObject(Atom.collider);
441 */
442  float[] fLocation=atomLocationalist[iAtom] as float[];
443  Vector3 location=new Vector3(fLocation[0],fLocation[1],fLocation[2]);
444 
445  Atom.transform.Translate(location);
446  Atom.GetComponent<Renderer>().material.SetColor("_Color",c);
447  Atom.transform.parent = AtomCubeParent.transform;
448 // Debug.Log(Atom.collider.ToString());
449 
450  MoleculeModel.atoms.Add(Atom);
451 
452  BallUpdate script;
453  if(atomtype==UIData.AtomType.hyperball) {
454  BallUpdateHB comp = Atom.GetComponent<BallUpdateHB>();
455  script = comp;
456  comp.rayon=(float)(v[0]);
457  comp.atomcolor=c;
458  comp.number=order;
459  comp.z=(float)(fLocation[2]);
460 // if(UI.GUIDisplay.file_extension=="xgmml")comp.xgmml=true;
461  comp.enabled = true;
462  switch(iType) {
463  case 0:
464  comp.oldrayonFactor=(MoleculeModel.carbonScale)/100;break;
465  case 1:
466  comp.oldrayonFactor=(MoleculeModel.nitrogenScale)/100;break;
467  case 2:
468  comp.oldrayonFactor=(MoleculeModel.oxygenScale)/100;break;
469  case 3:
470  comp.oldrayonFactor=(MoleculeModel.sulphurScale)/100;break;
471  case 4:
473  case 5:
474  comp.oldrayonFactor=(MoleculeModel.hydrogenScale)/100;break;
475  default:
476  comp.oldrayonFactor=2.0f;break;
477  }
478  }
479  else {
480  // Atom.AddComponent<BallUpdateCube>();
481  BallUpdateCube comp1 = Atom.GetComponent<BallUpdateCube>();
482  script = comp1;
483 // comp1.rayon = Atom.transform.localScale.x*2;
484  comp1.rayon = (float)(v[0])*2;
485  float rayonfactor;
486  switch(iType) {
487  case 0:
488  rayonfactor=(MoleculeModel.carbonScale)/100;break;
489  case 1:
490  rayonfactor=(MoleculeModel.nitrogenScale)/100;break;
491  case 2:
492  rayonfactor=(MoleculeModel.oxygenScale)/100;break;
493  case 3:
494  rayonfactor=(MoleculeModel.sulphurScale)/100;break;
495  case 4:
496  rayonfactor=(MoleculeModel.phosphorusScale)/100;break;
497  case 5:
498  rayonfactor=(MoleculeModel.hydrogenScale)/100;break;
499  default:
500  rayonfactor=1.0f;break;
501  }
502  comp1.SetRayonFactor(rayonfactor);
503  comp1.number=order;
504  comp1.enabled = true;
505  }
506 
507  switch(iType) {
508  case 0:Atom.tag="C";break;
509  case 1:Atom.tag="N";break;
510  case 2:Atom.tag="O";break;
511  case 3:Atom.tag="S";break;
512  case 4:Atom.tag="P";break;
513  case 5:Atom.tag="H";break;
514  default:Atom.tag="X";break;
515  }
516  if(atomtype==UIData.AtomType.particleball)
517  Atom.GetComponent<Renderer>().enabled = false;
518 
519  BoxCollider collider = Atom.GetComponent<Collider>() as BoxCollider;
520  float newSize = script.rayon * 60 / 100;
521  collider.size = new Vector3(newSize,newSize,newSize);
522 
523  //Aurélien : Adding the atom's index to the GameObject
524  // Atom.AddComponent<AtomIndex>();
525  AtomIndex link = Atom.GetComponent<AtomIndex>();
526  link.index = (int)fLocation[3];
527  }
528 
529  private void CreateAtomRC(int type, int start, int end, ArrayList atomLocationalist, Color c, Vector3 v, int order) {
530  GameObject Atom;
531  Atom=GameObject.CreatePrimitive(PrimitiveType.Cube);
532  Atom.transform.parent = AtomCubeParent.transform;
533  float[] fLocation=atomLocationalist[start] as float[];
534  Vector3 location=new Vector3(fLocation[0],fLocation[1],fLocation[2]);
535  Atom.transform.Translate(location);
536  Atom.GetComponent<Renderer>().material.SetColor("_Color",c);
537  MoleculeModel.atoms.Add(Atom);
538  Atom.GetComponent<Renderer>().material.shader=Shader.Find("FvNano/HyperBalls GL_D3D");
539  Atom.AddComponent<BallUpdateRC>();
540  BallUpdateRC comp = Atom.GetComponent<BallUpdateRC>();
541  comp.rayon=(float)(v[0]);
542  comp.atomcolor=c;
543  comp.number=order;
544  comp.enabled = true;
545  switch(type) {
546  case 0:Atom.tag="C";break;
547  case 1:Atom.tag="N";break;
548  case 2:Atom.tag="O";break;
549  case 3:Atom.tag="S";break;
550  case 4:Atom.tag="P";break;
551  case 5:Atom.tag="H";break;
552  default:Atom.tag="X";break;
553  }
554 
555  //Aurélien : Adding the atom's index to the GameObject
556  Atom.AddComponent<AtomIndex>();
557  AtomIndex link = Atom.GetComponent<AtomIndex>();
558  link.index = (int)fLocation[3];
559  }
560 
561  private void CreateAtomRCBB(int type,int start ,int end,ArrayList atomLocationalist,Color c,Vector3 v,int order) {
562  GameObject Atom;
563  if(UIData.toggleClip)
565  else
566  Atom=GameObject.CreatePrimitive(PrimitiveType.Plane);
567 
568  float[] fLocation=atomLocationalist[start] as float[];
569  Vector3 location=new Vector3(fLocation[0],fLocation[1],fLocation[2]);
570 
571  Atom.transform.Translate(location);
572  Atom.GetComponent<Renderer>().material.SetColor("_Color",c);
573  MoleculeModel.atoms.Add(Atom);
574  Atom.AddComponent<CameraFacingBillboard>();
575  Atom.GetComponent<CameraFacingBillboard>().cameraToLookAt = mainCamera;
576  Atom.transform.GetComponent<Renderer>().material.shader=Shader.Find("FvNano/HyperBalls GL_D3D");
577  Atom.AddComponent<BallUpdateRC>();
578  BallUpdateRC comp = Atom.GetComponent<BallUpdateRC>();
579  comp.rayon=(float)(v[0]);
580  comp.atomcolor=c;
581  comp.number=order;
582  comp.enabled = true;
583  switch(type) {
584  case 0:Atom.tag="C";break;
585  case 1:Atom.tag="N";break;
586  case 2:Atom.tag="O";break;
587  case 3:Atom.tag="S";break;
588  case 4:Atom.tag="P";break;
589  case 5:Atom.tag="H";break;
590  default:Atom.tag="X";break;
591  }
592 
593  //Aurélien : Adding the atom's index to the GameObject
594  Atom.AddComponent<AtomIndex>();
595  AtomIndex link = Atom.GetComponent<AtomIndex>();
596  link.index = (int)fLocation[3];
597  }
598 
599  private void CreateAtomHBBB(int type,int start ,int end,ArrayList atomLocationalist,Color c,Vector3 v,int order) {
600  GameObject Atom;
601  if(UIData.toggleClip)
603  else
604  Atom=GameObject.CreatePrimitive(PrimitiveType.Plane);
605 
606  float[] fLocation=atomLocationalist[start] as float[];
607  Vector3 location=new Vector3(fLocation[0],fLocation[1],fLocation[2]);
608 
609  Atom.transform.Translate(location);
610  Atom.GetComponent<Renderer>().material.SetColor("_Color",c);
611  MoleculeModel.atoms.Add(Atom);
612  Atom.AddComponent<CameraFacingBillboard>();
613  Atom.GetComponent<CameraFacingBillboard>().cameraToLookAt = mainCamera;
614  Atom.transform.GetComponent<Renderer>().material.shader=Shader.Find("FvNano/HyperBalls GL_D3D");
615  Atom.AddComponent<BallUpdateHB>();
616  BallUpdateHB comp = Atom.GetComponent<BallUpdateHB>();
617  comp.rayon=(float)(v[0]);
618  comp.atomcolor=c;
619 // Debug.Log(start+"/"+c);
620  comp.number=order;
621  comp.enabled = true;
622 
623  switch(type) {
624  case 0:Atom.tag="C";break;
625  case 1:Atom.tag="N";break;
626  case 2:Atom.tag="O";break;
627  case 3:Atom.tag="S";break;
628  case 4:Atom.tag="P";break;
629  case 5:Atom.tag="H";break;
630  default:Atom.tag="X";break;
631  }
632 
633  //Aurélien : Adding the atom's index to the GameObject
634  Atom.AddComponent<AtomIndex>();
635  AtomIndex link = Atom.GetComponent<AtomIndex>();
636  link.index = (int)fLocation[3];
637  }
638 
639  private void CreateAtomRCSprite(int type,int start ,int end,ArrayList atomLocationalist,Color c,Vector3 v,int order) {
640  LinkedSpriteManager linkedSpriteManager=null;
641  GameObject SpriteManager;
642  if(!GameObject.Find("SpriteManager")) {
643  SpriteManager=new GameObject();
644  SpriteManager.name="SpriteManager";
645  }
646  else
647  SpriteManager=GameObject.Find("SpriteManager");
648 
649  SpriteManager.GetComponent <MeshRenderer>().enabled=true;
650 
651  if(SpriteManager.GetComponent <LinkedSpriteManager>()==null) {
652  SpriteManager.AddComponent<LinkedSpriteManager>();
653  linkedSpriteManager= (LinkedSpriteManager)Component.FindObjectOfType(typeof(LinkedSpriteManager));
654  Material mat = Resources.Load("Materials/hyperballshader", typeof(Material)) as Material;
655  linkedSpriteManager.material=mat;
656  linkedSpriteManager.allocBlockSize=atomLocationalist.Count;
657  }
658  else {
659  linkedSpriteManager= (LinkedSpriteManager)Component.FindObjectOfType(typeof(LinkedSpriteManager));
660  linkedSpriteManager.allocBlockSize=atomLocationalist.Count;
661  linkedSpriteManager.enabled=true;
662  }
663  GameObject Atom;
664  float[] fLocation=atomLocationalist[start] as float[];
665  Vector3 location=new Vector3(fLocation[0],fLocation[1],fLocation[2]);
666  UnityEngine.Object o;
667  o=MonoBehaviour.Instantiate(Resources.Load("HBspriteplane"),location,new Quaternion(0f,0f,0f,0f));
668  Atom=(GameObject)o;
669  MoleculeModel.atoms.Add(Atom);
670  Atom.GetComponent<Renderer>().material.SetColor("_Color",c);
671  BallUpdateHB comp = Atom.GetComponent<BallUpdateHB>();
672  comp.rayon=(float)(v[0]);
673  comp.atomcolor=c;
674  comp.number=order;
675  comp.enabled = true;
676  linkedSpriteManager.AddSprite(Atom, 1f, 1f, 0, 0, 256, 256, true);
677  switch(type) {
678  case 0:Atom.tag="C";break;
679  case 1:Atom.tag="N";break;
680  case 2:Atom.tag="O";break;
681  case 3:Atom.tag="S";break;
682  case 4:Atom.tag="P";break;
683  case 5:Atom.tag="H";break;
684  default:Atom.tag="X";break;
685  }
686 
687  //Aurélien : Adding the atom's index to the GameObject
688  Atom.AddComponent<AtomIndex>();
689  AtomIndex link = Atom.GetComponent<AtomIndex>();
690  link.index = (int)fLocation[3];
691  }
692 
693  private void CreateAtomMtHyperBall(int type,int start ,int end,ArrayList atomLocationalist,Color c,Vector3 v,int order) {
694  GameObject Atom;
695  if(!GameObject.Find("MultiHBCube")) {
696  Atom=GameObject.CreatePrimitive(PrimitiveType.Cube);
697  Atom.name="MultiHBCube";
698  Atom.transform.parent = AtomCubeParent.transform;
699  }
700  else
701  Atom=GameObject.Find("MultiHBCube");
702  float[] fLocation=atomLocationalist[start] as float[];
703  Vector3 location=new Vector3(fLocation[0],fLocation[1],fLocation[2]);
704  Material newMat = new Material(Shader.Find("FvNano/HyperBalls GL_D3D"));
705  newMat.SetVector("_TexPos",location);
706  newMat.SetFloat("_Rayon",(float)(v[0])*0.1f);
707  newMat.SetColor("_Color",c);
708 
709  ArrayList materialArray= new ArrayList(Atom.transform.GetComponent<Renderer>().materials);
710  materialArray.Add(newMat);
711  Material[] array = new Material[materialArray.Count];
712  materialArray.CopyTo( array );
713  Atom.transform.GetComponent<Renderer>().materials = array;
714  switch(type) {
715  case 0:Atom.tag="C";break;
716  case 1:Atom.tag="N";break;
717  case 2:Atom.tag="O";break;
718  case 3:Atom.tag="S";break;
719  case 4:Atom.tag="P";break;
720  case 5:Atom.tag="H";break;
721  default:Atom.tag="X";break;
722  }
723  //Aurélien : Adding the atom's index to the GameObject
724  Atom.AddComponent<AtomIndex>();
725  AtomIndex link = Atom.GetComponent<AtomIndex>();
726  link.index = (int)fLocation[3];
727  }
728 
729  private void CreateCombineMeshHyperBall(int type,int start ,int end,ArrayList atomLocationalist,Color c,Vector3 v,int order) {
730  GameObject SpriteManager;
731  if(!GameObject.Find("SpriteManager")) {
732  SpriteManager=GameObject.CreatePrimitive(PrimitiveType.Cube);
733  SpriteManager.name="SpriteManager";
734  }
735  else
736  SpriteManager=GameObject.Find("SpriteManager");
737 
738  GameObject Atom;
739  if(UIData.toggleClip)
741  else
742  Atom=GameObject.CreatePrimitive(PrimitiveType.Plane);
743 
744  Atom.transform.parent=SpriteManager.transform;
745  float[] fLocation=atomLocationalist[start] as float[];
746  Vector3 location=new Vector3(fLocation[0],fLocation[1],fLocation[2]);
747  Atom.transform.Translate(location);
748  Atom.GetComponent<Renderer>().material.SetColor("_Color",c);
749  MoleculeModel.atoms.Add(Atom);
750  Atom.AddComponent<CameraFacingBillboard>();
751  Atom.GetComponent<CameraFacingBillboard>().cameraToLookAt = mainCamera;
752  Atom.transform.GetComponent<Renderer>().material.shader=Shader.Find("FvNano/HyperBalls GL_D3D");
753  Atom.AddComponent<BallUpdateHB>();
754  BallUpdateHB comp = Atom.GetComponent<BallUpdateHB>();
755  comp.rayon=(float)(v[0]);
756  comp.atomcolor=c;
757  comp.number=order;
758  comp.enabled = true;
759  switch(type) {
760  case 0:Atom.tag="C";break;
761  case 1:Atom.tag="N";break;
762  case 2:Atom.tag="O";break;
763  case 3:Atom.tag="S";break;
764  case 4:Atom.tag="P";break;
765  case 5:Atom.tag="H";break;
766  default:Atom.tag="X";break;
767  }
768  //Aurélien : Adding the atom's index to the GameObject
769  Atom.AddComponent<AtomIndex>();
770  AtomIndex link = Atom.GetComponent<AtomIndex>();
771  link.index = (int)fLocation[3];
772  }
773 
774 
775  }
776 }
static List< string[]> CSColorList
virtual void SetRayonFactor(float rf)
Definition: BallUpdate.cs:97
override void Init()
Initalizes this instance.
void GoOn()
Definition: Meshcombine.cs:76
static ColorObject phosphorusColor
static bool secondarystruct
Switch between all atoms and C-alpha trace or BFactor secondary structure representation.
Definition: UIData.cs:176
static ColorObject carbonColor
Sprite AddSprite(GameObject client, float width, float height, int leftPixelX, int bottomPixelY, int pixelWidth, int pixelHeight, bool billboarded)
void DisplayAtomCube(ArrayList atomsLocation, int iType)
ArrayList AtomListByAxisOrder(IList alist)
static bool toggleClip
Definition: UIData.cs:122
override void Init()
Initializes this instance of the manager.
Definition: CubeManager.cs:13
int index
Definition: AtomIndex.cs:7
void DisplayAtoms(UIData.AtomType type_atom, bool force_display=false)
void CreateAtomHBBB(int type, int start, int end, ArrayList atomLocationalist, Color c, Vector3 v, int order)
void CreateAtomRCSprite(int type, int start, int end, ArrayList atomLocationalist, Color c, Vector3 v, int order)
static List< AtomModel > atomsTypelist
The type of each atom.
Color color
Definition: ColorObject.cs:72
void CreateAtomMtHyperBall(int type, int start, int end, ArrayList atomLocationalist, Color c, Vector3 v, int order)
Color atomcolor
Definition: BallUpdate.cs:86
static Color HexToColor(string hexColor)
static List< float[]> CSRadiusList
static ColorObject nitrogenColor
long number
Definition: BallUpdate.cs:84
float rayon
Definition: BallUpdate.cs:78
static ColorObject hydrogenColor
static ColorObject oxygenColor
void CreateCombineMeshHyperBall(int type, int start, int end, ArrayList atomLocationalist, Color c, Vector3 v, int order)
static bool isReady
Definition: Reaction.cs:15
GameObject CreateAtomHB(int iAtom, IList coordinates, IList atomModels)
static List< float[]> CaSplineList
The coordinates of each Carbon alpha in the CA-Spline.
!WiP Includes FLAGS of GUI.
Definition: UIData.cs:78
static bool isParticlesInitialized
Definition: UIData.cs:101
bool isSplineNode
Definition: BallUpdate.cs:90
Material material
!WiP manage GUI, and provide static strings for the GUI.
Definition: GUIDisplay.cs:94
static string file_extension
Definition: GUIDisplay.cs:121
void CreateAtomRCBB(int type, int start, int end, ArrayList atomLocationalist, Color c, Vector3 v, int order)
static bool isCubeLoaded
Definition: UIData.cs:103
void CreateAtomRC(int type, int start, int end, ArrayList atomLocationalist, Color c, Vector3 v, int order)
static ColorObject unknownColor
static GameObject CreateClip()
float oldrayonFactor
Definition: BallUpdate.cs:80
void DisplayAtomCube(IList coordinates, IList atomModels)
static AtomType atomtype
Definition: UIData.cs:139
override void Init()
Initalizes this instance.
Definition: HBallManager.cs:99
static ColorObject sulphurColor
static bool isHBallLoaded
Definition: UIData.cs:105
static bool shadow
Definition: UIData.cs:198
static GameObject[] cubeGameObjects
Definition: CubeManager.cs:11
void CreateAtomHB(int iType, int iAtom, ArrayList atomLocationalist, Color c, Vector3 v, int order)
static List< AtomModel > CaSplineTypeList
Type of each carbon alpha in the CA-Spline.
Definition: GUIDisplay.cs:66
static List< float[]> atomsLocationlist
The coordinates of each atom.