Finding child entities of a model created in UU3D

Blitz3D Forums/Blitz3D Beginners Area/Finding child entities of a model created in UU3D

I have been having some problems trying to identify individual faces of a model I created within UU3D, to update the sides of a cube programmitically within B3D.

I suspected that my file maybe was not being saved/exported properly from UU3D. I used the following code to analyse my .b3d file, the only child entities returned were:

ROOT_UU3D

The file in question has had individual groups assigned to each side on the model within B3D, i.e. under the Groups expander I have Box, front, back, side1, side2, top and bottom.

[LAST...EDIT] solved now.... big thankyou to Ross for his help - see post #9 scroll down a bit to see the cuboids with various (albeit unimaginative) images applied via code.



[EDIT] - resolved this......:Why can't I see these as child entities using the code below and I only see ROOT_UU3D ?


[EDIT] seem to have resolved it by saving as B3D extension with multiple textures option selected. I now am getting the child entities.

How can I apply an image to one of the child entities identified upon loading - thanks.
, trying to use the following somehow:


This may depend on your model - and how you designed each face and named them.

You can 'face=FindChild(entity,"face name")' - then texture each face.




;--- attempt To paint different sides of a box with different images ----

;--- v4 attempt to apply images to sides of a model

;--- end versions

Graphics3D 640,480,0,2 
SetBuffer BackBuffer() 

camera=CreateCamera() 
PositionEntity camera,0,2,-5

;filepath$=("C:/first_b3d_boxv2.b3d") 
filepath$=("H:TORTOISEtop_level_tort_check_ootskiUltimateUnwrapProjectstry_b3d.b3d") 

Global mesh_with_children = LoadAnimMesh( filepath$ )

OutputChildNames( mesh_with_children )

WaitKey

Print "Press any key"

;End
;---

Function OutputChildNames( entity )

Local i, count

Print EntityName( entity )

count = CountChildren( entity )
For i = 1 To count
	OutputChildNames( GetChild( entity, i ) )
Next
End Function



light=CreateLight() 
;RotateEntity light,90,0,0 
RotateEntity light,90,45,45

; My Load mesh   -------------
old_box_3d=LoadAnimMesh("C:/first_b3d_boxv2.b3d") 
Global box_3d=LoadAnimMesh("H:TORTOISEtop_level_tort_check_ootskiUltimateUnwrapProjectstry_b3d.b3d")

; Load the Exported Texture:
textture =LoadTexture("H:TORTOISEtop_level_tort_check_ootskiUltimateUnwrapProjectsbox_export_uv_map_try1_bmp.bmp")


brush_top = CreateBrush()
brush_side = CreateBrush()
brush_front = CreateBrush()
brush_bottom = CreateBrush()
;
;source textures for applying to the top/side and bottom of the box
tex_top=LoadTexture( "c:top_box_200_x_80.png") 
tex_side=LoadTexture("c:side_80_x_300.png" )
tex_bottom=LoadTexture("c:bot_box_200_x_80.png" )
tex_front=LoadTexture( "c:200_by_300.png" )
 
;brush=CreateBrush() 
BrushTexture brush_top,tex_top,0,0
BrushTexture brush_side,tex_side,0,0
BrushTexture brush_front,tex_front,0,0
BrushTexture brush_bottom,tex_bottom,0,1

top_box=FindChild(mesh_with_children,"top")
bottom_box=FindChild(mesh_with_children,"bottom")

WaitKey

brush_all = CreateBrush()
BrushTexture brush_all,textture,0,0
;PaintSurface GetSurface( mesh_with_children, 1 ) , brush_all ; ERROR:  Surface out of range

;PaintSurface GetSurface( box_3d, top_box ) ,brush_top  ; ERROR:  Surface index out of range


PaintSurface GetSurface( old_box_3d, 1 ) ,brush_all  ; this works, due to not being exported as multiple layers,
                                                     ; hence ability to apply brush_all to the only Surface


;now modify the mesh_with_children top image

;BrushTexture brush_top,top_box,0,0             ;  ERROR texture does not exist despite brush_top
                                               ;  and top_box being assigned vars..

;now modify the mesh_with_children bottom image

;BrushTexture brush_bottom,bottom_box,0,0           ;  ERROR texture does not exist despite brush_bottom
                                               		;  and bottom_box being assigned vars..



PositionEntity box_3d,0,0,MeshDepth(box_3d)*2 

PositionEntity mesh_with_children,0,0,MeshDepth(mesh_with_children)*2 


While Not KeyDown( 1 ) 

