Primitives are objects that you can render. There isn't really much else in a fluxus scene, except lights, a camera and lots of primitives.
Returns primitiveid-number
A simple cube, texture mapped placement per face.
Example
(define mynewcube (build-cube))
Returns primitiveid-number
Builds a raw polygon primitive with size vertices (everything is initially set to zero). Type is a symbol that refers to the way the vertices are interpreted to build polygons, and can be one of the following: triangle-strip quad-list triangle-list triangle-fan polygon
Example
(define mynewshape (build-polygons 100 'triangle-strip))
Returns primitiveid-number
A sphere with the resolution specified, texture mapped in normal "world map" style.
Example
(define mynewshape (build-sphere 10 10))
Returns primitiveid-number
Build sphere by recursively subdividing an icosahedron.
Example
(define mynewshape (build-icosphere 1))
Returns primitiveid-number
A torus with the resolution specified, control the size and thickness of the donut with the inner and outer radius.
Example
(define mynewshape (build-torus 0.5 1 12 12))
Returns primitiveid-number
A single quad plane, texture mapped from 0->1 in both dimensions.
Example
(define mynewshape (build-plane))
Returns primitiveid-number
A tesselated poly plane, texture mapped from 0->1 in both dimensions.
Example
(define mynewshape (build-plane))
Returns primitiveid-number
A capped cylinder, texture map wrapped around, and badly wrapped around the ends.
Example
(define mynewshape (build-cylinder 10 10))
Returns primitiveid-number
Builds a ribbon consisting of numpoints points. The geometry is constantly camera facing and is texture mapped so the texture is stretched along the ribbon from start to finish. You use the pdata functions to edit the postions and widths of the segments. If used lit, the normals are faked to approximate a circular cross section. Additionally, if solid rendering is cleared with (hint-none) and (hint-wire) is activated, a faster constant width line will be drawn - width specified by the (line-width) command.
Example
(define mynewshape (build-ribbon 10))
Returns primitiveid-number
Builds a sequence of planes, texture mapped so that a font texture can be used to display text. Might also be useful for more abstract things. The font assumed to be non proportional - there is an example font shipped with fluxus Ok, so this isn't a very good font texture :)
Example
(texture (load-texture "font.png")) (define mynewshape (build-text "hello"))
Returns primitiveid-number
Builds a geometric type primitive from a ttf font and some text.
Example
(clear) (wire-colour (vector 0 0 1)) ; this font should be on the default fluxus path (as it's the editor font) (define t (build-type "Bitstream-Vera-Sans-Mono.ttf" "fluxus rocks!!")) ; make a poly primitive from the type (define p (with-state (translate (vector 0 4 0)) (type->poly t))) ; set some texture coords on the poly prim and load a texture onto it (with-primitive p (pdata-map! (lambda (t p) (vmul p 0.5)) "t" "p") (texture (load-texture "refmap.png")))
Returns primitiveid-number
Builds an extruded geometric type primitive from a ttf font and some text.
Example
(clear) (wire-colour (vector 0 0 1)) ; this font should be on the default fluxus path (as it's the editor font) (define t (build-extruded-type "Bitstream-Vera-Sans-Mono.ttf" "fluxus rocks!!" 1)) ; make a poly primitive from the type (define p (with-state (translate (vector 0 4 0)) (type->poly t))) ; set some texture coords on the poly prim and load a texture onto it (with-primitive p (pdata-map! (lambda (t p) (vmul p 0.5)) "t" "p") (texture (load-texture "refmap.png")))
Returns polyprimid-number
Converts the mesh of a type primitive into a triangle list polygon primitive. The poly primitive will be a bit slower to render, but you'll be able to do everything you can do with a poly primitive with it, such as add textures and deform it.
Example
(clear) (wire-colour (vector 0 0 1)) ; this font should be on the default fluxus path (as it's the editor font) (define t (build-extruded-type "Bitstream-Vera-Sans-Mono.ttf" "fluxus rocks!!" 1)) ; make a poly primitive from the type (define p (with-state (translate (vector 0 4 0)) (type->poly t))) ; set some texture coords on the poly prim and load a texture onto it (with-primitive p (pdata-map! (lambda (t p) (vmul p 0.5)) "t" "p") (texture (load-texture "refmap.png")))
Returns primitiveid-number
Sets parameters for making fonts from texture maps. Defaults: 16/256 16/256 16 0
Example
; don't use me!
Returns void
Inverts the automatically generated ribbon normals
Example
(define mynewshape (build-ribbon 10)) (with-primitive mynewshape (ribbon-inverse-normals 1))
Returns primitiveid-number
Builds a tesselated nurbs sphere, texture mapped in the same fashion as the poly sphere.
Example
(define mynewshape (build-nurbs-sphere 10 10))
Returns primitiveid-number
Builds a tesselated nurbs plane, texture mapped in uv direction.
Example
(define mynewshape (build-nurbs-plane 10 10))
Returns primitiveid-number
Builds a particles primitive containing num points, all initially set to the origin. You use the pdata functions to edit the postions, colours and sizes. Particles come in two flavors, camera facing sprites, which are the default, can be textured and individually scaled; and points (when hint-points is set), which cannot be textured but are much faster to render, as they are hardware supported gl points. By default these point particles are square, turn on hint-anti-alias to make them circular.
Example
(define mynewshape (build-particles 100))
Returns primitiveid-number
Builds an image, which is displayed on screen using 2D orthographic projection. Coordinate defines the location of the image from the upper-left corner. Size specifies the image display resolution in pixels.
Example
(define img (build-image (load-texture "test.png") (vector 0 0) (get-screen-size)))
Returns primitiveid-number
Builds voxels primitive, similar to pixel primitives, except include a 3rd dimension.
Example
(define vox (build-voxels 10 10 10))
Returns blobbyprimid-number
Converts the voxels from a voxels primitive to those of a blobby primitive, this is only really of use for then converting the voxels to a polygon primitive. The blobby is just the intermediate step.
Example
Returns polyprimid-number
Converts the voxels from a voxels primitive into a triangle list polygon primitive.
Example
(clear) (define vx (build-voxels 16 16 16)) (with-primitive vx (voxels-sphere-influence (vector 0 0 0) (vector 1 1 1 .1) .5) (voxels-calc-gradient) (voxels-point-light (vector .5 .5 .5) (vector 1 0 1))) (define pb (voxels->poly vx)) (with-primitive pb (recalc-normals 0) (translate #(1.1 0 0)))
Returns width-number
Returns the width of the current voxels primitive.
Example
(define mynewshape (build-voxels 10 10 10)) (with-primitive mynewshape (display (vector (voxels-width) (voxels-height) (voxels-depth)))(newline))
Returns height-number
Returns the height of the current voxels primitive.
Example
(define mynewshape (build-voxels 10 10 10)) (with-primitive mynewshape (display (vector (voxels-width) (voxels-height) (voxels-depth)))(newline))
Returns depth-number
Returns the depth of the current voxels primitive.
Example
(define mynewshape (build-voxels 10 10 10)) (with-primitive mynewshape (display (vector (voxels-width) (voxels-height) (voxels-depth)))(newline))
Returns void
Fills out the "g" pdata array with the gradient of the voxel intensities. This is the first derivative, the change in intensity in x,y and z directions across the voxels. This can be used to approximate normals, is mainly of use for lighting the voxels.
Example
(clear) (blend-mode 'src-alpha 'one) (hint-nozwrite) (texture (load-texture "splat.png")) (define p (build-voxels 30 30 30)) (define t 0) (every-frame (with-primitive p (set! t (+ t 0.02)) (for ((i (in-range 0 10))) (voxels-sphere-solid (vector (+ 0.5 (* 0.5 (sin (+ (* i 0.1) t)))) 0.5 0.5) (if (odd? i) (vector 0 0 0) (vmul (vector 1 0.1 0.1) (* i 0.05))) (- 1 (/ i 10)))) (voxels-box-solid (vector 0.5 0.5 -0.1) (vector 1.1 1.1 1.1) (vector 0 0 0)) (voxels-calc-gradient) (voxels-point-light (vector 0 50 0) (vmul (vector 1 1 1) 0.05))))
Returns void
Adds a coloured sperical influence into the voxel values from the centre position.
Example
(clear) (blend-mode 'src-alpha 'one) (hint-nozwrite) (texture (load-texture "splat.png")) (define p (build-voxels 30 30 30)) (define t 0) (every-frame (with-primitive p (set! t (+ t 0.02)) (for ((i (in-range 0 10))) (voxels-sphere-solid (vector (+ 0.5 (* 0.5 (sin (+ (* i 0.1) t)))) 0.5 0.5) (if (odd? i) (vector 0 0 0) (vmul (vector 1 0.1 0.1) (* i 0.05))) (- 1 (/ i 10)))) (voxels-box-solid (vector 0.5 0.5 -0.1) (vector 1.1 1.1 1.1) (vector 0 0 0)) (voxels-calc-gradient) (voxels-point-light (vector 0 50 0) (vmul (vector 1 1 1) 0.05))))
Returns void
Sets a solid sphere of coloured voxel values.
Example
(clear) (blend-mode 'src-alpha 'one) (hint-nozwrite) (texture (load-texture "splat.png")) (define p (build-voxels 30 30 30)) (define t 0) (every-frame (with-primitive p (set! t (+ t 0.02)) (for ((i (in-range 0 10))) (voxels-sphere-solid (vector (+ 0.5 (* 0.5 (sin (+ (* i 0.1) t)))) 0.5 0.5) (if (odd? i) (vector 0 0 0) (vmul (vector 1 0.1 0.1) (* i 0.05))) (- 1 (/ i 10)))) (voxels-box-solid (vector 0.5 0.5 -0.1) (vector 1.1 1.1 1.1) (vector 0 0 0)) (voxels-calc-gradient) (voxels-point-light (vector 0 50 0) (vmul (vector 1 1 1) 0.05))))
Returns void
Sets a solid cube of coloured voxel values.
Example
(clear) (blend-mode 'src-alpha 'one) (hint-nozwrite) (texture (load-texture "splat.png")) (define p (build-voxels 30 30 30)) (define t 0) (every-frame (with-primitive p (set! t (+ t 0.02)) (for ((i (in-range 0 10))) (voxels-sphere-solid (vector (+ 0.5 (* 0.5 (sin (+ (* i 0.1) t)))) 0.5 0.5) (if (odd? i) (vector 0 0 0) (vmul (vector 1 0.1 0.1) (* i 0.05))) (- 1 (/ i 10)))) (voxels-box-solid (vector 0.5 0.5 -0.1) (vector 1.1 1.1 1.1) (vector 0 0 0)) (voxels-calc-gradient) (voxels-point-light (vector 0 50 0) (vmul (vector 1 1 1) 0.05))))
Returns void
Thresholds the voxels and colours those above the threshold white and those below the threshold black.
Example
(clear) (blend-mode 'src-alpha 'one) (hint-nozwrite) (texture (load-texture "splat.png")) (define p (build-voxels 30 30 30)) (define t 0) (every-frame (with-primitive p (set! t (+ t 0.02)) (for ((i (in-range 0 10))) (voxels-sphere-solid (vector (+ 0.5 (* 0.5 (sin (+ (* i 0.1) t)))) 0.5 0.5) (if (odd? i) (vector 0 0 0) (vmul (vector 1 0.1 0.1) (* i 0.05))) (- 1 (/ i 10)))) (voxels-box-solid (vector 0.5 0.5 -0.1) (vector 1.1 1.1 1.1) (vector 0 0 0)) (voxels-calc-gradient) (voxels-point-light (vector 0 50 0) (vmul (vector 1 1 1) 0.05))))
Returns void
Uses the gradient pdata array to light the voxels from a point light source
Example
(clear) (blend-mode 'src-alpha 'one) (hint-nozwrite) (texture (load-texture "splat.png")) (define p (build-voxels 30 30 30)) (define t 0) (every-frame (with-primitive p (set! t (+ t 0.02)) (for ((i (in-range 0 10))) (voxels-sphere-solid (vector (+ 0.5 (* 0.5 (sin (+ (* i 0.1) t)))) 0.5 0.5) (if (odd? i) (vector 0 0 0) (vmul (vector 1 0.1 0.1) (* i 0.05))) (- 1 (/ i 10)))) (voxels-box-solid (vector 0.5 0.5 -0.1) (vector 1.1 1.1 1.1) (vector 0 0 0)) (voxels-calc-gradient) (voxels-point-light (vector 0 50 0) (vmul (vector 1 1 1) 0.05))))
Returns primitiveid-number
A locator is an empty primitive, useful for parenting to (when you don't want to have the parent object visible). This primitive can only be visualised with (hint-origin) to display it's local transform origin.
Example
(define mynewshape (build-locator))
Returns void
Sets the bounding box radius for the locator
Example
(define mylocator (build-locator)) (with-primitive mylocator (locator-bounding-radius 23.4))
Returns primitiveid-number
Loads a primitive from disk
Example
(define mynewshape (load-primitive "octopus.obj"))
Returns void
Clears cached geometry, so subsequent loads with come from the disk.
Example
(clear-geometry-cache)
Returns void
Saves the current primitive to disk. Pixel primitives are saved as PNG files. Polygon primitives are saved as Wavefront OBJ files with material information. The children of the primitives are also saved as different objects in the file. New groups are generated for each locator in the hierarchy.
Example
(define l (build-locator)) (with-primitive (build-sphere 10 10) (colour #(1 0 0)) (parent l)) (translate (vector 3 2 0)) (rotate (vector 15 60 70)) (with-primitive (build-torus 1 2 10 10) (colour #(0 1 0)) (parent l)) (with-primitive l (save-primitive "p.obj"))
Returns primitiveid-number
Makes a new pixel primitive. A pixel primitive is used for making procedural textures, which can then be applied to other primitives. For this reason, pixel primitives probably wont be rendered much, but you can render them to preview the texture on a flat plane. Objects can be rendered into pixels primitives. The pixels primitive renderer is disabled by default. To enable it, use the renderer-activate optional boolean parameter.
Example
(clear) (define p1 (build-pixels 16 16)) (with-primitive p1 (pdata-map! (lambda (c) (rndvec)) "c") (pixels-upload)) ; call pixels upload to see the results (translate (vector 1.5 0 0)) (define p2 (build-pixels 256 256 #t)) ; render target (with-pixels-renderer p2 ; render a cube into the pixels primitive (clear-colour (vector .37 .5 .59)) (scale 5) (rotate (vector -5 60 140)) (build-cube))
Returns void
Uploads the texture data, you need to call this when you've finished writing to the pixelprim, and while it's grabbed.
Example
(define mynewshape (build-pixels 100 100)) (with-primitive mynewshape (pdata-map! (lambda (c) (rndvec)) "c") (pixels-upload)) ; call pixels upload to see the results
Returns void
Downloads the texture data from the GPU to the PData array.
Example
(clear) (define p (build-pixels 256 256 #t)) (define q (with-pixels-renderer p (clear-colour (vector 1 1 1)) (scale 3) (colour (vector 0 0 1)) (build-torus 0.2 2 10 20))) (define i (with-state (translate (vector 0.5 0.5 0)) (scale 0.2) (build-cube))) (every-frame (begin (with-primitive p (pixels-download) ; paint the cube with the colour of the pixel underneath it (let ((c (pdata-ref "c" (pixels-index (vector 0.5 0.5 0))))) (with-primitive i (colour c)))) (with-pixels-renderer p (with-primitive q (rotate (vector 1 0.2 0))))))
Returns textureid-number
Returns a texture you can use exactly like a normal loaded one.
Example
(define mypixels (build-pixels 100 100)) (with-primitive mypixels (pdata-map! (lambda (c) (rndvec)) "c") (pixels-upload)) (with-state (texture (pixels->texture mypixels)) (build-torus 1 2 10 10))
Returns width-number
Returns the width of the current pixel primitive.
Example
(define mynewshape (build-pixels 100 100)) (with-primitive mynewshape (display (vector (pixels-width) (pixels-height)))(newline))
Returns width-number
Returns the height of the current pixel primitive.
Example
(define mynewshape (build-pixels 100 100)) (with-primitive mynewshape (display (vector (pixels-width) (pixels-height)))(newline))
Returns void
Activates/deactivates the pixel primitive renderer.
Example
(clear) (define p (build-pixels 256 256)) (with-primitive p (pixels-renderer-activate #t)) (define cube (with-pixels-renderer p (clear-colour (vector .2 .4 .8)) (rotate #(30 50 80)) (scale 5) (build-cube)))
Returns primitiveid-number
Blobby primitives are a higher level implicit surface representation in fluxus which is defined using influences in 3 dimesional space. These infuences are then summed together, and a particular value is "meshed" (using the marching cubes algorithm) to form a smooth surface. The influences can be animated, and the smooth surface moves and deforms to adapt, giving the primitive it's blobby name. build-blobby returns a new blobby primitive. Numinfluences is the number of "blobs". Subdivisions allows you to control the resolution of the surface in each dimension, while boundingvec sets the bounding area of the primitive in local object space. The mesh will not be calculated outside of this area. Influence positions and colours need to be set using pdata-set.
Example
(clear) (define b (build-blobby 5 (vector 30 30 30) (vector 1 1 1))) (with-primitive b (shinyness 100) (specular (vector 1 1 1)) (hint-vertcols) (pdata-set "p" 0 (vector 0.75 0.25 0.5)) (pdata-set "c" 0 (vector 0.01 0 0)) (pdata-set "s" 0 0.01) (pdata-set "p" 1 (vector 0.25 0.75 0.5)) (pdata-set "c" 1 (vector 0 0.01 0)) (pdata-set "s" 1 0.01) (pdata-set "p" 2 (vector 0.75 0.75 0.5)) (pdata-set "c" 2 (vector 0 0 0.01)) (pdata-set "s" 2 0.01) (pdata-set "p" 3 (vector 0.25 0.25 0.5)) (pdata-set "c" 3 (vector 0.01 0.01 0)) (pdata-set "s" 3 0.01) (pdata-set "p" 4 (vector 0.5 0.5 0.5)) (pdata-set "c" 4 (vector 0.01 0.01 0.01)) (pdata-set "s" 4 0.025))
Returns polyprimid-number
Converts the mesh of a blobby primitive into a triangle list polygon primitive. This is useful as the polygon primitive will be much much faster to render, but can't deform in the blobby way. Doesn't convert vertex colours over yet unfortunately.
Example
(clear) (define b (build-blobby 5 (vector 30 30 30) (vector 1 1 1))) (with-primitive b (shinyness 100) (specular (vector 1 1 1)) (hint-vertcols) (pdata-set "p" 0 (vector 0.75 0.25 0.5)) (pdata-set "c" 0 (vector 0.01 0 0)) (pdata-set "s" 0 0.01) (pdata-set "p" 1 (vector 0.25 0.75 0.5)) (pdata-set "c" 1 (vector 0 0.01 0)) (pdata-set "s" 1 0.01) (pdata-set "p" 2 (vector 0.75 0.75 0.5)) (pdata-set "c" 2 (vector 0 0 0.01)) (pdata-set "s" 2 0.01) (pdata-set "p" 3 (vector 0.25 0.25 0.5)) (pdata-set "c" 3 (vector 0.01 0.01 0)) (pdata-set "s" 3 0.01) (pdata-set "p" 4 (vector 0.5 0.5 0.5)) (pdata-set "c" 4 (vector 0.01 0.01 0.01)) (pdata-set "s" 4 0.025)) (define p (with-state (translate (vector 1 0 0)) (blobby->poly b)))
Returns void
Copies a retained mode primitive and draws it in the current state as an immediate mode primitive.
Example
(define mynewshape (build-cube)) (colour (vector 1 0 0)) (draw-instance mynewshape) ; draws a copy of mynewshape
Returns void
Draws a cube in the current state in immediate mode primitive.
Example
(define (render) (draw-cube)) (every-frame (render))
Returns void
Draws a plane in the current state in immediate mode primitive.
Example
(define (render) (draw-plane)) (every-frame (render))
Returns void
Draws a sphere in the current state in immediate mode primitive.
Example
(define (render) (draw-sphere)) (every-frame (render))
Returns void
Draws a cylinder in the current state in immediate mode primitive.
Example
(define (render) (draw-cylinder)) (every-frame (render))
Returns void
Draws a torus in the current state in immediate mode primitive.
Example
(define (render) (draw-torus)) (every-frame (render))
Returns void
Draws a line in the current state in immediate mode. primitive.
Example
(define (render) (draw-line (vector 0 0 0) (vector 2 1 0))) (every-frame (render))
Returns void
Deletes a built primitive from the renderer. primitive.
Example
(define mynewshape (build-sphere 10 10)) (destroy mynewshape)
Returns void
Gets the vertex indices from this primitive.
Example
(define p (build-cube)) (with-primitive p (poly-convert-to-indexed) (display (poly-indices))(newline))
Returns void
Returns the enum value representing the type of the current polygon primitive. This is needed as I can't get my scheme scripts to recognise symbols returned from here. Use (poly-type) instead of this directly. primitive.
Example
(define (poly-type) (let ((t (poly-type-enum))) (cond ((eq? t 0) 'triangle-strip) ((eq? t 1) 'quad-list) ((eq? t 2) 'triangle-list) ((eq? t 3) 'triangle-fan) ((eq? t 4) 'polygon))))
Returns void
Returns true if the current polygon primitive is in indexed mode. primitive.
Example
(define p (build-polygons 3 'triangle-strip)) (with-primitive p (poly-convert-to-indexed) (display (poly-indexed?))(newline))
Returns void
Switches the primitive to indexed mode, and uses the list as the index values for this primitive. primitive.
Example
(clear) ; lets build our own cube primitive... (define p (build-polygons 8 'quad-list)) (with-primitive p ; setup the vertex data (pdata-set "p" 0 (vector -1 -1 -1)) (pdata-set "p" 1 (vector 1 -1 -1)) (pdata-set "p" 2 (vector 1 -1 1)) (pdata-set "p" 3 (vector -1 -1 1)) (pdata-set "p" 4 (vector -1 1 -1)) (pdata-set "p" 5 (vector 1 1 -1)) (pdata-set "p" 6 (vector 1 1 1)) (pdata-set "p" 7 (vector -1 1 1)) (pdata-set "c" 0 (vector 0 0 0)) (pdata-set "c" 1 (vector 0 0 1)) (pdata-set "c" 2 (vector 0 1 0)) (pdata-set "c" 3 (vector 0 1 1)) (pdata-set "c" 4 (vector 1 0 0)) (pdata-set "c" 5 (vector 1 0 1)) (pdata-set "c" 6 (vector 1 1 0)) (pdata-set "c" 7 (vector 1 1 1)) (hint-wire) (hint-unlit) (hint-vertcols) ; connect the verts together into faces (poly-set-index (list 7 6 5 4 5 6 2 1 4 5 1 0 1 2 3 0 3 7 4 0 6 7 3 2)))
Returns void
Converts the currently grabbed polygon primitive from raw vertex arrays to indexed arrays. This removes duplicate vertices from the polygon, making the pdata arrays shorter, which speeds up processing time.
Example
(define mynewshape (build-sphere 10 10)) (grab mynewshape) (poly-convert-to-indexed) (ungrab)
Returns primitiveid-number
Returns a copy of a primitive
Example
(define mynewshape (build-sphere 10 10)) (define myothernewshape (build-copy mynewshape))
Returns pfuncid-number
Makes a new primitive function. pfuncs range from general purpose to complex and specialised operations which you can run on primitives. All pfuncs share the same interface for controlling and setting them up - pfunc-set! All pfunc types and arguments are as follows: arithmetic For applying general arithmetic to any pdata array operator string : one of add sub mul div src string : pdata array name other string : pdata array name (optional) constant float : constant value (optional) dst string : pdata array name genskinweights Generates skinweights - adds float pdata called "s1" -> "sn" where n is the number of nodes in the skeleton - 1 skeleton-root primid-number : the root of the bindpose skeleton for skinning sharpness float : a control of how sharp the creasing will be when skinned skinweights->vertcols A utility for visualising skinweights for debugging. no arguments skinning Skins a primitive - deforms it to follow a skeleton's movements. Primitives we want to run this on have to contain extra pdata - copies of the starting vert positions called "pref" and the same for normals, if normals are being skinned, called "nref". skeleton-root primid-number : the root primitive of the animating skeleton bindpose-root primid-number : the root primitive of the bindpose skeleton skin-normals number : whether to skin the normals as well as the positions
Example
(define mypfunc (make-pfunc 'arithmetic))
Returns void
Sets arguments on a primitive function. See docs for make-pfunc for all the arguments.
Example
(define mypfunc (make-pfunc 'arithmetic)) (pfunc-set! mypfunc (list 'operator "add" 'src "p" 'const 0.4 'dst "p"))
Returns void
Runs a primitive function on the currently grabbed primitive.
Example
(define mypfunc (make-pfunc 'arithmetic))
Returns void
Returns a list of pdata values at each intersection point of the specified line. The line is in primitive local space, to check with a point in global space, you need to transform the point with the inverse of the primitive transform.
Example
(clear) (define s (with-state (build-torus 1 2 10 10))) (define l (with-state (hint-none) (hint-unlit) (hint-wire) (build-line 2))) (define (check a b) (with-primitive s (for-each (lambda (intersection) (with-state ; draw a sphere at the intersection point (translate (cdr (assoc "p" intersection))) (colour (vector 0 1 0)) (scale (vector 0.3 0.3 0.3)) (draw-sphere))) (geo/line-intersect a b)))) (every-frame (with-primitive l (pdata-set "p" 0 (vector 0 -5 0)) (pdata-set "p" 1 (vector (* 5 (sin (time))) 5 0)) (check (pdata-ref "p" 0) (pdata-ref "p" 1))))
Returns void
This call regenerates the primitives bounding box. As this call can be expensive, it's up to you when to call it - only if the pdata has changed and just before operations that use the bounding box (such as bb/bb-intersect) is the fastest policy.
Example
(define myprim (build-cube)) (with-primitive myprim (hint-box) (pdata-set! "p" 0 (vector -10 0 0)) (recalc-bb))
Returns void
Returns #t if the current primitive bounding box intersects with the supplied one, with an additional expanding threshold.
Example
(clear) (define a (with-state (build-sphere 10 10))) (define b (with-state (translate (vector 2 0 0)) (build-sphere 10 10))) (every-frame (begin (with-primitive b (translate (vector (* -0.1 (sin (time))) 0 0)) (recalc-bb)) (with-primitive a (when (bb/bb-intersect? b 0) (colour (rndvec))))))
Returns void
Returns #t if the current primitive bounding box intersects with point supplied, with an additional expanding threshold (so you can do check intersections with spheres). The point is in world space. You need to call (recalc-bb) before using this function, if the primitive has been moved or had it's pdata changed.
Example
(clear) (define a (with-state (build-sphere 10 10))) (define b (with-state (translate (vector 2 0 0)) (build-sphere 10 10))) (every-frame (begin (with-primitive b (translate (vector (* -0.1 (sin (time))) 0 0)) (recalc-bb)) (with-primitive a ; check the centre point and give the radius, this sphere ; check is faster than a bb/bb one (when (bb/point-intersect? (vtransform (vector 0 0 0) (with-primitive b (get-transform))) 1) (colour (rndvec))))))
Returns void
Gets a list of primitives parented to this one.
Example
; build a random heirachical structure (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)))))))) ; navigate the scene graph and print it out (define (print-heir children) (for-each (lambda (child) (with-primitive child (printf "id: ~a parent: ~a children: ~a~n" child (get-parent) (get-children)) (print-heir (get-children)))) children)) (clear) (build-heir 5) (print-heir (get-children))
Returns void
Gets the parent of this node. 1 is the root node.
Example
; build a random heirachical structure (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)))))))) ; navigate the scene graph and print it out (define (print-heir children) (for-each (lambda (child) (with-primitive child (printf "id: ~a parent: ~a children: ~a~n" child (get-parent) (get-children)) (print-heir (get-children)))) children)) (clear) (build-heir 5) (print-heir (get-children))
Returns bounding-box
Gets the bounding box this primitive in object space. A bounding box is returned as a list of two vectors, the minimum (closest to the origin) and maximum (furthest) corner.
Example
(with-primitive (build-sphere 10 10) (scale (vector 3 1 0.3)) (rotate (vector 30 25 45)) (apply-transform) (display (get-bb))(newline))