Esempio n. 1
0
    // Use this for initialization
    void Start()
    {
        instance = this;
        //Init ();

        m_charaMat = gameObject.GetComponent <MeshRenderer> ().materials [0];
        m_mesh     = gameObject.GetComponent <MeshFilter> ().mesh;

        vertices = new Vector3[MAX_VERTS * MAX_CHARA];
        indices  = new int[MAX_VERTS * MAX_CHARA];
        uvs      = new Vector2[MAX_VERTS * MAX_CHARA];
        uvs2     = new Vector2[MAX_VERTS * MAX_CHARA];

        for (int i = 0; i < MAX_CHARA; i++)
        {
            AnimationChara a = new AnimationChara();
            float          x = Random.Range(-50f, 50f);
            float          z = Random.Range(-50f, 50f);
            float          y = Random.Range(-50f, 50f);

            /*
             * x = (float)i;
             * z = 0f;
             */

            if (i < 30)
            {
                x = Random.Range(-5f, 5f);
                z = Random.Range(-5f, 5f);
                y = Random.Range(-5f, 5f);
            }

            a.countTime = Random.Range(0.05f, 0.08f);
            a.Create(new Vector3(x, y, z), i * MAX_VERTS);
            animations.Add(a);
        }

        for (int i = 0; i < animations.Count; i++)
        {
            animations [i].Loop();
        }
        UpdateMesh2();
    }
Esempio n. 2
0
    public void CreatePlane(Vector3 pos)
    {
        BoneMain instance = BoneMain.GetInstance();

        instance.vertices[m_startIndex]     = new Vector3(-0.5f, 0f, 0f);    //0
        instance.vertices[m_startIndex + 1] = new Vector3(-0.5f, 1f, 0f);    //1
        instance.vertices[m_startIndex + 2] = new Vector3(0.5f, 0f, 0f);     // 5
        instance.vertices[m_startIndex + 3] = new Vector3(-0.5f, 1f, 0f);    //1
        instance.vertices[m_startIndex + 4] = new Vector3(0.5f, 1f, 0f);     // 4
        instance.vertices[m_startIndex + 5] = new Vector3(0.5f, 0f, 0f);     // 5

        instance.vertices[m_startIndex + 6]  = new Vector3(-0.5f, 1f, 0f);   //1
        instance.vertices[m_startIndex + 7]  = new Vector3(-0.5f, 1.5f, 0f); //2
        instance.vertices[m_startIndex + 8]  = new Vector3(0.5f, 1f, 0f);    // 4
        instance.vertices[m_startIndex + 9]  = new Vector3(-0.5f, 1.5f, 0f); //2
        instance.vertices[m_startIndex + 10] = new Vector3(0.5f, 1.5f, 0f);  //3
        instance.vertices[m_startIndex + 11] = new Vector3(0.5f, 1f, 0f);    // 4

        instance.indices[m_startIndex]     = 0;                              //0
        instance.indices[m_startIndex + 1] = 1;                              //1
        instance.indices[m_startIndex + 2] = 5;                              //5
        instance.indices[m_startIndex + 3] = 1;                              //1
        instance.indices[m_startIndex + 4] = 4;                              //4
        instance.indices[m_startIndex + 5] = 5;                              //5

        instance.indices[m_startIndex + 6]  = 1;                             //1
        instance.indices[m_startIndex + 7]  = 2;                             //2
        instance.indices[m_startIndex + 8]  = 4;                             //4
        instance.indices[m_startIndex + 9]  = 2;                             //2
        instance.indices[m_startIndex + 10] = 3;                             //3
        instance.indices[m_startIndex + 11] = 4;                             //4

        instance.uvs[m_startIndex]     = new Vector2(0f, 0f);                //0
        instance.uvs[m_startIndex + 1] = new Vector2(0f, 0.6f);              //1
        instance.uvs[m_startIndex + 2] = new Vector2(1f, 0f);                //5
        instance.uvs[m_startIndex + 3] = new Vector2(0f, 0.6f);              //1
        instance.uvs[m_startIndex + 4] = new Vector2(1f, 0.6f);              //4
        instance.uvs[m_startIndex + 5] = new Vector2(1f, 0f);                //5

        instance.uvs[m_startIndex + 6]  = new Vector2(0f, 0.6f);             //1
        instance.uvs[m_startIndex + 7]  = new Vector2(0f, 1f);               //2
        instance.uvs[m_startIndex + 8]  = new Vector2(1f, 0.6f);             //4
        instance.uvs[m_startIndex + 9]  = new Vector2(0f, 1f);               //2
        instance.uvs[m_startIndex + 10] = new Vector2(1f, 1f);               //3
        instance.uvs[m_startIndex + 11] = new Vector2(1f, 0.6f);             //4

        instance.uvs2[m_startIndex]     = new Vector2((float)m_startIndex, 0f);
        instance.uvs2[m_startIndex + 1] = new Vector2((float)m_startIndex + 1, 0f);
        instance.uvs2[m_startIndex + 2] = new Vector2((float)m_startIndex + 2, 0f);
        instance.uvs2[m_startIndex + 3] = new Vector2((float)m_startIndex + 3, 0f);
        instance.uvs2[m_startIndex + 4] = new Vector2((float)m_startIndex + 4, 0f);
        instance.uvs2[m_startIndex + 5] = new Vector2((float)m_startIndex + 5, 0f);

        instance.uvs2[m_startIndex + 6]  = new Vector2((float)m_startIndex + 6, 0f);
        instance.uvs2[m_startIndex + 7]  = new Vector2((float)m_startIndex + 7, 0f);
        instance.uvs2[m_startIndex + 8]  = new Vector2((float)m_startIndex + 8, 0f);
        instance.uvs2[m_startIndex + 9]  = new Vector2((float)m_startIndex + 9, 0f);
        instance.uvs2[m_startIndex + 10] = new Vector2((float)m_startIndex + 10, 0f);
        instance.uvs2[m_startIndex + 11] = new Vector2((float)m_startIndex + 11, 0f);

        instance.faceCount++;

        Quaternion rotation = Quaternion.Euler(0f, 0f, 0f);
        Matrix4x4  m        = Matrix4x4.identity;

        m.SetTRS(pos, rotation, scale);

        for (int i = m_startIndex; i < m_startIndex + 12; i++)
        {
            Vector3 newVert = m.MultiplyPoint3x4(instance.vertices[i] - pivot);
            instance.vertices [i] = newVert;
        }
        position = pos;
    }
