Showing posts with label animation. Show all posts
Showing posts with label animation. Show all posts

Wednesday, November 27, 2024

Day 12 and Last Day: 30-days to learn rgl, plotly, and gganimate - Create a Time-Based 3D Animation Using rgl and gganimate

 



N.B.: This is the last of learning a combination of rgl, plotly, and gganimate, as it becomes difficult to combine all these at this time.  

Step 1: Install Required Packages

Before starting, ensure the following packages are installed:

install.packages(c("rgl", "ggplot2", "gganimate", "ggimage"))

Step 2: Generate 3D Frames Using rgl

1.     Setup the Environment: Create a 3D scatter plot that rotates over time.

library(rgl)
 
# Create a 3D scatter plot
n <- 100  # Number of points
x <- rnorm(n)
y <- rnorm(n)
z <- rnorm(n)
col <- rainbow(n)
 
open3d()  # Initialize the 3D plot
plot3d(x, y, z, col = col, size = 5)

2.     Rotate and Save Frames: Capture frames by rotating the plot over time and saving each frame as an image.

frames_dir <- "frames"
dir.create(frames_dir, showWarnings = FALSE)  # Create a directory for frames
 
# Generate and save frames
for (i in 1:100) {
    view3d(userMatrix = rotationMatrix(pi * i / 50, 0, 1, 0))  # Rotate around Y-axis
    snapshot3d(file.path(frames_dir, paste0("frame_", sprintf("%03d", i), ".png")))
}

Step 3: Animate Frames Using gganimate

1.     Prepare Frame Data: Load the saved frames and prepare a data frame for animation.

library(ggplot2)
library(gganimate)
library(ggimage)
 
# List saved frames
frame_paths <- list.files(frames_dir, full.names = TRUE)
 
# Create a data frame
frame_df <- data.frame(
    frame = frame_paths,
    time = 1:length(frame_paths),  # Time points for animation
    x = 0,  # Placeholder for x-coordinate
    y = 0   # Placeholder for y-coordinate
)

2.     Build the Animation: Use gganimate to create the animation from the frames.

animation <- ggplot(frame_df, aes(x = x, y = y, image = frame)) +
    geom_image(size = 1) +              # Add images to the plot
    transition_time(time) +            # Transition over the time variable
    enter_fade() +                     # Fade-in effect
    exit_fade() +                      # Fade-out effect
    theme_void()                       # Remove unnecessary plot elements

3.     Save the Animation: Export the animation as a GIF.

anim_save("3d_time_animation.gif", animation)

Step 4: Review and Debug

  • Check the saved animation in your working directory (3d_time_animation.gif).
  • If the animation doesn’t look smooth, adjust the number of frames or transition settings.

Key Notes

  1. Custom Rotation: You can modify the view3d() function to rotate around different axes or add zoom effects.
  2. Image Quality: Ensure the rgl frames are saved with high resolution for better animation quality.
  3. Animation Effects: Experiment with different gganimate effects like ease_aes() or transitions (transition_states()).

Tuesday, November 26, 2024

Day 11: 30-days to learn rgl, plotly, and gganimate - Learn How to Save rgl 3D Frames and Stitch Them Into an Animation With gganimate

 

Step 1: Set Up the Environment

1.     Install Required Packages
Ensure you have the following packages installed:

install.packages(c("rgl", "gganimate", "magick"))

The magick package will handle image processing for stitching frames.

2.     Load the Libraries
Load the necessary libraries:

library(rgl)
library(magick)
library(gganimate)

Step 2: Create an rgl 3D Plot

1.     Generate Data for 3D Visualization
Create a 3D dataset for plotting:

set.seed(123)
x <- rnorm(100)
y <- rnorm(100)
z <- rnorm(100)
colors <- rainbow(100)
 
# Create a 3D scatter plot
plot3d(x, y, z, col = colors, size = 5, type = "s")

2.     Set Up Rotation or Camera Movements
Define the rotation sequence or camera viewpoints:

n_frames <- 36  # Number of frames
angles <- seq(0, 360, length.out = n_frames)

Step 3: Save rgl Frames

1.     Create a Temporary Directory for Frames
Create a directory to save the images:

dir.create("rgl_frames")

2.     Save Each Frame
Loop through the angles and save an image for each:

for (i in seq_along(angles)) {
    rgl.viewpoint(theta = angles[i], phi = 30, fov = 60)
    snapshot3d(sprintf("rgl_frames/frame_%03d.png", i))
}

