; 3D Fun rel 0.03 ; Created by Graechan ; You will need to install GMIC to run this Scipt ; GMIC can be downloaded from http://sourceforge.net/projects/gmic/files/ ; Comments directed to http://gimpchat.com or http://gimpscripts.com ; ; License: GPLv3 ; This program is free software: you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation, either version 3 of the License, or ; (at your option) any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; To view a copy of the GNU General Public License ; visit: http://www.gnu.org/licenses/gpl.html ; ; ; ------------ ;| Change Log | ; ------------ ; Rel 0.01 - Initial Release ; Rel 0.02 - Added more text adjustments and did some bugfixes now Script has no dependancies except Gmic ; Rel 0.03 - Added 'Bkg Animation Direction' choice (define (script-fu-3d-fun image drawable bkg-type pattern gradient shapes s-density s-size 3d-fgd-height frames direction texture txt-color txt-pattern txt-gradient ) ;; Start undo group. (gimp-image-undo-group-start image) (let* ( ;; verification of the dimensions (error 0) (text-layer (car (gimp-image-get-active-layer image))) (width (car (gimp-drawable-width text-layer))) (height (car (gimp-drawable-height text-layer))) (bkg-layer 0) ) (gimp-context-push) (if (< width 24) (set! error (+ error 1))) (if (< height 24) (set! error (+ error 10))) (if (= error 1) (gimp-message "ERROR 3d_fun WIDTH<24")) (if (= error 10) (gimp-message "ERROR 3d_fun HEIGHT<24")) (if (= error 11) (gimp-message "ERROR 3d_fun WIDTH<24 & HEIGHT<24")) (gimp-context-set-foreground '(0 0 0)) (set! bkg-layer (car (gimp-layer-new image width height RGBA-IMAGE "Background" 100 NORMAL-MODE))) (gimp-image-add-layer image bkg-layer 1) (if (= bkg-type 2);Pattern (begin (gimp-context-set-pattern pattern);;test (gimp-drawable-fill bkg-layer PATTERN-FILL) ) ) (if (= bkg-type 1);;White (begin (gimp-context-set-background '(255 255 255)) (gimp-drawable-fill bkg-layer BACKGROUND-FILL) ) ) (if (= bkg-type 3);;Gradient (begin (gimp-context-set-background '(255 255 255)) (gimp-drawable-fill bkg-layer BACKGROUND-FILL) (gimp-context-set-gradient gradient) (gimp-edit-blend bkg-layer CUSTOM-MODE NORMAL-MODE GRADIENT-LINEAR 100 0 REPEAT-NONE FALSE FALSE 3 0.2 TRUE 0 0 width height);; GRADIENT-LINEAR ) ) ; *******************************************start 3D_bkg (let* ( ;; Matching variables (3d_bkg (car (gimp-layer-copy bkg-layer TRUE))) (shape 0) (density s-density) (size s-size) ) ;; Add a layer (gimp-image-add-layer image 3d_bkg 1) (gimp-image-raise-layer-to-top image 3d_bkg) ;; name the layer (gimp-drawable-set-name 3d_bkg "3d_bkg") (if (= shapes 0) (set! shape 0)) (if (= shapes 1) (set! shape 1)) (if (= shapes 2) (set! shape 2)) (if (= shapes 3) (set! shape 3)) (if (= shapes 4) (set! shape 4)) ;; Render random3d using G'MIC. (plug-in-gmic 1 image 3d_bkg 1 (string-append "-v - " ; To have a silent output. Remove it to display errors from the G'MIC interpreter on stderr. "-gimp_random3d " (number->string shape) "," (number->string density) "," (number->string size) ",100,45,0,0,-100,0.5,0.7,5,1" ) ) ;; Render smoothing using G'MIC. (plug-in-gmic 1 image 3d_bkg 1 (string-append "-v - " ; To have a silent output. Remove it to display errors from the G'MIC interpreter on stderr. "-gimp_anisotropic_smoothing 60,1,1,4,1,1,30,2,0,1,1,1,1" ) ) ;;(gimp-hue-saturation 3d_bkg ALL-HUES 0 0 -100) ;; Make layers for animation (plug-in-make-seamless RUN-NONINTERACTIVE image 3d_bkg) (3d-fun-move-layer-anim image 3d_bkg frames direction FALSE TRUE 0 0 0 0 0 FALSE 0 100 0) (gimp-displays-flush) (gimp-image-remove-layer image bkg-layer) ) ; *******************************************end 3D_bkg ; ; ; *******************************************start 3D_fgd ; (let* ( ;; Matching variables (3D_fgd (car (gimp-layer-copy text-layer TRUE))) (txt-width (car (gimp-drawable-width text-layer))) (txt-height (car (gimp-drawable-height text-layer))) (texture-layer 0) (activeLayer 0) (temp-layer 0) (3d-height 3d-fgd-height) ) ;; Add a layers (gimp-image-add-layer image 3D_fgd 1) ;; name the layers (gimp-drawable-set-name 3D_fgd "3D_fgd") (gimp-image-remove-layer image text-layer) (gimp-image-lower-layer-to-bottom image 3D_fgd) ;; Render extrude3d using G'MIC. (plug-in-gmic 1 image 3D_fgd 1 (string-append "-v - " ; To have a silent output. Remove it to display errors from the G'MIC interpreter on stderr. "-gimp_extrude3d " (number->string 3d-height) ",512,0.6," (number->string txt-width) "," (number->string txt-height) ",0.78,53.4,12.2,13.8,45,100,0,-100,0.5,0.7,4" ) ) ;; Render deinterlace using G'MIC. (plug-in-gmic 1 image 3D_fgd 1 (string-append "-v - " ; To have a silent output. Remove it to display errors from the G'MIC interpreter on stderr. "-deinterlace 1" ) ) (set! texture-layer (car (gimp-layer-new image txt-width txt-height RGBA-IMAGE "Texture" 100 MULTIPLY-MODE))) (gimp-image-add-layer image texture-layer -1) (gimp-layer-resize-to-image-size texture-layer) (if (= texture 0) (begin (gimp-context-set-background txt-color);;test (gimp-drawable-fill texture-layer BACKGROUND-FILL) ) ) (if (= texture 1) (begin (gimp-context-set-pattern txt-pattern);;test (gimp-drawable-fill texture-layer PATTERN-FILL) ) ) (if (= texture 2) (begin (gimp-context-set-gradient txt-gradient) (plug-in-gradmap RUN-NONINTERACTIVE image 3D_fgd) ;; apply the gradient ) ) (gimp-image-merge-down image texture-layer CLIP-TO-IMAGE) (3d-fun-sg-anim-overlay-background image) (set! temp-layer (car (gimp-layer-new image txt-width txt-height RGBA-IMAGE "temp" 100 NORMAL-MODE))) (gimp-image-add-layer image temp-layer -1) (gimp-image-lower-layer-to-bottom image temp-layer) (gimp-image-raise-layer image temp-layer) (gimp-image-merge-down image temp-layer CLIP-TO-IMAGE) (set! activeLayer (car (gimp-image-get-active-layer image))) (gimp-image-remove-layer image activeLayer) (gimp-displays-flush) ) (gimp-context-pop) ;; Flush display. (gimp-displays-flush) ) ;; End undo group. (gimp-image-undo-group-end image) ) (script-fu-register "script-fu-3d-fun" _"3D FUN..." "Uses GMIC, to create a 3D animation" "Graechan" "Graechan - http://gimpchat.com" "May 2014" "*" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 SF-OPTION "Background Type" '("Black" "White" "Pattern" "Gradient") SF-PATTERN "Pattern" "Pink Marble" SF-GRADIENT "Background Gradient" "Abstract 3" SF-OPTION "Background Shapes" '("Cube" "Cone" "Cylinder" "Sphere" "Torus") SF-ADJUSTMENT "Density of Shapes" '(120 1 200 1 10 0 1) SF-ADJUSTMENT "Size of Shapes" '(3.5 1 20 0.1 1 1 1) SF-ADJUSTMENT "3D-fgd-height" '(30 1 50 0.1 1 1 1) SF-ADJUSTMENT "Frames for Animation" '(10 2 200 2 10 0 1) SF-OPTION "Bkg Direction Options" '("Up" "Down" "Left" "Right" "Up and Left" "Up and Right" "Down and Left" "Down and Right") SF-OPTION "Texture Type" '("Color" "Pattern" "Gradient") SF-COLOR "Texture Color" '(153 153 153) SF-PATTERN "Texture Pattern" "Blue Web" SF-GRADIENT "Texture Gradient" "Incandescent" ) (script-fu-menu-register "script-fu-3d-fun" "/Script-Fu/Alpha-to-Logo") (define (script-fu-3d-fun-logo text justify letter-spacing line-spacing font-in size bkg-type pattern gradient shapes s-density s-size 3d-fgd-height frames direction texture txt-color txt-pattern txt-gradient) (let* ( (image-width 250) (image-height 250) (width image-width) (height image-height) (offx 0) (offy 0) (image (car (gimp-image-new image-width image-height RGB))) (border (/ size 4)) (font (if (> (string-length font-in) 0) font-in (car (gimp-context-get-font)))) (text-layer (car (gimp-text-fontname image -1 0 0 text border TRUE size PIXELS font))) (text-width (car (gimp-drawable-width text-layer))) (text-height (car (gimp-drawable-height text-layer))) (justify (cond ((= justify 0) 2) ((= justify 1) 0) ((= justify 2) 1))) ) (gimp-context-push) ;;;;adjust the text-layer (gimp-text-layer-set-justification text-layer justify) (gimp-text-layer-set-letter-spacing text-layer letter-spacing) (gimp-text-layer-set-line-spacing text-layer line-spacing) (set! text-width (car (gimp-drawable-width text-layer))) (set! text-height (car (gimp-drawable-height text-layer))) ;;;;set the new Image size (if (> text-width image-width) (set! width text-width)) (if (> text-height image-height) (set! height text-height)) ;;;;resize the image (gimp-image-resize image width height 0 0) (set! offx (/ (- width text-width) 2)) (set! offy (/ (- height text-height) 2)) (gimp-image-resize image width height 0 0) (gimp-layer-set-offsets text-layer offx offy) (gimp-image-set-active-layer image text-layer);;test-OK (gimp-layer-resize-to-image-size text-layer) (script-fu-3d-fun image text-layer bkg-type pattern gradient shapes s-density s-size 3d-fgd-height frames direction texture txt-color txt-pattern txt-gradient) (gimp-context-pop) (gimp-display-new image) ) ) (script-fu-register "script-fu-3d-fun-logo" "3D-FUN Logo" "Uses GMIC, to create a 3D animation" "Graechan" "Graechan - http://gimpchat.com" "May 2014" "" SF-TEXT "Text" "Gimp" SF-OPTION "Justify" '("Centered" "Left" "Right") SF-ADJUSTMENT "Letter Spacing" '(50 -100 100 1 5 0 0) SF-ADJUSTMENT "Line Spacing" '(0 -100 100 1 5 0 0) SF-FONT "Font" "JasmineUPC Bold" SF-ADJUSTMENT "Font size (pixels)" '(300 6 500 1 1 0 1) SF-OPTION "Background Type" '("Black" "White" "Pattern" "Gradient") SF-PATTERN "Pattern" "Pink Marble" SF-GRADIENT "Background Gradient" "Abstract 3" SF-OPTION "Background Shapes" '("Cube" "Cone" "Cylinder" "Sphere" "Torus") SF-ADJUSTMENT "Density of Shapes" '(120 1 200 1 10 0 1) SF-ADJUSTMENT "Size of Shapes" '(3.5 1 20 0.1 1 1 1) SF-ADJUSTMENT "3D-fgd-height" '(30 1 50 0.1 1 1 1) SF-ADJUSTMENT "Frames for Animation" '(10 2 200 2 10 0 1) SF-OPTION "Bkg Direction Options" '("Up" "Down" "Left" "Right" "Up and Left" "Up and Right" "Down and Left" "Down and Right") SF-OPTION "Texture Type" '("Color" "Pattern" "Gradient") SF-COLOR "Texture Color" '(153 153 153) SF-PATTERN "Texture Pattern" "Blue Web" SF-GRADIENT "Texture Gradient" "Incandescent" ) (script-fu-menu-register "script-fu-3d-fun-logo" "/Script-Fu/Logos") (define (3d-fun-move-layer-anim image layer frames direction pingPong pingCopy layerHandle startX startY endX endY addPath blendMode opacity fillOption ) ; Declare the Variables (let* ( (height 0) (width 0) (copyLayer 0) (origSelect 0) (wrap 0) (x-dir (cond (( equal? direction 0 ) 0) (( equal? direction 1 ) 0) (( equal? direction 2 ) -1) (( equal? direction 3 ) 1) (( equal? direction 4 ) -1) (( equal? direction 5 ) 1) (( equal? direction 6 ) -1) (( equal? direction 7 ) 1) ) ) (y-dir (cond (( equal? direction 0 ) -1) (( equal? direction 1 ) 1) (( equal? direction 2 ) 0) (( equal? direction 3 ) 0) (( equal? direction 4 ) -1) (( equal? direction 5 ) -1) (( equal? direction 6 ) 1) (( equal? direction 7 ) 1) ) ) (step-x 0) (step-y 0) (offset-x 0) (offset-y 0) (mode-lut '#(0 1 3 15 4 5 16 17 18 19 20 21 6 7 8 9 10 11 12 13 14)) (vectors 0) (pathLength 0) (dist 0) (distInc 0) (points (cons-array 12 'double)) (numLayers 0) (layerID 0) (stackPos 1) (fillColor 0) ) (gimp-context-push) (gimp-undo-push-group-start image) (set! origSelect (car (gimp-selection-save image))) (gimp-selection-none image) (set! width (car (gimp-drawable-width layer))) (set! height (car (gimp-drawable-height layer))) (gimp-layer-add-alpha layer) (gimp-layer-set-mode layer (vector-ref mode-lut blendMode)) (gimp-layer-set-opacity layer opacity) (if (= pingPong TRUE) (set! frames (ceiling (/ frames 2))) ) (if (= direction 9) (begin (set! startX (car (gimp-drawable-offsets layer))) (set! startY (cadr (gimp-drawable-offsets layer))) ) ) (if (= direction 10) (set! vectors (car (gimp-image-get-active-vectors image))) ) (if (> direction 7) (begin (if (or (= direction 8)(= direction 9)) (begin (set! vectors (car (gimp-vectors-new image "New Path"))) (aset points 0 startX) (aset points 1 startY) (aset points 2 startX) (aset points 3 startY) (aset points 4 startX) (aset points 5 startY) (aset points 6 endX) (aset points 7 endY) (aset points 8 endX) (aset points 9 endY) (aset points 10 endX) (aset points 11 endY) (gimp-vectors-stroke-new-from-points vectors 0 12 points FALSE) ) ) (set! pathLength (trunc (car (gimp-vectors-stroke-get-length vectors 1 1)))) (set! distInc (/ pathLength (- frames 1))) (if (and (or (= direction 8)(= direction 9)) (= addPath TRUE)) (gimp-image-add-vectors image vectors -1) ) (while (>= frames 0) (set! offset-x (car (gimp-vectors-stroke-get-point-at-dist vectors 1 dist 1))) (set! offset-y (cadr (gimp-vectors-stroke-get-point-at-dist vectors 1 dist 1))) (set! copyLayer (car (gimp-layer-copy layer TRUE))) (if (> frames 0) (gimp-image-add-layer image copyLayer -1) ) (cond ( (= layerHandle 1) ; top middle (set! offset-x (- offset-x (/ width 2))) ) ( (= layerHandle 2) ; top right (set! offset-x (- offset-x width)) ) ( (= layerHandle 3) ; middle left (set! offset-y (- offset-y (/ height 2))) ) ( (= layerHandle 4) ; center (set! offset-x (- offset-x (/ width 2))) (set! offset-y (- offset-y (/ height 2))) ) ( (= layerHandle 5) ; middle right (set! offset-x (- offset-x width)) (set! offset-y (- offset-y (/ height 2))) ) ( (= layerHandle 6) ; bottom left (set! offset-y (- offset-y height)) ) ( (= layerHandle 7) ; bottom middle (set! offset-x (- offset-x (/ width 2))) (set! offset-y (- offset-y height)) ) ( (= layerHandle 8) ; bottom right (set! offset-x (- offset-x width)) (set! offset-y (- offset-y height)) ) ) (gimp-layer-set-offsets copyLayer offset-x offset-y) (if (> frames 0) (gimp-layer-resize-to-image-size copyLayer) ) (set! frames (- frames 1)) (set! dist (+ dist distInc)) ); while closure ;(gimp-image-remove-layer image layer) ); begin closure (begin (set! step-x (* x-dir (/ width frames))) (set! step-y (* y-dir (/ height frames))) (set! offset-x step-x) (set! offset-y step-y) (set! frames (- frames 1)) (while (>= frames 1) (set! copyLayer (car (gimp-layer-copy layer TRUE))) (gimp-image-add-layer image copyLayer -1) (if (= fillOption 0) (begin (set! wrap TRUE) (set! fillColor 1) ) ) (if (= fillOption 1) (begin (set! wrap FALSE) (set! fillColor 0) ) ) (if (= fillOption 2) (begin (set! wrap FALSE) (set! fillColor 1) ) ) (gimp-drawable-offset copyLayer wrap fillColor offset-x offset-y) (set! offset-x (+ offset-x step-x)) (set! offset-y (+ offset-y step-y)) (set! frames (- frames 1)) ); while closure ); begin closure direction < 7 ); if direction > 7 closure (if (= pingPong TRUE) (begin (if (= pingCopy TRUE) (set! numLayers (- (car (gimp-image-get-layers image)) 1)) (set! numLayers (car (gimp-image-get-layers image))) ) (set! layerID (cadr (gimp-image-get-layers image))) (while (> numLayers 2) (set! layer (car (gimp-image-set-active-layer image (aref layerID stackPos)))) (set! layer (car (gimp-image-get-active-layer image))) (set! copyLayer (car (gimp-layer-copy layer TRUE))) (gimp-image-add-layer image copyLayer 0) (set! numLayers (- numLayers 1)) (set! stackPos (+ stackPos 1)) ) ) ) (set! width (car (gimp-image-width image))) (set! height (car (gimp-image-height image))) (gimp-image-crop image width height 0 0) (gimp-selection-load origSelect) (gimp-image-remove-channel image origSelect) (gimp-displays-flush) (gimp-undo-push-group-end image) (gimp-context-pop) ) ) (define (3d-fun-sg-anim-overlay-background image) ; get visible layers (bottom-to-top) (define (get-visibles image) (let loop ((layers (vector->list (cadr (gimp-image-get-layers image)))) (visibles '()) ) (if (null? layers) visibles (loop (cdr layers) (if (zero? (car (gimp-drawable-get-visible (car layers)))) visibles (cons (car layers) visibles) ) ) ) ) ) (gimp-image-undo-group-start image) (let* ((layers (vector->list (cadr (gimp-image-get-layers image)))) (visibles (get-visibles image)) (bg-layer (car (last layers))) (orig-sel (car (gimp-selection-save image))) ) (gimp-selection-none image) (map (lambda (x) (gimp-drawable-set-visible x FALSE)) visibles) (when (= (car visibles) bg-layer) (set! visibles (cdr visibles)) (gimp-drawable-set-visible bg-layer TRUE) ) (while (pair? visibles) (let* ((layer (car visibles)) (position (car (gimp-image-get-layer-position image layer))) (over-layer 0) ) (gimp-drawable-set-visible layer TRUE) (gimp-image-set-active-layer image layer) (set! over-layer (car (gimp-layer-new-from-drawable bg-layer image))) (gimp-image-add-layer image over-layer -1) (gimp-drawable-set-visible over-layer TRUE) (gimp-image-merge-down image over-layer EXPAND-AS-NECESSARY) ) (set! visibles (cdr visibles)) ) (gimp-selection-load orig-sel) (gimp-image-remove-channel image orig-sel) ) (gimp-image-undo-group-end image) (gimp-displays-flush) )