If KeyDown( 205 )=True Then TurnEntity camera,0,-1,0 
If KeyDown( 203 )=True Then TurnEntity camera,0,1,0 
If KeyDown( 208 )=True Then MoveEntity camera,0,0,-0.05 
If KeyDown( 200 )=True Then MoveEntity camera,0,0,0.05

;move camera up and down
If KeyDown( 30 )=True Then MoveEntity camera,0,1,0  ;a
If KeyDown( 44 )=True Then MoveEntity camera,0,-1,0 ;z

; Change rotation values depending on the key pressed 
;If KeyDown( 208 )=True Then pitch#=pitch#-1 
;If KeyDown( 200 )=True Then pitch#=pitch#+1 
If KeyDown( 49 )=True Then yaw#=yaw#-1 
If KeyDown( 50 )=True Then yaw#=yaw#+1 
;If KeyDown( 45 )=True Then roll#=roll#-1 
;If KeyDown( 44 )=True Then roll#=roll#+1 

; Rotate cone using rotation values 
RotateEntity box_3d,pitch#,yaw#,roll# 

RotateEntity mesh_with_children,pitch#,yaw#,roll# 


RenderWorld 

Text 0,0,"Use cursor keys to move about" 
Text 0,20,"Use a/z for camera up/down"
Text 0,40,"Use m/n for rotate the box"

Flip 

Wend 

End 


Hmm, your code is quite confusing to follow...

You don't need to create brushes, in order to texture these entities. Find child seperates each mesh into an individual entity, so:

Topside = findchild(main_mesh,"topside")

texture_top = loadtexture("topside.png")

Entitytexture topside,texture_top


Should do the trick...?

thanks Ross, sorry about the confusing code its kind of work in progress.....

Did it work ?

Not so far, some reason my entity has stopped rotating also, but still move up/down & left right ?

However I did achieve my goal of producing a 3d box of my software product, so thankyou for that.

I just got a bit fixated on wanting to change the sides of a cuboid ( well its a kind of cereal box sized cube), and I think I'm close.

If you find a child of an entity is it possible to obtain the x and y sizes of the child ? Or do you just get a memory location and you have to ensure your image you are attempting to apply is exactly the same dimensions?

here is the code to date:

;--- attempt To paint different sides of a box with different images ----

;--- v4 attempt to apply images to sides of a model

;---v5

;You don't need to create brushes, in order to texture these entities. Find child seperates each mesh into an individual entity, so:
;
;Topside = findchild(main_mesh,"topside")
;
;texture_top = loadtexture("topside.png")
;
;Entitytexture topside,texture_top
;
;--- end versions

Graphics3D 640,480,0,2 
SetBuffer BackBuffer() 

camera=CreateCamera() 
PositionEntity camera,0,2,-5

;filepath$=("C:/first_b3d_boxv2.b3d") 
filepath$=("H:\TORTOISE\top_level_tort_check_ootski\UltimateUnwrapProjects\try_b3d.b3d") 

Global mesh_with_children = LoadAnimMesh( filepath$ )

OutputChildNames( mesh_with_children )

WaitKey

Print "Press any key"

;End
;---

Function OutputChildNames( entity )

Local i, count

Print EntityName( entity )

count = CountChildren( entity )
For i = 1 To count
	OutputChildNames( GetChild( entity, i ) )
Next
End Function



light=CreateLight() 
;RotateEntity light,90,0,0 
RotateEntity light,90,45,45

; My Load mesh   -------------
old_box_3d=LoadAnimMesh("C:/first_b3d_boxv2.b3d") 
Global box_3d=LoadAnimMesh("H:\TORTOISE\top_level_tort_check_ootski\UltimateUnwrapProjects\try_b3d.b3d")

; Load the Exported Texture:
textture =LoadTexture("H:\TORTOISE\top_level_tort_check_ootski\UltimateUnwrapProjects\box_export_uv_map_try1_bmp.bmp")


brush_top = CreateBrush()
brush_side = CreateBrush()
brush_front = CreateBrush()
brush_bottom = CreateBrush()
;
;source textures for applying to the top/side and bottom of the box
tex_top=LoadTexture( "c:\top_box_200_x_80.png") 
tex_side=LoadTexture("c:\side_80_x_300.png" )
tex_bottom=LoadTexture("c:\bot_box_200_x_80.png" )
tex_front=LoadTexture( "c:\200_by_300.png" )
 
;brush=CreateBrush() 
;BrushTexture brush_top,tex_top,0,0
;BrushTexture brush_side,tex_side,0,0
;BrushTexture brush_front,tex_front,0,0
;BrushTexture brush_bottom,tex_bottom,0,1

