-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvertex.py
More file actions
73 lines (57 loc) · 1.91 KB
/
Copy pathvertex.py
File metadata and controls
73 lines (57 loc) · 1.91 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
# vertex.py
from enum import Enum
class VertexSpace(Enum):
"""
Enumerates the coordinate space a vertex is currently in.
This makes pipeline stages explicit and type-safe.
"""
OBJECT = 0 # Object / model space
CLIP = 1 # Clip space (after vertex shader)
NDC = 2 # Normalized Device Coordinates
SCREEN = 3 # Screen / framebuffer space
class Vertex:
"""
Simple per-vertex container used throughout the rasterization engine.
Notes
-----
• x, y, z represent position, whose meaning depends on `space`
• w is the homogeneous clip-space component
• attrs / varyings store per-vertex interpolated data
"""
def __init__(self, x=1.0, y=1.0, z=1.0, r=0.0, g=0.0, b=0.0, w=1.0):
# Position
self.x = x
self.y = y
self.z = z
# Color (optional / legacy)
self.r = r
self.g = g
self.b = b
# Homogeneous clip-space w
self.w = w
# Track current pipeline space
self.space = VertexSpace.OBJECT
# Generic per-vertex attributes (varyings)
self.attrs = {}
self.varyings = self.attrs
def copy(self):
"""
Create a deep copy of this vertex, including varyings.
"""
v = Vertex(self.x, self.y, self.z, self.r, self.g, self.b, self.w)
v.space = self.space
v.attrs = dict(self.attrs)
v.varyings = v.attrs
return v
def attach_varying(self, name, value):
"""
Attach a varying value (normal, uv, pos_view, etc.) to this vertex.
This is just a convenience wrapper around self.attrs[name] = value.
"""
self.attrs[name] = value
def get_varying(self, name, default=None):
"""
Retrieve a varying value by name.
This is equivalent to self.attrs.get(name, default).
"""
return self.attrs.get(name, default)