コード例 #1
0
ファイル: Box.cs プロジェクト: niyuang2018/Portfolio
    private void initializeRandomness()
    {
        length = Random.Range(0.5f, maxLength);
        width  = Random.Range(0.5f, maxWidth);

        height = Random.Range(10.0f / ProceduralUtil.getDistanceTowardsCenter(gameObject.transform.position),
                              10.0f / ProceduralUtil.getDistanceTowardsCenter(gameObject.transform.position) + heightFraction);
    }
コード例 #2
0
ファイル: Box.cs プロジェクト: niyuang2018/Portfolio
    void Start()
    {
        _render = gameObject.AddComponent <MeshRenderer>();
        _filter = gameObject.AddComponent <MeshFilter>();
        _mesh   = _filter.mesh;

        // generate Random level of towers
        meshList.Add(ProceduralUtil.extrudeAFace(this, baseVertices, Height, false));

        // need to perform strip in the first place or top face vertice will be overwritten
        int   strip       = Random.Range(0, 3);
        float stripSize   = Random.Range(0.0f, 0.2f);
        float stripHeight = Random.Range(0.0f, Height);

        if (strip == 0)
        {
            for (int i = 0; i < baseVertices.Length; i++)
            {
                Vector3[] squareBase = new Vector3[4];
                squareBase = ProceduralUtil.generateSquareBaseFromVertice(baseVertices[i], stripSize);

                meshList.Add(ProceduralUtil.extrudeAFace(this, squareBase, stripHeight, true));
            }
            // only generate strip lines if the building is a cube
        }

        float randomHeightLevel = Random.Range(0.1f, 0.3f);

        int   numberOfLevel = Random.Range(0, 5);
        float randomRatio   = Random.Range(0.0f, 1.0f);

        for (int i = 0; i < numberOfLevel; i++)
        {
            // set level resizing offset
            meshList.Add(ProceduralUtil.extrudeAFaceWithLevels(this, lastExtrudedFaceVertices, Height, Length, randomHeightLevel, randomRatio));

            meshList.Add(ProceduralUtil.extrudeAFaceWithLevels(this, lastExtrudedFaceVertices, Height, Length, randomHeightLevel, 1.0f / randomRatio));
        }

        // Generate Attachment
        generateBoard();

        // Combine Mesh
        Mesh combinedMesh = ProceduralUtil.combineMeshes(gameObject.transform, meshList, false);

        combineMeshTriangles = new List <int>(combinedMesh.triangles);

        // need to set filter mesh before call findTrianglesWIthinVertices
        this._filter.mesh = combinedMesh;

        // AssignMaterial
        assignMaterial(combinedMesh);
    }
コード例 #3
0
ファイル: Box.cs プロジェクト: niyuang2018/Portfolio
    private void generateBoard()
    {
        // 1 / 6 chance to generate a board
        //int generateABoard = Random.Range(1, 4);
        //if (generateABoard == 1)
        //{
        meshList.Add(ProceduralUtil.generateBoardOnRoof(this));
        //}

        //generateABoard = Random.Range(1, 4);
        //if (generateABoard == 1)
        //{
        // meshList.Add(ProceduralUtil.generateBoardOnSide(this));
        //}
    }
コード例 #4
0
ファイル: Box.cs プロジェクト: niyuang2018/Portfolio
    private void initializeBaseShapeType()
    {
        // Random BaseShape
        int baseShape = Random.Range(0, 3);

        if (baseShape == 0)
        {
            baseVertices = ProceduralUtil.generateSquareBaseFace(transform, Width, Length).ToArray();
        }
        else if (baseShape == 1)
        {
            baseVertices = ProceduralUtil.generateBaseShape_1(transform, Width, Length, 0.1f).ToArray();
        }
        else if (baseShape == 2)
        {
            baseVertices = ProceduralUtil.generateBaseShape_2(transform, Width, Length, 0.1f).ToArray();
        }

        // load baseshape xml

        // assign BaseVertuces
    }
コード例 #5
0
    void Awake()
    {
        length = Random.Range(0.5f, maxLength);
        width  = Random.Range(0.5f, maxWidth);
        height = Random.Range(10.0f / getDistanceTowardsCenter(), 10.0f / getDistanceTowardsCenter() + heightFraction);

        // Random BaseShape
        int baseShape = Random.Range(0, 3);

        if (baseShape == 0)
        {
            baseVertices = ProceduralUtil.generateSquareBaseFace(transform, Width, Length).ToArray();
        }
        else if (baseShape == 1)
        {
            baseVertices = ProceduralUtil.generateBaseShape_1(transform, Width, Length, 0.1f).ToArray();
        }
        else if (baseShape == 2)
        {
            baseVertices = ProceduralUtil.generateBaseShape_2(transform, Width, Length, 0.1f).ToArray();
        }

        additionTextured = new List <List <Vector3> >();
    }
