~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to release/scripts/radiosity_export.py

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!BPY
2
2
 
3
3
"""
4
 
Name: 'Radiosity...'
 
4
Name: 'Radiosity (.radio)...'
5
5
Blender: 232
6
6
Group: 'Export'
7
 
Tooltip: 'Export selected mesh (with vertex colors) to Radiosity File Format (*.radio)'
8
 
"""
9
 
 
 
7
Tooltip: 'Export selected mesh (with vertex colors) to Radiosity File Format (.radio)'
 
8
"""
 
9
 
 
10
__author__ = "Anthony D'Agostino (Scorpius)"
 
11
__url__ = ("blender", "elysiun",
 
12
"Author's homepage, http://www.redrival.com/scorpius")
 
13
__version__ = "Part of IOSuite 0.5"
 
14
 
 
15
__bpydoc__ = """\
 
16
This script exports meshes to Radiosity file format.
 
17
 
 
18
The Radiosity file format is my own personal format. I created it to
 
19
learn how meshes and vertex colors were stored. See IO-Examples.zip, the
 
20
example *.radio files on my web page.
 
21
 
 
22
Usage:<br>
 
23
        Select meshes to be exported and run this script from "File->Export" menu.
 
24
 
 
25
Notes:<br>
 
26
        Before exporting to .radio format, the mesh must have vertex colors.
 
27
Here's how to assign them:
 
28
 
 
29
1. Use radiosity!
 
30
 
 
31
2. Set up lights and materials, select a mesh, switch the drawing mode
 
32
to "textured," press the VKEY.
 
33
 
 
34
3. Press the VKEY and paint manually.
 
35
 
 
36
4. Use a custom script to calculate and apply simple diffuse shading and
 
37
specular highlights to the vertex colors.
 
38
 
 
39
5. The Videoscape format also allows vertex colors to be specified.
 
40
"""
 
41
 
 
42
# $Id: radiosity_export.py,v 1.7 2005/03/21 05:26:52 ianwill Exp $
 
43
#
10
44
# +---------------------------------------------------------+
11
45
# | Copyright (c) 2002 Anthony D'Agostino                   |
12
 
# | http://ourworld.compuserve.com/homepages/scorpius       |
13
 
# | scorpius@compuserve.com                                 |
 
46
# | http://www.redrival.com/scorpius                        |
 
47
# | scorpius@netzero.com                                    |
14
48
# | April 11, 2002                                          |
15
49
# | Released under the Blender Artistic Licence (BAL)       |
16
50
# | Import Export Suite v0.5                                |
18
52
# | Read and write Radiosity File Format (*.radio)          |
19
53
# +---------------------------------------------------------+
20
54
 
21
 
import Blender
 
55
import Blender, meshtools
22
56
#import time
23
 
import mod_flags, mod_meshtools
 
57
 
24
58
try:
25
59
        import struct
26
60
except:
27
61
        msg = "Error: you need a full Python install to run this script."
28
 
        mod_meshtools.print_boxed(msg)
 
62
        meshtools.print_boxed(msg)
 
63
        Blender.Draw.PupMenu("ERROR%t|"+msg)
29
64
 
30
65
# ================================
31
66
# ====== Write Radio Format ======
40
75
        mesh = Blender.NMesh.GetRaw(meshname)
41
76
        obj = Blender.Object.Get(objname)
42
77
 
43
 
        if not mesh.hasVertexColours():
44
 
                message = "Please assign vertex colors before exporting.\n"
 
78
        if not meshtools.has_vertex_colors(mesh):
 
79
                message = "Please assign vertex colors before exporting. \n"
45
80
                message += objname + " object was not saved."
46
 
                mod_meshtools.print_boxed(message)
 
81
                meshtools.print_boxed(message)
 
82
                Blender.Draw.PupMenu("ERROR%t|"+message)
47
83
                return
48
84
 
49
85
        # === Object Name ===
53
89
        # === Vertex List ===
54
90
        file.write(struct.pack("<l", len(mesh.verts)))
55
91
        for i in range(len(mesh.verts)):
56
 
                if not i%100 and mod_flags.show_progress:
 
92
                if not i%100 and meshtools.show_progress:
57
93
                        Blender.Window.DrawProgressBar(float(i)/len(mesh.verts), "Writing Verts")
58
94
 
59
95
                x, y, z = mesh.verts[i].co
62
98
        # === Face List ===
63
99
        file.write(struct.pack("<l", len(mesh.faces)))
64
100
        for i in range(len(mesh.faces)):
65
 
                if not i%100 and mod_flags.show_progress:
 
101
                if not i%100 and meshtools.show_progress:
66
102
                        Blender.Window.DrawProgressBar(float(i)/len(mesh.faces), "Writing Faces")
67
103
 
68
104
                file.write(struct.pack("<b", len(mesh.faces[i].v)))
80
116
        #end = time.clock()
81
117
        #seconds = " in %.2f %s" % (end-start, "seconds")
82
118
        message = "Successfully exported " + Blender.sys.basename(filename)# + seconds
83
 
        mod_meshtools.print_boxed(message)
 
119
        meshtools.print_boxed(message)
84
120
 
85
121
def fs_callback(filename):
86
122
        if filename.find('.radio', -6) <= 0: filename += '.radio'
87
123
        write(filename)
88
124
 
89
 
Blender.Window.FileSelector(fs_callback, "Radio Export")
 
125
Blender.Window.FileSelector(fs_callback, "Export Radio")