Esempio n. 1
0
func NewChunk(parentObject *engine.Object, size int, ts *Tileset) *Chunk {
	chk := &Chunk{
		Size:    size,
		Tileset: ts,
		Data:    make([]*Voxel, size*size*size),

		vao: render.CreateVertexArray(),
		vbo: render.CreateVertexBuffer(),
	}

	chk.ComponentBase = engine.NewComponent(parentObject, chk)
	return chk
}
Esempio n. 2
0
func NewPlacementGrid(parentObject *engine.Object) *PlacementGrid {
	pg := &PlacementGrid{
		mesh:  geometry.CreateLines(),
		Chunk: nil,
	}
	pg.ComponentBase = engine.NewComponent(parentObject, pg)

	// find chunk
	obj, exists := parentObject.GetComponent(pg.Chunk)
	if !exists {
		panic("no chunk component")
	}
	chunk := obj.(*ColorChunk)

	// compute grid mesh
	pg.Chunk = chunk
	pg.Y = chunk.Size - 1
	pg.Compute()

	return pg
}