示例#1
0
    void Awake()
    {
        MoleculeCreator spawnScript = gameObject.GetComponent <MoleculeCreator>();

        toolKeyWords.Add("Hand");
        Gun[] allTools = Resources.FindObjectsOfTypeAll <Gun>();
        foreach (Gun tool in allTools)
        {
            if (/*tool.gameObject.activeSelf &&*/ tool.voiceName != "" && !toolKeyWords.Contains(tool.voiceName))
            {
                Debug.Log("hello " + tool.voiceName);
                toolKeyWords.Add(tool.voiceName);
            }
        }        //Tool Switchin


        Debug.Log("Speech tool list " + String.Join(", ", toolKeyWords.ToArray()));


        //Atom Spawning

        atomPrefabKeywords = new Dictionary <string, GameObject> {
            { "Hydrogen", spawnScript.hydrogenPrefab },
            { "Lithium", spawnScript.lithiumPrefab },
            { "Carbon", spawnScript.carbonPrefab },
            { "Nitrogen", spawnScript.nitrogenPrefab },
            { "Oxygen", spawnScript.oxygenPrefab },
            { "Fluorine", spawnScript.fluorinePrefab },
            { "Chlorine", spawnScript.chlorinePrefab },
            { "Sodium", spawnScript.sodiumPrefab },
            { "Phosphorus", spawnScript.phosphorusPrefab },
            { "Sulfur", spawnScript.sulfurPrefab },
            { "Iron", spawnScript.ironPrefab },
            { "Aluminum", spawnScript.aluminiumPrefab }
        };

        //Preloaded Molecule Spawning
        moleculeKeywords = new List <string> {
            "ATP", "Water", "CarbonDioxide", "Caffeine", "Aspirin", "SulfuricAcid", "SaturatedFat"
        };

        ListKeywords = ListKeywords.Concat(toolKeyWords).ToList();
        ListKeywords = ListKeywords.Concat(atomPrefabKeywords.Keys).ToList();
        ListKeywords = ListKeywords.Concat(moleculeKeywords).ToList();
        ListKeywords.Add("Reset");       //Game Reset
        ListKeywords.Add("Create");      //Pubchem Molecule Spawning
        ListKeywords.Add("BondCount");   //Count of number of Bonds/Atoms (Not precise yet, but provides rough estimate)
        ListKeywords.Add("AtomCount");
        ListKeywords.Add("help");        //Starts a Demo of how to use voice control
        ListKeywords.Add("Blackhole");   //Creates a "black hole." Pulls all atoms to a single point



        L_Recognizer = new KeywordRecognizer(ListKeywords.ToArray());
        L_Recognizer.OnPhraseRecognized += OnPhraseRecognized;
        L_Recognizer.Start();
        //StartCoroutine(GetText());

        Debug.Log("Speech recognition initialized!");
    }
示例#2
0
    void OnCollisionEnter(Collision other)
    {
        /*
         * Debug.Log("(((((((((((((((((((((((((((((");
         * Debug.Log(testString);
         * Debug.Log(nullString);
         * Debug.Log("(((((((((((((((((((((((((((((");
         * Debug.Log(saturatedfatData.ToString());
         */

        if (other.gameObject.CompareTag("Floor")

            )
        {
            MoleculeCreator script = gameObject.GetComponent <MoleculeCreator>();

            //Debug.Log("Script: "+script);

            script.instantiateMolecule(molData, transform.position);
        }

        else
        {
            Destroy(gameObject);
        }
    }
示例#3
0
    //Gets the JSON conformer file
    IEnumerator GetConformer(string ConformerID)
    {
        //Creates web request to load the JSON conformer via the conformerID
        UnityWebRequest www = UnityWebRequest.Get("https://pubchem.ncbi.nlm.nih.gov/rest/pug/conformers/" + ConformerID + "/JSON");

        yield return(www.SendWebRequest());

        //This should only happen with a real network error
        if (www.isNetworkError || www.isHttpError)
        {
            Debug.Log(www.error);
        }


        else
        {
            // Show results as text
            Debug.Log(www.downloadHandler.text);



            JObject dataObj = JObject.Parse(www.downloadHandler.text);

            //Loads molecule from JObject and instantiates it at the position of the VoiceRecognizer
            molData = loadMolecule(dataObj);
            MoleculeCreator script = gameObject.GetComponent <MoleculeCreator>();
            script.instantiateMolecule(molData, transform.position);
            GameObject.FindWithTag("DictationResult").GetComponent <TextMesh>().text = "Loaded: " + officialMolName;

            //Starts a couroutine to clear the billboard after a number of seconds
            StartCoroutine(ClearText());
        }
    }
