Cuda use streams and async to avoid busywaiting
[blender.git] / intern / cycles / app / io_export_cycles_xml.py
1 #
2 # Copyright 2011-2013 Blender Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License
15 #
16
17 # XML exporter for generating test files, not intended for end users
18
19 import os
20 import xml.etree.ElementTree as etree
21 import xml.dom.minidom as dom
22
23 import bpy
24 from bpy_extras.io_utils import ExportHelper
25 from bpy.props import PointerProperty, StringProperty
26
27 def strip(root):
28     root.text = None
29     root.tail = None
30
31     for elem in root:
32         strip(elem)
33
34 def write(node, fname):
35     strip(node)
36
37     s = etree.tostring(node)
38     s = dom.parseString(s).toprettyxml()
39
40     f = open(fname, "w")
41     f.write(s)
42     
43 class CyclesXMLSettings(bpy.types.PropertyGroup):
44     @classmethod
45     def register(cls):
46         bpy.types.Scene.cycles_xml = PointerProperty(
47                                         type=cls,
48                                         name="Cycles XML export Settings",
49                                         description="Cycles XML export settings")
50         cls.filepath = StringProperty(
51                         name='Filepath',
52                         description='Filepath for the .xml file',
53                         maxlen=256,
54                         default='',
55                         subtype='FILE_PATH')
56                         
57     @classmethod
58     def unregister(cls):
59         del bpy.types.Scene.cycles_xml
60         
61 # User Interface Drawing Code
62 class RenderButtonsPanel():
63     bl_space_type = 'PROPERTIES'
64     bl_region_type = 'WINDOW'
65     bl_context = "render"
66
67     @classmethod
68     def poll(self, context):
69         rd = context.scene.render
70         return rd.engine == 'CYCLES'
71
72
73 class PHYSICS_PT_fluid_export(RenderButtonsPanel, bpy.types.Panel):
74     bl_label = "Cycles XML Exporter"
75
76     def draw(self, context):
77         layout = self.layout
78         
79         cycles = context.scene.cycles_xml
80         
81         #layout.prop(cycles, "filepath")
82         layout.operator("export_mesh.cycles_xml")
83
84         
85 # Export Operator
86 class ExportCyclesXML(bpy.types.Operator, ExportHelper):
87     bl_idname = "export_mesh.cycles_xml"
88     bl_label = "Export Cycles XML"
89
90     filename_ext = ".xml"
91
92     @classmethod
93     def poll(cls, context):
94         return (context.active_object is not None)
95
96     def execute(self, context):
97         filepath = bpy.path.ensure_ext(self.filepath, ".xml")
98
99         # get mesh
100         scene = context.scene
101         object = context.active_object
102
103         if not object:
104             raise Exception("No active object")
105
106         mesh = object.to_mesh(scene, True, 'PREVIEW')
107
108         if not mesh:
109             raise Exception("No mesh data in active object")
110
111         # generate mesh node
112         nverts = ""
113         verts = ""
114         P = ""
115
116         for v in mesh.vertices:
117             P += "%f %f %f  " % (v.co[0], v.co[1], v.co[2])
118
119         for i, f in enumerate(mesh.tessfaces):
120             nverts += str(len(f.vertices)) + " "
121
122             for v in f.vertices:
123                 verts += str(v) + " "
124             verts += " "
125
126         node = etree.Element('mesh', attrib={'nverts': nverts, 'verts': verts, 'P': P})
127         
128         # write to file
129         write(node, filepath)
130
131         return {'FINISHED'}
132
133 def register():
134     bpy.utils.register_module(__name__)
135
136 def unregister():
137     bpy.utils.unregister_module(__name__)
138
139 if __name__ == "__main__":
140     register()
141