Ejemplo n.º 1
0
    void TriangulateCube(int index)
    {
        Vector3  positon = allCubePoint[index];
        CubeData data    = CubeData.ToCubeData(datas[index]);

        data.orientate = data.orientate.AddOrientate(PreviewOrientate);


        Vector3[] cubeVertices = GetCubeVertices(positon, data.orientate);



        for (int i = 0; i < 6; i++)
        {
            CubeOrientate temp = (CubeOrientate)i;
            if (i < 4)
            {
                temp = temp.SubOrientate(PreviewOrientate);
                temp = temp.AddOrientate(data.orientate);
            }
            if (!CheckAdjacent(index, (CubeSurface)temp))
            {
                TriangulateCubeSurface(cubeVertices, (CubeSurface)i, data);
            }
        }
    }
Ejemplo n.º 2
0
    public Vector3[] GetViewWireBoxVertices(CubeOrientate orientate)
    {
        Vector3 dir = transform.forward;

        switch (orientate)
        {
        case CubeOrientate.back:
            dir = -transform.forward;
            break;

        case CubeOrientate.left:
            dir = -transform.right;
            break;

        case CubeOrientate.right:
            dir = transform.right;
            break;
        }
        Vector3 center = transform.position + dir * (1 + (localScale - 1) / 2) + transform.up * ((localScale - 1) / 2);

        for (int i = 0; i < viewWireBoxVertices.Length; i++)
        {
            viewWireBoxVertices[i] = transform.InverseTransformPoint(center + CubeMetrics.cubeVertex[i] * localScale);
        }
        return(viewWireBoxVertices);
    }
Ejemplo n.º 3
0
 public CubeData(bool active, bool isTransparent, CubeOrientate orientate, CubeType type)
 {
     this.active        = active;
     this.isTransparent = isTransparent;
     this.orientate     = orientate;
     this.type          = type;
 }
Ejemplo n.º 4
0
 Vector3[] GetCubeVertices(Vector3 position, CubeOrientate orientate)
 {
     for (int i = 0; i < tempVerticesArray.Length; i++)
     {
         tempVerticesArray[i] = transform.InverseTransformPoint(position + CubeMetrics.GetCubeVertexByOrientate(i, orientate));
     }
     return(tempVerticesArray);
 }
Ejemplo n.º 5
0
    public static CubeData ToCubeData(byte data)
    {
        bool _active        = (data & 1 << 0) != 0;
        bool _isTransparent = (data & 1 << 1) != 0;

        CubeOrientate _orientate = (CubeOrientate)((data & 3 << 2) >> 2);

        CubeType _type = (CubeType)((data & 15 << 4) >> 4);

        return(new CubeData(_active, _isTransparent, _orientate, _type));
    }
Ejemplo n.º 6
0
 void TriangualteAllCubes(CubeOrientate orientate)
 {
     GetCurrentCubePoints(orientate);
     for (int i = 0; i < datas.Length; i++)
     {
         CubeData data = CubeData.ToCubeData(datas[i]);
         if (data.active)
         {
             TriangulateCube(i);
         }
     }
 }
Ejemplo n.º 7
0
    public Vector3 [] GetCurrentCubePoints(CubeOrientate orientate)
    {
        Vector3 dirX = transform.right;
        Vector3 dirZ = transform.forward;

        switch (orientate)
        {
        case CubeOrientate.back:
            dirX = -transform.right;
            dirZ = -transform.forward;
            break;

        case CubeOrientate.left:
            dirX = transform.forward;
            dirZ = -transform.right;

            break;

        case CubeOrientate.right:
            dirX = -transform.forward;
            dirZ = transform.right;
            break;
        }
        Vector3 deltaX     = dirX * CubeMetrics.CUBE_SIDE_LENGTH;
        Vector3 deltaY     = Vector3.up * CubeMetrics.CUBE_SIDE_LENGTH;
        Vector3 deltaZ     = dirZ * CubeMetrics.CUBE_SIDE_LENGTH;
        Vector3 startPoint = transform.position + deltaZ
                             - (deltaX * (localScale / 2));

        for (int y = 0; y < localScale; y++)
        {
            for (int z = 0; z < localScale; z++)
            {
                for (int x = 0; x < localScale; x++)
                {
                    int index = x + y * localScale * localScale + z * localScale;
                    try
                    {
                        allCubePoint[index] = startPoint + (x * deltaX) + (y * deltaY) + (z * deltaZ);
                    }
                    catch
                    {
                        Debug.LogError("index error :" + index + "(" + x + "," + y + "," + z + ")");
                    }
                }
            }
        }
        return(allCubePoint);
    }
Ejemplo n.º 8
0
    void CubeOrientateUpdate()
    {
        int orientTemp = (int)Orientate;

        if (Input.GetKeyDown(KeyCode.Q))
        {
            //Debug.Log("q");
            Orientate = orientTemp - 1 < 0 ? (CubeOrientate)(orientTemp + 3) : (CubeOrientate)(orientTemp - 1);
        }
        else if (Input.GetKeyDown(KeyCode.E))
        {
            //Debug.Log("e");
            Orientate = orientTemp + 1 > 3 ? (CubeOrientate)(orientTemp - 3) : (CubeOrientate)(orientTemp + 1);
        }
    }
