This commit is contained in:
2024-01-12 16:28:35 +01:00
parent 8b6d07fb3d
commit 13c59458bb
81 changed files with 1143 additions and 2 deletions

View File

@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
class MoleculeFactoryTester: MonoBehaviour {
public TextAsset jsonFile;
void Start(){
MoleculeFactory factory = MoleculeFactory.getInstrance(this.jsonFile);
//GameObject mol = factory.createMolecule("O2");
GameObject mol2 = factory.createMolecule("H2O");
//mol.transform.position = new Vector3(0,1,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

@ -93,6 +93,23 @@
"meltingPoint": -138.3,
"boilingPoint": -0.5
}
},{
"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]}
],
"bonds": [
{"atoms": [0, 1], "order": 1},
{"atoms": [1, 2], "order": 1}
],
"properties": {
"molecularMass": 18.01528,
"meltingPoint": 0.0,
"boilingPoint": 100.0
}
}
]
}

View File

@ -53,7 +53,32 @@ public class MoleculeFactory : MonoBehaviour{
//TODO: géré la taille de l'atome
//TODO: géré la couleur de l'atome
}
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.5f);
GObond.transform.parent = sortie.transform;
}
return sortie;
}
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;
}
}