forked from microsoft/AirSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
character_control.py
67 lines (51 loc) · 2.49 KB
/
character_control.py
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
# This script expects object available in UE environment of type AAirSimCharater
# In settings.json first activate computer vision mode:
# https://github.com/Microsoft/AirSim/blob/master/docs/image_apis.md#computer-vision-mode
import setup_path
import airsim
import pprint
import os
import time
pp = pprint.PrettyPrinter(indent=4)
client = airsim.VehicleClient()
client.confirmConnection()
airsim.wait_key('Press any key to set skin age to 0.9')
client.simCharSetSkinAgeing(0.9)
airsim.wait_key('Press any key to set skin color to 0.1')
client.simCharSetSkinDarkness(0.1)
airsim.wait_key('Press any key to set face expression')
client.simCharSetFaceExpression("BlendShapeNode_Smile", 1);
airsim.wait_key('Press any key to set bone pose')
jaw_pose = airsim.Pose()
jaw_pose.position = airsim.Vector3r(0.002, 0.001, -0.003)
jaw_pose.orientation = airsim.to_quaternion(0, 0, -.15)
client.simCharSetBonePose( "Jaw", jaw_pose);
airsim.wait_key('Press any key to set preset')
client.simCharSetFacePreset("FACS_01", 1);
airsim.wait_key('Press any key to turn head around')
for pitch in range(-15, 15, 5):
for yaw in range(-30, 30, 2):
q = airsim.to_quaternion(pitch/10.0, 0, yaw/10.0)
client.simCharSetHeadRotation(q)
time.sleep(0.1)
airsim.wait_key('Press any key to get images')
for x in range(3): # do few times
responses = client.simGetImages([
airsim.ImageRequest("0", airsim.ImageType.DepthVis),
airsim.ImageRequest("0", airsim.ImageType.Segmentation),
airsim.ImageRequest("0", airsim.ImageType.Scene),
airsim.ImageRequest("0", airsim.ImageType.SurfaceNormals)])
for i, response in enumerate(responses):
if response.pixels_as_float:
print("Type %d, size %d, pos %s" % (response.image_type, len(response.image_data_float), pprint.pformat(response.camera_position)))
airsim.write_pfm(os.path.normpath('/temp/cv_mode_' + str(x) + "_" + str(i) + '.pfm'), airsim.get_pfm_array(response))
else:
print("Type %d, size %d, pos %s" % (response.image_type, len(response.image_data_uint8), pprint.pformat(response.camera_position)))
airsim.write_file(os.path.normpath('/temp/cv_mode_' + str(x) + "_" + str(i) + '.png'), response.image_data_uint8)
pose = client.simGetVehiclePose()
pose.position.x_val = pose.position.x_val + 1
pose.position.y_val = pose.position.y_val - 0.5
pose.position.z_val = pose.position.z_val - 0.5
client.simSetVehiclePose(pose, True)
time.sleep(3)
client.reset()