First, don't use memblocks
There! Got that out of the way.
There are commands provided by my plug-ins that allow you to create objects to spec from scratch.
The first command is
MAKE OBJECT NEW which will allow you to create a single-limb object with the number of vertices and indices that you specify.
Here's a simple multi-coloured cube built from vertex data:0
sync on
sync rate 60
sync sleep 1
autocam off
restore ObjectData
BuildObjectFromData(1)
position camera 0.0, 1.5, -5.0
point camera 0.0, 0.0, 0.0
position light 0, 0.0, 1.5, -5.0
point light 0, 0.0, 0.0, 0.0
do
xrotate object 1, wrapvalue( object angle x(1) + 0.25 )
yrotate object 1, wrapvalue( object angle y(1) + 0.5 )
zrotate object 1, wrapvalue( object angle z(1) + 1.0 )
sync
loop
function BuildObjectFromData(Object as integer)
local Vertices as integer
local Indices as integer
local Diffuse as dword
local Index as integer
local x as float
local y as float
local z as float
local nx as float
local ny as float
local nz as float
local i as integer
read Vertices
read Indices
make object new 1, Vertices, Indices, FVF_XYZ || FVF_NORMAL || FVF_DIFFUSE
lock vertexdata for limb 1, 0
for i = 0 to Vertices-1
read x, y, z
read nx, ny, nz
read Diffuse
set vertexdata position i, x, y, z
set vertexdata normals i, nx, ny, nz
set vertexdata diffuse i, Diffuse
next
for i = 0 to Indices-1
read Index
set indexdata i, Index
next
unlock vertexdata
endfunction
ObjectData:
data 24, 36 ` 24 vertices, 36 indices
` Vertex data
` x y z nx ny nz diffuse
data -1, -1, -1, 0, 0, -1, 0xffffffff ` Front face
data -1, 1, -1, 0, 0, -1, 0xff000000
data 1, 1, -1, 0, 0, -1, 0xffff0000
data 1, -1, -1, 0, 0, -1, 0xff00ff00
data -1, -1, 1, 0, 0, 1, 0xff0000ff ` Back face
data -1, 1, 1, 0, 0, 1, 0xffffff00
data 1, 1, 1, 0, 0, 1, 0xff00ffff
data 1, -1, 1, 0, 0, 1, 0xffff00ff
data -1, -1, -1, -1, 0, 0, 0xffffffff ` Left face
data -1, 1, -1, -1, 0, 0, 0xff000000
data -1, -1, 1, -1, 0, 0, 0xff0000ff
data -1, 1, 1, -1, 0, 0, 0xffffff00
data 1, -1, -1, 1, 0, 0, 0xff00ff00 ` Right face
data 1, 1, -1, 1, 0, 0, 0xffff0000
data 1, -1, 1, 1, 0, 0, 0xffff00ff
data 1, 1, 1, 1, 0, 0, 0xff00ffff
data -1, 1, -1, 0, 1, 0, 0xff000000 ` Top face
data 1, 1, -1, 0, 1, 0, 0xffff0000
data -1, 1, 1, 0, 1, 0, 0xffffff00
data 1, 1, 1, 0, 1, 0, 0xff00ffff
data -1, -1, -1, 0, -1, 0, 0xffffffff ` Bottom face
data 1, -1, -1, 0, -1, 0, 0xff00ff00
data -1, -1, 1, 0, -1, 0, 0xff0000ff
data 1, -1, 1, 0, -1, 0, 0xffff00ff
` Index data
data 0, 1, 2, 0, 2, 3 ` Front face
data 4, 6, 5, 4, 7, 6 ` Back face
data 8, 10, 9, 9, 10, 11 ` Left face
data 12, 13, 14, 14, 13, 15 ` Right face
data 16, 19, 17, 16, 18, 19 ` Top face
data 20, 21, 22, 21, 23, 22 ` Bottom face
` FVF constants
#constant FVF_XYZ = 0x002
#constant FVF_XYZRHW = 0x004
#constant FVF_NORMAL = 0x010
#constant FVF_PSIZE = 0x020
#constant FVF_DIFFUSE = 0x040
#constant FVF_SPECULAR = 0x080
#constant FVF_TEX0 = 0x000
#constant FVF_TEX1 = 0x100
#constant FVF_TEX2 = 0x200
#constant FVF_TEX3 = 0x300
#constant FVF_TEX4 = 0x400
#constant FVF_TEX5 = 0x500
#constant FVF_TEX6 = 0x600
#constant FVF_TEX7 = 0x700
#constant FVF_TEX8 = 0x800
The second command is actually a whole set of commands -
BEGIN NEW OBJECT / ADD NEW LIMB / FINISH NEW OBJECT - that you can use to build multi-limbed objects, linked how you wish.
Here's an example:
sync on
sync rate 60
autocam off
dot 0, 0, rgb(255, 0, 0)
get image 1, 0, 0, 1, 1
dot 0, 0, rgb(0, 255, 0)
get image 2, 0, 0, 1, 1
dot 0, 0, rgb(0, 0, 255)
get image 3, 0, 0, 1, 1
dot 0, 0, rgb(255, 255, 0)
get image 4, 0, 0, 1, 1
make object cube 1, 1.0
rotate object 1, 45.0, 0.0, 45.0
make mesh from object 1, 1
delete object 1
BEGIN NEW OBJECT
` Top Triangle, red
ADD NEW LIMB 3, 0, 274, 0
SET NEW LIMB NAME "T0"
SET NEW LIMB TEXTURE 1
SET NEW LIMB CULL 0
` Pivot limb, no mesh
Pivot = ADD NEW LIMB()
SET NEW LIMB NAME "Pivot"
SET NEW LIMB OFFSET 0.0, -1.0, 0.0
` Middle-bottom triangle - untextured, culled
Limb = ADD NEW LIMB(3, 0, 274, 0)
SET NEW LIMB NAME "T1"
SET NEW LIMB ROTATION 0.0, 180.0, 0.0
SET NEW LIMB PARENT Pivot
SET NEW LIMB CULL 1
` Right-bottom triangle, green
ADD NEW LIMB 3, 0, 274, 0
SET NEW LIMB NAME "T2"
SET NEW LIMB OFFSET 1.0, 0.0, 0.2
SET NEW LIMB TEXTURE 2
SET NEW LIMB PARENT Limb
SET NEW LIMB CULL 0
` Left-bottom triangle, blue, not affected by lights
ADD NEW LIMB 3, 0, 274, 0
SET NEW LIMB NAME "T3"
SET NEW LIMB OFFSET -1.0, 0.0, -0.2
SET NEW LIMB TEXTURE 3
SET NEW LIMB PARENT Limb
SET NEW LIMB CULL 0
SET NEW LIMB TRANSPARENT 1
SET NEW LIMB LIGHT 0
` Bottom cube, yellow, generated from mesh data
ADD NEW LIMB FROM MESH 1
SET NEW LIMB NAME "CUBE"
SET NEW LIMB OFFSET 0.0, -1.0, 0.0
SET NEW LIMB PARENT Limb
SET NEW LIMB CULL 0
SET NEW LIMB TEXTURE 4
FINISH NEW OBJECT 1
` Set vertex data for all limbs that have a name starting with 'T' (triangle)
for Limb = 0 to get limb count(1)
lock vertexdata for limb 1, Limb
if left$( limb name$(1, Limb), 1 ) = "T"
set vertexdata position 0, -1.0, 0.0, 0.0
set vertexdata normals 0, 0.0, 0.0, 1.0
set vertexdata position 1, 1.0, 0.0, 0.0
set vertexdata normals 1, 0.0, 0.0, 1.0
set vertexdata position 2, 0.0, 1.0, 0.0
set vertexdata normals 2, 0.0, 0.0, 1.0
endif
unlock vertexdata
next
color backdrop rgb(0, 0, 0)
move camera -4.0
move camera down 0.5
do
set cursor 0, 0
for i = 0 to get limb count(1)
print i; " -> "; padright$(limb name$(1, i), 10);
print " - Parent = "; num(get limb parent(1, i), 2);
print ", Child = "; num(get limb child(1, i), 2);
print ", Sibling = "; num(get limb sibling(1, i), 2)
next
yrotate object 1, wrapvalue(object angle y(1) + 1.5)
rotate limb 1, get limb by name(1, "Pivot"), 0.0, object angle y(1), 0.0
rotate limb 1, get limb by name(1, "Cube"), 0.0, wrapvalue(object angle y(1) * -3.0), 0.0
sync
loop
function Num(v as integer, Size as integer)
local Result as string
if v < 0
Result = padleft$("*", Size)
else
Result = padleft$(str$(v), Size)
endif
endfunction Result
If you have an existing object, then my plug-ins can't help directly (I'll look into it!).
The way to do it though is to create a new object with the number of vertices and indices that you want to add, then make a mesh of it, then use the ADD MESH TO VERTEXDATA command to add it to a locked limb.