Mesh Manipulations
BlitzMax Forums/BlitzMax Programming/Mesh Manipulations
| ||
| I wanna start to build a Mesh manipulation Commands Lib. I will post the code here. Any one who wants to improve it will be welcomed. I will use Xors3D The goal is to be able to modify Mesh in many ways. For Example: AttachTwoMeshes(Mesh1Handle,Mesh2Handle) SplitMesh(MeshHandle) ExplodeMesh(MeshHandle) Then turn it into a module. What do you guys think? Anyway im doing it for my self so why not share it.. |
| ||
| Always handy and or educational to have collected functions like that. Any idas for funky features that can come in handy? A procedural modelling lib would be very cool ;) |
| ||
| Everything Imaginable for Mesh editing will go in. Ill start with simple stuff and see where it goes. Also might be followed with an Editor or Tester Maybe Later Make Image Editing Lib as well |
| ||
| Here is my first Command i worked today (Under Xors3D) Turning a PNG into a Mesh This is good for physics Use The only thing I didnt manage to do is to make the texture appear. This Is a basic outliner for png and not 100% accurate (at this point). it just gives you the outlines but its good for a start. '------------------------------------------' PS: Dont forget to change the png load to what you wish. Feel free to improve this code and repost it '------------------------------------------'
Strict
Import xorsteam.xors3d
'set graphics mode
xGraphics3D 1024, 768, 32, False, True
Local CAMERA = xCreateCamera()
xPositionEntity(CAMERA, 0, 0, -20)
xCreateLight()
Local imghandle = xLoadImage("diablo1ef.png")
'Seems like 16777215 represents empty space in an image
TurnPngToMesh("diablo1ef.png")
Repeat
xRenderWorld()
xUpdateWorld()
xDrawImage(imghandle, 0, 0)
xFlip
Until xKeyHit(1)
'TurnPngToMesh
Function TurnPngToMesh(PNGURL:String, Resolution:Float = 128, Debug = False)
Global ResJump:Float, CurrentAngle:Float, ImageW:Float, ImageH:Float, ImageRadius:Float, HalfImageW:Float, HalfImageH:Float, PPnt:Pntr_Class, Diversion:Float = 400
Global CoordsList:TList, NewMesh, PNGHandle, MeshTexture
PNGHandle = xLoadImage(PNGURL)
MeshTexture = xLoadTexture(PNGURL)
CoordsList = CreateList()
ImageW = xImageWidth(PNGHandle)
ImageH = xImageHeight(PNGHandle)
HalfImageW = ImageW / 2
HalfImageH = ImageH / 2
ResJump = 360 / Resolution
ImageRadius = (HalfImageW ^ 2 + HalfImageH ^ 2) ^ 0.5
'Creat Net Coords
While CurrentAngle < 360
PPnt = New Pntr_Class
PPnt = GetFirstPixelIncounter(CurrentAngle)
ListAddLast(CoordsList, PPnt)
If Debug Then xLine(Diversion, Diversion, Diversion + PPnt.X, Diversion + PPnt.Y)
CurrentAngle = CurrentAngle + ResJump
Wend
'MeshFromData
CreateMeshFromData()
xEntityTexture(NewMesh, MeshTexture)
xFreeImage(PNGHandle)
Return NewMesh
'------------------------------------------------------'
'GetFirstPixelIncounter (For Each Yeter)
Function GetFirstPixelIncounter:Pntr_Class(Angel:Float)
Local PointInTheRadius:Float, PIRX:Float, PIRY:Float, APntr:Pntr_Class, DiffrentFlg, Pixel, PIRAndHRX:Float, PIRAndHRY:Float
APntr = New Pntr_Class
For PointInTheRadius = ImageRadius To 0 Step - 1
PIRX = Cos(Angel) * PointInTheRadius
PIRY = Sin(Angel) * PointInTheRadius
PIRAndHRX = HalfImageW + PIRX
PIRAndHRY = HalfImageH + PIRY
Pixel = xReadPixel(PIRAndHRX, PIRAndHRY, xImageBuffer(PNGHandle))
If Pixel <> 16777215 And Pixel <> 0 Then
APntr.X = PIRX
APntr.Y = PIRY
Exit
End If
Next
Return APntr
End Function
Function CreateMeshFromData(SizeDiversion:Float = 40) 'How much to devide the coords (Changes Size)
Local TempCoord:Pntr_Class, SURFACE
NewMesh = xCreateMesh()
SURFACE = xCreateSurface(NewMesh)
xAddVertex(SURFACE, 0, 0, 0) 'MiddlePoint
'Create all the Radius Vertix
For TempCoord = EachIn CoordsList
xAddVertex(SURFACE, TempCoord.X / SizeDiversion, -(TempCoord.Y / SizeDiversion), 0) ' TempCoord.X / SizeDiversion, -(TempCoord.Y / SizeDiversion)
Next
Local VertexCounter, PreviousVertex
'Create Triangles
For TempCoord = EachIn CoordsList
VertexCounter = VertexCounter + 1
If VertexCounter = 1 Then
PreviousVertex = CountList(CoordsList)
Else
PreviousVertex = VertexCounter - 1
End If
xAddTriangle(SURFACE, 0, PreviousVertex, VertexCounter)
Next
End Function
'------------------------------------------------------'
End Function
Type Pntr_Class
Field X:Float
Field Y:Float
End Type
|