Problem Entity Parent.
Blitz3D Forums/Blitz3D Programming/Problem Entity Parent.
| ||
[codebox] TMC\MC.TMalla = Init_TMalla.TMalla( "Chassis.b3d") ScaleMesh TMC\MC\malla%, 2.5, 2.5, 2.5 TMC\motorBase.TMalla = Init_TMalla.TMalla( "MotorBase.b3d", TMC\MC\malla%) ScaleMesh TMC\motorBase\malla%, 2.5, 2.5, 2.5 PositionEntity ( TMC\motorBase\malla%, 0, 0, 22 ) TMC\sombra.TMalla = Init_TMalla.TMalla ( "Sombra.b3d", TMC\MC\malla% ) ScaleMesh TMC\sombra\malla%, 2.5, 2.5, 2.5 EntityAlpha ( TMC\sombra\malla%, 0.01 ) EntityFX ( TMC\sombra\malla%, 1 ) [/code] Local montacarga.TMalla = Null Type TMalla Field malla% Field padre% End Type Function Init_TMalla.TMalla( archivo$, padre% = False ) Local TMalla.TMalla = New TMalla TMalla\padre% = padre% Init_TZip%() TMalla\malla% = LoadMesh(pak(archivo$), TMalla\padre% ) DeInit_TZip%() Return ( TMalla.TMalla ) End Function Function DeInit_TMalla%() Local TMalla.TMalla = Null For TMalla.TMalla = Each TMalla If ( TMalla\padre% ) Then EntityParent( TMalla\malla%, 0 ) End If FreeEntity ( TMalla\malla% ) Delete Each TMalla Next End Function My problem is I can only attach a single entity , the two can not put me as children of a mesh top . The fact is that if I do not use types , if it works , any suggestions? |
| ||
Maybe try to rotate position your entity (child) with the wanted global orientationrotateentity(entity,entitypitch(oentity,true),entityyaw(oentity,true),entityroll(oentity,true),true) and at the wanted global position positionentity(entity,entityx(oentity,true),entityy(oentity,true),entityz(oentity,true),true) then turn it, move it as you want and then use entityparent(childentity,parententity,true) |
| ||
What I will say will NOT solve your problem 1 - You don't need to add ".TMalla" or "%" for each object, once it's declared, the object is set. your first code should look like this 2 - a codebox must be closed by a "/codebox" not a "/code" ;) 3 - Your function DeInit_TMalla() is bad You are calling the TMalla list to unparent entities but in the For/Each loop you call "Delete Each TMalla" -> so it "unparents" only the first one then destroy all instances of TMalla so the For/Each loop ends after the first TMalla object. 4 - your "padre" member is probably useless. If you need to get the parent of an entity, you can use 'GetParent(entity) 5 - You can, but should never use the same name for both type declaration and instances of it. -> it's harder to read -> if you intend to move to blitzmax someday, you'll encounter several problems -> you can try to use some tips on your local/global/members name to make them clear like "l_Variable" for local variables or "g_variable" for globals etc ..., you can also prefix your type members with "m", in the end it will be easier to understand what is what without the needs to look at the whole code to find out where a variable comes from ( also "p_" is a valid prefix for function parameters ) Type TModel Field mEntity End Type Function Do.TModel(pSomeFile$, pParent=0) Local l_M = New TModel l_M\mEntity = LoadMesh(pSomeFile, pParent) Return l_M End Function Local l_Ent.TModel = Do( "my file.b3d" ) Local l_Child1.TModel = Do("my child 1.b3d", GetParent(l_Ent\mEntity) ) Local l_Child2.TModel = Do("my child 2.b3d", GetParent(l_Ent\mEntity) ) PositionEntity( l_Child1\mEntity, ....... ) 6 - My problem is I can only attach a single entity , the two can not put me as children of a mesh top . The fact is that if I do not use types , if it works , any suggestions? Sorry for that but I'm really not sure about what you're asking. Are you saying you can't attach 2 entities on the same entity ? (there is nothing in your posted code that would prevent it to happen) |