FindChild/GetChild query.

Blitz3D Forums/Blitz3D Programming/FindChild/GetChild query.

Ross C(Posted 2009) [#1]
Hi there. I am curious as to what happens to the original variable, holding the mesh, when you have extracted all the mesh, via FindChild or GetChild, into other variable handles:

mesh = LoadAnimMesh("mesh.b3d")

a = GetChild(mesh,1)
b = GetChild(mesh,2)



What becomes of the orginal mesh variable. Is it holding a pivot?


Ross C(Posted 2009) [#2]
Ok, i have run it through EntityClass and it says it's a mesh. However, it has no surfaces. And if i free it, it frees the rest of my entities i extracted.


Ross C(Posted 2009) [#3]
Further to this, using:

EntityParent a,0
EntityParent b,0


And then freeing the Mesh, still results in the whole thing being freed. Strange. Anyway, i thought i'd just share that, incase anyone else was wondering that.


Kryzon(Posted 2009) [#4]

Blitz3D Online Manual:

FreeEntity

[...]

This command will also free all children entities parented to the entity.

[...]


That's one solved. I had some trouble as well getting to know this little fact.

I don't think using GetChild will "detach" a mesh from it's parent. You're simply referencing it.

And you can be sure that after "EntityParent a,0", if you free it's ex-parent, it won't get deleted. I don't know what you did in your code for it to happen, but in mine it goes normally.

(I had a camera parented to an animated pivot, and that pivot was a child of a scene. When I freed the scene the camera got deleted as well. I parented it to 0 and it wasn't deleted anymore after I freed the scene)


Ross C(Posted 2009) [#5]
Nope, it definetly frees all the children attached to it after it's un-parented. Thanks for your input though :o) I'm just going to avoid freeing that particular entity.

Odd how it's returned as a mesh though :o)


Stevie G(Posted 2009) [#6]
@ Ross, sounds like a dodgy model?

This works as expected:

Graphics3D 1024,768,32,1

camera = CreateCamera()
PositionEntity camera, 0,0,-10

pivot = CreatePivot()

tmp = CreateCube( pivot )
PositionEntity tmp, -5,0,0
tmp = CreateCube( pivot )
PositionEntity tmp, 5, 0, 0

a = GetChild( pivot,1 )
b = GetChild( pivot,2 )
EntityParent a, 0
EntityParent b, 0
FreeEntity pivot

While Not KeyHit(1)

	RenderWorld()
	Flip
	
Wend

End



Ross C(Posted 2009) [#7]
Maybe it's different for loaded models? The particular model was done by someone in cinema4d. That examples works the way it should, stevie.


big10p(Posted 2009) [#8]
Does CountChildren() return the expected number?


Warner(Posted 2009) [#9]
The model, is it a .b3d file? Does it use bones? I can imagine that if a model uses vertex weighting, that it would be more difficult to detach a child from it's structure. If a vertex can be affected by multiple bones, the bones could perhaps function as a sort of parent. And as far as I know of, you can only detach one single parent for each mesh.
If that is the case, try the Load/SaveB3D code from the archive to parse the .b3d file structure. Or offcourse, export the file differently.
Else, inspect the model using a function like this:
function ShowChildren(mesh, l=0)

   print string$("-", l*4) + ">" + entityname$(mesh) + " (" + entityclass$(mesh) + ")"
  
   for i = 1 to countchildren(mesh)
      showchildren(getchild(mesh, i), l+1)
   next

end function

Note that this code is untested, since I don't have b3d with me atm.


RifRaf(Posted 2009) [#10]
Ross, I would ask skid or mark about this one then. Perhaps Loadmesh does in fact create an internal Blitz child list that is later uneffected by entityparent child,0

? I havent tested this myself, but if the above is all correct it would have to be somthing like that.

In that case, you could load the animated model, and copymesh each child, and the main parent and reconstruct a new model and free the loaded one.. Perhaps that would remove the internal parent list ?


Ross C(Posted 2009) [#11]
Maybe i will. It's not too much of an issue :) I was just curoius more than anything. And I am load an animated mesh, however, it's just different parts of a tower. Seperate meshes.


BIG BUG(Posted 2009) [#12]
I think this is a problem in your code. Works as espected here, even with LoadAnimMesh. (B3D file created via Cinema4D)
It might be a problem to detach a bone from its mesh as warner mentioned, but anything else should work...


Ross C(Posted 2009) [#13]
I will double check my code and model in UU again.

@ Big10p, my model returns the correct amount of children.