Ejemplo n.º 1
0
    bool ParseShape(BinaryReader br, string cid)
    {
        MegaShape ms = (MegaShape)target;

        switch (cid)
        {
        case "Num":
            int count = br.ReadInt32();
            ms.splines = new List <MegaSpline>(count);
            //id = 0;
            break;

        case "Spline":
            MegaSpline spl = new MegaSpline();
            ms.splines.Add(spl);
            //MegaMorphEditor.Parse(br, SplineParse);
            MegaParse.Parse(br, SplineParse);
            break;

        case "Anim":
            //Debug.Log("Anim info");
            //MegaMorphEditor.Parse(br, AnimParse);
            MegaParse.Parse(br, AnimParse);
            break;
        }

        return(true);
    }
Ejemplo n.º 2
0
    // Fbx could have been exported any which way so still need to do try all mappings to find correct
    public bool ParseMorph(BinaryReader br, string id)
    {
        MegaMorphOMatic mr = (MegaMorphOMatic)target;

        switch (id)
        {
        case "Max": mr.Max = br.ReadSingle(); break;

        case "Min": mr.Min = br.ReadSingle(); break;

        case "UseLim": mr.UseLimit = (br.ReadInt32() == 1); break;

        // This will only be changed points, but we need scale
        case "StartPoints":                     // Mapping
            MegaTargetMesh tm = new MegaTargetMesh();
            tm.verts = MegaParse.ReadP3l(br);   // make a vector
            if (!TryMapping1(tm, mr))
            {
                EditorUtility.DisplayDialog("Mapping Failed!", "Mapping failed!", "OK");
                EditorUtility.ClearProgressBar();
                return(false);
            }
            break;

        case "Channel":         mr.chanBank.Add(LoadChan(br));  break;

        case "Animation":       LoadAnimation(mr, br);                  break;

        default: return(false);
        }

        return(true);
    }
Ejemplo n.º 3
0
    public void ParseFile(string assetpath, ParseClassCallbackType cb)
    {
        FileStream fs = new FileStream(assetpath, FileMode.Open, FileAccess.Read, System.IO.FileShare.Read);

        BinaryReader br = new BinaryReader(fs);

        bool processing = true;

        while (processing)
        {
            string classname = MegaParse.ReadString(br);

            if (classname == "Done")
            {
                break;
            }

            int  chunkoff = br.ReadInt32();
            long fpos     = fs.Position;

            cb(classname, br);

            fs.Position = fpos + chunkoff;
        }

        br.Close();
    }
    //public delegate bool ParseBinCallbackType(BinaryReader br, string id);
    //public delegate void ParseClassCallbackType(string classname, BinaryReader br);

    static public void Parse(BinaryReader br, ParseBinCallbackType cb)
    {
        bool readchunk = true;

        while (readchunk)
        {
            string id = MegaParse.ReadString(br);

            if (id == "eoc")
            {
                break;
            }

            int skip = br.ReadInt32();

            long fpos = br.BaseStream.Position;

            if (!cb(br, id))
            {
                Debug.Log("Error Loading chunk id " + id);
                readchunk = false;                      // done
                break;
            }

            br.BaseStream.Position = fpos + skip;
        }
    }
