fauxgl

package module
v0.0.0-...-9f8190b Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: MIT Imports: 18 Imported by: 0

README

FauxGL

3D software rendering in pure Go. No OpenGL, no C extensions, no nothin'.


Dragon

About

It's like OpenGL, but it's not. It's FauxGL.

It doesn't use your graphics card, only your CPU. So it's slow and unsuitable for realtime rendering. But it's still pretty fast. It works the same way OpenGL works - rasterizing.

Features
  • STL, OBJ, PLY, 3DS file formats
  • triangle rasterization
  • vertex and fragment "shaders"
  • view volume clipping
  • face culling
  • alpha blending
  • textures
  • triangle & line meshes
  • depth biasing
  • wireframe rendering
  • built-in shapes (plane, sphere, cube, cylinder, cone)
  • anti-aliasing (via supersampling)
  • voxel rendering
  • parallel processing
Performance

FauxGL uses all of your CPU cores. But none of your GPU.

Rendering the Stanford Dragon shown above (871306 triangles) at 1920x1080px takes about 150 milliseconds on my machine. With 4x4=16x supersampling, it takes about 950 milliseconds. This is the time to render a frame and does not include loading the mesh from disk.

Go Get
go get -u github.com/fogleman/fauxgl
Go Run
cd go/src/github.com/fogleman/fauxgl
go run examples/hello.go
Go Doc

https://godoc.org/github.com/fogleman/fauxgl

Complete Example
package main

import (
	. "github.com/fogleman/fauxgl"
	"github.com/nfnt/resize"
)

const (
	scale  = 1    // optional supersampling
	width  = 1920 // output width in pixels
	height = 1080 // output height in pixels
	fovy   = 30   // vertical field of view in degrees
	near   = 1    // near clipping plane
	far    = 10   // far clipping plane
)

var (
	eye    = V(-3, 1, -0.75)               // camera position
	center = V(0, -0.07, 0)                // view center position
	up     = V(0, 1, 0)                    // up vector
	light  = V(-0.75, 1, 0.25).Normalize() // light direction
	color  = HexColor("#468966")           // object color
)

func main() {
	// load a mesh
	mesh, err := LoadOBJ("examples/dragon.obj")
	if err != nil {
		panic(err)
	}

	// fit mesh in a bi-unit cube centered at the origin
	mesh.BiUnitCube()

	// smooth the normals
	mesh.SmoothNormalsThreshold(Radians(30))

	// create a rendering context
	context := NewContext(width*scale, height*scale)
	context.ClearColorBufferWith(HexColor("#FFF8E3"))

	// create transformation matrix and light direction
	aspect := float64(width) / float64(height)
	matrix := LookAt(eye, center, up).Perspective(fovy, aspect, near, far)

	// use builtin phong shader
	shader := NewPhongShader(matrix, light, eye)
	shader.ObjectColor = color
	context.Shader = shader

	// render
	context.DrawMesh(mesh)

	// downsample image for antialiasing
	image := context.Image()
	image = resize.Resize(width, height, image, resize.Bilinear)

	// save image
	SavePNG("out.png", image)
}

Teapot

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Discard     = Color{}           // 丢弃
	Transparent = Color{}           // 透明
	Black       = Color{0, 0, 0, 1} // 黑色
	White       = Color{1, 1, 1, 1} // 白色
)
View Source
var EmptyBox = Box{}

Functions

func AbsInt

func AbsInt(x int) int

取绝对值

func Clamp

func Clamp(x, lo, hi float64) float64

限制范围

func ClampInt

func ClampInt(x, lo, hi int) int

限制范围

func Degrees

func Degrees(radians float64) float64

弧度转角度

func InterpolateFloats

func InterpolateFloats(v1, v2, v3 float64, b VectorW) float64

插值浮点数

func LoadImage

func LoadImage(path string) (image.Image, error)

加载图片

func ParseFloats

func ParseFloats(items []string) []float64

解析浮点数

func Radians

func Radians(degrees float64) float64

角度转弧度

func Round

func Round(a float64) int

四舍五入

func RoundPlaces

func RoundPlaces(a float64, places int) float64

四舍五入到指定小数位

func SavePNG

func SavePNG(path string, im image.Image) error

保存图片

func SaveSTL

