Exemplo n.º 1
0
    void CalcR(MegaAxis axis, float ang)
    {
        float len = 0.0f;

        if (!doRegion)
        {
            switch (axis)
            {
            case MegaAxis.X: len = Width; break;

            case MegaAxis.Z: len = Height; break;

            case MegaAxis.Y: len = Length; break;
            }
        }
        else
        {
            len = to - from;
        }

        if (Mathf.Abs(ang) < 0.000001f)
        {
            r = 0.0f;
        }
        else
        {
            r = len / ang;
        }
    }
Exemplo n.º 2
0
    void CalcBulge(MegaAxis axis, float stretch, float amplify)
    {
        amount    = stretch;
        amplifier = (amplify >= 0.0f) ? amplify + 1.0f : 1.0f / (-amplify + 1.0f);

        if (!doRegion)
        {
            switch (axis)
            {
            case MegaAxis.X:
                heightMin = -Width * 0.5f;
                heightMax = Width * 0.5f;
                break;

            case MegaAxis.Z:
                heightMin = 0.0f;
                heightMax = Height;
                break;

            case MegaAxis.Y:
                heightMin = -Length * 0.5f;
                heightMax = Length * 0.5f;
                break;
            }
        }
        else
        {
            heightMin = from;
            heightMax = to;
        }
    }
    // Virtual method for all mods
    public override void SetValues(MegaModifier mod)
    {
        MegaBend bm = (MegaBend)mod;

        dir  = bm.dir;
        axis = bm.axis;
    }
Exemplo n.º 4
0
	void CalcBulge(MegaAxis axis, float stretch, float amplify)
	{
		amount = stretch;
		amplifier = (amplify >= 0.0f) ? amplify + 1.0f : 1.0f / (-amplify + 1.0f);

		if ( !doRegion )
		{
			switch ( axis )
			{
				case MegaAxis.X:
				heightMin = bbox.min.x;
				heightMax = bbox.max.x;
				break;

				case MegaAxis.Z:
				heightMin = bbox.min.y;
				heightMax = bbox.max.y;
				break;

				case MegaAxis.Y:
				heightMin = bbox.min.z;
				heightMax = bbox.max.z;
				break;
			}
		}
		else
		{
			heightMin = from;
			heightMax = to;
		}
	}
Exemplo n.º 5
0
	void CalcBulge(MegaAxis axis, float stretch, float amplify)
	{
		amount = stretch;
		amplifier = (amplify >= 0.0f) ? amplify + 1.0f : 1.0f / (-amplify + 1.0f);

		if ( !doRegion )
		{
			switch ( axis )
			{
				case MegaAxis.X:
					heightMin = -Width * 0.5f;
					heightMax = Width * 0.5f;
					break;

				case MegaAxis.Z:
					heightMin = 0.0f;
					heightMax = Height;
					break;

				case MegaAxis.Y:
					heightMin = -Length * 0.5f;
					heightMax = Length * 0.5f;
					break;
			}
		}
		else
		{
			heightMin = from;
			heightMax = to;
		}
	}
Exemplo n.º 6
0
    void CalcR(MegaAxis axis, float ang)
    {
        float len = 0.0f;

        if (!doRegion)
        {
            switch (axis)
            {
            case MegaAxis.X: len = bbox.max.x - bbox.min.x; break;

            case MegaAxis.Z: len = bbox.max.y - bbox.min.y; break;

            case MegaAxis.Y: len = bbox.max.z - bbox.min.z; break;
            }
        }
        else
        {
            len = to - from;
        }

        if (Mathf.Abs(ang) < 0.000001f)
        {
            r = 0.0f;
        }
        else
        {
            r = len / ang;
        }
    }
Exemplo n.º 7
0
    public override bool Inspector()
    {
        MegaConformMod mod = (MegaConformMod)target;

#if !UNITY_5
        EditorGUIUtility.LookLikeControls();
#endif
        CommonModParamsBasic(mod);

        mod.target        = (GameObject)EditorGUILayout.ObjectField("Target", mod.target, typeof(GameObject), true);
        mod.conformAmount = EditorGUILayout.Slider("Conform Amount", mod.conformAmount, 0.0f, 1.0f);
        mod.raystartoff   = EditorGUILayout.FloatField("Ray Start Off", mod.raystartoff);
        mod.raydist       = EditorGUILayout.FloatField("Ray Dist", mod.raydist);
        mod.offset        = EditorGUILayout.FloatField("Offset", mod.offset);
        MegaAxis axis = (MegaAxis)EditorGUILayout.EnumPopup("Axis", mod.axis);
        if (axis != mod.axis)
        {
            mod.axis = axis;
            mod.ChangeAxis();
        }

        mod.useLocalDown = EditorGUILayout.BeginToggleGroup("Use Local Down", mod.useLocalDown);
        mod.flipDown     = EditorGUILayout.Toggle("Flip Down", mod.flipDown);
        mod.downAxis     = (MegaAxis)EditorGUILayout.EnumPopup("Down Axis", mod.downAxis);
        EditorGUILayout.EndToggleGroup();
        return(false);
    }
    void CalcBulge(MegaAxis axis, float stretch, float amplify)
    {
        amount    = stretch;
        amplifier = (amplify >= 0.0f) ? amplify + 1.0f : 1.0f / (-amplify + 1.0f);

        if (!doRegion)
        {
            switch (axis)
            {
            case MegaAxis.X:
                heightMin = bbox.min.x;
                heightMax = bbox.max.x;
                break;

            case MegaAxis.Z:
                heightMin = bbox.min.y;
                heightMax = bbox.max.y;
                break;

            case MegaAxis.Y:
                heightMin = bbox.min.z;
                heightMax = bbox.max.z;
                break;
            }
        }
        else
        {
            heightMin = from;
            heightMax = to;
        }

        ovh = 1.0f / (heightMax - heightMin);
    }
Exemplo n.º 9
0
	//public float	amplify = 1.0f;

	// Virtual method for all mods
	public override void SetValues(MegaModifier mod)
	{
		MegaBend bm = (MegaBend)mod;
		//angle = bm.angle;
		dir = bm.dir;
		axis = bm.axis;
	}
Exemplo n.º 10
0
	// Virtual method for all mods
	public override void SetValues(MegaModifier mod)
	{
		MegaBend bm = (MegaBend)mod;
		angle = bm.angle;
		dir = bm.dir;
		axis = bm.axis;
		doRegion = bm.doRegion;
		from = bm.from;
		to = bm.to;
	}
Exemplo n.º 11
0
    // Virtual method for all mods
    public override void SetValues(MegaModifier mod)
    {
        MegaBend bm = (MegaBend)mod;

        angle    = bm.angle;
        dir      = bm.dir;
        axis     = bm.axis;
        doRegion = bm.doRegion;
        from     = bm.from;
        to       = bm.to;
    }
Exemplo n.º 12
0
	void CalcHeight(MegaAxis axis, float angle)
	{
		switch ( axis )
		{
			case MegaAxis.X: height = Width; break;
			case MegaAxis.Z: height = Height; break;
			case MegaAxis.Y: height = Length; break;
		}

		if ( height == 0.0f )
		{
			theAngle = 0.0f;
			angleOverHeight = 0.0f;
		}
		else
		{
			theAngle = angle;
			angleOverHeight = angle / height;
		}
	}
Exemplo n.º 13
0
	void CalcHeight(MegaAxis axis, float angle, MegaBox3 bbx)
	{
		switch ( axis )
		{
			case MegaAxis.X:	height = bbx.max.x - bbx.min.x;	break;
			case MegaAxis.Z:	height = bbx.max.y - bbx.min.y;	break;
			case MegaAxis.Y:	height = bbx.max.z - bbx.min.z;	break;
		}
	
		if ( height == 0.0f )
		{
			theAngle = 0.0f;
			angleOverHeight = 0.0f;
		}
		else
		{
			theAngle = angle;
			angleOverHeight = angle / height;
		}
	}
Exemplo n.º 14
0
	void CalcR(MegaAxis axis, float ang)
	{
		float len = 0.0f;

		if ( !doRegion )
		{
			switch ( axis )
			{
				case MegaAxis.X: len = bbox.max.x - bbox.min.x; break;
				case MegaAxis.Z: len = bbox.max.y - bbox.min.y; break;
				case MegaAxis.Y: len = bbox.max.z - bbox.min.z; break;
			}
		}
		else
			len = to - from;

		if ( Mathf.Abs(ang) < 0.000001f )
			r = 0.0f;
		else
			r = len / ang;
	}
Exemplo n.º 15
0
	void CalcR(MegaAxis axis, float ang)
	{
		float len = 0.0f;

		if ( !doRegion )
		{
			switch ( axis )
			{
				case MegaAxis.X: len = Width; break;
				case MegaAxis.Z: len = Height; break;
				case MegaAxis.Y: len = Length; break;
			}
		}
		else
			len = to - from;

		if ( Mathf.Abs(ang) < 0.000001f )
			r = 0.0f;
		else
			r = len / ang;
	}
Exemplo n.º 16
0
    // Put common params in, and each shape has its sections
    void OnGUI()
    {
        scroll = EditorGUILayout.BeginScrollView(scroll);

        //name = EditorGUILayout.TextField("Name", name);

        toolbarInt = GUILayout.Toolbar(toolbarInt, toolbarStrings, GUILayout.MaxWidth(150.0f));

        float butwidth = 80.0f;
        float width    = this.position.width;           // / 2.0f;

        int bstep = (int)(width / butwidth);

        if (bstep == 0)
        {
            bstep = 1;
        }

        if (toolbarInt == 0)
        {
            DoButtons(mods, (width / bstep) - 6.0f, bstep, true);
        }
        else
        {
            //showcommon = EditorGUILayout.Foldout(showcommon, "Common");

            //if ( showcommon )
            {
                axis        = (MegaAxis)EditorGUILayout.EnumPopup("Axis", axis);
                stepdist    = EditorGUILayout.FloatField("Step Dist", stepdist);
                knotsize    = EditorGUILayout.FloatField("Knot Size", knotsize);
                drawknots   = EditorGUILayout.Toggle("Draw Knots", drawknots);
                drawhandles = EditorGUILayout.Toggle("Draw Handles", drawhandles);
                col1        = EditorGUILayout.ColorField("Color 1", col1);
                col2        = EditorGUILayout.ColorField("Color 2", col2);
                makemesh    = EditorGUILayout.Toggle("Make Mesh", makemesh);
            }
        }
        EditorGUILayout.EndScrollView();
    }
Exemplo n.º 17
0
    void CalcHeight(MegaAxis axis, float angle)
    {
        switch (axis)
        {
        case MegaAxis.X: height = Width; break;

        case MegaAxis.Z: height = Height; break;

        case MegaAxis.Y: height = Length; break;
        }

        if (height == 0.0f)
        {
            theAngle        = 0.0f;
            angleOverHeight = 0.0f;
        }
        else
        {
            theAngle        = angle;
            angleOverHeight = angle / height;
        }
    }
Exemplo n.º 18
0
    void CalcHeight(MegaAxis axis, float angle, MegaBox3 bbx)
    {
        switch (axis)
        {
        case MegaAxis.X:        height = bbx.max.x - bbx.min.x; break;

        case MegaAxis.Z:        height = bbx.max.y - bbx.min.y; break;

        case MegaAxis.Y:        height = bbx.max.z - bbx.min.z; break;
        }

        if (height == 0.0f)
        {
            theAngle        = 0.0f;
            angleOverHeight = 0.0f;
        }
        else
        {
            theAngle        = angle;
            angleOverHeight = angle / height;
        }
    }
