Skip to content

Commit

Permalink
Fix orientation inconsistenceis.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Vin committed Feb 1, 2024
1 parent 783557d commit 3fbecd4
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/scenic/core/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,9 @@ def sampleGiven(self, value):
dimensions=value[self.dimensions],
position=value[self.position],
rotation=value[self.rotation],
orientation=value[self.orientation],
orientation=True
if self.__dict__.get("_usingDefaultOrientation", False)
else value[self.orientation],
tolerance=self.tolerance,
centerMesh=self.centerMesh,
onDirection=self.onDirection,
Expand All @@ -905,7 +907,11 @@ def evaluateInner(self, context):
dimensions = valueInContext(self.dimensions, context)
position = valueInContext(self.position, context)
rotation = valueInContext(self.rotation, context)
orientation = valueInContext(self.orientation, context)
orientation = (
True
if self.__dict__.get("_usingDefaultOrientation", False)
else valueInContext(self.orientation, context)
)

return cls(
mesh,
Expand Down Expand Up @@ -1740,7 +1746,6 @@ def getSurfaceRegion(self):
return MeshSurfaceRegion(
self.mesh,
self.name,
orientation=self.orientation,
tolerance=self.tolerance,
centerMesh=False,
onDirection=self.onDirection,
Expand Down Expand Up @@ -1779,21 +1784,23 @@ class MeshSurfaceRegion(MeshRegion):
onDirection: The direction to use if an object being placed on this region doesn't specify one.
"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def __init__(self, *args, orientation=True, **kwargs):
if orientation is True:
orientation = VectorField(
"DefaultSurfaceVectorField", lambda pos: self.getFlatOrientation(pos)
)
self._usingDefaultOrientation = True
else:
self._usingDefaultOrientation = False

super().__init__(*args, orientation=orientation, **kwargs)

# Validate dimensions
if self.dimensions is not None:
for dim, name in zip(self.dimensions, ("width", "length", "height")):
if dim < 0:
raise ValueError(f"{name} of MeshSurfaceRegion must be nonnegative")

# Set default orientation to one inferred from face norms if none is provided.
if self.orientation is None:
self.orientation = VectorField(
"DefaultSurfaceVectorField", lambda pos: self.getFlatOrientation(pos)
)

# Property testing methods #
@distributionFunction
def intersects(self, other, triedReversed=False):
Expand Down Expand Up @@ -1931,7 +1938,6 @@ def getVolumeRegion(self):
return MeshVolumeRegion(
self.mesh,
self.name,
orientation=self.orientation,
tolerance=self.tolerance,
centerMesh=False,
onDirection=self.onDirection,
Expand Down Expand Up @@ -3746,8 +3752,6 @@ class ViewRegion(MeshVolumeRegion):
name: An optional name to help with debugging.
position: An optional position, which determines where the center of the region will be.
rotation: An optional Orientation object which determines the rotation of the object in space.
orientation: An optional vector field describing the preferred orientation at every point in
the region.
angleCutoff: How close to 180/360 degrees an angle has to be to be mapped to that value.
tolerance: Tolerance for collision computations.
"""
Expand All @@ -3759,7 +3763,6 @@ def __init__(
name=None,
position=Vector(0, 0, 0),
rotation=None,
orientation=None,
angleCutoff=0.017,
tolerance=1e-8,
):
Expand Down Expand Up @@ -3806,7 +3809,6 @@ def __init__(
name=name,
position=position,
rotation=rotation,
orientation=orientation,
tolerance=tolerance,
centerMesh=False,
)
Expand Down

0 comments on commit 3fbecd4

Please sign in to comment.