-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlockHandler.py
More file actions
73 lines (54 loc) · 2 KB
/
Copy pathBlockHandler.py
File metadata and controls
73 lines (54 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from time import perf_counter
import numpy as np
from glm import ivec3, vec3, length
from DefaultBlockHandler import DefaultBlockLines, CentreBlock
from VboHandler import VBOChunkBlock
from OpenGL.GL import glLineWidth
from ChunkHandler import SerializeBlockData
class HighlightBlock:
def __init__(self, shader):
self.chunkId = 0
self.chunkPos = ivec3(0, 0, 0)
self.show = False
self.VBOBlock = VBOChunkBlock(
shader,
DefaultBlockLines(),
self,
isChunk=False
)
def draw(self):
if self.show:
glLineWidth(3)
self.VBOBlock.draw()
glLineWidth(1)
def serialize(self, skip=False, useCache=False, requireUpdate=False):
def serializeData(pos, id):
# x |
# y << 4 |
# z << 4 + 8 |
# zData[0] << 4 + 8 + 4 |
# zData[1] << 4 + 8 + 4 + 7
# = BlockId
# ---- | -------- | ---- | ------- | ------
# X | Y | Z | Id | FaceMask
return np.array([
SerializeBlockData(pos, (0b1111111, 0b111111)),
id
], dtype=np.uint32), 1
if skip:
return np.array([]), 0
#print(f"Serializing Highlight Block", end=" ")
#s = perf_counter()
serializedData, length = serializeData(self.chunkPos, self.chunkId)
#e = perf_counter()
#print("Finished", round((e-s)*1000, 3))
#print(getsizeof(serializedData), getsizeof(self.ChunkData), length)
return serializedData, length
def ClosestFace(point: vec3):
distanceD = {length(point - centre): i for i, centre in enumerate(CentreBlock.centres)}
minDist = min(distanceD.keys())
return distanceD[minDist]
def ClosestFaceSides(point: vec3):
distanceD = {length(point - centre): i for i, centre in enumerate(CentreBlock.centres) if i >= 2}
minDist = min(distanceD.keys())
return distanceD[minDist]