Exemplo n.º 19
0
	Vector3 SwapAxis(Vector3 val, MegaAxis axis)
	{
		float v = 0.0f;
		switch ( axis )
		{
			case MegaAxis.X:
				v = val.x;
				val.x = val.y;
				val.y = v;
				break;

			case MegaAxis.Y:
				break;

			case MegaAxis.Z:
				v = val.y;
				val.y = val.z;
				val.z = v;
				break;
		}

		return val;
	}
Exemplo n.º 20
0
    Vector3 SwapAxis(Vector3 val, MegaAxis axis)
    {
        float v = 0.0f;

        switch (axis)
        {
        case MegaAxis.X:
            v     = val.x;
            val.x = val.y;
            val.y = v;
            break;

        case MegaAxis.Y:
            break;

        case MegaAxis.Z:
            v     = val.y;
            val.y = val.z;
            val.z = v;
            break;
        }

        return(val);
    }
Exemplo n.º 21
0
    public void DrawFromTo(MegaAxis axis, float from, float to, MegaModContext mc)
    {
        Vector3 min = mc.bbox.min;
        Vector3 max = mc.bbox.max;

        switch (axis)
        {
        case MegaAxis.X:
            corners[0] = new Vector3(-from, min.y, min.z);
            corners[1] = new Vector3(-from, max.y, min.z);
            corners[2] = new Vector3(-from, max.y, max.z);
            corners[3] = new Vector3(-from, min.y, max.z);

            corners[4] = new Vector3(-to, min.y, min.z);
            corners[5] = new Vector3(-to, max.y, min.z);
            corners[6] = new Vector3(-to, max.y, max.z);
            corners[7] = new Vector3(-to, min.y, max.z);
            break;

        case MegaAxis.Y:
            corners[0] = new Vector3(min.x, min.y, -from);
            corners[1] = new Vector3(min.x, max.y, -from);
            corners[2] = new Vector3(max.x, max.y, -from);
            corners[3] = new Vector3(max.x, min.y, -from);

            corners[4] = new Vector3(min.x, min.y, -to);
            corners[5] = new Vector3(min.x, max.y, -to);
            corners[6] = new Vector3(max.x, max.y, -to);
            corners[7] = new Vector3(max.x, min.y, -to);
            break;

        case MegaAxis.Z:
            corners[0] = new Vector3(min.x, from, min.z);
            corners[1] = new Vector3(min.x, from, max.z);
            corners[2] = new Vector3(max.x, from, max.z);
            corners[3] = new Vector3(max.x, from, min.z);

            corners[4] = new Vector3(min.x, to, min.z);
            corners[5] = new Vector3(min.x, to, max.z);
            corners[6] = new Vector3(max.x, to, max.z);
            corners[7] = new Vector3(max.x, to, min.z);
            break;
        }

        Color c = Color.red;

        c.a          = gizCol1.a;
        Gizmos.color = c;

        Vector3 offset = Vector3.zero;          //mc.Offset;

        DrawEdgeCol(corners[0] - offset, corners[1] - offset);
        DrawEdgeCol(corners[1] - offset, corners[2] - offset);
        DrawEdgeCol(corners[2] - offset, corners[3] - offset);
        DrawEdgeCol(corners[3] - offset, corners[0] - offset);

        c            = Color.green;
        c.a          = gizCol1.a;
        Gizmos.color = c;

        DrawEdgeCol(corners[4] - offset, corners[5] - offset);
        DrawEdgeCol(corners[5] - offset, corners[6] - offset);
        DrawEdgeCol(corners[6] - offset, corners[7] - offset);
        DrawEdgeCol(corners[7] - offset, corners[4] - offset);
    }
Exemplo n.º 22
0
    public override void OnInspectorGUI()
    {
        bool      buildmesh = false;
        MegaShape shape     = (MegaShape)target;

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Add Knot"))
        {
            if (shape.splines == null || shape.splines.Count == 0)
            {
                MegaSpline spline = new MegaSpline();                   // Have methods for these
                shape.splines.Add(spline);
            }

            //Undo.RegisterUndo(target, "Add Knot");

            MegaKnot knot = new MegaKnot();
#if true
            // Add a point at CursorPos

            //sp = selected + 1;
            //Debug.Log("CursorPos " + CursorPos + " CursorKnot " + CursorKnot);
            float per = CursorPercent * 0.01f;

            CursorTangent = shape.splines[0].Interpolate(per + 0.01f, true, ref CursorKnot);    //this.GetPositionOnSpline(i) - p;
            CursorPos     = shape.splines[0].Interpolate(per, true, ref CursorKnot);            //this.GetPositionOnSpline(i) - p;

            knot.p = CursorPos;
            //CursorTangent =
            //Vector3 t = shape.splines[0].knots[selected].Interpolate(0.51f, shape.splines[0].knots[0]);
            knot.outvec = (CursorTangent - knot.p);
            knot.outvec.Normalize();
            knot.outvec *= shape.splines[0].knots[CursorKnot].seglength * 0.25f;
            knot.invec   = -knot.outvec;
            knot.invec  += knot.p;
            knot.outvec += knot.p;

            shape.splines[0].knots.Insert(CursorKnot + 1, knot);
#else
            int sp = 0;

            if (selected == -1 || shape.splines[0].knots.Count == 1)
            {
                shape.splines[0].knots.Add(knot);
                selected = shape.splines[0].knots.Count - 1;
            }
            else
            {
                if (selected < shape.splines[0].knots.Count - 1)
                {
                    sp     = selected + 1;
                    knot.p = shape.splines[0].knots[selected].Interpolate(0.5f, shape.splines[0].knots[selected + 1]);
                    Vector3 t = shape.splines[0].knots[selected].Interpolate(0.51f, shape.splines[0].knots[selected + 1]);
                    knot.outvec = (t - knot.p);                         //.Normalize();
                    knot.outvec.Normalize();
                    knot.outvec *= shape.splines[0].knots[selected].seglength * 0.25f;
                    knot.invec   = -knot.outvec;
                    knot.invec  += knot.p;
                    knot.outvec += knot.p;
                }
                else
                {
                    if (shape.splines[0].closed)
                    {
                        sp     = selected + 1;
                        knot.p = shape.splines[0].knots[selected].Interpolate(0.5f, shape.splines[0].knots[0]);
                        Vector3 t = shape.splines[0].knots[selected].Interpolate(0.51f, shape.splines[0].knots[0]);
                        knot.outvec = (t - knot.p);                             //.Normalize();
                        knot.outvec.Normalize();
                        knot.outvec *= shape.splines[0].knots[selected].seglength * 0.25f;
                        knot.invec   = -knot.outvec;
                        knot.invec  += knot.p;
                        knot.outvec += knot.p;
                    }
                    else
                    {
                        sp = selected - 1;

                        //Debug.Log("selected " + selected + " count " + shape.splines[0].knots.Count + " sp " + sp);
                        knot.p = shape.splines[0].knots[sp].Interpolate(0.5f, shape.splines[0].knots[sp + 1]);
                        Vector3 t = shape.splines[0].knots[sp].Interpolate(0.51f, shape.splines[0].knots[sp + 1]);
                        knot.outvec = (t - knot.p);                             //.Normalize();
                        knot.outvec.Normalize();
                        knot.outvec *= shape.splines[0].knots[sp].seglength * 0.25f;
                        knot.invec   = -knot.outvec;
                        knot.invec  += knot.p;
                        knot.outvec += knot.p;
                        sp++;
                    }
                }

                shape.splines[0].knots.Insert(sp, knot);
                selected = sp;                  //++;
            }
#endif
            shape.CalcLength(10);
            EditorUtility.SetDirty(target);
            buildmesh = true;
        }

        if (GUILayout.Button("Delete Knot"))
        {
            if (selected != -1)
            {
                //Undo.RegisterUndo(target, "Delete Knot");
                shape.splines[0].knots.RemoveAt(selected);
                selected--;
                shape.CalcLength(10);
            }
            EditorUtility.SetDirty(target);
            buildmesh = true;
        }

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Match Handles"))
        {
            if (selected != -1)
            {
                //Undo.RegisterUndo(target, "Match Handles");

                Vector3 p = shape.splines[0].knots[selected].p;
                Vector3 d = shape.splines[0].knots[selected].outvec - p;
                shape.splines[0].knots[selected].invec = p - d;
                shape.CalcLength(10);
            }
            EditorUtility.SetDirty(target);
            buildmesh = true;
        }

        if (GUILayout.Button("Load"))
        {
            // Load a spl file from max, so delete everything and replace
            LoadShape(ImportScale);
            buildmesh = true;
        }

        EditorGUILayout.EndHorizontal();

        showcommon = EditorGUILayout.Foldout(showcommon, "Common Params");

        bool rebuild = false;           //Params();

        if (showcommon)
        {
            //CursorPos = EditorGUILayout.Vector3Field("Cursor", CursorPos);
            CursorPercent = EditorGUILayout.FloatField("Cursor", CursorPercent);
            CursorPercent = Mathf.Repeat(CursorPercent, 100.0f);

            ImportScale = EditorGUILayout.FloatField("Import Scale", ImportScale);

            MegaAxis av = (MegaAxis)EditorGUILayout.EnumPopup("Axis", shape.axis);
            if (av != shape.axis)
            {
                shape.axis = av;
                rebuild    = true;
            }

            shape.col1 = EditorGUILayout.ColorField("Col 1", shape.col1);
            shape.col2 = EditorGUILayout.ColorField("Col 2", shape.col2);

            shape.KnotCol   = EditorGUILayout.ColorField("Knot Col", shape.KnotCol);
            shape.HandleCol = EditorGUILayout.ColorField("Handle Col", shape.HandleCol);
            shape.VecCol    = EditorGUILayout.ColorField("Vec Col", shape.VecCol);

            shape.KnotSize = EditorGUILayout.FloatField("Knot Size", shape.KnotSize);
            shape.stepdist = EditorGUILayout.FloatField("Step Dist", shape.stepdist);

            if (shape.stepdist < 0.01f)
            {
                shape.stepdist = 0.01f;
            }

            shape.normalizedInterp = EditorGUILayout.Toggle("Normalized Interp", shape.normalizedInterp);
            shape.drawHandles      = EditorGUILayout.Toggle("Draw Handles", shape.drawHandles);
            shape.drawKnots        = EditorGUILayout.Toggle("Draw Knots", shape.drawKnots);
            shape.drawspline       = EditorGUILayout.Toggle("Draw Spline", shape.drawspline);
            shape.lockhandles      = EditorGUILayout.Toggle("Lock Handles", shape.lockhandles);

            shape.animate = EditorGUILayout.Toggle("Animate", shape.animate);
            if (shape.animate)
            {
                shape.time     = EditorGUILayout.FloatField("Time", shape.time);
                shape.MaxTime  = EditorGUILayout.FloatField("Loop Time", shape.MaxTime);
                shape.speed    = EditorGUILayout.FloatField("Speed", shape.speed);
                shape.LoopMode = (MegaRepeatMode)EditorGUILayout.EnumPopup("Loop Mode", shape.LoopMode);
            }

            // Mesher
            shape.makeMesh = EditorGUILayout.Toggle("Make Mesh", shape.makeMesh);

            if (shape.makeMesh)
            {
                shape.meshType = (MeshShapeType)EditorGUILayout.EnumPopup("Mesh Type", shape.meshType);

                shape.Pivot = EditorGUILayout.Vector3Field("Pivot", shape.Pivot);

                shape.CalcTangents = EditorGUILayout.Toggle("Calc Tangents", shape.CalcTangents);
                shape.GenUV        = EditorGUILayout.Toggle("Gen UV", shape.GenUV);
                shape.PhysUV       = EditorGUILayout.Toggle("Physical UV", shape.PhysUV);
                shape.UVOffset     = EditorGUILayout.Vector2Field("UV Offset", shape.UVOffset);
                shape.UVRotate     = EditorGUILayout.Vector2Field("UV Rotate", shape.UVRotate);
                shape.UVScale      = EditorGUILayout.Vector2Field("UV Scale", shape.UVScale);
                shape.UVOffset1    = EditorGUILayout.Vector2Field("UV Offset1", shape.UVOffset1);
                shape.UVRotate1    = EditorGUILayout.Vector2Field("UV Rotate1", shape.UVRotate1);
                shape.UVScale1     = EditorGUILayout.Vector2Field("UV Scale1", shape.UVScale1);

                switch (shape.meshType)
                {
                case MeshShapeType.Fill:
                    shape.DoubleSided    = EditorGUILayout.Toggle("Double Sided", shape.DoubleSided);
                    shape.Height         = EditorGUILayout.FloatField("Height", shape.Height);
                    shape.HeightSegs     = EditorGUILayout.IntField("HeightSegs", shape.HeightSegs);
                    shape.UseHeightCurve = EditorGUILayout.Toggle("Use Height Crv", shape.UseHeightCurve);
                    if (shape.UseHeightCurve)
                    {
                        shape.heightCrv = EditorGUILayout.CurveField("Height Curve", shape.heightCrv);
                    }
                    break;

                case MeshShapeType.Line:
                    shape.DoubleSided = EditorGUILayout.Toggle("Double Sided", shape.DoubleSided);
                    shape.Height      = EditorGUILayout.FloatField("Height", shape.Height);
                    shape.HeightSegs  = EditorGUILayout.IntField("HeightSegs", shape.HeightSegs);
                    shape.heightCrv   = EditorGUILayout.CurveField("Height Curve", shape.heightCrv);
                    shape.Start       = EditorGUILayout.FloatField("Start", shape.Start);
                    shape.End         = EditorGUILayout.FloatField("End", shape.End);
                    shape.Rotate      = EditorGUILayout.FloatField("Rotate", shape.Rotate);
                    break;

                case MeshShapeType.Tube:
                    shape.Sides    = EditorGUILayout.IntField("Sides", shape.Sides);
                    shape.TubeStep = EditorGUILayout.FloatField("TubeStep", shape.TubeStep);
                    shape.Start    = EditorGUILayout.FloatField("Start", shape.Start);
                    shape.End      = EditorGUILayout.FloatField("End", shape.End);
                    break;
                }
            }

            showsplines = EditorGUILayout.Foldout(showsplines, "Splines");

            if (showsplines)
            {
                for (int i = 0; i < shape.splines.Count; i++)
                {
                    DisplaySpline(shape, shape.splines[i]);
                }
            }
        }

        if (Params())
        {
            rebuild = true;
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
            //shape.CalcLength(10);
            buildmesh = true;
        }

        if (rebuild)
        {
            shape.MakeShape();
            EditorUtility.SetDirty(target);
            buildmesh = true;
        }

        if (buildmesh)
        {
            shape.BuildMesh();
        }
    }
