Snippets
Created by
John Martini
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | /* scene setup */
clearlistener()
delete objects
target = convertToMesh (geosphere radius:30 wirecolor:[40,40,40] segs:5)
lite_pt = point size:2 wirecolor:yellow
lite = omnilight parent:lite_pt pos:[0,0,200]
lite_falloff = 30
pin = box length:4 height:4 width:4 widthsegs:1 heightsegs:1 lengthsegs:1
pin_min_height = 4
pin_max_height = 30
-- animate light distance variation
lite_offset = 20
lite.showtrajectory = true
with animate on for t = animationrange.start to animationrange.end by 10 do
(
at time t (lite.pos.z = 60 + random -lite_offset lite_offset)
)
-- animate rotate of lite's parent pt
with animate on for t = animationrange.start to animationrange.end by 10 do
(
at time t (rotate lite_pt (eulerAngles (random -360 360) (random -360 360) (random -360 360)))
)
fn GetVectorsAngle v1 v2 =
(
local d = dot (normalize v1) (normalize v2)
d = amax d -1.0
d = amin d 1.0
acos d
)
fn remap_value val from1 to1 from2 to2 =
(
return ((val - from1) / (to1 - from1) * (to2 - from2) + from2)
)
fn clamp minVal maxVal val =
(
if val < minVal then val = minVal
else if val > maxVal then val = maxVal
return val
)
fn place_pins pinObj surfaceObj influenceObj =
(
local vertCount = surfaceObj.numverts
for i = 1 to vertCount do
(
local vertFaces = meshop.getFacesUsingVert surfaceObj i
-- calculate normal
local tNormal = [0,0,0]
for f in vertFaces do tNormal += getFaceNormal surfaceObj f
local vec = normalize(tNormal / vertFaces.numberSet)
local vPos = getVert surfaceObj i
local thePin = copy pinObj
local theTM = matrixFromNormal vec
thePin.transform = theTM
thePin.pos = vPos
thePin.wirecolor = black
thePin.material = StandardMaterial()
with animate on for t = animationrange.start to animationrange.end by 1 do
(
at time t
(
-- user ang between pin and lite to influence height
local ang = GetVectorsAngle vec influenceObj.pos
local mult = remap_value ang 0 50 1.0 0.0
mult = clamp 0 1.0 mult
val = mult * pin_max_height
thePin.height = val + pin_min_height
col = black * (1 - mult) + red * mult
thePin.material.diffuse = col
)
)
)
)
place_pins pin target lite
-- fn setupDistanceColorController mat source target maxdistance:100 =
-- (
-- c = mat.diffuse.controller = point3_script()
-- c.AddConstant "maxdistance" maxdistance
-- c.AddObject "source" (NodeTransformMonitor node:source)
-- c.AddObject "target" (NodeTransformMonitor node:target)
-- str = "if isvalidnode source and isvalidnode target then\n"
-- str += "(\n"
-- str += " c = amin 1.0 ((distance source target)/maxdistance)\n"
-- str += " \n"
-- str += ")\n"
-- str += "else [0,0,0]"
-- print str
-- c.SetExpression str
-- c
-- )
-- (
-- delete objects
-- mat = standard name:"Distance Meter Material"
-- source = box name:"source" isselected:on material:mat
-- target = box name:"target" wirecolor:green
-- setupDistanceColorController mat source target
-- )
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.