Hi,
Let me know your thoughts and suggestions, please.
Python Code to export object name, loc, rot, and scale (source:
https://blender.stackexchange.com/questions/47061/exporting-information-of-multiple-objects )
import bpy
def grados(radianes):
x= (180*radianes)/3.141516
return x
#open path_file where I will save
full_filel = bpy.data.filepath.split("\\")
#print(full_filel)
#print(len(full_filel))
contador = 1
path_file = full_filel[0]
while contador != len(full_filel)-1:
path_file = str(path_file) + "\\" + str(full_filel[contador])
contador +=1
#path_file actual
print(path_file)
#file name
file_name = "data.txt"
#path blend file
file1 = open((path_file + '\\' + file_name), 'w', encoding = "utf-8")
objects = bpy.context.scene.objects
for ob in objects:
if ob.type =="MESH":
name = ob.name
loc = tuple(ob.location)
sc = tuple(ob.scale)
rot = [grados(ob.rotation_euler[0]), grados(ob.rotation_euler[1]), grados(ob.rotation_euler[2])]
#print(name, " ", loc, " ", sc, " ", rot)
dato = (ob.name," Location: ", loc, " Scale: ", sc, " Rotation: ", rot )
#write data in file
file1.write(str(dato) + "\n")
Data in example File
('Camp03_d_M', ' Location: ', (2.051640748977661, -9.229787826538086, 3.8183751106262207), ' Scale: ', (0.009999999776482582, 0.009999999776482582, 0.009999999776482582), ' Rotation: ', [-2.5045391752303115e-06, 0.0, 0.0])
('Chest04_b_M', ' Location: ', (-5.014889717102051, 9.133461952209473, 0.4422152042388916), ' Scale: ', (0.009999999776482582, 0.009999999776482582, 0.009999999776482582), ' Rotation: ', [-2.5045391752303115e-06, -0.0, 34.7200101016957])
('Cave03_b_M', ' Location: ', (9.234975814819336, -3.575174570083618, 1.100429892539978), ' Scale: ', (0.009999999776482582, 0.009999999776482582, 0.009999999776482582), ' Rotation: ', [0.0, 0.0, 0.0])
('Mushroom_01_c_M', ' Location: ', (-3.480337619781494, -6.187094211578369, 0.0), ' Scale: ', (0.009999999776482582, 0.009999999776482582, 0.009999999776482582), ' Rotation: ', [-2.5045391752303115e-06, 4.3790753729046344e-13, 1.0018156700921246e-05])
('Cave02_d_M', ' Location: ', (5.984580039978027, 6.0595479011535645, 0.009999999776482582), ' Scale: ', (0.009999999776482582, 0.009999999776482582, 0.009999999776482582), ' Rotation: ', [-2.5045391752303115e-06, 0.0, 0.0])
('Cave01_i_M', ' Location: ', (0.21695758402347565, -22.943309783935547, 0.0), ' Scale: ', (0.009999999776482582, 0.009999999776482582, 0.009999999776482582), ' Rotation: ', [-2.5045391752303115e-06, 0.0, 0.0])
('Camp03_e_M', ' Location: ', (2.5243210792541504, -10.289156913757324, 0.08987780660390854), ' Scale: ', (0.009999999776482582, 0.009999999776482582, 0.009999999776482582), ' Rotation: ', [-18.6159640501321, -0.0, 0.0])
('Campfire02_M', ' Location: ', (-0.045725017786026, 3.182037830352783, 0.014999999664723873), ' Scale: ', (0.009999999776482582, 9.933311230270192e-05, 0.009999999776482582), ' Rotation: ', [-2.5045391752303115e-06, 0.0, 0.0])
('Camp02_c_M', ' Location: ', (2.1111268997192383, -9.031360626220703, 0.12468037754297256), ' Scale: ', (0.009999999776482582, 0.009999999776482582, 0.009999999776482582), ' Rotation: ', [-2.5045391752303115e-06, 0.0, 0.0])
('Camp01_c_M', ' Location: ', (0.11259043216705322, 0.0, 0.014999999664723873), ' Scale: ', (0.009999999776482582, 0.009999999776482582, 0.009999999776482582), ' Rotation: ', [-2.5045391752303115e-06, -0.0, -90.00219852171104])
('Chest04_a_M', ' Location: ', (-5.014889717102051, 9.133461952209473, 0.43558287620544434), ' Scale: ', (0.009999999776482582, 0.009999999776482582, 0.009999999776482582), ' Rotation: ', [-2.5045391752303115e-06, -0.0, 34.7200101016957])
('Cave01_h_M', ' Location: ', (0.0, 0.0, 0.0), ' Scale: ', (0.009999999776482582, 0.009999999776482582, 0.009999999776482582), ' Rotation: ', [-2.5045391752303115e-06, 0.0, 0.0])
Load in with AppGameKit code
type obj_data
objName$
obj_x_pos#
obj_y_pos#
obj_z_pos#
obj_x_scl#
obj_y_scl#
obj_z_scl#
obj_x_rot#
obj_y_rot#
obj_z_rot#
obj_ID
endtype
function load3dmap()
level_texture = LoadImage( "gnollcave.png")
mapfiledata = OpenToRead( "data.txt" )
objdata$ = ReadString(mapfiledata)
Closefile(mapfiledata)
token_count = CountStringTokens( objdata$, "(',:)[] " )
file_lines = token_count/14 // 14 Tokens per Line
dim level [file_lines] as obj_data
for i=0 to file_lines-1
level[i].objName$ = GetStringToken( objdata$, "(',:)[] ",(i*14)+1)+".fbx"
level[i].obj_x_pos# = ValFloat(GetStringToken( objdata$, "(',:)[] ",(i*14)+3))
level[i].obj_y_pos# = ValFloat(GetStringToken( objdata$, "(',:)[] ",(i*14)+5))
level[i].obj_z_pos# = ValFloat(GetStringToken( objdata$, "(',:)[] ",(i*14)+4))
level[i].obj_x_scl# = ValFloat(GetStringToken( objdata$, "(',:)[] ",(i*14)+7))
level[i].obj_y_scl# = ValFloat(GetStringToken( objdata$, "(',:)[] ",(i*14)+9))
level[i].obj_z_scl# = ValFloat(GetStringToken( objdata$, "(',:)[] ",(i*14)+8))
level[i].obj_x_rot# = ValFloat(GetStringToken( objdata$, "(',:)[] ",(i*14)+11))
level[i].obj_y_rot# = ValFloat(GetStringToken( objdata$, "(',:)[] ",(i*14)+13))
level[i].obj_z_rot# = ValFloat(GetStringToken( objdata$, "(',:)[] ",(i*14)+12))
level[i].obj_ID = LoadObject( level[i].objName$ )
SetObjectImage ( level[i].obj_ID, level_texture, 0 )
SetObjectPosition( level[i].obj_ID, level[i].obj_x_pos#, level[i].obj_y_pos#, level[i].obj_z_pos# )
SetObjectScale ( level[i].obj_ID, level[i].obj_x_scl#, level[i].obj_y_scl#, level[i].obj_z_scl# )
SetObjectRotation ( level[i].obj_ID, level[i].obj_x_rot#, level[i].obj_y_rot#, level[i].obj_z_rot# )
next i
endfunction
load3dmap()
This will load in all your level assets. I am not sure if this is the most efficient thing. Obviously, I am open to suggestions. I have beginner knowledge when it comes to programming.