Exemplo n.º 23
0
	public override void OnInspectorGUI()
	{
		//undoManager.CheckUndo();
		bool buildmesh = false;
		bool recalc = false;
		MegaShape shape = (MegaShape)target;

		EditorGUILayout.BeginHorizontal();

		int curve = shape.selcurve;

		if ( GUILayout.Button("Add Knot") )
		{
			if ( shape.splines == null || shape.splines.Count == 0 )
			{
				MegaSpline spline = new MegaSpline();	// Have methods for these
				shape.splines.Add(spline);
			}

			MegaKnot knot = new MegaKnot();
			float per = shape.CursorPercent * 0.01f;

			CursorTangent = shape.splines[curve].Interpolate(per + 0.01f, true, ref CursorKnot);	//this.GetPositionOnSpline(i) - p;
			CursorPos = shape.splines[curve].Interpolate(per, true, ref CursorKnot);	//this.GetPositionOnSpline(i) - p;

			knot.p = CursorPos;
			knot.outvec = (CursorTangent - knot.p);
			knot.outvec.Normalize();
			knot.outvec *= shape.splines[curve].knots[CursorKnot].seglength * 0.25f;
			knot.invec = -knot.outvec;
			knot.invec += knot.p;
			knot.outvec += knot.p;
			knot.twist = shape.splines[curve].knots[CursorKnot].twist;
			knot.id = shape.splines[curve].knots[CursorKnot].id;

			shape.splines[curve].knots.Insert(CursorKnot + 1, knot);
			shape.CalcLength();	//10);
			EditorUtility.SetDirty(target);
			buildmesh = true;
		}

		if ( GUILayout.Button("Delete Knot") )
		{
			if ( selected != -1 )
			{
				shape.splines[curve].knots.RemoveAt(selected);
				selected--;
				shape.CalcLength();	//10);
			}
			EditorUtility.SetDirty(target);
			buildmesh = true;
		}
		
		EditorGUILayout.EndHorizontal();
		EditorGUILayout.BeginHorizontal();

		if ( GUILayout.Button("Match Handles") )
		{
			if ( selected != -1 )
			{
				Vector3 p = shape.splines[curve].knots[selected].p;
				Vector3 d = shape.splines[curve].knots[selected].outvec - p;
				shape.splines[curve].knots[selected].invec = p - d;
				shape.CalcLength();	//10);
			}
			EditorUtility.SetDirty(target);
			buildmesh = true;
		}

		if ( GUILayout.Button("Load") )
		{
			LoadShape(ImportScale);
			buildmesh = true;
		}

		if ( GUILayout.Button("Load SXL") )
		{
			LoadSXL(ImportScale);
			buildmesh = true;
		}

		if ( GUILayout.Button("Load KML") )
		{
			LoadKML(ImportScale);
			buildmesh = true;
		}

		EditorGUILayout.EndHorizontal();

		EditorGUILayout.BeginHorizontal();
		if ( GUILayout.Button("AutoCurve") )
		{
			shape.AutoCurve();
			EditorUtility.SetDirty(target);
			buildmesh = true;
		}

		if ( GUILayout.Button("Reverse") )
		{
			shape.Reverse(curve);
			//shape.CalcLength();
			EditorUtility.SetDirty(target);
			buildmesh = true;
		}

		EditorGUILayout.EndHorizontal();

		if ( GUILayout.Button("Centre Shape") )
		{
			shape.Centre(1.0f, Vector3.one);
		}

		if ( GUILayout.Button("Apply Scaling") )
		{
			shape.Scale(shape.transform.localScale);
			EditorUtility.SetDirty(target);
			shape.transform.localScale = Vector3.one;
			buildmesh = true;
		}

		if ( GUILayout.Button("Import SVG") )
		{
			LoadSVG(ImportScale);
			buildmesh = true;
		}

		showcommon = EditorGUILayout.Foldout(showcommon, "Common Params");

		bool rebuild = false;	//Params();

		if ( showcommon )
		{
			shape.CursorPercent = EditorGUILayout.FloatField("Cursor", shape.CursorPercent);
			shape.CursorPercent = Mathf.Repeat(shape.CursorPercent, 100.0f);

			ImportScale = EditorGUILayout.FloatField("Import Scale", ImportScale);

			MegaAxis av = (MegaAxis)EditorGUILayout.EnumPopup("Axis", shape.axis);
			if ( av != shape.axis )
			{
				shape.axis = av;
				rebuild = true;
			}

			if ( shape.splines.Count > 1 )
				shape.selcurve = EditorGUILayout.IntSlider("Curve", shape.selcurve, 0, shape.splines.Count - 1);

			if ( shape.selcurve < 0 )
				shape.selcurve = 0;

			if ( shape.selcurve > shape.splines.Count - 1 )
				shape.selcurve = shape.splines.Count - 1;

			EditorGUILayout.BeginHorizontal();
			EditorGUILayout.LabelField("Colors");
			shape.col1 = EditorGUILayout.ColorField(shape.col1);
			shape.col2 = EditorGUILayout.ColorField(shape.col2);
			EditorGUILayout.EndHorizontal();

			shape.VecCol = EditorGUILayout.ColorField("Vec Col", shape.VecCol);

			shape.KnotSize = EditorGUILayout.FloatField("Knot Size", shape.KnotSize);
			shape.stepdist = EditorGUILayout.FloatField("Step Dist", shape.stepdist);

			MegaSpline spline = shape.splines[shape.selcurve];

			if ( shape.stepdist < 0.01f )
				shape.stepdist = 0.01f;

			shape.dolateupdate = EditorGUILayout.Toggle("Do Late Update", shape.dolateupdate);
			shape.normalizedInterp = EditorGUILayout.Toggle("Normalized Interp", shape.normalizedInterp);

			spline.constantSpeed = EditorGUILayout.Toggle("Constant Speed", spline.constantSpeed);
			int subdivs = EditorGUILayout.IntField("Calc Subdivs", spline.subdivs);

			if ( subdivs < 2 )
				subdivs = 2;
			if ( subdivs != spline.subdivs )
				spline.CalcLength(subdivs);

			shape.drawHandles = EditorGUILayout.Toggle("Draw Handles", shape.drawHandles);
			shape.drawKnots = EditorGUILayout.Toggle("Draw Knots", shape.drawKnots);
			shape.drawTwist = EditorGUILayout.Toggle("Draw Twist", shape.drawTwist);
			shape.drawspline = EditorGUILayout.Toggle("Draw Spline", shape.drawspline);
			shape.showorigin = EditorGUILayout.Toggle("Origin Handle", shape.showorigin);
			shape.lockhandles = EditorGUILayout.Toggle("Lock Handles", shape.lockhandles);
			shape.updateondrag = EditorGUILayout.Toggle("Update On Drag", shape.updateondrag);

			shape.usesnap = EditorGUILayout.BeginToggleGroup("Use Snap", shape.usesnap);
			shape.usesnaphandles = EditorGUILayout.Toggle("Snap Handles", shape.usesnaphandles);
			shape.snap = EditorGUILayout.Vector3Field("Snap", shape.snap);
			if ( shape.snap.x < 0.0f ) shape.snap.x = 0.0f;
			if ( shape.snap.y < 0.0f ) shape.snap.y = 0.0f;
			if ( shape.snap.z < 0.0f ) shape.snap.z = 0.0f;
			EditorGUILayout.EndToggleGroup();

			//shape.autosmooth = EditorGUILayout.Toggle("Auto Smooth", shape.autosmooth);
			//shape.smoothness = EditorGUILayout.FloatField("Smoothness", shape.smoothness);
			float smoothness = EditorGUILayout.Slider("Smoothness", shape.smoothness, 0.0f, 1.5f);
			if ( smoothness != shape.smoothness )
			{
				shape.smoothness = smoothness;
				shape.AutoCurve();
				recalc = true;
			}

			shape.handleType = (MegaHandleType)EditorGUILayout.EnumPopup("Handle Type", shape.handleType);

			showlabels = EditorGUILayout.Toggle("Labels", showlabels);

			bool hidewire1 = EditorGUILayout.Toggle("Hide Wire", hidewire);

			if ( hidewire1 != hidewire )
			{
				hidewire = hidewire1;
				EditorUtility.SetSelectedWireframeHidden(shape.GetComponent<Renderer>(), hidewire);
			}

			shape.animate = EditorGUILayout.Toggle("Animate", shape.animate);
			if ( shape.animate )
			{
				shape.time = EditorGUILayout.FloatField("Time", shape.time);
				shape.MaxTime = EditorGUILayout.FloatField("Loop Time", shape.MaxTime);
				shape.speed = EditorGUILayout.FloatField("Speed", shape.speed);
				shape.LoopMode = (MegaRepeatMode)EditorGUILayout.EnumPopup("Loop Mode", shape.LoopMode);
			}

			AnimationKeyFrames(shape);

			if ( shape.splines.Count > 0 )
			{
				if ( spline.outlineSpline != -1 )
				{
					int outlineSpline = EditorGUILayout.IntSlider("Outline Spl", spline.outlineSpline, 0, shape.splines.Count - 1);
					float outline = EditorGUILayout.FloatField("Outline", spline.outline);

					if ( outline != spline.outline || outlineSpline != spline.outlineSpline )
					{
						spline.outlineSpline = outlineSpline;
						spline.outline = outline;
						if ( outlineSpline != shape.selcurve )
						{
							shape.OutlineSpline(shape.splines[spline.outlineSpline], spline, spline.outline, true);
							spline.CalcLength();	//10);
							EditorUtility.SetDirty(target);
							buildmesh = true;
						}
					}
				}
				else
				{
					outline = EditorGUILayout.FloatField("Outline", outline);

					if ( GUILayout.Button("Outline") )
					{
						shape.OutlineSpline(shape, shape.selcurve, outline, true);
						shape.splines[shape.splines.Count - 1].outline = outline;
						shape.splines[shape.splines.Count - 1].outlineSpline = shape.selcurve;
						shape.selcurve = shape.splines.Count - 1;
						EditorUtility.SetDirty(target);
						buildmesh = true;
					}
				}
			}

			// Mesher
			shape.makeMesh = EditorGUILayout.Toggle("Make Mesh", shape.makeMesh);

			if ( shape.makeMesh )
			{
				shape.meshType = (MeshShapeType)EditorGUILayout.EnumPopup("Mesh Type", shape.meshType);
				shape.Pivot = EditorGUILayout.Vector3Field("Pivot", shape.Pivot);

				shape.CalcTangents = EditorGUILayout.Toggle("Calc Tangents", shape.CalcTangents);
				shape.GenUV = EditorGUILayout.Toggle("Gen UV", shape.GenUV);

				if ( GUILayout.Button("Build LightMap") )
				{
					MegaShapeLightMapWindow.Init();
				}

				EditorGUILayout.BeginVertical("Box");
				switch ( shape.meshType )
				{
					case MeshShapeType.Fill:
						shape.DoubleSided = EditorGUILayout.Toggle("Double Sided", shape.DoubleSided);
						shape.Height = EditorGUILayout.FloatField("Height", shape.Height);
						shape.UseHeightCurve = EditorGUILayout.Toggle("Use Height Crv", shape.UseHeightCurve);
						if ( shape.UseHeightCurve )
						{
							shape.heightCrv = EditorGUILayout.CurveField("Height Curve", shape.heightCrv);
							shape.heightOff = EditorGUILayout.Slider("Height Off", shape.heightOff, -1.0f, 1.0f);
						}
						shape.mat1 = (Material)EditorGUILayout.ObjectField("Top Mat", shape.mat1, typeof(Material), true);
						shape.mat2 = (Material)EditorGUILayout.ObjectField("Bot Mat", shape.mat2, typeof(Material), true);
						shape.mat3 = (Material)EditorGUILayout.ObjectField("Side Mat", shape.mat3, typeof(Material), true);

						shape.PhysUV = EditorGUILayout.Toggle("Physical UV", shape.PhysUV);
						shape.UVOffset = EditorGUILayout.Vector2Field("UV Offset", shape.UVOffset);
						shape.UVRotate = EditorGUILayout.Vector2Field("UV Rotate", shape.UVRotate);
						shape.UVScale = EditorGUILayout.Vector2Field("UV Scale", shape.UVScale);
						shape.UVOffset1 = EditorGUILayout.Vector2Field("UV Offset1", shape.UVOffset1);
						shape.UVRotate1 = EditorGUILayout.Vector2Field("UV Rotate1", shape.UVRotate1);
						shape.UVScale1 = EditorGUILayout.Vector2Field("UV Scale1", shape.UVScale1);
						break;

					case MeshShapeType.Tube:
						shape.TubeStart = EditorGUILayout.Slider("Start", shape.TubeStart, -1.0f, 2.0f);
						shape.TubeLength = EditorGUILayout.Slider("Length", shape.TubeLength, 0.0f, 1.0f);
						shape.rotate = EditorGUILayout.FloatField("Rotate", shape.rotate);
						shape.tsides = EditorGUILayout.IntField("Sides", shape.tsides);
						shape.tradius = EditorGUILayout.FloatField("Radius", shape.tradius);
						shape.offset = EditorGUILayout.FloatField("Offset", shape.offset);

						shape.scaleX = EditorGUILayout.CurveField("Scale X", shape.scaleX);
						shape.unlinkScale = EditorGUILayout.BeginToggleGroup("unlink Scale", shape.unlinkScale);
						shape.scaleY = EditorGUILayout.CurveField("Scale Y", shape.scaleY);
						EditorGUILayout.EndToggleGroup();

						shape.strands = EditorGUILayout.IntField("Strands", shape.strands);
						if ( shape.strands > 1 )
						{
							shape.strandRadius = EditorGUILayout.FloatField("Strand Radius", shape.strandRadius);
							shape.TwistPerUnit = EditorGUILayout.FloatField("Twist", shape.TwistPerUnit);
							shape.startAng = EditorGUILayout.FloatField("Start Twist", shape.startAng);
						}
						shape.UVOffset = EditorGUILayout.Vector2Field("UV Offset", shape.UVOffset);
						shape.uvtilex = EditorGUILayout.FloatField("UV Tile X", shape.uvtilex);
						shape.uvtiley = EditorGUILayout.FloatField("UV Tile Y", shape.uvtiley);

						shape.cap = EditorGUILayout.Toggle("Cap", shape.cap);
						shape.RopeUp = (MegaAxis)EditorGUILayout.EnumPopup("Up", shape.RopeUp);
						shape.mat1 = (Material)EditorGUILayout.ObjectField("Mat", shape.mat1, typeof(Material), true);
						shape.flipNormals = EditorGUILayout.Toggle("Flip Normals", shape.flipNormals);
						break;

					case MeshShapeType.Ribbon:
						shape.TubeStart = EditorGUILayout.Slider("Start", shape.TubeStart, -1.0f, 2.0f);
						shape.TubeLength = EditorGUILayout.Slider("Length", shape.TubeLength, 0.0f, 1.0f);
						shape.boxwidth = EditorGUILayout.FloatField("Width", shape.boxwidth);
						shape.raxis = (MegaAxis)EditorGUILayout.EnumPopup("Axis", shape.raxis);
						shape.rotate = EditorGUILayout.FloatField("Rotate", shape.rotate);
						shape.ribsegs = EditorGUILayout.IntField("Segs", shape.ribsegs);
						if ( shape.ribsegs < 1 )
							shape.ribsegs = 1;
						shape.offset = EditorGUILayout.FloatField("Offset", shape.offset);

						shape.scaleX = EditorGUILayout.CurveField("Scale X", shape.scaleX);

						shape.strands = EditorGUILayout.IntField("Strands", shape.strands);
						if ( shape.strands > 1 )
						{
							shape.strandRadius = EditorGUILayout.FloatField("Strand Radius", shape.strandRadius);
							shape.TwistPerUnit = EditorGUILayout.FloatField("Twist", shape.TwistPerUnit);
							shape.startAng = EditorGUILayout.FloatField("Start Twist", shape.startAng);
						}

						shape.UVOffset = EditorGUILayout.Vector2Field("UV Offset", shape.UVOffset);
						shape.uvtilex = EditorGUILayout.FloatField("UV Tile X", shape.uvtilex);
						shape.uvtiley = EditorGUILayout.FloatField("UV Tile Y", shape.uvtiley);

						shape.RopeUp = (MegaAxis)EditorGUILayout.EnumPopup("Up", shape.RopeUp);
						shape.mat1 = (Material)EditorGUILayout.ObjectField("Mat", shape.mat1, typeof(Material), true);
						shape.flipNormals = EditorGUILayout.Toggle("Flip Normals", shape.flipNormals);
						break;

					case MeshShapeType.Box:
						shape.TubeStart = EditorGUILayout.Slider("Start", shape.TubeStart, -1.0f, 2.0f);
						shape.TubeLength = EditorGUILayout.Slider("Length", shape.TubeLength, 0.0f, 1.0f);
						shape.rotate = EditorGUILayout.FloatField("Rotate", shape.rotate);
						shape.boxwidth = EditorGUILayout.FloatField("Box Width", shape.boxwidth);
						shape.boxheight = EditorGUILayout.FloatField("Box Height", shape.boxheight);
						shape.offset = EditorGUILayout.FloatField("Offset", shape.offset);

						shape.scaleX = EditorGUILayout.CurveField("Scale X", shape.scaleX);
						shape.unlinkScale = EditorGUILayout.BeginToggleGroup("unlink Scale", shape.unlinkScale);
						shape.scaleY = EditorGUILayout.CurveField("Scale Y", shape.scaleY);
						EditorGUILayout.EndToggleGroup();

						shape.strands = EditorGUILayout.IntField("Strands", shape.strands);
						if ( shape.strands > 1 )
						{
							shape.tradius = EditorGUILayout.FloatField("Radius", shape.tradius);
							shape.TwistPerUnit = EditorGUILayout.FloatField("Twist", shape.TwistPerUnit);
							shape.startAng = EditorGUILayout.FloatField("Start Twist", shape.startAng);
						}

						shape.UVOffset = EditorGUILayout.Vector2Field("UV Offset", shape.UVOffset);
						shape.uvtilex = EditorGUILayout.FloatField("UV Tile X", shape.uvtilex);
						shape.uvtiley = EditorGUILayout.FloatField("UV Tile Y", shape.uvtiley);

						shape.cap = EditorGUILayout.Toggle("Cap", shape.cap);
						shape.RopeUp = (MegaAxis)EditorGUILayout.EnumPopup("Up", shape.RopeUp);
						shape.mat1 = (Material)EditorGUILayout.ObjectField("Mat", shape.mat1, typeof(Material), true);
						shape.flipNormals = EditorGUILayout.Toggle("Flip Normals", shape.flipNormals);
						break;
				}

				if ( shape.strands < 1 )
					shape.strands = 1;

				EditorGUILayout.EndVertical();

				// Conform
				shape.conform = EditorGUILayout.BeginToggleGroup("Conform", shape.conform);

				GameObject contarget = (GameObject)EditorGUILayout.ObjectField("Target", shape.target, typeof(GameObject), true);

				if ( contarget != shape.target )
					shape.SetTarget(contarget);
				shape.conformAmount = EditorGUILayout.Slider("Amount", shape.conformAmount, 0.0f, 1.0f);
				shape.raystartoff = EditorGUILayout.FloatField("Ray Start Off", shape.raystartoff);
				shape.conformOffset = EditorGUILayout.FloatField("Conform Offset", shape.conformOffset);
				shape.raydist = EditorGUILayout.FloatField("Ray Dist", shape.raydist);
				EditorGUILayout.EndToggleGroup();
			}
			else
			{
				shape.ClearMesh();
			}

			showsplines = EditorGUILayout.Foldout(showsplines, "Spline Data");

			if ( showsplines )
			{
				EditorGUILayout.BeginVertical("Box");
				if ( shape.splines != null && shape.splines.Count > 0 )
					DisplaySpline(shape, shape.splines[shape.selcurve]);
				EditorGUILayout.EndVertical();
			}

			EditorGUILayout.BeginHorizontal();

			Color col = GUI.backgroundColor;
			GUI.backgroundColor = Color.green;
			if ( GUILayout.Button("Add") )
			{
				// Create a new spline in the shape
				MegaSpline spl = MegaSpline.Copy(shape.splines[shape.selcurve]);

				shape.splines.Add(spl);
				shape.selcurve = shape.splines.Count - 1;
				EditorUtility.SetDirty(shape);
				buildmesh = true;
			}

			if ( shape.splines.Count > 1 )
			{
				GUI.backgroundColor = Color.red;
				if ( GUILayout.Button("Delete") )
				{
					// Delete current spline
					shape.splines.RemoveAt(shape.selcurve);


					for ( int i = 0; i < shape.splines.Count; i++ )
					{
						if ( shape.splines[i].outlineSpline == shape.selcurve )
							shape.splines[i].outlineSpline = -1;

						if ( shape.splines[i].outlineSpline > shape.selcurve )
							shape.splines[i].outlineSpline--;
					}

					shape.selcurve--;
					if ( shape.selcurve < 0 )
						shape.selcurve = 0;

					EditorUtility.SetDirty(shape);
					buildmesh = true;
				}
			}
			GUI.backgroundColor = col;
			EditorGUILayout.EndHorizontal();
		}

		if ( !shape.imported )
		{
			if ( Params() )
			{
				rebuild = true;
			}
		}

		showfuncs = EditorGUILayout.Foldout(showfuncs, "Extra Functions");

		if ( showfuncs )
		{
			if ( GUILayout.Button("Flatten") )
			{
				shape.SetHeight(shape.selcurve, 0.0f);
				shape.CalcLength();
				EditorUtility.SetDirty(target);
			}

			if ( GUILayout.Button("Remove Twist") )
			{
				shape.SetTwist(shape.selcurve, 0.0f);
				EditorUtility.SetDirty(target);
			}

			if ( GUILayout.Button("Copy IDS") )
			{
				shape.CopyIDS(shape.selcurve);
				EditorUtility.SetDirty(target);
			}
		}

		export = EditorGUILayout.Foldout(export, "Export Options");

		if ( export )
		{
			xaxis = (MegaAxis)EditorGUILayout.EnumPopup("X Axis", xaxis);
			yaxis = (MegaAxis)EditorGUILayout.EnumPopup("Y Axis", yaxis);

			strokewidth = EditorGUILayout.FloatField("Stroke Width", strokewidth);
			strokecol = EditorGUILayout.ColorField("Stroke Color", strokecol);

			if ( GUILayout.Button("Export") )
			{
				Export(shape);
			}
		}

		if ( recalc )
		{
			shape.CalcLength();	//10);

			shape.BuildMesh();

			//MegaLoftLayerSimple[] layers = (MegaLoftLayerSimple[])FindObjectsOfType(typeof(MegaLoftLayerSimple));

			//for ( int i = 0; i < layers.Length; i++ )
			//{
				//layers[i].Notify(shape.splines[shape.selcurve], 0);
			//}

			EditorUtility.SetDirty(shape);
		}

		if ( GUI.changed )
		{
			EditorUtility.SetDirty(target);
			buildmesh = true;
		}

		if ( rebuild )
		{
			shape.MakeShape();
			EditorUtility.SetDirty(target);
			buildmesh = true;
		}

		if ( buildmesh )
		{
			if ( shape.makeMesh )
			{
				shape.SetMats();
				shape.BuildMesh();
			}
		}

		//undoManager.CheckDirty();
	}
