Ejemplo n.º 1
0
	public MegaFlowXMLNode()
	{
		tagName = "NONE";
		parentNode = null;
		children = new List<MegaFlowXMLNode>();
		values = new List<MegaFlowXMLValue>();
	}
Ejemplo n.º 2
0
 public MegaFlowXMLNode()
 {
     tagName    = "NONE";
     parentNode = null;
     children   = new List <MegaFlowXMLNode>();
     values     = new List <MegaFlowXMLValue>();
 }
Ejemplo n.º 3
0
    static void ParseFluid(MegaFlowFrame flow, MegaFlowXMLNode node)
    {
        for (int i = 0; i < node.values.Count; i++)
        {
            MegaFlowXMLValue val = node.values[i];

            switch (val.name)
            {
            case "grid":
            {
                string[] vals = val.value.Split(',');
                flow.gridDim2[0] = int.Parse(vals[0]);
                flow.gridDim2[1] = int.Parse(vals[1]);
                flow.gridDim2[2] = int.Parse(vals[2]);
                break;
            }

            case "size":
            {
                string[] vals = val.value.Split(',');
                index = 0;
                Vector3 bmin = ReadV3(vals);
                Vector3 bmax = ReadV3(vals);

                flow.size  = bmax - bmin;
                flow.gsize = flow.size;

                // griddim should have a name change
                flow.spacing.x = flow.size.x / flow.gridDim2[0];
                flow.spacing.y = flow.size.y / flow.gridDim2[1];
                flow.spacing.z = flow.size.z / flow.gridDim2[2];
                flow.oos.x     = 1.0f / flow.spacing.x;
                flow.oos.y     = 1.0f / flow.spacing.y;
                flow.oos.z     = 1.0f / flow.spacing.z;
                break;
            }

            default: Debug.Log("Unknown Fluid attribute " + val.name); break;
            }
        }

        for (int i = 0; i < node.children.Count; i++)
        {
            MegaFlowXMLNode n = (MegaFlowXMLNode)node.children[i];
            switch (n.tagName)
            {
            case "Vel":
                ParseVel(flow, n);
                break;

            case "Force":
                break;

            case "Density":
                break;

            default: Debug.Log("Unknown Fluid node " + n.tagName); break;
            }
        }
    }
Ejemplo n.º 4
0
    public MegaFlowXMLNode read(String xml)
    {
        int             index       = 0;
        int             lastIndex   = 0;
        MegaFlowXMLNode rootNode    = new MegaFlowXMLNode();
        MegaFlowXMLNode currentNode = rootNode;

        xml = xml.Replace(" \n", "");
        xml = xml.Replace("\n", "");

        while (true)
        {
            index = xml.IndexOf(TAG_START, lastIndex);

            if (index < 0 || index >= xml.Length)
            {
                break;
            }

            index++;

            lastIndex = xml.IndexOf(TAG_END, index);
            if (lastIndex < 0 || lastIndex >= xml.Length)
            {
                break;
            }

            int    tagLength = lastIndex - index;
            String xmlTag    = xml.Substring(index, tagLength);

            if (xmlTag[0] == SLASH)
            {
                currentNode = currentNode.parentNode;
                continue;
            }

            bool openTag = true;

            if (xmlTag[tagLength - 1] == SLASH)
            {
                xmlTag  = xmlTag.Substring(0, tagLength - 1);
                openTag = false;
            }


            MegaFlowXMLNode node = parseTag(xmlTag);
            node.parentNode = currentNode;
            currentNode.children.Add(node);

            if (openTag)
            {
                currentNode = node;
            }
        }

        return(rootNode);
    }
Ejemplo n.º 5
0
    static public void ParseXML1(MegaFlowFrame flow, MegaFlowXMLNode node)
    {
        foreach (MegaFlowXMLNode n in node.children)
        {
            switch (n.tagName)
            {
            case "Fluid": ParseFluid(flow, n); break;

            default: Debug.Log("Unknown Fluid Node " + n.tagName); break;
            }
        }
    }
