Skip to content

Commit

Permalink
Merge pull request #320 from princeton-vl/develop
Browse files Browse the repository at this point in the history
Bugfix v1.10.1
  • Loading branch information
araistrick authored Nov 1, 2024
2 parents 98295c7 + 525c473 commit 4a7dc1a
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 75 deletions.
6 changes: 5 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,8 @@ v1.10.0
- Add config for multiview cameras surrounding a point of interest
- Add MaterialSegmentation output pass
- Add passthrough mode to direct manage_jobs stdout directly to terminal
- Add "copyfile:destination" upload mode
- Add "copyfile:destination" upload mode

v1.10.1
- Fix missing validity checks for camera-rig cameras which are not the 0th index
- Fix missing seat in dining chair
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.10.0"
__version__ = "1.10.1"


def repo_root():
Expand Down
17 changes: 5 additions & 12 deletions infinigen/assets/objects/seating/chairs/chair.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,7 @@ def make_seat(self):
np.array(
[
0,
-self.seat_back,
-self.seat_mid_x,
-1,
0,
0.1,
1,
self.seat_mid_x,
self.seat_back,
Expand All @@ -216,17 +213,13 @@ def make_seat(self):
/ 2
)
y_anchors = (
np.array(
[0, 0, -self.seat_mid, -1, -self.seat_front, -1, -self.seat_mid, 0, 0]
)
np.array([-self.seat_front, -self.seat_front, -1, -self.seat_mid, 0, 0])
* self.size
)
z_anchors = (
np.array([0, 0, self.seat_mid_z, 0, 0, 0, self.seat_mid_z, 0, 0])
* self.thickness
)
vector_locations = [1, 7] if self.is_seat_round else [1, 3, 5, 7]
z_anchors = np.array([0, 0, 0, self.seat_mid_z, 0, 0]) * self.thickness
vector_locations = [4] if self.is_seat_round else [2, 4]
obj = bezier_curve((x_anchors, y_anchors, z_anchors), vector_locations)
butil.modify_mesh(obj, "MIRROR")
with butil.ViewportMode(obj, "EDIT"):
bpy.ops.mesh.select_all(action="SELECT")
bpy.ops.mesh.fill_grid(use_interp_simple=True)
Expand Down
5 changes: 5 additions & 0 deletions infinigen/assets/utils/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ def curve2mesh(obj):
length = np.linalg.norm(cos[:-1] - cos[1:], axis=-1)
min_length = 5e-3
with butil.ViewportMode(obj, "EDIT"):
for i in range(len(points)):
if points[i].handle_left_type == "FREE":
points[i].handle_left_type = "ALIGNED"
if points[i].handle_right_type == "FREE":
points[i].handle_right_type = "ALIGNED"
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)
Expand Down
126 changes: 74 additions & 52 deletions infinigen/core/placement/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import typing
from copy import deepcopy
from dataclasses import dataclass
from functools import partial
from itertools import chain
from pathlib import Path

Expand All @@ -34,6 +33,7 @@
from infinigen.core.util.logging import Timer
from infinigen.core.util.organization import SelectionCriterions
from infinigen.core.util.random import random_general
from infinigen.terrain.core import Terrain
from infinigen.tools.suffixes import get_suffix

from . import animation_policy
Expand Down Expand Up @@ -190,7 +190,11 @@ def set_active_camera(camera: bpy.types.Object):


def terrain_camera_query(
cam, scene_bvh, terrain_tags_queries, vertexwise_min_dist, min_dist=0
cam: bpy.types.Object,
scene_bvh: BVHTree,
terrain_tags_queries,
vertexwise_min_dist,
min_dist=0,
):
dists = []
sensor_coords, pix_it = get_sensor_coords(cam, sparse=True)
Expand Down Expand Up @@ -222,10 +226,13 @@ class CameraProposal:
rot: np.array
focal_length: float

def apply(self, cam):
cam.location = self.loc
cam.rotation_euler = self.rot
cam.data.lens = self.focal_length
def apply(self, cam_rig):
cam_rig.location = self.loc
cam_rig.rotation_euler = self.rot