示例#4
0
        /// <summary>
        /// Create a CellUnity molecule species from a PDB molecule definition
        /// </summary>
        /// <param name="m">PDB molecule definition</param>
        private void Create(Molecule m)
        {
            string molName = m.Name;

            Debug.Log("Imported: " + m.Atoms.Length + "atoms / " + m.Bonds.Length + "bonds");

            Debug.Log("About to add atoms...");

            // GameObjects of the atoms
            GameObject[] gameObjects = new GameObject[m.Atoms.Length];

            // atom index
            int i = 0;

            // sum of the atom mass
            float mass = 0;

            foreach (Atom atom in m.Atoms)
            {
                EditorUtility.DisplayProgressBar("Creating Molecule...", "Atom " + (i + 1) + "/" + m.Atoms.Length, (i + 1) * 1f / m.Atoms.Length);

                gameObjects[i] = AddAtom(atom);

                mass += atom.Element.Mass;

                i++;
            }

            EditorUtility.DisplayProgressBar("Creating Molecule...", "Creating Prefab...", 0.2f);

            // Create species out of atom game objects
            MoleculeCreator creator = new MoleculeCreator();

            creator.gameObjects = gameObjects;
            creator.name        = molName;
            creator.mass        = mass;
            creator.Create();

            EditorUtility.DisplayProgressBar("Creating Molecule...", "Refresh...", 0.9f);

            EditorUtility.DisplayProgressBar("Creating Molecule...", "Done", 1f);
            Debug.Log("done");
            EditorUtility.ClearProgressBar();
        }
示例#5
0
    void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.CompareTag("Floor") && touched)
        {
            MoleculeCreator script = gameObject.GetComponent <MoleculeCreator>();
            //GetComponent<Rigidbody>().position
            //GameObject.Find("Your_Name_Here").transform.position;
            script.instantiateMolecule(saturatedfatData, GameObject.Find("Ammo").transform.position);
            Debug.Log(GameObject.Find("Ammo").transform.position);

            GetComponent <AudioSource>().clip = potassium;
            GetComponent <AudioSource>().Play();
        }
        touched = false;

        /*else
         * {
         *  touched = false;
         * }*/
    }
示例#6
0
    public void getConfigFrom(MoleculeCreator from)
    {
        this.loadHetatm       = from.loadHetatm;
        this.molRessourceName = from.molRessourceName;
        this.surface          = from.surface;
        this.baseTailleCube   = from.baseTailleCube;
        this.baseProbeBoost   = from.baseProbeBoost;
        this.baseProbeSize    = from.baseProbeSize;
        this.scale            = from.scale;
        this.nbAtomsPerMesh   = from.nbAtomsPerMesh;
        this.noHydrogen       = from.noHydrogen;
        this.maxAtomsLoaded   = from.maxAtomsLoaded;

        this.carbonne  = from.carbonne;
        this.oxygene   = from.oxygene;
        this.hydrogene = from.hydrogene;
        this.azote     = from.azote;
        this.unknown   = from.unknown;

        this.stickPrincipal       = from.stickPrincipal;
        this.stickLateral         = from.stickLateral;
        this.stickPrincipalDouble = from.stickPrincipalDouble;
        this.stickLateralDouble   = from.stickLateralDouble;
    }
