referring objects in a b3d file
Blitz3D Forums/Blitz3D Beginners Area/referring objects in a b3d file
| ||
Hi, want to ask something here. I used an external program (xworld 3d) to import my .3ds models and place them in position. Well, I exported it the scene out as a b3d file. Let's say I have a cube on a plane. When I export them out as a single b3d file (using 3ds max or xworld 3d in this case), how do I import it into blitz? And how do I refer to the objects in the scene? For example, I want the cube to move around. When I import the b3d format, how do I code so that the cube can move around? Do I refer it by its name in the scene? Thanks! |
| ||
If your .b3d file contains only one object, ex. a cube, then you just need:global cube = loadmesh("my_b3d_file.b3d") and then use all the entity command on the entity named 'cube', for example: moveentity cube, 0,0,1 If you have more than one object in the .b3d file, such a plane and a cube, assuming that you have named each object in 3dsmax or xworld3D before exporting the whole file as a .b3d, then you may use the FindChild command: http://www.blitzbasic.com/b3ddocs/command.php?name=FindChild&ref=goto to locate any child entity, and use it, again, as a normal entity. For example, you have named the plane as "myplane" and the cube as "mycube" in 3dmax. Then you could do: global cube myobj = loadmesh("my_b3d_object.b3d") cube = findchild myobj,"mycube" moveentity cube,0,0,1 ;ecc. ecc Have a look also at the following commands: FindChild GetChild CountChildren under entiy state category, and also GetParent in the entiy control category: http://www.blitzbasic.com/b3ddocs/command_list_3d_cat.php Hope this helps, Sergio. P.S. You are of course aware of the 3D object creation capability of B3D, which includes also CreatePlane and CreateCube, aren't you ? ;-) |
| ||
Thanks for the reply. Got another question here. If I want to use the camera created in xworld 3d (rather than create it in blitz), how do I refer it in blitz then? Is it the same as referring it to the name using the FindChild command? Actually, I wanted to create the camera in blitz, but because I find it hard to control the camera by typing the coordinates, so I turn to xworld 3d to position my camera. Thanks! |
| ||
Once you have positioned your camera from within xworld, you can use it as a pivot to create the camera object in blitz. - pivot = findchild(mesh,"mycamera") - createcamera(pivot) Sergio. |
| ||
I believe you need the command LoadAnimMesh To Keep the Heiarchy(sp) intact. Regards, Eric |
| ||
I tried using the FindChild command, but it didn't work. I created a simple scene with a cube and a plane. I wanted to move the cube in the scene. scene = LoadMesh("group.b3d") player = FindChild(scene, "Box") While Not KeyHit(1) If KeyDown(17) Then MoveEntity player, 0, 0, 2 EndIf UpdateWorld RenderWorld Flip Wend End When I hit the key "w" It pops out "entity does not exist". I checked the debug window and the player returns 0 value, which means it didn't load. Anyone knows why? |
| ||
You need to use LoadAnimMesh to keep the sub-objects intact. You can also try running this over it: scene = LoadAnimMesh("group.b3d") ent = scene While ent DebugLog EntityName(ent) ent = NextChild(ent) Wend Function NextChild(ent) If CountChildren(ent)>0 Return GetChild(ent,1) EndIf Local foundunused=False Local foundent = 0, parent,sibling While foundunused=False And ent<>0 parent = GetParent(ent) If parent<>0 If CountChildren(parent)>1 If GetChild(parent,CountChildren(parent))<>ent For siblingcnt = 1 To CountChildren(parent) sibling = GetChild(parent,siblingcnt) If sibling=ent foundunused = True foundent = GetChild(parent,siblingcnt+1) EndIf Next EndIf EndIf EndIf ent = parent Wend Return foundent End Function |