on est good

This commit is contained in:
2024-01-18 14:24:40 +01:00
parent 5ca3d16a29
commit 1bf7031f32
13 changed files with 166 additions and 18 deletions

View File

@ -7,13 +7,18 @@ using UnityEngine;
class MoleculeFactoryTester: MonoBehaviour {
public TextAsset jsonFile;
public TextAsset moleculeJson;
public TextAsset atomJson;
void Start(){
MoleculeFactory factory = MoleculeFactory.getInstrance(this.jsonFile);
//GameObject mol = factory.createMolecule("O2");
MoleculeFactory factory = MoleculeFactory.getInstrance(this.moleculeJson);
AtomeFactory atomeFactory = AtomeFactory.getInstrance(this.atomJson);
factory.setAtomFactory(atomeFactory);
GameObject mol = factory.createMolecule("O2");
GameObject mol2 = factory.createMolecule("H2O");
//mol.transform.position = new Vector3(0,1,0);
mol.transform.position = new Vector3(0,1,0);
GameObject mol3 = factory.createMolecule("C4H10");
mol3.transform.position = new Vector3(0,5,0);
//GameObject bon = GameOject.CreatePrimitive(PrimitiveType.)
}

View File

@ -97,13 +97,13 @@
"name": "Eau",
"formula": "H2O",
"atoms": [
{"element": "H", "geometry": [0.0, 0.0, 0.0]},
{"element": "O", "geometry": [0.74, 0.0, 0.0]},
{"element": "H", "geometry": [-0.74, 0.0, 0.0]}
{"element": "O", "geometry": [0.0, 0.0, 0.0]},
{"element": "H", "geometry": [1.2, 0.0, 0.0]},
{"element": "H", "geometry": [-1.2, 0.0, 0.0]}
],
"bonds": [
{"atoms": [0, 1], "order": 1},
{"atoms": [1, 2], "order": 1}
{"atoms": [0, 2], "order": 1}
],
"properties": {
"molecularMass": 18.01528,

View File

@ -8,8 +8,7 @@ public class MoleculeFactory : MonoBehaviour{
public TextAsset jsonFile;
//public AtomeFactory atomeFactory = AtomeFactory.getInstrance(this.jsonFile);
private AtomeFactory atomeFactory;
private static MoleculeFactory instance;
private Molecules moleculesInJson;
@ -51,10 +50,9 @@ public class MoleculeFactory : MonoBehaviour{
sphere.transform.parent = sortie.transform;
sphere.name = atom.element;
sphere.transform.localPosition = new Vector3(atom.geometry[0], atom.geometry[1], atom.geometry[2]);
//AtomeInformation att = Atomfactory.createAtome(atom.element);
AtomeInformation att = atomeFactory.createAtome(atom.element);
Color myColor = new Color(0, 0, 1, 1);
//TODO géré atom factory
//ColorUtility.TryParseHtmlString(att.representation.color, out myColor);
ColorUtility.TryParseHtmlString(att.representation.color, out myColor);
sphere.GetComponent<Renderer>().material.color = myColor;
}
foreach (Bond bond in molecule.bonds){
@ -66,12 +64,16 @@ public class MoleculeFactory : MonoBehaviour{
float atom2z = molecule.atoms[bond.atoms[1]].geometry[2];
Vector3 vecAtom1 = new Vector3(atom1x, atom1y, atom1z);
Vector3 vecAtom2 = new Vector3(atom2x, atom2y, atom2z);
GameObject GObond = CreateCylinderBetweenPoints(vecAtom1,vecAtom2, 0.5f);
GameObject GObond = CreateCylinderBetweenPoints(vecAtom1,vecAtom2, 0.3f);
GObond.transform.parent = sortie.transform;
}
return sortie;
}
public void setAtomFactory(AtomeFactory atomeFactory){
this.atomeFactory = atomeFactory;
}
private GameObject CreateCylinderBetweenPoints(Vector3 start, Vector3 end, float width){
var offset = end - start;
var scale = new Vector3(width, offset.magnitude / 2.0f, width);