void Start()
 {
     if (!morph)
     {
         morph = GetComponent <MegaMorph>();
     }
 }
    // Update is called once per frame
    void Update()
    {
        def = ratio*deprMM;
        if(!MorphBody)
        {
            MorphBody = Body.GetComponent<MegaMorph>();
        }

        if(!MorphRibcage)
        {
            MorphRibcage = Ribcage.GetComponent<MegaMorph>();
        }
        if(!MorphInternal)
        {
            MorphInternal = InternalCavity.GetComponent<MegaMorph>();
        }

        if(MorphBody)
        {
            MorphBody.SetPercent(0,def);
        }

        if(MorphInternal)
        {
            MorphInternal.SetPercent(0,def);
        }

        if(MorphRibcage)
        {
            MorphRibcage.SetPercent(0,def);
        }
    }
Beispiel #3
0
    public void SetSource(MegaMorph src)
    {
        source = src;

        if (source)
        {
            if (chanBank == null)
            {
                chanBank = new List <MegaMorphChan>();
            }

            chanBank.Clear();

            for (int i = 0; i < source.chanBank.Count; i++)
            {
                MegaMorphChan ch = new MegaMorphChan();

                ch.control = source.chanBank[i].control;
                ch.Percent = source.chanBank[i].Percent;
                ch.mName   = source.chanBank[i].mName;

                chanBank.Add(ch);
            }
        }
    }