Ejemplo n.º 6
0
	public MegaFlowXMLNode read(String xml)
	{
		int index = 0;
		int lastIndex = 0;
		MegaFlowXMLNode rootNode = new MegaFlowXMLNode();
		MegaFlowXMLNode currentNode = rootNode;

		xml = xml.Replace(" \n", "");
		xml = xml.Replace("\n", "");

		while ( true )
		{
			index = xml.IndexOf(TAG_START, lastIndex);

			if ( index < 0 || index >= xml.Length )
				break;

			index++;

			lastIndex = xml.IndexOf(TAG_END, index);
			if ( lastIndex < 0 || lastIndex >= xml.Length )
				break;

			int tagLength = lastIndex - index;
			String xmlTag = xml.Substring(index, tagLength);

			if ( xmlTag[0] == SLASH )
			{
				currentNode = currentNode.parentNode;
				continue;
			}

			bool openTag = true;

			if ( xmlTag[tagLength - 1] == SLASH )
			{
				xmlTag = xmlTag.Substring(0, tagLength - 1);
				openTag = false;
			}


			MegaFlowXMLNode node = parseTag(xmlTag);
			node.parentNode = currentNode;
			currentNode.children.Add(node);

			if ( openTag )
				currentNode = node;
		}

		return rootNode;
	}
Ejemplo n.º 7
0
    static public void LoadFLW(MegaFlowFrame flow, string filename)
    {
        StreamReader streamReader = new StreamReader(filename);
        string       data         = streamReader.ReadToEnd();

        streamReader.Close();

        MegaFlowXMLReader xml  = new MegaFlowXMLReader();
        MegaFlowXMLNode   node = xml.read(data);

        ParseXML1(flow, node);

        xml  = null;
        data = null;
        GC.Collect();
    }
Ejemplo n.º 8
0
    public MegaFlowXMLNode parseAttributes(String xmlTag, MegaFlowXMLNode node)
    {
        int index         = 0;
        int attrNameIndex = 0;
        int lastIndex     = 0;

        while (true)
        {
            index = xmlTag.IndexOf(BEGIN_QUOTE, lastIndex);
            if (index < 0 || index > xmlTag.Length)
            {
                break;
            }

            attrNameIndex = xmlTag.LastIndexOf(SPACE, index);
            if (attrNameIndex < 0 || attrNameIndex > xmlTag.Length)
            {
                break;
            }

            attrNameIndex++;
            String attrName = xmlTag.Substring(attrNameIndex, index - attrNameIndex);

            index += 2;

            lastIndex = xmlTag.IndexOf(QUOTE, index);
            if (lastIndex < 0 || lastIndex > xmlTag.Length)
            {
                break;
            }

            int    tagLength = lastIndex - index;
            String attrValue = xmlTag.Substring(index, tagLength);

            MegaFlowXMLValue val = new MegaFlowXMLValue();
            val.name  = attrName;
            val.value = attrValue;
            node.values.Add(val);
        }

        return(node);
    }
Ejemplo n.º 9
0
    public MegaFlowXMLNode parseTag(String xmlTag)
    {
        MegaFlowXMLNode node = new MegaFlowXMLNode();

        int nameEnd = xmlTag.IndexOf(SPACE, 0);

        if (nameEnd < 0)
        {
            node.tagName = xmlTag;
            return(node);
        }

        String tagName = xmlTag.Substring(0, nameEnd);

        node.tagName = tagName;

        String attrString = xmlTag.Substring(nameEnd, xmlTag.Length - nameEnd);

        return(parseAttributes(attrString, node));
    }
Ejemplo n.º 10
0
    static void ParseVel(MegaFlowFrame flow, MegaFlowXMLNode node)
    {
        for (int i = 0; i < node.values.Count; i++)
        {
            MegaFlowXMLValue val = node.values[i];

            switch (val.name)
            {
            case "data":
            {
                string[] vals = val.value.Split(',');
                index = 0;

                //int len = vals.Length / 3;

                flow.vel.Clear();

                Vector3[] vels = new Vector3[flow.gridDim2[0] * flow.gridDim2[1] * flow.gridDim2[2]];

                for (int z = 0; z < flow.gridDim2[2]; z++)
                {
                    for (int y = 0; y < flow.gridDim2[1]; y++)
                    {
                        for (int x = 0; x < flow.gridDim2[0]; x++)
                        {
                            vels[(x * flow.gridDim2[2] * flow.gridDim2[1]) + ((flow.gridDim2[2] - z - 1) * flow.gridDim2[1]) + y] = ReadV3Adj(vals);
                        }
                    }
                }

                flow.framenumber = 0;
                flow.vel.AddRange(vels);
                break;
            }

            default: Debug.Log("Unknown Vel attribute " + val.name); break;
            }
        }
    }
Ejemplo n.º 11
0
	static void ParseVel(MegaFlowFrame flow, MegaFlowXMLNode node)
	{
		for ( int i = 0; i < node.values.Count; i++ )
		{
			MegaFlowXMLValue val = node.values[i];

			switch ( val.name )
			{
				case "data":
					{
						string[] vals = val.value.Split(',');
						index = 0;

						//int len = vals.Length / 3;

						flow.vel.Clear();

						Vector3[] vels = new Vector3[flow.gridDim2[0] * flow.gridDim2[1] * flow.gridDim2[2]];

						for ( int z = 0; z < flow.gridDim2[2]; z++ )
						{
							for ( int y = 0; y < flow.gridDim2[1]; y++ )
							{
								for ( int x = 0; x < flow.gridDim2[0]; x++ )
									vels[(x * flow.gridDim2[2] * flow.gridDim2[1]) + ((flow.gridDim2[2] - z - 1) * flow.gridDim2[1]) + y] = ReadV3Adj(vals);
							}
						}

						flow.framenumber = 0;
						flow.vel.AddRange(vels);
						break;
					}

				default: Debug.Log("Unknown Vel attribute " + val.name); break;
			}
		}
	}
Ejemplo n.º 12
0
	static void ParseFluid(MegaFlowFrame flow, MegaFlowXMLNode node)
	{
		for ( int i = 0; i < node.values.Count; i++ )
		{
			MegaFlowXMLValue val = node.values[i];

			switch ( val.name )
			{
				case "grid":
					{
						string[] vals = val.value.Split(',');
						flow.gridDim2[0] = int.Parse(vals[0]);
						flow.gridDim2[1] = int.Parse(vals[1]);
						flow.gridDim2[2] = int.Parse(vals[2]);
						break;
					}

				case "size":
					{
						string[] vals = val.value.Split(',');
						index = 0;
						Vector3 bmin = ReadV3(vals);
						Vector3 bmax = ReadV3(vals);

						flow.size = bmax - bmin;
						flow.gsize = flow.size;

						// griddim should have a name change
						flow.spacing.x = flow.size.x / flow.gridDim2[0];
						flow.spacing.y = flow.size.y / flow.gridDim2[1];
						flow.spacing.z = flow.size.z / flow.gridDim2[2];
						flow.oos.x = 1.0f / flow.spacing.x;
						flow.oos.y = 1.0f / flow.spacing.y;
						flow.oos.z = 1.0f / flow.spacing.z;
						break;
					}

				default: Debug.Log("Unknown Fluid attribute " + val.name); break;
			}
		}

		for ( int i = 0; i < node.children.Count; i++ )
		{
			MegaFlowXMLNode n = (MegaFlowXMLNode)node.children[i];
			switch ( n.tagName )
			{
				case "Vel":
					ParseVel(flow, n);
					break;

				case "Force":
					break;

				case "Density":
					break;

				default: Debug.Log("Unknown Fluid node " + n.tagName); break;
			}
		}
	}
Ejemplo n.º 13
0
	static public void ParseXML1(MegaFlowFrame flow, MegaFlowXMLNode node)
	{
		foreach ( MegaFlowXMLNode n in node.children )
		{
			switch ( n.tagName )
			{
				case "Fluid": ParseFluid(flow, n); break;
				default: Debug.Log("Unknown Fluid Node " + n.tagName); break;
			}
		}
	}
Ejemplo n.º 14
0
	public MegaFlowXMLNode parseTag(String xmlTag)
	{
		MegaFlowXMLNode node = new MegaFlowXMLNode();

		int nameEnd = xmlTag.IndexOf(SPACE, 0);
		if ( nameEnd < 0 )
		{
			node.tagName = xmlTag;
			return node;
		}

		String tagName = xmlTag.Substring(0, nameEnd);
		node.tagName = tagName;

		String attrString = xmlTag.Substring(nameEnd, xmlTag.Length - nameEnd);
		return parseAttributes(attrString, node);
	}
Ejemplo n.º 15
0
	public MegaFlowXMLNode parseAttributes(String xmlTag, MegaFlowXMLNode node)
	{
		int index = 0;
		int attrNameIndex = 0;
		int lastIndex = 0;

		while ( true )
		{
			index = xmlTag.IndexOf(BEGIN_QUOTE, lastIndex);
			if ( index < 0 || index > xmlTag.Length )
				break;

			attrNameIndex = xmlTag.LastIndexOf(SPACE, index);
			if ( attrNameIndex < 0 || attrNameIndex > xmlTag.Length )
				break;

			attrNameIndex++;
			String attrName = xmlTag.Substring(attrNameIndex, index - attrNameIndex);

			index += 2;

			lastIndex = xmlTag.IndexOf(QUOTE, index);
			if ( lastIndex < 0 || lastIndex > xmlTag.Length )
			{
				break;
			}

			int tagLength = lastIndex - index;
			String attrValue = xmlTag.Substring(index, tagLength);

			MegaFlowXMLValue val = new MegaFlowXMLValue();
			val.name = attrName;
			val.value = attrValue;
			node.values.Add(val);
		}

		return node;
	}