Repository navigation
Expand file tree
/
Copy pathdata_types.py
More file actions
90 lines (72 loc) · 2.06 KB
/
Copy pathdata_types.py
File metadata and controls
90 lines (72 loc) · 2.06 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import json
from dataclasses import dataclass
from mathutils import Quaternion, Vector
from typing import List
from json import JSONEncoder
#region Simple Data Types
@dataclass
class WorkDirVector3:
x: float
y: float
z: float
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
@classmethod
def from_bvector(cls, v: Vector):
return cls(v.x, v.y, v.z)
@dataclass
class WorkDirQuaternion:
x: float
y: float
z: float
w: float
def __init__(self, x, y, z, w):
self.x = x
self.y = y
self.z = z
self.w = w
@classmethod
def from_bquat(cls, v: Quaternion):
return cls(v.x, v.y, v.z, v.w)
#endregion
@dataclass
class WorkDirSplinePointData:
position: WorkDirVector3
def __init__(self, position):
self.position = position
@dataclass
class WorkDirSplineObject:
name: str
object_id: str
cyclic: bool
position: WorkDirVector3
rotation_type: int # 0 is quaternion rotation, 1 is euler rotation, anything else is negligible
quat_rotation: WorkDirQuaternion
euler_rotation: WorkDirVector3
scale: WorkDirVector3
path_type: str
points: list[WorkDirSplinePointData]
def __init__(self, name, object_id, cyclic, position, rotation_type, quat_rotation, euler_rotation, scale, path_type, points):
self.name = name
self.object_id = object_id
self.cyclic = cyclic
self.position = position
self.rotation_type = rotation_type
self.quat_rotation = quat_rotation
self.euler_rotation = euler_rotation
self.scale = scale
self.path_type = path_type
self.points = points
@dataclass
class WorkDirSplineOutput:
splines: list[WorkDirSplineObject]
def __init(self, splines):
self.splines = splines
import dataclasses
class WorkDirSplineOutputEncoder(json.JSONEncoder):
def default(self, o : WorkDirSplineObject):
if dataclasses.is_dataclass(o):
return dataclasses.asdict(o)
return super().default(o)