Пример #1
0
    public void Initialize(int resolution, float size, float maxFeatureAngle, Action initCallback)
    {
        this.initCallback = initCallback;
        callbacksCount    = 0;
        sharpFeatureLimit = Mathf.Cos(maxFeatureAngle * Mathf.Deg2Rad);
        this.resolution   = resolution;
        gridSize          = size;
        voxelSize         = size / resolution;
        voxels            = new Voxel[resolution * resolution];
        voxelMaterials    = new Material[voxels.Length];

        dummyX = new Voxel();
        dummyY = new Voxel();
        dummyT = new Voxel();


        for (int i = 0, y = 0; y < resolution; y++)
        {
            for (int x = 0; x < resolution; x++, i++)
            {
                CreateVoxel(i, x, y);
            }
        }

        surface = Instantiate(surfacePrefab) as VoxelGridSurface;
        surface.transform.parent        = transform;
        surface.transform.localPosition = Vector3.zero;
        surface.Initialize(resolution, InitCallback);

        wall = Instantiate(wallPrefab) as VoxelGridWall;
        wall.transform.parent        = transform;
        wall.transform.localPosition = Vector3.zero;
        wall.Initialize(resolution, InitCallback);
    }
Пример #2
0
    VoxelLayer ExtractVoxelLayer(RaycastHit hit)
    {
        GameObject obj = hit.collider.gameObject;

        if (obj.tag == "layer")
        {
            VoxelGridSurface surf = obj.GetComponent <VoxelGridSurface>();

            VoxelLayer foundLayer = surf != null
                ? obj.transform.parent.parent.GetComponent <VoxelLayer>()
                : obj.GetComponent <VoxelLayer>();

            if (foundLayer != null)
            {
                return(foundLayer);
            }
        }
        return(null);
    }
Пример #3
0
    private void CreateRenderers()
    {
        renderers = new VoxelRenderer[materials.Length + 1];
        for (int i = 0; i < materials.Length; i++)
        {
            VoxelGridSurface surface =
                Instantiate(surfacePrefab) as VoxelGridSurface;
            surface.transform.parent        = transform;
            surface.transform.localPosition = Vector3.zero;
            surface.Initialize(resolution, materials[i].surfaceMaterial);

            VoxelGridWall wall = Instantiate(wallPrefab) as VoxelGridWall;
            wall.transform.parent        = transform;
            wall.transform.localPosition = Vector3.zero;
            wall.Initialize(resolution, materials[i].wallMaterial);

            renderers[i + 1] = new VoxelRenderer(surface, wall);
        }
    }
Пример #4
0
 public void Apply()
 {
     mesh.vertices  = vertices.Select(f => (Vector3)VoxelGridSurface.RotateX(f)).ToArray();
     mesh.normals   = normals.Select(f => (Vector3)VoxelGridSurface.RotateX(f)).ToArray();
     mesh.triangles = triangles.ToArray();
 }
Пример #5
0
 public VoxelRenderer(VoxelGridSurface surface, VoxelGridWall wall)
 {
     this.surface = surface;
     this.wall    = wall;
 }