-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnvironment.py
More file actions
157 lines (103 loc) · 4.45 KB
/
Copy pathEnvironment.py
File metadata and controls
157 lines (103 loc) · 4.45 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
from ursina import *
from colorama import init, Fore, Back, Style
from panda3d.core import loadPrcFileData
class Environment:
def __init__(self , scene_bg_color = color.dark_gray):
"""
:vec3 scale: REQUIRED , y is height, should be minimal ex: (20,1,20)
:string model: default --> 'plane'
:string name: default --> 'plane' , change name when creating more than a plane
:vec3 position: default --> (0,0,0) , you may need to adjust depending on your Robot model y dimension
:color color: default --> color.white
:string collider: default --> 'box' for model --> 'plane'
"""
self.height_axis = 'z'
self.main_plane = Vec3(0,0,0)
window.color = scene_bg_color
scene.fog_density = .1
self.elements = {}
def coords_mapper(self , coordinates):
if self.height_axis == 'z':
return Vec3(coordinates.x , coordinates.z , coordinates.y)
else:
return coordinates
def create_plane(self,model_scale,name,height_axis_user='z',position = Vec3(0,0,0),color=color.white,collider='box',main_plane = False):
if height_axis_user == 'y':
self.height_axis = 'y'
else:
self.height_axis = 'z'
mapped_scale = self.coords_mapper(Vec3(model_scale))
mapped_position = self.coords_mapper(Vec3(position))
if main_plane == True:
self.main_axis_plane = mapped_scale
self.plane_entity = Entity(
model='cube',
scale=(mapped_scale),
color=color,
position=mapped_position,
collider=collider,
texture='white_cube',
texture_scale=(mapped_scale.x , mapped_scale.z)
)
self.elements[name] = self.plane_entity
def create_obstacle(self,model_scale,name,model='cube',position = Vec3(0,0,0),color=color.red,collider='box'):
mapped_scale = self.coords_mapper(Vec3(model_scale))
mapped_position = self.coords_mapper(Vec3(position))
print(mapped_position)
self.obstacle_entity = Entity(
model=model,
scale=mapped_scale,
color=color,
position=mapped_position,
collider=collider,
texture='white_cube'
)
self.elements[name] = self.obstacle_entity
def show_axis(self, entity_name , show_axis , x , y , z):
print(f" successfully grabbed {entity_name}'s scale {self.coords_mapper(self.elements[entity_name].scale)} and position {self.coords_mapper(self.elements[entity_name].position)} ")
if show_axis == True:
self.x_axis = Entity(
model='cube',
scale=(x, 0.05 , 0.05),
color=color.red,
position=(0,0,0),
texture='white_cube'
)
if self.height_axis == 'z':
self.y_axis = Entity(
model='cube',
scale=(0.05 , y , 0.05), # I put the height y-axis as the x-axis to make the axis symmetric!
color=color.blue,
position=(0,self.main_axis_plane.z/2,0),
texture='white_cube'
)
self.z_axis = Entity(
model='cube',
scale=(0.05 , 0.05 , z),
color=color.green,
position=(0,0,0),
texture='white_cube'
)
else:
self.y_axis = Entity(
model='cube',
scale=(0.05 , 0.05 , y), # I put the height y-axis as the x-axis to make the axis symmetric!
color=color.blue,
position=(0,0,0),
texture='white_cube'
)
self.z_axis = Entity(
model='cube',
scale=(0.05 , z,0.05),
color=color.green,
position=(0,0,0),
texture='white_cube'
)
def show_fps(fps = False):
"""
:boolean fps: True --> shows fps on Ursina App , False --> otherwise
"""
if fps == True:
loadPrcFileData('', 'show-frame-rate-meter #t')
else:
loadPrcFileData('', 'show-frame-rate-meter #f')