Merge remote-tracking branch 'origin/develop' into feature/molecule

# Conflicts:
#	Assets/script/MoleculeFactory.cs
This commit is contained in:
2024-01-18 13:53:20 +01:00
19 changed files with 2484 additions and 15 deletions

View File

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using UnityEngine;
public class AtomeFactory : MonoBehaviour{
public TextAsset jsonFile;
private static AtomeFactory instance;
private AtomesInformation atomeInJson;
private Dictionary<string, AtomeInformation> AtomeDictionary;
public AtomeFactory(TextAsset jsonFile){
AtomeFactory.instance = this;
AtomeDictionary = new Dictionary<string, AtomeInformation>();
atomeInJson = JsonUtility.FromJson<AtomesInformation>(jsonFile.text);
foreach (var atome in atomeInJson.atomes){
AtomeDictionary.Add(atome.symbol, atome);
}
}
public static AtomeFactory getInstrance(){
if(AtomeFactory.instance == null){
Debug.LogError("no Json file");
}
return AtomeFactory.instance;
}
public static AtomeFactory getInstrance(TextAsset jsonFile){
if(AtomeFactory.instance == null){
AtomeFactory.instance = new AtomeFactory(jsonFile);
}
return AtomeFactory.instance;
}
public AtomeInformation createAtome(string symbol){
if(!AtomeDictionary.ContainsKey(symbol)){
Debug.LogError("Atome does not existe in json");
}
AtomeInformation atome = AtomeDictionary[symbol];
return atome;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 455447ed8d2676a4ba2d5cf8247bd83c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,37 @@
using System.Collections.Generic;
using System;
[System.Serializable]
public class AtomeProps {
public string yeardiscovered;
public string atomicmass;
public string standardstate;
public string groupblock;
public string discovered_by;
public string named_by;
}
[System.Serializable]
public class Representation {
public string color;
}
[System.Serializable]
public class AtomeInformation
{
public int atomicNumber;
public string symbol;
public string name;
public int protons;
public int neutrons;
public AtomeProps properties;
public Representation representation;
}
[System.Serializable]
public class AtomesInformation
{
// liste des liason entre les atoms
public AtomeInformation[] atomes;
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d2ff888d2e46a254ebb339c8dd3ed083
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
class MoleculeFactoryTester: MonoBehaviour {
public TextAsset moleculeJson;
public TextAsset atomJson;
void Start(){
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);
GameObject mol3 = factory.createMolecule("C4H10");
mol3.transform.position = new Vector3(0,5,0);
//GameObject bon = GameOject.CreatePrimitive(PrimitiveType.)
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8c2433f4f2c3ba343851fdf3c660c21e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -142,6 +142,23 @@
"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
}
}
]
}

View File

@ -8,11 +8,12 @@ public class MoleculeFactory : MonoBehaviour{
public TextAsset jsonFile;
private AtomeFactory atomeFactory;
private static MoleculeFactory instance;
private Molecules moleculesInJson;
private Dictionary<string, Molecule> moleculesDictionary;
private Dictionary<string, Molecule> moleculesDictionary;
public MoleculeFactory(TextAsset jsonFile){
MoleculeFactory.instance = this;
@ -37,10 +38,10 @@ public class MoleculeFactory : MonoBehaviour{
return MoleculeFactory.instance;
}
public Boolean hasMolecule(String formula)
{
return moleculesDictionary.ContainsKey(formula);
}
public Boolean hasMolecule(String formula)
{
return moleculesDictionary.ContainsKey(formula);
}
public GameObject createMolecule (string formula){
if(!moleculesDictionary.ContainsKey(formula)){
@ -50,15 +51,46 @@ public class MoleculeFactory : MonoBehaviour{
GameObject sortie = new GameObject(molecule.name);
foreach (Atom atom in molecule.atoms) {
var template = GameObject.Find("SPHERE");
var createdObj = Instantiate(template, new Vector3(atom.geometry[0], atom.geometry[1], atom.geometry[2]), Quaternion.identity);
createdObj.transform.parent = sortie.transform;
createdObj.name = atom.element;
createdObj.transform.localPosition = new Vector3(atom.geometry[0], atom.geometry[1], atom.geometry[2]);
//TODO: géré les laision
//TODO: géré la taille de l'atome
//TODO: géré la couleur de l'atome
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 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);
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;
}
}

2128
Assets/script/atomes.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ab8f44086e6af6f48a38b7d7d595e9a2
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: