Пример #1
0
    /// <summary>
    /// Places artefact at one of the instance points defined in Editor
    /// </summary>
    /// <param name="instantNumber">Instantiation number to place artefact at</param>
    /// <param name="browseArtefact">Artefact to place</param>
    private void PlaceArtefact(int instantNumber, GameObject collectArtefact)
    {
        Dictionary <string, Dictionary <string, float> > transInfo;
        VerticeTransform VertTrans;

        try {
            transInfo = CollectionReader.GetTransformForArtefactWithIdentifierInCollection(collectionId, collectArtefact.name);
            VertTrans = new VerticeTransform(transInfo);
        }
        catch (System.Exception ex)
        {
            transInfo = null;

            VertTrans = new VerticeTransform(loadPlaneBoxCol.bounds.min.x, loadPlaneBoxCol.bounds.max.x,
                                             loadPlaneBoxCol.bounds.min.z, loadPlaneBoxCol.bounds.max.z);
            Debug.Log("No pos info available, random assignment");
            Debug.Log("Random pos: " + VertTrans.position.x + " " + VertTrans.position.y + " " + VertTrans.position.z);
        }
        Instantiate(particleLocator, collectArtefact.transform);

        collectArtefact.transform.position = VertTrans.position;;
        Rigidbody rb = collectArtefact.AddComponent <Rigidbody> ();

        rb.mass = 3;
        collectArtefact.GetComponent <MeshRenderer>().enabled = true;

        ProgressBarCont.AddTask("Placing " + collectArtefact.name);
    }
Пример #2
0
    public void TestInstantiateRandomTransform()
    {
        VerticeTransform transform = new VerticeTransform(-10.0f, 10.0f, -10.0f, 10.0f);

        // Check that x is between xMin and xMax
        Assert.That(transform.position.x > -10.0f);
        Assert.That(transform.position.x < 10.0f);

        // Check that the default value (i.e. y = 15) is respected
        Assert.That(transform.position.y == 15.0f);

        // Check that z is between zMin and zMax
        Assert.That(transform.position.z > -10.0f);
        Assert.That(transform.position.z < 10.0f);

        // Check that rotation is set to the identity
        Assert.That(transform.rotation.x == Quaternion.identity.x);
        Assert.That(transform.rotation.y == Quaternion.identity.y);
        Assert.That(transform.rotation.z == Quaternion.identity.z);
        Assert.That(transform.rotation.w == Quaternion.identity.w);

        // Check that scale is set to the identity
        Assert.That(transform.scale.x == 1.0f);
        Assert.That(transform.scale.y == 1.0f);
        Assert.That(transform.scale.z == 1.0f);
    }
Пример #3
0
    /// <summary>
    /// Adds the artefacts belonging to a collection and their transforms to the <structural> child of a <verticeCollection> element
    /// </summary>
    /// <param name="collectionNode">The <verticeCollection> node</param>
    /// <param name="artefactTransforms">A dictionary mapping artefact identifiers to their VerticeTransform transforms</param>
    static void AddArtefactsToCollectionNode(XmlNode collectionNode, Dictionary <string, VerticeTransform> artefactTransforms)
    {
        XmlNode structuralNode = collectionNode.SelectSingleNode("structural");

        if (structuralNode == null)
        {
            XmlElement structuralElement = _xmlDocument.CreateElement("structural");
            structuralNode = collectionNode.AppendChild(structuralElement);
        }

        // Iterate through each artefact and pull out its identifier and transform, then add
        // a subtree to the <structural> element of the form:
        //		<artefact id="...">
        //			<transform>
        //				<position>
        //					<x>...</x>
        //					<y>...</y>
        //					<z>...</z>
        //				</position>
        //				<rotation>
        //					<x>...</x>
        //					<y>...</y>
        //					<z>...</z>
        //					<w>...</w>
        //				</rotation>
        //				<scale>
        //					<x>...</x>
        //					<y>...</y>
        //					<z>...</z>
        //				</scale>
        //			</transform>
        //		</artefact>
        foreach (string key in artefactTransforms.Keys)
        {
            XmlElement artefactElement = _xmlDocument.CreateElement("artefact");
            artefactElement.SetAttribute("id", key);
            XmlElement transformElement = _xmlDocument.CreateElement("transform");
            XmlNode    artefactNode     = structuralNode.AppendChild(artefactElement);

            VerticeTransform transform = artefactTransforms [key];

            XmlElement positionElement = _xmlDocument.CreateElement("position");
            XmlElement rotationElement = _xmlDocument.CreateElement("rotation");
            XmlElement scaleElement    = _xmlDocument.CreateElement("scale");

            addVector3ToNode(positionElement, artefactTransforms [key].position);
            addQuaternionToNode(rotationElement, artefactTransforms [key].rotation);
            addVector3ToNode(scaleElement, artefactTransforms [key].scale);

            transformElement.AppendChild(positionElement);
            transformElement.AppendChild(rotationElement);
            transformElement.AppendChild(scaleElement);

            artefactNode.AppendChild(transformElement);
            structuralNode.AppendChild(artefactNode);
        }
    }