示例#7
0
    IEnumerator loadRandomMol(bool randFromWeb)
    {
        //Chargement d'une molecule
        MoleculeCreator molCreator = new MoleculeCreator();

        molCreator.getConfigFrom(moleculeCreatorDeBase);
        currentMolCreator = molCreator;

        if (randFromWeb)
        {
            molCreator.molRessourceName = getRandomPdbURL();
            molCreator.isURL            = true;
        }
        else
        {
            molCreator.molRessourceName = getRandomPdbLocal();
            molCreator.isURL            = false;
        }

        yield return(StartCoroutine(molCreator.load()));

        yield return(new WaitForSeconds(1.0f));

        loadingNewMol_phase1 = false;
        loadingNewMol_phase2 = true;

        //On calcule la nouvelle position de la molécule
        Vector3 posMin = new Vector3();
        Vector3 posMax = new Vector3();

        molCreator.getDimensions(ref posMin, ref posMax);

        Debug.Log("Mol dimensions min " + posMin + " max " + posMax);

        //On trouve son max de longueur
        Vector3 widthMol    = posMax - posMin;
        Vector3 rotationMol = new Vector3();
        float   zWidth      = posMax.z - posMin.z;
        float   zOffset     = -posMin.z + molCreator.getBarycenter().z;

        if (widthMol.x > widthMol.y && widthMol.x > widthMol.z)
        {
            rotationMol = new Vector3(0, -90, 0);
            zWidth      = posMax.x - posMin.x;
            zOffset     = -posMin.x + molCreator.getBarycenter().x;
        }
        if (widthMol.y > widthMol.x && widthMol.y > widthMol.z)
        {
            rotationMol = new Vector3(90, 0, 0);
            zWidth      = posMax.y - posMin.y;
            zOffset     = -posMin.y + molCreator.getBarycenter().y;
        }
        if (widthMol.z > widthMol.x && widthMol.z > widthMol.y)
        {
            rotationMol = new Vector3(0, 0, 0);
            zWidth      = posMax.z - posMin.z;
            zOffset     = -posMin.z + molCreator.getBarycenter().z;
        }

        Debug.Log("ZOFFSET " + zOffset);
        Vector3 offsetCreation = new Vector3(0, 0, currentMaxZ + zOffset);

        //Change le son
        //player.GetComponent<SoundUpdater>().setZRange(currentMaxZ, currentMaxZ + zWidth);

        //On place le parent de la molécule
        GameObject parent = new GameObject();

        parent.transform.position = offsetCreation;

        //On dit a la mol ou se placer pour qu'elle load au bon endroit
        molCreator.setOffsetCreation(offsetCreation, rotationMol);

        isMolCreated     = false;
        assyncMolCreated = molCreator;
        System.Threading.Thread m_Thread = new System.Threading.Thread(this.molCreationAssync);
        m_Thread.Start();
        while (!isMolCreated)
        {
            yield return(null);
        }
        MarchingCubes.MCMesh[] meshTab = assyncMeshTab;
        yield return(new WaitForSeconds(1.0f));


        yield return(StartCoroutine(molCreator.makeBallsView(0.3f)));

        GameObject[] ballsViews = molCreator.getBallsView();

        yield return(StartCoroutine(molCreator.makeSticksView()));

        GameObject[] sticksViews = molCreator.getSticksView();

        Debug.Log("Molecule made of " + meshTab.Length + " meshes");

        for (int i = 0; i < meshTab.Length; i++)
        {
            Mesh mesh = new Mesh();
            mesh.vertices  = meshTab[i].vertices;
            mesh.normals   = meshTab[i].normals;
            mesh.triangles = meshTab[i].triangles;
            Transform moleculePart = GameObject.Instantiate(moleculeObjectPrefab) as Transform;
            moleculePart.GetComponent <MeshFilter>().mesh          = mesh;
            moleculePart.GetComponent <MeshCollider>().sharedMesh  = mesh;
            moleculePart.GetComponent <MoleculeObject>().ballsView = ballsViews[i];
            moleculePart.position          = offsetCreation;
            moleculePart.localEulerAngles  = rotationMol;
            ballsViews[i].transform.parent = moleculePart;
            moleculePart.GetComponent <MoleculeObject>().sticksView = sticksViews[i];
            sticksViews[i].transform.parent = moleculePart;
            moleculePart.parent             = parent.transform;
            moleculePartObjs.Add(moleculePart);



            yield return(new WaitForSeconds(1.0f));
        }

        //On stoque le parent, qui représente le game object de la molécule, en aggrégant tout ses bout
        moleculeObjs.Add(parent.transform);

        for (int i = 0; i < parent.transform.childCount; i++)
        {
            Transform moleculePart = parent.transform.GetChild(i);
            createTargetsFromBBox(moleculePart.position - moleculePart.GetComponent <Collider>().bounds.extents,
                                  moleculePart.position + moleculePart.GetComponent <Collider>().bounds.extents,
                                  moleculePart);
        }



        //on bouge la molecule
        //parent.transform.position = new Vector3(0, 0, currentMaxZ + zOffset);
        //parent.transform.localEulerAngles = rotationMol;
        currentMaxZ += zWidth;

        Debug.Log("Max z is now " + currentMaxZ);

        sun.position      = new Vector3(0, 0, currentMaxZ + 1000);
        endPlane.position = new Vector3(0, 0, currentMaxZ - 500);


        /*//Le xmax de la dernière molécule
         * float maxZLast = 0;
         * Transform lastMol = lastAddedMoleculeObj;
         * if (lastMol)
         * {
         *  for (int i = 0; i < lastMol.childCount; i++)
         *  {
         *      float z = lastMol.GetChild(i).position.z + lastMol.GetChild(i).collider.bounds.extents.z;
         *      if (z > maxZLast)
         *          maxZLast = z;
         *  }
         * }
         *
         * //Le minX de notre molécule
         * float minZNew = 100000;
         * float maxZNew = 0;
         * for (int i = 0; i < parent.transform.childCount; i++)
         * {
         *  float zStart = parent.transform.GetChild(i).position.z - parent.transform.GetChild(i).collider.bounds.extents.z;
         *  float zEnd = parent.transform.GetChild(i).position.z + parent.transform.GetChild(i).collider.bounds.extents.z;
         *  if (zStart < minZNew)
         *      minZNew = zStart;
         *  if (zEnd > maxZNew)
         *      maxZNew = zEnd;
         * }*/

        //currentMaxZ = maxZLast + maxZNew;

        //Debug.Log(currentMaxZ);



        lastAddedMoleculeObj = parent.transform;

        //parent.transform.position = new Vector3(0, 0, maxZLast - minZNew + 1000);

        loadingNewMol        = false;
        loadingNewMol_phase1 = false;
        loadingNewMol_phase2 = false;



        yield return(null);
    }