Beispiel #4
0
    void Start()
    {
        MegaMorph mr = GetComponent <MegaMorph>();

        if (mr != null)
        {
            channel   = mr.GetChannel(SrcChannel);
            channel1  = mr.GetChannel(SrcChannel1);
            channel2  = mr.GetChannel(SrcChannel2);
            channel3  = mr.GetChannel(SrcChannel3);
            channel4  = mr.GetChannel(SrcChannel4);
            channel5  = mr.GetChannel(SrcChannel5);
            channel6  = mr.GetChannel(SrcChannel6);
            channel7  = mr.GetChannel(SrcChannel7);
            channel8  = mr.GetChannel(SrcChannel8);
            channel9  = mr.GetChannel(SrcChannel9);
            channel10 = mr.GetChannel(SrcChannel10);
            channel11 = mr.GetChannel(SrcChannel11);
            channel12 = mr.GetChannel(SrcChannel12);
            channel13 = mr.GetChannel(SrcChannel13);
            channel14 = mr.GetChannel(SrcChannel14);
            channel15 = mr.GetChannel(SrcChannel15);
            channel16 = mr.GetChannel(SrcChannel16);
            channel17 = mr.GetChannel(SrcChannel17);
            channel18 = mr.GetChannel(SrcChannel18);
            channel19 = mr.GetChannel(SrcChannel19);
        }
    }
    bool AnimCallback(BinaryReader br, string id)
    {
        MegaMorph mr = (MegaMorph)target;

        switch (id)
        {
        case "Chan":
            int cn = br.ReadInt32() + startchan;
            if (cn < mr.chanBank.Count)
            {
                currentChan = mr.chanBank[cn];
            }
            else
            {
                Debug.LogWarning("Morph File has animation data for a missing target, check your original file and delete unused channels");
                currentChan = null;
            }
            break;

        case "Anim":
            MegaBezFloatKeyControl con = LoadAnim(br);
            if (currentChan != null)
            {
                currentChan.control = con;
            }
            break;

        default: return(false);
        }

        return(true);
    }
    void LoadTarget(MegaMorphTarget mt)
    {
        MegaMorph mr       = (MegaMorph)target;
        string    filename = EditorUtility.OpenFilePanel("Morph Target", lastpath, "obj");

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

        lastpath = filename;
        List <MegaTargetMesh> targets = MegaTargetMesh.LoadTargets(filename, mr.importScale, mr.flipyz, mr.negx);

        if (targets != null && targets.Count > 0)
        {
            MegaTargetMesh tm = targets[0];

            if (tm.verts.Count != mr.oPoints.Length)
            {
                EditorUtility.DisplayDialog("Target Vertex count mismatch!", "Target " + tm.name + " has wrong number of verts", "OK");
            }
            else
            {
                mt.points = tm.verts.ToArray();
                mt.name   = tm.name;
            }
        }
    }
    bool DoMapping(MegaModifiers mod, MegaMorph morph, MegaTargetMesh tm, int[] mapping, float scale, bool flipyz, bool negx, bool negy)
    {
        int step  = mod.verts.Length / 10;
        int count = 0;

        for (int i = 0; i < mod.verts.Length; i++)
        {
            count--;
            if (count < 0)
            {
                count = step;

                float a = (float)i / (float)mod.verts.Length;

                EditorUtility.DisplayProgressBar("Mapping", "Mapping vertex " + i, a);
            }
            mapping[i] = FindVert(mod.verts[i], tm.verts, morph.tolerance, scale, flipyz, negx, negy, i);

            if (mapping[i] == -1)
            {
                // Failed
                EditorUtility.ClearProgressBar();
                return(false);
            }
        }

        EditorUtility.ClearProgressBar();
        return(true);
    }
    int MorphedVerts(MegaMorph mr, MegaMorphChan channel)
    {
        int count = 0;

        for (int v = 0; v < mr.oPoints.Length; v++)
        {
            Vector3 p = mr.oPoints[v];

            bool morphed = false;

            for (int i = 0; i < channel.mTargetCache.Count; i++)
            {
                MegaMorphTarget mt = channel.mTargetCache[i];

                if (!p.Equals(mt.points[v]))
                {
                    morphed = true;
                    break;
                }
            }

            if (morphed)
            {
                count++;
            }
        }

        return(count);
    }
    void Start()
    {
        MegaMorph mr = GetComponent <MegaMorph>();

        if (mr != null)
        {
            channel   = mr.GetChannel(SrcChannel);
            channel1  = mr.GetChannel(SrcChannel1);
            channel2  = mr.GetChannel(SrcChannel2);
            channel3  = mr.GetChannel(SrcChannel3);
            channel4  = mr.GetChannel(SrcChannel4);
            channel5  = mr.GetChannel(SrcChannel5);
            channel6  = mr.GetChannel(SrcChannel6);
            channel7  = mr.GetChannel(SrcChannel7);
            channel8  = mr.GetChannel(SrcChannel8);
            channel9  = mr.GetChannel(SrcChannel9);
            channel10 = mr.GetChannel(SrcChannel10);
            channel11 = mr.GetChannel(SrcChannel11);
            channel12 = mr.GetChannel(SrcChannel12);
            channel13 = mr.GetChannel(SrcChannel13);
            channel14 = mr.GetChannel(SrcChannel14);
            channel15 = mr.GetChannel(SrcChannel15);
            channel16 = mr.GetChannel(SrcChannel16);
            channel17 = mr.GetChannel(SrcChannel17);
            channel18 = mr.GetChannel(SrcChannel18);
            channel19 = mr.GetChannel(SrcChannel19);
            channel20 = mr.GetChannel(SrcChannel20);
            channel21 = mr.GetChannel(SrcChannel21);
            channel22 = mr.GetChannel(SrcChannel22);
            channel23 = mr.GetChannel(SrcChannel23);
            channel24 = mr.GetChannel(SrcChannel24);
            channel25 = mr.GetChannel(SrcChannel25);
            channel26 = mr.GetChannel(SrcChannel26);
            channel27 = mr.GetChannel(SrcChannel27);
            channel28 = mr.GetChannel(SrcChannel28);
            channel29 = mr.GetChannel(SrcChannel29);
            channel30 = mr.GetChannel(SrcChannel30);
            channel31 = mr.GetChannel(SrcChannel31);
            channel32 = mr.GetChannel(SrcChannel32);
            channel33 = mr.GetChannel(SrcChannel33);
            channel34 = mr.GetChannel(SrcChannel34);
            channel35 = mr.GetChannel(SrcChannel35);
            channel36 = mr.GetChannel(SrcChannel36);
            channel37 = mr.GetChannel(SrcChannel37);
            channel38 = mr.GetChannel(SrcChannel38);
            channel39 = mr.GetChannel(SrcChannel39);
            channel40 = mr.GetChannel(SrcChannel40);
            channel41 = mr.GetChannel(SrcChannel41);
            channel42 = mr.GetChannel(SrcChannel42);
            channel43 = mr.GetChannel(SrcChannel43);
            channel44 = mr.GetChannel(SrcChannel44);
            channel45 = mr.GetChannel(SrcChannel45);
            channel46 = mr.GetChannel(SrcChannel46);
            channel47 = mr.GetChannel(SrcChannel47);
            channel48 = mr.GetChannel(SrcChannel48);
            channel49 = mr.GetChannel(SrcChannel49);
            channel50 = mr.GetChannel(SrcChannel50);
        }
    }
    public void GetMinMax(MegaMorph mr, int index, ref float min, ref float max)
    {
        MegaMorphChan chan = null;

        switch (index)
        {
        case 0: chan = channel; break;

        case 1: chan = channel1; break;

        case 2: chan = channel2; break;

        case 3: chan = channel3; break;

        case 4: chan = channel4; break;

        case 5: chan = channel5; break;

        case 6: chan = channel6; break;

        case 7: chan = channel7; break;

        case 8: chan = channel8; break;

        case 9: chan = channel9; break;

        case 10: chan = channel10; break;

        case 11: chan = channel11; break;

        case 12: chan = channel12; break;

        case 13: chan = channel13; break;

        case 14: chan = channel14; break;

        case 15: chan = channel15; break;

        case 16: chan = channel16; break;

        case 17: chan = channel17; break;

        case 18: chan = channel18; break;

        case 19: chan = channel19; break;
        }

        if (chan != null)
        {
            min = chan.mSpinmin;
            max = chan.mSpinmax;
        }
        else
        {
            min = 0.0f;
            max = 100.0f;
        }
    }
    // remove mPoints from channel, just use target list, if targets.Count == 1 then use delta
    // first target goes into mPoints
    // guess we should update any targets who we have already, ie use name
    void LoadTargets(MegaMorphChan channel)
    {
        MegaMorph mr = (MegaMorph)target;

        string filename = EditorUtility.OpenFilePanel("Morph Targets", lastpath, "obj");

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

        lastpath = filename;
        List <MegaTargetMesh> targets = MegaTargetMesh.LoadTargets(filename, mr.importScale, mr.flipyz, mr.negx);

        if (targets != null)
        {
            if (channel.mName == "Empty")
            {
                channel.mName = Path.GetFileNameWithoutExtension(filename);
            }

            // Now need to check that each target has correct num verts and face list matches
            for (int i = 0; i < targets.Count; i++)
            {
                MegaTargetMesh tm = targets[i];

                if (tm.verts.Count != mr.oPoints.Length)
                {
                    EditorUtility.DisplayDialog("Target Vertex count mismatch!", "Target " + tm.name + " has wrong number of verts", "OK");
                }
                else
                {
                    // See if we have a target with this name, if so update that
                    MegaMorphTarget mt = channel.GetTarget(tm.name);

                    if (mt == null)                             // add a new target
                    {
                        mt      = new MegaMorphTarget();
                        mt.name = tm.name;
                        channel.mTargetCache.Add(mt);
                    }

                    mt.points = tm.verts.ToArray();

                    //for ( int v = 0; v < mt.points.Length; v++ )
                    //{
                    //if ( mt.points[v] == mr.oPoints[v] )
                    //Debug.Log("Vert " + v + " isnt morphed");
                    //}
                }
            }

            channel.ResetPercent();
            channel.Rebuild(mr);                // rebuild delta for 1st channel
        }

        mr.BuildCompress();
    }
