def main(): with session_scope(commit=True) as sess: with open(CSV_FILE_PATH, 'r') as f: reader = csv.reader(f) for line in reader: tup = MERLTuple(*line[:len(MERLTuple._fields)]) if tup.name.strip() == '': continue material = models.Material( type=models.MaterialType.BLINN_PHONG, name=tup.name.strip(), spatially_varying=False, enabled=False, params={ 'diffuse': (tup.diff_r, tup.diff_g, tup.diff_b), 'specular': (tup.spec_r, tup.spec_g, tup.spec_b), 'shininess': tup.shininess, } ) if (sess.query(models.Material) .filter_by(type=material.type, name=material.name) .count() > 0): logger.info('Material already exists', **material.serialize()) continue logger.info('Adding material', **material.serialize()) sess.add(material)
def main(): with open(CSV_PATH, 'r') as f: with session_scope(commit=False) as sess: reader = csv.DictReader(f) for row in reader: material = models.Material( type=models.MaterialType.PRINCIPLED, name=row['name'], author='Keunhong Park', substance=row['substance'], spatially_varying=False, params={ 'diffuse_color': eval(row['diffuse_color']), 'specular': float(row['specular']), 'metallic': float(row['metallic']), 'roughness': float(row['roughness']), 'anisotropy': float(row['anisotropy']), 'anisotropic_rotation': float(row['anisotropic_rotation']), 'clearcoat': float(row['clearcoat']), 'clearcoat_roughness': float(row['clearcoat_roughness']), 'ior': float(row['ior']), }) if (sess.query(models.Material).filter_by( type=material.type, name=material.name).count() > 0): logger.info('Material already exists', **material.serialize()) continue logger.info('Adding material', **material.serialize()) sess.add(material) sess.commit()
def main(): with session_scope(commit=False) as sess: substance_dirs = list(Path(args.base_dir).iterdir()) for substance_dir in sorted(substance_dirs): mdl_paths = [] for material_dir in substance_dir.iterdir(): mdl_path = list(material_dir.glob('*.mdl'))[0] mdl_paths.append(mdl_path) for mdl_path in sorted(mdl_paths, key=lambda s: s.stem): mdl_dict = mdl.parse_mdl(mdl_path) spatially_varying = isinstance(mdl_dict['base_color'], str) material = models.Material( type=models.MaterialType.MDL, name=mdl_path.stem, substance=substance_dir.name, spatially_varying=spatially_varying, source='adobe_stock', source_id=mdl_path.parent.name.split('_')[1], params=mdl_dict, ) if (sess.query(models.Material).filter_by( type=material.type, source_id=material.source_id).count() > 0): logger.info('Material already exists', **material.serialize()) continue logger.info('Adding material', **material.serialize()) sess.add(material) sess.commit()
def main(): with session_scope(commit=True) as sess: substance_dirs = list(config.MATERIAL_DIR_POLIIGON.iterdir()) for substance_dir in substance_dirs: for material_dir in substance_dir.iterdir(): material = models.Material( type=models.MaterialType.POLIIGON, name=material_dir.name, substance=substance_dir.name, spatially_varying=True, ) annot_path = material_dir / 'annotations.json' if annot_path.exists(): with open(annot_path, 'r') as f: annot = json.load(f) if 'scale' in annot: material.min_scale = annot['scale'] if (sess.query(models.Material) .filter_by(type=material.type, name=material.name) .count() > 0): logger.info('Material already exists', **material.serialize()) continue logger.info('Adding material', **material.serialize()) sess.add(material)
def main(): with session_scope(commit=False) as sess: substance_dirs = list(config.MATERIAL_DIR_VRAY.iterdir()) for substance_dir in substance_dirs: for material_dir in sorted(substance_dir.iterdir()): name = material_dir.name pre, post = name.split('_by_') if '-' in post: subname = post.split('-')[1] name = f'{pre} ({subname})' author = post.split('-')[0] else: name = pre author = post material = models.Material(type=models.MaterialType.VRAY, name=name, author=author, substance=substance_dir.name, spatially_varying=True, params={ 'raw_name': material_dir.name, }) print(f'{name}, {author}') if (sess.query(models.Material).filter_by( type=material.type, name=material.name, author=material.author).count() > 0): logger.info('Material already exists', **material.serialize()) continue logger.info('Adding material', **material.serialize()) sess.add(material) sess.commit()