Step 4: Combine Frames Into an Animation

1.     Use magick to Stitch Images
Load and combine the images:

frames <- list.files("rgl_frames", full.names = TRUE, pattern = "png")
animation <- image_read(frames) %>%
             image_animate(fps = 10)  # Set frames per second

2.     Save the Animation
Save the animation as a GIF:

image_write(animation, "rgl_animation.gif")

Step 5: (Optional) Combine With gganimate

1.     Create a Data Frame for gganimate
If you want to integrate gganimate, create a dataset representing each frame's data:

animation_data <- data.frame(
    x = rep(x, n_frames),
    y = rep(y, n_frames),
    z = rep(z, n_frames),
    frame = rep(1:n_frames, each = length(x))
)

2.     Visualize With ggplot2 and gganimate
Use ggplot2 to create a dynamic scatter plot:

library(ggplot2)
ggplot(animation_data, aes(x = x, y = y, color = z, frame = frame)) +
    geom_point() +
    transition_manual(frame) +
    theme_minimal()

Step 6: Clean Up

1.     Remove Temporary Files
Delete the directory containing frames:

unlink("rgl_frames", recursive = TRUE)

2.     Review the Final Animation
Check the GIF and tweak the settings (e.g., angles, FPS) if needed.


Wednesday, October 23, 2024

Day 29: Blender tutorial for making illustrations – Preparing a YouTube-Ready Video

 


Step 1: Review the Final Video

Before diving into YouTube optimizations, you’ll need to ensure that your video is polished and fully edited. Recheck:

  • Voice Syncing: Ensure that your voiceover aligns with the visuals.
  • Subtitles & Captions: If you added subtitles on Day 27, confirm they appear at the right times.
  • Transitions & Animations: Make sure animations, transitions, and effects are smooth and visually appealing.
  • Audio Quality: Ensure clear, crisp audio without background noise.

Step 2: Choose the Correct Video Format

YouTube supports multiple video formats, but the preferred and most widely compatible is MP4. Blender allows exporting animations in MP4 format.

  1. Go to the "Output Properties" tab in Blender.
  2. Under File Format, select FFmpeg Video.
  3. Container: Choose MPEG-4 (MP4) for YouTube compatibility.
  4. Codec: Ensure the video codec is set to H.264, which offers the best balance of quality and file size.
  5. Audio Codec: If you added a voiceover, select AAC for the audio codec, which is also YouTube-friendly.

Step 3: Set Resolution & Frame Rate

For optimal YouTube video quality, adjust the resolution and frame rate in Blender:

  • Resolution: Set the resolution to 1920x1080 pixels (Full HD). This is the standard for YouTube videos and ensures your content looks crisp.
  • Frame Rate: YouTube videos should ideally be at 30 FPS (frames per second) or 60 FPS for smoother animations.
    • You can change this under Dimensions > Frame Rate in Blender’s Output Properties.

Step 4: Adjust Bitrate for Video Quality

You want a good balance between file size and quality. When exporting your video, pay attention to the bitrate:

  • Bitrate for Full HD: Set the bitrate to 10,000–12,000 kbps for high-quality 1080p video.
    • You can set this in Blender under the "Encoding" options (part of the Output Properties tab).

Step 5: Add a Thumbnail

Thumbnails are crucial for YouTube videos, as they determine whether viewers click on your video. You can create a custom thumbnail in Blender using a still frame from your video or a separately designed image.

  1. Select an appealing frame from your video or create a separate visual using text and graphics.
  2. Export it as an image (preferably PNG or JPEG).
  3. Make sure the thumbnail has a resolution of 1280x720 pixels.

Step 6: Optimize Video Title, Description, and Tags

Now that your video is YouTube-ready, let’s focus on the metadata to maximize visibility.

  • Title: Create a clear, engaging, and descriptive title.
    • Example: "Learn Medical Concepts with Blender Animations | Flowcharts & Diagrams Explained"
  • Description: Add a detailed description summarizing the video content.
    • Include relevant keywords like "Blender tutorial," "flowcharts," "educational diagrams," "Quran learning," or any other topic covered.
    • Add your Patreon link, social media handles, or any links to additional resources.
  • Tags: Use relevant keywords that describe your video. For example, "Blender," "educational videos," "flowcharts," "mindmaps," and your niche like "biology," "Quranic learning," etc.

Step 7: Video Settings for Uploading

