Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,7 +34,25 @@ def add_planet(name, radius, mass, distance_from_sun):
|
|
| 34 |
planet.name = name
|
| 35 |
planet.data.materials.append(material)
|
| 36 |
planet["mass"] = mass
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
def create_planet_flyby_animation(planet, radius, duration):
|
| 40 |
bpy.context.view_layer.objects.active = planet
|
|
|
|
| 34 |
planet.name = name
|
| 35 |
planet.data.materials.append(material)
|
| 36 |
planet["mass"] = mass
|
| 37 |
+
bpy.context.view_layer.objects.active = planet
|
| 38 |
+
planet.select_set(True)
|
| 39 |
+
planet.animation_data_create()
|
| 40 |
+
planet.animation_data.action = bpy.data.actions.new(name="OrbitAction")
|
| 41 |
+
start_frame = 1
|
| 42 |
+
end_frame = int(duration * 10)
|
| 43 |
+
for frame in range(start_frame, end_frame + 1):
|
| 44 |
+
##angle = (frame / end_frame) * 2 * math.pi
|
| 45 |
+
##x = radius * math.cos(angle)
|
| 46 |
+
##y = planet.location.y
|
| 47 |
+
##z = radius * math.sin(angle)
|
| 48 |
+
##planet.location = (x, y, z)
|
| 49 |
+
##planet.keyframe_insert(data_path="location", index=-1, frame=frame)
|
| 50 |
+
angle = math.radians(frame * 18)
|
| 51 |
+
planet.rotation_euler = (0, 0, angle)
|
| 52 |
+
planet.rotation_mode = 'XYZ'
|
| 53 |
+
planet.keyframe_insert(data_path="rotation_euler", index=2, frame=start_frame)
|
| 54 |
+
planet.keyframe_insert(data_path="rotation_euler", index=2, frame=end_frame)
|
| 55 |
+
##return planet
|
| 56 |
|
| 57 |
def create_planet_flyby_animation(planet, radius, duration):
|
| 58 |
bpy.context.view_layer.objects.active = planet
|