UnityMol  0.9.6-875
UnityMol viewer / In developement
ShurikenParticleManager.cs
Go to the documentation of this file.
1 
60 using UnityEngine;
61 using System.Collections;
62 using System.Collections.Generic;
63 using Molecule.Model;
64 using UI;
65 using UnityEngine.Rendering;
66 
67 
69  public ParticleSystem pSystem;
70  private Particle[] sourceParticles;
71  private static Vector3 LITTLE_OFFSET = new Vector3(0f, 0f, -1f); // not sure why, but this is needed
72  private ParticleSystem.Particle[] particles; // not exactly sure what the difference between Particle and ParticleSystem.Particle is
73  public static int pNumber;
74  //public bool test;
75  public static float radiusFactor;
76 
80  public override void Init () {
81  Debug.Log("Shuriken Initializing");
82  sourceParticles = MoleculeModel.p;
83  pNumber = sourceParticles.Length;
84  Debug.Log("Found: " + pNumber + " particles");
85  particles = new ParticleSystem.Particle[pNumber];
86 
87  for(int i=0; i<pNumber; i++) {
88  particles[i].position = sourceParticles[i].position + LITTLE_OFFSET;
89  particles[i].startColor = sourceParticles[i].color;
90  particles[i].startSize = sourceParticles[i].size * 0.5f * BallUpdate.radiusFactor;
91  }
92 
93  //We draw the molecule HERE!
94  pSystem.SetParticles(particles, pNumber);
95 
96  //CheckParticles();
97  Renderer rd = pSystem.GetComponent<Renderer>();
98  rd.enabled = true;
99 
100  enabled = true;
101  Debug.Log("Shuriken finished initializing");
102  isInit = true;
103 
104  }
105 
106  public override void DestroyAll() {
107  Debug.Log("Destroy Particles");
108  pSystem.Clear();
109  isInit = false;
110 
111  }
112 
113  public override void SetColor(Color col, List<string> atoms, string residue = "All", string chain = "All"){
114 
115  }
116  public override void SetColor(Color col, int atomNum){
117 
118  }
119  public override void SetRadii(List<string> atoms, string residue = "All", string chain = "All"){}
120  public override void SetRadii(int atomNum){}
121 
122  public override GameObject GetBall(int id){
123  return null;
124  }
125 
126  public override void ToggleDistanceCueing(bool enabling) {
127 
128  }
129 
133  private void CheckParticles() {
134  ParticleSystem.Particle[] currentParticles = new ParticleSystem.Particle[pNumber];
135  pSystem.GetParticles(currentParticles);
136  foreach(ParticleSystem.Particle p in currentParticles) {
137  Debug.Log(p.position.ToString());
138  Debug.Log(p.startColor.ToString());
139  }
140  Debug.Log(pSystem.GetComponent<Renderer>().enabled.ToString());
141  }
142 
143 /* private void ForDebugging() {
144  radiusFactor = BallUpdate.radiusFactor;
145  test = UIData.isParticlesInitialized;
146  //Debug.Log(UIData.atomtype.ToString());
147  }
148 */
149 
153  public override void ResetRadii() {
154  ParticleSystem.Particle[] currentParticles = new ParticleSystem.Particle[pNumber];
155  pSystem.GetParticles(currentParticles);
156  for(int i=0; i<pNumber; i++)
157  currentParticles[i].startSize = currentParticles[i].startSize * BallUpdate.radiusFactor / BallUpdate.oldRadiusFactor;
158 
159  pSystem.SetParticles(currentParticles, pNumber);
160  // Debug.Log("Resetting Particles radii");
162  }
163 
164  private void ResetColors() {
165  if(UIData.atomtype == UIData.AtomType.particleball) {
166  // Can't manage to change the color of the good atom. Particles and atomsColorList aren't organized the same way
167 // for(int i=0; i<pNumber; i++)
168 // currentParticles[i].color = MoleculeModel.atomsColorList[i];
169 
170 
171  BallUpdate.resetColors = false;
173  }
174  }
175 
179  public override void EnableRenderers() {
180  pSystem.GetComponent<Renderer>().enabled = true;
181  enabled = true;
182  if(UIData.guided){
183  ParticleSystem.Particle[] currentParticles = new ParticleSystem.Particle[pNumber];
184  pSystem.GetParticles(currentParticles);
185  for(int i=0; i<pNumber; i++)
186  currentParticles[i].position = new Vector3(MoleculeModel.atomsLocationlist[i][0], MoleculeModel.atomsLocationlist[i][1], MoleculeModel.atomsLocationlist[i][2]);
187  pSystem.SetParticles(currentParticles, pNumber);
188  }
189  }
190 
194  public override void DisableRenderers() {
195  pSystem.GetComponent<Renderer>().enabled = false;
196  enabled = false;
197  }
198  public override void EnableShadows(){
199  pSystem.GetComponent<Renderer>().shadowCastingMode = ShadowCastingMode.On;
200  pSystem.GetComponent<Renderer>().receiveShadows = true;
201  }
202  public override void DisableShadows(){
203  pSystem.GetComponent<Renderer>().shadowCastingMode = ShadowCastingMode.Off;
204  pSystem.GetComponent<Renderer>().receiveShadows = false;
205  }
206 
207 
208 
209  void Update () {
210  //ForDebugging();
211  if(UIData.atomtype != UIData.AtomType.particleball ){
213  return;
214  }
216  ResetRadii();
217 
218  //if(BallUpdate.resetColors)
219  // ResetColors();
220  }
221 
222  public override void ResetPositions(){
223  for (int j=0; j<particles.Length; j++){
224  particles[j].position = new Vector3(Molecule.Model.MoleculeModel.atomsLocationlist[j][0],
227  }
228  pSystem.SetParticles(particles, pNumber);
229  }
230 
231  public override void ResetIMDSimulationPositions(){
232 // for (int j=0; j<particles.Length; j++){
233 // particles[j].position = new Vector3(Molecule.Model.MoleculeModel.atomsIMDSimulationLocationlist[(j*3)],
234 // Molecule.Model.MoleculeModel.atomsIMDSimulationLocationlist[(j*3)+1],
235 // Molecule.Model.MoleculeModel.atomsIMDSimulationLocationlist[(j*3)+2]);
236 // }
237 // pSystem.SetParticles(particles, pNumber);
238  }
239  public override void showHydrogens(bool hide){
240  ParticleSystem.Particle[] currentParticles = new ParticleSystem.Particle[pNumber];
241  pSystem.GetParticles(currentParticles);
242  //Not working for now
243  for (int j=0; j<currentParticles.Length; j++){
244 
245  if(MoleculeModel.atomsTypelist[j].type == "H"){
246  if(hide)
247  currentParticles[j].lifetime = -1f;
248 
249  else
250  currentParticles[j].lifetime = Mathf.Infinity;
251 
252  }
253 
254  }
255 
256  pSystem.SetParticles(currentParticles, pNumber);
257 
258 
259 
260  }
261 }
override void SetRadii(List< string > atoms, string residue="All", string chain="All")
override void Init()
Initializes this instance of the ParticleSystem Manager.
override void SetColor(Color col, int atomNum)
override GameObject GetBall(int id)
static bool isFileLoaded
Definition: UIData.cs:115
static bool guided
Definition: UIData.cs:201
override void showHydrogens(bool hide)
override void EnableRenderers()
Enables this script and the renderer of its particle system.
static List< AtomModel > atomsTypelist
The type of each atom.
static bool resetColors
Definition: BallUpdate.cs:73
override void DisableRenderers()
Disables this script and the renderer of its particle system.
ParticleSystem.Particle[] particles
override void ResetIMDSimulationPositions()
override void SetColor(Color col, List< string > atoms, string residue="All", string chain="All")
override void SetRadii(int atomNum)
!WiP Includes FLAGS of GUI.
Definition: UIData.cs:78
void CheckParticles()
Used for debugging.
override void ToggleDistanceCueing(bool enabling)
static float radiusFactor
Definition: BallUpdate.cs:81
static float oldRadiusFactor
Definition: BallUpdate.cs:82
static bool bondsReadyToBeReset
Definition: BallUpdate.cs:75
static AtomType atomtype
Definition: UIData.cs:139
override void ResetRadii()
Resets the radii of the particle balls as needed when it is changed through the GUI.
Definition: GUIDisplay.cs:66
static List< float[]> atomsLocationlist
The coordinates of each atom.