Skip to content

compas_notebook.conversions ¤

Functions¤

box_to_threejs ¤

box_to_threejs(box: Box) -> BoxGeometry

Convert a COMPAS box to PyThreeJS.

Parameters:

Name Type Description Default
box Box

The box to convert.

required

Returns:

Type Description
BoxGeometry

Examples:

>>> from compas.geometry import Box
>>> box = Box.from_width_height_depth(1, 2, 3)
>>> box_to_threejs(box)
BoxGeometry(...)

color_to_threejs ¤

color_to_threejs(color: Color) -> MeshBasicMaterial

Convert a COMPAS color to a PyThreeJS material.

Parameters:

Name Type Description Default
color Color

The color to convert.

required

Returns:

Type Description
MeshBasicMaterials

The PyThreeJS material.

Examples:

>>> from compas.colors import Color
>>> color = Color.from_rgb255(255, 0, 0)
>>> color_to_threejs(color)
MeshBasicMaterial(...)

cone_to_threejs ¤

cone_to_threejs(cone: Cone) -> CylinderGeometry

Convert a COMPAS cone to PyThreeJS.

Parameters:

Name Type Description Default
cone Cone

The cone to convert.

required

Returns:

Type Description
CylinderGeometry

Examples:

>>> from compas.geometry import Cone
>>> cone = Cone(radius=1, height=2)
>>> cone_to_threejs(cone)
CylinderGeometry(...)

cylinder_to_threejs ¤

cylinder_to_threejs(cylinder: Cylinder) -> CylinderGeometry

Convert a COMPAS cylinder to PyThreeJS.

Parameters:

Name Type Description Default
cylinder Cylinder

The cylinder to convert.

required

Returns:

Type Description
CylinderGeometry

Examples:

>>> from compas.geometry import Cylinder
>>> cylinder = Cylinder(radius=1, height=2)
>>> cylinder_to_threejs(cylinder)
CylinderGeometry(...)

dot_to_threejs ¤

dot_to_threejs(dot: Dot, fontsize: int = 48, color: str = 'white') -> Sprite

Convert a COMPAS Dot to PyThreeJS Sprite.

The sprite maintains constant screen size regardless of zoom level.

Parameters:

Name Type Description Default
dot Dot

The dot to convert.

required
fontsize int

Font size for the text texture.

48
color str

Text color.

'white'

Returns:

Type Description
Sprite

A sprite with text texture positioned at the dot location.

line_to_threejs ¤

line_to_threejs(line: Line) -> BufferGeometry

Convert a COMPAS line to PyThreeJS.

Parameters:

Name Type Description Default
line Line

The line to convert.

required

Returns:

Type Description
BufferGeometry

nodes_and_edges_to_threejs ¤

nodes_and_edges_to_threejs(
    nodes: list[list[float]], edges: list[tuple[int, int]]
) -> BufferGeometry

Convert nodes and edges to a PyThreeJS geometry.

Parameters:

Name Type Description Default
nodes list[list[float]]

List of nodes.

required
edges list[tuple[int, int]]

List of edges.

required

Returns:

Type Description
BufferGeometry

The PyThreeJS geometry.

nodes_to_threejs ¤

nodes_to_threejs(nodes: list[list[float]]) -> BufferGeometry

Convert nodes to a PyThreeJS geometry.

Parameters:

Name Type Description Default
nodes list[list[float]]

List of nodes.

required

Returns:

Type Description
BufferGeometry

The PyThreeJS geometry.

point_to_threejs ¤

point_to_threejs(point: Point) -> SphereGeometry

Convert a COMPAS point to PyThreeJS.

Parameters:

Name Type Description Default
point Point

The point to convert.

required

Returns:

Type Description
BufferGeometry

Examples:

>>> from compas.geometry import Point
>>> point = Point(1, 2, 3)
>>> point_to_threejs(point)
BufferGeometry(...)

pointcloud_to_threejs ¤

pointcloud_to_threejs(pointcloud: Pointcloud) -> SphereGeometry

Convert a COMPAS point to PyThreeJS.

Parameters:

Name Type Description Default
pointcloud Pointcloud

The pointcloud to convert.

required

Returns:

Type Description
BufferGeometry

Examples:

>>>

polyline_to_threejs ¤

polyline_to_threejs(polyline: Polyline) -> BufferGeometry

Convert a COMPAS polyline to PyThreeJS.

Parameters:

Name Type Description Default
polyline Polyline

The polyline to convert.

required

Returns:

Type Description
BufferGeometry

shapes_to_edgesbuffer ¤

shapes_to_edgesbuffer(shapes: list[Mesh | Shape], color: Color) -> LineSegments

Convert the combined edges of a collection of shapes to one line segment buffer.

Parameters:

Name Type Description Default
shapes list[Mesh | Shape]

The shape collection.

required
color Color

The color of the edges.

required

Returns:

Type Description
LineSegments

shapes_to_facesbuffer ¤

shapes_to_facesbuffer(shapes: list[Mesh], color: Color) -> Mesh

Convert the combined faces of a collection of shapes to one mesh buffer.

Parameters:

Name Type Description Default
shapes list[Mesh]

The shape collection.

required
color Color

The color of the faces.

required

Returns:

Type Description
Mesh

sphere_to_threejs ¤

sphere_to_threejs(sphere: Sphere) -> SphereGeometry

Convert a COMPAS sphere to PyThreeJS.

Parameters:

Name Type Description Default
sphere Sphere

The sphere to convert.

required

Returns:

Type Description
SphereGeometry

Examples:

>>> from compas.geometry import Sphere
>>> sphere = Sphere(radius=1)
>>> sphere_to_threejs(sphere)
SphereGeometry(...)

torus_to_threejs ¤

torus_to_threejs(torus: Torus) -> TorusGeometry

Convert a COMPAS torus to a PyThreeJS torus geometry.

Parameters:

Name Type Description Default
torus Torus

The torus to convert.

required

Returns:

Type Description
TorusGeometry

The PyThreeJS torus geometry.

Examples:

>>> from compas.geometry import Torus
>>> torus = Torus(radius_axis=1, radius_pipe=0.2)
>>> torus_to_threejs(torus)
TorusGeometry(...)

vertices_and_edges_to_threejs ¤

vertices_and_edges_to_threejs(
    vertices: list[list[float]], edges: list[tuple[int, int]]
) -> BufferGeometry

Convert vertices and edges to a PyThreeJS geometry.

Parameters:

Name Type Description Default
vertices list[list[float]]

List of vertices.

required
edges list[tuple[int, int]]

List of edges.

required

Returns:

Type Description
BufferGeometry

The PyThreeJS geometry.

vertices_and_faces_to_threejs ¤

vertices_and_faces_to_threejs(
    vertices: list[list[float]], faces: list[list[int]]
) -> BufferGeometry

Convert vertices and faces to a PyThreeJS geometry.

Parameters:

Name Type Description Default
vertices list[list[float]]

List of vertices.

required
faces list[list[int]]

List of faces.

required

Returns:

Type Description
BufferGeometry

The PyThreeJS geometry.

vertices_to_threejs ¤

vertices_to_threejs(vertices: list[list[float]]) -> BufferGeometry

Convert vertices to a PyThreeJS geometry.

Parameters:

Name Type Description Default
vertices list[list[float]]

List of vertices.

required

Returns:

Type Description
BufferGeometry

The PyThreeJS geometry.