Merge remote-tracking branch 'origin/develop' into feature/molecule
# Conflicts: # Assets/script/AtomeFactory.cs
This commit is contained in:
9
Assets/script/Molecule/Atom.cs
Normal file
9
Assets/script/Molecule/Atom.cs
Normal file
@ -0,0 +1,9 @@
|
||||
[System.Serializable]
|
||||
public class Atom
|
||||
{
|
||||
// nom de l'atom
|
||||
public string element;
|
||||
|
||||
// coordonée XYZ
|
||||
public float[] geometry;
|
||||
}
|
11
Assets/script/Molecule/Atom.cs.meta
Normal file
11
Assets/script/Molecule/Atom.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d3069c87e06b0c4c9a88c0695461936
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
9
Assets/script/Molecule/Bond.cs
Normal file
9
Assets/script/Molecule/Bond.cs
Normal file
@ -0,0 +1,9 @@
|
||||
[System.Serializable]
|
||||
public class Bond
|
||||
{
|
||||
// numéro des atome lier
|
||||
public int[] atoms;
|
||||
|
||||
// nombre de liaison
|
||||
public int order;
|
||||
}
|
11
Assets/script/Molecule/Bond.cs.meta
Normal file
11
Assets/script/Molecule/Bond.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ee91233baa5bef4288717efd423d4df
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
142
Assets/script/Molecule/Molecul.json
Normal file
142
Assets/script/Molecule/Molecul.json
Normal file
@ -0,0 +1,142 @@
|
||||
{
|
||||
"molecules":[
|
||||
{
|
||||
"name": "Méthanal",
|
||||
"formula": "CH2O",
|
||||
"atoms": [
|
||||
{
|
||||
"element": "C",
|
||||
"geometry": [0.0, 0.0, 0.0]
|
||||
},
|
||||
{
|
||||
"element": "H2",
|
||||
"geometry": [0.0, 1.0, 2.0]
|
||||
},
|
||||
{
|
||||
"element": "O",
|
||||
"geometry": [1.2, 0.0, 0.0]
|
||||
}
|
||||
],
|
||||
"bonds": [
|
||||
{"atoms": [0, 1], "order": 1},
|
||||
{"atoms": [1, 2], "order": 1}
|
||||
],
|
||||
"properties": {
|
||||
"molecularMass": 32.0,
|
||||
"meltingPoint": -218.8,
|
||||
"boilingPoint": -183.0
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Dioxygène",
|
||||
"formula": "O2",
|
||||
"atoms": [
|
||||
{
|
||||
"element": "O",
|
||||
"geometry": [0.0, 0.0, 0.0]
|
||||
},
|
||||
{
|
||||
"element": "O",
|
||||
"geometry": [1.2, 0.0, 0.0]
|
||||
}
|
||||
],
|
||||
"bonds": [
|
||||
{"atoms": [0, 1], "order": 2}
|
||||
],
|
||||
"properties": {
|
||||
"molecularMass": 32.0,
|
||||
"meltingPoint": -218.8,
|
||||
"boilingPoint": -183.0
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Ozone",
|
||||
"formula": "O3",
|
||||
"atoms": [
|
||||
{"element": "O", "geometry": [0.0, 0.0, 0.0]},
|
||||
{"element": "O", "geometry": [0.7, 0.0, 0.0]},
|
||||
{"element": "O", "geometry": [1.4, 0.0, 0.0]}
|
||||
],
|
||||
"bonds": [
|
||||
{"atoms": [0, 1], "order": 1},
|
||||
{"atoms": [1, 2], "order": 1}
|
||||
],
|
||||
"properties": {
|
||||
"molecularMass": 47.9982,
|
||||
"meltingPoint": -192.5,
|
||||
"boilingPoint": -110.0
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Dioxyde de carbone",
|
||||
"formula": "CO2",
|
||||
"atoms": [
|
||||
{"element": "C", "geometry": [0.0, 0.0, 0.0]},
|
||||
{"element": "O", "geometry": [1.2, 0.0, 0.0]},
|
||||
{"element": "O", "geometry": [-1.2, 0.0, 0.0]}
|
||||
],
|
||||
"bonds": [
|
||||
{"atoms": [0, 1], "order": 2},
|
||||
{"atoms": [0, 2], "order": 2}
|
||||
],
|
||||
"properties": {
|
||||
"molecularMass": 44.0095,
|
||||
"meltingPoint": -56.6,
|
||||
"boilingPoint": -78.5
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Butane",
|
||||
"formula": "C4H10",
|
||||
"atoms": [
|
||||
{"element": "C", "geometry": [0.0, 0.0, 0.0]},
|
||||
{"element": "C", "geometry": [1.5, 0.0, 0.0]},
|
||||
{"element": "C", "geometry": [3.0, 0.0, 0.0]},
|
||||
{"element": "C", "geometry": [4.5, 0.0, 0.0]},
|
||||
{"element": "H", "geometry": [0.0, 1.5, 0.0]},
|
||||
{"element": "H", "geometry": [0.0, -1.5, 0.0]},
|
||||
{"element": "H", "geometry": [1.5, 1.5, 0.0]},
|
||||
{"element": "H", "geometry": [1.5, -1.5, 0.0]},
|
||||
{"element": "H", "geometry": [3.0, 1.5, 0.0]},
|
||||
{"element": "H", "geometry": [3.0, -1.5, 0.0]},
|
||||
{"element": "H", "geometry": [4.5, 1.5, 0.0]},
|
||||
{"element": "H", "geometry": [4.5, -1.5, 0.0]}
|
||||
],
|
||||
"bonds": [
|
||||
{"atoms": [0, 1], "order": 1},
|
||||
{"atoms": [1, 2], "order": 1},
|
||||
{"atoms": [2, 3], "order": 1},
|
||||
{"atoms": [0, 4], "order": 1},
|
||||
{"atoms": [0, 5], "order": 1},
|
||||
{"atoms": [1, 6], "order": 1},
|
||||
{"atoms": [1, 7], "order": 1},
|
||||
{"atoms": [2, 8], "order": 1},
|
||||
{"atoms": [2, 9], "order": 1},
|
||||
{"atoms": [3, 10], "order": 1},
|
||||
{"atoms": [3, 11], "order": 1}
|
||||
],
|
||||
"properties": {
|
||||
"molecularMass": 58.1222,
|
||||
"meltingPoint": -138.3,
|
||||
"boilingPoint": -0.5
|
||||
}
|
||||
},{
|
||||
"name": "Eau",
|
||||
"formula": "H2O",
|
||||
"atoms": [
|
||||
{"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": [0, 2], "order": 1}
|
||||
],
|
||||
"properties": {
|
||||
"molecularMass": 18.01528,
|
||||
"meltingPoint": 0.0,
|
||||
"boilingPoint": 100.0
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
7
Assets/script/Molecule/Molecul.json.meta
Normal file
7
Assets/script/Molecule/Molecul.json.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a11d0f923ae50c4d82ee1dda0f629a3
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
125
Assets/script/Molecule/MoleculeFactory.cs
Normal file
125
Assets/script/Molecule/MoleculeFactory.cs
Normal file
@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MoleculeFactory : MonoBehaviour{
|
||||
|
||||
public TextAsset jsonFile;
|
||||
|
||||
private AtomeFactory atomeFactory;
|
||||
private static MoleculeFactory instance;
|
||||
|
||||
private Molecules moleculesInJson;
|
||||
|
||||
private Dictionary<string, Molecule> moleculesDictionary;
|
||||
|
||||
public MoleculeFactory(TextAsset jsonFile){
|
||||
MoleculeFactory.instance = this;
|
||||
moleculesDictionary = new Dictionary<string, Molecule>();
|
||||
moleculesInJson = JsonUtility.FromJson<Molecules>(jsonFile.text);
|
||||
foreach (var molecule in moleculesInJson.molecules){
|
||||
moleculesDictionary.Add(molecule.formula, molecule);
|
||||
}
|
||||
}
|
||||
|
||||
public static MoleculeFactory getInstrance(){
|
||||
if(MoleculeFactory.instance == null){
|
||||
Debug.LogError("no Json file");
|
||||
}
|
||||
return MoleculeFactory.instance;
|
||||
}
|
||||
|
||||
public static MoleculeFactory getInstrance(TextAsset jsonFile){
|
||||
if(MoleculeFactory.instance == null){
|
||||
MoleculeFactory.instance = new MoleculeFactory(jsonFile);
|
||||
}
|
||||
return MoleculeFactory.instance;
|
||||
}
|
||||
|
||||
public Boolean hasMolecule(String formula)
|
||||
{
|
||||
return moleculesDictionary.ContainsKey(formula);
|
||||
}
|
||||
|
||||
public GameObject createMolecule (string formula){
|
||||
if(!moleculesDictionary.ContainsKey(formula)){
|
||||
Debug.LogError("molecules does not existe in json");
|
||||
}
|
||||
Molecule molecule = moleculesDictionary[formula];
|
||||
GameObject sortie = new GameObject(molecule.name);
|
||||
foreach (Atom atom in molecule.atoms) {
|
||||
var template = GameObject.Find("SPHERE");
|
||||
var sphere = Instantiate(template, new Vector3(atom.geometry[0], atom.geometry[1], atom.geometry[2]), Quaternion.identity);
|
||||
//GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
||||
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 = atomeFactory.createAtome(atom.element);
|
||||
Color myColor = new Color(0, 0, 1, 1);
|
||||
ColorUtility.TryParseHtmlString(att.representation.color, out myColor);
|
||||
sphere.GetComponent<Renderer>().material.color = myColor;
|
||||
}
|
||||
foreach (Bond bond in molecule.bonds){
|
||||
float atom1x = molecule.atoms[bond.atoms[0]].geometry[0];
|
||||
float atom2x = molecule.atoms[bond.atoms[1]].geometry[0];
|
||||
float atom1y = molecule.atoms[bond.atoms[0]].geometry[1];
|
||||
float atom2y = molecule.atoms[bond.atoms[1]].geometry[1];
|
||||
float atom1z = molecule.atoms[bond.atoms[0]].geometry[2];
|
||||
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.3f);
|
||||
GObond.transform.parent = sortie.transform;
|
||||
}
|
||||
return sortie;
|
||||
}
|
||||
|
||||
public Molecule GetMoleculeByFormula(String formula)
|
||||
{
|
||||
if (!hasMolecule(formula))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Molecule molecule = moleculesDictionary[formula];
|
||||
return molecule;
|
||||
}
|
||||
|
||||
public Dictionary<String, AtomeInformation> GetAtomsInfoByFormula(String formula)
|
||||
{
|
||||
if (!hasMolecule(formula))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Dictionary<String, AtomeInformation> dictionary = new Dictionary<string, AtomeInformation>();
|
||||
Molecule molecule = moleculesDictionary[formula];
|
||||
foreach (var atom in molecule.atoms)
|
||||
{
|
||||
dictionary.Add(atom.element, atomeFactory.createAtome(atom.element));
|
||||
}
|
||||
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
public void setAtomFactory(AtomeFactory atomeFactory){
|
||||
this.atomeFactory = atomeFactory;
|
||||
}
|
||||
|
||||
public AtomeFactory GetAtomFactory()
|
||||
{
|
||||
return this.atomeFactory;
|
||||
}
|
||||
|
||||
private GameObject CreateCylinderBetweenPoints(Vector3 start, Vector3 end, float width){
|
||||
var offset = end - start;
|
||||
var scale = new Vector3(width, offset.magnitude / 2.0f, width);
|
||||
var position = start + (offset / 2.0f);
|
||||
|
||||
var cylinderPrefab = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
|
||||
cylinderPrefab.transform.position = position;
|
||||
cylinderPrefab.transform.rotation = Quaternion.identity;
|
||||
cylinderPrefab.transform.up = offset;
|
||||
cylinderPrefab.transform.localScale = scale;
|
||||
return cylinderPrefab;
|
||||
}
|
||||
|
||||
}
|
11
Assets/script/Molecule/MoleculeFactory.cs.meta
Normal file
11
Assets/script/Molecule/MoleculeFactory.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68834abede8b8d14d93f46876f40df3e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
27
Assets/script/Molecule/Molecules.cs
Normal file
27
Assets/script/Molecule/Molecules.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
[System.Serializable]
|
||||
public class Molecule
|
||||
{
|
||||
// nom molécules
|
||||
public string name;
|
||||
|
||||
// formule melécule
|
||||
public string formula;
|
||||
|
||||
// liste des atoms
|
||||
public Atom[] atoms;
|
||||
|
||||
// liste des liason entre les atoms
|
||||
public Bond[] bonds;
|
||||
|
||||
// prorpiété de la molécule
|
||||
public Properties properties;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class Molecules
|
||||
{
|
||||
// liste des liason entre les atoms
|
||||
public Molecule[] molecules;
|
||||
}
|
11
Assets/script/Molecule/Molecules.cs.meta
Normal file
11
Assets/script/Molecule/Molecules.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23d78ff2f0da0df4ba3f76aa522bfe4c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
10
Assets/script/Molecule/Properties.cs
Normal file
10
Assets/script/Molecule/Properties.cs
Normal file
@ -0,0 +1,10 @@
|
||||
[System.Serializable]
|
||||
public class Properties
|
||||
{
|
||||
// masse en g/mol
|
||||
public float molecularMass;
|
||||
// température de fusion (solid->liquide)
|
||||
public float meltingPoint;
|
||||
// température d'évaporation (liquide-> gaz)
|
||||
public float boilingPoint;
|
||||
}
|
11
Assets/script/Molecule/Properties.cs.meta
Normal file
11
Assets/script/Molecule/Properties.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5df75892dfdcac7468e63229a5bd0ab8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
34
Assets/script/Molecule/ReadMolecule.cs
Normal file
34
Assets/script/Molecule/ReadMolecule.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ReadMolecule : MonoBehaviour
|
||||
{
|
||||
public TextAsset jsonFile;
|
||||
|
||||
void Start(){
|
||||
Molecules moleculesInJson = JsonUtility.FromJson<Molecules>(jsonFile.text);
|
||||
|
||||
int molNum = 0;
|
||||
int dist = 5;
|
||||
foreach (Molecule molecule in moleculesInJson.molecules){
|
||||
|
||||
GameObject moleculeObj = new GameObject(molecule.name);
|
||||
|
||||
foreach (Atom atom in molecule.atoms){
|
||||
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
|
||||
sphere.transform.parent = moleculeObj.transform;
|
||||
sphere.name = atom.element;
|
||||
sphere.transform.localPosition = new Vector3(atom.geometry[0], atom.geometry[1], atom.geometry[2]);
|
||||
}
|
||||
moleculeObj.transform.position = new Vector3(molNum*dist,0,0);
|
||||
molNum++;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
Assets/script/Molecule/ReadMolecule.cs.meta
Normal file
11
Assets/script/Molecule/ReadMolecule.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f13310aa5828a5d47b5e83a3e9eb3fec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user