Beispiel #12
0
    public void ChannelMapping(MegaMorph mr)
    {
        mapping = new int[mr.oPoints.Length];

        for (int i = 0; i < mr.oPoints.Length; i++)
        {
            mapping[i] = i;
        }
    }
Beispiel #13
0
    public void ChannelMapping(MegaMorph mr)
    {
        mapping = new int[mr.oPoints.Length];

        for ( int i = 0; i < mr.oPoints.Length; i++ )
        {
            mapping[i] = i;
        }
    }
    void CompressChannel(MegaMorph mr, MegaMorphChan mc)
    {
        // for now change system to work off mapping, just have 1 to 1 mapping to test its working

        mc.mapping = new int[mr.oPoints.Length];

        for (int i = 0; i < mr.oPoints.Length; i++)
        {
            mc.mapping[i] = i;
        }
#if false
        BitArray modded = new BitArray(mr.oPoints.Length);

        modded.SetAll(false);

        for (int t = 0; t < mc.mTargetCache.Count; t++)
        {
            MegaMorphTarget mt = mc.mTargetCache[t];

            for (int i = 0; i < mr.oPoints.Length; i++)
            {
                if (mt.points[i] != mr.oPoints[i])                      // Have a threshold for this
                {
                    modded[i] = true;
                    break;
                }
            }
        }

        List <int> points = new List <int>();

        for (int i = 0; i < modded.Count; i++)
        {
            if (modded[i])
            {
                points.Add(i);
            }
        }

        // points now holds indexes of morphed verts for the channel, so now need to collapse points
        Vector3[] pts = new Vector3[points.Count];

        for (int t = 0; t < mc.mTargetCache.Count; t++)
        {
            MegaMorphTarget mt = mc.mTargetCache[t];

            for (int i = 0; i < points.Count; i++)
            {
                pts[i] = mt.points[points[i]];
            }

            pts.CopyTo(mt.points, 0);
        }

        // If one target deal with deltas
#endif
    }
    void ChannelMapping(MegaMorph mr, MegaMorphChan mc)
    {
        mc.mapping = new int[mr.oPoints.Length];

        for (int i = 0; i < mr.oPoints.Length; i++)
        {
            mc.mapping[i] = i;
        }
    }
Beispiel #16
0
    // 고개 내미는 애니메이션 및 얼굴 애니메이션을 위한 morph 세팅
    public void StartPeep()
    {
        StartCoroutine(Peeping());

        if (ModelData != null)
        {
            megaMorph = (MegaMorph)ModelData.GetComponent <MegaMorph>();
            SetMorph(1);
        }
    }
    void ImportParams(MegaMorph morph)
    {
        showimport = EditorGUILayout.Foldout(showimport, "Import Params");

        if (showimport)
        {
            morph.importScale = EditorGUILayout.FloatField("Import Scale", morph.importScale);
            morph.flipyz      = EditorGUILayout.Toggle("FlipYZ", morph.flipyz);
            morph.negx        = EditorGUILayout.Toggle("Negate X", morph.negx);
            morph.tolerance   = EditorGUILayout.FloatField("Tolerance", morph.tolerance);
        }
    }
    int CalcMemoryUsage(MegaMorph mr)
    {
        int mem = 0;

        for (int i = 0; i < mr.chanBank.Count; i++)
        {
            MegaMorphChan mc = mr.chanBank[i];

            mem += mc.mTargetCache.Count * 12 * mr.oPoints.Length;
        }

        return(mem);
    }
Beispiel #19
0
    public void Update(MegaMorph morph, bool islate)
    {
        if (active && late == islate)           //&& target )
        {
            float alpha = Mathf.Clamp01((GetVal() - min) / (max - min));

            if (useCurve)
            {
                alpha = curve.Evaluate(alpha);
            }

            morph.SetPercentLim(channel, alpha);                // * 100.0f);
        }
    }
Beispiel #20
0
 // delta is only used if we have a single target
 public void Rebuild(MegaMorph mp)
 {
     if (mTargetCache != null && mTargetCache.Count > 0 && mp.oPoints != null && mTargetCache[0].points != null)
     {
         if (mp.oPoints.Length == mTargetCache[0].points.Length)
         {
             //Debug.Log("oplen " + mp.oPoints.Length + " tclen " + mTargetCache[0].points.Length);
             mDeltas = new Vector3[mp.oPoints.Length];
             for (int i = 0; i < mTargetCache[0].points.Length; i++)
             {
                 mDeltas[i] = (mTargetCache[0].points[i] - mp.oPoints[i]) / 100.0f;
             }
         }
     }
 }
