scheme-utils

Description

High level fluxus commands written in Scheme.

(detach-parent)

Returns void

Removes the parent for the current primitive, and fixes up the transform so the primitive doesn't move. Use (parent 1) to avoid this fix up.

Example

 ; builds and animates a random heirarchical structure,
 ; click on the objects to detach them from their parents
 (define (build-heir depth)
     (with-state
         (let ((p (with-state
                         (translate (vector 2 0 0))
                         (scale 0.9)
                         (build-cube))))
             (when (> depth 0)
                 (parent p)
                 (for ((i (in-range 0 5)))
                     (when (zero? (random 3))
                         (rotate (vector 0 0 (* 45 (crndf))))
                         (build-heir (- depth 1))))))))

 (define (animate-heir children depth)
     (for-each
         (lambda (child)
             (with-primitive child
                 (rotate (vector 0 0 (sin (+ depth (time)))))
                 (animate-heir (get-children) (+ depth 1))))
         children))

 (define (animate)
     (animate-heir (get-children) 0)
     (when (mouse-button 1)
         (let ((s (select (mouse-x) (mouse-y) 2)))
             (when (not (zero? s))
                 (with-primitive s
                     (detach-parent))))))

 (clear)
 (build-heir 5)
 (every-frame (animate))

(with-state expression ...)

Returns result of last expression

Encapsulates local state changes, and removes the need for push and pop.

Example

 ; state hierachy, by nesting with-state:
 (with-state
    (hint-vertcols)
    (colour (vector 0 0 1))
    (with-state
        (translate (vector 1 0 0))
        (build-sphere 10 10))
     (build-torus 1 2 30 30))

 ; making primitives:
 (define my-torus (with-state
    (hint-vertcols)
    (colour (vector 0 0 1))
    (build-torus 1 2 30 30)))

(with-primitive primitive expression ...)

Returns result of last expression

Encapsulates primitive state changes, and removes the need for grab and ungrab.

Example

 (define my-torus (with-state
    (colour (vector 0 0 1))
    (build-torus 1 2 30 30)))

 ; change the torus colour:
 (with-primitive my-torus
    (colour (vector 0 1 0)))

(with-pixels-renderer pixels-primitive expression ...)

Returns result of last expression

Allows you to render into a pixel primitive.

Example


(with-ffgl ffgl-pluginid expression ...)

Returns result of last expression

Allows you to work with the specified FFGL plugin.

Example

 (clear)
 (define plugin (ffgl-load "FFGLTile.dylib" 256 256))

 (with-ffgl plugin
   (for ([i (ffgl-get-info)])
        (printf "~a~n" i)))

(pdata-map! procedure read/write-pdata-name read-pdata-name ...)

Returns void

A high level control structure for simplifying passing over pdata arrays for primitive deformation. Should be easier and less error prone than looping manually. Writes to the first pdata array.

Example

 (clear)
 (define my-torus (build-torus 1 2 30 30))

 (with-primitive my-torus
   (pdata-map!
      (lambda (position)
          (vadd position (vector (flxrnd) 0 0))) ; jitter the vertex in x
      "p")) ; read/write the position pdata array

 (with-primitive my-torus
   (pdata-map!
      (lambda (position normal)
          (vadd position normal)) ; add the normal to the position (expand the object)
      "p" "n")) ; read/write the position pdata array, read the normals array

(pdata-index-map! procedure read/write-pdata-name read-pdata-name ...)

Returns void

A high level control structure for simplifying passing over pdata arrays for primitive deformation. Same as pdata-map! except pdata-index-map! supplies the index of the current pdata element as the first argument to 'procedure'.

Example

 (clear)
 (define my-torus (build-torus 1 2 30 30))

 (with-primitive my-torus
   (pdata-index-map!
      (lambda (index position)
          (vadd position (vector (gh index) 0 0))) ; jitter the vertex in x
      "p")) ; read/write the position pdata array

(pdata-fold procedure start-value read-pdata-name ...)

Returns result of folding procedure over pdata array

A high level control structure for doing calculations on pdata arrays. Runs the procedure over each pdata element accumulating the result. Should be easier and less error prone than looping manually.

