Ejemplo n.º 1
0
    // Maya format
    void LoadMCC()
    {
        MegaPointCache am = (MegaPointCache)target;

        mods = am.gameObject.GetComponent <MegaModifiers>();

        string filename = EditorUtility.OpenFilePanel("Maya Cache File", lastpath, "mc");

        if (filename == null || filename.Length < 1)
        {
            return;
        }

        lastpath = filename;

        FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, System.IO.FileShare.Read);

        BinaryReader br = new BinaryReader(fs);

        string id = Read(br, 4);

        if (id != "FOR4")
        {
            Debug.Log("wrong file");
            return;
        }

        int offset = MegaParse.ReadMotInt(br);

        br.ReadBytes(offset);

        List <MCCFrame> frames = new List <MCCFrame>();

        while (true)
        {
            string btag = Read(br, 4);
            if (btag == "")
            {
                break;
            }

            if (btag != "FOR4")
            {
                Debug.Log("File format error");
                return;
            }

            int blocksize = MegaParse.ReadMotInt(br);

            int bytesread = 0;

            btag = Read(br, 4);
            if (btag != "MYCH")
            {
                Debug.Log("File format error");
                return;
            }
            bytesread += 4;

            btag = Read(br, 4);
            if (btag != "TIME")
            {
                Debug.Log("File format error");
                return;
            }
            bytesread += 4;

            br.ReadBytes(4);
            bytesread += 4;

            int time = MegaParse.ReadMotInt(br);
            bytesread += 4;

            am.maxtime = (float)time / 6000.0f;

            while (bytesread < blocksize)
            {
                btag = Read(br, 4);
                if (btag != "CHNM")
                {
                    Debug.Log("chm error");
                    return;
                }
                bytesread += 4;

                int chnmsize = MegaParse.ReadMotInt(br);
                bytesread += 4;

                int mask           = 3;
                int chnmsizetoread = (chnmsize + mask) & (~mask);
                //byte[] channelname = br.ReadBytes(chnmsize);
                br.ReadBytes(chnmsize);

                int paddingsize = chnmsizetoread - chnmsize;

                if (paddingsize > 0)
                {
                    br.ReadBytes(paddingsize);
                }

                bytesread += chnmsizetoread;

                btag = Read(br, 4);

                if (btag != "SIZE")
                {
                    Debug.Log("Size error");
                    return;
                }
                bytesread += 4;

                br.ReadBytes(4);
                bytesread += 4;

                int arraylength = MegaParse.ReadMotInt(br);
                bytesread += 4;

                MCCFrame frame = new MCCFrame();
                frame.points = new Vector3[arraylength];

                string dataformattag = Read(br, 4);
                int    bufferlength  = MegaParse.ReadMotInt(br);
                bytesread += 8;

                if (dataformattag == "FVCA")
                {
                    if (bufferlength != arraylength * 3 * 4)
                    {
                        Debug.Log("buffer len error");
                        return;
                    }

                    for (int i = 0; i < arraylength; i++)
                    {
                        frame.points[i].x = MegaParse.ReadMotFloat(br);
                        frame.points[i].y = MegaParse.ReadMotFloat(br);
                        frame.points[i].z = MegaParse.ReadMotFloat(br);
                    }

                    bytesread += arraylength * 3 * 4;
                }
                else
                {
                    if (dataformattag == "DVCA")
                    {
                        if (bufferlength != arraylength * 3 * 8)
                        {
                            Debug.Log("buffer len error");
                            return;
                        }

                        for (int i = 0; i < arraylength; i++)
                        {
                            frame.points[i].x = (float)MegaParse.ReadMotDouble(br);
                            frame.points[i].y = (float)MegaParse.ReadMotDouble(br);
                            frame.points[i].z = (float)MegaParse.ReadMotDouble(br);
                        }

                        bytesread += arraylength * 3 * 8;
                    }
                    else
                    {
                        Debug.Log("Format Error");
                        return;
                    }
                }

                frames.Add(frame);
            }
        }

        // Build table
        am.Verts = new MegaPCVert[frames[0].points.Length];

        for (int i = 0; i < am.Verts.Length; i++)
        {
            am.Verts[i]        = new MegaPCVert();
            am.Verts[i].points = new Vector3[frames.Count];

            for (int p = 0; p < am.Verts[i].points.Length; p++)
            {
                am.Verts[i].points[p] = frames[p].points[i];
            }
        }

        BuildData(mods, am, filename);
        br.Close();
    }