Ejemplo n.º 5
0
    public bool ParseChan(BinaryReader br, string id)
    {
        //Debug.Log("ParseChan " + id);

        switch (id)
        {
        case "Target":          currentChan.mTargetCache.Add(LoadTarget(br)); break;

        case "Name":            currentChan.mName = MegaParse.ReadString(br); break;

        case "Percent":         currentChan.Percent = br.ReadSingle(); break;

        case "SpinMax":         currentChan.mSpinmax = br.ReadSingle(); break;

        case "SpinMin":         currentChan.mSpinmin = br.ReadSingle(); break;

        case "UseLim":          currentChan.mUseLimit = (br.ReadInt32() == 1); break;

        case "Override":        currentChan.mActiveOverride = (br.ReadInt32() == 1); break;

        case "Curve":           currentChan.mCurvature = br.ReadSingle(); break;
            //case "Anim":		currentChan.control = LoadAnim(br);	break;
        }

        return(true);
    }
    static public MegaBezFloatKeyControl LoadBezFloatKeyControl(BinaryReader br)
    {
        con = new MegaBezFloatKeyControl();

        MegaParse.Parse(br, Parse);
        return(con);
    }
    static public bool Parse(BinaryReader br, string id)
    {
        switch (id)
        {
        case "Num":
            int num = br.ReadInt32();
            con.Keys  = new MegaBezVector3Key[num];
            con.Times = new float[num];
            break;

        case "Keys":
            for (int i = 0; i < con.Keys.Length; i++)
            {
                con.Keys[i]        = new MegaBezVector3Key();
                con.Keys[i].val    = MegaParse.ReadP3(br);
                con.Keys[i].intan  = MegaParse.ReadP3(br);
                con.Keys[i].outtan = MegaParse.ReadP3(br);
                con.Times[i]       = br.ReadSingle();
            }
            con.InitKeys();
            break;
        }

        return(true);
    }
Ejemplo n.º 8
0
    public bool ParseTarget(BinaryReader br, string id)
    {
        switch (id)
        {
        case "Name":    currentTarget.name = MegaParse.ReadString(br); break;

        case "Percent": currentTarget.percent = br.ReadSingle(); break;

        case "MoPoints":
            int count = br.ReadInt32();

            if (count > 0)
            {
                currentTarget.loadpoints = new MOPoint[count];

                for (int i = 0; i < count; i++)
                {
                    MOPoint p = new MOPoint();
                    p.id = br.ReadInt32();                              // we need to find the ids for this point (could be more than one)
                    p.p  = ConvertPoint(MegaParse.ReadP3(br));

                    p.w = br.ReadSingle();
                    currentTarget.loadpoints[i] = p;
                }
            }
            break;
        }

        return(true);
    }
Ejemplo n.º 9
0
    public MegaMorphTarget LoadTarget(BinaryReader br)
    {
        MegaMorphTarget target = new MegaMorphTarget();

        currentTarget = target;

        MegaParse.Parse(br, ParseTarget);
        return(target);
    }
Ejemplo n.º 10
0
    void LoadMDD()
    {
        MegaPointCache am = (MegaPointCache)target;

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

        string filename = EditorUtility.OpenFilePanel("Motion Designer File", lastpath, "mdd");

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

        lastpath = filename;

        // Clear what we have
        Verts.Clear();

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

        BinaryReader br = new BinaryReader(fs);

        int numSamples = MegaParse.ReadMotInt(br);
        int numPoints  = MegaParse.ReadMotInt(br);

        float t = 0.0f;

        for (int i = 0; i < numSamples; i++)
        {
            t = MegaParse.ReadMotFloat(br);
        }

        am.maxtime = t;

        am.Verts = new MegaPCVert[numPoints];

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

        for (int i = 0; i < numSamples; i++)
        {
            for (int v = 0; v < numPoints; v++)
            {
                am.Verts[v].points[i].x = MegaParse.ReadMotFloat(br);
                am.Verts[v].points[i].y = MegaParse.ReadMotFloat(br);
                am.Verts[v].points[i].z = MegaParse.ReadMotFloat(br);
            }
        }

        BuildData(mods, am, filename);
        br.Close();
    }
Ejemplo n.º 11
0
    public void LoadMDD(string filename)
    {
        MegaPointCache am = (MegaPointCache)target;

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

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

        // Clear what we have
        Verts.Clear();

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

        BinaryReader br = new BinaryReader(fs);

        int numSamples = MegaParse.ReadMotInt(br);
        int numPoints  = MegaParse.ReadMotInt(br);

        float t = 0.0f;

        for (int i = 0; i < numSamples; i++)
        {
            t = MegaParse.ReadMotFloat(br);
        }

        am.maxtime = t;

        am.Verts = new MegaPCVert[numPoints];

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

        for (int i = 0; i < numSamples; i++)
        {
            for (int v = 0; v < numPoints; v++)
            {
                am.Verts[v].points[i].x = MegaParse.ReadMotFloat(br);
                am.Verts[v].points[i].y = MegaParse.ReadMotFloat(br);
                am.Verts[v].points[i].z = MegaParse.ReadMotFloat(br);
            }
        }

        BuildData(mods, am, filename);
        br.Close();
    }
