Skip to content

Commit

Permalink
Merge pull request #307 from princeton-vl/develop
Browse files Browse the repository at this point in the history
v1.9.1 bugfix
  • Loading branch information
pvl-bot authored Oct 18, 2024
2 parents 7105e2c + 3e201d4 commit 9c3097a
Show file tree
Hide file tree
Showing 34 changed files with 169 additions and 147 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ blender
blender.tar.xz
Blender.app

.nfs*

*.c

.coverage
Expand Down
11 changes: 10 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,13 @@ v1.8.3
v1.9.0
- Add CoPlanar indoor constraint, fix backwards tvs/monitors/sinks
- Fix empty scene / null objects selected during export
- Add full system visual check / integration script
- Add full system visual check / integration script

v1.9.1
- Reduce excessive polycount in bottles and tableware objects
- Fix alignment of windows
- Fix wall materials not being deterministic w.r.t random seed
- Fix gin configs not correctly passed to slurm jobs in generate_individual_assets
- Fix integration test image titles
- Fix integration test asset image alignment
- Make multistory houses disabled by default
2 changes: 1 addition & 1 deletion infinigen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging
from pathlib import Path

__version__ = "1.9.0"
__version__ = "1.9.1"


def repo_root():
Expand Down
4 changes: 2 additions & 2 deletions infinigen/assets/objects/bathroom/toilet.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def make_tube(self, lower, upper):
bpy.ops.mesh.select_mode(type="EDGE")
bpy.ops.mesh.select_all(action="SELECT")
bpy.ops.mesh.bridge_edge_loops(
number_cuts=np.random.randint(12, 16),
number_cuts=64,
profile_shape_factor=uniform(0.1, 0.2),
interpolation="SURFACE",
)
Expand Down Expand Up @@ -242,7 +242,7 @@ def make_stand(self, obj, bottom):
bpy.ops.mesh.select_mode(type="EDGE")
bpy.ops.mesh.select_all(action="SELECT")
bpy.ops.mesh.bridge_edge_loops(
number_cuts=np.random.randint(12, 16),
number_cuts=64,
profile_shape_factor=uniform(0.0, 0.15),
)
return stand
Expand Down
2 changes: 2 additions & 0 deletions infinigen/assets/objects/monocot/banana.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from infinigen.assets.utils.draw import bezier_curve, leaf
from infinigen.assets.utils.nodegroup import geo_radius
from infinigen.assets.utils.object import join_objects, origin2lowest
from infinigen.assets.utils.shapes import point_normal_up
from infinigen.core import surface
from infinigen.core.tagging import tag_object
from infinigen.core.util import blender as butil
Expand Down Expand Up @@ -134,6 +135,7 @@ def __init__(self, factory_seed, coarse=False):
self.max_y_angle = uniform(-np.pi * 0.05, 0)

