├── src └── main │ ├── resources │ ├── config.yml │ └── plugin.yml │ └── java │ └── com │ └── battledash │ └── blendmc │ ├── BlendMC.java │ ├── utils │ └── MathUtil.java │ ├── parse │ ├── Marker.java │ ├── Frame.java │ ├── Vector3f.java │ ├── BlendCutscene.java │ └── BlendCameraAnimation.java │ └── commands │ └── CutsceneCommand.java ├── .gitignore ├── LICENSE ├── README.md ├── pom.xml └── CODE_OF_CONDUCT.md /src/main/resources/config.yml: -------------------------------------------------------------------------------- 1 | # Nothing here for now. -------------------------------------------------------------------------------- /src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: BlendMC 2 | version: ${project.version} 3 | main: com.battledash.blendmc.BlendMC 4 | prefix: BlendMC 5 | authors: [ BattleDash ] 6 | description: Blender Camera to Minecraft Cinematic Creator 7 | website: https://battleda.sh 8 | 9 | commands: 10 | cutscene: 11 | description: Test command 12 | permission: blendmc.command.cutscene 13 | usage: /cutscene -------------------------------------------------------------------------------- /src/main/java/com/battledash/blendmc/BlendMC.java: -------------------------------------------------------------------------------- 1 | package com.battledash.blendmc; 2 | 3 | import com.battledash.blendmc.commands.CutsceneCommand; 4 | import org.bukkit.plugin.java.JavaPlugin; 5 | 6 | public final class BlendMC extends JavaPlugin { 7 | 8 | private static BlendMC INSTANCE; 9 | 10 | public static BlendMC getInstance() { 11 | return INSTANCE; 12 | } 13 | 14 | @Override 15 | public void onEnable() { 16 | INSTANCE = this; 17 | saveDefaultConfig(); 18 | getCommand("cutscene").setExecutor(new CutsceneCommand()); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/battledash/blendmc/utils/MathUtil.java: -------------------------------------------------------------------------------- 1 | package com.battledash.blendmc.utils; 2 | 3 | import org.bukkit.util.Vector; 4 | 5 | public class MathUtil { 6 | 7 | // Cleaned up method from https://www.spigotmc.org/threads/rotating-location-around-the-y-axis-math.429476/ 8 | public static Vector rotateLocXZ(Vector loc, Vector axis, double angle) { 9 | double cos = Math.cos(angle); 10 | double sin = Math.sin(angle); 11 | Vector v = loc.clone().subtract(axis); 12 | return new Vector(new Vector(cos, 0, -sin).dot(v), 0, new Vector(sin, 0, cos).dot(v)).add(axis); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/battledash/blendmc/parse/Marker.java: -------------------------------------------------------------------------------- 1 | package com.battledash.blendmc.parse; 2 | 3 | public class Marker { 4 | 5 | private final String name; 6 | private final int frame; 7 | 8 | public Marker(String name, int frame) { 9 | this.name = name; 10 | this.frame = frame; 11 | } 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public int getFrame() { 18 | return frame; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return "Marker{" + 24 | "name='" + name + '\'' + 25 | ", frame=" + frame + 26 | '}'; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | .idea/ 26 | target/ 27 | pom.xml.tag 28 | pom.xml.releaseBackup 29 | pom.xml.versionsBackup 30 | pom.xml.next 31 | release.properties 32 | dependency-reduced-pom.xml 33 | buildNumber.properties 34 | .mvn/timing.properties 35 | # https://github.com/takari/maven-wrapper#usage-without-binary-jar 36 | .mvn/wrapper/maven-wrapper.jar 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 BattleDash 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main/java/com/battledash/blendmc/commands/CutsceneCommand.java: -------------------------------------------------------------------------------- 1 | package com.battledash.blendmc.commands; 2 | 3 | import com.battledash.blendmc.BlendMC; 4 | import com.battledash.blendmc.parse.BlendCameraAnimation; 5 | import com.battledash.blendmc.parse.BlendCutscene; 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.ChatColor; 8 | import org.bukkit.Location; 9 | import org.bukkit.command.Command; 10 | import org.bukkit.command.CommandExecutor; 11 | import org.bukkit.command.CommandSender; 12 | import org.bukkit.entity.Player; 13 | 14 | import java.io.File; 15 | import java.io.IOException; 16 | 17 | /** 18 | * Example command 19 | */ 20 | public class CutsceneCommand implements CommandExecutor { 21 | 22 | @Override 23 | public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { 24 | try { 25 | Player player = (Player) sender; 26 | BlendCameraAnimation parse = BlendCameraAnimation.parse( 27 | new File(BlendMC.getInstance().getDataFolder().getAbsolutePath() + "/Factions.blendmc")); 28 | BlendCutscene cutscene = new BlendCutscene(parse, 29 | new Location(Bukkit.getWorld("world"), 41.427, 185, 4.092)); 30 | cutscene.rotateAllFrames((float) Math.toRadians(90)); 31 | cutscene.play(player); 32 | } catch (IOException e) { 33 | e.printStackTrace(); 34 | } 35 | return true; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/battledash/blendmc/parse/Frame.java: -------------------------------------------------------------------------------- 1 | package com.battledash.blendmc.parse; 2 | 3 | import org.bukkit.util.Vector; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * 9 | * A single frame of a cutscene, which include the position and rotation of the camera. 10 | * 11 | * @author BattleDash 12 | * @since 1/12/2021 13 | */ 14 | public class Frame { 15 | 16 | private Vector location; 17 | private final Vector3f rot; 18 | private final List markers; 19 | 20 | public Frame(float[] location, float[] rotation, List markers) { 21 | // Rearrange Locations a bit here, blender uses a different rotation matrix (XZY) 22 | this.location = new Vector( 23 | -location[1], 24 | location[2], 25 | -location[0] 26 | ); 27 | // Calculate pitch/yaw from euler angles provided by blender. x = yaw, z = pitch, y = roll (unused) 28 | this.rot = new Vector3f( 29 | Vector3f.transformFloat(90 - (float) Math.toDegrees(rotation[2]), 180), 30 | (float) Math.toDegrees(rotation[1]), // roll, unused (I think) 31 | Vector3f.transformFloat(90 - (float) Math.toDegrees(rotation[0]), 90) 32 | ); 33 | this.markers = markers; 34 | } 35 | 36 | public Vector getLocation() { 37 | return location; 38 | } 39 | 40 | public void setLocation(Vector location) { 41 | this.location = location; 42 | } 43 | 44 | public Vector3f getRot() { 45 | return rot; 46 | } 47 | 48 | public List getMarkers() { 49 | return markers; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "Frame{" + 55 | "location=" + location + 56 | ", rot=" + rot + 57 | ", markers=" + markers + 58 | '}'; 59 | } 60 | } -------------------------------------------------------------------------------- /src/main/java/com/battledash/blendmc/parse/Vector3f.java: -------------------------------------------------------------------------------- 1 | package com.battledash.blendmc.parse; 2 | 3 | /** 4 | * Mostly copied from Vector3f in NMS code, but with some slight modifications. 5 | * 6 | * @author BattleDash 7 | * @since 1/12/2021 8 | */ 9 | public class Vector3f { 10 | protected float x; 11 | protected float y; 12 | protected float z; 13 | 14 | public Vector3f(float x, float y, float z) { 15 | this.x = !Float.isInfinite(x) && !Float.isNaN(x) ? x % 360.0F : 0.0F; 16 | this.y = !Float.isInfinite(y) && !Float.isNaN(y) ? y % 360.0F : 0.0F; 17 | this.z = !Float.isInfinite(z) && !Float.isNaN(z) ? z % 360.0F : 0.0F; 18 | } 19 | 20 | public void setX(float x) { 21 | this.x = !Float.isInfinite(x) && !Float.isNaN(x) ? x % 360.0F : 0.0F; 22 | } 23 | 24 | public void setY(float y) { 25 | this.y = !Float.isInfinite(y) && !Float.isNaN(y) ? y % 360.0F : 0.0F; 26 | } 27 | 28 | public void setZ(float z) { 29 | this.z = !Float.isInfinite(z) && !Float.isNaN(z) ? z % 360.0F : 0.0F; 30 | } 31 | 32 | public boolean equals(Object compareAgainst) { 33 | if (!(compareAgainst instanceof Vector3f)) { 34 | return false; 35 | } else { 36 | Vector3f vecOther = (Vector3f)compareAgainst; 37 | return this.x == vecOther.x && this.y == vecOther.y && this.z == vecOther.z; 38 | } 39 | } 40 | 41 | public static float transformFloat(float f, float bound) { 42 | if (f > bound) { 43 | return transformFloat(-bound + (f - bound), bound); 44 | } 45 | if (f < -bound) { 46 | return transformFloat(bound + (f + bound), bound); 47 | } 48 | return f; 49 | } 50 | 51 | public float getX() { 52 | return this.x; 53 | } 54 | 55 | public float getY() { 56 | return this.y; 57 | } 58 | 59 | public float getZ() { 60 | return this.z; 61 | } 62 | 63 | public String toString() { 64 | return "Vector3f{" + 65 | x + "," + 66 | y + "," + 67 | z + "}"; 68 | } 69 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

