Heres the code for you Pincho,hope it comes in handy,be aware that the leaves are not part of the branch object,give me a few hours and ill add them in as another limb so you can position the whole tree as one object.
`%ProjectTitle%
`======================
`©P.Parkinson
`======================
`Main Source File
`*********************************
`enviroment set up
IF CHECK DISPLAY MODE(1024,768,32)
SET DISPLAY MODE 1024,768,32
h=DESKTOP HEIGHT()
w=DESKTOP WIDTH()
posx=w/2-512
posy=h/2-384
ELSE
SET DISPLAY MODE 640,480,32
h=DESKTOP HEIGHT()
w=DESKTOP WIDTH()
posx=w/2-320
posy=h/2-240
ENDIF
SET WINDOW POSITION posx,posy
SYNC ON
SYNC RATE 60
AUTOCAM OFF
HIDE MOUSE
COLOR BACKDROP 0,0
SET TEXT FONT "Arial"
SET TEXT SIZE 12
SET TEXT TRANSPARENT
POSITION CAMERA -50,50,-200
POINT CAMERA 0,0,0
POSITION MOUSE SCREEN WIDTH()/2,SCREEN HEIGHT()/2
dummy=MOUSEMOVEX()
dummy=MOUSEMOVEY()
RANDOMIZE TIMER()
SYNC
SYNC
`*********************************
`declarations and setup starts here
make_test_texture()
TYPE branch_type
used AS INTEGER
posx AS FLOAT
posy AS FLOAT
posz AS FLOAT
angx AS FLOAT
angy AS FLOAT
angz AS FLOAT
num_sections AS INTEGER
start_size AS FLOAT
ENDTYPE
TYPE branch_data_type
obj AS INTEGER
posx AS FLOAT
posy AS FLOAT
posz AS FLOAT
angx AS FLOAT
angy AS FLOAT
angz AS FLOAT
size AS FLOAT
section AS INTEGER
step_size AS FLOAT
ENDTYPE
GLOBAL max_branches AS INTEGER=25
DIM branch(max_branches) AS branch_type
GLOBAL max_sections AS INTEGER=40
DIM branch_data(max_branches,max_sections) AS branch_data_type
GLOBAL max_size AS FLOAT:max_size=10.0
GLOBAL max_step_size AS FLOAT:max_step_size=3.5
GLOBAL step_size AS FLOAT
GLOBAL bend AS FLOAT:bend=40.0
GLOBAL used_branches AS INTEGER=0
GLOBAL hide AS INTEGER=1
GLOBAL num_objects AS INTEGER=0
GLOBAL tree_section AS INTEGER
make_tree_section()
clear_data()
make_tree()
GLOBAL tree_model AS INTEGER
tree_model=free_object()
make_tree_object(tree_model)
obj=free_object()
MAKE OBJECT PLAIN obj,500,500,32,32,274
SET OBJECT WIREFRAME obj,1
``make sphere markers for end of branches
make_leaves_texture()
GLOBAL first_marker AS INTEGER=90000
FOR l=1 TO max_branches
// MAKE OBJECT SPHERE first_marker+l,3
// COLOR OBJECT first_marker+l,RGB(255,0,0)
make_bush(first_marker+l,RND(30)+10)
POSITION OBJECT first_marker+l,branch_data(l,branch(l).num_sections).posx,branch_data(l,branch(l).num_sections).posy,branch_data(l,branch(l).num_sections).posz
NEXT l
`*********************************
`main loop starts here
DO
IF SPACEKEY()
TEXT 0,0,"Please Wait"
SYNC
clear_data()
make_tree()
make_tree_object(tree_model)
``reposition the markers
FOR l=1 TO max_branches
POSITION OBJECT first_marker+l,branch_data(l,branch(l).num_sections).posx,branch_data(l,branch(l).num_sections).posy,branch_data(l,branch(l).num_sections).posz
NEXT l
ENDIF
mouse_control(1.0)
TEXT 0,0,"FPS "+STR$(SCREEN FPS())+" Press Space To Re-Generate"
SYNC
LOOP
`*********************************
`functions start here
FUNCTION mouse_control(speed AS FLOAT)
XROTATE CAMERA CAMERA ANGLE X()+MOUSEMOVEY()
YROTATE CAMERA CAMERA ANGLE Y()+MOUSEMOVEX()
IF MOUSECLICK()=1 THEN MOVE CAMERA speed
IF MOUSECLICK()=2 THEN MOVE CAMERA (0-speed)
dummy=MOUSEMOVEX()
dummy=MOUSEMOVEY()
ENDFUNCTION
FUNCTION free_object()
num_objects=0
REPEAT
INC i
IF OBJECT EXIST(i)=0
found=1
ELSE
INC num_objects
ENDIF
UNTIL found
ENDFUNCTION i
FUNCTION make_tree()
``make trunk
branch(used_branches).used=1
branch(used_branches).posx=0.0
branch(used_branches).posy=0.0
branch(used_branches).posz=0.0
branch(used_branches).angx=-90.0
branch(used_branches).angy=0.0
branch(used_branches).angz=0.0
branch(used_branches).num_sections=max_sections
branch(used_branches).start_size=max_size
obj=free_object()
scale#=branch(used_branches).start_size/(max_size/100)
CLONE OBJECT obj,tree_section
SCALE OBJECT obj,scale#,scale#,100
``MAKE OBJECT SPHERE obj,branch(used_branches).start_size
IF hide=1 THEN HIDE OBJECT obj
POSITION OBJECT obj,branch(used_branches).posx,branch(used_branches).posy,branch(used_branches).posz
ROTATE OBJECT obj,branch(used_branches).angx,branch(used_branches).angy,branch(used_branches).angz
branch_data(used_branches,1).obj=obj
branch_data(used_branches,1).posx=branch(used_branches).posx
branch_data(used_branches,1).posy=branch(used_branches).posy
branch_data(used_branches,1).posz=branch(used_branches).posz
branch_data(used_branches,1).angx=branch(used_branches).angx
branch_data(used_branches,1).angy=branch(used_branches).angy
branch_data(used_branches,1).angz=branch(used_branches).angz
branch_data(used_branches,1).size=branch(used_branches).start_size
branch_data(used_branches,1).section=1
step_size=max_step_size
branch_data(used_branches,1).step_size=step_size
FOR l=2 TO branch(used_branches).num_sections
obj=free_object()
new_size#=(branch(used_branches).start_size/max_sections)*(max_sections-l)
scale#=new_size#/(max_size/100)
CLONE OBJECT obj,tree_section
SCALE OBJECT obj,scale#,scale#,100
``MAKE OBJECT SPHERE obj,new_size#
IF hide=1 THEN HIDE OBJECT obj
ok=1
DO
POSITION OBJECT obj,branch_data(used_branches,l-1).posx,branch_data(used_branches,l-1).posy,branch_data(used_branches,l-1).posz
SET OBJECT TO OBJECT ORIENTATION obj,branch_data(used_branches,l-1).obj
IF l>2
XROTATE OBJECT obj,WRAPVALUE(OBJECT ANGLE X(obj)+RND(bend/2.0)-(bend/4.0))
YROTATE OBJECT obj,WRAPVALUE(OBJECT ANGLE Y(obj)+RND(bend/2.0)-(bend/4.0))
ZROTATE OBJECT obj,WRAPVALUE(OBJECT ANGLE Z(obj)+RND(bend/2.0)-(bend/4.0))
ENDIF
MOVE OBJECT obj,step_size
IF OBJECT POSITION Y(obj)>0 THEN ok=1
IF ok=1 THEN EXIT
LOOP
branch_data(used_branches,l).obj=obj
branch_data(used_branches,l).posx=OBJECT POSITION X(obj)
branch_data(used_branches,l).posy=OBJECT POSITION Y(obj)
branch_data(used_branches,l).posz=OBJECT POSITION Z(obj)
branch_data(used_branches,l).angx=OBJECT ANGLE X(obj)
branch_data(used_branches,l).angy=OBJECT ANGLE Y(obj)
branch_data(used_branches,l).angz=OBJECT ANGLE Z(obj)
branch_data(used_branches,l).size=new_size#
branch_data(used_branches,l).section=l
IF step_size>branch_data(used_branches,l).size THEN step_size=step_size*0.99
branch_data(used_branches,l).step_size=step_size
NEXT l
INC used_branches
``make branches
FOR ll=2 TO max_branches
IF used_branches>max_branches/3
branch_to_use=RND(used_branches)-1
ELSE
branch_to_use=1
ENDIF
IF branch_to_use<1 THEN branch_to_use=1
section_to_use=RND(branch(branch_to_use).num_sections)
IF branch_to_use=1
IF section_to_use<10 THEN section_to_use=10
ELSE
IF section_to_use<2 THEN section_to_use=2
ENDIF
branch(used_branches).used=1
branch(used_branches).posx=branch_data(branch_to_use,section_to_use).posx
branch(used_branches).posy=branch_data(branch_to_use,section_to_use).posy
branch(used_branches).posz=branch_data(branch_to_use,section_to_use).posz
branch(used_branches).angx=branch_data(branch_to_use,section_to_use).angx
branch(used_branches).angy=branch_data(branch_to_use,section_to_use).angy
branch(used_branches).angz=branch_data(branch_to_use,section_to_use).angz
branch(used_branches).num_sections=branch(branch_to_use).num_sections-branch_data(branch_to_use,section_to_use).section
branch(used_branches).start_size=branch_data(branch_to_use,section_to_use).size
obj=free_object()
scale#=branch(used_branches).start_size/(max_size/100)
CLONE OBJECT obj,tree_section
SCALE OBJECT obj,scale#,scale#,100
``MAKE OBJECT SPHERE obj,branch(used_branches).start_size
IF hide=1 THEN HIDE OBJECT obj
POSITION OBJECT obj,branch(used_branches).posx,branch(used_branches).posy,branch(used_branches).posz
ROTATE OBJECT obj,branch(used_branches).angx,branch(used_branches).angy,branch(used_branches).angz
XROTATE OBJECT obj,WRAPVALUE(OBJECT ANGLE X(obj)+RND(bend)-(bend/2.0))
YROTATE OBJECT obj,WRAPVALUE(OBJECT ANGLE Y(obj)+RND(bend)-(bend/2.0))
ZROTATE OBJECT obj,WRAPVALUE(OBJECT ANGLE Z(obj)+RND(bend)-(bend/2.0))
IF branch_to_use>1 THEN COLOR OBJECT obj,RGB(255,0,0)
branch_data(used_branches,1).obj=obj
branch_data(used_branches,1).posx=branch(used_branches).posx
branch_data(used_branches,1).posy=branch(used_branches).posy
branch_data(used_branches,1).posz=branch(used_branches).posz
branch_data(used_branches,1).angx=branch(used_branches).angx
branch_data(used_branches,1).angy=branch(used_branches).angy
branch_data(used_branches,1).angz=branch(used_branches).angz
branch_data(used_branches,1).size=branch(used_branches).start_size
branch_data(used_branches,1).section=1
step_size=branch_data(branch_to_use,section_to_use).step_size
FOR l=2 TO branch(used_branches).num_sections
obj=free_object()
new_size#=(branch(used_branches).start_size)/branch(used_branches).num_sections*(branch(used_branches).num_sections-l)
scale#=new_size#/(max_size/100)
CLONE OBJECT obj,tree_section
SCALE OBJECT obj,scale#,scale#,100
``MAKE OBJECT SPHERE obj,new_size#
IF hide=1 THEN HIDE OBJECT obj
ok=1
DO
POSITION OBJECT obj,branch_data(used_branches,l-1).posx,branch_data(used_branches,l-1).posy,branch_data(used_branches,l-1).posz
SET OBJECT TO OBJECT ORIENTATION obj,branch_data(used_branches,l-1).obj
IF l>4
XROTATE OBJECT obj,WRAPVALUE(OBJECT ANGLE X(obj)+RND(bend)-(bend/2.0))
YROTATE OBJECT obj,WRAPVALUE(OBJECT ANGLE Y(obj)+RND(bend)-(bend/2.0))
ZROTATE OBJECT obj,WRAPVALUE(OBJECT ANGLE Z(obj)+RND(bend)-(bend/2.0))
ENDIF
MOVE OBJECT obj,step_size
IF OBJECT POSITION Y(obj)>0 THEN ok=1
IF ok=1 THEN EXIT
LOOP
IF branch_to_use>1 THEN COLOR OBJECT obj,RGB(255,0,0)
branch_data(used_branches,l).obj=obj
branch_data(used_branches,l).posx=OBJECT POSITION X(obj)
branch_data(used_branches,l).posy=OBJECT POSITION Y(obj)
branch_data(used_branches,l).posz=OBJECT POSITION Z(obj)
branch_data(used_branches,l).angx=OBJECT ANGLE X(obj)
branch_data(used_branches,l).angy=OBJECT ANGLE Y(obj)
branch_data(used_branches,l).angz=OBJECT ANGLE Z(obj)
branch_data(used_branches,l).size=new_size#
branch_data(used_branches,l).section=l
IF step_size>branch_data(used_branches,l).size THEN step_size=step_size*0.99
branch_data(used_branches,l).step_size=step_size
NEXT l
// POINT CAMERA branch_data(used_branches,1).posx,branch_data(used_branches,1).posy,branch_data(used_branches,1).posz
// TEXT 0,0,STR$(branch_to_use)+" "+STR$(section_to_use)
// TEXT 0,20,STR$(branch_data(used_branches,1).posx)+" posx "+STR$(branch_data(used_branches,1).posy)+" posy "+STR$(branch_data(used_branches,1).posz)+" posz "
// TEXT 0,40,STR$(branch(used_branches).num_sections)+" sections"
// TEXT 0,60,STR$(used_branches)+" branches"
// TEXT 0,80,STR$(num_objects)+" num objects"
// TEXT 0,100,STR$(branch(used_branches).start_size)+" start size"
// TEXT 0,120,STR$(step_size)+" step size"
// SYNC
// DO
// IF INKEY$()="n"
// WAIT 100
// EXIT
// ENDIF
// LOOP
INC used_branches
NEXT ll
ENDFUNCTION
FUNCTION clear_data()
FOR l=1 TO max_branches
branch(l).used=0
branch(l).posx=0.0
branch(l).posy=0.0
branch(l).posz=0.0
branch(l).angx=-0.0
branch(l).angy=0.0
branch(l).angz=0.0
branch(l).num_sections=0
branch(l).start_size=0.0
FOR ll=1 TO max_sections
IF branch_data(l,ll).obj>0
IF OBJECT EXIST(branch_data(l,ll).obj) THEN DELETE OBJECT branch_data(l,ll).obj
ENDIF
branch_data(l,ll).obj=0
branch_data(l,ll).posx=0
branch_data(l,ll).posy=0
branch_data(l,ll).posz=0
branch_data(l,ll).angx=0
branch_data(l,ll).angy=0
branch_data(l,ll).angz=0
branch_data(l,ll).size=0
branch_data(l,ll).section=0
branch_data(l,ll).step_size=0
NEXT ll
NEXT l
used_branches=1
ENDFUNCTION
FUNCTION make_tree_section()
tree_section=free_object()
MAKE OBJECT CUBE tree_section,1
obj=free_object()
MAKE OBJECT CUBE obj,1
MAKE MESH FROM OBJECT 1,obj
FOR l=1 TO 18
POSITION OBJECT obj,COS(l*20)*max_size/2.0,SIN(l*20)*max_size/2.0,0
ADD LIMB tree_section,l,1
OFFSET LIMB tree_section,l,OBJECT POSITION X(obj),OBJECT POSITION y(obj),0
NEXT l
DELETE OBJECT obj
DELETE MESH 1
HIDE OBJECT tree_section
COLOR LIMB tree_section,1,RGB(255,0,0)
COLOR LIMB tree_section,8,RGB(0,255,0)
ENDFUNCTION
FUNCTION make_tree_object(obj)
IF OBJECT EXIST(obj) THEN DELETE OBJECT obj
MAKE OBJECT CUBE obj,1
convert object fvf obj,338
lmb=1
FOR b=1 TO max_branches
sections=branch(b).num_sections
IF sections>1
num_vertices=(sections-1)*120
create_memblockobject(1,num_vertices)
v=0
FOR s=1 TO sections-1
FOR l=1 TO 17
px#=LIMB POSITION X (branch_data(b,s).obj,l):py#=LIMB POSITION Y (branch_data(b,s).obj,l):pz#=LIMB POSITION Z (branch_data(b,s).obj,l)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),0.0,0.0)
INC v
px#=LIMB POSITION X (branch_data(b,s+1).obj,l+1):py#=LIMB POSITION Y (branch_data(b,s+1).obj,l+1):pz#=LIMB POSITION Z (branch_data(b,s+1).obj,l+1)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),1.0,1.0)
INC v
px#=LIMB POSITION X (branch_data(b,s+1).obj,l):py#=LIMB POSITION Y (branch_data(b,s+1).obj,l):pz#=LIMB POSITION Z (branch_data(b,s+1).obj,l)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),1.0,0.0)
INC v
px#=LIMB POSITION X (branch_data(b,s).obj,l):py#=LIMB POSITION Y (branch_data(b,s).obj,l):pz#=LIMB POSITION Z (branch_data(b,s).obj,l)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),0.0,0.0)
INC v
px#=LIMB POSITION X (branch_data(b,s).obj,l+1):py#=LIMB POSITION Y (branch_data(b,s).obj,l+1):pz#=LIMB POSITION Z (branch_data(b,s).obj,l+1)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),0.0,1.0)
INC v
px#=LIMB POSITION X (branch_data(b,s+1).obj,l+1):py#=LIMB POSITION Y (branch_data(b,s+1).obj,l+1):pz#=LIMB POSITION Z (branch_data(b,s+1).obj,l+1)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),1.0,1.0)
INC v
NEXT l
px#=LIMB POSITION X (branch_data(b,s).obj,18):py#=LIMB POSITION Y (branch_data(b,s).obj,18):pz#=LIMB POSITION Z (branch_data(b,s).obj,18)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),0.0,0.0)
INC v
px#=LIMB POSITION X (branch_data(b,s+1).obj,1):py#=LIMB POSITION Y (branch_data(b,s+1).obj,1):pz#=LIMB POSITION Z (branch_data(b,s+1).obj,1)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),1.0,1.0)
INC v
px#=LIMB POSITION X (branch_data(b,s+1).obj,18):py#=LIMB POSITION Y (branch_data(b,s+1).obj,18):pz#=LIMB POSITION Z (branch_data(b,s+1).obj,18)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),1.0,0.0)
INC v
px#=LIMB POSITION X (branch_data(b,s).obj,18):py#=LIMB POSITION Y (branch_data(b,s).obj,18):pz#=LIMB POSITION Z (branch_data(b,s).obj,18)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),0.0,0.0)
INC v
px#=LIMB POSITION X (branch_data(b,s).obj,1):py#=LIMB POSITION Y (branch_data(b,s).obj,1):pz#=LIMB POSITION Z (branch_data(b,s).obj,1)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),0.0,1.0)
INC v
px#=LIMB POSITION X (branch_data(b,s+1).obj,1):py#=LIMB POSITION Y (branch_data(b,s+1).obj,1):pz#=LIMB POSITION Z (branch_data(b,s+1).obj,1)
create_vertex(1,v,px#,py#,pz#,RGB(255,255,255),1.0,1.0)
INC v
NEXT s
IF MESH EXIST(1) THEN DELETE MESH 1
MAKE MESH FROM MEMBLOCK 1,1
add limb obj,lmb,1
inc lmb
ENDIF
NEXT b
TEXTURE OBJECT obj,1
SET OBJECT NORMALS obj
set object smoothing obj,25
ENDFUNCTION
FUNCTION create_memblockobject(memnum,v)
IF MEMBLOCK EXIST(memnum) THEN DELETE MEMBLOCK memnum
MAKE MEMBLOCK memnum,12+(36*v)
WRITE MEMBLOCK DWORD memnum,0,338
WRITE MEMBLOCK DWORD memnum,4,36
WRITE MEMBLOCK DWORD memnum,8,v
ENDFUNCTION
FUNCTION create_vertex(memnum,v,vposx#,vposy#,vposz#,color AS DWORD,u#,v#)
WRITE MEMBLOCK FLOAT memnum,v*36+12,vposx#
WRITE MEMBLOCK FLOAT memnum,v*36+16,vposy#
WRITE MEMBLOCK FLOAT memnum,v*36+20,vposz#
WRITE MEMBLOCK DWORD memnum,v*36+36,color `not needed in 274fvf format diffuse color seems to mess up some shader code
WRITE MEMBLOCK FLOAT memnum,v*36+40,u#
WRITE MEMBLOCK FLOAT memnum,v*36+44,v#
ENDFUNCTION
FUNCTION set_normal(memnum,v,normalx#,normaly#,normalz#)
WRITE MEMBLOCK FLOAT memnum,v*36+24,normalx#
WRITE MEMBLOCK FLOAT memnum,v*36+28,normaly#
WRITE MEMBLOCK FLOAT memnum,v*36+32,normalz#
ENDFUNCTION
FUNCTION make_object(objnum,meshnum,memnum,imgnum)
IF OBJECT EXIST (objnum) THEN DELETE OBJECT objnum
IF MESH EXIST (meshnum) THEN DELETE MESH meshnum
MAKE MESH FROM MEMBLOCK meshnum,memnum
MAKE OBJECT objnum,meshnum,imgnum
ENDFUNCTION
FUNCTION make_test_texture()
box 0,0,128,128,rgb(130,100,50)
FOR l=1 TO 10000
col1=RND(20)
col2=RND(20)
dot rnd(128),rnd(128),rgb(65+col1,50+col2,25)
NEXT l
get image 1,0,0,32,32
ENDFUNCTION
FUNCTION make_leaves_texture()
CLS
FOR l=1 TO 50000
xs=RND(256)
ys=RND(256)
col=RGB(0,RND(100)+100,0)
IF RND(100)<50
col=RGB(RND(40)+40,RND(40),0)
ENDIF
DOT xs,ys,col
NEXT l
GET IMAGE 2,0,0,256,256
`set image alpha
MAKE MEMBLOCK FROM IMAGE 1,2
DELETE IMAGE 2
pos=12
FOR y=1 TO 256
FOR x=1 TO 256
b=MEMBLOCK BYTE (1,pos):INC pos
g=MEMBLOCK BYTE (1,pos):INC pos
r=MEMBLOCK BYTE (1,pos):INC pos
IF g<=0
WRITE MEMBLOCK BYTE 1,pos,0
ELSE
WRITE MEMBLOCK BYTE 1,pos,255
ENDIF
INC pos
NEXT x
NEXT y
MAKE IMAGE FROM MEMBLOCK 2,1
DELETE MEMBLOCK 1
ENDFUNCTION
FUNCTION make_bush(obj,size#)
`leaves
MAKE OBJECT SPHERE obj,size#,20,20
`TRICK TO CHANGE obj+1ECT TO NO SHARED VERTICES FORMAT ===========================
MAKE MESH FROM OBJECT 1,obj
DELETE OBJECT obj
MAKE MEMBLOCK FROM MESH 1,1
MAKE MESH FROM MEMBLOCK 1,1
DELETE MEMBLOCK 1
MAKE OBJECT obj,1,0
LOCK VERTEXDATA FOR LIMB obj,0,1
nv=GET VERTEXDATA VERTEX COUNT()
FOR l=0 TO nv-1
xv#=GET VERTEXDATA POSITION X(l)
yv#=GET VERTEXDATA POSITION Y(l)
zv#=GET VERTEXDATA POSITION Z(l)
SET VERTEXDATA POSITION l,xv#+RND(size#/4.0)-size#/8.0,yv#+RND(size#/4.0)-size#/8.0,zv#+RND(size#/4.0)-size#/8.0
NEXT l
UNLOCK VERTEXDATA
SCALE OBJECT obj,RND(30)+100,RND(20)+80,RND(30)+100
TEXTURE OBJECT obj,2
SET OBJECT TRANSPARENCY obj,4
ZROTATE OBJECT obj,RND(10.0)-5.0
YROTATE OBJECT obj,RND(10.0)-5.0
ENDFUNCTION