Beispiel #21
0
 // delta is only used if we have a single target
 public void Rebuild(MegaMorph mp)
 {
     if ( mTargetCache != null && mTargetCache.Count > 0 && mp.oPoints != null && mTargetCache[0].points != null )
     {
         if ( mp.oPoints.Length == mTargetCache[0].points.Length )
         {
             //Debug.Log("oplen " + mp.oPoints.Length + " tclen " + mTargetCache[0].points.Length);
             mDeltas = new Vector3[mp.oPoints.Length];
             for ( int i = 0; i < mTargetCache[0].points.Length; i++ )
             {
                 mDeltas[i] = (mTargetCache[0].points[i] - mp.oPoints[i]) / 100.0f;
             }
         }
     }
 }
    public void Update(MegaMorph morph, bool islate)
    {
        if (active && late == islate)           //&& target )
        {
            float alpha = Mathf.Clamp01((GetVal() - min) / (max - min));

            if (useCurve)
            {
                alpha = curve.Evaluate(alpha);
            }

            //Debug.Log("val " + GetVal() + " percent " + Mathf.Lerp(low, high, alpha) + " alpha " + alpha);
            morph.SetPercentLim(channel, Mathf.Lerp(low, high, alpha));                 // * 100.0f);
        }
    }
	public void SetChannel(MegaMorph mr, int index)
	{
		switch ( index )
		{
			case 0: channel = mr.GetChannel(SrcChannel);	break;
			case 1: channel1 = mr.GetChannel(SrcChannel1); break;
			case 2: channel2 = mr.GetChannel(SrcChannel2); break;
			case 3: channel3 = mr.GetChannel(SrcChannel3); break;
			case 4: channel4 = mr.GetChannel(SrcChannel4); break;
			case 5: channel5 = mr.GetChannel(SrcChannel5); break;
			case 6: channel6 = mr.GetChannel(SrcChannel6); break;
			case 7: channel7 = mr.GetChannel(SrcChannel7); break;
			case 8: channel8 = mr.GetChannel(SrcChannel9); break;
			case 9: channel9 = mr.GetChannel(SrcChannel9); break;
		}
	}
        // Use this for initialization
        void Awake()
        {
            balloonType      = BalloonType.NONE;
            currentCoroutine = null;

            StartCoroutine(MainCoroutine());                     // 메인 코루틴을 실행 시킨다.

            stateMachine = new StateMachine <Stage1Enemy>(this); // 스테이트 머신 생성

            if (ModelData != null)
            {
                // 캐릭터의 얼굴 애니메이션을 위한 morph 세팅, morph는 에셋을 구입하여 사용
                megaMorph = (MegaMorph)ModelData.GetComponent <MegaMorph>();
                SetMorph(1);
            }
        }
    bool AnimCallback(BinaryReader br, string id)
    {
        MegaMorph mr = (MegaMorph)target;

        switch (id)
        {
        case "Chan":
            int cn = br.ReadInt32();
            currentChan = mr.chanBank[cn]; break;

        case "Anim": currentChan.control = LoadAnim(br);        break;

        default: return(false);
        }

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

        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);
    }
    public void SetChannel(MegaMorph mr, int index)
    {
        switch (index)
        {
        case 0: channel = mr.GetChannel(SrcChannel);    break;

        case 1: channel1 = mr.GetChannel(SrcChannel1); break;

        case 2: channel2 = mr.GetChannel(SrcChannel2); break;

        case 3: channel3 = mr.GetChannel(SrcChannel3); break;

        case 4: channel4 = mr.GetChannel(SrcChannel4); break;

        case 5: channel5 = mr.GetChannel(SrcChannel5); break;

        case 6: channel6 = mr.GetChannel(SrcChannel6); break;

        case 7: channel7 = mr.GetChannel(SrcChannel7); break;

        case 8: channel8 = mr.GetChannel(SrcChannel8); break;

        case 9: channel9 = mr.GetChannel(SrcChannel9); break;

        case 10: channel10 = mr.GetChannel(SrcChannel10); break;

        case 11: channel11 = mr.GetChannel(SrcChannel11); break;

        case 12: channel12 = mr.GetChannel(SrcChannel12); break;

        case 13: channel13 = mr.GetChannel(SrcChannel13); break;

        case 14: channel14 = mr.GetChannel(SrcChannel14); break;

        case 15: channel15 = mr.GetChannel(SrcChannel15); break;

        case 16: channel16 = mr.GetChannel(SrcChannel16); break;

        case 17: channel17 = mr.GetChannel(SrcChannel17); break;

        case 18: channel18 = mr.GetChannel(SrcChannel18); break;

        case 19: channel19 = mr.GetChannel(SrcChannel19); break;
        }
    }
    void LoadMorph()
    {
        MegaMorph mr = (MegaMorph)target;
        //Modifiers mod = mr.GetComponent<Modifiers>();	// Do this at start and store

        string filename = EditorUtility.OpenFilePanel("Morph File", lastpath, "mor");

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

        lastpath = filename;

        // Clear what we have
        mr.chanBank.Clear();

        ParseFile(filename, MorphCallback);

        mr.animate = false;
        float looptime = 0.0f;

        // Set Looptime and animate if there is an anim
        for (int i = 0; i < mr.chanBank.Count; i++)
        {
            MegaMorphChan mc = mr.chanBank[i];

            if (mc.control != null)
            {
                mr.animate = true;
                float t = mc.control.Times[mc.control.Times.Length - 1];
                if (t > looptime)
                {
                    looptime = t;
                }
            }
        }

        if (mr.animate)
        {
            mr.looptime = looptime;
        }
        mr.compressedmem = 0;
        mr.BuildCompress();
    }
Beispiel #29
0
    void Start()
    {
        MegaMorph mr = GetComponent <MegaMorph>();

        if (mr != null)
        {
            channel  = mr.GetChannel(SrcChannel);
            channel1 = mr.GetChannel(SrcChannel1);
            channel2 = mr.GetChannel(SrcChannel2);
            channel3 = mr.GetChannel(SrcChannel3);
            channel4 = mr.GetChannel(SrcChannel4);
            channel5 = mr.GetChannel(SrcChannel5);
            channel6 = mr.GetChannel(SrcChannel6);
            channel7 = mr.GetChannel(SrcChannel7);
            channel8 = mr.GetChannel(SrcChannel9);
            channel9 = mr.GetChannel(SrcChannel9);
        }
    }
    int CalcCompressedMemory(MegaMorph mr)
    {
        int mem = 0;

        for (int i = 0; i < mr.chanBank.Count; i++)
        {
            MegaMorphChan mc = mr.chanBank[i];

            //mem += MorphedVerts(mr, mc) * 12 * mc.mTargetCache.Count;

            int mv = MorphedVerts(mr, mc);
            int m  = mv * 12 * mc.mTargetCache.Count;
            mem += m;
            EditorGUILayout.LabelField(mc.mName, "Verts: " + mv + " mem: " + m);
        }

        EditorGUILayout.LabelField("Total: ", (mem / 1024) + "KB");

        return(mem);
    }
    // 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);
    }
    void ConvertPoints(Vector3[] verts)
    {
        MegaMorph mr = (MegaMorph)target;

        for (int i = 0; i < verts.Length; i++)
        {
            Vector3 p = verts[i] * mr.importScale;

            if (mr.negx)
            {
                p.x = -p.x;
            }

            if (mr.flipyz)
            {
                float y = p.y;
                p.y = p.z;
                p.z = y;
            }

            verts[i] = p;
        }
    }
