Example #1
0
    public void CenterGizmo()
    {
        MegaModifyObject mod = (MegaModifyObject)gameObject.GetComponent <MegaModifyObject>();
        Vector3          min = Vector3.zero;
        Vector3          max = Vector3.zero;

        MegaUtils.Extents(mod.verts, out min, out max);
        gizmoPos = -((min + max) * 0.5f);
        Debug.Log("pos " + gizmoPos);
    }
Example #2
0
    public void CenterOffset()
    {
        MegaModifyObject mod = (MegaModifyObject)gameObject.GetComponent <MegaModifyObject>();

        Vector3 min = Vector3.zero;
        Vector3 max = Vector3.zero;

        MegaUtils.Extents(mod.verts, out min, out max);
        Offset = -((min + max) * 0.5f);
        Debug.Log("off " + Offset);
        //Offset = (bbox.min + bbox.max) * 0.5f;
    }
    // We should know the mapping
    // remove morph pass tolerance instead
    bool TryMapping1(MegaTargetMesh tm, MegaMorphOMatic morph)
    {
        MegaModifiers mod = morph.GetComponent <MegaModifiers>();

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

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

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

        // need min max on all axis so we can produce an offset to add
        float d1 = ex1.x;
        float d2 = ex2.x;

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

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

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

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

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

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

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

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

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

            morph.mapping = new MegaMomVertMap[morph.oPoints.Length];

            for (int i = 0; i < morph.oPoints.Length; i++)
            {
                //int[] indices = morph.FindVerts(morph.oPoints[i], mod);
                int[] indices = FindVerts(morph.oPoints[i], mod);

                morph.mapping[i]         = new MegaMomVertMap();
                morph.mapping[i].indices = indices;                     //morph.FindVerts(morph.oPoints[i], mod);
            }

            return(true);
        }

        return(false);
    }
    void BuildPolyShape(MegaLoftSection lsection, int steps, Vector3 off, float width)
    {
        int       curve = lsection.curve;
        int       k     = -1;
        Matrix4x4 tm1   = Matrix4x4.identity;
        Vector2   uv    = Vector2.zero;

        float start = crossStart;
        float len   = crossEnd;

        if (lsection.uselen)
        {
            start = lsection.start;
            len   = lsection.length;
        }

        MegaShape shape = lsection.shape;

        verts.Clear();
        uvs.Clear();
        norms.Clear();

        MegaMatrix.Translate(ref tm1, pivot);
        Vector3 rot = crossRot + lsection.rot;

        MegaMatrix.Rotate(ref tm1, new Vector3(Mathf.Deg2Rad * rot.x, Mathf.Deg2Rad * rot.y, Mathf.Deg2Rad * rot.z));

        svert = verts.Count;

        float alpha = start;

        if (shape.splines[curve].closed)
        {
            alpha = Mathf.Repeat(alpha, 1.0f);
        }

        uv.y = start;

        float   dist = 0.0f;
        Vector3 last = Vector3.zero;

        for (int i = 0; i <= steps; i++)
        {
            alpha = start + (((float)i / (float)steps) * len);

            if (shape.splines[curve].closed)
            {
                alpha = Mathf.Repeat(alpha, 1.0f);
            }

            Vector3 pos = tm1.MultiplyPoint3x4(shape.splines[curve].InterpCurve3D(alpha, shape.normalizedInterp, ref k) + off + lsection.offset);

            pos.x *= lsection.scale.x;
            pos.y *= lsection.scale.y;
            pos.z *= lsection.scale.z;
            verts.Add(pos);

            if (physuv)
            {
                if (i > 0)
                {
                    dist += Vector3.Distance(pos, last);
                }

                last = pos;
                uv.x = (dist / width);
            }
            else
            {
                uv.x = alpha;
            }

            uvs.Add(uv);
        }

        evert = verts.Count - 1;

        uv.y = start + len;

        lsection.crossverts = verts.ToArray();
        lsection.crossuvs   = uvs.ToArray();

        lsection.crosssize = MegaUtils.Extents(lsection.crossverts, out lsection.crossmin, out lsection.crossmax);
    }