Hi there.
It's been a long time since I joined the forum last time . The best way to get that is playing with vertexdata . As our friend Derek Darkly has suggested, you shoud move all selected vertex that share the same coordinates at once . You can make your own function to select vertex .
Here's a little 20 lines code I made some time ago .
ink rgb(200,100,50),0:box 0,0,100,100:ink rgb(255,0,0),0:box 0,58,100,100:get image 1,0,0,100,100,1:autocam off:sync on:make light 1
position light 1,20,-10,0:make object sphere 1,8,7,10:make mesh from object 1,1:texture object 1,1:make object box 2,1,1,1
instance object 4,1:move object 4,5:xrotate object 1,5:xrotate object 4,-5:position camera 30,5,-30:point camera 0,0,0:do:set cursor 0,0
print "Fps ",screen fps():move object left 2,0.05:if object position x(2)>4 then zrotate object 2,0 else if object position x(2)<-0 then zrotate object 2,180
change mesh 1,0,1:lock vertexdata for limb 1,0:vertex = get vertexdata vertex count(): for i =0 to vertex
x# = get vertexdata position x(i):y# = get vertexdata position y(i):z# = get vertexdata position z(i)
if y#>0 then set vertexdata position i,x#*0.3+object position x(2),y#+x/5-object position x(2)/2,z#*0.3
if y#<0 then set vertexdata position i,x#*0.1+object position x(2),y#-x#/5-object position x(2)/2,z#*0.1
if y#>3 then set vertexdata position i,x#*1.2,y#+7+x#-object position x(2)/2,z#*1.2
if y#<-0 then set vertexdata position i,x#*0.2,y#-8,z#*0.2:if y#<-2.4 then set vertexdata position i,1.3+x#*0.9,y#-9,z#*0.3
if y#<-3.4 then set vertexdata position i,1.3+x#*0.9,y#-7,z#*0.3
next i:unlock vertexdata:sync:loop
As our friend WickedX has commented , you can build the object using a triangle-list primitive.
Here is an example:
set display mode 800,600,32
autocam off
sync on
hide light 0:set ambient light 0
make light 1:position light 1,100,0,0:color light 1,rgb(0,255,0)
make light 2:position light 2,-100,-100,0:color light 2,rgb(0,255,255)
make light 3:position light 3,50,100,0:color light 3,rgb(255,0,0)
rem vertex to see where to make triangles
for i= 1 to 12
make object box i,1,1,1
yrotate object i,72*i
move object up i,9
if i>5 then move object down i,18:yrotate object i,(i*72)+72/2
move object i,15
next
position object 11,0,20,0
position object 12,0,-20,0
rem faces
tri(20,11,1,2)
tri(21,11,2,3)
tri(22,11,3,4)
tri(23,11,4,5)
tri(24,11,5,1)
tri(25,1,6,2)
tri(26,2,7,3)
tri(27,3,8,4)
tri(28,5,4,9)
tri(29,1,5,10)
tri(30,1,10,6)
tri(31,2,6,7)
tri(32,3,7,8)
tri(33,4,8,9)
tri(34,5,9,10)
tri(35,6,10,12)
tri(36,10,9,12)
tri(37,9,8,12)
tri(38,8,7,12)
tri(39,7,6,12)
rem joining all meshes to a single object
make object box 100,0,0,0:position object 100,50,0,0
for i= 20 to 39
inc mesh
make mesh from object mesh,i
add limb 100,mesh,mesh
next
position camera 20,-10,-150
point camera 20,-10,0
do
g#=g#+0.1
rotate object 100,g#,g#,g#
ink rgb(0,255,0),1
for i= 1 to 12
text object screen x(i),object screen y(i),str$(i)
next
control camera using arrowkeys 0,0.1,0.1
a#=wrapvalue(a#+mousemovex()/2)
cam#=wrapvalue(cam#+mousemovey()/2)
rotate camera cam#,a#,0
if leftkey() then move camera left 0.1
if rightkey() then move camera right 0.1
sync
loop
function tri(n,a,b,c)
xx#=object position x(a)
yy#=object position y(a)
zz#=object position z(a)
xx2#=object position x(b)
yy2#=object position y(b)
zz2#=object position z(b)
xx3#=object position x(c)
yy3#=object position y(c)
zz3#=object position z(c)
make object triangle n,xx#,yy#,zz#,xx2#,yy2#,zz2#,xx3#,yy3#,zz3#
set object normals n
endfunction tri
Quote: "I thought I remember seeing in the past a command to weld vertices in Darkbasic"
The commands you're referring to are GET INDEXDATA and SET INDEXDATA .
Here's a good example of Ian to weld vertex of a cube.
sync on
sync rate 60
ink rgb(0, 0, 0), rgb(0, 0, 0)
make object cube 1, 2.0
rotate object 1, 45.0, 0.0, 45.0
fix object pivot 1
WeldLimbVertices(1, 0)
set object cull 1, 0
repeat
lock vertexdata for limb 1, 0
set cursor 0, 0
print "get vertexdata vertex count() = "; get vertexdata vertex count()
print "get vertexdata index count() = "; get vertexdata index count()
for i = 0 to array count( Vertex() )
print i; " - "; Vertex(i).UsageCount; " - "; Vertex(i).Matches; " - "; Vertex(i).Vertex.x; "/"; Vertex(i).Vertex.y; "/"; Vertex(i).Vertex.z
next
unlock vertexdata
rotate object 1, 0.0, wrapvalue( object angle y(1) + 1.0 ), 0.0
sync
until spacekey()
end
type Vertex_t
x as float
y as float
z as float
nx as float
ny as float
nz as float
u as float
v as float
Diffuse as dword
OriginalPosition as integer
UsageCount as integer
endtype
type VertexInfo_t
Vertex as Vertex_t
OriginalPosition as integer
Matches as integer
UsageCount as integer
endtype
global dim Vertex() as VertexInfo_t
global dim Index() as integer
function WeldLimbVertices(Object as integer, Limb as integer)
local V as Vertex_t
local VI as VertexInfo_t
lock vertexdata for limb Object, Limb
` Create/recreate arrays needed for manipulation
undim Vertex()
global dim Vertex( get vertexdata vertex count() - 1 ) as VertexInfo_t
undim Index()
global dim Index( get vertexdata index count() - 1 ) as integer
` Copy all vertex data into an array
for i = 0 to array count( Vertex() )
V.x = get vertexdata position x(i)
V.y = get vertexdata position y(i)
V.z = get vertexdata position z(i)
V.nx = get vertexdata normals x(i)
V.ny = get vertexdata normals y(i)
V.nz = get vertexdata normals z(i)
V.u = get vertexdata u(i)
V.v = get vertexdata v(i)
V.Diffuse = get vertexdata diffuse(i)
Vertex(i).Vertex = V
Vertex(i).OriginalPosition = i
Vertex(i).Matches = i
Vertex(i).UsageCount = 0
next
` Copy all index data into an array
for i = 0 to array count( Index() )
Index(i) = get indexdata(i)
inc Vertex( Index(i) ).UsageCount
next
` Look for matching vertices
for i = 1 to array count( Vertex() )
for j = 0 to i - 1
if CheckMatchingVertex(i, j) = 1
` Update the matching vertex
Vertex(j).Vertex.nx = Vertex(j).Vertex.nx + ( Vertex(i).Vertex.nx * Vertex(i).UsageCount )
Vertex(j).Vertex.ny = Vertex(j).Vertex.ny + ( Vertex(i).Vertex.ny * Vertex(i).UsageCount )
Vertex(j).Vertex.nz = Vertex(j).Vertex.nz + ( Vertex(i).Vertex.nz * Vertex(i).UsageCount )
Vertex(j).UsageCount = Vertex(j).UsageCount + Vertex(i).UsageCount
` Update this duplicate vertex
Vertex(i).UsageCount = 0
Vertex(i).Matches = j
` Skip on to the next vertex
exit
endif
next
next
` Divide the normals by the usage count (effectively, averaging the normals)
for i = 0 to array count( Vertex() )
if Vertex(i).UsageCount > 0
Vertex(i).Vertex.nx = Vertex(i).Vertex.nx + Vertex(i).UsageCount
Vertex(i).Vertex.ny = Vertex(i).Vertex.ny + Vertex(i).UsageCount
Vertex(i).Vertex.nz = Vertex(i).Vertex.nz + Vertex(i).UsageCount
endif
next
` Sort the vertices so unused ones are at the end
repeat
Swap = 0
for i = 1 to array count( Vertex() )
if Vertex(i-1).UsageCount < Vertex(i).UsageCount
Swap = 1
VI = Vertex(i-1)
Vertex(i-1) = Vertex(i)
Vertex(i) = VI
endif
next
until Swap = 0
` Update the indices so that duplicates point at the original
for i = 0 to array count( Index() )
Index(i) = FindVertexFromIndex( Index(i) )
next
` Update the object index data
for i = 0 to array count( Index() )
set indexdata i, Index(i)
next
` Update the object vertex data
i = 0
while Vertex(i).UsageCount > 0
set vertexdata position i, Vertex(i).Vertex.x, Vertex(i).Vertex.y, Vertex(i).Vertex.z
set vertexdata normals i, Vertex(i).Vertex.nx, Vertex(i).Vertex.ny, Vertex(i).Vertex.nz
set vertexdata uv i, Vertex(i).Vertex.u, Vertex(i).Vertex.v
set vertexdata diffuse i, Vertex(i).Vertex.Diffuse
inc i
endwhile
delete mesh from vertexdata i, get vertexdata vertex count(), get vertexdata index count(), get vertexdata index count()
unlock vertexdata
endfunction
function CheckMatchingVertex(i as integer, j as integer)
if Vertex(i).Vertex.x <> Vertex(j).Vertex.x then exitfunction 0
if Vertex(i).Vertex.y <> Vertex(j).Vertex.y then exitfunction 0
if Vertex(i).Vertex.z <> Vertex(j).Vertex.z then exitfunction 0
endfunction 1
function FindVertexFromIndex(Ind as integer)
for i = 0 to array count( Vertex() )
if Vertex(i).OriginalPosition = Ind
if Vertex(i).OriginalPosition = Vertex(i).Matches then exitfunction i
exitfunction FindVertexFromIndex( Vertex(i).Matches )
endif
next
endfunction -1
Cheers.
I'm not a grumpy grandpa