Example

 (define my-torus (build-torus 1 2 30 30))

 ; find the centre of the primitive by averaging
 ; the points position's together
 (let ((centre
        (with-primitive my-torus
                        (vdiv (pdata-fold
                               vadd
                               (vector 0 0 0)
                               "p") (pdata-size)))))

   (display centre)(newline))

(pdata-index-fold procedure start-value read-pdata-name ...)

Returns result of folding procedure over pdata array

Same as pdata-fold except it passes the index of the current pdata element as the first parameter of 'procedure'.

Example

 (define my-torus (build-torus 1 2 30 30))

 ; can't think of a good example for this yet...
 (let ((something
        (with-primitive my-torus
                        (vdiv (pdata-index-fold
                               (lambda (index position ret)
                                   (vadd ret (vmul position index)))
                               (vector 0 0 0)
                               "p") (pdata-size)))))

   (display something)(newline))

(vadd vector vector ...)

Returns result-vector

Adds vectors together

Example

 (vadd (vector 1 2 3) (vector 5 2 7))
 (vadd (vector 1 2 3 4) (vector 7 1 1 4))
 (vadd (vector 1 2) (vector 3 3) (vector 5 5))

(vsub vector vector ...)

Returns result-vector

Subtracts a vector or multiple vectors from each other

Example

 (vsub (vector 1 2 3) (vector 5 2 7))
 (vsub (vector 1 2 3 4) (vector 7 1 1 4))
 (vsub (vector 1 2) (vector 3 3) (vector 5 5))

(vmul vector number)

Returns result-vector

Multiplies a vector by a number

Example

 (vmul (vector 1 2 3) 2)
 (vmul (vector 1 2 3 4 5) 3)

(vdiv vector number)

Returns result-vector

Divides a vector by a number

Example

 (vdiv (vector 1 2 3) 2)
 (vdiv (vector 1 2 3 4 5) 3)

(collada-import filename-string)

Returns void

Loads a collada scene file and returns a scene description list. Files need to contain triangulated model data - this is usually an option on the export. Note: this is slow for heavy models

Example

 ;(collada-import "test.dae")

(detach-parent)

Returns void

Removes the parent for the current primitive, and fixes up the transform so the primitive doesn't move. Use (parent 1) to avoid this fix up.

Example

 ; builds and animates a random heirarchical structure,
 ; click on the objects to detach them from their parents
 (define (build-heir depth)
     (with-state
         (let ((p (with-state
                         (translate (vector 2 0 0))
                         (scale 0.9)
                         (build-cube))))
             (when (> depth 0)
                 (parent p)
                 (for ((i (in-range 0 5)))
                     (when (zero? (random 3))
                         (rotate (vector 0 0 (* 45 (crndf))))
                         (build-heir (- depth 1))))))))

 (define (animate-heir children depth)
     (for-each
         (lambda (child)
             (with-primitive child
                 (rotate (vector 0 0 (sin (+ depth (time)))))
                 (animate-heir (get-children) (+ depth 1))))
         children))

 (define (animate)
     (animate-heir (get-children) 0)
     (when (mouse-button 1)
         (let ((s (select (mouse-x) (mouse-y) 2)))
             (when (not (zero? s))
                 (with-primitive s
                     (detach-parent))))))

 (clear)
 (build-heir 5)
 (every-frame (animate))

(with-state expression ...)

Returns result of last expression

Encapsulates local state changes, and removes the need for push and pop.

Example

 ; state hierachy, by nesting with-state:
 (with-state
    (hint-vertcols)
    (colour (vector 0 0 1))
    (with-state
        (translate (vector 1 0 0))
        (build-sphere 10 10))
     (build-torus 1 2 30 30))

 ; making primitives:
 (define my-torus (with-state
    (hint-vertcols)
    (colour (vector 0 0 1))
    (build-torus 1 2 30 30)))

(with-primitive primitive expression ...)

Returns result of last expression

Encapsulates primitive state changes, and removes the need for grab and ungrab.

Example

 (define my-torus (with-state
    (colour (vector 0 0 1))
    (build-torus 1 2 30 30)))

 ; change the torus colour:
 (with-primitive my-torus
    (colour (vector 0 1 0)))

(with-pixels-renderer pixels-primitive expression ...)

Returns result of last expression

Allows you to render into a pixel primitive.

Example


(with-ffgl ffgl-pluginid expression ...)

Returns result of last expression

Allows you to work with the specified FFGL plugin.

