MCPcopy Create free account
hub / github.com/ICE27182/Python-3D-renderer / Object

Class Object

pyrender.py:25–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23
24
25class Object:
26 # [Object, Object, ...]
27 objects = []
28 # {name: Material}
29 materials = {}
30 # Remember to add / at the end
31 default_obj_dir = "./"
32
33 def __init__(self, name:str) -> None:
34 self.name = name
35 self.center = [0, 0, 0]
36 # [[x, y, z], [...], ...]
37 self.v = []
38 # [(u, v), (...), ...]
39 self.vt = []
40 # [[x, y, z], [...], ...]
41 self.vn = []
42 # [
43 # [
44 # (v_idx, v_idx, v_idx),
45 # (vt_idx, vt_idx, vt_idx),
46 # vn_idx
47 # ],
48 # [...],
49 # ...]
50 self.faces = []
51 self.svn = []
52 self.mtl = None
53 self.face_count = None
54 self.shade_smooth = False
55 self.shadow = True
56 self.hidden = False
57 self.hastexture = False
58 self.hasnormal_map = False
59 self.culling = True
60 self.no_lighting = False
61 self.x_r = 0.0
62 self.y_r = 0.0
63 self.z_r = 0.0
64 self.rotation = (
65 (1, 0, 0),
66 (0, 1, 0),
67 (0, 0, 1),
68 )
69
70
71 def __str__(self):
72 return (f"{self.name} | {self.face_count} faces | " +
73 f"Shading {'smooth' if self.shade_smooth else 'flat'} | " +
74 f"Texture: {self.hastexture} | Normal Map: {self.hasnormal_map} | " +
75 f"Shadow: {self.shadow} | Culling:{self.culling} | " +
76 f"Center: {self.center[0]:.3f} {self.center[1]:.3f} {self.center[2]:.3f} " +
77 f"Rotation {self.x_r:.3f} {self.y_r:.3f} {self.z_r:.3f}")
78
79
80 def load_obj(self, file:str, dir:str=None):
81 """
82 file can either be the name of the file or the path

Callers 1

load_objMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected