public void DisplayGUI() { MegaWalkLoft walk = (MegaWalkLoft)target; walk.mode = (MegaWalkMode)EditorGUILayout.EnumPopup("Mode", walk.mode); if (walk.mode == MegaWalkMode.Alpha) { walk.alpha = EditorGUILayout.Slider("Alpha", walk.alpha, 0.0f, 1.0f); } else { walk.distance = EditorGUILayout.FloatField("Distance", walk.distance); } walk.crossalpha = EditorGUILayout.Slider("Cross Alpha", walk.crossalpha, 0.0f, 1.0f); walk.surfaceLoft = (MegaShapeLoft)EditorGUILayout.ObjectField("Surface", walk.surfaceLoft, typeof(MegaShapeLoft), true); int surfaceLayer = MegaShapeUtils.FindLayer(walk.surfaceLoft, walk.surfaceLayer); surfaceLayer = EditorGUILayout.Popup("Layer", surfaceLayer + 1, MegaShapeUtils.GetLayers(walk.surfaceLoft)) - 1; if (walk.surfaceLoft) { for (int i = 0; i < walk.surfaceLoft.Layers.Length; i++) { //if ( walk.surfaceLoft.Layers[i].GetType() == typeof(MegaLoftLayerSimple) ) if (walk.surfaceLoft.Layers[i] is MegaLoftLayerSimple) { if (surfaceLayer == 0) { walk.surfaceLayer = i; break; } surfaceLayer--; } } } else { walk.surfaceLayer = surfaceLayer; } walk.upright = EditorGUILayout.Slider("Upright", walk.upright, 0.0f, 1.0f); walk.uprot = EditorGUILayout.Vector3Field("up Rotate", walk.uprot); walk.delay = EditorGUILayout.FloatField("Delay", walk.delay); walk.offset = EditorGUILayout.FloatField("Offset", walk.offset); walk.tangent = EditorGUILayout.FloatField("Tangent", walk.tangent); walk.rotate = EditorGUILayout.Vector3Field("Rotate", walk.rotate); walk.lateupdate = EditorGUILayout.Toggle("Late Update", walk.lateupdate); walk.animate = EditorGUILayout.BeginToggleGroup("Animate", walk.animate); walk.speed = EditorGUILayout.FloatField("Speed", walk.speed); EditorGUILayout.EndToggleGroup(); }
public override int BuildMesh(MegaShapeLoft loft, int triindex) { trisstart = triindex; if (Lock) { return(triindex + ((crosses - 2) * (evert - svert))); } if (layerPath == null || layerSection == null) { return(triindex); } MegaSpline pathspline = layerPath.splines[curve]; MegaSpline sectionspline = layerSection.splines[crosscurve]; // so for each loft section run through int vi = 0; Vector2 uv = Vector2.zero; Vector3 p = Vector3.zero; Vector3 scl = Vector3.one; float scalemultx = 1.0f; float scalemulty = 1.0f; Vector3 cmax = crossmax; cmax.x = 0.0f; cmax.z = 0.0f; Vector3 cmin = crossmin; cmin.x = 0.0f; cmin.z = 0.0f; Vector3 totaloff = Vector3.zero; float uvstart = pathStart; if (UVOrigin == MegaLoftUVOrigin.SplineStart) { uvstart = 0.0f; } Matrix4x4 twisttm = Matrix4x4.identity; Color col1 = color; Matrix4x4 tm; Vector3 lastup = loft.up; float calpha = 0.0f; for (int cr = 0; cr < crosses; cr++) { float a = ((float)cr / (float)(crosses - 1)); float alpha = pathStart + (pathLength * a); totaloff = offset; if (useOffsetX) { totaloff.x += offsetCrvX.Evaluate(alpha); } if (useOffsetY) { totaloff.y += offsetCrvY.Evaluate(alpha); } if (useOffsetZ) { totaloff.z += offsetCrvZ.Evaluate(alpha); } // get the point on the spline if (frameMethod == MegaFrameMethod.New) { tm = loft.GetDeformMatNewMethod(pathspline, alpha, true, alignCross, ref lastup); } else { tm = loft.GetDeformMatNew(pathspline, alpha, true, alignCross); } if (useTwistCrv) { float twist = twistCrv.Evaluate(alpha) * twistAmt; float tw1 = pathspline.GetTwist(alpha); MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * (twist - tw1)); tm = tm * twisttm; } if (useCrossScaleCrv) { float sa = Mathf.Repeat(a + scaleoff, 1.0f); scalemultx = crossScaleCrv.Evaluate(sa); } if (!sepscale) { scalemulty = scalemultx; } else { if (useCrossScaleCrvY) { float sa = Mathf.Repeat(a + scaleoffY, 1.0f); scalemulty = crossScaleCrvY.Evaluate(sa); } } scl.x = crossScale.x * scalemultx; // Use plus here and have curve as 0010 scl.y = crossScale.y * scalemulty; Vector3 crrot = cmax; crrot.y *= scl.y; Vector3 cminrot = cmin; cminrot.y *= scl.y; // Now need to loop through all the meshsections for (int m = 0; m < meshsections.Count; m++) { MegaMeshSection ms = meshsections[m]; MegaMaterialSection mats = sections[ms.mat]; if (mats.Enabled) { if (loft.useColors) { if (mats.colmode == MegaLoftColMode.Loft) { calpha = a; } else { calpha = alpha; } calpha = Mathf.Repeat(calpha + mats.coloffset, 1.0f); col1.r = mats.colR.Evaluate(calpha); col1.g = mats.colG.Evaluate(calpha); col1.b = mats.colB.Evaluate(calpha); col1.a = mats.colA.Evaluate(calpha); } for (int v = 0; v < ms.cverts.Count; v++) { p.x = ms.cverts[v].x * scl.x; p.y = ms.cverts[v].y * scl.y; // Curve for this value p.z = ms.cverts[v].z * scl.z; p = tm.MultiplyPoint3x4(p); uv.x = alpha - uvstart; //pathStart; uv.y = ms.cuvs[v].y; // - crossStart; // again not sure here start; if (mats.physuv) { uv.x *= pathspline.length; uv.y *= sectionspline.length; } else { if (mats.uvcalcy) { //uv.x = ((a * LoftLength) / sectionspline.length) - uvstart; uv.x = ((alpha * pathspline.length) / sectionspline.length) - uvstart; } } if (conform) { ms.verts1.Add(p + totaloff); } else { ms.verts.Add(p + totaloff); } if (mats.swapuv) { float ux = uv.x; uv.x = uv.y; uv.y = ux; } uv.x *= mats.UVScale.x; uv.y *= mats.UVScale.y; uv.x += mats.UVOffset.x; uv.y += mats.UVOffset.y; ms.uvs.Add(uv); //[vi] = uv; if (loft.useColors) { ms.cols.Add(col1); } vi++; } } } } //OptmizeMesh(); // Faces int index = triindex; int fi = 0; // Calc this if (enabled) { if (flip) { for (int m = 0; m < meshsections.Count; m++) { MegaMeshSection ms = meshsections[m]; MegaMaterialSection mats = sections[ms.mat]; if (mats.Enabled) { for (int cr = 0; cr < crosses - 1; cr++) { for (int f = 0; f < ms.cverts.Count - 1; f++) { ms.tris.Add(index + f); ms.tris.Add(index + f + 1); ms.tris.Add(index + f + 1 + ms.cverts.Count); ms.tris.Add(index + f); ms.tris.Add(index + f + 1 + ms.cverts.Count); ms.tris.Add(index + f + ms.cverts.Count); fi += 6; } index += ms.cverts.Count; } index += ms.cverts.Count; } } } else { for (int m = 0; m < meshsections.Count; m++) { MegaMeshSection ms = meshsections[m]; MegaMaterialSection mats = sections[ms.mat]; if (mats.Enabled) { for (int cr = 0; cr < crosses - 1; cr++) { for (int f = 0; f < ms.cverts.Count - 1; f++) { ms.tris.Add(index + f + 1 + ms.cverts.Count); ms.tris.Add(index + f + 1); ms.tris.Add(index + f); ms.tris.Add(index + f + ms.cverts.Count); ms.tris.Add(index + f + 1 + ms.cverts.Count); ms.tris.Add(index + f); fi += 6; } index += ms.cverts.Count; } index += ms.cverts.Count; } } } } if (conform) { CalcBounds(); DoConform(loft); } return(triindex + fi); //triindex; }
public override Vector3 SampleSplines(MegaShapeLoft loft, float ca, float pa) { Vector3 p = Vector3.zero; float lerp = 0.0f; Matrix4x4 pathtm = Matrix4x4.identity; //if ( SnapToPath ) //pathtm = layerPath.transform.localToWorldMatrix; Matrix4x4 twisttm = Matrix4x4.identity; //Vector3 sclc = Vector2.one; Matrix4x4 tm; float offx = 0.0f; float offy = 0.0f; float offz = 0.0f; //bool clsd = layerPath.splines[curve].closed; Vector3 lastup = locup; float alpha = pa; //(float)pi / (float)PathSteps; float pathalpha = pathStart + (pathLength * alpha); //if ( clsd ) //pathalpha = Mathf.Repeat(pathalpha, 1.0f); //if ( useScaleXCrv ) //sclc.x = scaleCrvX.Evaluate(pathalpha); //if ( useScaleYCrv ) //sclc.y = scaleCrvY.Evaluate(pathalpha); if (useTwistCrv) { float twist = twistCrv.Evaluate(pathalpha); float tw1 = layerPath.splines[curve].GetTwist(pathalpha); MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * (twist - tw1)); if (frameMethod == MegaFrameMethod.Old) { tm = pathtm * GetDeformMat(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp) * twisttm; } else { tm = pathtm * GetDeformMatNewMethod(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp, ref lastup) * twisttm; } } else { if (frameMethod == MegaFrameMethod.Old) { tm = pathtm * GetDeformMat(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp); } else { tm = pathtm * GetDeformMatNewMethod(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp, ref lastup); } } // Need to get the crosssection for the given alpha and the lerp value int csect = GetSection(pathalpha, out lerp); lerp = ease.easing(0.0f, 1.0f, lerp); Vector3 off = Vector3.zero; if (loftsections[csect].snap) { off = loftsections[0].shape.splines[loftsections[0].curve].knots[0].p - loftsections[csect].shape.splines[loftsections[csect].curve].knots[0].p; } else { off = Vector3.zero; } Vector3 crossp1 = GetCross(csect, ca, off); if (loftsections[csect + 1].snap) { off = loftsections[0].shape.splines[loftsections[0].curve].knots[0].p - loftsections[csect + 1].shape.splines[loftsections[csect + 1].curve].knots[0].p; } else { off = Vector3.zero; } Vector3 crossp2 = GetCross(csect + 1, ca, off); if (useOffsetX) { offx = offsetCrvX.Evaluate(pathalpha); } if (useOffsetY) { offy = offsetCrvY.Evaluate(pathalpha); } if (useOffsetZ) { offz = offsetCrvZ.Evaluate(pathalpha); } //float size = 1.0f / layerPath.splines[0].length; p = Vector3.Lerp(crossp1, crossp2, lerp); //if ( useScaleXCrv ) //p.x *= sclc.x; //if ( useScaleYCrv ) //p.y *= sclc.y; p.x += offx; p.y += offy; p.z += offz; p = tm.MultiplyPoint3x4(p); p += offset; return(p); }
public override int BuildMesh(MegaShapeLoft loft, int triindex) { if (Lock) { return(triindex); } if (layerPath == null || layerPath.splines == null || layerPath.splines.Count == 0) { return(triindex); } if (loftsections.Count < 2) //== 0 ) { return(triindex); } Vector2 uv = Vector2.zero; Vector3 p = Vector3.zero; //int wc = 1; //ActualCrossVerts; float lerp = 0.0f; Matrix4x4 pathtm = Matrix4x4.identity; //if ( SnapToPath ) // pathtm = layerPath.transform.localToWorldMatrix; Matrix4x4 twisttm = Matrix4x4.identity; //Vector3 sclc = Vector2.one; Matrix4x4 tm; float offx = 0.0f; float offy = 0.0f; float offz = 0.0f; MegaSpline pathspline = layerPath.splines[curve]; //bool clsd = layerPath.splines[curve].closed; float uvstart = pathStart; if (UVOrigin == MegaLoftUVOrigin.SplineStart) { uvstart = 0.0f; } Vector3 lastup = locup; Color col1 = color; float calpha = 0.0f; //float uvalpha = 0.0f; for (int pi = 0; pi < crosses; pi++) { float alpha = (float)pi / (float)(crosses - 1); //PathSteps; float pathalpha = pathStart + (pathLength * alpha); //uvalpha = pathalpha; //if ( clsd ) // pathalpha = Mathf.Repeat(pathalpha, 1.0f); //if ( useScaleXCrv ) // sclc.x = scaleCrvX.Evaluate(pathalpha); //if ( useScaleYCrv ) // sclc.y = scaleCrvY.Evaluate(pathalpha); if (useTwistCrv) { float twist = twistCrv.Evaluate(pathalpha); float tw1 = layerPath.splines[curve].GetTwist(pathalpha); MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * (twist - tw1)); if (frameMethod == MegaFrameMethod.Old) { tm = pathtm * GetDeformMat(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp) * twisttm; } else { tm = pathtm * GetDeformMatNewMethod(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp, ref lastup) * twisttm; } } else { if (frameMethod == MegaFrameMethod.Old) { tm = pathtm * GetDeformMat(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp); } else { tm = pathtm * GetDeformMatNewMethod(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp, ref lastup); } } // Need to get the crosssection for the given alpha and the lerp value int csect = GetSection(pathalpha, out lerp); lerp = ease.easing(0.0f, 1.0f, lerp); MegaLoftSection cs1 = loftsections[csect]; MegaLoftSection cs2 = loftsections[csect + 1]; //MegaSpline sectionspline = cs1.shape.splines[cs1.curve]; if (useOffsetX) { offx = offsetCrvX.Evaluate(pathalpha); } if (useOffsetY) { offy = offsetCrvY.Evaluate(pathalpha); } if (useOffsetZ) { offz = offsetCrvZ.Evaluate(pathalpha); } for (int i = 0; i < cs1.meshsections.Count; i++) { MegaMeshSection ms0 = loftsections[0].meshsections[i]; //float slen = sectionspline.knots[ms0.lastknot].length - sectionspline.knots[ms0.firstknot].length; MegaMaterialSection mats = sections[ms0.mat]; if (mats.Enabled) { MegaMeshSection ms1 = cs1.meshsections[i]; MegaMeshSection ms2 = cs2.meshsections[i]; if (loft.useColors) { if (mats.colmode == MegaLoftColMode.Loft) { calpha = alpha; } else { calpha = pathalpha; } calpha = Mathf.Repeat(calpha + mats.coloffset, 1.0f); col1.r = mats.colR.Evaluate(calpha); col1.g = mats.colG.Evaluate(calpha); col1.b = mats.colB.Evaluate(calpha); col1.a = mats.colA.Evaluate(calpha); } for (int v = 0; v < ms1.cverts.Count; v++) { p = Vector3.Lerp(ms1.cverts[v], ms2.cverts[v], lerp); // Easing here? //if ( useScaleXCrv ) // p.x *= sclc.x; //if ( useScaleYCrv ) // p.y *= sclc.y; p.x += offx; p.y += offy; p.z += offz; p = tm.MultiplyPoint3x4(p); p += offset; //int ix = (pi * wc) + v; if (conform) { ms0.verts1.Add(p); } else { ms0.verts.Add(p); } uv.y = Mathf.Lerp(ms1.cuvs[v].y, ms2.cuvs[v].y, lerp); uv.x = alpha - uvstart; //pathStart; //uv.y = ms.cuvs[v].y; // - crossStart; // again not sure here start; if (mats.physuv) { uv.x *= pathspline.length; uv.y *= ms0.len; //sectionspline.length; } else { if (mats.uvcalcy) { //uv.x = ((alpha * LoftLength) / sectionspline.length) - uvstart; uv.x = ((alpha * pathspline.length) / ms0.len) - uvstart; } } if (mats.swapuv) { float ux = uv.x; uv.x = uv.y; uv.y = ux; } uv.x *= mats.UVScale.x; uv.y *= mats.UVScale.y; uv.x += mats.UVOffset.x; uv.y += mats.UVOffset.y; ms0.uvs.Add(uv); //[vi] = uv; if (loft.useColors) { ms0.cols.Add(col1); } #if false uv.y = uvstart + alpha; uv.x *= UVScale.x; uv.y *= UVScale.y; uv.x += UVOffset.x; uv.y += UVOffset.y; #endif //ms0.uvs.Add(uv); } } } } int index = triindex; int fi = 0; // Calc this if (enabled) { if (flip) { for (int m = 0; m < loftsections[0].meshsections.Count; m++) { MegaMeshSection ms = loftsections[0].meshsections[m]; MegaMaterialSection mats = sections[ms.mat]; if (mats.Enabled) { for (int cr = 0; cr < crosses - 1; cr++) { for (int f = 0; f < ms.cverts.Count - 1; f++) { ms.tris.Add(index + f); ms.tris.Add(index + f + 1); ms.tris.Add(index + f + 1 + ms.cverts.Count); ms.tris.Add(index + f); ms.tris.Add(index + f + 1 + ms.cverts.Count); ms.tris.Add(index + f + ms.cverts.Count); fi += 6; } index += ms.cverts.Count; } index += ms.cverts.Count; } } } else { for (int m = 0; m < loftsections[0].meshsections.Count; m++) { MegaMeshSection ms = loftsections[0].meshsections[m]; MegaMaterialSection mats = sections[ms.mat]; if (mats.Enabled) { for (int cr = 0; cr < crosses - 1; cr++) { for (int f = 0; f < ms.cverts.Count - 1; f++) { ms.tris.Add(index + f + 1 + ms.cverts.Count); ms.tris.Add(index + f + 1); ms.tris.Add(index + f); ms.tris.Add(index + f + ms.cverts.Count); ms.tris.Add(index + f + 1 + ms.cverts.Count); ms.tris.Add(index + f); fi += 6; } index += ms.cverts.Count; } index += ms.cverts.Count; } } } } if (conform) { CalcBounds(); DoConform(loft); } return(triindex + fi); //triindex; }
public void DisplayGUI() { MegaLoftLayerCloneRules layer = (MegaLoftLayerCloneRules)target; MegaShapeLoftEditor.PushCols(); GUI.color = Color.white; GUI.backgroundColor = layer.paramcol; GUI.contentColor = Color.white; EditorGUILayout.BeginVertical("TextArea"); //MegaShapeLoft loft = layer.GetComponent<MegaShapeLoft>(); SetLimits(layer.gameObject); layer.LayerName = EditorGUILayout.TextField(MegaToolTip.LayerName, layer.LayerName); layer.LayerEnabled = EditorGUILayout.Toggle(MegaToolTip.Enabled, layer.LayerEnabled); layer.paramcol = EditorGUILayout.ColorField(MegaToolTip.ParamCol, layer.paramcol); if (layer.LayerEnabled) { layer.Lock = EditorGUILayout.Toggle("Lock", layer.Lock); if (!layer.Lock) { layer.surfaceLoft = (MegaShapeLoft)EditorGUILayout.ObjectField("Surface", layer.surfaceLoft, typeof(MegaShapeLoft), true); //layer.surfaceLayer = EditorGUILayout.Popup("Layer", layer.surfaceLayer + 1, MegaShapeUtils.GetLayers(layer.surfaceLoft)) - 1; int surfaceLayer = MegaShapeUtils.FindLayer(layer.surfaceLoft, layer.surfaceLayer); surfaceLayer = EditorGUILayout.Popup("Layer", surfaceLayer + 1, MegaShapeUtils.GetLayers(layer.surfaceLoft)) - 1; if (layer.surfaceLoft) { for (int i = 0; i < layer.surfaceLoft.Layers.Length; i++) { //if ( layer.surfaceLoft.Layers[i].GetType() == typeof(MegaLoftLayerSimple) ) if (layer.surfaceLoft.Layers[i] is MegaLoftLayerSimple) { if (surfaceLayer == 0) { layer.surfaceLayer = i; break; } surfaceLayer--; } } } else { layer.surfaceLayer = surfaceLayer; } layer.start = EditorGUILayout.Slider(MegaToolTip.Start, layer.start, sl, sh); layer.Length = EditorGUILayout.Slider(MegaToolTip.Length, layer.Length, ll, lh); layer.CrossAlpha = EditorGUILayout.Slider("Cross Alpha", layer.CrossAlpha, csl, csh); layer.CalcUp = EditorGUILayout.Toggle("Calc Up", layer.CalcUp); if (layer.CalcUp) { layer.calcUpAmount = EditorGUILayout.Slider("Up Amount", layer.calcUpAmount, 0.0f, 1.0f); } layer.Seed = EditorGUILayout.IntField("Seed", layer.Seed); layer.tmrot = EditorGUILayout.Vector3Field("TMRotate", layer.tmrot); layer.scale = EditorGUILayout.Vector3Field("Scale", layer.scale); layer.tangent = EditorGUILayout.FloatField("Tangent", layer.tangent); layer.axis = (MegaAxis)EditorGUILayout.EnumPopup("Axis", layer.axis); layer.useTwistCrv = EditorGUILayout.BeginToggleGroup(MegaToolTip.UseTwist, layer.useTwistCrv); layer.twist = EditorGUILayout.FloatField("Twist", layer.twist); layer.twistCrv = EditorGUILayout.CurveField("Twist Crv", layer.twistCrv); EditorGUILayout.EndToggleGroup(); // Advanced layer.RemoveDof = EditorGUILayout.FloatField("UpRight", layer.RemoveDof); layer.GlobalScale = EditorGUILayout.FloatField("Global Scale", layer.GlobalScale); layer.useCrossCrv = EditorGUILayout.BeginToggleGroup("Use Cross Crv", layer.useCrossCrv); layer.CrossCrv = EditorGUILayout.CurveField("Cross Crv", layer.CrossCrv); EditorGUILayout.EndToggleGroup(); if (GUILayout.Button("Add Rule")) { MegaLoftRule newrule = new MegaLoftRule(); layer.rules.Add(newrule); GUI.changed = true; } //layer.showmainparams = EditorGUILayout.Foldout(layer.showmainparams, "Rules"); layer.showmainparams = MegaFoldOut.Start("Rules", layer.showmainparams, new Color(0.5f, 0.5f, 1.0f)); if (layer.showmainparams) { for (int i = 0; i < layer.rules.Count; i++) { DisplayRuleGUI(layer.rules[i]); if (GUILayout.Button("Delete Rule")) { layer.rules.RemoveAt(i); i--; GUI.changed = true; } } } MegaFoldOut.End(layer.showmainparams); } //EditorGUILayout.EndVertical(); //MegaShapeLoftEditor.PopCols(); } EditorGUILayout.EndVertical(); MegaShapeLoftEditor.PopCols(); }
public void DisplayGUI() { MegaLoftLayerScatter layer = (MegaLoftLayerScatter)target; MegaShapeLoftEditor.PushCols(); GUI.color = Color.white; GUI.backgroundColor = layer.paramcol; GUI.contentColor = Color.white; EditorGUILayout.BeginVertical("TextArea"); SetLimits(layer.gameObject); //MegaShapeLoft loft = layer.GetComponent<MegaShapeLoft>(); layer.LayerName = EditorGUILayout.TextField(MegaToolTip.LayerName, layer.LayerName); layer.LayerEnabled = EditorGUILayout.Toggle(MegaToolTip.Enabled, layer.LayerEnabled); layer.paramcol = EditorGUILayout.ColorField(MegaToolTip.ParamCol, layer.paramcol); if (layer.LayerEnabled) { layer.Lock = EditorGUILayout.Toggle(MegaToolTip.Lock, layer.Lock); if (!layer.Lock) { layer.mainObj = (GameObject)EditorGUILayout.ObjectField("Scatter Mesh", layer.mainObj, typeof(GameObject), true); layer.surfaceLoft = (MegaShapeLoft)EditorGUILayout.ObjectField(MegaToolTip.Surface, layer.surfaceLoft, typeof(MegaShapeLoft), true); //layer.surfaceLayer = EditorGUILayout.Popup("Layer", layer.surfaceLayer + 1, MegaShapeUtils.GetLayers(layer.surfaceLoft)) - 1; int surfaceLayer = MegaShapeUtils.FindLayer(layer.surfaceLoft, layer.surfaceLayer); surfaceLayer = EditorGUILayout.Popup("Layer", surfaceLayer + 1, MegaShapeUtils.GetLayers(layer.surfaceLoft)) - 1; if (layer.surfaceLoft) { for (int i = 0; i < layer.surfaceLoft.Layers.Length; i++) { //if ( layer.surfaceLoft.Layers[i].GetType() == typeof(MegaLoftLayerSimple) ) if (layer.surfaceLoft.Layers[i] is MegaLoftLayerSimple) { if (surfaceLayer == 0) { layer.surfaceLayer = i; break; } surfaceLayer--; } } } else { layer.surfaceLayer = surfaceLayer; } layer.start = EditorGUILayout.Slider(MegaToolTip.StartSurface, layer.start, sl, sh); layer.length = EditorGUILayout.Slider(MegaToolTip.LengthSurface, layer.length, ll, lh); layer.cstart = EditorGUILayout.Slider(MegaToolTip.CrossStartSurface, layer.cstart, csl, csh); layer.clength = EditorGUILayout.Slider(MegaToolTip.CrossLengthSurface, layer.clength, cll, clh); layer.CalcUp = EditorGUILayout.Toggle("Calc Up", layer.CalcUp); layer.RemoveDof = EditorGUILayout.FloatField("UpRight", layer.RemoveDof); layer.Count = EditorGUILayout.IntField("Count", layer.Count); layer.Seed = EditorGUILayout.IntField("Seed", layer.Seed); layer.Offset = EditorGUILayout.Vector3Field("Offset", layer.Offset); layer.rot = EditorGUILayout.Vector3Field("Rotate", layer.rot); layer.scale = EditorGUILayout.Vector3Field("Scale", layer.scale); layer.rotRange = EditorGUILayout.Vector3Field("Rand Rotate", layer.rotRange); layer.scaleRangeMin = EditorGUILayout.Vector3Field("Rnd Scale Min", layer.scaleRangeMin); layer.scaleRangeMax = EditorGUILayout.Vector3Field("Rnd Scale Max", layer.scaleRangeMax); layer.tangent = EditorGUILayout.FloatField("Tangent", layer.tangent); layer.axis = (MegaAxis)EditorGUILayout.EnumPopup("Axis", layer.axis); // Advanced layer.GlobalScale = EditorGUILayout.FloatField("Scale", layer.GlobalScale); // Start Info EditorGUILayout.BeginVertical("TextArea"); layer.Alpha = EditorGUILayout.Slider("Alpha", layer.Alpha, 0.0f, 1.0f); layer.CAlpha = EditorGUILayout.Slider("Cross Alpha", layer.CAlpha, 0.0f, 1.0f); layer.Speed = EditorGUILayout.FloatField("Speed", layer.Speed); layer.useDensity = EditorGUILayout.BeginToggleGroup("Use Density", layer.useDensity); layer.density = EditorGUILayout.CurveField("Density", layer.density, Color.green, new Rect(0.0f, 0.0f, 1.0f, 1.0f)); EditorGUILayout.EndToggleGroup(); EditorGUILayout.EndVertical(); } //EditorGUILayout.EndVertical(); //MegaShapeLoftEditor.PopCols(); } EditorGUILayout.EndVertical(); MegaShapeLoftEditor.PopCols(); }
void OnGUI() { if (Selection.activeGameObject == null) { return; } MegaShapeLoft loft = Selection.activeGameObject.GetComponent <MegaShapeLoft>(); if (loft == null) { return; } lofttype = (MegaLoftType)EditorGUILayout.EnumPopup("Type", lofttype); LayerName = EditorGUILayout.TextField("Name", LayerName); start = EditorGUILayout.FloatField("Start", start); length = EditorGUILayout.FloatField("Length", length); paramCol = EditorGUILayout.ColorField("Param Col", paramCol); EditorStyles.textField.wordWrap = true; switch (lofttype) { case MegaLoftType.Simple: EditorGUILayout.TextArea("Basic Loft layer that uses a single spline for the path and another spline for the cross section", GUILayout.Height(50.0f)); path = (MegaShape)EditorGUILayout.ObjectField("Path", path, typeof(MegaShape), true); section = (MegaShape)EditorGUILayout.ObjectField("Section", section, typeof(MegaShape), true); material = (Material)EditorGUILayout.ObjectField("Material", material, typeof(Material), true); break; //case MegaLoftType.Collider: // colliderwidth = EditorGUILayout.FloatField("Collider Width", colliderwidth); // break; case MegaLoftType.CloneSimple: EditorGUILayout.TextArea("Clone a mesh onto a surface with options for start, end and main meshes", GUILayout.Height(50.0f)); startObjMesh = (Mesh)EditorGUILayout.ObjectField("Start Obj", startObjMesh, typeof(Mesh), true); mainObjMesh = (Mesh)EditorGUILayout.ObjectField("Main Obj", mainObjMesh, typeof(Mesh), true); endObjMesh = (Mesh)EditorGUILayout.ObjectField("End Obj", endObjMesh, typeof(Mesh), true); surfaceLoft = (MegaShapeLoft)EditorGUILayout.ObjectField("Surface", surfaceLoft, typeof(MegaShapeLoft), true); surfaceLayer = EditorGUILayout.Popup("Layer", surfaceLayer + 1, MegaShapeUtils.GetLayers(surfaceLoft)) - 1; material = (Material)EditorGUILayout.ObjectField("Material", material, typeof(Material), true); break; case MegaLoftType.ScatterSimple: EditorGUILayout.TextArea("Scatters a choosen mesh and material over a surface", GUILayout.Height(50.0f)); mainObjMesh = (Mesh)EditorGUILayout.ObjectField("Obj", mainObjMesh, typeof(Mesh), true); surfaceLoft = (MegaShapeLoft)EditorGUILayout.ObjectField("Surface", surfaceLoft, typeof(MegaShapeLoft), true); surfaceLayer = EditorGUILayout.Popup("Layer", surfaceLayer + 1, MegaShapeUtils.GetLayers(surfaceLoft)) - 1; material = (Material)EditorGUILayout.ObjectField("Material", material, typeof(Material), true); break; case MegaLoftType.Scatter: EditorGUILayout.TextArea("Builds a mesh layer by scattering a choosen object over a surface", GUILayout.Height(50.0f)); mainObj = (GameObject)EditorGUILayout.ObjectField("Obj", mainObj, typeof(Mesh), true); mainObj = MegaMeshCheck.ValidateObj(mainObj); surfaceLoft = (MegaShapeLoft)EditorGUILayout.ObjectField("Surface", surfaceLoft, typeof(MegaShapeLoft), true); surfaceLayer = EditorGUILayout.Popup("Layer", surfaceLayer + 1, MegaShapeUtils.GetLayers(surfaceLoft)) - 1; break; case MegaLoftType.ScatterSpline: EditorGUILayout.TextArea("Build a mesh by scattering a choosen mesh and material along a spline", GUILayout.Height(50.0f)); path = (MegaShape)EditorGUILayout.ObjectField("Path", path, typeof(MegaShape), true); mainObjMesh = (Mesh)EditorGUILayout.ObjectField("Obj", mainObjMesh, typeof(Mesh), true); material = (Material)EditorGUILayout.ObjectField("Material", material, typeof(Material), true); break; case MegaLoftType.Complex: EditorGUILayout.TextArea("Advanced lofter that uses a spline for the path and any number of cross section splines to define the loft", GUILayout.Height(50.0f)); path = (MegaShape)EditorGUILayout.ObjectField("Path", path, typeof(MegaShape), true); section = (MegaShape)EditorGUILayout.ObjectField("Section", section, typeof(MegaShape), true); material = (Material)EditorGUILayout.ObjectField("Material", material, typeof(Material), true); break; case MegaLoftType.CloneSplineSimple: EditorGUILayout.TextArea("Clone a mesh along a spline with options for start, end and main meshes", GUILayout.Height(50.0f)); path = (MegaShape)EditorGUILayout.ObjectField("Path", path, typeof(MegaShape), true); startObjMesh = (Mesh)EditorGUILayout.ObjectField("Start Obj", startObjMesh, typeof(Mesh), true); //startObj = MegaMeshCheck.ValidateObj(startObj); mainObjMesh = (Mesh)EditorGUILayout.ObjectField("Main Obj", mainObjMesh, typeof(Mesh), true); //mainObj = MegaMeshCheck.ValidateObj(mainObj); endObjMesh = (Mesh)EditorGUILayout.ObjectField("End Obj", endObjMesh, typeof(Mesh), true); //endObj = MegaMeshCheck.ValidateObj(endObj); material = (Material)EditorGUILayout.ObjectField("Material", material, typeof(Material), true); break; case MegaLoftType.Clone: EditorGUILayout.TextArea("Clone a mesh onto a surface with options for start, end and main meshes", GUILayout.Height(50.0f)); startObj = (GameObject)EditorGUILayout.ObjectField("Start Obj", startObj, typeof(GameObject), true); startObj = MegaMeshCheck.ValidateObj(startObj); mainObj = (GameObject)EditorGUILayout.ObjectField("Main Obj", mainObj, typeof(GameObject), true); mainObj = MegaMeshCheck.ValidateObj(mainObj); endObj = (GameObject)EditorGUILayout.ObjectField("End Obj", endObj, typeof(GameObject), true); endObj = MegaMeshCheck.ValidateObj(endObj); surfaceLoft = (MegaShapeLoft)EditorGUILayout.ObjectField("Surface", surfaceLoft, typeof(MegaShapeLoft), true); surfaceLayer = EditorGUILayout.Popup("Layer", surfaceLayer + 1, MegaShapeUtils.GetLayers(surfaceLoft)) - 1; material = (Material)EditorGUILayout.ObjectField("Material", material, typeof(Material), true); break; case MegaLoftType.CloneSpline: EditorGUILayout.TextArea("Build a mesh layer by cloning objects along a spline with options for start, end and main objects", GUILayout.Height(50.0f)); path = (MegaShape)EditorGUILayout.ObjectField("Path", path, typeof(MegaShape), true); startObj = (GameObject)EditorGUILayout.ObjectField("Start Obj", startObj, typeof(GameObject), true); startObj = MegaMeshCheck.ValidateObj(startObj); mainObj = (GameObject)EditorGUILayout.ObjectField("Main Obj", mainObj, typeof(GameObject), true); mainObj = MegaMeshCheck.ValidateObj(mainObj); endObj = (GameObject)EditorGUILayout.ObjectField("End Obj", endObj, typeof(GameObject), true); endObj = MegaMeshCheck.ValidateObj(endObj); break; case MegaLoftType.CloneRules: EditorGUILayout.TextArea("Rule based clone onto a surface", GUILayout.Height(50.0f)); //path = (MegaShape)EditorGUILayout.ObjectField("Path", path, typeof(MegaShape), true); surfaceLoft = (MegaShapeLoft)EditorGUILayout.ObjectField("Surface", surfaceLoft, typeof(MegaShapeLoft), true); surfaceLayer = EditorGUILayout.Popup("Layer", surfaceLayer + 1, MegaShapeUtils.GetLayers(surfaceLoft)) - 1; break; case MegaLoftType.CloneSplineRules: EditorGUILayout.TextArea("Rule based clone along a spline", GUILayout.Height(50.0f)); path = (MegaShape)EditorGUILayout.ObjectField("Path", path, typeof(MegaShape), true); surfaceLoft = (MegaShapeLoft)EditorGUILayout.ObjectField("Surface", surfaceLoft, typeof(MegaShapeLoft), true); surfaceLayer = EditorGUILayout.Popup("Layer", surfaceLayer + 1, MegaShapeUtils.GetLayers(surfaceLoft)) - 1; break; #if true case MegaLoftType.MultiMaterial: EditorGUILayout.TextArea("Will create a loft using multiple materials based on material ids in the spline knots. It uses a single spline for the path and another spline for the cross section", GUILayout.Height(50.0f)); path = (MegaShape)EditorGUILayout.ObjectField("Path", path, typeof(MegaShape), true); section = (MegaShape)EditorGUILayout.ObjectField("Section", section, typeof(MegaShape), true); material = (Material)EditorGUILayout.ObjectField("Material", material, typeof(Material), true); break; case MegaLoftType.MultiMaterialComplex: EditorGUILayout.TextArea("Will create a complex loft using multiple materials based on material ids in the spline knots. It uses a single spline for the path and another spline for the cross section", GUILayout.Height(50.0f)); path = (MegaShape)EditorGUILayout.ObjectField("Path", path, typeof(MegaShape), true); section = (MegaShape)EditorGUILayout.ObjectField("Section", section, typeof(MegaShape), true); material = (Material)EditorGUILayout.ObjectField("Material", material, typeof(Material), true); break; #endif } EditorStyles.textField.wordWrap = false; EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Create")) { MegaLoftLayerBase laybase = null; switch (lofttype) { case MegaLoftType.Simple: { MegaLoftLayerSimple layer = Selection.activeGameObject.AddComponent <MegaLoftLayerSimple>(); layer.pathStart = start; layer.pathLength = length; layer.layerPath = path; layer.layerSection = section; laybase = layer; } break; case MegaLoftType.CloneSimple: { MegaLoftLayerCloneSimple layer = Selection.activeGameObject.AddComponent <MegaLoftLayerCloneSimple>(); layer.startObj = startObjMesh; layer.mainObj = mainObjMesh; layer.endObj = endObjMesh; layer.surfaceLoft = surfaceLoft; layer.surfaceLayer = surfaceLayer; laybase = layer; } break; case MegaLoftType.ScatterSimple: { MegaLoftLayerScatterSimple layer = Selection.activeGameObject.AddComponent <MegaLoftLayerScatterSimple>(); layer.scatterMesh = mainObjMesh; layer.surfaceLoft = surfaceLoft; layer.surfaceLayer = surfaceLayer; laybase = layer; } break; case MegaLoftType.Scatter: { MegaLoftLayerScatter layer = Selection.activeGameObject.AddComponent <MegaLoftLayerScatter>(); layer.mainObj = mainObj; layer.surfaceLoft = surfaceLoft; layer.surfaceLayer = surfaceLayer; laybase = layer; } break; case MegaLoftType.ScatterSpline: { MegaLoftLayerScatterSpline layer = Selection.activeGameObject.AddComponent <MegaLoftLayerScatterSpline>(); layer.scatterMesh = mainObjMesh; layer.layerPath = path; laybase = layer; } break; case MegaLoftType.Complex: { MegaLoftLayerComplex layer = Selection.activeGameObject.AddComponent <MegaLoftLayerComplex>(); layer.layerPath = path; layer.layerSection = section; laybase = layer; } break; case MegaLoftType.CloneSplineSimple: { MegaLoftLayerCloneSplineSimple layer = Selection.activeGameObject.AddComponent <MegaLoftLayerCloneSplineSimple>(); layer.layerPath = path; layer.startObj = startObjMesh; layer.mainObj = mainObjMesh; layer.endObj = endObjMesh; laybase = layer; } break; case MegaLoftType.CloneSpline: { MegaLoftLayerCloneSpline layer = Selection.activeGameObject.AddComponent <MegaLoftLayerCloneSpline>(); layer.layerPath = path; layer.startObj = startObj; layer.mainObj = mainObj; layer.endObj = endObj; laybase = layer; } break; case MegaLoftType.Clone: { MegaLoftLayerClone layer = Selection.activeGameObject.AddComponent <MegaLoftLayerClone>(); layer.surfaceLoft = surfaceLoft; layer.surfaceLayer = surfaceLayer; layer.startObj = startObj; layer.mainObj = mainObj; layer.endObj = endObj; laybase = layer; } break; case MegaLoftType.CloneRules: { MegaLoftLayerCloneRules layer = Selection.activeGameObject.AddComponent <MegaLoftLayerCloneRules>(); layer.surfaceLoft = surfaceLoft; layer.surfaceLayer = surfaceLayer; //layer.layerPath = path; //layer.layerSection = section; laybase = layer; } break; case MegaLoftType.CloneSplineRules: { MegaLoftLayerCloneSplineRules layer = Selection.activeGameObject.AddComponent <MegaLoftLayerCloneSplineRules>(); layer.layerPath = path; laybase = layer; } break; #if true case MegaLoftType.MultiMaterial: { MegaLoftLayerMultiMat layer = Selection.activeGameObject.AddComponent <MegaLoftLayerMultiMat>(); layer.pathStart = start; layer.pathLength = length; layer.layerPath = path; layer.layerSection = section; MegaMaterialSection ms = new MegaMaterialSection(); ms.mat = material; layer.sections.Add(ms); laybase = layer; } break; // We should add two loft sections // if cross has multiple splines add them all equally spaced? case MegaLoftType.MultiMaterialComplex: { MegaLoftLayerMultiMatComplex layer = Selection.activeGameObject.AddComponent <MegaLoftLayerMultiMatComplex>(); layer.pathStart = start; layer.pathLength = length; layer.layerPath = path; layer.layerSection = section; MegaMaterialSection ms = new MegaMaterialSection(); ms.mat = material; layer.sections.Add(ms); laybase = layer; } break; #endif default: EditorUtility.DisplayDialog("Layer Not Supported", "Currently this layer type is not not supported", "OK"); break; } // Common params if (laybase) { laybase.paramcol = paramCol; laybase.LayerName = LayerName; laybase.LayerName = LayerName; laybase.material = material; } this.Close(); } if (GUILayout.Button("Cancel")) { this.Close(); } EditorGUILayout.EndHorizontal(); }
public void DisplayGUI() { CustomMegaBarrier barrier = (CustomMegaBarrier)target; barrier.prefabWalk = (MegaWalkLoft)EditorGUILayout.ObjectField("Prefab Walk", barrier.prefabWalk, typeof(MegaWalkLoft), true); barrier.numbers = EditorGUILayout.IntField("Numbers by Loft", barrier.numbers); if (barrier.numbers < 0) { barrier.numbers = 0; } barrier.min = EditorGUILayout.Slider("Min", barrier.min, 0f, barrier.max); barrier.max = EditorGUILayout.Slider("Max", barrier.max, barrier.min, 1f); barrier.crossalpha = EditorGUILayout.Slider("Cross Alpha", barrier.crossalpha, 0f, 1f); showSurfaceLayers = EditorGUILayout.Foldout(showSurfaceLayers, "Surface Layers"); if (showSurfaceLayers) { EditorGUI.indentLevel++; int size = EditorGUILayout.IntField("Size", barrier.surfaceLayers.Length); if (size < 0) { size = 0; } System.Array.Resize(ref barrier.surfaceLayers, size); System.Array.Resize(ref showElement, size); for (int i = 0; i < size; i++) { showElement[i] = EditorGUILayout.Foldout(showElement[i], "Element " + i); if (showElement[i]) { EditorGUI.indentLevel++; barrier.surfaceLayers[i].loft = (MegaShapeLoft)EditorGUILayout.ObjectField("Surface", barrier.surfaceLayers[i].loft, typeof(MegaShapeLoft), true); int surfaceLayer = MegaShapeUtils.FindLayer(barrier.surfaceLayers[i].loft, barrier.surfaceLayers[i].layer); surfaceLayer = EditorGUILayout.Popup("Layer", surfaceLayer + 1, MegaShapeUtils.GetLayers(barrier.surfaceLayers[i].loft)) - 1; if (barrier.surfaceLayers[i].loft) { for (int j = 0; j < barrier.surfaceLayers[i].loft.Layers.Length; j++) { if (barrier.surfaceLayers[i].loft.Layers[j] is MegaLoftLayerSimple) { if (surfaceLayer == 0) { barrier.surfaceLayers[i].layer = j; break; } surfaceLayer--; } } } else { barrier.surfaceLayers[i].layer = surfaceLayer; } EditorGUI.indentLevel--; } } EditorGUI.indentLevel--; } barrier.upright = EditorGUILayout.Slider("Upright", barrier.upright, 0f, 1f); barrier.uprot = EditorGUILayout.Vector3Field("up Rotate", barrier.uprot); barrier.delay = EditorGUILayout.FloatField("Delay", barrier.delay); barrier.offset = EditorGUILayout.FloatField("Offset", barrier.offset); barrier.tangent = EditorGUILayout.FloatField("Tangent", barrier.tangent); barrier.rotate = EditorGUILayout.Vector3Field("Rotate", barrier.rotate); barrier.lateupdate = EditorGUILayout.Toggle("Late Update", barrier.lateupdate); }
public void OnSceneGUI() { MegaLoftLayerComplex layer = (MegaLoftLayerComplex)target; MegaShapeLoft loft = layer.gameObject.GetComponent <MegaShapeLoft>(); if (loft == null) { return; } if (layer.layerPath == null) { return; } if (!layer.showsections) { return; } MegaSpline pathspline = layer.layerPath.splines[layer.curve]; Matrix4x4 pathtm = Matrix4x4.identity; if (layer.SnapToPath) { pathtm = layer.layerPath.transform.localToWorldMatrix; } Matrix4x4 twisttm = Matrix4x4.identity; Matrix4x4 tm; float offx = 0.0f; float offy = 0.0f; float offz = 0.0f; Vector3 lastup = locup; for (int i = 1; i < layer.sections.Count - 1; i++) { MegaLoftSection section = layer.sections[i]; float alpha = section.alpha; if (layer.useOffsetX) { offx = layer.offsetCrvX.Evaluate(alpha); } if (layer.useOffsetY) { offy = layer.offsetCrvY.Evaluate(alpha); } if (layer.useOffsetZ) { offz += layer.offsetCrvZ.Evaluate(alpha); } //if ( layer.useTwistCrv ) //{ // float twist = layer.twistCrv.Evaluate(alpha); // MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * twist); // tm = pathtm * layer.GetDeformMat(pathspline, alpha, layer.layerPath.normalizedInterp) * twisttm; //} //else // tm = pathtm * layer.GetDeformMat(pathspline, alpha, layer.layerPath.normalizedInterp); if (layer.useTwistCrv) { float twist = layer.twistCrv.Evaluate(section.alpha); float tw1 = pathspline.GetTwist(section.alpha); MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * (twist - tw1)); if (layer.frameMethod == MegaFrameMethod.Old) { tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp) * twisttm; } else { tm = pathtm * layer.GetDeformMatNewMethod(pathspline, section.alpha, layer.layerPath.normalizedInterp, ref lastup) * twisttm; } } else { if (layer.frameMethod == MegaFrameMethod.Old) { tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp); } else { tm = pathtm * layer.GetDeformMatNewMethod(pathspline, section.alpha, layer.layerPath.normalizedInterp, ref lastup); } } Vector3 p = section.crossverts[0]; if (layer.useScaleXCrv) { p.x *= layer.scaleCrvX.Evaluate(alpha); } if (layer.useScaleYCrv) { p.y *= layer.scaleCrvY.Evaluate(alpha); } p.x += offx; p.y += offy; p.z += offz; Vector3 tp = p; p = tm.MultiplyPoint3x4(p); p += layer.offset; Matrix4x4 tantm = pathtm * layer.GetDeformMat(pathspline, alpha + 0.01f, layer.layerPath.normalizedInterp); Vector3 tan = tantm.MultiplyPoint3x4(tp); tan += layer.offset; tan = (tan - p).normalized; Vector3 p1 = section.crossverts[section.crossverts.Length - 1]; if (layer.useScaleXCrv) { p1.x *= layer.scaleCrvX.Evaluate(alpha); } if (layer.useScaleYCrv) { p1.y *= layer.scaleCrvY.Evaluate(alpha); } p1.x += offx; p1.y += offy; p1.z += offz; tp = p1; p1 = tm.MultiplyPoint3x4(p1); p1 += layer.offset; Handles.color = Color.yellow; p = loft.transform.TransformPoint(p); //Vector3 pn = Handles.Slider(p, tan, layer.handlesize, Handles.SphereCap, 0.0f); Vector3 pn = Slider(p, tan, layer.handlesize); pn = pn - p; float delta = pn.magnitude; if (Vector3.Dot(tan, pn) < 0.0f) { delta = -delta; } section.alpha += delta * 0.0005f; float al = section.alpha; // + delta * 0.0005f; if (al != layer.sections[i].alpha) { if (i > 0) { if (al < layer.sections[i - 1].alpha) { al = layer.sections[i - 1].alpha; } } if (i < layer.sections.Count - 1) { if (al > layer.sections[i + 1].alpha) { al = layer.sections[i + 1].alpha; } } layer.sections[i].alpha = al; } if (delta != 0.0f) { GUI.changed = true; loft.rebuild = true; EditorUtility.SetDirty(target); } tan = tantm.MultiplyPoint3x4(tp); tan += layer.offset; tan = (tan - p1).normalized; p1 = loft.transform.TransformPoint(p1); //pn = Handles.Slider(p1, tan, layer.handlesize, Handles.SphereCap, 0.0f); pn = Slider(p1, tan, layer.handlesize); pn = pn - p1; delta = pn.magnitude; //Vector3.Distance(p, pn); if (Vector3.Dot(tan, pn) < 0.0f) { delta = -delta; } al = section.alpha + delta * 0.0005f; if (al != layer.sections[i].alpha) { if (i > 0) { if (al < layer.sections[i - 1].alpha) { al = layer.sections[i - 1].alpha; } } if (i < layer.sections.Count - 1) { if (al > layer.sections[i + 1].alpha) { al = layer.sections[i + 1].alpha; } } layer.sections[i].alpha = al; } if (delta != 0.0f) { GUI.changed = true; loft.rebuild = true; EditorUtility.SetDirty(target); } } if (layer.sections.Count > 0) { if (layer.sections[0].alpha != 0.0f) { layer.sections[0].alpha = 0.0f; } for (int i = 1; i < layer.sections.Count - 1; i++) { if (layer.sections[i].alpha <= layer.sections[i - 1].alpha) { layer.sections[i - 1].alpha = layer.sections[i].alpha; } if (layer.sections[i].alpha >= layer.sections[i + 1].alpha) { layer.sections[i].alpha = layer.sections[i + 1].alpha; } } if (layer.sections[layer.sections.Count - 1].alpha != 1.0f) { layer.sections[layer.sections.Count - 1].alpha = 1.0f; } } }
static void DrawPath(MegaLoftLayerComplex layer) { MegaShapeLoft loft = layer.gameObject.GetComponent <MegaShapeLoft>(); if (loft == null) { return; } if (layer.layerPath == null) { return; } if (layer.sections == null || layer.sections.Count < 2) { return; } for (int i = 0; i < layer.sections.Count; i++) { if (layer.sections[i].crossverts == null || layer.sections[i].crossverts.Length == 0) { return; } } MegaSpline pathspline = layer.layerPath.splines[layer.curve]; Matrix4x4 pathtm = Matrix4x4.identity; if (layer.SnapToPath) { pathtm = layer.layerPath.transform.localToWorldMatrix; } Color col = Gizmos.color; Matrix4x4 twisttm = Matrix4x4.identity; Matrix4x4 tm; Vector3 lastup = locup; for (int i = 0; i < layer.sections.Count; i++) { MegaLoftSection section = layer.sections[i]; //if ( layer.useTwistCrv ) //{ // float twist = layer.twistCrv.Evaluate(section.alpha); // MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * twist); // tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp) * twisttm; //loft.); //} //else // tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp); //loft.); if (layer.useTwistCrv) { float twist = layer.twistCrv.Evaluate(section.alpha); float tw1 = pathspline.GetTwist(section.alpha); MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * (twist - tw1)); if (layer.frameMethod == MegaFrameMethod.Old) { tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp) * twisttm; } else { tm = pathtm * layer.GetDeformMatNewMethod(pathspline, section.alpha, layer.layerPath.normalizedInterp, ref lastup) * twisttm; } } else { if (layer.frameMethod == MegaFrameMethod.Old) { tm = pathtm * layer.GetDeformMat(pathspline, section.alpha, layer.layerPath.normalizedInterp); } else { tm = pathtm * layer.GetDeformMatNewMethod(pathspline, section.alpha, layer.layerPath.normalizedInterp, ref lastup); } } Vector3 p1 = section.crossverts[0]; float offx = 0.0f; float offy = 0.0f; float offz = 0.0f; float sclx = 1.0f; float scly = 1.0f; if (layer.useScaleXCrv) { p1.x *= layer.scaleCrvX.Evaluate(section.alpha); } if (layer.useScaleYCrv) { p1.y *= layer.scaleCrvY.Evaluate(section.alpha); } if (layer.useOffsetX) { offx = layer.offsetCrvX.Evaluate(section.alpha); } if (layer.useOffsetY) { offy = layer.offsetCrvY.Evaluate(section.alpha); } if (layer.useOffsetZ) { offz = layer.offsetCrvZ.Evaluate(section.alpha); } if (layer.useScaleXCrv) { sclx = layer.scaleCrvX.Evaluate(section.alpha); } if (layer.useScaleYCrv) { scly = layer.scaleCrvY.Evaluate(section.alpha); } p1 = tm.MultiplyPoint3x4(p1); p1 += layer.offset; Gizmos.color = seccol; //Color.red; Vector3 mid = Vector3.zero; for (int v = 1; v < section.crossverts.Length; v++) { Vector3 p = section.crossverts[v]; p.x *= sclx; p.y *= scly; p.x += offx; p.y += offy; p.z += offz; p = tm.MultiplyPoint3x4(p); p += layer.offset; Gizmos.DrawLine(loft.transform.TransformPoint(p1), loft.transform.TransformPoint(p)); p1 = p; if (v == section.crossverts.Length / 2) { mid = p; } } Handles.color = Color.white; Handles.Label(loft.transform.TransformPoint(mid), "Cross: " + i); Gizmos.color = col; } // Draw outside edge Vector3 sclc = Vector3.one; float lerp = 0.0f; // The position stuff here is waht we could use instead of mesh verts Vector3 last = Vector3.zero; Vector3 last1 = Vector3.zero; lastup = locup; for (float alpha = 0.0f; alpha <= 1.0f; alpha += 0.005f) { if (layer.useScaleXCrv) { sclc.x = layer.scaleCrvX.Evaluate(alpha); } if (layer.useScaleYCrv) { sclc.y = layer.scaleCrvY.Evaluate(alpha); } //if ( layer.useTwistCrv ) //{ // float twist = layer.twistCrv.Evaluate(alpha); // MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * twist); // tm = pathtm * layer.GetDeformMat(layer.layerPath.splines[layer.curve], alpha, layer.layerPath.normalizedInterp) * twisttm; //loft.); //} //else // tm = pathtm * layer.GetDeformMat(layer.layerPath.splines[layer.curve], alpha, layer.layerPath.normalizedInterp); //loft.); if (layer.useTwistCrv) { float twist = layer.twistCrv.Evaluate(alpha); float tw1 = pathspline.GetTwist(alpha); MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * (twist - tw1)); if (layer.frameMethod == MegaFrameMethod.Old) { tm = pathtm * layer.GetDeformMat(pathspline, alpha, layer.layerPath.normalizedInterp) * twisttm; } else { tm = pathtm * layer.GetDeformMatNewMethod(pathspline, alpha, layer.layerPath.normalizedInterp, ref lastup) * twisttm; } } else { if (layer.frameMethod == MegaFrameMethod.Old) { tm = pathtm * layer.GetDeformMat(pathspline, alpha, layer.layerPath.normalizedInterp); } else { tm = pathtm * layer.GetDeformMatNewMethod(pathspline, alpha, layer.layerPath.normalizedInterp, ref lastup); } } // Need to get the crosssection for the given alpha and the lerp value int csect = layer.GetSection(alpha, out lerp); lerp = layer.ease.easing(0.0f, 1.0f, lerp); MegaLoftSection cs1 = layer.sections[csect]; MegaLoftSection cs2 = layer.sections[csect + 1]; Vector3 p = Vector3.Lerp(cs1.crossverts[0], cs2.crossverts[0], lerp); // * sclc; Vector3 p1 = Vector3.Lerp(cs1.crossverts[cs1.crossverts.Length - 1], cs2.crossverts[cs2.crossverts.Length - 1], lerp); // * sclc; if (layer.useScaleXCrv) { p.x *= sclc.x; p1.x *= sclc.x; } if (layer.useScaleYCrv) { p.y *= sclc.y; p1.y *= sclc.y; } if (layer.useOffsetX) { p.x += layer.offsetCrvX.Evaluate(alpha); p1.x += layer.offsetCrvX.Evaluate(alpha); } if (layer.useOffsetY) { p.y += layer.offsetCrvY.Evaluate(alpha); p1.y += layer.offsetCrvY.Evaluate(alpha); } if (layer.useOffsetZ) { p.z += layer.offsetCrvZ.Evaluate(alpha); p1.z += layer.offsetCrvZ.Evaluate(alpha); } p = tm.MultiplyPoint3x4(p); p += layer.offset; p1 = tm.MultiplyPoint3x4(p1); p1 += layer.offset; if (alpha > 0.0f) { Gizmos.DrawLine(loft.transform.TransformPoint(last), loft.transform.TransformPoint(p)); Gizmos.DrawLine(loft.transform.TransformPoint(last1), loft.transform.TransformPoint(p1)); } last = p; last1 = p1; } }
public void DisplayGUI() { MegaLoftScatter walk = (MegaLoftScatter)target; walk.count = EditorGUILayout.IntField("Count", walk.count); walk.seed = EditorGUILayout.IntField("Seed", walk.seed); walk.start = EditorGUILayout.Slider("Start", walk.start, 0.0f, 1.0f); walk.end = EditorGUILayout.Slider("End", walk.end, 0.0f, 1.0f); walk.crosslow = EditorGUILayout.Slider("Cross Start", walk.crosslow, 0.0f, 1.0f); walk.crosshigh = EditorGUILayout.Slider("Cross End", walk.crosshigh, 0.0f, 1.0f); walk.obj = (GameObject)EditorGUILayout.ObjectField("Scatter Obj", walk.obj, typeof(GameObject), true); walk.scalelow = EditorGUILayout.FloatField("Scale Low", walk.scalelow); walk.scalehigh = EditorGUILayout.FloatField("Scale High", walk.scalehigh); walk.rotlow = EditorGUILayout.FloatField("Rot Low", walk.rotlow); walk.rothigh = EditorGUILayout.FloatField("Rot High", walk.rothigh); walk.nametouse = EditorGUILayout.TextField("Name", walk.nametouse); walk.parent = (Transform)EditorGUILayout.ObjectField("Parent", walk.parent, typeof(Transform), true); walk.remove = EditorGUILayout.Toggle("Remove", walk.remove); walk.surfaceLoft = (MegaShapeLoft)EditorGUILayout.ObjectField("Surface", walk.surfaceLoft, typeof(MegaShapeLoft), true); int surfaceLayer = MegaShapeUtils.FindLayer(walk.surfaceLoft, walk.surfaceLayer); surfaceLayer = EditorGUILayout.Popup("Layer", surfaceLayer + 1, MegaShapeUtils.GetLayers(walk.surfaceLoft)) - 1; if (walk.surfaceLoft) { for (int i = 0; i < walk.surfaceLoft.Layers.Length; i++) { if (walk.surfaceLoft.Layers[i] is MegaLoftLayerSimple) { if (surfaceLayer == 0) { walk.surfaceLayer = i; break; } surfaceLayer--; } } } else { walk.surfaceLayer = surfaceLayer; } walk.upright = EditorGUILayout.Slider("Upright", walk.upright, 0.0f, 1.0f); walk.uprot = EditorGUILayout.Vector3Field("up Rotate", walk.uprot); walk.offset = EditorGUILayout.FloatField("Offset", walk.offset); walk.tangent = EditorGUILayout.FloatField("Tangent", walk.tangent); walk.rotate = EditorGUILayout.Vector3Field("Rotate", walk.rotate); //walk.refresh = EditorGUILayout.Toggle("Refresh", walk.refresh); walk.realtime = EditorGUILayout.Toggle("Realtime", walk.realtime); walk.scatteronstart = EditorGUILayout.Toggle("Scatter on Start", walk.scatteronstart); if (GUILayout.Button("Scatter")) { //walk.refresh = true; walk.Scatter(); } if (GUILayout.Button("Remove Objects")) { walk.Remove(); } }
public override int BuildMesh(MegaShapeLoft loft, int triindex) { if (Lock) { return(triindex); } if (layerPath == null || layerPath.splines == null || layerPath.splines.Count == 0) { return(triindex); } if (sections.Count < 2) //== 0 ) { return(triindex); } Vector2 uv = Vector2.zero; Vector3 p = Vector3.zero; int wc = ActualCrossVerts; float lerp = 0.0f; Matrix4x4 pathtm = Matrix4x4.identity; if (SnapToPath) { pathtm = layerPath.transform.localToWorldMatrix; } Matrix4x4 twisttm = Matrix4x4.identity; Vector3 sclc = Vector2.one; Matrix4x4 tm; float offx = 0.0f; float offy = 0.0f; float offz = 0.0f; bool clsd = layerPath.splines[curve].closed; float uvstart = pathStart; if (UVOrigin == MegaLoftUVOrigin.SplineStart) { uvstart = 0.0f; } Vector3 lastup = locup; for (int pi = 0; pi < PathSteps + 1; pi++) { float alpha = (float)pi / (float)PathSteps; float pathalpha = pathStart + (pathLength * alpha); if (clsd) { pathalpha = Mathf.Repeat(pathalpha, 1.0f); } if (useScaleXCrv) { sclc.x = scaleCrvX.Evaluate(pathalpha); } if (useScaleYCrv) { sclc.y = scaleCrvY.Evaluate(pathalpha); } if (useTwistCrv) { float twist = twistCrv.Evaluate(pathalpha); float tw1 = layerPath.splines[curve].GetTwist(pathalpha); MegaShapeUtils.RotateZ(ref twisttm, Mathf.Deg2Rad * (twist - tw1)); if (frameMethod == MegaFrameMethod.Old) { tm = pathtm * GetDeformMat(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp) * twisttm; } else { tm = pathtm * GetDeformMatNewMethod(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp, ref lastup) * twisttm; } } else { if (frameMethod == MegaFrameMethod.Old) { tm = pathtm * GetDeformMat(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp); } else { tm = pathtm * GetDeformMatNewMethod(layerPath.splines[curve], pathalpha, layerPath.normalizedInterp, ref lastup); } } // Need to get the crosssection for the given alpha and the lerp value int csect = GetSection(pathalpha, out lerp); lerp = ease.easing(0.0f, 1.0f, lerp); MegaLoftSection cs1 = sections[csect]; MegaLoftSection cs2 = sections[csect + 1]; if (useOffsetX) { offx = offsetCrvX.Evaluate(pathalpha); } if (useOffsetY) { offy = offsetCrvY.Evaluate(pathalpha); } if (useOffsetZ) { offz = offsetCrvZ.Evaluate(pathalpha); } if (planaruv) { float size = 1.0f / layerPath.splines[curve].length; Matrix4x4 uvtm = Matrix4x4.TRS(new Vector3(UVOffset.x, 0.0f, UVOffset.y), Quaternion.Euler(UVRotate.x, UVRotate.y, 0.0f), new Vector3(size * UVScale.x, 1.0f, size * UVScale.y)); for (int v = 0; v < cs1.crossverts.Length; v++) { p = Vector3.Lerp(cs1.crossverts[v], cs2.crossverts[v], lerp); if (useScaleXCrv) { p.x *= sclc.x; } if (useScaleYCrv) { p.y *= sclc.y; } p.x += offx; p.y += offy; p.z += offz; p = tm.MultiplyPoint3x4(p); p += offset; int ix = (pi * wc) + v; loftverts[ix] = p; p.y = 0.0f; p = uvtm.MultiplyPoint(p); loftuvs[ix].x = p.x; loftuvs[ix].y = p.z; } } else { for (int v = 0; v < cs1.crossverts.Length; v++) { p = Vector3.Lerp(cs1.crossverts[v], cs2.crossverts[v], lerp); if (useScaleXCrv) { p.x *= sclc.x; } if (useScaleYCrv) { p.y *= sclc.y; } p.x += offx; p.y += offy; p.z += offz; p = tm.MultiplyPoint3x4(p); p += offset; int ix = (pi * wc) + v; loftverts[ix] = p; uv = Vector3.Lerp(cs1.crossuvs[v], cs2.crossuvs[v], lerp); uv.y = uvstart + alpha; uv.x *= UVScale.x; uv.y *= UVScale.y; uv.x += UVOffset.x; uv.y += UVOffset.y; loftuvs[ix] = uv; } } } // Now need to build faces, normal grid face builder int fi = 0; int index = triindex; if (flip) //Tris ) { for (int iz = 0; iz < ActualPathSteps - 1; iz++) { int kv = iz * (ActualCrossVerts) + index; for (int ix = 0; ix < ActualCrossVerts - 1; ix++) { lofttris[fi + 0] = kv; lofttris[fi + 1] = kv + wc; lofttris[fi + 2] = kv + wc + 1; lofttris[fi + 3] = kv + wc + 1; lofttris[fi + 4] = kv + 1; lofttris[fi + 5] = kv; fi += 6; kv++; } } } else { for (int iz = 0; iz < ActualPathSteps - 1; iz++) { int kv = iz * (ActualCrossVerts) + index; for (int ix = 0; ix < ActualCrossVerts - 1; ix++) { lofttris[fi + 2] = kv; lofttris[fi + 1] = kv + wc; lofttris[fi + 0] = kv + wc + 1; lofttris[fi + 5] = kv + wc + 1; lofttris[fi + 4] = kv + 1; lofttris[fi + 3] = kv; fi += 6; kv++; } } } index = triindex + loftverts.Length; if (capStart) { Matrix4x4 uvtm = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0.0f, 0.0f, capStartUVRot), Vector3.one); // Do uvs here from end points, as we do some clipping in here for (int i = 0; i < capStartVerts.Length; i++) { Vector3 lp = loftverts[i]; capStartVerts[i] = lp; Vector3 uv1 = crossverts[i]; uv1.y = lp.y; uv1 = uvtm.MultiplyPoint(uv1); capStartUVS[i].x = (uv1.x * capStartUVScale.x) + capStartUVOffset.x; capStartUVS[i].y = (uv1.y * capStartUVScale.y) + capStartUVOffset.y; } if (capflip) { for (int i = 0; i < capfaces.Count; i += 3) { capStartTris[i + 2] = capfaces[i + 0] + index; capStartTris[i + 1] = capfaces[i + 1] + index; capStartTris[i + 0] = capfaces[i + 2] + index; } } else { for (int i = 0; i < capfaces.Count; i += 3) { capStartTris[i + 0] = capfaces[i + 0] + index; capStartTris[i + 1] = capfaces[i + 1] + index; capStartTris[i + 2] = capfaces[i + 2] + index; } } fi += capfaces.Count; index += capStartVerts.Length; } if (capEnd) { Matrix4x4 uvtm = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0.0f, 0.0f, capEndUVRot), Vector3.one); int ix = loftverts.Length - capEndVerts.Length; for (int i = 0; i < capEndVerts.Length; i++) { Vector3 lp = loftverts[ix + i]; capEndVerts[i] = lp; Vector3 uv1 = crossvertsend[i]; uv1.y = lp.y; uv1 = uvtm.MultiplyPoint(uv1); capEndUVS[i].x = (uv1.x * capEndUVScale.x) + capEndUVOffset.x; capEndUVS[i].y = (uv1.y * capEndUVScale.y) + capEndUVOffset.y; } if (capflip) { for (int i = 0; i < capfacesend.Count; i += 3) { capEndTris[i + 0] = capfacesend[i + 0] + index; capEndTris[i + 1] = capfacesend[i + 1] + index; capEndTris[i + 2] = capfacesend[i + 2] + index; } } else { for (int i = 0; i < capfacesend.Count; i += 3) { capEndTris[i + 2] = capfacesend[i + 0] + index; capEndTris[i + 1] = capfacesend[i + 1] + index; capEndTris[i + 0] = capfacesend[i + 2] + index; } } fi += capfacesend.Count; } return(triindex + fi); //triindex; }
public override void OnInspectorGUI() { MegaLoftTerrainCarve loft = (MegaLoftTerrainCarve)target; #if !UNITY_5 EditorGUIUtility.LookLikeControls(); #endif if (GUILayout.Button("Save Terrain")) { loft.SaveHeights(); } if (GUILayout.Button("Restore Terrain")) { loft.ResetHeights(); } if (GUILayout.Button("Clear Cache")) { loft.ClearMem(); } if (loft.savedheights != null) { if (GUILayout.Button("Conform")) { loft.ConformTerrain(); } } loft.tobj = (GameObject)EditorGUILayout.ObjectField("Terrain", loft.tobj, typeof(GameObject), true); loft.surfaceLoft = (MegaShapeLoft)EditorGUILayout.ObjectField(MegaToolTip.Surface, loft.surfaceLoft, typeof(MegaShapeLoft), true); int surfaceLayer = MegaShapeUtils.FindLayer(loft.surfaceLoft, loft.surfaceLayer); surfaceLayer = EditorGUILayout.Popup("Layer", surfaceLayer + 1, MegaShapeUtils.GetLayers(loft.surfaceLoft)) - 1; if (loft.surfaceLoft) { for (int i = 0; i < loft.surfaceLoft.Layers.Length; i++) { //if ( layer.surfaceLoft.Layers[i].GetType() == typeof(MegaLoftLayerSimple) ) if (loft.surfaceLoft.Layers[i] is MegaLoftLayerSimple) { if (surfaceLayer == 0) { loft.surfaceLayer = i; break; } surfaceLayer--; } } } else { loft.surfaceLayer = surfaceLayer; } loft.startray = EditorGUILayout.FloatField("Start Ray", loft.startray); loft.raydist = EditorGUILayout.FloatField("Ray Dist", loft.raydist); loft.offset = EditorGUILayout.FloatField("Offset", loft.offset); loft.cstart = EditorGUILayout.Slider("Cross Start", loft.cstart, 0.0f, 0.9999f); loft.cend = EditorGUILayout.Slider("Cross End", loft.cend, 0.0f, 0.9999f); loft.dist = EditorGUILayout.FloatField("Dist", loft.dist); //loft.scale = EditorGUILayout.FloatField("Scale", loft.scale); loft.leftscale = EditorGUILayout.FloatField("Left Scale", loft.leftscale); loft.rightscale = EditorGUILayout.FloatField("Right Scale", loft.rightscale); loft.sectioncrv = EditorGUILayout.CurveField("Section Crv", loft.sectioncrv); loft.leftenabled = EditorGUILayout.BeginToggleGroup("Left Falloff", loft.leftenabled); //loft.leftenabled = EditorGUILayout.Toggle("Left Falloff", loft.leftenabled); loft.leftfalloff = EditorGUILayout.FloatField("Left Falloff Dist", loft.leftfalloff); //loft.leftsampledist = EditorGUILayout.FloatField("Left Sample Dist", loft.leftsampledist); loft.leftfallcrv = EditorGUILayout.CurveField("Left Falloff Curve", loft.leftfallcrv); loft.leftalphaoff = EditorGUILayout.FloatField("Left Alpha off", loft.leftalphaoff); EditorGUILayout.EndToggleGroup(); loft.rightenabled = EditorGUILayout.BeginToggleGroup("Right Falloff", loft.rightenabled); loft.rightfalloff = EditorGUILayout.FloatField("Right Falloff Dist", loft.rightfalloff); //loft.rightsampledist = EditorGUILayout.FloatField("Right Sample Dist", loft.rightsampledist); loft.rightfallcrv = EditorGUILayout.CurveField("Right Falloff Curve", loft.rightfallcrv); loft.rightalphaoff = EditorGUILayout.FloatField("Right Alpha off", loft.rightalphaoff); EditorGUILayout.EndToggleGroup(); loft.restorebefore = EditorGUILayout.Toggle("Restore Before", loft.restorebefore); loft.numpasses = EditorGUILayout.IntField("Num Smooth Passes", loft.numpasses); if (GUI.changed) //rebuild ) { EditorUtility.SetDirty(target); loft.BuildVerts(); } }
public void DisplayGUI() { MegaLoftLayerClone layer = (MegaLoftLayerClone)target; MegaShapeLoftEditor.PushCols(); MegaShapeLoft loft = layer.GetComponent <MegaShapeLoft>(); float sl = -1.0f; float sh = 1.0f; float ll = 0.001f; float lh = 2.0f; float csl = -1.0f; float csh = 1.0f; if (loft) { sl = loft.startLow; sh = loft.startHigh; ll = loft.lenLow; lh = loft.lenHigh; csl = loft.crossLow; csh = loft.crossHigh; } GUI.color = Color.white; GUI.backgroundColor = layer.paramcol; GUI.contentColor = Color.white; EditorGUILayout.BeginVertical("TextArea"); layer.LayerName = EditorGUILayout.TextField(MegaToolTip.LayerName, layer.LayerName); layer.LayerEnabled = EditorGUILayout.Toggle(MegaToolTip.Enabled, layer.LayerEnabled); layer.paramcol = EditorGUILayout.ColorField(MegaToolTip.ParamCol, layer.paramcol); if (layer.LayerEnabled) { layer.Lock = EditorGUILayout.Toggle("Lock", layer.Lock); if (!layer.Lock) { //layer.material = (Material)EditorGUILayout.ObjectField(MegaToolTip.Material, layer.material, typeof(Material), true); layer.surfaceLoft = (MegaShapeLoft)EditorGUILayout.ObjectField("Surface", layer.surfaceLoft, typeof(MegaShapeLoft), true); //layer.surfaceLayer = EditorGUILayout.Popup("Layer", layer.surfaceLayer + 1, MegaShapeUtils.GetLayers(layer.surfaceLoft)) - 1; int surfaceLayer = MegaShapeUtils.FindLayer(layer.surfaceLoft, layer.surfaceLayer); surfaceLayer = EditorGUILayout.Popup("Layer", surfaceLayer + 1, MegaShapeUtils.GetLayers(layer.surfaceLoft)) - 1; if (layer.surfaceLoft) { for (int i = 0; i < layer.surfaceLoft.Layers.Length; i++) { //if ( layer.surfaceLoft.Layers[i].GetType() == typeof(MegaLoftLayerSimple) ) if (layer.surfaceLoft.Layers[i] is MegaLoftLayerSimple) { if (surfaceLayer == 0) { layer.surfaceLayer = i; break; } surfaceLayer--; } } } else { layer.surfaceLayer = surfaceLayer; } layer.start = EditorGUILayout.Slider(MegaToolTip.Start, layer.start, sl, sh); layer.Length = EditorGUILayout.Slider(MegaToolTip.Length, layer.Length, ll, lh); //layer.CrossAlpha = EditorGUILayout.Slider("Cross Alpha", layer.CrossAlpha, csl, csh); //-1.0f, 2.0f); layer.CrossAlpha = Slider("Cross Alpha", layer.CrossAlpha, csl, csh); //-1.0f, 2.0f); layer.CalcUp = EditorGUILayout.Toggle("Calc Up", layer.CalcUp); if (!layer.CalcUp) { layer.RemoveDof = EditorGUILayout.FloatField("UpRight", layer.RemoveDof); } //Vector3 off = EditorGUILayout.Vector3Field("Offset", layer.Offset); //layer.Offset += (layer.Offset - off) * 0.1f; layer.Offset = Vector3Field("Offset", layer.Offset); //layer.Offset = EditorGUILayout.Vector3Field("Offset", layer.Offset); layer.rot = EditorGUILayout.Vector3Field("Rotate", layer.rot); layer.tmrot = EditorGUILayout.Vector3Field("TMRotate", layer.tmrot); layer.tangent = EditorGUILayout.FloatField("Tangent", layer.tangent); layer.axis = (MegaAxis)EditorGUILayout.EnumPopup("Axis", layer.axis); layer.useTwist = EditorGUILayout.BeginToggleGroup(MegaToolTip.UseTwist, layer.useTwist); layer.twist = EditorGUILayout.FloatField(MegaToolTip.Twist, layer.twist); layer.twistCrv = EditorGUILayout.CurveField(MegaToolTip.TwistCrv, layer.twistCrv); EditorGUILayout.EndToggleGroup(); // Advanced layer.RemoveDof = EditorGUILayout.FloatField("UpRight", layer.RemoveDof); layer.GlobalScale = EditorGUILayout.FloatField("Scale", layer.GlobalScale); layer.useCrossCrv = EditorGUILayout.BeginToggleGroup("Use Cross Crv", layer.useCrossCrv); layer.CrossCrv = EditorGUILayout.CurveField("Cross Crv", layer.CrossCrv); EditorGUILayout.EndToggleGroup(); // Start Info //layer.showstartparams = EditorGUILayout.Foldout(layer.showstartparams, "Start Params"); layer.showstartparams = MegaFoldOut.Start("Start Params", layer.showstartparams, new Color(1.0f, 0.5f, 0.5f)); if (layer.showstartparams) { //EditorGUILayout.BeginVertical("TextArea"); layer.StartEnabled = EditorGUILayout.Toggle("Enabled", layer.StartEnabled); layer.startObj = (GameObject)EditorGUILayout.ObjectField("Mesh", layer.startObj, typeof(GameObject), true); layer.startObj = MegaMeshCheck.ValidateObj(layer.startObj); //layer.StartOff = EditorGUILayout.Vector3Field("Offset", layer.StartOff); layer.StartOff = Vector3Field("Offset", layer.StartOff); layer.StartScale = EditorGUILayout.Vector3Field("Scale", layer.StartScale); layer.StartGap = FloatField("Gap", layer.StartGap); //EditorGUILayout.EndVertical(); } MegaFoldOut.End(layer.showstartparams); // Main Info //layer.showmainparams = EditorGUILayout.Foldout(layer.showmainparams, "Main Params"); layer.showmainparams = MegaFoldOut.Start("Main Params", layer.showmainparams, new Color(0.5f, 1.0f, 0.5f)); if (layer.showmainparams) { //EditorGUILayout.BeginVertical("TextArea"); layer.MainEnabled = EditorGUILayout.Toggle("Enabled", layer.MainEnabled); layer.mainObj = (GameObject)EditorGUILayout.ObjectField("Mesh", layer.mainObj, typeof(GameObject), true); layer.mainObj = MegaMeshCheck.ValidateObj(layer.mainObj); //layer.MainOff = EditorGUILayout.Vector3Field("Offset", layer.MainOff); layer.MainOff = Vector3Field("Offset", layer.MainOff); layer.MainScale = EditorGUILayout.Vector3Field("Scale", layer.MainScale); if (layer.MainScale.x < 0.01f) { layer.MainScale.x = 0.01f; } if (layer.MainScale.y < 0.01f) { layer.MainScale.y = 0.01f; } if (layer.MainScale.z < 0.1f) { layer.MainScale.z = 0.1f; } layer.Gap = FloatField("Gap", layer.Gap); //EditorGUILayout.EndVertical(); } MegaFoldOut.End(layer.showmainparams); // End Info //layer.showendparams = EditorGUILayout.Foldout(layer.showendparams, "End Params"); layer.showendparams = MegaFoldOut.Start("End Params", layer.showendparams, new Color(0.5f, 0.5f, 1.0f)); if (layer.showendparams) { //EditorGUILayout.BeginVertical("TextArea"); layer.EndEnabled = EditorGUILayout.Toggle("Enabled", layer.EndEnabled); layer.endObj = (GameObject)EditorGUILayout.ObjectField("Mesh", layer.endObj, typeof(GameObject), true); layer.endObj = MegaMeshCheck.ValidateObj(layer.endObj); //layer.EndOff = EditorGUILayout.Vector3Field("Offset", layer.EndOff); layer.EndOff = Vector3Field("Offset", layer.EndOff); layer.EndScale = EditorGUILayout.Vector3Field("Scale", layer.EndScale); layer.EndGap = FloatField("Gap", layer.EndGap); //EditorGUILayout.EndVertical(); } MegaFoldOut.End(layer.showendparams); } //EditorGUILayout.EndVertical(); //MegaShapeLoftEditor.PopCols(); } EditorGUILayout.EndVertical(); MegaShapeLoftEditor.PopCols(); }
public void DisplayGUI() { MegaLoftLayerCloneSimple layer = (MegaLoftLayerCloneSimple)target; MegaShapeLoftEditor.PushCols(); GUI.color = Color.white; GUI.backgroundColor = layer.paramcol; GUI.contentColor = Color.white; //MegaShapeLoft loft = layer.GetComponent<MegaShapeLoft>(); SetLimits(layer.gameObject); EditorGUILayout.BeginVertical("TextArea"); layer.LayerName = EditorGUILayout.TextField(MegaToolTip.LayerName, layer.LayerName); layer.LayerEnabled = EditorGUILayout.Toggle(MegaToolTip.Enabled, layer.LayerEnabled); layer.paramcol = EditorGUILayout.ColorField(MegaToolTip.ParamCol, layer.paramcol); if (layer.LayerEnabled) { layer.Lock = EditorGUILayout.Toggle(MegaToolTip.Lock, layer.Lock); if (!layer.Lock) { // TODO: If null use material from main layer.material = (Material)EditorGUILayout.ObjectField(MegaToolTip.Material, layer.material, typeof(Material), true); layer.surfaceLoft = (MegaShapeLoft)EditorGUILayout.ObjectField(MegaToolTip.Surface, layer.surfaceLoft, typeof(MegaShapeLoft), true); //layer.surfaceLayer = EditorGUILayout.Popup(MegaToolTip.Layer, layer.surfaceLayer + 1, MegaShapeUtils.GetLayersAsContent(layer.surfaceLoft)) - 1; int surfaceLayer = MegaShapeUtils.FindLayer(layer.surfaceLoft, layer.surfaceLayer); surfaceLayer = EditorGUILayout.Popup("Layer", surfaceLayer + 1, MegaShapeUtils.GetLayers(layer.surfaceLoft)) - 1; if (layer.surfaceLoft) { for (int i = 0; i < layer.surfaceLoft.Layers.Length; i++) { //if ( layer.surfaceLoft.Layers[i].GetType() == typeof(MegaLoftLayerSimple) ) if (layer.surfaceLoft.Layers[i] is MegaLoftLayerSimple) { if (surfaceLayer == 0) { layer.surfaceLayer = i; break; } surfaceLayer--; } } } else { layer.surfaceLayer = surfaceLayer; } layer.start = EditorGUILayout.Slider(MegaToolTip.Start, layer.start, sl, sh); layer.Length = EditorGUILayout.Slider(MegaToolTip.Length, layer.Length, ll, lh); layer.CrossAlpha = EditorGUILayout.Slider("Cross Alpha", layer.CrossAlpha, csl, csh); //-1.0f, 2.0f); layer.CalcUp = EditorGUILayout.Toggle("Calc Up", layer.CalcUp); if (!layer.CalcUp) { layer.RemoveDof = EditorGUILayout.FloatField("UpRight", layer.RemoveDof); } layer.Offset = EditorGUILayout.Vector3Field("Offset", layer.Offset); layer.rot = EditorGUILayout.Vector3Field("Rotate", layer.rot); layer.tmrot = EditorGUILayout.Vector3Field("TMRotate", layer.tmrot); layer.tangent = EditorGUILayout.FloatField("Tangent", layer.tangent); layer.axis = (MegaAxis)EditorGUILayout.EnumPopup("Axis", layer.axis); layer.useTwist = EditorGUILayout.BeginToggleGroup(MegaToolTip.UseTwist, layer.useTwist); layer.twist = EditorGUILayout.FloatField(MegaToolTip.Twist, layer.twist); layer.twistCrv = EditorGUILayout.CurveField(MegaToolTip.TwistCrv, layer.twistCrv); EditorGUILayout.EndToggleGroup(); // Advanced layer.GlobalScale = EditorGUILayout.FloatField("Scale", layer.GlobalScale); layer.useCrossCrv = EditorGUILayout.BeginToggleGroup("Use Cross Crv", layer.useCrossCrv); layer.CrossCrv = EditorGUILayout.CurveField("Cross Crv", layer.CrossCrv); EditorGUILayout.EndToggleGroup(); // Start Info //layer.showstartparams = EditorGUILayout.Foldout(layer.showstartparams, "Start Params"); layer.showstartparams = MegaFoldOut.Start("Start Params", layer.showstartparams, new Color(1.0f, 0.5f, 0.5f)); if (layer.showstartparams) { //EditorGUILayout.BeginVertical("TextArea"); layer.StartEnabled = EditorGUILayout.Toggle("Enabled", layer.StartEnabled); Mesh startObj = (Mesh)EditorGUILayout.ObjectField("Mesh", layer.startObj, typeof(Mesh), true); if (startObj != layer.startObj) { layer.SetMesh(startObj, 0); } layer.StartOff = EditorGUILayout.Vector3Field("Offset", layer.StartOff); layer.StartScale = EditorGUILayout.Vector3Field("Scale", layer.StartScale); layer.StartGap = EditorGUILayout.FloatField("Gap", layer.StartGap); //EditorGUILayout.EndVertical(); } MegaFoldOut.End(layer.showstartparams); // Main Info //layer.showmainparams = EditorGUILayout.Foldout(layer.showmainparams, "Main Params"); layer.showmainparams = MegaFoldOut.Start("Main Params", layer.showmainparams, new Color(0.5f, 1.0f, 0.5f)); if (layer.showmainparams) { //EditorGUILayout.BeginVertical("TextArea"); layer.MainEnabled = EditorGUILayout.Toggle("Enabled", layer.MainEnabled); Mesh mainObj = (Mesh)EditorGUILayout.ObjectField("Mesh", layer.mainObj, typeof(Mesh), true); if (mainObj != layer.mainObj) { layer.SetMesh(mainObj, 1); } layer.MainOff = EditorGUILayout.Vector3Field("Offset", layer.MainOff); layer.MainScale = EditorGUILayout.Vector3Field("Scale", layer.MainScale); layer.Gap = EditorGUILayout.FloatField("Gap", layer.Gap); //EditorGUILayout.EndVertical(); } MegaFoldOut.End(layer.showmainparams); // End Info //layer.showendparams = EditorGUILayout.Foldout(layer.showendparams, "End Params"); layer.showendparams = MegaFoldOut.Start("End Params", layer.showendparams, new Color(0.5f, 0.5f, 1.0f)); if (layer.showendparams) { //EditorGUILayout.BeginVertical("TextArea"); layer.EndEnabled = EditorGUILayout.Toggle("Enabled", layer.EndEnabled); Mesh endObj = (Mesh)EditorGUILayout.ObjectField("Mesh", layer.endObj, typeof(Mesh), true); if (endObj != layer.endObj) { layer.SetMesh(endObj, 2); } layer.EndOff = EditorGUILayout.Vector3Field("Offset", layer.EndOff); layer.EndScale = EditorGUILayout.Vector3Field("Scale", layer.EndScale); layer.EndGap = EditorGUILayout.FloatField("Gap", layer.EndGap); //EditorGUILayout.EndVertical(); } MegaFoldOut.End(layer.showendparams); } //EditorGUILayout.EndVertical(); //MegaShapeLoftEditor.PopCols(); } EditorGUILayout.EndVertical(); MegaShapeLoftEditor.PopCols(); }