Spikiness

Blitz3D Forums/Blitz3D Programming/Spikiness

Matt Merkulov(Posted 2007) [#1]
I want to make a spikiness effect - when model is transformed so the spikes will poke out of it. Tried to create some with not very good result. Maybe you can help and create better? Here, this can be a template:

Graphics3D 800,600

Const sphere_segments = 8, segments = 48

PositionEntity CreateCamera(), 0, 0, -10
RotateEntity CreateLight(), 45, 45, 0

PositionEntity CreateSphere(sphere_segments), -6, 4, 0
PositionEntity Make_Spiky(CreateSphere(sphere_segments)), -2, 4, 0

PositionEntity CreateCube(), 2, 4, 0
PositionEntity Make_Spiky(CreateCube()), 6, 4, 0

PositionEntity CreateCone(segments), -6, 0, 0
PositionEntity Make_Spiky(CreateCone(segments)), -2, 0, 0

PositionEntity CreateCylinder(segments), 2, 0, 0
PositionEntity Make_Spiky(CreateCylinder(segments)), 6, 0, 0

mesh=LoadMesh("C:\Program Files\Blitz3D\samples\teapot\teapot.x")
If mesh Then
 PositionEntity mesh, -6, -4, 0 
 PositionEntity Make_Spiky(CopyMesh(mesh)), -2, -4, 0
End If

mesh=LoadMesh("C:\Program Files\Blitz3D\samples\anim\makbot\mak_robotic.3DS")
If mesh Then
 ScaleMesh mesh, 0.1, 0.1, 0.1
 PositionMesh mesh, 0, -2, 0
 PositionEntity mesh, 2, -4, 0
 PositionEntity Make_Spiky(CopyMesh(mesh)), 6, -4, 0
End If

RenderWorld
Flip
WaitKey

Function make_spiky(mesh)

;========
For n1 = 1 To CountSurfaces(mesh)
 s = GetSurface(mesh, n1)
 q = CountTriangles(s)
 For n2 = 0 To q - 1
  v0=TriangleVertex(s,n2,0)
  v1=TriangleVertex(s,n2,1)
  v2=TriangleVertex(s,n2,2)
  d# = 0.5
  x# = Rnd(-d#, d#) + (VertexX(s,v0)+VertexX(s,v1)+VertexX(s,v2))/3
  y# = Rnd(-d#, d#) + (VertexY(s,v0)+VertexY(s,v1)+VertexY(s,v2))/3
  z# = Rnd(-d#, d#) + (VertexZ(s,v0)+VertexZ(s,v1)+VertexZ(s,v2))/3
  v=AddVertex(s,x#,y#,z#)
  AddTriangle s,v0,v1,v
  AddTriangle s,v1,v2,v
  AddTriangle s,v2,v0,v
 Next
Next

UpdateNormals mesh
EntityFX mesh,16
;========

Return mesh
End Function

Function vertex_distance#(s, v1, v2)
dx# = VertexX(s, v1) - VertexX(s, v2)
dy# = VertexY(s, v1) - VertexY(s, v2)
dz# = VertexZ(s, v1) - VertexZ(s, v2)
Return Sqr(dx# * dx# + dy# * dy# + dz# * dz#)
End Function



Matt Merkulov(Posted 2007) [#2]
No code? :( Maybe some ideas?


b32(Posted 2007) [#3]
I would think two things:
1) subdivide triangles. For the sphere, the effect works the best, because it has sufficient triangles. However, for the cube, it doesn't work too good. So it would be better to generate more triangles.
Like this:

As I understood, the 'explode' code in the code archives does this.

2) Use the normals. If you generate the spikes in the same direction of the normals, they should allways point outwards. Then, the original shape will more or less remain intact.


Matt Merkulov(Posted 2007) [#4]
Thanks