Ok, i knocked this up. It should do what you want it to. I've not tried it on any complex meshes, but it works on primates. All you need to do, is copy the function into your code, and call it. You must pass across a mesh and a plane you wish to mirror along. 0 = x, 1 = y and 2 = z.
Also, if you have a surface you wish to mirror, you can pass that across. If not, omit it, and the function will mirror all surfaces.
Graphics3D 800,600
SetBuffer BackBuffer()
Global cam = CreateCamera()
PositionEntity cam,0,0,-10
Global light = CreateLight()
Global cube = CreateCube()
PositionMesh cube,2,1,2
While Not KeyHit(1)
If KeyHit(203) Then mirror_mesh(cube,0)
If KeyHit(200) Then mirror_mesh(cube,1)
If KeyHit(208) Then mirror_mesh(cube,2)
UpdateWorld
RenderWorld
Flip
Wend
End
Function mirror_mesh(mesh,plane,surface = 0)
If plane < 0 Or plane > 2 Then Return 0
If surface = 0 Then
s_count = CountSurfaces(mesh)
l_count = 1
Else
For loop = 0 To CountSurfaces(mesh)
temp = GetSurface(mesh,loop)
If surface = temp Then
s_count = temp
l_count = temp
End If
Next
End If
average_x# = EntityX(mesh) - (MeshWidth(mesh)/2.0)
average_y# = EntityY(mesh) - (MeshHeight(mesh)/2.0)
average_z# = EntityZ(mesh) - (MeshDepth(mesh)/2.0)
If plane = 0 Then
For sloop = l_count To s_count
surface = GetSurface(mesh,sloop)
For loop = 0 To CountVertices(surface) - 1
ny# = VertexNY (surface,loop)
nz# = VertexNZ (surface,loop)
nx# = VertexNX (surface,loop)
VertexCoords surface,loop, average_x - ( average_x + VertexX(surface,loop)), VertexY(surface,loop), VertexZ(surface,loop)
VertexNormal surface,loop,nx,ny,-nz
Next
Next
ElseIf plane = 1 Then
For sloop = l_count To s_count
surface = GetSurface(mesh,sloop)
For loop = 0 To CountVertices(surface) - 1
ny# = VertexNY (surface,loop)
nz# = VertexNZ (surface,loop)
nx# = VertexNX (surface,loop)
VertexCoords surface,loop, VertexX(surface,loop), average_y - ( average_y + VertexY(surface,loop)), VertexZ(surface,loop)
VertexNormal surface,loop,-nx,ny,-nz
Next
Next
ElseIf plane = 2 Then
For sloop = l_count To s_count
surface = GetSurface(mesh,sloop)
For loop = 0 To CountVertices(surface) - 1
ny# = VertexNY (surface,loop)
nz# = VertexNZ (surface,loop)
nx# = VertexNX (surface,loop)
VertexCoords surface,loop, VertexX(surface,loop), VertexY(surface,loop), average_z - ( average_z + VertexZ(surface,loop))
VertexNormal surface,loop,-nx,ny,nz
Next
Next
End If
FlipMesh mesh
End Function
|