Regions represent sets of points in space.
Scenic provides a variety of ways to define regions in 2D and 3D space: meshes, rectangles, circular sectors, line segments, polygons, occupancy grids, and explicit lists of points, among others.
Regions can have an associated vector field giving points in the region
preferred orientations
.
For example, a region representing a lane of traffic could have a preferred orientation aligned with the lane, so that we can easily talk about distances along the lane, even if it curves.
Another possible use of preferred orientations is to give the surface of an object normal vectors, so that other objects placed on the surface face outward by default.
The main operations available for use with all regions are:
If you need to perform more complex operations on regions, or are writing a
world model
and need to define your own regions, you will have to work with the
Region
class (which regions are instances of) and its subclasses for particular types of regions. These are listed in the
Regions
Types
reference. If you are working on Scenic’s internals, see the
scenic.core.regions
module for full details.
Shape
Shapes represent the shape of an object, i.e., the volume it occupies modulo translation, rotation, and scaling.
Shapes are represented by meshes, automatically converted to unit size and centered; Scenic considers the side of the shape facing the positive Y axis to be its front.
Shapes can be created from an arbitrary mesh or using one of the geometric primitives below.
For convenience, a shape created with specified dimensions will set the default dimensions for any
Object
created with that shape.
When creating a
MeshShape
, if no dimensions are provided then dimensions will be inferred from the mesh.
MeshShape
also takes an optional
initial_rotation
parameter, which allows directions other than the positive Y axis to be considered the front of the shape.
class
MeshShape
(
mesh
,
dimensions
=
None
,
scale
=
1
,
initial_rotation
=
None
)
[source]
A Shape subclass defined by a
trimesh.base.Trimesh
object.
The mesh passed must be a
trimesh.base.Trimesh
object that represents a well defined
volume (i.e. the
is_volume
property must be true), meaning the mesh must be watertight,
have consistent winding and have outward facing normals.
Parameters
:
mesh
– A mesh object.
dimensions
– The raw (before scaling) dimensions of the shape. If dimensions
and scale are both specified the dimensions are first set by dimensions, and then
scaled by scale.
scale
– Scales all the dimensions of the shape by a multiplicative factor.
If dimensions and scale are both specified the dimensions are first set by dimensions,
and then scaled by scale.
initial_rotation
– A 3-tuple containing the yaw, pitch, and roll respectively to apply when loading
the mesh. Note the initial_rotation must be fixed.
classmethod
fromFile
(
path
,
unify
=
True
,
**
kwargs
)
[source]
Load a mesh shape from a file, attempting to infer filetype and compression.
For example: “foo.obj.bz2” is assumed to be a compressed .obj file.
“foo.obj” is assumed to be an uncompressed .obj file. “foo” is an
unknown filetype, so unless a filetype is provided an exception will be raised.
Parameters
:
path
(
str
) – Path to the file to import.
filetype
(
str
) – Filetype of file to be imported. This will be inferred if not provided.
The filetype must be one compatible with
trimesh.load
.
compressed
(
bool
) – Whether or not this file is compressed (with bz2). This will be inferred
if not provided.
binary
(
bool
) – Whether or not to open the file as a binary file.
unify
(
bool
) – Whether or not to attempt to unify this mesh.
kwargs
– Additional arguments to the MeshShape initializer.
class
BoxShape
(
dimensions
=
(1,
1,
1)
,
scale
=
1
,
initial_rotation
=
None
)
[source]
A box shape with all dimensions 1 by default.
class
CylinderShape
(
dimensions
=
(1,
1,
1)
,
scale
=
1
,
initial_rotation
=
None
,
sections
=
24
)
[source]
A cylinder shape with all dimensions 1 by default.
class
ConeShape
(
dimensions
=
(1,
1,
1)
,
scale
=
1
,
initial_rotation
=
None
)
[source]
A cone shape with all dimensions 1 by default.
class
SpheroidShape
(
dimensions
=
(1,
1,
1)
,
scale
=
1
,
initial_rotation
=
None
)
[source]
A spheroid shape with all dimensions 1 by default.