Esempio n. 1
0
func (self *ArrayVoxelField) AddValue(from, to v.Vector3i, eval VoxelFunc) {
	from.SubIP(v.Vector3i{self.translateX, self.translateY, self.translateZ})
	to.SubIP(v.Vector3i{self.translateX, self.translateY, self.translateZ})

	for z := from.Z; z < to.Z; z++ {
		for y := from.Y; y < to.Y; y++ {
			for x := from.X; x < to.X; x++ {
				if x < 0 || y < 0 || z < 0 ||
					x >= self.sizeX || y >= self.sizeY || z >= self.sizeZ {
					continue
				}

				id := x + y*self.sizeX + z*self.sizeX*self.sizeY
				v := int(self.data[id]) + eval(x+self.translateX, y+self.translateY, z+self.translateZ)

				if v < 0 {
					v = 0
				} else if v > 255 {
					v = 255
				}
				self.data[id] = byte(v)
			}
		}
	}
}
Esempio n. 2
0
func (s *VoxelsMesh) UpdatePoint(point v.Vector3i) {
	b := point.Div3I(s.config.BlockSize)
	b.Sub(s.blockStart)

	baSize := s.config.BlockArraySize
	if b.X < 0 || b.X >= baSize.X ||
		b.Y < 0 || b.Y >= baSize.Y ||
		b.Z < 0 || b.Z >= baSize.Z {
		return
	}
	id := b.X + b.Y*baSize.X + b.Z*baSize.X*baSize.Y
	s.blockArray[id].State = VMB_DIRTY
}