From 887cd553df405e37ed82ff19c95a207eef13f5d8 Mon Sep 17 00:00:00 2001 From: Alex Raistrick Date: Fri, 18 Aug 2023 12:24:53 -0400 Subject: [PATCH] Fix everything that didnt pass tests / checks * Fix non-compiling code found by linting * Fix non fatal linting errors --- examples/generate_individual_assets.py | 6 +-- .../creatures/insects/utils/geom_utils.py | 3 ++ infinigen/assets/creatures/parts/head.py | 45 ------------------- infinigen/assets/creatures/reptile.py | 4 +- infinigen/assets/leaves/__init__.py | 2 +- infinigen/assets/leaves/leaf.py | 4 +- infinigen/assets/materials/bark.py | 1 + infinigen/assets/materials/bird.py | 2 + infinigen/assets/materials/chunkyrock.py | 8 ++-- .../assets/materials/three_color_spots.py | 2 +- infinigen/assets/materials/two_color_spots.py | 2 +- infinigen/assets/rocks/pile.py | 5 ++- infinigen/assets/trees/utils/materials.py | 2 +- infinigen/assets/trees/utils/mesh.py | 27 ----------- .../assets/tropic_plants/leaf_banana_tree.py | 9 +++- .../assets/tropic_plants/leaf_palm_plant.py | 16 ++++++- .../assets/tropic_plants/leaf_palm_tree.py | 20 ++++++++- infinigen/assets/weather/cloud/cloud.py | 1 + infinigen/assets/weather/cloud/node.py | 9 ---- infinigen/core/execute_tasks.py | 17 ++----- infinigen/core/nodes/__init__.py | 2 + infinigen/core/nodes/compatibility.py | 2 +- infinigen/core/nodes/node_wrangler.py | 4 +- infinigen/core/placement/animation_policy.py | 6 +-- infinigen/core/placement/camera.py | 12 ++--- infinigen/core/placement/factory.py | 2 +- infinigen/core/placement/placement.py | 5 ++- infinigen/core/rendering/post_render.py | 3 ++ infinigen/core/rendering/render.py | 16 +++---- infinigen/core/surface.py | 4 +- infinigen/core/util/exporting.py | 2 +- infinigen/core/util/math.py | 8 +--- .../configs/compute_platform/local_256GB.gin | 2 +- infinigen/datagen/customgt/show.py | 2 +- infinigen/datagen/job_funcs.py | 12 ++--- .../tools/blendscript_import_infinigen.py | 4 +- .../tools/dev/generate_terrain_assets.py | 10 ++--- .../datagen/tools/dev/landtile_viewer.py | 5 +-- infinigen/datagen/tools/export/export.py | 6 +-- .../datagen/tools/results/scatter_figure.py | 42 +++++++++-------- infinigen/datagen/util/submitit_emulator.py | 1 + infinigen/datagen/util/upload_util.py | 2 +- .../terrain/assets/upsidedown_mountains.py | 12 ++--- infinigen/terrain/land_process/erosion.py | 2 +- .../terrain/mesh_to_sdf/pyrender_wrapper.py | 1 + .../mesh_to_sdf/surface_point_cloud.py | 3 +- .../terrain/mesher/cube_spherical_mesher.py | 6 +-- .../mesher/frontview_spherical_mesher.py | 4 +- infinigen/terrain/mesher/uniform_mesher.py | 2 +- infinigen/terrain/utils/image_processing.py | 2 +- infinigen/terrain/utils/mesh.py | 6 +-- .../tools/blendscript_import_infinigen.py | 2 + .../tools/terrain/generate_terrain_assets.py | 2 - infinigen/tools/terrain/kernelize_surfaces.py | 5 +-- pyproject.toml | 18 ++++---- tests/integration/manual_integration_check.py | 8 ++-- tests/test_nature_materials_basic.py | 3 +- tests/test_nature_meshes_basic.py | 1 - 58 files changed, 187 insertions(+), 227 deletions(-) diff --git a/examples/generate_individual_assets.py b/examples/generate_individual_assets.py index d8cd39a7c..808cf27e2 100644 --- a/examples/generate_individual_assets.py +++ b/examples/generate_individual_assets.py @@ -290,14 +290,14 @@ def main(args): factories += [f.stem for f in Path('infinigen/assets/materials').iterdir()] factories.remove('ALL_MATERIALS') - for factory in factories: - fac_path = path / factory + for fac in factories: + fac_path = path / fac if fac_path.exists() and args.skip_existing: continue fac_path.mkdir(exist_ok=True) for idx in range(args.n_images): try: - build_scene(fac_path, idx, factory, args) + build_scene(fac_path, idx, fac, args) except Exception as e: print(e) continue diff --git a/infinigen/assets/creatures/insects/utils/geom_utils.py b/infinigen/assets/creatures/insects/utils/geom_utils.py index 5673d863f..b720ecd9f 100644 --- a/infinigen/assets/creatures/insects/utils/geom_utils.py +++ b/infinigen/assets/creatures/insects/utils/geom_utils.py @@ -7,11 +7,14 @@ import bpy import mathutils from numpy.random import uniform, normal, randint + from infinigen.core.nodes.node_wrangler import Nodes, NodeWrangler from infinigen.core.nodes import node_utils from infinigen.core.nodes.color import color_category from infinigen.core import surface +from .shader_utils import nodegroup_add_noise, nodegroup_color_noise + @node_utils.to_nodegroup('nodegroup_symmetric_clone', singleton=False, type='GeometryNodeTree') def nodegroup_symmetric_clone(nw: NodeWrangler): # Code generated using version 2.4.3 of the node_transpiler diff --git a/infinigen/assets/creatures/parts/head.py b/infinigen/assets/creatures/parts/head.py index e6f17d518..cd6773a63 100644 --- a/infinigen/assets/creatures/parts/head.py +++ b/infinigen/assets/creatures/parts/head.py @@ -491,51 +491,6 @@ def make_part(self, params): tag_object(part.obj, 'carnivore_jaw') return part -@node_utils.to_nodegroup('nodegroup_fish_head', singleton=True, type='GeometryNodeTree') -def nodegroup_fish_head(nw: NodeWrangler): - # Code generated using version 2.4.3 of the node_transpiler - - group_input = nw.new_node(Nodes.GroupInput, - expose_input=[('NodeSocketVector', 'length_rad1_rad2', (0.51, 0.27, 0.12)), - ('NodeSocketVector', 'angles_deg', (7.0, -18.36, 0.0)), - ('NodeSocketFloat', 'aspect', 0.56), - ('NodeSocketFloat', 'fullness', 1.96), - ('NodeSocketVector', 'eye_coord', (0.5, 0.0, 1.0)), - ('NodeSocketFloatDistance', 'eye_radius', 0.05)]) - - eyeball = nw.new_node(nodegroup_eyeball().name, - input_kwargs={'Radius': group_input.outputs["eye_radius"]}) - - simple_tube_v2 = nw.new_node(nodegroup_simple_tube_v2().name, - input_kwargs={'length_rad1_rad2': group_input.outputs["length_rad1_rad2"], 'angles_deg': group_input.outputs["angles_deg"], 'aspect': group_input.outputs["aspect"], 'fullness': group_input.outputs["fullness"]}) - - eyesockets = nw.new_node(nodegroup_eye_sockets().name, - input_kwargs={'Eyeball': eyeball, 'Skin Mesh': simple_tube_v2.outputs["Geometry"], 'Skeleton Curve': simple_tube_v2.outputs["Skeleton Curve"], 'Base Mesh': simple_tube_v2.outputs["Geometry"], 'Length/Yaw/Rad': group_input.outputs["eye_coord"]}) - - group_output = nw.new_node(Nodes.GroupOutput, - input_kwargs={'Geometry': eyesockets.outputs["Geometry"], 'Skeleton Curve': simple_tube_v2.outputs["Skeleton Curve"], 'LeftEye': eyesockets.outputs["LeftEye"], 'RightEye': eyesockets.outputs["RightEye"]}) - -class FishHead(PartFactory): - - tags = ['head'] - - def sample_params(self): - return { - 'length_rad1_rad2': (0.51, 0.27, 0.12), - 'angles_deg': (7.0, -18.36, 0.0), - 'aspect': 0.56, - 'fullness': 1.96, - 'eye_coord': (0.5, 0.0, 1.0), - 'eye_radius': 0.0 - } - - def make_part(self, params): - part = part_util.nodegroup_to_part(nodegroup_fish_head, params) - part.iks = {1.0: IKParams('head', rotation_weight=0.1, chain_parts=2)} - part.settings['rig_extras'] = True - tag_object(part.obj, 'fish_head') - return part - @node_utils.to_nodegroup('nodegroup_flying_bird_head', singleton=True, type='GeometryNodeTree') def nodegroup_flying_bird_head(nw: NodeWrangler): # Code generated using version 2.4.3 of the node_transpiler diff --git a/infinigen/assets/creatures/reptile.py b/infinigen/assets/creatures/reptile.py index f939c58da..98f84c7ab 100644 --- a/infinigen/assets/creatures/reptile.py +++ b/infinigen/assets/creatures/reptile.py @@ -391,7 +391,7 @@ def chameleon_postprocessing(body_parts, extras, params): body = body_parts + get_extras('BodyExtra') main_template.apply(body) - chameleon_eye.apply(get_extras('Eye')) + #chameleon_eye.apply(get_extras('Eye')) @gin.configurable class LizardFactory(AssetFactory): @@ -410,8 +410,6 @@ def create_asset(self, i, animate=False, rigging=False, cloth=False, **kwargs): postprocess_func=reptile_postprocessing, adapt_mode='remesh', rigging=rigging, **kwargs) if animate and arma is not None: pass - if simulate: - pass else: joined = butil.join_objects([joined] + extras) diff --git a/infinigen/assets/leaves/__init__.py b/infinigen/assets/leaves/__init__.py index a70f5173f..64eb41321 100644 --- a/infinigen/assets/leaves/__init__.py +++ b/infinigen/assets/leaves/__init__.py @@ -1,4 +1,4 @@ -from .leaf import BerryFactory, LeafFactory +from .leaf import LeafFactory from .leaf_broadleaf import LeafFactoryBroadleaf from .leaf_ginko import LeafFactoryGinko from .leaf_maple import LeafFactoryMaple diff --git a/infinigen/assets/leaves/leaf.py b/infinigen/assets/leaves/leaf.py index 84235d2fa..6d67c7375 100644 --- a/infinigen/assets/leaves/leaf.py +++ b/infinigen/assets/leaves/leaf.py @@ -87,7 +87,8 @@ def create_asset(self, **params) -> bpy.types.Object: butil.apply_transform(obj) return obj - + +''' class BerryFactory(AssetFactory): def __init__(self, factory_seed, genome, coarse=False): @@ -116,6 +117,7 @@ def create_asset(self, **params) -> bpy.types.Object: tag_object(obj, 'leaf') return obj +''' ''' def init_berries(n_leaves=5, im_mat=None, **leaf_kargs): diff --git a/infinigen/assets/materials/bark.py b/infinigen/assets/materials/bark.py index a35430db2..4260a3b72 100644 --- a/infinigen/assets/materials/bark.py +++ b/infinigen/assets/materials/bark.py @@ -5,6 +5,7 @@ import os, sys import numpy as np +from numpy.random import uniform as U, normal as N import math as ma from infinigen.assets.materials.utils.surface_utils import clip, sample_range, sample_ratio, sample_color, geo_voronoi_noise import bpy diff --git a/infinigen/assets/materials/bird.py b/infinigen/assets/materials/bird.py index 09280fc21..fe1750a8d 100644 --- a/infinigen/assets/materials/bird.py +++ b/infinigen/assets/materials/bird.py @@ -457,6 +457,8 @@ def apply(objs, shader_kwargs={}, **kwargs): else: kind = 'duck' shader_kwargs['kind'] = kind + if not isinstance(objs, list): + objs = [objs] for obj in objs: if "Tail" in obj.name: shader_kwargs['tail'] = True diff --git a/infinigen/assets/materials/chunkyrock.py b/infinigen/assets/materials/chunkyrock.py index 2e0b3f2f2..c4992244b 100644 --- a/infinigen/assets/materials/chunkyrock.py +++ b/infinigen/assets/materials/chunkyrock.py @@ -47,8 +47,8 @@ def shader_rocks(nw, rand=True, **input_kwargs): input_kwargs={'Fac': noise_texture_1.outputs["Fac"], 'Color1': (0.0, 0.0, 0.0, 1.0), 'Color2': (0.01, 0.024, 0.0283, 1.0)}) if rand: - sample_color(rock_color1.inputs["Color1"].default_value) - sample_color(rock_color1.inputs["Color2"].default_value) + sample_color(rock_color1.inputs[6].default_value) + sample_color(rock_color1.inputs[7].default_value) noise_texture_2 = nw.new_node(Nodes.NoiseTexture, input_kwargs={'Vector': mapping, 'Detail': 15.0}) @@ -57,8 +57,8 @@ def shader_rocks(nw, rand=True, **input_kwargs): input_kwargs={'Fac': noise_texture_2.outputs["Fac"], 'Color1': (0.0, 0.0, 0.0, 1.0), 'Color2': (0.0694, 0.1221, 0.0693, 1.0)}) if rand: - sample_color(rock_color2.inputs["Color1"].default_value) - sample_color(rock_color2.inputs["Color2"].default_value) + sample_color(rock_color2.inputs[6].default_value) + sample_color(rock_color2.inputs[7].default_value) mix_1 = nw.new_node(Nodes.MixRGB, input_kwargs={'Fac': colorramp_3.outputs["Color"], 'Color1': rock_color1, 'Color2': rock_color2}) diff --git a/infinigen/assets/materials/three_color_spots.py b/infinigen/assets/materials/three_color_spots.py index 93ef81ad7..eb26bb29f 100644 --- a/infinigen/assets/materials/three_color_spots.py +++ b/infinigen/assets/materials/three_color_spots.py @@ -24,7 +24,7 @@ def shader_spot(nw, rand=True, **input_kwargs): mix = nw.new_node(Nodes.MixRGB, input_kwargs={'Fac': 0.7, 'Color1': noise_texture.outputs["Color"], 'Color2': texture_coordinate.outputs["Object"]}) if rand: - mix.inputs["Fac"].default_value = sample_range(0.5, 0.9) + mix.inputs["Factor"].default_value = sample_range(0.5, 0.9) scale = nw.new_node(Nodes.Value) scale.outputs["Value"].default_value = input_kwargs['scale'] if 'scale' in input_kwargs else 2 diff --git a/infinigen/assets/materials/two_color_spots.py b/infinigen/assets/materials/two_color_spots.py index b34560b6d..d282d268e 100644 --- a/infinigen/assets/materials/two_color_spots.py +++ b/infinigen/assets/materials/two_color_spots.py @@ -50,7 +50,7 @@ def geo_two_color_spots(nw, rand=True, **input_kwargs): mix = nw.new_node(Nodes.MixRGB, input_kwargs={'Color1': noise_texture.outputs["Color"], 'Color2': vector_math.outputs["Vector"]}) if rand: - mix.inputs["Fac"].default_value = sample_range(0.5, 0.9) + mix.inputs["Factor"].default_value = sample_range(0.5, 0.9) voronoi_texture = nw.new_node(Nodes.VoronoiTexture, input_kwargs={'Vector': mix}, diff --git a/infinigen/assets/rocks/pile.py b/infinigen/assets/rocks/pile.py index 796227389..5eaca464d 100644 --- a/infinigen/assets/rocks/pile.py +++ b/infinigen/assets/rocks/pile.py @@ -9,7 +9,7 @@ import numpy as np from numpy.random import uniform -from infinigen.assets.boulder import BoulderFactory +from infinigen.assets.rocks.boulder import BoulderFactory from infinigen.assets.utils.physics import free_fall from infinigen.core.placement.detail import remesh_with_attrs from infinigen.core.placement.factory import AssetFactory @@ -17,7 +17,8 @@ from infinigen.assets.utils.decorate import join_objects, multi_res, toggle_hide from infinigen.assets.utils.draw import surface_from_func from infinigen.core.util.blender import deep_clone_obj -from infinigen.assets.utils.tag import tag_object, tag_nodegroup +from infinigen.assets.utils.tag import tag_object +from infinigen.core.util.random import log_uniform class BoulderPileFactory(AssetFactory): diff --git a/infinigen/assets/trees/utils/materials.py b/infinigen/assets/trees/utils/materials.py index f0531a68c..87d78b4e4 100644 --- a/infinigen/assets/trees/utils/materials.py +++ b/infinigen/assets/trees/utils/materials.py @@ -90,7 +90,7 @@ def create_leaf_material(src_hue, glow=False): nt.nodes.new('ShaderNodeEmission') em = nt.nodes.get('Emission') em.inputs.get('Strength').default_value = 1 - em.inputs.get('Color').default_value = (*utils.colorsys.hsv_to_rgb(src_hue + np.random.randn() * .1, 1, 1), 1) + em.inputs.get('Color').default_value = (*colorsys.hsv_to_rgb(src_hue + np.random.randn() * .1, 1, 1), 1) new_link(nt, em, 'Emission', out_node, 'Surface') else: diff --git a/infinigen/assets/trees/utils/mesh.py b/infinigen/assets/trees/utils/mesh.py index 452853b3f..2217af26f 100644 --- a/infinigen/assets/trees/utils/mesh.py +++ b/infinigen/assets/trees/utils/mesh.py @@ -271,33 +271,6 @@ def get_visible_vertices(cam, vertices, co2D=None, limit=0.02): return co2D, is_visible, in_frame - -def obj_point_sampling(cam, obj, n=300, start_frame=0, end_frame=10): - # Sample points distributed over mesh - geometry_point_distribute(obj) - - dgraph = C.evaluated_depsgraph_get() - obj_eval = obj.evaluated_get(dgraph) - subset = subsample_vertices(obj_eval.data.vertices, n) - - # Get point locations for all frames - all_pts = get_coords_clip(obj, start_frame, end_frame, subset) - - # Remove geometry node modifier - obj.modifiers.remove(obj.modifiers[-1]) - - # Get visibility info for all points at each frame - all_2d, vis, infr = [], [], [] - for i, pts in enumerate(all_pts): - C.scene.frame_set(i + start_frame) - co2D, is_visible, in_frame = get_visible_vertices(cam, pts) - all_2d += [co2D] - vis += [is_visible] - infr += [in_frame] - - return all_pts, np.stack(all_2d, 0), np.stack(vis, 0), np.stack(infr, 0) - - def sanity_check_viz(all_pts, is_visible, in_frame, frame_idx=0): C.scene.frame_set(frame_idx) for i in range(all_pts.shape[1]): diff --git a/infinigen/assets/tropic_plants/leaf_banana_tree.py b/infinigen/assets/tropic_plants/leaf_banana_tree.py index 661901362..8b793112b 100644 --- a/infinigen/assets/tropic_plants/leaf_banana_tree.py +++ b/infinigen/assets/tropic_plants/leaf_banana_tree.py @@ -13,7 +13,14 @@ from infinigen.core.placement.factory import AssetFactory import numpy as np from infinigen.core.nodes.color import hsv2rgba -from infinigen.assets.tropic_plants.tropic_plant_utils import * +from infinigen.assets.tropic_plants.tropic_plant_utils import ( + nodegroup_nodegroup_leaf_gen, + nodegroup_nodegroup_leaf_rotate_x, + nodegroup_nodegroup_leaf_shader, + nodegroup_nodegroup_move_to_origin, + nodegroup_nodegroup_sub_vein, + shader_stem_material +) from infinigen.core.util import blender as butil from infinigen.assets.utils.tag import tag_object, tag_nodegroup diff --git a/infinigen/assets/tropic_plants/leaf_palm_plant.py b/infinigen/assets/tropic_plants/leaf_palm_plant.py index 13cfe60f9..f7c476ccd 100644 --- a/infinigen/assets/tropic_plants/leaf_palm_plant.py +++ b/infinigen/assets/tropic_plants/leaf_palm_plant.py @@ -6,9 +6,21 @@ import bpy import mathutils -from numpy.random import uniform -from infinigen.assets.tropic_plants.tropic_plant_utils import * +import numpy as np +from numpy.random import uniform, normal, randint +from infinigen.assets.tropic_plants.tropic_plant_utils import ( + nodegroup_nodegroup_leaf_gen, + nodegroup_nodegroup_leaf_rotate_x, + nodegroup_nodegroup_leaf_shader, + nodegroup_nodegroup_move_to_origin, + nodegroup_nodegroup_sub_vein, + hsv2rgba, + shader_stem_material, +) +from infinigen.core.placement.factory import AssetFactory +from infinigen.core.nodes import Nodes, NodeWrangler, node_utils from infinigen.core.util import blender as butil +from infinigen.core import surface @node_utils.to_nodegroup('nodegroup_nodegroup_apply_wave', singleton=False, type='GeometryNodeTree') diff --git a/infinigen/assets/tropic_plants/leaf_palm_tree.py b/infinigen/assets/tropic_plants/leaf_palm_tree.py index 74cbe2035..bec5f6e6d 100644 --- a/infinigen/assets/tropic_plants/leaf_palm_tree.py +++ b/infinigen/assets/tropic_plants/leaf_palm_tree.py @@ -3,8 +3,24 @@ # Authors: Beining Han - -from infinigen.assets.tropic_plants.tropic_plant_utils import * +import bpy + +import numpy as np +from numpy.random import uniform, normal, randint + +from infinigen.core.nodes import Nodes, NodeWrangler, node_utils +from infinigen.core.nodes.color import hsv2rgba +from infinigen.core import surface +from infinigen.core.placement.factory import AssetFactory + +from infinigen.assets.tropic_plants.tropic_plant_utils import ( + nodegroup_nodegroup_leaf_shader, + nodegroup_nodegroup_sub_vein, + nodegroup_nodegroup_leaf_gen, + nodegroup_nodegroup_move_to_origin, + nodegroup_nodegroup_leaf_rotate_x, + shader_stem_material +) from infinigen.assets.utils.tag import tag_object, tag_nodegroup @node_utils.to_nodegroup('nodegroup_nodegroup_apply_wave', singleton=False, type='GeometryNodeTree') diff --git a/infinigen/assets/weather/cloud/cloud.py b/infinigen/assets/weather/cloud/cloud.py index 632321a0f..1383291ad 100644 --- a/infinigen/assets/weather/cloud/cloud.py +++ b/infinigen/assets/weather/cloud/cloud.py @@ -15,6 +15,7 @@ from infinigen.core.nodes import node_utils from infinigen.core import surface +from infinigen.assets.lighting import sky_lighting from infinigen.assets.weather.cloud.node import geometry_func, shader_material from infinigen.assets.weather.cloud.node import scatter_func diff --git a/infinigen/assets/weather/cloud/node.py b/infinigen/assets/weather/cloud/node.py index 0e0091ec3..118f3eb45 100644 --- a/infinigen/assets/weather/cloud/node.py +++ b/infinigen/assets/weather/cloud/node.py @@ -271,15 +271,6 @@ def cloud_geometry_node( 'operation': 'GREATER_THAN', }, ) - - if points_only: - group_output = nw.new_node( - Nodes.GroupOutput, - input_kwargs={ - 'Geometry': separate_geometry, - }, - ) - return separate_geometry = nw.new_node( Nodes.SeparateGeometry, diff --git a/infinigen/core/execute_tasks.py b/infinigen/core/execute_tasks.py index 3b301350c..ccbe0ae47 100644 --- a/infinigen/core/execute_tasks.py +++ b/infinigen/core/execute_tasks.py @@ -15,7 +15,8 @@ import time from collections import defaultdict -os.environ["OPENCV_IO_ENABLE_OPENEXR"] = "1" # This must be done BEFORE import cv2. +# ruff: noqa: F402 +os.environ["OPENCV_IO_ENABLE_OPENEXR"] = "1" # This must be done BEFORE import cv2. # See https://github.com/opencv/opencv/issues/21326#issuecomment-1008517425 import bpy @@ -54,16 +55,12 @@ from infinigen.assets import ( fluid, cactus, - cactus, trees, - monocot, rocks, - underwater, creatures, lighting, weather, ) -from infinigen.terrain import Terrain from infinigen.core.rendering.render import render_image from infinigen.core.rendering.resample import resample_scene @@ -72,11 +69,9 @@ from infinigen.core.util.organization import Task, Attributes, TerrainNames -from infinigen.core.placement import placement, density, camera as cam_util from infinigen.core.placement.split_in_view import split_inview import infinigen.assets.scatters -from infinigen.assets.scatters import ground_mushroom, slime_mold, moss, ivy, lichen, snow_layer from infinigen.assets.scatters.utils.selection import scatter_lower, scatter_upward from infinigen.core.util import ( @@ -87,14 +82,9 @@ ) from infinigen.core.util.math import FixedSeed, int_hash -from infinigen.core import execute_tasks, surface - - -from infinigen.core.util import exporting from infinigen.core.util.logging import Timer, save_polycounts, create_text_file, Suppress from infinigen.core.util.pipeline import RandomStageExecutor from infinigen.core.util.random import sample_registry - from infinigen.assets.utils.tag import tag_system def sanitize_gin_override(overrides: list): @@ -331,7 +321,6 @@ def execute_tasks( with Timer('Reading input blendfile'): bpy.ops.wm.open_mainfile(filepath=str(input_folder / 'scene.blend')) tag_system.load_tag(path=str(input_folder / "MaskTag.json")) - scene_version = get_scene_tag('infinigen.__version__') butil.approve_all_drivers() if frame_range[1] < frame_range[0]: @@ -349,7 +338,7 @@ def execute_tasks( try: with Suppress(): bpy.ops.preferences.addon_enable(module=name) - except Exception as e: + except Exception: logging.warning(f'Could not load addon "{name}"') bpy.context.preferences.system.scrollback = 0 diff --git a/infinigen/core/nodes/__init__.py b/infinigen/core/nodes/__init__.py index e69de29bb..e6573d44c 100644 --- a/infinigen/core/nodes/__init__.py +++ b/infinigen/core/nodes/__init__.py @@ -0,0 +1,2 @@ +from .node_wrangler import NodeWrangler +from .node_info import Nodes diff --git a/infinigen/core/nodes/compatibility.py b/infinigen/core/nodes/compatibility.py index 8ff7a5084..b74db399e 100644 --- a/infinigen/core/nodes/compatibility.py +++ b/infinigen/core/nodes/compatibility.py @@ -39,7 +39,7 @@ def make_virtual_transfer_attribute(nw, orig_type, input_args, attrs, input_kwar mapped_type = Nodes.SampleNearestSurface map_dict_keys(input_kwargs, {'Source': 'Mesh', 'Attribute': 'Value', 'Source Position': 'Sample Position'}) elif attrs['mapping'] == 'NEAREST': - raise ValueError(f"Compatibility mapping for mode='NEAREST' is not supported, please modify the code to resolve this outdated instance of TransferAttribute") + raise ValueError("Compatibility mapping for mode='NEAREST' is not supported, please modify the code to resolve this outdated instance of TransferAttribute") elif attrs['mapping'] == 'INDEX': mapped_type = Nodes.SampleIndex map_dict_keys(input_kwargs, {'Source': 'Geometry', 'Attribute': 'Value'}) diff --git a/infinigen/core/nodes/node_wrangler.py b/infinigen/core/nodes/node_wrangler.py index d2da1dec6..4f0972d76 100644 --- a/infinigen/core/nodes/node_wrangler.py +++ b/infinigen/core/nodes/node_wrangler.py @@ -244,8 +244,8 @@ def expose_input(self, name, val=None, attribute=None, dtype=None, use_namednode if attribute is not None: if self.modifier is None and val is None: raise ValueError( - f'Attempted to use expose_input(attribute=...) on NodeWrangler constructed from ' - f'node_tree.\n' + 'Attempted to use expose_input(attribute=...) on NodeWrangler constructed from ' + 'node_tree.\n' 'Please construct by passing in the modifier instead, or specify expose_input(val=..., ' 'attribute=...) to provide a fallback') diff --git a/infinigen/core/placement/animation_policy.py b/infinigen/core/placement/animation_policy.py index 680588c7f..1a8fead77 100644 --- a/infinigen/core/placement/animation_policy.py +++ b/infinigen/core/placement/animation_policy.py @@ -90,11 +90,11 @@ class AnimPolicyBrownian: def __init__(self, speed=3, pos_var=15.0): self.speed = speed self.pos_var = pos_var - + def __call__(self, obj, frame_curr, bvh, retry_pct): - speed = random_general(speed) + speed = random_general(self.speed) sampler = lambda: N(0, [self.pos_var, self.pos_var, 0.5]) pos = walk_same_altitude(obj.location, sampler, bvh) time = np.linalg.norm(pos - obj.location) / speed @@ -113,7 +113,7 @@ def __init__(self, speed=3, dist=("uniform", 5, 20), rot_var=[10, 0, 20]): def __call__(self, obj, frame_curr, bvh, retry_pct): - speed = random_general(speed) + speed = random_general(self.speed) def sampler(): theta = U(0, 2*np.pi) zoff = np.sin(np.deg2rad(N(-30, 30))) diff --git a/infinigen/core/placement/camera.py b/infinigen/core/placement/camera.py index c59bbcf3c..b7c199473 100644 --- a/infinigen/core/placement/camera.py +++ b/infinigen/core/placement/camera.py @@ -154,7 +154,8 @@ def get_camera(rig_id, subcam_id, checkonly=False): name = camera_name(rig_id, subcam_id) if name in col.objects.keys(): return col.objects[name] - if checkonly: return None + if checkonly: + return None raise ValueError(f'Could not get_camera({rig_id=}, {subcam_id=}). {list(col.objects.keys())=}') @node_utils.to_nodegroup('nodegroup_camera_info', singleton=True, type='GeometryNodeTree') @@ -239,7 +240,8 @@ def camera_pose_proposal( loc = np.random.uniform(*terrain_bbox) alt = animation_policy.get_altitude(loc, terrain_bvh) - if alt is None: return None + if alt is None: + return None headspace = animation_policy.get_altitude(loc, terrain_bvh, dir=Vector((0, 0, 1))) for headspace_retry in range(headspace_retries): @@ -303,7 +305,7 @@ def keep_cam_pose_proposal( cam, terrain_bvh, terrain_tags_answers, vertexwise_min_dist, min_dist=min_terrain_distance) if dists is None: - logger.debug(f'keep_cam_pose_proposal rejects terrain dists') + logger.debug('keep_cam_pose_proposal rejects terrain dists') return None coverage = len(dists)/n_pix @@ -417,7 +419,7 @@ def camera_selection_preprocessing( terrain_tags_ratio={}, ): - with Timer(f'Building placeholders KDTree'): + with Timer('Building placeholders KDTree'): placeholders = list(chain.from_iterable( c.all_objects for c in bpy.data.collections if c.name.startswith('placeholders:') @@ -496,7 +498,7 @@ def animate_cameras( for cam_rig in cam_rigs: - if policy_registry == None: + if policy_registry is None: if U() < follow_poi_chance and pois is not None and len(pois): policy = animation_policy.AnimPolicyFollowObject( target_obj=cam_rig, diff --git a/infinigen/core/placement/factory.py b/infinigen/core/placement/factory.py index 8f2270acf..fcb53f0a7 100644 --- a/infinigen/core/placement/factory.py +++ b/infinigen/core/placement/factory.py @@ -96,7 +96,7 @@ def spawn_asset(self, i, placeholder=None, distance=None, vis_distance=0, loc=(0 distance = detail.scatter_res_distance() if self.coarse: - raise ValueError(f'Attempted to spawn_asset() on an AssetFactory(coarse=True)') + raise ValueError('Attempted to spawn_asset() on an AssetFactory(coarse=True)') if placeholder is None: placeholder = self.spawn_placeholder(i=i, loc=loc, rot=rot) diff --git a/infinigen/core/placement/placement.py b/infinigen/core/placement/placement.py index f97e0a9bd..def93be70 100644 --- a/infinigen/core/placement/placement.py +++ b/infinigen/core/placement/placement.py @@ -39,7 +39,7 @@ def objects_to_grid(objects, spacing): def placeholder_locs(terrain, overall_density, selection, distance_min=0, altitude=0.0, max_locs=None): temp_vert = butil.spawn_vert('compute_placeholder_locations') geo = temp_vert.modifiers.new(name="GEOMETRY", type='NODES') - if geo.node_group == None: + if geo.node_group is None: group = geometry_node_group_empty_new() geo.node_group = group nw = NodeWrangler(geo) @@ -52,7 +52,8 @@ def placeholder_locs(terrain, overall_density, selection, distance_min=0, altitu 'Distance Min': distance_min}) verts = nw.new_node(Nodes.PointsToVertices, input_kwargs={'Points': points}) verts = nw.new_node(Nodes.SetPosition, input_kwargs={'Geometry': verts, 'Offset': (0, 0, altitude)}) - group_output = nw.new_node(Nodes.GroupOutput, input_kwargs={'Geometry': verts}) + + nw.new_node(Nodes.GroupOutput, input_kwargs={'Geometry': verts}) # dump the point locations out as vertices butil.apply_modifiers(temp_vert, geo) diff --git a/infinigen/core/rendering/post_render.py b/infinigen/core/rendering/post_render.py index 29f7c7ef2..a6c4f122f 100644 --- a/infinigen/core/rendering/post_render.py +++ b/infinigen/core/rendering/post_render.py @@ -6,7 +6,10 @@ import argparse import os + +# ruff: noqa: E402 os.environ["OPENCV_IO_ENABLE_OPENEXR"]="1" # This must be done BEFORE import cv2. + import cv2 import colorsys import flow_vis # run pip install flow_vis diff --git a/infinigen/core/rendering/render.py b/infinigen/core/rendering/render.py index bcfdf77da..29a89c78c 100644 --- a/infinigen/core/rendering/render.py +++ b/infinigen/core/rendering/render.py @@ -232,10 +232,10 @@ def render_image( for exclude in excludes: bpy.data.objects[exclude].hide_render = True - with Timer(f"Enable GPU"): + with Timer("Enable GPU"): devices = enable_gpu() - with Timer(f"Render/Cycles settings"): + with Timer("Render/Cycles settings"): if motion_blur: bpy.context.scene.cycles.motion_blur_position = 'START' bpy.context.scene.cycles.samples = num_samples # i.e. infinity @@ -250,8 +250,8 @@ def render_image( bpy.context.scene.cycles.use_denoising = True try: bpy.context.scene.cycles.denoiser = 'OPTIX' - except: - warnings.warn("Cannot use OPTIX denoiser") + except Exception as e: + warnings.warn(f"Cannot use OPTIX denoiser {e}") tmp_dir = frames_folder.parent.resolve() / "tmp" tmp_dir.mkdir(exist_ok=True) bpy.context.scene.render.filepath = f"{tmp_dir}{os.sep}" @@ -268,7 +268,7 @@ def render_image( global_flat_shading() - with Timer(f"Compositing Setup"): + with Timer("Compositing Setup"): if not bpy.context.scene.use_nodes: bpy.context.scene.use_nodes = True compositor_node_tree = bpy.context.scene.node_tree @@ -291,7 +291,7 @@ def render_image( for file_slot in compositor_nodes: file_slot.path = f"{file_slot.path}_####_{camera_rig_id:02d}_{subcam_id:02d}" - with Timer(f"get_camera"): + with Timer("get_camera"): camera = cam_util.get_camera(camera_rig_id, subcam_id) if use_dof == 'IF_TARGET_SET': use_dof = camera.data.dof.focus_object is not None @@ -305,10 +305,10 @@ def render_image( # Render the scene bpy.context.scene.camera = camera - with Timer(f"Actual rendering"): + with Timer("Actual rendering"): bpy.ops.render.render(animation=True) - with Timer(f"Post Processing"): + with Timer("Post Processing"): for frame in range(bpy.context.scene.frame_start, bpy.context.scene.frame_end + 1): if flat_shading: bpy.context.scene.frame_set(frame) diff --git a/infinigen/core/surface.py b/infinigen/core/surface.py index 664179a77..512590c1b 100644 --- a/infinigen/core/surface.py +++ b/infinigen/core/surface.py @@ -397,11 +397,11 @@ def initialize_from_gin(self, smooth_categories=0, **gin_category_info): def __call__(self, category_key): if self._registry is None: raise ValueError( - f'Surface registry has not been initialized! Have you loaded gin and called .initialize()?' + 'Surface registry has not been initialized! Have you loaded gin and called .initialize()?' 'Note, this step cannot happen at module initialization time, as gin is not yet loaded' ) - if not category_key in self._registry: + if category_key not in self._registry: raise KeyError( f'registry recieved request with {category_key=}, but no gin_config for this key was provided. {self._registry.keys()=}') diff --git a/infinigen/core/util/exporting.py b/infinigen/core/util/exporting.py index cee721207..24e9b62af 100644 --- a/infinigen/core/util/exporting.py +++ b/infinigen/core/util/exporting.py @@ -99,7 +99,7 @@ def get_all_non_instances(): yield dict(vertex_lookup=hair_vertices, radii=hair_radii, name=obj.name, matrices=mat, instance_ids=[get_id(deps_instance)], is_instance=False) def parse_group_from_name(name: str): - for reg in [f"(.*)\.spawn_asset\(.*", f"scatter:(.*)", "([A-Za-z_]+)"]: + for reg in ["(.*)\.spawn_asset\(.*", "scatter:(.*)", "([A-Za-z_]+)"]: match = re.fullmatch(reg, name) if match: return match.group(1) diff --git a/infinigen/core/util/math.py b/infinigen/core/util/math.py index 0b7d309ac..4cfafa960 100644 --- a/infinigen/core/util/math.py +++ b/infinigen/core/util/math.py @@ -162,14 +162,8 @@ def from_bpy_box(cls, bpy_obj): return cls.from_center_dims(center, dims) - def spawn_empty(self, name='BBoxEmpty'): - obj = spawn_empty(name, disp_type='CUBE', s=0.5) # rad 0.5, diameter 1 - obj.location = self.center() - obj.scale = self.dims() - return obj - @classmethod - def empty(cls, dim): + def empty_box(cls, dim): return cls(np.zeros(dim), np.zeros(dim)) def to_limits(self): diff --git a/infinigen/datagen/configs/compute_platform/local_256GB.gin b/infinigen/datagen/configs/compute_platform/local_256GB.gin index 0cf2fe5ca..211feaecd 100644 --- a/infinigen/datagen/configs/compute_platform/local_256GB.gin +++ b/infinigen/datagen/configs/compute_platform/local_256GB.gin @@ -8,7 +8,7 @@ LocalScheduleHandler.jobs_per_gpu = 1 jobs_to_launch_next.max_queued_total = 1 jobs_to_launch_next.max_stuck_at_task = 4 -get_cmd.blender_thread_limit = 8 +# get_cmd.blender_thread_limit = 8 # no longer supported with pip bpy # All will run locally, LocalScheduleHandler doesnt actually enforce cpu/ram constraints currently queue_coarse.submit_cmd = @local_submit_cmd diff --git a/infinigen/datagen/customgt/show.py b/infinigen/datagen/customgt/show.py index d44f598d8..11534077f 100644 --- a/infinigen/datagen/customgt/show.py +++ b/infinigen/datagen/customgt/show.py @@ -12,7 +12,7 @@ from matplotlib.text import Text from imageio import imread -import numpy as np; np.random.seed(42) +np.random.seed(42) if __name__ == "__main__": parser = argparse.ArgumentParser() diff --git a/infinigen/datagen/job_funcs.py b/infinigen/datagen/job_funcs.py index 438ac8ced..1ce515406 100644 --- a/infinigen/datagen/job_funcs.py +++ b/infinigen/datagen/job_funcs.py @@ -29,7 +29,7 @@ def get_cmd( taskname, output_folder, blender_thread_limit=None, - driver_script='generate.py', + driver_script='examples/generate_nature.py', input_folder=None, process_niceness=None, ): @@ -40,10 +40,12 @@ def get_cmd( cmd = '' if process_niceness is not None: cmd += f'nice -n {process_niceness} ' - cmd += f'python {driver_script} -- '' - if blender_thread_limit is not None: - cmd += f'--threads {blender_thread_limit} ' - + cmd += f'python {driver_script} ' + + # No longer supported using pip bpy + #if blender_thread_limit is not None: + # cmd += f'--threads {blender_thread_limit} ' + cmd += '-- ' if input_folder is not None: diff --git a/infinigen/datagen/tools/blendscript_import_infinigen.py b/infinigen/datagen/tools/blendscript_import_infinigen.py index 407a4ee65..dedb1c4df 100644 --- a/infinigen/datagen/tools/blendscript_import_infinigen.py +++ b/infinigen/datagen/tools/blendscript_import_infinigen.py @@ -10,8 +10,10 @@ import bpy from pathlib import Path -import sys, os +import sys +import os +# ruff: noqa pwd = os.getcwd() sys.path.append(pwd) diff --git a/infinigen/datagen/tools/dev/generate_terrain_assets.py b/infinigen/datagen/tools/dev/generate_terrain_assets.py index 3d3f81b63..f2cc8dc31 100644 --- a/infinigen/datagen/tools/dev/generate_terrain_assets.py +++ b/infinigen/datagen/tools/dev/generate_terrain_assets.py @@ -13,13 +13,11 @@ import argparse from pathlib import Path -sys.path.append(os.getcwd()) - import bpy -from terrain.assets.caves import caves_asset -from terrain.assets.landtiles import landtile_asset -from terrain.assets.upsidedown_mountains import upsidedown_mountains_asset -from util import blender as butil +from infinigen.terrain.assets.caves import caves_asset +from infinigen.terrain.assets.landtiles import landtile_asset +from infinigen.terrain.assets.upsidedown_mountains import upsidedown_mountains_asset +from infinigen.core.util import blender as butil from infinigen.core.util.math import int_hash, FixedSeed from infinigen.core.util.organization import Assets, LandTile, AssetFile diff --git a/infinigen/datagen/tools/dev/landtile_viewer.py b/infinigen/datagen/tools/dev/landtile_viewer.py index 4d23be24d..d08235314 100644 --- a/infinigen/datagen/tools/dev/landtile_viewer.py +++ b/infinigen/datagen/tools/dev/landtile_viewer.py @@ -6,13 +6,12 @@ import os import sys - -sys.path.append(f"{os.path.split(os.path.abspath(__file__))[0]}/../..") import argparse import bpy import numpy as np -from nodes.node_wrangler import Nodes, NodeWrangler + +from infinigen.core.nodes import Nodes, NodeWrangler from terrain.utils import Mesh, read from infinigen.core.util.blender import clear_scene from infinigen.core.util.organization import AssetFile diff --git a/infinigen/datagen/tools/export/export.py b/infinigen/datagen/tools/export/export.py index 45996b062..4000d0fdf 100644 --- a/infinigen/datagen/tools/export/export.py +++ b/infinigen/datagen/tools/export/export.py @@ -13,7 +13,7 @@ def realizeInstances(obj): for mod in obj.modifiers: - if (mod == None or mod.type != 'NODES'): continue + if (mod is None or mod.type != 'NODES'): continue print(mod) print(mod.node_group) print("Realizing instances on " + obj.name) @@ -81,7 +81,7 @@ def bakeTexture(obj, dest, img_size): # modified from https://blender.stackexcha diffuse_node.image = imgDiffuse nodes.active = diffuse_node - if (nodes.get("Principled BSDF") == None): + if (nodes.get("Principled BSDF") is None): noBSDF = True else: principled_bsdf_node = nodes["Principled BSDF"] @@ -206,7 +206,7 @@ def main(args, source, dest): obj.hide_render = True # remove grid - if (bpy.data.objects.get("Grid") != None): + if (bpy.data.objects.get("Grid") is not None): bpy.data.objects.remove(bpy.data.objects["Grid"], do_unlink=True) bpy.context.scene.render.engine = 'CYCLES' diff --git a/infinigen/datagen/tools/results/scatter_figure.py b/infinigen/datagen/tools/results/scatter_figure.py index d4f292874..2bae2208e 100644 --- a/infinigen/datagen/tools/results/scatter_figure.py +++ b/infinigen/datagen/tools/results/scatter_figure.py @@ -11,30 +11,35 @@ import numpy as np import os import argparse - -from surfaces.scatters import seashells - -sys.path.append(os.getcwd()) +import numpy as np +from numpy.random import uniform as U import gin +from infinigen.core.surface import registry + +from infinigen.assets.scatters import ( + grass, + chopped_trees, + pine_needle, + flowerplant, + fern, + pinecone, + urchin, + seaweed, + seashells +) +from infinigen.assets.materials import dirt, sand, mud +from infinigen.core.placement import density +import math +from infinigen.core.util import blender as butil +from infinigen.assets.lighting import sky_lighting + gin.clear_config() gin.enter_interactive_mode() -import generate gin.parse_config_files_and_bindings(['config/base.gin'], []) -from surfaces.surface import registry registry.initialize_from_gin() -import numpy as np -from numpy.random import uniform as U - -from surfaces.scatters import grass, chopped_trees, pine_needle, flowerplant, fern, pine_needle, pinecone, urchin, seaweed -from surfaces.templates import dirt, sand, mud -from placement import density -import math -from util import blender as butil -from lighting import lighting - class ArgumentParserForBlender(argparse.ArgumentParser): """ This class is identical to its superclass, except for the parse_args @@ -121,7 +126,8 @@ def apply_scatters(obj, mode, index): pio, _ = pinecone.apply(obj, selection=density.placement_mask(scale=U(0.1, 0.4), select_thresh=U(0.4, 0.6)), density=U(0.4, 0.6)) - co, _ = chopped_trees.apply(obj, selection=density.placement_mask(scale=U(0.1, 0.4), select_thresh=U(0.4, 0.6), density=U(0.4, 0.6)) + selection = density.placement_mask(scale=U(0.1, 0.4), select_thresh=U(0.4, 0.6), density=U(0.4, 0.6)) + co, _ = chopped_trees.apply(obj, selection=selection) all_objects.append(po) all_objects.append(pio) all_objects.append(co) @@ -142,7 +148,7 @@ def apply_scatters(obj, mode, index): planeres = 300 butil.clear_scene() -lighting.add_lighting() +sky_lighting.add_lighting() bpy.ops.object.camera_add(location=mathutils.Vector(args.view * np.array([-10,-10,10])), rotation=(np.deg2rad(70), 0, np.deg2rad(-45))) diff --git a/infinigen/datagen/util/submitit_emulator.py b/infinigen/datagen/util/submitit_emulator.py index 854818a59..9f68363f7 100644 --- a/infinigen/datagen/util/submitit_emulator.py +++ b/infinigen/datagen/util/submitit_emulator.py @@ -243,6 +243,7 @@ def get_all_processes(): groups = (psef_regex(l).groups() for l in psef_out.splitlines()) return {int(pid):cmd for pid, cmd in groups} +# ruff: noqa if __name__ == "__main__": test = 'upload' diff --git a/infinigen/datagen/util/upload_util.py b/infinigen/datagen/util/upload_util.py index 4c6b6bef7..9ba18cdc8 100644 --- a/infinigen/datagen/util/upload_util.py +++ b/infinigen/datagen/util/upload_util.py @@ -99,7 +99,7 @@ def apply_manifest_cleanup(scene_folder, manifest): def rclone_upload_file(src_file, dst_folder): if GDRIVE_NAME is None: - raise ValueError(f'Please specify GDRIVE_NAME') + raise ValueError('Please specify GDRIVE_NAME') assert os.path.exists(src_file), src_file cmd = f"{shutil.which('rclone')} copy -P {src_file} {GDRIVE_NAME}:{dst_folder}" diff --git a/infinigen/terrain/assets/upsidedown_mountains.py b/infinigen/terrain/assets/upsidedown_mountains.py index 76ff8870f..09e359c50 100644 --- a/infinigen/terrain/assets/upsidedown_mountains.py +++ b/infinigen/terrain/assets/upsidedown_mountains.py @@ -110,9 +110,9 @@ def upsidedown_mountains_asset( res = mg.at_node['topographic__elevation'] upside = res.reshape((N, N)) - cv2.imwrite(str(folder/f'upside.exr'), upside.astype(np.float32)) - cv2.imwrite(str(folder/f'peak.exr'), peak.astype(np.float32)) - cv2.imwrite(str(folder/f'downside.exr'), downside.astype(np.float32)) + cv2.imwrite(str(folder/'upside.exr'), upside.astype(np.float32)) + cv2.imwrite(str(folder/'peak.exr'), peak.astype(np.float32)) + cv2.imwrite(str(folder/'downside.exr'), downside.astype(np.float32)) with open(folder/f'{AssetFile.TileSize}.txt', "w") as f: f.write(f"{tile_size}\n") @@ -125,10 +125,10 @@ def upsidedown_mountains_asset( def assets_to_data(folder): data = {} - upside = read(str(folder/f'upside.exr')) + upside = read(str(folder/'upside.exr')) N = upside.shape[0] data["upside"] = AC(upside.reshape(-1)) - data["downside"] = AC(read(str(folder/f'downside.exr')).reshape(-1)) - data["peak"] = AC(read(str(folder/f'peak.exr')).reshape(-1)) + data["downside"] = AC(read(str(folder/'downside.exr')).reshape(-1)) + data["peak"] = AC(read(str(folder/'peak.exr')).reshape(-1)) L = float(np.loadtxt(f"{folder}/{AssetFile.TileSize}.txt")) return L, N, data diff --git a/infinigen/terrain/land_process/erosion.py b/infinigen/terrain/land_process/erosion.py index 114d52f3e..06247e54e 100644 --- a/infinigen/terrain/land_process/erosion.py +++ b/infinigen/terrain/land_process/erosion.py @@ -25,7 +25,7 @@ def run_erosion( ground_depth=25, sinking_rate=0.05, ): - dll = load_cdll(f"terrain/lib/cpu/soil_machine/SoilMachine.so") + dll = load_cdll("terrain/lib/cpu/soil_machine/SoilMachine.so") func = dll.run func.argtypes = [ POINTER(c_float), POINTER(c_float), POINTER(c_float), diff --git a/infinigen/terrain/mesh_to_sdf/pyrender_wrapper.py b/infinigen/terrain/mesh_to_sdf/pyrender_wrapper.py index b4d4bfa77..80884cf8f 100644 --- a/infinigen/terrain/mesh_to_sdf/pyrender_wrapper.py +++ b/infinigen/terrain/mesh_to_sdf/pyrender_wrapper.py @@ -14,6 +14,7 @@ if 'OpenGL' in sys.modules: raise ImportError('The mesh_to_sdf package must be imported before OpenGL is imported.') +# ruff: noqa: E402 # Disable antialiasing: import OpenGL.GL diff --git a/infinigen/terrain/mesh_to_sdf/surface_point_cloud.py b/infinigen/terrain/mesh_to_sdf/surface_point_cloud.py index 85b599278..932144bc6 100644 --- a/infinigen/terrain/mesh_to_sdf/surface_point_cloud.py +++ b/infinigen/terrain/mesh_to_sdf/surface_point_cloud.py @@ -13,7 +13,6 @@ import trimesh import logging -logging.getLogger("trimesh").setLevel(9000) import numpy as np from sklearn.neighbors import KDTree import math @@ -21,6 +20,8 @@ from .utils import sample_uniform_points_in_unit_sphere from .utils import get_raster_points, check_voxels +logging.getLogger("trimesh").setLevel(9000) + class BadMeshException(Exception): pass diff --git a/infinigen/terrain/mesher/cube_spherical_mesher.py b/infinigen/terrain/mesher/cube_spherical_mesher.py index a5d09064b..8e1c9fca0 100644 --- a/infinigen/terrain/mesher/cube_spherical_mesher.py +++ b/infinigen/terrain/mesher/cube_spherical_mesher.py @@ -85,7 +85,7 @@ def __call__(self, kernels): H = self.L - 2 * self.N0 W = self.L - 2 * self.N1 R = self.R - with Timer(f"init_and_get_emptytest_queries"): + with Timer("init_and_get_emptytest_queries"): test_L = (self.L - 1) // self.test_downscale + 1 test_R = (self.R - 1) // self.test_downscale + 1 positions = AC(np.zeros((6 * (test_L + 1) ** 2 * (test_R + 1), 3), dtype=np.float64)) @@ -129,7 +129,7 @@ def __call__(self, kernels): ASDOUBLE(AC(verts_i.astype(np.float64))), len(verts_i), ASINT(AC(faces_i.astype(np.int32))), len(faces_i), ) - with Timer(f"collect new cnt"): + with Timer("collect new cnt"): cnt = self.get_cnt() if self.upscale != -1 and self.upscale != 1: @@ -172,7 +172,7 @@ def __call__(self, kernels): ASDOUBLE(AC(verts_i.astype(np.float64))), len(verts_i), ASINT(AC(faces_i.astype(np.int32))), len(faces_i), ) - with Timer(f"collect new cnt"): + with Timer("collect new cnt"): cnt = self.finefront_get_cnt() self.finefront_cleanup() diff --git a/infinigen/terrain/mesher/frontview_spherical_mesher.py b/infinigen/terrain/mesher/frontview_spherical_mesher.py index 881a8c7b5..345078543 100644 --- a/infinigen/terrain/mesher/frontview_spherical_mesher.py +++ b/infinigen/terrain/mesher/frontview_spherical_mesher.py @@ -83,7 +83,7 @@ def __init__(self, def __call__(self, kernels): n_elements = len(kernels) - with Timer(f"init_and_get_emptytest_queries"): + with Timer("init_and_get_emptytest_queries"): test_H = (self.H - 1) // self.test_downscale + 1 test_W = (self.W - 1) // self.test_downscale + 1 test_R = (self.R - 1) // self.test_downscale + 1 @@ -127,7 +127,7 @@ def __call__(self, kernels): ASDOUBLE(AC(verts_frac.astype(np.float64))), len(verts_int), ASINT(AC(faces.astype(np.int32))), len(faces), ) - with Timer(f"collect new cnt"): + with Timer("collect new cnt"): cnt = self.get_cnt() with Timer("merge identifiers and get coarse vert counts"): diff --git a/infinigen/terrain/mesher/uniform_mesher.py b/infinigen/terrain/mesher/uniform_mesher.py index bbce11037..dc68c136a 100644 --- a/infinigen/terrain/mesher/uniform_mesher.py +++ b/infinigen/terrain/mesher/uniform_mesher.py @@ -36,7 +36,7 @@ def __init__(self, self.enclosed = enclosed self.upscale = upscale self.dimensions = dimensions - Lx, Ly, Lz = dimensions[1] - dimensions[0], dimensions[3] - dimensions[2], dimensions[5] - dimensions[4] + # Lx, Ly, Lz = dimensions[1] - dimensions[0], dimensions[3] - dimensions[2], dimensions[5] - dimensions[4] assert(np.sum(subdivisions == -1) in [0, 2]) for i, s in enumerate(subdivisions): if s != -1: diff --git a/infinigen/terrain/utils/image_processing.py b/infinigen/terrain/utils/image_processing.py index 78cc5ea69..5c11e4e5c 100644 --- a/infinigen/terrain/utils/image_processing.py +++ b/infinigen/terrain/utils/image_processing.py @@ -6,13 +6,13 @@ import os +# ruff: noqa: E402 os.environ["OPENCV_IO_ENABLE_OPENEXR"] = "1" # This must be done BEFORE import cv2. # See https://github.com/opencv/opencv/issues/21326#issuecomment-1008517425 import cv2 import numpy as np - def boundary_smooth(ar, p=0.1): N = ar.shape[0] P = int(N * p) diff --git a/infinigen/terrain/utils/mesh.py b/infinigen/terrain/utils/mesh.py index 2e435262f..adab067b2 100644 --- a/infinigen/terrain/utils/mesh.py +++ b/infinigen/terrain/utils/mesh.py @@ -189,7 +189,7 @@ def vertex_normals(self): return w_normals def facewise_mean(self, attr): - dll = load_cdll(f"terrain/lib/cpu/meshing/utils.so") + dll = load_cdll("terrain/lib/cpu/meshing/utils.so") facewise_mean = dll.facewise_mean facewise_mean.argtypes = [POINTER(c_double), POINTER(c_int32), c_int32, POINTER(c_double)] facewise_mean.restype = None @@ -198,7 +198,7 @@ def facewise_mean(self, attr): return result def facewise_intmax(self, attr): - dll = load_cdll(f"terrain/lib/cpu/meshing/utils.so") + dll = load_cdll("terrain/lib/cpu/meshing/utils.so") facewise_intmax = dll.facewise_intmax facewise_intmax.argtypes = [POINTER(c_int32), POINTER(c_int32), c_int32, POINTER(c_int32)] facewise_intmax.restype = None @@ -207,7 +207,7 @@ def facewise_intmax(self, attr): return result def get_adjacency(self): - dll = load_cdll(f"terrain/lib/cpu/meshing/utils.so") + dll = load_cdll("terrain/lib/cpu/meshing/utils.so") get_adjacency = dll.get_adjacency get_adjacency.argtypes = [c_int32, c_int32, POINTER(c_int32), POINTER(c_int32)] get_adjacency.restype = None diff --git a/infinigen/tools/blendscript_import_infinigen.py b/infinigen/tools/blendscript_import_infinigen.py index b84c01952..f45bf0cc0 100644 --- a/infinigen/tools/blendscript_import_infinigen.py +++ b/infinigen/tools/blendscript_import_infinigen.py @@ -8,6 +8,8 @@ Once this is done, you can do things like `from infinigen.assets.creatures.util.genomes.carnivore import CarnivoreFactory` then `CarnivoreFactory(0).spawn_asset(0)` directly in the blender commandline ''' +# ruff: noqa + import bpy from pathlib import Path import sys, os diff --git a/infinigen/tools/terrain/generate_terrain_assets.py b/infinigen/tools/terrain/generate_terrain_assets.py index 14649540b..f2cc8dc31 100644 --- a/infinigen/tools/terrain/generate_terrain_assets.py +++ b/infinigen/tools/terrain/generate_terrain_assets.py @@ -13,8 +13,6 @@ import argparse from pathlib import Path -sys.path.append(os.getcwd()) - import bpy from infinigen.terrain.assets.caves import caves_asset from infinigen.terrain.assets.landtiles import landtile_asset diff --git a/infinigen/tools/terrain/kernelize_surfaces.py b/infinigen/tools/terrain/kernelize_surfaces.py index d1da7a648..dde488010 100644 --- a/infinigen/tools/terrain/kernelize_surfaces.py +++ b/infinigen/tools/terrain/kernelize_surfaces.py @@ -7,12 +7,11 @@ import os import sys -sys.path.append(f"{os.path.split(os.path.abspath(__file__))[0]}/..") import subprocess from pathlib import Path import bpy -from infinigen.core import VERSION +from infinigen import __version__ from infinigen.assets.materials import chunkyrock, cobble_stone, cracked_ground, dirt, ice, mountain, mud, sand, sandstone, snow, soil, stone from infinigen.terrain.surface_kernel.kernelizer import Kernelizer from infinigen.core.util.blender import clear_scene @@ -29,7 +28,7 @@ folder.mkdir(exist_ok=1) dst = folder/f"{surface.name}.h" with open(dst, "w") as f: - f.write(f'''// Code generated using version {VERSION} of infinigen/tools/kernelize_surfaces.py; refer to infinigen/assets/materials/{surface.name}.py which has the copyright and authors''') + f.write(f'''// Code generated using version {__version__} of infinigen/tools/kernelize_surfaces.py; refer to infinigen/assets/materials/{surface.name}.py which has the copyright and authors''') f.write(code) f.write("\n") # optional: clang-format needed to format output code diff --git a/pyproject.toml b/pyproject.toml index 0aad919be..098aebd58 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,28 +70,28 @@ markers = [ [tool.ruff] select = [ - "E", - "F", - #"B", + "E", + "F", + #"B", #"C901", ] target-version = "py310" -line-length = 88 +line-length = 120 # will be reduced to 88 to match black soon -exclude = ["*/dependencies/"] +exclude = [ + "*/dependencies/" +] ignore = [ "E402", # we have lots of sys.path and opencv statements that must preceed imports, ignore for now "E501", # ignore line length for now "E701", # disable multi line statements until we enable black "F401", # unused imports are sometimes necessary for gin to work "E712", # some people think `if x == True` is more explicit, not going to force it -] +] [tool.ruff.per-file-ignores] "__init__.py" = [] -"infinigen/assets/*" = [ - "F841", #transpiler currently creates lots of unused variables -] +"infinigen/assets/*" = ["F841"] #transpiler currently creates lots of unused variables [tool.ruff.mccabe] diff --git a/tests/integration/manual_integration_check.py b/tests/integration/manual_integration_check.py index 39cab2ed9..baa47d00f 100644 --- a/tests/integration/manual_integration_check.py +++ b/tests/integration/manual_integration_check.py @@ -108,7 +108,7 @@ def parse_scene_log(scene_path, step_times, asset_time_data, poly_data, asset_me if "[MAIN TOTAL] finished in" not in text: continue search = re.search(r'\[MAIN TOTAL\] finished in ([0-9]+):([0-9]+):([0-9]+)', text) d = None - if search == None: + if search is None: search = re.search(r'\[MAIN TOTAL\] finished in ([0-9]) day.*, ([0-9]+):([0-9]+):([0-9]+)', text) d,h,m,s = search.group(1,2,3,4) else: @@ -196,9 +196,9 @@ def parse_scene_log(scene_path, step_times, asset_time_data, poly_data, asset_me all_data[seed]["[Instances Generated] [Coarse] " + row["name"]] = row["instance_delta"] fine_stage_df = pd.read_csv(os.path.join(coarse_folder, "pipeline_fine.csv")) # this is supposed to be coarse folder - fine_stage_df["mem_delta"] = fine_stage_df[fine_stage_df['ran']==True]['mem_at_finish'].diff() - fine_stage_df["obj_delta"] = fine_stage_df[fine_stage_df['ran']==True]['obj_count'].diff() - fine_stage_df["instance_delta"] = fine_stage_df[fine_stage_df['ran']==True]['instance_count'].diff() + fine_stage_df["mem_delta"] = fine_stage_df[fine_stage_df['ran']]['mem_at_finish'].diff() + fine_stage_df["obj_delta"] = fine_stage_df[fine_stage_df['ran']]['obj_count'].diff() + fine_stage_df["instance_delta"] = fine_stage_df[fine_stage_df['ran']]['instance_count'].diff() for index, row in fine_stage_df.iterrows(): if row["mem_delta"] == 0 or math.isnan(float(row["mem_delta"])) or row["ran"] == False: continue asset_mem_data["[Fine] " + row["name"]].append(row["mem_delta"]) diff --git a/tests/test_nature_materials_basic.py b/tests/test_nature_materials_basic.py index 6d23b6965..33029a9f9 100644 --- a/tests/test_nature_materials_basic.py +++ b/tests/test_nature_materials_basic.py @@ -5,7 +5,6 @@ import bpy import gin -from infinigen.assets import * # so gin can find them from infinigen.core.util import blender as butil from utils import ( @@ -17,7 +16,7 @@ @pytest.mark.parametrize('factory_name', load_txt_list('test_nature_materials_basic.txt')) def test_material_runs(factory_name, **kwargs): - butil.clear_scene + butil.clear_scene() with gin.unlock_config(): mat = importlib.import_module(f'infinigen.assets.materials.{factory_name}') bpy.ops.mesh.primitive_ico_sphere_add(radius=.8, subdivisions=5) diff --git a/tests/test_nature_meshes_basic.py b/tests/test_nature_meshes_basic.py index 034440299..1753fe448 100644 --- a/tests/test_nature_meshes_basic.py +++ b/tests/test_nature_meshes_basic.py @@ -4,7 +4,6 @@ import bpy import gin -from infinigen.assets import * # so gin can find them from infinigen.core.util import blender as butil from utils import (