Skip to content

Commit

Permalink
Add test_scatters_basic
Browse files Browse the repository at this point in the history
  • Loading branch information
araistrick authored and pvl-bot committed Jul 12, 2024
1 parent 5d431f9 commit 05a35dc
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 5 deletions.
4 changes: 3 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- Remove dependabot
- Add scatter unit tests and fix scatter imports
- Fix black renders due to non-hidden particle emitter
3 changes: 1 addition & 2 deletions infinigen/assets/scatters/clothes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions infinigen/assets/scatters/ground_mushroom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 0 additions & 1 deletion infinigen/assets/scatters/mollusk.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def scaling(nw):
)

scatter_obj = scatter_instances(
"mollusk",
base_obj=obj,
collection=mollusk,
density=density,
Expand Down
5 changes: 5 additions & 0 deletions infinigen/assets/scatters/moss.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ def instance_index(nw: NodeWrangler, n):
)

return scatter_obj


def apply(obj):
moss_cover = MossCover()
return moss_cover.apply(obj)
4 changes: 4 additions & 0 deletions infinigen/assets/scatters/slime_mold.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 7 additions & 0 deletions infinigen/assets/scatters/snow_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

class Snowlayer:
def __init__(self):
bpy.ops.preferences.addon_enable(module="real_snow")
pass

def apply(self, obj, **kwargs):
Expand All @@ -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
5 changes: 4 additions & 1 deletion infinigen/core/placement/instance_scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
25 changes: 25 additions & 0 deletions tests/assets/list_scatters.txt
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions tests/assets/test_scatters_basic.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 05a35dc

Please sign in to comment.