top_box=FindChild(mesh_with_children,"top")
bottom_box=FindChild(mesh_with_children,"bottom")

front=FindChild(mesh_with_children,"front")

;WaitKey

;EntityTexture top_box,tex_top                ;a test
EntityTexture bottom_box,tex_top              ;not causing any compile errors but not modifying the 'top' of the box

EntityTexture front,tex_front  


PositionEntity mesh_with_children,0,0,MeshDepth(mesh_with_children)*2 

While Not KeyDown( 1 ) 

If KeyDown( 205 )=True Then TurnEntity camera,0,-1,0 
If KeyDown( 203 )=True Then TurnEntity camera,0,1,0 
If KeyDown( 208 )=True Then MoveEntity camera,0,0,-0.05 
If KeyDown( 200 )=True Then MoveEntity camera,0,0,0.05

;move camera up and down
If KeyDown( 30 )=True Then MoveEntity camera,0,1,0  ;a
If KeyDown( 44 )=True Then MoveEntity camera,0,-1,0 ;z


If KeyDown( 49 )=True Then yaw#=yaw#-1 
If KeyDown( 50 )=True Then yaw#=yaw#+1 


RotateEntity mesh_with_children,pitch#,yaw#,roll# 


RenderWorld 

Text 0,0,"Use cursor keys to move about" 
Text 0,20,"Use a/z for camera up/down"
Text 0,40,"Use m/n for rotate the box"

Flip 

Wend 

End 




I'm slightly confused here. You are loading two meshes, both the exact same. So, they surely must be overlapping. Try the below code and see what you get. You should see another cube, textured with the texture for the top side.

;--- attempt To paint different sides of a box with different images ----

;--- v4 attempt to apply images to sides of a model

;---v5

;You don't need to create brushes, in order to texture these entities. Find child seperates each mesh into an individual entity, so:
;
;Topside = findchild(main_mesh,"topside")
;
;texture_top = loadtexture("topside.png")
;
;Entitytexture topside,texture_top
;
;--- end versions

Graphics3D 640,480,0,2 
SetBuffer BackBuffer() 

camera=CreateCamera() 
PositionEntity camera,0,2,-5

filepath$=("H:\TORTOISE\top_level_tort_check_ootski\UltimateUnwrapProjects\try_b3d.b3d") 

Global mesh_with_children = LoadAnimMesh( filepath$ )


light=CreateLight() 
RotateEntity light,90,45,45


;source textures for applying to the top/side and bottom of the box
global tex_top=LoadTexture( "c:\top_box_200_x_80.png") 
global tex_side=LoadTexture("c:\side_80_x_300.png" )
global tex_bottom=LoadTexture("c:\bot_box_200_x_80.png" )
global tex_front=LoadTexture( "c:\200_by_300.png" )
 

Global top_box = FindChild(mesh_with_children,"top")
Global bottom_box = FindChild(mesh_with_children,"bottom")

Global front = FindChild(mesh_with_children,"front")


EntityTexture bottom_box,tex_top              ;not causing any compile errors but not modifying the 'top' of the box

	; test to see if texture is loading properly
		c = createcube()
		positionentity c,2,0,0
		entitytexture c,tex_top
	; end test

EntityTexture front,tex_front  


PositionEntity mesh_with_children,0,0,MeshDepth(mesh_with_children)*2 

While Not KeyDown( 1 ) 

If KeyDown( 205 )=True Then TurnEntity camera,0,-1,0 
If KeyDown( 203 )=True Then TurnEntity camera,0,1,0 
If KeyDown( 208 )=True Then MoveEntity camera,0,0,-0.05 
If KeyDown( 200 )=True Then MoveEntity camera,0,0,0.05

;move camera up and down
If KeyDown( 30 )=True Then MoveEntity camera,0,1,0  ;a
If KeyDown( 44 )=True Then MoveEntity camera,0,-1,0 ;z


If KeyDown( 49 )=True Then yaw#=yaw#-1 
If KeyDown( 50 )=True Then yaw#=yaw#+1 


RotateEntity mesh_with_children,pitch#,yaw#,roll# 


RenderWorld 

Text 0,0,"Use cursor keys to move about" 
Text 0,20,"Use a/z for camera up/down"
Text 0,40,"Use m/n for rotate the box"

Flip 

Wend 

End 


Ross, you are a star, I have moved the code you sent me forward slightly and I am very nearly there! Gotta go for a quick run before the inky blackness of night rolls in, but heres your code stepped on a little, basically I'm checking all my individually loaded textures now and applying to sides of the cuboid with some minor scaling issues. Woo Hoo!

