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); } } }
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 DisplayChannelLim(MegaMorphRef 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 (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); } } }
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); } }
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; } }
static public void Copy(MegaMorphChan from, MegaMorphChan to) { to.mName = from.mName; to.Percent = from.Percent; to.mActiveOverride = from.mActiveOverride; to.mUseLimit = from.mUseLimit; to.mSpinmax = from.mSpinmax; to.mSpinmin = from.mSpinmin; to.mDeltas = from.mDeltas; to.mCurvature = from.mCurvature; to.showparams = from.showparams; to.showtargets = from.showtargets; to.mTargetCache = from.mTargetCache; to.control = from.control; to.mapping = from.mapping; to.cubic = from.cubic; to.morphedVerts = from.morphedVerts; to.oPoints = from.oPoints; to.speed = from.speed; to.targetPercent = from.targetPercent; to.fChannelPercent = from.fChannelPercent; to.targ = from.targ; to.fProgression = from.fProgression; to.segment = from.segment; to.p1 = from.p1; to.p2 = from.p2; to.p3 = from.p3; to.p4 = from.p4; to.diff = from.diff; }
public static void Copy(MegaMorphChan from, MegaMorphChan to) { to.mName = from.mName; to.Percent = from.Percent; to.mActiveOverride = from.mActiveOverride; to.mUseLimit = from.mUseLimit; to.mSpinmax = from.mSpinmax; to.mSpinmin = from.mSpinmin; to.mDeltas = from.mDeltas; to.mCurvature = from.mCurvature; to.showparams = from.showparams; to.showtargets = from.showtargets; to.mTargetCache = from.mTargetCache; to.control = from.control; to.mapping = from.mapping; to.cubic = from.cubic; to.morphedVerts = from.morphedVerts; to.oPoints = from.oPoints; to.speed = from.speed; to.targetPercent = from.targetPercent; to.fChannelPercent = from.fChannelPercent; to.targ = from.targ; to.fProgression = from.fProgression; to.segment = from.segment; to.p1 = from.p1; to.p2 = from.p2; to.p3 = from.p3; to.p4 = from.p4; to.diff = from.diff; }
// This is common to other morpher void DisplayChannel(MegaMorphOMatic morph, MegaMorphChan channel) { if ( GUILayout.Button(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, channel.mSpinmin, channel.mSpinmax); //.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); 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, channel.mSpinmin, channel.mSpinmax); //.0f, 100.0f); } } }
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); } }
// 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(); }
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; } }
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; } }
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 DisplayChannel(MegaMorphRef morph, MegaMorphChan channel, int num) { if (GUILayout.Button(num + " - " + channel.mName)) { channel.showparams = !channel.showparams; } 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.showparams) { channel.mName = EditorGUILayout.TextField("Name", channel.mName); if (morph.UseLimit) { channel.Percent = EditorGUILayout.Slider("Percent", channel.Percent, min, max); //0.0f, 100.0f); } else { if (channel.mUseLimit) { channel.Percent = EditorGUILayout.Slider("Percent", channel.Percent, channel.mSpinmin, channel.mSpinmax); } else { channel.Percent = EditorGUILayout.Slider("Percent", channel.Percent, 0.0f, 100.0f); } } } else { if (morph.UseLimit) { channel.Percent = EditorGUILayout.Slider("Percent", channel.Percent, min, max); //0.0f, 100.0f); } else { if (channel.mUseLimit) { channel.Percent = EditorGUILayout.Slider("Percent", channel.Percent, channel.mSpinmin, channel.mSpinmax); } else { channel.Percent = EditorGUILayout.Slider("Percent", channel.Percent, 0.0f, 100.0f); } } } }
void SetVerts(MegaMorphChan chan, int j, Vector3[] p) { switch (j) { case 0: chan.p1 = p; break; case 1: chan.p2 = p; break; case 2: chan.p3 = p; break; case 3: chan.p4 = p; break; } }
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); }
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); }
void SwapTargets(MegaMorphChan chan, int t1, int t2) { if (t1 >= 0 && t1 < chan.mTargetCache.Count && t2 >= 0 && t2 < chan.mTargetCache.Count && t1 != t2) { MegaMorphTarget mt1 = chan.mTargetCache[t1]; MegaMorphTarget mt2 = chan.mTargetCache[t2]; float per = mt1.percent; mt1.percent = mt2.percent; mt2.percent = per; chan.mTargetCache.RemoveAt(t1); chan.mTargetCache.Insert(t2, mt1); EditorUtility.SetDirty(target); } }
public override void PostCopy(MegaModifier src) { MegaMorphBase mor = (MegaMorphBase)src; chanBank = new List <MegaMorphChan>(); for (int c = 0; c < mor.chanBank.Count; c++) { MegaMorphChan chan = new MegaMorphChan(); MegaMorphChan.Copy(mor.chanBank[c], chan); chanBank.Add(chan); } }
public override void PostCopy(MegaModifier src) { MegaMorphBase mor = (MegaMorphBase)src; chanBank = new List<MegaMorphChan>(); for ( int c = 0; c < mor.chanBank.Count; c++ ) { MegaMorphChan chan = new MegaMorphChan(); MegaMorphChan.Copy(mor.chanBank[c], chan); chanBank.Add(chan); } }
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(SrcChannel9); break; case 9: channel9 = mr.GetChannel(SrcChannel9); break; } }
bool AnimCallback(BinaryReader br, string id) { MegaMorphOMatic mr = (MegaMorphOMatic)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 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(); }
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); } }
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); } }
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); }
void LoadMorph() { MegaMorphOMatic mr = (MegaMorphOMatic)target; string filename = EditorUtility.OpenFilePanel("Morph-O-Matic Morph File", lastpath, "mmf"); 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; } BuildData(); }
void DisplayTarget(MegaMorphOMatic 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); mt.percent = EditorGUILayout.Slider("Percent", mt.percent, channel.mSpinmin, channel.mSpinmax); //.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); GUI.backgroundColor = new Color(1.0f, 0.5f, 0.5f); EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel = 0; PopCols(); }
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); }
// 캐릭터 얼굴 애니메이션을 위한 morph 세팅 함수, 에셋을 구입하여 사용 public void SetMorph(int morphCnt) { if (megaMorph == null) { return; } float looptime = 0.0f; int start = morphCnt * 29; int end = (morphCnt + 1) * 29; int count = 0; if (megaMorph.chanBank[count] == null || !MorpManager.Instance.IsChanBankData()) { return; } for (int i = start; i < end; i++) { megaMorph.chanBank[count] = MorpManager.Instance.GetChanBank(i); MegaMorphChan mc = megaMorph.chanBank[count]; count++; if (mc.control != null) // ISSUE: On 2nd load we suddenly have controls for no reason { megaMorph.animate = true; if (mc.control.Times != null && mc.control.Times.Length > 0) { float t = mc.control.Times[mc.control.Times.Length - 1]; if (t > looptime) { looptime = t; } } } megaMorph.looptime = looptime; } }
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); for ( int i = 0; i < chan.mTargetCache.Count; i++ ) { if ( chan.mTargetCache[i].points == null || chan.mTargetCache[i].points.Length == 0 ) return null; } MegaMorph mr = (MegaMorph)target; chan.Rebuild(mr); return chan; }
void DisplayTarget(MegaMorphOMatic 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); mt.percent = EditorGUILayout.Slider("Percent", mt.percent, channel.mSpinmin, channel.mSpinmax); //.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); } GUI.backgroundColor = new Color(1.0f, 0.5f, 0.5f); EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel = 0; PopCols(); }
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); } } }
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; } }
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; mr.animtype = MegaMorphAnimType.Bezier; } break; case "MayaAnim": MegaBezFloatKeyControl hcon = LoadMayaAnim(br); if ( currentChan != null ) { currentChan.control = hcon; //currentChan.control = currentChan.hcontrol; mr.animtype = MegaMorphAnimType.Hermite; } break; default: return false; } return true; }
void DisplayChannel(MegaMorphRef morph, MegaMorphChan channel, int num) { if ( GUILayout.Button(num + " - " + channel.mName) ) channel.showparams = !channel.showparams; 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.showparams ) { channel.mName = EditorGUILayout.TextField("Name", channel.mName); if ( morph.UseLimit ) channel.Percent = EditorGUILayout.Slider("Percent", channel.Percent, min, max); //0.0f, 100.0f); else { if ( channel.mUseLimit ) channel.Percent = EditorGUILayout.Slider("Percent", channel.Percent, channel.mSpinmin, channel.mSpinmax); else channel.Percent = EditorGUILayout.Slider("Percent", channel.Percent, 0.0f, 100.0f); } } else { if ( morph.UseLimit ) channel.Percent = EditorGUILayout.Slider("Percent", channel.Percent, min, max); //0.0f, 100.0f); else { if ( channel.mUseLimit ) channel.Percent = EditorGUILayout.Slider("Percent", channel.Percent, channel.mSpinmin, channel.mSpinmax); else channel.Percent = EditorGUILayout.Slider("Percent", channel.Percent, 0.0f, 100.0f); } } }
public static GameObject DoCopyObjects(GameObject from) { MegaModifyObject fromMod = from.GetComponent<MegaModifyObject>(); GameObject to; if ( fromMod ) { to = CopyMesh(from, fromMod); } else to = CopyMesh(from); //CopyObject.CopyFromTo(from, to); //return to; //MegaModifier[] desmods = to.GetComponents<MegaModifier>(); //for ( int i = 0; i < desmods.Length; i++ ) //{ // GameObject.DestroyImmediate(desmods[i]); //} //MegaModifyObject mo = to.GetComponent<MegaModifyObject>(); //if ( mo ) //{ //GameObject.DestroyImmediate(mo); MegaModifyObject mo = to.AddComponent<MegaModifyObject>(); CopyModObj(fromMod, mo); //} MegaModifier[] mods = from.GetComponents<MegaModifier>(); for ( int i = 0; i < mods.Length; i++ ) { Component com = CopyComponent(mods[i], to); //Type tp = com.GetType(); #if false if ( tp.IsSubclassOf(typeof(MegaMorphBase)) ) { MegaMorphBase mor = (MegaMorphBase)com; // Need to rebuild the morphchan List<MegaMorphChan> chans = new List<MegaMorphChan>(); for ( int c = 0; c < mor.chanBank.Count; c++ ) { MegaMorphChan chan = new MegaMorphChan(); MegaMorphChan.Copy(mor.chanBank[c], chan); chans.Add(chan); } mor.chanBank = chans; } #endif #if false if ( tp.IsSubclassOf(typeof(MegaFFD)) ) { MegaFFD ffd = (MegaFFD)com; MegaFFD srcffd = (MegaFFD)mods[i]; ffd.pt = new Vector3[64]; for ( int c = 0; c < 64; c++ ) { ffd.pt[c] = srcffd.pt[c]; } } #endif // TODO: Add method to modifiers so can deal with any special cases if ( com ) { MegaModifier mod = (MegaModifier)com; mod.PostCopy(mods[i]); } } if ( mo ) { //mod.ReStart1(false); //for ( int i = 0; i < mods.Length; i++ ) // mods[i].SetModMesh(mod.cachedMesh); mo.MeshUpdated(); } to.name = from.name + " - Copy"; return to; }
// 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(); }
void DisplayChannel(MegaMorph morph, MegaMorphChan channel, int num) { if ( GUILayout.Button(num + " - " + channel.mName) ) channel.showparams = !channel.showparams; 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.showparams ) { channel.mName = EditorGUILayout.TextField("Name", channel.mName); if ( channel.mTargetCache != null && channel.mTargetCache.Count > 0 ) { channel.mActiveOverride = EditorGUILayout.Toggle("Active", channel.mActiveOverride); if ( morph.UseLimit ) { channel.Percent = EditorGUILayout.Slider("Percent", channel.Percent, min, max); //0.0f, 100.0f); } else { if ( channel.mUseLimit ) channel.Percent = EditorGUILayout.Slider("Percent", channel.Percent, channel.mSpinmin, channel.mSpinmax); else 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); if ( morph.UseLimit ) { channel.Percent = EditorGUILayout.Slider("Percent", channel.Percent, min, max); //0.0f, 100.0f); } else { if ( channel.mUseLimit ) channel.Percent = EditorGUILayout.Slider("Percent", channel.Percent, channel.mSpinmin, channel.mSpinmax); else channel.Percent = EditorGUILayout.Slider("Percent", channel.Percent, 0.0f, 100.0f); } } } }
// This is common to other morpher void DisplayChannel(MegaMorphOMatic morph, MegaMorphChan channel) { if (GUILayout.Button(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, channel.mSpinmin, channel.mSpinmax); //.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); 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, channel.mSpinmin, channel.mSpinmax); //.0f, 100.0f); } } }
// Build the morphing data // each target holds only the points that differe from the base so need to build table showing for each // target the points that differ public void BuildData() { MegaMorphOMatic mod = (MegaMorphOMatic)target; List <MOMVert> verts = new List <MOMVert>(); for (int c = 0; c < mod.chanBank.Count; c++) { MegaMorphChan chan = mod.chanBank[c]; int maxverts = 0; for (int t = 0; t < chan.mTargetCache.Count - 1; t++) { MegaMorphTarget targ = chan.mTargetCache[t]; MegaMorphTarget targ1 = chan.mTargetCache[t + 1]; // if t is 0 then just use the points Vector3 delta = Vector3.zero; Vector3 delta1 = Vector3.zero; float w = 1.0f; verts.Clear(); for (int v = 0; v < mod.oPoints.Length; v++) { bool t1 = GetDelta(targ, v, out delta, out w); bool t2 = GetDelta(targ1, v, out delta1, out w); if (t1 || t2) //GetDelta(targ, v, out delta, out w) || GetDelta(targ1, v, out delta1, out w) ) { MOMVert vert = new MOMVert(); vert.id = v; vert.w = w; vert.start = delta; vert.delta = delta1 - delta; verts.Add(vert); } } if (verts.Count > maxverts) { maxverts = verts.Count; } if (verts.Count > 0) { targ.mompoints = verts.ToArray(); } } for (int t = 0; t < chan.mTargetCache.Count; t++) { chan.mTargetCache[t].loadpoints = null; } chan.diff = new Vector3[maxverts]; } }
// 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(); }
public override void OnInspectorGUI() { MegaMorph morph = (MegaMorph)target; PushCols(); if ( GUILayout.Button("Import Morph File") ) { LoadMorph(); EditorUtility.SetDirty(target); } // Basic mod stuff showmodparams = EditorGUILayout.Foldout(showmodparams, "Modifier Common Params"); if ( showmodparams ) { morph.ModEnabled = EditorGUILayout.Toggle("Mod Enabled", morph.ModEnabled); morph.DisplayGizmo = EditorGUILayout.Toggle("Display Gizmo", morph.DisplayGizmo); morph.Order = EditorGUILayout.IntField("Order", morph.Order); morph.gizCol1 = EditorGUILayout.ColorField("Giz Col 1", morph.gizCol1); morph.gizCol2 = EditorGUILayout.ColorField("Giz Col 2", morph.gizCol2); } morph.animate = EditorGUILayout.Toggle("Animate", morph.animate); if ( morph.animate ) { morph.animtime = EditorGUILayout.FloatField("AnimTime", morph.animtime); morph.looptime = EditorGUILayout.FloatField("LoopTime", morph.looptime); morph.speed = EditorGUILayout.FloatField("Speed", morph.speed); morph.repeatMode = (MegaRepeatMode)EditorGUILayout.EnumPopup("RepeatMode", morph.repeatMode); } //ImportParams(morph); EditorGUILayout.BeginHorizontal(); PushCols(); if ( morph.mapping == null || morph.mapping.Length == 0 ) GUI.backgroundColor = Color.red; else GUI.backgroundColor = Color.green; if ( GUILayout.Button("Load Mapping") ) LoadBase(morph); PopCols(); if ( GUILayout.Button("Add Channel") ) { if ( morph.chanBank == null ) morph.chanBank = new List<MegaMorphChan>(); MegaMorphChan nc = new MegaMorphChan(); nc.mName = "Empty"; morph.chanBank.Add(nc); //ChannelMapping(morph, nc); // Create 1 to 1 mapping } EditorGUILayout.EndHorizontal(); string bname = "Hide Channels"; if ( !showchannels ) bname = "Show Channels"; if ( GUILayout.Button(bname) ) showchannels = !showchannels; if ( showchannels && morph.chanBank != null ) { for ( int i = 0; i < morph.chanBank.Count; i++ ) { PushCols(); if ( (i & 1) == 0 ) GUI.backgroundColor = ChanCol1; else GUI.backgroundColor = ChanCol2; DisplayChannel(morph, morph.chanBank[i], i); PopCols(); } } extraparams = EditorGUILayout.Foldout(extraparams, "Extra Params"); if ( extraparams ) { ChanCol1 = EditorGUILayout.ColorField("Channel Col 1", ChanCol1); ChanCol2 = EditorGUILayout.ColorField("Channel Col 2", ChanCol2); //int mem = CalcMemoryUsage(morph) / 1024; if ( morph.compressedmem == 0 ) { morph.memuse = CalcMemoryUsage(morph); morph.Compress(); } EditorGUILayout.LabelField("Memory: ", (morph.memuse / 1024) + "KB"); EditorGUILayout.LabelField("Channel Compressed: ", (morph.compressedmem / 1024) + "KB"); } PopCols(); if ( GUI.changed ) EditorUtility.SetDirty(target); }
void SwapTargets(MegaMorphChan chan, int t1, int t2) { if ( t1 >= 0 && t1 < chan.mTargetCache.Count && t2 >= 0 && t2 < chan.mTargetCache.Count && t1 != t2 ) { MegaMorphTarget mt1 = chan.mTargetCache[t1]; MegaMorphTarget mt2 = chan.mTargetCache[t2]; float per = mt1.percent; mt1.percent = mt2.percent; mt2.percent = per; chan.mTargetCache.RemoveAt(t1); chan.mTargetCache.Insert(t2, mt1); EditorUtility.SetDirty(target); } }
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; }
bool AnimCallback(BinaryReader br, string id) { MegaMorphOMatic mr = (MegaMorphOMatic)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 static GameObject DoCopyObjects(GameObject from) { MegaModifyObject fromMod = from.GetComponent<MegaModifyObject>(); GameObject to; if ( fromMod ) { to = CopyMesh(from, fromMod); } else to = CopyMesh(from); //CopyObject.CopyFromTo(from, to); //return to; MegaModifier[] desmods = to.GetComponents<MegaModifier>(); for ( int i = 0; i < desmods.Length; i++ ) { GameObject.DestroyImmediate(desmods[i]); } MegaModifyObject mo = to.GetComponent<MegaModifyObject>(); if ( mo ) { GameObject.DestroyImmediate(mo); mo = to.AddComponent<MegaModifyObject>(); CopyModObj(fromMod, mo); } MegaModifier[] mods = from.GetComponents<MegaModifier>(); //for ( int i = 0; i < mods.Length; i++ ) //{ // CopyComponent(mods[i], to); //} for ( int i = 0; i < mods.Length; i++ ) { Component com = CopyComponent(mods[i], to); Type tp = com.GetType(); if ( tp.IsSubclassOf(typeof(MegaMorphBase)) ) { MegaMorphBase mor = (MegaMorphBase)com; // Need to rebuild the morphchan List<MegaMorphChan> chans = new List<MegaMorphChan>(); for ( int c = 0; c < mor.chanBank.Count; c++ ) { MegaMorphChan chan = new MegaMorphChan(); MegaMorphChan.Copy(mor.chanBank[c], chan); chans.Add(chan); } mor.chanBank = chans; } } if ( mo ) { //mod.ReStart1(false); //for ( int i = 0; i < mods.Length; i++ ) // mods[i].SetModMesh(mod.cachedMesh); mo.MeshUpdated(); } to.name = from.name + " - Copy"; return to; }
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 override void OnInspectorGUI() { MegaMorphOMatic morph = (MegaMorphOMatic)target; PushCols(); if ( GUILayout.Button("Import MorphOMatic File") ) { LoadMorph(); EditorUtility.SetDirty(target); } // Basic mod stuff showmodparams = EditorGUILayout.Foldout(showmodparams, "Modifier Common Params"); if ( showmodparams ) { morph.Label = EditorGUILayout.TextField("Label", morph.Label); morph.MaxLOD = EditorGUILayout.IntField("MaxLOD", morph.MaxLOD); morph.ModEnabled = EditorGUILayout.Toggle("Mod Enabled", morph.ModEnabled); morph.DisplayGizmo = EditorGUILayout.Toggle("Display Gizmo", morph.DisplayGizmo); morph.Order = EditorGUILayout.IntField("Order", morph.Order); morph.gizCol1 = EditorGUILayout.ColorField("Giz Col 1", morph.gizCol1); morph.gizCol2 = EditorGUILayout.ColorField("Giz Col 2", morph.gizCol2); } morph.animate = EditorGUILayout.Toggle("Animate", morph.animate); if ( morph.animate ) { morph.animtime = EditorGUILayout.FloatField("AnimTime", morph.animtime); morph.looptime = EditorGUILayout.FloatField("LoopTime", morph.looptime); morph.speed = EditorGUILayout.FloatField("Speed", morph.speed); morph.repeatMode = (MegaRepeatMode)EditorGUILayout.EnumPopup("RepeatMode", morph.repeatMode); } EditorGUILayout.BeginHorizontal(); PushCols(); if ( morph.mapping == null || morph.mapping.Length == 0 ) GUI.backgroundColor = Color.red; else GUI.backgroundColor = Color.green; PopCols(); if ( GUILayout.Button("Add Channel") ) { if ( morph.chanBank == null ) morph.chanBank = new List<MegaMorphChan>(); MegaMorphChan nc = new MegaMorphChan(); nc.mName = "Empty"; morph.chanBank.Add(nc); } EditorGUILayout.EndHorizontal(); string bname = "Hide Channels"; if ( !showchannels ) bname = "Show Channels"; if ( GUILayout.Button(bname) ) showchannels = !showchannels; #if false if ( showchannels && morph.chanBank != null ) { for ( int i = 0; i < morph.chanBank.Count; i++ ) { PushCols(); if ( (i & 1) == 0 ) GUI.backgroundColor = ChanCol1; else GUI.backgroundColor = ChanCol2; DisplayChannel(morph, morph.chanBank[i]); PopCols(); } } #else morph.limitchandisplay = EditorGUILayout.Toggle("Compact Display", morph.limitchandisplay); if ( showchannels && morph.chanBank != null ) { if ( morph.limitchandisplay ) { morph.startchannel = EditorGUILayout.IntField("Start", morph.startchannel); morph.displaychans = EditorGUILayout.IntField("Display", morph.displaychans); if ( morph.displaychans < 0 ) morph.displaychans = 0; if ( morph.startchannel < 0 ) morph.startchannel = 0; if ( morph.startchannel >= morph.chanBank.Count - 1 ) morph.startchannel = morph.chanBank.Count - 1; int end = morph.startchannel + morph.displaychans; if ( end >= morph.chanBank.Count ) end = morph.chanBank.Count; for ( int i = morph.startchannel; i < end; i++ ) { PushCols(); if ( (i & 1) == 0 ) GUI.backgroundColor = ChanCol1; else GUI.backgroundColor = ChanCol2; DisplayChannel(morph, morph.chanBank[i]); PopCols(); } } else { for ( int i = 0; i < morph.chanBank.Count; i++ ) { PushCols(); if ( (i & 1) == 0 ) GUI.backgroundColor = ChanCol1; else GUI.backgroundColor = ChanCol2; DisplayChannel(morph, morph.chanBank[i]); PopCols(); } } } #endif extraparams = EditorGUILayout.Foldout(extraparams, "Extra Params"); if ( extraparams ) { ChanCol1 = EditorGUILayout.ColorField("Channel Col 1", ChanCol1); ChanCol2 = EditorGUILayout.ColorField("Channel Col 2", ChanCol2); } PopCols(); if ( GUI.changed ) EditorUtility.SetDirty(target); }
static public GameObject DoCopyObjects(GameObject from) { MegaModifyObject fromMod = from.GetComponent <MegaModifyObject>(); GameObject to; if (fromMod) { to = CopyMesh(from, fromMod); } else { to = CopyMesh(from); } //CopyObject.CopyFromTo(from, to); //return to; MegaModifier[] desmods = to.GetComponents <MegaModifier>(); for (int i = 0; i < desmods.Length; i++) { GameObject.DestroyImmediate(desmods[i]); } MegaModifyObject mo = to.GetComponent <MegaModifyObject>(); if (mo) { GameObject.DestroyImmediate(mo); mo = to.AddComponent <MegaModifyObject>(); CopyModObj(fromMod, mo); } MegaModifier[] mods = from.GetComponents <MegaModifier>(); //for ( int i = 0; i < mods.Length; i++ ) //{ // CopyComponent(mods[i], to); //} for (int i = 0; i < mods.Length; i++) { Component com = CopyComponent(mods[i], to); Type tp = com.GetType(); if (tp.IsSubclassOf(typeof(MegaMorphBase))) { MegaMorphBase mor = (MegaMorphBase)com; // Need to rebuild the morphchan List <MegaMorphChan> chans = new List <MegaMorphChan>(); for (int c = 0; c < mor.chanBank.Count; c++) { MegaMorphChan chan = new MegaMorphChan(); MegaMorphChan.Copy(mor.chanBank[c], chan); chans.Add(chan); } mor.chanBank = chans; } } if (mo) { //mod.ReStart1(false); //for ( int i = 0; i < mods.Length; i++ ) // mods[i].SetModMesh(mod.cachedMesh); mo.MeshUpdated(); } to.name = from.name + " - Copy"; return(to); }
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; } }
void SetVerts(MegaMorphChan chan, int j, Vector3[] p) { switch ( j ) { case 0: chan.p1 = p; break; case 1: chan.p2 = p; break; case 2: chan.p3 = p; break; case 3: chan.p4 = p; break; } }
void DisplayChannelLim(MegaMorphRef 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 ( 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); } }
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); } } }
static public GameObject DoCopyObjects(GameObject from) { MegaModifyObject fromMod = from.GetComponent <MegaModifyObject>(); GameObject to; if (fromMod) { to = CopyMesh(from, fromMod); } else { to = CopyMesh(from); } //CopyObject.CopyFromTo(from, to); //return to; //MegaModifier[] desmods = to.GetComponents<MegaModifier>(); //for ( int i = 0; i < desmods.Length; i++ ) //{ // GameObject.DestroyImmediate(desmods[i]); //} //MegaModifyObject mo = to.GetComponent<MegaModifyObject>(); //if ( mo ) //{ //GameObject.DestroyImmediate(mo); MegaModifyObject mo = to.AddComponent <MegaModifyObject>(); CopyModObj(fromMod, mo); //} MegaModifier[] mods = from.GetComponents <MegaModifier>(); for (int i = 0; i < mods.Length; i++) { Component com = CopyComponent(mods[i], to); //Type tp = com.GetType(); #if false if (tp.IsSubclassOf(typeof(MegaMorphBase))) { MegaMorphBase mor = (MegaMorphBase)com; // Need to rebuild the morphchan List <MegaMorphChan> chans = new List <MegaMorphChan>(); for (int c = 0; c < mor.chanBank.Count; c++) { MegaMorphChan chan = new MegaMorphChan(); MegaMorphChan.Copy(mor.chanBank[c], chan); chans.Add(chan); } mor.chanBank = chans; } #endif #if false if (tp.IsSubclassOf(typeof(MegaFFD))) { MegaFFD ffd = (MegaFFD)com; MegaFFD srcffd = (MegaFFD)mods[i]; ffd.pt = new Vector3[64]; for (int c = 0; c < 64; c++) { ffd.pt[c] = srcffd.pt[c]; } } #endif // TODO: Add method to modifiers so can deal with any special cases if (com) { MegaModifier mod = (MegaModifier)com; mod.PostCopy(mods[i]); } } if (mo) { //mod.ReStart1(false); //for ( int i = 0; i < mods.Length; i++ ) // mods[i].SetModMesh(mod.cachedMesh); mo.MeshUpdated(); } to.name = from.name + " - Copy"; return(to); }
public override void OnInspectorGUI() { undoManager.CheckUndo(); MegaMorph morph = (MegaMorph)target; PushCols(); if ( GUILayout.Button("Import Morph File") ) { LoadMorph(); EditorUtility.SetDirty(target); } // Basic mod stuff showmodparams = EditorGUILayout.Foldout(showmodparams, "Modifier Common Params"); if ( showmodparams ) { morph.ModEnabled = EditorGUILayout.Toggle("Mod Enabled", morph.ModEnabled); morph.DisplayGizmo = EditorGUILayout.Toggle("Display Gizmo", morph.DisplayGizmo); morph.Order = EditorGUILayout.IntField("Order", morph.Order); morph.gizCol1 = EditorGUILayout.ColorField("Giz Col 1", morph.gizCol1); morph.gizCol2 = EditorGUILayout.ColorField("Giz Col 2", morph.gizCol2); } // Advanced showadvanced = EditorGUILayout.Foldout(showadvanced, "Advanced Params"); if ( showadvanced ) { if ( morph.oPoints != null ) { morph.showmapping = EditorGUILayout.BeginToggleGroup("Show Mapping", morph.showmapping); morph.mapStart = EditorGUILayout.IntSlider("StartVert", morph.mapStart, 0, morph.oPoints.Length); morph.mapEnd = EditorGUILayout.IntSlider("endVert", morph.mapEnd, 0, morph.oPoints.Length); morph.mappingSize = EditorGUILayout.Slider("Size", morph.mappingSize, 0.0005f, 0.01f); EditorGUILayout.EndToggleGroup(); } morph.tolerance = EditorGUILayout.Slider("Tolerance", morph.tolerance, 0.0f, 0.01f); } morph.UseLimit = EditorGUILayout.BeginToggleGroup("Use Limits", morph.UseLimit); morph.Min = EditorGUILayout.FloatField("Min", morph.Min); morph.Max = EditorGUILayout.FloatField("Max", morph.Max); EditorGUILayout.EndToggleGroup(); morph.animate = EditorGUILayout.Toggle("Animate", morph.animate); if ( morph.animate ) { morph.animtime = EditorGUILayout.FloatField("AnimTime", morph.animtime); morph.looptime = EditorGUILayout.FloatField("LoopTime", morph.looptime); morph.speed = EditorGUILayout.FloatField("Speed", morph.speed); morph.repeatMode = (MegaRepeatMode)EditorGUILayout.EnumPopup("RepeatMode", morph.repeatMode); } //ImportParams(morph); EditorGUILayout.BeginHorizontal(); PushCols(); if ( morph.mapping == null || morph.mapping.Length == 0 ) GUI.backgroundColor = Color.red; else GUI.backgroundColor = Color.green; if ( GUILayout.Button("Load Mapping") ) LoadBase(morph); PopCols(); if ( GUILayout.Button("Add Channel") ) { if ( morph.chanBank == null ) morph.chanBank = new List<MegaMorphChan>(); MegaMorphChan nc = new MegaMorphChan(); nc.mName = "Empty"; morph.chanBank.Add(nc); //ChannelMapping(morph, nc); // Create 1 to 1 mapping } EditorGUILayout.EndHorizontal(); string bname = "Hide Channels"; if ( !showchannels ) bname = "Show Channels"; if ( GUILayout.Button(bname) ) showchannels = !showchannels; morph.limitchandisplay = EditorGUILayout.Toggle("Compact Display", morph.limitchandisplay); if ( showchannels && morph.chanBank != null ) { if ( morph.limitchandisplay ) { morph.startchannel = EditorGUILayout.IntField("Start", morph.startchannel); morph.displaychans = EditorGUILayout.IntField("Display", morph.displaychans); if ( morph.displaychans < 0 ) morph.displaychans = 0; if ( morph.startchannel < 0 ) morph.startchannel = 0; if ( morph.startchannel >= morph.chanBank.Count - 1 ) morph.startchannel = morph.chanBank.Count - 1; int end = morph.startchannel + morph.displaychans; if ( end >= morph.chanBank.Count ) end = morph.chanBank.Count; for ( int i = morph.startchannel; i < end; i++ ) { PushCols(); if ( (i & 1) == 0 ) GUI.backgroundColor = ChanCol1; else GUI.backgroundColor = ChanCol2; DisplayChannel(morph, morph.chanBank[i], i); PopCols(); } } else { for ( int i = 0; i < morph.chanBank.Count; i++ ) { PushCols(); if ( (i & 1) == 0 ) GUI.backgroundColor = ChanCol1; else GUI.backgroundColor = ChanCol2; DisplayChannel(morph, morph.chanBank[i], i); PopCols(); } } } extraparams = EditorGUILayout.Foldout(extraparams, "Extra Params"); if ( extraparams ) { ChanCol1 = EditorGUILayout.ColorField("Channel Col 1", ChanCol1); ChanCol2 = EditorGUILayout.ColorField("Channel Col 2", ChanCol2); //int mem = CalcMemoryUsage(morph) / 1024; if ( morph.compressedmem == 0 ) { morph.memuse = CalcMemoryUsage(morph); morph.Compress(); } EditorGUILayout.LabelField("Memory: ", (morph.memuse / 1024) + "KB"); EditorGUILayout.LabelField("Channel Compressed: ", (morph.compressedmem / 1024) + "KB"); } PopCols(); if ( GUI.changed ) EditorUtility.SetDirty(target); undoManager.CheckDirty(); }