Beispiel #1
0
    //---------------------------------------------------------------------------------------------------
    /// <summary>
    /// Method to move the face with adding the 'move' vector, used for faceSnap. Works only of the vertical faces.
    /// </summary>
    /// <param name="colliderName">Collider that is hit, if it is the same as this obj then run the function.</param>
    /// <param name="move">Vector to add to the move vector, used for snap jump.</param>
    public void MoveFace(string colliderName, Vector3 move)
    {
        if (this.name == colliderName)
        {
            // First get the vector between savedProjectedTarget and actualProjectedTarget, this is done in
            // order to avoid jumping the face location when the mouse is clicked.
            //Vector3 diff = (PROJECTED_TARGET + move) - savedProjectedTarget;
            Vector3 diff = _diffMove + move;
            for (int i = 0; i < VertexIndexCon.Length; i++)
            {
                // Get the container index (Check Rhino file for these indexes).
                int contIndex = VertexIndexCon[i];
                // Get the actual container that stores vertix index with the same coordinates.
                int[] vertexIndex = BLOCK_COMP.VertexIndexCon[contIndex];
                for (int j = 0; j < vertexIndex.Length; j++)
                {
                    // Get the index of vertex from BLOCK_COMP.vertex_index_con - this represent 3 vertices
                    // per container that share the same location
                    int index = vertexIndex[j];
                    // Get the actual vertex from mesh.
                    // When moving a face, in addition to its 4 vertices, this will move adjacent face's verts.

                    //BLOCK_COMP.vertices[index] += moveDir * 0.05f;

                    //if (BLOCK_COMP.name == "Block" && this.name == "face_pos_z") print(move.magnitude);

                    // Before adding the "diff" vector convert it to local sapace, otherwise it won't work when the block is rotated.
                    BLOCK_COMP.Vertices[index] = BLOCK_COMP.VerticesSaved[index] + BLOCK_COMP.transform.InverseTransformVector(diff);
                    // If snap face is active move it accordingly
                }
            }
            // Update block vertices with freshly moved ones.
            BLOCK_COMP.BlockMesh.vertices = BLOCK_COMP.Vertices;
            BLOCK_COMP.UpdateProximityCollider();
        }
    }
Beispiel #2
0
    //---------------------------------------------------------------------------------------------------
    /// <summary>
    /// Method to move the face. Works only of the vertical faces.
    /// </summary>
    /// <param name="colliderName">Collider that is hit, if it is the same as this obj then run the function.</param>
    public void MoveFace(string colliderName)
    {
        if (this.name == colliderName)
        {
            //if (BLOCK_COMP.name == "Block" && this.name == "face_pos_z") print("diff: " + diff.magnitude);
            if (Input.GetKeyDown(KeyCode.Z))
            {
                //Vector3 diffMod = diff;
                //diffMod.Normalize();
                //print("diffMod: " + (diff + (diffMod * 10f)));
                //diffMove += diffMod * 0.2f;
            }
            for (int i = 0; i < VertexIndexCon.Length; i++)
            {
                // Get the container index (Check Rhino file for these indexes).
                int contIndex = VertexIndexCon[i];
                // Get the actual container that stores vertix index with the same coordinates.
                int[] vertexIndex = BLOCK_COMP.VertexIndexCon[contIndex];
                for (int j = 0; j < vertexIndex.Length; j++)
                {
                    // Get the index of vertex from BLOCK_COMP.vertex_index_con - this represent 3 vertices
                    // per container that share the same location
                    int index = vertexIndex[j];
                    // Get the actual vertex from mesh.
                    // When moving a face, in addition to its 4 vertices, this will move adjacent face's verts.

                    // Before adding the "diff" vector convert it to local space, otherwise it won't work when the block is rotated.
                    BLOCK_COMP.Vertices[index] = BLOCK_COMP.VerticesSaved[index] + BLOCK_COMP.transform.InverseTransformVector(DYNAMIC_DIFF);
                    // If snap face is active move it accordingly
                }
            }
            // Update block vertices with freshly moved ones.
            BLOCK_COMP.BlockMesh.vertices = BLOCK_COMP.Vertices;
            BLOCK_COMP.UpdateProximityCollider();
        }
    }