Пример #4
0
    public void AddToCollection()
    {
        VerticeTransform defaultPosition = new VerticeTransform();

        if (ArtefactSaveData.ArtefactIdentifier != null)
        {
            Debug.Log("Collection identifier: " + identifier.text);
            CollectionWriter.AddArtefactToCollectionWithIdentifier(identifier.text, ArtefactSaveData.ArtefactIdentifier, defaultPosition);
        }
    }
    public void AddToCollection()
    {
        string artefactIdentifier = GameObject.Find("ArtefactInfoIdenifier_Text").GetComponent <Text>().text;

        VerticeTransform defaultPosition = new VerticeTransform();

        if (artefactIdentifier.Length > 0)
        {
            Debug.Log("Collection identifier: " + identifier.text);
            CollectionWriter.AddArtefactToCollectionWithIdentifier(identifier.text, artefactIdentifier, defaultPosition);
        }
    }
Пример #6
0
    public void SaveCollectionData()
    {
        //Pull metadata from struct
        Dictionary <string, string[]> collectionMetadata = new Dictionary <string, string[]>();

        string[] collectTitles = DataListToArray(CollectDataHost.CollectionTitle);
        collectionMetadata.Add("title", collectTitles);

//		string[] identArray = new string[1]{CollectDataHost.CollectionIdentifier}; //FIXME can't have two 'identifier' keys in the dictionary
//		collectionMetadata.Add("identifier", identArray);

        string[] collectCreators = DataListToArray(CollectDataHost.CollectionCreator);
        collectionMetadata.Add("creator", collectCreators);

        string[] collectContributors = DataListToArray(CollectDataHost.CollectionContributor);
        collectionMetadata.Add("contributor", collectContributors);

        string[] collectDates = DataListToArray(CollectDataHost.CollectionDate);
        collectionMetadata.Add("date", collectDates);

        string[] collectCoverage = DataListToArray(CollectDataHost.CollectionCoverage);
        collectionMetadata.Add("coverage", collectCoverage);

        string[] collectSubject = DataListToArray(CollectDataHost.CollectionSubject);
        collectionMetadata.Add("subject", collectSubject);

        string[] descriptArray = new string[1] {
            CollectDataHost.CollectionDescription
        };
        collectionMetadata.Add("description", descriptArray);


        //Create transforms
        Dictionary <string, VerticeTransform> artefactTransforms = new Dictionary <string, VerticeTransform>();

        if (collectionArtefactsParent.childCount > 0)
        {
            for (int i = 0; i < collectionArtefactsParent.childCount; i++)
            {
                Transform        curObjTrans             = collectionArtefactsParent.GetChild(i);
                VerticeTransform curArtefactVerticeTrans = new VerticeTransform(curObjTrans.position, curObjTrans.rotation, curObjTrans.localScale);
                string           curArtefactName         = curObjTrans.name;

                artefactTransforms.Add(curArtefactName, curArtefactVerticeTrans);
            }
        }

        CollectionWriter.WriteCollectionWithIdentifer(CollectDataHost.CollectionIdentifier, collectionMetadata, artefactTransforms);         //
        CollectMenuGuiControl.LoadCollectInfo(CollectDataHost.CollectionIdentifier);
    }
