Difference between revisions of "R3d.ConvexMeshShape.new"
From GiderosMobile
(Created page with "'''Available since:''' Gideros 2019.10<br/> '''Class:''' R3d.ConvexMeshShape<br/> === Description === Creates a new collision convex mesh shape (fixture). <source lang="l...") |
m (Text replacement - "</source>" to "</syntaxhighlight>") |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
=== Description === | === Description === | ||
Creates a new collision convex mesh shape (fixture). | Creates a new collision convex mesh shape (fixture). | ||
− | < | + | <syntaxhighlight lang="lua"> |
r3d.ConvexMeshShape.new(vertices,indices,faces) | r3d.ConvexMeshShape.new(vertices,indices,faces) | ||
− | </ | + | </syntaxhighlight> |
=== Parameters === | === Parameters === | ||
Line 14: | Line 14: | ||
=== Example === | === Example === | ||
− | < | + | '''A cylinder shape''' |
− | </ | + | <syntaxhighlight lang="lua"> |
+ | --For collision, ensure closed/CCW shape | ||
+ | local steps=8 | ||
+ | local ca,fa={},{} | ||
+ | local nc,nf=1,1 | ||
+ | for i=3,steps*4-1,4 do ca[nc]=i+1 nc+=1 end | ||
+ | fa[nf]=steps nf+=1 | ||
+ | for i=3,steps*4-1,4 do | ||
+ | ca[nc]=i+1 nc+=1 ca[nc]=i+2 nc+=1 | ||
+ | ca[nc]=i+6 nc+=1 ca[nc]=i+5 nc+=1 | ||
+ | fa[nf]=4 nf+=1 | ||
+ | end | ||
+ | ca[nc-2]=5 ca[nc-1]=4 | ||
+ | for i=steps*4-1,3,-4 do ca[nc]=i+2 nc+=1 end | ||
+ | fa[nf]=steps nf+=1 | ||
+ | |||
+ | self._r3dshape=r3d.ConvexMeshShape.new(self._va,ca,fa) | ||
+ | </syntaxhighlight> | ||
{{R3d.ConvexMeshShape}} | {{R3d.ConvexMeshShape}} |
Latest revision as of 14:32, 13 July 2023
Available since: Gideros 2019.10
Class: R3d.ConvexMeshShape
Description
Creates a new collision convex mesh shape (fixture).
r3d.ConvexMeshShape.new(vertices,indices,faces)
Parameters
vertices: (table) the vertex array table
indices: (table) the index array table
faces: (table) the face array table
Example
A cylinder shape
--For collision, ensure closed/CCW shape
local steps=8
local ca,fa={},{}
local nc,nf=1,1
for i=3,steps*4-1,4 do ca[nc]=i+1 nc+=1 end
fa[nf]=steps nf+=1
for i=3,steps*4-1,4 do
ca[nc]=i+1 nc+=1 ca[nc]=i+2 nc+=1
ca[nc]=i+6 nc+=1 ca[nc]=i+5 nc+=1
fa[nf]=4 nf+=1
end
ca[nc-2]=5 ca[nc-1]=4
for i=steps*4-1,3,-4 do ca[nc]=i+2 nc+=1 end
fa[nf]=steps nf+=1
self._r3dshape=r3d.ConvexMeshShape.new(self._va,ca,fa)