Files
2025-10-20 23:35:51 +02:00

173 lines
5.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import bpy
import math
import bmesh
import re
from mathutils.bvhtree import BVHTree
from mathutils import Vector, Euler, Matrix
import time
import flight_animation
### Setting the globe (the object of which the surface will be used as the height)
main_sphere = bpy.data.objects["Sphere.002"]
### Making the globe useful
origin: Vector = main_sphere.matrix_world.translation
bvh=flight_animation.create_bvh_from_object(main_sphere)
### Setting up world
airport_shader: bpy.types.Material | None = None # Placeholder for shader, can be set to a specific material if needed
flughafen1 = flight_animation.Airport( # Change to Place you want
name="BER2",
lon_lat="52° 21 44″ N, 13° 30 2″ O",
bvh=bvh,
origin=origin,
radius=0.1,
shader=airport_shader
)
flughafen2 = flight_animation.Airport(
name="HEL",
lon_lat="60° 19 2″ N, 24° 57 48″ O",
bvh=bvh,
origin=origin,
radius=0.1,
shader=airport_shader
)
flughafen3 = flight_animation.Airport(
name="NRT",
lon_lat="35° 45 53″ N, 140° 23 11″ O",
bvh=bvh,
origin=origin,
radius=0.1,
shader=airport_shader
)
### Initialize Animation
airplane = bpy.data.objects["Airplane"]
# airplane_vector = Vector((0, 1, 0)) # Setting the airplane default vector (x, y, z)
# reset_object(airplane) # Resetting the airplane location and rotation
centerjoint = bpy.data.objects["Center_Joint"]
# centerjoint_vectors = Vector((0, 0, 1)) # Setting the center joint default vector (x, y, z)
# reset_object(centerjoint) # Resetting the center joint location and rotation
### Animation Logic
# Way between airport1 and airport2
for airport in [flughafen1, flughafen2, flughafen3]:
print("lat: ", airport.latitude, "lon: ", airport.longitude)
lat=[
math.radians(flughafen1.latitude - 90),
math.radians(flughafen2.latitude - 90),
math.radians(flughafen3.latitude - 90)
]
print("lat:", lat)
lon=[
math.radians(flughafen1.longitude-90),
math.radians(flughafen2.longitude-90),
math.radians(flughafen3.longitude-90)
]
print("lon:", lon)
airplane_height = [
flughafen1.get_coordinates().length + 0.1,
flughafen2.get_coordinates().length + 0.1,
flughafen3.get_coordinates().length + 0.1
]
print("airplane_height:", airplane_height)
travel_height = airplane_height[0] * 1.1 # for 10% extra height in relation to the origin
print("travel_height:", travel_height)
# Set to the Rotation the plane needs to have for the correct rotation at the airport
airplane_rotation = [ # rotate the airplane at the timestamps of the airports !!! Only rotate the z achses in the plane propertys
math.radians(-35), # rotate so the plane on the first airport so that the front points to the 2nd
math.radians(-42), # rotate the plane at the second airport so that the back points to the last airport
math.radians(-111), # like first rotation from 2nd to third
math.radians(-102) # like 2nd rotation
] #! You do not need more rotation points the rest is done by the interpolation in blender. Maybe you need to set the motion to a constant instead of accelerating and decelerating
frame_count = 720
clear_timeline([airplane, centerjoint])
airplane.rotation_euler.x = math.radians(90)
### Start BER
bpy.context.scene.frame_set(0)
airplane.location.z = airplane_height[0]
airplane.keyframe_insert(data_path="location", index=2)
airplane.rotation_euler.z = airplane_rotation[0]
airplane.keyframe_insert(data_path="rotation_euler", index=2)
centerjoint.rotation_euler.x = lat[0]
centerjoint.rotation_euler.z = lon[0]
centerjoint.keyframe_insert(data_path="rotation_euler", index=-1)
### flight height start
bpy.context.scene.frame_set(32)
airplane.location.z = travel_height
airplane.keyframe_insert(data_path="location", index=2)
### End of high flight
bpy.context.scene.frame_set(49)
airplane.location.z = travel_height
airplane.keyframe_insert(data_path="location", index=2)
### Landing HEL
bpy.context.scene.frame_set(81)
airplane.location.z = airplane_height[1]
airplane.keyframe_insert(data_path="location", index=2)
airplane.rotation_euler.z = airplane_rotation[1]
airplane.keyframe_insert(data_path="rotation_euler", index=2)
centerjoint.rotation_euler.x = lat[1]
centerjoint.rotation_euler.z = lon[1]
centerjoint.keyframe_insert(data_path="rotation_euler", index=-1)
### Start HEL
bpy.context.scene.frame_set(127)
airplane.location.z = airplane_height[1]
airplane.keyframe_insert(data_path="location", index=2)
airplane.rotation_euler.z = airplane_rotation[2]
airplane.keyframe_insert(data_path="rotation_euler", index=2)
centerjoint.rotation_euler.x = lat[1]
centerjoint.rotation_euler.z = lon[1]
centerjoint.keyframe_insert(data_path="rotation_euler", index=-1)
### flight height start
bpy.context.scene.frame_set(255)
airplane.location.z = travel_height
airplane.keyframe_insert(data_path="location", index=2)
### End of high flight
bpy.context.scene.frame_set(592)
airplane.location.z = travel_height
airplane.keyframe_insert(data_path="location", index=2)
### Landing NRT
bpy.context.scene.frame_set(720)
airplane.location.z = airplane_height[2]
airplane.keyframe_insert(data_path="location", index=2)
airplane.rotation_euler.z = airplane_rotation[3]
airplane.keyframe_insert(data_path="rotation_euler", index=2)
centerjoint.rotation_euler.x = lat[2]
centerjoint.rotation_euler.z = lon[2]
centerjoint.keyframe_insert(data_path="rotation_euler", index=-1)
### reset
bpy.context.scene.frame_set(0)
print("END")