Documentation ¶
Index ¶
- Variables
- func AbsInt(x int) int
- func Clamp(x, lo, hi float64) float64
- func ClampInt(x, lo, hi int) int
- func Degrees(radians float64) float64
- func InterpolateFloats(v1, v2, v3 float64, b VectorW) float64
- func LoadImage(path string) (image.Image, error)
- func ParseFloats(items []string) []float64
- func Radians(degrees float64) float64
- func Round(a float64) int
- func RoundPlaces(a float64, places int) float64
- func SavePNG(path string, im image.Image) error
- func SaveSTL(path string, mesh *Mesh) error
- type Box
- func (a Box) Anchor(anchor Vector) Vector
- func (a Box) Center() Vector
- func (a Box) Contains(b Vector) bool
- func (a Box) ContainsBox(b Box) bool
- func (a Box) Extend(b Box) Box
- func (a Box) Intersection(b Box) Box
- func (a Box) Intersects(b Box) bool
- func (a Box) Offset(x float64) Box
- func (a Box) Size() Vector
- func (a Box) Transform(m Matrix) Box
- func (a Box) Translate(v Vector) Box
- func (a Box) Volume() float64
- type Color
- func (a Color) Add(b Color) Color
- func (a Color) AddScalar(b float64) Color
- func (a Color) Alpha(alpha float64) Color
- func (a Color) Div(b Color) Color
- func (a Color) DivScalar(b float64) Color
- func (a Color) Lerp(b Color, t float64) Color
- func (a Color) Max(b Color) Color
- func (a Color) Min(b Color) Color
- func (a Color) Mul(b Color) Color
- func (a Color) MulScalar(b float64) Color
- func (c Color) NRGBA() color.NRGBA
- func (a Color) Opaque() Color
- func (a Color) Pow(b float64) Color
- func (a Color) Sub(b Color) Color
- func (a Color) SubScalar(b float64) Color
- type Context
- func (dc *Context) ClearColorBuffer()
- func (dc *Context) ClearColorBufferWith(color Color)
- func (dc *Context) ClearDepthBuffer()
- func (dc *Context) ClearDepthBufferWith(value float64)
- func (dc *Context) DepthImage() image.Image
- func (dc *Context) DrawLine(t *Line) RasterizeInfo
- func (dc *Context) DrawLines(lines []*Line) RasterizeInfo
- func (dc *Context) DrawMesh(mesh *Mesh) RasterizeInfo
- func (dc *Context) DrawTriangle(t *Triangle) RasterizeInfo
- func (dc *Context) DrawTriangles(triangles []*Triangle) RasterizeInfo
- func (dc *Context) Image() image.Image
- type Cull
- type Face
- type ImageTexture
- type Line
- type Matrix
- func Frustum(l, r, b, t, n, f float64) Matrix
- func Identity() Matrix
- func LookAt(eye, center, up Vector) Matrix
- func LookAtDirection(forward, up Vector) Matrix
- func Orient(position, size, up Vector, rotation float64) Matrix
- func Orthographic(l, r, b, t, n, f float64) Matrix
- func Perspective(fovy, aspect, near, far float64) Matrix
- func Rotate(v Vector, a float64) Matrix
- func RotateTo(a, b Vector) Matrix
- func Scale(v Vector) Matrix
- func Screen(w, h int) Matrix
- func Translate(v Vector) Matrix
- func Viewport(x, y, w, h float64) Matrix
- func (a Matrix) Determinant() float64
- func (m Matrix) Frustum(l, r, b, t, n, f float64) Matrix
- func (a Matrix) Inverse() Matrix
- func (m Matrix) LookAt(eye, center, up Vector) Matrix
- func (m Matrix) LookAtDirection(forward, up Vector) Matrix
- func (a Matrix) Mul(b Matrix) Matrix
- func (a Matrix) MulBox(box Box) Box
- func (a Matrix) MulDirection(b Vector) Vector
- func (a Matrix) MulPosition(b Vector) Vector
- func (a Matrix) MulPositionW(b Vector) VectorW
- func (a Matrix) MulScalar(b float64) Matrix
- func (m Matrix) Orthographic(l, r, b, t, n, f float64) Matrix
- func (m Matrix) Perspective(fovy, aspect, near, far float64) Matrix
- func (m Matrix) Rotate(v Vector, a float64) Matrix
- func (m Matrix) RotateTo(a, b Vector) Matrix
- func (m Matrix) Scale(v Vector) Matrix
- func (m Matrix) Screen(w, h int) Matrix
- func (m Matrix) Translate(v Vector) Matrix
- func (a Matrix) Transpose() Matrix
- func (m Matrix) Viewport(x, y, w, h float64) Matrix
- type Mesh
- func Load3DS(filename string) (*Mesh, error)
- func LoadMesh(path string) (*Mesh, error)
- func LoadOBJ(path string) (*Mesh, error)
- func LoadPLY(path string) (*Mesh, error)
- func LoadSTL(path string) (*Mesh, error)
- func NewCone(step int, capped bool) *Mesh
- func NewCube() *Mesh
- func NewCubeForBox(box Box) *Mesh
- func NewCubeOutlineForBox(box Box) *Mesh
- func NewCylinder(step int, capped bool) *Mesh
- func NewEmptyMesh() *Mesh
- func NewIcosahedron() *Mesh
- func NewLatLngSphere(latStep, lngStep int) *Mesh
- func NewLineMesh(lines []*Line) *Mesh
- func NewMesh(triangles []*Triangle, lines []*Line) *Mesh
- func NewPlane() *Mesh
- func NewSphere(detail int) *Mesh
- func NewTriangleMesh(triangles []*Triangle) *Mesh
- func NewVoxelMesh(voxels []Voxel) *Mesh
- func (a *Mesh) Add(b *Mesh)
- func (m *Mesh) BiUnitCube() Matrix
- func (m *Mesh) BoundingBox() Box
- func (m *Mesh) Center() Matrix
- func (m *Mesh) Copy() *Mesh
- func (m *Mesh) FitInside(box Box, anchor Vector) Matrix
- func (m *Mesh) MoveTo(position, anchor Vector) Matrix
- func (m *Mesh) ReverseWinding()
- func (m *Mesh) SaveSTL(path string) error
- func (m *Mesh) SetColor(c Color)
- func (m *Mesh) SharpEdges(angleThreshold float64) *Mesh
- func (m *Mesh) Silhouette(eye Vector, offset float64) *Mesh
- func (m *Mesh) Simplify(factor float64)
- func (m *Mesh) SmoothNormals()
- func (m *Mesh) SmoothNormalsThreshold(radians float64)
- func (m *Mesh) SplitTriangles(maxEdgeLength float64)
- func (m *Mesh) SurfaceArea() float64
- func (m *Mesh) Transform(matrix Matrix)
- func (m *Mesh) UnitCube() Matrix
- func (m *Mesh) Volume() float64
- type PhongShader
- type RasterizeInfo
- type STLHeader
- type STLTriangle
- type Shader
- type SolidColorShader
- type Texture
- type TextureShader
- type Triangle
- type VOXChunk
- type VOXHeader
- type VOXVoxel
- type Vector
- func (a Vector) Abs() Vector
- func (a Vector) Add(b Vector) Vector
- func (a Vector) AddScalar(b float64) Vector
- func (a Vector) Ceil() Vector
- func (a Vector) Cross(b Vector) Vector
- func (a Vector) Distance(b Vector) float64
- func (a Vector) DistanceSquared(b Vector) float64
- func (a Vector) Div(b Vector) Vector
- func (a Vector) DivScalar(b float64) Vector
- func (a Vector) Dot(b Vector) float64
- func (a Vector) Floor() Vector
- func (a Vector) IsDegenerate() bool
- func (a Vector) Length() float64
- func (a Vector) LengthSquared() float64
- func (a Vector) Lerp(b Vector, t float64) Vector
- func (a Vector) LerpDistance(b Vector, d float64) Vector
- func (a Vector) Less(b Vector) bool
- func (a Vector) Max(b Vector) Vector
- func (a Vector) MaxComponent() float64
- func (a Vector) Min(b Vector) Vector
- func (a Vector) MinComponent() float64
- func (a Vector) Mod(b Vector) Vector
- func (a Vector) Mul(b Vector) Vector
- func (a Vector) MulScalar(b float64) Vector
- func (a Vector) Negate() Vector
- func (a Vector) Normalize() Vector
- func (a Vector) Perpendicular() Vector
- func (i Vector) Reflect(n Vector) Vector
- func (a Vector) Round() Vector
- func (a Vector) RoundPlaces(n int) Vector
- func (p Vector) SegmentDistance(v Vector, w Vector) float64
- func (a Vector) Sub(b Vector) Vector
- func (a Vector) SubScalar(b float64) Vector
- func (a Vector) VectorW() VectorW
- type VectorW
- type Vertex
- type Voxel
Constants ¶
This section is empty.
Variables ¶
var ( Discard = Color{} // 丢弃 Transparent = Color{} // 透明 Black = Color{0, 0, 0, 1} // 黑色 White = Color{1, 1, 1, 1} // 白色 )
var EmptyBox = Box{}
Functions ¶
Types ¶
type Context ¶
type Context struct { Width int // 宽度 Height int // 高度 ColorBuffer *image.NRGBA // 颜色缓冲区 DepthBuffer []float64 // 深度缓冲区 ClearColor Color // 清除颜色 Shader Shader // 着色器 ReadDepth bool // 深度测试 WriteDepth bool // 深度测试 WriteColor bool // 颜色混合 AlphaBlend bool // 颜色混合 Wireframe bool // 线框模式 FrontFace Face // 剔除模式 Cull Cull // 剔除模式 LineWidth float64 // 线宽 DepthBias float64 // 深度偏移 // contains filtered or unexported fields }
Context 是一个渲染上下文,包含颜色缓冲区、深度缓冲区、清除颜色、着色器、深度测试、颜色混合、线框模式、剔除模式、线宽、深度偏移、屏幕矩阵和锁等属性
func (*Context) ClearColorBuffer ¶
func (dc *Context) ClearColorBuffer()
ClearColorBuffer 使用清除颜色清除颜色缓冲区
func (*Context) ClearColorBufferWith ¶
ClearColorBufferWith 使用指定颜色清除颜色缓冲区
func (*Context) ClearDepthBuffer ¶
func (dc *Context) ClearDepthBuffer()
ClearDepthBuffer 使用最大值清除深度缓冲区
func (*Context) ClearDepthBufferWith ¶
ClearDepthBufferWith 使用指定值清除深度缓冲区
func (*Context) DrawLines ¶
func (dc *Context) DrawLines(lines []*Line) RasterizeInfo
DrawLines 绘制线段集合
func (*Context) DrawTriangle ¶
func (dc *Context) DrawTriangle(t *Triangle) RasterizeInfo
DrawTriangle 绘制三角形
func (*Context) DrawTriangles ¶
func (dc *Context) DrawTriangles(triangles []*Triangle) RasterizeInfo
DrawTriangles 绘制三角形集合
type Cull ¶
type Cull int
Cull 表示剔除模式
const ( // CullNone 表示不剔除 CullNone Cull // CullFront 表示剔除正面 CullFront // CullBack 表示剔除背面 CullBack )
type Face ¶
type Face int
Face 表示三角形的正反面
const ( // FaceCW 表示三角形的正面为顺时针方向 FaceCW Face // FaceCCW 表示三角形的正面为逆时针方向 FaceCCW )
type ImageTexture ¶
ImageTexture 纹理对象
func (*ImageTexture) BilinearSample ¶
func (t *ImageTexture) BilinearSample(u, v float64) Color
BilinearSample 使用双线性插值对纹理进行采样 u, v: 纹理坐标 返回值: 采样得到的颜色
func (*ImageTexture) Sample ¶
func (t *ImageTexture) Sample(u, v float64) Color
Sample 对纹理进行采样 u, v: 纹理坐标 返回值: 采样得到的颜色
type Matrix ¶
type Matrix struct {
X00, X01, X02, X03 float64 // 第一行
X10, X11, X12, X13 float64 // 第二行
X20, X21, X22, X23 float64 // 第三行
X30, X31, X32, X33 float64 // 第四行
}
func (Matrix) LookAtDirection ¶
LookAtDirection 返回一个观察矩阵
func (Matrix) MulDirection ¶
MulDirection 返回矩阵与方向向量的乘积
func (Matrix) MulPositionW ¶
MulPositionW 返回矩阵与位置向量的乘积
func (Matrix) Orthographic ¶
Orthographic 返回一个正交投影矩阵
func (Matrix) Perspective ¶
Perspective 返回一个透视投影矩阵
type Mesh ¶
type Mesh struct { Triangles []*Triangle // 三角形列表 Lines []*Line // 线列表 // contains filtered or unexported fields }
Mesh 网格
func NewCubeOutlineForBox ¶
NewCubeOutlineForBox函数返回一个盒子的轮廓线网格
func (*Mesh) Silhouette ¶
Silhouette 提取网格轮廓
func (*Mesh) SmoothNormalsThreshold ¶
SmoothNormalsThreshold 平滑网格法线
func (*Mesh) SplitTriangles ¶
SplitTriangles 分割三角形
type PhongShader ¶
type PhongShader struct { Matrix Matrix LightDirection Vector CameraPosition Vector ObjectColor Color AmbientColor Color DiffuseColor Color SpecularColor Color Texture Texture SpecularPower float64 }
PhongShader 实现冯氏着色法
func NewPhongShader ¶
func NewPhongShader(matrix Matrix, lightDirection, cameraPosition Vector) *PhongShader
NewPhongShader 创建一个实现冯氏着色法的着色器
type RasterizeInfo ¶
type RasterizeInfo struct { // TotalPixels 表示总像素数 TotalPixels uint64 // UpdatedPixels 表示更新的像素数 UpdatedPixels uint64 }
RasterizeInfo 表示光栅化信息
func (RasterizeInfo) Add ¶
func (info RasterizeInfo) Add(other RasterizeInfo) RasterizeInfo
Add 将两个 RasterizeInfo 相加
type STLHeader ¶
type STLHeader struct { Count uint32 // 三角形数量 // contains filtered or unexported fields }
STLHeader 是 STL 文件头部
type STLTriangle ¶
type STLTriangle struct {
N, V1, V2, V3 [3]float32 // 法向量和三角形三个顶点
// contains filtered or unexported fields
}
STLTriangle 是 STL 文件中的三角形
type SolidColorShader ¶
SolidColorShader 渲染单一颜色
func NewSolidColorShader ¶
func NewSolidColorShader(matrix Matrix, color Color) *SolidColorShader
NewSolidColorShader 创建一个渲染单一颜色的着色器
func (*SolidColorShader) Fragment ¶
func (shader *SolidColorShader) Fragment(v Vertex) Color
Fragment 片元着色器
func (*SolidColorShader) Vertex ¶
func (shader *SolidColorShader) Vertex(v Vertex) Vertex
Vertex 顶点着色器
type Texture ¶
type Texture interface { // Sample 对纹理进行采样 // u, v: 纹理坐标 // 返回值: 采样得到的颜色 Sample(u, v float64) Color // BilinearSample 使用双线性插值对纹理进行采样 // u, v: 纹理坐标 // 返回值: 采样得到的颜色 BilinearSample(u, v float64) Color }
Texture 纹理接口
func LoadTexture ¶
LoadTexture 加载纹理 path: 纹理文件路径 返回值: 纹理对象和错误信息
func NewImageTexture ¶
NewImageTexture 创建纹理对象 im: 图像对象 返回值: 纹理对象
type TextureShader ¶
TextureShader 渲染纹理
func NewTextureShader ¶
func NewTextureShader(matrix Matrix, texture Texture) *TextureShader
NewTextureShader 创建一个渲染纹理的着色器
func (*TextureShader) Fragment ¶
func (shader *TextureShader) Fragment(v Vertex) Color
Fragment 片元着色器
type Triangle ¶
type Triangle struct {
V1, V2, V3 Vertex
}
Triangle 三角形结构体
func NewTriangleForPoints ¶
NewTriangleForPoints 通过三个点创建新的三角形
type Vector ¶
type Vector struct {
X, Y, Z float64 // X、Y、Z分别表示三维向量的三个分量
}
Vector结构体表示一个三维向量
func (Vector) DistanceSquared ¶
DistanceSquared函数返回两个向量之间距离的平方
func (Vector) LerpDistance ¶
LerpDistance函数返回两个向量之间距离的插值
func (Vector) SegmentDistance ¶
SegmentDistance函数返回点到线段的距离
type VectorW ¶
type VectorW struct {
X, Y, Z, W float64 // X、Y、Z、W分别表示四维向量的四个分量
}
VectorW结构体表示一个四维向量