Example

 (clear)
 (define plugin (ffgl-load "FFGLTile.dylib" 256 256))

 (with-ffgl plugin
   (for ([i (ffgl-get-info)])
        (printf "~a~n" i)))

(pdata-map! procedure read/write-pdata-name read-pdata-name ...)

Returns void

A high level control structure for simplifying passing over pdata arrays for primitive deformation. Should be easier and less error prone than looping manually. Writes to the first pdata array.

Example

 (clear)
 (define my-torus (build-torus 1 2 30 30))

 (with-primitive my-torus
   (pdata-map!
      (lambda (position)
          (vadd position (vector (flxrnd) 0 0))) ; jitter the vertex in x
      "p")) ; read/write the position pdata array

 (with-primitive my-torus
   (pdata-map!
      (lambda (position normal)
          (vadd position normal)) ; add the normal to the position (expand the object)
      "p" "n")) ; read/write the position pdata array, read the normals array

(pdata-index-map! procedure read/write-pdata-name read-pdata-name ...)

Returns void

A high level control structure for simplifying passing over pdata arrays for primitive deformation. Same as pdata-map! except pdata-index-map! supplies the index of the current pdata element as the first argument to 'procedure'.

Example

 (clear)
 (define my-torus (build-torus 1 2 30 30))

 (with-primitive my-torus
   (pdata-index-map!
      (lambda (index position)
          (vadd position (vector (gh index) 0 0))) ; jitter the vertex in x
      "p")) ; read/write the position pdata array

(pdata-fold procedure start-value read-pdata-name ...)

Returns result of folding procedure over pdata array

A high level control structure for doing calculations on pdata arrays. Runs the procedure over each pdata element accumulating the result. Should be easier and less error prone than looping manually.

Example

 (define my-torus (build-torus 1 2 30 30))

 ; find the centre of the primitive by averaging
 ; the points position's together
 (let ((centre
        (with-primitive my-torus
                        (vdiv (pdata-fold
                               vadd
                               (vector 0 0 0)
                               "p") (pdata-size)))))

   (display centre)(newline))

(pdata-index-fold procedure start-value read-pdata-name ...)

Returns result of folding procedure over pdata array

Same as pdata-fold except it passes the index of the current pdata element as the first parameter of 'procedure'.

Example

 (define my-torus (build-torus 1 2 30 30))

 ; can't think of a good example for this yet...
 (let ((something
        (with-primitive my-torus
                        (vdiv (pdata-index-fold
                               (lambda (index position ret)
                                   (vadd ret (vmul position index)))
                               (vector 0 0 0)
                               "p") (pdata-size)))))

   (display something)(newline))

(vadd vector vector ...)

Returns result-vector

Adds vectors together

Example

 (vadd (vector 1 2 3) (vector 5 2 7))
 (vadd (vector 1 2 3 4) (vector 7 1 1 4))
 (vadd (vector 1 2) (vector 3 3) (vector 5 5))

(vsub vector vector ...)

Returns result-vector

Subtracts a vector or multiple vectors from each other

Example

 (vsub (vector 1 2 3) (vector 5 2 7))
 (vsub (vector 1 2 3 4) (vector 7 1 1 4))
 (vsub (vector 1 2) (vector 3 3) (vector 5 5))

(vmul vector number)

Returns result-vector

Multiplies a vector by a number

Example

 (vmul (vector 1 2 3) 2)
 (vmul (vector 1 2 3 4 5) 3)

(vdiv vector number)

Returns result-vector

Divides a vector by a number

Example

 (vdiv (vector 1 2 3) 2)
 (vdiv (vector 1 2 3 4 5) 3)

(collada-import filename-string)

Returns void

Loads a collada scene file and returns a scene description list. Files need to contain triangulated model data - this is usually an option on the export. Note: this is slow for heavy models

Example

 ;(collada-import "test.dae")

(vmix a b t)

Returns void

Linearly interpolates the two vectors together by t

Example

 
 ; mix red and blue together
 (colour (vmix (vector 1 0 0) (vector 0 0 1) 0.5))

(vclamp a)

Returns void

Clamp the vector so the elements are all between 0 and 1

Example

 
 ; make a valid colour from any old vector
 (colour (vclamp (vector 2 400 -123)))

(vsquash a)

Returns void