Before uploading, double-check the following YouTube settings:

  • Privacy Setting: Choose Public to make the video available to everyone, or Unlisted if you want to share it with select individuals first.
  • Category: Select the correct category, such as Education.
  • Monetization (Optional): If you’re eligible for monetization, turn this on.
  • Video Language & Captions: Set the language of the video and enable captions if applicable.

Step 8: Video End Screens and Cards

Enhance engagement by adding:

  • End Screens: Include clickable elements at the end of your video for viewers to subscribe, watch more videos, or visit your website.
  • Cards: You can add interactive elements during the video to link to related content or playlists.

Step 9: Review and Upload

Once everything is set:

  1. Upload your video using YouTube's "Upload" feature.
  2. Double-check the preview of the video to ensure everything (title, description, thumbnail) appears correctly.
  3. Publish your video.

Outcome

Your video is now YouTube-ready and will have the right quality, engaging metadata, and appealing visuals to attract and retain viewers.

Source:
ChatGPT


Tuesday, October 22, 2024

Day 28: Blender tutorial for making illustrations – Review and Final Touches

Step 1: Review Your Illustrations

  • Go over all the visuals you’ve created for your video. Check every diagram, flowchart, mind map, or educational graphic for completeness and accuracy.
    • Ask yourself: Is the information clear? Are the illustrations visually appealing and easy to follow?
  • Ensure consistency in design:
    • Consistent use of colors, text sizes, and fonts.
    • Uniform line thickness and styles across diagrams.

Tip: If certain parts of your video seem unclear or crowded, consider simplifying or breaking them into smaller sections.


Step 2: Fine-Tune Your Animations

  • Rewatch your animated sequences to ensure they are smooth and engaging.
    • Check for any awkward movements, pauses, or transitions.
    • Ensure animations are timed well to match the pace of your narration.
  • If needed, use Blender’s Graph Editor to smooth out any jerky movements.
    • Adjust ease-in and ease-out settings for smoother transitions.
    • If an element appears too fast or slow, tweak the animation timeline accordingly.

Tip: Animations should enhance understanding. If they distract from the main message, consider simplifying or slowing them down.


Step 3: Optimize Your Voice Narration

  • Listen to your voiceover carefully and note any sections where the audio is unclear, too fast, or doesn’t align well with the visuals.
    • Re-record any problematic sections if needed. Use the same recording settings for consistency.
  • Sync your voiceover with key visual moments in the video.
    • Ensure important points in the narration are highlighted with corresponding visuals.

Tip: For better engagement, match your tone and pace with the educational content. If discussing complex topics, slow down slightly to help viewers absorb the information.


Step 4: Check for Audio-Visual Sync

  • Watch the video with both visuals and audio playing together.
    • Ensure that transitions between visuals are in sync with the narration.
    • Verify that key points in your audio are highlighted with matching visual cues (e.g., text appearing, diagrams lighting up).
  • Adjust the timing of animations if they’re too fast or slow compared to your voice.

Step 5: Refine the Background and Overall Design

  • Look at the background and lighting in your illustrations and animations.
    • Does the background complement the visuals, or is it too distracting? If it’s overwhelming, opt for something simpler or subtler.
    • Ensure lighting is adding depth and clarity to the visuals, not overpowering them.

Tip: Adjust the brightness and contrast of your lighting to ensure the primary content stands out clearly.


Step 6: Test for Accessibility

  • Add captions or subtitles for better accessibility, especially for non-native speakers or viewers with hearing impairments.
    • Ensure that captions are accurately timed with the narration.
    • If possible, include on-screen annotations for emphasis, such as arrows, highlights, or brief text explanations.

Tip: Use Blender’s text tools or a separate video editor to add clear and concise subtitles.


Step 7: Ensure File Quality and Format

  • Set the correct resolution and export settings in Blender:
    • For YouTube, use a resolution of 1920x1080 (1080p) for Full HD quality.
    • Ensure the frame rate is consistent, typically 24-30 fps for educational content.
    • Choose a video format like MP4 with H.264 encoding for efficient file size without losing quality.

Tip: Run a quick test export of a small section to ensure the quality is up to your standards before exporting the full video.


Step 8: Render a Final Video

  • After making all adjustments, render the entire video.
    • Monitor the rendering process to ensure no errors occur.
    • Check the final rendered video for any last-minute issues like timing errors, visual glitches, or audio sync problems.

