Código:
import bpy.
Def read_some_data(context, filepath, use_some_setting):
Print(running read_some_data.).
File = open(filepath,
, encoding=utf-8).
Print(file, readline()).
File, readline().
CfType=file, readline(), replace(Type=,\).
Print(cfType).
Scene_name=cfType.
Sc=bpy, data, scenes, new(scene_name).
For scrn in bpy, data, screns:
If scrn, name == Default:
Bpy, context.window.screen = scrn.
Bpy, context, screen, scene=sc.
Numeroparts=int(file, readline(), replace(Number of blocks=,\)).
Print(numeroparts).
Numerovertxpart=[].
Numerofacexpart=[].
File, readline() t t t.
For i in range(0, numeroparts):
Line=file, readline().
Print(line, split()[0]).
Print(line, split()[1]).
Numerovertxpart, append(int(line, split()[0])).
Print(numerovertxpart[i]).
Numerofacexpart, append(int(line, split()[1])).
Print(numerofacexpart[i]) t t t t t t t.
Malla=[].
Ob=[].
For i in range(0, numeroparts):
Malla, append(bpy, data, meshes, new(name=2k_Part+str(i))).
Uv = [].
xyz= [].
For in range(0, numerovertxpart[i]):
Line=file, readline().
x, y, z, u, =float(line, split()[0].replace(,.)), float(line, split()[1].replace(,.)), float(line, split()[2].replace(,.)), float(line, split()[3].replace(,.)), float(line, split()[4].replace(,.)).
Uv, append((u,)).
xyz, append((x, y, z)).
Print(x, y, z).
#malla[i].vértices, add(1).
#malla[i].vértices[i].co=(float(x), float(y), float(z)) t .
A = [].
Bb = [].
Cc = [].
Faces= [] t .
For in range(0, numerofacexpart[i]):
Line=file, readline().
A, b, c=int(line, split()[0]), int(line, split()[1]), int(line, split()[2]).
Faces, append((a, b, c)).
A, append(a).
Bb, append(b).
Cc, append(c).
Print(a, b, c).
Malla[i].from_pydata(xyz, [], faces) t t.
For que in range(len(malla[i].polygons)):
#malla[i].faces[q].mode |= Blender. Mesh. FaceModes[TWOSIDE].
#malla[i].faces[q].transp = Blender. NMesh. FaceTranspModes[ALPHA].
#malla[i].faces[q].uv=Mathutils. Vector(uv[a[q]), Mathutils. Vector(uv[bb[q]), Mathutils. Vector(uv[cc[q]).
Print(i) t t t .
Scn =bpy, context, scene.
Objeto=bpy, data, objects, new(Part+str(i), malla[i]).
Objeto, modificadores, new(Subsurf, type=SUBSURF).
Objeto, modificadores, new(Subsurf, type=SUBSURF).
Scn, objects, link(objeto).
Scn, update().
File, close().
# would normally load the data here.
Return {FINISHED}.
# ImportHelper is a helper class, defines filename and.
# invoke() function which calls the file selector.
From bpy_extras, io_utils import ImportHelper.
From bpy, props import StringProperty, BolProperty, EnumProperty.
From bpy, types import Operator.
Class ImportSomeData(Operator, ImportHelper):
\This appears in the toltip of the operator and in the generated docs.
Bl_idname = import_test, cf_import # important since its how bpy, ops, import_test, some_data is constructed.
Bl_label = Import CF.
# ImportHelper mixin class uses this.
Filename_ext = .cf.
Filter_glob = StringProperty(.
Default=*.cf.
Options={HIDEN}.
).
# List of operator properties, the attributes will be assigned.
# to the class instance from the operator settings before calling.
Use_setting = BolProperty(.
Name=Example Bolean.
Description=Example Toltip.
Default=True.
).
Type = EnumProperty(.
Name=Example Enum.
Description=Chose betwen two items.
Items=((OPT_A, First Option, Description one).
(OPT_B, Second Option, Description two)).
Default=OPT_A.
).
Def execute (self, context):
Return read_some_data(context, self, filepath, self, use_setting).
# Only neded if you want to add into a dynamic menu.
Def menu_func_import(self, context):
Self, layout, operator(ImportSomeData, bl_idname, text=Text Import Operator).
Def register():
Bpy, utils, register_class(ImportSomeData).
Bpy, types. INFO_MT_file_import, append(menu_func_import).
Def unregister():
Bpy, utils, unregister_class(ImportSomeData).
Bpy, types. INFO_MT_file_import, remove(menu_func_import).
If __name__ == __main__:
Register().
# test call.
Bpy, ops, import_test, cf_import(INVOKE_DEFAULT).
.