Posted: 9th Mar 2003 20:41
Hi,

I've submitted a set of wrapper functions for editing a model at vertex level.

Hope they help people.

Issues:

1.DOES NOT work in DB Classic

2.DOES NOT work in Patch 4.3

3.Definitely does work with 3.1

4.It uses a memblock 1 and a mesh one - if you have these elsewhere in a project you'll need to change the numbers of the memblock and the mesh in the functions.

5.They could be made faster in a few ways. For every function it creates the mesh from the object, memblock from the mesh then once it is finished it deletes the memblock. If it was set up to just make the memblock once - perhaps an initialise command? then it would increase the speed. I didn't do this optimisation because I wanted them all to be fairly standalone.

6. All co-ordinates are relative to the position of the object - bear that in mind when amending models. So if the model is positioned at 10,100,15 then you'd add 10 to the vertex X co-ordinate to get its absolute position in 3D space, you'd add 100 to the Y and 15 to the Z.

Any problems please tell me so I can improve on these. Any other functions you wish me to add, ditto.

Commands:

Vertices(ObjectNo)
Returns the number of vertices in the Object

VertexX(ObjNo,VertexNo)
VertexY(ObjNo,VertexNo)
VertexZ(ObjNo,VertexNo)
These 3 return the relative position of the vertex in X Y and Z planes. (Its relative to the centre of the object)

Position_Vertex(ObjNo,VertexNo,X#,Y#,Z#)
Positions the vertex relative to the objects centre.

Amend_Vertex_Normals(ObjNo,VertexNo,X#,Y#,Z#)
Amends the Normals of the Vertex. YOu can get some nice shading effects using this command.

Amend_Vertex_Diffuse(ObjNo,VertexNo,Colour)
Amends the diffuse color of the Vertex. Great for gradiant colour fx on the object.


Function Vertices(ObjNo)
`Returns number of Vertices
`Vars
MeshNo=100
make mesh from object MeshNo,ObjNo
NoVerts=0
`Make your meshes and memblocks
make memblock from mesh 1,MeshNo
`Calculate no of vertices
NoVerts=memblock dword(1,8)
`Tidy
delete memblock 1
endfunction NoVerts



Function VertexX(ObjNo,VertexNo)
`Returns X position of specified vertex
MeshNo=100
make mesh from object MeshNo,ObjNo
NoVerts=0
`Make Memblock
make memblock from mesh 1,MeshNo
`Calculate no of vertices
NoVerts=memblock dword(1,8)
If VertexNo
Posted: 9th Mar 2003 20:43
Ooops.

+ Code Snippet
Function Vertices(ObjNo)
`Returns number of Vertices
`Vars
MeshNo=100
make mesh from object MeshNo,ObjNo
NoVerts=0
`Make your meshes and memblocks
make memblock from mesh 1,MeshNo
`Calculate no of vertices
NoVerts=memblock dword(1,8)
`Tidy
delete memblock 1
endfunction NoVerts



Function VertexX(ObjNo,VertexNo)
`Returns X position of specified vertex
MeshNo=100
make mesh from object MeshNo,ObjNo
NoVerts=0
`Make Memblock
make memblock from mesh 1,MeshNo
`Calculate no of vertices
NoVerts=memblock dword(1,8)
If VertexNo<NoVerts
`Get values of vertex cords
ValueX#=memblock float(1,12+((VertexNo*36)-36))
endif
`Tidy Up
delete memblock 1
endfunction ValueX#



Function VertexY(ObjNo,VertexNo)
`Returns Y position of specified vertex
MeshNo=100
make mesh from object MeshNo,ObjNo
NoVerts=0
`Make Memblock
make memblock from mesh 1,MeshNo
`Calculate no of vertices
NoVerts=memblock dword(1,8)
If VertexNo<NoVerts
`Get values of vertex cords
ValueY#=memblock float(1,12+((VertexNo*36)-32))
endif
`Tidy Up
delete memblock 1
endfunction ValueY#



Function VertexZ(ObjNo,VertexNo)
`Returns Z position of specified vertex
MeshNo=100
make mesh from object MeshNo,ObjNo
NoVerts=0
`Make Memblock
make memblock from mesh 1,MeshNo
`Calculate no of vertices
NoVerts=memblock dword(1,8)
If VertexNo<NoVerts
`Get values of vertex cords
ValueZ#=memblock float(1,12+((VertexNo*36)-28))
endif
`Tidy Up
delete memblock 1
endfunction ValueZ#




Function Position_Vertex(ObjNo,VertexNo,X#,Y#,Z#)
`Moves the Vertex
MeshNo=100
make mesh from object MeshNo,ObjNo
NoVerts=0
`Make Memblock
make memblock from mesh 1,MeshNo
`Calculate no of vertices
NoVerts=memblock dword(1,8)
If VertexNo<NoVerts
`Get values of vertex cords
write memblock float 1,12+((VertexNo*36)-36),X#
write memblock float 1,12+((VertexNo*36)-32),Y#
write memblock float 1,12+((VertexNo*36)-28),Z#
`Change the mesh
change mesh from memblock MeshNo,1
endif
`Tidy Up
change mesh ObjNo,0,MeshNo
delete memblock 1
endfunction




Function Amend_Vertex_Normals(ObjNo,VertexNo,X#,Y#,Z#)
`Amends the Normals Data of the vertex
MeshNo=100
make mesh from object MeshNo,ObjNo
NoVerts=0
`Make Memblock
make memblock from mesh 1,MeshNo
`Calculate no of vertices
NoVerts=memblock dword(1,8)
If VertexNo<NoVerts
`Get values of vertex cords
write memblock float 1,12+((VertexNo*36)-24),X#
write memblock float 1,12+((VertexNo*36)-20),Y#
write memblock float 1,12+((VertexNo*36)-16),Z#
`Change the mesh
change mesh from memblock MeshNo,1
endif
`Tidy Up
change mesh ObjNo,0,MeshNo
delete memblock 1
endfunction



Function Amend_Vertex_Diffuse(ObjNo,VertexNo,Diff)
`Amends the Diffuse Colour of the vertex
MeshNo=100
make mesh from object MeshNo,ObjNo
NoVerts=0
`Make Memblock
make memblock from mesh 1,MeshNo
`Calculate no of vertices
NoVerts=memblock dword(1,8)
If VertexNo<NoVerts
`Get values of vertex cords
write memblock dword 1,12+((VertexNo*36)-12),Diff

`Change the mesh
change mesh from memblock MeshNo,1
endif
`Tidy Up
change mesh ObjNo,0,MeshNo
delete memblock 1
endfunction
Posted: 22nd Mar 2003 15:09
From the amount of replies I've had I can see nobody really cares, but I thought I should mention that I've now tested this with the release candidate of patch 4 and it works ok.
Posted: 22nd Mar 2003 19:07
i dont see how you didnt get any posts were some one with a simerler item but by far less functionality got 8 this is a very usefull tool.

Damian