def displace_veins(self, obj):
point_normal_up(obj)
vg = obj.vertex_groups.new(name="distance")
x, y, z = read_co(obj).T
branch = np.cos(
Expand Down
2 changes: 1 addition & 1 deletion infinigen/assets/objects/monocot/veratrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def build_leaf(self, face_size):
[0, 2, 4],
dupli=True,
loop=True,
resolution=np.random.randint(3, 5),
rotation_resolution=np.random.randint(3, 5),
axis=(1, 0, 0),
)
butil.modify_mesh(obj, "WELD", merge_threshold=face_size / 2)
Expand Down
2 changes: 1 addition & 1 deletion infinigen/assets/objects/mushroom/cap.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def create_asset(self, face_size, **params) -> bpy.types.Object:
gill_config["vector_locations"],
dupli=True,
loop=True,
resolution=np.random.randint(8, 20),
rotation_resolution=np.random.randint(8, 20),
)
subsurface2face_size(gill, face_size)
assign_material(gill, self.material)
Expand Down
8 changes: 3 additions & 5 deletions infinigen/assets/objects/seating/chairs/chair.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def make_seat(self):
* self.thickness
)
vector_locations = [1, 7] if self.is_seat_round else [1, 3, 5, 7]
obj = bezier_curve((x_anchors, y_anchors, z_anchors), vector_locations, 8)
obj = bezier_curve((x_anchors, y_anchors, z_anchors), vector_locations)
with butil.ViewportMode(obj, "EDIT"):
bpy.ops.mesh.select_all(action="SELECT")
bpy.ops.mesh.fill_grid(use_interp_simple=True)
Expand Down Expand Up @@ -260,9 +260,7 @@ def make_limb(self, leg_ends, leg_starts):
case _:
axes = None
scale = None
limb = align_bezier(
np.stack([leg_start, leg_end], -1), axes, scale, resolution=64
)
limb = align_bezier(np.stack([leg_start, leg_end], -1), axes, scale)
limb.location = (
np.array(
[
Expand Down Expand Up @@ -335,7 +333,7 @@ def make_back_decors(self, backs, finalize=True):
& (center[:, -1] <= z_max * self.back_height),
)
bpy.ops.mesh.bridge_edge_loops(
number_cuts=32,
number_cuts=64,
interpolation="LINEAR",
smoothness=smoothness,
profile_shape_factor=profile_shape_factor,
Expand Down
1 change: 0 additions & 1 deletion infinigen/assets/objects/tableware/bottle.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ def make_bottle(self):
z_anchors = np.array(self.z_anchors) * self.z_length
anchors = x_anchors, 0, z_anchors
obj = spin(anchors, np.nonzero(self.is_vector)[0])
subsurf(obj, 1, True)
subsurf(obj, 1)
if self.bottle_width > 0:
butil.modify_mesh(obj, "SOLIDIFY", thickness=self.bottle_width)
Expand Down
9 changes: 3 additions & 6 deletions infinigen/assets/objects/tableware/bowl.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def __init__(self, factory_seed, coarse=False):
self.x_bottom = uniform(0.2, 0.3) * self.x_end
self.x_mid = uniform(0.8, 0.95) * self.x_end
self.has_guard = False
self.thickness = uniform(0.01, 0.03)
self.has_inside = uniform(0, 1) < 0.5
self.scale = log_uniform(0.15, 0.4)
self.thickness = uniform(0.01, 0.03) * self.scale
self.edge_wear = None

def create_placeholder(self, **kwargs) -> bpy.types.Object:
Expand All @@ -46,15 +46,12 @@ def create_asset(self, **params) -> bpy.types.Object:
self.x_end,
)
z_anchors = 0, 0, 0, self.z_bottom, self.z_length / 2, self.z_length
anchors = x_anchors, np.zeros_like(x_anchors), z_anchors
obj = spin(anchors, [2, 3], 16, 64)
subsurf(obj, 1)
anchors = np.array(x_anchors) * self.scale, 0, np.array(z_anchors) * self.scale
obj = spin(anchors, [2, 3])
self.solidify_with_inside(obj, self.thickness)
butil.modify_mesh(
obj, "BEVEL", width=self.thickness / 2, segments=np.random.randint(2, 5)
)
obj.scale = [self.scale] * 3
butil.apply_transform(obj)
subsurf(obj, 1)
set_shade_smooth(obj)
return obj
8 changes: 5 additions & 3 deletions infinigen/assets/objects/tableware/cup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ def create_asset(self, **params) -> bpy.types.Object:
self.x_end,
)
z_anchors = 0, 0, self.depth * 0.5, self.depth
anchors = x_anchors, np.zeros_like(x_anchors), z_anchors
obj = spin(anchors, [1], 16)
subsurf(obj, 1)
anchors = np.array(x_anchors) * self.scale, 0, np.array(z_anchors) * self.scale
obj = spin(anchors, [1])
obj.scale = [1 / self.scale] * 3
butil.apply_transform(obj, True)
butil.modify_mesh(
obj,
"BEVEL",
Expand All @@ -95,6 +96,7 @@ def create_asset(self, **params) -> bpy.types.Object:
else:
wrap = None
self.solidify_with_inside(obj, self.thickness)
subsurf(obj, 2)
handle_location = (
x_anchors[-2] * (1 - self.handle_location)
+ x_anchors[-1] * self.handle_location,
Expand Down
2 changes: 1 addition & 1 deletion infinigen/assets/objects/tableware/jar.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def create_asset(self, **params) -> bpy.types.Object:
bpy.ops.mesh.extrude_edges_move(
TRANSFORM_OT_translate={"value": (0, 0, self.z_cap * self.z_length)}
)
subsurf(obj, 1)
subsurf(obj, 2)
butil.modify_mesh(obj, "SOLIDIFY", thickness=self.thickness)

cap = new_cylinder(vertices=64)
Expand Down
1 change: 1 addition & 0 deletions infinigen/assets/objects/tableware/knife.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def selection(nw, x):
selection = self.make_double_sided(selection)
self.add_guard(obj, selection)
subsurf(obj, 1)
subsurf(obj, 1, True)
obj.scale = [self.scale] * 3
butil.apply_transform(obj)
return obj
Expand Down
10 changes: 4 additions & 6 deletions infinigen/assets/objects/tableware/plate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,19 @@ def __init__(self, factory_seed, coarse=False):
self.z_mid = uniform(0.3, 0.8) * self.z_length
self.has_guard = False
self.pre_level = 1
self.thickness = uniform(0.01, 0.03)
self.has_inside = uniform(0, 1) < 0.2
self.scale = log_uniform(0.2, 0.4)
self.thickness = uniform(0.01, 0.03) * self.scale
self.scratch = self.edge_wear = None

def create_asset(self, **params) -> bpy.types.Object:
x_anchors = 0, self.x_mid, self.x_mid, self.x_end
z_anchors = 0, 0, self.z_mid, self.z_length
anchors = x_anchors, np.zeros_like(x_anchors), z_anchors
obj = spin(anchors, [1, 2], 4, 16)
anchors = np.array(x_anchors) * self.scale, 0, np.array(z_anchors) * self.scale
obj = spin(anchors, [1, 2])
butil.modify_mesh(
obj, "SUBSURF", render_levels=self.pre_level, levels=self.pre_level
)
self.solidify_with_inside(obj, self.thickness)
subsurf(obj, 2)
obj.scale = [self.scale] * 3
butil.apply_transform(obj)
subsurf(obj, 1)
return obj
5 changes: 1 addition & 4 deletions infinigen/assets/objects/tableware/wineglass.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from infinigen.assets.materials import glass
from infinigen.assets.objects.tableware.base import TablewareFactory
from infinigen.assets.utils.decorate import subsurf
from infinigen.assets.utils.draw import spin
from infinigen.core.util import blender as butil
from infinigen.core.util.math import FixedSeed
Expand Down Expand Up @@ -43,10 +42,8 @@ def create_asset(self, **params) -> bpy.types.Object:
)
z_anchors = 0, z_bottom / 2, z_bottom, self.z_cup, self.z_mid, self.z_length
anchors = x_anchors, np.zeros_like(x_anchors), z_anchors
obj = spin(anchors, [0, 1, 2, 3], 4, 16)
subsurf(obj, 2)
obj = spin(anchors, [0, 1, 2, 3])
butil.modify_mesh(obj, "SOLIDIFY", thickness=self.thickness)
subsurf(obj, 1)
obj.scale = [self.scale] * 3
butil.apply_transform(obj)

Expand Down
53 changes: 35 additions & 18 deletions infinigen/assets/utils/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def surface_from_func(fn, div_x=16, div_y=16, size_x=2, size_y=2):
return mesh


def bezier_curve(anchors, vector_locations=(), resolution=64, to_mesh=True):
def bezier_curve(anchors, vector_locations=(), resolution=None, to_mesh=True):
n = [len(r) for r in anchors if isinstance(r, Sized)][0]
anchors = np.array(
[
Expand All @@ -98,22 +98,37 @@ def bezier_curve(anchors, vector_locations=(), resolution=64, to_mesh=True):
else:
points[i].handle_left_type = "AUTO"
points[i].handle_right_type = "AUTO"
obj.data.splines[0].resolution_u = resolution
if to_mesh:
return curve2mesh(obj)
return obj
obj.data.splines[0].resolution_u = resolution if resolution is not None else 12
if not to_mesh:
return obj
return curve2mesh(obj)


def curve2mesh(obj):
points = obj.data.splines[0].bezier_points
cos = np.array([p.co for p in points])
length = np.linalg.norm(cos[:-1] - cos[1:], axis=-1)
min_length = 5e-3
with butil.ViewportMode(obj, "EDIT"):
for i in reversed(range(len(points) - 1)):
points = list(obj.data.splines[0].bezier_points)
number_cuts = min(int(length[i] / min_length) - 1, 64)
if number_cuts < 0:
continue
bpy.ops.curve.select_all(action="DESELECT")
points[i].select_control_point = True
points[i + 1].select_control_point = True
bpy.ops.curve.subdivide(number_cuts=number_cuts)
obj.data.splines[0].resolution_u = 1
with butil.SelectObjects(obj):
bpy.ops.object.convert(target="MESH")
obj = bpy.context.active_object
butil.modify_mesh(obj, "WELD", merge_threshold=1e-4)
butil.modify_mesh(obj, "WELD", merge_threshold=1e-3)
return obj


def align_bezier(
anchors, axes=None, scale=None, vector_locations=(), resolution=64, to_mesh=True
anchors, axes=None, scale=None, vector_locations=(), resolution=None, to_mesh=True
):
obj = bezier_curve(anchors, vector_locations, resolution, False)
points = obj.data.splines[0].bezier_points
Expand Down Expand Up @@ -145,9 +160,9 @@ def align_bezier(
* np.linalg.norm(p.handle_right - p.co)
* scale[2 * i + 1]
)
if to_mesh:
return curve2mesh(obj)
return obj
if not to_mesh:
return obj
return curve2mesh(obj)


def remesh_fill(obj, resolution=0.005):
Expand All @@ -168,32 +183,34 @@ def remesh_fill(obj, resolution=0.005):
def spin(
anchors,
vector_locations=(),
subdivision=64,
resolution=None,
rotation_resolution=None,
axis=(0, 0, 1),
loop=False,
dupli=False,
):
obj = bezier_curve(anchors, vector_locations, subdivision)
obj = bezier_curve(anchors, vector_locations, resolution)
co = read_co(obj)
max_radius = np.amax(
mean_radius = np.mean(
np.linalg.norm(
co - (co @ np.array(axis))[:, np.newaxis] * np.array(axis), axis=-1
)
)
if resolution is None:
resolution = min(int(2 * np.pi * max_radius / 0.005), 128)
butil.modify_mesh(obj, "WELD", merge_threshold=1e-4)
if rotation_resolution is None:
rotation_resolution = min(int(2 * np.pi * mean_radius / 5e-3), 128)
butil.modify_mesh(obj, "WELD", merge_threshold=1e-3)
if loop:
with butil.ViewportMode(obj, "EDIT"), butil.Suppress():
bpy.ops.mesh.select_all(action="SELECT")
bpy.ops.mesh.fill()
remesh_fill(obj)
with butil.ViewportMode(obj, "EDIT"), butil.Suppress():
bpy.ops.mesh.select_all(action="SELECT")
bpy.ops.mesh.spin(steps=resolution, angle=np.pi * 2, axis=axis, dupli=dupli)
bpy.ops.mesh.spin(
steps=rotation_resolution, angle=np.pi * 2, axis=axis, dupli=dupli
)
bpy.ops.mesh.select_all(action="SELECT")
bpy.ops.mesh.remove_doubles(threshold=1e-4)
bpy.ops.mesh.remove_doubles(threshold=1e-3)
return obj


Expand Down
2 changes: 1 addition & 1 deletion infinigen/assets/utils/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def obj2polygon(obj):
for p in obj.data.polygons
]
)
return shapely.make_valid(shapely.simplify(p, 1e-6))
return shapely.ops.orient(shapely.make_valid(shapely.simplify(p, 1e-6)))


def buffer(p, distance):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def canonicalize(self, p):
break
if not is_valid_polygon(p):
raise NotImplementedError("Invalid polygon")
return p
return orient(p)
except AttributeError:
raise NotImplementedError("Invalid multi polygon")

Expand Down
6 changes: 4 additions & 2 deletions infinigen/core/constraints/example_solver/room/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,14 @@ def decorate(self, state):
quad_segs = (
1 if corner_func == "sharp" else np.random.randint(4, 7)
)
exterior_ = (
exterior_ = self.constants.canonicalize(
exterior.difference(cutter)
.union(shapely.Point(q).buffer(length, quad_segs=quad_segs))
.buffer(0)
)
new = state[k].polygon.intersection(exterior_).buffer(0)
new = self.constants.canonicalize(
state[k].polygon.intersection(exterior_).buffer(0)
)
if all(
new.buffer(-m + 1e-2).geom_type == "Polygon"
for m in np.linspace(0, 0.75, 4)
Expand Down
4 changes: 2 additions & 2 deletions infinigen/core/constraints/example_solver/room/decorate.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from infinigen.core.surface import write_attr_data
from infinigen.core.util import blender as butil
from infinigen.core.util.blender import deep_clone_obj
from infinigen.core.util.math import int_hash
from infinigen.core.util.math import FixedSeed, int_hash
from infinigen.core.util.random import log_uniform
from infinigen.core.util.random import random_general as rg

Expand Down Expand Up @@ -93,7 +93,7 @@ def split_rooms(rooms_meshed: list[bpy.types.Object]):


def import_material(factory_name):
with gin.unlock_config():
with gin.unlock_config(), FixedSeed(0):
try:
return importlib.import_module(f"infinigen.assets.materials.{factory_name}")
except ImportError:
Expand Down
Loading

0 comments on commit 9c3097a

Please sign in to comment.