本文整理匯總了Golang中github.com/fogleman/ln/ln.Scene類的典型用法代碼示例。如果您正苦於以下問題:Golang Scene類的具體用法?Golang Scene怎麽用?Golang Scene使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Scene類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
scene := ln.Scene{}
n := 20
for x := -n; x <= n; x++ {
for y := -n; y <= n; y++ {
// z := rand.Float64() * 3
// scene.Add(cube(float64(x), float64(y), float64(z)))
// scene.Add(cube(float64(x), float64(y), float64(z+1)))
// scene.Add(cube(float64(x), float64(y), float64(z+2)))
}
}
n = 8
for x := -n; x <= n; x++ {
for y := -n; y <= n; y++ {
scene.Add(ln.NewSphere(ln.Vector{float64(x), float64(y), 0}, 0.45))
}
}
// scene.Add(ln.NewSphere(ln.Vector{0, 4, 0}, 4))
// scene.Add(ln.NewSphere(ln.Vector{-7, 0, 0}, 4))
// scene.Add(ln.NewSphere(ln.Vector{7, 0, 0}, 4))
eye := ln.Vector{8, 8, 1}
center := ln.Vector{0, 0, -4.25}
up := ln.Vector{0, 0, 1}
width := 1024.0
height := 1024.0
paths := scene.Render(eye, center, up, width, height, 50, 0.1, 100, 0.01)
paths.WriteToPNG("out.png", width, height)
// paths.Print()
}
示例2: main
func main() {
rand.Seed(1211)
eye := ln.Vector{8, 8, 8}
center := ln.Vector{0, 0, 0}
up := ln.Vector{0, 0, 1}
scene := ln.Scene{}
for a := 0; a < 50; a++ {
n := 200
xs := LowPassNoise(n, 0.3, 4)
ys := LowPassNoise(n, 0.3, 4)
zs := LowPassNoise(n, 0.3, 4)
ss := LowPassNoise(n, 0.3, 4)
position := ln.Vector{}
for i := 0; i < n; i++ {
sphere := ln.NewOutlineSphere(eye, up, position, 0.1)
scene.Add(sphere)
s := (ss[i]+1)/2*0.1 + 0.01
v := ln.Vector{xs[i], ys[i], zs[i]}.Normalize().MulScalar(s)
position = position.Add(v)
}
}
width := 380.0 * 5
height := 315.0 * 5
fovy := 50.0
paths := scene.Render(eye, center, up, width, height, fovy, 0.1, 100, 0.01)
paths.WriteToPNG("out.png", width, height)
paths.Print()
}
示例3: main
func main() {
// create a scene and add a single cube
scene := ln.Scene{}
scene.Add(ln.NewCube(ln.Vector{-1, -1, -1}, ln.Vector{1, 1, 1}))
// define camera parameters
eye := ln.Vector{4, 3, 2} // camera position
center := ln.Vector{0, 0, 0} // camera looks at
up := ln.Vector{0, 0, 1} // up direction
// define rendering parameters
width := 1024.0 // rendered width
height := 1024.0 // rendered height
fovy := 50.0 // vertical field of view, degrees
znear := 0.1 // near z plane
zfar := 10.0 // far z plane
step := 0.01 // how finely to chop the paths for visibility testing
// compute 2D paths that depict the 3D scene
paths := scene.Render(eye, center, up, width, height, fovy, znear, zfar, step)
// save the result as a png
paths.WriteToPNG("out.png", width, height)
// save the result as an svg
paths.WriteToSVG("out.svg", width, height)
}
示例4: main
func main() {
scene := ln.Scene{}
n := 15
for x := -n; x <= n; x++ {
for y := -n; y <= n; y++ {
p := rand.Float64()*0.25 + 0.2
dx := rand.Float64()*0.5 - 0.25
dy := rand.Float64()*0.5 - 0.25
fx := float64(x) + dx*0
fy := float64(y) + dy*0
fz := rand.Float64()*3 + 1
shape := ln.NewCube(ln.Vector{fx - p, fy - p, 0}, ln.Vector{fx + p, fy + p, fz})
if x == 2 && y == 1 {
continue
}
scene.Add(shape)
}
}
eye := ln.Vector{1.75, 1.25, 6}
center := ln.Vector{0, 0, 0}
up := ln.Vector{0, 0, 1}
width := 1024.0
height := 1024.0
paths := scene.Render(eye, center, up, width, height, 100, 0.1, 100, 0.01)
paths.WriteToPNG("out.png", width, height)
// paths.Print()
}
示例5: run
func run(seed int) {
// fmt.Println(seed)
rand.Seed(int64(seed))
eye := ln.Vector{}
center := ln.Vector{0.5, 0, 8}
up := ln.Vector{0, 0, 1}
scene := ln.Scene{}
n := 9.0
points := pt.PoissonDisc(-n, -n, n, n, 2, 32)
for _, p := range points {
z := rand.Float64()*5 + 20
v0 := ln.Vector{p.X, p.Y, 0}
v1 := ln.Vector{p.X, p.Y, z}
if v0.Distance(eye) < 1 {
continue
}
c := ln.NewTransformedOutlineCone(eye, up, v0, v1, z/64)
tree := Tree{c, v0, v1}
scene.Add(&tree)
}
width := 2048.0
height := 2048.0
fovy := 90.0
paths := scene.Render(eye, center, up, width, height, fovy, 0.1, 100, 0.1)
path := fmt.Sprintf("out%d.png", seed)
paths.WriteToPNG(path, width, height)
paths.Print()
}
示例6: Render
func Render(lines ln.Paths, matrix ln.Matrix) ln.Paths {
scene := ln.Scene{}
sphere := ln.NewSphere(ln.Vector{}, 1)
earth := Earth{sphere, lines}
shape := ln.NewTransformedShape(&earth, matrix)
scene.Add(shape)
eye := ln.LatLngToXYZ(35.7806, -78.6389, 1).Normalize().MulScalar(2.46)
center := ln.Vector{}
up := ln.Vector{0, 0, 1}
return scene.Render(eye, center, up, 60, 1, 0.1, 100, 0.01)
}
示例7: main
func main() {
scene := ln.Scene{}
box := ln.Box{ln.Vector{-2, -2, -4}, ln.Vector{2, 2, 2}}
scene.Add(ln.NewFunction(function, box, ln.Below))
eye := ln.Vector{3, 0, 3}
center := ln.Vector{1.1, 0, 0}
up := ln.Vector{0, 0, 1}
width := 1024.0
height := 1024.0
paths := scene.Render(eye, center, up, width, height, 50, 0.1, 100, 0.01)
paths.WriteToPNG("out.png", width, height)
paths.WriteToSVG("out.svg", width, height)
// paths.Print()
}
示例8: main
func main() {
blocks := load("examples/mountain.csv")
fmt.Println(len(blocks))
scene := ln.Scene{}
size := ln.Vector{0.5, 0.5, 0.5}
for _, v := range blocks {
scene.Add(ln.NewCube(v.Sub(size), v.Add(size)))
}
eye := ln.Vector{90, -90, 70}
center := ln.Vector{0, 0, -15}
up := ln.Vector{0, 0, 1}
width := 1920.0
height := 1080.0
paths := scene.Render(eye, center, up, width, height, 50, 0.1, 1000, 0.1)
paths.WriteToPNG("out.png", width, height)
// paths.Print()
}
示例9: main
func main() {
scene := ln.Scene{}
mesh, err := ln.LoadOBJ("examples/suzanne.obj")
if err != nil {
panic(err)
}
mesh.UnitCube()
scene.Add(ln.NewTransformedShape(mesh, ln.Rotate(ln.Vector{0, 1, 0}, 0.5)))
// scene.Add(mesh)
eye := ln.Vector{-0.5, 0.5, 2}
center := ln.Vector{}
up := ln.Vector{0, 1, 0}
width := 1024.0
height := 1024.0
paths := scene.Render(eye, center, up, width, height, 35, 0.1, 100, 0.01)
paths.WriteToPNG("out.png", width, height)
}
示例10: Paths
func (m *Molecule) Paths(width, height float64) ln.Paths {
scene := ln.Scene{}
nodes := make([]ln.Vector, len(m.Atoms))
for i, atom := range m.Atoms {
nodes[i] = ln.Vector{atom.X, atom.Y, atom.Z}
}
mid := ln.BoxForVectors(nodes).Center()
for i, node := range nodes {
nodes[i] = node.Sub(mid)
}
eye := CameraPosition(nodes)
center := ln.Vector{}
fov := CameraFOV(nodes, eye, center)
up := ln.Vector{0, 0, 1}
for i, node := range nodes {
atom := m.Atoms[i]
radius := float64(AtomicRadii[atom.Symbol]) / 100
scene.Add(ln.NewOutlineSphere(eye, up, node, radius*0.5))
}
for _, bond := range m.Bonds {
v0 := nodes[bond.I]
v1 := nodes[bond.J]
r := float64(bond.Type) / 16
scene.Add(ln.NewTransformedOutlineCylinder(eye, up, v0, v1, r))
}
return scene.Render(eye, center, up, width, height, fov, 0.1, 100, 0.01)
}
示例11: main
func main() {
scene := ln.Scene{}
for x := -2; x <= 2; x++ {
for y := -2; y <= 2; y++ {
z := rand.Float64()
scene.Add(cube(float64(x), float64(y), z))
}
}
eye := ln.Vector{6, 5, 3}
center := ln.Vector{0, 0, 0}
up := ln.Vector{0, 0, 1}
width := 1920.0
height := 1200.0
fovy := 30.0
paths := scene.Render(eye, center, up, width, height, fovy, 0.1, 100, 0.01)
paths.WriteToPNG("out.png", width, height)
paths.WriteToSVG("out.svg", width, height)
}
示例12: main
func main() {
eye := ln.Vector{8, 8, 8}
center := ln.Vector{0, 0, 0}
up := ln.Vector{0, 0, 1}
scene := ln.Scene{}
n := 10
for x := -n; x <= n; x++ {
for y := -n; y <= n; y++ {
z := rand.Float64() * 3
v := ln.Vector{float64(x), float64(y), z}
sphere := ln.NewOutlineSphere(eye, up, v, 0.45)
scene.Add(sphere)
}
}
width := 1920.0
height := 1200.0
fovy := 50.0
paths := scene.Render(eye, center, up, width, height, fovy, 0.1, 100, 0.01)
paths.WriteToPNG("out.png", width, height)
}
示例13: main
func main() {
scene := ln.Scene{}
mesh, err := ln.LoadBinarySTL("bowser.stl")
// mesh, err := ln.LoadOBJ("../pt/examples/bunny.obj")
if err != nil {
panic(err)
}
mesh.FitInside(ln.Box{ln.Vector{-1, -1, -1}, ln.Vector{1, 1, 1}}, ln.Vector{0.5, 0.5, 0.5})
scene.Add(&Shape{*mesh})
// scene.Add(mesh)
eye := ln.Vector{-2, 2, 1}
center := ln.Vector{0, 0, 0}
up := ln.Vector{0, 0, 1}
width := 1024.0 * 2
height := 1024.0 * 2
paths := scene.Render(eye, center, up, width, height, 50, 0.1, 100, 0.01)
paths.WriteToPNG("out.png", width, height)
// paths.WriteToSVG("out.svg", width, height)
// paths.Print()
}
示例14: main
func main() {
scene := ln.Scene{}
mesh, err := ln.LoadBinarySTL("bowser.stl")
// mesh, err := ln.LoadOBJ("../pt/examples/bunny.obj")
if err != nil {
panic(err)
}
mesh.FitInside(ln.Box{ln.Vector{-1, -1, -1}, ln.Vector{1, 1, 1}}, ln.Vector{0.5, 0.5, 0.5})
cubes := mesh.Voxelize(1.0 / 64)
for _, cube := range cubes {
scene.Add(cube)
}
eye := ln.Vector{-1, -2, 0}
center := ln.Vector{0, 0, 0}
up := ln.Vector{0, 0, 1}
width := 1024.0 * 2
height := 1024.0 * 2
paths := scene.Render(eye, center, up, width, height, 60, 0.1, 100, 0.01)
paths.WriteToPNG("out.png", width, height)
// paths.WriteToSVG("out.svg", width, height)
// paths.Print()
}
示例15: main
func main() {
shape := ln.NewDifference(
ln.NewIntersection(
ln.NewSphere(ln.Vector{}, 1),
ln.NewCube(ln.Vector{-0.8, -0.8, -0.8}, ln.Vector{0.8, 0.8, 0.8}),
),
ln.NewCylinder(0.4, -2, 2),
ln.NewTransformedShape(ln.NewCylinder(0.4, -2, 2), ln.Rotate(ln.Vector{1, 0, 0}, ln.Radians(90))),
ln.NewTransformedShape(ln.NewCylinder(0.4, -2, 2), ln.Rotate(ln.Vector{0, 1, 0}, ln.Radians(90))),
)
for i := 0; i < 90; i += 2 {
fmt.Println(i)
scene := ln.Scene{}
m := ln.Rotate(ln.Vector{0, 0, 1}, ln.Radians(float64(i)))
scene.Add(ln.NewTransformedShape(shape, m))
eye := ln.Vector{0, 6, 2}
center := ln.Vector{0, 0, 0}
up := ln.Vector{0, 0, 1}
width := 750.0
height := 750.0
paths := scene.Render(eye, center, up, width, height, 20, 0.1, 100, 0.01)
paths.WriteToPNG(fmt.Sprintf("out%03d.png", i), width, height)
}
}