def save(self, **kwargs): self.ctm.addAttrib(self.aux, "auxdat") self.ctm.addAttrib(self.mni, "mnicoords") self.ctm.save(**kwargs) ctm = CTMfile(self.tf.name) return ctm.getMesh(), self.tf.read()
def __init__(self, pts, polys, norms=None): self.tf = tempfile.NamedTemporaryFile() self.ctm = CTMfile(self.tf.name, "w") self.ctm.setMesh(pts.astype(np.float32), polys.astype(np.uint32), norms=norms) self.pts = pts self.polys = polys self.flat = None self.surfs = {} self.aux = np.zeros((len(self.ctm), 4))
def read_pack(ctmfile): fname = os.path.splitext(ctmfile)[0] jsfile = json.load(open(fname + ".json")) offset = jsfile["offsets"] meshes = [] with open(ctmfile, "r") as ctmfp: ctmfp.seek(0, 2) offset.append(ctmfp.tell()) for start, end in zip(offset[:-1], offset[1:]): ctmfp.seek(start) tf = tempfile.NamedTemporaryFile() tf.write(ctmfp.read(end - start)) tf.seek(0) ctm = CTMfile(tf.name, "r") pts, polys, norms = ctm.getMesh() meshes.append((pts, polys)) return meshes
class Hemi(object): def __init__(self, pts, polys, norms=None): self.tf = tempfile.NamedTemporaryFile() self.ctm = CTMfile(self.tf.name, "w") self.ctm.setMesh(pts.astype(np.float32), polys.astype(np.uint32), norms=norms) self.pts = pts self.polys = polys self.flat = None self.surfs = {} self.aux = np.zeros((len(self.ctm), 4)) def addSurf(self, pts, name=None, renorm=True): '''Scales the in-between surfaces to be same scale as fiducial''' if name is None: name = 'morphTarget%d' % len(self.surfs) if renorm: norm = (pts - pts.min(0)) / (pts.max(0) - pts.min(0)) rnorm = norm * (self.pts.max(0) - self.pts.min(0)) + self.pts.min(0) else: rnorm = pts attrib = np.hstack([rnorm, np.zeros((len(rnorm), 1))]) self.surfs[name] = attrib self.ctm.addAttrib(attrib, name) def setFlat(self, pts): self.ctm.addUV(pts[:, :2].astype(float), 'uv') self.flat = pts[:, :2] def save(self, **kwargs): self.ctm.addAttrib(self.aux, 'auxdat') self.ctm.save(**kwargs) ctm = CTMfile(self.tf.name) return ctm.getMesh(), self.tf.read()
def read_pack(ctmfile): fname = os.path.splitext(ctmfile)[0] jsfile = json.load(open(fname + ".json")) offset = jsfile['offsets'] meshes = [] with open(ctmfile, 'r') as ctmfp: ctmfp.seek(0, 2) offset.append(ctmfp.tell()) for start, end in zip(offset[:-1], offset[1:]): ctmfp.seek(start) tf = tempfile.NamedTemporaryFile() tf.write(ctmfp.read(end - start)) tf.seek(0) ctm = CTMfile(tf.name, "r") pts, polys, norms = ctm.getMesh() meshes.append((pts, polys)) return meshes
class Hemi(object): def __init__(self, pts, polys, norms=None): self.tf = tempfile.NamedTemporaryFile() self.ctm = CTMfile(self.tf.name, "w") self.ctm.setMesh(pts.astype(np.float32), polys.astype(np.uint32), norms=norms) self.pts = pts self.polys = polys self.flat = None self.surfs = {} self.aux = np.zeros((len(self.ctm), 4)) def addSurf(self, pts, name=None, renorm=True): '''Scales the in-between surfaces to be same scale as fiducial''' if name is None: name = 'morphTarget%d'%len(self.surfs) if renorm: norm = (pts - pts.min(0)) / (pts.max(0) - pts.min(0)) rnorm = norm * (self.pts.max(0) - self.pts.min(0)) + self.pts.min(0) else: rnorm = pts attrib = np.hstack([rnorm, np.zeros((len(rnorm),1))]) self.surfs[name] = attrib self.ctm.addAttrib(attrib, name) def setFlat(self, pts): self.ctm.addUV(pts[:,:2].astype(float), 'uv') self.flat = pts[:,:2] def save(self, **kwargs): self.ctm.addAttrib(self.aux, 'auxdat') self.ctm.save(**kwargs) ctm = CTMfile(self.tf.name) return ctm.getMesh(), self.tf.read()
def save(self, **kwargs): self.ctm.addAttrib(self.aux, 'auxdat') self.ctm.save(**kwargs) ctm = CTMfile(self.tf.name) return ctm.getMesh(), self.tf.read()