solid

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const PlaneEPSILON = 1e-5

PlaneEPSILON is the tolerance used by `SplitPolygon()` to decide if a point is on the plane.

Variables

This section is empty.

Functions

func NewSolid

func NewSolid(kind string, csg CSG) seen.Object

Types

type BSP

type BSP struct {
	Plane    *Plane
	Polygons []Polygon
	Front    *BSP
	Back     *BSP
}

BSP holds a node in a BSP tree. A BSP tree is built from a collection of polygons by picking a polygon to split along. That polygon (and all other coplanar polygons) are added directly to that node and the other polygons are added to the front and/or back subtrees. This is not a leafy BSP tree since there is no distinction between internal and leaf nodes.

func (*BSP) AddPolygons

func (n *BSP) AddPolygons(polygons []Polygon)

AddPolygons builds a BSP tree out of `polygons`. When called on an existing tree, the new polygons are filtered down to the bottom of the tree and become new nodes there. Each set of polygons is partitioned using the first polygon (no heuristic is used to pick a good split).

func (BSP) AllPolygons

func (n BSP) AllPolygons() []Polygon

AllPolygons returns a list of all polygons in this BSP tree.

func (BSP) ClipPolygons

func (n BSP) ClipPolygons(polygons []Polygon) []Polygon

ClipPolygons recursively removes all polygons in `polygons` that are inside this BSP tree.

func (*BSP) ClipTo

func (n *BSP) ClipTo(bsp *BSP)

ClipTo removes all polygons in this BSP tree that are inside the other BSP tree `bsp`.

func (*BSP) Invert

func (n *BSP) Invert()

Invert converts solid space to empty space and empty space to solid space.

func (*BSP) String

func (n *BSP) String() string

type CSG

type CSG []Polygon

CSG holds a binary space partition tree representing a 3D solid. Two solids can be combined using the `Union()`, `Subtract()` and `Intersect()` methods.

func Cube

func Cube(options ...Option) CSG

Cube constructs an axis-aligned solid cuboid. Optional parameters are `Center` and `Size`, which default to `Center(0, 0, 0)` and `Size(2, 2, 2)`. The Size is specified a list of three numbers, one for each axis.

Example code:

cube := solid.Cube(
  solid.Center(0, 0, 0),
  solid.Size(2, 2, 2))

func Cylinder

func Cylinder(options ...Option) CSG

Cylinder constructs a solid cylinder. Optional parameters are `Start`, `End`, `Radius`, and `Slices`, which default to `Start(0, -1, 0)`, `End(0, 1, 0)`, `Radius(1)`, and `Slices(16)`. The `Slices` parameter controls the tessellation.

Example usage:

cylinder := Cylinder(
  Start(0, -1, 0),
  End(0, 1, 0),
  Radius(1),
  Slices(16))

func Sphere

func Sphere(options ...Option) CSG

Sphere constructs a solid sphere. Optional parameters are `Center`, `Radius`, `Slices`, and `Stacks`, which default to `Center(0, 0, 0)`, `Radius(1)`, `Slices(16)`, and `Stacks(8)`. The `Slices` and `Stacks` parameters control the tessellation along the longitude and latitude directions.

Example usage:

sphere := Sphere(
  Center(0, 0, 0),
  Radius(1),
  Slices(16),
  Stacks(8))

func (CSG) Clone

func (p CSG) Clone() CSG

Clone returns a new CSG solid that is a deep clone.

func (CSG) Intersect

func (s CSG) Intersect(other CSG) CSG

Intersect returns a new CSG solid representing space both this solid and in the solid `csg`. Neither this solid nor the solid `csg` are modified.

A.intersect(B)

+-------+
|       |
|   A   |
|    +--+----+   =   +--+
+----+--+    |       +--+
     |   B   |
     |       |
     +-------+

func (CSG) Inverse

func (s CSG) Inverse() CSG

Inverse returns a new CSG solid with solid and empty space switched. This solid is not modified.

func (CSG) Subtract

func (s CSG) Subtract(other CSG) CSG

Subtract returns a new CSG solid representing space in this solid but not in the solid `csg`. Neither this solid nor the solid `csg` are modified.

A.Subtract(B)

+-------+            +-------+
|       |            |       |
|   A   |            |       |
|    +--+----+   =   |    +--+
+----+--+    |       +----+
     |   B   |
     |       |
     +-------+

func (CSG) Union

func (s CSG) Union(other CSG) CSG

Union returns a new CSG solid representing space in either this solid or in the solid `csg`. Neither this solid nor the solid `csg` are modified.

A.Union(B)

+-------+            +-------+
|       |            |       |
|   A   |            |       |
|    +--+----+   =   |       +----+
+----+--+    |       +----+       |
     |   B   |            |       |
     |       |            |       |
     +-------+            +-------+

type Option

type Option func(*Options)

func Center

func Center(x, y, z float64) Option

func End

func End(x, y, z float64) Option

func Radius

func Radius(radius float64) Option

func Size

func Size(x, y, z float64) Option

func Slices

func Slices(slices int) Option

func Stacks

func Stacks(stacks int) Option

func Start

func Start(x, y, z float64) Option

type Options

type Options struct {
	Center Vector
	Radius float64
	Size   Vector
	Slices int
	Stacks int
	Start  Vector
	End    Vector
}

func OptionsFrom

func OptionsFrom(options []Option) *Options

type Plane

type Plane struct {
	Normal Vector
	W      float64
}

Plane represents a plane in 3D space.

func PlaneFromPoints

func PlaneFromPoints(a, b, c Vector) Plane

func (*Plane) Flip

func (p *Plane) Flip()

func (Plane) SplitPolygon

func (p Plane) SplitPolygon(polygon Polygon, coplanarFront, coplanarBack, front, back *[]Polygon)

SplitPolygon splits `polygon` by this plane if needed, then put the polygon or polygon fragments in the appropriate lists. Coplanar polygons go into either `coplanarFront` or `coplanarBack` depending on their orientation with respect to this plane. Polygons in front or in back of this plane go into either `front` or `back`.

type Polygon

type Polygon struct {
	Vertices []Vertex
	Plane    Plane
}

Polygon represents a convex polygon. The vertices used to initialize a polygon must be coplanar and form a convex loop.

Each convex polygon has a `Shared` property, which is shared between all polygons that are clones of each other or were split from the same polygon. This can be used to define per-polygon properties (such as face color).

func PolygonFromVertices

func PolygonFromVertices(vertices ...Vertex) Polygon

func (*Polygon) Flip

func (p *Polygon) Flip()

type Solid

type Solid struct {
	transform.Transform
	// contains filtered or unexported fields
}

func (Solid) Faces

func (s Solid) Faces() face.Faces

func (Solid) Kind

func (s Solid) Kind() string

type Vector

type Vector = point.Point

type Vertex

type Vertex struct{ Pos, Normal Vector }

Vertex represents a vertex of a polygon. Use your own vertex class instead of this one to provide additional features like texture coordinates and vertex colors. Custom vertex classes need to provide a `Pos` property and `Flip()`, and `Interpolate()` methods that behave analogous to the ones defined by `Vertex`. This struct provides `Normal` so convenience functions like `Sphere()` can return a smooth vertex normal, but `Normal` is not used anywhere else.

func (*Vertex) Flip

func (v *Vertex) Flip()

Flip inverts all orientation-specific data (e.g. vertex normal). Called when the orientation of a polygon is flipped.

func (Vertex) Interpolate

func (v Vertex) Interpolate(other Vertex, t float64) Vertex

Interpolate creates a new vertex between this vertex and `other` by linearly interpolating all properties using a parameter of `t`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL