It is currently Thu Apr 25, 2024 10:23 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: 3D visual image of height maps
PostPosted: Wed Jun 04, 2014 7:39 pm  (#1) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
This script is to automate steps described here: http://gimpchat.com/viewtopic.php?f=9&t=10463&start=10#p138070
Without the colorize.
You can choose "RIGHT" "LEFT" "TOP" or "BOTTOM"
In order to run this script you need to install script found here: http://gimpchat.com/viewtopic.php?f=9&t=8088&start=10#p122817
Here's the script (tested in 2.8.10 and 2.6.12) (will be available under Script-Fu -> Create New -> 3D visuals of height maps)
Attachment:
3D_visual_image_of_height_maps.scm [6.18 KiB]
Downloaded 184 times


The script will create a new image of that view with layer named "Right" or "Left" or "Top" or "Bottom" depending on what view you've selected in the options when the script runs.

This script was requested by PegLeg44
Original file to test with
Image
sample output (RIGHT)
Image
(LEFT)
Image
(TOP)
Image
(BOTTOM)
Image

Here's the (dynamic) version. It allows you to choose preset angles or "USE CUSTOM ANGLE".
Attachment:
3D_visual_image_of_height_maps_dynamic_angle.scm [7.15 KiB]
Downloaded 143 times

Here's what the options window looks like
Image

_________________
TinT


Last edited by trandoductin on Thu Jun 05, 2014 2:07 am, edited 1 time in total.

Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: 3D visual image of height maps
PostPosted: Wed Jun 04, 2014 10:30 pm  (#2) 
Offline
GimpChat Member
User avatar

Joined: Feb 14, 2012
Posts: 426
trandoductin

Your pretty good with the script creating. I like the way that it opens up in a new window too. Thanks a lot! I don't have to wish I had the script any more because now I do.

Since I make a lot of height maps this will come in handy. I usually work with images that are around 1400 pixels so this will give a good height per image size for me.

Thanks, PegLeg44


Top
 Post subject: Re: 3D visual image of height maps
PostPosted: Wed Jun 04, 2014 11:12 pm  (#3) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
glad it works for you!

_________________
TinT


Top
 Post subject: Re: 3D visual image of height maps
PostPosted: Wed Jun 04, 2014 11:33 pm  (#4) 
Offline
GimpChat Founder
User avatar

Joined: May 22, 2008
Posts: 5242
Location: Gimpville
Nice work, trandoductin. :bigthup

Might I suggest allowing the user to adjust the elevation & depth of the emboss filter. Another nice feature would be a user configurable view angle (say a 5th drop down option that used an azimuth value specified in a dialog). Colorizing could be implemented nicely with the colorify plug-in.

_________________
“If you reach for the stars, you just might land on a decently sized hill.” - Stuart Hill


Top
 Post subject: Re: 3D visual image of height maps
PostPosted: Wed Jun 04, 2014 11:51 pm  (#5) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
I thought about a 5th drop down to be "CUSTOM" which uses user specified values. But there's a scale image step that i don't know how scale the image based on the custom values. it might involve a lot of trigonometry.
hey nice animated avatar

_________________
TinT


Top
 Post subject: split
PostPosted: Wed Jun 04, 2014 11:53 pm  (#6) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4827
Location: Bendigo Vic. Australia
Trandoductin ther is no need to have a script-fu as a dependency Ive added the script-below

; following steps described by PegLeg44
; found at link: http://gimpchat.com/viewtopic.php?f=9&t=10463&start=10#p138070
;
; author: Tin Tran
; date: 2014

(define (script-fu-3D-visual-image-of-height-maps image layer
                               preset-view-angle
         )
   (let*
     (
     (dummy-variable-to-make-let-happy 0)
     (image-width)
     (image-height)
     (new-image)
     (new-layer)
     (new-display)
    
    
     (get-layers-returned-values)
     (layers-visibility-array)     ;array of bytes to store visibility flags
     (layers-name-vector)          ;vector to store layers' names
     (layers-count)
     (layers-array)
     (current-layer)
     (current-layer-name)
     (visibility-flag)
     (offset-x)
     (offset-y)
     (layer-name)
     (new-width)
     (new-height)
     (azimuth)
     )
   ;(gimp-image-undo-group-start image)                   ;undo-group in one step
   ;GIMP 2.6 backward compatibility check---------------------------------
   (if (not (defined? 'gimp-item-get-name)) ;Check for 2.8 proc
    (begin
        (define (gimp-item-get-name layer) ;Define it
            ;(gimp-layer-get-name layer)    ;Call 2.6 proc
         (gimp-drawable-get-tattoo layer)
        )
    )
   )
   (if (not (defined? 'gimp-item-get-visible)) ;Check for 2.8 proc
    (begin
        (define (gimp-item-get-visible layer) ;Define it
            (gimp-drawable-get-visible layer)    ;Call 2.6 proc
        )
    )
   )
   (if (not (defined? 'gimp-item-set-visible)) ;Check for 2.8 proc
    (begin
        (define (gimp-item-set-visible layer visible) ;Define it
            (gimp-drawable-set-visible layer visible)    ;Call 2.6 proc
        )
    )
   )
   (if (not (defined? 'gimp-image-get-item-position)) ;Check for 2.8 proc
    (begin
        (define (gimp-image-get-item-position image layer) ;Define it
            (gimp-image-get-layer-position image layer)    ;Call 2.6 proc
        )
    )
   )
   (if (not (defined? 'gimp-item-delete)) ;Check for 2.8 proc
    (begin
        (define (gimp-item-delete drawable) ;Define it
            (gimp-drawable-delete drawable)    ;Call 2.6 proc
        )
    )
   )
   (if (not (defined? 'gimp-item-set-name)) ;Check for 2.8 proc
    (begin
        (define (gimp-item-set-name drawable name) ;Define it
            (gimp-drawable-set-name drawable name)    ;Call 2.6 proc
        )
    )
   )
   (if (not (defined? 'gimp-image-insert-layer)) ;Check for 2.8 proc
    (begin
        (define (gimp-image-insert-layer image layer parent position) ;Define it
            (gimp-image-add-layer image layer position)    ;Call 2.6 proc
        )
    )
   )
   (if (not (defined? 'gimp-image-insert-channel)) ;Check for 2.8 proc
    (begin
        (define (gimp-image-insert-channel image channel parent position) ;Define it
            (gimp-image-add-channel image channel position)    ;Call 2.6 proc
        )
    )
   )
   (if (not (defined? 'gimp-image-get-layer-by-name)) ;Check for 2.8 proc
    (begin
        (define (gimp-image-get-layer-by-name image tattoo) ;Define it
            (gimp-image-get-layer-by-tattoo image tattoo)    ;Call 2.6 proc
        )
    )
   )
   
   ;-------------------------------------------------------------------------
   (set! image-width (car (gimp-image-width image)))
   (set! image-height (car (gimp-image-height image)))
   (gimp-layer-resize-to-image-size layer)               ;layer to image size
   (gimp-selection-none image)                           ;selects none
   ;copy the active layer into a new image
   ;(set! new-image (car (gimp-image-new image-width image-height RGB)))      ;creates new image
    (gimp-selection-all image)
   (gimp-edit-copy layer)
   (set! new-image (car(gimp-edit-paste-as-new)))
   ;(set! new-layer (car (gimp-image-get-layer-by-name new-image "Green Apple-innershadow")))
   (set! new-layer (car (gimp-image-get-active-layer new-image)))
   
   
   
   ;("RIGHT" "LEFT" "TOP" "BOTTOM")
   (if (= preset-view-angle 0)  ;RIGHT
      (begin
         (set! offset-x 125)
         (set! offset-y 0)
         (set! layer-name "Right")
         (set! new-width (/ image-width 2))
         (set! new-height image-height)
         (set! azimuth 30)
         ;do other sets here
      )
   )
   (if (= preset-view-angle 1)  ;LEFT
      (begin
         (set! offset-x -125)
         (set! offset-y 0)
         (set! layer-name "Left")
         (set! new-width (/ image-width 2))
         (set! new-height image-height)
         (set! azimuth 210)
         ;do other sets here
      )
   )
   (if (= preset-view-angle 2)  ;TOP
      (begin
         (set! offset-x 0)
         (set! offset-y -125)
         (set! layer-name "Top")
         (set! new-width image-width)
         (set! new-height (/ image-height 2))
         (set! azimuth 120)
         ;do other sets here
      )
   )
   (if (= preset-view-angle 3)  ;BOTTOM
      (begin
         (set! offset-x 0)
         (set! offset-y 125)
         (set! layer-name "Bottom")
         (set! new-width image-width)
         (set! new-height (/ image-height 2))
         (set! azimuth 300)
         ;do other sets here
      )
   )
   (gimp-item-set-name new-layer layer-name) ;set the appropriate layer name (user friendliness)
   (3D-visual-height-value-offset new-image
                           new-layer
                           offset-x
                           offset-y
                           TRUE)
   (gimp-image-scale new-image new-width new-height)
   (plug-in-emboss 1 new-image new-layer azimuth
                                       45 ;elevation
                              20 ;depth
                              1  ;emboss or bump map
   )
    (gimp-selection-none image)
   (set! new-display (car (gimp-display-new new-image)))
   ;(gimp-image-undo-group-end image)                     ;undo group in one step
   (gimp-displays-flush)
   )
)

(script-fu-register
  "script-fu-3D-visual-image-of-height-maps"         ;function name
  "<Image>/Script-Fu/Create New/3D visual of height maps"    ;menu register
  "Creates a new 3D visual image of height maps."       ;description
  "Tin Tran"                          ;author name
  "copyright info and description"         ;copyright info or description
  "2014"                          ;date
  "RGB*, GRAY*"                        ;mode
  SF-IMAGE      "Image" 0                   
  SF-DRAWABLE   "Layer" 0
  SF-OPTION "Preset View Angle" '("RIGHT" "LEFT" "TOP" "BOTTOM")
)
;from Heightfield Offset by Value... by RobA
(define (3D-visual-height-value-offset  img inLayer xOff yOff inInvert)
 
  (let* (
      (newimg (car (gimp-image-duplicate img))) ; run in duplicate image for speed.
     (newinLayer (car (gimp-image-get-active-layer newimg)))
   )
   
    (gimp-context-push)
    (gimp-image-undo-group-start img)
   
   ;save memory
   (gimp-image-undo-freeze newimg)
   
    (let* (
         (loopcount 255)
           (newLayer (car (gimp-layer-copy newinLayer TRUE)))
           (origSel (car (gimp-selection-save img)))
         (buff "ovhbuff")
           )

      (gimp-selection-none newimg)
      (gimp-selection-none img)

      (gimp-image-add-layer newimg newLayer -1)
     (gimp-context-set-foreground (list 0 0 0))
     (gimp-drawable-fill newLayer FOREGROUND-FILL)
     
      ;invert flag
      (if (= inInvert TRUE) (gimp-invert newinLayer))
    
     (while (>= loopcount 0)
    
       ;select with threshold
      (gimp-by-color-select newinLayer (list 255 255 255) loopcount CHANNEL-OP-REPLACE FALSE FALSE 0 FALSE)
       
        (if (equal? (car (gimp-selection-is-empty newimg)) TRUE)
          (set! loopcount -1)
          ;else
        (begin
         (gimp-selection-translate newimg (round (/ (* xOff (- 255 loopcount)) 255)) (round (/ (* yOff (- 255 loopcount)) 255)))
          (gimp-context-set-foreground (list (- 255 loopcount) (- 255 loopcount) (- 255 loopcount)))
          (gimp-edit-fill newLayer FOREGROUND-FILL)
         
         (set! loopcount (- loopcount 1))
         (gimp-progress-update (/ (- 255 loopcount) 255))
          )
        )
     )
 
     (gimp-selection-none newimg)
     
      ;invert flag
      (if (= inInvert TRUE) (gimp-invert newLayer))

     ;transfer new layer back     
     (set! buff (car (gimp-edit-named-copy newLayer buff)))
     (gimp-floating-sel-anchor (car (gimp-edit-named-paste inLayer buff FALSE)))
    
     (gimp-selection-load origSel)
      (gimp-image-remove-channel img origSel)
   
    )

    ;delete temp image
    (gimp-image-delete newimg)
   
    ; Done
    (gimp-progress-update 0)
    (gimp-image-undo-group-end img)
    (gimp-context-pop)
   
    (gimp-displays-flush)

  )
)


_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Top
 Post subject: Re: 3D visual image of height maps
PostPosted: Thu Jun 05, 2014 12:08 am  (#7) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
I thought using predefined procedures are good because if RobA updates his procedure with a newer version, I don't have do another cut and paste, unless of course parameters changes.
No?

_________________
TinT


Top
 Post subject: Re: 3D visual image of height maps
PostPosted: Thu Jun 05, 2014 12:18 am  (#8) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4827
Location: Bendigo Vic. Australia
If you include RobA's script as a procedure exactly as it is now You will never have to worry about an update by RobA to his script affecting your script

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Top
 Post subject: Re: 3D visual image of height maps
PostPosted: Thu Jun 05, 2014 12:32 am  (#9) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
i think it's a trade off though, if he updates his script with an improved version for example faster or fixes a bug or something like that provided the interface is still the same i don't have to go an copy the new version.

_________________
TinT


Top
 Post subject: Re: 3D visual image of height maps
PostPosted: Thu Jun 05, 2014 12:46 am  (#10) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4827
Location: Bendigo Vic. Australia
Experiece has taught me that you will get more complaints about your script failing due to users not having RobA's script than anything (users seldom read instructions), I know I don't ;)

If your script works OK then it's best to include it as a procedure

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Top
 Post subject: Re: 3D visual image of height maps
PostPosted: Thu Jun 05, 2014 12:52 am  (#11) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
heheh not reading instructions? tsk tsk.
I'll just leave it as is and wait to see how many complaints i get I'll see if it's worth the trade off

_________________
TinT


Top
 Post subject: Re: 3D visual image of height maps
PostPosted: Thu Jun 05, 2014 3:17 am  (#12) 
Offline
GimpChat Founder
User avatar

Joined: May 22, 2008
Posts: 5242
Location: Gimpville
trandoductin wrote:
I thought using predefined procedures are good because if RobA updates his procedure with a newer version, I don't have do another cut and paste, unless of course parameters changes.

Well, if your script is dependent on another coder's script, your script is always subject to breaking anytime an update is made to the other script. The stability and maintenance schedule of your script is now in the hands of someone else.

There are other support issues, as well. You now have to deal with installation problems and release version mismatches between the two scripts/plug-ins, which can be especially problematic when dealing with python and binary plug-ins as dependencies. For example, you might not want to force a user to install the python version of layerFX, just to get the inner shadow function being used in your script. They might already be using a different scheme script to provide that functionality.

The scenario exist where a user has Script A Ver1. The user also has Script B, which is dependent on Script A Ver1. You release Script C, which is dependent on Script A Ver2. The user can't have both Script A Ver1 & Ver2 installed. Script B development has been abandoned, but the user really needs Script B, so has to stick with Script A Ver1. You can see where all this is going and how problems can arise when 3rd party scripts are dependent on other 3rd party scripts.

These are some of the reasons that as a general rule, I avoid 3rd party supported scripts/plug-ins as dependencies.

On a related note, there are also the issues with calling a script-fu script interactively from another script-fu script.

Btw- The avatar is not my creation. It's a PD image I found on a Russian Guitar Site.

_________________
“If you reach for the stars, you just might land on a decently sized hill.” - Stuart Hill


Top
 Post subject: Re: 3D visual image of height maps
PostPosted: Thu Jun 05, 2014 1:37 pm  (#13) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3975
Location: Canada
I still think it's a trade off.
You either run your own version (cut and pasted at the time you write your script).
Or you can run whatever version is installed (provided the parameters haven't changed). I kind'a want my script to break if it isn't running the latest version, if the parameters changed, maybe i want to add that extra parameter as an input to my new version.
Breaking tells me that it needs attention.
If the parameters haven't changed, then great it runs whatever version you have installed (the latest) if they have installed the latest.

_________________
TinT


Top
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Experiment with a Lighten-only Height/Depth/Bumpmap Brush

2

No new posts Attachment(s) Wood E-maps

8

No new posts Attachment(s) Bubble glass e-maps

9

No new posts Retexture an image with another image as "Image Pattern" Plug-in

4

No new posts GIMP XCF image plug-in could not open image; File is Not 0 Bytes

4



* Login  



Powered by phpBB3 © phpBB Group