loading multiple mesh's with one comand
Blitz3D Forums/Blitz3D Programming/loading multiple mesh's with one comand
ok i have some code to load a mesh to be used at verious time during the running of the application. what can i put before the actual loadmesh statment to load the files but give them different names that can later be called by mesh modifying comands?
;loading a mesh
MFolder$="Models"
Color(255,255,255)
mydir=ReadDir(Mfolder$)
Repeat
File$=NextFile$(mydir)
If file$="" Then Exit
If FileType(folder$+"\"+file$) = 2 Then
Print "Folder:" + file$
Else
Print "File:"+ file$
End If
Forever
loadmod$= Input$("Which do you want To load?")
CloseDir mydir
selobjanim=0
**what do i put here?**=LoadMesh(MFolder$ + "\" + loadmod$)
mesh1=LoadMesh(MFolder$ + "\" + loadmod$)
mesh2=LoadMesh(MFolder$ + "\" + loadmod$)
mesh3=LoadMesh(MFolder$ + "\" + loadmod$)
Something like that?
Or use an array, or types, whichever suits your needs.
You can also copy the mesh or entity (copyentity/copymesh) so it won't be loaded from the file every time.
EDIT: ow, with one command? Not possible I think, but don't see why that would be necessary. Just load it once, and make some copies, in an array or with types.
any ideas how to possibly use array's for this sercumstances?
what i want this for is for the user of the app to be able to load as many mesh's as they want which can be called back later seperatly....
hope this helps
mesh(1)=LoadMesh(MFolder$ + "" + loadmod$)
mesh(2)=LoadMesh(MFolder$ + "" + loadmod$)
mesh(3)=LoadMesh(MFolder$ + "" + loadmod$)
Dim mesh(totalmesh)
for n=0 to totalmesh
mesh(n) = loadmesh(blah blah)
next
Or better if you use types then you can store additional info about the mesh
type nmesh
field mesh
field id
field xscale#
field yscale#
field zscale#
field numberoffins
field cupsofcoffee
field etc
end type
function loadnmesh(filename$,id=0)
if id = 0 then id = millisecs()
n.nmesh = new nmesh
n\mesh = loadmesh(filename$)
n\id = id
end function
then just use loadnmesh instead of loadmesh.
Use the id to identify the mesh uniquely. Or use a name or something.
On top of this you could make the fields into global variables:
global meshhandle
global xscale#
global yscale#
global zscale#
global numberoffins
global cupsofcoffee
global etc
The have a function:
function getmesh(id)
for n.nmesh = each mesh
if n\id = id
meshhandle = n\meshhandle
xscale# = n\xscale
yscale# = n\yscale
zscale# = n\zscale
numberoffins = numberoffins
cupsofcoffee = cupsofcoffee
etc = etc
return true
endif
next
return false
end function
Then you'd just use
if getmesh(400) then print "Found" else print "Not Found"
And all your globals will be populated if the mesh is found.
Note: All of this code is off the top of my head untested stuff so it might not work, however, it's there to explain the principle.
Thanks it looks like it will do the trick, i wish i understood array's better but i think i'll try to use types for this. thanks rob
Arrays are much simpler than types, look at my first example:
dim mesh(5)
for n=0 to 5
mesh(n) = loadmesh("meshname_"+n+".b3d")
next
Then you just have mesh(0) mesh(1) mesh(2) etc.
sorry i still don't get array's (i don't even know where in the code to put that stuff) so i'll go with the types without the global stuff. but i'm still having trouble if i want to do some thing to the mesh what do i call it? id deosn't seem to work is their something i need with it?
eg
EntityPickMode(????,2) ;model just loaded
i wish i understood array's better
Does
this help?
And while you're at it, check out the rest of my
site.
ok thanx. that helps me understand arrays better but i still need help with my problem with the type command. and i think the last example in the link is wrong shouldn't it be Dim Array(2, 2, 2)not Dim Array(1, 1, 1)?
would i have to do something like this?
EntityPickMode(nmesh\id,2)
when i do it says "variable must be a type"
Dim Array(1, 1, 1)
Has:
Array(0, 0, 0)
Array(1, 0, 0)
Array(0, 1, 0)
...
Array(1, 1, 0)
Array(1, 1, 1)
so it has 2 elements (counting 0)
And you would have to put:
EntityPickMode(nmesh\mesh,2)
or
EntityPickMode(meshhandle,2)
not
EntityPickMode(nmesh\id,2)
"And you would have to put:
EntityPickMode(nmesh\mesh,2)
or
EntityPickMode(meshhandle,2)"
nope they don't seem to work...
Sorry I mean
EntityPickMode(n\mesh,2)
eg:
type nmesh
field mesh
end type
global n.nmesh
n.nmesh=New nmesh
n\mesh=LoadMesh("Mesh.3ds")
function SetPick()
for n.nmesh=Each nmesh
EntityPickMode(n\mesh,2)
next
end function
Still a little confused here:i'm using the type and function.. but it's not working i'm trying to use the function: setpick() but it's complaining so i was hoping someone would help me out by pointing out what information form this whole topic-thing i need to use.
i'm trying to use the function: setpick() but it's complaining
Are you serious? Do you really think I can help you if you tell me that it's 'complaining'?
Be more specific.
Show us the code you are using. That's the best ticket.
You really have to learn the basics first before trying to build any games/application. Look at the examples and code something simple.
You can't really make anything bigger without understanding arrays and lot's of other basics.
Ok what i mean is i have this code at the start:
Function loadnmesh (modledir$,id=0)
If id=0 Then id = MilliSecs()
n.nmesh = New nmesh
n\mesh = LoadMesh(modledir)
n\id = id
End Function
Function Setpick()
For n.mesh=Each mesh
EntityPickMode(n\mesh,2)
Next
End Function
And then in the main loop i have:
;-----------------------------------------------
If MouseHit(1)
MFolder$="Models"
mydir=ReadDir(Mfolder$)
Repeat
File$=NextFile$(mydir)
If file$="" Then Exit
If FileType(folder$+"\"+file$) = 2 Then
Print "Folder:" + file$
Else
Print "File:"+ file$
End If
Forever
loadmod$= Input$("Which do you want To load?")
CloseDir mydir
modledir$=(MFolder$ + "\" + loadmod$)
loadnmesh(modledir$,loadmod$)
;------ok so here it loads the mesh properly but then i don't know how to assign a pickmode to it.
;EntityPickMode(n\mesh,2)
setpick
so.... how do i assign the pick mode?