Exemplo n.º 24
0
    // Use this for initialization
    void Setup()
    {
        int len = rows * cols;

        buffer1 = new float[len];
        buffer2 = new float[len];
        input   = new float[len];

        swapMe        = false;
        currentBuffer = buffer2;

        //float xStep = (bbox.max.x - bbox.min.x) / cols;
        //float zStep = (bbox.max.z - bbox.min.z) / rows;

        vertexIndices = new int[verts.Length];

        SetObstructions(obTexture);

        for (int i = 0; i < len; i++)
        {
            //vertexIndices[i] = -1;
            buffer1[i] = 0;
            buffer2[i] = 0;
        }

        int xc = 0;
        int yc = 1;

        Vector3 size = bbox.Size();

        if (size.x == 0.0f)
        {
            axis = MegaAxis.X;
        }

        if (size.y == 0.0f)
        {
            axis = MegaAxis.Y;
        }

        if (size.z == 0.0f)
        {
            axis = MegaAxis.Z;
        }

        // this will produce a list of indices that are sorted the way I need them to
        // be for the algo to work right
        switch (axis)
        {
        case MegaAxis.X:
            vertcomponent = 0;
            xc            = 1;
            yc            = 2;
            break;

        case MegaAxis.Y:
            vertcomponent = 1;
            xc            = 0;
            yc            = 2;
            break;

        case MegaAxis.Z:
            vertcomponent = 2;
            xc            = 0;
            yc            = 1;
            break;
        }

        //Debug.Log("Size " + size);
        for (int i = 0; i < verts.Length; i++)
        {
            //float column = ((verts[i].x - bbox.min.x) / size.x);// + 0.5;
            //float row = ((verts[i].z - bbox.min.z) / size.z);// + 0.5;

            float column = ((verts[i][xc] - bbox.min[xc]) / size[xc]);         // + 0.5;
            float row    = ((verts[i][yc] - bbox.min[yc]) / size[yc]);         // + 0.5;

            if (column >= 1.0f)
            {
                column = 0.999f;
            }

            if (row >= 1.0f)
            {
                row = 0.999f;
            }

            int   ci       = (int)(column * (float)(cols));
            int   ri       = (int)(row * (float)(rows));
            float position = (ri * (cols)) + ci;                // + 0.5f;
            //Debug.Log("ci " + ci + " ri " + ri + " Pos " + position);
            //if ( vertexIndices[(int)position] >= 0 )
            //	Debug.Log("smash");

            //if ( (int)position < 0 )
            //{
            //	Debug.Log("errr col " + column + " row " + row + " ci " + ci + " ri " + ri);
            //}
            vertexIndices[i] = (int)position;                   //] = i;
        }

        //Debug.Log("Plop");
        //splashAtPoint(cols / 2, rows / 2);
    }