Beispiel #33
0
    void Update()
    {
        t += Time.deltaTime;

        if (t > time)
        {
            t -= time;
            Vector3 pos = Vector3.zero;

            pos.x = Random.Range(-range.x, range.x);
            pos.y = Random.Range(-range.y, range.y);
            pos.z = Random.Range(-range.z, range.z);

            GameObject newobj = MegaCopyObject.DeepCopy(spawnobj);
            newobj.transform.position = pos;

            MegaMorph mor = newobj.GetComponent <MegaMorph>();
            if (mor)
            {
                mor.animtime = 0.0f;
            }
        }
    }
    void LoadBase(MegaMorph morph)
    {
        string filename = EditorUtility.OpenFilePanel("Morph Base", lastpath, "obj");

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

        lastpath = filename;
        List <MegaTargetMesh> targets = MegaTargetMesh.LoadTargets(filename, 1.0f, false, false);               //morph.importScale, morph.flipyz, morph.negx);

        // only use first
        if (targets != null && targets.Count > 0)
        {
            if (!TryMapping(targets, morph))
            {
                // No match found
                EditorUtility.DisplayDialog("Mapping Failed!", "Mapping of " + Path.GetFileNameWithoutExtension(filename) + " failed!", "OK");
                EditorUtility.ClearProgressBar();
                return;
            }
        }
    }
Beispiel #35
0
    void CompressChannel(MegaMorph mr, MegaMorphChan mc)
    {
        // for now change system to work off mapping, just have 1 to 1 mapping to test its working

        mc.mapping = new int[mr.oPoints.Length];

        for ( int i = 0; i < mr.oPoints.Length; i++ )
        {
            mc.mapping[i] = i;
        }
        #if false
        BitArray modded = new BitArray(mr.oPoints.Length);

        modded.SetAll(false);

        for ( int t = 0; t < mc.mTargetCache.Count; t++ )
        {
            MegaMorphTarget mt = mc.mTargetCache[t];

            for ( int i = 0; i < mr.oPoints.Length; i++ )
            {
                if ( mt.points[i] != mr.oPoints[i] )	// Have a threshold for this
                {
                    modded[i] = true;
                    break;
                }
            }
        }

        List<int>	points = new List<int>();

        for ( int i = 0; i < modded.Count; i++ )
        {
            if ( modded[i] )
                points.Add(i);
        }

        // points now holds indexes of morphed verts for the channel, so now need to collapse points
        Vector3[] pts = new Vector3[points.Count];

        for ( int t = 0; t < mc.mTargetCache.Count; t++ )
        {
            MegaMorphTarget mt = mc.mTargetCache[t];

            for ( int i = 0; i < points.Count; i++ )
            {
                pts[i] = mt.points[points[i]];
            }

            pts.CopyTo(mt.points, 0);
        }

        // If one target deal with deltas
        #endif
    }
Beispiel #36
0
    bool TryMapping(List<MegaTargetMesh> targets, MegaMorph morph)
    {
        MegaModifiers mod = morph.GetComponent<MegaModifiers>();

        if ( mod == null )
        {
            //Debug.Log("No modifyobject found");
            EditorUtility.DisplayDialog("Missing ModifyObject!", "No ModifyObject script found on the object", "OK");
            return false;
        }

        int[] mapping = new int[mod.verts.Length];

        for ( int i = 0; i < 18; i++ )
        {
            Debug.Log("v[" + i + "] " + mod.verts[i].ToString("0.00000"));
        }

        for ( int i = 0; i < 18; i++ )
        {
            Debug.Log("t[" + i + "] " + targets[0].verts[i].ToString("0.00000"));
        }

        for ( int t = 0; t < targets.Count;	t++ )
        {
            MegaTargetMesh tm = targets[t];

            // Get extents for mod verts and for imported meshes, if not the same then scale
            Vector3 min1,max1;
            Vector3 min2,max2;

            Vector3 ex1 = Extents(mod.verts, out min1, out max1);
            Vector3 ex2 = Extents(tm.verts, out min2, out max2);

            Debug.Log("min1 " + min1.ToString("0.000"));
            Debug.Log("max1 " + max1.ToString("0.000"));
            Debug.Log("min2 " + min2.ToString("0.000"));
            Debug.Log("max2 " + max2.ToString("0.000"));
            // need min max on all axis so we can produce an offset to add
            float d1 = ex1.x;
            float d2 = ex2.x;

            float scl = d1 / d2;	//d2 / d1;
            bool flipyz = false;
            bool negx = false;

            //Vector3 offset = (min2 * scl) - min1;
            //Debug.Log("offset " + offset.ToString("0.0000"));
            Debug.Log("scl " + scl);

            // So try to match first vert using autoscale and no flip
            bool mapped = DoMapping(mod, morph, tm, mapping, scl, flipyz, negx);

            if ( !mapped )
            {
                flipyz = true;
                mapped = DoMapping(mod, morph, tm, mapping, scl, flipyz, negx);
                if ( !mapped )	//DoMapping(mod, morph, tm, mapping, scl, flipyz, negx) )
                {
                    flipyz = false;
                    negx = true;
                    mapped = DoMapping(mod, morph, tm, mapping, scl, flipyz, negx);
                    if ( !mapped )
                    {
                        flipyz = true;
                        mapped = DoMapping(mod, morph, tm, mapping, scl, flipyz, negx);
                    }
                }
            }

            if ( mapped )
            {
                morph.importScale = scl;
                morph.flipyz = flipyz;
                morph.negx = negx;

                morph.mapping = mapping;
                // if mapping was ok set opoints
                morph.oPoints = tm.verts.ToArray();

                for ( int i = 0; i < morph.oPoints.Length; i++ )
                {
                    Vector3 p = morph.oPoints[i];

                    if ( negx )
                        p.x = -p.x;

                    if ( flipyz )
                    {
                        float z = p.z;
                        p.z = p.y;
                        p.y = z;
                    }

                    morph.oPoints[i] = p * morph.importScale;
                }

                return true;
            }
        }

        return false;
    }
