I'm getting Illegal Type Conversion errors compiling this code.. can someone straighten me out on passing and returning typed data ?
Global newmesh
Global newsurf
Type subdivvect
Field x#
Field y#
Field z#
End Type
Function subdiv(mesh)
newmesh = CreateMesh()
For i=1 To CountSurfaces(mesh)
subdivsurf(GetSurface(mesh,i))
Next
FreeEntity mesh
Return newmesh
End Function
Function subdivsurf(surf)
newsurf = CreateSurface(newmesh)
tris = CountTriangles(surf)-1
For i=0 To tris
c1 = GetCoords(surf,TriangleVertex(surf,i,0))
c2 = GetCoords(surf,TriangleVertex(surf,i,1))
c3 = GetCoords(surf,TriangleVertex(surf,i,2))
c4 = spheresplit(c1,c2)
c5 = spheresplit(c2,c3)
c6 = spheresplit(c3,c1)
Vects2Triangle(c1,c4,c6)
Vects2Triangle(c4,c2,c5)
Vects2Triangle(c5,c3,c6)
Vects2Triangle(c4,c5,c6)
Next
End Function
Function spheresplit(c1.subdivvect, c2.subdivvect)
p1# = VectorPitch(c1\x,c1\y,c1\z)
p2# = VectorPitch(c2\x,c2\y,c2\z)
y1# = VectorYaw(c1\x,c1\y,c1\z)
y2# = VectorYaw(c2\x,c2\y,c2\z)
p# = (p1#+p2#)/2
y# = (y1#+y2#)/2
c.subdivvect = PitchYaw2Vector(p#,y#)
Return c
End Function
Function GetCoords(surf, vert)
res.subdivvect = New subdivvect
res\x = VertexX(surf,vert)
res\y = VertexY(surf,vert)
res\z = VertexZ(surf,vert)
Return res
End Function
Function PitchYaw2Vector(p#, y#)
res.subdivvect = New subdivvect
res\x#=Sin#(y#)+Cos#(y#)
res\y#=1
res\z#=Cos#(y#)-Sin#(y#)
res\x#=res\x#
res\y#=res\y#*Cos#(p#)-res\z#*Sin#(p#)
res\z#=res\y#*Sin#(p#)+res\z#*Cos#(p#)
Return res
End Function
Function Vects2Triangle(c1.subdivvect,c2.subdivvect,c3.subdivvect)
v1 = vertindex(newsurf, c1)
v2 = vertindex(newsurf, c2)
v3 = vertindex(newsurf, c3)
AddTriangle(newsurf, v1, v2, v3)
End Function
Function vertindex(surf, c.subdivvect)
verts = CountVertices(surf) - 1
For i=0 To verts
If VertexX(surf,i)=c\x And VertexY(surf,i)=c\y And VertexZ(surf,i)=c\z
Return i
EndIf
Next
Return AddVertex(surf, c\x, c\y, c\z)
End Function
|