Bunny 3ΒΆ

The Bunny Blocks example surface.

../../_images/blender_bunny_toy.png
import numpy as np
import s3dlib.surface as s3d

# Toy Bunny from Obj datafile to Obj file

# 1. Define function to examine .....................................

def block_surface(surf,N=10) :
    bnds = surf.bounds
    ofst = np.array([ bnds['xlim'][0], bnds['ylim'][0],bnds['zlim'][0] ])
    rang = np.array([ 
        bnds['xlim'][1]- bnds['xlim'][0],
        bnds['ylim'][1]- bnds['ylim'][0],
        bnds['zlim'][1]- bnds['zlim'][0]   
      ])
    scale = N/ np.amax(rang)
    fc = np.array(surf.facecenters).T
    fc = (fc-ofst)*scale
    coor = fc.astype(int)
    coor,cInx = np.unique(coor, return_index=True, axis=0)
    return coor.astype(float), cInx

# 2. Setup and map surfaces .........................................

surface = s3d.get_surfgeom_from_obj("obj_files/bunny.obj")
cubeCenters,tmp = block_surface(surface,30)

unitCubes = None
for i,pos in enumerate( cubeCenters ) :
    cube = s3d.CubicSurface(0)
    cube.transform(scale=0.5,translate=pos)
    if unitCubes is None : unitCubes = cube
    else : unitCubes += cube

s3d.save_surfgeom_to_obj('obj_files/bunny_cubes.obj',unitCubes)