Пример #7
0
    public void TestInstantiateWithFloats()
    {
        VerticeTransform transform = new VerticeTransform(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 0.0f, -1.0f, -2.0f, -3.0f);

        Assert.That(transform.position.x == 1.0f);
        Assert.That(transform.position.y == 2.0f);
        Assert.That(transform.position.z == 3.0f);
        Assert.That(transform.rotation.x == 4.0f);
        Assert.That(transform.rotation.y == 5.0f);
        Assert.That(transform.rotation.z == 6.0f);
        Assert.That(transform.rotation.w == 0.0f);
        Assert.That(transform.scale.x == -1.0f);
        Assert.That(transform.scale.y == -2.0f);
        Assert.That(transform.scale.z == -3.0f);
    }
Пример #8
0
    public void TestInstantiateWithCollectionReaderDictionary()
    {
        // Get the list of collection identifiers, and subsequently the list of artefact identifiers for the first collection
        string[] collectionIdentifiers = CollectionReader.GetIdentifiersForCollections();
        string[] artefactIdentifiers   = CollectionReader.GetIdentifiersForArtefactsInCollectionWithIdentifier(collectionIdentifiers [0]);

        // Now get the transform data for the first artefact in the first collection, and attempt to construct a VerticeTransform with the data
        Dictionary <string, Dictionary <string, float> > transformData = CollectionReader.GetTransformForArtefactWithIdentifierInCollection(collectionIdentifiers [0], artefactIdentifiers [0]);
        VerticeTransform transform = new VerticeTransform(transformData);

        Assert.That(transform.position.x == 40.01599f);
        Assert.That(transform.position.y == -11.58916f);
        Assert.That(transform.position.z == 184.2516f);
        Assert.That(transform.rotation.x == 1.0f);
        Assert.That(transform.rotation.y == 1.0f);
        Assert.That(transform.rotation.z == 1.0f);
        Assert.That(transform.rotation.w == 1.0f);
        Assert.That(transform.scale.x == 1.0f);
        Assert.That(transform.scale.y == 1.0f);
        Assert.That(transform.scale.z == 1.0f);
    }
Пример #9
0
    /// <summary>
    /// Adds the passed in artefact to an existing collection in a Vertice XML and persists the data to the
    /// collection XML file
    /// </summary>
    /// <param name="collectionIdentifier">The identifier for the collection in which to add the artefact</param>
    /// <param name="newArtefactIdentifier">The identifier for the new artefact (which should correspond with the artefact XML file)</param>
    /// <param name="newArtefactTransform">The VerticeTransform to use as the default coordinate for the new artefact</param>
    /// <exception cref="NoSuchCollectionException>If the collection identifier does not correspond to a collection in the XML file, NoSuchCollectionException is thrown and no data is written</exception>
    public static void AddArtefactToCollectionWithIdentifier(string collectionIdentifier, string newArtefactIdentifier, VerticeTransform newArtefactTransform)
    {
        Debug.Log(String.Format("Will attempt to write {0} to {1}", newArtefactIdentifier, collectionIdentifier));
        if (_xmlDocument == null)
        {
            Debug.Log(String.Format("_xmlDocument is not loaded; will load from {0}", Paths.CollectionMetadata));
            LoadXml();
        }

        XmlNode collectionNode = _xmlDocument.SelectSingleNode(String.Format("/verticeCollections/verticeCollection[@id='{0}']", collectionIdentifier));

        if (collectionNode == null)
        {
            Debug.Log(String.Format("No such collection with id {0}", collectionIdentifier));
            throw new NoSuchCollectionException();
        }
        else
        {
            Dictionary <string, VerticeTransform> newArtefact = new Dictionary <string, VerticeTransform> ();
            newArtefact.Add(newArtefactIdentifier, newArtefactTransform);
            AddArtefactsToCollectionNode(collectionNode, newArtefact);
            Debug.Log("Will write to XML");
            WriteXmlToFile();
        }
    }