当前位置: 首页>>代码示例>>Golang>>正文


Golang Scene.Add方法代码示例

本文整理汇总了Golang中github.com/fogleman/ln/ln.Scene.Add方法的典型用法代码示例。如果您正苦于以下问题:Golang Scene.Add方法的具体用法?Golang Scene.Add怎么用?Golang Scene.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/fogleman/ln/ln.Scene的用法示例。


在下文中一共展示了Scene.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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()
}
开发者ID:fogleman,项目名称:ln,代码行数:28,代码来源:cones.go

示例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()
}
开发者ID:fogleman,项目名称:ln,代码行数:28,代码来源:beads.go

示例3: 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()
}
开发者ID:fogleman,项目名称:ln,代码行数:29,代码来源:test.go

示例4: 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)
}
开发者ID:fogleman,项目名称:ln,代码行数:27,代码来源:example0.go

示例5: 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)
}
开发者ID:mantyr,项目名称:mol,代码行数:33,代码来源:model.go

示例6: 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()
}
开发者ID:fogleman,项目名称:ln,代码行数:27,代码来源:skyscrapers.go

示例7: 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)
}
开发者ID:fogleman,项目名称:ln,代码行数:11,代码来源:earth.go

示例8: 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()
}
开发者ID:fogleman,项目名称:ln,代码行数:14,代码来源:function.go

示例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)
}
开发者ID:fogleman,项目名称:ln,代码行数:17,代码来源:suzanne.go

示例10: 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()
}
开发者ID:fogleman,项目名称:ln,代码行数:17,代码来源:mountain.go

示例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)
}
开发者ID:fogleman,项目名称:ln,代码行数:18,代码来源:example1.go

示例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)
}
开发者ID:fogleman,项目名称:ln,代码行数:20,代码来源:outline.go

示例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()
}
开发者ID:fogleman,项目名称:ln,代码行数:20,代码来源:slices.go

示例14: Paths

func (m *Molecule) Paths(width, height float64) ln.Paths {
	scene := ln.Scene{}

	camera := m.Camera()
	eye := camera.Eye.ln()
	center := camera.Center.ln()
	up := camera.Up.ln()
	fovy := camera.Fovy

	spheres, cylinders := m.Solids()

	for _, s := range spheres {
		scene.Add(ln.NewOutlineSphere(eye, up, s.Center.ln(), s.Radius*0.5))
	}

	for _, c := range cylinders {
		scene.Add(ln.NewTransformedOutlineCylinder(eye, up, c.A.ln(), c.B.ln(), c.Radius))
	}

	return scene.Render(eye, center, up, width, height, fovy, 0.1, 100, 0.01)
}
开发者ID:fogleman,项目名称:mol,代码行数:21,代码来源:model.go

示例15: 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()
}
开发者ID:fogleman,项目名称:ln,代码行数:22,代码来源:voxelize.go


注:本文中的github.com/fogleman/ln/ln.Scene.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。