Normalise the vector so all the elements are between 0 and 1 but maintain the same ratio between them.

Example

 
 ; make a valid colour from any old vector
 (colour (vsquash (vector 2 400 -123)))

(pixels-circle pos radius colour)

Returns void

Draws a circle into a pixels primitive

Example

 
 (with-primitive (build-pixels 100 100)
     (pixels-circle (vector 50 50 0) 30 (vector 1 0 0 1))
     (pixels-upload))

(pixels-blend-circle pos radius colour)

Returns void

Draws a blended circle into a pixels primitive

Example

 (with-primitive (build-pixels 100 100)
     (pixels-blend-circle (vector 50 50 0) 30 (vector 1 0 0 1))
     (pixels-upload))

(pixels-dodge pos radius strength)

Returns void

Lightens a circular area of a pixels primitive

Example

 (with-primitive (build-pixels 100 100)
     (pixels-dodge (vector 50 50 0) 30 (vector 1 0 0 1))
     (pixels-upload))

(pixels-burn pos radius strength)

Returns void

Darkens a circular area of a pixels primitive

Example

 (with-primitive (build-pixels 100 100)
     (pixels-burn (vector 50 50 0) 30 (vector 1 0 0 1))
     (pixels-upload))

(pixels-clear col)

Returns void

Sets all of the pixels to the supplied colour

Example

 (with-primitive (build-pixels 100 100)
     (pixels-clear (vector 1 0 0))
     (pixels-upload))

(pixels-index position-vector)

Returns index-number

Returns the pdata index for the given texture coordinate

Example

 
 (with-primitive (build-pixels 10 10)
     (display (pixels-index (vector 0.5 0.5 0)))(newline))

(pixels-texcoord index)

Returns position-vector

Returns the texture coordinate for the given pdata index

Example

 
 (with-primitive (build-pixels 10 10)
     (display (pixels-texcoord 25))(newline))

(poly-type)

Returns void

Returns a symbol representing the type of the current polygon primitive. primitive.

