def __init__(self, name, ship_object, radius): ShipBase.__init__(self, name) self.ship_object = ship_object self.radius = radius #TODO: Should be refactored with StellarBody ! self.shown = True self.visible = True self.resolved = True self.oid_color = LColor() self.world_body_center_offset = LVector3d() self.model_body_center_offset = LVector3d() self.light_color = LColor(1, 1, 1, 1) self.rel_position = None self.scene_rel_position = None self.distance_to_obs = None self.vector_to_obs = None self.vector_to_star = None self.star = None self.directional_light = None self.light_source = None self.scene_position = None self.scene_distance = None self.scene_scale_factor = None self.scene_orientation = None self.ship_object.set_parent(self) #TODO: Temporary workaround as some code need the shape to have an owner self.ship_object.set_owner(self) self.ship_object.set_scale(LVector3d(self.radius, self.radius, self.radius)) self.shadow_caster = None self.create_own_shadow_caster = True
def __init__(self, height, mie_coef=0.0, mie_scale_height=0.0, mie_phase_asymmetry=0.0, rayleigh_coef=None, rayleigh_scale_height=0.0, absorption_coef=None, appearance=None, shader=None): Atmosphere.__init__(self, appearance=appearance, shader=shader) self.height = height self.mie_coef = mie_coef self.mie_scale_height = mie_scale_height self.mie_phase_asymmetry = mie_phase_asymmetry if rayleigh_coef is None: self.rayleigh_coef = LVector3d() else: self.rayleigh_coef = LVector3d(*rayleigh_coef) self.rayleigh_scale_height = rayleigh_scale_height if absorption_coef is None: self.absorption_coef = LVector3d() else: self.absorption_coef = LVector3d(*absorption_coef) self.alpha_mode = ColorBlendAttrib.OIncomingAlpha
def _boundaries_without_priming(self) -> BoundingBox3D: """Return this Model's boundaries without the priming layer.""" if self.index_to_layer: layer_points_min, layer_points_max = zip( *[(layer.boundaries.point_min, layer.boundaries.point_max) for layer in self._layer_to_z.keys()]) layers_min = reduce(lambda a, b: a.fmin(b), layer_points_min) layers_max = reduce(lambda a, b: a.fmax(b), layer_points_max) point_min = LVector3d( x=layers_min.x, y=layers_min.y, z=0, ) point_max = LVector3d( x=layers_max.x, y=layers_max.y, z=max(self._layer_to_z.values()), ) return BoundingBox3D(point_min=point_min, point_max=point_max) # No layers return BoundingBox3D.null_object()
def __init__(self, height, mie_coef=0.0, mie_scale_height=0.0, mie_phase_asymmetry=0.0, rayleigh_coef=None, rayleigh_scale_height=0.0, absorption_coef=None, shape=None, appearance=None, shader=None): Atmosphere.__init__(self, shape=shape, appearance=appearance, shader=shader) self.height = height self.mie_coef = mie_coef self.mie_scale_height = mie_scale_height self.mie_phase_asymmetry = mie_phase_asymmetry if rayleigh_coef is None: self.rayleigh_coef = LVector3d() else: self.rayleigh_coef = LVector3d(*rayleigh_coef) self.rayleigh_scale_height = rayleigh_scale_height if absorption_coef is None: self.absorption_coef = LVector3d() else: self.absorption_coef = LVector3d(*absorption_coef) self.blend = TransparencyBlend.TB_AlphaAdditive
def __init__(self, names, orbit=None, rotation=None, body_class=None, point_color=None, description=''): LabelledObject.__init__(self, names) self.description = description self.system = None self.body_class = body_class if orbit is None: orbit = FixedOrbit() self.orbit = orbit if rotation is None: rotation = UnknownRotation() self.rotation = rotation if point_color is None: point_color = LColor(1.0, 1.0, 1.0, 1.0) self.point_color = srgb_to_linear(point_color) self.abs_magnitude = 99.0 self.oid = None self.oid_color = None #Flags self.visible = False self.resolved = False self.in_view = False self.selected = False self.update_id = 0 self.visibility_override = False #Cached values self._position = LPoint3d() self._global_position = LPoint3d() self._local_position = LPoint3d() self._orientation = LQuaterniond() self._equatorial = LQuaterniond() self._app_magnitude = None self._extend = 0.0 #Scene parameters self.rel_position = None self.distance_to_obs = None self.vector_to_obs = None self.distance_to_star = None self.vector_to_star = None self.height_under = 0.0 self.star = None self.light_color = (1.0, 1.0, 1.0, 1.0) self.visible_size = 0.0 self.scene_position = None self.scene_orientation = None self.scene_scale_factor = None self.world_body_center_offset = LVector3d() self.model_body_center_offset = LVector3d() self.projected_world_body_center_offset = LVector3d() #Components self.orbit_object = None self.rotation_axis = None self.reference_axis = None self.init_annotations = False self.init_components = False self.update_frozen = False #TODO: Should be done properly self.orbit.body = self self.rotation.body = self objectsDB.add(self)
def update_shader_shape_static(self, shape, appearance): parameters = shape.owner.atmosphere planet_radius = shape.owner.get_apparent_radius() if self.atmosphere: #render.cpp 7193 radius = planet_radius + shape.owner.atmosphere.height #renderglsl.cpp 557 atmosphereRadius = radius + -parameters.mie_scale_height * log( self.AtmosphereExtinctionThreshold) atmPlanetRadius = radius objRadius = atmosphereRadius else: radius = planet_radius #rendercontext.cpp 785 atmPlanetRadius = radius objRadius = radius #shadermanager.cpp 3446 skySphereRadius = atmPlanetRadius + -parameters.mie_scale_height * log( self.AtmosphereExtinctionThreshold) mieCoeff = parameters.mie_coef * objRadius rayleighCoeff = parameters.rayleigh_coef * objRadius absorptionCoeff = parameters.absorption_coef * objRadius r = skySphereRadius / objRadius atmosphereRadius = LVector3d(r, r * r, atmPlanetRadius / objRadius) mieScaleHeight = objRadius / parameters.mie_scale_height # The scattering shaders use the Schlick approximation to the # Henyey-Greenstein phase function because it's slightly faster # to compute. Convert the HG asymmetry parameter to the Schlick # parameter. g = parameters.mie_phase_asymmetry miePhaseAsymmetry = 1.55 * g - 0.55 * g * g * g rayleighScaleHeight = 0.0 # Precompute sum and inverse sum of scattering coefficients to save work # in the vertex shader. scatterCoeffSum = rayleighCoeff + LVector3d(mieCoeff, mieCoeff, mieCoeff) invScatterCoeffSum = LVector3d(1.0 / scatterCoeffSum[0], 1.0 / scatterCoeffSum[1], 1.0 / scatterCoeffSum[2]) extinctionCoeff = scatterCoeffSum + absorptionCoeff shape.instance.setShaderInput("atmosphereRadius", *atmosphereRadius) shape.instance.setShaderInput("mieCoeff", mieCoeff) shape.instance.setShaderInput("mieH", mieScaleHeight) shape.instance.setShaderInput("mieK", miePhaseAsymmetry) shape.instance.setShaderInput("rayleighCoeff", *rayleighCoeff) shape.instance.setShaderInput("rayleighH", rayleighScaleHeight) # Color of sun shape.instance.setShaderInput("scatterCoeffSum", *scatterCoeffSum) shape.instance.setShaderInput("invScatterCoeffSum", *invScatterCoeffSum) shape.instance.setShaderInput("extinctionCoeff", *extinctionCoeff)
class CelestiaBodyFixedReferenceFrame(RelativeReferenceFrame): rotY180 = LQuaterniond() rotY180.set_from_axis_angle(180, LVector3d(0, 1, 0)) rotZ90 = LQuaterniond() rotZ90.set_from_axis_angle(-90, LVector3d(0, 0, 1)) def get_orientation(self): rot = self.body.get_sync_rotation() return rot
def _boundaries_with_priming(self) -> BoundingBox3D: """Return this Model's boundaries with the priming layer.""" if not self._priming_layer: return self._boundaries_without_priming # Calc new boundaries with priming layer in mind point_min = self._boundaries_without_priming.point_min.fmin( LVector3d(self._priming_layer.boundaries.point_min, 0)) point_max = self._boundaries_without_priming.point_max.fmax( LVector3d(self._priming_layer.boundaries.point_max, 0)) return BoundingBox3D(point_min=point_min, point_max=point_max)
def __init__(self, recipe): self.__dict__.update(recipe) self.SATS = [] self.sys_vec = LVector3d(0, 0, 0) self.sys_pos = LVector3d(0, 0, 0) self.sys_hpr = LVector3f(0, 0, 0) self.sys_rot = LVector3f(0, 0, 0) self.POS = LVector3f(0, 0, 0) self.far_radius = _env.ATMOS_RADIUS - self.radius self.near_radius = 0 self._mode = "far" ## self._lod = "low" self._loaded = False
def __init__(self, env): self.env = env self.cam_node = Camera(self.__class__.__name__.lower()) self.cam_node.setScene(env.NP) self.NP = NodePath(self.cam_node) self.NP.reparentTo(env.NP) self.LENS = self.cam_node.getLens() self.LENS.setFar(_cam.FAR) self.LENS.setFov(base.camLens.getFov()) self.FOCUS = None self.focus_pos = LVector3d(0, 0, 0) self.sys_pos = LVector3d(0, 0, 0)
def __init__(self, names, orbit=None, rotation=None, body_class=None, point_color=None, description=''): LabelledObject.__init__(self, names) self.description = description self.system = None self.body_class = body_class self.visible = True self.resolved = True self.in_view = True if orbit is None: orbit = FixedOrbit() self.orbit = orbit if rotation is None: rotation = FixedRotation() self.rotation = rotation if point_color is None: point_color = LColor(1.0, 1.0, 1.0, 1.0) self.point_color = point_color self.position = LPoint3d() self.orbit_position = LPoint3d() self.orbit_rotation = LQuaterniond() self.orientation = LQuaterniond() self.equatorial = LQuaterniond() self.abs_magnitude = 99.0 self.cached_app_magnitude = None self.rel_position = None self.distance_to_obs = None self.vector_to_obs = None self.distance_to_star = None self.vector_to_star = None self.height_under = 0.0 self.light_color = (1.0, 1.0, 1.0, 1.0) self.visible_size = 0.0 self.scene_position = None self.scene_orientation = None self.scene_scale_factor = None self.orbit_object = None self.rotation_axis = None self.reference_axis = None self.star = None self.init_annotations = False self.init_components = False #TODO: Should be done properly self.orbit.body = self self.rotation.body = self self.selected = False objectsDB.add(self) self.global_position = self.orbit.get_global_position_at(0) self.cast_shadows = False self.world_body_center_offset = LVector3d() self.model_body_center_offset = LVector3d()
def __init__(self, position=None, global_position=True, right_asc=0.0, right_asc_unit=units.Deg, declination=0.0, declination_unit=units.Deg, distance=0.0, distance_unit=units.Ly, frame=None): Orbit.__init__(self, frame) if position is None: self.right_asc = right_asc * right_asc_unit self.declination = declination * declination_unit distance = distance * distance_unit else: self.right_asc = None self.declination = None if not isinstance(position, LPoint3d): position = LPoint3d(*position) if position is None: self.orientation = calc_orientation(self.right_asc, self.declination) position = self.orientation.xform(LVector3d(0, 0, distance)) if global_position: self.global_position = position self.position = LPoint3d() else: self.global_position = LPoint3d() self.position = position self.rotation = LQuaterniond()
def _task_handle_key(self, task): """Handle keypress event. This is a task function. """ # Calc translation vector, based on pressed keys rel_translate_vec: LVector3d = reduce( lambda x, y: x + y, [ self._key_combo_to_direction[key] for key, is_pressed in self._key_combo_to_is_pressed.items() if is_pressed and key in self._key_combo_to_direction ], LVector3d(0, 0, 0), ) hpr_backup = self._camera_anchor.getHpr() self._camera_anchor.setP(0) self._camera_anchor.setR(0) self._camera_anchor.setPos(self._camera_anchor, *(rel_translate_vec * 0.75)) self._camera_anchor.setHpr(hpr_backup) if self._continue_tasks: return task.cont
def do_load_bin(filepath, names, universe): start = time() print("Loading", filepath) base.splash.set_text("Loading %s" % filepath) data = open(filepath, 'rb') field = data.read(8 + 2 + 4) header, version, count = struct.unpack("<8shi", field) if not header == b"CELSTARS": print("Invalid header", header) return if not version == 0x0100: print("Invalid version", version) return print("Found", count, "stars") fmt = "<ifffhh" size = struct.calcsize(fmt) for i in range(count): fields = data.read(size) catNo, x, y, z, abs_magnitude, spectral_type = struct.unpack( fmt, fields) if catNo in names: name = names[catNo] else: name = "HIP %d" % catNo position = LVector3d(x * units.Ly, -z * units.Ly, y * units.Ly) orbit = FixedPosition(position=position) star = Star(name, surface_factory=celestiaStarSurfaceFactory, spectral_type=spectralTypeIntDecoder.decode(spectral_type), abs_magnitude=abs_magnitude / 256.0, orbit=orbit, rotation=FixedRotation()) universe.add_child_fast(star) end = time() print("Load time:", end - start)
def set_focus(self, obj): if self.FOCUS and obj is self.FOCUS: return self.FOCUS = obj self.focus_pos.set(0, obj.radius * 12, 0) obj_state = self.env.client.SIM.get_object_state(obj.name, ["sys_pos"]) obj.sys_pos = LVector3d(*obj_state['sys_pos']) self.sys_pos = obj.sys_pos - self.focus_pos
def NormalizedSquarePatchPoint(radius, u, v, x0, y0, x1, y1, offset=None, x_inverted=False, y_inverted=False, xy_swap=False): if offset is not None: normal = NormalizedSquarePatchNormal(x0, y0, x1, y1, x_inverted, y_inverted, xy_swap) (x0, y0, x1, y1, dx, dy) = convert_xy(x0, y0, x1, y1, x_inverted, y_inverted, xy_swap) x = x0 + u * dx y = y0 + v * dy vec = LVector3d(2.0 * x - 1.0, 2.0 * y - 1.0, 1.0) vec.normalize() if offset is not None: vec = (vec - normal * offset) * radius return vec
def UVPatchNormal(x0, y0, x1, y1): dx = x1 - x0 dy = y1 - y0 x = cos(2 * pi * (x0 + dx / 2) + pi) * sin(pi * (y0 + dy / 2)) y = sin(2 * pi * (x0 + dx / 2) + pi) * sin(pi * (y0 + dy / 2)) z = sin(pi / 2 - pi * (y0 + dy / 2)) return LVector3d(x, y, z)
def LQuaternionromAxisAngle(axis, angle, angle_units=units.Rad): if isinstance(axis, list): axis = LVector3d(*axis) axis.normalize() rot = LQuaterniond() rot.setFromAxisAngleRad(angle * angle_units, axis) return rot
def update_instance(self, camera_pos, orientation): if not self.instance_ready: return self.place_instance(self.instance, self.parent) if not self.shape.patchable and settings.offset_body_center and self.parent is not None: #TODO: Should be done in place_instance, but that would make several if... self.instance.setPos(*(self.parent.scene_position + self.parent.world_body_center_offset)) if self.shape.patchable and settings.offset_body_center and self.parent is not None: #In case of oblate shape, the offset can not be used directly to retrieve the body center #The scale must be applied to the offset to retrieve the real center offset = self.shape.instance.getMat().xform( LVector3(*self.shape.owner.model_body_center_offset)) self.parent.projected_world_body_center_offset = LVector3d( *offset.get_xyz()) if self.shape.update_lod(self.context.observer.get_camera_pos(), self.parent.distance_to_obs, self.context.observer.pixel_size, self.appearance): self.schedule_jobs() if self.shape.patchable: self.shape.place_patches(self.parent) if self.appearance is not None: self.appearance.update_lod(self.shape, self.parent.get_apparent_radius(), self.parent.distance_to_obs, self.context.observer.pixel_size) if self.shadows.update_needed: self.update_shader() self.shadows.update_needed = False if self.shader is not None: self.shader.update(self.shape, self.appearance)
def step(self, distance): arc_to_angle = 1.0 / (self.body.get_apparent_radius()) camera_pos = self.observer.get_camera_pos() (normal, tangent, binormal) = self.body.get_normals_under(camera_pos) direction = self.observer.get_camera_rot().xform( LVector3d(0, distance, 0)) projected = direction - normal * direction.dot(normal) position = self.body.cartesian_to_spherical( self.observer.get_camera_pos()) delta_x = tangent.dot(projected) * arc_to_angle delta_y = binormal.dot(projected) * arc_to_angle new_position = [ position[0] + delta_x, position[1] + delta_y, position[2] ] altitude = position[2] - self.body.height_under (x, y, distance) = self.body.spherical_to_longlat(new_position) new_height = self.body.surface.get_height_at(x, y, strict=True) if new_height is not None: new_position[2] = new_height + altitude else: print("Patch not found for", x, y, '->', new_position[2]) new_position = self.body.spherical_to_cartesian(new_position) self.observer.set_camera_pos(new_position) target_pos = new_position + direction * 10 * units.m target_pos = self.body.cartesian_to_spherical(target_pos) (x, y, distance) = self.body.spherical_to_longlat(target_pos) target_height = self.body.surface.get_height_at(x, y, strict=True) if target_height is not None: target_pos = (target_pos[0], target_pos[1], target_height + altitude) else: print("Patch not found for", x, y, '->', target_pos[2]) target_pos = self.body.spherical_to_cartesian(target_pos) rot, angle = self.observer.calc_look_at(target_pos, rel=False)
def __init__(self, position=None, right_asc=0.0, right_asc_unit=units.Deg, declination=0.0, declination_unit=units.Deg, distance=0.0, distance_unit=units.Ly, frame=None): Orbit.__init__(self, frame) if position is None: self.right_asc = right_asc * right_asc_unit self.declination = declination * declination_unit distance = distance * distance_unit else: self.right_asc = None self.declination = None if not isinstance(position, LPoint3d): position = LPoint3d(*position) if position is None: inclination = pi / 2 - self.declination ascending_node = self.right_asc + pi / 2 inclination_quat = LQuaterniond() inclination_quat.setFromAxisAngleRad(inclination, LVector3d.unitX()) ascending_node_quat = LQuaterniond() ascending_node_quat.setFromAxisAngleRad(ascending_node, LVector3d.unitZ()) self.orientation = inclination_quat * ascending_node_quat * J2000EquatorialReferenceFrame.orientation position = self.orientation.xform(LVector3d(0, 0, distance)) self.global_position = position self.position = LPoint3d() self.rotation = LQuaterniond()
def update_instance(self, camera_pos, orientation): body = self.parent if body.is_emissive() and (not body.resolved or isinstance(body, DeepSpaceObject)): if body.scene_position != None: self.instance.setPos(*body.scene_position) scale = abs(self.context.observer.pixel_size * body.get_label_size() * body.scene_distance) else: scale = 0.0 else: offset = body.get_apparent_radius() * 1.01 rel_front_pos = body.rel_position - orientation.xform(LPoint3d(0, offset, 0)) vector_to_obs = LVector3d(-rel_front_pos) distance_to_obs = vector_to_obs.length() vector_to_obs /= distance_to_obs position, distance, scale_factor = self.get_real_pos_rel(rel_front_pos, distance_to_obs, vector_to_obs) self.instance.setPos(*position) scale = abs(self.context.observer.pixel_size * body.get_label_size() * distance) color = body.get_label_color() * self.fade self.look_at.set_pos(LVector3(*(orientation.xform(LVector3d.forward())))) self.label_instance.look_at(self.look_at, LVector3(), LVector3(*(orientation.xform(LVector3d.up())))) color[3] = 1.0 self.label.setTextColor(color) if scale < 1e-7: print("Label too far", self.get_name()) scale = 1e-7 self.instance.setScale(scale)
def __init__(self, model, offset=None, rotation=None, scale=None, auto_scale_mesh=True, flatten=True, panda=False, attribution=None, context=defaultDirContext): Shape.__init__(self) self.model = model self.attribution = attribution self.context = context if offset is None: offset = LPoint3d() self.offset = offset if rotation is None: rotation = LQuaterniond() if scale is None and not auto_scale_mesh: scale = LVector3d(1, 1, 1) self.scale_factor = scale self.rotation = rotation self.auto_scale_mesh = auto_scale_mesh self.flatten = flatten self.panda = panda self.mesh = None self.callback = None self.cb_args = None
def _setup_camera(self, focal_point: LVector3d): """Setup camera for this camera controller.""" node_render: NodePath = self._camera_anchor.getParent() focal_point = LVector3d(*focal_point) last_camera_pos_abs = LVector3d(*self._camera.getPos(node_render)) # Place anchor at focal point self._camera_anchor.setPos(*focal_point) # Place camera in front of anchor dist_anchor_to_camera: float = ( last_camera_pos_abs - LVector3d(*self._camera_anchor.getPos())).length() self._camera.setPos(0, dist_anchor_to_camera, 0) self._camera.setHpr(180, 0, 0) # Anchor look at camera abs position from before setup self._camera_anchor.lookAt(node_render, *last_camera_pos_abs)
def calc_look_at(self, target, rel=True, position=None): if not rel: if position is None: position = self.get_pos() direction = LVector3d(target - position) else: direction = LVector3d(target) direction.normalize() local_direction = self.get_rot().conjugate().xform(direction) angle = LVector3d.forward().angleRad(local_direction) axis = LVector3d.forward().cross(local_direction) if axis.length() > 0.0: new_rot = utils.relative_rotation(self.get_rot(), axis, angle) # new_rot=LQuaterniond() # lookAt(new_rot, direction, LVector3d.up()) else: new_rot = self.get_rot() return new_rot, angle
def _handle_user_events_(self, ue, dt, delta=LVector3f()): if not self.FOCUS: return delta.set(0, 0, 0) cmds = ue.get_cmds(self) # Y-axis movement. if "move_y" in cmds: self._y_val += ue.y_diff delta.setY(self._y_val) else: self._y_val = 0 # X-axis movement. if "move_left" in cmds: delta.setX(self._x_val) if "move_right" in cmds: delta.setX(-self._x_val) # Z-axiz movement. if "move_up" in cmds: delta.setZ(-self._z_val) if "move_down" in cmds: delta.setZ(self._z_val) # Heading rotation. if "rotate_heading" in cmds: self._h_val += ue.x_diff * self._rot_factor # Only change heading if mouse moves out of "y_zone". _y_zone = self._y_zone * self._rot_factor if self._h_val > _y_zone or self._h_val < -_y_zone: self.NP.setH(self.NP, -(self._h_val - _y_zone)) else: self._h_val = 0 # Pitch rotation. if "rotate_pitch" in cmds: self._p_val += ue.y_diff * self._rot_factor self.LENS.setViewHpr(0, -self._p_val * 20, 0) # Translate and apply delta. mat = self.NP.getTransform(render).getMat() trans_delta = LVector3d(*mat.xformVec(delta)) * dt self.focus_pos += trans_delta self.sys_pos = self.FOCUS.sys_pos - self.focus_pos # Correct tilt of camera to stay level with surface. delta.normalize() _pos = LVector3f(*self.focus_pos) _pos.normalize() deg = self._prev_pos.angleDeg(_pos) y_deg = deg * delta.y x_deg = deg * delta.x self.NP.setP(self.NP, y_deg) self.NP.setR(self.NP, -x_deg) self._prev_pos = _pos
def instanciate_body(universe, item_type, item_name, item_data): ra = None decl = None distance = None type = None radius = None axis = None angle = None abs_magnitude = None app_magnitude = None orbit = None axis = LVector3d.up() angle = 0.0 names = names_list(item_name) for (key, value) in item_data.items(): if key == 'RA': ra = value elif key == 'Dec': decl = value elif key == 'Distance': distance = value elif key == 'Type': type = value elif key == 'Radius': radius = value elif key == 'Axis': axis = LVector3d(*value) elif key == 'Angle': angle = value elif key == 'AbsMag': abs_magnitude = value elif key == 'AppMag': app_magnitude = value elif key == 'InfoURL': pass # = value else: print("Key of", item_type, key, "not supported") orbit = FixedPosition(right_asc=ra, right_asc_unit=units.HourAngle, declination=decl, distance=distance, distance_unit=units.Ly) rot = utils.LQuaternionromAxisAngle(axis, angle, units.Deg) rotation = FixedRotation(rot, J2000EquatorialReferenceFrame()) if app_magnitude != None and distance != None: abs_magnitude = units.app_to_abs_mag(app_magnitude, distance) dso = Galaxy(names, abs_magnitude=abs_magnitude, radius=radius, orbit=orbit, rotation=rotation) return dso
def __get_State(self, sys_pos, obj_vec=LVector3d(0, 0, 0)): state = {} for obj_id, o in self.BODIES.items(): obj_vec.set(o['x'].value, o['y'].value, o['z'].value) dist = (sys_pos - obj_vec).length() if dist < o['_prox']: state[obj_id] = { 'sys_pos': (o['x'].value, o['y'].value, o['z'].value), 'sys_vec': (o['vx'].value, o['vy'].value, o['vz'].value), 'sys_hpr': (o['h'].value, o['p'].value, o['r'].value), 'sys_rot': (o['rh'].value, o['rp'].value, o['rr'].value) } return state
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 go_to_surface(self, duration = None, height=1.001): if not self.ui.selected: return target = self.ui.selected if duration is None: duration = settings.slow_move print("Go to surface", target.get_name()) self.ui.sync_selected() center = target.get_rel_position_to(self.ship._global_position) direction = self.ship.get_pos() - center new_orientation = LQuaterniond() lookAt(new_orientation, direction) height = target.get_height_under(self.ship.get_pos()) + 10 * units.m new_position = center + new_orientation.xform(LVector3d(0, height, 0)) self.move_and_rotate_to(new_position, new_orientation, duration=duration)