if self.focal_length is not None:
for cam in cam_rig.children:
cam.data.lens = self.focal_length


@gin.configurable
Expand Down Expand Up @@ -310,9 +317,9 @@ def location_sample():

@gin.configurable
def keep_cam_pose_proposal(
cam,
terrain,
scene_bvh,
cam: bpy.types.Object,
terrain: Terrain,
scene_bvh: BVHTree,
placeholders_kd,
camera_selection_answers,
vertexwise_min_dist,
Expand All @@ -323,11 +330,9 @@ def keep_cam_pose_proposal(
):
if terrain is not None: # TODO refactor
terrain_sdf = terrain.compute_camera_space_sdf(
np.array(cam.location).reshape((1, 3))
np.array(cam.matrix_world.translation).reshape((1, 3))
)

if not cam.type == "CAMERA":
cam = cam.children[0]
if not cam.type == "CAMERA":
raise ValueError(f"{cam.name=} had {cam.type=}")

Expand Down Expand Up @@ -359,7 +364,9 @@ def keep_cam_pose_proposal(
return None

if terrain is not None and terrain_sdf <= 0:
logger.debug(f"keep_cam_pose_proposal rejects {terrain_sdf=}")
logger.debug(
f"keep_cam_pose_proposal rejects {terrain_sdf=} for {cam.matrix_world.translation=}"
)
return None

if rparams := camera_selection_ratio:
Expand Down Expand Up @@ -415,10 +422,10 @@ def __call__(self, camera_rig, frame_curr, retry_pct, bvh):

@gin.configurable
def compute_base_views(
cam,
n_views,
camera_rig: bpy.types.Object,
n_views: int,
terrain,
scene_bvh,
scene_bvh: BVHTree,
location_sample: typing.Callable,
center_coordinate=None,
radius=None,
Expand Down Expand Up @@ -455,23 +462,31 @@ def compute_base_views(
)
continue

props.apply(cam)
props.apply(camera_rig)

all_scores = []
for cam in camera_rig.children:
score = keep_cam_pose_proposal(
cam,
terrain,
scene_bvh,
placeholders_kd,
camera_selection_answers=camera_selection_answers,
vertexwise_min_dist=vertexwise_min_dist,
camera_selection_ratio=camera_selection_ratio,
)
all_scores.append(score)

criterion = keep_cam_pose_proposal(
cam,
terrain,
scene_bvh,
placeholders_kd,
camera_selection_answers=camera_selection_answers,
vertexwise_min_dist=vertexwise_min_dist,
camera_selection_ratio=camera_selection_ratio,
)
if any(score is None for score in all_scores):
criterion = None
else:
criterion = np.mean(all_scores)

if visualize:
criterion_str = f"{criterion:.2f}" if criterion is not None else "None"
marker = butil.spawn_empty(f"attempt_{it}_{criterion_str}")
marker.location = cam.location
marker.rotation_euler = cam.rotation_euler
marker.location = camera_rig.location
marker.rotation_euler = camera_rig.rotation_euler

if criterion is None:
logger.debug(f"{it=} {criterion=}")
Expand Down Expand Up @@ -515,6 +530,7 @@ def build_bvh_and_attrs(objs, tags_queries):
obj.select_set(True)
bpy.ops.object.join()
obj = bpy.context.view_layer.objects.active

bvh = BVHTree.FromObject(obj, bpy.context.evaluated_depsgraph_get())
from infinigen.terrain.utils import Mesh

Expand Down Expand Up @@ -642,7 +658,6 @@ def configure_cameras(
mvs_radius=("uniform", 12, 18),
):
bpy.context.view_layer.update()
dummy_camera = spawn_camera()

if init_bounding_box is not None:

Expand Down Expand Up @@ -688,18 +703,18 @@ def contain_keywords(name, keywords):
else:
center_coordinate = None

base_views = compute_base_views(
dummy_camera,
n_views=len(cam_rigs),
location_sample=location_sample,
center_coordinate=center_coordinate,
radius=mvs_radius,
bbox=init_bounding_box,
**scene_preprocessed,
)
for cam_rig in cam_rigs:
views = compute_base_views(
cam_rig,
n_views=1,
location_sample=location_sample,
center_coordinate=center_coordinate,
radius=mvs_radius,
bbox=init_bounding_box,
**scene_preprocessed,
)

for view, cam_rig in zip(base_views, cam_rigs):
score, props, focus_dist = view
score, props, focus_dist = views[0]
cam_rig.location = props.loc
cam_rig.rotation_euler = props.rot

Expand All @@ -712,8 +727,6 @@ def contain_keywords(name, keywords):
continue
cam.data.dof.focus_distance = focus_dist

butil.delete(dummy_camera)


@gin.configurable
def animate_cameras(
Expand All @@ -731,15 +744,24 @@ def animate_cameras(
animation_ratio[k] = scene_preprocessed["camera_selection_ratio"][k]
animation_answers[k] = scene_preprocessed["camera_selection_answers"][k]

anim_valid_pose_func = partial(
keep_cam_pose_proposal,
placeholders_kd=scene_preprocessed["placeholders_kd"],
scene_bvh=scene_preprocessed["scene_bvh"],
terrain=scene_preprocessed["terrain"],
vertexwise_min_dist=scene_preprocessed["vertexwise_min_dist"],
camera_selection_answers=animation_answers,
camera_selection_ratio=animation_ratio,
)
def anim_valid_camrig_pose_func(cam_rig: bpy.types.Object):
assert len(cam_rig.children) > 0

for cam in cam_rig.children:
score = keep_cam_pose_proposal(
cam,
placeholders_kd=scene_preprocessed["placeholders_kd"],
scene_bvh=scene_preprocessed["scene_bvh"],
terrain=scene_preprocessed["terrain"],
vertexwise_min_dist=scene_preprocessed["vertexwise_min_dist"],
camera_selection_answers=animation_answers,
camera_selection_ratio=animation_ratio,
)

if score is None:
return False

return True

for cam_rig in cam_rigs:
if policy_registry is None:
Expand All @@ -758,7 +780,7 @@ def animate_cameras(
cam_rig,
scene_preprocessed["scene_bvh"],
policy_func=policy,
validate_pose_func=anim_valid_pose_func,
validate_pose_func=anim_valid_camrig_pose_func,
verbose=True,
fatal=True,
bounding_box=bounding_box,
Expand Down
1 change: 1 addition & 0 deletions infinigen_examples/generate_indoors.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ def main(args):
parser.add_argument("-d", "--debug", type=str, nargs="*", default=None)

args = init.parse_args_blender(parser)

logging.getLogger("infinigen").setLevel(logging.INFO)
logging.getLogger("infinigen.core.nodes.node_wrangler").setLevel(logging.CRITICAL)

Expand Down
20 changes: 11 additions & 9 deletions infinigen_examples/generate_nature.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,16 +1023,18 @@ def main(args):
"e.g. --gin_param module_1.a=2 module_2.b=3",
)
parser.add_argument("--task_uniqname", type=str, default=None)
parser.add_argument(
"-d",
"--debug",
action="store_const",
dest="loglevel",
const=logging.DEBUG,
default=logging.INFO,
)
parser.add_argument("-d", "--debug", type=str, nargs="*", default=None)

args = init.parse_args_blender(parser)
logging.getLogger("infinigen").setLevel(args.loglevel)

logging.getLogger("infinigen").setLevel(logging.INFO)
logging.getLogger("infinigen.core.nodes.node_wrangler").setLevel(logging.CRITICAL)

if args.debug is not None:
for name in logging.root.manager.loggerDict:
if not name.startswith("infinigen"):
continue
if len(args.debug) == 0 or any(name.endswith(x) for x in args.debug):
logging.getLogger(name).setLevel(logging.DEBUG)

main(args)

0 comments on commit 4a7dc1a

Please sign in to comment.