scenic.core.shapes

Module containing the Shape class and its subclasses, which represent shapes of Objects

Summary of Module Members

Classes

BoxShape

A box shape with all dimensions 1 by default.

ConeShape

A cone shape with all dimensions 1 by default.

CylinderShape

A cylinder shape with all dimensions 1 by default.

MeshShape

A Shape subclass defined by a trimesh.base.Trimesh object.

Shape

An abstract base class for Scenic shapes.

SpheroidShape

A spheroid shape with all dimensions 1 by default.

Member Details

class Shape(dimensions, scale)[source]

Bases: ABC

An abstract base class for Scenic shapes.

Represents a physical shape in Scenic. Does not encode position or orientation, which are handled by the Region class. Does contain dimension information, which is used as a default value by any Object with this shape and can be overwritten.

If dimensions and scale are both specified the dimensions are first set by dimensions, and then scaled by scale.

Parameters:
  • dimensions – The raw (before scaling) dimensions of the shape.

  • scale – Scales all the dimensions of the shape by a multiplicative factor.

property containsCenter

Whether or not this object contains its central point

class MeshShape(mesh, dimensions=None, scale=1, initial_rotation=None)[source]

Bases: Shape

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]

Bases: MeshShape

A box shape with all dimensions 1 by default.

class CylinderShape(dimensions=(1, 1, 1), scale=1, initial_rotation=None, sections=24)[source]

Bases: MeshShape

A cylinder shape with all dimensions 1 by default.

class ConeShape(dimensions=(1, 1, 1), scale=1, initial_rotation=None)[source]

Bases: MeshShape

A cone shape with all dimensions 1 by default.

class SpheroidShape(dimensions=(1, 1, 1), scale=1, initial_rotation=None)[source]

Bases: MeshShape

A spheroid shape with all dimensions 1 by default.