December 03, 2020, 08:08:55 PM

Author Topic: [bb] Simple hair by David819 [ 1+ years ago ]  (Read 782 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Simple hair by David819 [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Simple hair
Author : David819
Posted : 1+ years ago

Description : code to create a simple hair effect

Code :
Code: BlitzBasic
  1. Graphics3D 640,480,32,2
  2. SetBuffer BackBuffer()
  3. camera=CreateCamera()
  4. TranslateEntity camera,0,0,-3
  5.  
  6.  
  7. c=CreateSphere(60) ; sphere width 60 segments for demo
  8. EntityColor c,235,176,142
  9.  
  10. ;       mesh, lenght,width
  11. c2=hair(c,0.5,.01)
  12.  
  13. ;length#=0
  14.  
  15. While Not KeyDown(1)
  16. ;TurnEntity c,.1,.1,.1
  17. RenderWorld()
  18.  Flip
  19. Wend
  20. FreeEntity c
  21. FreeEntity c2
  22. FreeEntity camera
  23. End
  24.  
  25. Function hair(mesh,ln#,wid#)
  26.  s=GetSurface(mesh,1)
  27.  m3=CreateMesh()
  28.  For i=0 To CountVertices(s)-1
  29.   m2=CreateMesh()
  30.   s2=CreateSurface(m2)
  31.   ScaleMesh m2,wid,ln,wid
  32.   FitMesh m2,-MeshWidth(m2)/2.0,0,-MeshDepth(m2)/2.0,MeshWidth(m2),MeshHeight(m2),MeshDepth(m2)
  33.   x#=VertexX(s,i)
  34.   y#=VertexY(s,i)
  35.   z#=VertexZ(s,i)
  36.  
  37.   nx#=VertexNX(s,i)
  38.   ny#=VertexNY(s,i)
  39.   nz#=VertexNZ(s,i)
  40.  
  41.   TFormPoint x,y,z,mesh,0
  42.   x=TFormedX()
  43.   y=TFormedY()
  44.   z=TFormedZ()
  45.   v0=AddVertex(s2,0,0,0)
  46.   v1=AddVertex(s2,0,0+ln,0)
  47.   v2=AddVertex(s2,0,0,0+wid)
  48.   red  =(255)
  49.   green=(255)
  50.   blue =Rand(1,255)
  51.   VertexColor s2,v0,red,green,blue
  52.   VertexColor s2,v1,red,green,blue
  53.   VertexColor s2,v2,red,green,blue
  54.   AddTriangle(s2,v0,v1,v2)
  55.   AddTriangle(s2,v0,v2,v1)
  56.   UpdateNormals m2
  57.  
  58.   AlignToVector m2,nx,ny,nz,2 ; didn't find a better way yet
  59.   mpitch#= EntityPitch(m2,1)
  60.   myaw#=   EntityYaw(m2,1)
  61.   mroll#=  EntityRoll(m2,1)
  62.   RotateEntity m2,0,0,0,1
  63.   RotateMesh m2,mpitch,myaw,mroll
  64.   PositionMesh m2,x,y,z
  65.   EntityParent m2,mesh
  66.   AddMesh m2,m3
  67.   FreeEntity m2
  68.  Next
  69.  UpdateNormals m3
  70.  EntityFX m3,16 Or 2 ; 2=use vertexcolors, 16=show both sides of triangles
  71.  EntityParent m3,mesh
  72.  
  73. End Function


Comments :


Beaker(Posted 1+ years ago)

 Similar effect BUT very different technique here:<a href="codearcs2934.html?code=627" target="_blank">http://www.blitzbasic.com/codearcs/codearcs.php?code=627[/url]


jfk EO-11110(Posted 1+ years ago)

 hehe, pretty nice code.


jfk EO-11110(Posted 1+ years ago)

 .


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal