From d636eaf1e3811eefaa26a86fac79af253f0d4403 Mon Sep 17 00:00:00 2001 From: Alhadis Date: Mon, 23 Nov 2015 17:12:18 +1100 Subject: [PATCH 1/7] Add example MAXScript files from Autodesk reference --- samples/MAXScript/macro-1.mcr | 29 ++++++++++++++ samples/MAXScript/macro-2.mcr | 53 +++++++++++++++++++++++++ samples/MAXScript/svg-renderer.ms | 64 +++++++++++++++++++++++++++++++ samples/MAXScript/volume-calc.ms | 22 +++++++++++ 4 files changed, 168 insertions(+) create mode 100644 samples/MAXScript/macro-1.mcr create mode 100644 samples/MAXScript/macro-2.mcr create mode 100644 samples/MAXScript/svg-renderer.ms create mode 100644 samples/MAXScript/volume-calc.ms diff --git a/samples/MAXScript/macro-1.mcr b/samples/MAXScript/macro-1.mcr new file mode 100644 index 00000000..fff41b51 --- /dev/null +++ b/samples/MAXScript/macro-1.mcr @@ -0,0 +1,29 @@ +-- Taken from an example from Autodesk's MAXScript reference: +-- http://help.autodesk.com/view/3DSMAX/2016/ENU/?guid=__files_GUID_84E24969_C175_4389_B9A6_3B2699B66785_htm + +macroscript MoveToSurface + category: "HowTo" +( + fn g_filter o = superclassof o == Geometryclass + fn find_intersection z_node node_to_z = ( + local testRay = ray node_to_z.pos [0,0,-1] + local nodeMaxZ = z_node.max.z + testRay.pos.z = nodeMaxZ + 0.0001 * abs nodeMaxZ + intersectRay z_node testRay + ) + + on isEnabled return selection.count > 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) +) From cdb5206def88932f43a33dfcb3c69603b9cb8515 Mon Sep 17 00:00:00 2001 From: Alhadis Date: Mon, 23 Nov 2015 17:14:35 +1100 Subject: [PATCH 2/7] Define MAXScript's language traits The colour chosen to represent the language is taken from Autodesk's own colouring scheme, which should easily be recognised by their userbase. --- lib/linguist/languages.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index b14b371e..45f618de 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1956,6 +1956,15 @@ M: tm_scope: source.lisp ace_mode: lisp +MAXScript: + type: programming + color: "#00aaaa" + extensions: + - .ms + - .mcr + tm_scope: source.maxscript + ace_mode: text + MTML: type: markup color: "#b7e1f4" From 37174e1d2ccf4faba7af397bbbc41742f8cbb4f8 Mon Sep 17 00:00:00 2001 From: Alhadis Date: Mon, 23 Nov 2015 17:34:43 +1100 Subject: [PATCH 3/7] Include MAXScript submodule in grammars directory --- .gitmodules | 3 +++ grammars.yml | 2 ++ vendor/grammars/language-maxscript | 1 + 3 files changed, 6 insertions(+) create mode 160000 vendor/grammars/language-maxscript diff --git a/.gitmodules b/.gitmodules index b164e010..da0effac 100644 --- a/.gitmodules +++ b/.gitmodules @@ -689,3 +689,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 7f9c3f77..348f677f 100644 --- a/grammars.yml +++ b/grammars.yml @@ -345,6 +345,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/vendor/grammars/language-maxscript b/vendor/grammars/language-maxscript new file mode 160000 index 00000000..5d75d784 --- /dev/null +++ b/vendor/grammars/language-maxscript @@ -0,0 +1 @@ +Subproject commit 5d75d784a89448df87998638686cbbc85d6658f2 From d2e739ba8c22c721845fb0b3dafaf92e6e5aaa10 Mon Sep 17 00:00:00 2001 From: Alhadis Date: Mon, 23 Nov 2015 19:02:50 +1100 Subject: [PATCH 4/7] Update MAXScript submodule to include license file See also: Alhadis/language-maxscript@96dbacf5b --- vendor/grammars/language-maxscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/grammars/language-maxscript b/vendor/grammars/language-maxscript index 5d75d784..96dbacf5 160000 --- a/vendor/grammars/language-maxscript +++ b/vendor/grammars/language-maxscript @@ -1 +1 @@ -Subproject commit 5d75d784a89448df87998638686cbbc85d6658f2 +Subproject commit 96dbacf5bfe16b6241b811e758e55ce853113b32 From f46e0536330e5b5bfd008169e2655d4f04654306 Mon Sep 17 00:00:00 2001 From: Alhadis Date: Mon, 23 Nov 2015 19:04:09 +1100 Subject: [PATCH 5/7] Darken MAXScript's language colour Rake's tests are failing because #0AA is too similar to the colour being used by another language (Dart: #00B4AB). This commit increases contrast enough to satisfy the build (with 00A6A6 being the closest shade allowed by the current colour threshold). See also: github/linguist@3c96f9e --- lib/linguist/languages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 45f618de..e41f3868 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -1958,7 +1958,7 @@ M: MAXScript: type: programming - color: "#00aaaa" + color: "#00a6a6" extensions: - .ms - .mcr From 73ef1bf156933b81409e7fd93cafe10b96654e67 Mon Sep 17 00:00:00 2001 From: Alhadis Date: Thu, 26 Nov 2015 05:56:37 +1100 Subject: [PATCH 6/7] Update MAXScript submodule to version v1.0 This is the first "real" version of the language package, which I pushed to Atom's packages repository earlier before. --- vendor/grammars/language-maxscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/grammars/language-maxscript b/vendor/grammars/language-maxscript index 96dbacf5..a465c9ca 160000 --- a/vendor/grammars/language-maxscript +++ b/vendor/grammars/language-maxscript @@ -1 +1 @@ -Subproject commit 96dbacf5bfe16b6241b811e758e55ce853113b32 +Subproject commit a465c9ca4adf71b8524021acb3cbe447db19753b From 06c049b8c0533add03d2412616bef316da770d8e Mon Sep 17 00:00:00 2001 From: Alhadis Date: Sat, 28 Nov 2015 04:40:29 +1100 Subject: [PATCH 7/7] Change ".ms" heuristic to accommodate MAXScript Linguist currently uses the presence of "move" commands to differentiate a GAS file from Groff. This is problematic with MAXScript, with includes a built-in function of that name. Furthermore, because of the language's exhaustive vocabulary, case insensitive nature and flexible syntax, it's difficult to impose rigid criteria on classifying it. This commit modifies the heuristic to assume the following flow: 1. If a line contains ".include" or ".global"/".globl" which doesn't follow a non-whitespace character, assume GAS. 2. Otherwise, if the line starts with a command like ".LG7E0" with a possible string of whitespace before it, assume it's also GAS. UNLESS either of the following conditions are true: 2a. The token is enclosed by a string or /* multiline comment */ 2b. The previous line ends with a backslash to denote a statement broken between lines, with possible whitespace and/or comment sequences between the backslash and the actual newline. 3. If neither of the above are met, assume the file is MAXScript. This approach may appear overly-inclusive, but given real-world usage of MAXScript includes writing brief files with few distinguishing keywords, it's reasonable to permit this leniency. --- lib/linguist/heuristics.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 /(?