Reading multiple entity coordinates from file?

Blitz3D Forums/Blitz3D Beginners Area/Reading multiple entity coordinates from file?

Guy Fawkes(Posted 2013) [#1]
Hi! =) So I've been working on my level editor, and it's coming along great! The problem is, I can't get it to load the entities, and when I do, it only loads the 1st one..

What am I doing wrong, here?

The way the file is read is like this:



Sample Data.dat:



It uses full path to load all the saved models at their correct coordinates, sizes, etc...

It checks whether or not the model is animated, by loading a temporary mesh, checking if animlength() is > 0, and deleting the temp mesh, then reload it either as a static, or non-static, depending on if the temporary mesh had any frames in it.



Thank You!


RemiD(Posted 2013) [#2]
Try to use the debuglog command and i am sure you will find the problem and how to fix it by yourself.

Debuglog("VariableName = "+Value)
Flushkeys()
Waitkey()

For example :
For e.ent = Each ent
 EId% = EId + 1
 Debuglog("EId = "+EId)
 e\fname$ = ReadLine(fi)
 Debuglog("e\fname = "+e\fname)
 ;etc... 
 Flushkeys()
 Waitkey()
Next


You will find the error this way, it is called "debugging".


KronosUK(Posted 2013) [#3]
You are reading ents from your file so you should be creating new ents, not trying to loop through non existent ones

ie instead of

For e.ent = Each ent

do

e.ent = new ent

and get rid of the associated next of course

edit


also this bit of code seems totally redundant

If AnimLength(e\id)>0
															
FreeEntity e\id <--
														
e\id = LoadAnimMesh(e\fname$) <-- already loaded as anim  why free and load again
																Else
															
FreeEntity e\id
														
e\id = LoadMesh(e\fname$)

endif




Guy Fawkes(Posted 2013) [#4]
Ok, I did as you said. Import file is working fine. I debuglogged the crap out of LoadAllEnts(), and it's loading / reading the file fine.. The problem seems to be that it is not loading all meshes...

It only loads 1, usually, but right now for some reason, it's loading 0... o.O




KronosUK(Posted 2013) [#5]
you dropped the repeat until loop. You still need that to read through the entire file.


Guy Fawkes(Posted 2013) [#6]
I added the repeat loop. Now it's not loading anything... :(




KronosUK(Posted 2013) [#7]
Another thought, do you need an ent type at all when you could store and recall all of these properties in the entity directly.


KronosUK(Posted 2013) [#8]
check here

If e\id<>0

..

endif


e/id is always 0 because loadanimmesh is never getting called.


KronosUK(Posted 2013) [#9]
try this

DebugLog "e\xscale#: "+e\zscale#
														
	
e\id = LoadAnimMesh(e\fname$)
	
If Not e\id Then DebugLog "Failed to load mesh":end
			
If AnimLength(e\id)=0
					
FreeEntity e\id
															
e\id = LoadMesh(e\fname$)
	
DebugLog "Loaded Static Mesh: "+e\fname$+"{"+e\id+"}"
															
EndIf




Guy Fawkes(Posted 2013) [#10]
Ok, this works PERFECTLY..

Now, how can I make them pickable like the 1's that I import? When I import, they all work fine, I can pick them and everything. But when I load a save file, even though I set their type to EntityType e\id, TYPE_OBJECT, and EntityPickMode e\id, 2, 1, it still doesn't let me pick them using camerapick()...



Thank You!


RemiD(Posted 2013) [#11]
See where the Repeat Until loop starts and ends,
see where you create and define the properties of each instance of the type,
see where you set its entitypickmode,

Don't you see the problem here ?

Btw e\id is not the best way to name a pointer of a mesh. Consider an id as the number of an instance of a type. What your e\id represents here is the pointer of the mesh you are loading. So i think e\mesh or e\meshpointer would be more approriate.

Also what is the point of this part of the code ?
If AnimLength(e\id)=0
											
							FreeEntity e\id
																						
							e\id = LoadMesh(e\fname$)
								
							DebugLog "Loaded Static Mesh: "+e\fname$+"{"+e\id+"}"
							
						Else If AnimLength(e\id)>0

							FreeEntity e\id
																						
							e\id = LoadAnimMesh(e\fname$)
								
							DebugLog "Loaded Static Mesh: "+e\fname$+"{"+e\id+"}"
																						
						EndIf

The program has already loaded (or tried to load) the mesh with the previous line :
e\id = LoadAnimMesh(e\fname$)
If Not e\id Then DebugLog "Failed to load mesh" : End



Guy Fawkes(Posted 2013) [#12]
The point is to check whether or not the mesh is animated.


RemiD(Posted 2013) [#13]

The point is to check whether or not the mesh is animated.


Ok. Maybe instead of loading and freeing the mesh just for that, you could create a directory for animated meshes, and another directory for static meshes.

Concerning the problem in your code, if you have not found, i think it is because these commands :
EntityType e\id, TYPE_OBJECT
EntityPickMode e\id, 2, 1

should be applied to each entity so you have to put these commands inside the loop after having loaded the mesh.


Guy Fawkes(Posted 2013) [#14]
Tried that just now. It did nothing :(




RemiD(Posted 2013) [#15]
Ok...

First, if you don't want to use these meshes as colliders for collisions, you don't need to use EntityType(), so remove it.

Second, check if each e\id mesh correspond to a pointer or to 0
Debuglog("e\id pointer = "+e\id)
And check if each mesh is visible in game.

Third, try with EntityPickMode(Mesh,2)

Then, if i remember correctly, the skinned meshes have problems with linepick because only the first "pose" is taken into account.
So in order to be able to pick an animated mesh, you want to parent either several Blitz3d sphere colliders (EntityRadius) or several Blitz3d box colliders (EntityBox) or several low tris colliders (meshes) which have approximately the same shape than the body parts of your mesh, to each bone and then use EntityPickmode(Mesh,2) for each collider.
You can also use NameEntity(Mesh,"Name") for all colliders parented to the bones of an animated character so that you know which character was picked.
I think it will work this way.


Guy Fawkes(Posted 2013) [#16]
Uh, ok?


Guy Fawkes(Posted 2013) [#17]
Could you please explain this to me in an easier fashion?

Thank You!


RemiD(Posted 2013) [#18]
The first 3 steps no, because it is what it is.

Concerning the 4th step, yes, see this image :
[img]

[/img]

On the left you can see a skinned animated mesh (some joints have a % of influence over one or more vertices, and there are animation sequences)

On the right you can see a non skinned mesh (what you call a static mesh, no joint (= no bone) and no animations sequences)

The white cubes represent the picked points after several linepicks.

As you can see, a non skinned mesh (static mesh) will be picked correctly on all its triangles.

However, a skinned animated mesh will be picked only on all triangles of the default pose.

So if you want to be able to pick the body parts of a skinned animated mesh, you have to create several colliders (with EntityRadius or with EntityBox or with your own low tris static meshes) and set each collider as a child of a joint so it will move with the joint, and of course set each collider as pickable with EntityPickMode(Collider,2)


Guy Fawkes(Posted 2013) [#19]
I see, so basically what it amounts to, is that I add a small cube with collision abilities, to each joint, and then it will allow me to manipulate an anim mesh, using the camerapick() function?


RemiD(Posted 2013) [#20]
If you want to be able to pick it, the small cube attached to a joint needs to be pickable (with EntityRadius or with EntityBox or with your own low tris static mesh + EntityPickMode)

If you want to be able to detect a collision the small cube needs to be set as a collider (with EntityRadius or with EntityBox or with your own low tris static mesh + EntityType) and the collisions groups, detection, response need to be set (with Collisions)

You only need to do that for skinned animated mesh.

Another solution is to import only a skeleton with the joints and the animations, and add body parts to the skeleton (each set as a child of a joint) and because the body part is a "static" mesh, it can be picked even if it turns/moves.