Basic Shapes
Description
Basic shapes are building blocks to modify and customize your environment. All shapes are spawned by default as static objects complete with collision boundaries which can be useful to create walls and other obstacles. Dynamics can be enabled and disabled to facilitate dynamic events that are triggered by actor locations such as the sudden appearance of an obstacle crossing the path. The physics properties can also be modified to tune the physics response depending 9on the number of interacting actors and what they are colliding with .
Basic shapes include full support for parenting to build long kinematic chains or simply to group multiple shapes together so they can be moved by manipulating a single parent actor.
If you are using a large number of dynamic shapes, consider using Widgets instead. They have both limitations and additional features, but are more efficient when spawning large numbers of dynamic actors.
See the Basic Shapes Tutorial to get a better understanding of using basic shapes in Quanser Interactive Labs.
Library
Constants
- QLabsBasicShape.ID_BASIC_SHAPE = 200
Class ID
- QLabsBasicShape.SHAPE_CUBE = 0
- QLabsBasicShape.SHAPE_CYLINDER = 1
- QLabsBasicShape.SHAPE_SPHERE = 2
- QLabsBasicShape.SHAPE_CONE = 3
- QLabsBasicShape.COMBINE_AVERAGE = 0
- QLabsBasicShape.COMBINE_MIN = 1
- QLabsBasicShape.COMBINE_MULTIPLY = 2
- QLabsBasicShape.COMBINE_MAX = 3
Member Variables
- QLabsBasicShape.actorNumber = None
The current actor number of this class to be addressed. This will be set by spawn methods and cleared by destroy methods. It will not be modified by the destroy all actors. This can be manually altered at any time to use one object to address multiple actors.
Methods
- QLabsBasicShape.__init__(qlabs, verbose=False)[source]
Constructor Method
- Parameters
qlabs (object) – A QuanserInteractiveLabs object
verbose (boolean) – (Optional) Print error information to the console.
- QLabsBasicShape.spawn(location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], configuration=0, waitForConfirmation=True)
Spawns a new actor with the next available actor number within this class.
- Parameters
location (float array[3]) – (Optional) An array of floats for x, y and z coordinates
rotation (float array[3]) – (Optional) An array of floats for the roll, pitch, and yaw in radians
scale (float array[3]) – (Optional) An array of floats for the scale in the x, y, and z directions. Scale values of 0.0 should not be used.
configuration (uint32) – (Optional) Spawn configuration. See class library for configuration options.
waitForConfirmation (boolean) – (Optional) Make this operation blocking until confirmation of the spawn has occurred. Note that if this is False, the returned actor number will be invalid.
- Returns
status - 0 if successful, 1 class not available, 3 unknown error, -1 communications error.
actorNumber - An actor number to use for future references.
- Return type
int32, int32
- QLabsBasicShape.spawn_degrees(location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], configuration=0, waitForConfirmation=True)
Spawns a new actor with the next available actor number within this class.
- Parameters
location (float array[3]) – (Optional) An array of floats for x, y and z coordinates
rotation (float array[3]) – (Optional) An array of floats for the roll, pitch, and yaw in degrees
scale (float array[3]) – (Optional) An array of floats for the scale in the x, y, and z directions. Scale values of 0.0 should not be used.
configuration (uint32) – (Optional) Spawn configuration. See class library for configuration options.
waitForConfirmation (boolean) – (Optional) Make this operation blocking until confirmation of the spawn has occurred. Note that if this is False, the returned actor number will be invalid.
- Returns
status - 0 if successful, 1 class not available, 3 unknown error, -1 communications error.
actorNumber - An actor number to use for future references.
- Return type
int32, int32
- QLabsBasicShape.spawn_id(actorNumber, location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], configuration=0, waitForConfirmation=True)
Spawns a new actor.
- Parameters
actorNumber (uint32) – User defined unique identifier for the class actor in QLabs
location (float array[3]) – (Optional) An array of floats for x, y and z coordinates
rotation (float array[3]) – (Optional) An array of floats for the roll, pitch, and yaw in radians
scale (float array[3]) – (Optional) An array of floats for the scale in the x, y, and z directions. Scale values of 0.0 should not be used.
configuration (uint32) – (Optional) Spawn configuration. See class library for configuration options.
waitForConfirmation (boolean) – (Optional) Make this operation blocking until confirmation of the spawn has occurred.
- Returns
status - 0 if successful, 1 class not available, 2 actor number not available or already in use, 3 unknown error, -1 communications error
- Return type
int32
- QLabsBasicShape.spawn_id_degrees(actorNumber, location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], configuration=0, waitForConfirmation=True)
Spawns a new actor.
- Parameters
actorNumber (uint32) – User defined unique identifier for the class actor in QLabs
location (float array[3]) – (Optional) An array of floats for x, y and z coordinates
rotation (float array[3]) – (Optional) An array of floats for the roll, pitch, and yaw in radians
scale (float array[3]) – (Optional) An array of floats for the scale in the x, y, and z directions. Scale values of 0.0 should not be used.
configuration (uint32) – (Optional) Spawn configuration. See class library for configuration options.
waitForConfirmation (boolean) – (Optional) Make this operation blocking until confirmation of the spawn has occurred.
- Returns
status - 0 if successful, 1 class not available, 2 actor number not available or already in use, 3 unknown error, -1 communications error
- Return type
int32
- QLabsBasicShape.spawn_id_and_parent_with_relative_transform(actorNumber, location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], configuration=0, parentClassID=0, parentActorNumber=0, parentComponent=0, waitForConfirmation=True)
Spawns a new actor relative to an existing actor and creates a kinematic relationship.
- Parameters
actorNumber (uint32) – User defined unique identifier for the class actor in QLabs
location (float array[3]) – (Optional) An array of floats for x, y and z coordinates
rotation (float array[3]) – (Optional) An array of floats for the roll, pitch, and yaw in radians
scale (float array[3]) – (Optional) An array of floats for the scale in the x, y, and z directions. Scale values of 0.0 should not be used.
configuration (uint32) – (Optional) Spawn configuration. See class library for configuration options.
parentClassID (uint32) – See the ID variables in the respective library classes for the class identifier
parentActorNumber (uint32) – User defined unique identifier for the class actor in QLabs
parentComponent (uint32) – 0 for the origin of the parent actor, see the parent class for additional reference frame options
waitForConfirmation (boolean) – (Optional) Make this operation blocking until confirmation of the spawn has occurred.
- Returns
status - 0 if successful, 1 class not available, 2 actor number not available or already in use, 3 cannot find the parent actor, 4 unknown error, -1 communications error
- Return type
int32
- QLabsBasicShape.spawn_id_and_parent_with_relative_transform_degrees(actorNumber, location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], configuration=0, parentClassID=0, parentActorNumber=0, parentComponent=0, waitForConfirmation=True)
Spawns a new actor relative to an existing actor and creates a kinematic relationship.
- Parameters
actorNumber (uint32) – User defined unique identifier for the class actor in QLabs
location (float array[3]) – (Optional) An array of floats for x, y and z coordinates
rotation (float array[3]) – (Optional) An array of floats for the roll, pitch, and yaw in degrees
scale (float array[3]) – (Optional) An array of floats for the scale in the x, y, and z directions. Scale values of 0.0 should not be used.
configuration (uint32) – (Optional) Spawn configuration. See class library for configuration options.
parentClassID (uint32) – See the ID variables in the respective library classes for the class identifier
parentActorNumber (uint32) – User defined unique identifier for the class actor in QLabs
parentComponent (uint32) – 0 for the origin of the parent actor, see the parent class for additional reference frame options
waitForConfirmation (boolean) – (Optional) Make this operation blocking until confirmation of the spawn has occurred.
- Returns
status - 0 if successful, 1 class not available, 2 actor number not available or already in use, 3 cannot find the parent actor, 4 unknown error, -1 communications error
- Return type
int32
- QLabsBasicShape.set_material_properties(color, roughness=0.4, metallic=False, waitForConfirmation=True)[source]
Sets the visual surface properties of the shape.
- Parameters
color (float array[3]) – Red, Green, Blue components of the RGB color on a 0.0 to 1.0 scale.
roughness (float) – A value between 0.0 (completely smooth and reflective) to 1.0 (completely rough and diffuse). Note that reflections are rendered using screen space reflections. Only objects visible in the camera view will be rendered in the reflection of the object.
metallic (boolean) – Metallic (True) or non-metallic (False)
waitForConfirmation (boolean) – (Optional) Wait for confirmation of the operation before proceeding. This makes the method a blocking operation.
- Returns
True if successful, False otherwise
- Return type
boolean
- QLabsBasicShape.get_material_properties()[source]
Gets the visual surface properties of the shape.
- Returns
status - True if successful or False otherwise
color - Red, Green, Blue components of the RGB color on a 0.0 to 1.0 scale.
roughness - A value between 0.0 (completely smooth and reflective) to 1.0 (completely rough and diffuse).
metallic - Metallic (True) or non-metallic (False)
- Return type
boolean, float array[3], float, boolean
- QLabsBasicShape.set_enable_dynamics(enableDynamics, waitForConfirmation=True)[source]
Sets the visual surface properties of the shape.
- Parameters
enableDynamics (boolean) – Enable (True) or disable (False) the shape dynamics. A dynamic actor can be pushed with other static or dynamic actors. A static actor will generate collisions, but will not be affected by interactions with other actors.
waitForConfirmation (boolean) – (Optional) Wait for confirmation of the operation before proceeding. This makes the method a blocking operation.
- Returns
True if successful, False otherwise
- Return type
boolean
- QLabsBasicShape.set_enable_collisions(enableCollisions, waitForConfirmation=True)[source]
Enables and disables physics collisions. When disabled, other physics or velocity-based actors will be able to pass through.
- Parameters
enableCollisions (boolean) – Enable (True) or disable (False) the collision.
waitForConfirmation (boolean) – (Optional) Wait for confirmation of the operation before proceeding. This makes the method a blocking operation.
- Returns
True if successful, False otherwise
- Return type
boolean
- QLabsBasicShape.set_physics_properties(enableDynamics, mass=1.0, linearDamping=0.01, angularDamping=0.0, staticFriction=0.0, dynamicFriction=0.7, frictionCombineMode=COMBINE_AVERAGE, restitution=0.3, restitutionCombineMode=COMBINE_AVERAGE, waitForConfirmation=True)[source]
Sets the dynamic properties of the shape.
- Parameters
enableDynamics (boolean) – Enable (True) or disable (False) the shape dynamics. A dynamic actor can be pushed with other static or dynamic actors. A static actor will generate collisions, but will not be affected by interactions with other actors.
mass (float) – (Optional) Sets the mass of the actor in kilograms.
linearDamping (float) – (Optional) Sets the damping of the actor for linear motions.
angularDamping (float) – (Optional) Sets the damping of the actor for angular motions.
staticFriction (float) – (Optional) Sets the coefficient of friction when the actor is at rest. A value of 0.0 is frictionless.
dynamicFriction (float) – (Optional) Sets the coefficient of friction when the actor is moving relative to the surface it is on. A value of 0.0 is frictionless.
frictionCombineMode (byte) – (Optional) Defines how the friction between two surfaces with different coefficients should be calculated (see COMBINE constants).
restitution (float) – (Optional) The coefficient of restitution defines how plastic or elastic a collision is. A value of 0.0 is plastic and will absorb all energy. A value of 1.0 is elastic and will bounce forever. A value greater than 1.0 will add energy with each collision.
restitutionCombineMode (byte) – (Optional) Defines how the restitution between two surfaces with different coefficients should be calculated (see COMBINE constants).
waitForConfirmation (boolean) – (Optional) Wait for confirmation of the operation before proceeding. This makes the method a blocking operation.
- Returns
True if successful, False otherwise
- Return type
boolean
- QLabsBasicShape.set_transform(location, rotation, scale, waitForConfirmation=True)[source]
Sets the location, rotation in radians, and scale. If a shape is parented to another actor then the location, rotation, and scale are relative to the parent actor.
- Parameters
location (float array[3]) – An array of floats for x, y and z coordinates in full-scale units.
rotation (float array[3]) – An array of floats for the roll, pitch, and yaw in radians
scale (float array[3]) – An array of floats for the scale in the x, y, and z directions.
waitForConfirmation (boolean) – (Optional) Wait for confirmation of the operation before proceeding. This makes the method a blocking operation.
- Returns
True if successful or False otherwise
- Return type
boolean
- QLabsBasicShape.set_transform_degrees(location, rotation, scale, waitForConfirmation=True)[source]
Sets the location, rotation in degrees, and scale. If a shape is parented to another actor then the location, rotation, and scale are relative to the parent actor.
- Parameters
location (float array[3]) – An array of floats for x, y and z coordinates in full-scale units.
rotation (float array[3]) – An array of floats for the roll, pitch, and yaw in degrees
scale (float array[3]) – An array of floats for the scale in the x, y, and z directions.
waitForConfirmation (boolean) – (Optional) Wait for confirmation of the operation before proceeding. This makes the method a blocking operation.
- Returns
True if successful or False otherwise
- Return type
boolean
- QLabsBasicShape.spawn_id_box_walls_from_end_points(actorNumber, startLocation, endLocation, height, thickness, color=[1, 1, 1], waitForConfirmation=True)[source]
Given a start and end point, this helper method calculates the position, rotation, and scale required to place a box on top of this line.
- Parameters
actorNumber (uint32) – User defined unique identifier for the class actor in QLabs
startLocation (float array[3]) – An array of floats for x, y and z coordinates.
endLocation (float array[3]) – An array of floats for x, y and z coordinates.
height (float) – The height of the wall.
thickness (float) – The width or thickness of the wall.
color (float array[3]) – Red, Green, Blue components of the RGB color on a 0.0 to 1.0 scale.
waitForConfirmation (boolean) – (Optional) Wait for confirmation of the operation before proceeding. This makes the method a blocking operation.
- Returns
True if successful or False otherwise
- Return type
boolean
- QLabsBasicShape.spawn_id_box_walls_from_center(actorNumbers, centerLocation, yaw, xSize, ySize, zHeight, wallThickness, floorThickness=0, wallColor=[1, 1, 1], floorColor=[1, 1, 1], waitForConfirmation=True)[source]
Creates a container-like box with 4 walls and an optional floor.
- Parameters
actorNumbers (uint32 array[5]) – An array of 5 user defined unique identifiers for the class actors in QLabs.
centerLocation (float array[3]) – An array of floats for x, y and z coordinates.
yaw (float) – Rotation about the z axis in radians.
xSize (float) – Size of the box in the x direction.
ySize (float) – Size of the box in the y direction.
zSize (float) – Size of the box in the z direction.
wallThickness (float) – The thickness of the walls.
floorThickness (float) – (Optional) The thickness of the floor. Setting this to 0 will spawn a box without a floor.
wallColor (float array[3]) – (Optional) Red, Green, Blue components of the wall color on a 0.0 to 1.0 scale.
floorColor (float array[3]) – (Optional) Red, Green, Blue components of the floor color on a 0.0 to 1.0 scale.
waitForConfirmation (boolean) – (Optional) Wait for confirmation of the operation before proceeding. This makes the method a blocking operation.
- Returns
True if successful or False otherwise
- Return type
boolean
- QLabsBasicShape.spawn_id_box_walls_from_center_degrees(actorNumbers, centerLocation, yaw, xSize, ySize, zHeight, wallThickness, floorThickness=0, wallColor=[1, 1, 1], floorColor=[1, 1, 1], waitForConfirmation=True)[source]
Creates a container-like box with 4 walls and an optional floor.
- Parameters
actorNumbers (uint32 array[5]) – An array of 5 user defined unique identifiers for the class actors in QLabs.
centerLocation (float array[3]) – An array of floats for x, y and z coordinates.
yaw (float) – Rotation about the z axis in degrees.
xSize (float) – Size of the box in the x direction.
ySize (float) – Size of the box in the y direction.
zSize (float) – Size of the box in the z direction.
wallThickness (float) – The thickness of the walls.
floorThickness (float) – (Optional) The thickness of the floor. Setting this to 0 will spawn a box without a floor.
wallColor (float array[3]) – (Optional) Red, Green, Blue components of the wall color on a 0.0 to 1.0 scale.
floorColor (float array[3]) – (Optional) Red, Green, Blue components of the floor color on a 0.0 to 1.0 scale.
waitForConfirmation (boolean) – (Optional) Wait for confirmation of the operation before proceeding. This makes the method a blocking operation.
- Returns
True if successful or False otherwise
- Return type
boolean
- QLabsBasicShape.destroy()
Find and destroy a specific actor. This is a blocking operation.
- Returns
numActorsDestroyed - The number of actors destroyed. -1 if failed.
- Return type
int32
- QLabsBasicShape.destroy_all_actors_of_class()
Find and destroy all actors of this class. This is a blocking operation.
- Returns
numActorsDestroyed - The number of actors destroyed. -1 if failed.
- Return type
int32
- QLabsBasicShape.get_world_transform()
Get the location, rotation, and scale in world coordinates of the actor.
- Returns
status - True if successful, False otherwise
location
rotation
scale
- Return type
boolean, float array[3], float array[3], float array[3]
- QLabsBasicShape.get_world_transform_degrees()
Get the location, rotation, and scale in world coordinates of the actor.
- Returns
status - True if successful, False otherwise
location
rotation
scale
- Return type
boolean, float array[3], float array[3], float array[3]
- QLabsBasicShape.ping()
Checks if the actor is still present in the environment. Note that if you did not spawn the actor with one of the spawn functions, you may need to manually set the actorNumber member variable.
- Returns
status - True if successful, False otherwise
- Return type
boolean
- QLabsBasicShape.parent_with_relative_transform(location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], parentClassID=0, parentActorNumber=0, parentComponent=0, waitForConfirmation=True)
Parents one existing actor to another to create a kinematic relationship.
- Parameters
location (float array[3]) – (Optional) An array of floats for x, y and z coordinates
rotation (float array[3]) – (Optional) An array of floats for the roll, pitch, and yaw in radians
scale (float array[3]) – (Optional) An array of floats for the scale in the x, y, and z directions. Scale values of 0.0 should not be used.
parentClassID (uint32) – See the ID variables in the respective library classes for the class identifier
parentActorNumber (uint32) – User defined unique identifier for the class actor in QLabs
parentComponent (uint32) – 0 for the origin of the parent actor, see the parent class for additional reference frame options
waitForConfirmation (boolean) – (Optional) Make this operation blocking until confirmation of the spawn has occurred.
- Returns
status - 0 if successful, 1 cannot find this actor, 2 cannot find the parent actor, 3 unknown error, -1 communications error
- Return type
int32
- QLabsBasicShape.parent_with_relative_transform_degrees(location=[0, 0, 0], rotation=[0, 0, 0], scale=[1, 1, 1], parentClassID=0, parentActorNumber=0, parentComponent=0, waitForConfirmation=True)
Parents one existing actor to another to create a kinematic relationship.
- Parameters
location (float array[3]) – (Optional) An array of floats for x, y and z coordinates
rotation (float array[3]) – (Optional) An array of floats for the roll, pitch, and yaw in degrees
scale (float array[3]) – (Optional) An array of floats for the scale in the x, y, and z directions. Scale values of 0.0 should not be used.
parentClassID (uint32) – (Optional) See the ID variables in the respective library classes for the class identifier
parentActorNumber (uint32) – (Optional) User defined unique identifier for the class actor in QLabs
parentComponent (uint32) – (Optional) 0 for the origin of the parent actor, see the parent class for additional reference frame options
waitForConfirmation (boolean) – (Optional) Make this operation blocking until confirmation of the spawn has occurred.
- Returns
status - 0 if successful, 1 cannot find this actor, 2 cannot find the parent actor, 3 unknown error, -1 communications error
- Return type
int32
- QLabsBasicShape.parent_with_current_world_transform(parentClassID=0, parentActorNumber=0, parentComponent=0, waitForConfirmation=True)
Parents one existing actor to another to create a kinematic relationship while preserving the current world transform of the child actor.
- Parameters
parentClassID (uint32) – See the ID variables in the respective library classes for the class identifier
parentActorNumber (uint32) – User defined unique identifier for the class actor in QLabs
parentComponent (uint32) – 0 for the origin of the parent actor, see the parent class for additional reference frame options
waitForConfirmation (boolean) – (Optional) Make this operation blocking until confirmation of the spawn has occurred.
- Returns
status - 0 if successful, 1 cannot find this actor, 2 cannot find the parent actor, 3 unknown error, -1 communications error
- Return type
int32
- QLabsBasicShape.parent_break(waitForConfirmation=True)
Breaks any relationship with a parent actor (if it exists) and preserves the current world transform
- Parameters
waitForConfirmation (boolean) – (Optional) Make this operation blocking until confirmation of the spawn has occurred.
- Returns
status - 0 if successful, 1 cannot find this actor, -1 communications error
- Return type
int32
- QLabsBasicShape.set_custom_properties(measuredMass=0, IDTag=0, properties='', waitForConfirmation=True)
Assigns custom properties to an actor.
- Parameters
measuredMass (float) – A float value for use with mass sensor instrumented actors. This does not alter the dynamic properties.
IDTag (uint32) – An integer value for use with IDTag sensor instrumented actors or for custom use.
properties (string) – A string for use with properties sensor instrumented actors. This can contain any string that is available for use to parse user-customized parameters.
waitForConfirmation (boolean) – (Optional) Make this operation blocking until confirmation of the spawn has occurred.
- Returns
status - True if successful, False otherwise
- Return type
boolean
- QLabsBasicShape.get_custom_properties()
Gets previously assigned custom properties to an actor.
- Returns
status - True if successful, False otherwise
measuredMass - float value
IDTag - integer value
properties - UTF-8 string
- Return type
boolean, float, int32, string
Configurations
There are four configurations (0-3) for the basic shape actor class.
0 - Cube
1 - Cylinder
2 - Sphere
3 - Cone
Connection Points
There are no connection points for this actor class.
Basic Shapes Tutorial
Example
Raw to download this tutorial: Basic Shapes Tutorial
.
1"""
2Basic Shape Library Example
3---------------------------
4
5.. note::
6
7 Make sure you have Quanser Interactive Labs open before running this
8 example. This example is designed to best be run in QCar Cityscape.
9
10"""
11# imports to important libraries
12import sys
13import math
14import time
15
16from qvl.qlabs import QuanserInteractiveLabs
17from qvl.free_camera import QLabsFreeCamera
18from qvl.basic_shape import QLabsBasicShape
19
20def main():
21
22 # creates a server connection with Quanser Interactive Labs and manages
23 # the communications
24 qlabs = QuanserInteractiveLabs()
25
26 # initialize our desired variables
27 # note that you can use the coordinate helper to pick locations for your camera.
28 loc = [-17.801, 31.145, 1.783]
29 rot = [0, -0.93, 6.9]
30
31 # trying to connect to QLabs and open the instance we have created - program will end if this fails
32 print("Connecting to QLabs...")
33 try:
34 qlabs.open("localhost")
35 except:
36 print("Unable to connect to QLabs")
37 return
38
39 # destroy any spawned actors in our QLabs that currently exist
40 qlabs.destroy_all_spawned_actors()
41 # create a camera in this qlabs instance
42 camera = QLabsFreeCamera(qlabs)
43 # add a custom camera at a specified location and rotation using degrees
44 camera.spawn_degrees(location=loc, rotation=rot)
45 # to switch our view from our current camera to the new camera we just initialized
46 camera.possess()
47
48 # initialize 4 cubes in our qlabs instance
49 cube0 = QLabsBasicShape(qlabs)
50 cube1 = QLabsBasicShape(qlabs)
51 cube2 = QLabsBasicShape(qlabs, True)
52 cube3 = QLabsBasicShape(qlabs, True)
53
54 # spawn one of the cubes using radians
55 cube0.spawn_id(actorNumber=0, location=[-10.202, 36.005, 0.5], rotation=[0,0,math.pi/4], scale=[0.5,0.5,0.5], configuration=cube0.SHAPE_CUBE, waitForConfirmation=True)
56 # ping this cube, expect True if cube does exist and the actorNumber hasn't been changed
57 cube0.ping()
58 # collecting the world transform coordinates of the cube
59 x, loc, rot, scale = cube0.get_world_transform()
60 print(x, loc, rot, scale)
61
62 # spawn a second cube using degrees
63 cube1.spawn_id_degrees(actorNumber=1, location=[-13.503, 33.677, 0.5], rotation=[0,0,45], scale=[0.5,0.5,0.5], configuration=cube1.SHAPE_CUBE, waitForConfirmation=True)
64 # wait to see visualization
65 time.sleep(1)
66 # destroy this created block
67 cube1.destroy()
68 # spawn a third and fourth cube relative to another parent actor already created in our qlabs instance using radians and then degrees respectively
69 cube2.spawn_id_and_parent_with_relative_transform(actorNumber=2, location=[0,2,0], rotation=[0,0,math.pi/4], scale=[1,1,1], configuration=cube2.SHAPE_CUBE, parentClassID=cube0.ID_BASIC_SHAPE, parentActorNumber=cube0.actorNumber, parentComponent=0, waitForConfirmation=True)
70 cube3.spawn_id_and_parent_with_relative_transform_degrees(actorNumber=3, location=[0,-2,0], rotation=[0,0,45], scale=[1,1,1], configuration=cube3.SHAPE_CUBE, parentClassID=cube0.ID_BASIC_SHAPE, parentActorNumber=cube0.actorNumber, parentComponent=0, waitForConfirmation=True)
71 # set the material properties to a metallic red and gold reflective surface
72 cube2.set_material_properties(color=[1,0,0], roughness=0.0, metallic=True, waitForConfirmation=True)
73 cube3.set_material_properties(color=[252/255,144/255,3/255], roughness=0.0, metallic=True, waitForConfirmation=True)
74 # have child actors rotate around the parent actor as their scale grows in size simultaneously
75 for y in range(51):
76 cube0.set_transform(location=[-10.202, 36.005, 0.5], rotation=[0,0,math.pi/4+2*math.pi/50*y], scale=[0.5+0.5*y/50,0.5+0.5*y/50,0.5+0.5*y/50])
77 cube2.set_transform(location=[0,2,0], rotation=[0,0,math.pi/4-math.pi/25*y], scale=[1,1,1])
78 cube3.set_transform_degrees(location=[0,-2,0], rotation=[0,0,45-180/25*y], scale=[1,1,1])
79
80 # initialize 6 spheres in our qlabs instance
81 sphere10 = QLabsBasicShape(qlabs)
82 sphere11 = QLabsBasicShape(qlabs)
83 sphere12 = QLabsBasicShape(qlabs)
84
85 sphere13 = QLabsBasicShape(qlabs)
86 sphere14 = QLabsBasicShape(qlabs)
87 sphere15 = QLabsBasicShape(qlabs)
88
89 # for the three first spheres, spawns spheres increasing in size using radians
90 sphere10.spawn_id(actorNumber=10, location=[-13.75, 32.5, 0.25], rotation=[0,0,0], scale=[0.5,0.5,0.5], configuration=sphere10.SHAPE_SPHERE, waitForConfirmation=True)
91 sphere11.spawn_id(actorNumber=11, location=[-13.75, 31.5, 1], rotation=[0,0,0], scale=[0.6,0.6,0.6], configuration=sphere11.SHAPE_SPHERE, waitForConfirmation=True)
92 sphere12.spawn_id(actorNumber=12, location=[-13.75, 30.5, 0.25], rotation=[0,0,0], scale=[0.7,0.7,0.7], configuration=sphere12.SHAPE_SPHERE, waitForConfirmation=True)
93
94 # in qlabs, the color of shapes uses the RGB color space with 0 to 255 represented between 0 and 1.
95 # if you know what color you'd like to set your shape in RGB simply devide the red, green and blue numbers by 255.
96 # this script sets these spheres to red, green and blue respectively while increasing in roughness
97 sphere10.set_material_properties(color=[1,0,0], roughness=0.0, metallic=False, waitForConfirmation=True)
98 sphere11.set_material_properties(color=[0,1,0], roughness=0.5, metallic=False, waitForConfirmation=True)
99 sphere12.set_material_properties(color=[0,0,1], roughness=1.0, metallic=False, waitForConfirmation=True)
100
101 # we want to now look at physics properties that are available to us in qlabs
102 # if we spawn three more spheres and set the properties of these spheres to
103 sphere13.spawn_id(actorNumber=13, location=[-11.253, 28.614, 1], rotation=[0,0,0], scale=[0.6,0.6,0.6], configuration=sphere13.SHAPE_SPHERE, waitForConfirmation=True)
104 sphere14.spawn_id(actorNumber=14, location=[-8.669, 26.631, 1], rotation=[0,0,0], scale=[0.6,0.6,0.6], configuration=sphere14.SHAPE_SPHERE, waitForConfirmation=True)
105 sphere15.spawn_id(actorNumber=15, location=[-8.685, 25.751, 1], rotation=[0,0,0], scale=[0.6,0.6,0.6], configuration=sphere13.SHAPE_SPHERE, waitForConfirmation=True)
106 sphere13.set_physics_properties(mass=10, linearDamping=0, angularDamping=0, enableDynamics=True, waitForConfirmation=True)
107 sphere13.set_enable_collisions(enableCollisions=True, waitForConfirmation=True)
108 sphere15.set_physics_properties(mass=0.5, linearDamping=0, angularDamping=0, enableDynamics=True, waitForConfirmation=True)
109 sphere15.set_enable_collisions(enableCollisions=True, waitForConfirmation=True)
110
111 sphere10.set_enable_dynamics(enableDynamics=True, waitForConfirmation=True)
112 sphere11.set_enable_dynamics(enableDynamics=True, waitForConfirmation=True)
113 sphere12.set_enable_dynamics(enableDynamics=True, waitForConfirmation=True)
114 sphere13.set_enable_dynamics(enableDynamics=True, waitForConfirmation=True)
115
116
117
118 boxSpawn = QLabsBasicShape(qlabs)
119 boxSpawn.spawn_id_box_walls_from_center(actorNumbers=[210, 211, 212, 213, 214], centerLocation=[-9.35, 26.5, 0.005], yaw=math.pi/4, xSize=2, ySize=2, zHeight=0.5, wallThickness=0.1, floorThickness=0.1, wallColor=[1,0,0], floorColor=[0,0,0], waitForConfirmation=True)
120
121
122 boxSpawn.spawn_id_box_walls_from_center_degrees(actorNumbers=[270, 271, 272, 273, 274], centerLocation=[-11.35, 28.5, 0.005], yaw=45, xSize=2, ySize=2, zHeight=0.5, wallThickness=0.1, floorThickness=0.1, wallColor=[1,0,0], floorColor=[0,0,0], waitForConfirmation=True)
123
124
125 boxSpawn.spawn_id_box_walls_from_end_points(actorNumber=280, startLocation=[-10.5, 32.5, 0.005], endLocation=[-10.5, 30.5, 0.005], height=0.1, thickness=0.1, color=[0.2,0.2,0.2], waitForConfirmation=True)
126
127
128 x, shapeHandle1 = boxSpawn.spawn(location=[-6.945, 31.5, 0.5], rotation=[0,0,math.pi/4], scale=[1,1,1], configuration=boxSpawn.SHAPE_CUBE, waitForConfirmation=True)
129 x, shapeHandle2 = boxSpawn.spawn(location=[-6.945, 31.5, 1.375], rotation=[0,0,0], scale=[0.75,0.75,0.75], configuration=boxSpawn.SHAPE_CUBE, waitForConfirmation=True)
130 x, shapeHandle3 = boxSpawn.spawn(location=[-6.945, 31.5, 2], rotation=[0,0,math.pi/4], scale=[0.5,0.5,0.5], configuration=boxSpawn.SHAPE_CUBE, waitForConfirmation=True)
131
132
133 x, shapeHandle4 = boxSpawn.spawn_degrees(location=[-6.945, 31.5, 2.50], rotation=[0,0,0], scale=[0.5,0.5,0.5], configuration=boxSpawn.SHAPE_CUBE, waitForConfirmation=True)
134 x, shapeHandle5 = boxSpawn.spawn_degrees(location=[-6.945, 31.5, 2.875], rotation=[0,0,45], scale=[0.25,0.25,0.25], configuration=boxSpawn.SHAPE_CUBE, waitForConfirmation=True)
135
136
137 boxSpawn.actorNumber = shapeHandle1
138 boxSpawn.set_material_properties(color=[0,0,0], roughness=0.0, metallic=False, waitForConfirmation=True)
139 boxSpawn.actorNumber = shapeHandle2
140 boxSpawn.set_material_properties(color=[1,1,1], roughness=0.0, metallic=False, waitForConfirmation=True)
141 boxSpawn.actorNumber = shapeHandle3
142 boxSpawn.set_material_properties(color=[0.5,0.5,0.5], roughness=0.0, metallic=False, waitForConfirmation=True)
143 boxSpawn.actorNumber = shapeHandle4
144 boxSpawn.set_material_properties(color=[0,0,0], roughness=0.0, metallic=False, waitForConfirmation=True)
145
146
147
148if __name__ == "__main__":
149 main()