Code:--

;--- attempt To paint different sides of a box with different images ----

;-v6.........
;v7 Ross's one with a little more....
;--- end versions

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,2,-5

filepath$=("H:\TORTOISE\top_level_tort_check_ootski\UltimateUnwrapProjects\try_b3d.b3d")

Global mesh_with_children = LoadAnimMesh( filepath$ )


light=CreateLight()
RotateEntity light,90,45,45


;source textures for applying to the top/side and bottom of the box
Global tex_top=LoadTexture( "c:\top_box_200_x_80.png")
Global tex_side=LoadTexture("c:\side_80_x_300.png" )
Global tex_bottom=LoadTexture("c:\bot_box_200_x_80.png" )
Global tex_front=LoadTexture( "c:\200_by_300.png" )


Global top_box = FindChild(mesh_with_children,"top")
Global bottom_box = FindChild(mesh_with_children,"bottom")

Global front = FindChild(mesh_with_children,"front")


EntityTexture bottom_box,tex_top ;not causing any compile errors but not modifying the 'top' of the box

; test to see if top_texture is loading properly
c = CreateCube()
PositionEntity c,2,0,0
EntityTexture c,tex_top
; end test

; test to see if bottom_texture is loading properly
d = CreateCube()
PositionEntity d,1,0,5
EntityTexture d,tex_bottom
; end test

; test to see if front_texture is loading properly
e = CreateCube()
PositionEntity e,0,0,10
EntityTexture e,tex_front
; end test


EntityTexture front,tex_front

EntityTexture top_box,tex_top


;PositionEntity mesh_with_children,0,0,MeshDepth(mesh_with_children)*2
PositionEntity mesh_with_children,0,-20,20


While Not KeyDown( 1 )

If KeyDown( 205 )=True Then TurnEntity camera,0,-1,0
If KeyDown( 203 )=True Then TurnEntity camera,0,1,0
If KeyDown( 208 )=True Then MoveEntity camera,0,0,-0.05
If KeyDown( 200 )=True Then MoveEntity camera,0,0,0.05

;move camera up and down
If KeyDown( 30 )=True Then MoveEntity camera,0,1,0 ;a
If KeyDown( 44 )=True Then MoveEntity camera,0,-1,0 ;z

If KeyDown( 24 )=True Then TurnEntity camera,0,0,-1 ;O
If KeyDown( 25 )=True Then TurnEntity camera,0,0,1 ;P


If KeyDown( 49 )=True Then yaw#=yaw#-1
If KeyDown( 50 )=True Then yaw#=yaw#+1


RotateEntity mesh_with_children,pitch#,yaw#,roll#


RenderWorld

Text 0,0,"Use cursor keys to move about"
Text 0,20,"Use a/z for camera up/down"
Text 0,40,"Use m/n for rotate the box"

Flip

Wend

End

Another Evolution, this one displays 7 cuboids - each with a different side modified. Stuck the cuboids and their child entities into an array to allow simple manipulation - contemplated a select case switch thingy but am happy with it in its current guise.


will upload media for the code if anyone wants, or might upload anyway and stick in the code archives.... ?


;--- key_boxv7.bb Painting different sides of a box with different images ----

;--- Thanks to Ross for his help ---------------------------------------------

;-----------------------------------------------------------------------------
your_path$=("H:\TORTOISE\top_level_tort_check_ootski\UltimateUnwrapProjects")

Graphics3D 800,600,0,1 
SetBuffer BackBuffer() 

;filepath$=("C:/first_b3d_boxv2.b3d") 
filepath$=(your_path$+"\try_b3d.b3d") 

;-- note following code tests child entites loaded successfully ---------

;Global test_mesh = LoadAnimMesh( filepath$ )
;
;OutputChildNames( test_mesh )
;
;Print "Press any key"
;
;WaitKey
;
;;End
;;---
;
;Function OutputChildNames( entity )
;
;Local i, count
;
;Print EntityName( entity )
;
;count = CountChildren( entity )
;For i = 1 To count
;	OutputChildNames( GetChild( entity, i ) )
;Next
;End Function

;----------------------------end test child entities ----------------------


camera=CreateCamera() 
PositionEntity camera,50,20,-70

filepath$=(your_path$+"\try_b3d.b3d") 

Dim top_side(7)
Dim bottom_side(7)
Dim front_side(7)
Dim left_side(7)
Dim right_side(7)
Dim back_side(7)

Dim mesh_with_children(7)

For count = 1 To 7
	mesh_with_children(count) = LoadAnimMesh( filepath$ )
	
	;and find all sides of all seven cuboids
	
	top_side(count) = FindChild(mesh_with_children(count),"top")
	bottom_side(count) = FindChild(mesh_with_children(count),"bottom")
	front_side(count) = FindChild(mesh_with_children(count),"front")
	left_side(count) = FindChild(mesh_with_children(count),"side1")
	right_side(count) = FindChild(mesh_with_children(count),"side2")
	back_side(count) = FindChild(mesh_with_children(count),"back")
Next


light=CreateLight() 
RotateEntity light,90,45,45


;source textures for applying to the top/side and bottom of the box
Global tex_top=LoadTexture( "c:\top_side_200_x_80.png" ) 
Global tex_side=LoadTexture( "c:\side_80_x_300.png" )
Global tex_bottom=LoadTexture( "c:\bot_box_200_x_80.png" )
Global tex_front=LoadTexture( "c:\200_by_300.png" )
 


		
	; test to see if bottom_texture is loading properly
		a = CreateCube()
		PositionEntity a,30,25,-30
		EntityTexture a,tex_bottom
	; end test
	
	; test to see if front_texture is loading properly
		b = CreateCube()
		PositionEntity b,36,25,-30
		EntityTexture b,tex_front
	; end test

	; test to see if top_texture is loading properly
		c = CreateCube()
		PositionEntity c,42,25,-30
		EntityTexture c,tex_side  ; Not there?
	; end test
		
	; test to see if bottom_texture is loading properly
		d = CreateCube()
		PositionEntity d,48,25,-30
		EntityTexture d,tex_bottom
	; end test
	
	; test to see if front_texture is loading properly
		e = CreateCube()
		PositionEntity e,54,25,-30
		EntityTexture e,tex_front
	; end test
	
	; test to see if top_texture is loading properly
		f = CreateCube()
		PositionEntity f,60,25,-30
		EntityTexture f,tex_side     ;not_there ?
	; end test
	


; Texture different sides of different cubes with different images
For texture_diff_sides=1 To 7

	If texture_diff_sides=1
		;just texture with big brush........? 
	EndIf
	
	If texture_diff_sides=2
		EntityTexture front_side(texture_diff_sides),tex_bottom
	EndIf
	
	If texture_diff_sides=3
		EntityTexture top_side(texture_diff_sides),tex_front 
	EndIf
	
	If texture_diff_sides=4
		EntityTexture left_side(texture_diff_sides),tex_front 
	EndIf
	
	If texture_diff_sides=5
		EntityTexture right_side(texture_diff_sides),tex_front 
	EndIf
	
	If texture_diff_sides=6
		EntityTexture back_side(texture_diff_sides),tex_bottom ;hehe
	EndIf
	
	If texture_diff_sides=7
		EntityTexture bottom_side(texture_diff_sides),tex_front 
	EndIf

;EntityTexture top_side,tex_top 

Next

;----------- draw the cuboids with different face modified ---------

For x=1 To 7

	PositionEntity mesh_with_children(x),(-60+(x*30)),-20,50

Next


;---------- draw and move stuff, if input detected ------------------

While Not KeyDown( 1 ) 

If KeyDown( 205 )=True Then TurnEntity camera,0,-1,0 
If KeyDown( 203 )=True Then TurnEntity camera,0,1,0 
If KeyDown( 208 )=True Then MoveEntity camera,0,0,-0.5 
If KeyDown( 200 )=True Then MoveEntity camera,0,0,0.5

;move camera up and down
If KeyDown( 30 )=True Then MoveEntity camera,0,1,0  ;a
If KeyDown( 44 )=True Then MoveEntity camera,0,-1,0 ;z

If KeyDown( 24 )=True Then TurnEntity camera,0,0,-1 ;O
If KeyDown( 25 )=True Then TurnEntity camera,0,0,1  ;P


If KeyDown( 49 )=True Then yaw#=yaw#-1 
If KeyDown( 50 )=True Then yaw#=yaw#+1 

For move_one_at_a_time=1 To 7
	RotateEntity mesh_with_children(move_one_at_a_time),pitch#,yaw#,roll# 
Next


RenderWorld 

Text 0,0,"Use cursor keys to move about" 
Text 0,20,"Use a/z for camera up/down"
Text 0,40,"Use m/n for rotate the box"
Text 0,60,"Use o/p for rotate all"

Flip 

Wend 

End 





Glad you got it sorted man!

Cheers Ross!

Added an image of what the code in post #8 does....