Example #1
0
    override public void GenerateMeshInChunk(CSBlockType type, Vector3Int posInChunk, Vector3Int globalPos, List <Vector3> vertices, List <Vector2> uv, List <int> triangles)
    {
        TexCoords  texCoords = ChunkMeshGenerator.type2texcoords[(byte)type];
        Vector2Int texPos    = texCoords.front;

        texPos.y = (atlas_row - 1) - texPos.y;

        CSBlockOrientation orient = ChunkManager.GetBlockOrientation(globalPos);

        Mesh stairMesh = GetStairMesh(orient, globalPos);
        int  length    = vertices.Count;

        foreach (Vector3 singleVertex in stairMesh.vertices)
        {
            Vector3 pos = singleVertex + posInChunk;
            vertices.Add(pos);
        }

        foreach (Vector2 singleUV in stairMesh.uv)
        {
            uv.Add(new Vector2((texPos.x + singleUV.x) / atlas_column, (texPos.y + singleUV.y) / atlas_row));
        }

        foreach (int index in stairMesh.triangles)
        {
            triangles.Add(index + length);
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        string text = "Theircraft " + version;

        text += "\n" + GetFPS() + " fps";

        Vector3 pos = PlayerController.instance.transform.position;

        text += string.Format("\nXYZ: {0:0.000} / {1:0.000} / {2:0.000}", pos.x, pos.y, pos.z);
        Vector3Int curBlock = PlayerController.GetCurrentBlock();

        text += string.Format("\nBlock: {0} {1} {2}", curBlock.x, curBlock.y, curBlock.z);
        Vector2Int curChunk = PlayerController.GetCurrentChunk();

        text += string.Format("\nChunk: {0} {1}", curChunk.x, curChunk.y);
        if (WireFrameHelper.render)
        {
            text += string.Format("\nLooking at: {0} {1} {2}", WireFrameHelper.pos.x, WireFrameHelper.pos.y, WireFrameHelper.pos.z);

            CSBlockType type = ChunkManager.GetBlockType(WireFrameHelper.pos);
            text += string.Format("\nType: {0}", type);
            if (type == CSBlockType.BrickStairs)
            {
                CSBlockOrientation orient = ChunkManager.GetBlockOrientation(WireFrameHelper.pos);
                text += string.Format("\nOrient: {0}", orient);
            }
        }
        label.text = text;
    }
Example #3
0
    static Mesh GetMeshNegativeYNegativeZ(Vector3Int globalPosition)
    {
        Mesh mesh = LoadMesh("stair_-y-z");

        if (ChunkManager.IsStairs(globalPosition + forward))
        {
            CSBlockOrientation forwardOrientation = ChunkManager.GetBlockOrientation(globalPosition + forward);
            if (forwardOrientation == CSBlockOrientation.NegativeY_PositiveX)
            {
                mesh = LoadMesh("stair_joint_-y_bottom_right");
            }
            else if (forwardOrientation == CSBlockOrientation.NegativeY_NegativeX)
            {
                mesh = LoadMesh("stair_joint_-y_bottom_left");
            }
        }
        else if (ChunkManager.IsStairs(globalPosition + back))
        {
            CSBlockOrientation backOrientation = ChunkManager.GetBlockOrientation(globalPosition + back);
            if (backOrientation == CSBlockOrientation.NegativeY_PositiveX)
            {
                mesh = LoadMesh("stair_joint_-y_no_top_left");
            }
            else if (backOrientation == CSBlockOrientation.NegativeY_NegativeX)
            {
                mesh = LoadMesh("stair_joint_-y_no_top_right");
            }
        }
        return(mesh);
    }
Example #4
0
    static Mesh GetMesh(CSBlockOrientation orientation = CSBlockOrientation.PositiveY_NegativeX)
    {
        Mesh mesh = null;

        switch (orientation)
        {
        case CSBlockOrientation.PositiveY_PositiveX:
        case CSBlockOrientation.NegativeY_PositiveX:
            mesh = Resources.Load <Mesh>("Meshes/blocks/vertical_slab/vslab_+x");
            break;

        case CSBlockOrientation.PositiveY_NegativeX:
        case CSBlockOrientation.NegativeY_NegativeX:
            mesh = Resources.Load <Mesh>("Meshes/blocks/vertical_slab/vslab_-x");
            break;

        case CSBlockOrientation.PositiveY_PositiveZ:
        case CSBlockOrientation.NegativeY_PositiveZ:
            mesh = Resources.Load <Mesh>("Meshes/blocks/vertical_slab/vslab_+y");
            break;

        case CSBlockOrientation.PositiveY_NegativeZ:
        case CSBlockOrientation.NegativeY_NegativeZ:
            mesh = Resources.Load <Mesh>("Meshes/blocks/vertical_slab/vslab_-y");
            break;
        }

        return(mesh);
    }
Example #5
0
    static Mesh GetMeshNegativeYNegativeX(Vector3Int globalPosition)
    {
        Mesh mesh = LoadMesh("stair_-y-x");

        if (ChunkManager.IsStairs(globalPosition + Vector3Int.right))
        {
            CSBlockOrientation rightOrientation = ChunkManager.GetBlockOrientation(globalPosition + Vector3Int.right);
            if (rightOrientation == CSBlockOrientation.NegativeY_PositiveZ)
            {
                mesh = LoadMesh("stair_joint_-y_top_left");
            }
            else if (rightOrientation == CSBlockOrientation.NegativeY_NegativeZ)
            {
                mesh = LoadMesh("stair_joint_-y_bottom_left");
            }
        }
        else if (ChunkManager.IsStairs(globalPosition + Vector3Int.left))
        {
            CSBlockOrientation leftOrientation = ChunkManager.GetBlockOrientation(globalPosition + Vector3Int.left);
            if (leftOrientation == CSBlockOrientation.NegativeY_PositiveZ)
            {
                mesh = LoadMesh("stair_joint_-y_no_bottom_right");
            }
            else if (leftOrientation == CSBlockOrientation.NegativeY_NegativeZ)
            {
                mesh = LoadMesh("stair_joint_-y_no_top_right");
            }
        }
        return(mesh);
    }
Example #6
0
    override public void GenerateMeshInChunk(CSBlockType type, Vector3Int pos, Vector3Int globalPos, List <Vector3> vertices, List <Vector2> uv, List <int> triangles)
    {
        TexCoords texCoords = ChunkMeshGenerator.type2texcoords[(byte)type];

        if (texCoords.isRotatable)
        {
            Matrix4x4          rotationMatrix = Matrix4x4.identity;
            CSBlockOrientation orient         = ChunkManager.GetBlockOrientation(globalPos);
            if (orient != CSBlockOrientation.Default)
            {
                if (orient == CSBlockOrientation.PositiveY_NegativeZ)
                {
                    rotationMatrix = Matrix4x4.identity;
                }
                else if (orient == CSBlockOrientation.PositiveY_NegativeX)
                {
                    rotationMatrix = Matrix4x4.Rotate(Quaternion.Euler(0, 90, 0));
                }
                else if (orient == CSBlockOrientation.PositiveY_PositiveZ)
                {
                    rotationMatrix = Matrix4x4.Rotate(Quaternion.Euler(0, 180, 0));
                }
                else if (orient == CSBlockOrientation.PositiveY_PositiveX)
                {
                    rotationMatrix = Matrix4x4.Rotate(Quaternion.Euler(0, 270, 0));
                }
            }
            AddFacesNoCull(rotationMatrix, texCoords, pos, vertices, uv, triangles);
        }
        else
        {
            AddFacesCullInvisible(texCoords, pos, globalPos, vertices, uv, triangles);
        }
    }
Example #7
0
 public static void AddBlockOrientation(Vector3Int pos, CSBlockOrientation orientation)
 {
     if (orientation != CSBlockOrientation.Default)
     {
         orientationDict.Add(pos, orientation);
     }
 }
Example #8
0
    public static CSBlockOrientation GetBlockOrientation(Vector3 playerPos, Vector3 blockPos, Vector3 hitPos)
    {
        float diff = hitPos.y - blockPos.y;

        Vector2            dir    = (new Vector2(playerPos.x, playerPos.z) - new Vector2(blockPos.x, blockPos.z)).normalized;
        CSBlockOrientation orient = CSBlockOrientation.Default;

        if (dir.x > 0)
        {
            if (dir.y > 0)
            {
                if (dir.y > dir.x)
                {
                    orient = diff < 0 ? CSBlockOrientation.PositiveY_PositiveZ : CSBlockOrientation.NegativeY_PositiveZ;
                }
                else
                {
                    orient = diff < 0 ? CSBlockOrientation.PositiveY_PositiveX : CSBlockOrientation.NegativeY_PositiveX;
                }
            }
            else
            {
                if (-dir.y > dir.x)
                {
                    orient = diff < 0 ? CSBlockOrientation.PositiveY_NegativeZ : CSBlockOrientation.NegativeY_NegativeZ;
                }
                else
                {
                    orient = diff < 0 ? CSBlockOrientation.PositiveY_PositiveX : CSBlockOrientation.NegativeY_PositiveX;
                }
            }
        }
        else
        {
            if (dir.y > 0)
            {
                if (dir.y > -dir.x)
                {
                    orient = diff < 0 ? CSBlockOrientation.PositiveY_PositiveZ : CSBlockOrientation.NegativeY_PositiveZ;
                }
                else
                {
                    orient = diff < 0 ? CSBlockOrientation.PositiveY_NegativeX : CSBlockOrientation.NegativeY_NegativeX;
                }
            }
            else
            {
                if (-dir.y > -dir.x)
                {
                    orient = diff < 0 ? CSBlockOrientation.PositiveY_NegativeZ : CSBlockOrientation.NegativeY_NegativeZ;
                }
                else
                {
                    orient = diff < 0 ? CSBlockOrientation.PositiveY_NegativeX : CSBlockOrientation.NegativeY_NegativeX;
                }
            }
        }
        return(orient);
    }
Example #9
0
    public void GenerateMeshInChunk(CSBlockType type, Vector3Int _pos, Vector3Int _globalPos, List <Vector3> _vertices, List <Color> _colors, List <Vector2> _uv, List <int> _triangles)
    {
        texCoords      = ChunkMeshGenerator.type2texcoords[(byte)type];
        pos            = _pos;
        globalPos      = _globalPos;
        vertices       = _vertices;
        uv             = _uv;
        triangles      = _triangles;
        colors         = _colors;
        rotationMatrix = Matrix4x4.identity;

        if (texCoords.isRotatable)
        {
            CSBlockOrientation orient = ChunkManager.GetBlockOrientation(globalPos);
            if (orient != CSBlockOrientation.Default)
            {
                if (orient == CSBlockOrientation.PositiveY_NegativeZ)
                {
                    rotationMatrix = Matrix4x4.identity;
                }
                else if (orient == CSBlockOrientation.PositiveY_NegativeX)
                {
                    rotationMatrix = Matrix4x4.Rotate(Quaternion.Euler(0, 90, 0));
                }
                else if (orient == CSBlockOrientation.PositiveY_PositiveZ)
                {
                    rotationMatrix = Matrix4x4.Rotate(Quaternion.Euler(0, 180, 0));
                }
                else if (orient == CSBlockOrientation.PositiveY_PositiveX)
                {
                    rotationMatrix = Matrix4x4.Rotate(Quaternion.Euler(0, 270, 0));
                }
                else if (orient == CSBlockOrientation.X)
                {
                    rotationMatrix = Matrix4x4.Rotate(Quaternion.Euler(-90, 0, 0));
                }
                else if (orient == CSBlockOrientation.Z)
                {
                    rotationMatrix = Matrix4x4.Rotate(Quaternion.Euler(0, 0, 90));
                }
            }
            AddFacesNoCull();
        }
        else
        {
            AddFacesCullInvisible();
        }
    }
Example #10
0
    void AddBlockReq(Vector3Int pos, CSBlockType type, CSBlockOrientation orient = CSBlockOrientation.Default)
    {
        CSAddBlockReq addBlockReq = new CSAddBlockReq
        {
            block = new CSBlock
            {
                position = new CSVector3Int
                {
                    x = pos.x,
                    y = pos.y,
                    z = pos.z
                },
                type   = type,
                orient = orient,
            }
        };

        NetworkManager.SendPkgToServer(ENUM_CMD.CS_ADD_BLOCK_REQ, addBlockReq, AddBlockRes);
    }
Example #11
0
    protected static Mesh LoadMesh(CSBlockOrientation orient = CSBlockOrientation.Y)
    {
        Mesh mesh;

        switch (orient)
        {
        case CSBlockOrientation.X:
            mesh = Resources.Load <Mesh>("Meshes/blocks/log/log_x");
            break;

        case CSBlockOrientation.Z:
            mesh = Resources.Load <Mesh>("Meshes/blocks/log/log_z");
            break;

        case CSBlockOrientation.Y:
        default:
            mesh = Resources.Load <Mesh>("Meshes/blocks/log/log_y");
            break;
        }
        return(mesh);
    }
Example #12
0
    static Mesh GetStairMesh(CSBlockOrientation orientation, Vector3Int globalPosition)
    {
        Mesh mesh = null;

        switch (orientation)
        {
        case CSBlockOrientation.PositiveY_NegativeX:
            mesh = GetMeshPositiveYNegativeX(globalPosition);
            break;

        case CSBlockOrientation.PositiveY_NegativeZ:
            mesh = GetMeshPositiveYNegativeZ(globalPosition);
            break;

        case CSBlockOrientation.PositiveY_PositiveX:
            mesh = GetMeshPositiveYPositiveX(globalPosition);
            break;

        case CSBlockOrientation.PositiveY_PositiveZ:
            mesh = GetMeshPositiveYPositiveZ(globalPosition);
            break;

        case CSBlockOrientation.NegativeY_NegativeX:
            mesh = GetMeshNegativeYNegativeX(globalPosition);
            break;

        case CSBlockOrientation.NegativeY_NegativeZ:
            mesh = GetMeshNegativeYNegativeZ(globalPosition);
            break;

        case CSBlockOrientation.NegativeY_PositiveX:
            mesh = GetMeshNegativeYPositiveX(globalPosition);
            break;

        case CSBlockOrientation.NegativeY_PositiveZ:
            mesh = GetMeshNegativeYPositiveZ(globalPosition);
            break;
        }
        return(mesh);
    }
    static Mesh GetMesh(CSBlockOrientation orientation = CSBlockOrientation.NegativeY_PositiveX)
    {
        Mesh mesh = null;

        switch (orientation)
        {
        case CSBlockOrientation.PositiveY_NegativeX:
        case CSBlockOrientation.PositiveY_NegativeZ:
        case CSBlockOrientation.PositiveY_PositiveX:
        case CSBlockOrientation.PositiveY_PositiveZ:
            mesh = Resources.Load <Mesh>("Meshes/blocks/slab/top");
            break;

        case CSBlockOrientation.NegativeY_NegativeX:
        case CSBlockOrientation.NegativeY_NegativeZ:
        case CSBlockOrientation.NegativeY_PositiveX:
        case CSBlockOrientation.NegativeY_PositiveZ:
        default:
            mesh = Resources.Load <Mesh>("Meshes/blocks/slab/bottom");
            break;
        }
        return(mesh);
    }
Example #14
0
    void Update()
    {
        DrawWireFrame();

        if (acceptInput)
        {
            RotateView();

            if (Input.GetMouseButtonDown(0))
            {
                handAnimator.SetTrigger("interactTrigger");
                if (WireFrameHelper.render)
                {
                    if (WireFrameHelper.pos.y != 0)
                    {
                        DeleteBlockReq(WireFrameHelper.pos);
                    }
                }
            }

            if (Input.GetMouseButtonDown(1))
            {
                if (WireFrameHelper.render && ItemSelectPanel.curBlockType != CSBlockType.None)
                {
                    Vector3Int pos = WireFrameHelper.pos;
                    if (ChunkManager.HasCollidableBlock(WireFrameHelper.pos.x, WireFrameHelper.pos.y, WireFrameHelper.pos.z))
                    {
                        pos = WireFrameHelper.pos + Vector3Int.RoundToInt(hit.normal);
                    }

                    if (!cc.bounds.Intersects(new Bounds(pos, Vector3.one)) && !ChunkManager.HasNotPlantBlock(pos))
                    {
                        if (ItemSelectPanel.curBlockType == CSBlockType.Torch)
                        {
                            AddBlockReq(Vector3Int.RoundToInt(pos), ItemSelectPanel.curBlockType, WireFrameHelper.pos);
                        }
                        else
                        {
                            CSBlockOrientation orientation = ChunkMeshGenerator.GetBlockOrientation(transform.position, pos, WireFrameHelper.hitPos);
                            AddBlockReq(Vector3Int.RoundToInt(pos), ItemSelectPanel.curBlockType, orientation);
                        }
                    }
                }
            }
            if (Input.GetKeyDown(KeyCode.Space))
            {
                Jump();
            }
            if (Input.GetKeyDown(KeyCode.Q))
            {
                ItemSelectPanel.DropCurItem();
            }
        }

        if (needUpdate && Time.realtimeSinceStartup - lastUpdateTime > timeInterval)
        {
            needUpdate     = false;
            lastUpdateTime = Time.realtimeSinceStartup;
            CSHeroMoveReq req = new CSHeroMoveReq
            {
                Position = new CSVector3 {
                    x = transform.position.x, y = transform.position.y, z = transform.position.z
                },
                Rotation = new CSVector3 {
                    x = 0, y = transform.localEulerAngles.y, z = camera.transform.localEulerAngles.x
                }
            };
            NetworkManager.SendPkgToServer(ENUM_CMD.CS_HERO_MOVE_REQ, req);
        }
    }
Example #15
0
 public static void AddBlockOrientation(Vector3Int pos, CSBlockOrientation orientation)
 {
     orientationDict.Add(pos, orientation);
 }