annotate SceneGraph/BlenderScript/export_xml1209.py @ 217:897aeb144569

fix
author gongo@localhost.localdomain
date Wed, 04 Feb 2009 22:50:42 +0900
parents dc68bc5c9e41
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
171
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
1 #!BPY
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
2 """Registration info for Blender menus:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
3 Name: 'Libps3 (.xml)'
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
4 Blender: 240
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
5 Group: 'Export'
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
6 Tooltip: 'Export to (.xml) for libps3'
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
7 """
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
8
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
9
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
10 ######################################################
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
11 # Importing modules
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
12 ######################################################
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
13
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
14 import math
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
15 #import subprocess
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
16 import os
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
17 import Blender
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
18 import struct
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
19 import base64
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
20 from Blender import NMesh, Scene, Object, Material, Texture, Window
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
21 from Blender import sys as bsys, Mathutils, Draw, BGL
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
22 from Blender.sys import *
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
23
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
24
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
25 def info(object, spacing=10, collapse=1):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
26 """Print methods and doc strings.
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
27
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
28 Takes module, class, list, dictionary, or string."""
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
29 methodList = [e for e in dir(object) if callable(getattr(object, e))]
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
30 processFunc = collapse and (lambda s: " ".join(s.split())) or (lambda s: s)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
31 print "\n".join(["%s %s" %
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
32 (method.ljust(spacing),
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
33 processFunc(str(getattr(object, method).__doc__)))
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
34 for method in methodList])
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
35
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
36
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
37 ######################################################
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
38 # Data Structures
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
39 ######################################################
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
40
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
41
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
42
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
43
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
44 ######################################################
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
45 # Functions
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
46 ######################################################
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
47
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
48 # Image Get ?
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
49 # New name based on old with a different extension
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
50 def newFName(ext):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
51 return Blender.Get('filename')[: -len(Blender.Get('filename').split('.', -1)[-1]) ] + ext
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
52
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
53
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
54 #exporting an anime
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
55 ###change
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
56 #def export_anime(object_name):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
57 def export_anime(object_name,file):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
58 startF = Blender.Get('staframe')
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
59 endF = Blender.Get('endframe')
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
60 #str = ""
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
61 file.write("")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
62 file.write("\t\t<anim frame=\"%d\">\n" %(endF) )
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
63 for i in range (startF, endF+1):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
64 Blender.Set('curframe', i)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
65 Blender.Redraw()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
66 time1 = Blender.sys.time()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
67
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
68 ##### XML header ######
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
69 #get all the objects in this scene
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
70 activelayers = Window.ViewLayer()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
71 for i in range(len(activelayers)):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
72 activelayers[i] = 2**(activelayers[i]-1)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
73 object_list1 = Blender.Scene.GetCurrent().getChildren()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
74 object_list = []
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
75 matnames= []
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
76 for obj in object_list1:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
77 if obj.Layer in activelayers:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
78 object_list.append(obj)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
79
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
80 if obj.getType() == "Mesh":
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
81 materials_obj_list = []
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
82 materials_obj_list = obj.getData().materials
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
83 for mat in materials_obj_list:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
84 if mat.name not in matnames:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
85 matnames.append(mat.name)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
86
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
87 ##### Process Meshes ######
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
88 for obj in object_list:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
89 matrix = obj.getMatrix()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
90 if obj == object_name:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
91 file.write("\t\t\t%f %f %f\n" %(matrix[3][0], matrix[3][1], matrix[3][2]) )
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
92
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
93 file.write("\t\t</anim>\n")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
94 #return str
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
95
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
96
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
97
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
98 # exporting a mesh
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
99 ##change
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
100 #def exportMesh(mesh, obj):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
101 def exportMesh(mesh, obj, file):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
102
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
103 vdata = [] # list of [ii0, ii1, ii2, ...] lists indexed by Blender-Vertex-index
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
104 vlist = []
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
105 flist = []
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
106 tri_first = []
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
107 tri_second = []
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
108 tri_third = []
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
109
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
110 def addVertex(bvindex, coord, normal, uv):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
111 index = -1
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
112 if bvindex < len(vdata):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
113 for ivindex in vdata[bvindex]:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
114 v = vlist[ivindex]
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
115 if (abs(v[0][0]-coord[0])<0.0001) and \
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
116 (abs(v[0][1]-coord[1])<0.0001) and \
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
117 (abs(v[0][2]-coord[2])<0.0001) and \
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
118 (abs(v[1][0]-normal[0])<0.0001) and \
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
119 (abs(v[1][1]-normal[1])<0.0001) and \
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
120 (abs(v[1][2]-normal[2])<0.0001):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
121 if ((v[2]==[]) and (uv==[])) or \
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
122 ((abs(v[2][0]-uv[0])<0.0001) and \
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
123 (abs(v[2][1]-uv[1])<0.0001)):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
124 index = ivindex
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
125 if index < 0:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
126 index = len(vlist)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
127 vlist.append([coord, normal, uv])
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
128 while bvindex >= len(vdata):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
129 vdata.append([])
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
130 vdata[bvindex].append(index)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
131 return index
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
132
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
133 def addFace(mindex, index0, index1, index2):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
134 while mindex >= len(flist):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
135 flist.append([])
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
136 flist[mindex].append([index0, index1, index2])
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
137
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
138 ###change
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
139 def getFaces():
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
140 ##change
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
141 #str = ""
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
142 file.write("")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
143 matrix = obj.getMatrix()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
144
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
145 for mindex in range(len(flist)):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
146 fl = flist[mindex]
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
147 if fl != []:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
148 parent_name = obj.getParent()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
149 if parent_name:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
150 parent_name = "%s" %parent_name
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
151 ###change
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
152 #str += "\t<surface name=\"%s\" size=\"%d\" prim=\"Triangle\" parent=%s>\n" %(obj.name, len(fl)*3, parent_name[8:-1])
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
153 file.write("\t<surface name=\"%s\" size=\"%d\" prim=\"Triangle\" parent=%s>\n" %(obj.name, len(fl)*3, parent_name[8:-1]) )
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
154 else:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
155 ###change
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
156 #str += "\t<surface name=\"%s\" size=\"%d\" prim=\"Triangle\" parent=\"NULL\">\n" %(obj.name, len(fl)*3)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
157 file.write("\t<surface name=\"%s\" size=\"%d\" prim=\"Triangle\" parent=\"NULL\">\n" %(obj.name, len(fl)*3) )
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
158 ###change
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
159 #str += "\t\t<coordinate>\n"
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
160 file.write("\t\t<coordinate>\n")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
161 for f in fl:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
162 tri_first = vlist[f[0]]
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
163 tri_second = vlist[f[1]]
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
164 tri_third = vlist[f[2]]
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
165
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
166 file.write("\t\t\t%f %f %f\n" %(tri_first[0][0] + matrix[3][0], tri_first[0][1] + matrix[3][1], tri_first[0][2] + matrix[3][2]) )
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
167 file.write("\t\t\t%f %f %f\n" %(tri_second[0][0] + matrix[3][0], tri_second[0][1] + matrix[3][1], tri_second[0][2] + matrix[3][2]) )
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
168 file.write("\t\t\t%f %f %f\n" %(tri_third[0][0] + matrix[3][0], tri_third[0][1] + matrix[3][1], tri_third[0][2] + matrix[3][2]) )
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
169 file.write("\t\t</coordinate>\n")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
170
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
171 file.write("\t\t<normal>\n")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
172 for f in fl:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
173 tri_first = vlist[f[0]]
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
174 tri_second = vlist[f[1]]
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
175 tri_third = vlist[f[2]]
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
176
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
177 file.write("\t\t\t%f %f %f\n" %(tri_first[1][0], tri_first[1][1], tri_first[1][2]) )
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
178 file.write("\t\t\t%f %f %f\n" %(tri_second[1][0], tri_second[1][1], tri_second[1][2]) )
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
179 file.write("\t\t\t%f %f %f\n" %(tri_third[1][0], tri_third[1][1], tri_third[1][2]) )
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
180 file.write("\t\t</normal>\n" )
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
181
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
182 file.write("\t\t<model>\n" )
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
183 ###parameter of translate
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
184 file.write("\t\t\t%f %f %f\n" % (matrix[3][0], matrix[3][1], matrix[3][2]) )
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
185 file.write("\t\t</model>\n")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
186
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
187 if tri_first[2] != []:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
188 file.write("\t\t<texture>\n")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
189 for f in fl:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
190 tri_first = vlist[f[0]]
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
191 tri_second = vlist[f[1]]
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
192 tri_third = vlist[f[2]]
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
193
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
194 file.write("\t\t\t%f %f\n" %(tri_first[2][0], tri_first[2][1]) )
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
195 file.write("\t\t\t%f %f\n" %(tri_second[2][0], tri_second[2][1]) )
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
196 file.write("\t\t\t%f %f\n" %(tri_third[2][0], tri_third[2][1]) )
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
197 file.write("\t\t</texture>\n")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
198 else:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
199 file.write("\t\t<texture/>\n")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
200
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
201
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
202 ### get texture_image and change base64 data
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
203 texture = mesh.faces[0].image
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
204 if texture:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
205 file.write("\t\t<image name=\"%s\">\n" %(texture.getName()) )
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
206 image_path = texture.getFilename()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
207 #file.write("print_path = %s" %(image_path) )
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
208 input = open(expandpath(image_path), 'r')
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
209 #input = open('/Users/tkaito/CVS/Game_project/student/y06/e065725/SG_cube/xml/image_file/sample_white.png', 'r')
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
210 output = open('output.txt', 'w')
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
211 base64.encode(input,output)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
212 input.close()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
213 output.close()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
214 input = open('output.txt', 'r')
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
215 for b64 in input.readlines():
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
216 file.write("\t\t\t%s" %b64)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
217 input.close()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
218 file.write("\t\t</image>\n")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
219 else:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
220 file.write("\t\t<image name=\"%s\">\n" %("sample_white.png") )
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
221
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
222 file.write("\t\t\tiVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAAAAADhZOFXAAAAEElEQVQImWP8zwABTAwUMQBJQQEP\n");
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
223 file.write("\t\t\tlYH+agAAAABJRU5ErkJggg==\n");
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
224
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
225 file.write("\t\t</image>\n")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
226
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
227 #return str
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
228
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
229 vdata = []
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
230 vlist = []
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
231 flist = []
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
232 for face in mesh.faces:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
233 iis = [-1, -1, -1, -1]
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
234 for vi in range(len(face.v)):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
235 vert = face.v[vi]
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
236 if face.smooth:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
237 normal = vert.no
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
238 else:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
239 normal = face.no
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
240 if len(face.uv) == len(face.v):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
241 uv = face.uv[vi]
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
242 else:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
243 uv = []
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
244 iis[vi] = addVertex(vert.index, vert.co, normal, uv)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
245 addFace(face.materialIndex, iis[0], iis[1], iis[2])
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
246 if len(face.v)==4:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
247 addFace(face.materialIndex, iis[2], iis[3], iis[0])
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
248
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
249 #str = ""
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
250 #str += getFaces()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
251 getFaces();
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
252
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
253 #return str
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
254
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
255
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
256 ######################################################
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
257 # EXPORT
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
258 ######################################################
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
259 def save_xml(filename, unindexedname, anim):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
260 print("XML EXPORT\n")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
261 time1 = Blender.sys.time()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
262 print("Saving to '" + filename + "'...\n")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
263 file = open(filename, 'w')
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
264
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
265 count_h = 0
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
266 n = 0
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
267 filename_h = filename[:-4] + ".h" #header file for cpp
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
268 file_h = open(filename_h, 'w')
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
269
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
270 ##### XML header ######
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
271 file.write("<?xml version=\"1.0\"?>\n")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
272
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
273 #get all the objects in this scene
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
274 activelayers = Window.ViewLayer()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
275 for i in range(len(activelayers)):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
276 activelayers[i] = 2**(activelayers[i]-1)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
277 object_list1 = Blender.Scene.GetCurrent().getChildren()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
278 object_list = []
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
279 matnames= []
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
280 for obj in object_list1:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
281 if obj.Layer in activelayers:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
282 object_list.append(obj)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
283
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
284 if obj.getType() == "Mesh":
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
285 materials_obj_list = []
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
286 materials_obj_list = obj.getData().materials
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
287 for mat in materials_obj_list:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
288 if mat.name not in matnames:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
289 matnames.append(mat.name)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
290
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
291 ##### Process Meshes ######
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
292 meshlist = []
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
293 file.write("<OBJECT-3D>\n")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
294 for obj in object_list:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
295 if obj.getType() == "Mesh":
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
296 objectname = obj.getName()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
297 mesh = Blender.NMesh.GetRawFromObject(objectname)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
298 meshname = mesh.name
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
299 meshlight = 0
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
300 if len(mesh.materials) > 0:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
301 mat0 = mesh.materials[0]
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
302 if mat0.emit > 0:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
303 meshlight = 1
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
304 if meshlight:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
305 print "processing Object \"%s\" as Meshlight (Mesh \"%s\")..." %(objectname, meshname)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
306 else:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
307 print "processing Object \"%s\" (Mesh \"%s\")..." %(objectname, meshname)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
308 try:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
309 meshlist.index(meshname)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
310 except ValueError:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
311 ###change
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
312 #file.write(exportMesh(mesh,obj))
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
313 exportMesh(mesh,obj,file)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
314 meshlist.append(meshname)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
315 if anim == 1:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
316 #file.write("\t\t<anim>\n")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
317 ###change
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
318 #file.write(export_anime(obj))
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
319 export_anime(obj,file)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
320 #file.write("\t\t</anim>\n")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
321 file.write("\t</surface>\n")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
322 file_h.write("#define %s scene_graph" %(obj.name))
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
323 while n != count_h:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
324 file_h.write("->next")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
325 n = n + 1
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
326 file_h.write("\n")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
327 count_h = count_h + 1
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
328 n = 0
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
329
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
330
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
331 ##### XML FOOTER ######
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
332 file.write("</OBJECT-3D>")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
333 file.close()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
334 file_h.close()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
335 print("Finished.\n")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
336
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
337 time2 = Blender.sys.time()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
338 print("Processing time: %f\n" %(time2-time1))
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
339 Draw.Exit()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
340
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
341
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
342 ### SAVE ANIMATION ###
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
343 def save_anim(filename):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
344 global MatSaved
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
345
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
346 MatSaved = 0
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
347 unindexedname = filename
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
348 save_xml(filename, unindexedname, 1)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
349
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
350
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
351 #### SAVE STILL (hackish...) ####
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
352 def save_still(filename):
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
353 global MatSaved
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
354
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
355 MatSaved = 0
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
356 unindexedname = filename
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
357 save_xml(filename, unindexedname, 0)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
358
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
359 ######################################################
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
360 # Settings GUI
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
361 ######################################################
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
362
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
363 # Assign event numbers to buttons
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
364 evtNoEvt = 0
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
365 evtExport = 1
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
366 evtExportAnim = 2
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
367
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
368 # Set initial values of buttons
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
369
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
370 ## <size>800 600</size>
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
371
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
372 sceneSizeX = Scene.GetCurrent().getRenderingContext().imageSizeX()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
373 sceneSizeY = Scene.GetCurrent().getRenderingContext().imageSizeY()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
374
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
375 SizeX = Draw.Create(sceneSizeX)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
376 SizeY = Draw.Create(sceneSizeY)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
377 TexExponent = Draw.Create(2.3)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
378
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
379 ## <metropolis>1</metropolis>
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
380 MLT = Draw.Create(1)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
381
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
382 ## <large_mutation_prob>0.1</large_mutation_prob>
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
383 LMP = Draw.Create(0.1)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
384
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
385 ## <max_change>0.02</max_change>
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
386 MaxChange = Draw.Create(0.02)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
387
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
388 ## <russian_roulette_live_prob>0.7</russian_roulette_live_prob>
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
389 RRLP = Draw.Create(0.7)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
390
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
391 ## <max_depth>100</max_depth>
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
392 MaxDepth = Draw.Create(100)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
393
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
394 ## <bidirectional>false</bidirectional>
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
395 Bidirectional = Draw.Create(0)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
396
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
397 ## <strata_width>14</strata_width>
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
398 StrataWidth = Draw.Create(14)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
399
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
400 ## <logging>0</logging>
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
401 Logging = Draw.Create(0)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
402
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
403 ## <save_untonemapped_exr>false</save_untonemapped_exr>
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
404 SaveUTMExr = Draw.Create(0)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
405
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
406 ## <save_tonemapped_exr>false</save_tonemapped_exr>
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
407 SaveTMExr = Draw.Create(0)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
408
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
409 ## <lens_radius>0.0</lens_radius>
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
410 LensRadius = Draw.Create(0.0)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
411
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
412 ## <focus_distance>2.0</focus_distance>
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
413 FocusDistance = Draw.Create(2.0)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
414
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
415 ## <turbidity>2.0</turbidity>
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
416 Turbidity = Draw.Create(2.0)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
417
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
418 GroundPlane = Draw.Create(1)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
419
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
420 ## Separate materials
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
421 MatFile = Draw.Create(1)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
422
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
423 # text color fix
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
424 textcol = [0, 0, 0]
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
425
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
426
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
427 def gui():
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
428 global evtNoEvt, evtExport, evtExportAnim
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
429 global SizeX, SizeY, TexExponent, MLT, LMP, MaxChange, RRLP, MaxDepth, Bidirectional, StrataWidth, Logging, SaveUTMExr, SaveTMExr, LensRadius, FocusDistance,Turbidity, GroundPlane, MatFile
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
430 global textcol
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
431
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
432 Draw.Button("Export", evtExport, 10, 25, 100, 18, "Open file dialog and export")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
433 Draw.Button("Export Animation", evtExportAnim, 130, 25, 150, 18, "Open filedialog and export animation (careful: takes a lot of diskspace!!!)")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
434 BGL.glColor3f(textcol[0], textcol[1], textcol[2]) ; BGL.glRasterPos2i(10,10) ; Draw.Text("Press Q or ESC to quit.", "tiny")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
435
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
436 BGL.glRasterPos2i(10,60) ; Draw.Text("xml exporter for libps3")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
437
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
438
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
439 def event(evt, val): # function that handles keyboard and mouse events
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
440 if evt == Draw.ESCKEY or evt == Draw.QKEY:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
441 stop = Draw.PupMenu("OK?%t|Cancel export %x1")
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
442 if stop == 1:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
443 Draw.Exit()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
444 return
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
445
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
446 def buttonEvt(evt): # function that handles button events
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
447 if evt == evtExport:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
448 Blender.Window.FileSelector(save_still, "Export", newFName('xml'))
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
449 if evt == evtExportAnim:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
450 Blender.Window.FileSelector(save_anim, "Export Animation", newFName('xml'))
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
451 #if there was an event, redraw the window
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
452 if evt:
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
453 Draw.Redraw()
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
454
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
455 Draw.Register(gui, event, buttonEvt)
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
456
dc68bc5c9e41 Scale-SceneGraph.cpp
tkaito@nw0534.st.ie.u-ryukyu.ac.jp
parents:
diff changeset
457