Exemplo n.º 25
0
    public void DrawFromTo(MegaAxis axis, float from, float to, MegaModContext mc)
    {
        Vector3 min = mc.bbox.min;
        Vector3 max = mc.bbox.max;

        switch ( axis )
        {
            case MegaAxis.X:
                corners[0] = new Vector3(-from, min.y, min.z);
                corners[1] = new Vector3(-from, max.y, min.z);
                corners[2] = new Vector3(-from, max.y, max.z);
                corners[3] = new Vector3(-from, min.y, max.z);

                corners[4] = new Vector3(-to, min.y, min.z);
                corners[5] = new Vector3(-to, max.y, min.z);
                corners[6] = new Vector3(-to, max.y, max.z);
                corners[7] = new Vector3(-to, min.y, max.z);
                break;

            case MegaAxis.Y:
                corners[0] = new Vector3(min.x, min.y, -from);
                corners[1] = new Vector3(min.x, max.y, -from);
                corners[2] = new Vector3(max.x, max.y, -from);
                corners[3] = new Vector3(max.x, min.y, -from);

                corners[4] = new Vector3(min.x, min.y, -to);
                corners[5] = new Vector3(min.x, max.y, -to);
                corners[6] = new Vector3(max.x, max.y, -to);
                corners[7] = new Vector3(max.x, min.y, -to);
                break;

            case MegaAxis.Z:
                corners[0] = new Vector3(min.x, from, min.z);
                corners[1] = new Vector3(min.x, from, max.z);
                corners[2] = new Vector3(max.x, from, max.z);
                corners[3] = new Vector3(max.x, from, min.z);

                corners[4] = new Vector3(min.x, to, min.z);
                corners[5] = new Vector3(min.x, to, max.z);
                corners[6] = new Vector3(max.x, to, max.z);
                corners[7] = new Vector3(max.x, to, min.z);
                break;
        }

        Color c = Color.red;
        c.a = gizCol1.a;
        Gizmos.color = c;

        Vector3 offset = Vector3.zero;	//mc.Offset;

        DrawEdgeCol(corners[0] - offset, corners[1] - offset);
        DrawEdgeCol(corners[1] - offset, corners[2] - offset);
        DrawEdgeCol(corners[2] - offset, corners[3] - offset);
        DrawEdgeCol(corners[3] - offset, corners[0] - offset);

        c = Color.green;
        c.a = gizCol1.a;
        Gizmos.color = c;

        DrawEdgeCol(corners[4] - offset, corners[5] - offset);
        DrawEdgeCol(corners[5] - offset, corners[6] - offset);
        DrawEdgeCol(corners[6] - offset, corners[7] - offset);
        DrawEdgeCol(corners[7] - offset, corners[4] - offset);
    }
Exemplo n.º 26
0
    // Put common params in, and each shape has its sections
    void OnGUI()
    {
        //name = EditorGUILayout.TextField("Name", name);
        showcommon = EditorGUILayout.Foldout(showcommon, "Common");

        if ( showcommon )
        {
            axis = (MegaAxis)EditorGUILayout.EnumPopup("Axis", axis);
            stepdist = EditorGUILayout.FloatField("Step Dist", stepdist);
            knotsize = EditorGUILayout.FloatField("Knot Size", knotsize);
            drawknots = EditorGUILayout.Toggle("Draw Knots", drawknots);
            drawhandles = EditorGUILayout.Toggle("Draw Handles", drawhandles);

            col1 = EditorGUILayout.ColorField("Color 1", col1);
            col2 = EditorGUILayout.ColorField("Color 2", col2);
        }

        if ( GUILayout.Button("Circle") )	CreateShape("Circle");
        if ( GUILayout.Button("Star") ) CreateShape("Star");
        if ( GUILayout.Button("NGon") ) CreateShape("NGon");
        if ( GUILayout.Button("Arc") ) CreateShape("Arc");
        if ( GUILayout.Button("Ellipse") ) CreateShape("Ellipse");
        if ( GUILayout.Button("Rectangle") ) CreateShape("Rectangle");
        if ( GUILayout.Button("Helix") ) CreateShape("Helix");
    }
Exemplo n.º 27
0
 void AddKnot(MegaSpline spline, Vector3 p, Vector3 invec, Vector3 outvec, MegaAxis axis)
 {
     spline.AddKnot(SwapAxis(p, axis), SwapAxis(invec, axis), SwapAxis(outvec, axis));
 }
