You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Permission is hereby granted, free of charge, to any person obtaining a copy
13
+
of this software and associated documentation files (the "Software"), to deal
14
+
in the Software without restriction, including without limitation the rights
15
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+
copies of the Software, and to permit persons to whom the Software is
17
+
furnished to do so, subject to the following conditions:
18
+
19
+
The above copyright notice and this permission notice shall be included in
20
+
all copies or substantial portions of the Software.
21
+
22
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
+
THE SOFTWARE.
29
+
*/
30
+
31
+
// AnimationToPNG is based on Twinfox and bitbutter's Render Particle to Animated Texture Scripts, this script will render out an animation that is played when "Play" is pressed in the editor.
32
+
33
+
/* Basically this is a script you can attach to any gameobject in the scene, but you have to reference a Black Camera and White Camera both of which should be set to orthographic, but this script should have it covered. There is a prefab called AnimationToPNG which should include everything needed to run the script.
34
+
35
+
If you have Unity Pro, you can use Render Texture, which can accurately render the transparent background for your animations easily in full resolution of the camera. Just check the box for the variable "useRenderTexture" to use RenderTextures instead. If you are using Unity Free, then leave this unchecked and you will have a split area using half of the screen width to render the animations.
36
+
37
+
You can change the "animationName" to a string of your choice for a prefix for the output file names, if it is left empty then no filename will be added.
38
+
39
+
The destination folder is relative to the Project Folder root, so you can change the string to a folder name of your choice and it will be created. If it already exists, it will simply create a new folder with a number incremented as to how many of those named folders exist.
40
+
41
+
Choose how many frames per second the animation will run by changing the "frameRate" variable, and how many frames of the animation you wish to capture by changing the "framesToCapture" variable.
42
+
43
+
Once "Play" is pressed in the Unity Editor, it should output all the animation frames to PNGs output in the folder you have chosen, and will stop capturing after the number of frames you wish to capture is completed. */
44
+
45
+
publicclassAnimationToPNG:MonoBehaviour{
46
+
47
+
// Animation Name to be the prefix for the output filenames
48
+
publicstringanimationName="";
49
+
50
+
// Default folder name where you want the animations to be output
51
+
publicstringfolder="PNG_Animations";
52
+
53
+
// Framerate at which you want to play the animation
54
+
publicintframeRate=25;
55
+
56
+
// How many frames you want to capture during the animation
57
+
publicintframesToCapture=25;
58
+
59
+
// White Camera
60
+
publicCamerawhiteCam;
61
+
62
+
// Black Camera
63
+
publicCamerablackCam;
64
+
65
+
// Pixels to World Unit size
66
+
publicfloatpixelsToWorldUnit=74.48275862068966f;
67
+
68
+
// If you have Unity Pro you can use a RenderTexture which will render the full camera width, otherwise it will only render half
69
+
publicbooluseRenderTexture=false;
70
+
71
+
privateintvideoframe=0;// how many frames we've rendered
72
+
73
+
privatefloatoriginaltimescaleTime;// track the original time scale so we can freeze the animation between frames
74
+
75
+
privatestringrealFolder="";// real folder where the output files will be
76
+
77
+
privatebooldone=false;// is the capturing finished?
78
+
79
+
privateboolreadyToCapture=false;// Make sure all the camera setup is complete before capturing
80
+
81
+
privatefloatcameraSize;// Size of the orthographic camera established from the current screen resolution and the pixels to world unit
82
+
83
+
privateTexture2Dtexb;// black camera texture
84
+
85
+
privateTexture2Dtexw;// white camera texture
86
+
87
+
privateTexture2Doutputtex;// final output texture
88
+
89
+
privateRenderTextureblackCamRenderTexture;// black camera render texure
90
+
91
+
privateRenderTexturewhiteCamRenderTexture;// white camera render texure
92
+
93
+
// Get the texture from the screen, render all or only half of the camera
94
+
publicTexture2DGetTex2D(boolrenderAll){
95
+
// Create a texture the size of the screen, RGB24 format
0 commit comments