public void InstantiateBricks(BrickItConfiguration cfg)
    {
        var buildingBlocks = GetBuildingBlocks(cfg);

        foreach (BuildingBlock bb in buildingBlocks)
        {
            Vector3 position = new Vector3(bb.pos.x, bb.pos.y * GlobalConstants.VoxelHeight, bb.pos.z);

            if (bb.isFlipped)
            {
                VoxelTools.MakeCube(position, bb.blockColor, new Vector3(bb.extends.z, bb.extends.y * GlobalConstants.VoxelHeight, bb.extends.x));
            }
            else
            {
                VoxelTools.MakeCube(position, bb.blockColor, new Vector3(bb.extends.x, bb.extends.y * GlobalConstants.VoxelHeight, bb.extends.z));
            }
        }
        var cubeContainer = GameObject.Find(GlobalConstants.cubeContainerName);

        cubeContainer.transform.parent        = GameObject.Find("ModelsContainer").transform;
        cubeContainer.transform.localRotation = Quaternion.identity;
        var boundsHandler = cubeContainer.AddComponent <BoundsHandler>();

        cubeContainer.tag    = GlobalConstants.containerTag;
        cubeContainer.layer  = 9;
        boundsHandler.Bounds = new Vector3(lastExtends[1] - lastExtends[0], lastExtends[3] - lastExtends[2], lastExtends[5] - lastExtends[4]);
        cubeContainer.transform.localPosition = new Vector3(-(boundsHandler.Bounds.x / 2), -(boundsHandler.Bounds.y / 2), -(boundsHandler.Bounds.z / 2));
        lastBricked = cubeContainer;
    }
Exemplo n.º 2
0
    private BrickItConfiguration getBrickItConfig()
    {
        var output = new BrickItConfiguration();

        output.brickExtends = getBricks();
        output.colors       = getColors();
        output.height       = (int)Mathf.Round(scaling.value);
        output.depth        = (int)Mathf.Round(depth.value);
        output.mesh         = modelSelection.activeObject.GetComponentInChildren <MeshFilter>().mesh;
        output.transform    = modelSelection.activeObject.transform;
        output.tex          = (Texture2D)textureController.activeTexture;

        modelSelection.activeObject.SetActive(false);
        return(output);
    }
    /*
     * public int height;
     * public Mesh testMesh;
     * public Texture2D testTex;
     * public bool isDebug = false;
     *
     * private void Start()
     * {
     *  if (isDebug)
     *  {
     *      BrickItConfiguration testCFG = GetTestCfg();
     *      runBrickification(testCFG);
     *  }
     * }*/

    public List <BuildingBlock> GetBuildingBlocks(BrickItConfiguration cfg)
    {
        var oldMesh = cfg.mesh.vertices;

        if (lastBricked != null)
        {
            DestroyImmediate(lastBricked);
            lastBricked = null;
        }
        BlockSelector selector = new BlockSelector(cfg.brickExtends);
        var           tex      = ColorCalculation.colorCalculate(cfg.tex, cfg.colors);
        var           voxels   = Voxelizer.Voxelize(cfg.mesh, tex, cfg.height);

        voxels            = Voxelizer.AddWidth(voxels, cfg.depth);
        lastExtends       = MeshUtils.GetBoundsPerDimension(cfg.mesh);
        cfg.mesh.vertices = oldMesh;
        cfg.mesh.RecalculateBounds();
        return(selector.calculateBlocksSpiralWithBounds(voxels));
    }
 public void TriggerAnimation(BrickItConfiguration cfg)
 {
     animationController.StartAnimation(GetBuildingBlocks(cfg), lastExtends);
 }