示例#8
0
    public void ProcessRecognizedPhrase(string phrase)
    {
        //Debug.Log(args.text);

        //Resets game
        if (phrase == "Reset")
        {
            L_Recognizer.Stop();
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }


        //Changes tool
        if (toolKeyWords.Contains(phrase))
        {
            GameObject rightWand  = GameObject.FindWithTag("RightWand");
            GameObject leftWand   = GameObject.FindWithTag("LeftWand");
            GameObject higherWand = null;
            higherWand = rightWand == null ? leftWand : leftWand == null ? rightWand
                : rightWand.transform.position.y > leftWand.transform.position.y ? rightWand : leftWand;
            if (higherWand == null)
            {
                Debug.LogError("Could not determine which wand has the higher y value");
            }
            higherWand.GetComponent <Wand>().setToolByVoiceName(phrase);
        }



        //Spawns atoms
        if (atomPrefabKeywords.ContainsKey(phrase))
        {
            Instantiate(atomPrefabKeywords[phrase], transform.position, transform.rotation);
        }


        //Spawns preloaded molecules
        if (moleculeKeywords.Contains(phrase))
        {
            setMoleculeToSpawn(phrase);
            MoleculeCreator script = gameObject.GetComponent <MoleculeCreator>();
            script.instantiateMolecule(molData, transform.position);
        }

        //Spawns Molecules via Pubchem
        if (phrase == "Create")
        {
            //Stops keyword recognizer (needed in order to start dictator)
            PhraseRecognitionSystem.Shutdown();
            D_Recognizer = new DictationRecognizer();

            //Updates position of "billboard" and updates its status to "Listening"
            ShowOnBillboard("Listening");

            D_Recognizer.DictationResult   += DictationRecognizer_DictationResult;
            D_Recognizer.DictationComplete += DictationRecognizer_DictationComplete;
            D_Recognizer.DictationError    += DictationRecognizer_DictationError;

            //Starts dictation recognizer
            D_Recognizer.Start();
        }
        if (phrase == "BondCount")
        {
            //Gets array of objects tagged with "bond" and "doublebond", returns the sum of their length
            Array getCountSingleBond = GameObject.FindGameObjectsWithTag("Bond");
            Array getCountDoubleBond = GameObject.FindGameObjectsWithTag("DoubleBond");
            int   count = getCountSingleBond.Length + getCountDoubleBond.Length * 2;
            ShowOnBillboard("Bonds: " + count);
        }
        if (phrase == "AtomCount")
        {
            //Gets array of objects tagged with "atom", and returns its length
            Array getCount = GameObject.FindGameObjectsWithTag("Atom");
            int   count    = getCount.Length;
            ShowOnBillboard("Atoms: " + count);
        }
        if (phrase == "help")
        {
            string help = "Voice Commands:\n\n ATP, CAFFEINE, SATURATED FAT         Create molecule\n   WATER, CARBON DIOXIDE,\n   SULFURIC ACID, ASPIRIN,       \n CREATE + [Name of Molecule]          Fetch pubchem molecules\n[Element Name]                                   Create atom\n HAND, TRACTOR, PISTOL,            Change what you hold\n       BLASTER, CARDS     \n BLACKHOLE\n RESET                                               Reset game\n";
            ShowOnBillboard(help, 50);
        }
        if (phrase == "Blackhole")
        {
            GameObject.Find("Blackhole").GetComponent <BlackHole>().createBlackHole();
        }
    }