Example

 (define p (build-polygons 3 'triangle-strip))
 (with-primitive p
     (display (poly-type))(newline))

(poly-for-each-face proc pdatanames)

Returns list of pdata values

Calls proc with the indices for each face in a polygon primitive

Example

 

(poly-for-each-triangle proc)

Returns list of pdata values

Calls proc with the pdata for each triangle in a face - assumes all faces are convex.

Example

 

(poly-build-triangulate primitive-id)

Returns primitive-id

A new poly primitive of type triangle-list representing the supplied poly primitive.

Example

 
 (define triangulated-plane (poly-build-triangulate (build-seg-plane 20 20)))

(poly-for-each-tri-sample proc samples-per-triangle)

Returns void

Calls proc with the triangle indices and a random barycentric coord.

Example

 

(build-extrusion profile-list path-list width-list tex-vscale up)

Returns primitive-id

Returns an indexed polygon primitive made by extruding the profile along path and scaling using values in width. The path and width lists need to be the same size. tex-vscale allows you to scale the texture coordinates along the length of the extrusion. An up vector is needed for aiming the profile along the path.

Example

 
 (clear)
 (build-extrusion 
     (build-circle-points 20 0.3)
     (list
         (vector 0 0 0)
         (vector 0 1 2)
         (vector 0 -1 4)
         (vector 0 0 6))
     (list 0 1 1 0) 1 (vector 0 1 0))

(build-partial-extrusion profile-list path-list tex-vscale)

Returns primitive-id

Builds a primitive ready to be used with partial-extrusion. Use this is for animating growth along extrusions.

Example

 
 (clear)
 
 (define profile (build-circle-points 10 0.3))
 (define path (build-list 20 (lambda (i) (vector (crndf) (crndf) i))))
 (define width (build-list 20 (lambda (_) 1)))
 
 (hint-wire)
 (define p (build-partial-extrusion profile path 1))
  
 (every-frame 
     (with-primitive p
         (partial-extrude (* (length path) 0.5 (+ (sin (time)) 1)) 
             profile path width (vector 0 1 0) 0.1))) 

(partial-extrude profile-list t profile-list path-list width-list up grow-value)

Returns primitive-id

Animates growth along extrusions. t is a value between 0 and the length of the path, and controls how far along the extrusion to calculate. Grow value is a scale to control how much the profile is scaled to change it's width as it grows.

Example

 
 (clear)
 
 (define profile (build-circle-points 10 0.3))
 (define path (build-list 20 (lambda (i) (vector (crndf) (crndf) i))))
 (define width (build-list 20 (lambda (_) 1)))
 
 (hint-wire)
 (define p (build-partial-extrusion profile path 100))
  
 (every-frame 
     (with-primitive p
         (partial-extrude (* (length path) 0.5 (+ (sin (time)) 1)) 
             profile path width (vector 0 1 0) 0.1))) 

(build-disk num-points)

Returns primitive-id

Builds a disk shaped poly primitive

Example

 
 (clear)
 (build-disk 10)

(rndf)

Returns number

Returns a random number in the range 0->1

Example

 (display (rndf))(newline)

(crndf)

Returns number

Returns a random number in the range -1->1 (centred on zero)

Example

 (display (crndf))(newline)

(rndvec)

Returns vector

Returns a random 3 element vector with each element in the range 0->1. If you visualise a lot of these as points, they will fill the unit cube (see the example).

Example

 (clear)
 (hint-none)
 (hint-points)
 (point-width 4)
 (define p (build-particles 1000))
 
 (show-axis 1)
 
 (with-primitive p
     (pdata-map! 
         (lambda (p)
             (vector 1 1 1))
         "c")
     (pdata-map! 
         (lambda (p)
             (rndvec))
         "p"))

(crndvec)

Returns vector

Returns a random 3 element vector with each element in the range -1->1. If you visualise a lot of these as points, they will fill a cube centred on the origin (see the example).

Example

 (clear)
 (hint-none)
 (hint-points)
 (point-width 4)
 (define p (build-particles 1000))
 
 (show-axis 1)
 
 (with-primitive p
     (pdata-map! 
         (lambda (p)
             (vector 1 1 1))
         "c")
     (pdata-map! 
         (lambda (p)
             (crndvec))
         "p"))

(srndvec)

Returns vector

Returns a random 3 element vector. If you visualise a lot of these as points, they will fill a sphere centred on the origin (see the example).

Example

 (clear)
 (hint-none)
 (hint-points)
 (point-width 4)
 (define p (build-particles 1000))
 
 (show-axis 1)
 
 (with-primitive p
     (pdata-map! 
         (lambda (p)
             (vector 1 1 1))
         "c")
     (pdata-map! 
         (lambda (p)
             (srndvec))
         "p"))

(hsrndvec)

Returns vector

Returns a random 3 element vector. If you visualise a lot of these as points, they will cover the surface of a sphere centred on the origin (see the example). The name stands for "hollow sphere".

Example

 (clear)
 (hint-none)
 (hint-points)
 (point-width 4)
 (define p (build-particles 1000))
 
 (show-axis 1)
 
 (with-primitive p
     (pdata-map! 
         (lambda (p)
             (vector 1 1 1))
         "c")
     (pdata-map! 
         (lambda (p)
             (hsrndvec))
         "p"))

(grndf)

Returns number

Returns a gaussian random number in the range centred on zero, with a variance of 1

Example

 (display (grndf))(newline)

(grndvec)

Returns vector

Returns a gaussian random 3 element vector. If you visualise a lot of these as points, you will see a normal distribution centred on the origin. (see the example).

Example

 (clear)
 (hint-none)
 (hint-points)
 (point-width 4)
 (define p (build-particles 1000))
 
 (show-axis 1)
 
 (with-primitive p
     (pdata-map! 
         (lambda (p)
             (vector 1 1 1))
         "c")
     (pdata-map! 
         (lambda (p)
             (grndvec))
         "p"))

(rndbary)

Returns vector

Returns a vector representing a uniformly distributed triangular barycentric coordinate (wip - doesn't seem to be very uniform to me...)

Example

 (rndbary)

(rndbary normal)

Returns vector

Returns a vector representing a random point on a hemisphere, defined by normal.

Example

 (clear)
 (hint-none)
 (hint-points)
 (point-width 4)
 (define p (build-particles 1000))
 
 (show-axis 1)
 
 (with-primitive p
     (pdata-map! 
         (lambda (p)
             (vector 1 1 1))
         "c")
     (pdata-map! 
         (lambda (p)
             (rndhemi (vector 0 1 0)))
         "p"))

(hrndbary normal)

Returns vector

Returns a vector representing a random point on a hollow hemisphere, defined by normal.

Example

 (clear)
 (hint-none)
 (hint-points)
 (point-width 4)
 (define p (build-particles 1000))
 
 (show-axis 1)
 
 (with-primitive p
     (pdata-map! 
         (lambda (p)
             (vector 1 1 1))
         "c")
     (pdata-map! 
         (lambda (p)
             (hrndhemi (vector 0 1 0)))
         "p"))

(build-circle-points num-points radius)

Returns primitive-id

Returns a list of vectors describing a circle. Useful for generating circles for the extrusion generator.

Example

 
 (clear)
 (build-extrusion 
     (build-circle-points 20 0.3)
     (list
         (vector 0 0 0)
         (vector 0 1 2)
         (vector 0 -1 4)
         (vector 0 0 6))
     (list 0 1 1 0) 1 (vector 0 1 0))

(pdata-for-each-tri-sample proc samples-per-triangle)

Returns void

Calls proc with the triangle indices and a random barycentric coord?

Example


(expand distance-value)

Returns void

Expand object along the normals

Example

 (with-primitive (build-cube)
   (expand 5))

(occlusion-texture-bake tex prim samples-per-face rays-per-sample ray-length debug)

Returns void

Bakes ambient occlusion textures. See ambient-occlusion.scm for more info.

Example


(vmix a b t)

Returns vector

Linearly interpolates the two vectors together by t

Example

 
 ; mix red and blue together
 (colour (vmix (vector 1 0 0) (vector 0 0 1) 0.5))

(vclamp a)

Returns vector

Clamp the vector so the elements are all between 0 and 1

Example

 
 ; make a valid colour from any old vector
 (colour (vclamp (vector 2 400 -123)))

(vsquash a)

Returns vector

Normalise the vector so all the elements are between 0 and 1 but maintain the same ratio between them.

Example

 
 ; make a valid colour from any old vector
 (colour (vsquash (vector 2 400 -123)))

(lerp a b t)

Returns number

Linearly interpolates the two numbers together by t

Example

 (lerp 1 2 .3)

(vlerp a b t)

Returns vector

Linearly interpolates the two vectors together by t

Example

 ; mix red and blue together
 (colour (vlerp (vector 1 0 0) (vector 0 0 1) 0.3))

(mlerp a b t)

Returns vector

Linearly interpolates the two matrices together by t

Example

 (mlerp (mtranslate (vector 1 0 0)) (mtranslate (vector 0 1 0)) .3)

(get-line-from-xy)

Returns list of 2 vectors (start position, end position)

Gets a line representing a segment of the projection of the x,y points into 3D space. at depth z from the camera

Example

 

(world-pos)

Returns vector

Gets the world position of a point in 3D world space.

Example

 

(mouse-pos)

Returns vector

Gets the mouse position in 3D world space.

Example

 

(mouse-pos-z)

Returns vector

Gets the mouse position in 3D world space at depth z.

Example

 

(2dvec->angle x y)

Returns float

Converts a 2D vector into an angle, with some dodgy Dave maths

Example

 

(pixels-circle pos radius colour)

Returns void

Draws a circle into a pixels primitive

Example

 
 (with-primitive (build-pixels 100 100)
     (pixels-circle (vector 50 50 0) 30 (vector 1 0 0 1))
     (pixels-upload))

(pixels-blend-circle pos radius colour)

Returns void

Draws a blended circle into a pixels primitive

Example

 (with-primitive (build-pixels 100 100)
     (pixels-blend-circle (vector 50 50 0) 30 (vector 1 0 0 1))
     (pixels-upload))

(pixels-dodge pos radius strength)

Returns void

Lightens a circular area of a pixels primitive

Example

 (with-primitive (build-pixels 100 100)
     (pixels-dodge (vector 50 50 0) 30 (vector 1 0 0 1))
     (pixels-upload))

(pixels-burn pos radius strength)

Returns void

Darkens a circular area of a pixels primitive

Example

 (with-primitive (build-pixels 100 100)
     (pixels-burn (vector 50 50 0) 30 (vector 1 0 0 1))
     (pixels-upload))

(pixels-clear col)

Returns void

Sets all of the pixels to the supplied colour

Example

 (with-primitive (build-pixels 100 100)
     (pixels-clear (vector 1 0 0))
     (pixels-upload))

(pixels-index position-vector)

Returns index-number

Returns the pdata index for the given texture coordinate

Example

 
 (with-primitive (build-pixels 10 10)
     (display (pixels-index (vector 0.5 0.5 0)))(newline))

(pixels-texcoord index)

Returns position-vector

Returns the texture coordinate for the given pdata index

Example

 
 (with-primitive (build-pixels 10 10)
     (display (pixels-texcoord 25))(newline))

(poly-type)

Returns void

Returns a symbol representing the type of the current polygon primitive. primitive.

Example

 (define p (build-polygons 3 'triangle-strip))
 (with-primitive p
     (display (poly-type))(newline))

(poly-for-each-face proc pdatanames)

Returns list of pdata values

Calls proc with the indices for each face in a polygon primitive

Example

 

(poly-for-each-triangle proc)

Returns list of pdata values

Calls proc with the pdata for each triangle in a face - assumes all faces are convex.

Example

 

(poly-build-triangulate primitive-id)

Returns primitive-id

A new poly primitive of type triangle-list representing the supplied poly primitive.

Example

 
 (define triangulated-plane (poly-build-triangulate (build-seg-plane 20 20)))

(poly-for-each-tri-sample proc samples-per-triangle)

Returns void

Calls proc with the triangle indices and a random barycentric coord.

Example

 

(build-extrusion profile-list path-list width-list tex-vscale up)

Returns primitive-id

Returns an indexed polygon primitive made by extruding the profile along path and scaling using values in width. The path and width lists need to be the same size. tex-vscale allows you to scale the texture coordinates along the length of the extrusion. An up vector is needed for aiming the profile along the path.

Example

 
 (clear)
 (build-extrusion 
     (build-circle-points 20 0.3)
     (list
         (vector 0 0 0)
         (vector 0 1 2)
         (vector 0 -1 4)
         (vector 0 0 6))
     (list 0 1 1 0) 1 (vector 0 1 0))

(build-partial-extrusion profile-list path-list tex-vscale)

Returns primitive-id

Builds a primitive ready to be used with partial-extrusion. Use this is for animating growth along extrusions.

Example

 
 (clear)
 
 (define profile (build-circle-points 10 0.3))
 (define path (build-list 20 (lambda (i) (vector (crndf) (crndf) i))))
 (define width (build-list 20 (lambda (_) 1)))
 
 (hint-wire)
 (define p (build-partial-extrusion profile path 1))
  
 (every-frame 
     (with-primitive p
         (partial-extrude (* (length path) 0.5 (+ (sin (time)) 1)) 
             profile path width (vector 0 1 0) 0.1))) 

(partial-extrude profile-list t profile-list path-list width-list up grow-value)

Returns primitive-id

Animates growth along extrusions. t is a value between 0 and the length of the path, and controls how far along the extrusion to calculate. Grow value is a scale to control how much the profile is scaled to change it's width as it grows.

Example

 
 (clear)
 
 (define profile (build-circle-points 10 0.3))
 (define path (build-list 20 (lambda (i) (vector (crndf) (crndf) i))))
 (define width (build-list 20 (lambda (_) 1)))
 
 (hint-wire)
 (define p (build-partial-extrusion profile path 100))
  
 (every-frame 
     (with-primitive p
         (partial-extrude (* (length path) 0.5 (+ (sin (time)) 1)) 
             profile path width (vector 0 1 0) 0.1))) 

(build-disk num-points)

Returns primitive-id

Builds a disk shaped poly primitive

Example

 
 (clear)
 (build-disk 10)

(rndf)

Returns number

Returns a random number in the range 0->1

Example

 (display (rndf))(newline)

(crndf)

Returns number

Returns a random number in the range -1->1 (centred on zero)

Example

 (display (crndf))(newline)

(rndvec)

Returns vector

Returns a random 3 element vector with each element in the range 0->1. If you visualise a lot of these as points, they will fill the unit cube (see the example).

Example

 (clear)
 (hint-none)
 (hint-points)
 (point-width 4)
 (define p (build-particles 1000))
 
 (show-axis 1)
 
 (with-primitive p
     (pdata-map! 
         (lambda (p)
             (vector 1 1 1))
         "c")
     (pdata-map! 
         (lambda (p)
             (rndvec))
         "p"))

(crndvec)

Returns vector

Returns a random 3 element vector with each element in the range -1->1. If you visualise a lot of these as points, they will fill a cube centred on the origin (see the example).

Example

 (clear)
 (hint-none)
 (hint-points)
 (point-width 4)
 (define p (build-particles 1000))
 
 (show-axis 1)
 
 (with-primitive p
     (pdata-map! 
         (lambda (p)
             (vector 1 1 1))
         "c")
     (pdata-map! 
         (lambda (p)
             (crndvec))
         "p"))

(srndvec)

Returns vector

Returns a random 3 element vector. If you visualise a lot of these as points, they will fill a sphere centred on the origin (see the example).

Example

 (clear)
 (hint-none)
 (hint-points)
 (point-width 4)
 (define p (build-particles 1000))
 
 (show-axis 1)
 
 (with-primitive p
     (pdata-map! 
         (lambda (p)
             (vector 1 1 1))
         "c")
     (pdata-map! 
         (lambda (p)
             (srndvec))
         "p"))

(hsrndvec)

Returns vector

Returns a random 3 element vector. If you visualise a lot of these as points, they will cover the surface of a sphere centred on the origin (see the example). The name stands for "hollow sphere".

Example

 (clear)
 (hint-none)
 (hint-points)
 (point-width 4)
 (define p (build-particles 1000))
 
 (show-axis 1)
 
 (with-primitive p
     (pdata-map! 
         (lambda (p)
             (vector 1 1 1))
         "c")
     (pdata-map! 
         (lambda (p)
             (hsrndvec))
         "p"))

(grndf)

Returns number

Returns a gaussian random number in the range centred on zero, with a variance of 1

Example

 (display (grndf))(newline)

(grndvec)

Returns vector

Returns a gaussian random 3 element vector. If you visualise a lot of these as points, you will see a normal distribution centred on the origin. (see the example).

Example

 (clear)
 (hint-none)
 (hint-points)
 (point-width 4)
 (define p (build-particles 1000))
 
 (show-axis 1)
 
 (with-primitive p
     (pdata-map! 
         (lambda (p)
             (vector 1 1 1))
         "c")
     (pdata-map! 
         (lambda (p)
             (grndvec))
         "p"))

(rndbary)

Returns vector

Returns a vector representing a uniformly distributed triangular barycentric coordinate (wip - doesn't seem to be very uniform to me...)

Example

 (rndbary)

(rndbary normal)

Returns vector

Returns a vector representing a random point on a hemisphere, defined by normal.

Example

 (clear)
 (hint-none)
 (hint-points)
 (point-width 4)
 (define p (build-particles 1000))
 
 (show-axis 1)
 
 (with-primitive p
     (pdata-map! 
         (lambda (p)
             (vector 1 1 1))
         "c")
     (pdata-map! 
         (lambda (p)
             (rndhemi (vector 0 1 0)))
         "p"))

(hrndbary normal)

Returns vector

Returns a vector representing a random point on a hollow hemisphere, defined by normal.

Example

 (clear)
 (hint-none)
 (hint-points)
 (point-width 4)
 (define p (build-particles 1000))
 
 (show-axis 1)
 
 (with-primitive p
     (pdata-map! 
         (lambda (p)
             (vector 1 1 1))
         "c")
     (pdata-map! 
         (lambda (p)
             (hrndhemi (vector 0 1 0)))
         "p"))

(build-circle-points num-points radius)

Returns primitive-id

Returns a list of vectors describing a circle. Useful for generating circles for the extrusion generator.

Example

 
 (clear)
 (build-extrusion 
     (build-circle-points 20 0.3)
     (list
         (vector 0 0 0)
         (vector 0 1 2)
         (vector 0 -1 4)
         (vector 0 0 6))
     (list 0 1 1 0) 1 (vector 0 1 0))

(pdata-for-each-tri-sample proc samples-per-triangle)

Returns void

Calls proc with the triangle indices and a random barycentric coord?

Example


(expand distance-value)

Returns void

Expand object along the normals

Example

 (with-primitive (build-cube)
   (expand 5))

(occlusion-texture-bake tex prim samples-per-face rays-per-sample ray-length debug)

Returns void

Bakes ambient occlusion textures. See ambient-occlusion.scm for more info.

Example