func SaveSTL(path string, mesh *Mesh) error

SaveSTL 将网格保存到 STL 文件中

Types

type Box

type Box struct {
	Min, Max Vector // 最小点和最大点
}

func BoxForBoxes

func BoxForBoxes(boxes []Box) Box

BoxForBoxes 返回一个包含所有盒子的最小盒子

func (Box) Anchor

func (a Box) Anchor(anchor Vector) Vector

Anchor 返回盒子的锚点

func (Box) Center

func (a Box) Center() Vector

Center 返回盒子的中心点

func (Box) Contains

func (a Box) Contains(b Vector) bool

Contains 判断点是否在盒子内

func (Box) ContainsBox

func (a Box) ContainsBox(b Box) bool

ContainsBox 判断盒子是否在盒子内

func (Box) Extend

func (a Box) Extend(b Box) Box

Extend 扩展盒子

func (Box) Intersection

func (a Box) Intersection(b Box) Box

Intersection 返回两个盒子的交集

func (Box) Intersects

func (a Box) Intersects(b Box) bool

Intersects 判断盒子是否相交

func (Box) Offset

func (a Box) Offset(x float64) Box

Offset 偏移盒子

func (Box) Size

func (a Box) Size() Vector

Size 返回盒子的大小

func (Box) Transform

func (a Box) Transform(m Matrix) Box

Transform 变换盒子

func (Box) Translate

func (a Box) Translate(v Vector) Box

Translate 移动盒子

func (Box) Volume

func (a Box) Volume() float64

Volume 返回盒子的体积

type Color

type Color struct {
	R, G, B, A float64 // 颜色的 RGBA 值
}

func Gray

func Gray(x float64) Color

Gray 生成灰度颜色

func HexColor

func HexColor(x string) Color

HexColor 生成十六进制颜色

func InterpolateColors

func InterpolateColors(v1, v2, v3 Color, b VectorW) Color

插值颜色

func MakeColor

func MakeColor(c color.Color) Color

MakeColor 生成颜色

func (Color) Add

func (a Color) Add(b Color) Color

Add 返回两个颜色的和

func (Color) AddScalar

func (a Color) AddScalar(b float64) Color

AddScalar 返回颜色与标量的和

func (Color) Alpha

func (a Color) Alpha(alpha float64) Color

Alpha 返回指定透明度的颜色

func (Color) Div

func (a Color) Div(b Color) Color

Div 返回两个颜色的商

func (Color) DivScalar

func (a Color) DivScalar(b float64) Color

DivScalar 返回颜色与标量的商

func (Color) Lerp

func (a Color) Lerp(b Color, t float64) Color

Lerp 返回两个颜色之间的插值

func (Color) Max

func (a Color) Max(b Color) Color

Max 返回两个颜色的最大值

func (Color) Min

func (a Color) Min(b Color) Color

Min 返回两个颜色的最小值

func (Color) Mul

func (a Color) Mul(b Color) Color

Mul 返回两个颜色的积

func (Color) MulScalar

func (a Color) MulScalar(b float64) Color

MulScalar 返回颜色与标量的积

func (Color) NRGBA

func (c Color) NRGBA() color.NRGBA

NRGBA 返回颜色的 NRGBA 值

func (Color) Opaque

func (a Color) Opaque() Color

Opaque 返回不透明的颜色

func (Color) Pow

func (a Color) Pow(b float64) Color

Pow 返回颜色的幂

func (Color) Sub

func (a Color) Sub(b Color) Color

Sub 返回两个颜色的差

func (Color) SubScalar

func (a Color) SubScalar(b float64) Color

SubScalar 返回颜色与标量的差

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 NewContext

func NewContext(width, height int) *Context

NewContext 创建一个新的渲染上下文

func (*Context) ClearColorBuffer

func (dc *Context) ClearColorBuffer()

ClearColorBuffer 使用清除颜色清除颜色缓冲区

func (*Context) ClearColorBufferWith

func (dc *Context) ClearColorBufferWith(color Color)

ClearColorBufferWith 使用指定颜色清除颜色缓冲区

func (*Context) ClearDepthBuffer

func (dc *Context) ClearDepthBuffer()

ClearDepthBuffer 使用最大值清除深度缓冲区

func (*Context) ClearDepthBufferWith

