Posted: 22nd Jan 2003 7:35
Just a little snippet that creates an object and lets you modify it by moving its vertices. I know it can be optimized a great deal, this was just test code, but feel free to give your suggestions.

just replace the texture with one of your own


+ Code Snippet
Rem Project: uvtexture
Rem Created: 1/13/2003 8:32:12 AM

Rem ***** Main Source File *****
sync on
sync rate 0
set ambient light 50
set text font "arial" : set text size 13
set text to bold : set text transparent
autocam off
color backdrop 0

position camera 0,0,0
`---------make initial  object--------

make object sphere 2,50,3,3
position object 2,0,0,100
load image "firebal.bmp",2
texture object 2,2
ghost object on 2
`----------load the object into a memblock------------
make mesh from object 2,2
MAKE MEMBLOCK FROM MESH 2,2


`-------Extracting some data from the memblock header------------
fvf2 = memblock dword(2,0)
fvfsz2=memblock dword(2,4)
vcount2 = memblock dword(2,8)
memsz2=GET MEMBLOCK SIZE(2)
scwid# = screen width()
schi# = screen height()


`------------setting up  variables-----------------

dim posx(vcount2-1)
dim posy(vcount2-1)
dim posz(vcount2-1)
dim vertx#(vcount2-1)
dim verty#(vcount2-1)
dim vertz#(vcount2-1)
dim sel(vcount2+3)
for v =0 to vcount2-1
  ` make some plains to visualize the vertexes
   make object plain V+3,1,1
  ` Calc positions of vertices in memblock
  posx(v)=12+(v*fvfsz2)
  posy(v)=posx(v)+4
  posz(v)=posx(v)+8
  ` store the vertex position values
  vertx#(v) = memblock float(2,posx(v))
  verty#(v) = memblock float(2,posy(v))
  vertz#(v) = memblock float(2,posz(v))
  position object v+3,vertx#(v),verty#(v),vertz#(v)+100
  set object light v+3,0
next v
`-------------MAIN LOOP-----------------

do

` check function to see if a vertex is selected
selected = selectvertex(vcount2)
if selected
   mmx# = mousemovex()
   mmy# = mousemovey()
   mmz# = mousemovez()
   oldselected = selected
      while mouseclick()=2
         hide mouse
            for vert = 0 to vcount2-1
               mmx# = mousemovex()
               mmy# = mousemovey()
               mmz# = mousemovez()
               mmy#= (mmy#-(mmy#*2))
               vertx#(selected-3)= vertx#(selected-3)+ mmx#
               verty#(selected-3)= verty#(selected-3)+ mmy#
               vertz#(selected-3)= vertz#(selected-3)+ mmz#
               mmx#=0
               mmy#=0
               mmz#=0
                  if sel(vert)>0
                     write memblock float 2,posx(vert),vertx#(selected-3)
                     write memblock float 2,posy(vert),verty#(selected-3)
                     write memblock float 2,posz(vert),vertz#(selected-3)
                  endif
               position object selected,vertx#(selected-3),verty#(selected-3),vertz#(selected-3)+100
            next vert
         positobj(modelx#,modely#,modelz#,vcount2,memsz2)
         show mouse
      endwhile
endif

`-----------------------------------------------------
` if no longer selected, then reset
if oldselected
   if selected = 0
       for vert = 0 to vcount2-1
        color object vert+3,RGB(255,255,255)
        sel(vert)=0
       next vert
      oldselected=0
   endif
endif

`------------------------------------------------------

if rightkey() then turn object right 2, 5
if leftkey() then turn object left 2, 5
if upkey() then pitch object up 2,5
if downkey()then pitch object down 2,5
modelx# = object position x(2)
modely# = object position y(2)
modelz# = object position z(2)
updtobj(vcount2)
sync
Display_UWProgramInfo()
loop
`--------------------------------------------------------------------------------------------------
function selectvertex(vcount2)
for vert = 0 to vcount2-1
   if mousex()  object screen x(vert+3)-5
      if mousey()  object screen y(vert+3)-5
            color object vert+3,RGB(0,0,255)
            selobj = vert+3
            sel(vert)=vert+3
      endif
   endif
next vert
endfunction selobj

`----------------------------------------------------------------------------------------------------
`----------------------------------------------------------------------------------------------------

function positobj(modelx#,modely#,modelz#,vcount2,memsz2)
   change mesh from memblock 2,2
   delete memblock 2
   delete object 2
   make object 2,2,2
   make memblock from mesh 2,2
   set object 2,1,1,0
   ghost object on 2
   position object 2,modelx#,modely#,modelz#
   sync
Display_UWProgramInfo()
endfunction

`----------------------------------------------------------------------------------------------------
`------------------------------------------------------------------------------------------------------

function updtobj(vcount2)
   make mesh from object 2,2
   delete memblock 2
   make memblock from mesh 2,2
   for v =0 to vcount2-1
      vertx#(v) = memblock float(2,posx(v))
      verty#(v) = memblock float(2,posy(v))
      vertz#(v) = memblock float(2,posz(v))
      position object v+3,vertx#(v),verty#(v),vertz#(v)+100
      set object 2,0,1,0
   next v
endfunction

`-----------------------------------------------------------------------------------------------------
Function Display_UWProgramInfo()
    x=0: y=100: yh=15
    set cursor 0,0
    print "hold LMB to drag vertices"
    print "arrow keys to rotate"
    text x,y,"Example By: Jetmech": y=y+yh
    text x,y,"Fps:"+str$(screen fps()): y=y+yh
EndFunction
Posted: 23rd Jan 2003 21:01
Please send me the shader examples: regulyistvan@hotmail.com
Posted: 24th Jan 2003 0:10
ummm no Idea what shader examples your talking about
Posted: 24th Jan 2003 4:34
lmao... don't worry about that guy he's spamming alot
seems to be pretty good, i'd replace alot of the arrays with types for a single array if i were you but on the whole this is certainly interest peaking
Posted: 24th Jan 2003 5:04
lol yeah I found that out after I moved on and found his spam on a hundred other posts... This was actually some older code I had.. in the project Im currently working on I'm using types.
What i need to work on is a Decent way to update an object from a memblock. the lack of direct access to the objects in memory makes for slow and awkward code...( unless of course im missing something).
Posted: 24th Jan 2003 13:14
well personally i use an array to store and edit the model data (much easier within pro as you can actually contain it to 2 arrays with single elements with types)

you then use a memblock to write the model, or you could always have the same model and only update what you have to.
if you use a type the point is you can actualy edit vertex directly ...

i.e.
type test_vertex
x as float
y as float
z as float
endtype

type dbo_mdl
vertex as test_vertex
endtype
dim pArray(4028) as dbo_mdl

so from that you have pArray(vertex/face index).vertex.x
and you can then edit that value
so you have the whole model in more human terms

see what i'd like to see is open and type arrays so you can combine them into a single type you declare per model and the array can grow to however many vertex and face's you have
Posted: 24th Jan 2003 17:53
@Raven

thanks - this script is pretty useful, although my code is pretty similar. It is reasonably fast as well - usually mesh deformations don't have to be done too quickly.
Posted: 25th Jan 2003 21:22
well that code isn't thought for speed... more for ease of use
Posted: 15th Mar 2003 15:21
Hey, something is missing at the selectvertex(vcount2)function:

if mousex() object screen x(vert+3)-5
if mousey() object screen y(vert+3)-5

those lines do not compile, which should be the comparative ("=" perharps although it does not work)?

I'm working on realtime mesh deformation. This example is very nice.

Thanks!