BlendMC

2 | 3 |

BlendMC: A Cinematic Camera plugin for Minecraft Spigot that uses Blender motion paths for cutscenes.

4 | 5 |

6 | 7 | 8 | 9 | 10 | 11 |

12 | 13 | ------ 14 | 15 |

16 | Examples • 17 | Usage • 18 | API 19 |

20 | 21 | ## Examples 22 | 23 | Click for full video: 24 | [![example](https://i.battleda.sh/1df746663a9497ac8c8234161ea907b0.png)](https://i.battleda.sh/b75e6bd0a0ecab074296fb6479dcfb3f.mp4) 25 | 26 |

27 | 28 | 29 |

30 | 31 | ## Usage 32 | 33 | To use BlendMC, you'll need [Blender 2.8](https://www.blender.org/download/) or newer installed on your computer. Once it's done, you can download the latest release of the BlendMC Exporter Addon [here](https://i.battleda.sh/stuff/mcblend.py). 34 | 35 | 1. Install [Blender 2.8](https://www.blender.org/download/) 36 | 2. Install the BlendMC Exporter Addon [here](https://i.battleda.sh/stuff/mcblend.py) 37 | 3. Select your camera, go to File > Export > BlendMC Camera Exporter, and save as a `.blendmc` file. Put this in your BlendMC plugin data folder. 38 | 39 | ## API 40 | 41 | Using the API is very simple. 42 | 43 | To create a cutscene: 44 | 45 | ```java 46 | Player player = null; // However you get a player. 47 | BlendCameraAnimation anim = BlendCameraAnimation.parse( 48 | new File(BlendMC.getInstance().getDataFolder().getAbsolutePath() + "/example.blendmc")); // The fully qualified path to your blendmc file. 49 | // Create a cutscene with the camera start location being the player's current position. 50 | BlendCutscene cutscene = new BlendCutscene(anim, player.getLocation()); 51 | ``` 52 | 53 | To play that cutscene: 54 | 55 | ```java 56 | cutscene.play(player, () -> { 57 | // this optional callback is ran when the cutscene ends 58 | }); 59 | ``` 60 | 61 | If the cutscene is in the wrong direction, you can easily rotate it like this: 62 | 63 | ```java 64 | // Rotate the entire cutscene 90° right clockwise. 65 | cutscene.rotateAllFrames((float) Math.toRadians(90)); 66 | ``` 67 | 68 | # Closing 69 | 70 | Pull Requests and issues/feature requests are welcome! 71 | 72 | **Note:** You are responsible for things like setting players to spectator mode. BlendMC does not do this automatically. -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.battledash 8 | BlendMC 9 | 1.0-SNAPSHOT 10 | jar 11 | 12 | BlendMC 13 | 14 | Blender Camera to Minecraft Cinematic Creator 15 | 16 | 1.8 17 | UTF-8 18 | 19 | battleda.sh 20 | 21 | 22 | 23 | 24 | org.apache.maven.plugins 25 | maven-compiler-plugin 26 | 3.8.1 27 | 28 | ${java.version} 29 | ${java.version} 30 | 31 | 32 | 33 | org.apache.maven.plugins 34 | maven-shade-plugin 35 | 3.2.4 36 | 37 | 38 | package 39 | 40 | shade 41 | 42 | 43 | false 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | src/main/resources 52 | true 53 | 54 | 55 | 56 | 57 | 58 | 59 | spigotmc-repo 60 | https://hub.spigotmc.org/nexus/content/repositories/snapshots/ 61 | 62 | 63 | sonatype 64 | https://oss.sonatype.org/content/groups/public/ 65 | 66 | 67 | 68 | 69 | 70 | org.spigotmc 71 | spigot 72 | 1.12.2-R0.1-SNAPSHOT 73 | provided 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /src/main/java/com/battledash/blendmc/parse/BlendCutscene.java: -------------------------------------------------------------------------------- 1 | package com.battledash.blendmc.parse; 2 | 3 | import com.battledash.blendmc.BlendMC; 4 | import com.battledash.blendmc.utils.MathUtil; 5 | import org.bukkit.Location; 6 | import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; 7 | import org.bukkit.entity.Player; 8 | import org.bukkit.scheduler.BukkitRunnable; 9 | import org.bukkit.util.Consumer; 10 | 11 | /** 12 | * An entire cutscene, this includes the {@link BlendCameraAnimation} and the start location of the camera. 13 | * 14 | * @author BattleDash 15 | * @since 1/12/2021 16 | */ 17 | public class BlendCutscene { 18 | 19 | private final BlendCameraAnimation animation; 20 | private Location startLocation; 21 | 22 | public BlendCutscene(BlendCameraAnimation animation, Location startLocation) { 23 | this.animation = animation.clone(); 24 | this.startLocation = startLocation; 25 | this.animation.getFrames().forEach(f -> f.setLocation(f.getLocation().add(startLocation.toVector()))); 26 | } 27 | 28 | public BlendCameraAnimation getAnimation() { 29 | return animation; 30 | } 31 | 32 | public Location getStartLocation() { 33 | return startLocation; 34 | } 35 | 36 | public void setStartLocation(Location startLocation) { 37 | this.startLocation = startLocation; 38 | } 39 | 40 | /** 41 | * Rotates all frames by positions around the axis (startLocation) and yaw rotation. 42 | * @param yaw 43 | */ 44 | public void rotateAllFrames(double yaw) { 45 | animation.getFrames().forEach(f -> f.getRot().setX(Vector3f.transformFloat(f.getRot().x + ((float) Math.toDegrees(yaw)), 46 | 180))); 47 | animation.getFrames().forEach(f -> f.setLocation(MathUtil.rotateLocXZ(f.getLocation(), 48 | startLocation.toVector().clone().setY(f.getLocation().getY()), 49 | yaw))); 50 | } 51 | 52 | public void play(Player player) { 53 | play(player, null, null, null); 54 | } 55 | 56 | public void play(Player player, Runnable startCallback, Runnable endCallback, Consumer markerCallback) { 57 | new BukkitRunnable() { 58 | int frameIndex = 0; 59 | @Override 60 | public void run() { 61 | Frame frame = animation.getFrames().get(this.frameIndex++); 62 | player.teleport(new Location(startLocation.getWorld(), 63 | frame.getLocation().getX(), 64 | frame.getLocation().getY(), 65 | frame.getLocation().getZ(), 66 | frame.getRot().getX(), 67 | frame.getRot().getZ())); 68 | if (frameIndex <= 1) startCallback.run(); 69 | ((CraftPlayer) player).getHandle().x().getPlayerChunkMap().movePlayer(((CraftPlayer) player).getHandle()); 70 | frame.getMarkers().forEach(markerCallback::accept); 71 | if (this.frameIndex >= animation.getFrames().size()) cancel(); 72 | } 73 | 74 | @Override 75 | public synchronized void cancel() throws IllegalStateException { 76 | if (endCallback != null) endCallback.run(); 77 | super.cancel(); 78 | } 79 | }.runTaskTimer(BlendMC.getInstance(), 0, 1); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at battledash@enlightenmc.net. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /src/main/java/com/battledash/blendmc/parse/BlendCameraAnimation.java: -------------------------------------------------------------------------------- 1 | package com.battledash.blendmc.parse; 2 | 3 | import org.bukkit.util.Vector; 4 | 5 | import javax.activation.UnsupportedDataTypeException; 6 | import java.io.*; 7 | import java.nio.charset.StandardCharsets; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | import java.util.stream.Collectors; 11 | 12 | /** 13 | * A full camera animation imported from blender, this includes the frame counts and an array of the {@link Frame}s 14 | * 15 | * @author BattleDash 16 | * @since 1/12/2021 17 | */ 18 | public class BlendCameraAnimation implements Cloneable { 19 | 20 | private final int startFrame; 21 | private final int endFrame; 22 | private final int totalFrames; 23 | private final List frames; 24 | 25 | public BlendCameraAnimation(int startFrame, int endFrame, int totalFrames, List frames) { 26 | this.startFrame = startFrame; 27 | this.endFrame = endFrame; 28 | this.totalFrames = totalFrames; 29 | Vector clone = frames.get(0).getLocation().clone(); 30 | this.frames = frames.stream().map(f -> { 31 | f.getLocation().subtract(clone); 32 | return f; 33 | }).collect(Collectors.toList()); 34 | } 35 | 36 | public int getStartFrame() { 37 | return startFrame; 38 | } 39 | 40 | public int getEndFrame() { 41 | return endFrame; 42 | } 43 | 44 | public int getTotalFrames() { 45 | return totalFrames; 46 | } 47 | 48 | public List getFrames() { 49 | return frames; 50 | } 51 | 52 | @Override 53 | public BlendCameraAnimation clone() { 54 | try { 55 | return ((BlendCameraAnimation) super.clone()); 56 | } catch (CloneNotSupportedException e) { 57 | return null; 58 | } 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "BlendCameraAnimation{" + 64 | "startFrame=" + startFrame + 65 | ", endFrame=" + endFrame + 66 | ", totalFrames=" + totalFrames + 67 | ", frames=" + frames + 68 | '}'; 69 | } 70 | 71 | public static BlendCameraAnimation parse(File file) throws IOException { 72 | return parse(new FileInputStream(file)); 73 | } 74 | 75 | public static BlendCameraAnimation parse(InputStream file) throws IOException { 76 | List strings = new ArrayList<>(); 77 | try (BufferedReader reader = new BufferedReader(new InputStreamReader(file, StandardCharsets.UTF_8))) { 78 | for (;;) { 79 | String line = reader.readLine(); 80 | if (line == null) 81 | break; 82 | strings.add(line); 83 | } 84 | } 85 | int seek = 0; 86 | if (!strings.get(seek++).equals("BLENDMC")) { 87 | throw new UnsupportedDataTypeException("This is not a BlendMC file."); 88 | } 89 | int startFrame = Integer.parseInt(strings.get(seek++)); 90 | int endFrame = Integer.parseInt(strings.get(seek++)); 91 | int totalFrames = Integer.parseInt(strings.get(seek++)); 92 | // Not the cleanest thing, but works for now. 93 | List frames = new ArrayList<>(); 94 | List locations = new ArrayList<>(); 95 | List rotations = new ArrayList<>(); 96 | for (int i = 0; i < totalFrames; i++) { 97 | locations.add(new float[]{ 98 | Float.parseFloat(strings.get(seek++)), 99 | Float.parseFloat(strings.get(seek++)), 100 | Float.parseFloat(strings.get(seek++)) 101 | }); 102 | rotations.add(new float[]{ 103 | Float.parseFloat(strings.get(seek++)), 104 | Float.parseFloat(strings.get(seek++)), 105 | Float.parseFloat(strings.get(seek++)) 106 | }); 107 | } 108 | int totalMarkers = Integer.parseInt(strings.get(seek++)); 109 | List markers = new ArrayList<>(); 110 | for (int i = 0; i < totalMarkers; i++) { 111 | markers.add(new Marker(strings.get(seek++), Integer.parseInt(strings.get(seek++)))); 112 | } 113 | for (int i = 0; i < totalFrames; i++) { 114 | int finalI = i; 115 | frames.add(new Frame(locations.get(i), rotations.get(i), markers.stream().filter(m -> m.getFrame() == finalI).collect(Collectors.toList()))); 116 | } 117 | return new BlendCameraAnimation(startFrame, endFrame, totalFrames, frames); 118 | } 119 | 120 | } --------------------------------------------------------------------------------