Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Mesh Editor:
- Original: https://www.roblox.com/catalog/3076076256/
- CHL's Fork: https://www.roblox.com/catalog/7612497706
- Note: this whole thing is a fork
- ]]
- local importableMeshEditorV2 = {}
- local util = {}
- local constants = {}
- function util:flipTable(t)
- assert(type(t) == 'table')
- local nT = {}
- for i, v in next, t do
- nT[v] = i
- end
- return nT
- end
- function util:characterSplitifyAndFlip(str)
- return util:flipTable(str:split(''))
- end
- function util:getCharactersInRange(a, b)
- local t = {}
- for byte = a:byte(), b:byte() do
- table.insert(t, string.char(byte))
- end
- return t
- end
- function util:getCharactersInRangeToString(a, b)
- local t = util:getCharactersInRange(a, b)
- return table.concat(t)
- end
- function util:PositionTriangle(triangle, position1, position2, position3)
- local magnitude1 = (position1 - position2).Magnitude
- local magnitude2 = (position2 - position3).Magnitude
- local magnitude3 = (position3 - position1).Magnitude
- if magnitude1 > magnitude2 and magnitude1 > magnitude3 then
- position1, position2, position3 = position2, position3, position1
- elseif magnitude2 > magnitude3 then
- position1, position2, position3 = position3, position1, position2
- end
- local vectorZ = position2 - position1
- local vectorY = position3 - position1
- local vectorX = vectorY:Cross(vectorZ)
- if vectorX.Magnitude == 0 then return end
- local width = vectorY:Dot(vectorZ)/vectorY.Magnitude
- local height = math.sqrt(vectorZ.Magnitude * vectorZ.Magnitude - width * width)
- local child = triangle:GetChildren()
- child[1].CFrame = CFrame.fromMatrix((position1 + position2)/2, vectorX, -vectorY, -vectorZ)
- child[1].Size = Vector3.new(child[1].Size.X, width, height)
- child[2].CFrame = CFrame.fromMatrix((position3 + position2)/2, -vectorX, vectorY, -vectorZ)
- child[2].Size = Vector3.new(child[2].Size.X, vectorY.Magnitude - width, height)
- end
- function util:CreateTriangle(parent, position1, position2, position3, thickness, properties)
- local instance = Instance.new("Folder")
- instance.Name = "Triangle"
- local part1 = Instance.new("WedgePart")
- local part2 = Instance.new("WedgePart")
- part1.BottomSurface = Enum.SurfaceType.Smooth
- part2.BottomSurface = Enum.SurfaceType.Smooth
- part1.Size = Vector3.new(thickness, thickness, thickness)
- part2.Size = part1.Size
- for option, value in pairs(properties) do
- part1[option] = value
- part2[option] = value
- end
- part1.Parent = instance
- part2.Parent = instance
- instance.Parent = parent
- util:PositionTriangle(instance, position1, position2, position3)
- end
- -- this function is the one you want, note, str is your export
- --[[
- Legend:
- O/M = Mandatory or optional
- .___________________________________________________________________________________________________________.
- |Order|O/M|Default|Type |Description |
- [-----------------------------------------------------------------------------------------------------------]
- |1 |M | |String |Export result from the plugin |
- |2 |O |.001 |Number |Size on the X axis of the triangles |
- |3 |O |{} |Table (Dictionary)|A dictionary where the index is the property and the value is the new |
- | | | | |value. Thus, for each iteration of the triangle, this set is applied. |
- '-----------------------------------------------------------------------------------------------------------'
- ]]
- function importableMeshEditorV2:Import(str, thickess, properties)
- thickess = thickess or .001
- properties = properties or {}
- assert(
- type(str) == 'string' and
- type(thickess) == 'number'and
- type(properties) == 'table'
- )
- local v = {}
- local f = {}
- local modelPosition = Vector3.new()
- local mode = 'NotBegan'
- local p = 1
- local function getStr(a, b)
- return str:sub(a or p, b or p)
- end
- local beginP, endP = 1, 1
- local args = {}
- -- compile string
- while true do
- local char = getStr()
- if mode=='NotBegan'then
- if getStr(p, p + 6) == '|BEGIN|'then
- mode = 'Vertex'
- p += 6
- end
- elseif mode == 'Vertex'then
- -- vertex
- if char == '|'then
- mode = 'Face'
- elseif constants.exportAllowedDigits[char]then
- beginP = p
- while char ~= ' ' do
- p += 1
- char = getStr()
- end
- endP = p - 1
- local StrNum = getStr(beginP, endP)
- table.insert(args, tonumber(StrNum))
- if #args >= 3 then
- table.insert(v, Vector3.new(unpack(args)))
- args = {}
- end
- else
- error('MODE: VERTEX | Expected " ", a valid digit character or "|", got ' .. char )
- end
- elseif mode == 'Face'then
- -- face
- local num = constants.newBaseStrToNum[char]
- if char == ''then
- break
- elseif char == '|' and getStr(p + 1, p + 1) == '|' then
- break
- elseif char == '|' or num then
- if char == '|' then
- num = 0
- repeat
- p += 1;
- char = getStr()
- local tempNum = constants.newBaseStrToNum[char]
- if tempNum then
- num += tempNum
- end
- until char == '|'
- end
- table.insert(args, num)
- if #args >= 3 then
- table.insert(f, args)
- args = {}
- end
- else
- error('MODE: FACE | Expected valid character, got "' .. char .. '"')
- end
- else
- error('undefined mode: ' .. mode)
- end
- p += 1
- end
- local t = {}
- if #f > 0 then
- local model = Instance.new("Model")
- model.Parent = workspace
- for i, data in ipairs(f) do
- local count = #data
- for j = 3, count do
- local v1, v2, v3 = f[i][1], f[i][j-1], f[i][j]
- local found = false
- if t[v1.." "..v2.." "..v3] then found = true
- elseif t[v1.." "..v3.." "..v2] then found = true
- elseif t[v2.." "..v3.." "..v1] then found = true
- elseif t[v2.." "..v1.." "..v3] then found = true
- elseif t[v3.." "..v1.." "..v2] then found = true
- elseif t[v3.." "..v2.." "..v1] then found = true
- end
- if not found then
- t[v1.." "..v2.." "..v3] = true
- util:CreateTriangle(
- model,
- v[v1],
- v[v2],
- v[v3],
- thickess,
- properties
- )
- end
- end
- end
- return model
- end
- end
- constants.digitString = util:getCharactersInRangeToString('0', '9')
- constants.alphabet = util:getCharactersInRangeToString('a', 'z')
- constants.exportAllowedDigits = util:characterSplitifyAndFlip('-.e' .. constants.digitString)
- constants.newBaseNumToStr = (constants.digitString .. constants.alphabet .. constants.alphabet:upper() .. ',./<>?;:\'"[]{}\\-=_+!@#$%^&*()`~'):split('')
- constants.newBaseStrToNum = util:flipTable(constants.newBaseNumToStr)
- local exportStr = [[Mesh Editor:
- Original: https://www.roblox.com/catalog/3076076256/
- CHL's Fork: https://www.roblox.com/catalog/7612497706
- Note: anything before "the |begin" is considered a comment and thus the script won't
- run over it.
- This is so that yall can put your credits here and stuff.
- |BEGIN|68.910163879395 -1.0974895954132 -55.423545837402 68.910171508789 .72284317016602 -55.423542022705 67.089828491211 -1.0974895954132 -55.423545837402 67.089828491211 .72284311056137 -58.576457977295 66.179672241211 .72284317016602 -57.000003814697 67.089828491211 -1.0974895954132 -58.576457977295 69.820327758789 -1.0974895954132 -57 69.820327758789 .72284311056137 -57.000003814697 66.179672241211 -1.0974895954132 -57 68.910171508789 .72284317016602 -58.576454162598 68.910163879395 -1.0974895954132 -58.576454162598 67.089828491211 .72284311056137 -55.423545837402 |012021345354016061716761842824796769845854a96a69a95a59b42b24395359b12b21||]]
- local ref = CFrame.new(68, 1.18, -57)
- local hexagonModel = importableMeshEditorV2:Import(exportStr, nil, {Anchored = true; CanCollide = false})
- local owner = getfenv().owner
- assert(typeof(owner) == 'Instance' and owner:IsA('Player'))
- local character = owner.Character
- for _, descendant in next, hexagonModel:GetDescendants() do
- assert(typeof(descendant) == 'Instance')
- if descendant:IsA('BasePart')then
- local weld = Instance.new('Weld')
- weld.C0 = ref:Inverse() * descendant.CFrame
- weld.Parent = descendant
- weld.Part1 = descendant
- weld.Part0 = owner.Character.HumanoidRootPart
- descendant.Anchored = false
- descendant.CanCollide = false
- descendant.Massless = true
- end
- end
- hexagonModel.Parent = owner.Character
Add Comment
Please, Sign In to add comment