예제 #1
0
        public static VoxelSet <bool> LowPassFilter(VoxelSet <Vec4b> voxels, float transference, float threshold)
        {
            VoxelSet <float> fVoxels = voxels.Project(ToFloat);

            Vec3i[] dirs =
            {
                new Vec3i(1,   0,  0),
                new Vec3i(-1,  0,  0),
                new Vec3i(0,   1,  0),
                new Vec3i(0,  -1,  0),
                new Vec3i(0,   0,  1),
                new Vec3i(0,   0, -1),
            };

            foreach (var dir in dirs)
            {
                SmearDirection(fVoxels, transference, dir);
            }

            return(fVoxels.Project(v => v >= threshold));
        }
예제 #2
0
    // Adds colliders to the given game object.
    public static void AddColliders(GameObject obj, VoxelSet <Color32> voxels, ColliderType colliderType)
    {
        if (colliderType != ColliderType.None)
        {
            VoxelSet <bool> shape = voxels.Project(v => v.a > 0);
            int             scale = 1;
            if (colliderType == ColliderType.HalfScale)
            {
                //shape = ReduceShape(shape);
                shape = ReduceShape(shape, 2);
                scale = 2;
            }

            if (colliderType == ColliderType.ThirdScale)
            {
                shape = ReduceShape(shape, 3);
                scale = 3;
            }

            if (colliderType == ColliderType.QuarterScale)
            {
                //shape = ReduceShape(ReduceShape(shape));
                shape = ReduceShape(shape, 4);
                scale = 4;
            }

            List <BoxMaker.Box> boxes = MakeBoxes(shape, scale);

            // Add box colliders
            foreach (var boxDesc in boxes)
            {
                BoxCollider box = obj.AddComponent <BoxCollider>();
                box.size   = new Vector3(boxDesc.extents.x, boxDesc.extents.y, boxDesc.extents.z);
                box.center = new Vector3(boxDesc.origin.x, boxDesc.origin.y, boxDesc.origin.z) + box.size / 2.0f;
            }
        }
    }
예제 #3
0
 public static List <Box> MakeBoxes(VoxelSet <Vec4b> voxels)
 {
     return(MakeBoxes(voxels.Project(ToSolid)));
 }