Ejemplo n.º 12
0
    public MegaMorphChan LoadChan(BinaryReader br)
    {
        MegaMorphChan chan = new MegaMorphChan();

        chan.control      = null;
        chan.showparams   = false;
        chan.mTargetCache = new List <MegaMorphTarget>();
        currentChan       = chan;

        MegaParse.Parse(br, ParseChan);

        return(chan);
    }
    public MegaMorphChan LoadChan(BinaryReader br)
    {
        MegaMorphChan chan = new MegaMorphChan();

        //Debug.Log("Load Chan");
        chan.control      = null;
        chan.showparams   = false;
        chan.mTargetCache = new List <MegaMorphTarget>();
        currentChan       = chan;

        //Parse(br, ParseChan);
        MegaParse.Parse(br, ParseChan);

        MegaMorph mr = (MegaMorph)target;

        chan.Rebuild(mr);
        return(chan);
    }
Ejemplo n.º 14
0
    public bool ParseTarget(BinaryReader br, string id)
    {
        //Debug.Log("ParseTarget " + id);
        switch (id)
        {
        case "Name":    currentTarget.name = MegaParse.ReadString(br);  break;

        case "Percent": currentTarget.percent = br.ReadSingle(); break;

        case "TPoints": currentTarget.points = MegaParse.ReadP3v(br); ConvertPoints(currentTarget.points); break;

        case "MoPoints":
            Debug.Log("Got morpho points");
            break;
        }

        return(true);
    }
    // Fbx could have been exported any which way so still need to do try all mappings to find correct
    public bool ParseMorph(BinaryReader br, string id)
    {
        MegaMorph mr = (MegaMorph)target;

        //Debug.Log("ParseMorph " + id);
        switch (id)
        {
        case "Max": mr.Max = br.ReadSingle(); break;

        case "Min": mr.Min = br.ReadSingle(); break;

        case "UseLim": mr.UseLimit = (br.ReadInt32() == 1); break;

        case "StartPoints":                     // Mapping
            MegaTargetMesh tm = new MegaTargetMesh();
            tm.verts = MegaParse.ReadP3l(br);   // make a vector
            //Debug.Log("num " + tm.verts.Count);
            if (!TryMapping1(tm, mr))
            {
                EditorUtility.DisplayDialog("Mapping Failed!", "Mapping failed! Please check the Morph page on the MegaFiers website for reasons for this", "OK");
                EditorUtility.ClearProgressBar();
                return(false);
            }
            //Debug.Log("StartPoints " + tm.verts.Count);
            break;

        case "Channel":
            mr.chanBank.Add(LoadChan(br));
            break;

        case "Animation":
            LoadAnimation(mr, br);
            break;

        default:        return(false);
        }

        return(true);
    }
Ejemplo n.º 16
0
	bool ParseShape(BinaryReader br, string cid)
	{
		MegaShape ms = (MegaShape)target;

		switch ( cid )
		{
			case "Num":
				int count = br.ReadInt32();
				ms.splines = new List<MegaSpline>(count);
				break;

			case "Spline":
				MegaSpline spl = new MegaSpline();
				ms.splines.Add(spl);
				MegaParse.Parse(br, SplineParse);
				break;

			case "Anim":
				MegaParse.Parse(br, AnimParse);
				break;
		}

		return true;
	}
Ejemplo n.º 17
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.º 18
0
    void LoadPC2()
    {
        MegaPointCache am = (MegaPointCache)target;

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

        string filename = EditorUtility.OpenFilePanel("Point Cache File", lastpath, "pc2");

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

        lastpath = filename;

        // Clear what we have
        Verts.Clear();

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

        BinaryReader br = new BinaryReader(fs);

        string sig = MegaParse.ReadStr(br);

        if (sig != "POINTCACHE2")
        {
            br.Close();
            return;
        }

        int fileVersion = br.ReadInt32();

        if (fileVersion != 1)
        {
            br.Close();
            return;
        }

        int numPoints = br.ReadInt32();

        br.ReadSingle();
        br.ReadSingle();
        int numSamples = br.ReadInt32();

        am.Verts = new MegaPCVert[numPoints];

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

        for (int i = 0; i < numSamples; i++)
        {
            for (int v = 0; v < numPoints; v++)
            {
                am.Verts[v].points[i] = MegaParse.ReadP3(br);
            }
        }
        BuildData(mods, am, filename);
        br.Close();
    }