func (dc *Context) ClearDepthBufferWith(value float64)

ClearDepthBufferWith 使用指定值清除深度缓冲区

func (*Context) DepthImage

func (dc *Context) DepthImage() image.Image

DepthImage 返回深度缓冲区的图像

func (*Context) DrawLine

func (dc *Context) DrawLine(t *Line) RasterizeInfo

DrawLine 绘制线段

func (*Context) DrawLines

func (dc *Context) DrawLines(lines []*Line) RasterizeInfo

DrawLines 绘制线段集合

func (*Context) DrawMesh

func (dc *Context) DrawMesh(mesh *Mesh) RasterizeInfo

DrawMesh 绘制网格

func (*Context) DrawTriangle

func (dc *Context) DrawTriangle(t *Triangle) RasterizeInfo

DrawTriangle 绘制三角形

func (*Context) DrawTriangles

func (dc *Context) DrawTriangles(triangles []*Triangle) RasterizeInfo

DrawTriangles 绘制三角形集合

func (*Context) Image

func (dc *Context) Image() image.Image

Image 返回颜色缓冲区的图像

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

type ImageTexture struct {
	Width  int
	Height int
	Image  image.Image
}

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 Line

type Line struct {
	V1, V2 Vertex
}

Line 结构体表示一条线段

func ClipLine

func ClipLine(l *Line) *Line

剪裁线段

func NewLine

func NewLine(v1, v2 Vertex) *Line

NewLine 用于创建一条线段

func NewLineForPoints

func NewLineForPoints(p1, p2 Vector) *Line

NewLineForPoints 用于创建一条线段

func (*Line) BoundingBox

func (l *Line) BoundingBox() Box

BoundingBox 用于获取线段的包围盒

func (*Line) Transform

func (l *Line) Transform(matrix Matrix)

Transform 用于对线段进行变换

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 Frustum

func Frustum(l, r, b, t, n, f float64) Matrix

Frustum 返回一个透视投影矩阵

func Identity

func Identity() Matrix

Identity 返回一个单位矩阵

func LookAt

func LookAt(eye, center, up Vector) Matrix

LookAt 返回一个观察矩阵

func LookAtDirection

func LookAtDirection(forward, up Vector) Matrix

LookAtDirection 返回一个观察矩阵

func Orient

func Orient(position, size, up Vector, rotation float64) Matrix

Orient 返回一个定位矩阵

func Orthographic

func Orthographic(l, r, b, t, n, f float64) Matrix

Orthographic 返回一个正交投影矩阵

func Perspective

func Perspective(fovy, aspect, near, far float64) Matrix

Perspective 返回一个透视投影矩阵

func Rotate

func Rotate(v Vector, a float64) Matrix

Rotate 返回一个绕向量 v 旋转 a 角度的矩阵

func RotateTo

func RotateTo(a, b Vector) Matrix

RotateTo 返回一个将 a 向量旋转到 b 向量的矩阵

func Scale

func Scale(v Vector) Matrix

Scale 返回一个缩放矩阵

func Screen

func Screen(w, h int) Matrix

Screen 返回一个屏幕矩阵

func Translate

func Translate(v Vector) Matrix

Translate 返回一个平移矩阵

func Viewport

func Viewport(x, y, w, h float64) Matrix

Viewport 返回一个视口矩阵

func (Matrix) Determinant

func (a Matrix) Determinant() float64

Determinant 返回矩阵的行列式

func (Matrix) Frustum

func (m Matrix) Frustum(l, r, b, t, n, f float64) Matrix

Frustum 返回一个透视投影矩阵

func (Matrix) Inverse

func (a Matrix) Inverse() Matrix

Inverse 返回矩阵的逆矩阵

func (Matrix) LookAt

func (m Matrix) LookAt(eye, center, up Vector) Matrix

LookAt 返回一个观察矩阵

func (Matrix) LookAtDirection

func (m Matrix) LookAtDirection(forward, up Vector) Matrix

LookAtDirection 返回一个观察矩阵

func (Matrix) Mul

func (a Matrix) Mul(b Matrix) Matrix

Mul 返回矩阵的乘积

func (Matrix) MulBox

func (a Matrix) MulBox(box Box) Box

MulBox 返回矩阵与包围盒的乘积

