Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IncludeFile "RotateImage.pb"
- UsePNGImageEncoder()
- #WhiteColor = -1
- #RedColor = -16776961
- #Width = 800
- #Height = 800
- Interface objectMethods
- readObject()
- drawObjIntoFile(fName.s)
- EndInterface
- Structure vertice
- x.f : y.f : z.f
- EndStructure
- Structure face
- v1.l : v2.l : v3.l
- EndStructure
- Structure objectModel
- *vTable
- pathToObjFile.s
- objFile.l
- imgFile.l
- Array vertices.vertice(0)
- Array faces.face(0)
- EndStructure
- Procedure InizializeObject(name.s)
- Protected *this.objectModel = AllocateMemory(SizeOf(objectModel))
- InitializeStructure(*this,objectModel)
- *this\pathToObjFile = name
- *this\imgFile = CreateImage(#PB_Any, #Width, #Height)
- *this\vTable = ?objectMethods_vTable
- ProcedureReturn *this
- EndProcedure
- Procedure VeloLine(x0.l, y0.l, x1.l, y1.l, color.l)
- steep.a = 0
- y10.a = 0
- If (Abs(x0-x1) < Abs(y0-y1))
- Swap x0, y0
- Swap x1, y1
- steep = 1
- EndIf
- If (x0 > x1)
- Swap x0, x1
- Swap y0, y1
- EndIf
- dx.l = x1 - x0
- dy.l = y1 - y0
- derror2.l = Abs(dy)*2
- error2.l = 0
- y.l = y0
- If (y1 > y0)
- y10 = 1
- EndIf
- For x = x0 To x1
- If (steep = 1)
- If (y < #Width And x < #Height)
- Plot(y, x, color)
- EndIf
- Else
- If (x < #Width And y < #Height)
- Plot(x, y, color)
- EndIf
- EndIf
- error2 = error2 + derror2
- If (error2 > dx)
- If y10 = 1
- y = y + 1
- Else
- y = y - 1
- EndIf
- error2 = error2 - dx*2;
- EndIf
- Next
- EndProcedure
- Procedure objectMethods_ReadObject(*this.objectModel)
- *this\objFile = ReadFile(#PB_Any, *this\pathToObjFile)
- If *this\objFile
- temp.s = ""
- v_index.l = 0
- v_faces.l = 0
- While Not Eof(*this\objFile)
- temp = ReadString(*this\objFile)
- Select StringField(temp, 1, " ")
- Case "v"
- *this\vertices(v_index)\x = ValF(StringField(temp, 2, " "))
- *this\vertices(v_index)\y = ValF(StringField(temp, 3, " "))
- *this\vertices(v_index)\z = ValF(StringField(temp, 4, " "))
- v_index = v_index + 1
- ReDim *this\vertices(v_index)
- Case "f"
- *this\faces(v_faces)\v1 = Val(StringField(StringField(temp, 2, " "), 1, "/"))
- *this\faces(v_faces)\v2 = Val(StringField(StringField(temp, 3, " "), 1, "/"))
- *this\faces(v_faces)\v3 = Val(StringField(StringField(temp, 4, " "), 1, "/"))
- v_faces = v_faces + 1
- ReDim *this\faces(v_faces)
- EndSelect
- Wend
- CloseFile(*this\objFile)
- EndIf
- EndProcedure
- Procedure objectMethods_DrawObjIntoFile(*this.objectModel, name.s)
- count_vertices = ArraySize(*this\vertices()) - 1
- count_faces = ArraySize(*this\faces()) - 1
- StartDrawing(ImageOutput(*this\imgFile))
- For i = 0 To count_faces
- current_face.face = *this\faces(i)
- For j = 0 To 2
- Select j
- Case 0
- v0.vertice = *this\vertices(current_face\v1 - 1)
- v1.vertice = *this\vertices(current_face\v2 - 1)
- Case 1
- v0.vertice = *this\vertices(current_face\v2 - 1)
- v1.vertice = *this\vertices(current_face\v3 - 1)
- Case 2
- v0.vertice = *this\vertices(current_face\v3 - 1)
- v1.vertice = *this\vertices(current_face\v1 - 1)
- EndSelect
- temp.f = 0
- temp = (v0\x+1)*#Width/2
- x0.l = temp
- temp = (v0\y+1)*#Height/2
- y0.l = temp
- temp = (v1\x+1)*#Width/2
- x1.l = temp
- temp = (v1\y+1)*#Height/2
- y1.l = temp
- VeloLine(x0, y0, x1, y1, #WhiteColor)
- Next
- Next
- StopDrawing()
- flip = FlipImage(*this\imgFile)
- SaveImage(flip, name, #PB_ImagePlugin_PNG)
- EndProcedure
- Procedure Main()
- testObj.objectMethods = InizializeObject("model.obj")
- testObj\readObject()
- testObj\drawObjIntoFile("output80026.png")
- EndProcedure
- Main()
- End
- DataSection
- objectMethods_vTable:
- Data.i @objectMethods_ReadObject()
- Data.i @objectMethods_DrawObjIntoFile()
- EndDataSection
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement