Skip to content

Commit

Permalink
Working pip installation
Browse files Browse the repository at this point in the history
* Update test import mechanism to use better specified paths

* Move nonessential tools out of the infinigen package dir

* Dont build terrain etc during tests

* temp commit txt package data

* Fix tests and runtime errors when running as a package

* Refactor config loading, fix relative paths in config, html, json pallette

* Move examples to infinigen_examples, test execute_tasks, make all config imports relative

* Add manifest.in, simplify pyproject.toml

* Convert surface registry to relative importlib style

Remove old docs, single-source the package version

Fix misc test warnings, disable egregiously slow single asset tests

* Final painstaking fix for pyproject.toml to include all compiled files & data files
  • Loading branch information
araistrick authored and pvl-bot committed Oct 4, 2023
1 parent eaaa816 commit cba91ca
Show file tree
Hide file tree
Showing 154 changed files with 756 additions and 1,087 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
- main
- develop

env:
INFINIGEN_INSTALL_RUNBUILD: False # disable building terrain, opengl and fluids, which wont be tested by pytest

jobs:

checks:
Expand All @@ -20,21 +23,23 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Lint with ruff
run: |
pip install ruff
# stop the build if there are Python syntax errors or undefined names
ruff --format=github --select=E9,F63,F7,F82 .
# default set of ruff rules with GitHub Annotations
#ruff --format=github . # to be enabled in a future PR
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install dependencies
- name: Install infinigen & dependencies
run: |
pip install .[dev]
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
ruff --format=github --select=E9,F63,F7,F82 .
# default set of ruff rules with GitHub Annotations
#ruff --format=github . # to be enabled in a future PR
- name: Test with pytest
run: |
pytest tests --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Blender-FLIP-Fluids
*.obj
*.blend
*.blend1
*.in
*.out
profiles_*.npz
*outputs
Expand All @@ -65,3 +64,6 @@ dist
build
blends
*.ipynb_checkpoints

process_mesh
worldgen
15 changes: 15 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Inspired by https://github.com/pytorch/pytorch/blob/main/MANIFEST.in

# Explanation: files denoted here are excluded from `python setup.py sdist`,
# but some are still explicitly included in the .whl via

recursive-include infinigen *.*
recursive-include tests *.*
recursive-include docs *.*
recursive-include infinigen_examples *.*

