4 def collect_object_lods(self, obj):
6 lods += sorted([c for c in obj.children if c.lod_for_parent], key=(lambda l: l.lod_index))
7 for i, l in enumerate(lods):
8 if i>0 and l.lod_index!=i:
9 raise Exception("Invalid configuration on object {}: Inconsistent LOD indices".format(obj.name))
13 def export_object_resources(self, ctx, obj, resources):
14 lods = self.collect_object_lods(obj)
16 from .export_mesh import MeshExporter
17 from .export_material import MaterialExporter
18 from .mesh import create_mesh_from_object
19 from .material import Material
20 mesh_export = MeshExporter()
21 material_export = MaterialExporter()
23 ctx.set_slices(len(lods))
25 lod_index = l.lod_index if l.lod_for_parent else 0
26 task = ctx.next_slice("LOD {}".format(lod_index))
28 if l.material_slots and l.material_slots[0].material:
29 material = l.material_slots[0].material
30 subtask = task.task(material, 0.1)
31 if material.render_mode!='EXTERNAL':
32 tech_name = material.name+".tech"
33 if tech_name not in resources:
34 material = Material(material)
35 material_export.export_technique_resources(subtask, material, resources)
36 resources[tech_name] = material_export.export_technique(material, resources)
37 elif "stub.tech" not in resources:
38 resources["stub.tech"] = self.export_stub_technique()
40 mesh_name = l.data.name+".mesh"
41 if mesh_name not in resources:
42 subtask = task.task(l.data, 1.0)
43 mesh = create_mesh_from_object(subtask, l)
44 mesh_res = mesh_export.export_mesh(subtask, mesh)
45 resources[mesh_name] = mesh_res
47 def export_object(self, obj, resources):
49 raise ValueError("Object {} is not a mesh".format(obj.name))
51 lods = self.collect_object_lods(obj)
53 from .datafile import Resource, Statement
54 obj_res = Resource(obj.name+".object", "object")
55 statements = obj_res.statements
57 from .util import compute_bounding_sphere
58 center, radius = compute_bounding_sphere([v.co for v in obj.data.vertices])
59 statements.append(Statement("bounding_sphere_hint", *center, radius))
63 for i, l in enumerate(lods):
66 if l.data.name!=prev_mesh:
67 mesh_res = resources[l.data.name+".mesh"]
68 lod_st.append(obj_res.create_reference_statement("mesh", mesh_res))
70 prev_mesh = l.data.name
74 material = l.material_slots[0].material
76 if material.render_mode=='EXTERNAL':
77 tech_name = material.technique
79 tech_name = material.name+".tech"
81 tech_name = "stub.tech"
83 if tech_name!=prev_tech:
84 if material and material.render_mode=='EXTERNAL':
85 lod_st.append(Statement("technique", material.technique))
87 lod_st.append(obj_res.create_reference_statement("technique", resources[tech_name]))
91 st = Statement("level_of_detail", i)
99 def export_stub_technique(self):
100 from .datafile import Resource, Statement, Token
101 tech_res = Resource("stub.tech", "technique")
102 pass_st = Statement("method", "")
103 tech_res.statements.append(pass_st)
104 mat_st = Statement("material")
105 pass_st.sub.append(mat_st)
106 mat_st.sub.append(Statement("type", Token("basic")))