Exemplo n.º 28
0
	public override void OnInspectorGUI()
	{
		//undoManager.CheckUndo();
		bool buildmesh = false;
		bool recalc = false;
		MegaShape shape = (MegaShape)target;

		EditorGUILayout.BeginHorizontal();

		int curve = shape.selcurve;

		if ( GUILayout.Button("Add Knot") )
		{
			if ( shape.splines == null || shape.splines.Count == 0 )
			{
				MegaSpline spline = new MegaSpline();	// Have methods for these
				shape.splines.Add(spline);
			}

			MegaKnot knot = new MegaKnot();
			float per = shape.CursorPercent * 0.01f;

			CursorTangent = shape.splines[curve].Interpolate(per + 0.01f, true, ref CursorKnot);	//this.GetPositionOnSpline(i) - p;
			CursorPos = shape.splines[curve].Interpolate(per, true, ref CursorKnot);	//this.GetPositionOnSpline(i) - p;

			knot.p = CursorPos;
			knot.outvec = (CursorTangent - knot.p);
			knot.outvec.Normalize();
			knot.outvec *= shape.splines[curve].knots[CursorKnot].seglength * 0.25f;
			knot.invec = -knot.outvec;
			knot.invec += knot.p;
			knot.outvec += knot.p;
			knot.twist = shape.splines[curve].knots[CursorKnot].twist;
			knot.id = shape.splines[curve].knots[CursorKnot].id;

			shape.splines[curve].knots.Insert(CursorKnot + 1, knot);

			if ( shape.smoothonaddknot )
				shape.AutoCurve(shape.splines[snum]);	//, knum, knum + 2);

			shape.CalcLength();	//10);
			EditorUtility.SetDirty(target);
			buildmesh = true;
		}

		if ( GUILayout.Button("Delete Knot") )
		{
			if ( selected != -1 )
			{
				shape.splines[curve].knots.RemoveAt(selected);
				selected--;
				shape.CalcLength();	//10);
			}
			EditorUtility.SetDirty(target);
			buildmesh = true;
		}
		
		EditorGUILayout.EndHorizontal();
		EditorGUILayout.BeginHorizontal();

		if ( GUILayout.Button("Match Handles") )
		{
			if ( selected != -1 )
			{
				Vector3 p = shape.splines[curve].knots[selected].p;
				Vector3 d = shape.splines[curve].knots[selected].outvec - p;
				shape.splines[curve].knots[selected].invec = p - d;
				shape.CalcLength();	//10);
			}
			EditorUtility.SetDirty(target);
			buildmesh = true;
		}

		if ( GUILayout.Button("Load") )
		{
			LoadShape(ImportScale);
			buildmesh = true;
		}

		if ( GUILayout.Button("Load SXL") )
		{
			LoadSXL(ImportScale);
			buildmesh = true;
		}

		if ( GUILayout.Button("Load KML") )
		{
			LoadKML(ImportScale);
			buildmesh = true;
		}

		EditorGUILayout.EndHorizontal();

		EditorGUILayout.BeginHorizontal();
		if ( GUILayout.Button("AutoCurve") )
		{
			shape.AutoCurve();
			EditorUtility.SetDirty(target);
			buildmesh = true;
		}

		if ( GUILayout.Button("Reverse") )
		{
			shape.Reverse(curve);
			//shape.CalcLength();
			EditorUtility.SetDirty(target);
			buildmesh = true;
		}

		EditorGUILayout.EndHorizontal();

		if ( GUILayout.Button("Centre Shape") )
		{
			shape.Centre(1.0f, Vector3.one);
		}

		if ( GUILayout.Button("Apply Scaling") )
		{
			shape.Scale(shape.transform.localScale);
			EditorUtility.SetDirty(target);
			shape.transform.localScale = Vector3.one;
			buildmesh = true;
		}

		if ( GUILayout.Button("Import SVG") )
		{
			LoadSVG(ImportScale);
			buildmesh = true;
		}

		showcommon = EditorGUILayout.Foldout(showcommon, "Common Params");

		bool rebuild = false;	//Params();

		if ( showcommon )
		{
			shape.CursorPercent = EditorGUILayout.FloatField("Cursor", shape.CursorPercent);
			shape.CursorPercent = Mathf.Repeat(shape.CursorPercent, 100.0f);

			ImportScale = EditorGUILayout.FloatField("Import Scale", ImportScale);

			MegaAxis av = (MegaAxis)EditorGUILayout.EnumPopup("Axis", shape.axis);
			if ( av != shape.axis )
			{
				shape.axis = av;
				rebuild = true;
			}

			if ( shape.splines.Count > 1 )
				shape.selcurve = EditorGUILayout.IntSlider("Curve", shape.selcurve, 0, shape.splines.Count - 1);

			if ( shape.selcurve < 0 )
				shape.selcurve = 0;

			if ( shape.selcurve > shape.splines.Count - 1 )
				shape.selcurve = shape.splines.Count - 1;

			EditorGUILayout.BeginHorizontal();
			EditorGUILayout.LabelField("Colors");
			shape.col1 = EditorGUILayout.ColorField(shape.col1);
			shape.col2 = EditorGUILayout.ColorField(shape.col2);
			EditorGUILayout.EndHorizontal();

			shape.VecCol = EditorGUILayout.ColorField("Vec Col", shape.VecCol);

			shape.KnotSize = EditorGUILayout.FloatField("Knot Size", shape.KnotSize);
			shape.stepdist = EditorGUILayout.FloatField("Step Dist", shape.stepdist);

			MegaSpline spline = shape.splines[shape.selcurve];

			if ( shape.stepdist < 0.01f )
				shape.stepdist = 0.01f;

			shape.dolateupdate = EditorGUILayout.Toggle("Do Late Update", shape.dolateupdate);
			shape.normalizedInterp = EditorGUILayout.Toggle("Normalized Interp", shape.normalizedInterp);

			spline.constantSpeed = EditorGUILayout.Toggle("Constant Speed", spline.constantSpeed);
			int subdivs = EditorGUILayout.IntField("Calc Subdivs", spline.subdivs);

			if ( subdivs < 2 )
				subdivs = 2;
			if ( subdivs != spline.subdivs )
				spline.CalcLength(subdivs);

			shape.drawHandles = EditorGUILayout.Toggle("Draw Handles", shape.drawHandles);
			shape.drawKnots = EditorGUILayout.Toggle("Draw Knots", shape.drawKnots);
			shape.drawTwist = EditorGUILayout.Toggle("Draw Twist", shape.drawTwist);
			shape.drawspline = EditorGUILayout.Toggle("Draw Spline", shape.drawspline);
			shape.showorigin = EditorGUILayout.Toggle("Origin Handle", shape.showorigin);
			shape.lockhandles = EditorGUILayout.Toggle("Lock Handles", shape.lockhandles);
			shape.updateondrag = EditorGUILayout.Toggle("Update On Drag", shape.updateondrag);

			shape.usesnap = EditorGUILayout.BeginToggleGroup("Use Snap", shape.usesnap);
			shape.usesnaphandles = EditorGUILayout.Toggle("Snap Handles", shape.usesnaphandles);
			shape.snap = EditorGUILayout.Vector3Field("Snap", shape.snap);
			if ( shape.snap.x < 0.0f ) shape.snap.x = 0.0f;
			if ( shape.snap.y < 0.0f ) shape.snap.y = 0.0f;
			if ( shape.snap.z < 0.0f ) shape.snap.z = 0.0f;
			EditorGUILayout.EndToggleGroup();

			//shape.autosmooth = EditorGUILayout.Toggle("Auto Smooth", shape.autosmooth);
			//shape.smoothness = EditorGUILayout.FloatField("Smoothness", shape.smoothness);
			float smoothness = EditorGUILayout.Slider("Smoothness", shape.smoothness, 0.0f, 1.5f);
			if ( smoothness != shape.smoothness )
			{
				shape.smoothness = smoothness;
				shape.AutoCurve();
				recalc = true;
			}
			shape.smoothonaddknot = EditorGUILayout.Toggle("Smooth on Add Knot", shape.smoothonaddknot);

			shape.handleType = (MegaHandleType)EditorGUILayout.EnumPopup("Handle Type", shape.handleType);

			showlabels = EditorGUILayout.Toggle("Labels", showlabels);

			bool hidewire1 = EditorGUILayout.Toggle("Hide Wire", hidewire);

			if ( hidewire1 != hidewire )
			{
				hidewire = hidewire1;
				EditorUtility.SetSelectedWireframeHidden(shape.GetComponent<Renderer>(), hidewire);
			}

			shape.animate = EditorGUILayout.Toggle("Animate", shape.animate);
			if ( shape.animate )
			{
				shape.time = EditorGUILayout.FloatField("Time", shape.time);
				shape.MaxTime = EditorGUILayout.FloatField("Loop Time", shape.MaxTime);
				shape.speed = EditorGUILayout.FloatField("Speed", shape.speed);
				shape.LoopMode = (MegaRepeatMode)EditorGUILayout.EnumPopup("Loop Mode", shape.LoopMode);
			}

			AnimationKeyFrames(shape);

			if ( shape.splines.Count > 0 )
			{
				if ( spline.outlineSpline != -1 )
				{
					int outlineSpline = EditorGUILayout.IntSlider("Outline Spl", spline.outlineSpline, 0, shape.splines.Count - 1);
					float outline = EditorGUILayout.FloatField("Outline", spline.outline);

					if ( outline != spline.outline || outlineSpline != spline.outlineSpline )
					{
						spline.outlineSpline = outlineSpline;
						spline.outline = outline;
						if ( outlineSpline != shape.selcurve )
						{
							shape.OutlineSpline(shape.splines[spline.outlineSpline], spline, spline.outline, true);
							spline.CalcLength();	//10);
							EditorUtility.SetDirty(target);
							buildmesh = true;
						}
					}
				}
				else
				{
					outline = EditorGUILayout.FloatField("Outline", outline);

					if ( GUILayout.Button("Outline") )
					{
						shape.OutlineSpline(shape, shape.selcurve, outline, true);
						shape.splines[shape.splines.Count - 1].outline = outline;
						shape.splines[shape.splines.Count - 1].outlineSpline = shape.selcurve;
						shape.selcurve = shape.splines.Count - 1;
						EditorUtility.SetDirty(target);
						buildmesh = true;
					}
				}
			}

			// Mesher
			shape.makeMesh = EditorGUILayout.Toggle("Make Mesh", shape.makeMesh);

			if ( shape.makeMesh )
			{
				shape.meshType = (MeshShapeType)EditorGUILayout.EnumPopup("Mesh Type", shape.meshType);
				shape.Pivot = EditorGUILayout.Vector3Field("Pivot", shape.Pivot);

				shape.CalcTangents = EditorGUILayout.Toggle("Calc Tangents", shape.CalcTangents);
				shape.GenUV = EditorGUILayout.Toggle("Gen UV", shape.GenUV);

				if ( GUILayout.Button("Build LightMap") )
				{
					MegaShapeLightMapWindow.Init();
				}

				EditorGUILayout.BeginVertical("Box");
				switch ( shape.meshType )
				{
					case MeshShapeType.Fill:
						shape.DoubleSided = EditorGUILayout.Toggle("Double Sided", shape.DoubleSided);
						shape.Height = EditorGUILayout.FloatField("Height", shape.Height);
						shape.UseHeightCurve = EditorGUILayout.Toggle("Use Height Crv", shape.UseHeightCurve);
						if ( shape.UseHeightCurve )
						{
							shape.heightCrv = EditorGUILayout.CurveField("Height Curve", shape.heightCrv);
							shape.heightOff = EditorGUILayout.Slider("Height Off", shape.heightOff, -1.0f, 1.0f);
						}
						shape.mat1 = (Material)EditorGUILayout.ObjectField("Top Mat", shape.mat1, typeof(Material), true);
						shape.mat2 = (Material)EditorGUILayout.ObjectField("Bot Mat", shape.mat2, typeof(Material), true);
						shape.mat3 = (Material)EditorGUILayout.ObjectField("Side Mat", shape.mat3, typeof(Material), true);

						shape.PhysUV = EditorGUILayout.Toggle("Physical UV", shape.PhysUV);
						shape.UVOffset = EditorGUILayout.Vector2Field("UV Offset", shape.UVOffset);
						shape.UVRotate = EditorGUILayout.Vector2Field("UV Rotate", shape.UVRotate);
						shape.UVScale = EditorGUILayout.Vector2Field("UV Scale", shape.UVScale);
						shape.UVOffset1 = EditorGUILayout.Vector2Field("UV Offset1", shape.UVOffset1);
						shape.UVRotate1 = EditorGUILayout.Vector2Field("UV Rotate1", shape.UVRotate1);
						shape.UVScale1 = EditorGUILayout.Vector2Field("UV Scale1", shape.UVScale1);
						break;

					case MeshShapeType.Tube:
						shape.TubeStart = EditorGUILayout.Slider("Start", shape.TubeStart, -1.0f, 2.0f);
						shape.TubeLength = EditorGUILayout.Slider("Length", shape.TubeLength, 0.0f, 1.0f);
						shape.rotate = EditorGUILayout.FloatField("Rotate", shape.rotate);
						shape.tsides = EditorGUILayout.IntField("Sides", shape.tsides);
						shape.tradius = EditorGUILayout.FloatField("Radius", shape.tradius);
						shape.offset = EditorGUILayout.FloatField("Offset", shape.offset);

						shape.scaleX = EditorGUILayout.CurveField("Scale X", shape.scaleX);
						shape.unlinkScale = EditorGUILayout.BeginToggleGroup("unlink Scale", shape.unlinkScale);
						shape.scaleY = EditorGUILayout.CurveField("Scale Y", shape.scaleY);
						EditorGUILayout.EndToggleGroup();

						shape.strands = EditorGUILayout.IntField("Strands", shape.strands);
						if ( shape.strands > 1 )
						{
							shape.strandRadius = EditorGUILayout.FloatField("Strand Radius", shape.strandRadius);
							shape.TwistPerUnit = EditorGUILayout.FloatField("Twist", shape.TwistPerUnit);
							shape.startAng = EditorGUILayout.FloatField("Start Twist", shape.startAng);
						}
						shape.UVOffset = EditorGUILayout.Vector2Field("UV Offset", shape.UVOffset);
						shape.uvtilex = EditorGUILayout.FloatField("UV Tile X", shape.uvtilex);
						shape.uvtiley = EditorGUILayout.FloatField("UV Tile Y", shape.uvtiley);

						shape.cap = EditorGUILayout.Toggle("Cap", shape.cap);
						shape.RopeUp = (MegaAxis)EditorGUILayout.EnumPopup("Up", shape.RopeUp);
						shape.mat1 = (Material)EditorGUILayout.ObjectField("Mat", shape.mat1, typeof(Material), true);
						shape.flipNormals = EditorGUILayout.Toggle("Flip Normals", shape.flipNormals);
						break;

					case MeshShapeType.Ribbon:
						shape.TubeStart = EditorGUILayout.Slider("Start", shape.TubeStart, -1.0f, 2.0f);
						shape.TubeLength = EditorGUILayout.Slider("Length", shape.TubeLength, 0.0f, 1.0f);
						shape.boxwidth = EditorGUILayout.FloatField("Width", shape.boxwidth);
						shape.raxis = (MegaAxis)EditorGUILayout.EnumPopup("Axis", shape.raxis);
						shape.rotate = EditorGUILayout.FloatField("Rotate", shape.rotate);
						shape.ribsegs = EditorGUILayout.IntField("Segs", shape.ribsegs);
						if ( shape.ribsegs < 1 )
							shape.ribsegs = 1;
						shape.offset = EditorGUILayout.FloatField("Offset", shape.offset);

						shape.scaleX = EditorGUILayout.CurveField("Scale X", shape.scaleX);

						shape.strands = EditorGUILayout.IntField("Strands", shape.strands);
						if ( shape.strands > 1 )
						{
							shape.strandRadius = EditorGUILayout.FloatField("Strand Radius", shape.strandRadius);
							shape.TwistPerUnit = EditorGUILayout.FloatField("Twist", shape.TwistPerUnit);
							shape.startAng = EditorGUILayout.FloatField("Start Twist", shape.startAng);
						}

						shape.UVOffset = EditorGUILayout.Vector2Field("UV Offset", shape.UVOffset);
						shape.uvtilex = EditorGUILayout.FloatField("UV Tile X", shape.uvtilex);
						shape.uvtiley = EditorGUILayout.FloatField("UV Tile Y", shape.uvtiley);

						shape.RopeUp = (MegaAxis)EditorGUILayout.EnumPopup("Up", shape.RopeUp);
						shape.mat1 = (Material)EditorGUILayout.ObjectField("Mat", shape.mat1, typeof(Material), true);
						shape.flipNormals = EditorGUILayout.Toggle("Flip Normals", shape.flipNormals);
						break;

					case MeshShapeType.Box:
						shape.TubeStart = EditorGUILayout.Slider("Start", shape.TubeStart, -1.0f, 2.0f);
						shape.TubeLength = EditorGUILayout.Slider("Length", shape.TubeLength, 0.0f, 1.0f);
						shape.rotate = EditorGUILayout.FloatField("Rotate", shape.rotate);
						shape.boxwidth = EditorGUILayout.FloatField("Box Width", shape.boxwidth);
						shape.boxheight = EditorGUILayout.FloatField("Box Height", shape.boxheight);
						shape.offset = EditorGUILayout.FloatField("Offset", shape.offset);

						shape.scaleX = EditorGUILayout.CurveField("Scale X", shape.scaleX);
						shape.unlinkScale = EditorGUILayout.BeginToggleGroup("unlink Scale", shape.unlinkScale);
						shape.scaleY = EditorGUILayout.CurveField("Scale Y", shape.scaleY);
						EditorGUILayout.EndToggleGroup();

						shape.strands = EditorGUILayout.IntField("Strands", shape.strands);
						if ( shape.strands > 1 )
						{
							shape.tradius = EditorGUILayout.FloatField("Radius", shape.tradius);
							shape.TwistPerUnit = EditorGUILayout.FloatField("Twist", shape.TwistPerUnit);
							shape.startAng = EditorGUILayout.FloatField("Start Twist", shape.startAng);
						}

						shape.UVOffset = EditorGUILayout.Vector2Field("UV Offset", shape.UVOffset);
						shape.uvtilex = EditorGUILayout.FloatField("UV Tile X", shape.uvtilex);
						shape.uvtiley = EditorGUILayout.FloatField("UV Tile Y", shape.uvtiley);

						shape.cap = EditorGUILayout.Toggle("Cap", shape.cap);
						shape.RopeUp = (MegaAxis)EditorGUILayout.EnumPopup("Up", shape.RopeUp);
						shape.mat1 = (Material)EditorGUILayout.ObjectField("Mat", shape.mat1, typeof(Material), true);
						shape.flipNormals = EditorGUILayout.Toggle("Flip Normals", shape.flipNormals);
						break;
				}

				if ( shape.strands < 1 )
					shape.strands = 1;

				EditorGUILayout.EndVertical();

				// Conform
				shape.conform = EditorGUILayout.BeginToggleGroup("Conform", shape.conform);

				GameObject contarget = (GameObject)EditorGUILayout.ObjectField("Target", shape.target, typeof(GameObject), true);

				if ( contarget != shape.target )
					shape.SetTarget(contarget);
				shape.conformAmount = EditorGUILayout.Slider("Amount", shape.conformAmount, 0.0f, 1.0f);
				shape.raystartoff = EditorGUILayout.FloatField("Ray Start Off", shape.raystartoff);
				shape.conformOffset = EditorGUILayout.FloatField("Conform Offset", shape.conformOffset);
				shape.raydist = EditorGUILayout.FloatField("Ray Dist", shape.raydist);
				EditorGUILayout.EndToggleGroup();
			}
			else
			{
				shape.ClearMesh();
			}

			showsplines = EditorGUILayout.Foldout(showsplines, "Spline Data");

			if ( showsplines )
			{
				EditorGUILayout.BeginVertical("Box");
				if ( shape.splines != null && shape.splines.Count > 0 )
					DisplaySpline(shape, shape.splines[shape.selcurve]);
				EditorGUILayout.EndVertical();
			}

			EditorGUILayout.BeginHorizontal();

			Color col = GUI.backgroundColor;
			GUI.backgroundColor = Color.green;
			if ( GUILayout.Button("Add") )
			{
				// Create a new spline in the shape
				MegaSpline spl = MegaSpline.Copy(shape.splines[shape.selcurve]);

				shape.splines.Add(spl);
				shape.selcurve = shape.splines.Count - 1;
				EditorUtility.SetDirty(shape);
				buildmesh = true;
			}

			if ( shape.splines.Count > 1 )
			{
				GUI.backgroundColor = Color.red;
				if ( GUILayout.Button("Delete") )
				{
					// Delete current spline
					shape.splines.RemoveAt(shape.selcurve);


					for ( int i = 0; i < shape.splines.Count; i++ )
					{
						if ( shape.splines[i].outlineSpline == shape.selcurve )
							shape.splines[i].outlineSpline = -1;

						if ( shape.splines[i].outlineSpline > shape.selcurve )
							shape.splines[i].outlineSpline--;
					}

					shape.selcurve--;
					if ( shape.selcurve < 0 )
						shape.selcurve = 0;

					EditorUtility.SetDirty(shape);
					buildmesh = true;
				}
			}
			GUI.backgroundColor = col;
			EditorGUILayout.EndHorizontal();
		}

		if ( !shape.imported )
		{
			if ( Params() )
			{
				rebuild = true;
			}
		}

		showfuncs = EditorGUILayout.Foldout(showfuncs, "Extra Functions");

		if ( showfuncs )
		{
			if ( GUILayout.Button("Flatten") )
			{
				shape.SetHeight(shape.selcurve, 0.0f);
				shape.CalcLength();
				EditorUtility.SetDirty(target);
			}

			if ( GUILayout.Button("Remove Twist") )
			{
				shape.SetTwist(shape.selcurve, 0.0f);
				EditorUtility.SetDirty(target);
			}

			if ( GUILayout.Button("Copy IDS") )
			{
				shape.CopyIDS(shape.selcurve);
				EditorUtility.SetDirty(target);
			}
		}

		export = EditorGUILayout.Foldout(export, "Export Options");

		if ( export )
		{
			xaxis = (MegaAxis)EditorGUILayout.EnumPopup("X Axis", xaxis);
			yaxis = (MegaAxis)EditorGUILayout.EnumPopup("Y Axis", yaxis);

			strokewidth = EditorGUILayout.FloatField("Stroke Width", strokewidth);
			strokecol = EditorGUILayout.ColorField("Stroke Color", strokecol);

			if ( GUILayout.Button("Export") )
			{
				Export(shape);
			}
		}

		if ( recalc )
		{
			shape.CalcLength();	//10);

			shape.BuildMesh();

			//MegaLoftLayerSimple[] layers = (MegaLoftLayerSimple[])FindObjectsOfType(typeof(MegaLoftLayerSimple));

			//for ( int i = 0; i < layers.Length; i++ )
			//{
				//layers[i].Notify(shape.splines[shape.selcurve], 0);
			//}

			EditorUtility.SetDirty(shape);
		}

		if ( GUI.changed )
		{
			EditorUtility.SetDirty(target);
			buildmesh = true;
		}

		if ( rebuild )
		{
			shape.MakeShape();
			EditorUtility.SetDirty(target);
			buildmesh = true;
		}

		if ( buildmesh )
		{
			if ( shape.makeMesh )
			{
				shape.SetMats();
				shape.BuildMesh();
			}
		}

		//undoManager.CheckDirty();
	}
