diff --git a/.gitmodules b/.gitmodules index ee9600c0..f12d73b7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -692,3 +692,6 @@ [submodule "vendor/grammars/FreeMarker.tmbundle"] path = vendor/grammars/FreeMarker.tmbundle url = https://github.com/freemarker/FreeMarker.tmbundle +[submodule "vendor/grammars/language-maxscript"] + path = vendor/grammars/language-maxscript + url = https://github.com/Alhadis/language-maxscript diff --git a/grammars.yml b/grammars.yml index d812f05b..9a818865 100644 --- a/grammars.yml +++ b/grammars.yml @@ -347,6 +347,8 @@ vendor/grammars/language-javascript: vendor/grammars/language-jsoniq/: - source.jq - source.xq +vendor/grammars/language-maxscript: +- source.maxscript vendor/grammars/language-ncl: - source.ncl vendor/grammars/language-python: diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 0a1ab912..7c1c7db1 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -238,8 +238,10 @@ module Linguist disambiguate ".ms" do |data| if /^[.'][a-z][a-z](\s|$)/i.match(data) Language["Groff"] - elsif /((^|\s)move?[. ])|\.(include|globa?l)\s/.match(data) + elsif /(? 0 + + on Execute do ( + target_mesh = pickObject message:"Pick Target Surface:" filter:g_filter + + if isValidNode target_mesh then ( + undo "MoveToSurface" on ( + for i in selection do ( + int_point = find_intersection target_mesh i + if int_point != undefined then i.pos = int_point.pos + )--end i loop + )--end undo + )--end if + )--end execute +)--end script diff --git a/samples/MAXScript/macro-2.mcr b/samples/MAXScript/macro-2.mcr new file mode 100644 index 00000000..e0a897cf --- /dev/null +++ b/samples/MAXScript/macro-2.mcr @@ -0,0 +1,53 @@ +-- Taken from an example from Autodesk's MAXScript reference: +-- http://help.autodesk.com/view/3DSMAX/2016/ENU/?guid=__files_GUID_0876DF46_FAA3_4131_838D_5739A67FF2C1_htm + +macroscript FreeSpline category:"HowTo" tooltip:"FreeSpline" ( +local old_pos +local new_spline +local second_knot_set + +fn get_mouse_pos pen_pos old_pen_pos = ( + if old_pos == undefined then old_pos = old_pen_pos + if distance pen_pos old_pos > 10 then + ( + if second_knot_set then + addKnot new_spline 1 #smooth #curve pen_pos + else + ( + setKnotPoint new_spline 1 2 pen_pos + second_knot_set = true + ) + old_pos = pen_pos + updateShape new_spline + )-- end if +)-- end fn + +fn draw_new_line old_pen_pos = ( + pickPoint mouseMoveCallback:#(get_mouse_pos,old_pen_pos) +) + +undo"Free Spline"on( + new_spline = splineShape () + old_pen_pos = pickPoint () + + if old_pen_pos == #RightClick then + delete new_spline + else + ( + select new_spline + new_spline.pos = old_pen_pos + addNewSpline new_spline + addKnot new_spline 1 #smooth #curve old_pen_pos + addKnot new_spline 1 #smooth #curve old_pen_pos + second_knot_set = false + draw_new_line old_pen_pos + q = querybox "Close Spline?" title:"Free Spline" + if q then + ( + close new_spline 1 + updateshape new_spline + ) + select new_spline + )--end else +)--end undo +)--end script diff --git a/samples/MAXScript/svg-renderer.ms b/samples/MAXScript/svg-renderer.ms new file mode 100644 index 00000000..872334fe --- /dev/null +++ b/samples/MAXScript/svg-renderer.ms @@ -0,0 +1,64 @@ +-- Taken from a 3-part tutorial from Autodesk's MAXScript reference +-- Source: http://help.autodesk.com/view/3DSMAX/2016/ENU/?guid=__files_GUID_6B5EDC11_A154_4AA7_A972_A11AC36949E9_htm + +fn ColourToHex col = ( + local theComponents = #(bit.intAsHex col.r, bit.intAsHex col.g, bit.intAsHex col.b) + local theValue = "#" + for i in theComponents do + theValue += (if i.count == 1 then "0" else "") + i + theValue +) + +local st = timestamp() +local theFileName = (getDir #userscripts + "\\PolygonRendering3.svg") +local theSVGfile = createFile theFileName +format "\n" to:theSVGfile + +local theViewTM = viewport.getTM() +theViewTM.row4 = [0,0,0] + +local theViewTM2 = viewport.getTM() +local theViewSize = getViewSize() +local theViewScale = getViewSize() +theViewScale.x /= 1024.0 +theViewScale.y /= 1024.0 + +local theStrokeThickness = 3 + +gw.setTransform (matrix3 1) +for o in Geometry where not o.isHiddenInVpt and classof o != TargetObject do ( + local theStrokeColour = white + local theFillColour = o.wirecolor + + local theMesh = snapshotAsMesh o + for f = 1 to theMesh.numfaces do ( + local theNormal = normalize (getFaceNormal theMesh f) + + if (theNormal*theViewTM).z > 0 do + ( + local theFace = getFace theMesh f + local v1 = gw.transPoint (getVert theMesh theFace.x) + local v2 = gw.transPoint (getVert theMesh theFace.y) + local v3 = gw.transPoint (getVert theMesh theFace.z) + + v1.x /= theViewScale.x + v1.y /= theViewScale.y + v2.x /= theViewScale.x + v2.y /= theViewScale.y + v3.x /= theViewScale.x + v3.y /= theViewScale.y + + format "\t\n" (ColourToHex theStrokeColour) (ColourToHex theFillColour) theStrokeThickness to:theSVGfile + )--end if normal positive + )--end f loop +)--end o loop + +format "\n" to:theSVGfile +close theSVGfile +local theSVGMap = VectorMap vectorFile:theFileName alphasource:0 +local theBitmap = bitmap theViewSize.x theViewSize.y +renderMap theSVGMap into:theBitmap filter:true +display theBitmap +format "Render Time: % sec.\n" ((timestamp()-st)/1000.0) diff --git a/samples/MAXScript/volume-calc.ms b/samples/MAXScript/volume-calc.ms new file mode 100644 index 00000000..5e84e341 --- /dev/null +++ b/samples/MAXScript/volume-calc.ms @@ -0,0 +1,22 @@ +fn CalculateVolumeAndCentreOfMass obj = +( + local Volume= 0.0 + local Centre= [0.0, 0.0, 0.0] + local theMesh = snapshotasmesh obj + local numFaces = theMesh.numfaces + for i = 1 to numFaces do + ( + local Face= getFace theMesh i + local vert2 = getVert theMesh Face.z + local vert1 = getVert theMesh Face.y + local vert0 = getVert theMesh Face.x + local dV = Dot (Cross (vert1 - vert0) (vert2 - vert0)) vert0 + Volume+= dV + Centre+= (vert0 + vert1 + vert2) * dV + ) + delete theMesh + Volume /= 6 + Centre /= 24 + Centre /= Volume + #(Volume,Centre) +) diff --git a/vendor/grammars/language-maxscript b/vendor/grammars/language-maxscript new file mode 160000 index 00000000..a465c9ca --- /dev/null +++ b/vendor/grammars/language-maxscript @@ -0,0 +1 @@ +Subproject commit a465c9ca4adf71b8524021acb3cbe447db19753b