Ejemplo n.º 2
0
	public void LoadMCC(string filename)
	{
		MegaPointCache am = (MegaPointCache)target;
		mods = am.gameObject.GetComponent<MegaModifiers>();

		if ( mods == null )
		{
			Debug.LogWarning("You need to add a Mega Modify Object component first!");
			return;
		}

		lastpath = filename;

		FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, System.IO.FileShare.Read);

		BinaryReader br = new BinaryReader(fs);

		string id = Read(br, 4);
		if ( id != "FOR4" )
		{
			Debug.Log("wrong file");
			return;
		}

		int offset  = MegaParse.ReadMotInt(br);

		br.ReadBytes(offset);

		List<MCCFrame> frames = new List<MCCFrame>();

		while ( true )
		{
			string btag = Read(br, 4);
			if ( btag == "" )
				break;

			if ( btag != "FOR4" )
			{
				Debug.Log("File format error");
				return;
			}

			int blocksize = MegaParse.ReadMotInt(br);

			int bytesread = 0;

			btag = Read(br, 4);
			if ( btag != "MYCH" )
			{
				Debug.Log("File format error");
				return;
			}
			bytesread += 4;

			btag = Read(br, 4);
			if ( btag != "TIME" )
			{
				Debug.Log("File format error");
				return;
			}
			bytesread += 4;

			br.ReadBytes(4);
			bytesread += 4;

			int time = MegaParse.ReadMotInt(br);
			bytesread += 4;

			am.maxtime = (float)time / 6000.0f;

			while ( bytesread < blocksize )
			{
				btag = Read(br, 4);
				if ( btag != "CHNM" )
				{
					Debug.Log("chm error");
					return;
				}
				bytesread += 4;

				int chnmsize = MegaParse.ReadMotInt(br);
				bytesread += 4;

				int mask = 3;
				int chnmsizetoread = (chnmsize + mask) & (~mask);
				//byte[] channelname = br.ReadBytes(chnmsize);
				br.ReadBytes(chnmsize);

				int paddingsize = chnmsizetoread - chnmsize;

				if ( paddingsize > 0 )
					br.ReadBytes(paddingsize);

				bytesread += chnmsizetoread;

				btag = Read(br, 4);

				if ( btag != "SIZE" )
				{
					Debug.Log("Size error");
					return;
				}
				bytesread += 4;

				br.ReadBytes(4);
				bytesread += 4;

				int arraylength = MegaParse.ReadMotInt(br);
				bytesread += 4;

				MCCFrame frame = new MCCFrame();
				frame.points = new Vector3[arraylength];

				string dataformattag = Read(br, 4);
				int bufferlength = MegaParse.ReadMotInt(br);
				bytesread += 8;

				if ( dataformattag == "FVCA" )
				{
					if ( bufferlength != arraylength * 3 * 4 )
					{
						Debug.Log("buffer len error");
						return;
					}

					for ( int i = 0; i < arraylength; i++ )
					{
						frame.points[i].x = MegaParse.ReadMotFloat(br);
						frame.points[i].y = MegaParse.ReadMotFloat(br);
						frame.points[i].z = MegaParse.ReadMotFloat(br);
					}

					bytesread += arraylength * 3 * 4;
				}
				else
				{
					if ( dataformattag == "DVCA" )
					{
						if ( bufferlength != arraylength * 3 * 8 )
						{
							Debug.Log("buffer len error");
							return;
						}

						for ( int i = 0; i < arraylength; i++ )
						{
							frame.points[i].x = (float)MegaParse.ReadMotDouble(br);
							frame.points[i].y = (float)MegaParse.ReadMotDouble(br);
							frame.points[i].z = (float)MegaParse.ReadMotDouble(br);
						}

						bytesread += arraylength * 3 * 8;
					}
					else
					{
						Debug.Log("Format Error");
						return;
					}
				}

				frames.Add(frame);
			}
		}

		// Build table
		am.Verts = new MegaPCVert[frames[0].points.Length];

		for ( int i = 0; i < am.Verts.Length; i++ )
		{
			am.Verts[i] = new MegaPCVert();
			am.Verts[i].points = new Vector3[frames.Count];

			for ( int p = 0; p < am.Verts[i].points.Length; p++ )
				am.Verts[i].points[p] = frames[p].points[i];
		}

		BuildData(mods, am, filename);
		br.Close();
	}