Exemplo n.º 29
0
    public void DrawFromTo(MegaAxis axis, float from, float to)
    {
        Vector3 min = new Vector3(-Width * 0.5f, 0.0f, -Length * 0.5f);
        Vector3 max = new Vector3(Width * 0.5f, Height, Length * 0.5f);

        switch (axis)
        {
        case MegaAxis.X:
            corners[0] = new Vector3(-from, min.y, min.z);
            corners[1] = new Vector3(-from, max.y, min.z);
            corners[2] = new Vector3(-from, max.y, max.z);
            corners[3] = new Vector3(-from, min.y, max.z);

            corners[4] = new Vector3(-to, min.y, min.z);
            corners[5] = new Vector3(-to, max.y, min.z);
            corners[6] = new Vector3(-to, max.y, max.z);
            corners[7] = new Vector3(-to, min.y, max.z);
            break;

        case MegaAxis.Y:
            corners[0] = new Vector3(min.x, min.y, -from);
            corners[1] = new Vector3(min.x, max.y, -from);
            corners[2] = new Vector3(max.x, max.y, -from);
            corners[3] = new Vector3(max.x, min.y, -from);

            corners[4] = new Vector3(min.x, min.y, -to);
            corners[5] = new Vector3(min.x, max.y, -to);
            corners[6] = new Vector3(max.x, max.y, -to);
            corners[7] = new Vector3(max.x, min.y, -to);
            break;

        case MegaAxis.Z:
            corners[0] = new Vector3(min.x, from, min.z);
            corners[1] = new Vector3(min.x, from, max.z);
            corners[2] = new Vector3(max.x, from, max.z);
            corners[3] = new Vector3(max.x, from, min.z);

            corners[4] = new Vector3(min.x, to, min.z);
            corners[5] = new Vector3(min.x, to, max.z);
            corners[6] = new Vector3(max.x, to, max.z);
            corners[7] = new Vector3(max.x, to, min.z);
            break;
        }

        Color c = Color.red;

        c.a          = gCol1.a;
        Gizmos.color = c;

        DrawEdgeCol(corners[0] - Offset, corners[1] - Offset);
        DrawEdgeCol(corners[1] - Offset, corners[2] - Offset);
        DrawEdgeCol(corners[2] - Offset, corners[3] - Offset);
        DrawEdgeCol(corners[3] - Offset, corners[0] - Offset);

        c            = Color.green;
        c.a          = gCol1.a;
        Gizmos.color = c;

        DrawEdgeCol(corners[4] - Offset, corners[5] - Offset);
        DrawEdgeCol(corners[5] - Offset, corners[6] - Offset);
        DrawEdgeCol(corners[6] - Offset, corners[7] - Offset);
        DrawEdgeCol(corners[7] - Offset, corners[4] - Offset);
    }