Esempio n. 3
0
    public void Loop()
    {
        BoneMain instance = BoneMain.GetInstance();

        count += countTime;
        float s = Mathf.Sin(count);
        float a = 0.3f * s;

        for (int i = 0; i < bones.Count; i++)
        {
            Matrix4x4 m = MatrixUtils.RotateY(a);
            bones [i].matrixBone = bones [i].matrixInit * m;
        }

        Bone.UpdateBone(bones[0], gmat);

        for (int i = 0; i < bones.Count; i++)
        {
            combMatArr[i] = bones[i].matrixComb;
        }

        int index = 0;

        for (int i = 0; i < 6; i++)
        {
            int idxBase = index * 3;
            int idx0    = idxBase + 0;
            int idx1    = idxBase + 1;
            int idx2    = idxBase + 2;

            Matrix4x4[] comb1 =
            {
                Matrix4x4.identity,
                Matrix4x4.identity,
                Matrix4x4.identity,
                Matrix4x4.identity
            };
            Matrix4x4 comb2 = Matrix4x4.zero;

            for (var j = 0; j < 3; j++)
            {
                int boneIdx   = index * 4 + j;
                int weightIdx = index * 3 + j;

                comb1[j] = MatrixUtils.MultiplyScalar(combMatArr[m_planeData.boneIndices[boneIdx]],
                                                      m_planeData.weights[weightIdx], comb1[j]);
            }

            // 1.0 - weight1 - weight2 - weight3
            float weight = 1.0f - (m_planeData.weights[index * 3 + 0] +
                                   m_planeData.weights[index * 3 + 1] +
                                   m_planeData.weights[index * 3 + 2]);
            comb1[3] = MatrixUtils.MultiplyScalar(combMatArr[m_planeData.boneIndices[index * 4 + 3]], weight, comb1[3]);

            for (int k = 0; k < 4; k++)
            {
                comb2 = MatrixUtils.Add(comb2, comb1 [k], comb2);
            }

            Vector3 pos = newPos [i];
            pos.x = m_planeData.position[idx0];
            pos.y = m_planeData.position[idx1];
            pos.z = m_planeData.position[idx2];

            pos            = comb2.MultiplyVector(pos);
            newVec [index] = pos;
            index++;
        }

        Matrix4x4 m2 = Matrix4x4.identity;

        m2.SetTRS(position, rot, scale);

        index = 0;
        for (int i = m_startIndex; i < m_startIndex + 12; i++)
        {
            Vector3 newVert = m2.MultiplyPoint3x4(newVec [m_planeData.index [index]] - pivot);
            instance.vertices [i] = newVert;
            instance.indices [i]  = i;
            index++;
        }
    }