コード例 #6
0
    void Start()
    {
        _render = gameObject.AddComponent <MeshRenderer>();

        // Main building material
        selfIlluminMainBuilding = Resources.Load("Materials/apt_4", typeof(Material)) as Material;
        selfIlluminMainBuilding.SetColor("_EmissionColor", Color.white);

        int     randomEmissionMap = Random.Range(4, 6);
        Texture emission          = Resources.Load("Texture/emission_" + randomEmissionMap, typeof(Texture)) as Texture;

        selfIlluminMainBuilding.SetTexture("_EmissionMap", emission);

        boardMaterial = Resources.Load("Materials/board", typeof(Material)) as Material;

        _filter = gameObject.AddComponent <MeshFilter>();
        _mesh   = _filter.mesh;

        // generate Random level of towers
        _meshList.Add(ProceduralUtil.extrudeAFace(this, baseVertices, Height, false));

        // need to perform strip in the first place or top face vertice will be overwritten
        int   strip       = Random.Range(0, 3);
        float stripSize   = Random.Range(0.0f, 0.2f);
        float stripHeight = Random.Range(0.0f, Height);

        if (strip == 0)
        {
            for (int i = 0; i < baseVertices.Length; i++)
            {
                Vector3[] squareBase = new Vector3[4];
                squareBase = ProceduralUtil.generateSquareBaseFromVertice(baseVertices[i], stripSize);

                _meshList.Add(ProceduralUtil.extrudeAFace(this, squareBase, stripHeight, true));
            }
            // only generate strip lines if the building is a cube
        }

        int   preserveResizeRatio = Random.Range(0, 4);
        float randomHeightLevel   = Random.Range(0.1f, 0.3f);

        if (preserveResizeRatio == 0)
        {
            int   numberOfLevel = Random.Range(0, 5);
            float randomRatio   = Random.Range(0.0f, 1.0f);
            for (int i = 0; i < numberOfLevel; i++)
            {
                _meshList.Add(ProceduralUtil.extrudeAFaceWithLevels(this, extrudedFaceVertices, Height, Length, randomHeightLevel, randomRatio));
                _meshList.Add(ProceduralUtil.extrudeAFaceWithLevels(this, extrudedFaceVertices, Height, Length, randomHeightLevel, 1.0f / randomRatio));
            }

            for (int i = 0; i < extrudedFaceVertices.Length; i++)
            {
                extrudedFaceVertices[i] = extrudedFaceVertices[i] + new Vector3(0.0f, randomHeightLevel, 0.0f);
            }
        }
        else if (preserveResizeRatio == 1)
        {
            int   numberOfLevel = Random.Range(0, 3);
            float randomRatio   = Random.Range(0.0f, 1.0f); for (int i = 0; i < numberOfLevel; i++)
            {
                _meshList.Add(ProceduralUtil.extrudeAFaceWithLevels(this, extrudedFaceVertices, Width, Length, randomHeightLevel, randomRatio));
            }

            for (int i = 0; i < extrudedFaceVertices.Length; i++)
            {
                extrudedFaceVertices[i] = extrudedFaceVertices[i] + new Vector3(0.0f, randomHeightLevel, 0.0f);
            }
        }

        // 1 / 6 chance to generate a board
        int generateABoard = Random.Range(1, 4);

        if (generateABoard == 1)
        {
            _meshList.Add(ProceduralUtil.generateBoardOnRoof(this));
        }

        generateABoard = Random.Range(1, 4);
        if (generateABoard == 1)
        {
            _meshList.Add(ProceduralUtil.generateBoardOnSide(this));
        }

        Mesh       combinedMesh         = combineMeshes();
        List <int> combineMeshTriangles = new List <int>(combinedMesh.triangles);

        // need to set filter mesh before call findTrianglesWIthinVertices
        this._filter.mesh = combinedMesh;

        List <int> boardTriangles = new List <int>();

        // if the tower contains board
        if (additionTextured.Count != 0)
        {
            combinedMesh.subMeshCount = additionTextured.Count + 1;
            List <int> towerTriangles = new List <int>();

            for (int i = 0; i < additionTextured.Count; i++)
            {
                boardTriangles = ProceduralUtil.findTrianglesWithinVertices(this, additionTextured[i].ToArray());

                combinedMesh.SetTriangles(boardTriangles.ToArray(), i);
                towerTriangles = ProceduralUtil.removeTrianglesFromList(new List <int>(combineMeshTriangles), boardTriangles);
            }

            combinedMesh.SetTriangles(towerTriangles.ToArray(), additionTextured.Count);

            Material[] materials = new Material[additionTextured.Count + 1];
            for (int i = 0; i < additionTextured.Count; i++)
            {
                materials[i] = boardMaterial;
            }
            materials[additionTextured.Count] = selfIlluminMainBuilding;
            _render.materials = materials;
        }
        else
        {
            // set default material as main building material
            _render.material = selfIlluminMainBuilding;
        }

        this._filter.mesh = combinedMesh;
    }