Exemplo n.º 30
0
 void AddKnot(MegaSpline spline, Vector3 p, Vector3 invec, Vector3 outvec, MegaAxis axis)
 {
     spline.AddKnot(SwapAxis(p, axis), SwapAxis(invec, axis), SwapAxis(outvec, axis));
 }
Exemplo n.º 31
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        waveOffset = target as WaveOffset;

        EditorGUI.BeginChangeCheck();
        MegaAxis axis = (MegaAxis)EditorGUILayout.EnumPopup("Axis", waveOffset.axis);

        if (EditorGUI.EndChangeCheck())
        {
            waveOffset.Record("Axis");
            waveOffset.axis = axis;
        }

        waveOffset.Update(ref waveOffset.min, "Min", 0f, waveOffset.max);
        waveOffset.Update(ref waveOffset.max, "Max", waveOffset.min, 1f);
        waveOffset.Update(ref waveOffset.amplitude, "Amplitude");
        waveOffset.Update(ref waveOffset.loop, "Loop");

        EditorGUILayout.BeginVertical("Box");

        EditorGUI.BeginChangeCheck();
        WaveType type = (WaveType)EditorGUILayout.EnumPopup("Type", waveOffset.type);

        if (EditorGUI.EndChangeCheck())
        {
            waveOffset.Record("Type");
            waveOffset.type = type;
            waveOffset.Restart();
        }

        switch (type)
        {
        case WaveType.Wave:
            waveOffset.Update(ref waveOffset.startToEnd, "Start To End");
            waveOffset.Update(ref waveOffset.duration, "Duration");
            if (GUILayout.Button("Match distances"))
            {
                waveOffset.Record("Match distances");
                waveOffset.MatchDistances();
            }
            waveOffset.Update(ref waveOffset.gap, "Gap", 0.001f, waveOffset.length);
            break;

        case WaveType.Sinus:
            if (!waveOffset.loop)
            {
                waveOffset.Update(ref waveOffset.turns, "Turns");
                if (waveOffset.turns < 1)
                {
                    waveOffset.turns = 1;
                }
            }
            waveOffset.Update(ref waveOffset.freq, "Frequence");
            if (waveOffset.freq < 1)
            {
                waveOffset.freq = 1;
            }
            waveOffset.Update(ref waveOffset.speed, "Speed");
            break;
        }
        EditorGUILayout.EndVertical();

        waveOffset.Update(ref waveOffset.customizeOffset, "Customize offset");
        waveOffset.Update(ref waveOffset.param1, "Param1");
        waveOffset.Update(ref waveOffset.param2, "Param2");
        waveOffset.Update(ref waveOffset.param3, "Param3");
        waveOffset.Update(ref waveOffset.param4, "Param4");
    }
Exemplo n.º 32
0
    public MegaSculptCurve()
    {
        curve = new AnimationCurve(new Keyframe(0.0f, 0.0f), new Keyframe(1.0f, 0.0f));

        offamount = Vector3.one;
        sclamount = Vector3.one;
        axis = MegaAxis.X;
        affectOffset = MegaAffect.Y;
        affectScale = MegaAffect.None;
        enabled = true;
        weight = 1.0f;
        name = "None";
        uselimits = false;
    }
Exemplo n.º 33
0
	// Put common params in, and each shape has its sections
	void OnGUI()
	{
		scroll = EditorGUILayout.BeginScrollView(scroll);

		//name = EditorGUILayout.TextField("Name", name);

		toolbarInt = GUILayout.Toolbar(toolbarInt, toolbarStrings, GUILayout.MaxWidth(150.0f));

		float butwidth = 80.0f;
		float width = this.position.width;	// / 2.0f;

		int bstep = (int)(width / butwidth);
		if ( bstep == 0 )
			bstep = 1;

		if ( toolbarInt == 0 )
		{
			DoButtons(mods, (width / bstep) - 6.0f, bstep, true);
		}
		else
		{
			//showcommon = EditorGUILayout.Foldout(showcommon, "Common");

			//if ( showcommon )
			{
				axis		= (MegaAxis)EditorGUILayout.EnumPopup("Axis", axis);
				stepdist	= EditorGUILayout.FloatField("Step Dist", stepdist);
				knotsize	= EditorGUILayout.FloatField("Knot Size", knotsize);
				drawknots	= EditorGUILayout.Toggle("Draw Knots", drawknots);
				drawhandles	= EditorGUILayout.Toggle("Draw Handles", drawhandles);
				col1		= EditorGUILayout.ColorField("Color 1", col1);
				col2		= EditorGUILayout.ColorField("Color 2", col2);
				makemesh	= EditorGUILayout.Toggle("Make Mesh", makemesh);
			}
		}
		EditorGUILayout.EndScrollView();
	}
Exemplo n.º 34
0
    // Use this for initialization
    void Setup()
    {
        int len = rows * cols;

        buffer1 = new float[len];
        buffer2 = new float[len];
        input   = new float[len];

        swapMe        = false;
        currentBuffer = buffer2;

        vertexIndices = new int[verts.Length];

        SetObstructions(obTexture);

        for (int i = 0; i < len; i++)
        {
            buffer1[i] = 0;
            buffer2[i] = 0;
        }

        int xc = 0;
        int yc = 1;

        Vector3 size = bbox.Size();

        if (size.x == 0.0f)
        {
            axis = MegaAxis.X;
        }

        if (size.y == 0.0f)
        {
            axis = MegaAxis.Y;
        }

        if (size.z == 0.0f)
        {
            axis = MegaAxis.Z;
        }

        // this will produce a list of indices that are sorted the way I need them to
        // be for the algo to work right
        switch (axis)
        {
        case MegaAxis.X:
            vertcomponent = 0;
            xc            = 1;
            yc            = 2;
            break;

        case MegaAxis.Y:
            vertcomponent = 1;
            xc            = 0;
            yc            = 2;
            break;

        case MegaAxis.Z:
            vertcomponent = 2;
            xc            = 0;
            yc            = 1;
            break;
        }

        for (int i = 0; i < verts.Length; i++)
        {
            float column = ((verts[i][xc] - bbox.min[xc]) / size[xc]);         // + 0.5;
            float row    = ((verts[i][yc] - bbox.min[yc]) / size[yc]);         // + 0.5;

            if (column >= 1.0f)
            {
                column = 0.999f;
            }

            if (row >= 1.0f)
            {
                row = 0.999f;
            }

            int   ci       = (int)(column * (float)(cols));
            int   ri       = (int)(row * (float)(rows));
            float position = (ri * (cols)) + ci;                // + 0.5f;
            vertexIndices[i] = (int)position;                   //] = i;
        }
    }
Exemplo n.º 35
0
    public void DrawFromTo(MegaAxis axis, float from, float to)
    {
        Vector3 min = new Vector3(-Width * 0.5f, 0.0f, -Length * 0.5f);
        Vector3 max = new Vector3(Width * 0.5f, Height, Length * 0.5f);

        switch ( axis )
        {
            case MegaAxis.X:
                corners[0] = new Vector3(-from, min.y, min.z);
                corners[1] = new Vector3(-from, max.y, min.z);
                corners[2] = new Vector3(-from, max.y, max.z);
                corners[3] = new Vector3(-from, min.y, max.z);

                corners[4] = new Vector3(-to, min.y, min.z);
                corners[5] = new Vector3(-to, max.y, min.z);
                corners[6] = new Vector3(-to, max.y, max.z);
                corners[7] = new Vector3(-to, min.y, max.z);
                break;

            case MegaAxis.Y:
                corners[0] = new Vector3(min.x, min.y, -from);
                corners[1] = new Vector3(min.x, max.y, -from);
                corners[2] = new Vector3(max.x, max.y, -from);
                corners[3] = new Vector3(max.x, min.y, -from);

                corners[4] = new Vector3(min.x, min.y, -to);
                corners[5] = new Vector3(min.x, max.y, -to);
                corners[6] = new Vector3(max.x, max.y, -to);
                corners[7] = new Vector3(max.x, min.y, -to);
                break;

            case MegaAxis.Z:
                corners[0] = new Vector3(min.x, from, min.z);
                corners[1] = new Vector3(min.x, from, max.z);
                corners[2] = new Vector3(max.x, from, max.z);
                corners[3] = new Vector3(max.x, from, min.z);

                corners[4] = new Vector3(min.x, to, min.z);
                corners[5] = new Vector3(min.x, to, max.z);
                corners[6] = new Vector3(max.x, to, max.z);
                corners[7] = new Vector3(max.x, to, min.z);
                break;
        }

        Color c = Color.red;
        c.a = gCol1.a;
        Gizmos.color = c;

        DrawEdgeCol(corners[0] - Offset, corners[1] - Offset);
        DrawEdgeCol(corners[1] - Offset, corners[2] - Offset);
        DrawEdgeCol(corners[2] - Offset, corners[3] - Offset);
        DrawEdgeCol(corners[3] - Offset, corners[0] - Offset);

        c = Color.green;
        c.a = gCol1.a;
        Gizmos.color = c;

        DrawEdgeCol(corners[4] - Offset, corners[5] - Offset);
        DrawEdgeCol(corners[5] - Offset, corners[6] - Offset);
        DrawEdgeCol(corners[6] - Offset, corners[7] - Offset);
        DrawEdgeCol(corners[7] - Offset, corners[4] - Offset);
    }