Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _G.Imported_Model=nil
- repeat wait() until _G.Imported_Model
- local loadspeed=_G.Imported_Model.loadspeed
- local Scale=_G.Imported_Model.Scale
- local wrongAngleFixer=_G.Imported_Model.WrongAngleFixer
- local loadColors=_G.Imported_Model.loadColors
- local Offset=_G.Imported_Model.Offset
- local objFile=_G.Imported_Model.Mesh
- local mtlFile=_G.Imported_Model.Materials
- local shouldrenderVertexes=false
- local shouldrenderWireFrame=false
- local shouldrenderFaces=true
- local Vertexes
- local Materials
- local Faces
- local PolyDraw={}
- function parseMaterials()
- Materials={}
- local FilePos=0
- local EndFile=false
- while not EndFile do
- EndFile=true
- local MaterialPos=string.find(mtlFile,"newmtl",FilePos)
- if MaterialPos then
- local MaterialNameStartPos=string.find(mtlFile,"%s",MaterialPos+1)
- local MaterialNameEndPos=string.find(mtlFile,"%s",MaterialNameStartPos+1)
- local MaterialName=string.sub(mtlFile,MaterialNameStartPos+1,MaterialNameEndPos-1)
- local ColorPos=string.find(mtlFile,"Kd",MaterialNameEndPos)
- local ColorStartPos=string.find(mtlFile,"%s",ColorPos)
- local ColorEndPos=string.find(mtlFile,"Ks",ColorStartPos)
- local Color=string.sub(mtlFile,ColorStartPos+1,ColorEndPos-2)
- local Color1EndPos=string.find(Color," ")
- local Color1=string.sub(Color,0,Color1EndPos-1)
- local Color2EndPos= string.find(Color," ",Color1EndPos+1)
- local Color2=string.sub(Color,Color1EndPos+1,Color2EndPos-1)
- local Color_3=string.sub(Color,Color2EndPos+1)
- local EndColor=Color3.new(tonumber(Color1),tonumber(Color2),tonumber(Color_3))
- Materials[MaterialName]=EndColor
- FilePos=ColorEndPos
- else
- EndFile=true
- break
- end
- end
- end
- function parseVertexes()
- Vertexes={}
- local FilePos=0
- local EndFile=false
- while not EndFile do
- local VertexPos=string.find(objFile,"v ",FilePos)
- if VertexPos then
- local StartPos=string.find(objFile,"%S",VertexPos+1)
- local FirstCordPos=string.find(objFile," ",StartPos)
- local FirstCord=string.sub(objFile,VertexPos+1,FirstCordPos-1)
- local SecondCordPos=string.find(objFile," ",FirstCordPos+1)
- local SecondCord=string.sub(objFile,FirstCordPos+1,SecondCordPos-1)
- local ThirdCordPos=string.find(objFile,"%s",SecondCordPos+1)
- local ThirdCord=string.sub(objFile,SecondCordPos+1,ThirdCordPos-1)
- local FilePos=ThirdCordPos
- local Vertex=Vector3.new(tonumber(FirstCord)*Scale,tonumber(SecondCord)*Scale,tonumber(ThirdCord)*Scale)+Offset*Scale
- if wrongAngleFixer then
- Vertex=Vector3.new(tonumber(FirstCord)*Scale,tonumber(ThirdCord)*Scale,tonumber(SecondCord)*Scale)+Offset*Scale
- end
- table.insert(Vertexes,Vertex)
- else
- print("Number of Vertices: "..#Vertexes)
- EndFile=true
- end
- end
- end
- local UseColor
- function parseFaces()
- Faces={}
- local FilePos=0
- local EndFile=false
- while not EndFile do
- local FaceStringPos=string.find(objFile,"f",FilePos)
- if loadColors then
- local UseMaterial=string.find(objFile,"usemtl",FilePos)
- if UseMaterial and UseMaterial<FaceStringPos then
- local MaterialNameStartPos=string.find(objFile,"%s",UseMaterial)
- local MaterialNameEndPos=string.find(objFile,"%s",MaterialNameStartPos+1)
- local MaterialName=string.sub(objFile,MaterialNameStartPos+1,MaterialNameEndPos-1)
- UseColor=Materials[MaterialName]
- end
- end
- if FaceStringPos then
- local Face2StartPos=string.find(objFile," ",FaceStringPos+2)
- local Face3StartPos=string.find(objFile," ",Face2StartPos+1)
- local FacePos1String=objFile:match("%d+",FaceStringPos)
- local FacePos2String=objFile:match("%d+",Face2StartPos)
- local FacePos3String=objFile:match("%d+",Face3StartPos)
- local Face1Pos=Vertexes[tonumber(FacePos1String)]
- local Face2Pos=Vertexes[tonumber(FacePos2String)]
- local Face3Pos=Vertexes[tonumber(FacePos3String)]
- table.insert(Faces,{Face1Pos,Face2Pos,Face3Pos,UseColor})
- FilePos=Face3StartPos+1
- else
- print("Number of Faces: "..#Faces)
- EndFile=true
- end
- end
- end
- function renderVertexes()
- local speedLoad=0
- for k,v in pairs(Vertexes) do
- wait()
- if speedLoad>loadspeed then
- wait()
- speedLoad=0
- end
- speedLoad=speedLoad+1
- local VertexPart=Instance.new("Part",workspace)
- VertexPart.Size=Vector3.new(1,1,1)
- VertexPart.CFrame=CFrame.new(v.X,v.Y,v.Z)
- VertexPart.Name=k
- VertexPart.Anchored=true
- VertexPart.BrickColor=BrickColor.new("Really red")
- end
- end
- function renderVertexesOfFace(Face)
- for i,v in pairs(Face) do
- wait()
- local VertexPart=Instance.new("Part",workspace)
- VertexPart.Size=Vector3.new(1,1,1)
- VertexPart.CFrame=CFrame.new(v.X,v.Y,v.Z)
- VertexPart.Anchored=true
- VertexPart.BrickColor=BrickColor.new("Really red")
- end
- end
- local FacesRendered
- function renderFace(Face)
- FacesRendered=FacesRendered+1
- PolyDraw.Tri.new(Face[1],Face[2],Face[3],Face[4])
- end
- function createFaceInfoHint()
- coroutine.wrap(function()
- local Hint=Instance.new("Hint",workspace)
- local StartTime=tick()
- while wait() do
- Hint.Text="" --Damn you OCD
- .."Faces Rendered: "
- ..FacesRendered
- .." Percent done: "
- ..math.floor((FacesRendered/#Faces*10000)/100)
- .."%"
- .." Approximate time left: "..math.floor((((tick()-StartTime)/FacesRendered)*(#Faces-FacesRendered))*10)/10
- .." seconds"
- end
- end)()
- end
- function renderFaces()
- local speedLoad=0
- FacesRendered=0
- createFaceInfoHint()
- for i,v in pairs(Faces) do
- wait()
- if speedLoad>loadspeed then
- wait()
- speedLoad=0
- end
- speedLoad=speedLoad+1
- renderFace(v)
- end
- print("Render finished")
- end
- function renderWireFrame()
- local speedLoad=0
- for i,v in pairs(Faces) do
- wait()
- if speedLoad>loadspeed then
- wait()
- speedLoad=0
- end
- speedLoad=speedLoad+1
- renderWiresForFace(v)
- end
- end
- local Wire=Instance.new("Part")
- Wire.Anchored=true
- Wire.FormFactor=Enum.FormFactor.Custom
- Wire.BrickColor=BrickColor.new("New Yeller")
- function renderWiresForFace(Face)
- renderWire(Face[1],Face[2])
- renderWire(Face[2],Face[3])
- renderWire(Face[3],Face[1])
- end
- function renderWire(Pos1,Pos2)
- local Distance=(Pos1-Pos2).magnitude
- local wire=Wire:Clone()
- wire.Parent=workspace
- wire.Size=Vector3.new(.2,.2,Distance)
- wire.CFrame=CFrame.new(Pos1,Pos2)*CFrame.new(0,0,-Distance/2)
- end
- local Mesh=Instance.new("Model",workspace)
- Mesh.Name="Mesh"
- PolyDraw.BrickColor=BrickColor.new(21)
- PolyDraw.CanCollide=false
- local function setupPart(Part)
- Part.Anchored=true
- Part.FormFactor="Custom"
- Part.CanCollide=PolyDraw.CanCollide
- Part.BrickColor=PolyDraw.BrickColor
- Part.TopSurface="Smooth"
- Part.BottomSurface="Smooth"
- local mesh=Instance.new("SpecialMesh",Part)
- mesh.MeshType="Wedge"
- mesh.Scale=Vector3.new(0,1,1)
- end
- local Point={}
- PolyDraw.Point=Point
- function Point.new(Parent,At)
- local This={}
- local mPart=Instance.new("Part")
- setupPart(mPart)
- mPart.Size=Vector3.new(1,1,1)
- mPart.Parent=Parent
- function This:Set(At)
- mPart.CFrame=CFrame.new(At)
- end
- function This:Destroy()
- mPart:Destroy()
- end
- function This:SetProperty(Prop,Value)
- mPart[Prop]=Value
- end
- This:Set(At)
- return This
- end
- local Edge={}
- PolyDraw.Edge=Edge
- function Edge.new(Parent,A,B)
- local This={}
- local mPart=Instance.new("Part")
- setupPart(mPart)
- mPart.Parent=Parent
- function This:Set(A,B)
- local Sep=(A-B).magnitude
- mPart.Size=Vector3.new(.5,.5,Sep)
- mPart.CFrame=CFrame.new(A,B)*CFrame.new(0,0,-.5*Sep)
- end
- function This:Destroy()
- mPart:Destroy()
- end
- function This:SetProperty(Prop,Value)
- mPart[Prop]=Value
- end
- This:Set(A,B)
- return This
- end
- local Tri={}
- PolyDraw.Tri=Tri
- local function CFrameFromTopBack(At,Top,Back)
- local Right=Top:Cross(Back)
- return CFrame.new(At.X,At.Y,At.Z,Right.X,Top.X,Back.X,Right.Y,Top.Y,Back.Y,Right.Z,Top.Z,Back.Z)
- end
- function Tri.new(A,B,C,Color)
- local This={}
- local mPart1=Instance.new("WedgePart")
- setupPart(mPart1)
- local mPart2=Instance.new("WedgePart")
- setupPart(mPart2)
- function This:Set(A,B,C)
- local AB,BC,CA=B-A,C-B,A-C
- local ABM,BCM,CAM=AB.magnitude,BC.magnitude,CA.magnitude
- local Edge1=math.abs(.5+CA:Dot(AB)/(ABM*ABM))
- local Edge2=math.abs(.5+AB:Dot(BC)/(BCM*BCM))
- local Edge3=math.abs(.5+BC:Dot(CA)/(CAM*CAM))
- if Edge1<Edge2 then
- if Edge1>Edge3 then
- A,B,C=C,A,B
- AB,BC,CA=CA,AB,BC
- ABM=CAM
- end
- else
- if Edge2<Edge3 then
- A,B,C=B,C,A
- AB,BC,CA=BC,CA,AB
- ABM=BCM
- else
- A,B,C=C,A,B
- AB,BC,CA=CA,AB,BC
- ABM=CAM
- end
- end
- local Len1=-CA:Dot(AB)/ABM
- local Len2=ABM-Len1
- local Width=(CA+AB.unit*Len1).magnitude
- local maincf=CFrameFromTopBack(A,AB:Cross(BC).unit,-AB.unit)
- mPart1.Parent=Mesh
- mPart1.Size=Vector3.new(.2,.2,.2)
- mPart1.Mesh.Scale=Vector3.new(0.00001,Width,Len1)/.2
- mPart1.CFrame=maincf*CFrame.Angles(math.pi,0,math.pi/2)*CFrame.new(0,Width/2,Len1/2)
- mPart1.Color=Color or Color3.new(1,1,1)
- mPart2.Parent=Mesh
- mPart2.Size=Vector3.new(.2,.2,.2)
- mPart2.Mesh.Scale=Vector3.new(0.00001,Width,Len2)/.2
- mPart2.CFrame=maincf*CFrame.Angles(math.pi,math.pi,-math.pi/2)*CFrame.new(0,Width/2,-Len1-Len2/2)
- mPart2.Color=Color or Color3.new(1,1,1)
- end
- function This:SetProperty(Prop,Value)
- mPart1[Prop]=Value
- mPart2[Prop]=Value
- end
- This:Set(A,B,C)
- function This:Destroy()
- mPart1:Destroy()
- mPart2:Destroy()
- end
- return This
- end
- if loadColors then
- parseMaterials()
- end
- parseVertexes()
- parseFaces()
- if shouldrenderVertexes then
- renderVertexes()
- end
- if shouldrenderWireFrame then
- renderWireFrame()
- end
- if shouldrenderFaces then
- renderFaces()
- end
Advertisement
Add Comment
Please, Sign In to add comment