Ejemplo n.º 9
0
    void SetDataFromPreviewBox(CubeOrientate orientate)
    {
        var allPoint = GetCurrentCubePoints(orientate);

        for (int i = 0; i < datas.Length; i++)
        {
            CubeData data = CubeData.ToCubeData(datas[i]);
            if (data.active)
            {
                data.orientate     = data.orientate.AddOrientate(orientate);
                data.isTransparent = true;
                grid.SetCubeData(allPoint[i], data.ToByte());
                BuilderAI.pendingPosList.Enqueue(allPoint[i]);
            }
        }
    }
Ejemplo n.º 10
0
    void GetDataFromPreviewBox(CubeOrientate orientate)
    {
        var allPoint = GetCurrentCubePoints(orientate);

        for (int i = 0; i < allPoint.Length; i++)
        {
            CubeData data = CubeData.ToCubeData(grid.GetCubeData(allPoint[i]));
            if (!data.isTransparent && data.active)
            {
                data.orientate = data.orientate.SubOrientate(orientate);
                datas[i]       = data.ToByte();
            }
            else
            {
                datas[i] = byte.MinValue;
            }
        }
    }
Ejemplo n.º 11
0
    bool GetAdjacentPath(CubeCoordinate coordinate, CubeOrientate orientate, out CubeCoordinate result)
    {
        AdjacentDirection temp = AdjacentDirection.front;

        switch (orientate)
        {
        case CubeOrientate.back:
            temp = AdjacentDirection.back;
            break;

        case CubeOrientate.left:
            temp = AdjacentDirection.left;
            break;

        case CubeOrientate.right:
            temp = AdjacentDirection.right;
            break;
        }
        if (HasCube(coordinate.GetAdjacentCoordinate(temp, AdjacentDirection.up, AdjacentDirection.up)))
        {
            result = coordinate.GetAdjacentCoordinate(temp, AdjacentDirection.up, AdjacentDirection.up);
            return(false);
        }
        if (HasCube(coordinate.GetAdjacentCoordinate(temp, AdjacentDirection.up)))
        {
            result = coordinate.GetAdjacentCoordinate(temp, AdjacentDirection.up);
            return(true);
        }
        if (HasCube(coordinate.GetAdjacentCoordinate(temp)))
        {
            result = coordinate.GetAdjacentCoordinate(temp);
            return(true);
        }
        if (HasCube(coordinate.GetAdjacentCoordinate(temp, AdjacentDirection.down)))
        {
            result = coordinate.GetAdjacentCoordinate(temp, AdjacentDirection.down);
            return(true);
        }
        result = new CubeCoordinate(0, 0, 0);
        return(false);
    }
Ejemplo n.º 12
0
    public static Vector3 GetCubeVertexByOrientate(int index, CubeOrientate orientate)
    {
        switch (orientate)
        {
        case CubeOrientate.front:

            return(Matrix3x3Operation(Vector3.right, Vector3.up, Vector3.forward, cubeVertex[index]));

        case CubeOrientate.right:
            return(Matrix3x3Operation(Vector3.back, Vector3.up, Vector3.right, cubeVertex[index]));

        case CubeOrientate.back:
            return(Matrix3x3Operation(Vector3.left, Vector3.up, Vector3.back, cubeVertex[index]));

        case CubeOrientate.left:
            return(Matrix3x3Operation(Vector3.forward, Vector3.up, Vector3.left, cubeVertex[index]));

        default:
            return(cubeVertex[index]);
        }
    }
Ejemplo n.º 13
0
    public void TriangualtePreview(PreviewMode previewMode, CubeOrientate orientate, CubeData data,
                                   CharacherCubeControlType type)
    {
        mode             = previewMode;
        PreviewOrientate = orientate;
        controlType      = type;

        Clear();
        if (mode == PreviewMode.cube)
        {
            TriangulateCube(transform.position, data);
        }
        else
        {
            TriangulatePreviewWire(orientate);
            if (controlType == CharacherCubeControlType.add)
            {
                TriangualteAllCubes(orientate);
            }
        }
        Apply();
    }
Ejemplo n.º 14
0
 void TriangulatePreviewWire(CubeOrientate orientate)
 {
     GetViewWireBoxVertices(orientate);
     mesh.AddQuad(viewWireBoxVertices[6], viewWireBoxVertices[7], viewWireBoxVertices[4], viewWireBoxVertices[5], 1);
     mesh.AddQuadUV(0f, 1f, 0f, 1f);
 }
Ejemplo n.º 15
0
    public static CubeOrientate SubOrientate(this CubeOrientate orientate, CubeOrientate target)
    {
        int temp = ((int)orientate - (int)target) % 4;

        return(temp < 0 ? (CubeOrientate)(temp + 4) : (CubeOrientate)temp);
    }
Ejemplo n.º 16
0
 public static CubeOrientate AddOrientate(this CubeOrientate orientate, CubeOrientate target)
 {
     return((CubeOrientate)(((int)orientate + (int)target) % 4));
 }