func (Matrix) MulDirection

func (a Matrix) MulDirection(b Vector) Vector

MulDirection 返回矩阵与方向向量的乘积

func (Matrix) MulPosition

func (a Matrix) MulPosition(b Vector) Vector

MulPosition 返回矩阵与位置向量的乘积

func (Matrix) MulPositionW

func (a Matrix) MulPositionW(b Vector) VectorW

MulPositionW 返回矩阵与位置向量的乘积

func (Matrix) MulScalar

func (a Matrix) MulScalar(b float64) Matrix

MulScalar 返回矩阵的标量积

func (Matrix) Orthographic

func (m Matrix) Orthographic(l, r, b, t, n, f float64) Matrix

Orthographic 返回一个正交投影矩阵

func (Matrix) Perspective

func (m Matrix) Perspective(fovy, aspect, near, far float64) Matrix

Perspective 返回一个透视投影矩阵

func (Matrix) Rotate

func (m Matrix) Rotate(v Vector, a float64) Matrix

Rotate 返回一个绕向量 v 旋转 a 角度的矩阵

func (Matrix) RotateTo

func (m Matrix) RotateTo(a, b Vector) Matrix

RotateTo 返回一个将 a 向量旋转到 b 向量的矩阵

func (Matrix) Scale

func (m Matrix) Scale(v Vector) Matrix

Scale 返回一个缩放矩阵

func (Matrix) Screen

func (m Matrix) Screen(w, h int) Matrix

Screen 返回一个屏幕矩阵

func (Matrix) Translate

func (m Matrix) Translate(v Vector) Matrix

Translate 返回一个平移矩阵

func (Matrix) Transpose

func (a Matrix) Transpose() Matrix

Transpose 返回矩阵的转置矩阵

func (Matrix) Viewport

func (m Matrix) Viewport(x, y, w, h float64) Matrix

Viewport 返回一个视口矩阵

type Mesh

type Mesh struct {
	Triangles []*Triangle // 三角形列表
	Lines     []*Line     // 线列表
	// contains filtered or unexported fields
}

Mesh 网格

func Load3DS

func Load3DS(filename string) (*Mesh, error)

Load3DS 从3DS文件中加载网格

func LoadMesh

func LoadMesh(path string) (*Mesh, error)

加载模型

func LoadOBJ

func LoadOBJ(path string) (*Mesh, error)

LoadOBJ 从文件中加载OBJ模型

func LoadPLY

func LoadPLY(path string) (*Mesh, error)

LoadPLY 从PLY文件中加载网格

func LoadSTL

func LoadSTL(path string) (*Mesh, error)

LoadSTL 从 STL 文件中加载网格

func NewCone

func NewCone(step int, capped bool) *Mesh

NewCone函数返回一个圆锥网格

func NewCube

func NewCube() *Mesh

NewCube函数返回一个立方体网格

func NewCubeForBox

func NewCubeForBox(box Box) *Mesh

NewCubeForBox函数返回一个盒子网格

func NewCubeOutlineForBox

func NewCubeOutlineForBox(box Box) *Mesh

NewCubeOutlineForBox函数返回一个盒子的轮廓线网格

func NewCylinder

func NewCylinder(step int, capped bool) *Mesh

NewCylinder函数返回一个圆柱网格

func NewEmptyMesh

func NewEmptyMesh() *Mesh

NewEmptyMesh 创建一个空网格

func NewIcosahedron

func NewIcosahedron() *Mesh

NewIcosahedron函数返回一个正二十面体网格

func NewLatLngSphere

func NewLatLngSphere(latStep, lngStep int) *Mesh

NewLatLngSphere函数返回一个经纬度球网格

func NewLineMesh

func NewLineMesh(lines []*Line) *Mesh

NewLineMesh 创建一个新线网格

func NewMesh

func NewMesh(triangles []*Triangle, lines []*Line) *Mesh

NewMesh 创建一个新网格

func NewPlane

func NewPlane() *Mesh

NewPlane函数返回一个平面网格

func NewSphere

func NewSphere(detail int) *Mesh

NewSphere函数返回一个球体网格

func NewTriangleMesh

func NewTriangleMesh(triangles []*Triangle) *Mesh

NewTriangleMesh 创建一个新三角形网格

func NewVoxelMesh