Step 9: Final Playback and Review

  • Watch the entire video from start to finish as if you were the audience.
    • Pay attention to the flow of the video: Does it feel smooth and logical? Does it effectively communicate the educational content?
    • Ask yourself if you would find it engaging, informative, and easy to follow.

Tip: If possible, get feedback from someone else before moving to the next step. Fresh eyes can help spot issues you might have missed.


Step 10: Prepare for YouTube Upload

  • Ensure all elements of the video (title screen, visuals, audio, captions) are finalized and ready for upload.
  • Export a thumbnail that clearly represents the content of your video.
    • Make sure it’s visually appealing and includes readable text (if applicable).

Source:
ChatGPT


Monday, October 21, 2024

Day 27: Blender tutorial for making illustrations – Adding Subtitles and Annotations in Blender (for Illustrative Videos)

Step 1: Prepare Your Voiceover/Audio

  1. Record Your Voiceover:
    • Ensure your voiceover is clear and well-paced. If you’ve already added it to your video (as done in Day 19), make sure it is synced properly with your animations.
  2. Transcribe Your Voiceover:
    • Listen to your voiceover and type out the script for subtitles. This will be the text you'll use for the subtitles. Make sure the transcription is accurate.

Step 2: Switch to Blender’s Video Sequencer

  1. Open the Video Editing Layout:
    • In Blender, go to the "Video Editing" workspace from the top of the interface or by selecting it from the workspace dropdown menu.
  2. Add Your Animation:
    • Load the animated video created in previous days by clicking Add > Movie or Add > Image Sequence if you rendered your animations as image frames.

Step 3: Add Text Strips for Subtitles

  1. Add Text Strips for Subtitles:
    • In the timeline (lower area), go to Add > Text. A text strip will appear in the sequencer.
  2. Adjust the Duration:
    • Drag the text strip to match the timing of the relevant spoken words in your voiceover. Make sure the text strip starts and ends exactly when the dialogue is happening.
  3. Edit the Text:
    • With the text strip selected, click on the Modifiers tab in the properties area. Here you can type the subtitle text you want to display. Add the transcribed sentences, one by one.
  4. Customize the Appearance:
    • Change the font, size, and position of the text by selecting the text strip and adjusting the options under Strip > Transform or in the text strip properties panel. You can position the subtitles at the bottom of the screen, change their color, or add a background for better visibility.

Step 4: Sync Subtitles with Audio

  1. Play Through the Sequence:
    • Use the timeline play button or press Spacebar to play your video and make sure the subtitles appear at the correct times.
  2. Adjust Timing if Needed:
    • Adjust the text strips by dragging them along the timeline to fine-tune their start and end points to ensure synchronization with the voiceover.

Step 5: Add Annotations

  1. Use Grease Pencil for Annotations:
    • Switch back to the 3D View workspace, and use the Grease Pencil tool to draw or write annotations directly onto the video.
    • Create a new Grease Pencil object, and then use the Draw Tool to write notes, labels, or arrows that highlight key parts of your illustrations.
  2. Animate the Annotations:
    • You can animate these annotations by using the keyframes function. For example, you can make an annotation appear at a specific time and disappear later. This will guide your audience to focus on the important parts of the visual content.
  3. Add Text Annotations:
    • Another option for adding annotations is through text objects. In the Add Menu, choose Text, and position it within the 3D scene to add notes or explanations. You can animate the text objects similarly, using keyframes.

Step 6: Preview and Fine-Tune

  1. Preview the Full Video:
    • Play through your entire animation to ensure that subtitles and annotations are appearing correctly at the intended moments and are synchronized with the voiceover.
  2. Fine-Tune the Appearance:
    • Adjust the text size, timing, and appearance of annotations if needed to improve clarity and readability.

Step 7: Rendering the Final Video with Subtitles

  1. Set up the Render:
    • Once satisfied with the timing of subtitles and annotations, set up the final render. Switch to the Output Properties panel, choose your desired format (MP4, AVI, etc.), and set the resolution and frame rate.
  2. Render the Animation:
    • Click Render > Render Animation to export the video with subtitles and annotations embedded.

Step 8: Export as SRT File (Optional)

  • If you want to upload subtitles separately, you can manually create an SRT (SubRip Subtitle) file for platforms like YouTube. Tools like Subtitle Edit or Aegisub can be used to add the same subtitles, and the timings you adjusted in Blender can guide your SRT creation.

Source:

ChatGPT