Ejemplo n.º 19
0
 void LoadAnimation(MegaMorph mr, BinaryReader br)
 {
     //Parse(br, AnimCallback);
     MegaParse.Parse(br, AnimCallback);
 }
Ejemplo n.º 20
0
    public void LoadPC2(string filename)
    {
        MegaPointCache am = (MegaPointCache)target;

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

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

        lastpath = filename;

        // Clear what we have
        Verts.Clear();

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

        long         len = fs.Length;
        BinaryReader br  = new BinaryReader(fs);

        string sig = MegaParse.ReadStr(br);

        if (sig != "POINTCACHE2")
        {
            EditorUtility.DisplayDialog("PC2 Importer", "The selected file does not appear to be a valid PC2 File", "Ok");
            br.Close();
            return;
        }

        int fileVersion = br.ReadInt32();

        if (fileVersion != 1)
        {
            br.Close();
            return;
        }

        int numPoints = br.ReadInt32();

        br.ReadSingle();
        br.ReadSingle();
        int  numSamples = br.ReadInt32();
        long csamples   = (len - 24) / (numPoints * 12);

        numSamples = (int)csamples;

        am.Verts = new MegaPCVert[numPoints];

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

        for (int i = 0; i < numSamples; i++)
        {
            for (int v = 0; v < numPoints; v++)
            {
                am.Verts[v].points[i] = MegaParse.ReadP3(br);
            }
        }
        BuildData(mods, am, filename);
        br.Close();
    }
Ejemplo n.º 21
0
    public bool ParseAnimMesh(BinaryReader br, string id)
    {
        switch (id)
        {
        case "Size":
            Vector3 sz = MegaParse.ReadP3(br);
            Vector3 min1, max1;

            Vector3 ex1 = Extents(mods.verts, out min1, out max1);

            int largest = 0;
            if (sz.x > sz.y)
            {
                if (sz.x > sz.z)
                {
                    largest = 0;
                }
                else
                {
                    largest = 2;
                }
            }
            else
            {
                if (sz.y > sz.z)
                {
                    largest = 1;
                }
                else
                {
                    largest = 2;
                }
            }

            scl = ex1[largest] / sz[largest];
            break;

        case "V":
            Vector3 p = MegaParse.ReadP3(br) * scl;
            // Find all matching verts
            currentVert           = new MegaAnimatedVert();
            currentVert.startVert = p;
            currentVert.indices   = FindVerts(p);
            if (currentVert.indices == null)
            {
                Debug.Log("Error! No match found");
            }

            Verts.Add(currentVert);
            break;

        case "Anim":
            //currentVert.con = MegaBezVector3KeyControl.LoadBezVector3KeyControl(br);
            currentVert.con = MegaParseBezVector3Control.LoadBezVector3KeyControl(br);

            currentVert.con.Scale(scl);
            break;

        default: return(false);
        }

        return(true);
    }
Ejemplo n.º 22
0
 public void LoadAnimMesh(BinaryReader br)
 {
     MegaParse.Parse(br, ParseAnimMesh);
 }
Ejemplo n.º 23
0
 public void LoadMorph(BinaryReader br)
 {
     MegaParse.Parse(br, ParseMorph);
 }
Ejemplo n.º 24
0
 public void LoadShape(BinaryReader br)
 {
     //MegaMorphEditor.Parse(br, ParseShape);
     MegaParse.Parse(br, ParseShape);
 }
Ejemplo n.º 25
0
	public void LoadShape(BinaryReader br)
	{
		MegaParse.Parse(br, ParseShape);
	}
Ejemplo n.º 26
0
 void LoadAnimation(MegaMorphOMatic mr, BinaryReader br)
 {
     MegaParse.Parse(br, AnimCallback);
 }