meshprims.monkey2 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. Namespace mojo3d
  2. Private
  3. Function Editing:Bool()
  4. Return Scene.GetCurrent().Editing
  5. End
  6. Function AddInstance( instance:Mesh,ctor:String,args:Variant[] )
  7. Local scene:=Scene.GetCurrent()
  8. If scene?.Editing scene.Jsonifier.AddInstance( instance,ctor,args )
  9. End
  10. Struct TerrainData
  11. Field heightMap:Pixmap
  12. Field bounds:Boxf
  13. Field width:Int
  14. Field depth:Int
  15. Field iscale:Float
  16. Field jscale:Float
  17. Method GetPosition:Vec3f( i:Int,j:Int )
  18. Local x:=i*iscale
  19. Local z:=j*jscale
  20. Local y:=heightMap.PixelPtr( i,j )[0]/255.0
  21. Return New Vec3f( x,y,z ) * bounds.Size + bounds.min
  22. End
  23. Method GetTexCoord0:Vec2f( i:Int,j:Int )
  24. Return New Vec2f( i*iscale,j*jscale )
  25. End
  26. Method GetNormal:Vec3f( i:Int,j:Int )
  27. Local v0:=GetPosition( i,j )
  28. Local v1:=GetPosition( i,Min( j+1,depth-1 ) )
  29. Local v2:=GetPosition( Min( i+1,width-1 ),j )
  30. Local v3:=GetPosition( i,Max( j-1,0 ) )
  31. Local v4:=GetPosition( Max( i-1,0 ),j )
  32. Local n0:=(v1-v0).Cross(v2-v0).Normalize()
  33. Local n1:=(v2-v0).Cross(v3-v0).Normalize()
  34. Local n2:=(v3-v0).Cross(v4-v0).Normalize()
  35. Local n3:=(v4-v0).Cross(v1-v0).Normalize()
  36. Local n:=(n0+n1+n2+n3).Normalize()
  37. ' If (i&15)=0 And (j&15)=0 print "n="+v
  38. ' DebugAssert( n.y>0 )
  39. Return n
  40. End
  41. End
  42. Public
  43. #rem monkeydoc Extension methods for creating meshes.
  44. #end
  45. Class Mesh Extension
  46. Function CreateRect:Mesh( rect:Rectf )
  47. Local mesh:=New Mesh(
  48. New Vertex3f[](
  49. New Vertex3f( rect.min.x,rect.max.y,0, 0,0, 0,0,-1 ),
  50. New Vertex3f( rect.max.x,rect.max.y,0, 1,0, 0,0,-1 ),
  51. New Vertex3f( rect.max.x,rect.min.y,0, 1,1, 0,0,-1 ),
  52. New Vertex3f( rect.min.x,rect.min.y,0, 0,1, 0,0,-1 ) ),
  53. New UInt[](
  54. 0,1,2,
  55. 0,2,3 ) )
  56. If Editing() AddInstance( mesh,"mojo3d.Mesh.CreateRect",New Variant[]( rect ) )
  57. mesh.UpdateTangents()
  58. Return mesh
  59. End
  60. Function CreateBox:Mesh( box:Boxf,xsegs:Int=1,ysegs:Int=1,zsegs:Int=1 )
  61. Local vertices:=New Vertex3f[ ((ysegs+1)*(xsegs+1) + (zsegs+1)*(xsegs+1) + (ysegs+1)*(zsegs+1))*2 ],vp:=vertices.Data
  62. For Local q:=-1 To 1 Step 2
  63. For Local y:=0 To ysegs
  64. For Local x:=0 To xsegs
  65. Local vx:=box.Width*x/xsegs+box.min.x
  66. Local vy:=box.Height*y/ysegs+box.min.y
  67. Local u:=Float(x)/xsegs,v:=Float(y)/ysegs
  68. vp[0]=New Vertex3f( vx,vy,q>0 ? box.max.z Else box.min.z, q=1 ? 1-u Else u,1-v, 0,0,q )
  69. vp+=1
  70. Next
  71. Next
  72. For Local z:=0 To zsegs
  73. For Local x:=0 To xsegs
  74. Local vx:=box.Width*x/xsegs+box.min.x
  75. Local vz:=box.Depth*z/zsegs+box.min.z
  76. Local u:=Float(x)/xsegs,v:=Float(z)/zsegs
  77. vp[0]=New Vertex3f( vx,q>0 ? box.max.y Else box.min.y,vz, u,q=1 ? 1-v Else v, 0,q,0 )
  78. vp+=1
  79. Next
  80. Next
  81. For Local y:=0 To ysegs
  82. For Local z:=0 To zsegs
  83. Local vy:=box.Height*y/ysegs+box.min.y
  84. Local vz:=box.Depth*z/zsegs+box.min.z
  85. Local u:=Float(z)/zsegs,v:=Float(y)/ysegs
  86. vp[0]=New Vertex3f( q>0 ? box.max.x Else box.min.x,vy,vz, q=-1 ? 1-u Else u,1-v, q,0,0 )
  87. vp+=1
  88. Next
  89. Next
  90. Next
  91. Local indices:=New UInt[ (ysegs*xsegs + zsegs*xsegs + ysegs*zsegs) * 12 ],ip:=indices.Data,v0:=0
  92. For Local i:=0 To 1
  93. For Local y:=0 Until ysegs
  94. For Local x:=0 Until xsegs
  95. ip[0]=v0 ; ip[1+i]=v0+xsegs+2 ; ip[2-i]=v0+1
  96. ip[3]=v0 ; ip[4+i]=v0+xsegs+1 ; ip[5-i]=v0+xsegs+2
  97. ip+=6
  98. v0+=1
  99. Next
  100. v0+=1
  101. Next
  102. v0+=xsegs+1
  103. For Local z:=0 Until zsegs
  104. For Local x:=0 Until xsegs
  105. ip[0]=v0 ; ip[1+i]=v0+1 ; ip[2-i]=v0+xsegs+2
  106. ip[3]=v0 ; ip[4+i]=v0+xsegs+2 ; ip[5-i]=v0+xsegs+1
  107. ip+=6
  108. v0+=1
  109. Next
  110. v0+=1
  111. Next
  112. v0+=xsegs+1
  113. For Local y:=0 Until ysegs
  114. For Local z:=0 Until zsegs
  115. ip[0]=v0 ; ip[1+i]=v0+1 ; ip[2-i]=v0+zsegs+2
  116. ip[3]=v0 ; ip[4+i]=v0+zsegs+2 ; ip[5-i]=v0+zsegs+1
  117. ip+=6
  118. v0+=1
  119. Next
  120. v0+=1
  121. Next
  122. v0+=zsegs+1
  123. Next
  124. Local mesh:=New Mesh( vertices,indices )
  125. If Editing() AddInstance( mesh,"mojo3d.Mesh.CreateBox",New Variant[]( box,xsegs,ysegs,zsegs ) )
  126. mesh.UpdateTangents()
  127. Return mesh
  128. End
  129. Function CreateSphere:Mesh( radius:float,hsegs:Int=24,vsegs:Int=12 )
  130. Local vertices:=New Stack<Vertex3f>
  131. For Local i:=0 Until hsegs
  132. vertices.Push( New Vertex3f( 0,radius,0, (i+.5)/hsegs,0 ) )
  133. Next
  134. For Local i:=1 Until vsegs
  135. Local pitch:=i*Pi/vsegs-Pi/2
  136. For Local j:=0 To hsegs
  137. Local yaw:=(j Mod hsegs)*TwoPi/hsegs
  138. Local p:=Mat3f.Rotation( pitch,yaw,0 ).k * radius
  139. vertices.Push( New Vertex3f( p.x,p.y,p.z, Float(j)/hsegs,Float(i)/vsegs ) )
  140. Next
  141. Next
  142. For Local i:=0 Until hsegs
  143. vertices.Push( New Vertex3f( 0,-radius,0, (i+.5)/hsegs,1 ) )
  144. Next
  145. Local indices:=New Stack<UInt>
  146. For Local i:=0 Until hsegs
  147. indices.AddAll( New UInt[]( i,i+hsegs+1,i+hsegs ) )
  148. Next
  149. For Local i:=1 Until vsegs-1
  150. For Local j:=0 Until hsegs
  151. Local v0:=i*(hsegs+1)+j-1
  152. indices.AddAll( New UInt[]( v0,v0+1,v0+hsegs+2 ) )
  153. indices.AddAll( New UInt[]( v0,v0+hsegs+2,v0+hsegs+1 ) )
  154. Next
  155. Next
  156. For Local i:=0 Until hsegs
  157. Local v0:=(hsegs+1)*(vsegs-1)+i-1
  158. indices.AddAll( New UInt[]( v0,v0+1,v0+hsegs+1 ) )
  159. Next
  160. Local vdata:=vertices.Data
  161. For Local i:=0 Until vertices.Length
  162. vdata[i].normal=vdata[i].position.Normalize()
  163. Next
  164. Local mesh:=New Mesh( vertices.ToArray(),indices.ToArray() )
  165. If Editing() AddInstance( mesh,"mojo3d.Mesh.CreateSphere",New Variant[]( radius,hsegs,vsegs ) )
  166. mesh.UpdateTangents()
  167. Return mesh
  168. End
  169. Function CreateTorus:Mesh( outerRadius:Float,innerRadius:Float,outerSegs:Int=24,innerSegs:Int=12 )
  170. Local vertices:=New Vertex3f[ (outerSegs+1)*(innerSegs+1) ],vp:=vertices.Data
  171. For Local outer:=0 To outerSegs
  172. Local sweep:=Mat3f.Yaw( outer*TwoPi/outerSegs )
  173. For Local inner:=0 To innerSegs
  174. Local an:=inner*TwoPi/innerSegs
  175. Local cos:=Cos( an ),sin:=Sin( an )
  176. Local p:=sweep * New Vec3f( cos * innerRadius + outerRadius,sin * innerRadius,0 )
  177. Local t:=New Vec2f( Float(inner)/innerSegs,Float(outer)/outerSegs )
  178. Local n:=sweep * New Vec3f( cos,sin,0 )
  179. Local v:=New Vertex3f( p,t,n )
  180. vp[0]=v
  181. vp+=1
  182. Next
  183. Next
  184. Local indices:=New UInt[ outerSegs*innerSegs*6 ],ip:=indices.Data
  185. For Local outer:=0 Until outerSegs
  186. Local v0:=outer * (innerSegs+1)
  187. For Local inner:=0 Until innerSegs
  188. ip[0]=v0+innerSegs+1
  189. ip[2]=v0+innerSegs+2
  190. ip[1]=v0+1
  191. ip[3]=v0+innerSegs+1
  192. ip[5]=v0+1
  193. ip[4]=v0
  194. ip+=6
  195. v0+=1
  196. Next
  197. Next
  198. Local mesh:=New Mesh( vertices,indices )
  199. If Editing() AddInstance( mesh,"mojo3d.Mesh.CreateTorus",New Variant[]( outerRadius,innerRadius,outerSegs,innerSegs ) )
  200. mesh.UpdateTangents()
  201. Return mesh
  202. End
  203. Function CreateCylinder:Mesh( radius:Float,length:Float,axis:Axis,segs:Int )
  204. Local hlength:=length/2
  205. Local vertices:=New Stack<Vertex3f>
  206. Local triangles:=New Stack<UInt>
  207. 'tube
  208. For Local i:=0 To segs
  209. Local yaw:=(i Mod segs) * TwoPi / segs
  210. Local v:=New Vec3f( Cos( yaw ) * radius,hlength,Sin( yaw )* radius )
  211. Local n:=New Vec3f( v.x,0,v.z ).Normalize()
  212. Local tc:=New Vec2f( Float(i)/segs,0 )
  213. vertices.Add( New Vertex3f( v,tc,n ) )
  214. v.y=-v.y
  215. tc.y=1
  216. vertices.Add( New Vertex3f( v,tc,n ) )
  217. Next
  218. For Local i:=0 Until segs
  219. triangles.Add( i*2 ) ; triangles.Add( i*2+2 ) ; triangles.Add( i*2+3 )
  220. triangles.Add( i*2 ) ; triangles.Add( i*2+3 ) ; triangles.Add( i*2+1 )
  221. Next
  222. 'caps
  223. Local v0:=vertices.Length
  224. For Local i:=0 Until segs
  225. Local yaw:=i * TwoPi / segs
  226. Local v:=New Vec3f( Cos( yaw ) * radius,hlength,Sin( yaw ) * radius )
  227. Local n:=New Vec3f( 0,1,0 )
  228. Local tc:=New Vec2f( v.x*.5+.5,1-(v.z*.5+.5) )
  229. vertices.Add( New Vertex3f( v,tc,n ) )
  230. v.y=-v.y
  231. n.y=-n.y
  232. tc.y=1-tc.y
  233. vertices.Add( New Vertex3f( v,tc,n ) )
  234. Next
  235. For Local i:=1 Until segs-1
  236. triangles.Add( v0 ) ; triangles.Add( v0+(i+1)*2 ) ; triangles.Add( v0+i*2 )
  237. triangles.Add( v0+1 ) ; triangles.Add( v0+i*2+1 ) ; triangles.Add( v0+(i+1)*2+1 )
  238. Next
  239. Local mesh:=New Mesh( vertices.ToArray(),triangles.ToArray() )
  240. If Editing() AddInstance( mesh,"mojo3d.Mesh.CreateCylinder",New Variant[]( radius,length,axis,segs ) )
  241. Select axis
  242. Case Axis.X
  243. mesh.TransformVertices( New AffineMat4f( 0,1,0, 1,0,0, 0,0,1, 0,0,0 ) )
  244. Case Axis.Z
  245. mesh.TransformVertices( New AffineMat4f( 1,0,0, 0,0,1, 0,-1,0, 0,0,0 ) )
  246. End
  247. mesh.UpdateTangents()
  248. Return mesh
  249. End
  250. Function CreateCapsule:Mesh( radius:Float,length:Float,axis:Axis,segs:Int )
  251. Const HalfPi:=Pi/2
  252. Local vertices:=New Stack<Vertex3f>
  253. Local triangles:=New Stack<UInt>
  254. Local t0:=HalfPi/radius/(length+HalfPi/radius)
  255. Local hlength:=length/2
  256. 'Top hemisphere
  257. '
  258. For Local i:=0 Until segs
  259. vertices.Add( New Vertex3f( 0,hlength+radius,0, (i+.5)/segs,0, 0,1,0 ) )
  260. Next
  261. For Local j:=1 To segs
  262. Local pitch:=j*Pi/(segs*2)-HalfPi
  263. For Local i:=0 To segs
  264. Local yaw:=(i Mod segs) * TwoPi / segs
  265. Local n:=Mat3f.Rotation( pitch,yaw,0 ).k
  266. Local v:=n*radius
  267. v.y+=hlength
  268. vertices.Add( New Vertex3f( v.x,v.y,v.z, Float(i)/Float(segs),Float(j)/Float(segs)*2*t0, n.x,n.y,n.z ) )
  269. Next
  270. Next
  271. For Local i:=0 Until segs
  272. triangles.Add( i ) ; triangles.Add( i+segs+1 ) ; triangles.Add( i+segs )
  273. Next
  274. For Local j:=1 Until segs
  275. For Local i:=0 Until segs
  276. Local t:=j*(segs+1)+i-1
  277. triangles.Add( t ) ; triangles.Add( t+1 ) ; triangles.Add( t+segs+2 )
  278. triangles.Add( t ) ; triangles.Add( t+segs+2 ) ; triangles.Add( t+segs+1 )
  279. Next
  280. Next
  281. Local v0:=vertices.Length
  282. For Local j:=segs Until segs*2
  283. Local pitch:=j*Pi/(segs*2)-HalfPi
  284. For Local i:=0 To segs
  285. Local yaw:=(i Mod segs) * TwoPi / segs
  286. Local n:=Mat3f.Rotation( pitch,yaw,0 ).k
  287. Local v:=n*radius
  288. v.y-=hlength
  289. vertices.Add( New Vertex3f( v.x,v.y,v.z, Float(i)/Float(segs),(Float(j)/Float(segs*2)-.5)*2*t0, n.x,n.y,n.z ) )
  290. Next
  291. Next
  292. For Local i:=0 Until segs
  293. vertices.Add( New Vertex3f( 0,-hlength-radius,0, (i+.5)/segs,1, 0,-1,0 ) )
  294. Next
  295. For Local j:=0 Until segs-1
  296. For Local i:=0 Until segs
  297. Local t:=j*(segs+1)+i+v0
  298. triangles.Add( t ) ; triangles.Add( t+1 ) ; triangles.Add( t+segs+2 )
  299. triangles.Add( t ) ; triangles.Add( t+segs+2 ) ; triangles.Add( t+segs+1 )
  300. Next
  301. Next
  302. For Local i:=0 Until segs
  303. Local t:=(segs+1)*(segs-1)+i+v0
  304. triangles.Add( t ) ; triangles.Add( t+1 ) ; triangles.Add( t+segs+1 )
  305. Next
  306. ' Join 2 bits together...
  307. '
  308. For Local i:=0 Until segs
  309. Local t:=segs*(segs+1)-1+i
  310. triangles.Add( t ) ; triangles.Add( t+1 ) ; triangles.Add( t+segs+2 )
  311. triangles.Add( t ) ; triangles.Add( t+segs+2 ) ; triangles.Add( t+segs+1 )
  312. Next
  313. Local mesh:=New Mesh( vertices.ToArray(),triangles.ToArray() )
  314. If Editing() AddInstance( mesh,"mojo3d.Mesh.CreateCapsule",New Variant[]( radius,length,axis,segs ) )
  315. Select axis
  316. Case Axis.X
  317. mesh.TransformVertices( New AffineMat4f( 0,1,0, 1,0,0, 0,0,1, 0,0,0 ) )
  318. Case Axis.Z
  319. mesh.TransformVertices( New AffineMat4f( 1,0,0, 0,0,1, 0,-1,0, 0,0,0 ) )
  320. End
  321. mesh.UpdateTangents()
  322. Return mesh
  323. End
  324. Function CreateCone:Mesh( radius:Float,length:Float,axis:Axis,segs:Int )
  325. Local hlength:=length/2
  326. Local vertices:=New Stack<Vertex3f>
  327. Local triangles:=New Stack<UInt>
  328. For Local i:=0 Until segs
  329. vertices.Add( New Vertex3f( 0,hlength,0, (i+.5)/segs,0, 0,1,0 ) )
  330. Next
  331. For Local i:=0 To segs
  332. Local yaw:=(i Mod segs) * TwoPi/segs
  333. Local n:=New Vec3f( Cos( yaw ),0,Sin( yaw ) )
  334. Local v:=New Vec3f( n.x*radius,-hlength,n.z*radius )
  335. Local tc:=New Vec2f( Float(i)/segs,1 )
  336. vertices.Add( new Vertex3f( v,tc,n ) )
  337. Next
  338. For Local i:=0 Until segs
  339. triangles.Add( i ) ; triangles.Add( i+segs+1 ) ; triangles.Add( i+segs )
  340. Next
  341. 'cap
  342. Local v0:=vertices.Length
  343. For Local i:=0 Until segs
  344. Local yaw:=i * TwoPi / segs
  345. Local n:=New Vec3f( Cos( yaw ),0,Sin( yaw ) )
  346. Local v:=New Vec3f( n.x*radius,-hlength,n.z*radius )
  347. Local tc:=New Vec2f( n.x*.5+.5,n.z*.5+.5 )
  348. vertices.Add( new Vertex3f( v,tc,n ) )
  349. Next
  350. For Local i:=1 Until segs-1
  351. triangles.Add( v0 ) ; triangles.Add( v0+i ) ; triangles.Add( v0+i+1 )
  352. Next
  353. Local mesh:=New Mesh( vertices.ToArray(),triangles.ToArray() )
  354. If Editing() AddInstance( mesh,"mojo3d.Mesh.CreateCone",New Variant[]( radius,length,axis,segs ) )
  355. Select axis
  356. Case Axis.X
  357. mesh.TransformVertices( New AffineMat4f( 0,1,0, 1,0,0, 0,0,1, 0,0,0 ) )
  358. Case Axis.Z
  359. mesh.TransformVertices( New AffineMat4f( 1,0,0, 0,0,1, 0,-1,0, 0,0,0 ) )
  360. End
  361. mesh.UpdateTangents()
  362. Return mesh
  363. End
  364. Function CreateTerrain:Mesh( heightMap:Pixmap,bounds:Boxf )
  365. Local width:=heightMap.Width
  366. Local depth:=heightMap.Height
  367. Local data:TerrainData
  368. data.heightMap=heightMap
  369. data.bounds=bounds
  370. data.width=width
  371. data.depth=depth
  372. data.iscale=1.0/(width-1)
  373. data.jscale=1.0/(depth-1)
  374. Local vertices:=New Vertex3f[ width*depth ]
  375. For Local j:=0 Until depth
  376. Local vp:=vertices.Data+j*width
  377. For Local i:=0 Until width
  378. vp[i].position=data.GetPosition( i,j )
  379. vp[i].texCoord0=data.GetTexCoord0( i,j )
  380. vp[i].normal=data.GetNormal( i,j )
  381. Next
  382. Next
  383. Local indices:=New UInt[ (width-1)*(depth-1)*6 ]
  384. local ip:=indices.Data
  385. For Local j:=0 Until depth-1
  386. Local v0:=j*width
  387. For Local i:=0 Until width-1
  388. ip[0]=v0+i ; ip[1]=v0+i+1+width ; ip[2]=v0+i+1
  389. ip[3]=v0+i ; ip[4]=v0+i+width ; ip[5]=v0+i+1+width
  390. ip+=6
  391. Next
  392. Next
  393. Local mesh:=New Mesh( vertices,indices )
  394. mesh.UpdateTangents()
  395. Return mesh
  396. End
  397. End
  398. #rem monkeydoc Extension methods for creating models.
  399. #end
  400. Class Model Extension
  401. Function CreateBox:Model( box:Boxf,xsegs:Int,ysegs:Int,zsegs:Int,material:Material,parent:Entity=Null )
  402. Local mesh:=mojo3d.Mesh.CreateBox( box,xsegs,ysegs,zsegs )
  403. Local model:=New Model( mesh,material,parent )
  404. Return model
  405. End
  406. Function CreateSphere:Model( radius:Float,hsegs:Int,vsegs:Int,material:Material,parent:Entity=Null )
  407. Local mesh:=mojo3d.Mesh.CreateSphere( radius,hsegs,vsegs )
  408. Local model:=New Model( mesh,material,parent )
  409. Return model
  410. End
  411. Function CreateTorus:Model( outerRadius:Float,innerRadius:Float,outerSegs:Int,innerSegs:Int,material:Material,parent:Entity=Null )
  412. Local mesh:=mojo3d.Mesh.CreateTorus( outerRadius,innerRadius,outerSegs,innerSegs )
  413. Local model:=New Model( mesh,material,parent )
  414. Return model
  415. End
  416. Function CreateCylinder:Model( radius:Float,length:Float,axis:Axis,segs:Int,material:Material,parent:Entity=null )
  417. Local mesh:=mojo3d.Mesh.CreateCylinder( radius,length,axis,segs )
  418. Local model:=New Model( mesh,material,parent )
  419. Return model
  420. End
  421. Function CreateCapsule:Model( radius:Float,length:Float,axis:Axis,segs:Int,material:Material,parent:Entity=null )
  422. Local mesh:=mojo3d.Mesh.CreateCapsule( radius,length,axis,segs )
  423. Local model:=New Model( mesh,material,parent )
  424. Return model
  425. End
  426. Function CreateCone:Model( radius:Float,length:Float,axis:Axis,segs:Int,material:Material,parent:Entity=null )
  427. Local mesh:=mojo3d.Mesh.CreateCone( radius,length,axis,segs )
  428. Local model:=New Model( mesh,material,parent )
  429. Return model
  430. End
  431. Function CreateTerrain:Model( heightMap:Pixmap,bounds:Boxf,material:Material,parent:Entity=Null )
  432. Local mesh:=mojo3d.Mesh.CreateTerrain( heightMap,bounds )
  433. Local model:=New Model( mesh,material,parent )
  434. Return model
  435. End
  436. End