Created
May 27, 2021 08:38
-
-
Save akiross/26a88fcf8d7eafd26b5676a2f0cd9089 to your computer and use it in GitHub Desktop.
Parallel animation example on pythreejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"id": "6b644e4d", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "pythree_example_model_159", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"Renderer(camera=PerspectiveCamera(aspect=1.5, position=(10.0, 10.0, 10.0), projectionMatrix=(1.0, 0.0, 0.0, 0.…" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"from pythreejs import *\n", | |
"import ipywidgets\n", | |
"from IPython.display import display\n", | |
"\n", | |
"# Reduce repo churn for examples with embedded state:\n", | |
"from pythreejs._example_helper import use_example_model_ids\n", | |
"use_example_model_ids()\n", | |
"\n", | |
"view_width = 600\n", | |
"view_height = 400\n", | |
"\n", | |
"sphere = Mesh(\n", | |
" SphereBufferGeometry(1, 32, 16),\n", | |
" MeshStandardMaterial(color='red'),\n", | |
" name=\"sfera\"\n", | |
")\n", | |
"\n", | |
"cube = Mesh(\n", | |
" BoxBufferGeometry(1, 1, 1),\n", | |
" MeshPhysicalMaterial(color='green'),\n", | |
" position=[2, 0, 4],\n", | |
" name=\"cubo\"\n", | |
")\n", | |
"\n", | |
"camera = PerspectiveCamera(position=[10, 10, 10], aspect=view_width/view_height)\n", | |
"key_light = DirectionalLight(position=[0, 10, 10])\n", | |
"ambient_light = AmbientLight()\n", | |
"\n", | |
"positon_track = VectorKeyframeTrack(name='scene/sfera.position',\n", | |
" times=[0, 2, 5, 6],\n", | |
" values=[0, 0, 0, 3, 0, 0, 3, 5, 0, 0, 0, 0])\n", | |
"\n", | |
"cube_pos_track = VectorKeyframeTrack(\n", | |
" name='scene/cubo.position',\n", | |
" times=[0, 1, 2, 6],\n", | |
" values=[2, 0, 4, 0, 0, 0, 6, 0, 6, 2, 0, 4]\n", | |
")\n", | |
"\n", | |
"scene = Scene(children=[sphere, cube, camera, key_light, ambient_light])\n", | |
"\n", | |
"scene_clip = AnimationClip(tracks=[positon_track, cube_pos_track])\n", | |
"scene_action = AnimationAction(AnimationMixer(scene), scene_clip, scene)\n", | |
"\n", | |
"controller = OrbitControls(controlling=camera)\n", | |
"renderer = Renderer(camera=camera, scene=scene, controls=[controller],\n", | |
" width=view_width, height=view_height)\n", | |
"\n", | |
"renderer" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"id": "659ac6cb", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "pythree_example_model_156", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"AnimationAction(clip=AnimationClip(duration=6.0, tracks=(VectorKeyframeTrack(name='scene/sfera.position', time…" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"scene_action" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "17797ae1", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.8.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See this as well: https://gist.github.com/moorepants/c5ebb846499c4002744b8c101705015f