Beispiel #37
0
    int MorphedVerts(MegaMorph mr, MegaMorphChan channel)
    {
        int count = 0;

        for ( int v = 0; v < mr.oPoints.Length; v++ )
        {
            Vector3 p = mr.oPoints[v];

            bool morphed = false;

            for ( int i = 0; i < channel.mTargetCache.Count; i++ )
            {
                MegaMorphTarget mt = channel.mTargetCache[i];

                if ( !p.Equals(mt.points[v]) )
                {
                    morphed = true;
                    break;
                }
            }

            if ( morphed )
                count++;
        }

        return count;
    }
Beispiel #38
0
    void LoadBase(MegaMorph morph)
    {
        string filename = EditorUtility.OpenFilePanel("Morph Base", lastpath, "obj");

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

        lastpath = filename;
        List<MegaTargetMesh> targets = MegaTargetMesh.LoadTargets(filename, 1.0f, false, false);	//morph.importScale, morph.flipyz, morph.negx);

        // only use first
        if ( targets != null && targets.Count > 0 )
        {
            if ( !TryMapping(targets, morph) )
            {
                // No match found
                EditorUtility.DisplayDialog("Mapping Failed!", "Mapping of " + Path.GetFileNameWithoutExtension(filename) + " failed!", "OK");
                EditorUtility.ClearProgressBar();
                return;
            }
        }
    }
Beispiel #39
0
 void LoadAnimation(MegaMorph mr, BinaryReader br)
 {
     //Parse(br, AnimCallback);
     MegaParse.Parse(br, AnimCallback);
 }
Beispiel #40
0
    void ImportParams(MegaMorph morph)
    {
        showimport = EditorGUILayout.Foldout(showimport, "Import Params");

        if ( showimport )
        {
            morph.importScale = EditorGUILayout.FloatField("Import Scale", morph.importScale);
            morph.flipyz = EditorGUILayout.Toggle("FlipYZ", morph.flipyz);
            morph.negx = EditorGUILayout.Toggle("Negate X", morph.negx);
            morph.tolerance = EditorGUILayout.FloatField("Tolerance", morph.tolerance);
        }
    }
Beispiel #41
0
    // TODO: report error if target vert counts dont match base mapping
    bool DoMapping(MegaModifiers mod, MegaMorph morph, MegaTargetMesh tm, int[] mapping, float scale, bool flipyz, bool negx)
    {
        for ( int i = 0; i < mod.verts.Length; i++ )
        {
            float a = (float)i / (float)mod.verts.Length;

            EditorUtility.DisplayProgressBar("Mapping", "Mapping vertex " + i, a);
            mapping[i] = FindVert(mod.verts[i], tm.verts, morph.tolerance, scale, flipyz, negx, i);

            if ( mapping[i] == -1 )
            {
                // Failed
                EditorUtility.ClearProgressBar();
                return false;
            }
        }

        EditorUtility.ClearProgressBar();
        return true;
    }
Beispiel #42
0
    void DisplayChannelLim(MegaMorph morph, MegaMorphChan channel, int num)
    {
        float min = 0.0f;
        float max = 100.0f;
        if ( morph.UseLimit )
        {
            min = morph.Min;
            max = morph.Max;
        }

        GUI.backgroundColor = new Color(1, 1, 1);
        if ( channel.mActiveOverride && channel.mTargetCache != null && channel.mTargetCache.Count > 0 )
        {
            if ( morph.UseLimit )
            {
                channel.Percent = EditorGUILayout.Slider(channel.mName, channel.Percent, min, max);	//0.0f, 100.0f);
            }
            else
            {
                if ( channel.mUseLimit )
                    channel.Percent = EditorGUILayout.Slider(channel.mName, channel.Percent, channel.mSpinmin, channel.mSpinmax);
                else
                    channel.Percent = EditorGUILayout.Slider(channel.mName, channel.Percent, 0.0f, 100.0f);
            }
        }
    }
Beispiel #43
0
    public void GetMinMax(MegaMorph mr, int index, ref float min, ref float max)
    {
        MegaMorphChan chan = null;

        switch ( index )
        {
            case 0: chan = channel;	break;
            case 1: chan = channel1; break;
            case 2: chan = channel2; break;
            case 3: chan = channel3; break;
            case 4: chan = channel4; break;
            case 5: chan = channel5; break;
            case 6: chan = channel6; break;
            case 7: chan = channel7; break;
            case 8: chan = channel8; break;
            case 9: chan = channel9; break;
            case 10: chan = channel10; break;
            case 11: chan = channel11; break;
            case 12: chan = channel12; break;
            case 13: chan = channel13; break;
            case 14: chan = channel14; break;
            case 15: chan = channel15; break;
            case 16: chan = channel16; break;
            case 17: chan = channel17; break;
            case 18: chan = channel18; break;
            case 19: chan = channel19; break;
            case 20: chan = channel20; break;
            case 21: chan = channel21; break;
            case 22: chan = channel22; break;
            case 23: chan = channel23; break;
            case 24: chan = channel24; break;
            case 25: chan = channel25; break;
            case 26: chan = channel26; break;
            case 27: chan = channel27; break;
            case 28: chan = channel28; break;
            case 29: chan = channel29; break;
            case 30: chan = channel30; break;
            case 31: chan = channel31; break;
            case 32: chan = channel32; break;
            case 33: chan = channel33; break;
            case 34: chan = channel34; break;
            case 35: chan = channel35; break;
            case 36: chan = channel36; break;
            case 37: chan = channel37; break;
            case 38: chan = channel38; break;
            case 39: chan = channel39; break;
            case 40: chan = channel40; break;
            case 41: chan = channel41; break;
            case 42: chan = channel42; break;
            case 43: chan = channel43; break;
            case 44: chan = channel44; break;
            case 45: chan = channel45; break;
            case 46: chan = channel46; break;
            case 47: chan = channel47; break;
            case 48: chan = channel48; break;
            case 49: chan = channel49; break;
            case 50: chan = channel50; break;
        }

        if ( chan != null )
        {
            min = chan.mSpinmin;
            max = chan.mSpinmax;
        }
        else
        {
            min = 0.0f;
            max = 100.0f;
        }
    }
