Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
pvl-bot committed Oct 8, 2024
2 parents 85db7b5 + b6a65b8 commit 7105e2c
Show file tree
Hide file tree
Showing 34 changed files with 1,502 additions and 486 deletions.
8 changes: 8 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,11 @@ v1.8.2
- Add smbpy du and df commands
- Fix fineterrain not included in export for optimize_diskusage=True
- Update mesher_backend config name & default commands

v1.8.3
- Fix landlab import error message, add no_landlab.gin config

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
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.8.3"
__version__ = "1.9.0"


def repo_root():
Expand Down
7 changes: 0 additions & 7 deletions infinigen/assets/materials/art.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ def shader_art_composite(nw: NodeWrangler, **kwargs):

return shader_art_composite

def make_sphere(self):
return make_sphere()


class ArtRug(ArtComposite):
@property
Expand All @@ -98,7 +95,3 @@ def apply(obj, selection=None, bbox=(0, 1, 0, 1), scale=None, **kwargs):
if scale is not None:
write_uv(obj, read_uv(obj) * scale)
Art(np.random.randint(1e5)).apply(obj, selection, bbox, **kwargs)


def make_sphere():
return text.make_sphere()
1 change: 1 addition & 0 deletions infinigen/core/constraints/constraint_language/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from .relations import (
AnyRelation,
ConnectorType,
CoPlanar,
CutFrom,
GeometryRelation,
NegatedRelation,
Expand Down
13 changes: 13 additions & 0 deletions infinigen/core/constraints/constraint_language/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,17 @@ class SupportedBy(Touching):
__repr__ = no_frozenset_repr


@dataclass(frozen=True)
class CoPlanar(GeometryRelation):
margin: float = 0

# rev_normal: if True, align the normals so they face the SAME direction, rather than two planes facing eachother.
# typical use is for sink embedded in countertop
rev_normal: bool = False

__repr__ = no_frozenset_repr


@dataclass(frozen=True)
class StableAgainst(GeometryRelation):
margin: float = 0
Expand All @@ -394,6 +405,8 @@ class StableAgainst(GeometryRelation):
# typical use is chair-against-table relation
check_z: bool = True

rev_normal: bool = False

__repr__ = no_frozenset_repr


Expand Down
27 changes: 11 additions & 16 deletions infinigen/core/constraints/constraint_language/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,30 +213,21 @@ def delete_obj(scene, a, delete_blender=True):
scene.delete_geometry(obj_name + "_mesh")


def global_vertex_coordinates(obj, local_vertex) -> Vector:
return obj.matrix_world @ local_vertex.co


def global_polygon_normal(obj, polygon):
loc, rot, scale = obj.matrix_world.decompose()
rot = rot.to_matrix()
normal = rot @ polygon.normal
return normal / np.linalg.norm(normal)


def is_planar(obj, tolerance=1e-6):
if len(obj.data.polygons) != 1:
return False

polygon = obj.data.polygons[0]
global_normal = global_polygon_normal(obj, polygon)
global_normal = butil.global_polygon_normal(obj, polygon)

# Take the first vertex as a reference point on the plane
ref_vertex = global_vertex_coordinates(obj, obj.data.vertices[polygon.vertices[0]])
ref_vertex = butil.global_vertex_coordinates(
obj, obj.data.vertices[polygon.vertices[0]]
)

# Check if all vertices lie on the plane defined by the reference vertex and the global normal
for vertex in obj.data.vertices:
distance = (global_vertex_coordinates(obj, vertex) - ref_vertex).dot(
distance = (butil.global_vertex_coordinates(obj, vertex) - ref_vertex).dot(
global_normal
)
if not math.isclose(distance, 0, abs_tol=tolerance):
Expand All @@ -253,8 +244,12 @@ def planes_parallel(plane_obj_a, plane_obj_b, tolerance=1e-6):
# if not is_planar(plane_obj_a) or not is_planar(plane_obj_b):
# raise ValueError("One or both objects are not planar")

global_normal_a = global_polygon_normal(plane_obj_a, plane_obj_a.data.polygons[0])
global_normal_b = global_polygon_normal(plane_obj_b, plane_obj_b.data.polygons[0])
global_normal_a = butil.global_polygon_normal(
plane_obj_a, plane_obj_a.data.polygons[0]
)
global_normal_b = butil.global_polygon_normal(
plane_obj_b, plane_obj_b.data.polygons[0]
)

dot_product = global_normal_a.dot(global_normal_b)

Expand Down
35 changes: 16 additions & 19 deletions infinigen/core/constraints/evaluator/indoor_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import trimesh
from shapely import LineString, Point

from infinigen.core.util import blender as butil


def meshes_from_names(scene, names):
if isinstance(names, str):
Expand Down Expand Up @@ -172,30 +174,21 @@ def delete_obj(a, scene=None):
scene.delete_geometry(obj_name + "_mesh")


def global_vertex_coordinates(obj, local_vertex):
return obj.matrix_world @ local_vertex.co


def global_polygon_normal(obj, polygon):
loc, rot, scale = obj.matrix_world.decompose()
rot = rot.to_matrix()
normal = rot @ polygon.normal
return normal / np.linalg.norm(normal)


def is_planar(obj, tolerance=1e-6):
if len(obj.data.polygons) != 1:
return False

polygon = obj.data.polygons[0]
global_normal = global_polygon_normal(obj, polygon)
global_normal = butil.global_polygon_normal(obj, polygon)

# Take the first vertex as a reference point on the plane
ref_vertex = global_vertex_coordinates(obj, obj.data.vertices[polygon.vertices[0]])
ref_vertex = butil.global_vertex_coordinates(
obj, obj.data.vertices[polygon.vertices[0]]
)

# Check if all vertices lie on the plane defined by the reference vertex and the global normal
for vertex in obj.data.vertices:
distance = (global_vertex_coordinates(obj, vertex) - ref_vertex).dot(
distance = (butil.global_vertex_coordinates(obj, vertex) - ref_vertex).dot(
global_normal
)
if not math.isclose(distance, 0, abs_tol=tolerance):
Expand All @@ -212,8 +205,12 @@ def planes_parallel(plane_obj_a, plane_obj_b, tolerance=1e-6):
# if not is_planar(plane_obj_a) or not is_planar(plane_obj_b):
# raise ValueError("One or both objects are not planar")

global_normal_a = global_polygon_normal(plane_obj_a, plane_obj_a.data.polygons[0])
global_normal_b = global_polygon_normal(plane_obj_b, plane_obj_b.data.polygons[0])
global_normal_a = butil.global_polygon_normal(
plane_obj_a, plane_obj_a.data.polygons[0]
)
global_normal_b = butil.global_polygon_normal(
plane_obj_b, plane_obj_b.data.polygons[0]
)

dot_product = global_normal_a.dot(global_normal_b)

Expand All @@ -230,12 +227,12 @@ def distance_to_plane(point, plane_point, plane_normal):
def is_within_margin_from_plane(obj, obj_b, margin, tol=1e-6):
"""Check if all vertices of an object are within a given margin from a plane."""
polygon_b = obj_b.data.polygons[0]
plane_point_b = global_vertex_coordinates(
plane_point_b = butil.global_vertex_coordinates(
obj_b, obj_b.data.vertices[polygon_b.vertices[0]]
)
plane_normal_b = global_polygon_normal(obj_b, polygon_b)
plane_normal_b = butil.global_polygon_normal(obj_b, polygon_b)
for vertex in obj.data.vertices:
global_vertex = global_vertex_coordinates(obj, vertex)
global_vertex = butil.global_vertex_coordinates(obj, vertex)
distance = distance_to_plane(global_vertex, plane_point_b, plane_normal_b)
if not math.isclose(distance, margin, abs_tol=tol):
return False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
from infinigen.core import tags as t
from infinigen.core.constraints.example_solver import state_def
from infinigen.core.constraints.example_solver.geometry.parse_scene import add_to_scene
from infinigen.core.util import blender as butil
from infinigen.core.util.logging import lazydebug

# from infinigen.core.util import blender as butil

# import fcl


Expand Down Expand Up @@ -85,10 +84,10 @@ def get_axis(state: state_def.State, obj: bpy.types.Object, tag=t.Subpart.Front)
a_front_plane = a_front_planes[0]
a_front_plane_ind = a_front_plane[1]
a_poly = obj.data.polygons[a_front_plane_ind]
front_plane_pt = iu.global_vertex_coordinates(
front_plane_pt = butil.global_vertex_coordinates(
obj, obj.data.vertices[a_poly.vertices[0]]
)
front_plane_normal = iu.global_polygon_normal(obj, a_poly)
front_plane_normal = butil.global_polygon_normal(obj, a_poly)
return front_plane_pt, front_plane_normal


Expand Down
Loading

0 comments on commit 7105e2c

Please sign in to comment.