Utilities (.util)

Contents

Utilities (.util)#

Code Statistics (.util.codestats)#

compute#

The model is already indexed into topological order by setup.py.

  • choice_probs[choice_id] gives branch probabilities for one discrete choice

  • choice_branches[choice_id] gives the branch ids for that choice

  • branch_vars[branch_id] is a bitmask of variables activated by that branch

  • var_kind[var_id] is “choice” or “continuous”

infinigen2.util.codestats.compute.shannon_entropy_bits(probabilities) float[source]#
Parameters:

probabilities

infinigen2.util.codestats.compute.cyclomatic_complexity(choice_probs) int[source]#

Cyclomatic complexity where only control flow is pf.control.hcoice Return 1 + sum(branch_count - 1) over discrete choices.

Parameters:

choice_probs (dict[int, list[float]])

infinigen2.util.codestats.compute.solve_tree(indexed_model) dict[source]#

Tree-style recursion.

child subtrees inside one branch are treated as disjoint and summed independently.

Parameters:

indexed_model (dict)

infinigen2.util.codestats.compute.solve_dp(indexed_model) dict[source]#

Exact DP

Parameters:

indexed_model (dict)

setup#

Compute-graph extraction and stat summaries

Representation after setup:

  • choice_probs[choice_id] gives branch probabilities for one discrete choice

  • choice_branches[choice_id] gives the branch ids for that choice

  • branch_vars[branch_id] gives the variables activated by that branch

  • var_kind[var_id] is “choice” or “continuous”

This code handles: - extracting this model from a compute graph - topologically reindexing variables so the solver can use bitmasks - calling either the plain recursion or the memoized DP

infinigen2.util.codestats.setup.build_model_from_compute_graph(graph) dict[source]#

Extract the compact branch-first model from a traced compute graph.

Parameters:

graph (ComputeGraph)

infinigen2.util.codestats.setup.build_indexed_model(model) dict[source]#

Reindex variables into topological order and convert branches to masks.

Parameters:

model (dict)

infinigen2.util.codestats.setup.compute_stats(...) dict[source]#

Extract the compact model and run either the tree or DP solver.

Parameters:

Module contents#

infinigen2.util.codestats.build_indexed_model(model) dict[source]#

Reindex variables into topological order and convert branches to masks.

Parameters:

model (dict)

infinigen2.util.codestats.build_model_from_compute_graph(graph) dict[source]#

Extract the compact branch-first model from a traced compute graph.

Parameters:

graph (ComputeGraph)

infinigen2.util.codestats.compute_stats(...) dict[source]#

Extract the compact model and run either the tree or DP solver.

Parameters:
infinigen2.util.codestats.cyclomatic_complexity(choice_probs) int[source]#

Cyclomatic complexity where only control flow is pf.control.hcoice Return 1 + sum(branch_count - 1) over discrete choices.

Parameters:

choice_probs (dict[int, list[float]])

infinigen2.util.codestats.solve_dp(indexed_model) dict[source]#

Exact DP

Parameters:

indexed_model (dict)

infinigen2.util.codestats.solve_tree(indexed_model) dict[source]#

Tree-style recursion.

child subtrees inside one branch are treated as disjoint and summed independently.

Parameters:

indexed_model (dict)

camera_projection#

infinigen2.util.camera_projection.adjust_camera_sensor(camera)[source]#
Parameters:

camera (CameraObject)

infinigen2.util.camera_projection.bpy_resolution() tuple[int, int][source]#
infinigen2.util.camera_projection.get_calibration_matrix_K_from_blender(camera) ndarray[source]#

Build intrinsic camera parameters from Blender camera data

Based on https://blender.stackexchange.com/questions/15102/what-is-blenders-camera-projection-matrix-model

Parameters:

camera (CameraObject) -- Blender camera object

Returns:

3x3 intrinsic camera matrix

Return type:

K

infinigen2.util.camera_projection.get_3x4_RT_matrix_from_blender(camera) ndarray[source]#

Get camera rotation and translation matrices from Blender.

We return a camera matrix in the usual computer vision convention: +x is horizontal, +y is down, +z is forward.

This is different than blender’s camera typical convention, which is +x is horizontal, +y is up, -z is forward.

Parameters:

camera (CameraObject) -- Blender camera object

Returns:

3x4 camera matrix

Return type:

RT

infinigen2.util.camera_projection.get_3x4_P_matrix_from_blender(cam)[source]#
Parameters:

cam

infinigen2.util.camera_projection.project_points(camera, points_N3) ndarray[source]#

Project points onto the camera image plane.

Parameters:
infinigen2.util.camera_projection.is_projection_within_image(projected, resolution=None) ndarray[source]#

Check if the projection is within the image.

Parameters:
infinigen2.util.camera_projection.camera_depth_raycast(cam, colliders, meshgridcoords) ndarray[source]#
Parameters:
infinigen2.util.camera_projection.get_camera_parameters(camera, frame=None, use_dof=False) dict[source]#
Parameters:
  • camera (CameraObject)

  • frame (int | None) -- (default: None)

  • use_dof (bool | None) -- (default: False)