func NewVoxelMesh(voxels []Voxel) *Mesh

NewVoxelMesh 根据体素创建网格

func (*Mesh) Add

func (a *Mesh) Add(b *Mesh)

Add 添加网格

func (*Mesh) BiUnitCube

func (m *Mesh) BiUnitCube() Matrix

BiUnitCube 双单位立方体

func (*Mesh) BoundingBox

func (m *Mesh) BoundingBox() Box

BoundingBox 计算网格包围盒

func (*Mesh) Center

func (m *Mesh) Center() Matrix

Center 居中网格

func (*Mesh) Copy

func (m *Mesh) Copy() *Mesh

Copy 复制网格

func (*Mesh) FitInside

func (m *Mesh) FitInside(box Box, anchor Vector) Matrix

FitInside 适应盒子

func (*Mesh) MoveTo

func (m *Mesh) MoveTo(position, anchor Vector) Matrix

MoveTo 移动网格

func (*Mesh) ReverseWinding

func (m *Mesh) ReverseWinding()

ReverseWinding 反转网格

func (*Mesh) SaveSTL

func (m *Mesh) SaveSTL(path string) error

SaveSTL 保存网格为STL文件

func (*Mesh) SetColor

func (m *Mesh) SetColor(c Color)

SetColor 设置网格颜色

func (*Mesh) SharpEdges

func (m *Mesh) SharpEdges(angleThreshold float64) *Mesh

SharpEdges 提取网格锐边

func (*Mesh) Silhouette

func (m *Mesh) Silhouette(eye Vector, offset float64) *Mesh

Silhouette 提取网格轮廓

func (*Mesh) Simplify

func (m *Mesh) Simplify(factor float64)

Simplify 简化网格

func (*Mesh) SmoothNormals

func (m *Mesh) SmoothNormals()

SmoothNormals 平滑网格法线

func (*Mesh) SmoothNormalsThreshold

func (m *Mesh) SmoothNormalsThreshold(radians float64)

SmoothNormalsThreshold 平滑网格法线

func (*Mesh) SplitTriangles

func (m *Mesh) SplitTriangles(maxEdgeLength float64)

SplitTriangles 分割三角形

func (*Mesh) SurfaceArea

func (m *Mesh) SurfaceArea() float64

SurfaceArea 计算网格表面积

func (*Mesh) Transform

func (m *Mesh) Transform(matrix Matrix)

Transform 变换网格

func (*Mesh) UnitCube

func (m *Mesh) UnitCube() Matrix

UnitCube 单位立方体

func (*Mesh) Volume

func (m *Mesh) Volume() float64

Volume 计算网格体积

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 创建一个实现冯氏着色法的着色器

func (*PhongShader) Fragment

func (shader *PhongShader) Fragment(v Vertex) Color

Fragment 片元着色器

func (*PhongShader) Vertex

func (shader *PhongShader) Vertex(v Vertex) Vertex

Vertex 顶点着色器

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 Shader

type Shader interface {
	Vertex(Vertex) Vertex  // 顶点着色器
	Fragment(Vertex) Color // 片元着色器
}

Shader 接口

type SolidColorShader

type SolidColorShader struct {
	Matrix Matrix // 变换矩阵
	Color  Color  // 颜色
}

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

func LoadTexture(path string) (Texture, error)

LoadTexture 加载纹理 path: 纹理文件路径 返回值: 纹理对象和错误信息

func NewImageTexture

func NewImageTexture(im image.Image) Texture

NewImageTexture 创建纹理对象 im: 图像对象 返回值: 纹理对象

type TextureShader

type TextureShader struct {
	Matrix  Matrix
	Texture Texture
}

TextureShader 渲染纹理

func NewTextureShader

func NewTextureShader(matrix Matrix, texture Texture) *TextureShader

NewTextureShader 创建一个渲染纹理的着色器

func (*TextureShader) Fragment

func (shader *TextureShader) Fragment(v Vertex) Color

Fragment 片元着色器

func (*TextureShader) Vertex

func (shader *TextureShader) Vertex(v Vertex) Vertex

Vertex 顶点着色器

type Triangle

type Triangle struct {
	V1, V2, V3 Vertex
}

Triangle 三角形结构体

func ClipTriangle