prune */__pycache__
prune infinigen/datagen/customgt/build/*
prune infinigen/datagen/customgt/dependencies/*

global-exclude *.o *.so *.pyc .git *.png
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
build_terrain:
cleanpip:
rm -rf *.egg-info
rm -rf build

clean_terrain:
rm -rf infinigen/terrain/*.egg-info
rm -rf infinigen/terrain/__pycache__
rm -rf infinigen/terrain/build

terrain: clean_terrain
bash infinigen/tools/install/compile_terrain.sh

build_custom_groundtruth:
customgt:
bash ./infinigen/tools/install/compile_opengl.sh

build_flip_fluids:
flip_fluids:
bash ./infinigen/tools/install/compile_flip_fluids.sh

DOCKER_BUILD_PROGRESS ?= auto
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


## [Infinigen: Infinite Photorealistic Worlds using Procedural Generation](https://infinigen.org)

Please visit our website, [https://infinigen.org](https://infinigen.org)
Expand Down
42 changes: 21 additions & 21 deletions docs/ConfiguringInfinigen.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/GroundTruthAnnotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Continuing the [Hello-World](/README.md#generate-a-scene-step-by-step) example,

4. Export the geometry from blender to disk
```
python examples/generate_nature.py -- --seed 0 --task mesh_save -g desert simple --input_folder outputs/helloworld/fine --output_folder outputs/helloworld/saved_mesh
python infinigen_examples/generate_nature.py -- --seed 0 --task mesh_save -g desert simple --input_folder outputs/helloworld/fine --output_folder outputs/helloworld/saved_mesh
```
5. Generate dense annotations
```
Expand Down
8 changes: 4 additions & 4 deletions docs/HelloWorld.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ Infinigen generates scenes by running multiple tasks (usually executed automatic
mkdir outputs
# Generate a scene layout
python examples/generate_nature.py -- --seed 0 --task coarse -g desert.gin simple.gin --output_folder outputs/helloworld/coarse
python infinigen_examples/generate_nature.py -- --seed 0 --task coarse -g desert.gin simple.gin --output_folder outputs/helloworld/coarse
# Populate unique assets
python examples/generate_nature.py -- --seed 0 --task populate fine_terrain -g desert.gin simple.gin --input_folder outputs/helloworld/coarse --output_folder outputs/helloworld/fine
python infinigen_examples/generate_nature.py -- --seed 0 --task populate fine_terrain -g desert.gin simple.gin --input_folder outputs/helloworld/coarse --output_folder outputs/helloworld/fine
# Render RGB images
python examples/generate_nature.py -- --seed 0 --task render -g desert.gin simple.gin --input_folder outputs/helloworld/fine --output_folder outputs/helloworld/frames
python infinigen_examples/generate_nature.py -- --seed 0 --task render -g desert.gin simple.gin --input_folder outputs/helloworld/fine --output_folder outputs/helloworld/frames
# Render again for accurate ground-truth
python examples/generate_nature.py -- --seed 0 --task render -g desert.gin simple.gin --input_folder outputs/helloworld/fine --output_folder outputs/helloworld/frames -p render.render_image_func=@flat/render_image
python infinigen_examples/generate_nature.py -- --seed 0 --task render -g desert.gin simple.gin --input_folder outputs/helloworld/fine --output_folder outputs/helloworld/frames -p render.render_image_func=@flat/render_image
```

Output logs should indicate what the code is working on. Use `--debug` for even more detail. After each command completes you can inspect it's `--output_folder` for results, including running `$BLENDER outputs/helloworld/coarse/scene.blend` or similar to view blender files. We hide many meshes by default for viewport stability; to view them, click "Render" or use the UI to unhide them.
Expand Down
2 changes: 1 addition & 1 deletion docs/ImplementingAssets.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class MyAssetFactory(AssetFactory):
You can implement the `create_asset` function however you wish so long as it produces a Blender Object as a result. Many existing assets use various different strategies, which you can use as examples:
- `assets/flower.py` uses mostly auto-generated code from transpiling a hand-designed geometry node-graph.
- `assets/grassland/grass_tuft.py` uses pure NumPy code to create and define a mesh.
- `assets/trees/examples/generate_nature.py` combines transpiled materials & leaves with a python-only space colonization algorithm.
- `assets/trees/infinigen_examples/generate_nature.py` combines transpiled materials & leaves with a python-only space colonization algorithm.

The simplest implementation for a new asset is to create a geometry nodes equivelant, transpile it similarly to as shown above, copy the code into the same file as the template shown above, and implement the `create_asset` function as shown:

Expand Down
5 changes: 0 additions & 5 deletions examples/configs/performance/simple.gin

This file was deleted.

13 changes: 0 additions & 13 deletions examples/scripts/hello_world_stepbystep.sh

This file was deleted.

11 changes: 0 additions & 11 deletions examples/scripts/render_river_video.sh

This file was deleted.

6 changes: 0 additions & 6 deletions examples/scripts/render_video_fire.sh

This file was deleted.

12 changes: 9 additions & 3 deletions infinigen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import pkg_resources
from pathlib import Path
__version__ = pkg_resources.get_distribution(Path(__file__).parent.name).version
import logging

__version__ = "1.1.0"

logging.basicConfig(
format='[%(asctime)s.%(msecs)03d] [%(name)s] [%(levelname)s] | %(message)s',
level=logging.INFO,
datefmt='%H:%M:%S'
)
4 changes: 2 additions & 2 deletions infinigen/assets/creatures/bird.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def duck_genome(mode):
body_lrr = np.array((0.85, 0.25, 0.38)) * N(1, 0.2) * N(1, 0.2, 3)
body_fac = parts.generic_nurbs.NurbsBody(prefix='body_bird', tags=['body', 'rigid'], var=U(0.3, 1))
body = genome.part(body_fac)
l = body_fac.params['length'].reshape(1)
l = body_fac.params['length'][0]

tail = genome.part(parts.wings.BirdTail())
genome.attach(tail, body, coord=(0.2, 1, 0.5), joint=Joint(rest=(0, 170 * N(1, 0.1), 0)))
Expand Down Expand Up @@ -163,7 +163,7 @@ def flying_bird_genome(mode):

body_lrr = np.array((0.95, 0.13, 0.18)) * N(1.0, 0.05, size=(3,))
body = genome.part(parts.body.BirdBody({'length_rad1_rad2': body_lrr}))
l = body_lrr[:1]
l = body_lrr[0]

tail = genome.part(parts.wings.FlyingBirdTail())
genome.attach(tail, body, coord=(U(0.08, 0.15), 1, 0.5), joint=Joint(rest=(0, 180 * N(1, 0.1), 0)))
Expand Down
2 changes: 1 addition & 1 deletion infinigen/assets/creatures/carnivore.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def tiger_genome():
head_fac = parts.generic_nurbs.NurbsHead(prefix='head_carnivore', tags=['head'], var=0.5)
head = genome.part(head_fac)

headl = head_fac.params['length']
headl = head_fac.params['length'][0]
head_length_rad1_rad2 = np.array((headl, 0.20, 0.18)) * N(1, 0.1, 3)

jaw_pct = np.array((0.7, 0.55, 0.5))
Expand Down
11 changes: 6 additions & 5 deletions infinigen/assets/creatures/parts/generic_nurbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
from infinigen.core.util.logging import Suppress
from infinigen.assets.utils.tag import tag_object, tag_nodegroup

NURBS_BASE_PATH = Path('infinigen/assets/creatures/parts/nurbs_data/')
load_nurbs = lambda p: np.load(p)[..., :3] # strip W coordinate if present
ALL_NURBS = {p.stem: load_nurbs(p) for p in NURBS_BASE_PATH.iterdir()}
NURBS_BASE_PATH = Path(__file__).parent/'nurbs_data'
NURBS_KEYS = [p.stem for p in NURBS_BASE_PATH.iterdir()]
def load_nurbs(name:str):
return np.load(NURBS_BASE_PATH/(name + '.npy'))[..., :3]

def decompose_nurbs_handles(handles):

Expand Down Expand Up @@ -92,13 +93,13 @@ def sample_params(self, select=None):

N = lambda u, v, d=1: np.random.normal(u, np.array(v) * self.var, d)

target_keys = [k for k in ALL_NURBS if self.prefix is None or k.startswith(self.prefix)]
target_keys = [k for k in NURBS_KEYS if self.prefix is None or k.startswith(self.prefix)]
weights = part_util.random_convex_coord(target_keys, select=select, temp=self.temperature)
if self.exps is not None:
for k, exp in self.exps.items():
weights[k] = weights[k] ** exp

handles = sum(w * ALL_NURBS[k] for k, w in weights.items())
handles = sum(w * load_nurbs(k) for k, w in weights.items())
decomp = decompose_nurbs_handles(handles)

sz = N(1, 0.1)
Expand Down
8 changes: 4 additions & 4 deletions infinigen/assets/creatures/util/genome.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ class Joint:
stretch: float = 0

def __post_init__(self):
self.rest = np.array(self.rest, dtype=np.float)
self.rest = np.array(self.rest, dtype=float)
assert self.rest.shape == (3,), self.rest

if self.pose is not None:
self.pose = np.array(self.pose, dtype=np.float)
self.pose = np.array(self.pose, dtype=float)
assert self.pose.shape == (3,), self.pose

if self.bounds is not None:
self.bounds = np.array(self.bounds, dtype=np.float)
self.bounds = np.array(self.bounds, dtype=float)


@dataclass
Expand All @@ -61,7 +61,7 @@ class Attachment:
smooth_rad: float = 0.0

def __post_init__(self):
self.coord = np.array(self.coord, dtype=np.float)
self.coord = np.array(self.coord, dtype=float)


@dataclass
Expand Down
5 changes: 5 additions & 0 deletions infinigen/assets/fluid/fluid.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@

from infinigen.core.util import blender as butil

try:
bpy.ops.flip_fluid_operators.complete_installation()
except Exception as e:
logging.warning(f'Could not complete flip fluids installation {e}')

# find next available number for fluid cache folder
def find_available_cache(cache_folder):
Path(cache_folder).mkdir(parents=True, exist_ok=True)
Expand Down
4 changes: 3 additions & 1 deletion infinigen/assets/materials/grass_blade_texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@
((0.1329, 0.1812, 0.0395, 1.0), 0.9756),
((0.1195, 0.1651, 0.0319, 1.0), 1.0)]

pallettes = np.array([pallete1, pallete2, pallete3, pallete4, pallete5], dtype=object)

def shader_grass_texture_original(nw: NodeWrangler):
# Code generated using version 2.4.3 of the node_transpiler

Expand Down Expand Up @@ -195,7 +197,7 @@ def shader_grass_texture_original(nw: NodeWrangler):
map_range_1 = nw.new_node(Nodes.MapRange, input_kwargs={0: uniform(), 3: object_info.outputs["Random"], 4: mix_1})
colorramp = nw.new_node(Nodes.ColorRamp, input_kwargs={'Fac': map_range_1.outputs["Result"]})

pallete = np.random.choice([pallete1, pallete2, pallete3, pallete4, pallete5])
pallete = np.random.choice(pallettes)
np.random.shuffle(pallete)
pallete = pallete[:np.random.randint(4, len(pallete))]
for _ in range(len(pallete)-2):
Expand Down
2 changes: 1 addition & 1 deletion infinigen/assets/materials/simple_greenery.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

# Authors: Alexander Raistrick


import bpy
import mathutils
from numpy.random import uniform as U, normal as N, 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
Expand Down
Loading

0 comments on commit cba91ca

Please sign in to comment.