diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 9e08a31f6..44cfae68e 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -72,4 +72,6 @@ v1.5.1 - Fix "base.gin" crash in generate_individual_assets - Fix individual_export in export.py - Fix Dockerfile -- Remove dependabot \ No newline at end of file +- Remove dependabot +- Add scatter unit tests and fix scatter imports +- Fix black renders due to non-hidden particle emitter \ No newline at end of file diff --git a/infinigen/assets/scatters/clothes.py b/infinigen/assets/scatters/clothes.py index cf4966756..9e9dbf894 100644 --- a/infinigen/assets/scatters/clothes.py +++ b/infinigen/assets/scatters/clothes.py @@ -9,6 +9,7 @@ import numpy as np from numpy.random import uniform +from infinigen.assets.objects.clothes import blanket, pants, shirt from infinigen.assets.objects.creatures.util.cloth_sim import bake_cloth from infinigen.assets.utils.decorate import read_co, subsurf from infinigen.core.placement.factory import make_asset_collection @@ -49,8 +50,6 @@ class ClothesCover: def __init__( self, bbox=(0.3, 0.7, 0.3, 0.7), factory_fn=None, width=None, size=None ): - from infinigen.assets.clothes import blanket, pants, shirt - probs = np.array([2, 1, 1]) if factory_fn is None: factory_fn = np.random.choice( diff --git a/infinigen/assets/scatters/ground_mushroom.py b/infinigen/assets/scatters/ground_mushroom.py index 959c11da3..43f35cfed 100644 --- a/infinigen/assets/scatters/ground_mushroom.py +++ b/infinigen/assets/scatters/ground_mushroom.py @@ -39,3 +39,8 @@ def apply(self, obj, scale=0.3, density=1.0, selection=None): ) return scatter_obj + + +def apply(obj): + mushrooms = Mushrooms() + return mushrooms.apply(obj) diff --git a/infinigen/assets/scatters/mollusk.py b/infinigen/assets/scatters/mollusk.py index d56ad3134..3ad39616f 100644 --- a/infinigen/assets/scatters/mollusk.py +++ b/infinigen/assets/scatters/mollusk.py @@ -32,7 +32,6 @@ def scaling(nw): ) scatter_obj = scatter_instances( - "mollusk", base_obj=obj, collection=mollusk, density=density, diff --git a/infinigen/assets/scatters/moss.py b/infinigen/assets/scatters/moss.py index 75b6e086a..b4ef4c924 100644 --- a/infinigen/assets/scatters/moss.py +++ b/infinigen/assets/scatters/moss.py @@ -50,3 +50,8 @@ def instance_index(nw: NodeWrangler, n): ) return scatter_obj + + +def apply(obj): + moss_cover = MossCover() + return moss_cover.apply(obj) diff --git a/infinigen/assets/scatters/slime_mold.py b/infinigen/assets/scatters/slime_mold.py index c4342192a..ba77bfb68 100644 --- a/infinigen/assets/scatters/slime_mold.py +++ b/infinigen/assets/scatters/slime_mold.py @@ -86,3 +86,7 @@ def weight(nw): assign_material(scatter_obj, shaderfunc_to_material(shader_mold, base_hue)) return scatter_obj + + +def apply(obj, selection=None): + SlimeMold().apply(obj, selection) diff --git a/infinigen/assets/scatters/snow_layer.py b/infinigen/assets/scatters/snow_layer.py index 64ad02d21..653877605 100644 --- a/infinigen/assets/scatters/snow_layer.py +++ b/infinigen/assets/scatters/snow_layer.py @@ -12,6 +12,7 @@ class Snowlayer: def __init__(self): + bpy.ops.preferences.addon_enable(module="real_snow") pass def apply(self, obj, **kwargs): @@ -21,3 +22,9 @@ def apply(self, obj, **kwargs): snow = bpy.context.active_object tag_object(snow, "snow") tag_object(snow, "boulder") + + +def apply(obj): + snowlayer = Snowlayer() + snowlayer.apply(obj) + return snowlayer diff --git a/infinigen/core/placement/instance_scatter.py b/infinigen/core/placement/instance_scatter.py index 5c81dbd01..ae9627dcd 100644 --- a/infinigen/core/placement/instance_scatter.py +++ b/infinigen/core/placement/instance_scatter.py @@ -332,7 +332,10 @@ def scatter_instances( name = "scatter:" + collection.name.split(":")[-1] - avg_scale = scale * (1 - scale_rand / 2) * (1 - scale_rand_axi / 2) + if scale is not None: + avg_scale = scale * (1 - scale_rand / 2) * (1 - scale_rand_axi / 2) + else: + avg_scale = 1 if vol_density is not None: assert ( diff --git a/tests/assets/list_scatters.txt b/tests/assets/list_scatters.txt new file mode 100644 index 000000000..063fd1672 --- /dev/null +++ b/tests/assets/list_scatters.txt @@ -0,0 +1,25 @@ +# infinigen.assets.scatters.coral_reef # too slow for unit tests +infinigen.assets.scatters.chopped_trees +infinigen.assets.scatters.clothes +infinigen.assets.scatters.decorative_plants +infinigen.assets.scatters.fern +infinigen.assets.scatters.flowerplant +infinigen.assets.scatters.grass +infinigen.assets.scatters.ground_leaves +infinigen.assets.scatters.ground_mushroom +infinigen.assets.scatters.ground_twigs +infinigen.assets.scatters.ivy +infinigen.assets.scatters.jellyfish +infinigen.assets.scatters.lichen +infinigen.assets.scatters.mollusk +infinigen.assets.scatters.monocots +infinigen.assets.scatters.moss +infinigen.assets.scatters.mushroom +infinigen.assets.scatters.pebbles +infinigen.assets.scatters.pine_needle +infinigen.assets.scatters.pinecone +infinigen.assets.scatters.seashells +infinigen.assets.scatters.seaweed +infinigen.assets.scatters.slime_mold +infinigen.assets.scatters.snow_layer +infinigen.assets.scatters.urchin diff --git a/tests/assets/test_scatters_basic.py b/tests/assets/test_scatters_basic.py new file mode 100644 index 000000000..707e8d318 --- /dev/null +++ b/tests/assets/test_scatters_basic.py @@ -0,0 +1,24 @@ +# Copyright (c) Princeton University. +# This source code is licensed under the BSD 3-Clause license found in the LICENSE file in the root directory +# of this source tree. + +# Authors: Alexander Raistrick + +import pytest + +from infinigen.core.util import blender as butil +from infinigen_examples.util.test_utils import import_item, load_txt_list, setup_gin + + +def check_scatter_runs(pathspec): + butil.clear_scene() + base_cube = butil.spawn_cube() + + scatter = import_item(pathspec) + scatter.apply(base_cube) + + +@pytest.mark.parametrize("pathspec", load_txt_list("tests/assets/list_scatters.txt")) +def test_scatter_runs(pathspec, **kwargs): + setup_gin("infinigen_examples/configs_nature", ["base_nature.gin"]) + check_scatter_runs(pathspec)