Example #1
0
    private void saveTriangleIndexToFile(string fileName)
    {
        float[] shoulderL = planes.getControlPlane("shoulderLeft");
        float[] shoulderR = planes.getControlPlane("shoulderRight");
        //float[] back = planes.getControlPlane ("back");

        int[] tri = clothMesh.triangles;
        //Vector3[] vertices = clothMesh.vertices;
        Vector3[] vertices = clothVertices;
        string    data     = "";
        int       index    = 0;

        for (int i = 0; i < tri.Length; i += 3, index++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (!AuxMath.isAbovePlane(vertices [tri [i + j]], shoulderL) &&
                    !AuxMath.isAbovePlane(vertices [tri [i + j]], shoulderR)
                    )
                {
                    data += index.ToString() + " ";
                    break;
                }
            }
        }
        FileOperator.SaveDataToFile(fileName, data);
    }
Example #2
0
    // 胸围
    private void scaleBustGrith(float scale)
    {
        Vector3[] old    = sizedMesh.vertices;
        Vector3[] tmp    = templateMesh.vertices;
        Vector3[] tmpLen = templateLenMesh.vertices;
        ArrayList vertex = templateBody.vertexIndexsPerBone [HumanBone.Spine2];

        float[] top         = planes.getControlPlane("PlaneBustTop");
        float[] topL        = planes.getControlPlane("PlaneBustTopLeft");
        float[] topR        = planes.getControlPlane("PlaneBustTopRight");
        float[] bust        = planes.getControlPlane("PlaneBust");
        float[] bottom      = planes.getControlPlane("PlaneBustBottom");
        Vector3 busthNormal = new Vector3(bust [0], bust [1], bust [2]);

        // Scale the left thigh
        for (int i = 0; i < vertex.Count; ++i)
        {
            if (AuxMath.isAbovePlane(tmp [(int)vertex [i]], top) !=
                AuxMath.isAbovePlane(tmp [(int)vertex [i]], bottom))
            {
                if (!AuxMath.isAbovePlane(tmp [(int)vertex [i]], topL) &&
                    !AuxMath.isAbovePlane(tmp [(int)vertex [i]], topR))
                {
                    Vector3 projectNormal = AuxMath.projectOnPlane(templateMesh.normals [(int)vertex [i]],
                                                                   busthNormal);
                    float cosAngel = Vector3.Dot(projectNormal.normalized, Vector3.forward);
                    float k        = (scale - 1.0f) * cosAngel +
                                     Mathf.Sqrt((scale - 1.0f) * (scale - 1.0f) * cosAngel * cosAngel + 2 * scale - 1);
                    old [(int)vertex [i]] = tmpLen [(int)vertex [i]] +
                                            (templateMesh.normals [(int)vertex [i]] * (k - 1.0f) * measurement [HumanSize.Bust_Grith]);
                }
            }
        }
        sizedMesh.vertices = old;
    }
Example #3
0
    // 臀围
    private void scaleHipGrith(float scale)
    {
        Vector3[] old    = sizedMesh.vertices;
        Vector3[] tmp    = templateMesh.vertices;
        Vector3[] tmpLen = templateLenMesh.vertices;
        ArrayList vertex = templateBody.vertexIndexsPerBone [HumanBone.Pelvis];
        float     top    = planes.getPlaneHeight("PlaneHipTop");

        float[] topPlane = planes.getControlPlane("PlaneHipTop");
        float   hip      = planes.getPlaneHeight("PlaneHip");
        float   bottom   = planes.getPlaneHeight("PlaneHipBottom");
        float   height   = top - bottom;
        float   std      = ControlPoints.hipBezier.getBezierPoint((hip - bottom) / height).z;

        for (int i = 0; i < vertex.Count; ++i)
        {
            if (!AuxMath.isAbovePlane(tmp [(int)vertex [i]], topPlane) && tmp [(int)vertex [i]].y > bottom)
            {
                float   ratio         = (tmp [(int)vertex [i]].y - bottom) / height;
                float   p             = (ControlPoints.hipBezier.getBezierPoint(ratio).z - std) / 5.0f + 1.0f;
                Vector3 projectNormal = AuxMath.projectOnPlane(templateMesh.normals [(int)vertex [i]], Vector3.up);
                float   cosAngel      = Vector3.Dot(projectNormal.normalized, Vector3.back);
                float   k             = (scale - 1.0f) * cosAngel +
                                        Mathf.Sqrt((scale - 1.0f) * (scale - 1.0f) * cosAngel * cosAngel + 2 * scale - 1);
                old [(int)vertex [i]] = tmpLen [(int)vertex [i]] +
                                        (templateMesh.normals [(int)vertex [i]] * (k - 1.0f) * measurement [HumanSize.Hip_Grith] * p);
            }
        }
        sizedMesh.vertices = old;
    }