Beispiel #44
0
    public void Update(MegaMorph morph, bool islate)
    {
        if ( active && late == islate )	//&& target )
        {
            float alpha = Mathf.Clamp01((GetVal() - min) / (max - min));

            if ( useCurve )
                alpha = curve.Evaluate(alpha);

            //Debug.Log("val " + GetVal() + " percent " + Mathf.Lerp(low, high, alpha) + " alpha " + alpha);
            morph.SetPercentLim(channel, Mathf.Lerp(low, high, alpha));	// * 100.0f);
        }
    }
Beispiel #45
0
    int CalcCompressedMemory(MegaMorph mr)
    {
        int mem = 0;

        for ( int i = 0; i < mr.chanBank.Count; i++ )
        {
            MegaMorphChan mc = mr.chanBank[i];

            //mem += MorphedVerts(mr, mc) * 12 * mc.mTargetCache.Count;

            int mv = MorphedVerts(mr, mc);
            int m = mv * 12 * mc.mTargetCache.Count;
            mem += m;
            EditorGUILayout.LabelField(mc.mName, "Verts: " + mv + " mem: " + m);
        }

        EditorGUILayout.LabelField("Total: ", (mem / 1024) + "KB");

        return mem;
    }
Beispiel #46
0
    public void SetSource(MegaMorph src)
    {
        source = src;

        if ( source )
        {
            if ( chanBank == null )
                chanBank = new List<MegaMorphChan>();

            chanBank.Clear();

            for ( int i = 0; i < source.chanBank.Count; i++ )
            {
                MegaMorphChan ch = new MegaMorphChan();

                ch.control = source.chanBank[i].control;
                ch.Percent = source.chanBank[i].Percent;
                ch.mName = source.chanBank[i].mName;

                chanBank.Add(ch);
            }
        }
    }
Beispiel #47
0
 public void SetChannel(MegaMorph mr, int index)
 {
     switch ( index )
     {
         case 0: channel = mr.GetChannel(SrcChannel);	break;
         case 1: channel1 = mr.GetChannel(SrcChannel1); break;
         case 2: channel2 = mr.GetChannel(SrcChannel2); break;
         case 3: channel3 = mr.GetChannel(SrcChannel3); break;
         case 4: channel4 = mr.GetChannel(SrcChannel4); break;
         case 5: channel5 = mr.GetChannel(SrcChannel5); break;
         case 6: channel6 = mr.GetChannel(SrcChannel6); break;
         case 7: channel7 = mr.GetChannel(SrcChannel7); break;
         case 8: channel8 = mr.GetChannel(SrcChannel8); break;
         case 9: channel9 = mr.GetChannel(SrcChannel9); break;
         case 10: channel10 = mr.GetChannel(SrcChannel10); break;
         case 11: channel11 = mr.GetChannel(SrcChannel11); break;
         case 12: channel12 = mr.GetChannel(SrcChannel12); break;
         case 13: channel13 = mr.GetChannel(SrcChannel13); break;
         case 14: channel14 = mr.GetChannel(SrcChannel14); break;
         case 15: channel15 = mr.GetChannel(SrcChannel15); break;
         case 16: channel16 = mr.GetChannel(SrcChannel16); break;
         case 17: channel17 = mr.GetChannel(SrcChannel17); break;
         case 18: channel18 = mr.GetChannel(SrcChannel18); break;
         case 19: channel19 = mr.GetChannel(SrcChannel19); break;
         case 20: channel20 = mr.GetChannel(SrcChannel20); break;
         case 21: channel21 = mr.GetChannel(SrcChannel21); break;
         case 22: channel22 = mr.GetChannel(SrcChannel22); break;
         case 23: channel23 = mr.GetChannel(SrcChannel23); break;
         case 24: channel24 = mr.GetChannel(SrcChannel24); break;
         case 25: channel25 = mr.GetChannel(SrcChannel25); break;
         case 26: channel26 = mr.GetChannel(SrcChannel26); break;
         case 27: channel27 = mr.GetChannel(SrcChannel27); break;
         case 28: channel28 = mr.GetChannel(SrcChannel28); break;
         case 29: channel29 = mr.GetChannel(SrcChannel29); break;
         case 30: channel30 = mr.GetChannel(SrcChannel30); break;
         case 31: channel31 = mr.GetChannel(SrcChannel31); break;
         case 32: channel32 = mr.GetChannel(SrcChannel32); break;
         case 33: channel33 = mr.GetChannel(SrcChannel33); break;
         case 34: channel34 = mr.GetChannel(SrcChannel34); break;
         case 35: channel35 = mr.GetChannel(SrcChannel35); break;
         case 36: channel36 = mr.GetChannel(SrcChannel36); break;
         case 37: channel37 = mr.GetChannel(SrcChannel37); break;
         case 38: channel38 = mr.GetChannel(SrcChannel38); break;
         case 39: channel39 = mr.GetChannel(SrcChannel39); break;
         case 40: channel40 = mr.GetChannel(SrcChannel40); break;
         case 41: channel41 = mr.GetChannel(SrcChannel41); break;
         case 42: channel42 = mr.GetChannel(SrcChannel42); break;
         case 43: channel43 = mr.GetChannel(SrcChannel43); break;
         case 44: channel44 = mr.GetChannel(SrcChannel44); break;
         case 45: channel45 = mr.GetChannel(SrcChannel45); break;
         case 46: channel46 = mr.GetChannel(SrcChannel46); break;
         case 47: channel47 = mr.GetChannel(SrcChannel47); break;
         case 48: channel48 = mr.GetChannel(SrcChannel48); break;
         case 49: channel49 = mr.GetChannel(SrcChannel49); break;
         case 50: channel50 = mr.GetChannel(SrcChannel50); break;
     }
 }