curve#

class infinigen2.util.curve.CurveToMeshWithUvResult(mesh, vector)[source]#

Bases: NamedTuple

mesh: pf.ProcNode[pf.MeshObject]#
vector: pf.ProcNode[pf.Vector]#
class infinigen2.util.curve.FilletMaskResult(...)[source]#

Bases: NamedTuple

curve: pf.ProcNode[CurveObject]#
is_fillet_point: pf.ProcNode[bool]#
is_flat_point: pf.ProcNode[bool]#
orig_point_idx: pf.ProcNode[int]#
infinigen2.util.curve.curve_to_mesh_with_uv(
curve,
profile,
fill_caps=False,
) CurveToMeshWithUvResult[source]#
Parameters:
infinigen2.util.curve.curve_to_noncyclic(input) pf.ProcNode[CurveObject][source]#
Parameters:

input (pf.ProcNode[CurveObject])

infinigen2.util.curve.fillet_mask(...) FilletMaskResult[source]#
Parameters:

errors#

exception infinigen2.util.errors.RejectedScene[source]#

Bases: Exception

external_assets#

infinigen2.util.external_assets.distribution_from_asset_glob(folder)[source]#
Parameters:

folder (Path)

infinigen2.util.external_assets.pregenerated_asset_rand(relative_glob) Callable[[pf.RNG], pf.MeshObject | None][source]#
Parameters:

relative_glob (str)

hardware_info#

infinigen2.util.hardware_info.get_hardware_info() dict[source]#

import_utils#

Utilities for dynamic imports and finding generator functions.

infinigen2.util.import_utils.module_path()[source]#

instance#

infinigen2.util.instance.instance(...) pf.ProcNode[source]#
Parameters:
infinigen2.util.instance.instanced_objects(...) list[pf.MeshObject][source]#
Parameters:

math#

infinigen2.util.math.offset_spacing(...) pf.ProcNode[float][source]#
Parameters:

mesh#

class infinigen2.util.mesh.CubeWithVertexIndicesResult(...)[source]#

Bases: NamedTuple

mesh: pf.ProcNode[pf.MeshObject]#
index_x: pf.ProcNode[int]#
index_y: pf.ProcNode[int]#
index_z: pf.ProcNode[int]#
class infinigen2.util.mesh.ExtrudeSeamlessResult(mesh, top, side)[source]#

Bases: NamedTuple

mesh: pf.ProcNode[pf.MeshObject]#
top: pf.ProcNode[bool]#
side: pf.ProcNode[bool]#
class infinigen2.util.mesh.WallCutoutResult(wall, sill, lightblocker)[source]#

Bases: NamedTuple

wall: pf.ProcNode[pf.MeshObject]#
sill: pf.ProcNode[pf.MeshObject]#
lightblocker: pf.ProcNode[pf.MeshObject]#
infinigen2.util.mesh.corner_box(...) CubeWithVertexIndicesResult[source]#
Parameters:
infinigen2.util.mesh.crease_sharp(
mesh,
threshold_degrees,
) pf.ProcNode[pf.MeshObject][source]#
Parameters:
infinigen2.util.mesh.extrude_mesh_seamless_uvs(...) ExtrudeSeamlessResult[source]#

Extrude faces and continue source UVs onto the new side faces seamlessly.

Each side corner gets uv0 plus a perpendicular offset proportional to its extrusion depth. The boundary edge driving that offset is found per corner via its own next-corner edge (the one with both ends on the depth-0 ring), then broadcast across the side face with accumulate_field.

Parameters:
infinigen2.util.mesh.grid_from_corners(...) pf.ProcNode[source]#
Parameters:
infinigen2.util.mesh.uv_winding_sign(obj) float[source]#

Sign of the first face’s UV winding (+1/-1), for un-mirrored continuation.

Parameters:

obj (pf.MeshObject)

infinigen2.util.mesh.wall_cutout_split(...) WallCutoutResult[source]#

Split a flat cutout_sel-tagged surface into holed wall, sill tunnels, and lightblocker backing.

The mouth of each hole gets a chamfer-wide angled lip, kept on the wall (it reads as a bevel of the wall surface around the opening); the sill is just the deep reveal tunnel. The footprint must be pre-expanded by chamfer (see face_expand_margin) so the inner opening lands at the originally-intended size.

Parameters:

render_metadata#

infinigen2.util.render_metadata.time_step(times, name) Iterator[None][source]#
Parameters:
infinigen2.util.render_metadata.write_render_metadata(...) dict[source]#
Parameters:

scene_cleanup#

infinigen2.util.scene_cleanup.cleanup_except(keep) list[str][source]#

Delete every bpy.data.objects entry not in keep.

Placement helpers (e.g. repeat_attempts) leave failed-placement objects in the scene. They are excluded from the returned all_objects lists but still live in the blend and would otherwise be rendered. Pass the union of objects/cameras/lights you want kept and this removes the rest.

Parameters:

keep (Iterable[Object])

Module contents#