func ClipTriangle(t *Triangle) []*Triangle

剪裁三角形

func NewTriangle

func NewTriangle(v1, v2, v3 Vertex) *Triangle

NewTriangle 创建新的三角形

func NewTriangleForPoints

func NewTriangleForPoints(p1, p2, p3 Vector) *Triangle

NewTriangleForPoints 通过三个点创建新的三角形

func (*Triangle) Area

func (t *Triangle) Area() float64

Area 返回三角形面积

func (*Triangle) BoundingBox

func (t *Triangle) BoundingBox() Box

BoundingBox 返回三角形的包围盒

func (*Triangle) FixNormals

func (t *Triangle) FixNormals()

FixNormals 修正三角形法向量

func (*Triangle) IsDegenerate

func (t *Triangle) IsDegenerate() bool

IsDegenerate 判断三角形是否退化

func (*Triangle) Normal

func (t *Triangle) Normal() Vector

Normal 返回三角形法向量

func (*Triangle) ReverseWinding

func (t *Triangle) ReverseWinding()

ReverseWinding 反转三角形的顶点顺序

func (*Triangle) SetColor

func (t *Triangle) SetColor(c Color)

SetColor 设置三角形的颜色

func (*Triangle) Transform

func (t *Triangle) Transform(matrix Matrix)

Transform 对三角形进行变换

type VOXChunk

type VOXChunk struct {
	ID            [4]byte // 块ID
	ContentBytes  int32   // 块内容大小
	ChildrenBytes int32   // 子块大小
}

VOXChunk VOX文件块

type VOXHeader

type VOXHeader struct {
	Magic   [4]byte // 魔数
	Version int32   // 版本号
}

VOXHeader VOX文件头部

type VOXVoxel

type VOXVoxel struct {
	X, Y, Z, I uint8 // 体素坐标和颜色索引
}

VOXVoxel VOX体素

type Vector

type Vector struct {
	X, Y, Z float64 // X、Y、Z分别表示三维向量的三个分量
}

Vector结构体表示一个三维向量

func InterpolateVectors

func InterpolateVectors(v1, v2, v3 Vector, b VectorW) Vector

插值向量

func LatLngToXYZ

func LatLngToXYZ(lat, lng float64) Vector

经纬度转空间坐标

func RandomUnitVector

func RandomUnitVector() Vector

RandomUnitVector函数返回一个随机的单位向量

func V

func V(x, y, z float64) Vector

V函数返回一个新的Vector

func (Vector) Abs

func (a Vector) Abs() Vector

Abs函数返回向量的绝对值

func (Vector) Add

func (a Vector) Add(b Vector) Vector

Add函数返回两个向量的和

func (Vector) AddScalar

func (a Vector) AddScalar(b float64) Vector

AddScalar函数返回向量加上标量的结果

func (Vector) Ceil

func (a Vector) Ceil() Vector

Ceil函数返回向量的上取整

func (Vector) Cross

func (a Vector) Cross(b Vector) Vector

Cross函数返回两个向量的叉积

func (Vector) Distance

func (a Vector) Distance(b Vector) float64

Distance函数返回两个向量之间的距离

func (Vector) DistanceSquared

func (a Vector) DistanceSquared(b Vector) float64

DistanceSquared函数返回两个向量之间距离的平方

func (Vector) Div

func (a Vector) Div(b Vector) Vector

Div函数返回两个向量的商

func (Vector) DivScalar

func (a Vector) DivScalar(b float64) Vector

DivScalar函数返回向量除以标量的结果

func (Vector) Dot

func (a Vector) Dot(b Vector) float64

Dot函数返回两个向量的点积

func (Vector) Floor

func (a Vector) Floor() Vector

Floor函数返回向量的下取整

func (Vector) IsDegenerate

func (a Vector) IsDegenerate() bool

IsDegenerate函数判断向量是否退化

func (Vector) Length

func (a Vector) Length() float64

Length函数返回向量的长度

func (Vector) LengthSquared

func (a Vector) LengthSquared() float64

LengthSquared函数返回向量的长度的平方

func (Vector) Lerp

func (a Vector) Lerp(b Vector, t float64) Vector

Lerp函数返回两个向量之间的插值

func (Vector) LerpDistance

func (a Vector) LerpDistance(b Vector, d float64) Vector