示例#9
0
    // Use this for initialization
    void Start()
    {
        aspirinData       = loadMolecule("aspirindata.json", "Aspirin");
        waterData         = loadMolecule("waterdata.json", "Water");
        atpData           = loadMolecule("atpdata.json", "ATP");
        caffeineData      = loadMolecule("caffeinedata.json", "Caffeine");
        carbondioxideData = loadMolecule("carbondioxidedata.json", "CarbonDioxide");
        saturatedfatData  = loadMolecule("saturatedfatdata.json", "SaturatedFat");
        sulfuricacidData  = loadMolecule("sulfuricaciddata.json", "SulfuricAcid");
        nitroData         = loadMolecule("nitrodata.json", "Nitroglycerin");

        /*atoms waterAtoms = new atoms(new List<int>{8,1,1});
         * bonds waterBonds = new bonds (new List<int> {1, 1}, new List<int> {2, 3}, new List<int> {1, 1});
         * coords waterCoords = new coords (new conformers(new List<float> {0,0.2774f,0.6068f}, new List<float> {0,0.8929f,-0.2383f}, new List<float> {0,0.2544f,-0.7169f}));
         * MoleculeData water = new MoleculeData( waterAtoms,waterBonds,waterCoords, "water");*/
        MoleculeCreator script = gameObject.GetComponent <MoleculeCreator> ();

        //Debug.Log(waterData.atom.element[0]);
        //Debug.Log(waterData.conf.x[1]);

        for (int i = 0; i < 3; i++)
        {
            script.instantiateMolecule(aspirinData, new Vector3(Random.Range(-3f, 4f), Random.Range(2f, 4f), Random.Range(-4f, 4f)) * spawnDist);
        }
        for (int i = 0; i < 50; i++)
        {
            script.instantiateMolecule(waterData, new Vector3(Random.Range(-3f, 4f), Random.Range(2f, 4f), Random.Range(-4f, 4f)) * spawnDist);
        }

        for (int i = 0; i < 50; i++)
        {
            script.instantiateMolecule(carbondioxideData, new Vector3(Random.Range(-3f, 4f), Random.Range(2f, 4f), Random.Range(-4, 4f)) * spawnDist);
        }

        script.instantiateMolecule(caffeineData, new Vector3(Random.Range(-3f, 4f), Random.Range(3f, 4f), Random.Range(-4f, 4f)) * spawnDist);
        script.instantiateMolecule(caffeineData, new Vector3(Random.Range(-3f, 4f), Random.Range(3f, 4f), Random.Range(-4f, 4f)) * spawnDist);
        script.instantiateMolecule(caffeineData, new Vector3(Random.Range(-3f, 4f), Random.Range(3f, 4f), Random.Range(-4f, 4f)) * spawnDist);



        script.instantiateMolecule(saturatedfatData, new Vector3(Random.Range(-3f, 4f), Random.Range(3f, 4f), Random.Range(-4f, 4f)) * spawnDist);


        script.instantiateMolecule(sulfuricacidData, new Vector3(Random.Range(-3f, 4f), Random.Range(3f, 4f), Random.Range(-4f, 4f)) * spawnDist);

        script.instantiateMolecule(nitroData, new Vector3(Random.Range(-3f, 4f), Random.Range(3f, 4f), Random.Range(-4f, 4f)) * spawnDist);



        script.instantiateMolecule(atpData, new Vector3(Random.Range(-3f, 4f), Random.Range(3f, 4f), Random.Range(-4f, 4f)) * spawnDist);

        /*
         * script.instantiateMiniatureRigidMolecule(saturatedfatData, new Vector3(Random.Range(-3f, 4f), Random.Range(3f, 4f), Random.Range(-4f, 4f)));
         *
         * script.instantiateMiniatureRigidMolecule(atpData, new Vector3(Random.Range(-3f, 4f), Random.Range(3f, 4f), Random.Range(-4f, 4f)) );
         *
         *
         * script.instantiateMiniatureRigidMolecule(caffeineData, new Vector3(Random.Range(-3f, 4f), Random.Range(3f, 4f), Random.Range(-4f, 4f)));
         *
         * script.instantiateMiniatureRigidMolecule(aspirinData, new Vector3(Random.Range(-3f, 4f), Random.Range(2f, 4f), Random.Range(-4f, 4f)));*/
    }