Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --defined by a tri-mesh and simpleObject plugin is similar to all the Standard and Extended primitives
- -- numTimesBuilt = 0 --I'm interested in how many times this is happening
- -- numTimesRot = 0
- plugin simpleObject helperSample --the 'scripted simpleObject' is it's own type of plugin, simpleObject is the superclass, it creates an object that whose superclass is GeometryClass
- name:"HelperSample"
- category:"HowTo"
- classID:#(0x453e608, 0x40dda998)
- --usePBValidity:on --this is for when you are extending an existing class, default is false and does not include the validity of the scripted controllers - whatever that means
- (
- parameters main rollout:params --can add rollout here
- (
- p1 type:#maxObject
- p2 type:#maxObject
- p3 type:#maxObject
- stairWidth type:#worldUnits ui:spnStairWidth default:5.0 --the height param, it won't be visible until you run the rollout params below
- )
- rollout params "Parameters"
- (
- spinner spnStairWidth "Stair Width" range:[-100.0,100.0,5.0] type:#worldunits
- --
- on spnStairWidth changed theVal do
- (
- p2UnitVector = p2.node.transform[1]
- rotatedMatrix = rotateZMatrix 90
- rotatedVector = p2UnitVector * rotatedMatrix
- p3.node.pos = p2.node.pos + (rotatedVector * this.stairWidth)
- )
- )
- fn isValid= isValidObj p1 and isValidObj p2 and isValidObj p3 --make sure the correct objects exist
- fn rot=
- (
- --numTimesRot += 1
- --p2 orientation
- --local owner = refs.dependentNodes this firstOnly:on --this is the object being created.
- --owner.pivot = p1.node.pos --ERROR this creates a recursive operation!
- p2Vec = [p1.node.pos.x, p1.node.pos.y, 0] - [p2.node.pos.x, p2.node.pos.y, 0] --the vector is just the xy to the xy, the z will be equal. minus points away, plus points towards
- p2Angle = atan2 p2Vec.y p2Vec.x
- p2Matrix = rotate (matrix3 1) (eulerangles 0.0 0.0 p2Angle as quat)
- scale p2Matrix p2.node.scale
- translate p2Matrix p2.node.pos
- p2.node.transform = p2Matrix
- --p3 orientation
- p3Vec = [p2.node.pos.x, p2.node.pos.y, 0] - [p3.node.pos.x, p3.node.pos.y, 0] --the vector is just the xy to the xy, the z will be equal. minus points away, plus points towards
- p3Angle = atan2 p3Vec.y p3Vec.x
- p3Matrix = rotate (matrix3 1) (eulerangles 0.0 0.0 p3Angle as quat)
- scale p3Matrix p3.node.scale
- translate p3Matrix p3.node.pos
- p3.node.transform = p3Matrix
- )
- on load do when transform #(p1, p2, p3) changes id:#forceUpdate do notifyDependents this
- on buildMesh do if isValid() do --I love quickly stacking up a few conditionals in this way.
- (
- /*
- when p1 moves the build is not taking it's position into account...
- */
- --numTimesBuilt += 1
- --print "BUILD MESH!!"
- local owner = refs.dependentNodes this firstOnly:on --this is the object being created.
- --owner.pivot = [0,0,0]--p1.node.pos --ERROR this creates a recursive operation!
- /*
- try using p1.node.posInParent, there is a p3.node.pos * inverse owner.transform being used too...that's interesting.
- */
- lDir = [p2.node.pos.x, p2.node.pos.y, 0] - [p1.node.pos.x, p1.node.pos.y, 0] --length direction
- lUVec = normalize lDir
- wDir = [p3.node.pos.x, p3.node.pos.y, 0] - [p2.node.pos.x, p2.node.pos.y, 0]--p3.pos - p2.pos --width direction in x and y only
- wUVec = normalize wDir
- totalStairLength = distance [p1.node.pos.x,p1.node.pos.y] [p2.node.pos.x,p2.node.pos.y]
- amountOfStairs = (totalStairLength / 1) as integer
- stepLength = 1--totalStairLength / amountOfStairs
- totalStairDrop = p2.node.pos.z - p1.node.pos.z
- dropDist = totalStairDrop / amountOfStairs
- stepWidth = distance [p2.node.pos.x,p2.node.pos.y] [p3.node.pos.x,p3.node.pos.y]
- fn stairVec _pnt3=
- (
- --why do I have to set these variables again as local?
- local lDir = [p2.node.pos.x, p2.node.pos.y, 0] - [p1.node.pos.x, p1.node.pos.y, 0] --length direction
- local lUVec = normalize lDir
- local wDir = [p3.node.pos.x, p3.node.pos.y, 0] - [p2.node.pos.x, p2.node.pos.y, 0] --width direction
- local wUVec = normalize wDir
- --
- --width,length,drop
- local x = wUVec * _pnt3[1] --width
- local y = lUVec * _pnt3[2]--length
- local z = _pnt3[3] --drop
- return (x + y + [0,0,z])
- )
- vert_array =#()
- face_array =#()
- vert_count = 0
- vertPos = undefined
- for i = 1 to amountOfStairs do
- (
- if i == 1 then
- (
- vertPos = [0,0,0]--p1.node.pos
- --6 verts, the first 2 verts are created uniquely, after that the final 2 are shared for the next step, so there'll only be 4 verts.
- append vert_array vertPos
- append vert_array (vertPos + (stairVec [stepWidth,0,0]))
- append vert_array (vertPos + (stairVec [stepWidth,stepLength,0]))
- append vert_array (vertPos + (stairVec [0,stepLength,0]))
- append vert_array (vertPos + (stairVec [stepWidth,stepLength,dropDist]))
- append vert_array (vertPos + (stairVec [0,stepLength,dropDist]))
- --4 faces
- append face_array [vert_count+1, vert_count+2, vert_count+3]
- append face_array [vert_count+1, vert_count+3, vert_count+4]
- append face_array [vert_count+4, vert_count+3, vert_count+5]
- append face_array [vert_count+4, vert_count+5, vert_count+6]
- vert_count += 6
- ) else
- (
- --4 verts
- append vert_array (vertPos + (stairVec [stepWidth,stepLength,0]))
- append vert_array (vertPos + (stairVec [0,stepLength,0]))
- append vert_array (vertPos + (stairVec [stepWidth,stepLength,dropDist]))
- append vert_array (vertPos + (stairVec [0,stepLength,dropDist]))
- --4 faces
- append face_array [vert_count,vert_count-1,vert_count+1]
- append face_array [vert_count,vert_count+1,vert_count+2]
- append face_array [vert_count+2,vert_count+3,vert_count+4]
- append face_array [vert_count+2,vert_count+1,vert_count+3]
- vert_count += 4
- )
- vertPos = vert_array[vert_array.count]
- )
- setMesh mesh verts:vert_array faces:face_array smGroup:0
- for i = 1 to (getNumFaces mesh) do
- (
- setFaceSmoothGroup mesh i 0
- )
- )--end buildMesh
- tool create numPoints:2 -- the 3 points are: first click, drag and unclick I believe?...
- (
- local p3Pos
- on mousePoint click do if click == 1 do --didn't need to split this across lines or parenthesis.
- (
- --print "click 1 - first point placed!"
- p3Pos = undefined --at the first click, p3's position is reset here and the scope is set for use.
- nodeTM.translation = gridPoint --set the simple object (node) to the first position clicked.
- local owner = refs.dependentNodes this firstOnly:on --this is the object being created.
- --print ("click owner: "+owner as string)
- --print (refs.dependentNodes this) --returns: $helperSample:helperSample001 @ [0.000000,0.000000,0.000000]
- print (refs.dependentNodes this firstOnly:on) --returns: $helperSample:helperSample002 @ [0.000000,0.000000,0.000000]
- --the following are created
- p1 = NodeTransformMonitor node:(Point prefix:"p1-" parent:owner showLinks:on size:10 cross:off box:on constantscreensize:on wirecolor:yellow) --1st pnt
- p2 = NodeTransformMonitor node:(Point prefix:"p2-" parent:p1.node showLinks:on size:10 cross:off box:on constantscreensize:on wirecolor:yellow) --2nd pnt, a child of the first
- p3 = NodeTransformMonitor node:(Point prefix:"p3-" parent:p2.node showLinks:on size:10 cross:off box:on constantscreensize:on wirecolor:yellow) --3rd point
- p1.node.pos = owner.position
- --NodeTransformMonitor is an object that holds a reference to a node. I think it will stop recursion in the call back.
- when transform #(p1, p2, p3) changes id:#forceUpdate do notifyDependents this --executes the forceUpdate on this object, it is the buildMesh operation
- when transform #(p2, p3) changes id:#stairsPointDirection do rot() --orients the p2 and p3 correctly
- )
- on mouseMove click do if click == 2 and lbutton do
- (
- --2nd action, 1st unclick, worldPoint is the unclick point
- --print "drag 1"
- p2.node.pos = worldPoint
- p2UnitVector = p2.node.transform[1]
- rotatedMatrix = rotateZMatrix 90
- rotatedVector = p2UnitVector * rotatedMatrix
- p3.node.pos = p2.node.pos + (rotatedVector * this.stairWidth)
- )
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement