The command is
lock vertexdata for limb and
unlock vertexdata. I haven't used those commands to remove data from meshes and I think it doesn't support that anyway (correct me if I'm wrong).
If speed is not an issue then I do have an answer for you using memblocks. The commands we'll be looking at are:
make mesh from object
make memblock from mesh
make mesh from memblock
update object mesh <-- I'm actually not sure if this is correct
Before we dive into that however, let's quickly go over the theory of what we want to achieve. Let's say you have 5 polygons in your object and want to remove one of them via memblocks. Here's a simplified structure of the data:
-header
--> FVF
--> Vertex Size (in bytes)
--> Vertex Count
-data
--> Polygon 1
----> Vertex 1
----> Vertex 2
----> Vertex 3
--> Polygon 2
----> Vertex 1
----> Vertex 2
----> Vertex 3
--> Polygon 3
----> Vertex 1
----> Vertex 2
----> Vertex 3
--> Polygon 4
----> Vertex 1
----> Vertex 2
----> Vertex 3
--> Polygon 5
----> Vertex 1
----> Vertex 2
----> Vertex 3
Say you wanted to remove polygon 3. It's not as easy as simply deleting the data, because you'll then have this:
-header
--> FVF
--> Vertex Size (in bytes)
--> Vertex Count
-data
--> Polygon 1
----> Vertex 1
----> Vertex 2
----> Vertex 3
--> Polygon 2
----> Vertex 1
----> Vertex 2
----> Vertex 3
--> Polygon 3
----> (EMPTY DATA)
----> (EMPTY DATA)
----> (EMPTY DATA)
--> Polygon 4
----> Vertex 1
----> Vertex 2
----> Vertex 3
--> Polygon 5
----> Vertex 1
----> Vertex 2
----> Vertex 3
What we have to do is shift all of the data proceeding after Polygon 3 so it overwrites it:
-header
--> FVF
--> Vertex Size (in bytes)
--> Vertex Count
-data
--> Polygon 1
----> Vertex 1
----> Vertex 2
----> Vertex 3
--> Polygon 2
----> Vertex 1
----> Vertex 2
----> Vertex 3
--> Polygon 4
----> Vertex 1
----> Vertex 2
----> Vertex 3
--> Polygon 5
----> Vertex 1
----> Vertex 2
----> Vertex 3
--> ?
----> (EMPTY DATA)
----> (EMPTY DATA)
----> (EMPTY DATA)
And then we can shorten the size of the memblock so we can drop the last polygon:
-header
--> FVF
--> Vertex Size (in bytes)
--> Vertex Count
-data
--> Polygon 1
----> Vertex 1
----> Vertex 2
----> Vertex 3
--> Polygon 2
----> Vertex 1
----> Vertex 2
----> Vertex 3
--> Polygon 4
----> Vertex 1
----> Vertex 2
----> Vertex 3
--> Polygon 5
----> Vertex 1
----> Vertex 2
----> Vertex 3
We will also have to change some of the header data in order to really remove the polygon. So how does this look with code? Let's get started. *Cracks Knuckles like always*
First of all, we need to convert the object into a memblock so we can edit it. Pretty straight forward:
function RemovePolygon( Obj , Index )
rem local variables
local FVF as dword
local vertSize as dword
local vertCount as dword
local FreeMesh as dword
local FreeMem as dword
rem convert object to memblock
FreeMesh = find free mesh()
FreeMem = find free memblock()
make mesh from object Obj , FreeMesh
make memblock from mesh FreeMesh , FreeMem
rem do manipulation here
rem convert back to object
make mesh from memblock FreeMem , FreeMesh
update object mesh Obj , FreeMesh
rem clean up
delete memblock FreeMem
delete mesh FreeMesh
endfunction
As we discussed above, we will need to shift all of the data down. Depending on the
flexible vertex format (FVF) the vertex is going to have different sizes in the memblock. Don't worry too much about that, the size of the vertices is saved in the header of the memblock in bytes, so we're going to read the header and then shift all of the data after the deleted polygon up. Here's the code:
function RemovePolygon( Obj , Index )
rem local variables
local FVF as dword
local vertSize as dword
local vertCount as dword
local FreeMesh as dword
local FreeMem as dword
local i as integer
rem convert object to memblock
FreeMesh = find free mesh()
FreeMem = find free memblock()
make mesh from object Obj , FreeMesh
make memblock from mesh FreeMesh , FreeMem
rem read header
FVF = memblock dword( FreeMem , 0 )
vertSize = memblock dword( FreeMem , 4 )
vertCount = memblock dword( FreeMem , 8 )
rem make sure polygon actually exists
Index = Index*3 : rem because every polygon consists of 3 vertices
if Index > vertCount
delete memblock FreeMem
delete mesh FreeMesh
exitfunction
endif
rem there's no use shifting the data if you're removing the very last polygon
if Index < vertCount-3
rem shift data and overwrite polygon
for i = Index*vertSize+12 to (vertCount-3)*vertSize+12 step 4
write memblock dword FreeMem , i , memblock dword( FreeMem , (i+(vertSize*3)) )
next i
endif
rem change vertex count in header
write memblock dword FreeMem , 8 , vertCount-3
rem convert back to object
make mesh from memblock FreeMem , FreeMesh
update object mesh Obj , FreeMesh
rem clean up
delete memblock FreeMem
delete mesh FreeMesh
endfunction
I hope that works, I'll be in range of a DBP compiler in a few hours and will hopefully remember to check on this again.
TheComet
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown