def decode(self, data): name = data.get('name') radius = data.get('radius', 10) radius_units = data.get('radius-units', units.m) radius *= radius_units camera_distance = data.get('camera-distance', None) camera_pos = data.get('camera-position', None) camera_pos_units = data.get('camera-position-units', units.m) camera_rot_data = data.get('camera-rotation', None) if camera_rot_data is not None: if len(camera_rot_data) == 3: camera_rot = LQuaterniond() camera_rot.set_hpr(LVector3d(*camera_rot_data)) else: camera_rot = LQuaterniond(*camera_rot_data) else: camera_rot = LQuaterniond() shape = data.get('shape') appearance = data.get('appearance') lighting_model = data.get('lighting-model') shape, extra = ShapeYamlParser.decode(shape) if appearance is None: if isinstance(shape, MeshShape): appearance = 'model' else: appearance = 'textures' appearance = AppearanceYamlParser.decode(appearance) lighting_model = LightingModelYamlParser.decode( lighting_model, appearance) shader = BasicShader( lighting_model=lighting_model, use_model_texcoord=not extra.get('create-uv', False)) ship_object = ShapeObject('ship', shape=shape, appearance=appearance, shader=shader) if camera_distance is None: if camera_pos is None: camera_distance = 5.0 camera_pos = LPoint3d(0, -camera_distance * radius, 0) else: camera_pos = LPoint3d(*camera_pos) * camera_pos_units camera_distance = camera_pos.length() / radius else: camera_pos = LPoint3d(0, -camera_distance * radius, 0) ship = VisibleShip(name, ship_object, radius) ship.set_camera_hints(camera_distance, camera_pos, camera_rot) for mode in self.camera_modes: ship.add_camera_mode(mode) self.app.add_ship(ship)
def decode(self, data): if isinstance(data, str): data = {'model': data} model = data.get('model') create_uv = data.get('create-uv', False) panda = data.get('panda', False) auto_scale_mesh = data.get('auto-scale', True) offset = data.get('offset', None) rotation_data = data.get('rotation', None) scale = data.get('scale', None) if offset is not None: offset = LVector3d(*offset) if rotation_data is not None: if len(rotation_data) == 3: rotation = LQuaterniond() rotation.set_hpr(LVector3d(*rotation_data)) else: rotation = LQuaterniond(*rotation_data) else: rotation = None flatten = data.get('flatten', True) attribution = data.get('attribution', None) shape = MeshShape(model, offset, rotation, scale, auto_scale_mesh, flatten, panda, attribution, context=YamlModuleParser.context) return (shape, {'create-uv': create_uv})
def quaternion_from_euler(h, p, r): rotation = LQuaterniond() rotation.set_hpr((h, p, r)) return rotation