Beispiel #48
0
    void DisplayChannel(MegaMorph morph, MegaMorphChan channel, int num)
    {
        if ( GUILayout.Button(num + " - " + channel.mName) )
            channel.showparams = !channel.showparams;

        GUI.backgroundColor = new Color(1, 1, 1);
        if ( channel.showparams )
        {
            channel.mName = EditorGUILayout.TextField("Name", channel.mName);

            if ( channel.mTargetCache != null && channel.mTargetCache.Count > 0 )
            {
                channel.mActiveOverride = EditorGUILayout.Toggle("Active", channel.mActiveOverride);
                channel.Percent = EditorGUILayout.Slider("Percent", channel.Percent, 0.0f, 100.0f);
                channel.mCurvature = EditorGUILayout.FloatField("Tension", channel.mCurvature);
            }

            channel.mUseLimit = EditorGUILayout.Toggle("Use Limit", channel.mUseLimit);

            if ( channel.mUseLimit )
            {
                channel.mSpinmin = EditorGUILayout.FloatField("Min", channel.mSpinmin);
                channel.mSpinmax = EditorGUILayout.FloatField("Max", channel.mSpinmax);
            }

            EditorGUILayout.BeginHorizontal();
            PushCols();
            GUI.backgroundColor = new Color(0.5f, 0.5f, 0.5f);
            if ( GUILayout.Button("Load Targets") )
                LoadTargets(channel);

            GUI.backgroundColor = new Color(0.5f, 1.0f, 0.5f);
            if ( GUILayout.Button("Add Target") )
            {
                if ( channel.mTargetCache == null )
                    channel.mTargetCache = new List<MegaMorphTarget>();

                MegaMorphTarget mt = new MegaMorphTarget();
                channel.mTargetCache.Add(mt);
                channel.ResetPercent();
            }

            GUI.backgroundColor = new Color(1.5f, 0.5f, 0.5f);
            if ( GUILayout.Button("Delete Channel") )
                morph.chanBank.Remove(channel);

            EditorGUILayout.EndHorizontal();

            PopCols();

            if ( channel.mTargetCache != null && channel.mTargetCache.Count > 0 )
            {
                channel.showtargets = EditorGUILayout.Foldout(channel.showtargets, "Targets");

                if ( channel.showtargets )
                {
                    if ( channel.mTargetCache != null )
                    {
                        for ( int i = 0; i < channel.mTargetCache.Count; i++ )
                            DisplayTarget(morph, channel, channel.mTargetCache[i], i);
                    }
                }
            }
        }
        else
        {
            if ( channel.mActiveOverride && channel.mTargetCache != null && channel.mTargetCache.Count > 0 )
                channel.Percent = EditorGUILayout.Slider("Percent", channel.Percent, 0.0f, 100.0f);
        }
    }
Beispiel #49
0
    int CalcMemoryUsage(MegaMorph mr)
    {
        int mem = 0;

        for ( int i = 0; i < mr.chanBank.Count; i++ )
        {
            MegaMorphChan mc = mr.chanBank[i];

            mem += mc.mTargetCache.Count * 12 * mr.oPoints.Length;
        }

        return mem;
    }
Beispiel #50
0
    // Still need to be able to add in unity meshes
    void DisplayTarget(MegaMorph morph, MegaMorphChan channel, MegaMorphTarget mt, int num)
    {
        PushCols();
        EditorGUI.indentLevel = 1;
        mt.name = EditorGUILayout.TextField("Name", mt.name);
        mt.percent = EditorGUILayout.Slider("Percent", mt.percent, 0.0f, 100.0f);

        EditorGUILayout.BeginHorizontal();

        if ( mt.points == null || mt.points.Length != morph.oPoints.Length)
            GUI.backgroundColor = new Color(0.5f, 0.5f, 0.5f);
        else
            GUI.backgroundColor = new Color(0.0f, 1.0f, 0.0f);

        if ( GUILayout.Button("Load") )
        {
            LoadTarget(mt);
        }

        GUI.backgroundColor = new Color(1.0f, 0.5f, 0.5f);
        if ( GUILayout.Button("Delete") )
        {
            MegaMorphTarget mt0 = channel.mTargetCache[0];

            channel.mTargetCache.Remove(mt);
            channel.ResetPercent();

            if ( channel.mTargetCache.Count > 0 && channel.mTargetCache[0] != mt0 )
                channel.Rebuild(morph);
        }

        GUI.backgroundColor = new Color(1.0f, 1.0f, 0.5f);
        if ( GUILayout.Button("Up") )
        {
            if ( num > 0 )
            {
                SwapTargets(channel, num, num - 1);

                if ( num == 1 )
                    channel.Rebuild(morph);
            }
        }

        GUI.backgroundColor = new Color(0.5f, 1.0f, 1.0f);
        if ( GUILayout.Button("Dn") )
        {
            if ( num < channel.mTargetCache.Count - 1 )
            {
                SwapTargets(channel, num, num + 1);

                if ( num == 0 )
                    channel.Rebuild(morph);
            }
        }

        EditorGUILayout.EndHorizontal();
        EditorGUI.indentLevel = 0;
        PopCols();
    }
Beispiel #51
0
 void Start()
 {
     if ( !morph )
         morph = GetComponent<MegaMorph>();
 }
Beispiel #52
0
    void ChannelMapping(MegaMorph mr, MegaMorphChan mc)
    {
        mc.mapping = new int[mr.oPoints.Length];

        for ( int i = 0; i < mr.oPoints.Length; i++ )
        {
            mc.mapping[i] = i;
        }
    }