Example #4
0
    // 大腿围
    private void scaleThighGrith(float scale)
    {
        Vector3[] old    = sizedMesh.vertices;
        Vector3[] tmp    = templateMesh.vertices;
        Vector3[] tmpLen = templateLenMesh.vertices;
        ArrayList vertex = templateBody.vertexIndexsPerBone [HumanBone.L_Thigh];

        float[] top         = planes.getControlPlane("PlaneThighTopLeft");
        float[] thigh       = planes.getControlPlane("PlaneThigh");
        float[] bottom      = planes.getControlPlane("PlaneThighBottom");
        Vector3 thighNormal = new Vector3(thigh [0], thigh [1], thigh [2]);

        // Scale the left thigh
        for (int i = 0; i < vertex.Count; ++i)
        {
            if (AuxMath.isAbovePlane(tmp [(int)vertex [i]], top) !=
                AuxMath.isAbovePlane(tmp [(int)vertex [i]], bottom))
            {
                Vector3 projectNormal = AuxMath.projectOnPlane(templateMesh.normals [(int)vertex [i]],
                                                               thighNormal);
                float cosAngel = Vector3.Dot(projectNormal.normalized, Vector3.back);
                float k        = (scale - 1.0f) * cosAngel +
                                 Mathf.Sqrt((scale - 1.0f) * (scale - 1.0f) * cosAngel * cosAngel + 2 * scale - 1);
                old [(int)vertex [i]] = tmpLen [(int)vertex [i]] +
                                        (templateMesh.normals [(int)vertex [i]] * (k - 1.0f) * measurement [HumanSize.Thigh_Grith]);
            }
        }
        // Scale the Right Thigh
        vertex = templateBody.vertexIndexsPerBone [HumanBone.R_Thigh];
        top    = planes.getControlPlane("PlaneThighTopRight");
        for (int i = 0; i < vertex.Count; ++i)
        {
            if (AuxMath.isAbovePlane(tmp [(int)vertex [i]], top) !=
                AuxMath.isAbovePlane(tmp [(int)vertex [i]], bottom))
            {
                Vector3 projectNormal = AuxMath.projectOnPlane(templateMesh.normals [(int)vertex [i]],
                                                               thighNormal);
                float cosAngel = Vector3.Dot(projectNormal.normalized, Vector3.back);
                float k        = (scale - 1.0f) * cosAngel +
                                 Mathf.Sqrt((scale - 1.0f) * (scale - 1.0f) * cosAngel * cosAngel + 2 * scale - 1);
                old [(int)vertex [i]] = tmpLen [(int)vertex [i]] +
                                        (templateMesh.normals [(int)vertex [i]] * (k - 1.0f) * measurement [HumanSize.Thigh_Grith]);
            }
        }
        sizedMesh.vertices = old;
    }
Example #5
0
    private void initGrith(string planeName, HumanSize grithKey, HumanBone planeInBone)
    {
        float[] plane = { 0.0f, 0.0f, 0.0f, 0.0f };
        planes.getControlPlane(planeName, plane);
        ArrayList grithList = new ArrayList();
        ArrayList edgeList  = templateBody.edgeIndexsPerBone [planeInBone];

        for (int i = 0; i < edgeList.Count; i++)
        {
            Edge e = edgeList [i] as Edge;
            if (AuxMath.isAbovePlane(templateMesh.vertices [e.e1], plane) !=
                AuxMath.isAbovePlane(templateMesh.vertices [e.e2], plane))
            {
                Vector3 intersectPoint = AuxMath.intersectPlane(templateMesh.vertices [e.e1],
                                                                templateMesh.vertices [e.e2],
                                                                plane);
                if (intersectPoint != AuxMath.nullVector)
                {
                    if (HumanSize.Thigh_Grith == grithKey)
                    {
                        if (intersectPoint.x < 0.0f)
                        {
                            grithList.Add(intersectPoint);
                        }
                    }
                    else
                    {
                        grithList.Add(intersectPoint);
                    }
                }
            }
        }
        if (grithList.Count > 0)
        {
            ArrayList grithIndex = new ArrayList();
            AuxMath.convexInPlane(new Vector3(plane [0], plane [1], plane [2]),
                                  grithList, grithIndex);
            initMeasurements [(int)grithKey - 1] = AuxMath.getLength(grithIndex, grithList);
            measurement [grithKey] = initMeasurements [(int)grithKey - 1] / (2.0f * Mathf.PI);
        }
    }