gameview
EventFilter
#
Bases: QObject
Event filter registered on the 3D Window.
Filter all mouse and keyboard events related to moving the scene in front of the camera.
Source code in cogip/widgets/gameview.py
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 |
|
__init__(parent)
#
Class constructor
Source code in cogip/widgets/gameview.py
31 32 33 34 35 36 37 |
|
eventFilter(source, event)
#
Required event filter function.
Source code in cogip/widgets/gameview.py
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 |
|
GameView
#
Bases: QWidget
The GameView
class is a QWidget
containing a Qt3DWindow
used to display all the game element, like table, robot and obstacles.
It also contains an horizontal plane entity with a invisible
QPlaneMesh
.
This plane is has a QObjectPicker
to detect mouse clicks, to help grabbing and moving entities on the horizontal plane.
Attributes:
Name | Type | Description |
---|---|---|
ground_image |
Path
|
image to display on the table floor |
obstacle_entities |
list[ObstacleEntity]
|
List of obstacles |
plane_intersection |
QVector3D
|
last active intersection of plane picker in world coordinates |
mouse_enabled |
bool
|
True to authorize translation and rotation of the scene using the mouse, False when an other object (obstacle, manual robot, ...) is picked. |
new_move_delta |
Signal
|
signal emitted to movable entities when a mouse drag is detected |
Source code in cogip/widgets/gameview.py
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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
|
__init__()
#
Create all entities required in the view:
- the
Qt3DWindow
to display the scene - the camera and all controls to move the scene in front of the camera
- the lights to have a good lightning of the scene
- the plane entity to help moving obstacles
Source code in cogip/widgets/gameview.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
add_asset(asset)
#
Add an asset (like TableEntity or RobotEntity) in the 3D view.
Argument
asset: The asset entity to add to the vew
Source code in cogip/widgets/gameview.py
261 262 263 264 265 266 267 268 269 270 |
|
add_ground_image()
#
Add a plane to display the ground image
Source code in cogip/widgets/gameview.py
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
|
add_obstacle(x=0, y=0, rotation=0, **kwargs)
#
Create a new obstacle in the 3D view.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
int
|
X position |
0
|
y |
int
|
Y position |
0
|
rotation |
int
|
Rotation |
0
|
Return
The obstacle entity
Source code in cogip/widgets/gameview.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
|
add_robot(robot_id)
#
Add a new robot status bar.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
robot_id |
int
|
ID of the new robot |
required |
Source code in cogip/widgets/gameview.py
376 377 378 379 380 381 382 383 384 385 386 387 |
|
asset_ready()
#
Create artifacts when all assets are ready (loading assets is done in background).
Source code in cogip/widgets/gameview.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
|
create_object_picker()
#
Add a plane mesh with object picker to help moving objects with mouse drag and drop.
Source code in cogip/widgets/gameview.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
|
del_robot(robot_id)
#
Remove a robot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
robot_id |
int
|
ID of the robot to remove |
required |
Source code in cogip/widgets/gameview.py
389 390 391 392 393 394 395 396 397 398 399 |
|
get_camera_params()
#
Return current camera parameters to save them for next session.
Source code in cogip/widgets/gameview.py
491 492 493 494 495 496 497 498 499 500 501 502 |
|
load_obstacles(filename)
#
Load obstacles from a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
Path
|
path of the JSON file |
required |
Source code in cogip/widgets/gameview.py
291 292 293 294 295 296 297 298 299 300 301 302 303 |
|
moved(pick)
#
Function called on a moved
mouse event on the artifact.
Just record that the artifact is moving, the translation is computed in the GameView object.
Source code in cogip/widgets/gameview.py
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
|
new_robot_path(robot_id, new_path)
#
Function called when robot path is updated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
robot_id |
int
|
ID of the robot |
required |
new_path |
list[Vertex]
|
new robot path |
required |
Source code in cogip/widgets/gameview.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
|
plane_moved(pick)
#
Compute the translation on the plane entity between the
current moved
mouse event and the previous one.
Emit the new_move_delta
signal to update the corresponding asset's position.
Source code in cogip/widgets/gameview.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
|
plane_pressed(pick)
#
Record the intersection between the mouse pointer and the plane entity,
on the pressed
mouse event, in world coordinate.
Source code in cogip/widgets/gameview.py
335 336 337 338 339 340 341 342 343 |
|
plane_released(pick)
#
Emit the new_move_delta
signal with None
argument,
on released
mouse event, to notify that mouse button was released
and no further moves will happen until next pressed
mouse event.
Source code in cogip/widgets/gameview.py
367 368 369 370 371 372 373 374 |
|
pressed(pick)
#
Function called on a pressed
mouse event on the artifact.
Emit a signal to disable the camera controller before moving the artifact.
Source code in cogip/widgets/gameview.py
416 417 418 419 420 421 422 |
|
save_obstacles(filename)
#
Save obstacles to a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
Path
|
path of the JSON file |
required |
Source code in cogip/widgets/gameview.py
305 306 307 308 309 310 311 312 313 314 315 316 |
|
set_camera_params(camera_params)
#
Set camera parameters to restore them from previous session.
Source code in cogip/widgets/gameview.py
504 505 506 507 508 509 510 511 |
|
create_light_entity(parent, x, y, z, intensity=1)
#
Create a light entity at the position specified in arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parent |
QEntity
|
parent entity |
required |
x |
float
|
X position |
required |
y |
float
|
Y position |
required |
z |
float
|
Z position |
required |
intensity |
float
|
light intensity |
1
|
Return
The light entity
Source code in cogip/widgets/gameview.py
514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
|