User:Pedro Oval/GIMP Layers to SL Animated Texture
< User:Pedro Oval
Jump to navigation
Jump to search
Revision as of 14:47, 5 December 2010 by Pedro Oval (talk | contribs) (Add note that Unoptimize fixes the issue.)
Development version
<scheme>
- Layers to SL Texture Animation, version 1.1pre1.
- Written by Pedro Oval, 2010-12-04.
- Donated to the public domain.
- Thanks to Digital Dharma for the suggestions.
(define (script-fu-layers-to-sl-anim curimg curdrawable xframes yframes)
(define layerset (gimp-image-get-layers curimg)) (define numframes (car layerset)) (set! layerset (cadr layerset)) (define framexsize (car (gimp-image-width curimg))) (define frameysize (car (gimp-image-height curimg))) (define imgtype (car (gimp-image-base-type curimg)))
(if (= numframes (* xframes yframes)) (begin (define img (car (gimp-image-new (* framexsize xframes) (* frameysize yframes) imgtype))) (gimp-image-undo-group-start img) (if (= imgtype INDEXED) (begin (define palette (gimp-image-get-colormap curimg)) (gimp-image-set-colormap img (car palette) (cadr palette))))
(define frame 0) (while (< frame numframes) (begin (define newlayer (car (gimp-layer-new-from-drawable (vector-ref layerset (- numframes frame 1)) img))) (gimp-image-add-layer img newlayer frame) (define framey (truncate (/ frame xframes))) (define framex (- frame (* framey xframes))) (gimp-layer-set-offsets newlayer (* framex framexsize) (* framey frameysize)) (set! frame (+ frame 1)))) (gimp-image-merge-visible-layers img CLIP-TO-IMAGE) (if (not (= imgtype RGB)) (gimp-image-convert-rgb img)) (gimp-image-undo-group-end img) (gimp-display-new img)) (gimp-message "Error: Number of layers doesn't match horizontal x vertical frames")))
(script-fu-register "script-fu-layers-to-sl-anim"
_"<Image>/Script-Fu/SecondLife/Frames to texture..." _"Convert a set of layers (frames) to a texture suitable for llSetTextureAnim." "Pedro Oval" _"Public Domain" "2010-12-04" "RGB*, GRAY*, INDEXED*" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 SF-ADJUSTMENT _"# of horizontal frames" '(2 1 1024 1 10 0 1) SF-ADJUSTMENT _"# of vertical frames" '(2 1 1024 1 10 0 1))
</scheme>
TODO list
- Add option to generate and show the script that will animate the texture with the given parameters. It has the problem that we don't ask for the final frame count, so the real from/to values can be different to the ones that the script can output, which may confuse some users. It will have a checkbox, "Generate script", initially checked, but uncheckable to avoid the annoyance of a dialog at the end.
- Perhaps change the strategy to use gimp-image-duplicate to simplify the process. The drawback is that only visible layers get merged down, so either the user should ensure that all layers are visible, or the program should do that.
- Add note somewhere in the documentation that it assumes that the frames have the size of the original image, even if GIMP layers can exceed that or be smaller. NOTE: For now, Unoptimize does the fixes already in the original image.
- To alleviate that last issue, it would be wise to clip each layer to the rectangle it's assumed to be on, if it's bigger. Using the relative position of each layer in the original image would be wise too.
- Add the opposite conversion: given an animated texture, split it into layers.