LerpDistance函数返回两个向量之间距离的插值

func (Vector) Less

func (a Vector) Less(b Vector) bool

Less函数比较两个向量的大小

func (Vector) Max

func (a Vector) Max(b Vector) Vector

Max函数返回两个向量的最大值

func (Vector) MaxComponent

func (a Vector) MaxComponent() float64

MaxComponent函数返回向量的最大分量

func (Vector) Min

func (a Vector) Min(b Vector) Vector

Min函数返回两个向量的最小值

func (Vector) MinComponent

func (a Vector) MinComponent() float64

MinComponent函数返回向量的最小分量

func (Vector) Mod

func (a Vector) Mod(b Vector) Vector

Mod函数返回两个向量的模

func (Vector) Mul

func (a Vector) Mul(b Vector) Vector

Mul函数返回两个向量的积

func (Vector) MulScalar

func (a Vector) MulScalar(b float64) Vector

MulScalar函数返回向量乘以标量的结果

func (Vector) Negate

func (a Vector) Negate() Vector

Negate函数返回向量的相反向量

func (Vector) Normalize

func (a Vector) Normalize() Vector

Normalize函数返回向量的单位向量

func (Vector) Perpendicular

func (a Vector) Perpendicular() Vector

Perpendicular函数返回向量的垂直向量

func (Vector) Reflect

func (i Vector) Reflect(n Vector) Vector

Reflect函数返回向量在法向量上的反射向量

func (Vector) Round

func (a Vector) Round() Vector

Round函数返回向量的四舍五入

func (Vector) RoundPlaces

func (a Vector) RoundPlaces(n int) Vector

RoundPlaces函数返回向量的四舍五入到指定小数位数

func (Vector) SegmentDistance

func (p Vector) SegmentDistance(v Vector, w Vector) float64

SegmentDistance函数返回点到线段的距离

func (Vector) Sub

func (a Vector) Sub(b Vector) Vector

Sub函数返回两个向量的差

func (Vector) SubScalar

func (a Vector) SubScalar(b float64) Vector

SubScalar函数返回向量减去标量的结果

func (Vector) VectorW

func (a Vector) VectorW() VectorW

VectorW函数返回一个新的VectorW

type VectorW

type VectorW struct {
	X, Y, Z, W float64 // X、Y、Z、W分别表示四维向量的四个分量
}

VectorW结构体表示一个四维向量

func Barycentric

func Barycentric(p1, p2, p3, p Vector) VectorW

计算重心坐标

func InterpolateVectorWs

func InterpolateVectorWs(v1, v2, v3, b VectorW) VectorW

插值向量W

func (VectorW) Add

func (a VectorW) Add(b VectorW) VectorW

Add函数返回两个VectorW的和

func (VectorW) DivScalar

func (a VectorW) DivScalar(b float64) VectorW

DivScalar函数返回VectorW除以标量的结果

func (VectorW) Dot

func (a VectorW) Dot(b VectorW) float64

Dot函数返回两个VectorW的点积

func (VectorW) MulScalar

func (a VectorW) MulScalar(b float64) VectorW

MulScalar函数返回VectorW乘以标量的结果

func (VectorW) Outside

func (a VectorW) Outside() bool

Outside函数判断VectorW是否在超出范围

func (VectorW) Sub

func (a VectorW) Sub(b VectorW) VectorW

Sub函数返回两个VectorW的差

func (VectorW) Vector

func (a VectorW) Vector() Vector

Vector函数返回VectorW的Vector部分

type Vertex

type Vertex struct {
	Position Vector  // 位置
	Normal   Vector  // 法向量
	Texture  Vector  // 纹理坐标
	Color    Color   // 颜色
	Output   VectorW // 输出
}

Vertex 顶点结构体

func InterpolateVertexes

func InterpolateVertexes(v1, v2, v3 Vertex, b VectorW) Vertex

插值顶点

func (Vertex) Outside

func (a Vertex) Outside() bool

判断是否在外部

type Voxel

type Voxel struct {
	X, Y, Z int   // 体素坐标
	Color   Color // 体素颜色
}

Voxel 体素

func LoadVOX

func LoadVOX(path string) ([]Voxel, error)

LoadVOX 从文件中读取voxel数据

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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